From d7bc17c602f128bb358376e6976b3b5dee1ad732 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Fri, 27 Sep 2019 15:46:22 +0200 Subject: qapi: Improve reporting of invalid name errors Split check_name() into check_name_is_str() and check_name_str(), keep check_name() as a wrapper. Move add_name()'s call into its caller check_exprs(), and inline. This permits delaying check_name_str() there, so its error message gains an "in definition" line. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20190927134639.4284-10-armbru@redhat.com> --- scripts/qapi/common.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'scripts/qapi/common.py') diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index c909821560..6f35cd131e 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -708,11 +708,22 @@ valid_name = re.compile(r'^(__[a-zA-Z0-9.-]+_)?' def check_name(name, info, source, allow_optional=False, enum_member=False, permit_upper=False): - global valid_name - membername = name + check_name_is_str(name, info, source) + check_name_str(name, info, source, + allow_optional, enum_member, permit_upper) + +def check_name_is_str(name, info, source): if not isinstance(name, str): raise QAPISemError(info, "%s requires a string name" % source) + + +def check_name_str(name, info, source, + allow_optional=False, enum_member=False, + permit_upper=False): + global valid_name + membername = name + if name.startswith('*'): membername = name[1:] if not allow_optional: @@ -734,7 +745,6 @@ def check_name(name, info, source, def add_name(name, info, meta): global all_names - check_name(name, info, "'%s'" % meta, permit_upper=True) # FIXME should reject names that differ only in '_' vs. '.' # vs. '-', because they're liable to clash in generated C. if name in all_names: @@ -1153,8 +1163,10 @@ def check_exprs(exprs): raise QAPISemError(info, "expression is missing metatype") normalize_if(expr) name = expr[meta] - add_name(name, info, meta) + check_name_is_str(name, info, "'%s'" % meta) info.set_defn(meta, name) + check_name_str(name, info, "'%s'" % meta, permit_upper=True) + add_name(name, info, meta) if doc and doc.symbol != name: raise QAPISemError( info, -- cgit v1.2.3