[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 12/16] qapi: Support downstream simple unions
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v4 12/16] qapi: Support downstream simple unions |
Date: |
Thu, 14 May 2015 06:50:58 -0600 |
Enhance the testsuite to cover downstream simple unions, including
when a union branch is a downstream name. Update the generator to
mangle the union names in the appropriate places.
Signed-off-by: Eric Blake <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
---
scripts/qapi-types.py | 2 +-
scripts/qapi-visit.py | 8 ++++----
tests/qapi-schema/qapi-schema-test.json | 1 +
tests/qapi-schema/qapi-schema-test.out | 6 ++++--
4 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 5118151..5b0bc5d 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -193,7 +193,7 @@ const int %(name)s_qtypes[QTYPE_MAX] = {
def generate_union(expr, meta):
- name = expr[meta]
+ name = c_name(expr[meta])
typeinfo = expr['data']
base = expr.get('base')
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index b500724..d1ec70b 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -255,9 +255,9 @@ def generate_visit_union(expr):
disc_type = enum_define['enum_name']
else:
# There will always be a discriminator in the C switch code, by default
- # it is an enum type generated silently as "'%sKind' % (name)"
- ret = generate_visit_enum('%sKind' % name, members.keys())
- disc_type = '%sKind' % (name)
+ # it is an enum type generated silently
+ ret = generate_visit_enum(name + 'Kind', members.keys())
+ disc_type = c_name(name) + 'Kind'
if base:
assert discriminator
@@ -281,7 +281,7 @@ void visit_type_%(name)s(Visitor *m, %(name)s **obj, const
char *name, Error **e
}
if (*obj) {
''',
- name=name)
+ name=c_name(name))
if base:
ret += mcgen('''
diff --git a/tests/qapi-schema/qapi-schema-test.json
b/tests/qapi-schema/qapi-schema-test.json
index ca9b34c..6416d85 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -114,3 +114,4 @@
'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
'data': { '__org.qemu_x-member2': 'str' } }
+{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
diff --git a/tests/qapi-schema/qapi-schema-test.out
b/tests/qapi-schema/qapi-schema-test.out
index 6ab4f00..f9ebe08 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -25,11 +25,13 @@
OrderedDict([('event', 'EVENT_D'), ('data', OrderedDict([('a',
'EventStructOne'), ('b', 'str'), ('*c', 'str'), ('*enum3', 'EnumOne')]))]),
OrderedDict([('enum', '__org.qemu_x-Enum'), ('data',
['__org.qemu_x-value'])]),
OrderedDict([('struct', '__org.qemu_x-Base'), ('data',
OrderedDict([('__org.qemu_x-member1', '__org.qemu_x-Enum')]))]),
- OrderedDict([('struct', '__org.qemu_x-Struct'), ('base',
'__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member2',
'str')]))])]
+ OrderedDict([('struct', '__org.qemu_x-Struct'), ('base',
'__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member2',
'str')]))]),
+ OrderedDict([('union', '__org.qemu_x-Union1'), ('data',
OrderedDict([('__org.qemu_x-branch', 'str')]))])]
[{'enum_name': 'EnumOne', 'enum_values': ['value1', 'value2', 'value3']},
{'enum_name': '__org.qemu_x-Enum', 'enum_values': ['__org.qemu_x-value']},
{'enum_name': 'UserDefAlternateKind', 'enum_values': None},
- {'enum_name': 'UserDefNativeListUnionKind', 'enum_values': None}]
+ {'enum_name': 'UserDefNativeListUnionKind', 'enum_values': None},
+ {'enum_name': '__org.qemu_x-Union1Kind', 'enum_values': None}]
[OrderedDict([('struct', 'NestedEnumsOne'), ('data', OrderedDict([('enum1',
'EnumOne'), ('*enum2', 'EnumOne'), ('enum3', 'EnumOne'), ('*enum4',
'EnumOne')]))]),
OrderedDict([('struct', 'UserDefZero'), ('data', OrderedDict([('integer',
'int')]))]),
OrderedDict([('struct', 'UserDefOne'), ('base', 'UserDefZero'), ('data',
OrderedDict([('string', 'str'), ('*enum1', 'EnumOne')]))]),
--
2.1.0
- [Qemu-devel] [PATCH v4 00/16] Fix qapi mangling of downstream names, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 02/16] qapi: Rename identical c_fun()/c_var() into c_name(), Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 05/16] qapi: Simplify c_enum_const(), Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 10/16] qapi: Support downstream enums, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 12/16] qapi: Support downstream simple unions,
Eric Blake <=
- [Qemu-devel] [PATCH v4 14/16] qapi: Support downstream alternates, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 11/16] qapi: Support downstream structs, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 15/16] qapi: Support downstream events and commands, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 16/16] qapi: Prefer '"str" + var' over '"str%s" % var', Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 13/16] qapi: Support downstream flat unions, Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 03/16] qapi: Rename _generate_enum_string() to camel_to_upper(), Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 04/16] qapi: Rename generate_enum_full_value() to c_enum_const(), Eric Blake, 2015/05/14
- [Qemu-devel] [PATCH v4 01/16] qapi: Fix C identifiers generated for names containing '.', Eric Blake, 2015/05/14