qemu-devel
[Top][All Lists]
Advanced

[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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]