class QAPIGen(object):
- def __init__(self):
+ def __init__(self, fname):
+ self.fname = fname
self._preamble = ''
self._body = ''
def add(self, text):
self._body += text
- def get_content(self, fname=None):
- return (self._top(fname) + self._preamble + self._body
- + self._bottom(fname))
+ def get_content(self):
+ return self._top() + self._preamble + self._body + self._bottom()
- def _top(self, fname):
+ def _top(self):
return ''
- def _bottom(self, fname):
+ def _bottom(self):
return ''
- def write(self, output_dir, fname):
- pathname = os.path.join(output_dir, fname)
+ def write(self, output_dir):
+ pathname = os.path.join(output_dir, self.fname)
dir = os.path.dirname(pathname)
if dir:
try:
f = open(fd, 'r+', encoding='utf-8')
else:
f = os.fdopen(fd, 'r+')
- text = self.get_content(fname)
+ text = self.get_content()
oldtext = f.read(len(text) + 1)
if text != oldtext:
f.seek(0)
class QAPIGenCCode(QAPIGen):
- def __init__(self):
- QAPIGen.__init__(self)
+ def __init__(self, fname):
+ QAPIGen.__init__(self, fname)
self._start_if = None
def start_if(self, ifcond):
self._preamble = _wrap_ifcond(self._start_if[0],
self._start_if[2], self._preamble)
- def get_content(self, fname=None):
+ def get_content(self):
assert self._start_if is None
- return QAPIGen.get_content(self, fname)
+ return QAPIGen.get_content(self)
class QAPIGenC(QAPIGenCCode):
- def __init__(self, blurb, pydoc):
- QAPIGenCCode.__init__(self)
+ def __init__(self, fname, blurb, pydoc):
+ QAPIGenCCode.__init__(self, fname)
self._blurb = blurb
self._copyright = '\n * '.join(re.findall(r'^Copyright .*', pydoc,
re.MULTILINE))
- def _top(self, fname):
+ def _top(self):
return mcgen('''
/* AUTOMATICALLY GENERATED, DO NOT MODIFY */
''',
blurb=self._blurb, copyright=self._copyright)
- def _bottom(self, fname):
+ def _bottom(self):
return mcgen('''
/* Dummy declaration to prevent empty .o file */
char dummy_%(name)s;
''',
- name=c_name(fname))
+ name=c_name(self.fname))
class QAPIGenH(QAPIGenC):
- def _top(self, fname):
- return QAPIGenC._top(self, fname) + guardstart(fname)
+ def _top(self):
+ return QAPIGenC._top(self) + guardstart(self.fname)
- def _bottom(self, fname):
- return guardend(fname)
+ def _bottom(self):
+ return guardend(self.fname)
class QAPIGenDoc(QAPIGen):
- def _top(self, fname):
- return (QAPIGen._top(self, fname)
+ def _top(self):
+ return (QAPIGen._top(self)
+ '@c AUTOMATICALLY GENERATED, DO NOT MODIFY\n\n')
def __init__(self, prefix, what, blurb, pydoc):
self._prefix = prefix
self._what = what
- self._genc = QAPIGenC(blurb, pydoc)
- self._genh = QAPIGenH(blurb, pydoc)
+ self._genc = QAPIGenC(self._prefix + self._what + '.c',
+ blurb, pydoc)
+ self._genh = QAPIGenH(self._prefix + self._what + '.h',
+ blurb, pydoc)
def write(self, output_dir):
- self._genc.write(output_dir, self._prefix + self._what + '.c')
- self._genh.write(output_dir, self._prefix + self._what + '.h')
+ self._genc.write(output_dir)
+ self._genh.write(output_dir)
class QAPISchemaModularCVisitor(QAPISchemaVisitor):
return ret
def _add_module(self, name, blurb):
- genc = QAPIGenC(blurb, self._pydoc)
- genh = QAPIGenH(blurb, self._pydoc)
+ basename = self._module_basename(self._what, name)
+ genc = QAPIGenC(basename + '.c', blurb, self._pydoc)
+ genh = QAPIGenH(basename + '.h', blurb, self._pydoc)
self._module[name] = (genc, genh)
self._set_module(name)
for name in self._module:
if self._is_builtin_module(name) and not opt_builtins:
continue
- basename = self._module_basename(self._what, name)
(genc, genh) = self._module[name]
- genc.write(output_dir, basename + '.c')
- genh.write(output_dir, basename + '.h')
+ genc.write(output_dir)
+ genh.write(output_dir)
def _begin_user_module(self, name):
pass