[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH for-4.0 v7 19/27] qapi: add 'if' to alternate member
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH for-4.0 v7 19/27] qapi: add 'if' to alternate members |
Date: |
Sat, 8 Dec 2018 15:15:58 +0400 |
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>
---
scripts/qapi/common.py | 10 +++++-----
docs/devel/qapi-code-gen.txt | 2 +-
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/scripts/qapi/common.py b/scripts/qapi/common.py
index 44020779dd..a70d6dec3b 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -857,7 +857,7 @@ def check_alternate(expr, info):
if isinstance(value, dict):
check_known_keys(info,
"member '%s' of alternate '%s'" % (key, name),
- value, ['type'], [])
+ value, ['type'], ['if'])
typ = value['type']
else:
typ = value
@@ -1784,8 +1784,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):
@@ -1808,7 +1808,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:
@@ -1829,7 +1829,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/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
index 6f2457a2e0..5ea62cb111 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/tests/qapi-schema/qapi-schema-test.json
b/tests/qapi-schema/qapi-schema-test.json
index 0d28475f4c..d58cc49028 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': 'TestIfCmd', 'data':
diff --git a/tests/qapi-schema/qapi-schema-test.out
b/tests/qapi-schema/qapi-schema-test.out
index aedc668aa4..59d7ed17a1 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_TestIfCmd-arg
member foo: TestIfStruct optional=False
--
2.20.0.rc1
- Re: [Qemu-devel] [PATCH for-4.0 v7 15/27] qapi: add an error in case a discriminator is conditional, (continued)
- [Qemu-devel] [PATCH for-4.0 v7 16/27] qapi: add 'if' to union members, Marc-André Lureau, 2018/12/08
- [Qemu-devel] [PATCH for-4.0 v7 17/27] qapi: simplify make_enum_members(), Marc-André Lureau, 2018/12/08
- [Qemu-devel] [PATCH for-4.0 v7 18/27] tests/qapi: add command with condition on union argument, Marc-André Lureau, 2018/12/08
- [Qemu-devel] [PATCH for-4.0 v7 19/27] qapi: add 'if' to alternate members,
Marc-André Lureau <=
- [Qemu-devel] [PATCH for-4.0 v7 20/27] tests/qapi: add command with condition on alternate argument, Marc-André Lureau, 2018/12/08
- [Qemu-devel] [PATCH for-4.0 v7 21/27] qapi: add #if conditions to generated code members, Marc-André Lureau, 2018/12/08
- [Qemu-devel] [PATCH for-4.0 v7 22/27] qapi: add 'If:' condition to enum values documentation, Marc-André Lureau, 2018/12/08
- [Qemu-devel] [PATCH for-4.0 v7 23/27] qapi: add 'If:' condition to struct members documentation, Marc-André Lureau, 2018/12/08