|
@@ -638,6 +638,27 @@ def add_name(name, info, meta, implicit=False):
|
|
all_names[name] = meta
|
|
all_names[name] = meta
|
|
|
|
|
|
|
|
|
|
|
|
+def check_if(expr, info):
|
|
|
|
+
|
|
|
|
+ def check_if_str(ifcond, info):
|
|
|
|
+ if not isinstance(ifcond, str):
|
|
|
|
+ raise QAPISemError(
|
|
|
|
+ info, "'if' condition must be a string or a list of strings")
|
|
|
|
+ if ifcond == '':
|
|
|
|
+ raise QAPISemError(info, "'if' condition '' makes no sense")
|
|
|
|
+
|
|
|
|
+ ifcond = expr.get('if')
|
|
|
|
+ if ifcond is None:
|
|
|
|
+ return
|
|
|
|
+ if isinstance(ifcond, list):
|
|
|
|
+ if ifcond == []:
|
|
|
|
+ raise QAPISemError(info, "'if' condition [] is useless")
|
|
|
|
+ for elt in ifcond:
|
|
|
|
+ check_if_str(elt, info)
|
|
|
|
+ else:
|
|
|
|
+ check_if_str(ifcond, info)
|
|
|
|
+
|
|
|
|
+
|
|
def check_type(info, source, value, allow_array=False,
|
|
def check_type(info, source, value, allow_array=False,
|
|
allow_dict=False, allow_optional=False,
|
|
allow_dict=False, allow_optional=False,
|
|
allow_metas=[]):
|
|
allow_metas=[]):
|
|
@@ -871,6 +892,8 @@ def check_keys(expr_elem, meta, required, optional=[]):
|
|
raise QAPISemError(info,
|
|
raise QAPISemError(info,
|
|
"'%s' of %s '%s' should only use true value"
|
|
"'%s' of %s '%s' should only use true value"
|
|
% (key, meta, name))
|
|
% (key, meta, name))
|
|
|
|
+ if key == 'if':
|
|
|
|
+ check_if(expr, info)
|
|
for key in required:
|
|
for key in required:
|
|
if key not in expr:
|
|
if key not in expr:
|
|
raise QAPISemError(info, "Key '%s' is missing from %s '%s'"
|
|
raise QAPISemError(info, "Key '%s' is missing from %s '%s'"
|
|
@@ -899,28 +922,28 @@ def check_exprs(exprs):
|
|
|
|
|
|
if 'enum' in expr:
|
|
if 'enum' in expr:
|
|
meta = 'enum'
|
|
meta = 'enum'
|
|
- check_keys(expr_elem, 'enum', ['data'], ['prefix'])
|
|
|
|
|
|
+ check_keys(expr_elem, 'enum', ['data'], ['if', 'prefix'])
|
|
enum_types[expr[meta]] = expr
|
|
enum_types[expr[meta]] = expr
|
|
elif 'union' in expr:
|
|
elif 'union' in expr:
|
|
meta = 'union'
|
|
meta = 'union'
|
|
check_keys(expr_elem, 'union', ['data'],
|
|
check_keys(expr_elem, 'union', ['data'],
|
|
- ['base', 'discriminator'])
|
|
|
|
|
|
+ ['base', 'discriminator', 'if'])
|
|
union_types[expr[meta]] = expr
|
|
union_types[expr[meta]] = expr
|
|
elif 'alternate' in expr:
|
|
elif 'alternate' in expr:
|
|
meta = 'alternate'
|
|
meta = 'alternate'
|
|
- check_keys(expr_elem, 'alternate', ['data'])
|
|
|
|
|
|
+ check_keys(expr_elem, 'alternate', ['data'], ['if'])
|
|
elif 'struct' in expr:
|
|
elif 'struct' in expr:
|
|
meta = 'struct'
|
|
meta = 'struct'
|
|
- check_keys(expr_elem, 'struct', ['data'], ['base'])
|
|
|
|
|
|
+ check_keys(expr_elem, 'struct', ['data'], ['base', 'if'])
|
|
struct_types[expr[meta]] = expr
|
|
struct_types[expr[meta]] = expr
|
|
elif 'command' in expr:
|
|
elif 'command' in expr:
|
|
meta = 'command'
|
|
meta = 'command'
|
|
check_keys(expr_elem, 'command', [],
|
|
check_keys(expr_elem, 'command', [],
|
|
['data', 'returns', 'gen', 'success-response',
|
|
['data', 'returns', 'gen', 'success-response',
|
|
- 'boxed', 'allow-oob', 'allow-preconfig'])
|
|
|
|
|
|
+ 'boxed', 'allow-oob', 'allow-preconfig', 'if'])
|
|
elif 'event' in expr:
|
|
elif 'event' in expr:
|
|
meta = 'event'
|
|
meta = 'event'
|
|
- check_keys(expr_elem, 'event', [], ['data', 'boxed'])
|
|
|
|
|
|
+ check_keys(expr_elem, 'event', [], ['data', 'boxed', 'if'])
|
|
else:
|
|
else:
|
|
raise QAPISemError(expr_elem['info'],
|
|
raise QAPISemError(expr_elem['info'],
|
|
"Expression is missing metatype")
|
|
"Expression is missing metatype")
|