aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2019-09-27 15:46:14 +0200
committerMarkus Armbruster <armbru@redhat.com>2019-09-28 17:17:18 +0200
commit0ca7b11709b8e81e5e8f28245b5b594b597b062b (patch)
tree8b9ecfbf0ee8512f84d59bbc40dd88191d576d11 /scripts/qapi
parent2546be1c85913da46fe4fb15fefdcbfad026a7df (diff)
downloadqemu-0ca7b11709b8e81e5e8f28245b5b594b597b062b.zip
qemu-0ca7b11709b8e81e5e8f28245b5b594b597b062b.tar.gz
qemu-0ca7b11709b8e81e5e8f28245b5b594b597b062b.tar.bz2
qapi: Tighten QAPISchemaFOO.check() assertions
When we introduced the QAPISchema intermediate representation (commit ac88219a6c7), we took a shortcut: we left check_exprs() & friends alone instead of moving semantic checks into the QAPISchemaFOO.check(). check_exprs() still checks and reports errors, and the .check() assert check_exprs() did the job. There are a few gaps, though. QAPISchemaArrayType.check() neglects to assert the element type is not an array. Add the assertion. QAPISchemaObjectTypeVariants.check() neglects to assert the tag member is not optional. Add the assertion. It neglects to assert the tag member is not conditional. Add the assertion. It neglects to assert we actually have variants. Add the assertion. It asserts the variants are object types, but neglects to assert they don't have variants. Tighten the assertion. QAPISchemaObjectTypeVariants.check_clash() has the same issue. However, it can run only after .check(). Delete the assertion instead of tightening it. QAPISchemaAlternateType.check() neglects to assert the branch types don't conflict. Fixing that isn't trivial, so add just a TODO comment for now. It'll be resolved later in this series. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20190927134639.4284-2-armbru@redhat.com>
Diffstat (limited to 'scripts/qapi')
-rw-r--r--scripts/qapi/common.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index b00caac..155b87b 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -1362,6 +1362,7 @@ class QAPISchemaArrayType(QAPISchemaType):
QAPISchemaType.check(self, schema)
self.element_type = schema.lookup_type(self._element_type_name)
assert self.element_type
+ assert not isinstance(self.element_type, QAPISchemaArrayType)
@property
def ifcond(self):
@@ -1606,6 +1607,8 @@ class QAPISchemaObjectTypeVariants(object):
self.tag_member = seen[c_name(self._tag_name)]
assert self._tag_name == self.tag_member.name
assert isinstance(self.tag_member.type, QAPISchemaEnumType)
+ assert not self.tag_member.optional
+ assert self.tag_member.ifcond == []
if self._tag_name: # flat union
# branches that are not explicitly covered get an empty type
cases = set([v.name for v in self.variants])
@@ -1615,20 +1618,21 @@ class QAPISchemaObjectTypeVariants(object):
m.ifcond)
v.set_owner(self.tag_member.owner)
self.variants.append(v)
+ assert self.variants
for v in self.variants:
v.check(schema)
# Union names must match enum values; alternate names are
# checked separately. Use 'seen' to tell the two apart.
if seen:
assert v.name in self.tag_member.type.member_names()
- assert isinstance(v.type, QAPISchemaObjectType)
+ assert (isinstance(v.type, QAPISchemaObjectType)
+ and not v.type.variants)
v.type.check(schema)
def check_clash(self, info, seen):
for v in self.variants:
# Reset seen map for each variant, since qapi names from one
# branch do not affect another branch
- assert isinstance(v.type, QAPISchemaObjectType)
v.type.check_clash(info, dict(seen))
@@ -1659,6 +1663,7 @@ class QAPISchemaAlternateType(QAPISchemaType):
seen = {}
for v in self.variants.variants:
v.check_clash(self.info, seen)
+ # TODO check conflicting qtypes
if self.doc:
self.doc.connect_member(v)
if self.doc: