aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2017-03-15 13:57:31 +0100
committerMarkus Armbruster <armbru@redhat.com>2017-03-16 07:13:04 +0100
commit5f018446fe69ec85711db364e8d1f4c4de372bf5 (patch)
tree9e40c2ee981f8466a23dccbaef423580406ff642
parent6f05345f8f8eac137e0ba22a7389cdeaff60c9b2 (diff)
qapi: enum_types is a list used like a dict, make it one
Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <1489582656-31133-43-git-send-email-armbru@redhat.com>
-rw-r--r--scripts/qapi.py29
1 files changed, 6 insertions, 23 deletions
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 1f79eb4d17..735ddaa605 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -46,7 +46,7 @@ returns_whitelist = []
# Whitelist of entities allowed to violate case conventions
name_case_whitelist = []
-enum_types = []
+enum_types = {}
struct_types = []
union_types = []
all_names = {}
@@ -567,7 +567,7 @@ def find_alternate_member_qtype(qapi_type):
return builtin_types[qapi_type]
elif find_struct(qapi_type):
return 'QTYPE_QDICT'
- elif find_enum(qapi_type):
+ elif qapi_type in enum_types:
return 'QTYPE_QSTRING'
elif find_union(qapi_type):
return 'QTYPE_QDICT'
@@ -591,7 +591,7 @@ def discriminator_find_enum_define(expr):
if not discriminator_type:
return None
- return find_enum(discriminator_type)
+ return enum_types.get(discriminator_type)
# Names must be letters, numbers, -, and _. They must start with letter,
@@ -664,23 +664,6 @@ def find_union(name):
return None
-def add_enum(definition, info):
- global enum_types
- enum_types.append(definition)
-
-
-def find_enum(name):
- global enum_types
- for enum in enum_types:
- if enum['enum'] == name:
- return enum
- return None
-
-
-def is_enum(name):
- return find_enum(name) is not None
-
-
def check_type(info, source, value, allow_array=False,
allow_dict=False, allow_optional=False,
allow_metas=[]):
@@ -799,7 +782,7 @@ def check_union(expr, info):
"Discriminator '%s' is not a member of base "
"struct '%s'"
% (discriminator, base))
- enum_define = find_enum(discriminator_type)
+ enum_define = enum_types.get(discriminator_type)
allow_metas = ['struct']
# Do not allow string discriminator
if not enum_define:
@@ -933,7 +916,7 @@ def check_exprs(exprs):
if 'enum' in expr:
meta = 'enum'
check_keys(expr_elem, 'enum', ['data'], ['prefix'])
- add_enum(expr, info)
+ enum_types[expr[meta]] = expr
elif 'union' in expr:
meta = 'union'
check_keys(expr_elem, 'union', ['data'],
@@ -971,7 +954,7 @@ def check_exprs(exprs):
name = '%sKind' % expr['alternate']
else:
continue
- add_enum({ 'enum': name }, expr_elem['info'])
+ enum_types[name] = {'enum': name}
add_name(name, info, 'enum', implicit=True)
# Validate that exprs make sense