qapi: Enforce enum member naming rules
Enum members should use '-', not '_'. Enforce this. Fix the fixable offenders (all in tests/), and add the remainder to pragma member-name-exceptions. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20210323094025.3569441-28-armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
5aceeac04d
commit
407efbf9e7
@ -32,12 +32,15 @@
|
||||
'member-name-exceptions': [ # visible in:
|
||||
'ACPISlotType', # query-acpi-ospm-status
|
||||
'AcpiTableOptions', # -acpitable
|
||||
'BlkdebugEvent', # blockdev-add, -blockdev
|
||||
'BlkdebugSetStateOptions', # blockdev-add, -blockdev
|
||||
'BlockDeviceInfo', # query-block
|
||||
'BlockDeviceStats', # query-blockstats
|
||||
'BlockDeviceTimedStats', # query-blockstats
|
||||
'BlockIOThrottle', # block_set_io_throttle
|
||||
'BlockInfo', # query-block
|
||||
'BlockdevAioOptions', # blockdev-add, -blockdev
|
||||
'BlockdevDriver', # blockdev-add, query-blockstats, ...
|
||||
'BlockdevVmdkAdapterType', # blockdev-create (to match VMDK spec)
|
||||
'BlockdevVmdkSubformat', # blockdev-create (to match VMDK spec)
|
||||
'ColoCompareProperties', # object_add, -object
|
||||
@ -46,10 +49,15 @@
|
||||
'FilterRewriterProperties', # object_add, -object
|
||||
'InputLinuxProperties', # object_add, -object
|
||||
'NetdevTapOptions', # netdev_add, query-netdev, -netdev
|
||||
'ObjectType', # object-add, -object
|
||||
'PCIELinkSpeed', # internal only
|
||||
'PciBusInfo', # query-pci
|
||||
'PciDeviceInfo', # query-pci
|
||||
'PciMemoryRegion', # query-pci
|
||||
'QKeyCode', # send-key, input-sent-event
|
||||
'QapiErrorClass', # QMP error replies
|
||||
'SshHostKeyCheckMode', # blockdev-add, -blockdev
|
||||
'SysEmuTarget', # query-cpu-fast, query-target
|
||||
'UuidInfo', # query-uuid
|
||||
'VncClientInfo', # query-vnc, query-vnc-servers, ...
|
||||
'X86CPURegister32' # qom-get of x86 CPU properties
|
||||
|
@ -229,7 +229,7 @@ def check_enum(expr, info):
|
||||
if prefix is not None and not isinstance(prefix, str):
|
||||
raise QAPISemError(info, "'prefix' must be a string")
|
||||
|
||||
permit_upper = name in info.pragma.member_name_exceptions
|
||||
permissive = name in info.pragma.member_name_exceptions
|
||||
|
||||
members[:] = [m if isinstance(m, dict) else {'name': m}
|
||||
for m in members]
|
||||
@ -243,7 +243,8 @@ def check_enum(expr, info):
|
||||
if member_name[0].isdigit():
|
||||
member_name = 'd' + member_name # Hack: hide the digit
|
||||
check_name_lower(member_name, info, source,
|
||||
permit_upper, permit_underscore=True)
|
||||
permit_upper=permissive,
|
||||
permit_underscore=permissive)
|
||||
check_if(member, info, source)
|
||||
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
enum-clash-member.json: In enum 'MyEnum':
|
||||
enum-clash-member.json:2: value 'one_two' collides with value 'one-two'
|
||||
enum-clash-member.json:3: value 'one_two' collides with value 'one-two'
|
||||
|
@ -1,2 +1,3 @@
|
||||
# we reject enums where members will clash when mapped to C enum
|
||||
{ 'pragma': { 'member-name-exceptions': [ 'MyEnum' ] } }
|
||||
{ 'enum': 'MyEnum', 'data': [ 'one-two', 'one_two' ] }
|
||||
|
Loading…
Reference in New Issue
Block a user