diff options
| author | Peter Maydell <peter.maydell@linaro.org> | 2018-07-05 10:31:36 +0100 |
|---|---|---|
| committer | Peter Maydell <peter.maydell@linaro.org> | 2018-07-05 10:31:36 +0100 |
| commit | 5dafaf4fbceeb4c5d204039045b50b2f37443ff4 (patch) | |
| tree | db8692abda31876ebf09ba63d2e64b78c36a1aaa /scripts/qapi/types.py | |
| parent | 8beb8cc64da2868acec270e4becb9fea8f9093dc (diff) | |
| parent | 514337c142f9522f6ab89c3d2f964f446ebeb1cd (diff) | |
| download | focaccia-qemu-5dafaf4fbceeb4c5d204039045b50b2f37443ff4.tar.gz focaccia-qemu-5dafaf4fbceeb4c5d204039045b50b2f37443ff4.zip | |
Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2018-07-03' into staging
QAPI patches for 2018-07-03 # gpg: Signature made Tue 03 Jul 2018 21:52:55 BST # gpg: using RSA key 3870B400EB918653 # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-qapi-2018-07-03: qapi: add conditions to SPICE type/commands/events on the schema qapi: add conditions to VNC type/commands/events on the schema qapi: add 'If:' section to generated documentation qapi-types: add #if conditions to types & visitors qapi/events: add #if conditions to events qapi/commands: add #if conditions to commands qapi-introspect: add preprocessor conditions to generated QLit qapi-introspect: modify to_qlit() to append ',' on level > 0 qapi: add #if/#endif helpers qapi: mcgen() shouldn't indent # lines qapi: add 'ifcond' to visitor methods qapi: leave the ifcond attribute undefined until check() qapi: pass 'if' condition into QAPISchemaEntity objects qapi: add 'if' to top-level expressions Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'scripts/qapi/types.py')
| -rw-r--r-- | scripts/qapi/types.py | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index a599352e59..fd7808103c 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -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 @@ -208,34 +212,40 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor): self._genh.add(gen_type_cleanup_decl(name)) self._genc.add(gen_type_cleanup(name)) - def visit_enum_type(self, name, info, values, prefix): - self._genh.preamble_add(gen_enum(name, values, prefix)) - self._genc.add(gen_enum_lookup(name, values, prefix)) + def visit_enum_type(self, name, info, ifcond, 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, 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) + def visit_array_type(self, name, info, ifcond, element_type): + 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, base, members, variants): + 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) - - def visit_alternate_type(self, name, info, 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, 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): + 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): |