mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-31 14:23:53 -06:00
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>
This commit is contained in:
parent
2028be8eea
commit
e7823a2adf
12 changed files with 28 additions and 28 deletions
|
@ -248,18 +248,21 @@ class QAPISchemaParser(object):
|
||||||
self.line_pos = 0
|
self.line_pos = 0
|
||||||
self.exprs = []
|
self.exprs = []
|
||||||
self.docs = []
|
self.docs = []
|
||||||
|
self.cur_doc = None
|
||||||
self.accept()
|
self.accept()
|
||||||
|
|
||||||
while self.tok is not None:
|
while self.tok is not None:
|
||||||
info = {'file': fname, 'line': self.line,
|
info = {'file': fname, 'line': self.line,
|
||||||
'parent': self.incl_info}
|
'parent': self.incl_info}
|
||||||
if self.tok == '#':
|
if self.tok == '#':
|
||||||
doc = self.get_doc(info)
|
self.reject_expr_doc()
|
||||||
self.docs.append(doc)
|
self.cur_doc = self.get_doc(info)
|
||||||
|
self.docs.append(self.cur_doc)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
expr = self.get_expr(False)
|
expr = self.get_expr(False)
|
||||||
if 'include' in expr:
|
if 'include' in expr:
|
||||||
|
self.reject_expr_doc()
|
||||||
if len(expr) != 1:
|
if len(expr) != 1:
|
||||||
raise QAPISemError(info, "Invalid 'include' directive")
|
raise QAPISemError(info, "Invalid 'include' directive")
|
||||||
include = expr['include']
|
include = expr['include']
|
||||||
|
@ -269,6 +272,7 @@ class QAPISchemaParser(object):
|
||||||
self._include(include, info, os.path.dirname(abs_fname),
|
self._include(include, info, os.path.dirname(abs_fname),
|
||||||
previously_included)
|
previously_included)
|
||||||
elif "pragma" in expr:
|
elif "pragma" in expr:
|
||||||
|
self.reject_expr_doc()
|
||||||
if len(expr) != 1:
|
if len(expr) != 1:
|
||||||
raise QAPISemError(info, "Invalid 'pragma' directive")
|
raise QAPISemError(info, "Invalid 'pragma' directive")
|
||||||
pragma = expr['pragma']
|
pragma = expr['pragma']
|
||||||
|
@ -280,13 +284,23 @@ class QAPISchemaParser(object):
|
||||||
else:
|
else:
|
||||||
expr_elem = {'expr': expr,
|
expr_elem = {'expr': expr,
|
||||||
'info': info}
|
'info': info}
|
||||||
if (self.docs
|
if self.cur_doc:
|
||||||
and self.docs[-1].info['file'] == fname
|
if not self.cur_doc.symbol:
|
||||||
and not self.docs[-1].expr):
|
raise QAPISemError(
|
||||||
self.docs[-1].expr = expr
|
self.cur_doc.info,
|
||||||
expr_elem['doc'] = self.docs[-1]
|
"Expression documentation required")
|
||||||
|
self.cur_doc.expr = expr
|
||||||
|
expr_elem['doc'] = self.cur_doc
|
||||||
self.exprs.append(expr_elem)
|
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):
|
def _include(self, include, info, base_dir, previously_included):
|
||||||
incl_abs_fname = os.path.join(base_dir, include)
|
incl_abs_fname = os.path.join(base_dir, include)
|
||||||
|
@ -950,11 +964,6 @@ def check_exprs(exprs):
|
||||||
|
|
||||||
|
|
||||||
def check_freeform_doc(doc):
|
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)
|
body = str(doc.body)
|
||||||
if re.search(r'@\S+:', body, re.MULTILINE):
|
if re.search(r'@\S+:', body, re.MULTILINE):
|
||||||
raise QAPISemError(doc.info,
|
raise QAPISemError(doc.info,
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
tests/qapi-schema/doc-before-include.json:3: Documentation for 'foo' is not followed by the definition
|
|
@ -1 +1 @@
|
||||||
0
|
1
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
# Doc comment separated from defining expression by non-defining expression
|
# Doc comment separated from defining expression by non-defining expression
|
||||||
# BUG: not rejected
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# @foo:
|
# @foo:
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbool']
|
|
||||||
prefix QTYPE
|
|
||||||
object foo
|
|
||||||
object q_empty
|
|
|
@ -0,0 +1 @@
|
||||||
|
tests/qapi-schema/doc-before-pragma.json:3: Documentation for 'foo' is not followed by the definition
|
|
@ -1 +1 @@
|
||||||
0
|
1
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
# Doc comment separated from defining expression by non-defining expression
|
# Doc comment separated from defining expression by non-defining expression
|
||||||
# BUG: not rejected
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# @foo:
|
# @foo:
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
enum QType ['none', 'qnull', 'qint', 'qstring', 'qdict', 'qlist', 'qfloat', 'qbool']
|
|
||||||
prefix QTYPE
|
|
||||||
object foo
|
|
||||||
object q_empty
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
# Documentation for expression lacks symbol
|
# Documentation for expression lacks symbol
|
||||||
# BUG: Error message claims it has symbol 'None'
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# foo:
|
# foo:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue