qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH 13/19] qapi: Normalize 'if' in check_exprs(), like other sugar
Date: Sat, 14 Sep 2019 17:35:00 +0200	[thread overview]
Message-ID: <20190914153506.2151-14-armbru@redhat.com> (raw)
In-Reply-To: <20190914153506.2151-1-armbru@redhat.com>

We normalize shorthand to longhand forms in check_expr(): enumeration
values with normalize_enum(), feature values with
normalize_features(), struct members, union branches and alternate
branches with normalize_members().  If conditions are an exception: we
normalize them in QAPISchemaEntity.check() and
QAPISchemaMember.__init(), with listify_cond().  The idea goes back to
commit 2cbc94376e "qapi: pass 'if' condition into QAPISchemaEntity
objects", v3.0.0.

Normalize in check_expr() instead, with new helper normalize_if().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi/common.py | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index cacee9b8bb..4d1f62e808 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -804,6 +804,7 @@ def check_type(info, source, value,
         check_known_keys(info, "member '%s' of %s" % (key, source),
                          arg, ['type'], ['if'])
         check_if(arg, info)
+        normalize_if(arg)
         check_type(info, "Member '%s' of %s" % (key, source),
                    arg['type'], allow_array=True,
                    allow_metas=['built-in', 'union', 'alternate', 'struct',
@@ -904,6 +905,7 @@ def check_union(expr, info):
         check_known_keys(info, "member '%s' of union '%s'" % (key, name),
                          value, ['type'], ['if'])
         check_if(value, info)
+        normalize_if(value)
         # Each value must name a known type
         check_type(info, "Member '%s' of union '%s'" % (key, name),
                    value['type'],
@@ -933,6 +935,7 @@ def check_alternate(expr, info):
                          "member '%s' of alternate '%s'" % (key, name),
                          value, ['type'], ['if'])
         check_if(value, info)
+        normalize_if(value)
         typ = value['type']
 
         # Ensure alternates have no type conflicts.
@@ -978,6 +981,7 @@ def check_enum(expr, info):
         check_known_keys(info, "member of enum '%s'" % name, member,
                          ['name'], ['if'])
         check_if(member, info)
+        normalize_if(member)
         check_name(info, "Member of enum '%s'" % name, member['name'],
                    enum_member=True)
 
@@ -1003,6 +1007,7 @@ def check_struct(expr, info):
                              ['name'], ['if'])
 
             check_if(f, info)
+            normalize_if(f)
             check_name(info, "Feature of struct %s" % name, f['name'])
 
 
@@ -1067,6 +1072,12 @@ def normalize_features(features):
                        for f in features]
 
 
+def normalize_if(expr):
+    ifcond = expr.get('if')
+    if isinstance(ifcond, str):
+        expr['if'] = [ifcond]
+
+
 def check_exprs(exprs):
     global all_names
 
@@ -1123,6 +1134,7 @@ def check_exprs(exprs):
         else:
             raise QAPISemError(expr_elem['info'],
                                "Expression is missing metatype")
+        normalize_if(expr)
         name = expr[meta]
         add_name(name, info, meta)
         if doc and doc.symbol != name:
@@ -1177,14 +1189,6 @@ def check_exprs(exprs):
 # Schema compiler frontend
 #
 
-def listify_cond(ifcond):
-    if not ifcond:
-        return []
-    if not isinstance(ifcond, list):
-        return [ifcond]
-    return ifcond
-
-
 class QAPISchemaEntity(object):
     def __init__(self, name, info, doc, ifcond=None):
         assert name is None or isinstance(name, str)
@@ -1197,7 +1201,7 @@ class QAPISchemaEntity(object):
         # such place).
         self.info = info
         self.doc = doc
-        self._ifcond = ifcond  # self.ifcond is set only after .check()
+        self._ifcond = ifcond or []
 
     def c_name(self):
         return c_name(self.name)
@@ -1209,7 +1213,7 @@ class QAPISchemaEntity(object):
             typ.check(schema)
             self.ifcond = typ.ifcond
         else:
-            self.ifcond = listify_cond(self._ifcond)
+            self.ifcond = self._ifcond
         if self.info:
             self.module = os.path.relpath(self.info['file'],
                                           os.path.dirname(schema.fname))
@@ -1515,7 +1519,7 @@ class QAPISchemaMember(object):
     def __init__(self, name, ifcond=None):
         assert isinstance(name, str)
         self.name = name
-        self.ifcond = listify_cond(ifcond)
+        self.ifcond = ifcond or []
         self.owner = None
 
     def set_owner(self, name):
-- 
2.21.0



  parent reply	other threads:[~2019-09-14 15:48 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-14 15:34 [Qemu-devel] [PATCH 00/19] qapi: Frontend fixes and cleanups Markus Armbruster
2019-09-14 15:34 ` [Qemu-devel] [PATCH 01/19] tests/qapi-schema: Cover unknown pragma Markus Armbruster
2019-09-17 16:36   ` Eric Blake
2019-09-14 15:34 ` [Qemu-devel] [PATCH 02/19] tests/qapi-schema: Delete two redundant tests Markus Armbruster
2019-09-17 16:57   ` Eric Blake
2019-09-14 15:34 ` [Qemu-devel] [PATCH 03/19] tests/qapi-schema: Demonstrate misleading optional tag error Markus Armbruster
2019-09-17 17:36   ` Eric Blake
2019-09-14 15:34 ` [Qemu-devel] [PATCH 04/19] tests/qapi-schema: Demonstrate broken discriminator errors Markus Armbruster
2019-09-17 17:43   ` Eric Blake
2019-09-14 15:34 ` [Qemu-devel] [PATCH 05/19] tests/qapi-schema: Demonstrate insufficient 'if' checking Markus Armbruster
2019-09-17 17:47   ` Eric Blake
2019-09-23 11:55     ` Markus Armbruster
2019-09-23 12:55       ` Eric Blake
2019-09-14 15:34 ` [Qemu-devel] [PATCH 06/19] tests/qapi-schema: Demonstrate suboptimal lexical errors Markus Armbruster
2019-09-17 17:49   ` Eric Blake
2019-09-14 15:34 ` [Qemu-devel] [PATCH 07/19] qapi: Use quotes more consistently in frontend error messages Markus Armbruster
2019-09-17 17:52   ` Eric Blake
2019-09-14 15:34 ` [Qemu-devel] [PATCH 08/19] qapi: Improve reporting of lexical errors Markus Armbruster
2019-09-17 17:54   ` Eric Blake
2019-09-14 15:34 ` [Qemu-devel] [PATCH 09/19] qapi: Remove null from schema language Markus Armbruster
2019-09-17 18:01   ` Eric Blake
2019-09-14 15:34 ` [Qemu-devel] [PATCH 10/19] qapi: Fix broken discriminator error messages Markus Armbruster
2019-09-17 18:05   ` Eric Blake
2019-09-14 15:34 ` [Qemu-devel] [PATCH 11/19] qapi: Reject blank 'if' conditions in addition to empty ones Markus Armbruster
2019-09-17 18:06   ` Eric Blake
2019-09-14 15:34 ` [Qemu-devel] [PATCH 12/19] qapi: Fix missing 'if' checks in struct, union, alternate 'data' Markus Armbruster
2019-09-17 18:10   ` Eric Blake
2019-09-14 15:35 ` Markus Armbruster [this message]
2019-09-17 18:14   ` [Qemu-devel] [PATCH 13/19] qapi: Normalize 'if' in check_exprs(), like other sugar Eric Blake
2019-09-23 11:59     ` Markus Armbruster
2019-09-14 15:35 ` [Qemu-devel] [PATCH 14/19] qapi: Simplify check_keys() Markus Armbruster
2019-09-17 19:01   ` Eric Blake
2019-09-14 15:35 ` [Qemu-devel] [PATCH 15/19] qapi: Clean up around check_known_keys() Markus Armbruster
2019-09-17 19:03   ` Eric Blake
2019-09-14 15:35 ` [Qemu-devel] [PATCH 16/19] qapi: Delete useless check_exprs() code for simple union kind Markus Armbruster
2019-09-17 19:05   ` Eric Blake
2019-09-14 15:35 ` [Qemu-devel] [PATCH 17/19] qapi: Fix to .check() empty structs just once Markus Armbruster
2019-09-17 19:06   ` Eric Blake
2019-09-14 15:35 ` [Qemu-devel] [PATCH 18/19] qapi: Fix excessive QAPISchemaEntity.check() recursion Markus Armbruster
2019-09-17 19:26   ` Eric Blake
2019-09-23 12:01     ` Markus Armbruster
2019-09-14 15:35 ` [Qemu-devel] [PATCH 19/19] qapi: Assert .visit() and .check_clash() run only after .check() Markus Armbruster
2019-09-17 19:27   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190914153506.2151-14-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).