mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-01-22 19:51:10 +00:00
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. Backports commit 18df515ebbefa9f13474b128b8050d5fa346ea1e from qemu
This commit is contained in:
parent
baab1986a3
commit
f114c7b027
|
@ -17,17 +17,17 @@ import getopt
|
|||
import errno
|
||||
|
||||
def _generate_event_api_name(event_name, params):
|
||||
api_name = "void qapi_event_send_%s(" % c_fun(event_name).lower();
|
||||
api_name = "void qapi_event_send_%s(" % c_name(event_name).lower();
|
||||
l = len(api_name)
|
||||
|
||||
if params:
|
||||
for argname, argentry, optional in parse_args(params):
|
||||
if optional:
|
||||
api_name += "bool has_%s,\n" % c_var(argname)
|
||||
api_name += "bool has_%s,\n" % c_name(argname)
|
||||
api_name += "".ljust(l)
|
||||
|
||||
api_name += "%s %s,\n" % (c_type(argentry, is_param=True),
|
||||
c_var(argname))
|
||||
c_name(argname))
|
||||
api_name += "".ljust(l)
|
||||
|
||||
api_name += "Error **errp)"
|
||||
|
@ -98,7 +98,7 @@ def generate_event_implement(api_name, event_name, params):
|
|||
ret += mcgen("""
|
||||
if (has_%(var)s) {
|
||||
""",
|
||||
var = c_var(argname))
|
||||
var = c_name(argname))
|
||||
push_indent()
|
||||
|
||||
if argentry == "str":
|
||||
|
@ -113,7 +113,7 @@ def generate_event_implement(api_name, event_name, params):
|
|||
}
|
||||
""",
|
||||
var_type = var_type,
|
||||
var = c_var(argname),
|
||||
var = c_name(argname),
|
||||
type = type_name(argentry),
|
||||
name = argname)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -173,7 +173,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('''
|
||||
};
|
||||
|
@ -210,7 +210,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('''
|
||||
};
|
||||
|
|
|
@ -66,7 +66,7 @@ if (err) {
|
|||
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:
|
||||
|
@ -74,13 +74,13 @@ if (err) {
|
|||
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:
|
||||
|
@ -223,7 +223,7 @@ void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error **e
|
|||
''',
|
||||
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:
|
||||
|
@ -324,7 +324,7 @@ void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error **e
|
|||
''',
|
||||
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:
|
||||
|
|
|
@ -752,9 +752,9 @@ def camel_case(name):
|
|||
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',
|
||||
|
@ -783,10 +783,7 @@ def c_var(name, protect=True):
|
|||
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
|
||||
|
@ -944,7 +941,7 @@ def guardend(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
|
||||
|
||||
|
|
Loading…
Reference in a new issue