qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL for 2.9 33/49] qapi: Fix detection of doc / expression mismatch
Date: Thu, 16 Mar 2017 07:27:49 +0100	[thread overview]
Message-ID: <1489645685-4750-34-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1489645685-4750-1-git-send-email-armbru@redhat.com>

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>
---
 scripts/qapi.py                           | 35 +++++++++++++++++++------------
 tests/qapi-schema/doc-before-include.err  |  1 +
 tests/qapi-schema/doc-before-include.exit |  2 +-
 tests/qapi-schema/doc-before-include.json |  1 -
 tests/qapi-schema/doc-before-include.out  |  4 ----
 tests/qapi-schema/doc-before-pragma.err   |  1 +
 tests/qapi-schema/doc-before-pragma.exit  |  2 +-
 tests/qapi-schema/doc-before-pragma.json  |  1 -
 tests/qapi-schema/doc-before-pragma.out   |  4 ----
 tests/qapi-schema/doc-missing-expr.err    |  2 +-
 tests/qapi-schema/doc-no-symbol.err       |  2 +-
 tests/qapi-schema/doc-no-symbol.json      |  1 -
 12 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/scripts/qapi.py b/scripts/qapi.py
index 21a1591..37f2814 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 e69de29..a649d38 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 573541a..d00491f 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 ec1fbf2..0caa0ae 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 236a849..e69de29 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 e69de29..c0fb066 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 573541a..d00491f 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 fb2ec8e..a6e090e 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 236a849..e69de29 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 c0e687c..c909e26 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 727966c..75f032a 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 ee86ca1..98605ba 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:
-- 
2.7.4

  parent reply	other threads:[~2017-03-16  6:28 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-16  6:27 [Qemu-devel] [PULL for 2.9 00/49] QAPI patches for 2017-03-16 Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 01/49] qapi2texi: change texi formatters Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 02/49] qmp: allow setting properties to empty string in qmp-shell Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 03/49] qapi: Factor QAPISchemaParser._include() out of .__init__() Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 04/49] qapi: Make doc comments optional where we don't need them Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 05/49] qapi: Back out doc comments added just to please qapi.py Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 06/49] docs/qapi-code-gen.txt: Drop confusing reference to 'gen' Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 07/49] qapi: Have each QAPI schema declare its returns white-list Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 08/49] qapi: Have each QAPI schema declare its name rule violations Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 09/49] qapi: Clean up build of generated documentation Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 10/49] tests/qapi-schema: Cover empty union base Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 11/49] qapi: Fix to reject empty union base gracefully Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 12/49] qapi2texi: Fix up output around #optional Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 13/49] qapi: Avoid unwanted blank lines in QAPIDoc Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 14/49] qapi/rocker: Fix up doc comment notes on optional members Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 15/49] qapi: Fix QAPISchemaEnumType.is_implicit() for 'QType' Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 16/49] qapi: Prepare for requiring more complete documentation Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 17/49] qapi: Conjure up QAPIDoc.ArgSection for undocumented members Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 18/49] qapi2texi: Convert to QAPISchemaVisitor Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 19/49] qapi: The #optional tag is redundant, drop Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 20/49] qapi: Use raw strings for regular expressions consistently Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 21/49] qapi: Prefer single-quoted strings more consistently Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 22/49] qapi2texi: Plainer enum value and member name formatting Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 23/49] qapi2texi: Present the table of members more clearly Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 24/49] qapi2texi: Explain enum value undocumentedness " Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 25/49] qapi2texi: Don't hide undocumented members and arguments Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 26/49] qapi2texi: Implement boxed argument documentation Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 27/49] qapi2texi: Include member type in generated documentation Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 28/49] qapi2texi: Generate reference to base type members Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 29/49] qapi2texi: Generate documentation for variant members Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 30/49] qapi2texi: Generate descriptions for simple union tags Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 31/49] qapi2texi: Use category "Object" for all object types Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 32/49] tests/qapi-schema: Improve doc / expression mismatch coverage Markus Armbruster
2017-03-16  6:27 ` Markus Armbruster [this message]
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 34/49] qapi: Move detection of doc / expression name mismatch Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 35/49] qapi: Improve error message on @NAME: in free-form doc Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 36/49] qapi: Move empty doc section checking to doc parser Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 37/49] tests/qapi-schema: Rename doc-bad-args to doc-bad-command-arg Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 38/49] tests/qapi-schema: Improve coverage of bogus member docs Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 39/49] qapi: Fix detection of bogus member documentation Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 40/49] qapi: Eliminate check_docs() and drop QAPIDoc.expr Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 41/49] qapi: Drop unused variable events Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 42/49] qapi: Simplify what gets stored in enum_types Markus Armbruster
2017-03-16  6:27 ` [Qemu-devel] [PULL for 2.9 43/49] qapi: Factor add_name() calls out of the meta conditional Markus Armbruster
2017-03-16  6:28 ` [Qemu-devel] [PULL for 2.9 44/49] qapi: enum_types is a list used like a dict, make it one Markus Armbruster
2017-03-16  6:28 ` [Qemu-devel] [PULL for 2.9 45/49] qapi: struct_types " Markus Armbruster
2017-03-16  6:28 ` [Qemu-devel] [PULL for 2.9 46/49] qapi: union_types " Markus Armbruster
2017-03-16  6:28 ` [Qemu-devel] [PULL for 2.9 47/49] qapi: Drop unused .check_clash() parameter schema Markus Armbruster
2017-03-16  6:28 ` [Qemu-devel] [PULL for 2.9 48/49] qapi: Make pylint a bit happier Markus Armbruster
2017-03-16  6:28 ` [Qemu-devel] [PULL for 2.9 49/49] qapi: Fix a misleading parser error message Markus Armbruster
2017-03-16 14:22 ` [Qemu-devel] [PULL for 2.9 00/49] QAPI patches for 2017-03-16 Peter Maydell

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=1489645685-4750-34-git-send-email-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 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).