[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 17/25] qapi: Move context-free checking to the proper place
From: |
Markus Armbruster |
Subject: |
[PATCH 17/25] qapi: Move context-free checking to the proper place |
Date: |
Tue, 24 Sep 2019 15:28:22 +0200 |
QAPISchemaCommand.check() and QAPISchemaEvent().check() check 'data'
is present when 'boxed': true. That's context-free. Move to
check_command() and check_event().
Tweak the error message while there.
check_exprs() & friends now check exactly what qapi-code-gen.txt calls
the second layer of syntax.
Signed-off-by: Markus Armbruster <address@hidden>
---
scripts/qapi/common.py | 16 ++++++++--------
tests/qapi-schema/event-boxed-empty.err | 2 +-
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index ac4c898e51..7577120f12 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -767,10 +767,12 @@ def check_type(value, info, source,
def check_command(expr, info):
name = expr['command']
+ args = expr.get('data')
boxed = expr.get('boxed', False)
- check_type(expr.get('data'), info,
- "'data' for command '%s'" % name,
+ if boxed and args is None:
+ raise QAPISemError(info, "'boxed': true requires 'data'")
+ check_type(args, info, "'data' for command '%s'" % name,
allow_dict=not boxed)
check_type(expr.get('returns'), info,
"'returns' for command '%s'" % name,
@@ -779,10 +781,12 @@ def check_command(expr, info):
def check_event(expr, info):
name = expr['event']
+ args = expr.get('data')
boxed = expr.get('boxed', False)
- check_type(expr.get('data'), info,
- "'data' for event '%s'" % name,
+ if boxed and args is None:
+ raise QAPISemError(info, "'boxed': true requires 'data'")
+ check_type(args, info, "'data' for event '%s'" % name,
allow_dict=not boxed)
@@ -1691,8 +1695,6 @@ class QAPISchemaCommand(QAPISchemaEntity):
self.info,
"command's 'data' can take %s only with 'boxed': true"
% self.arg_type.describe())
- elif self.boxed:
- raise QAPISemError(self.info, "use of 'boxed' requires 'data'")
if self._ret_type_name:
self.ret_type = schema.resolve_type(
self._ret_type_name, self.info, "command's 'returns'")
@@ -1740,8 +1742,6 @@ class QAPISchemaEvent(QAPISchemaEntity):
self.info,
"event's 'data' can take %s only with 'boxed': true"
% self.arg_type.describe())
- elif self.boxed:
- raise QAPISemError(self.info, "use of 'boxed' requires 'data'")
def visit(self, visitor):
QAPISchemaEntity.visit(self, visitor)
diff --git a/tests/qapi-schema/event-boxed-empty.err
b/tests/qapi-schema/event-boxed-empty.err
index 9c691b7d97..931c10b036 100644
--- a/tests/qapi-schema/event-boxed-empty.err
+++ b/tests/qapi-schema/event-boxed-empty.err
@@ -1,2 +1,2 @@
tests/qapi-schema/event-boxed-empty.json: In event 'FOO':
-tests/qapi-schema/event-boxed-empty.json:2: use of 'boxed' requires 'data'
+tests/qapi-schema/event-boxed-empty.json:2: 'boxed': true requires 'data'
--
2.21.0
- [PATCH 00/25] qapi: Pay back some frontend technical debt, Markus Armbruster, 2019/09/24
- [PATCH 01/25] qapi: Tighten QAPISchemaFOO.check() assertions, Markus Armbruster, 2019/09/24
- [PATCH 03/25] qapi: New QAPISourceInfo, replacing dict, Markus Armbruster, 2019/09/24
- [PATCH 02/25] qapi: Rename .owner to .defined_in, Markus Armbruster, 2019/09/24
- [PATCH 10/25] qapi: Use check_name_str() where it suffices, Markus Armbruster, 2019/09/24
- [PATCH 17/25] qapi: Move context-free checking to the proper place,
Markus Armbruster <=
- [PATCH 11/25] qapi: Report invalid '*' prefix like any other invalid name, Markus Armbruster, 2019/09/24
- [PATCH 24/25] qapi: Improve reporting of redefinition, Markus Armbruster, 2019/09/24
- [PATCH 15/25] qapi: Inline check_name() into check_union(), Markus Armbruster, 2019/09/24
- [PATCH 07/25] qapi: Improve reporting of member name clashes, Markus Armbruster, 2019/09/24
- [PATCH 13/25] qapi: Make check_type()'s array case a bit more obvious, Markus Armbruster, 2019/09/24