[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 16/51] qapi-types: add #if conditions to types &
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH v4 16/51] qapi-types: add #if conditions to types & visitors |
Date: |
Thu, 11 Jan 2018 22:32:15 +0100 |
Types & visitors are coupled and must be handled together to avoid
temporary build regression.
Wrap generated types/visitor code with #if/#endif using the
ifcond_decorator & helpers.
Signed-off-by: Marc-André Lureau <address@hidden>
---
scripts/qapi-types.py | 18 ++++++++++++++----
scripts/qapi-visit.py | 5 +++++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 2b3588267b..789e89ff59 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -59,8 +59,10 @@ def gen_variants_objects(variants):
for v in variants.variants:
if isinstance(v.type, QAPISchemaObjectType):
ret += gen_variants_objects(v.type.variants)
+ ret += gen_if(v.type.ifcond)
ret += gen_object(v.type.name, v.type.base,
v.type.local_members, v.type.variants)
+ ret += gen_endif(v.type.ifcond)
return ret
@@ -175,6 +177,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
self.defn = None
self._fwdecl = None
self._btin = None
+ self.if_members = ['decl', 'defn', '_fwdecl', '_btin']
def visit_begin(self, schema):
# gen_object() is recursive, ensure it doesn't visit the empty type
@@ -199,6 +202,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
self.decl += gen_type_cleanup_decl(name)
self.defn += gen_type_cleanup(name)
+ @ifcond_decorator
def visit_enum_type(self, name, info, ifcond, values, prefix):
# Special case for our lone builtin enum type
# TODO use something cleaner than existence of info
@@ -210,6 +214,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
self._fwdecl += gen_enum(name, values, prefix)
self.defn += gen_enum_lookup(name, values, prefix)
+ @ifcond_decorator
def visit_array_type(self, name, info, ifcond, element_type):
if isinstance(element_type, QAPISchemaBuiltinType):
self._btin += gen_fwd_object_or_array(name)
@@ -222,6 +227,7 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
self.decl += gen_array(name, element_type)
self._gen_type_cleanup(name)
+ @ifcond_decorator
def _gen_object(self, name, info, ifcond, base, members, variants):
self.decl += gen_object(name, base, members, variants)
if base and not base.is_implicit():
@@ -232,18 +238,22 @@ class QAPISchemaGenTypeVisitor(QAPISchemaVisitor):
# implicit types won't be directly allocated/freed
self._gen_type_cleanup(name)
+ @ifcond_decorator
+ def _gen_fwd_object_or_array(self, name, ifcond):
+ self._fwdecl += gen_fwd_object_or_array(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._fwdecl += gen_fwd_object_or_array(name)
+ self._gen_fwd_object_or_array(name, ifcond)
self.decl += gen_variants_objects(variants)
- self._gen_object(name, info, None, base, members, variants)
+ self._gen_object(name, info, ifcond, base, members, variants)
def visit_alternate_type(self, name, info, ifcond, variants):
- self._fwdecl += gen_fwd_object_or_array(name)
+ self._gen_fwd_object_or_array(name, ifcond)
self.decl += gen_variants_objects(variants)
- self._gen_object(name, info, None, None,
+ self._gen_object(name, info, ifcond, None,
[variants.tag_member], variants)
# If you link code generated from multiple schemata, you want only one
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index aceea2a9f9..4b0e005437 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -267,6 +267,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor):
self.decl = None
self.defn = None
self._btin = None
+ self.if_members = ['decl', 'defn', '_btin']
def visit_begin(self, schema):
self.decl = ''
@@ -282,6 +283,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor):
self.decl = self._btin + self.decl
self._btin = None
+ @ifcond_decorator
def visit_enum_type(self, name, info, ifcond, values, prefix):
# Special case for our lone builtin enum type
# TODO use something cleaner than existence of info
@@ -293,6 +295,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor):
self.decl += gen_visit_decl(name, scalar=True)
self.defn += gen_visit_enum(name)
+ @ifcond_decorator
def visit_array_type(self, name, info, ifcond, element_type):
decl = gen_visit_decl(name)
defn = gen_visit_list(name, element_type)
@@ -304,6 +307,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor):
self.decl += decl
self.defn += defn
+ @ifcond_decorator
def visit_object_type(self, name, info, ifcond, base, members, variants):
# Nothing to do for the special empty builtin
if name == 'q_empty':
@@ -317,6 +321,7 @@ class QAPISchemaGenVisitVisitor(QAPISchemaVisitor):
self.decl += gen_visit_decl(name)
self.defn += gen_visit_object(name, base, members, variants)
+ @ifcond_decorator
def visit_alternate_type(self, name, info, ifcond, variants):
self.decl += gen_visit_decl(name)
self.defn += gen_visit_alternate(name, variants)
--
2.16.0.rc1.1.gef27df75a1
- [Qemu-devel] [PATCH v4 06/51] qapi: pass 'if' condition into QAPISchemaEntity objects, (continued)
- [Qemu-devel] [PATCH v4 06/51] qapi: pass 'if' condition into QAPISchemaEntity objects, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 07/51] qapi: leave the ifcond attribute undefined until check(), Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 08/51] qapi: add 'ifcond' to visitor methods, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 09/51] qapi: mcgen() shouldn't indent # lines, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 10/51] qapi: add #if/#endif helpers, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 11/51] qapi-introspect: modify to_qlit() to append ', ' on level > 0, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 12/51] qapi-introspect: add preprocessor conditions to generated QLit, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 13/51] qapi-commands: add #if conditions to commands, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 14/51] qapi-event: add #if conditions to events, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 15/51] qapi-types: refactor variants handling, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 16/51] qapi-types: add #if conditions to types & visitors,
Marc-André Lureau <=
- [Qemu-devel] [PATCH v4 17/51] qapi: do not define enumeration value explicitely, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 18/51] qapi: rename QAPISchemaEnumType.values to .members, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 20/51] tests: modify visit_enum_type() in test-qapi to print members, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 19/51] qapi: change enum visitor to take QAPISchemaMember, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 22/51] qapi: add a dictionnary form with 'name' key for enum members, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 21/51] qapi: factor out check_known_keys(), Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 24/51] qapi-event: add 'if' condition to implicit event enum, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 23/51] qapi: add 'if' to enum members, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 25/51] qapi: rename allow_dict to allow_implicit, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 27/51] qapi: add 'if' to implicit struct members, Marc-André Lureau, 2018/01/11