[Qemu-devel] [PATCH v3 12/50] qapi-introspect: add preprocessor conditions to generated QLit

Marc-André Lureau posted 50 patches 8 years, 5 months ago
There is a newer version of this series
[Qemu-devel] [PATCH v3 12/50] qapi-introspect: add preprocessor conditions to generated QLit
Posted by Marc-André Lureau 8 years, 5 months ago
Add 'ifcond' condition to top-level QLit objects.

to_qlit() handles the (obj, ifcond) tuples in previous patch.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 scripts/qapi-introspect.py | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py
index dc70954e8a..69d9afc792 100644
--- a/scripts/qapi-introspect.py
+++ b/scripts/qapi-introspect.py
@@ -128,12 +128,12 @@ const QLitObject %(c_name)s = %(c_string)s;
             return '[' + self._use_type(typ.element_type) + ']'
         return self._name(typ.name)
 
-    def _gen_qlit(self, name, mtype, obj):
+    def _gen_qlit(self, name, mtype, obj, ifcond):
         if mtype not in ('command', 'event', 'builtin', 'array'):
             name = self._name(name)
         obj['name'] = name
         obj['meta-type'] = mtype
-        self._qlits.append(obj)
+        self._qlits.append((obj, ifcond))
 
     def _gen_member(self, member):
         ret = {'name': member.name, 'type': self._use_type(member.type)}
@@ -149,26 +149,27 @@ const QLitObject %(c_name)s = %(c_string)s;
         return {'case': variant.name, 'type': self._use_type(variant.type)}
 
     def visit_builtin_type(self, name, info, json_type):
-        self._gen_qlit(name, 'builtin', {'json-type': json_type})
+        self._gen_qlit(name, 'builtin', {'json-type': json_type}, None)
 
     def visit_enum_type(self, name, info, ifcond, values, prefix):
-        self._gen_qlit(name, 'enum', {'values': values})
+        self._gen_qlit(name, 'enum', {'values': values}, ifcond)
 
     def visit_array_type(self, name, info, ifcond, element_type):
         element = self._use_type(element_type)
-        self._gen_qlit('[' + element + ']', 'array', {'element-type': element})
+        self._gen_qlit('[' + element + ']', 'array', {'element-type': element},
+                       ifcond)
 
     def visit_object_type_flat(self, name, info, ifcond, members, variants):
         obj = {'members': [self._gen_member(m) for m in members]}
         if variants:
             obj.update(self._gen_variants(variants.tag_member.name,
                                           variants.variants))
-        self._gen_qlit(name, 'object', obj)
+        self._gen_qlit(name, 'object', obj, ifcond)
 
     def visit_alternate_type(self, name, info, ifcond, variants):
         self._gen_qlit(name, 'alternate',
                        {'members': [{'type': self._use_type(m.type)}
-                                    for m in variants.variants]})
+                                    for m in variants.variants]}, ifcond)
 
     def visit_command(self, name, info, ifcond, arg_type, ret_type,
                       gen, success_response, boxed):
@@ -176,11 +177,12 @@ const QLitObject %(c_name)s = %(c_string)s;
         ret_type = ret_type or self._schema.the_empty_object_type
         self._gen_qlit(name, 'command',
                        {'arg-type': self._use_type(arg_type),
-                        'ret-type': self._use_type(ret_type)})
+                        'ret-type': self._use_type(ret_type)}, ifcond)
 
     def visit_event(self, name, info, ifcond, arg_type, boxed):
         arg_type = arg_type or self._schema.the_empty_object_type
-        self._gen_qlit(name, 'event', {'arg-type': self._use_type(arg_type)})
+        self._gen_qlit(name, 'event', {'arg-type': self._use_type(arg_type)},
+                       ifcond)
 
 # Debugging aid: unmask QAPI schema's type names
 # We normally mask them, because they're not QMP wire ABI
-- 
2.14.1.146.gd35faa819


Re: [Qemu-devel] [PATCH v3 12/50] qapi-introspect: add preprocessor conditions to generated QLit
Posted by Markus Armbruster 8 years, 2 months ago
Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> Add 'ifcond' condition to top-level QLit objects.
>
> to_qlit() handles the (obj, ifcond) tuples in previous patch.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

According to my testing, this patch adds blank lines between the
elements of qmp_schema_qlit.  I suspect this is because to_qlit((obj,
None) is not actually equivalent to to_qlit(obj).  It should be.

Note that the issue is in PATCH 11, but becomes visible only in PATCH
12, because the new code only gets used in PATCH 12.  Consider squashing
the two together.