mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-08 02:03:56 -06:00
qapi script: support enum type as discriminator in union
By default, any union will automatically generate a enum type as "[UnionName]Kind" in C code, and it is duplicated when the discriminator is specified as a pre-defined enum type in schema. After this patch, the pre-defined enum type will be really used as the switch case condition in generated C code, if discriminator is an enum field. Signed-off-by: Wenchao Xia <wenchaoqemu@gmail.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
parent
b0b58195e4
commit
bceae7697f
9 changed files with 94 additions and 17 deletions
0
tests/qapi-schema/flat-union-reverse-define.err
Normal file
0
tests/qapi-schema/flat-union-reverse-define.err
Normal file
1
tests/qapi-schema/flat-union-reverse-define.exit
Normal file
1
tests/qapi-schema/flat-union-reverse-define.exit
Normal file
|
@ -0,0 +1 @@
|
|||
0
|
17
tests/qapi-schema/flat-union-reverse-define.json
Normal file
17
tests/qapi-schema/flat-union-reverse-define.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{ 'union': 'TestUnion',
|
||||
'base': 'TestBase',
|
||||
'discriminator': 'enum1',
|
||||
'data': { 'value1': 'TestTypeA',
|
||||
'value2': 'TestTypeB' } }
|
||||
|
||||
{ 'type': 'TestBase',
|
||||
'data': { 'enum1': 'TestEnum' } }
|
||||
|
||||
{ 'enum': 'TestEnum',
|
||||
'data': [ 'value1', 'value2' ] }
|
||||
|
||||
{ 'type': 'TestTypeA',
|
||||
'data': { 'string': 'str' } }
|
||||
|
||||
{ 'type': 'TestTypeB',
|
||||
'data': { 'integer': 'int' } }
|
9
tests/qapi-schema/flat-union-reverse-define.out
Normal file
9
tests/qapi-schema/flat-union-reverse-define.out
Normal file
|
@ -0,0 +1,9 @@
|
|||
[OrderedDict([('union', 'TestUnion'), ('base', 'TestBase'), ('discriminator', 'enum1'), ('data', OrderedDict([('value1', 'TestTypeA'), ('value2', 'TestTypeB')]))]),
|
||||
OrderedDict([('type', 'TestBase'), ('data', OrderedDict([('enum1', 'TestEnum')]))]),
|
||||
OrderedDict([('enum', 'TestEnum'), ('data', ['value1', 'value2'])]),
|
||||
OrderedDict([('type', 'TestTypeA'), ('data', OrderedDict([('string', 'str')]))]),
|
||||
OrderedDict([('type', 'TestTypeB'), ('data', OrderedDict([('integer', 'int')]))])]
|
||||
[{'enum_name': 'TestEnum', 'enum_values': ['value1', 'value2']}]
|
||||
[OrderedDict([('type', 'TestBase'), ('data', OrderedDict([('enum1', 'TestEnum')]))]),
|
||||
OrderedDict([('type', 'TestTypeA'), ('data', OrderedDict([('string', 'str')]))]),
|
||||
OrderedDict([('type', 'TestTypeB'), ('data', OrderedDict([('integer', 'int')]))])]
|
Loading…
Add table
Add a link
Reference in a new issue