Eolian: WIP
This commit is contained in:
parent
99d5ccd87b
commit
9af2bbe472
|
@ -21,7 +21,7 @@ complex_types = (
|
||||||
"Eina_List"
|
"Eina_List"
|
||||||
)
|
)
|
||||||
|
|
||||||
param_type_mapping = {
|
mapping_in = {
|
||||||
# c_type: pyx_type
|
# c_type: pyx_type
|
||||||
"Eina_Bool": "bint",
|
"Eina_Bool": "bint",
|
||||||
"char *": "",
|
"char *": "",
|
||||||
|
@ -29,7 +29,7 @@ param_type_mapping = {
|
||||||
"Eo *": "_Eo_Base",
|
"Eo *": "_Eo_Base",
|
||||||
}
|
}
|
||||||
|
|
||||||
param_conversions = {
|
conversions_in = {
|
||||||
# c_type: (conversion, c_param_convert)
|
# c_type: (conversion, c_param_convert)
|
||||||
"Eina_Bool": (None, None),
|
"Eina_Bool": (None, None),
|
||||||
"char *": (
|
"char *": (
|
||||||
|
@ -40,7 +40,7 @@ param_conversions = {
|
||||||
"Eo *": (None, "{0}.obj"),
|
"Eo *": (None, "{0}.obj"),
|
||||||
}
|
}
|
||||||
|
|
||||||
return_type_mapping = {
|
mapping_out = {
|
||||||
# c_type: pyx_type
|
# c_type: pyx_type
|
||||||
"Eina_Bool": "bint",
|
"Eina_Bool": "bint",
|
||||||
"char *": "unicode",
|
"char *": "unicode",
|
||||||
|
@ -49,9 +49,9 @@ return_type_mapping = {
|
||||||
"Eo *": "_Eo_Base",
|
"Eo *": "_Eo_Base",
|
||||||
}
|
}
|
||||||
|
|
||||||
return_conversions = {
|
conversions_out = {
|
||||||
# c_type: conversion
|
# c_type: conversion
|
||||||
"Eina_Bool": None,
|
"Eina_Bool": "{0}",
|
||||||
"char *": '{0}.decode("utf-8")',
|
"char *": '{0}.decode("utf-8")',
|
||||||
"Elm_Object_Item *": 'object_item_to_python({0})',
|
"Elm_Object_Item *": 'object_item_to_python({0})',
|
||||||
"Evas_Object *": 'object_from_instance({0})',
|
"Evas_Object *": 'object_from_instance({0})',
|
||||||
|
@ -74,12 +74,15 @@ def remove_type_prefixes(ctype):
|
||||||
|
|
||||||
|
|
||||||
def convert_in_param(c_type, name):
|
def convert_in_param(c_type, name):
|
||||||
pass
|
c_type = conversions_in.get(c_type, c_type)
|
||||||
return c_type, name
|
return c_type, name
|
||||||
|
|
||||||
|
|
||||||
def convert_out_param(c_type, name):
|
def convert_out_param(c_type, name):
|
||||||
pass
|
conv = conversions_out.get(c_type)
|
||||||
|
if not conv:
|
||||||
|
return c_type, name
|
||||||
|
name = conv.format(name)
|
||||||
return c_type, name
|
return c_type, name
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,9 @@ class Generator(object):
|
||||||
|
|
||||||
|
|
||||||
class PyxGenerator(Generator):
|
class PyxGenerator(Generator):
|
||||||
|
|
||||||
|
RET_PARAM = "py_efl_ret"
|
||||||
|
|
||||||
def method_header_write(self, name, params, clsm=False):
|
def method_header_write(self, name, params, clsm=False):
|
||||||
params2 = []
|
params2 = []
|
||||||
if clsm:
|
if clsm:
|
||||||
|
@ -117,6 +120,8 @@ class PyxGenerator(Generator):
|
||||||
self.write(define)
|
self.write(define)
|
||||||
|
|
||||||
def out_cdefs_write(self, out_cdefs):
|
def out_cdefs_write(self, out_cdefs):
|
||||||
|
if not out_cdefs:
|
||||||
|
return
|
||||||
self.write("cdef:")
|
self.write("cdef:")
|
||||||
self.indent()
|
self.indent()
|
||||||
types = {}
|
types = {}
|
||||||
|
@ -134,9 +139,10 @@ class PyxGenerator(Generator):
|
||||||
self.dedent()
|
self.dedent()
|
||||||
|
|
||||||
def c_call_write(self, c_name, c_params, ret_type=None, returns=None):
|
def c_call_write(self, c_name, c_params, ret_type=None, returns=None):
|
||||||
|
c_params = ", ".join(c_params)
|
||||||
c_call = "eo_do(self.obj, %s(%s))" % (c_name, c_params)
|
c_call = "eo_do(self.obj, %s(%s))" % (c_name, c_params)
|
||||||
if ret_type:
|
if ret_type:
|
||||||
c_call = self.RET_PARAM + " = " + c_call
|
c_call = "cdef " + ret_type + " " + self.RET_PARAM + " = " + "<{0}>".format(ret_type) + c_call
|
||||||
self.write(c_call)
|
self.write(c_call)
|
||||||
|
|
||||||
|
|
||||||
|
@ -180,11 +186,13 @@ class Function(object):
|
||||||
|
|
||||||
def generate(self, gen):
|
def generate(self, gen):
|
||||||
func = self.func
|
func = self.func
|
||||||
|
py_name = None
|
||||||
c_name = self.c_name
|
c_name = self.c_name
|
||||||
|
|
||||||
header_params = []
|
header_params = []
|
||||||
c_call_params = []
|
c_call_params = []
|
||||||
return_params = []
|
return_params = []
|
||||||
|
conv_params = []
|
||||||
|
|
||||||
out_cdefs = []
|
out_cdefs = []
|
||||||
|
|
||||||
|
@ -207,23 +215,19 @@ class Function(object):
|
||||||
name = p.name
|
name = p.name
|
||||||
|
|
||||||
if di == eolian.ParameterDir.IN:
|
if di == eolian.ParameterDir.IN:
|
||||||
#c_type = convert_in_param((c_type, name))
|
#c_type, name = convert_in_param(c_type, name)
|
||||||
header_params.append((c_type, name))
|
header_params.append((c_type, name))
|
||||||
|
c_call_params.append(name)
|
||||||
elif di == eolian.ParameterDir.OUT:
|
elif di == eolian.ParameterDir.OUT:
|
||||||
out_cdefs.append((c_type, "&"+name))
|
out_cdefs.append((c_type, "&"+name))
|
||||||
#c_type = convert_out_param((c_type, name))
|
c_type, name = convert_out_param(c_type, name)
|
||||||
return_params.append((c_type, name))
|
return_params.append((c_type, name))
|
||||||
elif di == eolian.ParameterDir.INOUT:
|
elif di == eolian.ParameterDir.INOUT:
|
||||||
pass
|
log.error("TODO: INOUT params")
|
||||||
|
|
||||||
gen.method_header_write(py_name, header_params)
|
|
||||||
gen.indent()
|
|
||||||
|
|
||||||
ret_type = func.return_type_get(eolian.FunctionType.METHOD)
|
ret_type = func.return_type_get(eolian.FunctionType.METHOD)
|
||||||
if ret_type.type != eolian.TypeType.UNKNOWN:
|
|
||||||
out_cdefs.append((ret_type.c_type, self.RET_PARAM))
|
|
||||||
|
|
||||||
if func.type == ftypes.PROP_SET or func.type == ftypes.PROPERTY and not self.isget:
|
if (func.type == ftypes.PROP_SET or func.type == ftypes.PROPERTY) and not self.isget:
|
||||||
|
|
||||||
py_name = "__set__"
|
py_name = "__set__"
|
||||||
c_name = "_".join((c_name, "set"))
|
c_name = "_".join((c_name, "set"))
|
||||||
|
@ -236,26 +240,18 @@ class Function(object):
|
||||||
|
|
||||||
c_type = p.type.c_type
|
c_type = p.type.c_type
|
||||||
name = p.name
|
name = p.name
|
||||||
|
#c_type, name = convert_in_param(c_type, name)
|
||||||
|
|
||||||
conv_params.append((c_type, name))
|
conv_params.append(name)
|
||||||
#c_params.append((c_type, name))
|
c_call_params.append(name)
|
||||||
|
|
||||||
assert conv_params, "params should not be empty for setter of: %s" % (func.name)
|
assert conv_params, "params should not be empty for setter of: %s" % (func.name)
|
||||||
|
|
||||||
header_params = (("", "value"),)
|
header_params = (("", "value"),)
|
||||||
|
|
||||||
gen.method_header_write(py_name, header_params)
|
|
||||||
gen.indent()
|
|
||||||
|
|
||||||
#params_conv = "%s = value" % (conv_params)
|
|
||||||
|
|
||||||
gen.c_call_write(c_name, c_call_params, ret_type, return_params)
|
|
||||||
|
|
||||||
ret_type = func.return_type_get(eolian.FunctionType.PROP_SET)
|
ret_type = func.return_type_get(eolian.FunctionType.PROP_SET)
|
||||||
if ret_type.type != eolian.TypeType.UNKNOWN:
|
|
||||||
ret_type = ret_type.c_type
|
|
||||||
|
|
||||||
if func.type == ftypes.PROP_GET or func.type == ftypes.PROPERTY and self.isget:
|
if (func.type == ftypes.PROP_GET or func.type == ftypes.PROPERTY) and self.isget:
|
||||||
|
|
||||||
py_name = "__get__"
|
py_name = "__get__"
|
||||||
c_name = "_".join((c_name, "get"))
|
c_name = "_".join((c_name, "get"))
|
||||||
|
@ -264,23 +260,39 @@ class Function(object):
|
||||||
|
|
||||||
#assert p.direction == eolian.ParameterDir.OUT, "prop %s getter has param other than OUT" % (c_name)
|
#assert p.direction == eolian.ParameterDir.OUT, "prop %s getter has param other than OUT" % (c_name)
|
||||||
|
|
||||||
out_cdefs.append((p.type.c_type, p.name))
|
c_type = p.type.c_type
|
||||||
c_call_params.append((p.type.c_type, "&%s" % (p.name)))
|
name = p.name
|
||||||
return_params.append((p.type.c_type, p.name))
|
|
||||||
|
|
||||||
gen.method_header_write(py_name, header_params)
|
out_cdefs.append((c_type, name))
|
||||||
gen.indent()
|
c_call_params.append("&%s" % (name))
|
||||||
|
c_type, name = convert_out_param(c_type, name)
|
||||||
gen.c_call_write(c_name, c_call_params, ret_type, return_params)
|
return_params.append((c_type, name))
|
||||||
|
|
||||||
ret_type = func.return_type_get(eolian.FunctionType.PROP_GET)
|
ret_type = func.return_type_get(eolian.FunctionType.PROP_GET)
|
||||||
if ret_type.type != eolian.TypeType.UNKNOWN:
|
|
||||||
ret_type = ret_type.c_type
|
if not py_name:
|
||||||
|
return
|
||||||
|
|
||||||
|
gen.method_header_write(py_name, header_params)
|
||||||
|
gen.indent()
|
||||||
|
|
||||||
|
if conv_params:
|
||||||
|
conv_params = ", ".join(conv_params)
|
||||||
|
gen.write("%s = value" % (conv_params))
|
||||||
|
|
||||||
|
gen.out_cdefs_write(out_cdefs)
|
||||||
|
|
||||||
|
if ret_type.type != eolian.TypeType.UNKNOWN:
|
||||||
|
ret_type2 = ret_type.c_type
|
||||||
|
else:
|
||||||
|
ret_type2 = None
|
||||||
|
|
||||||
|
gen.c_call_write(c_name, c_call_params, ret_type2, return_params)
|
||||||
|
|
||||||
if return_params:
|
if return_params:
|
||||||
ret = return_params[:]
|
ret = return_params[:]
|
||||||
gen.write("return %s" % (", ".join([r[1] for r in ret])))
|
gen.write("return %s" % (", ".join([r[1] for r in ret])))
|
||||||
elif ret_type != eolian.TypeType.UNKNOWN:
|
elif ret_type.type != eolian.TypeType.UNKNOWN:
|
||||||
ret = self.RET_PARAM
|
ret = self.RET_PARAM
|
||||||
gen.write("return %s" % (ret))
|
gen.write("return %s" % (ret))
|
||||||
|
|
||||||
|
@ -438,8 +450,9 @@ class Class(object):
|
||||||
o = EoConstructor.parse(ctor, prefix)
|
o = EoConstructor.parse(ctor, prefix)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warn(
|
log.warn(
|
||||||
"Skipping %s.%s because of an exception"
|
"Skipping %s.%s because of an exception",
|
||||||
% (cls.name, ctor.full_name))
|
cls.name, ctor.full_name
|
||||||
|
)
|
||||||
log.warn(e)
|
log.warn(e)
|
||||||
log.debug(format_exc())
|
log.debug(format_exc())
|
||||||
continue
|
continue
|
||||||
|
@ -453,19 +466,32 @@ class Class(object):
|
||||||
|
|
||||||
props = cls.functions_get(eolian.FunctionType.PROPERTY)
|
props = cls.functions_get(eolian.FunctionType.PROPERTY)
|
||||||
for prop in props:
|
for prop in props:
|
||||||
|
if not prop.scope == eolian.ObjectScope.PUBLIC:
|
||||||
|
log.debug(
|
||||||
|
"Skipping non-public property %s.%s",
|
||||||
|
cls.name, prop.name
|
||||||
|
)
|
||||||
|
continue
|
||||||
function_counter["_".join((prefix, prop.name))] += 1
|
function_counter["_".join((prefix, prop.name))] += 1
|
||||||
try:
|
try:
|
||||||
o = Property(prop, prefix)
|
o = Property(prop, prefix)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(
|
log.exception(
|
||||||
"Skipping %s.%s because of an exception"
|
"Skipping %s.%s because of an exception",
|
||||||
% (cls.name, prop.name))
|
cls.name, prop.name
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
self.props.append(o)
|
self.props.append(o)
|
||||||
generated_function_counter["_".join((prefix, prop.name))] += 1
|
generated_function_counter["_".join((prefix, prop.name))] += 1
|
||||||
|
|
||||||
methods = cls.functions_get(eolian.FunctionType.METHOD)
|
methods = cls.functions_get(eolian.FunctionType.METHOD)
|
||||||
for method in methods:
|
for method in methods:
|
||||||
|
if not method.scope == eolian.ObjectScope.PUBLIC:
|
||||||
|
log.debug(
|
||||||
|
"Skipping non-public method %s.%s",
|
||||||
|
cls.name, method.name
|
||||||
|
)
|
||||||
|
continue
|
||||||
function_counter["_".join((prefix, method.name))] += 1
|
function_counter["_".join((prefix, method.name))] += 1
|
||||||
try:
|
try:
|
||||||
o = Function(method, prefix)
|
o = Function(method, prefix)
|
||||||
|
@ -602,8 +628,18 @@ with open(py_path, "a") as py_f:
|
||||||
pyxgen = PyxGenerator()
|
pyxgen = PyxGenerator()
|
||||||
gencls.pyx_generate(pyxgen)
|
gencls.pyx_generate(pyxgen)
|
||||||
|
|
||||||
f_base = os.path.splitext(py_path)[0]
|
#f_base = os.path.splitext(py_path)[0]
|
||||||
pxi_path = os.path.join(args.output, cls.name.lower() + ".pxi")
|
|
||||||
|
path = [args.output]
|
||||||
|
namespaces = []
|
||||||
|
for ns in cls.namespaces:
|
||||||
|
namespaces.append(ns.lower())
|
||||||
|
filename = cls.name.lower() + ".pxi"
|
||||||
|
namespace = ".".join(namespaces)
|
||||||
|
filename = ".".join((namespace, filename))
|
||||||
|
path.append(filename)
|
||||||
|
pxi_path = os.path.join(*path)
|
||||||
|
|
||||||
o = pyxgen.printout()
|
o = pyxgen.printout()
|
||||||
if o:
|
if o:
|
||||||
with open(pxi_path, "w") as f:
|
with open(pxi_path, "w") as f:
|
||||||
|
|
Loading…
Reference in New Issue