qapi: Enforce struct member naming rules

Struct members, including command arguments, event data, and union
inline base 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-27-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Markus Armbruster 2021-03-23 10:40:23 +01:00
parent e75d4225b7
commit 5aceeac04d
8 changed files with 36 additions and 8 deletions

View file

@ -6,6 +6,10 @@
# Whitelists to permit QAPI rule violations
{ 'pragma': {
# Types whose member names may use '_'
'member-name-exceptions': [
'UserDefA'
],
# Commands allowed to return a non-dictionary:
'command-returns-exceptions': [
'guest-get-time',
@ -231,7 +235,7 @@
'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' }
{ 'command': 'test-if-union-cmd',
'data': { 'union_cmd_arg': 'TestIfUnion' },
'data': { 'union-cmd-arg': 'TestIfUnion' },
'if': 'defined(TEST_IF_UNION)' }
{ 'alternate': 'TestIfAlternate', 'data':
@ -240,7 +244,7 @@
'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }
{ 'command': 'test-if-alternate-cmd',
'data': { 'alt_cmd_arg': 'TestIfAlternate' },
'data': { 'alt-cmd-arg': 'TestIfAlternate' },
'if': 'defined(TEST_IF_ALT)' }
{ 'command': 'test-if-cmd',

View file

@ -320,7 +320,7 @@ object TestIfUnion
if ['defined(TEST_IF_UNION_BAR)']
if ['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)']
object q_obj_test-if-union-cmd-arg
member union_cmd_arg: TestIfUnion optional=False
member union-cmd-arg: TestIfUnion optional=False
if ['defined(TEST_IF_UNION)']
command test-if-union-cmd q_obj_test-if-union-cmd-arg -> None
gen=True success_response=True boxed=False oob=False preconfig=False
@ -332,7 +332,7 @@ alternate TestIfAlternate
if ['defined(TEST_IF_ALT_BAR)']
if ['defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)']
object q_obj_test-if-alternate-cmd-arg
member alt_cmd_arg: TestIfAlternate optional=False
member alt-cmd-arg: TestIfAlternate optional=False
if ['defined(TEST_IF_ALT)']
command test-if-alternate-cmd q_obj_test-if-alternate-cmd-arg -> None
gen=True success_response=True boxed=False oob=False preconfig=False

View file

@ -1,2 +1,2 @@
struct-member-name-clash.json: In struct 'Oops':
struct-member-name-clash.json:4: member 'a_b' collides with member 'a-b'
struct-member-name-clash.json:5: member 'a_b' collides with member 'a-b'

View file

@ -1,4 +1,5 @@
# C member name collision
# Reject members that clash when mapped to C names (we would have two 'a_b'
# members).
{ 'pragma': { 'member-name-exceptions': [ 'Oops' ] } }
{ 'struct': 'Oops', 'data': { 'a-b': 'str', 'a_b': 'str' } }