diff options
author | Wenchao Xia <wenchaoqemu@gmail.com> | 2014-03-06 17:08:56 -0800 |
---|---|---|
committer | Luiz Capitulino <lcapitulino@redhat.com> | 2014-03-11 09:07:42 -0400 |
commit | bceae7697ff1711675c26f715b945737bc6849ae (patch) | |
tree | b528a35656db4d66e9c5be5be54edc7cbeb79344 /docs | |
parent | b0b58195e4a3039b6a473124dc27ed707db50240 (diff) | |
download | qemu-bceae7697ff1711675c26f715b945737bc6849ae.zip qemu-bceae7697ff1711675c26f715b945737bc6849ae.tar.gz qemu-bceae7697ff1711675c26f715b945737bc6849ae.tar.bz2 |
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>
Diffstat (limited to 'docs')
-rw-r--r-- | docs/qapi-code-gen.txt | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/docs/qapi-code-gen.txt b/docs/qapi-code-gen.txt index 0728f36..a2e7921 100644 --- a/docs/qapi-code-gen.txt +++ b/docs/qapi-code-gen.txt @@ -123,11 +123,15 @@ And it looks like this on the wire: Flat union types avoid the nesting on the wire. They are used whenever a specific field of the base type is declared as the discriminator ('type' is -then no longer generated). The discriminator must always be a string field. +then no longer generated). The discriminator can be a string field or a +predefined enum field. If it is a string field, a hidden enum type will be +generated as "[UNION_NAME]Kind". If it is an enum field, a compile time check +will be done to verify the correctness. It is recommended to use an enum field. The above example can then be modified as follows: + { 'enum': 'BlockdevDriver', 'data': [ 'raw', 'qcow2' ] } { 'type': 'BlockdevCommonOptions', - 'data': { 'driver': 'str', 'readonly': 'bool' } } + 'data': { 'driver': 'BlockdevDriver', 'readonly': 'bool' } } { 'union': 'BlockdevOptions', 'base': 'BlockdevCommonOptions', 'discriminator': 'driver', |