All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [PULL 02/12] qapi: Store pragma state in QAPISourceInfo, not global state
Date: Tue, 22 Oct 2019 09:56:05 +0200	[thread overview]
Message-ID: <20191022075615.956-3-armbru@redhat.com> (raw)
In-Reply-To: <20191022075615.956-1-armbru@redhat.com>

The frontend can't be run more than once due to its global state.
A future commit will want to do that.

Recent commit "qapi: Move context-sensitive checking to the proper
place" got rid of many global variables already, but pragma state is
still stored in global variables (that's why a pragma directive's
scope is the complete schema).

Move the pragma state to QAPISourceInfo.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20191018074345.24034-3-armbru@redhat.com>
---
 scripts/qapi/common.py | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index d6e00c80ea..5abab44302 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -21,25 +21,28 @@ import string
 import sys
 from collections import OrderedDict
 
-# Are documentation comments required?
-doc_required = False
-
-# Whitelist of commands allowed to return a non-dictionary
-returns_whitelist = []
-
-# Whitelist of entities allowed to violate case conventions
-name_case_whitelist = []
-
 
 #
 # Parsing the schema into expressions
 #
 
+
+class QAPISchemaPragma(object):
+    def __init__(self):
+        # Are documentation comments required?
+        self.doc_required = False
+        # Whitelist of commands allowed to return a non-dictionary
+        self.returns_whitelist = []
+        # Whitelist of entities allowed to violate case conventions
+        self.name_case_whitelist = []
+
+
 class QAPISourceInfo(object):
     def __init__(self, fname, line, parent):
         self.fname = fname
         self.line = line
         self.parent = parent
+        self.pragma = parent.pragma if parent else QAPISchemaPragma()
         self.defn_meta = None
         self.defn_name = None
 
@@ -486,26 +489,25 @@ class QAPISchemaParser(object):
         return QAPISchemaParser(incl_fname, previously_included, info)
 
     def _pragma(self, name, value, info):
-        global doc_required, returns_whitelist, name_case_whitelist
         if name == 'doc-required':
             if not isinstance(value, bool):
                 raise QAPISemError(info,
                                    "pragma 'doc-required' must be boolean")
-            doc_required = value
+            info.pragma.doc_required = value
         elif name == 'returns-whitelist':
             if (not isinstance(value, list)
                     or any([not isinstance(elt, str) for elt in value])):
                 raise QAPISemError(
                     info,
                     "pragma returns-whitelist must be a list of strings")
-            returns_whitelist = value
+            info.pragma.returns_whitelist = value
         elif name == 'name-case-whitelist':
             if (not isinstance(value, list)
                     or any([not isinstance(elt, str) for elt in value])):
                 raise QAPISemError(
                     info,
                     "pragma name-case-whitelist must be a list of strings")
-            name_case_whitelist = value
+            info.pragma.name_case_whitelist = value
         else:
             raise QAPISemError(info, "unknown pragma '%s'" % name)
 
@@ -757,7 +759,7 @@ def check_type(value, info, source,
         raise QAPISemError(info,
                            "%s should be an object or type name" % source)
 
-    permit_upper = allow_dict in name_case_whitelist
+    permit_upper = allow_dict in info.pragma.name_case_whitelist
 
     # value is a dictionary, check that each member is okay
     for (key, arg) in value.items():
@@ -840,7 +842,7 @@ def check_enum(expr, info):
     if prefix is not None and not isinstance(prefix, str):
         raise QAPISemError(info, "'prefix' must be a string")
 
-    permit_upper = name in name_case_whitelist
+    permit_upper = name in info.pragma.name_case_whitelist
 
     for member in members:
         source = "'data' member"
@@ -968,7 +970,7 @@ def check_exprs(exprs):
                 raise QAPISemError(
                     info, "documentation comment is for '%s'" % doc.symbol)
             doc.check_expr(expr)
-        elif doc_required:
+        elif info.pragma.doc_required:
             raise QAPISemError(info,
                                "documentation comment required")
 
@@ -1690,7 +1692,7 @@ class QAPISchemaCommand(QAPISchemaEntity):
         if self._ret_type_name:
             self.ret_type = schema.resolve_type(
                 self._ret_type_name, self.info, "command's 'returns'")
-            if self.name not in returns_whitelist:
+            if self.name not in self.info.pragma.returns_whitelist:
                 if not (isinstance(self.ret_type, QAPISchemaObjectType)
                         or (isinstance(self.ret_type, QAPISchemaArrayType)
                             and isinstance(self.ret_type.element_type,
-- 
2.21.0



  parent reply	other threads:[~2019-10-22  7:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-22  7:56 [PULL 00/12] QAPI patches for 2019-10-22 Markus Armbruster
2019-10-22  7:56 ` [PULL 01/12] qapi: Don't suppress doc generation without pragma doc-required Markus Armbruster
2019-10-22  7:56 ` Markus Armbruster [this message]
2019-10-22  7:56 ` [PULL 03/12] qapi: Eliminate accidental global frontend state Markus Armbruster
2019-10-22  7:56 ` [PULL 04/12] qapi: Speed up frontend tests Markus Armbruster
2019-10-22  7:56 ` [PULL 05/12] qapi: Move gen_enum(), gen_enum_lookup() back to qapi/types.py Markus Armbruster
2019-10-22  7:56 ` [PULL 06/12] qapi: Split up scripts/qapi/common.py Markus Armbruster
2019-10-22  7:56 ` [PULL 07/12] qapi: Clear scripts/qapi/doc.py executable bits again Markus Armbruster
2019-10-22  7:56 ` [PULL 08/12] tests/qapi-schema: Tidy up test output indentation Markus Armbruster
2019-10-22  7:56 ` [PULL 09/12] qapi: Add feature flags to commands Markus Armbruster
2019-10-22  7:56 ` [PULL 10/12] tests: qapi: Test 'features' of commands Markus Armbruster
2019-10-22  7:56 ` [PULL 11/12] tests/qapi-schema: Cover feature documentation comments Markus Armbruster
2019-10-22  7:56 ` [PULL 12/12] qapi: Allow introspecting fix for savevm's cooperation with blockdev Markus Armbruster
2019-10-22  9:32 ` [PULL 00/12] QAPI patches for 2019-10-22 Peter Maydell
2019-10-22 10:49   ` Markus Armbruster

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=20191022075615.956-3-armbru@redhat.com \
    --to=armbru@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.