aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2018-12-13 16:37:11 +0400
committerMarkus Armbruster <armbru@redhat.com>2018-12-13 19:20:11 +0100
commit6cc32b0e14b3f91e15a9511d90b222abc1df391d (patch)
tree3b8cbbcd19be7c206ae11dd861328ce58dfd6034 /scripts/qapi
parentea738b21685814dc54352858afabc2ff33ade53e (diff)
downloadqemu-6cc32b0e14b3f91e15a9511d90b222abc1df391d.zip
qemu-6cc32b0e14b3f91e15a9511d90b222abc1df391d.tar.gz
qemu-6cc32b0e14b3f91e15a9511d90b222abc1df391d.tar.bz2
qapi: add 'if' to enum members
QAPISchemaMember gains .ifcond for enum members: inherited classes, such as QAPISchemaObjectTypeMember, will thus have an ifcond member after this (those different types will also use the .ifcond to store the condition and generate conditional code in the following patches). The generated code remains unconditional for now. Later patches generate the conditionals. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20181213123724.4866-10-marcandre.lureau@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'scripts/qapi')
-rw-r--r--scripts/qapi/common.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index b1cf33a..a609ffc 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -871,7 +871,8 @@ def check_enum(expr, info):
for member in members:
source = "dictionary member of enum '%s'" % name
- check_known_keys(info, source, member, ['name'], [])
+ check_known_keys(info, source, member, ['name'], ['if'])
+ check_if(member, info)
check_name(info, "Member of enum '%s'" % name, member['name'],
enum_member=True)
@@ -1345,9 +1346,10 @@ class QAPISchemaObjectType(QAPISchemaType):
class QAPISchemaMember(object):
role = 'member'
- def __init__(self, name):
+ def __init__(self, name, ifcond=None):
assert isinstance(name, str)
self.name = name
+ self.ifcond = listify_cond(ifcond)
self.owner = None
def set_owner(self, name):
@@ -1656,7 +1658,7 @@ class QAPISchema(object):
qtype_values, 'QTYPE'))
def _make_enum_members(self, values):
- return [QAPISchemaMember(v['name']) for v in values]
+ return [QAPISchemaMember(v['name'], v.get('if')) for v in values]
def _make_implicit_enum_type(self, name, info, ifcond, values):
# See also QAPISchemaObjectTypeMember._pretty_owner()