1 #ifdef HAVE_CONFIG_H
2 # include "config.h"
3 #endif
4 
5 #include <Eina.h>
6 #include "eolian_database.h"
7 #include "eo_lexer.h"
8 
9 EAPI Eolian_Type_Type
eolian_type_type_get(const Eolian_Type * tp)10 eolian_type_type_get(const Eolian_Type *tp)
11 {
12    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, EOLIAN_TYPE_UNKNOWN_TYPE);
13    return tp->type;
14 }
15 
16 EAPI Eolian_Type_Builtin_Type
eolian_type_builtin_type_get(const Eolian_Type * tp)17 eolian_type_builtin_type_get(const Eolian_Type *tp)
18 {
19    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, EOLIAN_TYPE_BUILTIN_INVALID);
20    return tp->btype;
21 }
22 
23 EAPI Eolian_Typedecl_Type
eolian_typedecl_type_get(const Eolian_Typedecl * tp)24 eolian_typedecl_type_get(const Eolian_Typedecl *tp)
25 {
26    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, EOLIAN_TYPEDECL_UNKNOWN);
27    return tp->type;
28 }
29 
30 EAPI Eina_Iterator *
eolian_typedecl_struct_fields_get(const Eolian_Typedecl * tp)31 eolian_typedecl_struct_fields_get(const Eolian_Typedecl *tp)
32 {
33    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
34    if (tp->type != EOLIAN_TYPEDECL_STRUCT)
35      return NULL;
36    return eina_list_iterator_new(tp->field_list);
37 }
38 
39 EAPI const Eolian_Struct_Type_Field *
eolian_typedecl_struct_field_get(const Eolian_Typedecl * tp,const char * field)40 eolian_typedecl_struct_field_get(const Eolian_Typedecl *tp, const char *field)
41 {
42    Eolian_Struct_Type_Field *sf = NULL;
43    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
44    EINA_SAFETY_ON_NULL_RETURN_VAL(field, NULL);
45    if (tp->type != EOLIAN_TYPEDECL_STRUCT)
46      return NULL;
47    sf = eina_hash_find(tp->fields, field);
48    if (!sf) return NULL;
49    return sf;
50 }
51 
52 EAPI const Eolian_Documentation *
eolian_typedecl_struct_field_documentation_get(const Eolian_Struct_Type_Field * fl)53 eolian_typedecl_struct_field_documentation_get(const Eolian_Struct_Type_Field *fl)
54 {
55    EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL);
56    return fl->doc;
57 }
58 
59 EAPI const Eolian_Type *
eolian_typedecl_struct_field_type_get(const Eolian_Struct_Type_Field * fl)60 eolian_typedecl_struct_field_type_get(const Eolian_Struct_Type_Field *fl)
61 {
62    EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL);
63    return fl->type;
64 }
65 
66 EAPI Eina_Bool
eolian_typedecl_struct_field_is_by_ref(const Eolian_Struct_Type_Field * fl)67 eolian_typedecl_struct_field_is_by_ref(const Eolian_Struct_Type_Field *fl)
68 {
69    EINA_SAFETY_ON_NULL_RETURN_VAL(fl, EINA_FALSE);
70    return fl->by_ref;
71 }
72 
73 EAPI Eina_Bool
eolian_typedecl_struct_field_is_move(const Eolian_Struct_Type_Field * fl)74 eolian_typedecl_struct_field_is_move(const Eolian_Struct_Type_Field *fl)
75 {
76    EINA_SAFETY_ON_NULL_RETURN_VAL(fl, EINA_FALSE);
77    return fl->move;
78 }
79 
80 EAPI Eina_Stringshare *
eolian_typedecl_struct_field_c_type_get(const Eolian_Struct_Type_Field * fl)81 eolian_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 
91 EAPI Eina_Iterator *
eolian_typedecl_enum_fields_get(const Eolian_Typedecl * tp)92 eolian_typedecl_enum_fields_get(const Eolian_Typedecl *tp)
93 {
94    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
95    if (tp->type != EOLIAN_TYPEDECL_ENUM)
96      return NULL;
97    return eina_list_iterator_new(tp->field_list);
98 }
99 
100 EAPI const Eolian_Enum_Type_Field *
eolian_typedecl_enum_field_get(const Eolian_Typedecl * tp,const char * field)101 eolian_typedecl_enum_field_get(const Eolian_Typedecl *tp, const char *field)
102 {
103    Eolian_Enum_Type_Field *ef = NULL;
104    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
105    EINA_SAFETY_ON_NULL_RETURN_VAL(field, NULL);
106    if (tp->type != EOLIAN_TYPEDECL_ENUM)
107      return NULL;
108    ef = eina_hash_find(tp->fields, field);
109    if (!ef) return NULL;
110    return ef;
111 }
112 
113 EAPI Eina_Stringshare *
eolian_typedecl_enum_field_c_constant_get(const Eolian_Enum_Type_Field * fl)114 eolian_typedecl_enum_field_c_constant_get(const Eolian_Enum_Type_Field *fl)
115 {
116    Eina_Stringshare *ret;
117    Eina_Strbuf *buf;
118    char *bufp, *p;
119    EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL);
120    buf = eina_strbuf_new();
121    if (fl->base_enum->legacy)
122      eina_strbuf_append(buf, fl->base_enum->legacy);
123    else
124      eina_strbuf_append(buf, fl->base_enum->base.c_name);
125    eina_strbuf_append_char(buf, '_');
126    eina_strbuf_append(buf, fl->base.name);
127    bufp = eina_strbuf_string_steal(buf);
128    eina_strbuf_free(buf);
129    eina_str_toupper(&bufp);
130    while ((p = strchr(bufp, '.'))) *p = '_';
131    ret = eina_stringshare_add(bufp);
132    free(bufp);
133    return ret;
134 }
135 
136 EAPI const Eolian_Documentation *
eolian_typedecl_enum_field_documentation_get(const Eolian_Enum_Type_Field * fl)137 eolian_typedecl_enum_field_documentation_get(const Eolian_Enum_Type_Field *fl)
138 {
139    EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL);
140    return fl->doc;
141 }
142 
143 EAPI const Eolian_Expression *
eolian_typedecl_enum_field_value_get(const Eolian_Enum_Type_Field * fl,Eina_Bool force)144 eolian_typedecl_enum_field_value_get(const Eolian_Enum_Type_Field *fl, Eina_Bool force)
145 {
146    EINA_SAFETY_ON_NULL_RETURN_VAL(fl, NULL);
147    if (!force && !fl->is_public_value) return NULL;
148    return fl->value;
149 }
150 
151 EAPI const char *
eolian_typedecl_enum_legacy_prefix_get(const Eolian_Typedecl * tp)152 eolian_typedecl_enum_legacy_prefix_get(const Eolian_Typedecl *tp)
153 {
154    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
155    if (tp->type != EOLIAN_TYPEDECL_ENUM)
156      return NULL;
157    return tp->legacy;
158 }
159 
160 EAPI const Eolian_Documentation *
eolian_typedecl_documentation_get(const Eolian_Typedecl * tp)161 eolian_typedecl_documentation_get(const Eolian_Typedecl *tp)
162 {
163    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
164    return tp->doc;
165 }
166 
167 EAPI const Eolian_Type *
eolian_type_base_type_get(const Eolian_Type * tp)168 eolian_type_base_type_get(const Eolian_Type *tp)
169 {
170    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
171    return tp->base_type;
172 }
173 
174 EAPI const Eolian_Type *
eolian_type_next_type_get(const Eolian_Type * tp)175 eolian_type_next_type_get(const Eolian_Type *tp)
176 {
177    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
178    return tp->next_type;
179 }
180 
181 EAPI const Eolian_Typedecl *
eolian_type_typedecl_get(const Eolian_Type * tp)182 eolian_type_typedecl_get(const Eolian_Type *tp)
183 {
184    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
185    if (eolian_type_type_get(tp) != EOLIAN_TYPE_REGULAR)
186      return NULL;
187    return tp->tdecl;
188 }
189 
190 EAPI const Eolian_Type *
eolian_typedecl_base_type_get(const Eolian_Typedecl * tp)191 eolian_typedecl_base_type_get(const Eolian_Typedecl *tp)
192 {
193    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
194    return tp->base_type;
195 }
196 
197 EAPI const Eolian_Type *
eolian_type_aliased_base_get(const Eolian_Type * tp)198 eolian_type_aliased_base_get(const Eolian_Type *tp)
199 {
200    if (!tp || tp->type != EOLIAN_TYPE_REGULAR || tp->is_ptr)
201      return tp;
202    const Eolian_Typedecl *btp = eolian_type_typedecl_get(tp);
203    if (btp && (btp->type == EOLIAN_TYPEDECL_ALIAS))
204      return eolian_typedecl_aliased_base_get(btp);
205    return tp;
206 }
207 
208 EAPI const Eolian_Type *
eolian_typedecl_aliased_base_get(const Eolian_Typedecl * tp)209 eolian_typedecl_aliased_base_get(const Eolian_Typedecl *tp)
210 {
211    if (!tp || tp->type != EOLIAN_TYPEDECL_ALIAS)
212      return NULL;
213    return eolian_type_aliased_base_get(tp->base_type);
214 }
215 
216 EAPI const Eolian_Class *
eolian_type_class_get(const Eolian_Type * tp)217 eolian_type_class_get(const Eolian_Type *tp)
218 {
219    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
220    if (eolian_type_type_get(tp) != EOLIAN_TYPE_CLASS)
221      return NULL;
222    return tp->klass;
223 }
224 
225 EAPI const Eolian_Error *
eolian_type_error_get(const Eolian_Type * tp)226 eolian_type_error_get(const Eolian_Type *tp)
227 {
228    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
229    if (eolian_type_type_get(tp) != EOLIAN_TYPE_ERROR)
230      return NULL;
231    return tp->error;
232 }
233 
234 EAPI Eina_Bool
eolian_type_is_move(const Eolian_Type * tp)235 eolian_type_is_move(const Eolian_Type *tp)
236 {
237    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, EINA_FALSE);
238    return tp->move;
239 }
240 
241 EAPI Eina_Bool
eolian_type_is_const(const Eolian_Type * tp)242 eolian_type_is_const(const Eolian_Type *tp)
243 {
244    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, EINA_FALSE);
245    return tp->is_const;
246 }
247 
248 EAPI Eina_Bool
eolian_type_is_ptr(const Eolian_Type * tp)249 eolian_type_is_ptr(const Eolian_Type *tp)
250 {
251    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, EINA_FALSE);
252    return tp->is_ptr;
253 }
254 
255 EAPI Eina_Bool
eolian_typedecl_is_extern(const Eolian_Typedecl * tp)256 eolian_typedecl_is_extern(const Eolian_Typedecl *tp)
257 {
258    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, EINA_FALSE);
259    return tp->is_extern;
260 }
261 
262 EAPI Eina_Stringshare *
eolian_type_c_type_get(const Eolian_Type * tp)263 eolian_type_c_type_get(const Eolian_Type *tp)
264 {
265    Eina_Stringshare *ret;
266    Eina_Strbuf *buf;
267    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
268    buf = eina_strbuf_new();
269    database_type_to_str(tp, buf, NULL, EOLIAN_C_TYPE_DEFAULT, EINA_FALSE);
270    ret = eina_stringshare_add(eina_strbuf_string_get(buf));
271    eina_strbuf_free(buf);
272    return ret;
273 }
274 
275 EAPI Eina_Stringshare *
eolian_typedecl_c_type_get(const Eolian_Typedecl * tp)276 eolian_typedecl_c_type_get(const Eolian_Typedecl *tp)
277 {
278    Eina_Stringshare *ret;
279    Eina_Strbuf *buf;
280    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
281    buf = eina_strbuf_new();
282    database_typedecl_to_str(tp, buf);
283    ret = eina_stringshare_add(eina_strbuf_string_get(buf));
284    eina_strbuf_free(buf);
285    return ret;
286 }
287 
288 EAPI const char *
eolian_typedecl_free_func_get(const Eolian_Typedecl * tp)289 eolian_typedecl_free_func_get(const Eolian_Typedecl *tp)
290 {
291    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
292    return tp->freefunc;
293 }
294 
295 EAPI const Eolian_Function *
eolian_typedecl_function_pointer_get(const Eolian_Typedecl * tp)296 eolian_typedecl_function_pointer_get(const Eolian_Typedecl *tp)
297 {
298    EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
299    if (eolian_typedecl_type_get(tp) != EOLIAN_TYPEDECL_FUNCTION_POINTER)
300      return NULL;
301    return tp->function_pointer;
302 }
303