qapi: add 'if' to alternate members
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 <marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20181213123724.4866-17-marcandre.lureau@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
a2724280fb
commit
3e270dcacc
@ -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,
|
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'
|
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
|
Example: a conditional 'bar' member
|
||||||
|
|
||||||
|
@ -833,7 +833,7 @@ def check_alternate(expr, info):
|
|||||||
check_name(info, "Member of alternate '%s'" % name, key)
|
check_name(info, "Member of alternate '%s'" % name, key)
|
||||||
check_known_keys(info,
|
check_known_keys(info,
|
||||||
"member '%s' of alternate '%s'" % (key, name),
|
"member '%s' of alternate '%s'" % (key, name),
|
||||||
value, ['type'], [])
|
value, ['type'], ['if'])
|
||||||
typ = value['type']
|
typ = value['type']
|
||||||
|
|
||||||
# Ensure alternates have no type conflicts.
|
# Ensure alternates have no type conflicts.
|
||||||
@ -1754,8 +1754,8 @@ class QAPISchema(object):
|
|||||||
self._make_members(data, info),
|
self._make_members(data, info),
|
||||||
None))
|
None))
|
||||||
|
|
||||||
def _make_variant(self, case, typ):
|
def _make_variant(self, case, typ, ifcond):
|
||||||
return QAPISchemaObjectTypeVariant(case, typ)
|
return QAPISchemaObjectTypeVariant(case, typ, ifcond)
|
||||||
|
|
||||||
def _make_simple_variant(self, case, typ, ifcond, info):
|
def _make_simple_variant(self, case, typ, ifcond, info):
|
||||||
if isinstance(typ, list):
|
if isinstance(typ, list):
|
||||||
@ -1778,7 +1778,7 @@ class QAPISchema(object):
|
|||||||
name, info, doc, ifcond,
|
name, info, doc, ifcond,
|
||||||
'base', self._make_members(base, info))
|
'base', self._make_members(base, info))
|
||||||
if tag_name:
|
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()]
|
for (key, value) in data.items()]
|
||||||
members = []
|
members = []
|
||||||
else:
|
else:
|
||||||
@ -1799,7 +1799,7 @@ class QAPISchema(object):
|
|||||||
name = expr['alternate']
|
name = expr['alternate']
|
||||||
data = expr['data']
|
data = expr['data']
|
||||||
ifcond = expr.get('if')
|
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()]
|
for (key, value) in data.items()]
|
||||||
tag_member = QAPISchemaObjectTypeMember('type', 'QType', False)
|
tag_member = QAPISchemaObjectTypeMember('type', 'QType', False)
|
||||||
self._def_entity(
|
self._def_entity(
|
||||||
|
@ -218,7 +218,9 @@
|
|||||||
{ 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' },
|
{ 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' },
|
||||||
'if': 'defined(TEST_IF_UNION)' }
|
'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)' }
|
'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }
|
||||||
|
|
||||||
{ 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlternate' },
|
{ 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlternate' },
|
||||||
|
@ -300,6 +300,7 @@ alternate TestIfAlternate
|
|||||||
tag type
|
tag type
|
||||||
case foo: int
|
case foo: int
|
||||||
case bar: TestStruct
|
case bar: TestStruct
|
||||||
|
if ['defined(TEST_IF_ALT_BAR)']
|
||||||
if ['defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)']
|
if ['defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)']
|
||||||
object q_obj_TestIfAlternateCmd-arg
|
object q_obj_TestIfAlternateCmd-arg
|
||||||
member alt_cmd_arg: TestIfAlternate optional=False
|
member alt_cmd_arg: TestIfAlternate optional=False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user