Eolian: Add dedicated function for removing type prefixes, handle short
This commit is contained in:
parent
67d9128089
commit
d4c47203e2
|
@ -61,6 +61,7 @@ complex_types = (
|
|||
param_type_mapping = {
|
||||
# c_type: (py_type, conversion, c_param_convert)
|
||||
"int": (None, None, None),
|
||||
"short": (None, None, None),
|
||||
"double": (None, None, None),
|
||||
"Evas_Coord": ("int", None, None),
|
||||
"Eina_Bool": ("bint", None, None),
|
||||
|
@ -76,6 +77,7 @@ param_type_mapping = {
|
|||
return_type_mapping = {
|
||||
# c_type: (py_type, conversion)
|
||||
"int": (None, None),
|
||||
"short": (None, None, None),
|
||||
"double": (None, None),
|
||||
"Evas_Coord": ("int", None),
|
||||
"Eina_Bool": ("bint", None),
|
||||
|
@ -109,6 +111,12 @@ def conv_func_name(prefix, func_name):
|
|||
return "_".join((prefix, func_name))
|
||||
|
||||
|
||||
def remove_type_prefixes(ctype):
|
||||
for t in "const ", "unsigned ", "short ":
|
||||
ctype = ctype.replace(t, "")
|
||||
return ctype
|
||||
|
||||
|
||||
class Generator(object):
|
||||
|
||||
tab = " "
|
||||
|
@ -265,7 +273,7 @@ class Method(object):
|
|||
|
||||
for p in func.parameters_list:
|
||||
pdir, ptype, name, desc = p.information
|
||||
ptype2 = ptype.replace("const ", "").replace("unsigned ", "")
|
||||
ptype2 = remove_type_prefixes(ptype)
|
||||
if not ptype2 in param_type_mapping:
|
||||
if not ptype2 in enums:
|
||||
raise TypeError("Unknown param type: %s" % (ptype2))
|
||||
|
@ -289,7 +297,7 @@ class Method(object):
|
|||
|
||||
ret_type = func.return_type_get(func.type)
|
||||
if ret_type:
|
||||
ret_type2 = ret_type.replace("const ", "").replace("unsigned ", "")
|
||||
ret_type2 = remove_type_prefixes(ret_type)
|
||||
if not ret_type2 in return_type_mapping:
|
||||
if not ret_type2 in enums:
|
||||
raise TypeError("Unknown return type: %s" % (ret_type2))
|
||||
|
@ -346,7 +354,7 @@ class Method(object):
|
|||
if self.ret_type:
|
||||
t = self.ret_type
|
||||
if t in return_type_mapping:
|
||||
c_t = t.replace("const ", "").replace("unsigned ", "")
|
||||
c_t = remove_type_prefixes(t)
|
||||
py_t = return_type_mapping[c_t][0]
|
||||
if py_t is not None:
|
||||
t = py_t
|
||||
|
@ -360,14 +368,14 @@ class Method(object):
|
|||
gen.write(conv)
|
||||
|
||||
for t, n in self.py_params:
|
||||
t = t.replace("const ", "")
|
||||
t = remove_type_prefixes(t)
|
||||
if t in param_type_mapping:
|
||||
conv = param_type_mapping[t][1]
|
||||
if conv:
|
||||
gen.write(conv.format(n, t))
|
||||
|
||||
for i, (t, n) in enumerate(self.c_params):
|
||||
t2 = t.replace("const ", "")
|
||||
t2 = remove_type_prefixes(t)
|
||||
if t2 in param_type_mapping:
|
||||
conv = param_type_mapping[t2][2]
|
||||
if conv:
|
||||
|
@ -385,7 +393,7 @@ class Method(object):
|
|||
if self.returns:
|
||||
ret = self.returns[:]
|
||||
for i, (t, n) in enumerate(self.returns):
|
||||
t = t.replace("const ", "")
|
||||
t = remove_type_prefixes(t)
|
||||
if t in return_type_mapping:
|
||||
conv = return_type_mapping[t][1]
|
||||
if conv:
|
||||
|
@ -471,7 +479,7 @@ class Property(object):
|
|||
for p in func.property_values_list:
|
||||
pdir, ptype, name, desc = p.information
|
||||
assert pdir == eolian.ParameterDir.IN, "prop has other than IN"
|
||||
ptype2 = ptype.replace("const ", "").replace("unsigned ", "")
|
||||
ptype2 = remove_type_prefixes(ptype)
|
||||
if not ptype2 in param_type_mapping:
|
||||
if not ptype2 in enums:
|
||||
raise TypeError("Unknown param type: %s" % (ptype2))
|
||||
|
@ -492,8 +500,7 @@ class Property(object):
|
|||
|
||||
m.ret_type = func.return_type_get(eolian.FunctionType.PROP_SET)
|
||||
if m.ret_type:
|
||||
ret_type2 = m.ret_type.replace(
|
||||
"const ", "").replace("unsigned ", "")
|
||||
ret_type2 = remove_type_prefixes(m.ret_type)
|
||||
if not ret_type2 in return_type_mapping:
|
||||
if not ret_type2 in enums:
|
||||
raise TypeError(
|
||||
|
@ -518,7 +525,7 @@ class Property(object):
|
|||
for p in func.property_values_list:
|
||||
pdir, ptype, name, desc = p.information
|
||||
assert pdir == eolian.ParameterDir.IN, "prop has other than IN"
|
||||
ptype2 = ptype.replace("const ", "").replace("unsigned ", "")
|
||||
ptype2 = remove_type_prefixes(ptype)
|
||||
if not ptype2 in param_type_mapping:
|
||||
if not ptype2 in enums:
|
||||
raise TypeError("Unknown param type: %s" % (ptype2))
|
||||
|
@ -532,8 +539,7 @@ class Property(object):
|
|||
|
||||
m.ret_type = func.return_type_get(eolian.FunctionType.PROP_GET)
|
||||
if m.ret_type:
|
||||
ret_type2 = m.ret_type.replace(
|
||||
"const ", "").replace("unsigned ", "")
|
||||
ret_type2 = remove_type_prefixes(m.ret_type)
|
||||
if not ret_type2 in return_type_mapping:
|
||||
if not ret_type2 in enums:
|
||||
raise TypeError(
|
||||
|
|
Loading…
Reference in New Issue