diff options
Diffstat (limited to 'scripts/qapi.py')
-rw-r--r-- | scripts/qapi.py | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/scripts/qapi.py b/scripts/qapi.py index 86e96089af..54b97cb48e 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -248,6 +248,16 @@ def discriminator_find_enum_define(expr): return find_enum(discriminator_type) +def check_event(expr, expr_info): + params = expr.get('data') + if params: + for argname, argentry, optional, structured in parse_args(params): + if structured: + raise QAPIExprError(expr_info, + "Nested structure define in event is not " + "supported now, event '%s', argname '%s'" + % (expr['event'], argname)) + def check_union(expr, expr_info): name = expr['union'] base = expr.get('base') @@ -311,6 +321,8 @@ def check_exprs(schema): expr = expr_elem['expr'] if expr.has_key('union'): check_union(expr, expr_elem['info']) + if expr.has_key('event'): + check_event(expr, expr_elem['info']) def parse_schema(input_file): try: @@ -470,9 +482,17 @@ def find_enum(name): def is_enum(name): return find_enum(name) != None -def c_type(name): +eatspace = '\033EATSPACE.' + +# A special suffix is added in c_type() for pointer types, and it's +# stripped in mcgen(). So please notice this when you check the return +# value of c_type() outside mcgen(). +def c_type(name, is_param=False): if name == 'str': - return 'char *' + if is_param: + return 'const char *' + eatspace + return 'char *' + eatspace + elif name == 'int': return 'int64_t' elif (name == 'int8' or name == 'int16' or name == 'int32' or @@ -486,15 +506,19 @@ def c_type(name): elif name == 'number': return 'double' elif type(name) == list: - return '%s *' % c_list_type(name[0]) + return '%s *%s' % (c_list_type(name[0]), eatspace) elif is_enum(name): return name elif name == None or len(name) == 0: return 'void' elif name == name.upper(): - return '%sEvent *' % camel_case(name) + return '%sEvent *%s' % (camel_case(name), eatspace) else: - return '%s *' % name + return '%s *%s' % (name, eatspace) + +def is_c_ptr(name): + suffix = "*" + eatspace + return c_type(name).endswith(suffix) def genindent(count): ret = "" @@ -519,7 +543,8 @@ def cgen(code, **kwds): return '\n'.join(lines) % kwds + '\n' def mcgen(code, **kwds): - return cgen('\n'.join(code.split('\n')[1:-1]), **kwds) + raw = cgen('\n'.join(code.split('\n')[1:-1]), **kwds) + return re.sub(re.escape(eatspace) + ' *', '', raw) def basename(filename): return filename.split("/")[-1] |