Skip to content

Commit 3248c1a

Browse files
elmarcoMarkus Armbruster
authored andcommitted
docs: update the documentation upfront about schema configuration
Update the documentation describing the changes in this series. Signed-off-by: Marc-André Lureau <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]> Tested-by: John Snow <[email protected]> Reviewed-by: Markus Armbruster <[email protected]> Message-Id: <[email protected]> [Rebased with straightforward conflicts] Signed-off-by: Markus Armbruster <[email protected]>
1 parent b32abbb commit 3248c1a

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

docs/devel/qapi-code-gen.rst

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -826,25 +826,31 @@ Configuring the schema
826826
Syntax::
827827

828828
COND = STRING
829-
| [ STRING, ... ]
829+
| { 'all: [ COND, ... ] }
830+
| { 'any: [ COND, ... ] }
831+
| { 'not': COND }
830832

831833
All definitions take an optional 'if' member. Its value must be a
832-
string or a list of strings. A string is shorthand for a list
833-
containing just that string. The code generated for the definition
834-
will then be guarded by #if STRING for each STRING in the COND list.
834+
string, or an object with a single member 'all', 'any' or 'not'.
835+
836+
The C code generated for the definition will then be guarded by an #if
837+
preprocessing directive with an operand generated from that condition:
838+
839+
* STRING will generate defined(STRING)
840+
* { 'all': [COND, ...] } will generate (COND && ...)
841+
* { 'any': [COND, ...] } will generate (COND || ...)
842+
* { 'not': COND } will generate !COND
835843

836844
Example: a conditional struct ::
837845

838846
{ 'struct': 'IfStruct', 'data': { 'foo': 'int' },
839-
'if': ['defined(CONFIG_FOO)', 'defined(HAVE_BAR)'] }
847+
'if': { 'all': [ 'CONFIG_FOO', 'HAVE_BAR' ] } }
840848

841849
gets its generated code guarded like this::
842850

843-
#if defined(CONFIG_FOO)
844-
#if defined(HAVE_BAR)
851+
#if defined(CONFIG_FOO) && defined(HAVE_BAR)
845852
... generated code ...
846-
#endif /* defined(HAVE_BAR) */
847-
#endif /* defined(CONFIG_FOO) */
853+
#endif /* defined(HAVE_BAR) && defined(CONFIG_FOO) */
848854

849855
Individual members of complex types, commands arguments, and
850856
event-specific data can also be made conditional. This requires the
@@ -855,7 +861,7 @@ member 'bar' ::
855861

856862
{ 'struct': 'IfStruct', 'data':
857863
{ 'foo': 'int',
858-
'bar': { 'type': 'int', 'if': 'defined(IFCOND)'} } }
864+
'bar': { 'type': 'int', 'if': 'IFCOND'} } }
859865

860866
A union's discriminator may not be conditional.
861867

@@ -867,7 +873,7 @@ value 'bar' ::
867873

868874
{ 'enum': 'IfEnum', 'data':
869875
[ 'foo',
870-
{ 'name' : 'bar', 'if': 'defined(IFCOND)' } ] }
876+
{ 'name' : 'bar', 'if': 'IFCOND' } ] }
871877

872878
Likewise, features can be conditional. This requires the longhand
873879
form of FEATURE_.
@@ -877,7 +883,7 @@ Example: a struct with conditional feature 'allow-negative-numbers' ::
877883
{ 'struct': 'TestType',
878884
'data': { 'number': 'int' },
879885
'features': [ { 'name': 'allow-negative-numbers',
880-
'if': 'defined(IFCOND)' } ] }
886+
'if': 'IFCOND' } ] }
881887

882888
Please note that you are responsible to ensure that the C code will
883889
compile with an arbitrary combination of conditions, since the

0 commit comments

Comments
 (0)