On Mon, Oct 2, 2017 at 5:25 PM, Markus Armbruster <arm...@redhat.com> wrote: > Replace flags @enum_member, @allow_optional by string @meta: > 'member-enum' implies @enum_member, 'member-struct' implies > @allow_optional. > > Signed-off-by: Markus Armbruster <arm...@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lur...@redhat.com> > --- > scripts/qapi.py | 22 ++++++++++------------ > 1 file changed, 10 insertions(+), 12 deletions(-) > > diff --git a/scripts/qapi.py b/scripts/qapi.py > index 248af89b0b..208010c241 100644 > --- a/scripts/qapi.py > +++ b/scripts/qapi.py > @@ -593,8 +593,7 @@ valid_name = re.compile(r'^(__[a-zA-Z0-9.-]+_)?' > '[a-zA-Z][a-zA-Z0-9_-]*$') > > > -def check_name(info, source, name, allow_optional=False, > - enum_member=False): > +def check_name(info, source, name, meta): > global valid_name > membername = name > > @@ -602,12 +601,12 @@ def check_name(info, source, name, allow_optional=False, > raise QAPISemError(info, "%s requires a string name" % source) > if name.startswith('*'): > membername = name[1:] > - if not allow_optional: > + if meta != 'member-struct': > raise QAPISemError(info, "%s does not allow optional name '%s'" > % (source, name)) > # Enum members can start with a digit, because the generated C > # code always prefixes it with the enum name > - if enum_member and membername[0].isdigit(): > + if meta == 'member-enum' and membername[0].isdigit(): > membername = 'D' + membername > # Reserve the entire 'q_' namespace for c_name(), and for 'q_empty' > # and 'q_obj_*' implicit type names. > @@ -618,7 +617,7 @@ def check_name(info, source, name, allow_optional=False, > > def add_name(name, info, meta, implicit=False): > global all_names > - check_name(info, "'%s'" % meta, name) > + check_name(info, "'%s'" % meta, name, meta) > # FIXME should reject names that differ only in '_' vs. '.' > # vs. '-', because they're liable to clash in generated C. > if name in all_names: > @@ -667,8 +666,7 @@ def check_type(info, source, value, allow_array=False, > > # value is a dictionary, check that each member is okay > for (key, arg) in value.items(): > - check_name(info, "Member of %s" % source, key, > - allow_optional=allow_optional) > + check_name(info, "Member of %s" % source, key, 'member-struct') > if c_name(key, False) == 'u' or c_name(key, > False).startswith('has_'): > raise QAPISemError(info, "Member of %s uses reserved name '%s'" > % (source, key)) > @@ -741,7 +739,7 @@ def check_union(expr, info): > # The value of member 'discriminator' must name a non-optional > # member of the base struct. > check_name(info, "Discriminator of flat union '%s'" % name, > - discriminator) > + discriminator, 'member-union') > discriminator_type = base_members.get(discriminator) > if not discriminator_type: > raise QAPISemError(info, > @@ -760,7 +758,7 @@ def check_union(expr, info): > if len(members) == 0: > raise QAPISemError(info, "Union '%s' cannot have empty 'data'" % > name) > for (key, value) in members.items(): > - check_name(info, "Member of union '%s'" % name, key) > + check_name(info, "Member of union '%s'" % name, key, 'member-union') > > # Each value must name a known type > check_type(info, "Member '%s' of union '%s'" % (key, name), > @@ -794,7 +792,8 @@ def check_alternate(expr, info): > "Alternate '%s' should have at least two branches > " > "in 'data'" % name) > for (key, value) in members.items(): > - check_name(info, "Member of alternate '%s'" % name, key) > + check_name(info, "Member of alternate '%s'" % name, key, > + 'member-alternate') > > # Ensure alternates have no type conflicts. > check_type(info, "Member '%s' of alternate '%s'" % (key, name), > @@ -836,8 +835,7 @@ def check_enum(expr, info): > raise QAPISemError(info, > "Enum '%s' requires a string for 'prefix'" % name) > for member in members: > - check_name(info, "Member of enum '%s'" % name, member, > - enum_member=True) > + check_name(info, "Member of enum '%s'" % name, member, 'member-enum') > > > def check_struct(expr, info): > -- > 2.13.6 > > -- Marc-André Lureau