提交 086ee7a6 编写于 作者: M Marc-André Lureau 提交者: Markus Armbruster

scripts: use build_ prefix for string not piped through cgen()

The gen_ prefix is awkward.  Generated C should go through cgen()
exactly once (see commit 1f9a7a1a).  The common way to get this wrong is
passing a foo=gen_foo() keyword argument to mcgen().  I'd like us to
adopt a naming convention where gen_ means "something that's been piped
through cgen(), and thus must not be passed to cgen() or mcgen()".
Requires renaming gen_params(), gen_marshal_proto() and
gen_event_send_proto().
Suggested-by: NMarkus Armbruster <armbru@redhat.com>
Signed-off-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20170601124143.10915-1-marcandre.lureau@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
上级 8a4613a0
...@@ -21,7 +21,7 @@ def gen_command_decl(name, arg_type, boxed, ret_type): ...@@ -21,7 +21,7 @@ def gen_command_decl(name, arg_type, boxed, ret_type):
''', ''',
c_type=(ret_type and ret_type.c_type()) or 'void', c_type=(ret_type and ret_type.c_type()) or 'void',
c_name=c_name(name), c_name=c_name(name),
params=gen_params(arg_type, boxed, 'Error **errp')) params=build_params(arg_type, boxed, 'Error **errp'))
def gen_call(name, arg_type, boxed, ret_type): def gen_call(name, arg_type, boxed, ret_type):
...@@ -82,7 +82,7 @@ static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, QObject **ret_out, ...@@ -82,7 +82,7 @@ static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, QObject **ret_out,
c_type=ret_type.c_type(), c_name=ret_type.c_name()) c_type=ret_type.c_type(), c_name=ret_type.c_name())
def gen_marshal_proto(name): def build_marshal_proto(name):
return ('void qmp_marshal_%s(QDict *args, QObject **ret, Error **errp)' return ('void qmp_marshal_%s(QDict *args, QObject **ret, Error **errp)'
% c_name(name)) % c_name(name))
...@@ -91,7 +91,7 @@ def gen_marshal_decl(name): ...@@ -91,7 +91,7 @@ def gen_marshal_decl(name):
return mcgen(''' return mcgen('''
%(proto)s; %(proto)s;
''', ''',
proto=gen_marshal_proto(name)) proto=build_marshal_proto(name))
def gen_marshal(name, arg_type, boxed, ret_type): def gen_marshal(name, arg_type, boxed, ret_type):
...@@ -103,7 +103,7 @@ def gen_marshal(name, arg_type, boxed, ret_type): ...@@ -103,7 +103,7 @@ def gen_marshal(name, arg_type, boxed, ret_type):
{ {
Error *err = NULL; Error *err = NULL;
''', ''',
proto=gen_marshal_proto(name)) proto=build_marshal_proto(name))
if ret_type: if ret_type:
ret += mcgen(''' ret += mcgen('''
......
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
from qapi import * from qapi import *
def gen_event_send_proto(name, arg_type, boxed): def build_event_send_proto(name, arg_type, boxed):
return 'void qapi_event_send_%(c_name)s(%(param)s)' % { return 'void qapi_event_send_%(c_name)s(%(param)s)' % {
'c_name': c_name(name.lower()), 'c_name': c_name(name.lower()),
'param': gen_params(arg_type, boxed, 'Error **errp')} 'param': build_params(arg_type, boxed, 'Error **errp')}
def gen_event_send_decl(name, arg_type, boxed): def gen_event_send_decl(name, arg_type, boxed):
...@@ -25,10 +25,10 @@ def gen_event_send_decl(name, arg_type, boxed): ...@@ -25,10 +25,10 @@ def gen_event_send_decl(name, arg_type, boxed):
%(proto)s; %(proto)s;
''', ''',
proto=gen_event_send_proto(name, arg_type, boxed)) proto=build_event_send_proto(name, arg_type, boxed))
# Declare and initialize an object 'qapi' using parameters from gen_params() # Declare and initialize an object 'qapi' using parameters from build_params()
def gen_param_var(typ): def gen_param_var(typ):
assert not typ.variants assert not typ.variants
ret = mcgen(''' ret = mcgen('''
...@@ -42,7 +42,7 @@ def gen_param_var(typ): ...@@ -42,7 +42,7 @@ def gen_param_var(typ):
if memb.optional: if memb.optional:
ret += 'has_' + c_name(memb.name) + sep ret += 'has_' + c_name(memb.name) + sep
if memb.type.name == 'str': if memb.type.name == 'str':
# Cast away const added in gen_params() # Cast away const added in build_params()
ret += '(char *)' ret += '(char *)'
ret += c_name(memb.name) ret += c_name(memb.name)
ret += mcgen(''' ret += mcgen('''
...@@ -72,7 +72,7 @@ def gen_event_send(name, arg_type, boxed): ...@@ -72,7 +72,7 @@ def gen_event_send(name, arg_type, boxed):
Error *err = NULL; Error *err = NULL;
QMPEventFuncEmit emit; QMPEventFuncEmit emit;
''', ''',
proto=gen_event_send_proto(name, arg_type, boxed)) proto=build_event_send_proto(name, arg_type, boxed))
if arg_type and not arg_type.is_empty(): if arg_type and not arg_type.is_empty():
ret += mcgen(''' ret += mcgen('''
......
...@@ -1897,7 +1897,7 @@ extern const char *const %(c_name)s_lookup[]; ...@@ -1897,7 +1897,7 @@ extern const char *const %(c_name)s_lookup[];
return ret return ret
def gen_params(arg_type, boxed, extra): def build_params(arg_type, boxed, extra):
if not arg_type: if not arg_type:
assert not boxed assert not boxed
return extra return extra
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册