[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 31/51] qapi: add #if conditions to generated code
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH v4 31/51] qapi: add #if conditions to generated code |
Date: |
Thu, 11 Jan 2018 22:32:30 +0100 |
Wrap generated enum/struct members and code with #if/#endif, using the
.ifcond members added in the previous patches.
Some types generate both enum and struct members for example, so a
step-by-step is unnecessarily complicated to deal with (it would
easily generate invalid intermediary code).
Signed-off-by: Marc-André Lureau <address@hidden>
---
scripts/qapi.py | 4 ++++
scripts/qapi-introspect.py | 13 +++++++++----
scripts/qapi-types.py | 4 ++++
scripts/qapi-visit.py | 8 +++++++-
4 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index f24cf8bda6..1668a6da6c 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -2043,11 +2043,13 @@ const QEnumLookup %(c_name)s_lookup = {
''',
c_name=c_name(name))
for m in members:
+ ret += gen_if(m.ifcond)
index = c_enum_const(name, m.name, prefix)
ret += mcgen('''
[%(index)s] = "%(name)s",
''',
index=index, name=m.name)
+ ret += gen_endif(m.ifcond)
ret += mcgen('''
},
@@ -2069,10 +2071,12 @@ typedef enum %(c_name)s {
c_name=c_name(name))
for m in enum_members:
+ ret += gen_if(m.ifcond)
ret += mcgen('''
%(c_enum)s,
''',
c_enum=c_enum_const(name, m.name, prefix))
+ ret += gen_endif(m.ifcond)
ret += mcgen('''
} %(c_name)s;
diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py
index 868d12f504..6a66047243 100644
--- a/scripts/qapi-introspect.py
+++ b/scripts/qapi-introspect.py
@@ -141,6 +141,8 @@ const QLitObject %(c_name)s = %(c_string)s;
ret = {'name': member.name, 'type': self._use_type(member.type)}
if member.optional:
ret['default'] = None
+ if member.ifcond:
+ ret = (ret, member.ifcond)
return ret
def _gen_variants(self, tag_name, variants):
@@ -148,14 +150,16 @@ const QLitObject %(c_name)s = %(c_string)s;
'variants': [self._gen_variant(v) for v in variants]}
def _gen_variant(self, variant):
- return {'case': variant.name, 'type': self._use_type(variant.type)}
+ return ({'case': variant.name, 'type': self._use_type(variant.type)},
+ variant.ifcond)
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, members, prefix):
self._gen_qlit(name, 'enum',
- {'values': [m.name for m in members]}, ifcond)
+ {'values': [(m.name, m.ifcond) for m in members]},
+ ifcond)
def visit_array_type(self, name, info, ifcond, element_type):
element = self._use_type(element_type)
@@ -171,8 +175,9 @@ const QLitObject %(c_name)s = %(c_string)s;
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]}, ifcond)
+ {'members': [
+ ({'type': self._use_type(m.type)}, m.ifcond)
+ for m in variants.variants]}, ifcond)
def visit_command(self, name, info, ifcond, arg_type, ret_type,
gen, success_response, boxed):
diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 75c1823e44..312685c295 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -41,6 +41,7 @@ struct %(c_name)s {
def gen_struct_members(members):
ret = ''
for memb in members:
+ ret += gen_if(memb.ifcond)
if memb.optional:
ret += mcgen('''
bool has_%(c_name)s;
@@ -50,6 +51,7 @@ def gen_struct_members(members):
%(c_type)s %(c_name)s;
''',
c_type=memb.type.c_type(), c_name=c_name(memb.name))
+ ret += gen_endif(memb.ifcond)
return ret
@@ -129,11 +131,13 @@ def gen_variants(variants):
c_name=c_name(variants.tag_member.name))
for var in variants.variants:
+ ret += gen_if(var.ifcond)
ret += mcgen('''
%(c_type)s %(c_name)s;
''',
c_type=var.type.c_unboxed_type(),
c_name=c_name(var.name))
+ ret += gen_endif(var.ifcond)
ret += mcgen('''
} u;
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 7e816ae98e..48ac1c9a42 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -53,6 +53,7 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s
*obj, Error **errp)
c_type=base.c_name())
for memb in members:
+ ret += gen_if(memb.ifcond)
if memb.optional:
ret += mcgen('''
if (visit_optional(v, "%(name)s", &obj->has_%(c_name)s)) {
@@ -72,6 +73,7 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s
*obj, Error **errp)
ret += mcgen('''
}
''')
+ ret += gen_endif(memb.ifcond)
if variants:
ret += mcgen('''
@@ -80,6 +82,7 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s
*obj, Error **errp)
c_name=c_name(variants.tag_member.name))
for var in variants.variants:
+ ret += gen_if(var.ifcond)
ret += mcgen('''
case %(case)s:
visit_type_%(c_type)s_members(v, &obj->u.%(c_name)s, &err);
@@ -90,6 +93,7 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s
*obj, Error **errp)
variants.tag_member.type.prefix),
c_type=var.type.c_name(), c_name=c_name(var.name))
+ ret += gen_endif(var.ifcond)
ret += mcgen('''
default:
abort();
@@ -177,9 +181,10 @@ void visit_type_%(c_name)s(Visitor *v, const char *name,
%(c_name)s **obj, Error
}
switch ((*obj)->type) {
''',
- c_name=c_name(name))
+ c_name=c_name(name))
for var in variants.variants:
+ ret += gen_if(var.ifcond)
ret += mcgen('''
case %(case)s:
''',
@@ -207,6 +212,7 @@ void visit_type_%(c_name)s(Visitor *v, const char *name,
%(c_name)s **obj, Error
ret += mcgen('''
break;
''')
+ ret += gen_endif(var.ifcond)
ret += mcgen('''
case QTYPE_NONE:
--
2.16.0.rc1.1.gef27df75a1
- [Qemu-devel] [PATCH v4 22/51] qapi: add a dictionnary form with 'name' key for enum members, (continued)
- [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
- [Qemu-devel] [PATCH v4 26/51] qapi: add a dictionary form with 'type' key for members, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 28/51] qapi: add an error in case a discriminator is conditionnal, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 29/51] qapi: add 'if' on union members, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 30/51] qapi: add 'if' to alternate members, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 31/51] qapi: add #if conditions to generated code,
Marc-André Lureau <=
- [Qemu-devel] [PATCH v4 32/51] docs: document schema configuration, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 33/51] qapi2texi: add 'If:' section to generated documentation, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 34/51] qapi2texi: add 'If:' condition to enum values, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 36/51] qapi2texi: add condition to variants, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 35/51] qapi2texi: add 'If:' condition to struct members, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 37/51] qapi: add conditions to VNC type/commands/events on the schema, Marc-André Lureau, 2018/01/11
- [Qemu-devel] [PATCH v4 38/51] qapi: add conditions to SPICE type/commands/events on the schema, Marc-André Lureau, 2018/01/11