mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-07-08 22:10:42 +00:00
qapi: add 'if' to top-level expressions
Accept 'if' key in top-level elements, accepted as string or list of string type. The following patches will modify the test visitor to check the value is correctly saved, and generate #if/#endif code (as a single #if/endif line or a series for a list). Example of 'if' key: { 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, 'if': 'defined(TEST_IF_STRUCT)' } The generated code is for now *unconditional*. Later patches generate the conditionals. Backports commit 967c885108f18e5065744719f7959ba5ea0a5b0d from qemu
This commit is contained in:
parent
9bec5e0be8
commit
b55309fab2
|
@ -650,6 +650,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=[]):
|
||||||
|
@ -883,6 +904,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'"
|
||||||
|
@ -911,28 +934,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")
|
||||||
|
|
Loading…
Reference in a new issue