summaryrefslogtreecommitdiffstats
path: root/scripts/qapi.py
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2015-12-01 22:20:54 -0700
committerTimothy Pearson <tpearson@raptorengineering.com>2019-11-29 19:28:19 -0600
commite55a945fff9461c4336ca1302a0f307916131265 (patch)
treed7b436f9fab687620fbaaadbf3a84c075eb588eb /scripts/qapi.py
parenta1f6056b9b3c027166263ca9f66b279bce430ca5 (diff)
downloadhqemu-e55a945fff9461c4336ca1302a0f307916131265.zip
hqemu-e55a945fff9461c4336ca1302a0f307916131265.tar.gz
qapi: Prepare new QAPISchemaMember base class
We want to share some clash detection code between enum values and object type members. To assist with that, split off part of QAPISchemaObjectTypeMember into a new base class QAPISchemaMember that tracks name, owner, and common clash detection code; while the former keeps the additional fields for type and optional flag. Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1449033659-25497-11-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'scripts/qapi.py')
-rw-r--r--scripts/qapi.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 58ecdf2..168463a 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -1018,28 +1018,18 @@ class QAPISchemaObjectType(QAPISchemaType):
self.members, self.variants)
-class QAPISchemaObjectTypeMember(object):
+class QAPISchemaMember(object):
role = 'member'
- def __init__(self, name, typ, optional):
+ def __init__(self, name):
assert isinstance(name, str)
- assert isinstance(typ, str)
- assert isinstance(optional, bool)
self.name = name
- self._type_name = typ
- self.type = None
- self.optional = optional
self.owner = None
def set_owner(self, name):
assert not self.owner
self.owner = name
- def check(self, schema):
- assert self.owner
- self.type = schema.lookup_type(self._type_name)
- assert self.type
-
def check_clash(self, info, seen):
cname = c_name(self.name)
if cname in seen:
@@ -1066,6 +1056,21 @@ class QAPISchemaObjectTypeMember(object):
return "'%s' %s" % (self.name, self._pretty_owner())
+class QAPISchemaObjectTypeMember(QAPISchemaMember):
+ def __init__(self, name, typ, optional):
+ QAPISchemaMember.__init__(self, name)
+ assert isinstance(typ, str)
+ assert isinstance(optional, bool)
+ self._type_name = typ
+ self.type = None
+ self.optional = optional
+
+ def check(self, schema):
+ assert self.owner
+ self.type = schema.lookup_type(self._type_name)
+ assert self.type
+
+
class QAPISchemaObjectTypeVariants(object):
def __init__(self, tag_name, tag_member, variants):
# Flat unions pass tag_name but not tag_member.
OpenPOWER on IntegriCloud