[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 for-2.9 37/47] qapi: Fix detection of bogus membe
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH v2 for-2.9 37/47] qapi: Fix detection of bogus member documentation |
Date: |
Wed, 15 Mar 2017 13:57:26 +0100 |
check_definition_doc() checks for member documentation without a
matching member. It laboriously second-guesses what members
QAPISchema._def_exprs() will create. That's a stupid game.
Move the check into QAPISchema.check(), where the members are known.
Delegate the actual checking to new QAPIDoc.check().
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
scripts/qapi.py | 38 ++++++++++-------------------
tests/qapi-schema/doc-bad-union-member.err | 1 +
tests/qapi-schema/doc-bad-union-member.exit | 2 +-
tests/qapi-schema/doc-bad-union-member.out | 11 ---------
4 files changed, 15 insertions(+), 37 deletions(-)
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 648355e..ca9926b 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -249,6 +249,15 @@ class QAPIDoc(object):
self.args[member.name] = QAPIDoc.ArgSection(member.name)
self.args[member.name].connect(member)
+ def check(self):
+ bogus = [name for name, section in self.args.iteritems()
+ if not section.member]
+ if bogus:
+ raise QAPISemError(
+ self.info,
+ "The following documented members are not in "
+ "the declaration: %s" % ", ".join(bogus))
+
class QAPISchemaParser(object):
@@ -995,34 +1004,9 @@ def check_exprs(exprs):
def check_definition_doc(doc, expr, info):
- for i in ('enum', 'union', 'alternate', 'struct', 'command', 'event'):
- if i in expr:
- meta = i
- break
-
if doc.has_section('Returns') and 'command' not in expr:
raise QAPISemError(info, "'Returns:' is only valid for commands")
- if meta == 'union':
- args = expr.get('base', [])
- else:
- args = expr.get('data', [])
- if isinstance(args, str):
- return
- if isinstance(args, dict):
- args = args.keys()
- assert isinstance(args, list)
-
- if (meta == 'alternate'
- or (meta == 'union' and not expr.get('discriminator'))):
- args.append('type')
-
- doc_args = set(doc.args.keys())
- args = set([name.strip('*') for name in args])
- if not doc_args.issubset(args):
- raise QAPISemError(info, "The following documented members are not in "
- "the declaration: %s" % ', '.join(doc_args - args))
-
def check_docs(docs):
for doc in docs:
@@ -1268,6 +1252,8 @@ class QAPISchemaObjectType(QAPISchemaType):
self.variants.check(schema, seen)
assert self.variants.tag_member in self.members
self.variants.check_clash(schema, self.info, seen)
+ if self.doc:
+ self.doc.check()
# Check that the members of this type do not cause duplicate JSON members,
# and update seen to track the members seen so far. Report any errors
@@ -1437,6 +1423,8 @@ class QAPISchemaAlternateType(QAPISchemaType):
v.check_clash(self.info, seen)
if self.doc:
self.doc.connect_member(v)
+ if self.doc:
+ self.doc.check()
def c_type(self):
return c_name(self.name) + pointer_suffix
diff --git a/tests/qapi-schema/doc-bad-union-member.err
b/tests/qapi-schema/doc-bad-union-member.err
index e69de29..4b016df 100644
--- a/tests/qapi-schema/doc-bad-union-member.err
+++ b/tests/qapi-schema/doc-bad-union-member.err
@@ -0,0 +1 @@
+tests/qapi-schema/doc-bad-union-member.json:3: The following documented
members are not in the declaration: a, b
diff --git a/tests/qapi-schema/doc-bad-union-member.exit
b/tests/qapi-schema/doc-bad-union-member.exit
index 573541a..d00491f 100644
--- a/tests/qapi-schema/doc-bad-union-member.exit
+++ b/tests/qapi-schema/doc-bad-union-member.exit
@@ -1 +1 @@
-0
+1
diff --git a/tests/qapi-schema/doc-bad-union-member.out
b/tests/qapi-schema/doc-bad-union-member.out
index 2576ecd..e69de29 100644
--- a/tests/qapi-schema/doc-bad-union-member.out
+++ b/tests/qapi-schema/doc-bad-union-member.out
@@ -1,11 +0,0 @@
-object Base
- member type: T optional=False
-object Empty
-object Frob
- base Base
- tag type
- case nothing: Empty
-enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat',
'qbool']
- prefix QTYPE
-enum T ['nothing']
-object q_empty
--
2.7.4
- [Qemu-devel] [PATCH v2 for-2.9 45/47] qapi: Drop unused .check_clash() parameter schema, (continued)
- [Qemu-devel] [PATCH v2 for-2.9 45/47] qapi: Drop unused .check_clash() parameter schema, Markus Armbruster, 2017/03/15
- [Qemu-devel] [PATCH v2 for-2.9 44/47] qapi: union_types is a list used like a dict, make it one, Markus Armbruster, 2017/03/15
- [Qemu-devel] [PATCH v2 for-2.9 40/47] qapi: Simplify what gets stored in enum_types, Markus Armbruster, 2017/03/15
- [Qemu-devel] [PATCH v2 for-2.9 05/47] qapi: Have each QAPI schema declare its returns white-list, Markus Armbruster, 2017/03/15
- [Qemu-devel] [PATCH v2 for-2.9 35/47] tests/qapi-schema: Rename doc-bad-args to doc-bad-command-arg, Markus Armbruster, 2017/03/15
- [Qemu-devel] [PATCH v2 for-2.9 43/47] qapi: struct_types is a list used like a dict, make it one, Markus Armbruster, 2017/03/15
- [Qemu-devel] [PATCH v2 for-2.9 17/47] qapi: The #optional tag is redundant, drop, Markus Armbruster, 2017/03/15
- [Qemu-devel] [PATCH v2 for-2.9 41/47] qapi: Factor add_name() calls out of the meta conditional, Markus Armbruster, 2017/03/15
- [Qemu-devel] [PATCH v2 for-2.9 36/47] tests/qapi-schema: Improve coverage of bogus member docs, Markus Armbruster, 2017/03/15
- [Qemu-devel] [PATCH v2 for-2.9 37/47] qapi: Fix detection of bogus member documentation,
Markus Armbruster <=
- [Qemu-devel] [PATCH v2 for-2.9 47/47] qapi: Fix a misleading parser error message, Markus Armbruster, 2017/03/15
- [Qemu-devel] [PATCH v2 for-2.9 46/47] qapi: Make pylint a bit happier, Markus Armbruster, 2017/03/15
- [Qemu-devel] [PATCH v2 for-2.9 31/47] qapi: Fix detection of doc / expression mismatch, Markus Armbruster, 2017/03/15
- [Qemu-devel] [PATCH v2 for-2.9 38/47] qapi: Eliminate check_docs() and drop QAPIDoc.expr, Markus Armbruster, 2017/03/15
- [Qemu-devel] [PATCH v2 for-2.9 19/47] qapi: Prefer single-quoted strings more consistently, Markus Armbruster, 2017/03/15
- [Qemu-devel] [PATCH v2 for-2.9 03/47] qapi: Back out doc comments added just to please qapi.py, Markus Armbruster, 2017/03/15
- [Qemu-devel] [PATCH v2 for-2.9 30/47] tests/qapi-schema: Improve doc / expression mismatch coverage, Markus Armbruster, 2017/03/15