qapi-types: add #if conditions to types & visitors
Types & visitors are coupled and must be handled together to avoid temporary build regression. Wrap generated types/visitor code with #if/#endif using the context helpers. Derived from a patch by Marc-André. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20180703155648.11933-12-marcandre.lureau@redhat.com>
This commit is contained in:
parent
c3cd6aa020
commit
9f88c66211
@ -55,7 +55,7 @@ def gen_struct_members(members):
|
||||
return ret
|
||||
|
||||
|
||||
def gen_object(name, base, members, variants):
|
||||
def gen_object(name, ifcond, base, members, variants):
|
||||
if name in objects_seen:
|
||||
return ''
|
||||
objects_seen.add(name)
|
||||
@ -64,11 +64,14 @@ def gen_object(name, base, members, variants):
|
||||
if variants:
|
||||
for v in variants.variants:
|
||||
if isinstance(v.type, QAPISchemaObjectType):
|
||||
ret += gen_object(v.type.name, v.type.base,
|
||||
ret += gen_object(v.type.name, v.type.ifcond, v.type.base,
|
||||
v.type.local_members, v.type.variants)
|
||||
|
||||
ret += mcgen('''
|
||||
|
||||
''')
|
||||
ret += gen_if(ifcond)
|
||||
ret += mcgen('''
|
||||
struct %(c_name)s {
|
||||
''',
|
||||
c_name=c_name(name))
|
||||
@ -101,6 +104,7 @@ struct %(c_name)s {
|
||||
ret += mcgen('''
|
||||
};
|
||||
''')
|
||||
ret += gen_endif(ifcond)
|
||||
|
||||
return ret
|
||||
|
||||
@ -209,33 +213,39 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor):
|
||||
self._genc.add(gen_type_cleanup(name))
|
||||
|
||||
def visit_enum_type(self, name, info, ifcond, values, prefix):
|
||||
self._genh.preamble_add(gen_enum(name, values, prefix))
|
||||
self._genc.add(gen_enum_lookup(name, values, 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))
|
||||
|
||||
def visit_array_type(self, name, info, ifcond, element_type):
|
||||
self._genh.preamble_add(gen_fwd_object_or_array(name))
|
||||
self._genh.add(gen_array(name, element_type))
|
||||
self._gen_type_cleanup(name)
|
||||
with ifcontext(ifcond, self._genh, self._genc):
|
||||
self._genh.preamble_add(gen_fwd_object_or_array(name))
|
||||
self._genh.add(gen_array(name, element_type))
|
||||
self._gen_type_cleanup(name)
|
||||
|
||||
def visit_object_type(self, name, info, ifcond, base, members, variants):
|
||||
# Nothing to do for the special empty builtin
|
||||
if name == 'q_empty':
|
||||
return
|
||||
self._genh.preamble_add(gen_fwd_object_or_array(name))
|
||||
self._genh.add(gen_object(name, base, members, variants))
|
||||
if base and not base.is_implicit():
|
||||
self._genh.add(gen_upcast(name, base))
|
||||
# TODO Worth changing the visitor signature, so we could
|
||||
# directly use rather than repeat type.is_implicit()?
|
||||
if not name.startswith('q_'):
|
||||
# implicit types won't be directly allocated/freed
|
||||
self._gen_type_cleanup(name)
|
||||
with ifcontext(ifcond, self._genh):
|
||||
self._genh.preamble_add(gen_fwd_object_or_array(name))
|
||||
self._genh.add(gen_object(name, ifcond, base, members, variants))
|
||||
with ifcontext(ifcond, self._genh, self._genc):
|
||||
if base and not base.is_implicit():
|
||||
self._genh.add(gen_upcast(name, base))
|
||||
# TODO Worth changing the visitor signature, so we could
|
||||
# directly use rather than repeat type.is_implicit()?
|
||||
if not name.startswith('q_'):
|
||||
# implicit types won't be directly allocated/freed
|
||||
self._gen_type_cleanup(name)
|
||||
|
||||
def visit_alternate_type(self, name, info, ifcond, variants):
|
||||
self._genh.preamble_add(gen_fwd_object_or_array(name))
|
||||
self._genh.add(gen_object(name, None,
|
||||
with ifcontext(ifcond, self._genh):
|
||||
self._genh.preamble_add(gen_fwd_object_or_array(name))
|
||||
self._genh.add(gen_object(name, ifcond, None,
|
||||
[variants.tag_member], variants))
|
||||
self._gen_type_cleanup(name)
|
||||
with ifcontext(ifcond, self._genh, self._genc):
|
||||
self._gen_type_cleanup(name)
|
||||
|
||||
|
||||
def gen_types(schema, output_dir, prefix, opt_builtins):
|
||||
|
@ -311,29 +311,34 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor):
|
||||
types=types))
|
||||
|
||||
def visit_enum_type(self, name, info, ifcond, values, prefix):
|
||||
self._genh.add(gen_visit_decl(name, scalar=True))
|
||||
self._genc.add(gen_visit_enum(name))
|
||||
with ifcontext(ifcond, self._genh, self._genc):
|
||||
self._genh.add(gen_visit_decl(name, scalar=True))
|
||||
self._genc.add(gen_visit_enum(name))
|
||||
|
||||
def visit_array_type(self, name, info, ifcond, element_type):
|
||||
self._genh.add(gen_visit_decl(name))
|
||||
self._genc.add(gen_visit_list(name, element_type))
|
||||
with ifcontext(ifcond, self._genh, self._genc):
|
||||
self._genh.add(gen_visit_decl(name))
|
||||
self._genc.add(gen_visit_list(name, element_type))
|
||||
|
||||
def visit_object_type(self, name, info, ifcond, base, members, variants):
|
||||
# Nothing to do for the special empty builtin
|
||||
if name == 'q_empty':
|
||||
return
|
||||
self._genh.add(gen_visit_members_decl(name))
|
||||
self._genc.add(gen_visit_object_members(name, base, members, variants))
|
||||
# TODO Worth changing the visitor signature, so we could
|
||||
# directly use rather than repeat type.is_implicit()?
|
||||
if not name.startswith('q_'):
|
||||
# only explicit types need an allocating visit
|
||||
self._genh.add(gen_visit_decl(name))
|
||||
self._genc.add(gen_visit_object(name, base, members, variants))
|
||||
with ifcontext(ifcond, self._genh, self._genc):
|
||||
self._genh.add(gen_visit_members_decl(name))
|
||||
self._genc.add(gen_visit_object_members(name, base,
|
||||
members, variants))
|
||||
# TODO Worth changing the visitor signature, so we could
|
||||
# directly use rather than repeat type.is_implicit()?
|
||||
if not name.startswith('q_'):
|
||||
# only explicit types need an allocating visit
|
||||
self._genh.add(gen_visit_decl(name))
|
||||
self._genc.add(gen_visit_object(name, base, members, variants))
|
||||
|
||||
def visit_alternate_type(self, name, info, ifcond, variants):
|
||||
self._genh.add(gen_visit_decl(name))
|
||||
self._genc.add(gen_visit_alternate(name, variants))
|
||||
with ifcontext(ifcond, self._genh, self._genc):
|
||||
self._genh.add(gen_visit_decl(name))
|
||||
self._genc.add(gen_visit_alternate(name, variants))
|
||||
|
||||
|
||||
def gen_visit(schema, output_dir, prefix, opt_builtins):
|
||||
|
Loading…
Reference in New Issue
Block a user