Hi On Mon, Jun 14, 2021 at 4:48 PM Markus Armbruster wrote: > marcandre.lureau@redhat.com writes: > > > From: Marc-André Lureau > > > > Instead of building prepocessor conditions from a list of string, use > > the result generated from QAPISchemaIfCond.cgen(). > > I understand why you're doing this, but only because I know where you're > headed. By itself, it is not an improvement: you move C generation out > of common.py into schema.py. You need to explain why that's useful. > > What about? In the following commits, QAPISchemaIfCond is going to hold an internal tree structure. Moving cgen() there allows to abstract away the condition representation. > > diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py > > index bc357ebbfa..aa4715c519 100644 > > --- a/scripts/qapi/schema.py > > +++ b/scripts/qapi/schema.py > > @@ -29,6 +29,9 @@ class QAPISchemaIfCond: > > def __init__(self, ifcond=None): > > self.ifcond = ifcond or [] > > > > + def cgen(self): > > + return ' && '.join(self.ifcond) > > Fragile. Better: > > return '(' + ') && ('.join(self.ifcond) + ')' > > This is an intermediary step, but ok. If we want to keep C generation details out of schema.py, we need a > helper mapping self.ifcond: Sequence[str] to C code, similar to how > QAPISchemaEntity.c_name() works with helper c_name(). > Leaving a FIXME. > > + > > # Returns true if the condition is not void > > def __bool__(self): > > return bool(self.ifcond) > > diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py > > index 3673cf0f49..db9ff95bd1 100644 > > --- a/scripts/qapi/types.py > > +++ b/scripts/qapi/types.py > > @@ -51,13 +51,13 @@ def gen_enum_lookup(name: str, > > ''', > > c_name=c_name(name)) > > for memb in members: > > - ret += gen_if(memb.ifcond.ifcond) > > + ret += gen_if(memb.ifcond.cgen()) > > index = c_enum_const(name, memb.name, prefix) > > ret += mcgen(''' > > [%(index)s] = "%(name)s", > > ''', > > index=index, name=memb.name) > > - ret += gen_endif(memb.ifcond.ifcond) > > + ret += gen_endif(memb.ifcond.cgen()) > > > > ret += mcgen(''' > > }, > [More of the same snipped...] > > > -- Marc-André Lureau