mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-02-25 21:26:46 +00:00
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. Backports commit d44f9ac80c43e34b1522cde8829f0ab371f086ca from qemu
This commit is contained in:
parent
994490d197
commit
ff43b7446a
|
@ -1021,28 +1021,18 @@ class QAPISchemaObjectType(QAPISchemaType):
|
||||||
self.members, self.variants)
|
self.members, self.variants)
|
||||||
|
|
||||||
|
|
||||||
class QAPISchemaObjectTypeMember(object):
|
class QAPISchemaMember(object):
|
||||||
role = 'member'
|
role = 'member'
|
||||||
|
|
||||||
def __init__(self, name, typ, optional):
|
def __init__(self, name):
|
||||||
assert isinstance(name, str)
|
assert isinstance(name, str)
|
||||||
assert isinstance(typ, str)
|
|
||||||
assert isinstance(optional, bool)
|
|
||||||
self.name = name
|
self.name = name
|
||||||
self._type_name = typ
|
|
||||||
self.type = None
|
|
||||||
self.optional = optional
|
|
||||||
self.owner = None
|
self.owner = None
|
||||||
|
|
||||||
def set_owner(self, name):
|
def set_owner(self, name):
|
||||||
assert not self.owner
|
assert not self.owner
|
||||||
self.owner = name
|
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):
|
def check_clash(self, info, seen):
|
||||||
cname = c_name(self.name)
|
cname = c_name(self.name)
|
||||||
if cname in seen:
|
if cname in seen:
|
||||||
|
@ -1069,6 +1059,21 @@ class QAPISchemaObjectTypeMember(object):
|
||||||
return "'%s' %s" % (self.name, self._pretty_owner())
|
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):
|
class QAPISchemaObjectTypeVariants(object):
|
||||||
def __init__(self, tag_name, tag_member, variants):
|
def __init__(self, tag_name, tag_member, variants):
|
||||||
# Flat unions pass tag_name but not tag_member.
|
# Flat unions pass tag_name but not tag_member.
|
||||||
|
|
Loading…
Reference in a new issue