aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2015-05-04 09:05:25 -0600
committerMarkus Armbruster <armbru@redhat.com>2015-05-05 18:39:01 +0200
commitfd41dd4eae5f7ea92f10c04cb3f217727fcee91f (patch)
tree04cf70812be04f55d4a4aa5cd770a7ab5b1ec6eb /scripts
parent2cbf09925ad45401673a79ab77f67de2f04a826c (diff)
downloadqemu-fd41dd4eae5f7ea92f10c04cb3f217727fcee91f.zip
qemu-fd41dd4eae5f7ea92f10c04cb3f217727fcee91f.tar.gz
qemu-fd41dd4eae5f7ea92f10c04cb3f217727fcee91f.tar.bz2
qapi: Prefer 'struct' over 'type' in generator
Referring to "type" as both a meta-type (built-in, enum, union, alternate, or struct) and a specific type (the name that the schema uses for declaring structs) is confusing. The confusion is only made worse by the fact that the generator mostly already refers to struct even when dealing with expr['type']. This commit changes the generator to consistently refer to it as struct everywhere, plus a single back-compat tweak that allows accepting the existing .json files as-is, so that the meat of this change is separate from the mindless churn of that change. Fix the testsuite fallout for error messages that change, and in some cases, become more legible. Improve comments to better match our intentions where a struct (rather than any complex type) is required. Note that in some cases, an error message now refers to 'struct' while the schema still refers to 'type'; that will be cleaned up in the later commit to the schema. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qapi-types.py16
-rw-r--r--scripts/qapi-visit.py8
-rw-r--r--scripts/qapi.py46
3 files changed, 41 insertions, 29 deletions
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 9c8d68c..a429d9e 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -83,7 +83,7 @@ def generate_struct_fields(members):
def generate_struct(expr):
- structname = expr.get('type', "")
+ structname = expr.get('struct', "")
fieldname = expr.get('field', "")
members = expr['data']
base = expr.get('base')
@@ -394,8 +394,8 @@ fdecl.write(guardend("QAPI_TYPES_BUILTIN_STRUCT_DECL"))
for expr in exprs:
ret = "\n"
- if expr.has_key('type'):
- ret += generate_fwd_struct(expr['type'], expr['data'])
+ if expr.has_key('struct'):
+ ret += generate_fwd_struct(expr['struct'], expr['data'])
elif expr.has_key('enum'):
ret += generate_enum(expr['enum'], expr['data']) + "\n"
ret += generate_fwd_enum_struct(expr['enum'], expr['data'])
@@ -435,12 +435,12 @@ if do_builtins:
for expr in exprs:
ret = "\n"
- if expr.has_key('type'):
+ if expr.has_key('struct'):
ret += generate_struct(expr) + "\n"
- ret += generate_type_cleanup_decl(expr['type'] + "List")
- fdef.write(generate_type_cleanup(expr['type'] + "List") + "\n")
- ret += generate_type_cleanup_decl(expr['type'])
- fdef.write(generate_type_cleanup(expr['type']) + "\n")
+ ret += generate_type_cleanup_decl(expr['struct'] + "List")
+ fdef.write(generate_type_cleanup(expr['struct'] + "List") + "\n")
+ ret += generate_type_cleanup_decl(expr['struct'])
+ fdef.write(generate_type_cleanup(expr['struct']) + "\n")
elif expr.has_key('union'):
ret += generate_union(expr, 'union')
ret += generate_type_cleanup_decl(expr['union'] + "List")
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 9222671..c739a95 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -178,7 +178,7 @@ def generate_visit_struct_body(field_prefix, name, members):
def generate_visit_struct(expr):
- name = expr['type']
+ name = expr['struct']
members = expr['data']
base = expr.get('base')
@@ -545,12 +545,12 @@ if do_builtins:
fdef.write(generate_visit_list(typename, None))
for expr in exprs:
- if expr.has_key('type'):
+ if expr.has_key('struct'):
ret = generate_visit_struct(expr)
- ret += generate_visit_list(expr['type'], expr['data'])
+ ret += generate_visit_list(expr['struct'], expr['data'])
fdef.write(ret)
- ret = generate_declaration(expr['type'], expr['data'])
+ ret = generate_declaration(expr['struct'], expr['data'])
fdecl.write(ret)
elif expr.has_key('union'):
ret = generate_visit_union(expr)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index e391b5a..e50fec8 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -419,7 +419,7 @@ def check_union(expr, expr_info):
members = expr['data']
values = { 'MAX': '(automatic)' }
- # If the object has a member 'base', its value must name a complex type,
+ # If the object has a member 'base', its value must name a struct,
# and there must be a discriminator.
if base is not None:
if discriminator is None:
@@ -448,18 +448,18 @@ def check_union(expr, expr_info):
base_fields = find_base_fields(base)
if not base_fields:
raise QAPIExprError(expr_info,
- "Base '%s' is not a valid type"
+ "Base '%s' is not a valid struct"
% base)
# The value of member 'discriminator' must name a non-optional
- # member of the base type.
+ # member of the base struct.
check_name(expr_info, "Discriminator of flat union '%s'" % name,
discriminator)
discriminator_type = base_fields.get(discriminator)
if not discriminator_type:
raise QAPIExprError(expr_info,
"Discriminator '%s' is not a member of base "
- "type '%s'"
+ "struct '%s'"
% (discriminator, base))
enum_define = find_enum(discriminator_type)
allow_metas=['struct']
@@ -546,12 +546,12 @@ def check_enum(expr, expr_info):
values[key] = member
def check_struct(expr, expr_info):
- name = expr['type']
+ name = expr['struct']
members = expr['data']
- check_type(expr_info, "'data' for type '%s'" % name, members,
+ check_type(expr_info, "'data' for struct '%s'" % name, members,
allow_dict=True, allow_optional=True)
- check_type(expr_info, "'base' for type '%s'" % name, expr.get('base'),
+ check_type(expr_info, "'base' for struct '%s'" % name, expr.get('base'),
allow_metas=['struct'])
def check_exprs(schema):
@@ -565,7 +565,7 @@ def check_exprs(schema):
check_union(expr, info)
elif expr.has_key('alternate'):
check_alternate(expr, info)
- elif expr.has_key('type'):
+ elif expr.has_key('struct'):
check_struct(expr, info)
elif expr.has_key('command'):
check_command(expr, info)
@@ -617,6 +617,20 @@ def parse_schema(input_file):
for expr_elem in schema.exprs:
expr = expr_elem['expr']
info = expr_elem['info']
+
+ # back-compat hack until all schemas have been converted;
+ # preserve the ordering of the original expression
+ if expr.has_key('type'):
+ seen_type = False
+ for (key, value) in expr.items():
+ if key == 'type':
+ seen_type = True
+ del expr['type']
+ expr['struct'] = value
+ elif seen_type:
+ del expr[key]
+ expr[key] = value
+
if expr.has_key('enum'):
check_keys(expr_elem, 'enum', ['data'])
add_enum(expr['enum'], info, expr['data'])
@@ -627,8 +641,8 @@ def parse_schema(input_file):
elif expr.has_key('alternate'):
check_keys(expr_elem, 'alternate', ['data'])
add_name(expr['alternate'], info, 'alternate')
- elif expr.has_key('type'):
- check_keys(expr_elem, 'type', ['data'], ['base'])
+ elif expr.has_key('struct'):
+ check_keys(expr_elem, 'struct', ['data'], ['base'])
add_struct(expr, info)
elif expr.has_key('command'):
check_keys(expr_elem, 'command', [],
@@ -745,11 +759,9 @@ def type_name(name):
return c_list_type(name[0])
return name
-def add_name(name, info, meta, implicit = False, source = None):
+def add_name(name, info, meta, implicit = False):
global all_names
- if not source:
- source = "'%s'" % meta
- check_name(info, source, name)
+ check_name(info, "'%s'" % meta, name)
if name in all_names:
raise QAPIExprError(info,
"%s '%s' is already defined"
@@ -762,14 +774,14 @@ def add_name(name, info, meta, implicit = False, source = None):
def add_struct(definition, info):
global struct_types
- name = definition['type']
- add_name(name, info, 'struct', source="'type'")
+ name = definition['struct']
+ add_name(name, info, 'struct')
struct_types.append(definition)
def find_struct(name):
global struct_types
for struct in struct_types:
- if struct['type'] == name:
+ if struct['struct'] == name:
return struct
return None