[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 19/51] qapi: change enum visitor to take QAPISche
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH v4 19/51] qapi: change enum visitor to take QAPISchemaMember |
Date: |
Thu, 11 Jan 2018 22:32:18 +0100 |
This will allow to add and access more properties associated with enum
values/members, like the associated 'if' condition. We may want to
have a specialized type QAPISchemaEnumMember, for now this will do.
Suggested-by: Markus Armbruster <address@hidden>
Signed-off-by: Marc-André Lureau <address@hidden>
---
scripts/qapi.py | 12 ++++++------
scripts/qapi-event.py | 2 +-
scripts/qapi-introspect.py | 3 ++-
tests/qapi-schema/test-qapi.py | 2 +-
4 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index c7cd98a890..f8c711b81b 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -1166,7 +1166,7 @@ class QAPISchemaEnumType(QAPISchemaType):
def visit(self, visitor):
visitor.visit_enum_type(self.name, self.info, self.ifcond,
- self.member_names(), self.prefix)
+ self.members, self.prefix)
class QAPISchemaArrayType(QAPISchemaType):
@@ -1966,11 +1966,11 @@ const QEnumLookup %(c_name)s_lookup = {
''',
c_name=c_name(name))
for m in members:
- index = c_enum_const(name, m, prefix)
+ index = c_enum_const(name, m.name, prefix)
ret += mcgen('''
- [%(index)s] = "%(value)s",
+ [%(index)s] = "%(name)s",
''',
- index=index, value=m)
+ index=index, name=m.name)
ret += mcgen('''
},
@@ -1983,7 +1983,7 @@ const QEnumLookup %(c_name)s_lookup = {
def gen_enum(name, members, prefix=None):
# append automatically generated _MAX value
- enum_members = members + ['_MAX']
+ enum_members = members + [QAPISchemaMember('_MAX')]
ret = mcgen('''
@@ -1995,7 +1995,7 @@ typedef enum %(c_name)s {
ret += mcgen('''
%(c_enum)s,
''',
- c_enum=c_enum_const(name, m, prefix))
+ c_enum=c_enum_const(name, m.name, prefix))
ret += mcgen('''
} %(c_name)s;
diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index bef301dfe9..38f4264817 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -168,7 +168,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaVisitor):
def visit_event(self, name, info, ifcond, arg_type, boxed):
self.decl += gen_event_send_decl(name, arg_type, boxed)
self.defn += gen_event_send(name, arg_type, boxed)
- self._event_names.append(name)
+ self._event_names.append(QAPISchemaMember(name))
(input_file, output_dir, do_c, do_h, prefix, dummy) = parse_command_line()
diff --git a/scripts/qapi-introspect.py b/scripts/qapi-introspect.py
index 9fcb342c91..868d12f504 100644
--- a/scripts/qapi-introspect.py
+++ b/scripts/qapi-introspect.py
@@ -154,7 +154,8 @@ const QLitObject %(c_name)s = %(c_string)s;
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': members}, ifcond)
+ self._gen_qlit(name, 'enum',
+ {'values': [m.name for m in members]}, ifcond)
def visit_array_type(self, name, info, ifcond, element_type):
element = self._use_type(element_type)
diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py
index 1c4f9e0dac..2ab79230c2 100644
--- a/tests/qapi-schema/test-qapi.py
+++ b/tests/qapi-schema/test-qapi.py
@@ -18,7 +18,7 @@ import sys
class QAPISchemaTestVisitor(QAPISchemaVisitor):
def visit_enum_type(self, name, info, ifcond, members, prefix):
- print 'enum %s %s' % (name, members)
+ print 'enum %s %s' % (name, [m.name for m in members])
if prefix:
print ' prefix %s' % prefix
self._print_if(ifcond)
--
2.16.0.rc1.1.gef27df75a1
- [Qemu-devel] [PATCH v4 10/51] qapi: add #if/#endif helpers, (continued)
- [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, 2018/01/11
- [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 <=
- [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