Marc-André Lureau <marcandre.lur...@gmail.com> writes: > Hi > > On Tue, Jul 3, 2018 at 2:09 PM, Markus Armbruster <arm...@redhat.com> wrote: >> Marc-André Lureau <marcandre.lur...@redhat.com> writes: >> >>> The generator will take (obj, condition) tuples to wrap generated QLit >>> objects for 'obj' with #if/#endif conditions. >>> >>> This commit adds 'ifcond' condition to top-level QLit objects. >>> >>> See generated tests/test-qmp-introspect.c. Example diff after this patch: >>> >>> --- before 2018-01-08 11:55:24.757083654 +0100 >>> +++ tests/test-qmp-introspect.c 2018-01-08 13:08:44.477641629 +0100 >>> @@ -51,6 +51,8 @@ >>> { "name", QLIT_QSTR("EVENT_F"), }, >>> {} >>> })), >>> +#if defined(TEST_IF_CMD) >>> +#if defined(TEST_IF_STRUCT) >>> QLIT_QDICT(((QLitDictEntry[]) { >>> { "arg-type", QLIT_QSTR("5"), }, >>> { "meta-type", QLIT_QSTR("command"), }, >>> @@ -58,12 +60,16 @@ >>> { "ret-type", QLIT_QSTR("0"), }, >>> {} >>> })), >>> +#endif /* defined(TEST_IF_STRUCT) */ >>> +#endif /* defined(TEST_IF_CMD) */ >>> >>> Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> >>> --- >>> scripts/qapi/introspect.py | 31 +++++++++++++++++++++---------- >>> 1 file changed, 21 insertions(+), 10 deletions(-) >>> >>> diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py >>> index bd7e1219be..71d4a779ce 100644 >>> --- a/scripts/qapi/introspect.py >>> +++ b/scripts/qapi/introspect.py >>> @@ -18,6 +18,15 @@ def to_qlit(obj, level=0, suppress_first_indent=False): >>> def indent(level): >>> return level * 4 * ' ' >>> >>> + if isinstance(obj, tuple): >>> + ifobj, ifcond = obj >>> + ret = gen_if(ifcond) >>> + ret += to_qlit(ifobj, level) >>> + endif = gen_endif(ifcond) >>> + if endif: >>> + ret += '\n' + endif >>> + return ret >>> + >>> ret = '' >>> if not suppress_first_indent: >>> ret += indent(level) >> >> @obj represents a JSON object. It consists of dictionaries, lists, >> strings, booleans and None. Numbers aren't implemented. Your patch >> splices in tuples to represent conditionals at any level. >> >> So far, tuples occur only as elements of the outermost list (see >> ._gen_qlit() below), but to_qlit() supports them anywhere. I figure >> that will be needed later. Can you point me to such a later use? > > It's added in the introspect.py part from "qapi: add #if conditions to > generated code members"
Thanks! Let's add a hint to the commit message. Pergaps: qapi-introspect: add preprocessor conditions to generated QLit This commit adds 'ifcond' conditions to top-level QLit objects. Future work will add them to object and enum type members, i.e. within QLit objects. Extend the QLit generator to_qlit() to accept (@obj, @cond) tuples in addition to just @obj. The tuple causes the QLit generated for objects for @obj with #if/#endif conditions for @cond. See generated tests/test-qmp-introspect.c. Example diff after this patch: [...]