diff options
author | Markus Armbruster <armbru@redhat.com> | 2021-03-23 10:40:06 +0100 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2021-03-23 22:30:32 +0100 |
commit | 0825f62c842f2c07c5471391c6d7fd3f4fe83732 (patch) | |
tree | e86a8c3d0c7fc41255a9bfd762ed7523d9e69e29 | |
parent | 5fbc78dd3675832062894aeca89a52c90a96f954 (diff) |
qapi: Lift enum-specific code out of check_name_str()
check_name_str() masks leading digits when passed enum_member=True.
Only check_enum() does. Lift the masking into check_enum().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20210323094025.3569441-10-armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
-rw-r--r-- | scripts/qapi/expr.py | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 507550c340..e00467636c 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -34,18 +34,11 @@ def check_name_is_str(name, info, source): def check_name_str(name, info, source, - enum_member=False, permit_upper=False): - membername = name - - # Enum members can start with a digit, because the generated C - # code always prefixes it with the enum name - if enum_member and membername[0].isdigit(): - membername = 'D' + membername # Reserve the entire 'q_' namespace for c_name(), and for 'q_empty' # and 'q_obj_*' implicit type names. - if not valid_name.match(membername) or \ - c_name(membername, False).startswith('q_'): + if not valid_name.match(name) or \ + c_name(name, False).startswith('q_'): raise QAPISemError(info, "%s has an invalid name" % source) if not permit_upper and name.lower() != name: raise QAPISemError( @@ -213,11 +206,15 @@ def check_enum(expr, info): for m in members] for member in members: source = "'data' member" + member_name = member['name'] check_keys(member, info, source, ['name'], ['if']) - check_name_is_str(member['name'], info, source) - source = "%s '%s'" % (source, member['name']) - check_name_str(member['name'], info, source, - enum_member=True, permit_upper=permit_upper) + check_name_is_str(member_name, info, source) + source = "%s '%s'" % (source, member_name) + # Enum members may start with a digit + if member_name[0].isdigit(): + member_name = 'd' + member_name # Hack: hide the digit + check_name_str(member_name, info, source, + permit_upper=permit_upper) check_if(member, info, source) |