Avoid the ugly flat union / simple union / alternate conditional by
doing just the essential work here, namely setting self.tag_member.
Move the rest to callers.

Signed-off-by: Markus Armbruster <arm...@redhat.com>
---
 scripts/qapi.py | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/scripts/qapi.py b/scripts/qapi.py
index f0cbb7e..86341e6 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -988,9 +988,10 @@ class QAPISchemaObjectType(QAPISchemaType):
         for m in self.local_members:
             m.check(schema)
             m.check_clash(seen)
+        self.members = seen.values()
         if self.variants:
             self.variants.check(schema, seen)
-        self.members = seen.values()
+            assert self.variants.tag_member in self.members
 
     def is_implicit(self):
         # See QAPISchema._make_implicit_object_type()
@@ -1050,12 +1051,8 @@ class QAPISchemaObjectTypeVariants(object):
         self.variants = variants
 
     def check(self, schema, seen):
-        if self.tag_name:    # flat union
+        if not self.tag_member: # flat union
             self.tag_member = seen[self.tag_name]
-        elif seen:           # simple union
-            assert self.tag_member in seen.itervalues()
-        else:                # alternate
-            self.tag_member.check(schema)
         assert isinstance(self.tag_member.type, QAPISchemaEnumType)
         for v in self.variants:
             v.check(schema, self.tag_member.type)
@@ -1088,6 +1085,7 @@ class QAPISchemaAlternateType(QAPISchemaType):
         self.variants = variants
 
     def check(self, schema):
+        self.variants.tag_member.check(schema)
         self.variants.check(schema, {})
 
     def json_type(self):
-- 
2.4.3


Reply via email to