From nobody Mon Feb 9 16:44:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1629981537; cv=none; d=zohomail.com; s=zohoarc; b=IeIqvlOlgJzi8JUR7qky2Y1OzY2yZ39uNDNFNiO5v0q5H8bAnhKWVejLLpCOMHK/yB64x7hnw4sXe1jkZEkqOuAzEctB2TetZmWucHkT4WzTpSPAjlATR6bmpdEhURH/+M0ZifZiBaEZ6qWUKcOtg8EDsfc/EGJ5tOpjApXV0KA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629981537; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=V1+I+ZEjd1RdE1fUCXAXh/uFGkFrTb3/VKlu+KCr0xc=; b=hGVM6no6ShSpSfxCBLfkt7c8yfTAlUo7APtWOk28A1AH5VG9IWKikxSoHp00BH1kj7D6Sr7uncReJ1eF4c+HWsnwH2b1hNmM4MUyaongiRFcBOHVhtndPbb1Vaw3qSnUiRZAm9YlOySS+BQ0P4/mrTAQ3SBkyjJcou2Up9vBa3s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1629981537471135.14237392826794; Thu, 26 Aug 2021 05:38:57 -0700 (PDT) Received: from localhost ([::1]:58730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJEem-00030u-Ge for importer@patchew.org; Thu, 26 Aug 2021 08:38:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJEYm-0004Aj-D7 for qemu-devel@nongnu.org; Thu, 26 Aug 2021 08:32:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59766) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJEYh-0008Bc-UD for qemu-devel@nongnu.org; Thu, 26 Aug 2021 08:32:44 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-388-6hBjrGc2NzaBHi2Q-Yl58w-1; Thu, 26 Aug 2021 08:32:33 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 63DE61008065; Thu, 26 Aug 2021 12:32:32 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-4.ams2.redhat.com [10.36.112.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BCDD160583; Thu, 26 Aug 2021 12:32:28 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id AA35A11380B9; Thu, 26 Aug 2021 14:32:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629981154; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V1+I+ZEjd1RdE1fUCXAXh/uFGkFrTb3/VKlu+KCr0xc=; b=K1FWrG17vZslsZfiqs2toben1y2stKGkGlr8zUajg07tZ8PURp5nC68yxylHuj37CMVyCu Ib36pxtVI9WFD3Q6L9bbr9GE7qp2NM9x2bWIWOUooFjGLnAQboMAQdFhOkeg3Af7seMcNv 1NxhCssQpiI9IvLiAgqpob7W4Y3NtbA= X-MC-Unique: 6hBjrGc2NzaBHi2Q-Yl58w-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 06/11] qapidoc: introduce QAPISchemaIfCond.docgen() Date: Thu, 26 Aug 2021 14:32:20 +0200 Message-Id: <20210826123225.157891-7-armbru@redhat.com> In-Reply-To: <20210826123225.157891-1-armbru@redhat.com> References: <20210826123225.157891-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629981537957100002 From: Marc-Andr=C3=A9 Lureau Instead of building the condition documentation from a list of string, use the result generated from QAPISchemaIfCond.docgen(). This changes the generated documentation from: - COND1, COND2... (where COND1, COND2 are Literal nodes, and ',' is Text) to: - COND1 and COND2 (the whole string as a Literal node) This will allow us to generate more complex conditions in the following patches, such as "(COND1 and COND2) or COND3". Adding back the differentiated formatting is left to the wish list. Signed-off-by: Marc-Andr=C3=A9 Lureau Message-Id: <20210804083105.97531-6-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster [TODO comment added] Signed-off-by: Markus Armbruster --- docs/sphinx/qapidoc.py | 14 ++++++++------ scripts/qapi/common.py | 7 +++++++ scripts/qapi/schema.py | 10 +++++++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/docs/sphinx/qapidoc.py b/docs/sphinx/qapidoc.py index 511520f33f..d791b59492 100644 --- a/docs/sphinx/qapidoc.py +++ b/docs/sphinx/qapidoc.py @@ -112,17 +112,19 @@ def _make_section(self, title): def _nodes_for_ifcond(self, ifcond, with_if=3DTrue): """Return list of Text, literal nodes for the ifcond =20 - Return a list which gives text like ' (If: cond1, cond2, cond3)', = where - the conditions are in literal-text and the commas are not. + Return a list which gives text like ' (If: condition)'. If with_if is False, we don't return the "(If: " and ")". """ - condlist =3D intersperse([nodes.literal('', c) for c in ifcond.ifc= ond], - nodes.Text(', ')) + + doc =3D ifcond.docgen() + if not doc: + return [] + doc =3D nodes.literal('', doc) if not with_if: - return condlist + return [doc] =20 nodelist =3D [nodes.Text(' ('), nodes.strong('', 'If: ')] - nodelist.extend(condlist) + nodelist.append(doc) nodelist.append(nodes.Text(')')) return nodelist =20 diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index ba9fe14e4b..ddc54e4368 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -205,6 +205,13 @@ def cgen_ifcond(ifcond: Union[str, List[str]]) -> str: return '(' + ') && ('.join(ifcond) + ')' =20 =20 +def docgen_ifcond(ifcond: Union[str, List[str]]) -> str: + # TODO Doc generated for conditions needs polish + if not ifcond: + return '' + return ' and '.join(ifcond) + + def gen_if(cond: str) -> str: if not cond: return '' diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 4ea7e88846..a9345af7b7 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -19,7 +19,12 @@ import re from typing import Optional =20 -from .common import POINTER_SUFFIX, c_name, cgen_ifcond +from .common import ( + POINTER_SUFFIX, + c_name, + cgen_ifcond, + docgen_ifcond, +) from .error import QAPIError, QAPISemError, QAPISourceError from .expr import check_exprs from .parser import QAPISchemaParser @@ -32,6 +37,9 @@ def __init__(self, ifcond=3DNone): def cgen(self): return cgen_ifcond(self.ifcond) =20 + def docgen(self): + return docgen_ifcond(self.ifcond) + def is_present(self): return bool(self.ifcond) =20 --=20 2.31.1