eolian: new type API

This new API supports function pointer types, multiple type subtypes, const attribute without parsing
the name string, own attribute for any partial type and more. This commit also updates the C and C++
generators so that they compile and generate correct code.

@feature
This commit is contained in:
Daniel Kolesa 2014-06-27 14:47:40 +01:00
parent ba362d350f
commit 7b54a0101c
11 changed files with 557 additions and 197 deletions

View File

@ -89,23 +89,24 @@ eo_fundef_generate(const Eolian_Class class, Eolian_Function func, Eolian_Functi
char descname[0xFF];
char *tmpstr = malloc(0x1FF);
Eina_Bool var_as_ret = EINA_FALSE;
Eolian_Type rettypet = NULL;
const char *rettype = NULL;
Eina_Bool ret_const = EINA_FALSE;
Eolian_Function_Scope scope = eolian_function_scope_get(func);
_class_func_env_create(class, eolian_function_name_get(func), ftype, &func_env);
char *fsuffix = "";
rettype = eolian_function_return_type_get(func, ftype);
rettypet = eolian_function_return_type_get(func, ftype);
if (ftype == EOLIAN_PROP_GET)
{
fsuffix = "_get";
if (!rettype)
if (!rettypet)
{
l = eolian_parameters_list_get(func);
if (eina_list_count(l) == 1)
{
data = eina_list_data_get(l);
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettype, NULL, NULL);
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettypet, NULL, NULL);
var_as_ret = EINA_TRUE;
ret_const = eolian_parameter_const_attribute_get(data, EINA_TRUE);
}
@ -151,27 +152,35 @@ eo_fundef_generate(const Eolian_Class class, Eolian_Function func, Eolian_Functi
EINA_LIST_FOREACH(eolian_property_keys_list_get(func), l, data)
{
Eolian_Type ptypet;
const char *pname;
const char *ptype;
const char *pdesc = NULL;
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptype, &pname, &pdesc);
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptypet, &pname, &pdesc);
ptype = eolian_type_c_type_get(ptypet);
eina_strbuf_append_printf(str_pardesc, tmpl_eo_pardesc, "in", pname, pdesc?pdesc:"No description supplied.");
if (eina_strbuf_length_get(str_par)) eina_strbuf_append(str_par, ", ");
eina_strbuf_append_printf(str_par, "%s %s", ptype, pname);
eina_stringshare_del(ptype);
}
if (!var_as_ret)
{
EINA_LIST_FOREACH(eolian_parameters_list_get(func), l, data)
{
Eolian_Type ptypet;
const char *pname;
const char *ptype;
const char *pdesc;
Eina_Bool add_star = EINA_FALSE;
Eolian_Parameter_Dir pdir;
eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptype, &pname, &pdesc);
eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptypet, &pname, &pdesc);
ptype = eolian_type_c_type_get(ptypet);
Eina_Bool is_const = eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET);
if (ftype == EOLIAN_PROP_GET) {
add_star = EINA_TRUE;
@ -190,9 +199,12 @@ eo_fundef_generate(const Eolian_Class class, Eolian_Function func, Eolian_Functi
is_const?"const ":"",
ptype, had_star?"":" ", add_star?"*":"", pname);
eina_stringshare_del(ptype);
}
}
if (rettypet) rettype = eolian_type_c_type_get(rettypet);
tmpstr[0] = '\0';
sprintf(tmpstr, "%s%s%s",
ret_const ? "const " : "",
@ -207,6 +219,8 @@ eo_fundef_generate(const Eolian_Class class, Eolian_Function func, Eolian_Functi
eina_strbuf_replace_all(str_func, "@#ret_desc", eina_strbuf_string_get(str_retdesc));
eina_strbuf_replace_all(str_func, "@#list_typecheck", eina_strbuf_string_get(str_typecheck));
if (rettype) eina_stringshare_del(rettype);
free(tmpstr);
eina_strbuf_free(str_par);
eina_strbuf_free(str_retdesc);
@ -317,6 +331,7 @@ eo_bind_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_F
_eolian_class_func_vars func_env;
const char *suffix = "";
Eina_Bool var_as_ret = EINA_FALSE;
Eolian_Type rettypet = NULL;
const char *rettype = NULL;
const char *retname = NULL;
Eina_Bool ret_const = EINA_FALSE;
@ -330,19 +345,19 @@ eo_bind_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_F
Eina_Strbuf *params = eina_strbuf_new(); /* only variables names */
Eina_Strbuf *full_params = eina_strbuf_new(); /* variables types + names */
rettype = eolian_function_return_type_get(funcid, ftype);
rettypet = eolian_function_return_type_get(funcid, ftype);
retname = "ret";
if (ftype == EOLIAN_PROP_GET)
{
suffix = "_get";
add_star = EINA_TRUE;
if (!rettype)
if (!rettypet)
{
const Eina_List *l = eolian_parameters_list_get(funcid);
if (eina_list_count(l) == 1)
{
void* data = eina_list_data_get(l);
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettype, &retname, NULL);
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettypet, &retname, NULL);
var_as_ret = EINA_TRUE;
ret_const = eolian_parameter_const_attribute_get(data, EINA_TRUE);
}
@ -358,24 +373,33 @@ eo_bind_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_F
EINA_LIST_FOREACH(eolian_property_keys_list_get(funcid), l, data)
{
Eolian_Type ptypet;
const char *pname;
const char *ptype;
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptype, &pname, NULL);
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptypet, &pname, NULL);
ptype = eolian_type_c_type_get(ptypet);
Eina_Bool is_const = eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET);
if (eina_strbuf_length_get(params)) eina_strbuf_append(params, ", ");
eina_strbuf_append_printf(params, "%s", pname);
eina_strbuf_append_printf(full_params, ", %s%s %s",
is_const?"const ":"",
ptype, pname);
eina_stringshare_del(ptype);
}
if (!var_as_ret)
{
EINA_LIST_FOREACH(eolian_parameters_list_get(funcid), l, data)
{
Eolian_Type ptypet;
const char *pname;
const char *ptype;
Eolian_Parameter_Dir pdir;
eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptype, &pname, NULL);
eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptypet, &pname, NULL);
ptype = eolian_type_c_type_get(ptypet);
Eina_Bool is_const = eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET);
Eina_Bool had_star = !!strchr(ptype, '*');
if (ftype == EOLIAN_UNRESOLVED || ftype == EOLIAN_METHOD) add_star = (pdir == EOLIAN_OUT_PARAM);
@ -384,9 +408,12 @@ eo_bind_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_F
eina_strbuf_append_printf(full_params, ", %s%s%s%s%s",
is_const?"const ":"",
ptype, had_star?"":" ", add_star?"*":"", pname);
eina_stringshare_del(ptype);
}
}
if (rettypet) rettype = eolian_type_c_type_get(rettypet);
if (need_implementation)
{
Eina_Strbuf *ret_param = eina_strbuf_new();
@ -451,6 +478,8 @@ eo_bind_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_F
}
eina_strbuf_append(buf, eina_strbuf_string_get(fbody));
if (rettype) eina_stringshare_del(rettype);
eina_strbuf_free(va_args);
eina_strbuf_free(full_params);
eina_strbuf_free(params);

View File

@ -16,9 +16,11 @@ _params_generate(Eolian_Function foo, Eolian_Function_Type ftype, Eina_Bool var_
eina_strbuf_reset(short_params);
EINA_LIST_FOREACH(eolian_property_keys_list_get(foo), itr, param)
{
Eolian_Type ptypet;
const char *pname;
const char *ptype;
eolian_parameter_information_get(param, NULL, &ptype, &pname, NULL);
eolian_parameter_information_get(param, NULL, &ptypet, &pname, NULL);
ptype = eolian_type_c_type_get(ptypet);
Eina_Bool had_star = !!strchr(ptype, '*');
Eina_Bool is_const = eolian_parameter_const_attribute_get(param, ftype == EOLIAN_PROP_GET);
if (eina_strbuf_length_get(params))
@ -31,16 +33,19 @@ _params_generate(Eolian_Function foo, Eolian_Function_Type ftype, Eina_Bool var_
had_star?"":" ",
pname);
eina_strbuf_append_printf(short_params, "%s", pname);
eina_stringshare_del(ptype);
}
if (!var_as_ret)
{
Eina_Bool add_star = (ftype == EOLIAN_PROP_GET);
EINA_LIST_FOREACH(eolian_parameters_list_get(foo), itr, param)
{
Eolian_Type ptypet;
const char *pname;
const char *ptype;
Eolian_Parameter_Dir pdir;
eolian_parameter_information_get(param, &pdir, &ptype, &pname, NULL);
eolian_parameter_information_get(param, &pdir, &ptypet, &pname, NULL);
ptype = eolian_type_c_type_get(ptypet);
Eina_Bool is_const = eolian_parameter_const_attribute_get(param, ftype == EOLIAN_PROP_GET);
Eina_Bool had_star = !!strchr(ptype, '*');
if (ftype == EOLIAN_UNRESOLVED || ftype == EOLIAN_METHOD) add_star = (pdir == EOLIAN_OUT_PARAM);
@ -53,6 +58,7 @@ _params_generate(Eolian_Function foo, Eolian_Function_Type ftype, Eina_Bool var_
is_const?"const ":"",
ptype, had_star?"":" ", add_star?"*":"", pname);
eina_strbuf_append_printf(short_params, "%s", pname);
eina_stringshare_del(ptype);
}
}
return EINA_TRUE;
@ -136,14 +142,14 @@ _prototype_generate(Eolian_Function foo, Eolian_Function_Type ftype, Eina_Strbuf
if (_function_exists(func_name, buffer)) goto end;
printf("Generation of function %s\n", func_name);
const char *rettype = eolian_function_return_type_get(foo, ftype);
if (ftype == EOLIAN_PROP_GET && !rettype)
Eolian_Type rettypet = eolian_function_return_type_get(foo, ftype);
if (ftype == EOLIAN_PROP_GET && !rettypet)
{
const Eina_List *l = eolian_parameters_list_get(foo);
if (eina_list_count(l) == 1)
{
Eolian_Function_Parameter param = eina_list_data_get(l);
eolian_parameter_information_get(param, NULL, &rettype, NULL, NULL);
eolian_parameter_information_get(param, NULL, &rettypet, NULL, NULL);
var_as_ret = EINA_TRUE;
ret_const = eolian_parameter_const_attribute_get(param, EINA_TRUE);
}
@ -164,6 +170,9 @@ _prototype_generate(Eolian_Function foo, Eolian_Function_Type ftype, Eina_Strbuf
eina_strbuf_string_get(short_params));
}
const char *rettype = NULL;
if (rettypet) rettype = eolian_type_c_type_get(rettypet);
eina_strbuf_append_printf(buffer,
"EOLIAN static %s%s\n%s(%sEo *obj, %s *pd%s%s)\n{\n%s\n}\n\n",
ret_const?"const ":"", !rettype?"void":rettype,
@ -175,6 +184,8 @@ _prototype_generate(Eolian_Function foo, Eolian_Function_Type ftype, Eina_Strbuf
eina_strbuf_string_get(super_invok)
);
if (rettype) eina_stringshare_del(rettype);
end:
eina_strbuf_free(short_params);
eina_strbuf_free(params);

View File

@ -47,6 +47,7 @@ _eapi_decl_func_generate(Eolian_Class class, Eolian_Function funcid, Eolian_Func
_eolian_class_func_vars func_env;
const char *funcname = eolian_function_name_get(funcid);
const char *suffix = "";
Eolian_Type rettypet = NULL;
const char *rettype = NULL;
Eina_Bool var_as_ret = EINA_FALSE;
Eina_Bool add_star = EINA_FALSE;
@ -62,18 +63,18 @@ _eapi_decl_func_generate(Eolian_Class class, Eolian_Function funcid, Eolian_Func
Eina_Strbuf *descparam = eina_strbuf_new();
_class_func_env_create(class, funcname, ftype, &func_env);
rettype = eolian_function_return_type_get(funcid, ftype);
rettypet = eolian_function_return_type_get(funcid, ftype);
if (ftype == EOLIAN_PROP_GET)
{
suffix = "_get";
add_star = EINA_TRUE;
if (!rettype)
if (!rettypet)
{
l = eolian_parameters_list_get(funcid);
if (eina_list_count(l) == 1)
{
data = eina_list_data_get(l);
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettype, NULL, NULL);
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettypet, NULL, NULL);
var_as_ret = EINA_TRUE;
ret_const = eolian_parameter_const_attribute_get(data, EINA_TRUE);
}
@ -105,14 +106,17 @@ _eapi_decl_func_generate(Eolian_Class class, Eolian_Function funcid, Eolian_Func
EINA_LIST_FOREACH(eolian_property_keys_list_get(funcid), l, data)
{
Eolian_Type ptypet;
const char *pname;
const char *pdesc;
const char *ptype;
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptype, &pname, &pdesc);
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptypet, &pname, &pdesc);
ptype = eolian_type_c_type_get(ptypet);
leg_param_idx++;
eina_strbuf_append_printf(fparam, ", %s%s %s",
eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET)?"const":"",
ptype, pname);
eina_stringshare_del(ptype);
eina_strbuf_append_printf(descparam, " * @param[in] %s %s\n", pname, pdesc?pdesc:"No description supplied.");
if (eolian_parameter_is_nonull((Eolian_Function_Parameter)data))
{
@ -129,12 +133,14 @@ _eapi_decl_func_generate(Eolian_Class class, Eolian_Function funcid, Eolian_Func
{
EINA_LIST_FOREACH(eolian_parameters_list_get(funcid), l, data)
{
Eolian_Type ptypet;
const char *pname;
const char *pdesc;
const char *ptype;
Eolian_Parameter_Dir pdir;
const char *str_dir[] = {"in", "out", "inout"};
eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptype, &pname, &pdesc);
eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptypet, &pname, &pdesc);
ptype = eolian_type_c_type_get(ptypet);
Eina_Bool had_star = !!strchr(ptype, '*');
if (ftype == EOLIAN_UNRESOLVED || ftype == EOLIAN_METHOD) add_star = (pdir == EOLIAN_OUT_PARAM);
if (ftype == EOLIAN_PROP_GET) pdir = EOLIAN_OUT_PARAM;
@ -143,6 +149,7 @@ _eapi_decl_func_generate(Eolian_Class class, Eolian_Function funcid, Eolian_Func
eina_strbuf_append_printf(fparam, ", %s%s%s%s%s",
eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET)?"const ":"",
ptype, had_star?"":" ", add_star?"*":"", pname);
eina_stringshare_del(ptype);
const char *dir_str = str_dir[(int)pdir];
eina_strbuf_append_printf(descparam, " * @param[%s] %s %s\n", dir_str, pname, pdesc?pdesc:"No description supplied.");
if (eolian_parameter_is_nonull((Eolian_Function_Parameter)data))
@ -159,6 +166,8 @@ _eapi_decl_func_generate(Eolian_Class class, Eolian_Function funcid, Eolian_Func
}
if (flags) eina_strbuf_append_printf(flags, ")");
if (rettypet) rettype = eolian_type_c_type_get(rettypet);
eina_strbuf_replace_all(fbody, "@#params", eina_strbuf_string_get(fparam));
eina_strbuf_replace_all(fbody, "@#list_desc_param", eina_strbuf_string_get(descparam));
eina_strbuf_reset(fparam);
@ -179,6 +188,8 @@ _eapi_decl_func_generate(Eolian_Class class, Eolian_Function funcid, Eolian_Func
eina_strbuf_replace_all(fbody, "@#flags", (eolian_function_return_is_warn_unused(funcid, ftype)) ? " EINA_WARN_UNUSED_RESULT" : "");
eina_strbuf_append(buf, eina_strbuf_string_get(fbody));
if (rettype) eina_stringshare_del(rettype);
end:
eina_strbuf_free(flags);
eina_strbuf_free(fbody);
@ -192,6 +203,7 @@ _eapi_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_Fun
_eolian_class_func_vars func_env;
char tmpstr[0xFF];
Eina_Bool var_as_ret = EINA_FALSE;
Eolian_Type rettypet = NULL;
const char *rettype = NULL;
const char *retname = NULL;
Eina_Bool ret_const = EINA_FALSE;
@ -203,19 +215,20 @@ _eapi_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_Fun
Eina_Strbuf *eoparam = eina_strbuf_new();
_class_func_env_create(class, eolian_function_name_get(funcid), ftype, &func_env);
rettype = eolian_function_return_type_get(funcid, ftype);
rettypet = eolian_function_return_type_get(funcid, ftype);
if (rettypet) rettype = eolian_type_c_type_get(rettypet);
if (rettype && !strcmp(rettype, "void")) ret_is_void = EINA_TRUE;
retname = "ret";
if (ftype == EOLIAN_PROP_GET)
{
add_star = EINA_TRUE;
if (!rettype)
if (!rettypet)
{
const Eina_List *l = eolian_parameters_list_get(funcid);
if (eina_list_count(l) == 1)
{
void* data = eina_list_data_get(l);
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettype, &retname, NULL);
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &rettypet, &retname, NULL);
var_as_ret = EINA_TRUE;
ret_const = eolian_parameter_const_attribute_get(data, EINA_TRUE);
}
@ -224,6 +237,8 @@ _eapi_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_Fun
if (func_env.legacy_func[0] == '\0') goto end;
if (!rettype && rettypet) rettype = eolian_type_c_type_get(rettypet);
if (rettype && (!ret_is_void))
eina_strbuf_append(fbody, tmpl_eapi_body);
else
@ -239,12 +254,15 @@ _eapi_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_Fun
EINA_LIST_FOREACH(eolian_property_keys_list_get(funcid), l, data)
{
Eolian_Type ptypet;
const char *pname;
const char *ptype;
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptype, &pname, NULL);
eolian_parameter_information_get((Eolian_Function_Parameter)data, NULL, &ptypet, &pname, NULL);
ptype = eolian_type_c_type_get(ptypet);
eina_strbuf_append_printf(fparam, ", %s%s %s",
eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET)?"const ":"",
ptype, pname);
eina_stringshare_del(ptype);
if (eina_strbuf_length_get(eoparam)) eina_strbuf_append(eoparam, ", ");
eina_strbuf_append_printf(eoparam, "%s", pname);
}
@ -252,15 +270,18 @@ _eapi_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_Fun
{
EINA_LIST_FOREACH(eolian_parameters_list_get(funcid), l, data)
{
Eolian_Type ptypet;
const char *pname;
const char *ptype;
Eolian_Parameter_Dir pdir;
eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptype, &pname, NULL);
eolian_parameter_information_get((Eolian_Function_Parameter)data, &pdir, &ptypet, &pname, NULL);
ptype = eolian_type_c_type_get(ptypet);
Eina_Bool had_star = !!strchr(ptype, '*');
if (ftype == EOLIAN_UNRESOLVED || ftype == EOLIAN_METHOD) add_star = (pdir == EOLIAN_OUT_PARAM);
eina_strbuf_append_printf(fparam, ", %s%s%s%s%s",
eolian_parameter_const_attribute_get(data, ftype == EOLIAN_PROP_GET)?"const ":"",
ptype, had_star?"":" ", add_star?"*":"", pname);
eina_stringshare_del(ptype);
if (eina_strbuf_length_get(eoparam)) eina_strbuf_append(eoparam, ", ");
eina_strbuf_append_printf(eoparam, "%s", pname);
}
@ -292,6 +313,8 @@ _eapi_func_generate(const Eolian_Class class, Eolian_Function funcid, Eolian_Fun
eina_strbuf_append(buf, eina_strbuf_string_get(fbody));
if (rettype) eina_stringshare_del(rettype);
end:
eina_strbuf_free(fbody);
eina_strbuf_free(fparam);

View File

@ -60,8 +60,12 @@ static std::string
_comment_return(Eolian_Function function,
Eolian_Function_Type rettype)
{
Eolian_Type rettypet = eolian_function_return_type_get(function, rettype);
const char *rettypes = NULL;
if (rettypet) rettypes = eolian_type_c_type_get(rettypet);
std::string doc = "";
std::string ret = safe_str(eolian_function_return_type_get(function, rettype));
std::string ret = safe_str(rettypes);
if (rettypes) eina_stringshare_del(rettypes);
std::string comment = safe_str(eolian_function_return_comment_get(function, rettype));
if (ret != "void" && ret != "" && comment != "")
{

View File

@ -27,13 +27,16 @@ static std::string
_resolve_param_type(Eolian_Function_Parameter id, bool is_get)
{
Eolian_Parameter_Dir dir;
const char *type;
Eolian_Type typet;
const char *type = NULL;
bool is_const;
std::string res;
eolian_parameter_information_get(id, &dir, &type, NULL, NULL);
eolian_parameter_information_get(id, &dir, &typet, NULL, NULL);
if (typet) type = eolian_type_c_type_get(typet);
is_const = eolian_parameter_const_attribute_get(id, is_get);
res = safe_str(type);
eina_stringshare_del(type);
assert(res != "");
if (is_const) res = std::string("const ") + res;
if (dir == EOLIAN_OUT_PARAM || dir == EOLIAN_INOUT_PARAM) res += "*";
@ -91,8 +94,11 @@ _get_properties(const Eolian_Class klass)
getter.type = efl::eolian::eo_function::regular_;
getter.name = name + "_get";
getter.impl = _dedup_func_name(property, (prefix != "" ? prefix : cxx_classname)) + "_get";
std::string ret = safe_str
(eolian_function_return_type_get(property, EOLIAN_PROP_GET));
Eolian_Type tp = eolian_function_return_type_get(property, EOLIAN_PROP_GET);
const char *tps = NULL;
if (tp) tps = eolian_type_c_type_get(tp);
std::string ret = safe_str(tps);
if (tps) eina_stringshare_del(tps);
if (ret == "") ret = "void";
// if the getter has a single parameter and void return
@ -137,8 +143,11 @@ _get_properties(const Eolian_Class klass)
setter.name = name + "_set";
setter.impl = _dedup_func_name(property, (prefix != "" ? prefix : cxx_classname)) + "_set";
setter.params = params;
setter.ret = safe_str(eolian_function_return_type_get
(property, EOLIAN_PROP_SET));
Eolian_Type tp = eolian_function_return_type_get(property, EOLIAN_PROP_SET);
const char *tps = NULL;
if (tp) tps = eolian_type_c_type_get(tp);
setter.ret = safe_str(tps);
if (tps) eina_stringshare_del(tps);
if (setter.ret == "") setter.ret = "void";
setter.comment = detail::eolian_property_setter_comment(property);
container.push_back(setter);
@ -250,8 +259,11 @@ convert_eolian_functions(efl::eolian::eo_class& cls, const Eolian_Class klass)
function.type = efl::eolian::eo_function::regular_;
function.name = safe_str(eolian_function_name_get(eolian_function));
function.impl = _dedup_func_name(eolian_function, (prefix != "" ? prefix : cls.name));
function.ret = safe_str(eolian_function_return_type_get
(eolian_function, EOLIAN_METHOD));
Eolian_Type tp = eolian_function_return_type_get(eolian_function, EOLIAN_METHOD);
const char *tps = NULL;
if (tp) tps = eolian_type_c_type_get(tp);
function.ret = safe_str(tps);
if (tps) eina_stringshare_del(tps);
if(function.ret == "") function.ret = "void";
function.params = _get_params(eolian_parameters_list_get(eolian_function));
function.comment = detail::eolian_function_comment(eolian_function);

View File

@ -498,7 +498,7 @@ EAPI const Eina_List *eolian_parameters_list_get(Eolian_Function function_id);
*
* @ingroup Eolian
*/
EAPI void eolian_parameter_information_get(const Eolian_Function_Parameter param_desc, Eolian_Parameter_Dir *param_dir, const char **type, const char **name, const char **description);
EAPI void eolian_parameter_information_get(const Eolian_Function_Parameter param_desc, Eolian_Parameter_Dir *param_dir, Eolian_Type *type, const char **name, const char **description);
/*
* @brief Get type of a parameter
@ -508,17 +508,7 @@ EAPI void eolian_parameter_information_get(const Eolian_Function_Parameter param
*
* @ingroup Eolian
*/
EAPI Eina_Stringshare *eolian_parameter_type_get(const Eolian_Function_Parameter param);
/*
* @brief Get a list of all the types of a parameter
*
* @param[in] param_desc parameter handle
* @return the types of the parameter
*
* @ingroup Eolian
*/
EAPI Eolian_Type eolian_parameter_types_list_get(const Eolian_Function_Parameter param);
EAPI Eolian_Type eolian_parameter_type_get(const Eolian_Function_Parameter param);
/*
* @brief Get name of a parameter
@ -566,19 +556,7 @@ EAPI Eina_Bool eolian_parameter_is_nonull(Eolian_Function_Parameter param_desc);
*
* @ingroup Eolian
*/
EAPI const char *eolian_function_return_type_get(Eolian_Function function_id, Eolian_Function_Type ftype);
/*
* @brief Get a list of all the types of a function return
*
* @param[in] foo_id Function Id
* @param[in] ftype Function Type
* @return the types of the function return
*
* @ingroup Eolian
*/
EAPI Eolian_Type
eolian_function_return_types_list_get(Eolian_Function foo_id, Eolian_Function_Type ftype);
EAPI Eolian_Type eolian_function_return_type_get(Eolian_Function function_id, Eolian_Function_Type ftype);
/*
* @brief Get the return default value of a function.
@ -721,8 +699,129 @@ EAPI Eina_Bool eolian_class_dtor_enable_get(const Eolian_Class klass);
*
* @ingroup Eolian
*/
EAPI Eolian_Type
eolian_type_find_by_alias(const char *alias);
EAPI Eolian_Type eolian_type_find_by_alias(const char *alias);
/*
* @brief Get the type of a type (regular, function, pointer)
*
* @param[in] tp the type.
* @return EOLIAN_TYPE_UNKNOWN_TYPE when @c tp is NULL, otherwise
* EOLIAN_TYPE_REGULAR, EOLIAN_TYPE_POINTER or EOLIAN_TYPE_FUNCTION.
*
* @ingroup Eolian
*/
EAPI Eolian_Type_Type eolian_type_type_get(Eolian_Type tp);
/*
* @brief Get an iterator to all arguments of a function type.
*
* @param[in] tp the type.
* @return the iterator when @c tp is an EOLIAN_TYPE_FUNCTION, NULL otherwise.
*
* @ingroup Eolian
*/
EAPI Eina_Iterator *eolian_type_arguments_list_get(Eolian_Type tp);
/*
* @brief Get an iterator to all subtypes of a type.
*
* @param[in] tp the type.
* @return the iterator when @c tp is an EOLIAN_TYPE_REGULAR or
* EOLIAN_TYPE_POINTER and has subtypes, NULL otherwise.
*
* @ingroup Eolian
*/
EAPI Eina_Iterator *eolian_type_subtypes_list_get(Eolian_Type tp);
/*
* @brief Get the return type of a function type.
*
* @param[in] tp the type.
* @return the return type when @c tp is an EOLIAN_TYPE_FUNCTION, NULL otherwise.
*
* @ingroup Eolian
*/
EAPI Eolian_Type eolian_type_return_type_get(Eolian_Type tp);
/*
* @brief Get the base type of a function type.
*
* @param[in] tp the type.
* @return the base type when @c tp is an EOLIAN_TYPE_POINTER, NULL otherwise.
*
* @ingroup Eolian
*/
EAPI Eolian_Type eolian_type_base_type_get(Eolian_Type tp);
/*
* @brief Get whether the given type is @own.
*
* @param[in] tp the type.
* @return EINA_TRUE when @c tp is a non-function type and not NULL,
* EINA_FALSE otherwise.
*
* @ingroup Eolian
*/
EAPI Eina_Bool eolian_type_is_own(Eolian_Type tp);
/*
* @brief Get whether the given type is const.
*
* @param[in] tp the type.
* @return EINA_TRUE when @c tp is a non-function type and not NULL,
* EINA_FALSE otherwise.
*
* @ingroup Eolian
*/
EAPI Eina_Bool eolian_type_is_const(Eolian_Type tp);
/*
* @brief Get the full C type name of the given type with a name.
*
* @param[in] tp the type.
* @param[in] name the name.
* @return The C type name assuming @c tp is not NULL.
*
* Providing the name is useful for function types, as in C a function
* pointer type alone is not valid syntax. For non-function types, the
* name is simply appended to the type (with a space). C type names do
* not include subtypes as C doesn't support them.
*
* Keep in mind that if @c name is NULL, the name won't be included.
*
* @see eolian_type_c_type_get
*
* @ingroup Eolian
*/
EAPI Eina_Stringshare *eolian_type_c_type_named_get(Eolian_Type tp, const char *name);
/*
* @brief Get the full C type name of the given type without a name.
*
* @param[in] tp the type.
* @return The C type name assuming @c tp is not NULL.
*
* This behaves exactly like eolian_type_c_type_named_get when name is NULL.
* Keep in mind that this is not useful for function types as a function
* pointer type in C cannot be used without a name.
*
* @see eolian_type_c_type_named_get
*
* @ingroup Eolian
*/
EAPI Eina_Stringshare *eolian_type_c_type_get(Eolian_Type tp);
/*
* @brief Get the type name of the given type. You have to manually delete
* the stringshare.
*
* @param[in] tp the type.
* @return the name assuming @c tp is an EOLIAN_TYPE_REGULAR, NULL otherwise.
* The name may include a "struct" keyword.
*
* @ingroup Eolian
*/
EAPI Eina_Stringshare *eolian_type_name_get(Eolian_Type tp);
#endif

View File

@ -2,12 +2,25 @@
#include <stdlib.h>
#include "eo_definitions.h"
#include "eolian_database.h"
static void
eo_definitions_type_free(Eo_Type_Def *tp)
{
Eo_Type_Def *stp;
if (tp->name) eina_stringshare_del(tp->name);
/* for function types, this will map to arguments and ret_type */
if (tp->subtypes)
EINA_LIST_FREE(tp->subtypes, stp)
eo_definitions_type_free(stp);
if (tp->base_type)
eo_definitions_type_free(tp->base_type);
free(tp);
}
static void
eo_definitions_ret_free(Eo_Ret_Def *ret)
{
if (ret->type) database_type_del(ret->type);
if (ret->type) eo_definitions_type_free(ret->type);
if (ret->comment) eina_stringshare_del(ret->comment);
if (ret->dflt_ret_val) eina_stringshare_del(ret->dflt_ret_val);
free(ret);
@ -16,7 +29,7 @@ eo_definitions_ret_free(Eo_Ret_Def *ret)
static void
eo_definitions_param_free(Eo_Param_Def *param)
{
if (param->type) database_type_del(param->type);
if (param->type) eo_definitions_type_free(param->type);
if (param->name) eina_stringshare_del(param->name);
if (param->comment) eina_stringshare_del(param->comment);
free(param);
@ -120,7 +133,7 @@ eo_definitions_typedef_def_free(Eo_Typedef_Def *type)
eina_stringshare_del(type->alias);
if (type->type)
database_type_del(type->type);
eo_definitions_type_free(type->type);
free(type);
}
@ -191,6 +204,9 @@ eo_definitions_temps_free(Eo_Lexer_Temps *tmp)
if (tmp->typedef_def)
eo_definitions_typedef_def_free(tmp->typedef_def);
if (tmp->type_def)
eo_definitions_type_free(tmp->type_def);
if (tmp->prop)
eo_definitions_property_def_free(tmp->prop);
@ -214,7 +230,4 @@ eo_definitions_temps_free(Eo_Lexer_Temps *tmp)
if (tmp->impl)
eo_definitions_impl_def_free(tmp->impl);
if (tmp->type)
database_type_del(tmp->type);
}

View File

@ -9,8 +9,8 @@
typedef struct _eo_type_def Eo_Type_Def;
struct _eo_type_def
{
const char *name;
int type;
const char *name;
Eolian_Type_Type type;
union {
struct {
Eina_List *subtypes;
@ -21,13 +21,14 @@ struct _eo_type_def
Eo_Type_Def *ret_type;
};
};
Eina_Bool is_const :1;
Eina_Bool is_own :1;
Eina_Bool is_const :1;
Eina_Bool is_own :1;
Eina_Bool is_struct :1;
};
typedef struct _eo_ret_def
{
Eolian_Type type;
Eo_Type_Def *type;
const char *comment;
const char *dflt_ret_val;
Eina_Bool warn_unused:1;
@ -46,7 +47,7 @@ typedef enum _param_way
typedef struct _eo_param_def
{
Param_Way way;
Eolian_Type type;
Eo_Type_Def *type;
const char *name;
const char *comment;
Eina_Bool nonull:1;
@ -146,7 +147,7 @@ typedef struct _eo_class_def
typedef struct _eo_typedef_def
{
const char *alias;
Eolian_Type type;
Eo_Type_Def *type;
} Eo_Typedef_Def;
/* TEMPS */
@ -159,6 +160,7 @@ typedef struct _Eo_Lexer_Temps
Eo_Class_Def *kls;
Eo_Ret_Def *ret_def;
Eo_Typedef_Def *typedef_def;
Eo_Type_Def *type_def;
Eo_Property_Def *prop;
Eo_Method_Def *meth;
Eo_Param_Def *param;
@ -167,7 +169,6 @@ typedef struct _Eo_Lexer_Temps
Eina_List *str_items;
Eo_Event_Def *event;
Eo_Implement_Def *impl;
Eolian_Type type;
} Eo_Lexer_Temps;
void eo_definitions_class_def_free(Eo_Class_Def *kls);

View File

@ -147,88 +147,72 @@ parse_name_list(Eo_Lexer *ls)
return ls->tmp.str_items;
}
static void
parse_type_sub(Eo_Lexer *ls, Eina_Strbuf *buf, Eina_Bool *has_ptr)
static Eo_Type_Def *
parse_type(Eo_Lexer *ls)
{
const char *ctype;
if (has_ptr) *has_ptr = EINA_FALSE;
Eina_Bool has_struct = EINA_FALSE;
Eo_Type_Def *def;
const char *ctype;
switch (ls->t.kw)
{
case KW_const:
{
int line;
size_t buflen;
Eina_Bool is_ptr;
eo_lexer_get(ls);
line = ls->line_number;
check_next(ls, '(');
buflen = eina_strbuf_length_get(buf);
parse_type_sub(ls, buf, &is_ptr);
def = parse_type(ls);
def->is_const = EINA_TRUE;
check_match(ls, ')', '(', line);
goto parse_ptr;
}
case KW_at_own:
{
int line;
eo_lexer_get(ls);
line = ls->line_number;
check_next(ls, '(');
def = parse_type(ls);
def->is_own = EINA_TRUE;
check_match(ls, ')', '(', line);
if (!is_ptr)
eina_strbuf_insert(buf, "const ", buflen);
else
eina_strbuf_append(buf, " const");
goto parse_ptr;
}
case KW_struct:
eo_lexer_get(ls);
eina_strbuf_append(buf, "struct ");
has_struct = EINA_TRUE;
break;
default:
break;
}
def = calloc(1, sizeof(Eo_Type_Def));
ls->tmp.type_def = def;
def->type = EOLIAN_TYPE_REGULAR;
def->is_struct = has_struct;
def->is_const = EINA_FALSE;
check(ls, TOK_VALUE);
ctype = eo_lexer_get_c_type(ls->t.kw);
eina_strbuf_append(buf, ctype ? ctype : ls->t.value);
def->name = eina_stringshare_add(ctype ? ctype : ls->t.value);
eo_lexer_get(ls);
parse_ptr:
if (ls->t.token != '*') return;
if (has_ptr) *has_ptr = EINA_TRUE;
eina_strbuf_append_char(buf, ' ');
while (ls->t.token == '*')
{
eina_strbuf_append_char(buf, '*');
Eo_Type_Def *pdef = calloc(1, sizeof(Eo_Type_Def));
ls->tmp.type_def = pdef;
pdef->base_type = def;
pdef->type = EOLIAN_TYPE_POINTER;
def = pdef;
eo_lexer_get(ls);
}
}
static Eolian_Type
parse_type(Eo_Lexer *ls, Eolian_Type type, Eina_Strbuf *sbuf)
{
Eina_Bool is_own = EINA_FALSE;
Eina_Strbuf *buf = sbuf ? sbuf : push_strbuf(ls);
if (ls->t.kw == KW_at_own)
{
if (sbuf) eina_strbuf_append(buf, "@own ");
is_own = EINA_TRUE;
eo_lexer_get(ls);
}
parse_type_sub(ls, buf, NULL);
if (!sbuf)
{
type = database_type_append(type, eina_strbuf_string_get(buf), is_own);
ls->tmp.type = type;
pop_strbuf(ls);
}
if (ls->t.token == '<')
{
int line = ls->line_number;
if (sbuf) eina_strbuf_append(buf, " <");
eo_lexer_get(ls);
parse_type(ls, type, sbuf);
def->subtypes = eina_list_append(def->subtypes, parse_type(ls));
while (test_next(ls, ','))
parse_type(ls, type, buf);
parse_type(ls, type, sbuf);
def->subtypes = eina_list_append(def->subtypes, parse_type(ls));
check_match(ls, '>', '<', line);
if (sbuf) eina_strbuf_append_char(buf, '>');
}
return type;
return def;
}
static void
@ -240,8 +224,8 @@ parse_typedef(Eo_Lexer *ls)
ls->tmp.typedef_def->alias = eina_stringshare_add(ls->t.value);
eo_lexer_get(ls);
test_next(ls, ':');
ls->tmp.typedef_def->type = parse_type(ls, NULL, NULL);
ls->tmp.type = NULL;
ls->tmp.typedef_def->type = parse_type(ls);
ls->tmp.type_def = NULL;
check_next(ls, ';');
}
@ -251,8 +235,8 @@ parse_return(Eo_Lexer *ls)
Eo_Ret_Def *ret = calloc(1, sizeof(Eo_Ret_Def));
ls->tmp.ret_def = ret;
eo_lexer_get(ls);
ret->type = parse_type(ls, NULL, NULL);
ls->tmp.type = NULL;
ret->type = parse_type(ls);
ls->tmp.type_def = NULL;
if (ls->t.token == '(')
{
int line = ls->line_number;
@ -299,8 +283,8 @@ parse_param(Eo_Lexer *ls, Eina_Bool allow_inout)
else
par->way = PARAM_IN;
}
par->type = parse_type(ls, NULL, NULL);
ls->tmp.type = NULL;
par->type = parse_type(ls);
ls->tmp.type_def = NULL;
check(ls, TOK_VALUE);
par->name = eina_stringshare_add(ls->t.value);
eo_lexer_get(ls);
@ -927,15 +911,45 @@ typedef struct
} _Parameter_Type;
static void
_print_type(FILE *f, Eolian_Type tp)
_print_type(FILE *f, Eo_Type_Def *tp)
{
Eina_List *l;
Eolian_Type stp;
_Parameter_Type *tpp = (_Parameter_Type*)tp;
fprintf(f, "%s%s<", tpp->name, tpp->is_own ? "@own " : "");
EINA_LIST_FOREACH(tpp->subtypes, l, stp)
_print_type(f, stp);
fputc('>', f);
Eo_Type_Def *stp;
if (tp->is_own)
fputs("@own(", f);
if (tp->is_const)
fputs("const(", f);
if (tp->is_struct)
fputs("struct ", f);
if (tp->type == EOLIAN_TYPE_REGULAR)
fputs(tp->name, f);
else if (tp->type == EOLIAN_TYPE_POINTER)
{
_print_type(f, tp->base_type);
fputc('*', f);
}
else if (tp->type == EOLIAN_TYPE_FUNCTION)
{
Eina_Bool first = EINA_TRUE;
fputs("fn", f);
if (tp->ret_type)
{
fputs(" -> ", f);
_print_type(f, tp->ret_type);
}
fputs(" (", f);
EINA_LIST_FOREACH(tp->arguments, l, stp)
{
if (!first) fputs(", ", f);
first = EINA_FALSE;
_print_type(f, stp);
}
fputc(')', f);
}
if (tp->is_own)
fputc(')', f);
if (tp->is_const)
fputc(')', f);
}
static void
@ -1110,7 +1124,7 @@ _db_fill_class(Eo_Class_Def *kls, const char *filename)
database_function_data_set(foo_id, EOLIAN_LEGACY, meth->legacy);
EINA_LIST_FOREACH(meth->params, m, param)
{
database_method_parameter_add(foo_id, (Eolian_Parameter_Dir)param->way, param->type, param->name, param->comment);
database_method_parameter_add(foo_id, (Eolian_Parameter_Dir)param->way, (Eolian_Type)param->type, param->name, param->comment);
param->type = NULL;
}
}
@ -1122,14 +1136,14 @@ _db_fill_class(Eo_Class_Def *kls, const char *filename)
EINA_LIST_FOREACH(prop->keys, m, param)
{
Eolian_Function_Parameter p = database_property_key_add(
foo_id, param->type, param->name, param->comment);
foo_id, (Eolian_Type)param->type, param->name, param->comment);
database_parameter_nonull_set(p, param->nonull);
param->type = NULL;
}
EINA_LIST_FOREACH(prop->values, m, param)
{
Eolian_Function_Parameter p = database_property_value_add(
foo_id, param->type, param->name, param->comment);
foo_id, (Eolian_Type)param->type, param->name, param->comment);
database_parameter_nonull_set(p, param->nonull);
param->type = NULL;
}
@ -1140,7 +1154,7 @@ _db_fill_class(Eo_Class_Def *kls, const char *filename)
accessor->type == SETTER?EOLIAN_PROP_SET:EOLIAN_PROP_GET;
if (accessor->ret && accessor->ret->type)
{
database_function_return_type_set(foo_id, ftype, accessor->ret->type);
database_function_return_type_set(foo_id, ftype, (Eolian_Type)accessor->ret->type);
database_function_return_comment_set(foo_id,
ftype, accessor->ret->comment);
database_function_return_flag_set_as_warn_unused(foo_id,
@ -1192,7 +1206,7 @@ _db_fill_class(Eo_Class_Def *kls, const char *filename)
database_class_function_add(class, foo_id);
if (meth->ret)
{
database_function_return_type_set(foo_id, EOLIAN_METHOD, meth->ret->type);
database_function_return_type_set(foo_id, EOLIAN_METHOD, (Eolian_Type)meth->ret->type);
database_function_return_comment_set(foo_id, EOLIAN_METHOD, meth->ret->comment);
database_function_return_flag_set_as_warn_unused(foo_id,
EOLIAN_METHOD, meth->ret->warn_unused);
@ -1206,7 +1220,7 @@ _db_fill_class(Eo_Class_Def *kls, const char *filename)
EINA_LIST_FOREACH(meth->params, m, param)
{
Eolian_Function_Parameter p = database_method_parameter_add(foo_id,
(Eolian_Parameter_Dir)param->way, param->type, param->name, param->comment);
(Eolian_Parameter_Dir)param->way, (Eolian_Type)param->type, param->name, param->comment);
database_parameter_nonull_set(p, param->nonull);
param->type = NULL;
}
@ -1269,7 +1283,7 @@ _db_fill_class(Eo_Class_Def *kls, const char *filename)
static Eina_Bool
_db_fill_type(Eo_Typedef_Def *type_def)
{
database_type_add(type_def->alias, type_def->type);
database_type_add(type_def->alias, (Eolian_Type)type_def->type);
type_def->type = NULL;
return EINA_TRUE;
}

View File

@ -75,11 +75,24 @@ typedef struct
Eina_Bool nonull :1; /* True if this argument cannot be NULL */
} _Parameter_Desc;
/* maps directly to Eo_Type_Def */
typedef struct
{
Eina_List *subtypes;
Eina_Stringshare *name;
Eina_Bool is_own :1; /* True if the ownership of this argument passes to the caller/callee */
const char *name;
Eolian_Type_Type type;
union {
struct {
Eina_List *subtypes;
Eolian_Type base_type;
};
struct {
Eina_List *arguments;
Eolian_Type ret_type;
};
};
Eina_Bool is_const :1;
Eina_Bool is_own :1;
Eina_Bool is_struct :1;
} _Parameter_Type;
typedef struct
@ -110,9 +123,13 @@ database_type_del(Eolian_Type type)
_Parameter_Type *typep = (_Parameter_Type*)type;
Eolian_Type stype;
if (!type) return;
EINA_LIST_FREE(typep->subtypes, stype)
database_type_del(stype);
eina_stringshare_del(typep->name);
if (typep->name) eina_stringshare_del(typep->name);
/* for function types, this will map to arguments and ret_type */
if (typep->subtypes)
EINA_LIST_FREE(typep->subtypes, stype)
database_type_del(stype);
if (typep->base_type)
database_type_del(typep->base_type);
free(typep);
}
@ -819,13 +836,11 @@ eolian_function_parameter_get(const Eolian_Function foo_id, const char *param_na
return NULL;
}
EAPI Eina_Stringshare *
EAPI Eolian_Type
eolian_parameter_type_get(const Eolian_Function_Parameter param)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(param, NULL);
_Parameter_Type *type = (_Parameter_Type *)((_Parameter_Desc *)param)->type;
eina_stringshare_ref(type->name);
return type->name;
return ((_Parameter_Desc*)param)->type;
}
EAPI Eina_Stringshare *
@ -860,13 +875,12 @@ eolian_parameters_list_get(Eolian_Function foo_id)
/* Get parameter information */
EAPI void
eolian_parameter_information_get(const Eolian_Function_Parameter param_desc, Eolian_Parameter_Dir *param_dir, const char **type, const char **name, const char **description)
eolian_parameter_information_get(const Eolian_Function_Parameter param_desc, Eolian_Parameter_Dir *param_dir, Eolian_Type *type, const char **name, const char **description)
{
_Parameter_Desc *param = (_Parameter_Desc *)param_desc;
EINA_SAFETY_ON_NULL_RETURN(param);
_Parameter_Type *ptype = (_Parameter_Type *)((_Parameter_Desc *)param)->type;
if (param_dir) *param_dir = param->param_dir;
if (type) *type = ptype->name;
if (type) *type = param->type;
if (name) *name = param->name;
if (description) *description = param->description;
}
@ -882,29 +896,6 @@ database_parameter_const_attribute_set(Eolian_Function_Parameter param_desc, Ein
param->is_const_on_set = is_const;
}
EAPI Eolian_Type
eolian_parameter_types_list_get(const Eolian_Function_Parameter param_desc)
{
_Parameter_Desc *param = (_Parameter_Desc *)param_desc;
EINA_SAFETY_ON_NULL_RETURN_VAL(param, NULL);
return param->type;
}
Eolian_Type
database_type_append(Eolian_Type type, const char *name, Eina_Bool own)
{
_Parameter_Type *stypep = calloc(1, sizeof(*stypep));
stypep->name = eina_stringshare_add(name);
stypep->is_own = own;
if (type)
{
_Parameter_Type *typep = (_Parameter_Type*)type;
typep->subtypes = eina_list_append(typep->subtypes, stypep);
return type;
}
return (Eolian_Type)stypep;
}
void
database_parameter_type_set(Eolian_Function_Parameter param_desc, Eolian_Type types)
{
@ -951,17 +942,8 @@ void database_function_return_type_set(Eolian_Function foo_id, Eolian_Function_T
}
}
EAPI const char *
eolian_function_return_type_get(Eolian_Function foo_id, Eolian_Function_Type ftype)
{
Eolian_Type types = eolian_function_return_types_list_get(foo_id, ftype);
_Parameter_Type *type = (_Parameter_Type *)types;
if (type) return type->name;
else return NULL;
}
EAPI Eolian_Type
eolian_function_return_types_list_get(Eolian_Function foo_id, Eolian_Function_Type ftype)
eolian_function_return_type_get(Eolian_Function foo_id, Eolian_Function_Type ftype)
{
_Function_Id *fid = (_Function_Id *)foo_id;
switch (ftype)
@ -1152,6 +1134,149 @@ eolian_class_dtor_enable_get(const Eolian_Class class)
return cl->class_dtor_enable;
}
EAPI Eolian_Type_Type
eolian_type_type_get(Eolian_Type tp)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, EOLIAN_TYPE_UNKNOWN_TYPE);
return ((_Parameter_Type*)tp)->type;
}
EAPI Eina_Iterator *
eolian_type_arguments_list_get(Eolian_Type tp)
{
_Parameter_Type *tpp = (_Parameter_Type*)tp;
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
EINA_SAFETY_ON_FALSE_RETURN_VAL(eolian_type_type_get(tp) != EOLIAN_TYPE_FUNCTION, NULL);
if (!tpp->arguments) return NULL;
return eina_list_iterator_new(tpp->arguments);
}
EAPI Eina_Iterator *
eolian_type_subtypes_list_get(Eolian_Type tp)
{
_Parameter_Type *tpp = (_Parameter_Type*)tp;
Eolian_Type_Type tpt;
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
tpt = tpp->type;
EINA_SAFETY_ON_FALSE_RETURN_VAL(tpt != EOLIAN_TYPE_REGULAR && tpt != EOLIAN_TYPE_POINTER, NULL);
if (!tpp->subtypes) return NULL;
return eina_list_iterator_new(tpp->subtypes);
}
EAPI Eolian_Type
eolian_type_return_type_get(Eolian_Type tp)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
EINA_SAFETY_ON_FALSE_RETURN_VAL(eolian_type_type_get(tp) != EOLIAN_TYPE_FUNCTION, NULL);
return ((_Parameter_Type*)tp)->ret_type;
}
EAPI Eolian_Type
eolian_type_base_type_get(Eolian_Type tp)
{
Eolian_Type_Type tpt;
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
tpt = eolian_type_type_get(tp);
EINA_SAFETY_ON_FALSE_RETURN_VAL(tpt != EOLIAN_TYPE_REGULAR && tpt != EOLIAN_TYPE_POINTER, NULL);
return ((_Parameter_Type*)tp)->base_type;
}
EAPI Eina_Bool
eolian_type_is_own(Eolian_Type tp)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, EINA_FALSE);
return ((_Parameter_Type*)tp)->is_own;
}
EAPI Eina_Bool
eolian_type_is_const(Eolian_Type tp)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, EINA_FALSE);
return ((_Parameter_Type*)tp)->is_const;
}
static void _type_to_str(Eolian_Type tp, Eina_Strbuf *buf, const char *name);
static void
_ftype_to_str(Eolian_Type tp, Eina_Strbuf *buf, const char *name)
{
_Parameter_Type *tpp = (_Parameter_Type*)tp;
Eina_List *l;
Eolian_Type stp;
Eina_Bool first = EINA_TRUE;
if (tpp->ret_type)
_type_to_str(tpp->ret_type, buf, NULL);
else
eina_strbuf_append(buf, "void");
eina_strbuf_append(buf, " (*");
if (name) eina_strbuf_append(buf, name);
eina_strbuf_append(buf, ")(");
EINA_LIST_FOREACH(tpp->arguments, l, stp)
{
if (!first) eina_strbuf_append(buf, ", ");
first = EINA_FALSE;
_type_to_str(stp, buf, NULL);
}
}
static void
_type_to_str(Eolian_Type tp, Eina_Strbuf *buf, const char *name)
{
_Parameter_Type *tpp = (_Parameter_Type*)tp;
if (tpp->type == EOLIAN_TYPE_FUNCTION)
{
_ftype_to_str(tp, buf, name);
return;
}
if (tpp->type == EOLIAN_TYPE_REGULAR && tpp->is_const)
eina_strbuf_append(buf, "const ");
if (tpp->is_struct)
eina_strbuf_append(buf, "struct ");
if (tpp->type == EOLIAN_TYPE_REGULAR)
eina_strbuf_append(buf, tpp->name);
else
{
_Parameter_Type *btpp = (_Parameter_Type*)tpp->base_type;
_type_to_str(tpp->base_type, buf, NULL);
if (btpp->type != EOLIAN_TYPE_POINTER || btpp->is_const)
eina_strbuf_append_char(buf, ' ');
eina_strbuf_append_char(buf, '*');
if (tpp->is_const) eina_strbuf_append(buf, " const");
}
if (name)
{
eina_strbuf_append_char(buf, ' ');
eina_strbuf_append(buf, name);
}
}
EAPI Eina_Stringshare *
eolian_type_c_type_named_get(Eolian_Type tp, const char *name)
{
Eina_Stringshare *ret;
Eina_Strbuf *buf;
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
buf = eina_strbuf_new();
_type_to_str(tp, buf, name);
ret = eina_stringshare_add(eina_strbuf_string_get(buf));
eina_strbuf_free(buf);
return ret;
}
EAPI Eina_Stringshare *
eolian_type_c_type_get(Eolian_Type tp)
{
return eolian_type_c_type_named_get(tp, NULL);
}
EAPI Eina_Stringshare *
eolian_type_name_get(Eolian_Type tp)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
eina_stringshare_ref(((_Parameter_Type*)tp)->name);
return ((_Parameter_Type*)tp)->name;
}
static void
_implements_print(Eolian_Implement impl, int nb_spaces)
{
@ -1192,10 +1317,41 @@ _type_print(Eolian_Type tp, Eina_Strbuf *buf)
_Parameter_Type *tpp = (_Parameter_Type*)tp;
Eina_List *l;
Eolian_Type stp;
eina_strbuf_append_printf(buf, "%s%s<", tpp->name, tpp->is_own ? "@own" : "");
EINA_LIST_FOREACH(tpp->subtypes, l, stp)
_type_print(stp, buf);
eina_strbuf_append_char(buf, '>');
if (tpp->is_own)
eina_strbuf_append(buf, "@own(");
if (tpp->is_const)
eina_strbuf_append(buf, "const(");
if (tpp->is_struct)
eina_strbuf_append(buf, "struct ");
if (tpp->type == EOLIAN_TYPE_REGULAR)
eina_strbuf_append(buf, tpp->name);
else if (tpp->type == EOLIAN_TYPE_POINTER)
{
_type_print(tpp->base_type, buf);
eina_strbuf_append_char(buf, '*');
}
else if (tpp->type == EOLIAN_TYPE_FUNCTION)
{
Eina_Bool first = EINA_TRUE;
eina_strbuf_append(buf, "fn");
if (tpp->ret_type)
{
eina_strbuf_append(buf, " -> ");
_type_print(tpp->ret_type, buf);
}
eina_strbuf_append(buf, " (");
EINA_LIST_FOREACH(tpp->arguments, l, stp)
{
if (!first) eina_strbuf_append(buf, ", ");
first = EINA_FALSE;
_type_print(stp, buf);
}
eina_strbuf_append_char(buf, ')');
}
if (tpp->is_own)
eina_strbuf_append_char(buf, ')');
if (tpp->is_const)
eina_strbuf_append_char(buf, ')');
}
static Eina_Bool _function_print(const _Function_Id *fid, int nb_spaces)

View File

@ -89,8 +89,6 @@ Eolian_Function_Parameter database_property_value_add(Eolian_Function foo_id, Eo
/* Add a parameter to a method */
Eolian_Function_Parameter database_method_parameter_add(Eolian_Function foo_id, Eolian_Parameter_Dir param_dir, Eolian_Type type, const char *name, const char *description);
Eolian_Type database_type_append(Eolian_Type type, const char *name, Eina_Bool own);
void database_type_del(Eolian_Type type);
void database_parameter_const_attribute_set(Eolian_Function_Parameter param_desc, Eina_Bool is_get, Eina_Bool is_const);