From nobody Thu Nov 6 16:05:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489387142822541.2023135397648; Sun, 12 Mar 2017 23:39:02 -0700 (PDT) Received: from localhost ([::1]:50442 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnJdF-0006nT-E0 for importer@patchew.org; Mon, 13 Mar 2017 02:39:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnJJr-0007bC-0b for qemu-devel@nongnu.org; Mon, 13 Mar 2017 02:19:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnJJm-0003eN-Kl for qemu-devel@nongnu.org; Mon, 13 Mar 2017 02:18:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59482) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnJJm-0003bG-6L for qemu-devel@nongnu.org; Mon, 13 Mar 2017 02:18:54 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2C8BE3A768B; Mon, 13 Mar 2017 06:18:54 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2D6IqMC003268 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 02:18:53 -0400 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7980111384B5; Mon, 13 Mar 2017 07:18:47 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 13 Mar 2017 07:18:31 +0100 Message-Id: <1489385927-6735-32-git-send-email-armbru@redhat.com> In-Reply-To: <1489385927-6735-1-git-send-email-armbru@redhat.com> References: <1489385927-6735-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 13 Mar 2017 06:18:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.9 31/47] qapi: Fix detection of doc / expression mismatch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This fixes the errors uncovered by the previous commit. Signed-off-by: Markus Armbruster --- scripts/qapi.py | 34 +++++++++++++++++++++---------= ---- tests/qapi-schema/doc-bad-expr.err | 1 + tests/qapi-schema/doc-bad-expr.exit | 2 +- tests/qapi-schema/doc-bad-expr.json | 1 - tests/qapi-schema/doc-bad-expr.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 - 8 files changed, 25 insertions(+), 22 deletions(-) diff --git a/scripts/qapi.py b/scripts/qapi.py index b82a2a6..1052274 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -248,18 +248,21 @@ class QAPISchemaParser(object): self.line_pos =3D 0 self.exprs =3D [] self.docs =3D [] + self.cur_doc =3D None self.accept() =20 while self.tok is not None: info =3D {'file': fname, 'line': self.line, 'parent': self.incl_info} if self.tok =3D=3D '#': - doc =3D self.get_doc(info) - self.docs.append(doc) + self.reject_expr_doc() + self.cur_doc =3D self.get_doc(info) + self.docs.append(self.cur_doc) continue =20 expr =3D self.get_expr(False) if 'include' in expr: + self.reject_expr_doc() if len(expr) !=3D 1: raise QAPISemError(info, "Invalid 'include' directive") include =3D expr['include'] @@ -276,13 +279,23 @@ class QAPISchemaParser(object): else: expr_elem =3D {'expr': expr, 'info': info} - if (self.docs - and self.docs[-1].info['file'] =3D=3D fname - and not self.docs[-1].expr): - self.docs[-1].expr =3D expr - expr_elem['doc'] =3D 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 =3D expr + expr_elem['doc'] =3D self.cur_doc self.exprs.append(expr_elem) + self.cur_doc =3D 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) =20 def _include(self, include, info, base_dir, previously_included): incl_abs_fname =3D os.path.join(base_dir, include) @@ -946,11 +959,6 @@ def check_exprs(exprs): =20 =20 def check_freeform_doc(doc): - if doc.symbol: - raise QAPISemError(doc.info, - "Documention for '%s' is not followed" - " by the definition" % doc.symbol) - body =3D str(doc.body) if re.search(r'@\S+:', body, re.MULTILINE): raise QAPISemError(doc.info, diff --git a/tests/qapi-schema/doc-bad-expr.err b/tests/qapi-schema/doc-bad= -expr.err index e69de29..65e9d1f 100644 --- a/tests/qapi-schema/doc-bad-expr.err +++ b/tests/qapi-schema/doc-bad-expr.err @@ -0,0 +1 @@ +tests/qapi-schema/doc-bad-expr.json:3: Documentation for 'foo' is not foll= owed by the definition diff --git a/tests/qapi-schema/doc-bad-expr.exit b/tests/qapi-schema/doc-ba= d-expr.exit index 573541a..d00491f 100644 --- a/tests/qapi-schema/doc-bad-expr.exit +++ b/tests/qapi-schema/doc-bad-expr.exit @@ -1 +1 @@ -0 +1 diff --git a/tests/qapi-schema/doc-bad-expr.json b/tests/qapi-schema/doc-ba= d-expr.json index ec1fbf2..0caa0ae 100644 --- a/tests/qapi-schema/doc-bad-expr.json +++ b/tests/qapi-schema/doc-bad-expr.json @@ -1,5 +1,4 @@ # Doc comment separated from defining expression by non-defining expression -# BUG: not rejected =20 ## # @foo: diff --git a/tests/qapi-schema/doc-bad-expr.out b/tests/qapi-schema/doc-bad= -expr.out index 236a849..e69de29 100644 --- a/tests/qapi-schema/doc-bad-expr.out +++ b/tests/qapi-schema/doc-bad-expr.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 fo= llowed 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 docume= ntation 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-n= o-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' =20 ## # foo: --=20 2.7.4