q66 pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=0275ef0f33f017ad5a6cb681f1b108a2769c428f
commit 0275ef0f33f017ad5a6cb681f1b108a2769c428f Author: Daniel Kolesa <d.kol...@samsung.com> Date: Wed Sep 4 15:56:32 2019 +0200 eolian: add APIs to get full C types of parameters/returns/fields These are needed because the type itself does not carry all the information it needs to carry (particularly by_ref). --- src/lib/eolian/Eolian.h | 46 ++++++++++++++++++++++++ src/lib/eolian/database_function_api.c | 40 +++++++++++++++++++++ src/lib/eolian/database_function_parameter_api.c | 14 ++++++++ src/lib/eolian/database_type.c | 10 +++--- src/lib/eolian/database_type_api.c | 13 ++++++- src/lib/eolian/eolian_database.h | 2 +- 6 files changed, 119 insertions(+), 6 deletions(-) diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h index b054792e29..cee793f0d9 100644 --- a/src/lib/eolian/Eolian.h +++ b/src/lib/eolian/Eolian.h @@ -1903,6 +1903,23 @@ EAPI Eina_Bool eolian_parameter_is_by_ref(const Eolian_Function_Parameter *param */ EAPI Eina_Bool eolian_parameter_is_move(const Eolian_Function_Parameter *param_desc); +/* + * @brief Get the full C type name of the given parameter. + * + * @param[in] param_desc parameter handle + * @param[in] as_return if true, it will be treated as a return type + * @return The C type name assuming @c param_desc is not NULL. + * + * You're responsible for the stringshare. The @c as_return argument is meant + * for properties, where the first out-param gets made into a return, which + * has different typing characteristics. + * + * @see eolian_type_c_type_get + * + * @ingroup Eolian + */ +EAPI Eina_Stringshare *eolian_parameter_c_type_get(const Eolian_Function_Parameter *param_desc, Eina_Bool as_return); + /* * @brief Get the return type of a function. * @@ -2001,6 +2018,21 @@ EAPI Eina_Bool eolian_function_return_is_by_ref(const Eolian_Function *foo_id, E */ EAPI Eina_Bool eolian_function_return_is_move(const Eolian_Function *foo_id, Eolian_Function_Type ftype); +/* + * @brief Get the full C type name of the return value. + * + * @param[in] function_id id of the function + * @param[in] ftype type of the function + * @return The C type name. + * + * You're responsible for the stringshare. + * + * @see eolian_type_c_type_get + * + * @ingroup Eolian + */ +EAPI Eina_Stringshare *eolian_function_return_c_type_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype); + /* * @brief Indicates if a function object is const. * @@ -2574,6 +2606,20 @@ EAPI Eina_Bool eolian_typedecl_struct_field_is_by_ref(const Eolian_Struct_Type_F */ EAPI Eina_Bool eolian_typedecl_struct_field_is_move(const Eolian_Struct_Type_Field *fl); +/* + * @brief Get the full C type name of the struct field. + * + * @param[in] fl the field. + * @return The C type name. + * + * You're responsible for the stringshare. + * + * @see eolian_type_c_type_get + * + * @ingroup Eolian + */ +EAPI Eina_Stringshare *eolian_typedecl_struct_field_c_type_get(const Eolian_Struct_Type_Field *fl); + /* * @brief Get an iterator to all fields of an enum type. * diff --git a/src/lib/eolian/database_function_api.c b/src/lib/eolian/database_function_api.c index 15bbfde785..fd78164892 100644 --- a/src/lib/eolian/database_function_api.c +++ b/src/lib/eolian/database_function_api.c @@ -342,6 +342,46 @@ eolian_function_return_is_move(const Eolian_Function *fid, } } +EAPI Eina_Stringshare * +eolian_function_return_c_type_get(const Eolian_Function *fid, + Eolian_Function_Type ftype) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(fid, EINA_FALSE); + EINA_SAFETY_ON_FALSE_RETURN_VAL(ftype != EOLIAN_UNRESOLVED, EINA_FALSE); + EINA_SAFETY_ON_FALSE_RETURN_VAL(ftype != EOLIAN_PROPERTY, EINA_FALSE); + const Eolian_Type *tp = NULL; + Eina_Bool by_ref = EINA_FALSE; + switch (ftype) + { + case EOLIAN_METHOD: + case EOLIAN_FUNCTION_POINTER: + if (fid->type != ftype) + return NULL; + tp = fid->get_ret_type; + by_ref = fid->get_return_by_ref; + break; + case EOLIAN_PROP_GET: + if ((fid->type != EOLIAN_PROP_GET) && (fid->type != EOLIAN_PROPERTY)) + return NULL; + tp = fid->get_ret_type; + by_ref = fid->get_return_by_ref; + break; + case EOLIAN_PROP_SET: + if ((fid->type != EOLIAN_PROP_SET) && (fid->type != EOLIAN_PROPERTY)) + return NULL; + tp = fid->set_ret_type; + by_ref = fid->set_return_by_ref; + break; + default: + return NULL; + } + Eina_Strbuf *buf = eina_strbuf_new(); + database_type_to_str(tp, buf, NULL, EOLIAN_C_TYPE_RETURN, by_ref); + Eina_Stringshare *ret = eina_stringshare_add(eina_strbuf_string_get(buf)); + eina_strbuf_free(buf); + return ret; +} + EAPI Eina_Bool eolian_function_object_is_const(const Eolian_Function *fid) { diff --git a/src/lib/eolian/database_function_parameter_api.c b/src/lib/eolian/database_function_parameter_api.c index 60673a55ff..341b287978 100644 --- a/src/lib/eolian/database_function_parameter_api.c +++ b/src/lib/eolian/database_function_parameter_api.c @@ -53,3 +53,17 @@ eolian_parameter_is_by_ref(const Eolian_Function_Parameter *param) EINA_SAFETY_ON_NULL_RETURN_VAL(param, EINA_FALSE); return param->by_ref; } + +EAPI Eina_Stringshare * +eolian_parameter_c_type_get(const Eolian_Function_Parameter *param_desc, + Eina_Bool as_return) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(param_desc, NULL); + Eina_Strbuf *buf = eina_strbuf_new(); + database_type_to_str(param_desc->type, buf, NULL, + as_return ? EOLIAN_C_TYPE_RETURN : EOLIAN_C_TYPE_PARAM, + param_desc->by_ref); + Eina_Stringshare *ret = eina_stringshare_add(eina_strbuf_string_get(buf)); + eina_strbuf_free(buf); + return ret; +} \ No newline at end of file diff --git a/src/lib/eolian/database_type.c b/src/lib/eolian/database_type.c index 70a8ad6354..6381cf8496 100644 --- a/src/lib/eolian/database_type.c +++ b/src/lib/eolian/database_type.c @@ -101,7 +101,7 @@ _buf_add_suffix(Eina_Strbuf *buf, const char *suffix) void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, - Eolian_C_Type_Type ctype) + Eolian_C_Type_Type ctype, Eina_Bool by_ref) { if ((tp->type == EOLIAN_TYPE_REGULAR || tp->type == EOLIAN_TYPE_CLASS @@ -128,7 +128,7 @@ database_type_to_str(const Eolian_Type *tp, { /* handles arrays and pointers as they all serialize to pointers */ database_type_to_str(tp->base_type, buf, NULL, - EOLIAN_C_TYPE_DEFAULT); + EOLIAN_C_TYPE_DEFAULT, EINA_FALSE); _buf_add_suffix(buf, "*"); if (tp->is_const && (ctype != EOLIAN_C_TYPE_RETURN)) eina_strbuf_append(buf, " const"); @@ -137,6 +137,8 @@ database_type_to_str(const Eolian_Type *tp, _buf_add_suffix(buf, "*"); if (tp->is_ptr) _buf_add_suffix(buf, "*"); + if (by_ref) + _buf_add_suffix(buf, "*"); _buf_add_suffix(buf, name); } @@ -153,7 +155,7 @@ _stype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf) EINA_LIST_FOREACH(tp->field_list, l, sf) { database_type_to_str(sf->type, buf, sf->base.name, - EOLIAN_C_TYPE_DEFAULT); + EOLIAN_C_TYPE_DEFAULT, sf->by_ref); eina_strbuf_append(buf, "; "); } eina_strbuf_append(buf, "}"); @@ -191,7 +193,7 @@ _atype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf) { eina_strbuf_append(buf, "typedef "); database_type_to_str(tp->base_type, buf, tp->base.c_name, - EOLIAN_C_TYPE_DEFAULT); + EOLIAN_C_TYPE_DEFAULT, EINA_FALSE); } void diff --git a/src/lib/eolian/database_type_api.c b/src/lib/eolian/database_type_api.c index 2bec505ca0..12e787d8f8 100644 --- a/src/lib/eolian/database_type_api.c +++ b/src/lib/eolian/database_type_api.c @@ -77,6 +77,17 @@ eolian_typedecl_struct_field_is_move(const Eolian_Struct_Type_Field *fl) return fl->move; } +EAPI Eina_Stringshare * +eolian_typedecl_struct_field_c_type_get(const Eolian_Struct_Type_Field *fl) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL); + Eina_Strbuf *buf = eina_strbuf_new(); + database_type_to_str(fl->type, buf, NULL, EOLIAN_C_TYPE_DEFAULT, fl->by_ref); + Eina_Stringshare *ret = eina_stringshare_add(eina_strbuf_string_get(buf)); + eina_strbuf_free(buf); + return ret; +} + EAPI Eina_Iterator * eolian_typedecl_enum_fields_get(const Eolian_Typedecl *tp) { @@ -262,7 +273,7 @@ eolian_type_c_type_get(const Eolian_Type *tp, Eolian_C_Type_Type ctype) Eina_Strbuf *buf; EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL); buf = eina_strbuf_new(); - database_type_to_str(tp, buf, NULL, ctype); + database_type_to_str(tp, buf, NULL, ctype, EINA_FALSE); ret = eina_stringshare_add(eina_strbuf_string_get(buf)); eina_strbuf_free(buf); return ret; diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h index 8f67ab5dc5..8a16733780 100644 --- a/src/lib/eolian/eolian_database.h +++ b/src/lib/eolian/eolian_database.h @@ -425,7 +425,7 @@ void database_enum_add(Eolian_Unit *unit, Eolian_Typedecl *tp); void database_type_del(Eolian_Type *tp); void database_typedecl_del(Eolian_Typedecl *tp); -void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, Eolian_C_Type_Type ctype); +void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, Eolian_C_Type_Type ctype, Eina_Bool by_ref); void database_typedecl_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf); Eolian_Typedecl *database_type_decl_find(const Eolian_Unit *src, const Eolian_Type *tp); --