aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2017-03-15 13:57:20 +0100
committerMarkus Armbruster <armbru@redhat.com>2017-03-16 07:13:03 +0100
commite7823a2adf7222d0513b8e7cfd8af85d407d4918 (patch)
treeed25b9f488b11f23325753213697cd9abd9d34b7
parent2028be8eeaa5334ce63fbf625942c6d52c6dac28 (diff)
qapi: Fix detection of doc / expression mismatch
This fixes the errors uncovered by the previous commit. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <1489582656-31133-32-git-send-email-armbru@redhat.com>
-rw-r--r--scripts/qapi.py35
-rw-r--r--tests/qapi-schema/doc-before-include.err1
-rw-r--r--tests/qapi-schema/doc-before-include.exit2
-rw-r--r--tests/qapi-schema/doc-before-include.json1
-rw-r--r--tests/qapi-schema/doc-before-include.out4
-rw-r--r--tests/qapi-schema/doc-before-pragma.err1
-rw-r--r--tests/qapi-schema/doc-before-pragma.exit2
-rw-r--r--tests/qapi-schema/doc-before-pragma.json1
-rw-r--r--tests/qapi-schema/doc-before-pragma.out4
-rw-r--r--tests/qapi-schema/doc-missing-expr.err2
-rw-r--r--tests/qapi-schema/doc-no-symbol.err2
-rw-r--r--tests/qapi-schema/doc-no-symbol.json1
12 files changed, 28 insertions, 28 deletions
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 21a15918dc..37f28146eb 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -248,18 +248,21 @@ class QAPISchemaParser(object):
self.line_pos = 0
self.exprs = []
self.docs = []
+ self.cur_doc = None
self.accept()
while self.tok is not None:
info = {'file': fname, 'line': self.line,
'parent': self.incl_info}
if self.tok == '#':
- doc = self.get_doc(info)
- self.docs.append(doc)
+ self.reject_expr_doc()
+ self.cur_doc = self.get_doc(info)
+ self.docs.append(self.cur_doc)
continue
expr = self.get_expr(False)
if 'include' in expr:
+ self.reject_expr_doc()
if len(expr) != 1:
raise QAPISemError(info, "Invalid 'include' directive")
include = expr['include']
@@ -269,6 +272,7 @@ class QAPISchemaParser(object):
self._include(include, info, os.path.dirname(abs_fname),
previously_included)
elif "pragma" in expr:
+ self.reject_expr_doc()
if len(expr) != 1:
raise QAPISemError(info, "Invalid 'pragma' directive")
pragma = expr['pragma']
@@ -280,13 +284,23 @@ class QAPISchemaParser(object):
else:
expr_elem = {'expr': expr,
'info': info}
- if (self.docs
- and self.docs[-1].info['file'] == fname
- and not self.docs[-1].expr):
- self.docs[-1].expr = expr
- expr_elem['doc'] = self.docs[-1]
-
+ if self.cur_doc:
+ if not self.cur_doc.symbol:
+ raise QAPISemError(
+ self.cur_doc.info,
+ "Expression documentation required")
+ self.cur_doc.expr = expr
+ expr_elem['doc'] = self.cur_doc
self.exprs.append(expr_elem)
+ self.cur_doc = None
+ self.reject_expr_doc()
+
+ def reject_expr_doc(self):
+ if self.cur_doc and self.cur_doc.symbol:
+ raise QAPISemError(
+ self.cur_doc.info,
+ "Documentation for '%s' is not followed by the definition"
+ % self.cur_doc.symbol)
def _include(self, include, info, base_dir, previously_included):
incl_abs_fname = os.path.join(base_dir, include)
@@ -950,11 +964,6 @@ def check_exprs(exprs):
def check_freeform_doc(doc):
- if doc.symbol:
- raise QAPISemError(doc.info,
- "Documention for '%s' is not followed"
- " by the definition" % doc.symbol)
-
body = str(doc.body)
if re.search(r'@\S+:', body, re.MULTILINE):
raise QAPISemError(doc.info,
diff --git a/tests/qapi-schema/doc-before-include.err b/tests/qapi-schema/doc-before-include.err
index e69de29bb2..a649d38a63 100644
--- a/tests/qapi-schema/doc-before-include.err
+++ b/tests/qapi-schema/doc-before-include.err
@@ -0,0 +1 @@
+tests/qapi-schema/doc-before-include.json:3: Documentation for 'foo' is not followed by the definition
diff --git a/tests/qapi-schema/doc-before-include.exit b/tests/qapi-schema/doc-before-include.exit
index 573541ac97..d00491fd7e 100644
--- a/tests/qapi-schema/doc-before-include.exit
+++ b/tests/qapi-schema/doc-before-include.exit
@@ -1 +1 @@
-0
+1
diff --git a/tests/qapi-schema/doc-before-include.json b/tests/qapi-schema/doc-before-include.json
index ec1fbf275f..0caa0ae079 100644
--- a/tests/qapi-schema/doc-before-include.json
+++ b/tests/qapi-schema/doc-before-include.json
@@ -1,5 +1,4 @@
# Doc comment separated from defining expression by non-defining expression
-# BUG: not rejected
##
# @foo:
diff --git a/tests/qapi-schema/doc-before-include.out b/tests/qapi-schema/doc-before-include.out
index 236a849d48..e69de29bb2 100644
--- a/tests/qapi-schema/doc-before-include.out
+++ b/tests/qapi-schema/doc-before-include.out
@@ -1,4 +0,0 @@
-enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbool']
- prefix QTYPE
-object foo
-object q_empty
diff --git a/tests/qapi-schema/doc-before-pragma.err b/tests/qapi-schema/doc-before-pragma.err
index e69de29bb2..c0fb0660d1 100644
--- a/tests/qapi-schema/doc-before-pragma.err
+++ b/tests/qapi-schema/doc-before-pragma.err
@@ -0,0 +1 @@
+tests/qapi-schema/doc-before-pragma.json:3: Documentation for 'foo' is not followed by the definition
diff --git a/tests/qapi-schema/doc-before-pragma.exit b/tests/qapi-schema/doc-before-pragma.exit
index 573541ac97..d00491fd7e 100644
--- a/tests/qapi-schema/doc-before-pragma.exit
+++ b/tests/qapi-schema/doc-before-pragma.exit
@@ -1 +1 @@
-0
+1
diff --git a/tests/qapi-schema/doc-before-pragma.json b/tests/qapi-schema/doc-before-pragma.json
index fb2ec8e3fb..a6e090e44a 100644
--- a/tests/qapi-schema/doc-before-pragma.json
+++ b/tests/qapi-schema/doc-before-pragma.json
@@ -1,5 +1,4 @@
# Doc comment separated from defining expression by non-defining expression
-# BUG: not rejected
##
# @foo:
diff --git a/tests/qapi-schema/doc-before-pragma.out b/tests/qapi-schema/doc-before-pragma.out
index 236a849d48..e69de29bb2 100644
--- a/tests/qapi-schema/doc-before-pragma.out
+++ b/tests/qapi-schema/doc-before-pragma.out
@@ -1,4 +0,0 @@
-enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbool']
- prefix QTYPE
-object foo
-object q_empty
diff --git a/tests/qapi-schema/doc-missing-expr.err b/tests/qapi-schema/doc-missing-expr.err
index c0e687cadd..c909e26eca 100644
--- a/tests/qapi-schema/doc-missing-expr.err
+++ b/tests/qapi-schema/doc-missing-expr.err
@@ -1 +1 @@
-tests/qapi-schema/doc-missing-expr.json:3: Documention for 'bar' is not followed by the definition
+tests/qapi-schema/doc-missing-expr.json:3: Documentation for 'bar' is not followed by the definition
diff --git a/tests/qapi-schema/doc-no-symbol.err b/tests/qapi-schema/doc-no-symbol.err
index 727966cc0c..75f032a942 100644
--- a/tests/qapi-schema/doc-no-symbol.err
+++ b/tests/qapi-schema/doc-no-symbol.err
@@ -1 +1 @@
-tests/qapi-schema/doc-no-symbol.json:4: Definition of 'foo' follows documentation for 'None'
+tests/qapi-schema/doc-no-symbol.json:3: Expression documentation required
diff --git a/tests/qapi-schema/doc-no-symbol.json b/tests/qapi-schema/doc-no-symbol.json
index ee86ca184b..98605bab96 100644
--- a/tests/qapi-schema/doc-no-symbol.json
+++ b/tests/qapi-schema/doc-no-symbol.json
@@ -1,5 +1,4 @@
# Documentation for expression lacks symbol
-# BUG: Error message claims it has symbol 'None'
##
# foo: