From 81d00a496a1592ab94dd069ee21117f19134cb4c Mon Sep 17 00:00:00 2001 From: Kai Huuhko Date: Mon, 22 Sep 2014 17:00:11 +0300 Subject: [PATCH] Eolian: WIP --- scripts/converters.py | 65 ++++++++++++++++++++++++++------------ scripts/eolian_generate.py | 31 ++++++++++-------- 2 files changed, 63 insertions(+), 33 deletions(-) diff --git a/scripts/converters.py b/scripts/converters.py index 66e2957..5c44c02 100644 --- a/scripts/converters.py +++ b/scripts/converters.py @@ -3,6 +3,8 @@ log = logging.getLogger("efl.eolian.conv") import re +from efl import eolian + docstring_replacements = ( ("@brief ", ""), (re.compile(r"@ingroup .+", re.S), r""), @@ -42,7 +44,7 @@ conversions_in = { mapping_out = { # c_type: pyx_type - "Eina_Bool": "bint", + "bool": "bint", "char *": "unicode", "Elm_Object_Item *": "_ObjectItem", "Evas_Object *": "_Eo_Base", @@ -51,11 +53,11 @@ mapping_out = { conversions_out = { # c_type: conversion - "Eina_Bool": "{0}", + "bool": "bool({0})", "char *": '{0}.decode("utf-8")', "Elm_Object_Item *": 'object_item_to_python({0})', "Evas_Object *": 'object_from_instance({0})', - "Eo *": 'object_from_instance({0})', + "Eo": 'object_from_instance({0})', } @@ -73,33 +75,56 @@ def remove_type_prefixes(ctype): return ctype -def convert_in_param(c_type, name): - c_type = conversions_in.get(c_type, c_type) - return c_type, name +def convert_in_param(tp, name, is_nonull=None): + if tp.type == eolian.TypeType.POINTER: + c_type = tp.c_type + tp = tp.base_type + else: + c_type = tp.c_type + + key = tp.name if tp.name else c_type + conv_expr = conversions_in.get(key) + + c_type = conversions_in.get(key, c_type) + + if tp.type == eolian.TypeType.CLASS: + key = "{0}.obj".format(key) + + if not is_nonull: + key = "<{0}>if {1} is not None else NULL".format(c_type, name) + + return conv_expr, c_type, key -def convert_out_param(c_type, name): - conv = conversions_out.get(c_type) +def convert_out_param(tp, name): + if tp.type == eolian.TypeType.POINTER: + tp = tp.base_type + + key = tp.name if tp.name else tp.c_type + conv = conversions_out.get(key) + if not conv: - return c_type, name + return tp.c_type, name + name = conv.format(name) - return c_type, name + return tp.c_type, name def conv_type_ret(tp): - tp = tp.return_type.c_type if not tp: - log.error("ret type empty") return - if tp in return_type_mapping: - c_t = remove_type_prefixes(tp) - py_t = return_type_mapping[c_t][0] - if py_t is not None: - py_ret_type = py_t - else: - log.warn("Unknown ret type") + c_type = tp.c_type + key = tp.name if tp.name else c_type - c_ret_type = remove_type_prefixes(tp) + #c_t = remove_type_prefixes(tp) + py_t = mapping_out.get(key) + if py_t is None: + log.warn("Unknown ret type: %s", key) + return c_type, c_type + + py_ret_type = py_t[0] + + c_ret_type = remove_type_prefixes(c_type) return py_ret_type, c_ret_type diff --git a/scripts/eolian_generate.py b/scripts/eolian_generate.py index 4cbb084..1a4c284 100755 --- a/scripts/eolian_generate.py +++ b/scripts/eolian_generate.py @@ -212,18 +212,21 @@ class Function(object): di = p.direction c_type = p.type.c_type - name = p.name if di == eolian.ParameterDir.IN: - #c_type, name = convert_in_param(c_type, name) - header_params.append((c_type, name)) + conv_expr, c_type, name = convert_in_param(p.type, p.name, p.is_nonull) + header_params.append((c_type, p.name)) c_call_params.append(name) elif di == eolian.ParameterDir.OUT: out_cdefs.append((c_type, "&"+name)) - c_type, name = convert_out_param(c_type, name) - return_params.append((c_type, name)) + c_type, name = convert_out_param(p.type, name) + return_params.append((p.type, name)) elif di == eolian.ParameterDir.INOUT: - log.error("TODO: INOUT params") + conv_expr, c_type, name = convert_in_param(p.type, p.name, p.is_nonull) + header_params.append((c_type, p.name)) + c_call_params.append(name) + c_type, name = convert_out_param(p.type, p.name) + return_params.append((p.type, p.name)) ret_type = func.return_type_get(eolian.FunctionType.METHOD) @@ -238,9 +241,7 @@ class Function(object): #assert p.direction == eolian.ParameterDir.IN, "prop %s setter has param other than IN" % (c_name) - c_type = p.type.c_type - name = p.name - #c_type, name = convert_in_param(c_type, name) + conv_expr, c_type, name = convert_in_param(p.type, p.name, p.is_nonull) conv_params.append(name) c_call_params.append(name) @@ -265,8 +266,8 @@ class Function(object): out_cdefs.append((c_type, name)) c_call_params.append("&%s" % (name)) - c_type, name = convert_out_param(c_type, name) - return_params.append((c_type, name)) + c_type, name = convert_out_param(p.type, name) + return_params.append((p.type, name)) ret_type = func.return_type_get(eolian.FunctionType.PROP_GET) @@ -290,10 +291,14 @@ class Function(object): gen.c_call_write(c_name, c_call_params, ret_type2, return_params) if return_params: - ret = return_params[:] - gen.write("return %s" % (", ".join([r[1] for r in ret]))) + rparams = [] + for t, n in return_params: + py_ret_type, c_ret_type = conv_type_ret(t) + rparams.append((c_ret_type, n)) + gen.write("return %s" % (", ".join([r[1] for r in rparams]))) elif ret_type.type != eolian.TypeType.UNKNOWN: ret = self.RET_PARAM + ret_type = convert_out_param(ret_type, ret) gen.write("return %s" % (ret)) gen.dedent()