[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 26/32] qapi: add 'if' to alternate members
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 26/32] qapi: add 'if' to alternate members |
Date: |
Thu, 13 Dec 2018 19:43:34 +0100 |
From: Marc-André Lureau <address@hidden>
Add 'if' key to alternate members:
{ 'alternate': 'TestIfAlternate', 'data':
{ 'alt': { 'type': 'TestStruct', 'if': 'COND' } } }
Generated code is not changed by this patch but with "qapi: add #if
conditions to generated code".
Signed-off-by: Marc-André Lureau <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Markus Armbruster <address@hidden>
---
docs/devel/qapi-code-gen.txt | 2 +-
scripts/qapi/common.py | 10 +++++-----
tests/qapi-schema/qapi-schema-test.json | 4 +++-
tests/qapi-schema/qapi-schema-test.out | 1 +
4 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
index 0a0e53ede5..43bd853e69 100644
--- a/docs/devel/qapi-code-gen.txt
+++ b/docs/devel/qapi-code-gen.txt
@@ -754,7 +754,7 @@ gets its generated code guarded like this:
Where a member can be defined with a single string value for its type,
it is also possible to supply a dictionary instead with both 'type'
-and 'if' keys. (TODO: alternate)
+and 'if' keys.
Example: a conditional 'bar' member
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 44fe8868ed..17707b6de7 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -833,7 +833,7 @@ def check_alternate(expr, info):
check_name(info, "Member of alternate '%s'" % name, key)
check_known_keys(info,
"member '%s' of alternate '%s'" % (key, name),
- value, ['type'], [])
+ value, ['type'], ['if'])
typ = value['type']
# Ensure alternates have no type conflicts.
@@ -1754,8 +1754,8 @@ class QAPISchema(object):
self._make_members(data, info),
None))
- def _make_variant(self, case, typ):
- return QAPISchemaObjectTypeVariant(case, typ)
+ def _make_variant(self, case, typ, ifcond):
+ return QAPISchemaObjectTypeVariant(case, typ, ifcond)
def _make_simple_variant(self, case, typ, ifcond, info):
if isinstance(typ, list):
@@ -1778,7 +1778,7 @@ class QAPISchema(object):
name, info, doc, ifcond,
'base', self._make_members(base, info))
if tag_name:
- variants = [self._make_variant(key, value['type'])
+ variants = [self._make_variant(key, value['type'], value.get('if'))
for (key, value) in data.items()]
members = []
else:
@@ -1799,7 +1799,7 @@ class QAPISchema(object):
name = expr['alternate']
data = expr['data']
ifcond = expr.get('if')
- variants = [self._make_variant(key, value['type'])
+ variants = [self._make_variant(key, value['type'], value.get('if'))
for (key, value) in data.items()]
tag_member = QAPISchemaObjectTypeMember('type', 'QType', False)
self._def_entity(
diff --git a/tests/qapi-schema/qapi-schema-test.json
b/tests/qapi-schema/qapi-schema-test.json
index a33eff8f86..cb0857df52 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -218,7 +218,9 @@
{ 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' },
'if': 'defined(TEST_IF_UNION)' }
-{ 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStruct'
},
+{ 'alternate': 'TestIfAlternate', 'data':
+ { 'foo': 'int',
+ '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'
},
diff --git a/tests/qapi-schema/qapi-schema-test.out
b/tests/qapi-schema/qapi-schema-test.out
index f4c11f1e6a..9464101d26 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -300,6 +300,7 @@ alternate TestIfAlternate
tag type
case foo: int
case bar: TestStruct
+ if ['defined(TEST_IF_ALT_BAR)']
if ['defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)']
object q_obj_TestIfAlternateCmd-arg
member alt_cmd_arg: TestIfAlternate optional=False
--
2.17.2
- [Qemu-devel] [PULL 21/32] qapi: add 'if' to enum members, (continued)
[Qemu-devel] [PULL 26/32] qapi: add 'if' to alternate members,
Markus Armbruster <=
[Qemu-devel] [PULL 20/32] qapi: add a dictionary form with 'name' key for enum members, Markus Armbruster, 2018/12/13
[Qemu-devel] [PULL 25/32] qapi: add 'if' to union members, Markus Armbruster, 2018/12/13
[Qemu-devel] [PULL 11/32] json: Fix to reject duplicate object member names, Markus Armbruster, 2018/12/13
[Qemu-devel] [PULL 29/32] qapi: add 'If:' condition to struct members documentation, Markus Armbruster, 2018/12/13
[Qemu-devel] [PULL 16/32] qapi: change enum visitor and gen_enum* to take QAPISchemaMember, Markus Armbruster, 2018/12/13
[Qemu-devel] [PULL 18/32] qapi: factor out checking for keys, Markus Armbruster, 2018/12/13
[Qemu-devel] [PULL 24/32] qapi: Add 'if' to implicit struct members, Markus Armbruster, 2018/12/13
[Qemu-devel] [PULL 22/32] qapi-events: add 'if' condition to implicit event enum, Markus Armbruster, 2018/12/13
[Qemu-devel] [PULL 23/32] qapi: add a dictionary form for TYPE, Markus Armbruster, 2018/12/13
Re: [Qemu-devel] [PULL 00/32] QAPI patches for 2018-12-13, Markus Armbruster, 2018/12/14