summaryrefslogtreecommitdiffstats
path: root/scripts/qapi/visit.py
diff options
context:
space:
mode:
authorJohn Snow2020-10-09 18:15:56 +0200
committerMarkus Armbruster2020-10-10 11:37:49 +0200
commit554df4f33f2076f973b4ae6bc55b5160f513634f (patch)
tree6193b53ca65299f1536f038af10ecec7c9de0725 /scripts/qapi/visit.py
parentqapi/types.py: remove one-letter variables (diff)
downloadqemu-554df4f33f2076f973b4ae6bc55b5160f513634f.tar.gz
qemu-554df4f33f2076f973b4ae6bc55b5160f513634f.tar.xz
qemu-554df4f33f2076f973b4ae6bc55b5160f513634f.zip
qapi/visit.py: assert tag_member contains a QAPISchemaEnumType
This is true by design, but not presently able to be expressed in the type system. An assertion helps mypy understand our constraints. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20201009161558.107041-35-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'scripts/qapi/visit.py')
-rw-r--r--scripts/qapi/visit.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py
index 708f72c4a1..e00f2a09d7 100644
--- a/scripts/qapi/visit.py
+++ b/scripts/qapi/visit.py
@@ -22,7 +22,7 @@ from .common import (
mcgen,
)
from .gen import QAPISchemaModularCVisitor, ifcontext
-from .schema import QAPISchemaObjectType
+from .schema import QAPISchemaEnumType, QAPISchemaObjectType
def gen_visit_decl(name, scalar=False):
@@ -84,15 +84,17 @@ bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **errp)
ret += gen_endif(memb.ifcond)
if variants:
+ tag_member = variants.tag_member
+ assert isinstance(tag_member.type, QAPISchemaEnumType)
+
ret += mcgen('''
switch (obj->%(c_name)s) {
''',
- c_name=c_name(variants.tag_member.name))
+ c_name=c_name(tag_member.name))
for var in variants.variants:
- case_str = c_enum_const(variants.tag_member.type.name,
- var.name,
- variants.tag_member.type.prefix)
+ case_str = c_enum_const(tag_member.type.name, var.name,
+ tag_member.type.prefix)
ret += gen_if(var.ifcond)
if var.type.name == 'q_empty':
# valid variant and nothing to do