[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 04/11] qapi: _make_enum_members() to work with pre-built QAPIS
From: |
marcandre . lureau |
Subject: |
[PATCH v6 04/11] qapi: _make_enum_members() to work with pre-built QAPISchemaIfCond |
Date: |
Fri, 18 Jun 2021 14:25:00 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Instead of lowering the expression back to its original form, and having
to convert it again, special-case the 'if' condition to be pre-built.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
scripts/qapi/schema.py | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index e3bd8f8720..c35fa3bf51 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -982,8 +982,13 @@ def _make_features(self, features, info):
for f in features]
def _make_enum_members(self, values, info):
- return [QAPISchemaEnumMember(v['name'], info,
- QAPISchemaIfCond(v.get('if')))
+ def _get_if(v):
+ ifcond = v.get('if')
+ if isinstance(ifcond, QAPISchemaIfCond):
+ return ifcond
+ else:
+ return QAPISchemaIfCond(ifcond)
+ return [QAPISchemaEnumMember(v['name'], info, _get_if(v))
for v in values]
def _make_implicit_enum_type(self, name, info, ifcond, values):
@@ -1103,7 +1108,7 @@ def _def_union_type(self, expr, info, doc):
QAPISchemaIfCond(value.get('if')),
info)
for (key, value) in data.items()]
- enum = [{'name': v.name, 'if': v.ifcond.ifcond} for v in variants]
+ enum = [{'name': v.name, 'if': v.ifcond} for v in variants]
typ = self._make_implicit_enum_type(name, info, ifcond, enum)
tag_member = QAPISchemaObjectTypeMember('type', info, typ, False)
members = [tag_member]
--
2.29.0
- [PATCH v6 00/11] qapi: untie 'if' conditions from C preprocessor, marcandre . lureau, 2021/06/18
- [PATCH v6 01/11] docs: update the documentation upfront about schema configuration, marcandre . lureau, 2021/06/18
- [PATCH v6 02/11] qapi: wrap Sequence[str] in an object, marcandre . lureau, 2021/06/18
- [PATCH v6 03/11] qapi: add QAPISchemaIfCond.is_present(), marcandre . lureau, 2021/06/18
- [PATCH v6 04/11] qapi: _make_enum_members() to work with pre-built QAPISchemaIfCond,
marcandre . lureau <=
- [PATCH v6 05/11] qapi: introduce QAPISchemaIfCond.cgen(), marcandre . lureau, 2021/06/18
- [PATCH v6 06/11] qapidoc: introduce QAPISchemaIfCond.docgen(), marcandre . lureau, 2021/06/18
- [PATCH v6 07/11] qapi: replace if condition list with dict {'all': [...]}, marcandre . lureau, 2021/06/18
- [PATCH v6 08/11] qapi: add 'any' condition, marcandre . lureau, 2021/06/18
- [PATCH v6 09/11] qapi: convert 'if' C-expressions to the new syntax tree, marcandre . lureau, 2021/06/18
- [PATCH v6 10/11] qapi: add 'not' condition operation, marcandre . lureau, 2021/06/18
- [PATCH v6 11/11] qapi: make 'if' condition strings simple identifiers, marcandre . lureau, 2021/06/18