From 0d14eeb23325b6b1f0f9adce8baf7d1b415cba81 Mon Sep 17 00:00:00 2001 From: Amos Kong Date: Tue, 10 Jun 2014 19:25:52 +0800 Subject: qapi: add const prefix to 'char *' insider c_type() It's ugly to add const prefix for parameter type by an if statement outside c_type(). This patch adds a parameter to do it. Signed-off-by: Amos Kong Suggested-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Paolo Bonzini Reviewed-by: Markus Armbruster Signed-off-by: Luiz Capitulino --- scripts/qapi.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'scripts/qapi.py') diff --git a/scripts/qapi.py b/scripts/qapi.py index 86e9608..dc690bb 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -470,8 +470,10 @@ def find_enum(name): def is_enum(name): return find_enum(name) != None -def c_type(name): +def c_type(name, is_param=False): if name == 'str': + if is_param: + return 'const char *' return 'char *' elif name == 'int': return 'int64_t' -- cgit v1.1 From 05dfb26cd2bf3f50a0fbf08a68a3bd415301edc5 Mon Sep 17 00:00:00 2001 From: Amos Kong Date: Tue, 10 Jun 2014 19:25:53 +0800 Subject: qapi: Suppress unwanted space between type and identifier We always generate a space between type and identifier in parameter and variable declarations, even when idiomatic C style doesn't have a space there. Suppress it. Signed-off-by: Amos Kong Signed-off-by: Luiz Capitulino --- scripts/qapi.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'scripts/qapi.py') diff --git a/scripts/qapi.py b/scripts/qapi.py index dc690bb..0079194 100644 --- a/scripts/qapi.py +++ b/scripts/qapi.py @@ -470,11 +470,17 @@ def find_enum(name): def is_enum(name): return find_enum(name) != None +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': if is_param: - return 'const char *' - return 'char *' + return 'const char *' + eatspace + return 'char *' + eatspace + elif name == 'int': return 'int64_t' elif (name == 'int8' or name == 'int16' or name == 'int32' or @@ -488,15 +494,19 @@ def c_type(name, is_param=False): 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 = "" @@ -521,7 +531,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] -- cgit v1.1 From 21cd70dfc1a6dc90511bae55a460a3a55461339a Mon Sep 17 00:00:00 2001 From: Wenchao Xia Date: Wed, 18 Jun 2014 08:43:28 +0200 Subject: qapi script: add event support qapi-event.py will parse the schema and generate qapi-event.c, then the API in qapi-event.c can be used to handle events in qemu code. All API have prefix "qapi_event". The script mainly includes two parts: generate API for each event define, generate an enum type for all defined events. Since in some cases the real emit behavior may change, for example, qemu-img would not send a event, a callback layer is used to control the behavior. As a result, the stubs at compile time can be saved, the binding of block layer code and monitor code will become looser. Signed-off-by: Wenchao Xia Signed-off-by: Paolo Bonzini Reviewed-by: Eric Blake Signed-off-by: Luiz Capitulino --- scripts/qapi.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'scripts/qapi.py') diff --git a/scripts/qapi.py b/scripts/qapi.py index 0079194..54b97cb 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: -- cgit v1.1