From nobody Mon Feb 9 19:30:32 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1629981360114110.33259164259528; Thu, 26 Aug 2021 05:36:00 -0700 (PDT) Received: from localhost ([::1]:52172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJEbu-000705-VW for importer@patchew.org; Thu, 26 Aug 2021 08:35:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJEYn-0004Ak-7s for qemu-devel@nongnu.org; Thu, 26 Aug 2021 08:32:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:35366) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJEYi-0008C1-6k for qemu-devel@nongnu.org; Thu, 26 Aug 2021 08:32:45 -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-3-kKe2Hxn-NhqQMfO-VXJlWQ-1; Thu, 26 Aug 2021 08:32:35 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A578E87D541; Thu, 26 Aug 2021 12:32:34 +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 0B6D95C1D5; Thu, 26 Aug 2021 12:32:27 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 9C32111380AB; 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=1629981157; 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=PsTutcg/lRrtWDE4iFDlyr/ZBBbqmo2DXv8ZTmGwZcM=; b=Qk8kX5g5XQYoYdwETb31QriebPumfohDtEtLINAWrKSLpth+joUPKHvlXyfYOrPLGuvwNY X2rPYBFbygNlHLS1vvp66fqTA/J1KavXHQ+GlagVU/rm23BHdUhrClD1UJy+CdCF6pRd3i KnbJjTBQHdivZFst4z+RclmcUqrcvfc= X-MC-Unique: kKe2Hxn-NhqQMfO-VXJlWQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 02/11] docs: update the documentation upfront about schema configuration Date: Thu, 26 Aug 2021 14:32:16 +0200 Message-Id: <20210826123225.157891-3-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.16 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.129.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, 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, John Snow , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1629981360845100002 From: Marc-Andr=C3=A9 Lureau Update the documentation describing the changes in this series. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Stefan Hajnoczi Tested-by: John Snow Reviewed-by: Markus Armbruster Message-Id: <20210804083105.97531-2-marcandre.lureau@redhat.com> [Rebased with straightforward conflicts] Signed-off-by: Markus Armbruster --- docs/devel/qapi-code-gen.rst | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst index 26c62b0e7b..ced7a5ffe1 100644 --- a/docs/devel/qapi-code-gen.rst +++ b/docs/devel/qapi-code-gen.rst @@ -826,25 +826,31 @@ Configuring the schema Syntax:: =20 COND =3D STRING - | [ STRING, ... ] + | { 'all: [ COND, ... ] } + | { 'any: [ COND, ... ] } + | { 'not': COND } =20 All definitions take an optional 'if' member. Its value must be a -string or a list of strings. A string is shorthand for a list -containing just that string. The code generated for the definition -will then be guarded by #if STRING for each STRING in the COND list. +string, or an object with a single member 'all', 'any' or 'not'. + +The C code generated for the definition will then be guarded by an #if +preprocessing directive with an operand generated from that condition: + + * STRING will generate defined(STRING) + * { 'all': [COND, ...] } will generate (COND && ...) + * { 'any': [COND, ...] } will generate (COND || ...) + * { 'not': COND } will generate !COND =20 Example: a conditional struct :: =20 { 'struct': 'IfStruct', 'data': { 'foo': 'int' }, - 'if': ['defined(CONFIG_FOO)', 'defined(HAVE_BAR)'] } + 'if': { 'all': [ 'CONFIG_FOO', 'HAVE_BAR' ] } } =20 gets its generated code guarded like this:: =20 - #if defined(CONFIG_FOO) - #if defined(HAVE_BAR) + #if defined(CONFIG_FOO) && defined(HAVE_BAR) ... generated code ... - #endif /* defined(HAVE_BAR) */ - #endif /* defined(CONFIG_FOO) */ + #endif /* defined(HAVE_BAR) && defined(CONFIG_FOO) */ =20 Individual members of complex types, commands arguments, and event-specific data can also be made conditional. This requires the @@ -855,7 +861,7 @@ member 'bar' :: =20 { 'struct': 'IfStruct', 'data': { 'foo': 'int', - 'bar': { 'type': 'int', 'if': 'defined(IFCOND)'} } } + 'bar': { 'type': 'int', 'if': 'IFCOND'} } } =20 A union's discriminator may not be conditional. =20 @@ -867,7 +873,7 @@ value 'bar' :: =20 { 'enum': 'IfEnum', 'data': [ 'foo', - { 'name' : 'bar', 'if': 'defined(IFCOND)' } ] } + { 'name' : 'bar', 'if': 'IFCOND' } ] } =20 Likewise, features can be conditional. This requires the longhand form of FEATURE_. @@ -877,7 +883,7 @@ Example: a struct with conditional feature 'allow-negat= ive-numbers' :: { 'struct': 'TestType', 'data': { 'number': 'int' }, 'features': [ { 'name': 'allow-negative-numbers', - 'if': 'defined(IFCOND)' } ] } + 'if': 'IFCOND' } ] } =20 Please note that you are responsible to ensure that the C code will compile with an arbitrary combination of conditions, since the --=20 2.31.1