mirror of
https://github.com/yuzu-emu/unicorn
synced 2024-11-25 17:35:26 +00:00
qapi: Drop support for inline nested types
A future patch will be using a 'name':{dictionary} entry in the QAPI schema to specify a default value for an optional argument (see previous commit messages for more details why); but existing use of inline nested structs conflicts with that goal. Now that all commands have been changed to avoid inline nested structs, nuke support for them, and turn it into a hard error. Update the testsuite to reflect tighter parsing rules. Backports commit 6b5abc7df7ef9aadb3ff0eba6ccf4f1f0181e2e1 from qemu
This commit is contained in:
parent
2d6d612c61
commit
8d2f349447
4 changed files with 16 additions and 55 deletions
|
@ -21,7 +21,7 @@ def _generate_event_api_name(event_name, params):
|
|||
l = len(api_name)
|
||||
|
||||
if params:
|
||||
for argname, argentry, optional, structured in parse_args(params):
|
||||
for argname, argentry, optional in parse_args(params):
|
||||
if optional:
|
||||
api_name += "bool has_%s,\n" % c_var(argname)
|
||||
api_name += "".ljust(l)
|
||||
|
@ -93,7 +93,7 @@ def generate_event_implement(api_name, event_name, params):
|
|||
""",
|
||||
event_name = event_name)
|
||||
|
||||
for argname, argentry, optional, structured in parse_args(params):
|
||||
for argname, argentry, optional in parse_args(params):
|
||||
if optional:
|
||||
ret += mcgen("""
|
||||
if (has_%(var)s) {
|
||||
|
|
|
@ -63,18 +63,13 @@ typedef struct %(name)sList
|
|||
def generate_struct_fields(members):
|
||||
ret = ''
|
||||
|
||||
for argname, argentry, optional, structured in parse_args(members):
|
||||
for argname, argentry, optional in parse_args(members):
|
||||
if optional:
|
||||
ret += mcgen('''
|
||||
bool has_%(c_name)s;
|
||||
''',
|
||||
c_name=c_var(argname))
|
||||
if structured:
|
||||
push_indent()
|
||||
ret += generate_struct({ "field": argname, "data": argentry})
|
||||
pop_indent()
|
||||
else:
|
||||
ret += mcgen('''
|
||||
ret += mcgen('''
|
||||
%(c_type)s %(c_name)s;
|
||||
''',
|
||||
c_type=c_type(argentry), c_name=c_var(argname))
|
||||
|
|
|
@ -51,27 +51,6 @@ def generate_visit_struct_fields(name, field_prefix, fn_prefix, members, base =
|
|||
else:
|
||||
full_name = "%s_%s" % (name, fn_prefix)
|
||||
|
||||
for argname, argentry, optional, structured in parse_args(members):
|
||||
if structured:
|
||||
if not fn_prefix:
|
||||
nested_fn_prefix = argname
|
||||
else:
|
||||
nested_fn_prefix = "%s_%s" % (fn_prefix, argname)
|
||||
|
||||
nested_field_prefix = "%s%s." % (field_prefix, argname)
|
||||
ret += generate_visit_struct_fields(name, nested_field_prefix,
|
||||
nested_fn_prefix, argentry)
|
||||
ret += mcgen('''
|
||||
|
||||
static void visit_type_%(full_name)s_field_%(c_name)s(Visitor *m, %(name)s **obj, Error **errp)
|
||||
{
|
||||
''',
|
||||
name=name, full_name=full_name, c_name=c_var(argname))
|
||||
ret += generate_visit_struct_body(full_name, argname, argentry)
|
||||
ret += mcgen('''
|
||||
}
|
||||
''')
|
||||
|
||||
if base:
|
||||
ret += generate_visit_implicit_struct(base)
|
||||
|
||||
|
@ -94,7 +73,7 @@ if (err) {
|
|||
c_prefix=c_var(field_prefix),
|
||||
type=type_name(base), c_name=c_var('base'))
|
||||
|
||||
for argname, argentry, optional, structured in parse_args(members):
|
||||
for argname, argentry, optional in parse_args(members):
|
||||
if optional:
|
||||
ret += mcgen('''
|
||||
visit_optional(m, &(*obj)->%(c_prefix)shas_%(c_name)s, "%(name)s", &err);
|
||||
|
@ -104,18 +83,12 @@ if (!err && (*obj)->%(prefix)shas_%(c_name)s) {
|
|||
c_name=c_var(argname), name=argname)
|
||||
push_indent()
|
||||
|
||||
if structured:
|
||||
ret += mcgen('''
|
||||
visit_type_%(full_name)s_field_%(c_name)s(m, obj, &err);
|
||||
''',
|
||||
full_name=full_name, c_name=c_var(argname))
|
||||
else:
|
||||
ret += mcgen('''
|
||||
ret += mcgen('''
|
||||
visit_type_%(type)s(m, &(*obj)->%(c_prefix)s%(c_name)s, "%(name)s", &err);
|
||||
''',
|
||||
c_prefix=c_var(field_prefix), prefix=field_prefix,
|
||||
type=type_name(argentry), c_name=c_var(argname),
|
||||
name=argname)
|
||||
c_prefix=c_var(field_prefix), prefix=field_prefix,
|
||||
type=type_name(argentry), c_name=c_var(argname),
|
||||
name=argname)
|
||||
|
||||
if optional:
|
||||
pop_indent()
|
||||
|
|
|
@ -373,10 +373,12 @@ def check_type(expr_info, source, value, allow_array = False,
|
|||
for (key, arg) in value.items():
|
||||
check_name(expr_info, "Member of %s" % source, key,
|
||||
allow_optional=allow_optional)
|
||||
# Todo: allow dictionaries to represent default values of
|
||||
# an optional argument.
|
||||
check_type(expr_info, "Member '%s' of %s" % (key, source), arg,
|
||||
allow_array=True, allow_dict=True, allow_optional=True,
|
||||
allow_array=True, allow_star=allow_star,
|
||||
allow_metas=['built-in', 'union', 'alternate', 'struct',
|
||||
'enum'], allow_star=allow_star)
|
||||
'enum'])
|
||||
|
||||
def check_command(expr, expr_info):
|
||||
name = expr['command']
|
||||
|
@ -405,14 +407,6 @@ def check_event(expr, expr_info):
|
|||
expr.get('data'), allow_dict=True, allow_optional=True,
|
||||
allow_metas=['union', 'struct'])
|
||||
|
||||
if params:
|
||||
for argname, argentry, optional, structured in parse_args(params):
|
||||
if structured:
|
||||
raise QAPIExprError(expr_info,
|
||||
"Nested structure define in event is not "
|
||||
"supported, event '%s', argname '%s'"
|
||||
% (expr['event'], argname))
|
||||
|
||||
def check_union(expr, expr_info):
|
||||
name = expr['union']
|
||||
base = expr.get('base')
|
||||
|
@ -671,13 +665,12 @@ def parse_args(typeinfo):
|
|||
argname = member
|
||||
argentry = typeinfo[member]
|
||||
optional = False
|
||||
structured = False
|
||||
if member.startswith('*'):
|
||||
argname = member[1:]
|
||||
optional = True
|
||||
if isinstance(argentry, OrderedDict):
|
||||
structured = True
|
||||
yield (argname, argentry, optional, structured)
|
||||
# Todo: allow argentry to be OrderedDict, for providing the
|
||||
# value of an optional argument.
|
||||
yield (argname, argentry, optional)
|
||||
|
||||
def de_camel_case(name):
|
||||
new_name = ''
|
||||
|
|
Loading…
Reference in a new issue