[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 17/27] qapi: add 'if' to implicit struct members
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH v6 17/27] qapi: add 'if' to implicit struct members |
Date: |
Fri, 6 Jul 2018 12:57:43 +0200 |
Generated code is not changed by this patch, but with "qapi: add #if
conditions to generated code" patch.
Signed-off-by: Marc-André Lureau <address@hidden>
---
scripts/qapi/common.py | 14 +++++++-------
tests/qapi-schema/qapi-schema-test.json | 12 +++++++++---
tests/qapi-schema/qapi-schema-test.out | 5 +++++
tests/qapi-schema/test-qapi.py | 1 +
4 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index fc68bb472e..9b95f8cfe9 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -714,7 +714,7 @@ def check_type(info, source, value, allow_array=False,
# Todo: allow dictionaries to represent default values of
# an optional argument.
check_known_keys(info, "member '%s' of %s" % (key, source),
- arg, ['type'], [])
+ arg, ['type'], ['if'])
check_type(info, "Member '%s' of %s" % (key, source),
arg['type'], allow_array=True,
allow_metas=['built-in', 'union', 'alternate', 'struct',
@@ -1422,8 +1422,8 @@ class QAPISchemaMember(object):
class QAPISchemaObjectTypeMember(QAPISchemaMember):
- def __init__(self, name, typ, optional):
- QAPISchemaMember.__init__(self, name)
+ def __init__(self, name, typ, optional, ifcond=None):
+ QAPISchemaMember.__init__(self, name, ifcond)
assert isinstance(typ, str)
assert isinstance(optional, bool)
self._type_name = typ
@@ -1744,7 +1744,7 @@ class QAPISchema(object):
name, info, doc, ifcond,
self._make_enum_members(data), prefix))
- def _make_member(self, name, typ, info):
+ def _make_member(self, name, typ, ifcond, info):
optional = False
if name.startswith('*'):
name = name[1:]
@@ -1752,10 +1752,10 @@ class QAPISchema(object):
if isinstance(typ, list):
assert len(typ) == 1
typ = self._make_array_type(typ[0], info)
- return QAPISchemaObjectTypeMember(name, typ, optional)
+ return QAPISchemaObjectTypeMember(name, typ, optional, ifcond)
def _make_members(self, data, info):
- return [self._make_member(key, value['type'], info)
+ return [self._make_member(key, value['type'], value.get('if'), info)
for (key, value) in data.items()]
def _def_struct_type(self, expr, info, doc):
@@ -1776,7 +1776,7 @@ class QAPISchema(object):
typ = self._make_array_type(typ[0], info)
typ = self._make_implicit_object_type(
typ, info, None, self.lookup_type(typ),
- 'wrapper', [self._make_member('data', typ, info)])
+ 'wrapper', [self._make_member('data', typ, None, info)])
return QAPISchemaObjectTypeVariant(case, typ)
def _def_union_type(self, expr, info, doc):
diff --git a/tests/qapi-schema/qapi-schema-test.json
b/tests/qapi-schema/qapi-schema-test.json
index 30f635d484..3bf440aab4 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -199,7 +199,9 @@
# test 'if' condition handling
-{ 'struct': 'TestIfStruct', 'data': { 'foo': 'int' },
+{ 'struct': 'TestIfStruct', 'data':
+ { 'foo': 'int',
+ 'bar': { 'type': 'int', 'if': 'defined(TEST_IF_STRUCT_BAR)'} },
'if': 'defined(TEST_IF_STRUCT)' }
{ 'enum': 'TestIfEnum', 'data':
@@ -212,11 +214,15 @@
{ 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStruct'
},
'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }
-{ 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct', 'bar': 'TestIfEnum'
},
+{ 'command': 'TestIfCmd', 'data':
+ { 'foo': 'TestIfStruct',
+ 'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_CMD_BAR)' } },
'returns': 'UserDefThree',
'if': ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] }
{ 'command': 'TestCmdReturnDefThree', 'returns': 'UserDefThree' }
-{ 'event': 'TestIfEvent', 'data': { 'foo': 'TestIfStruct' },
+{ 'event': 'TestIfEvent', 'data':
+ { 'foo': 'TestIfStruct',
+ 'bar': { 'type': 'TestIfEnum', 'if': 'defined(TEST_IF_EVT_BAR)' } },
'if': 'defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)' }
diff --git a/tests/qapi-schema/qapi-schema-test.out
b/tests/qapi-schema/qapi-schema-test.out
index 1fb33f302c..71b84878c7 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -266,6 +266,8 @@ command __org.qemu_x-command q_obj___org.qemu_x-command-arg
-> __org.qemu_x-Unio
gen=True success_response=True boxed=False oob=False preconfig=False
object TestIfStruct
member foo: int optional=False
+ member bar: int optional=False
+ if ['defined(TEST_IF_STRUCT_BAR)']
if ['defined(TEST_IF_STRUCT)']
enum TestIfEnum
member foo
@@ -290,6 +292,7 @@ alternate TestIfAlternate
object q_obj_TestIfCmd-arg
member foo: TestIfStruct optional=False
member bar: TestIfEnum optional=False
+ if ['defined(TEST_IF_CMD_BAR)']
if ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)']
command TestIfCmd q_obj_TestIfCmd-arg -> UserDefThree
gen=True success_response=True boxed=False oob=False preconfig=False
@@ -298,6 +301,8 @@ command TestCmdReturnDefThree None -> UserDefThree
gen=True success_response=True boxed=False oob=False preconfig=False
object q_obj_TestIfEvent-arg
member foo: TestIfStruct optional=False
+ member bar: TestIfEnum optional=False
+ if ['defined(TEST_IF_EVT_BAR)']
if ['defined(TEST_IF_EVT) && defined(TEST_IF_STRUCT)']
event TestIfEvent q_obj_TestIfEvent-arg
boxed=False
diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py
index b2f4ce6134..69e40d87d2 100644
--- a/tests/qapi-schema/test-qapi.py
+++ b/tests/qapi-schema/test-qapi.py
@@ -39,6 +39,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor):
for m in members:
print(' member %s: %s optional=%s'
% (m.name, m.type.name, m.optional))
+ self._print_if(m.ifcond, 8)
self._print_variants(variants)
self._print_if(ifcond)
--
2.18.0.rc1
- [Qemu-devel] [PATCH v6 08/27] qapi: change enum visitor and gen_enum* to take QAPISchemaMember, (continued)
- [Qemu-devel] [PATCH v6 08/27] qapi: change enum visitor and gen_enum* to take QAPISchemaMember, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 10/27] qapi: factor out checking for keys, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 09/27] tests: print enum type members more like object type members, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 11/27] qapi: improve reporting of unknown or missing keys, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 12/27] qapi: add a dictionnary form with 'name' key for enum members, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 14/27] qapi-event: add 'if' condition to implicit event enum, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 13/27] qapi: add 'if' to enum members, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 15/27] qapi: rename allow_dict to allow_implicit, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 16/27] qapi: add a dictionary form with 'type' key for members, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 18/27] qapi: add an error in case a discriminator is conditionnal, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 17/27] qapi: add 'if' to implicit struct members,
Marc-André Lureau <=
- [Qemu-devel] [PATCH v6 19/27] qapi: add 'if' on union members, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 20/27] qapi: add 'if' to alternate members, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 21/27] qapi: add #if conditions to generated code members, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 23/27] qapi: add 'If:' condition to enum values documentation, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 24/27] qapi: add 'If:' condition to struct members documentation, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 26/27] qapi: add more conditions to SPICE, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 22/27] docs: document schema configuration, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 25/27] qapi: add condition to variants documentation, Marc-André Lureau, 2018/07/06
- [Qemu-devel] [PATCH v6 27/27] qapi: add conditions to REPLICATION type/commands on the schema, Marc-André Lureau, 2018/07/06