From 18df515ebbefa9f13474b128b8050d5fa346ea1e Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 14 May 2015 06:50:48 -0600 Subject: qapi: Rename identical c_fun()/c_var() into c_name() Now that the two functions are identical, we only need one of them, and we might as well give it a more descriptive name. Basically, the function serves as the translation from a QAPI name into a (portion of a) C identifier, without regards to whether it is a variable or function name. Signed-off-by: Eric Blake Signed-off-by: Markus Armbruster --- scripts/qapi-types.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'scripts/qapi-types.py') diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 2bf8145076..e74cabece0 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -68,11 +68,11 @@ def generate_struct_fields(members): ret += mcgen(''' bool has_%(c_name)s; ''', - c_name=c_var(argname)) + c_name=c_name(argname)) ret += mcgen(''' %(c_type)s %(c_name)s; ''', - c_type=c_type(argentry), c_name=c_var(argname)) + c_type=c_type(argentry), c_name=c_name(argname)) return ret @@ -184,7 +184,7 @@ const int %(name)s_qtypes[QTYPE_MAX] = { ''', qtype = qtype, abbrev = de_camel_case(name).upper(), - enum = c_fun(de_camel_case(key),False).upper()) + enum = c_name(de_camel_case(key),False).upper()) ret += mcgen(''' }; @@ -221,7 +221,7 @@ struct %(name)s %(c_type)s %(c_name)s; ''', c_type=c_type(typeinfo[key]), - c_name=c_fun(key)) + c_name=c_name(key)) ret += mcgen(''' }; -- cgit v1.2.3 From 7c81c61f9c2274f66ba947eafd9618d60da838a6 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 14 May 2015 06:50:50 -0600 Subject: qapi: Rename generate_enum_full_value() to c_enum_const() Signed-off-by: Markus Armbruster Signed-off-by: Eric Blake --- scripts/qapi-types.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts/qapi-types.py') diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index e74cabece0..6ca48c11c0 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -118,13 +118,13 @@ const char *%(name)s_lookup[] = { name=name) i = 0 for value in values: - index = generate_enum_full_value(name, value) + index = c_enum_const(name, value) ret += mcgen(''' [%(index)s] = "%(value)s", ''', index = index, value = value) - max_index = generate_enum_full_value(name, 'MAX') + max_index = c_enum_const(name, 'MAX') ret += mcgen(''' [%(max_index)s] = NULL, }; @@ -150,7 +150,7 @@ typedef enum %(name)s i = 0 for value in enum_values: - enum_full_value = generate_enum_full_value(name, value) + enum_full_value = c_enum_const(name, value) enum_decl += mcgen(''' %(enum_full_value)s = %(i)d, ''', -- cgit v1.2.3 From b42e91484df9772bb0c26aa0f05390a92d564d6f Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 14 May 2015 06:50:52 -0600 Subject: qapi: Use c_enum_const() in generate_alternate_qtypes() Missed in commit b0b5819. Signed-off-by: Markus Armbruster Signed-off-by: Eric Blake --- scripts/qapi-types.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'scripts/qapi-types.py') diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 6ca48c11c0..9eb08a6266 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -180,11 +180,9 @@ const int %(name)s_qtypes[QTYPE_MAX] = { assert qtype, "Invalid alternate member" ret += mcgen(''' - [ %(qtype)s ] = %(abbrev)s_KIND_%(enum)s, + [ %(qtype)s ] = %(enum_const)s, ''', - qtype = qtype, - abbrev = de_camel_case(name).upper(), - enum = c_name(de_camel_case(key),False).upper()) + qtype = qtype, enum_const = c_enum_const(name + 'Kind', key)) ret += mcgen(''' }; -- cgit v1.2.3 From fce384b8e5193e02421f6b2c2880f3684abcbdc0 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 14 May 2015 06:50:56 -0600 Subject: qapi: Support downstream enums Enhance the testsuite to cover a downstream enum type and enum string. Update the generator to mangle the enum name in the appropriate places. Signed-off-by: Eric Blake Signed-off-by: Markus Armbruster --- scripts/qapi-types.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'scripts/qapi-types.py') diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 9eb08a6266..1593fc6561 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -58,7 +58,7 @@ typedef struct %(name)sList struct %(name)sList *next; } %(name)sList; ''', - name=name) + name=c_name(name)) def generate_struct_fields(members): ret = '' @@ -115,7 +115,7 @@ def generate_enum_lookup(name, values): ret = mcgen(''' const char *%(name)s_lookup[] = { ''', - name=name) + name=c_name(name)) i = 0 for value in values: index = c_enum_const(name, value) @@ -134,6 +134,7 @@ const char *%(name)s_lookup[] = { return ret def generate_enum(name, values): + name = c_name(name) lookup_decl = mcgen(''' extern const char *%(name)s_lookup[]; ''', @@ -247,15 +248,15 @@ extern const int %(name)s_qtypes[]; def generate_type_cleanup_decl(name): ret = mcgen(''' -void qapi_free_%(type)s(%(c_type)s obj); +void qapi_free_%(name)s(%(c_type)s obj); ''', - c_type=c_type(name),type=name) + c_type=c_type(name), name=c_name(name)) return ret def generate_type_cleanup(name): ret = mcgen(''' -void qapi_free_%(type)s(%(c_type)s obj) +void qapi_free_%(name)s(%(c_type)s obj) { QapiDeallocVisitor *md; Visitor *v; @@ -266,11 +267,11 @@ void qapi_free_%(type)s(%(c_type)s obj) md = qapi_dealloc_visitor_new(); v = qapi_dealloc_get_visitor(md); - visit_type_%(type)s(v, &obj, NULL, NULL); + visit_type_%(name)s(v, &obj, NULL, NULL); qapi_dealloc_visitor_cleanup(md); } ''', - c_type=c_type(name),type=name) + c_type=c_type(name), name=c_name(name)) return ret -- cgit v1.2.3 From 83a02706bb1fd31c93eab755de543dfe228682d4 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 14 May 2015 06:50:57 -0600 Subject: qapi: Support downstream structs Enhance the testsuite to cover downstream structs, including struct members and base structs. Update the generator to mangle the struct names in the appropriate places. Signed-off-by: Eric Blake Signed-off-by: Markus Armbruster --- scripts/qapi-types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/qapi-types.py') diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 1593fc6561..51181512bf 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -45,7 +45,7 @@ typedef struct %(name)sList struct %(name)sList *next; } %(name)sList; ''', - name=name) + name=c_name(name)) def generate_fwd_enum_struct(name, members): return mcgen(''' @@ -87,7 +87,7 @@ def generate_struct(expr): struct %(name)s { ''', - name=structname) + name=c_name(structname)) if base: ret += generate_struct_fields({'base': base}) -- cgit v1.2.3 From bb33729043ceda56b4068db13bdc17786ebd0ed0 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 14 May 2015 06:50:58 -0600 Subject: qapi: Support downstream simple unions Enhance the testsuite to cover downstream simple unions, including when a union branch is a downstream name. Update the generator to mangle the union names in the appropriate places. Signed-off-by: Eric Blake Signed-off-by: Markus Armbruster --- scripts/qapi-types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/qapi-types.py') diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 51181512bf..5b0bc5d353 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -193,7 +193,7 @@ const int %(name)s_qtypes[QTYPE_MAX] = { def generate_union(expr, meta): - name = expr[meta] + name = c_name(expr[meta]) typeinfo = expr['data'] base = expr.get('base') -- cgit v1.2.3 From 857af5f06c3fb097d1bb6bc8a23b9992aac99e75 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 14 May 2015 06:50:59 -0600 Subject: qapi: Support downstream flat unions Enhance the testsuite to cover downstream flat unions, including the base type, discriminator name and type, and branch name and type. Update the generator to mangle the union names in the appropriate places. Signed-off-by: Eric Blake Signed-off-by: Markus Armbruster --- scripts/qapi-types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/qapi-types.py') diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 5b0bc5d353..13e4b530f9 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -213,7 +213,7 @@ struct %(name)s void *data; ''', name=name, - discriminator_type_name=discriminator_type_name) + discriminator_type_name=c_name(discriminator_type_name)) for key in typeinfo: ret += mcgen(''' -- cgit v1.2.3 From d1f07c86c05706facf950b0b0dba370f71fd5ef6 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 14 May 2015 06:51:00 -0600 Subject: qapi: Support downstream alternates Enhance the testsuite to cover downstream alternates, including whether the branch name or type is downstream. Update the generator to mangle alternate names in the appropriate places. Signed-off-by: Eric Blake Signed-off-by: Markus Armbruster --- scripts/qapi-types.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'scripts/qapi-types.py') diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 13e4b530f9..56651451c9 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -174,16 +174,17 @@ def generate_alternate_qtypes(expr): ret = mcgen(''' const int %(name)s_qtypes[QTYPE_MAX] = { ''', - name=name) + name=c_name(name)) for key in members: qtype = find_alternate_member_qtype(members[key]) assert qtype, "Invalid alternate member" ret += mcgen(''' - [ %(qtype)s ] = %(enum_const)s, + [%(qtype)s] = %(enum_const)s, ''', - qtype = qtype, enum_const = c_enum_const(name + 'Kind', key)) + qtype = qtype, + enum_const = c_enum_const(name + 'Kind', key)) ret += mcgen(''' }; -- cgit v1.2.3 From 2114f5a98d0d80774306279e1694de074ca86aa0 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 2 Apr 2015 13:12:21 +0200 Subject: qapi: Factor parse_command_line() out of the generators Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi-types.py | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) (limited to 'scripts/qapi-types.py') diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 56651451c9..62044c11cb 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -11,9 +11,7 @@ from ordereddict import OrderedDict from qapi import * -import sys import os -import getopt import errno def generate_fwd_struct(name, members, builtin_type=False): @@ -275,43 +273,17 @@ void qapi_free_%(name)s(%(c_type)s obj) c_type=c_type(name), name=c_name(name)) return ret - -try: - opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:i:o:", - ["source", "header", "builtins", - "prefix=", "input-file=", "output-dir="]) -except getopt.GetoptError, err: - print str(err) - sys.exit(1) - -output_dir = "" -input_file = "" -prefix = "" c_file = 'qapi-types.c' h_file = 'qapi-types.h' - -do_c = False -do_h = False do_builtins = False +(input_file, output_dir, do_c, do_h, prefix, opts) = \ + parse_command_line("b", ["builtins"]) + for o, a in opts: - if o in ("-p", "--prefix"): - prefix = a - elif o in ("-i", "--input-file"): - input_file = a - elif o in ("-o", "--output-dir"): - output_dir = a + "/" - elif o in ("-c", "--source"): - do_c = True - elif o in ("-h", "--header"): - do_h = True - elif o in ("-b", "--builtins"): + if o in ("-b", "--builtins"): do_builtins = True -if not do_c and not do_h: - do_c = True - do_h = True - c_file = output_dir + prefix + c_file h_file = output_dir + prefix + h_file -- cgit v1.2.3 From 12f8e1b9ff57e99dafbb13f89cd5a99ad5c28527 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 2 Apr 2015 14:46:39 +0200 Subject: qapi: Factor open_output(), close_output() out of generators Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- scripts/qapi-types.py | 67 ++++++++++++++------------------------------------- 1 file changed, 18 insertions(+), 49 deletions(-) (limited to 'scripts/qapi-types.py') diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py index 62044c11cb..6bd0b13759 100644 --- a/scripts/qapi-types.py +++ b/scripts/qapi-types.py @@ -11,8 +11,6 @@ from ordereddict import OrderedDict from qapi import * -import os -import errno def generate_fwd_struct(name, members, builtin_type=False): if builtin_type: @@ -273,8 +271,6 @@ void qapi_free_%(name)s(%(c_type)s obj) c_type=c_type(name), name=c_name(name)) return ret -c_file = 'qapi-types.c' -h_file = 'qapi-types.h' do_builtins = False (input_file, output_dir, do_c, do_h, prefix, opts) = \ @@ -284,28 +280,7 @@ for o, a in opts: if o in ("-b", "--builtins"): do_builtins = True -c_file = output_dir + prefix + c_file -h_file = output_dir + prefix + h_file - -try: - os.makedirs(output_dir) -except os.error, e: - if e.errno != errno.EEXIST: - raise - -def maybe_open(really, name, opt): - if really: - return open(name, opt) - else: - import StringIO - return StringIO.StringIO() - -fdef = maybe_open(do_c, c_file, 'w') -fdecl = maybe_open(do_h, h_file, 'w') - -fdef.write(mcgen(''' -/* AUTOMATICALLY GENERATED, DO NOT MODIFY */ - +c_comment = ''' /* * deallocation functions for schema-defined QAPI types * @@ -319,16 +294,8 @@ fdef.write(mcgen(''' * See the COPYING.LIB file in the top-level directory. * */ - -#include "qapi/dealloc-visitor.h" -#include "%(prefix)sqapi-types.h" -#include "%(prefix)sqapi-visit.h" - -''', prefix=prefix)) - -fdecl.write(mcgen(''' -/* AUTOMATICALLY GENERATED, DO NOT MODIFY */ - +''' +h_comment = ''' /* * schema-defined QAPI types * @@ -341,15 +308,25 @@ fdecl.write(mcgen(''' * See the COPYING.LIB file in the top-level directory. * */ +''' -#ifndef %(guard)s -#define %(guard)s +(fdef, fdecl) = open_output(output_dir, do_c, do_h, prefix, + 'qapi-types.c', 'qapi-types.h', + c_comment, h_comment) +fdef.write(mcgen(''' +#include "qapi/dealloc-visitor.h" +#include "%(prefix)sqapi-types.h" +#include "%(prefix)sqapi-visit.h" + +''', + prefix=prefix)) + +fdecl.write(mcgen(''' #include #include -''', - guard=guardname(h_file))) +''')) exprs = parse_schema(input_file) exprs = filter(lambda expr: not expr.has_key('gen'), exprs) @@ -427,12 +404,4 @@ for expr in exprs: continue fdecl.write(ret) -fdecl.write(''' -#endif -''') - -fdecl.flush() -fdecl.close() - -fdef.flush() -fdef.close() +close_output(fdef, fdecl) -- cgit v1.2.3