mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-01-22 19:51:10 +00:00
qapi: Simplify QAPISchemaObjectTypeMember.check()
QAPISchemaObjectTypeMember.check() currently does four things: 1. Compute self.type 2. Accumulate members in all_members Only one caller cares: QAPISchemaObjectType.check() uses it to compute self.members. The other callers pass a throw-away accumulator. 3. Accumulate a map from names to members in seen Only one caller cares: QAPISchemaObjectType.check() uses it to compute its local variable seen, for self.variants.check(), which uses it to compute self.variants.tag_member from self.variants.tag_name. The other callers pass a throw-away accumulator. 4. Check for collisions This piggybacks on 3: before adding a new entry, we assert it's new. Only one caller cares: QAPISchemaObjectType.check() uses it to assert non-variant members don't clash. Simplify QAPISchemaObjectType.check(): move 2.-4. to QAPISchemaObjectType.check(), and drop parameters all_members and seen. Backports commit e564e2dd5963a75f32bbb90ac8181ba9dca2f1aa from qemu
This commit is contained in:
parent
85ef080183
commit
f246800df6
|
@ -990,7 +990,10 @@ class QAPISchemaObjectType(QAPISchemaType):
|
|||
assert c_name(m.name) not in seen
|
||||
seen[m.name] = m
|
||||
for m in self.local_members:
|
||||
m.check(schema, members, seen)
|
||||
m.check(schema)
|
||||
assert m.name not in seen
|
||||
seen[m.name] = m
|
||||
members.append(m)
|
||||
if self.variants:
|
||||
self.variants.check(schema, members, seen)
|
||||
self.members = members
|
||||
|
@ -1027,12 +1030,9 @@ class QAPISchemaObjectTypeMember(object):
|
|||
self.type = None
|
||||
self.optional = optional
|
||||
|
||||
def check(self, schema, all_members, seen):
|
||||
assert self.name not in seen
|
||||
def check(self, schema):
|
||||
self.type = schema.lookup_type(self._type_name)
|
||||
assert self.type
|
||||
all_members.append(self)
|
||||
seen[self.name] = self
|
||||
|
||||
|
||||
class QAPISchemaObjectTypeVariants(object):
|
||||
|
@ -1064,7 +1064,7 @@ class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember):
|
|||
QAPISchemaObjectTypeMember.__init__(self, name, typ, False)
|
||||
|
||||
def check(self, schema, tag_type, seen):
|
||||
QAPISchemaObjectTypeMember.check(self, schema, [], seen)
|
||||
QAPISchemaObjectTypeMember.check(self, schema)
|
||||
assert self.name in tag_type.values
|
||||
|
||||
# This function exists to support ugly simple union special cases
|
||||
|
@ -1086,7 +1086,7 @@ class QAPISchemaAlternateType(QAPISchemaType):
|
|||
self.variants = variants
|
||||
|
||||
def check(self, schema):
|
||||
self.variants.tag_member.check(schema, [], {})
|
||||
self.variants.tag_member.check(schema)
|
||||
self.variants.check(schema, [], {})
|
||||
|
||||
def json_type(self):
|
||||
|
|
Loading…
Reference in a new issue