for argname, argtype, optional in parse_args(args):
argtype = c_type(argtype, is_param=True)
if optional:
- arglist += "bool has_%s, " % c_var(argname)
- arglist += "%s %s, " % (argtype, c_var(argname))
+ arglist += "bool has_%s, " % c_name(argname)
+ arglist += "%s %s, " % (argtype, c_name(argname))
return mcgen('''
%(ret_type)s qmp_%(name)s(%(args)sError **errp);
''',
- ret_type=c_type(ret_type), name=c_fun(name), args=arglist).strip()
+ ret_type=c_type(ret_type), name=c_name(name),
+ args=arglist).strip()
def gen_err_check(errvar):
if errvar:
retval = "retval = "
for argname, argtype, optional in parse_args(args):
if optional:
- arglist += "has_%s, " % c_var(argname)
- arglist += "%s, " % (c_var(argname))
+ arglist += "has_%s, " % c_name(argname)
+ arglist += "%s, " % (c_name(argname))
push_indent(indent)
ret = mcgen('''
%(retval)sqmp_%(name)s(%(args)s&local_err);
''',
- name=c_fun(name), args=arglist, retval=retval).rstrip()
+ name=c_name(name), args=arglist, retval=retval).rstrip()
if ret_type:
ret += "\n" + gen_err_check('local_err')
ret += "\n" + mcgen(''''
def gen_marshal_output_call(name, ret_type):
if not ret_type:
return ""
- return "qmp_marshal_output_%s(retval, ret, &local_err);" % c_fun(name)
+ return "qmp_marshal_output_%s(retval, ret, &local_err);" % c_name(name)
def gen_visitor_input_containers_decl(args, obj):
ret = ""
ret += mcgen('''
bool has_%(argname)s = false;
''',
- argname=c_var(argname))
+ argname=c_name(argname))
if is_c_ptr(argtype):
ret += mcgen('''
%(argtype)s %(argname)s = NULL;
''',
- argname=c_var(argname), argtype=c_type(argtype))
+ argname=c_name(argname), argtype=c_type(argtype))
else:
ret += mcgen('''
%(argtype)s %(argname)s = {0};
''',
- argname=c_var(argname), argtype=c_type(argtype))
+ argname=c_name(argname), argtype=c_type(argtype))
pop_indent()
return ret.rstrip()
ret += mcgen('''
visit_optional(v, &has_%(c_name)s, "%(name)s", %(errp)s);
''',
- c_name=c_var(argname), name=argname, errp=errparg)
+ c_name=c_name(argname), name=argname, errp=errparg)
ret += gen_err_check(errarg)
ret += mcgen('''
if (has_%(c_name)s) {
''',
- c_name=c_var(argname))
+ c_name=c_name(argname))
push_indent()
ret += mcgen('''
%(visitor)s(v, &%(c_name)s, "%(name)s", %(errp)s);
''',
- c_name=c_var(argname), name=argname, argtype=argtype,
+ c_name=c_name(argname), name=argname, argtype=argtype,
visitor=type_visitor(argtype), errp=errparg)
ret += gen_err_check(errarg)
if optional:
qapi_dealloc_visitor_cleanup(md);
}
''',
- c_ret_type=c_type(ret_type), c_name=c_fun(name),
+ c_ret_type=c_type(ret_type), c_name=c_name(name),
visitor=type_visitor(ret_type))
return ret
def gen_marshal_input_decl(name, args, ret_type, middle_mode):
if middle_mode:
- return 'int qmp_marshal_input_%s(Monitor *mon, const QDict *qdict, QObject **ret)' % c_fun(name)
+ return 'int qmp_marshal_input_%s(Monitor *mon, const QDict *qdict, QObject **ret)' % c_name(name)
else:
- return 'static void qmp_marshal_input_%s(QDict *args, QObject **ret, Error **errp)' % c_fun(name)
+ return 'static void qmp_marshal_input_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name)
registry += mcgen('''
qmp_register_command("%(name)s", qmp_marshal_input_%(c_name)s, %(opts)s);
''',
- name=cmd['command'], c_name=c_fun(cmd['command']),
+ name=cmd['command'], c_name=c_name(cmd['command']),
opts=options)
pop_indent()
ret = mcgen('''
goto out;
}
''',
- type=type_name(base), c_name=c_var('base'))
+ type=type_name(base), c_name=c_name('base'))
for argname, argentry, optional in parse_args(members):
if optional:
visit_optional(m, &(*obj)->has_%(c_name)s, "%(name)s", &err);
if (!err && (*obj)->has_%(c_name)s) {
''',
- c_name=c_var(argname), name=argname)
+ c_name=c_name(argname), name=argname)
push_indent()
ret += mcgen('''
visit_type_%(type)s(m, &(*obj)->%(c_name)s, "%(name)s", &err);
''',
- type=type_name(argentry), c_name=c_var(argname),
+ type=type_name(argentry), c_name=c_name(argname),
name=argname)
if optional:
''',
enum_full_value = enum_full_value,
c_type = type_name(members[key]),
- c_name = c_fun(key))
+ c_name = c_name(key))
ret += mcgen('''
default:
''',
enum_full_value = enum_full_value,
c_type=type_name(members[key]),
- c_name=c_fun(key))
+ c_name=c_name(key))
ret += mcgen('''
default:
new_name += ch.lower()
return new_name
-c_var_trans = string.maketrans('.-', '__')
+c_name_trans = string.maketrans('.-', '__')
-def c_var(name, protect=True):
+def c_name(name, protect=True):
# ANSI X3J11/88-090, 3.1.1
c89_words = set(['auto', 'break', 'case', 'char', 'const', 'continue',
'default', 'do', 'double', 'else', 'enum', 'extern', 'float',
polluted_words = set(['unix', 'errno'])
if protect and (name in c89_words | c99_words | c11_words | gcc_words | cpp_words | polluted_words):
return "q_" + name
- return name.translate(c_var_trans)
-
-def c_fun(name, protect=True):
- return c_var(name, protect)
+ return name.translate(c_name_trans)
def c_list_type(name):
return '%sList' % name
# ENUM_NAME -> ENUM_NAME, ENUM_NAME1 -> ENUM_NAME1, ENUM_Name2 -> ENUM_NAME2
# ENUM24_Name -> ENUM24_NAME
def _generate_enum_string(value):
- c_fun_str = c_fun(value, False)
+ c_fun_str = c_name(value, False)
if value.isupper():
return c_fun_str