diff options
author | Markus Armbruster <armbru@redhat.com> | 2017-03-15 13:57:29 +0100 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2017-03-16 07:13:04 +0100 |
commit | eda43c68440e32062c32cc99a79edbb52cf87a74 (patch) | |
tree | 4650901863220b9de276cd30bcd32d52eedffa3f /scripts/qapi.py | |
parent | 062e856b155a8b7724b8eba449fc3aa8a181d46b (diff) |
qapi: Simplify what gets stored in enum_types
Don't invent a new dictionary structure just for enum_types, simply
store the defining expression, like we do for struct_types and
union_types.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <1489582656-31133-41-git-send-email-armbru@redhat.com>
Diffstat (limited to 'scripts/qapi.py')
-rw-r--r-- | scripts/qapi.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/scripts/qapi.py b/scripts/qapi.py index d5a113c7d6..3c6e137847 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -668,16 +668,17 @@ def find_union(name): return None -def add_enum(name, info, enum_values=None, implicit=False): +def add_enum(definition, info): global enum_types - add_name(name, info, 'enum', implicit) - enum_types.append({'enum_name': name, 'enum_values': enum_values}) + name = definition['enum'] + add_name(name, info, 'enum', 'data' not in definition) + enum_types.append(definition) def find_enum(name): global enum_types for enum in enum_types: - if enum['enum_name'] == name: + if enum['enum'] == name: return enum return None @@ -825,15 +826,15 @@ def check_union(expr, info): # If the discriminator names an enum type, then all members # of 'data' must also be members of the enum type. if enum_define: - if key not in enum_define['enum_values']: + if key not in enum_define['data']: raise QAPISemError(info, "Discriminator value '%s' is not found in " "enum '%s'" - % (key, enum_define['enum_name'])) + % (key, enum_define['enum'])) # If discriminator is user-defined, ensure all values are covered if enum_define: - for value in enum_define['enum_values']: + for value in enum_define['data']: if value not in members.keys(): raise QAPISemError(info, "Union '%s' data missing '%s' branch" % (name, value)) @@ -938,7 +939,7 @@ def check_exprs(exprs): if 'enum' in expr: name = expr['enum'] check_keys(expr_elem, 'enum', ['data'], ['prefix']) - add_enum(name, info, expr['data']) + add_enum(expr, info) elif 'union' in expr: name = expr['union'] check_keys(expr_elem, 'union', ['data'], @@ -971,13 +972,13 @@ def check_exprs(exprs): # Try again for hidden UnionKind enum for expr_elem in exprs: expr = expr_elem['expr'] - if 'union' in expr: - if not discriminator_find_enum_define(expr): - add_enum('%sKind' % expr['union'], expr_elem['info'], - implicit=True) + if 'union' in expr and not discriminator_find_enum_define(expr): + name = '%sKind' % expr['union'] elif 'alternate' in expr: - add_enum('%sKind' % expr['alternate'], expr_elem['info'], - implicit=True) + name = '%sKind' % expr['alternate'] + else: + continue + add_enum({ 'enum': name }, expr_elem['info']) # Validate that exprs make sense for expr_elem in exprs: |