Eolian: Raise an exception if param/return type is unknown

This commit is contained in:
Kai Huuhko 2014-06-19 18:53:16 +03:00
parent a9e0bb6f4d
commit 0ee569672b
1 changed files with 45 additions and 9 deletions

View File

@ -51,17 +51,25 @@ complex_types = (
)
param_type_mapping = {
"Eina_Bool": ("bint", None, None),
# c_type: (py_type, conversion, c_param_convert)
"int": (None, None, None),
"double": (None, None, None),
"Evas_Coord": ("int", None, None),
"Eina_Bool": ("bint", None, None),
"char *": (
"",
"if isinstance({0}, unicode): {0} = PyUnicode_AsUTF8String({0})",
"<{1}>if {0} is not None else NULL"
),
"Eo *": ("_Eo_Base", None, "{0}.obj")
"Evas_Object *": ("_Eo_Base", None, "{0}.obj"),
"Eo *": ("_Eo_Base", None, "{0}.obj"),
}
return_type_mapping = {
# c_type: (py_type, conversion)
"int": (None, None),
"double": (None, None),
"Evas_Coord": ("int", None),
"Eina_Bool": ("bint", None),
"char *": ("unicode", '{0}.decode("utf-8")'),
"Elm_Object_Item *": (
@ -142,8 +150,11 @@ class PyxGenerator(Generator):
params2.append("self")
for t, n in params:
t.replace("const ", "")
t = param_type_mapping.get(t, ("", None))[0]
if t in param_type_mapping:
c_t = t.replace("const ", "").replace("unsigned ", "")
py_t = param_type_mapping[c_t][0]
if py_t is not None:
t = py_t
params2.append(" ".join((t, n)).strip())
params2 = ", ".join(params2)
@ -203,6 +214,11 @@ class Method(object):
for p in func.parameters_list:
pdir, ptype, name, desc = p.information
ptype2 = ptype.replace("const ", "").replace("unsigned ", "")
if not ptype2 in param_type_mapping:
for t in eolian.type_find_by_alias(ptype2):
print(t)
raise TypeError("Unknown param type: %s" % (ptype2))
self.params.append((ptype, name))
if pdir == eolian.ParameterDir.IN:
self.py_params.append((ptype, name))
@ -218,7 +234,14 @@ class Method(object):
self.c_params.append((ptype, name))
self.returns.append((ptype, name))
self.ret_type = func.return_type_get(func.type)
ret_type = func.return_type_get(func.type)
if ret_type:
ret_type2 = ret_type.replace("const ", "").replace("unsigned ", "")
if not ret_type2 in return_type_mapping:
for t in eolian.type_find_by_alias(ret_type2):
print(t)
raise TypeError("Unknown return type: %s" % (ret_type2))
self.ret_type = ret_type
ret_desc = func.return_comment_get(func.type)
if self.returns:
@ -243,10 +266,13 @@ class Method(object):
gen.docstring_write(self.docs)
if self.ret_type:
r_type = self.ret_type
if r_type in return_type_mapping:
r_type = return_type_mapping[r_type][0]
self.cdefs.append((r_type, RET_PARAM))
t = self.ret_type
if t in return_type_mapping:
c_t = t.replace("const ", "").replace("unsigned ", "")
py_t = return_type_mapping[c_t][0]
if py_t is not None:
t = py_t
self.cdefs.append((t, RET_PARAM))
if self.cdefs:
gen.cdefs_write(self.cdefs)
@ -354,6 +380,11 @@ 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 ", "")
if not ptype2 in param_type_mapping:
for t in eolian.type_find_by_alias(ptype2):
print(t)
raise TypeError("Unknown param type: %s" % (ptype2))
m.params.append((ptype, name))
py_params.append(name)
m.c_params.append((ptype, name))
@ -377,6 +408,11 @@ 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 ", "")
if not ptype2 in param_type_mapping:
for t in eolian.type_find_by_alias(ptype2):
print(t)
raise TypeError("Unknown param type: %s" % (ptype2))
m.params.append((ptype, name))
m.cdefs.append((ptype, name))
m.c_params.append((ptype, "&%s" % (name)))