mirror of https://gitee.com/openkylin/qemu.git
qapi: change enum visitor and gen_enum* to take QAPISchemaMember
This will allow to add and access more properties associated with enum values/members, like the associated 'if' condition. We may want to have a specialized type QAPISchemaEnumMember, for now this will do. Modify gen_enum() and gen_enum_lookup() for the same reason. Suggested-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20181213123724.4866-3-marcandre.lureau@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
9c2f56e9f9
commit
1962bd39d5
|
@ -1063,7 +1063,7 @@ def visit_include(self, fname, info):
|
|||
def visit_builtin_type(self, name, info, json_type):
|
||||
pass
|
||||
|
||||
def visit_enum_type(self, name, info, ifcond, values, prefix):
|
||||
def visit_enum_type(self, name, info, ifcond, members, prefix):
|
||||
pass
|
||||
|
||||
def visit_array_type(self, name, info, ifcond, element_type):
|
||||
|
@ -1193,7 +1193,7 @@ def json_type(self):
|
|||
|
||||
def visit(self, visitor):
|
||||
visitor.visit_enum_type(self.name, self.info, self.ifcond,
|
||||
self.member_names(), self.prefix)
|
||||
self.members, self.prefix)
|
||||
|
||||
|
||||
class QAPISchemaArrayType(QAPISchemaType):
|
||||
|
@ -2012,19 +2012,19 @@ def _wrap_ifcond(ifcond, before, after):
|
|||
return out
|
||||
|
||||
|
||||
def gen_enum_lookup(name, values, prefix=None):
|
||||
def gen_enum_lookup(name, members, prefix=None):
|
||||
ret = mcgen('''
|
||||
|
||||
const QEnumLookup %(c_name)s_lookup = {
|
||||
.array = (const char *const[]) {
|
||||
''',
|
||||
c_name=c_name(name))
|
||||
for value in values:
|
||||
index = c_enum_const(name, value, prefix)
|
||||
for m in members:
|
||||
index = c_enum_const(name, m.name, prefix)
|
||||
ret += mcgen('''
|
||||
[%(index)s] = "%(value)s",
|
||||
[%(index)s] = "%(name)s",
|
||||
''',
|
||||
index=index, value=value)
|
||||
index=index, name=m.name)
|
||||
|
||||
ret += mcgen('''
|
||||
},
|
||||
|
@ -2035,9 +2035,9 @@ def gen_enum_lookup(name, values, prefix=None):
|
|||
return ret
|
||||
|
||||
|
||||
def gen_enum(name, values, prefix=None):
|
||||
def gen_enum(name, members, prefix=None):
|
||||
# append automatically generated _MAX value
|
||||
enum_values = values + ['_MAX']
|
||||
enum_members = members + [QAPISchemaMember('_MAX')]
|
||||
|
||||
ret = mcgen('''
|
||||
|
||||
|
@ -2045,11 +2045,11 @@ def gen_enum(name, values, prefix=None):
|
|||
''',
|
||||
c_name=c_name(name))
|
||||
|
||||
for value in enum_values:
|
||||
for m in enum_members:
|
||||
ret += mcgen('''
|
||||
%(c_enum)s,
|
||||
''',
|
||||
c_enum=c_enum_const(name, value, prefix))
|
||||
c_enum=c_enum_const(name, m.name, prefix))
|
||||
|
||||
ret += mcgen('''
|
||||
} %(c_name)s;
|
||||
|
|
|
@ -206,7 +206,7 @@ def __init__(self, prefix):
|
|||
def write(self, output_dir):
|
||||
self._gen.write(output_dir, self._prefix + 'qapi-doc.texi')
|
||||
|
||||
def visit_enum_type(self, name, info, ifcond, values, prefix):
|
||||
def visit_enum_type(self, name, info, ifcond, members, prefix):
|
||||
doc = self.cur_doc
|
||||
self._gen.add(TYPE_FMT(type='Enum',
|
||||
name=doc.symbol,
|
||||
|
|
|
@ -143,8 +143,8 @@ def __init__(self, prefix):
|
|||
QAPISchemaModularCVisitor.__init__(
|
||||
self, prefix, 'qapi-events',
|
||||
' * Schema-defined QAPI/QMP events', __doc__)
|
||||
self._enum_name = c_name(prefix + 'QAPIEvent', protect=False)
|
||||
self._event_names = []
|
||||
self._event_enum_name = c_name(prefix + 'QAPIEvent', protect=False)
|
||||
self._event_enum_members = []
|
||||
|
||||
def _begin_module(self, name):
|
||||
types = self._module_basename('qapi-types', name)
|
||||
|
@ -170,15 +170,16 @@ def _begin_module(self, name):
|
|||
|
||||
def visit_end(self):
|
||||
(genc, genh) = self._module[self._main_module]
|
||||
genh.add(gen_enum(self._enum_name, self._event_names))
|
||||
genc.add(gen_enum_lookup(self._enum_name, self._event_names))
|
||||
genh.add(gen_enum(self._event_enum_name, self._event_enum_members))
|
||||
genc.add(gen_enum_lookup(self._event_enum_name,
|
||||
self._event_enum_members))
|
||||
|
||||
def visit_event(self, name, info, ifcond, arg_type, boxed):
|
||||
with ifcontext(ifcond, self._genh, self._genc):
|
||||
self._genh.add(gen_event_send_decl(name, arg_type, boxed))
|
||||
self._genc.add(gen_event_send(name, arg_type, boxed,
|
||||
self._enum_name))
|
||||
self._event_names.append(name)
|
||||
self._event_enum_name))
|
||||
self._event_enum_members.append(QAPISchemaMember(name))
|
||||
|
||||
|
||||
def gen_events(schema, output_dir, prefix):
|
||||
|
|
|
@ -174,8 +174,9 @@ def _gen_variant(self, variant):
|
|||
def visit_builtin_type(self, name, info, json_type):
|
||||
self._gen_qlit(name, 'builtin', {'json-type': json_type}, [])
|
||||
|
||||
def visit_enum_type(self, name, info, ifcond, values, prefix):
|
||||
self._gen_qlit(name, 'enum', {'values': values}, ifcond)
|
||||
def visit_enum_type(self, name, info, ifcond, members, prefix):
|
||||
self._gen_qlit(name, 'enum',
|
||||
{'values': [m.name for m in members]}, ifcond)
|
||||
|
||||
def visit_array_type(self, name, info, ifcond, element_type):
|
||||
element = self._use_type(element_type)
|
||||
|
|
|
@ -212,10 +212,10 @@ def _gen_type_cleanup(self, name):
|
|||
self._genh.add(gen_type_cleanup_decl(name))
|
||||
self._genc.add(gen_type_cleanup(name))
|
||||
|
||||
def visit_enum_type(self, name, info, ifcond, values, prefix):
|
||||
def visit_enum_type(self, name, info, ifcond, members, prefix):
|
||||
with ifcontext(ifcond, self._genh, self._genc):
|
||||
self._genh.preamble_add(gen_enum(name, values, prefix))
|
||||
self._genc.add(gen_enum_lookup(name, values, prefix))
|
||||
self._genh.preamble_add(gen_enum(name, members, prefix))
|
||||
self._genc.add(gen_enum_lookup(name, members, prefix))
|
||||
|
||||
def visit_array_type(self, name, info, ifcond, element_type):
|
||||
with ifcontext(ifcond, self._genh, self._genc):
|
||||
|
|
|
@ -310,7 +310,7 @@ def _begin_module(self, name):
|
|||
''',
|
||||
types=types))
|
||||
|
||||
def visit_enum_type(self, name, info, ifcond, values, prefix):
|
||||
def visit_enum_type(self, name, info, ifcond, members, prefix):
|
||||
with ifcontext(ifcond, self._genh, self._genc):
|
||||
self._genh.add(gen_visit_decl(name, scalar=True))
|
||||
self._genc.add(gen_visit_enum(name))
|
||||
|
|
|
@ -23,8 +23,8 @@ def visit_module(self, name):
|
|||
def visit_include(self, name, info):
|
||||
print('include %s' % name)
|
||||
|
||||
def visit_enum_type(self, name, info, ifcond, values, prefix):
|
||||
print('enum %s %s' % (name, values))
|
||||
def visit_enum_type(self, name, info, ifcond, members, prefix):
|
||||
print('enum %s %s' % (name, [m.name for m in members]))
|
||||
if prefix:
|
||||
print(' prefix %s' % prefix)
|
||||
self._print_if(ifcond)
|
||||
|
|
Loading…
Reference in New Issue