]> Git Repo - qemu.git/commitdiff
qapi: add QAPISchemaIfCond.is_present()
authorMarc-André Lureau <[email protected]>
Wed, 4 Aug 2021 08:30:58 +0000 (12:30 +0400)
committerMarkus Armbruster <[email protected]>
Thu, 26 Aug 2021 11:53:56 +0000 (13:53 +0200)
Signed-off-by: Marc-André Lureau <[email protected]>
Reviewed-by: Markus Armbruster <[email protected]>
Message-Id: <20210804083105[email protected]>
Signed-off-by: Markus Armbruster <[email protected]>
docs/sphinx/qapidoc.py
scripts/qapi/introspect.py
scripts/qapi/schema.py
tests/qapi-schema/test-qapi.py

index 0eac3308b2e9c689c5134d0b1c4c2f13eaa3cac8..511520f33fdf9b1626c14a4dabd018734652e263 100644 (file)
@@ -139,7 +139,7 @@ class QAPISchemaGenRSTVisitor(QAPISchemaVisitor):
             term.append(nodes.literal('', member.type.doc_type()))
         if member.optional:
             term.append(nodes.Text(' (optional)'))
-        if member.ifcond.ifcond:
+        if member.ifcond.is_present():
             term.extend(self._nodes_for_ifcond(member.ifcond))
         return term
 
@@ -154,7 +154,7 @@ class QAPISchemaGenRSTVisitor(QAPISchemaVisitor):
                 nodes.literal('', variants.tag_member.name),
                 nodes.Text(' is '),
                 nodes.literal('', '"%s"' % variant.name)]
-        if variant.ifcond.ifcond:
+        if variant.ifcond.is_present():
             term.extend(self._nodes_for_ifcond(variant.ifcond))
         return term
 
@@ -209,7 +209,7 @@ class QAPISchemaGenRSTVisitor(QAPISchemaVisitor):
         dlnode = nodes.definition_list()
         for section in doc.args.values():
             termtext = [nodes.literal('', section.member.name)]
-            if section.member.ifcond.ifcond:
+            if section.member.ifcond.is_present():
                 termtext.extend(self._nodes_for_ifcond(section.member.ifcond))
             # TODO drop fallbacks when undocumented members are outlawed
             if section.text:
@@ -277,7 +277,7 @@ class QAPISchemaGenRSTVisitor(QAPISchemaVisitor):
     def _nodes_for_if_section(self, ifcond):
         """Return list of doctree nodes for the "If" section"""
         nodelist = []
-        if ifcond.ifcond:
+        if ifcond.is_present():
             snode = self._make_section('If')
             snode += nodes.paragraph(
                 '', '', *self._nodes_for_ifcond(ifcond, with_if=False)
index db1ebbf53a1b9da356987c3540d354e1068c67e6..e23725e2f9cad924fa94b0888d3a9c9d775bdb9a 100644 (file)
@@ -123,10 +123,10 @@ def _tree_to_qlit(obj: JSONValue,
         ret = ''
         if obj.comment:
             ret += indent(level) + f"/* {obj.comment} */\n"
-        if obj.ifcond.ifcond:
+        if obj.ifcond.is_present():
             ret += gen_if(obj.ifcond.ifcond)
         ret += _tree_to_qlit(obj.value, level)
-        if obj.ifcond.ifcond:
+        if obj.ifcond.is_present():
             ret += '\n' + gen_endif(obj.ifcond.ifcond)
         return ret
 
index e3beb24500f262851c773e43481a2679436d2402..86fcd6cbd548f1d00f246da323120697df368589 100644 (file)
@@ -29,6 +29,9 @@ class QAPISchemaIfCond:
     def __init__(self, ifcond=None):
         self.ifcond = ifcond or []
 
+    def is_present(self):
+        return bool(self.ifcond)
+
 
 class QAPISchemaEntity:
     meta: Optional[str] = None
@@ -598,7 +601,7 @@ class QAPISchemaVariants:
                     self.info,
                     "discriminator member '%s' of %s must not be optional"
                     % (self._tag_name, base))
-            if self.tag_member.ifcond.ifcond:
+            if self.tag_member.ifcond.is_present():
                 raise QAPISemError(
                     self.info,
                     "discriminator member '%s' of %s must not be conditional"
@@ -606,7 +609,7 @@ class QAPISchemaVariants:
         else:                   # simple union
             assert isinstance(self.tag_member.type, QAPISchemaEnumType)
             assert not self.tag_member.optional
-            assert self.tag_member.ifcond.ifcond == []
+            assert not self.tag_member.ifcond.is_present()
         if self._tag_name:    # flat union
             # branches that are not explicitly covered get an empty type
             cases = {v.name for v in self.variants}
index 7907b4ac3aa0be45cee7c9fbe023c2d93c59fbab..c92be2d086a2aa4224722cb5eebf929210246c26 100755 (executable)
@@ -94,7 +94,7 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor):
 
     @staticmethod
     def _print_if(ifcond, indent=4):
-        if ifcond.ifcond:
+        if ifcond.is_present():
             print('%sif %s' % (' ' * indent, ifcond.ifcond))
 
     @classmethod
This page took 0.036684 seconds and 4 git commands to generate.