qapi: Support downstream flat unions

Enhance the testsuite to cover downstream flat unions, including
the base type, discriminator name and type, and branch name and
type. Update the generator to mangle the union names in the
appropriate places.

Backports commit 857af5f06c3fb097d1bb6bc8a23b9992aac99e75 from qemu
This commit is contained in:
Eric Blake 2018-02-19 15:06:21 -05:00 committed by Lioncash
parent a2119bd210
commit 4292c61dbe
No known key found for this signature in database
GPG Key ID: 4E3C3CC1031BA9C7
2 changed files with 3 additions and 3 deletions

View File

@ -204,7 +204,7 @@ struct %(name)s
void *data; void *data;
''', ''',
name=name, name=name,
discriminator_type_name=discriminator_type_name) discriminator_type_name=c_name(discriminator_type_name))
for key in typeinfo: for key in typeinfo:
ret += mcgen(''' ret += mcgen('''

View File

@ -253,7 +253,7 @@ def generate_visit_union(expr):
if enum_define: if enum_define:
# Use the enum type as discriminator # Use the enum type as discriminator
ret = "" ret = ""
disc_type = enum_define['enum_name'] disc_type = c_name(enum_define['enum_name'])
else: else:
# There will always be a discriminator in the C switch code, by default # There will always be a discriminator in the C switch code, by default
# it is an enum type generated silently # it is an enum type generated silently
@ -291,7 +291,7 @@ void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error **e
goto out_obj; goto out_obj;
} }
''', ''',
name=name) name=c_name(name))
if not discriminator: if not discriminator:
disc_key = "type" disc_key = "type"