qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v4 05/51] qapi: add 'if' to top-level expression


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH v4 05/51] qapi: add 'if' to top-level expressions
Date: Mon, 05 Feb 2018 07:12:51 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)

Marc-André Lureau <address@hidden> writes:

> Accept 'if' key in top-level elements, accepted as string or list of
> string type. The following patches will modify the test visitor to
> check the value is correctly saved, and generate #if/#endif code (as a
> single #if/endif line or a series for a list).
>
> Example of 'if' key:
> { 'struct': 'TestIfStruct', 'data': { 'foo': 'int' },
>   'if': 'defined(TEST_IF_STRUCT)' }
>
> The generated code is for now *unconditional*. Later patches generate
> the conditionals.
>
> A following patch for qapi-code-gen.txt will provide more complete
> documentation for 'if' usage.
>
> Signed-off-by: Marc-André Lureau <address@hidden>
> Reviewed-by: Markus Armbruster <address@hidden>
> ---
>  scripts/qapi.py                          | 36 
> ++++++++++++++++++++++++++------
>  tests/test-qmp-commands.c                |  6 ++++++
>  tests/Makefile.include                   |  4 ++++
>  tests/qapi-schema/bad-if-empty-list.err  |  1 +
>  tests/qapi-schema/bad-if-empty-list.exit |  1 +
>  tests/qapi-schema/bad-if-empty-list.json |  3 +++
>  tests/qapi-schema/bad-if-empty-list.out  |  0
>  tests/qapi-schema/bad-if-empty.err       |  1 +
>  tests/qapi-schema/bad-if-empty.exit      |  1 +
>  tests/qapi-schema/bad-if-empty.json      |  3 +++
>  tests/qapi-schema/bad-if-empty.out       |  0
>  tests/qapi-schema/bad-if-list.err        |  1 +
>  tests/qapi-schema/bad-if-list.exit       |  1 +
>  tests/qapi-schema/bad-if-list.json       |  3 +++
>  tests/qapi-schema/bad-if-list.out        |  0
>  tests/qapi-schema/bad-if.err             |  1 +
>  tests/qapi-schema/bad-if.exit            |  1 +
>  tests/qapi-schema/bad-if.json            |  3 +++
>  tests/qapi-schema/bad-if.out             |  0
>  tests/qapi-schema/qapi-schema-test.json  | 20 ++++++++++++++++++
>  tests/qapi-schema/qapi-schema-test.out   | 22 +++++++++++++++++++
>  21 files changed, 102 insertions(+), 6 deletions(-)
>  create mode 100644 tests/qapi-schema/bad-if-empty-list.err
>  create mode 100644 tests/qapi-schema/bad-if-empty-list.exit
>  create mode 100644 tests/qapi-schema/bad-if-empty-list.json
>  create mode 100644 tests/qapi-schema/bad-if-empty-list.out
>  create mode 100644 tests/qapi-schema/bad-if-empty.err
>  create mode 100644 tests/qapi-schema/bad-if-empty.exit
>  create mode 100644 tests/qapi-schema/bad-if-empty.json
>  create mode 100644 tests/qapi-schema/bad-if-empty.out
>  create mode 100644 tests/qapi-schema/bad-if-list.err
>  create mode 100644 tests/qapi-schema/bad-if-list.exit
>  create mode 100644 tests/qapi-schema/bad-if-list.json
>  create mode 100644 tests/qapi-schema/bad-if-list.out
>  create mode 100644 tests/qapi-schema/bad-if.err
>  create mode 100644 tests/qapi-schema/bad-if.exit
>  create mode 100644 tests/qapi-schema/bad-if.json
>  create mode 100644 tests/qapi-schema/bad-if.out
>
> diff --git a/scripts/qapi.py b/scripts/qapi.py
> index 43a54bf40f..27df0fcf48 100644
> --- a/scripts/qapi.py
> +++ b/scripts/qapi.py
> @@ -630,6 +630,27 @@ def add_name(name, info, meta, implicit=False):
>      all_names[name] = meta
>  
>  
> +def check_if(expr, info):
> +
> +    def check_if_str(ifcond, info):
> +        if not isinstance(ifcond, str):
> +            raise QAPISemError(
> +                info, "'if' condition must be a string or a list of strings")
> +        if ifcond == '':
> +            raise QAPISemError(info, "'if' condition '' makes no sense")
> +
> +    ifcond = expr.get('if')
> +    if ifcond is None:
> +        return
> +    elif isinstance(ifcond, list):

Suggest s/elif/if/

> +        if ifcond == []:
> +            raise QAPISemError(info, "'if' condition [] is useless")
> +        for elt in ifcond:
> +            check_if_str(elt, info)
> +    else:
> +        check_if_str(ifcond, info)
> +
> +
>  def check_type(info, source, value, allow_array=False,
>                 allow_dict=False, allow_optional=False,
>                 allow_metas=[]):

R-by stands.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]