summaryrefslogtreecommitdiff
path: root/src/lib/eolian
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2019-09-04 15:56:32 +0200
committerDaniel Kolesa <d.kolesa@samsung.com>2019-09-04 16:27:54 +0200
commit0275ef0f33f017ad5a6cb681f1b108a2769c428f (patch)
tree065b30c4524465188c686e587cd1e7263d1a8fee /src/lib/eolian
parentc5b88ca745b5f457975963914bb2f319705f5c7e (diff)
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).
Diffstat (limited to 'src/lib/eolian')
-rw-r--r--src/lib/eolian/Eolian.h46
-rw-r--r--src/lib/eolian/database_function_api.c40
-rw-r--r--src/lib/eolian/database_function_parameter_api.c14
-rw-r--r--src/lib/eolian/database_type.c10
-rw-r--r--src/lib/eolian/database_type_api.c13
-rw-r--r--src/lib/eolian/eolian_database.h2
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
@@ -1904,6 +1904,23 @@ EAPI Eina_Bool eolian_parameter_is_by_ref(const Eolian_Function_Parameter *param
1904EAPI Eina_Bool eolian_parameter_is_move(const Eolian_Function_Parameter *param_desc); 1904EAPI Eina_Bool eolian_parameter_is_move(const Eolian_Function_Parameter *param_desc);
1905 1905
1906/* 1906/*
1907 * @brief Get the full C type name of the given parameter.
1908 *
1909 * @param[in] param_desc parameter handle
1910 * @param[in] as_return if true, it will be treated as a return type
1911 * @return The C type name assuming @c param_desc is not NULL.
1912 *
1913 * You're responsible for the stringshare. The @c as_return argument is meant
1914 * for properties, where the first out-param gets made into a return, which
1915 * has different typing characteristics.
1916 *
1917 * @see eolian_type_c_type_get
1918 *
1919 * @ingroup Eolian
1920 */
1921EAPI Eina_Stringshare *eolian_parameter_c_type_get(const Eolian_Function_Parameter *param_desc, Eina_Bool as_return);
1922
1923/*
1907 * @brief Get the return type of a function. 1924 * @brief Get the return type of a function.
1908 * 1925 *
1909 * @param[in] function_id id of the function 1926 * @param[in] function_id id of the function
@@ -2002,6 +2019,21 @@ EAPI Eina_Bool eolian_function_return_is_by_ref(const Eolian_Function *foo_id, E
2002EAPI Eina_Bool eolian_function_return_is_move(const Eolian_Function *foo_id, Eolian_Function_Type ftype); 2019EAPI Eina_Bool eolian_function_return_is_move(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
2003 2020
2004/* 2021/*
2022 * @brief Get the full C type name of the return value.
2023 *
2024 * @param[in] function_id id of the function
2025 * @param[in] ftype type of the function
2026 * @return The C type name.
2027 *
2028 * You're responsible for the stringshare.
2029 *
2030 * @see eolian_type_c_type_get
2031 *
2032 * @ingroup Eolian
2033 */
2034EAPI Eina_Stringshare *eolian_function_return_c_type_get(const Eolian_Function *foo_id, Eolian_Function_Type ftype);
2035
2036/*
2005 * @brief Indicates if a function object is const. 2037 * @brief Indicates if a function object is const.
2006 * 2038 *
2007 * @param[in] function_id id of the function 2039 * @param[in] function_id id of the function
@@ -2575,6 +2607,20 @@ EAPI Eina_Bool eolian_typedecl_struct_field_is_by_ref(const Eolian_Struct_Type_F
2575EAPI Eina_Bool eolian_typedecl_struct_field_is_move(const Eolian_Struct_Type_Field *fl); 2607EAPI Eina_Bool eolian_typedecl_struct_field_is_move(const Eolian_Struct_Type_Field *fl);
2576 2608
2577/* 2609/*
2610 * @brief Get the full C type name of the struct field.
2611 *
2612 * @param[in] fl the field.
2613 * @return The C type name.
2614 *
2615 * You're responsible for the stringshare.
2616 *
2617 * @see eolian_type_c_type_get
2618 *
2619 * @ingroup Eolian
2620 */
2621EAPI Eina_Stringshare *eolian_typedecl_struct_field_c_type_get(const Eolian_Struct_Type_Field *fl);
2622
2623/*
2578 * @brief Get an iterator to all fields of an enum type. 2624 * @brief Get an iterator to all fields of an enum type.
2579 * 2625 *
2580 * @param[in] tp the type declaration. 2626 * @param[in] tp the type declaration.
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,
342 } 342 }
343} 343}
344 344
345EAPI Eina_Stringshare *
346eolian_function_return_c_type_get(const Eolian_Function *fid,
347 Eolian_Function_Type ftype)
348{
349 EINA_SAFETY_ON_NULL_RETURN_VAL(fid, EINA_FALSE);
350 EINA_SAFETY_ON_FALSE_RETURN_VAL(ftype != EOLIAN_UNRESOLVED, EINA_FALSE);
351 EINA_SAFETY_ON_FALSE_RETURN_VAL(ftype != EOLIAN_PROPERTY, EINA_FALSE);
352 const Eolian_Type *tp = NULL;
353 Eina_Bool by_ref = EINA_FALSE;
354 switch (ftype)
355 {
356 case EOLIAN_METHOD:
357 case EOLIAN_FUNCTION_POINTER:
358 if (fid->type != ftype)
359 return NULL;
360 tp = fid->get_ret_type;
361 by_ref = fid->get_return_by_ref;
362 break;
363 case EOLIAN_PROP_GET:
364 if ((fid->type != EOLIAN_PROP_GET) && (fid->type != EOLIAN_PROPERTY))
365 return NULL;
366 tp = fid->get_ret_type;
367 by_ref = fid->get_return_by_ref;
368 break;
369 case EOLIAN_PROP_SET:
370 if ((fid->type != EOLIAN_PROP_SET) && (fid->type != EOLIAN_PROPERTY))
371 return NULL;
372 tp = fid->set_ret_type;
373 by_ref = fid->set_return_by_ref;
374 break;
375 default:
376 return NULL;
377 }
378 Eina_Strbuf *buf = eina_strbuf_new();
379 database_type_to_str(tp, buf, NULL, EOLIAN_C_TYPE_RETURN, by_ref);
380 Eina_Stringshare *ret = eina_stringshare_add(eina_strbuf_string_get(buf));
381 eina_strbuf_free(buf);
382 return ret;
383}
384
345EAPI Eina_Bool 385EAPI Eina_Bool
346eolian_function_object_is_const(const Eolian_Function *fid) 386eolian_function_object_is_const(const Eolian_Function *fid)
347{ 387{
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)
53 EINA_SAFETY_ON_NULL_RETURN_VAL(param, EINA_FALSE); 53 EINA_SAFETY_ON_NULL_RETURN_VAL(param, EINA_FALSE);
54 return param->by_ref; 54 return param->by_ref;
55} 55}
56
57EAPI Eina_Stringshare *
58eolian_parameter_c_type_get(const Eolian_Function_Parameter *param_desc,
59 Eina_Bool as_return)
60{
61 EINA_SAFETY_ON_NULL_RETURN_VAL(param_desc, NULL);
62 Eina_Strbuf *buf = eina_strbuf_new();
63 database_type_to_str(param_desc->type, buf, NULL,
64 as_return ? EOLIAN_C_TYPE_RETURN : EOLIAN_C_TYPE_PARAM,
65 param_desc->by_ref);
66 Eina_Stringshare *ret = eina_stringshare_add(eina_strbuf_string_get(buf));
67 eina_strbuf_free(buf);
68 return ret;
69} \ 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)
101void 101void
102database_type_to_str(const Eolian_Type *tp, 102database_type_to_str(const Eolian_Type *tp,
103 Eina_Strbuf *buf, const char *name, 103 Eina_Strbuf *buf, const char *name,
104 Eolian_C_Type_Type ctype) 104 Eolian_C_Type_Type ctype, Eina_Bool by_ref)
105{ 105{
106 if ((tp->type == EOLIAN_TYPE_REGULAR 106 if ((tp->type == EOLIAN_TYPE_REGULAR
107 || tp->type == EOLIAN_TYPE_CLASS 107 || tp->type == EOLIAN_TYPE_CLASS
@@ -128,7 +128,7 @@ database_type_to_str(const Eolian_Type *tp,
128 { 128 {
129 /* handles arrays and pointers as they all serialize to pointers */ 129 /* handles arrays and pointers as they all serialize to pointers */
130 database_type_to_str(tp->base_type, buf, NULL, 130 database_type_to_str(tp->base_type, buf, NULL,
131 EOLIAN_C_TYPE_DEFAULT); 131 EOLIAN_C_TYPE_DEFAULT, EINA_FALSE);
132 _buf_add_suffix(buf, "*"); 132 _buf_add_suffix(buf, "*");
133 if (tp->is_const && (ctype != EOLIAN_C_TYPE_RETURN)) 133 if (tp->is_const && (ctype != EOLIAN_C_TYPE_RETURN))
134 eina_strbuf_append(buf, " const"); 134 eina_strbuf_append(buf, " const");
@@ -137,6 +137,8 @@ database_type_to_str(const Eolian_Type *tp,
137 _buf_add_suffix(buf, "*"); 137 _buf_add_suffix(buf, "*");
138 if (tp->is_ptr) 138 if (tp->is_ptr)
139 _buf_add_suffix(buf, "*"); 139 _buf_add_suffix(buf, "*");
140 if (by_ref)
141 _buf_add_suffix(buf, "*");
140 _buf_add_suffix(buf, name); 142 _buf_add_suffix(buf, name);
141} 143}
142 144
@@ -153,7 +155,7 @@ _stype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf)
153 EINA_LIST_FOREACH(tp->field_list, l, sf) 155 EINA_LIST_FOREACH(tp->field_list, l, sf)
154 { 156 {
155 database_type_to_str(sf->type, buf, sf->base.name, 157 database_type_to_str(sf->type, buf, sf->base.name,
156 EOLIAN_C_TYPE_DEFAULT); 158 EOLIAN_C_TYPE_DEFAULT, sf->by_ref);
157 eina_strbuf_append(buf, "; "); 159 eina_strbuf_append(buf, "; ");
158 } 160 }
159 eina_strbuf_append(buf, "}"); 161 eina_strbuf_append(buf, "}");
@@ -191,7 +193,7 @@ _atype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf)
191{ 193{
192 eina_strbuf_append(buf, "typedef "); 194 eina_strbuf_append(buf, "typedef ");
193 database_type_to_str(tp->base_type, buf, tp->base.c_name, 195 database_type_to_str(tp->base_type, buf, tp->base.c_name,
194 EOLIAN_C_TYPE_DEFAULT); 196 EOLIAN_C_TYPE_DEFAULT, EINA_FALSE);
195} 197}
196 198
197void 199void
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)
77 return fl->move; 77 return fl->move;
78} 78}
79 79
80EAPI Eina_Stringshare *
81eolian_typedecl_struct_field_c_type_get(const Eolian_Struct_Type_Field *fl)
82{
83 EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL);
84 Eina_Strbuf *buf = eina_strbuf_new();
85 database_type_to_str(fl->type, buf, NULL, EOLIAN_C_TYPE_DEFAULT, fl->by_ref);
86 Eina_Stringshare *ret = eina_stringshare_add(eina_strbuf_string_get(buf));
87 eina_strbuf_free(buf);
88 return ret;
89}
90
80EAPI Eina_Iterator * 91EAPI Eina_Iterator *
81eolian_typedecl_enum_fields_get(const Eolian_Typedecl *tp) 92eolian_typedecl_enum_fields_get(const Eolian_Typedecl *tp)
82{ 93{
@@ -262,7 +273,7 @@ eolian_type_c_type_get(const Eolian_Type *tp, Eolian_C_Type_Type ctype)
262 Eina_Strbuf *buf; 273 Eina_Strbuf *buf;
263 EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL); 274 EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
264 buf = eina_strbuf_new(); 275 buf = eina_strbuf_new();
265 database_type_to_str(tp, buf, NULL, ctype); 276 database_type_to_str(tp, buf, NULL, ctype, EINA_FALSE);
266 ret = eina_stringshare_add(eina_strbuf_string_get(buf)); 277 ret = eina_stringshare_add(eina_strbuf_string_get(buf));
267 eina_strbuf_free(buf); 278 eina_strbuf_free(buf);
268 return ret; 279 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);
425void database_type_del(Eolian_Type *tp); 425void database_type_del(Eolian_Type *tp);
426void database_typedecl_del(Eolian_Typedecl *tp); 426void database_typedecl_del(Eolian_Typedecl *tp);
427 427
428void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, Eolian_C_Type_Type ctype); 428void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, Eolian_C_Type_Type ctype, Eina_Bool by_ref);
429void database_typedecl_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf); 429void database_typedecl_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf);
430 430
431Eolian_Typedecl *database_type_decl_find(const Eolian_Unit *src, const Eolian_Type *tp); 431Eolian_Typedecl *database_type_decl_find(const Eolian_Unit *src, const Eolian_Type *tp);