Marc-André Lureau <marcandre.lur...@redhat.com> writes: > Add helpers to wrap generated code with #if/#endif lines. > > Add QAPIGenCSnippet class to write C snippet code, make QAPIGenC > inherit from it, for full C files with copyright headers etc. > > Add a 'with' statement context manager that will be used to wrap > generator visitor methods. The manager will check if code was > generated before adding #if/#endif lines on QAPIGenCSnippet > objects. Used in the following patches. > > Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> > --- > scripts/qapi/common.py | 82 +++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 78 insertions(+), 4 deletions(-) > > diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py > index 47efe79758..60c1d0a783 100644 > --- a/scripts/qapi/common.py > +++ b/scripts/qapi/common.py [...] > @@ -2061,6 +2097,23 @@ class QAPIGen(object): > def add(self, text): > self._body += text > > + def start_if(self, ifcond): > + self._ifcond = ifcond > + self._start_if_body = self._body > + self._start_if_preamble = self._preamble
pylint gripes: +W:2102, 8: Attribute '_start_if_body' defined outside __init__ (attribute-defined-outside-init) +W:2103, 8: Attribute '_start_if_preamble' defined outside __init__ (attribute-defined-outside-init) We generally define in .__init__(), except when we want to catch premature use, such as in PATCH 05. Let's define these two in .__init__(). [...]