From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com
Subject: [PATCH 2/7] qapi: Store pragma state in QAPISourceInfo, not global state
Date: Tue, 1 Oct 2019 21:15:09 +0200 [thread overview]
Message-ID: <20191001191514.11208-3-armbru@redhat.com> (raw)
In-Reply-To: <20191001191514.11208-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>
---
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
next prev parent reply other threads:[~2019-10-01 19:24 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-01 19:15 [PATCH 0/7] qapi: Cleanups and test speedup Markus Armbruster
2019-10-01 19:15 ` [PATCH 1/7] qapi: Don't suppress doc generation without pragma doc-required Markus Armbruster
2019-10-01 19:59 ` Eric Blake
2019-10-01 19:15 ` Markus Armbruster [this message]
2019-10-01 20:01 ` [PATCH 2/7] qapi: Store pragma state in QAPISourceInfo, not global state Eric Blake
2019-10-01 19:15 ` [PATCH 3/7] qapi: Eliminate accidental global frontend state Markus Armbruster
2019-10-01 20:03 ` Eric Blake
2019-10-01 19:15 ` [PATCH 4/7] qapi: Speed up frontend tests Markus Armbruster
2019-10-01 20:23 ` Eric Blake
2019-10-02 14:31 ` Markus Armbruster
2019-10-01 19:15 ` [PATCH 5/7] qapi: Move gen_enum(), gen_enum_lookup() back to qapi/types.py Markus Armbruster
2019-10-01 20:26 ` Eric Blake
2019-10-01 19:15 ` [PATCH 6/7] qapi: Split up scripts/qapi/common.py Markus Armbruster
2019-10-01 21:19 ` Eric Blake
2019-10-02 15:16 ` Markus Armbruster
2019-10-02 15:27 ` Eric Blake
2019-10-02 16:13 ` Markus Armbruster
2019-10-16 13:05 ` Kevin Wolf
2019-10-16 14:09 ` Markus Armbruster
2019-10-01 19:15 ` [PATCH 7/7] qapi: Clear scripts/qapi/doc.py executable bits again Markus Armbruster
2019-10-01 20:34 ` 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=20191001191514.11208-3-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).