[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 28/50] qapi: add 'if' to alternate variant
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH v3 28/50] qapi: add 'if' to alternate variant |
Date: |
Mon, 11 Sep 2017 13:06:01 +0200 |
Signed-off-by: Marc-André Lureau <address@hidden>
---
scripts/qapi.py | 9 ++++++++-
tests/qapi-schema/qapi-schema-test.json | 6 +++++-
tests/qapi-schema/qapi-schema-test.out | 8 +++++++-
3 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 2f14edfa1f..19e48bd4d2 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -849,6 +849,9 @@ def check_alternate(expr, info):
check_type(info, "Member '%s' of alternate '%s'" % (key, name),
value,
allow_metas=['built-in', 'union', 'struct', 'enum'])
+ if isinstance(value, dict):
+ check_unknown_keys(info, value, {'type', 'if'})
+ value = value['type']
qtype = find_alternate_member_qtype(value)
if not qtype:
raise QAPISemError(info, "Alternate '%s' member '%s' cannot use "
@@ -1671,7 +1674,11 @@ class QAPISchema(object):
None))
def _make_variant(self, case, typ):
- return QAPISchemaObjectTypeVariant(case, typ)
+ ifcond = None
+ if isinstance(typ, dict):
+ ifcond = typ.get('if')
+ typ = typ['type']
+ return QAPISchemaObjectTypeVariant(case, typ, ifcond)
def _make_simple_variant(self, case, typ, info):
ifcond = None
diff --git a/tests/qapi-schema/qapi-schema-test.json
b/tests/qapi-schema/qapi-schema-test.json
index 895e80a978..f7a62b24d1 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -208,9 +208,13 @@
{ 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' },
'if': 'defined(TEST_IF_UNION)' }
-{ 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStruct'
},
+{ 'alternate': 'TestIfAlternate', 'data':
+ { 'foo': 'int', 'alt_bar': { 'type': 'TestStruct', 'if':
'defined(TEST_IF_ALT_BAR)'} },
'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }
+{ 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlternate'
},
+ 'if': 'defined(TEST_IF_ALT)' }
+
{ 'command': 'TestIfCmd', 'data':
{ 'foo': 'TestIfStruct',
'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_CMD_BAR)' } },
diff --git a/tests/qapi-schema/qapi-schema-test.out
b/tests/qapi-schema/qapi-schema-test.out
index ee009c5626..6887e49c9b 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -67,8 +67,11 @@ enum QType
alternate TestIfAlternate
tag type
case foo: int
- case bar: TestStruct
+ case alt_bar: TestStruct if=defined(TEST_IF_ALT_BAR)
if defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)
+command TestIfAlternateCmd q_obj_TestIfAlternateCmd-arg -> None
+ gen=True success_response=True boxed=False
+ if defined(TEST_IF_ALT)
command TestIfCmd q_obj_TestIfCmd-arg -> None
gen=True success_response=True boxed=False
if defined(TEST_IF_CMD) && defined(TEST_IF_STRUCT)
@@ -232,6 +235,9 @@ object q_obj_EVENT_D-arg
member b: str optional=False
member c: str optional=True
member enum3: EnumOne optional=True
+object q_obj_TestIfAlternateCmd-arg
+ member alt_cmd_arg: TestIfAlternate optional=False
+ if defined(TEST_IF_ALT)
object q_obj_TestIfCmd-arg
member foo: TestIfStruct optional=False
member bar: TestIfEnum optional=False if=defined(TEST_IF_CMD_BAR)
--
2.14.1.146.gd35faa819
- [Qemu-devel] [PATCH v3 19/50] qapi: add 'if' to enum members, (continued)
- [Qemu-devel] [PATCH v3 19/50] qapi: add 'if' to enum members, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 18/50] qapi: change enum visitor to take QAPISchemaMember, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 21/50] qapi: add #if conditions on generated enum members, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 20/50] qapi-event: add 'if' condition to generated enum, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 23/50] qapi: add 'if' to struct members and implicit objects members, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 22/50] tests: add some enum members tests, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 24/50] qapi: add some struct member tests, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 25/50] qapi: add #if conditions to generated struct members, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 27/50] qapi: add #if conditions to generated variants, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 26/50] qapi: add 'if' on union variants, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 28/50] qapi: add 'if' to alternate variant,
Marc-André Lureau <=
- [Qemu-devel] [PATCH v3 30/50] qapi: add #if conditions to generated alternate variants, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 29/50] qapi: add tests for invalid alternate, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 32/50] qapi2texi: add 'If:' section to generated documentation, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 31/50] docs: document schema configuration, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 33/50] qapi2texi: add 'If:' condition to enum values, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 34/50] qapi2texi: add 'If:' condition to struct members, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 35/50] qapi2texi: add condition to variants, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 36/50] qapi: add conditions to VNC type/commands/events on the schema, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 37/50] qapi: add conditions to SPICE type/commands/events on the schema, Marc-André Lureau, 2017/09/11
- [Qemu-devel] [PATCH v3 38/50] qapi: add conditions to REPLICATION type/commands on the schema, Marc-André Lureau, 2017/09/11