[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH for-4.0 v7 08/27] qapi: add a dictionary form wi
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH for-4.0 v7 08/27] qapi: add a dictionary form with 'name' key for enum members |
Date: |
Mon, 10 Dec 2018 17:05:10 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
One more thing...
Markus Armbruster <address@hidden> writes:
> Marc-André Lureau <address@hidden> writes:
>
>> Desugar the enum NAME form to { 'name': NAME }. This will allow to add
>> new enum members, such as 'if' in the following patch.
>>
>> Signed-off-by: Marc-André Lureau <address@hidden>
>> ---
>> scripts/qapi/common.py | 49 ++++++++++++++++---
>> tests/Makefile.include | 3 +-
>> tests/qapi-schema/enum-bad-member.err | 1 +
>> ...-dict-member.exit => enum-bad-member.exit} | 0
>> tests/qapi-schema/enum-bad-member.json | 2 +
>> ...um-dict-member.out => enum-bad-member.out} | 0
>> .../qapi-schema/enum-dict-member-unknown.err | 2 +
>> .../qapi-schema/enum-dict-member-unknown.exit | 1 +
>> .../qapi-schema/enum-dict-member-unknown.json | 2 +
>> .../qapi-schema/enum-dict-member-unknown.out | 0
>> tests/qapi-schema/enum-dict-member.err | 1 -
>> tests/qapi-schema/enum-dict-member.json | 2 -
>> 12 files changed, 52 insertions(+), 11 deletions(-)
>> create mode 100644 tests/qapi-schema/enum-bad-member.err
>> rename tests/qapi-schema/{enum-dict-member.exit => enum-bad-member.exit}
>> (100%)
>> create mode 100644 tests/qapi-schema/enum-bad-member.json
>> rename tests/qapi-schema/{enum-dict-member.out => enum-bad-member.out}
>> (100%)
>> create mode 100644 tests/qapi-schema/enum-dict-member-unknown.err
>> create mode 100644 tests/qapi-schema/enum-dict-member-unknown.exit
>> create mode 100644 tests/qapi-schema/enum-dict-member-unknown.json
>> create mode 100644 tests/qapi-schema/enum-dict-member-unknown.out
>> delete mode 100644 tests/qapi-schema/enum-dict-member.err
>> delete mode 100644 tests/qapi-schema/enum-dict-member.json
>>
>> diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
[...]
>> @@ -847,18 +851,32 @@ def check_alternate(expr, info):
>> types_seen[qt] = key
>>
>>
>> +def normalize_enum(expr):
>> + members = expr['data']
>> +
>> + # translate short member form to dict form
>> + expr['data'] = [m if isinstance(m, dict) else {'name': m} for m in
>> members]
>> +
>> +
>> def check_enum(expr, info):
>> name = expr['enum']
>> - members = expr.get('data')
>> + members = expr['data']
>> prefix = expr.get('prefix')
>>
>> - if not isinstance(members, list):
>> - raise QAPISemError(info,
>> - "Enum '%s' requires an array for 'data'" % name)
>> if prefix is not None and not isinstance(prefix, str):
>> raise QAPISemError(info,
>> "Enum '%s' requires a string for 'prefix'" %
>> name)
>> +
>> + if not isinstance(members, list):
>> + raise QAPISemError(info,
>> + "Enum '%s' requires an array for 'data'" % name)
>> +
>
> Did you move this check down intentionally?
>
>> for member in members:
>> + if isinstance(member, dict):
>> + source = "dictionary member of enum '%s'" % name
>> + check_known_keys(info, source, member, ['name'], [])
>> + member = member['name']
>> +
>> check_name(info, "Member of enum '%s'" % name, member,
>> enum_member=True)
>
> Again, slightly more complicated than v6 because it now runs before
> normalization. We'll revisit this at [*] below.
If we keep it this way, then let's at least avoid assigning to the loop
control variable:
member_name = member['name']
else:
member_name = member
check_name(info, "Member of enum '%s'" % name, member_name,
enum_member=True)
[...]
- Re: [Qemu-devel] [PATCH for-4.0 v7 01/27] qapi: make sure osdep.h is included in type headers, (continued)
[Qemu-devel] [PATCH for-4.0 v7 02/27] qapi: do not define enumeration value explicitly, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 03/27] qapi: rename QAPISchemaEnumType.values to .members, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 04/27] qapi: change enum visitor and gen_enum* to take QAPISchemaMember, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 05/27] tests: print enum type members more like object type members, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 06/27] qapi: factor out checking for keys, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 08/27] qapi: add a dictionary form with 'name' key for enum members, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 07/27] qapi: improve reporting of unknown or missing keys, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 09/27] qapi: add 'if' to enum members, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 10/27] qapi-events: add 'if' condition to implicit event enum, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 11/27] qapi: pass long form enum to make_enum_members, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 12/27] qapi: rename allow_dict to allow_implicit, Marc-André Lureau, 2018/12/08
[Qemu-devel] [PATCH for-4.0 v7 13/27] qapi: add a dictionary form for TYPE, Marc-André Lureau, 2018/12/08