qapi: Move context-free checking to the proper place
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 <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20190927134639.4284-18-armbru@redhat.com>
This commit is contained in:
parent
fa110c6a9e
commit
4ebda5abdb
@ -768,10 +768,12 @@ def check_type(value, info, source,
|
|||||||
|
|
||||||
def check_command(expr, info):
|
def check_command(expr, info):
|
||||||
name = expr['command']
|
name = expr['command']
|
||||||
|
args = expr.get('data')
|
||||||
boxed = expr.get('boxed', False)
|
boxed = expr.get('boxed', False)
|
||||||
|
|
||||||
check_type(expr.get('data'), info,
|
if boxed and args is None:
|
||||||
"'data' for command '%s'" % name,
|
raise QAPISemError(info, "'boxed': true requires 'data'")
|
||||||
|
check_type(args, info, "'data' for command '%s'" % name,
|
||||||
allow_dict=not boxed)
|
allow_dict=not boxed)
|
||||||
check_type(expr.get('returns'), info,
|
check_type(expr.get('returns'), info,
|
||||||
"'returns' for command '%s'" % name,
|
"'returns' for command '%s'" % name,
|
||||||
@ -780,10 +782,12 @@ def check_command(expr, info):
|
|||||||
|
|
||||||
def check_event(expr, info):
|
def check_event(expr, info):
|
||||||
name = expr['event']
|
name = expr['event']
|
||||||
|
args = expr.get('data')
|
||||||
boxed = expr.get('boxed', False)
|
boxed = expr.get('boxed', False)
|
||||||
|
|
||||||
check_type(expr.get('data'), info,
|
if boxed and args is None:
|
||||||
"'data' for event '%s'" % name,
|
raise QAPISemError(info, "'boxed': true requires 'data'")
|
||||||
|
check_type(args, info, "'data' for event '%s'" % name,
|
||||||
allow_dict=not boxed)
|
allow_dict=not boxed)
|
||||||
|
|
||||||
|
|
||||||
@ -1699,8 +1703,6 @@ class QAPISchemaCommand(QAPISchemaEntity):
|
|||||||
self.info,
|
self.info,
|
||||||
"command's 'data' can take %s only with 'boxed': true"
|
"command's 'data' can take %s only with 'boxed': true"
|
||||||
% self.arg_type.describe())
|
% self.arg_type.describe())
|
||||||
elif self.boxed:
|
|
||||||
raise QAPISemError(self.info, "use of 'boxed' requires 'data'")
|
|
||||||
if self._ret_type_name:
|
if self._ret_type_name:
|
||||||
self.ret_type = schema.resolve_type(
|
self.ret_type = schema.resolve_type(
|
||||||
self._ret_type_name, self.info, "command's 'returns'")
|
self._ret_type_name, self.info, "command's 'returns'")
|
||||||
@ -1748,8 +1750,6 @@ class QAPISchemaEvent(QAPISchemaEntity):
|
|||||||
self.info,
|
self.info,
|
||||||
"event's 'data' can take %s only with 'boxed': true"
|
"event's 'data' can take %s only with 'boxed': true"
|
||||||
% self.arg_type.describe())
|
% self.arg_type.describe())
|
||||||
elif self.boxed:
|
|
||||||
raise QAPISemError(self.info, "use of 'boxed' requires 'data'")
|
|
||||||
|
|
||||||
def visit(self, visitor):
|
def visit(self, visitor):
|
||||||
QAPISchemaEntity.visit(self, visitor)
|
QAPISchemaEntity.visit(self, visitor)
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
tests/qapi-schema/event-boxed-empty.json: In event 'FOO':
|
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'
|
||||||
|
Loading…
Reference in New Issue
Block a user