]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
qapi: Improve reporting of invalid name errors
authorMarkus Armbruster <armbru@redhat.com>
Fri, 27 Sep 2019 13:46:22 +0000 (15:46 +0200)
committerMarkus Armbruster <armbru@redhat.com>
Sat, 28 Sep 2019 15:17:18 +0000 (17:17 +0200)
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 <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20190927134639.4284-10-armbru@redhat.com>

scripts/qapi/common.py
tests/qapi-schema/bad-ident.err
tests/qapi-schema/command-int.err
tests/qapi-schema/redefined-builtin.err
tests/qapi-schema/redefined-command.err
tests/qapi-schema/redefined-event.err
tests/qapi-schema/redefined-type.err
tests/qapi-schema/reserved-command-q.err
tests/qapi-schema/reserved-type-kind.err
tests/qapi-schema/reserved-type-list.err

index c9098215608a6e15cd5a3f58a7f05d696711c713..6f35cd131e1ec16313e71de05f60ee9249b136d6 100644 (file)
@@ -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,
index c4190602b5c4f552b4fea0fe3d6f9e186134cd11..687888985478943e2c8456dbee985564c78bd1fa 100644 (file)
@@ -1 +1,2 @@
+tests/qapi-schema/bad-ident.json: In struct '*oops':
 tests/qapi-schema/bad-ident.json:2: 'struct' does not allow optional name '*oops'
index 0f9300679b304398cf6ec9cd1fdbe51ede29d3d4..56b45bf656eb6ac17b616cfbd05ffcd6334b425f 100644 (file)
@@ -1 +1,2 @@
+tests/qapi-schema/command-int.json: In command 'int':
 tests/qapi-schema/command-int.json:2: built-in 'int' is already defined
index b2757225c4ea5aecaa2ecc02ae2acca023e57659..67775fdb4105f7ec3fe37467528cb8184592ee95 100644 (file)
@@ -1 +1,2 @@
+tests/qapi-schema/redefined-builtin.json: In struct 'size':
 tests/qapi-schema/redefined-builtin.json:2: built-in 'size' is already defined
index 82ae256e639e8866926572ac7be6329c2a8738b6..b77a05d354fe2b08275fb951fc2a1d00bca8ec28 100644 (file)
@@ -1 +1,2 @@
+tests/qapi-schema/redefined-command.json: In command 'foo':
 tests/qapi-schema/redefined-command.json:3: command 'foo' is already defined
index 35429cb48186a0bd2d3798c458c06c1f71e1bf45..fd02d38157706b142548651f8c85ca4eb6235e10 100644 (file)
@@ -1 +1,2 @@
+tests/qapi-schema/redefined-event.json: In event 'EVENT_A':
 tests/qapi-schema/redefined-event.json:3: event 'EVENT_A' is already defined
index 06ea78c4781e479cea71a15b34609adc36ba36cd..89acc82c2dbd002ab9578da209db8527b6233e57 100644 (file)
@@ -1 +1,2 @@
+tests/qapi-schema/redefined-type.json: In enum 'foo':
 tests/qapi-schema/redefined-type.json:3: struct 'foo' is already defined
index f939e044eba01713c57ca727882753af8adaf1dd..0844e14b26d1d7e88ae9115d774bdfe220a34424 100644 (file)
@@ -1 +1,2 @@
+tests/qapi-schema/reserved-command-q.json: In command 'q-unix':
 tests/qapi-schema/reserved-command-q.json:5: 'command' uses invalid name 'q-unix'
index 0a38efaad8d8df6331a8d9431c5613bd18986068..8d21479000d9203249eb4ed0a8df86914bbb88b5 100644 (file)
@@ -1 +1,2 @@
+tests/qapi-schema/reserved-type-kind.json: In enum 'UnionKind':
 tests/qapi-schema/reserved-type-kind.json:2: enum 'UnionKind' should not end in 'Kind'
index 4510fa6d903c1907e3f8cd268c419f1bcff374f3..2bdd7d8a06a6be552bc457febe78b1a5f07c7690 100644 (file)
@@ -1 +1,2 @@
+tests/qapi-schema/reserved-type-list.json: In struct 'FooList':
 tests/qapi-schema/reserved-type-list.json:5: struct 'FooList' should not end in 'List'