summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/eolian/Eolian.h12
-rw-r--r--src/lib/eolian/database_expr.c2
-rw-r--r--src/lib/eolian/database_expr_api.c4
-rw-r--r--src/lib/eolian/database_type.c35
-rw-r--r--src/lib/eolian/database_type_api.c19
-rw-r--r--src/lib/eolian/database_validate.c8
-rw-r--r--src/lib/eolian/database_var.c4
-rw-r--r--src/lib/eolian/eo_parser.c10
-rw-r--r--src/lib/eolian/eolian_database.c39
-rw-r--r--src/lib/eolian/eolian_database.h13
-rw-r--r--src/lib/eolian_cxx/grammar/klass_def.hpp4
11 files changed, 77 insertions, 73 deletions
diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h
index ad35d16..2f63366 100644
--- a/src/lib/eolian/Eolian.h
+++ b/src/lib/eolian/Eolian.h
@@ -1807,12 +1807,13 @@ EAPI const Eolian_Type *eolian_typedecl_base_type_get(const Eolian_Typedecl *tp)
1807 * If the given typedecl is an alias, it returns the result of 1807 * If the given typedecl is an alias, it returns the result of
1808 * eolian_type_aliased_base_get on its base type. Otherwise this returns NULL. 1808 * eolian_type_aliased_base_get on its base type. Otherwise this returns NULL.
1809 * 1809 *
1810 * @param[in] unit the unit to look in
1810 * @param[in] tp the type declaration. 1811 * @param[in] tp the type declaration.
1811 * @return the lowest alias base or the given type. 1812 * @return the lowest alias base or the given type.
1812 * 1813 *
1813 * @ingroup Eolian 1814 * @ingroup Eolian
1814 */ 1815 */
1815EAPI const Eolian_Type *eolian_typedecl_aliased_base_get(const Eolian_Typedecl *tp); 1816EAPI const Eolian_Type *eolian_typedecl_aliased_base_get(const Eolian_Unit *unit, const Eolian_Typedecl *tp);
1816 1817
1817/* 1818/*
1818 * @brief Check if a struct or alias type declaration is extern. 1819 * @brief Check if a struct or alias type declaration is extern.
@@ -1955,12 +1956,13 @@ EAPI const Eolian_Type *eolian_type_next_type_get(const Eolian_Type *tp);
1955 * 1956 *
1956 * This tries to look up alias, struct and enum in that order. 1957 * This tries to look up alias, struct and enum in that order.
1957 * 1958 *
1959 * @param[in] unit the unit to look in
1958 * @param[in] tp the type. 1960 * @param[in] tp the type.
1959 * @return the pointed to type decalration or NULL. 1961 * @return the pointed to type decalration or NULL.
1960 * 1962 *
1961 * @ingroup Eolian 1963 * @ingroup Eolian
1962 */ 1964 */
1963EAPI const Eolian_Typedecl *eolian_type_typedecl_get(const Eolian_Type *tp); 1965EAPI const Eolian_Typedecl *eolian_type_typedecl_get(const Eolian_Unit *unit, const Eolian_Type *tp);
1964 1966
1965/* 1967/*
1966 * @brief Get the lowest base type of an alias stack. 1968 * @brief Get the lowest base type of an alias stack.
@@ -1972,12 +1974,13 @@ EAPI const Eolian_Typedecl *eolian_type_typedecl_get(const Eolian_Type *tp);
1972 * type actually is while still having convenience. Keep in mind that this stops 1974 * type actually is while still having convenience. Keep in mind that this stops
1973 * if the found type is actually a pointer (has a ptr() on it). 1975 * if the found type is actually a pointer (has a ptr() on it).
1974 * 1976 *
1977 * @param[in] unit the unit to look in
1975 * @param[in] tp the type. 1978 * @param[in] tp the type.
1976 * @return the lowest alias base or the given type. 1979 * @return the lowest alias base or the given type.
1977 * 1980 *
1978 * @ingroup Eolian 1981 * @ingroup Eolian
1979 */ 1982 */
1980EAPI const Eolian_Type *eolian_type_aliased_base_get(const Eolian_Type *tp); 1983EAPI const Eolian_Type *eolian_type_aliased_base_get(const Eolian_Unit *unit, const Eolian_Type *tp);
1981 1984
1982/* 1985/*
1983 * @brief Get the class associated with an EOLIAN_TYPE_CLASS type. 1986 * @brief Get the class associated with an EOLIAN_TYPE_CLASS type.
@@ -2025,6 +2028,7 @@ EAPI Eina_Bool eolian_type_is_ptr(const Eolian_Type *tp);
2025/* 2028/*
2026 * @brief Get the full C type name of the given type. 2029 * @brief Get the full C type name of the given type.
2027 * 2030 *
2031 * @param[in] unit the unit to look in
2028 * @param[in] tp the type. 2032 * @param[in] tp the type.
2029 * @param[in] ctype the context within which the C type string will be used. 2033 * @param[in] ctype the context within which the C type string will be used.
2030 * @return The C type name assuming @c tp is not NULL. 2034 * @return The C type name assuming @c tp is not NULL.
@@ -2035,7 +2039,7 @@ EAPI Eina_Bool eolian_type_is_ptr(const Eolian_Type *tp);
2035 * 2039 *
2036 * @ingroup Eolian 2040 * @ingroup Eolian
2037 */ 2041 */
2038EAPI Eina_Stringshare *eolian_type_c_type_get(const Eolian_Type *tp, Eolian_C_Type_Type ctype); 2042EAPI Eina_Stringshare *eolian_type_c_type_get(const Eolian_Unit *unit, const Eolian_Type *tp, Eolian_C_Type_Type ctype);
2039 2043
2040/* 2044/*
2041 * @brief Get the name of the given type. For regular types, this is for 2045 * @brief Get the name of the given type. For regular types, this is for
diff --git a/src/lib/eolian/database_expr.c b/src/lib/eolian/database_expr.c
index 6a3b1d5..1b0a6d1 100644
--- a/src/lib/eolian/database_expr.c
+++ b/src/lib/eolian/database_expr.c
@@ -522,7 +522,7 @@ eval_exp(const Eolian_Unit *unit, const Eolian_Expression *expr,
522 const Eolian_Type *etp = eolian_typedecl_base_type_get(etpd); 522 const Eolian_Type *etp = eolian_typedecl_base_type_get(etpd);
523 if (!etp || etp->type != EOLIAN_TYPE_REGULAR) 523 if (!etp || etp->type != EOLIAN_TYPE_REGULAR)
524 break; 524 break;
525 etpd = eolian_type_typedecl_get(etp); 525 etpd = eolian_type_typedecl_get(unit, etp);
526 } 526 }
527 527
528 if (!etpd) etpd = eolian_typedecl_enum_get_by_name(unit, fulln); 528 if (!etpd) etpd = eolian_typedecl_enum_get_by_name(unit, fulln);
diff --git a/src/lib/eolian/database_expr_api.c b/src/lib/eolian/database_expr_api.c
index 9e8e1f6..adf5734 100644
--- a/src/lib/eolian/database_expr_api.c
+++ b/src/lib/eolian/database_expr_api.c
@@ -29,12 +29,12 @@ _eval_type(const Eolian_Unit *unit, const Eolian_Expression *expr,
29 return database_expr_eval(unit, expr, EOLIAN_MASK_NULL); 29 return database_expr_eval(unit, expr, EOLIAN_MASK_NULL);
30 case EOLIAN_TYPE_REGULAR: 30 case EOLIAN_TYPE_REGULAR:
31 { 31 {
32 if (database_type_is_ownable(type)) 32 if (database_type_is_ownable(unit, type))
33 return database_expr_eval(unit, expr, EOLIAN_MASK_NULL); 33 return database_expr_eval(unit, expr, EOLIAN_MASK_NULL);
34 int kw = eo_lexer_keyword_str_to_id(type->name); 34 int kw = eo_lexer_keyword_str_to_id(type->name);
35 if (!kw || kw < KW_byte || kw >= KW_void) 35 if (!kw || kw < KW_byte || kw >= KW_void)
36 { 36 {
37 const Eolian_Typedecl *base = eolian_type_typedecl_get(type); 37 const Eolian_Typedecl *base = eolian_type_typedecl_get(unit, type);
38 if (!base) 38 if (!base)
39 return err; 39 return err;
40 if (base->type == EOLIAN_TYPEDECL_ALIAS) 40 if (base->type == EOLIAN_TYPEDECL_ALIAS)
diff --git a/src/lib/eolian/database_type.c b/src/lib/eolian/database_type.c
index 5258709..1400aa0 100644
--- a/src/lib/eolian/database_type.c
+++ b/src/lib/eolian/database_type.c
@@ -47,7 +47,7 @@ database_type_add(Eolian *state, Eolian_Typedecl *def)
47 eina_hash_set(state->aliases_f, def->base.file, eina_list_append 47 eina_hash_set(state->aliases_f, def->base.file, eina_list_append
48 ((Eina_List*)eina_hash_find(state->aliases_f, def->base.file), 48 ((Eina_List*)eina_hash_find(state->aliases_f, def->base.file),
49 def)); 49 def));
50 database_decl_add(def->full_name, EOLIAN_DECL_ALIAS, def->base.file, def); 50 database_decl_add(state, def->full_name, EOLIAN_DECL_ALIAS, def->base.file, def);
51} 51}
52 52
53void 53void
@@ -56,7 +56,7 @@ database_struct_add(Eolian *state, Eolian_Typedecl *tp)
56 eina_hash_set(state->unit.structs, tp->full_name, tp); 56 eina_hash_set(state->unit.structs, tp->full_name, tp);
57 eina_hash_set(state->structs_f, tp->base.file, eina_list_append 57 eina_hash_set(state->structs_f, tp->base.file, eina_list_append
58 ((Eina_List*)eina_hash_find(state->structs_f, tp->base.file), tp)); 58 ((Eina_List*)eina_hash_find(state->structs_f, tp->base.file), tp));
59 database_decl_add(tp->full_name, EOLIAN_DECL_STRUCT, tp->base.file, tp); 59 database_decl_add(state, tp->full_name, EOLIAN_DECL_STRUCT, tp->base.file, tp);
60} 60}
61 61
62void 62void
@@ -65,11 +65,11 @@ database_enum_add(Eolian *state, Eolian_Typedecl *tp)
65 eina_hash_set(state->unit.enums, tp->full_name, tp); 65 eina_hash_set(state->unit.enums, tp->full_name, tp);
66 eina_hash_set(state->enums_f, tp->base.file, eina_list_append 66 eina_hash_set(state->enums_f, tp->base.file, eina_list_append
67 ((Eina_List*)eina_hash_find(state->enums_f, tp->base.file), tp)); 67 ((Eina_List*)eina_hash_find(state->enums_f, tp->base.file), tp));
68 database_decl_add(tp->full_name, EOLIAN_DECL_ENUM, tp->base.file, tp); 68 database_decl_add(state, tp->full_name, EOLIAN_DECL_ENUM, tp->base.file, tp);
69} 69}
70 70
71Eina_Bool 71Eina_Bool
72database_type_is_ownable(const Eolian_Type *tp) 72database_type_is_ownable(const Eolian_Unit *unit, const Eolian_Type *tp)
73{ 73{
74 if (tp->is_ptr) 74 if (tp->is_ptr)
75 return EINA_TRUE; 75 return EINA_TRUE;
@@ -79,13 +79,13 @@ database_type_is_ownable(const Eolian_Type *tp)
79 const char *ct = eo_lexer_get_c_type(kw); 79 const char *ct = eo_lexer_get_c_type(kw);
80 if (!ct) 80 if (!ct)
81 { 81 {
82 const Eolian_Typedecl *tpp = eolian_type_typedecl_get(tp); 82 const Eolian_Typedecl *tpp = eolian_type_typedecl_get(unit, tp);
83 if (!tpp) 83 if (!tpp)
84 return EINA_FALSE; 84 return EINA_FALSE;
85 if (tpp->type == EOLIAN_TYPEDECL_FUNCTION_POINTER) 85 if (tpp->type == EOLIAN_TYPEDECL_FUNCTION_POINTER)
86 return EINA_TRUE; 86 return EINA_TRUE;
87 if (tpp->type == EOLIAN_TYPEDECL_ALIAS) 87 if (tpp->type == EOLIAN_TYPEDECL_ALIAS)
88 return database_type_is_ownable(tpp->base_type); 88 return database_type_is_ownable(unit, tpp->base_type);
89 return EINA_FALSE; 89 return EINA_FALSE;
90 } 90 }
91 return (ct[strlen(ct) - 1] == '*'); 91 return (ct[strlen(ct) - 1] == '*');
@@ -103,14 +103,15 @@ _buf_add_suffix(Eina_Strbuf *buf, const char *suffix)
103} 103}
104 104
105void 105void
106database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, 106database_type_to_str(const Eolian_Unit *src, const Eolian_Type *tp,
107 Eina_Strbuf *buf, const char *name,
107 Eolian_C_Type_Type ctype) 108 Eolian_C_Type_Type ctype)
108{ 109{
109 if ((tp->type == EOLIAN_TYPE_REGULAR 110 if ((tp->type == EOLIAN_TYPE_REGULAR
110 || tp->type == EOLIAN_TYPE_CLASS 111 || tp->type == EOLIAN_TYPE_CLASS
111 || tp->type == EOLIAN_TYPE_VOID) 112 || tp->type == EOLIAN_TYPE_VOID)
112 && tp->is_const 113 && tp->is_const
113 && ((ctype != EOLIAN_C_TYPE_RETURN) || database_type_is_ownable(tp))) 114 && ((ctype != EOLIAN_C_TYPE_RETURN) || database_type_is_ownable(src, tp)))
114 { 115 {
115 eina_strbuf_append(buf, "const "); 116 eina_strbuf_append(buf, "const ");
116 } 117 }
@@ -137,7 +138,8 @@ database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name,
137 else 138 else
138 { 139 {
139 /* handles arrays and pointers as they all serialize to pointers */ 140 /* handles arrays and pointers as they all serialize to pointers */
140 database_type_to_str(tp->base_type, buf, NULL, EOLIAN_C_TYPE_DEFAULT); 141 database_type_to_str(src, tp->base_type, buf, NULL,
142 EOLIAN_C_TYPE_DEFAULT);
141 _buf_add_suffix(buf, "*"); 143 _buf_add_suffix(buf, "*");
142 if (tp->is_const && (ctype != EOLIAN_C_TYPE_RETURN)) 144 if (tp->is_const && (ctype != EOLIAN_C_TYPE_RETURN))
143 eina_strbuf_append(buf, " const"); 145 eina_strbuf_append(buf, " const");
@@ -150,7 +152,8 @@ database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name,
150} 152}
151 153
152static void 154static void
153_stype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf) 155_stype_to_str(const Eolian_Unit *src, const Eolian_Typedecl *tp,
156 Eina_Strbuf *buf)
154{ 157{
155 Eolian_Struct_Type_Field *sf; 158 Eolian_Struct_Type_Field *sf;
156 Eina_List *l; 159 Eina_List *l;
@@ -167,7 +170,8 @@ _stype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf)
167 eina_strbuf_append(buf, " { "); 170 eina_strbuf_append(buf, " { ");
168 EINA_LIST_FOREACH(tp->field_list, l, sf) 171 EINA_LIST_FOREACH(tp->field_list, l, sf)
169 { 172 {
170 database_type_to_str(sf->type, buf, sf->name, EOLIAN_C_TYPE_DEFAULT); 173 database_type_to_str(src, sf->type, buf, sf->name,
174 EOLIAN_C_TYPE_DEFAULT);
171 eina_strbuf_append(buf, "; "); 175 eina_strbuf_append(buf, "; ");
172 } 176 }
173 eina_strbuf_append(buf, "}"); 177 eina_strbuf_append(buf, "}");
@@ -222,7 +226,8 @@ _append_name(const Eolian_Typedecl *tp, Eina_Strbuf *buf)
222} 226}
223 227
224static void 228static void
225_atype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf) 229_atype_to_str(const Eolian_Unit *src, const Eolian_Typedecl *tp,
230 Eina_Strbuf *buf)
226{ 231{
227 eina_strbuf_append(buf, "typedef "); 232 eina_strbuf_append(buf, "typedef ");
228 233
@@ -239,7 +244,7 @@ _atype_to_str(const Eolian_Typedecl *tp, Eina_Strbuf *buf)
239 244
240 Eina_Strbuf *fulln = eina_strbuf_new(); 245 Eina_Strbuf *fulln = eina_strbuf_new();
241 _append_name(tp, fulln); 246 _append_name(tp, fulln);
242 database_type_to_str(tp->base_type, buf, eina_strbuf_string_get(fulln), 247 database_type_to_str(src, tp->base_type, buf, eina_strbuf_string_get(fulln),
243 EOLIAN_C_TYPE_DEFAULT); 248 EOLIAN_C_TYPE_DEFAULT);
244 eina_strbuf_free(fulln); 249 eina_strbuf_free(fulln);
245} 250}
@@ -251,14 +256,14 @@ database_typedecl_to_str(const Eolian_Unit *src, const Eolian_Typedecl *tp,
251 switch (tp->type) 256 switch (tp->type)
252 { 257 {
253 case EOLIAN_TYPEDECL_ALIAS: 258 case EOLIAN_TYPEDECL_ALIAS:
254 _atype_to_str(tp, buf); 259 _atype_to_str(src, tp, buf);
255 break; 260 break;
256 case EOLIAN_TYPEDECL_ENUM: 261 case EOLIAN_TYPEDECL_ENUM:
257 _etype_to_str(src, tp, buf); 262 _etype_to_str(src, tp, buf);
258 break; 263 break;
259 case EOLIAN_TYPEDECL_STRUCT: 264 case EOLIAN_TYPEDECL_STRUCT:
260 case EOLIAN_TYPEDECL_STRUCT_OPAQUE: 265 case EOLIAN_TYPEDECL_STRUCT_OPAQUE:
261 _stype_to_str(tp, buf); 266 _stype_to_str(src, tp, buf);
262 break; 267 break;
263 default: 268 default:
264 break; 269 break;
diff --git a/src/lib/eolian/database_type_api.c b/src/lib/eolian/database_type_api.c
index 5edaed9..d733a93 100644
--- a/src/lib/eolian/database_type_api.c
+++ b/src/lib/eolian/database_type_api.c
@@ -266,7 +266,7 @@ eolian_type_next_type_get(const Eolian_Type *tp)
266} 266}
267 267
268EAPI const Eolian_Typedecl * 268EAPI const Eolian_Typedecl *
269eolian_type_typedecl_get(const Eolian_Type *tp) 269eolian_type_typedecl_get(const Eolian_Unit *unit, const Eolian_Type *tp)
270{ 270{
271 EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL); 271 EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
272 if (eolian_type_type_get(tp) != EOLIAN_TYPE_REGULAR) 272 if (eolian_type_type_get(tp) != EOLIAN_TYPE_REGULAR)
@@ -277,7 +277,7 @@ eolian_type_typedecl_get(const Eolian_Type *tp)
277 int kw = eo_lexer_keyword_str_to_id(tp->full_name); 277 int kw = eo_lexer_keyword_str_to_id(tp->full_name);
278 if (!kw || kw < KW_byte || kw >= KW_true) 278 if (!kw || kw < KW_byte || kw >= KW_true)
279 { 279 {
280 Eolian_Declaration *decl = eina_hash_find(_decls, tp->full_name); 280 Eolian_Declaration *decl = eina_hash_find(unit->state->unit.decls, tp->full_name);
281 if (decl && decl->type != EOLIAN_DECL_CLASS 281 if (decl && decl->type != EOLIAN_DECL_CLASS
282 && decl->type != EOLIAN_DECL_VAR) 282 && decl->type != EOLIAN_DECL_VAR)
283 return decl->data; 283 return decl->data;
@@ -293,22 +293,22 @@ eolian_typedecl_base_type_get(const Eolian_Typedecl *tp)
293} 293}
294 294
295EAPI const Eolian_Type * 295EAPI const Eolian_Type *
296eolian_type_aliased_base_get(const Eolian_Type *tp) 296eolian_type_aliased_base_get(const Eolian_Unit *unit, const Eolian_Type *tp)
297{ 297{
298 if (!tp || tp->type != EOLIAN_TYPE_REGULAR || tp->is_ptr) 298 if (!tp || tp->type != EOLIAN_TYPE_REGULAR || tp->is_ptr)
299 return tp; 299 return tp;
300 const Eolian_Typedecl *btp = eolian_type_typedecl_get(tp); 300 const Eolian_Typedecl *btp = eolian_type_typedecl_get(unit, tp);
301 if (btp && (btp->type == EOLIAN_TYPEDECL_ALIAS)) 301 if (btp && (btp->type == EOLIAN_TYPEDECL_ALIAS))
302 return eolian_typedecl_aliased_base_get(btp); 302 return eolian_typedecl_aliased_base_get(unit, btp);
303 return tp; 303 return tp;
304} 304}
305 305
306EAPI const Eolian_Type * 306EAPI const Eolian_Type *
307eolian_typedecl_aliased_base_get(const Eolian_Typedecl *tp) 307eolian_typedecl_aliased_base_get(const Eolian_Unit *unit, const Eolian_Typedecl *tp)
308{ 308{
309 if (!tp || tp->type != EOLIAN_TYPEDECL_ALIAS) 309 if (!tp || tp->type != EOLIAN_TYPEDECL_ALIAS)
310 return NULL; 310 return NULL;
311 return eolian_type_aliased_base_get(tp->base_type); 311 return eolian_type_aliased_base_get(unit, tp->base_type);
312} 312}
313 313
314EAPI const Eolian_Class * 314EAPI const Eolian_Class *
@@ -349,13 +349,14 @@ eolian_typedecl_is_extern(const Eolian_Typedecl *tp)
349} 349}
350 350
351EAPI Eina_Stringshare * 351EAPI Eina_Stringshare *
352eolian_type_c_type_get(const Eolian_Type *tp, Eolian_C_Type_Type ctype) 352eolian_type_c_type_get(const Eolian_Unit *unit, const Eolian_Type *tp,
353 Eolian_C_Type_Type ctype)
353{ 354{
354 Eina_Stringshare *ret; 355 Eina_Stringshare *ret;
355 Eina_Strbuf *buf; 356 Eina_Strbuf *buf;
356 EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL); 357 EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
357 buf = eina_strbuf_new(); 358 buf = eina_strbuf_new();
358 database_type_to_str(tp, buf, NULL, ctype); 359 database_type_to_str(unit, tp, buf, NULL, ctype);
359 ret = eina_stringshare_add(eina_strbuf_string_get(buf)); 360 ret = eina_stringshare_add(eina_strbuf_string_get(buf));
360 eina_strbuf_free(buf); 361 eina_strbuf_free(buf);
361 return ret; 362 return ret;
diff --git a/src/lib/eolian/database_validate.c b/src/lib/eolian/database_validate.c
index e4cf4ca..6706464 100644
--- a/src/lib/eolian/database_validate.c
+++ b/src/lib/eolian/database_validate.c
@@ -173,7 +173,7 @@ _validate_type(const Eolian_Unit *src, Eolian_Type *tp)
173{ 173{
174 char buf[256]; 174 char buf[256];
175 175
176 if (tp->owned && !database_type_is_ownable(tp)) 176 if (tp->owned && !database_type_is_ownable(src, tp))
177 { 177 {
178 snprintf(buf, sizeof(buf), "type '%s' is not ownable", tp->full_name); 178 snprintf(buf, sizeof(buf), "type '%s' is not ownable", tp->full_name);
179 return _obj_error(&tp->base, buf); 179 return _obj_error(&tp->base, buf);
@@ -182,7 +182,7 @@ _validate_type(const Eolian_Unit *src, Eolian_Type *tp)
182 if (tp->is_ptr && !tp->legacy) 182 if (tp->is_ptr && !tp->legacy)
183 { 183 {
184 tp->is_ptr = EINA_FALSE; 184 tp->is_ptr = EINA_FALSE;
185 Eina_Bool still_ownable = database_type_is_ownable(tp); 185 Eina_Bool still_ownable = database_type_is_ownable(src, tp);
186 tp->is_ptr = EINA_TRUE; 186 tp->is_ptr = EINA_TRUE;
187 if (still_ownable) 187 if (still_ownable)
188 { 188 {
@@ -213,7 +213,7 @@ _validate_type(const Eolian_Unit *src, Eolian_Type *tp)
213 return EINA_FALSE; 213 return EINA_FALSE;
214 if ((kwid >= KW_accessor) && (kwid <= KW_list)) 214 if ((kwid >= KW_accessor) && (kwid <= KW_list))
215 { 215 {
216 if (!database_type_is_ownable(itp)) 216 if (!database_type_is_ownable(src, itp))
217 { 217 {
218 snprintf(buf, sizeof(buf), 218 snprintf(buf, sizeof(buf),
219 "%s cannot contain value types (%s)", 219 "%s cannot contain value types (%s)",
@@ -253,7 +253,7 @@ _validate_type(const Eolian_Unit *src, Eolian_Type *tp)
253 return _validate(&tp->base); 253 return _validate(&tp->base);
254 } 254 }
255 /* user defined */ 255 /* user defined */
256 tpp = (Eolian_Typedecl *)eolian_type_typedecl_get(tp); 256 tpp = (Eolian_Typedecl *)eolian_type_typedecl_get(src, tp);
257 if (!tpp) 257 if (!tpp)
258 { 258 {
259 snprintf(buf, sizeof(buf), "undefined type %s", tp->full_name); 259 snprintf(buf, sizeof(buf), "undefined type %s", tp->full_name);
diff --git a/src/lib/eolian/database_var.c b/src/lib/eolian/database_var.c
index b14a99a..d0870c3 100644
--- a/src/lib/eolian/database_var.c
+++ b/src/lib/eolian/database_var.c
@@ -28,7 +28,7 @@ database_var_global_add(Eolian *state, Eolian_Variable *var)
28 eina_hash_set(state->unit.globals, var->full_name, var); 28 eina_hash_set(state->unit.globals, var->full_name, var);
29 eina_hash_set(state->globals_f, var->base.file, eina_list_append 29 eina_hash_set(state->globals_f, var->base.file, eina_list_append
30 ((Eina_List*)eina_hash_find(state->globals_f, var->base.file), var)); 30 ((Eina_List*)eina_hash_find(state->globals_f, var->base.file), var));
31 database_decl_add(var->full_name, EOLIAN_DECL_VAR, var->base.file, var); 31 database_decl_add(state, var->full_name, EOLIAN_DECL_VAR, var->base.file, var);
32} 32}
33 33
34static void 34static void
@@ -37,7 +37,7 @@ database_var_constant_add(Eolian *state, Eolian_Variable *var)
37 eina_hash_set(state->unit.constants, var->full_name, var); 37 eina_hash_set(state->unit.constants, var->full_name, var);
38 eina_hash_set(state->constants_f, var->base.file, eina_list_append 38 eina_hash_set(state->constants_f, var->base.file, eina_list_append
39 ((Eina_List*)eina_hash_find(state->constants_f, var->base.file), var)); 39 ((Eina_List*)eina_hash_find(state->constants_f, var->base.file), var));
40 database_decl_add(var->full_name, EOLIAN_DECL_VAR, var->base.file, var); 40 database_decl_add(state, var->full_name, EOLIAN_DECL_VAR, var->base.file, var);
41} 41}
42 42
43void 43void
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index 71e1d7e..b8e721a 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -866,7 +866,7 @@ parse_typedef(Eo_Lexer *ls)
866 parse_name(ls, buf); 866 parse_name(ls, buf);
867 _fill_name(eina_stringshare_add(eina_strbuf_string_get(buf)), 867 _fill_name(eina_stringshare_add(eina_strbuf_string_get(buf)),
868 &def->full_name, &def->name, &def->namespaces); 868 &def->full_name, &def->name, &def->namespaces);
869 decl = (Eolian_Declaration *)eina_hash_find(_decls, def->full_name); 869 decl = (Eolian_Declaration *)eina_hash_find(ls->state->unit.decls, def->full_name);
870 if (decl) 870 if (decl)
871 { 871 {
872 eo_lexer_context_restore(ls); 872 eo_lexer_context_restore(ls);
@@ -902,7 +902,7 @@ parse_variable(Eo_Lexer *ls, Eina_Bool global)
902 parse_name(ls, buf); 902 parse_name(ls, buf);
903 _fill_name(eina_stringshare_add(eina_strbuf_string_get(buf)), 903 _fill_name(eina_stringshare_add(eina_strbuf_string_get(buf)),
904 &def->full_name, &def->name, &def->namespaces); 904 &def->full_name, &def->name, &def->namespaces);
905 decl = (Eolian_Declaration *)eina_hash_find(_decls, def->full_name); 905 decl = (Eolian_Declaration *)eina_hash_find(ls->state->unit.decls, def->full_name);
906 if (decl) 906 if (decl)
907 { 907 {
908 eo_lexer_context_restore(ls); 908 eo_lexer_context_restore(ls);
@@ -2117,7 +2117,7 @@ parse_class(Eo_Lexer *ls, Eolian_Class_Type type)
2117 _fill_name(eina_stringshare_add(eina_strbuf_string_get(buf)), 2117 _fill_name(eina_stringshare_add(eina_strbuf_string_get(buf)),
2118 &ls->tmp.kls->full_name, &ls->tmp.kls->name, 2118 &ls->tmp.kls->full_name, &ls->tmp.kls->name,
2119 &ls->tmp.kls->namespaces); 2119 &ls->tmp.kls->namespaces);
2120 decl = (Eolian_Declaration *)eina_hash_find(_decls, ls->tmp.kls->full_name); 2120 decl = (Eolian_Declaration *)eina_hash_find(ls->state->unit.decls, ls->tmp.kls->full_name);
2121 if (decl) 2121 if (decl)
2122 { 2122 {
2123 eo_lexer_context_restore(ls); 2123 eo_lexer_context_restore(ls);
@@ -2233,7 +2233,7 @@ parse_unit(Eo_Lexer *ls, Eina_Bool eot)
2233 col = ls->column; 2233 col = ls->column;
2234 parse_name(ls, buf); 2234 parse_name(ls, buf);
2235 name = eina_stringshare_add(eina_strbuf_string_get(buf)); 2235 name = eina_stringshare_add(eina_strbuf_string_get(buf));
2236 decl = (Eolian_Declaration *)eina_hash_find(_decls, name); 2236 decl = (Eolian_Declaration *)eina_hash_find(ls->state->unit.decls, name);
2237 if (decl) 2237 if (decl)
2238 { 2238 {
2239 eina_stringshare_del(name); 2239 eina_stringshare_del(name);
@@ -2271,7 +2271,7 @@ parse_unit(Eo_Lexer *ls, Eina_Bool eot)
2271 } 2271 }
2272 return EINA_FALSE; 2272 return EINA_FALSE;
2273found_class: 2273found_class:
2274 database_decl_add(ls->tmp.kls->full_name, EOLIAN_DECL_CLASS, 2274 database_decl_add(ls->state, ls->tmp.kls->full_name, EOLIAN_DECL_CLASS,
2275 ls->tmp.kls->base.file, ls->tmp.kls); 2275 ls->tmp.kls->base.file, ls->tmp.kls);
2276 return EINA_TRUE; 2276 return EINA_TRUE;
2277} 2277}
diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c
index bf8f17f..fdba068 100644
--- a/src/lib/eolian/eolian_database.c
+++ b/src/lib/eolian/eolian_database.c
@@ -8,9 +8,6 @@
8#include "eolian_database.h" 8#include "eolian_database.h"
9#include "eolian_priv.h" 9#include "eolian_priv.h"
10 10
11Eina_Hash *_decls = NULL;
12Eina_Hash *_declsf = NULL;
13
14static int _database_init_count = 0; 11static int _database_init_count = 0;
15 12
16static void 13static void
@@ -23,8 +20,6 @@ int
23database_init() 20database_init()
24{ 21{
25 if (_database_init_count > 0) return ++_database_init_count; 22 if (_database_init_count > 0) return ++_database_init_count;
26 _decls = eina_hash_stringshared_new(free);
27 _declsf = eina_hash_stringshared_new(_hashlist_free);
28 return ++_database_init_count; 23 return ++_database_init_count;
29} 24}
30 25
@@ -38,52 +33,48 @@ database_shutdown()
38 } 33 }
39 _database_init_count--; 34 _database_init_count--;
40 35
41 if (_database_init_count == 0)
42 {
43 eina_hash_free(_decls ); _decls = NULL;
44 eina_hash_free(_declsf ); _declsf = NULL;
45 }
46 return _database_init_count; 36 return _database_init_count;
47} 37}
48 38
49void 39void
50database_decl_add(Eina_Stringshare *name, Eolian_Declaration_Type type, 40database_decl_add(Eolian *state, Eina_Stringshare *name,
41 Eolian_Declaration_Type type,
51 Eina_Stringshare *file, void *ptr) 42 Eina_Stringshare *file, void *ptr)
52{ 43{
53 Eolian_Declaration *decl = calloc(1, sizeof(Eolian_Declaration)); 44 Eolian_Declaration *decl = calloc(1, sizeof(Eolian_Declaration));
54 decl->type = type; 45 decl->type = type;
55 decl->name = name; 46 decl->name = name;
56 decl->data = ptr; 47 decl->data = ptr;
57 eina_hash_set(_decls, name, decl); 48 eina_hash_set(state->unit.decls, name, decl);
58 eina_hash_set(_declsf, file, eina_list_append 49 eina_hash_set(state->decls_f, file, eina_list_append
59 ((Eina_List*)eina_hash_find(_declsf, file), decl)); 50 ((Eina_List*)eina_hash_find(state->decls_f, file), decl));
60} 51}
61 52
62EAPI const Eolian_Declaration * 53EAPI const Eolian_Declaration *
63eolian_declaration_get_by_name(const Eolian_Unit *unit EINA_UNUSED, const char *name) 54eolian_declaration_get_by_name(const Eolian_Unit *unit, const char *name)
64{ 55{
65 if (!_decls) return NULL; 56 if (!unit) return NULL;
66 Eina_Stringshare *shr = eina_stringshare_add(name); 57 Eina_Stringshare *shr = eina_stringshare_add(name);
67 const Eolian_Declaration *decl = eina_hash_find(_decls, shr); 58 const Eolian_Declaration *decl = eina_hash_find(unit->state->unit.decls, shr);
68 eina_stringshare_del(shr); 59 eina_stringshare_del(shr);
69 return decl; 60 return decl;
70} 61}
71 62
72EAPI Eina_Iterator * 63EAPI Eina_Iterator *
73eolian_declarations_get_by_file(const Eolian *state EINA_UNUSED, const char *fname) 64eolian_declarations_get_by_file(const Eolian *state, const char *fname)
74{ 65{
75 if (!_declsf) return NULL; 66 if (!state) return NULL;
76 Eina_Stringshare *shr = eina_stringshare_add(fname); 67 Eina_Stringshare *shr = eina_stringshare_add(fname);
77 Eina_List *l = eina_hash_find(_declsf, shr); 68 Eina_List *l = eina_hash_find(state->decls_f, shr);
78 eina_stringshare_del(shr); 69 eina_stringshare_del(shr);
79 if (!l) return NULL; 70 if (!l) return NULL;
80 return eina_list_iterator_new(l); 71 return eina_list_iterator_new(l);
81} 72}
82 73
83EAPI Eina_Iterator * 74EAPI Eina_Iterator *
84eolian_all_declarations_get(const Eolian_Unit *unit EINA_UNUSED) 75eolian_all_declarations_get(const Eolian_Unit *unit)
85{ 76{
86 return (_decls ? eina_hash_iterator_data_new(_decls) : NULL); 77 return (unit ? eina_hash_iterator_data_new(unit->state->unit.decls) : NULL);
87} 78}
88 79
89EAPI Eolian_Declaration_Type 80EAPI Eolian_Declaration_Type
@@ -551,6 +542,7 @@ database_unit_init(Eolian *state, Eolian_Unit *unit)
551 unit->aliases = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del)); 542 unit->aliases = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del));
552 unit->structs = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del)); 543 unit->structs = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del));
553 unit->enums = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del)); 544 unit->enums = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del));
545 unit->decls = eina_hash_stringshared_new(free);
554} 546}
555 547
556void 548void
@@ -565,6 +557,7 @@ database_unit_del(Eolian_Unit *unit)
565 eina_hash_free(unit->aliases); 557 eina_hash_free(unit->aliases);
566 eina_hash_free(unit->structs); 558 eina_hash_free(unit->structs);
567 eina_hash_free(unit->enums); 559 eina_hash_free(unit->enums);
560 eina_hash_free(unit->decls);
568} 561}
569 562
570EAPI Eolian * 563EAPI Eolian *
@@ -591,6 +584,7 @@ eolian_new(void)
591 state->enums_f = eina_hash_stringshared_new(_hashlist_free); 584 state->enums_f = eina_hash_stringshared_new(_hashlist_free);
592 state->globals_f = eina_hash_stringshared_new(_hashlist_free); 585 state->globals_f = eina_hash_stringshared_new(_hashlist_free);
593 state->constants_f = eina_hash_stringshared_new(_hashlist_free); 586 state->constants_f = eina_hash_stringshared_new(_hashlist_free);
587 state->decls_f = eina_hash_stringshared_new(_hashlist_free);
594 588
595 return state; 589 return state;
596} 590}
@@ -618,6 +612,7 @@ eolian_free(Eolian *state)
618 eina_hash_free(state->enums_f); 612 eina_hash_free(state->enums_f);
619 eina_hash_free(state->globals_f); 613 eina_hash_free(state->globals_f);
620 eina_hash_free(state->constants_f); 614 eina_hash_free(state->constants_f);
615 eina_hash_free(state->decls_f);
621 616
622 free(state); 617 free(state);
623} 618}
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index b2e7290..edef41e 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -31,10 +31,6 @@ extern Eina_Prefix *_eolian_prefix;
31#endif 31#endif
32#define DBG(...) EINA_LOG_DOM_DBG(_eolian_log_dom, __VA_ARGS__) 32#define DBG(...) EINA_LOG_DOM_DBG(_eolian_log_dom, __VA_ARGS__)
33 33
34/* a hash holding all declarations, for redef checking etc */
35extern Eina_Hash *_decls;
36extern Eina_Hash *_declsf;
37
38struct _Eolian_Unit 34struct _Eolian_Unit
39{ 35{
40 Eolian *state; 36 Eolian *state;
@@ -45,6 +41,7 @@ struct _Eolian_Unit
45 Eina_Hash *aliases; 41 Eina_Hash *aliases;
46 Eina_Hash *structs; 42 Eina_Hash *structs;
47 Eina_Hash *enums; 43 Eina_Hash *enums;
44 Eina_Hash *decls;
48}; 45};
49 46
50struct _Eolian 47struct _Eolian
@@ -66,6 +63,7 @@ struct _Eolian
66 Eina_Hash *enums_f; 63 Eina_Hash *enums_f;
67 Eina_Hash *globals_f; 64 Eina_Hash *globals_f;
68 Eina_Hash *constants_f; 65 Eina_Hash *constants_f;
66 Eina_Hash *decls_f;
69}; 67};
70 68
71typedef struct _Eolian_Object 69typedef struct _Eolian_Object
@@ -322,7 +320,8 @@ int database_shutdown(void);
322char *database_class_to_filename(const char *cname); 320char *database_class_to_filename(const char *cname);
323Eina_Bool database_validate(Eolian *state, const Eolian_Unit *src); 321Eina_Bool database_validate(Eolian *state, const Eolian_Unit *src);
324 322
325void database_decl_add(Eina_Stringshare *name, Eolian_Declaration_Type type, 323void database_decl_add(Eolian *state, Eina_Stringshare *name,
324 Eolian_Declaration_Type type,
326 Eina_Stringshare *file, void *ptr); 325 Eina_Stringshare *file, void *ptr);
327 326
328void database_doc_del(Eolian_Documentation *doc); 327void database_doc_del(Eolian_Documentation *doc);
@@ -338,10 +337,10 @@ void database_enum_add(Eolian *state, Eolian_Typedecl *tp);
338void database_type_del(Eolian_Type *tp); 337void database_type_del(Eolian_Type *tp);
339void database_typedecl_del(Eolian_Typedecl *tp); 338void database_typedecl_del(Eolian_Typedecl *tp);
340 339
341void database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, Eolian_C_Type_Type ctype); 340void database_type_to_str(const Eolian_Unit *src, const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, Eolian_C_Type_Type ctype);
342void database_typedecl_to_str(const Eolian_Unit *src, const Eolian_Typedecl *tp, Eina_Strbuf *buf); 341void database_typedecl_to_str(const Eolian_Unit *src, const Eolian_Typedecl *tp, Eina_Strbuf *buf);
343 342
344Eina_Bool database_type_is_ownable(const Eolian_Type *tp); 343Eina_Bool database_type_is_ownable(const Eolian_Unit *unit, const Eolian_Type *tp);
345 344
346/* expressions */ 345/* expressions */
347 346
diff --git a/src/lib/eolian_cxx/grammar/klass_def.hpp b/src/lib/eolian_cxx/grammar/klass_def.hpp
index e7a32ad..d1fce8f 100644
--- a/src/lib/eolian_cxx/grammar/klass_def.hpp
+++ b/src/lib/eolian_cxx/grammar/klass_def.hpp
@@ -259,7 +259,7 @@ type_def const void_ {attributes::regular_type_def{"void", {qualifier_info::is_n
259 259
260inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* unit, Eolian_C_Type_Type ctype) 260inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* unit, Eolian_C_Type_Type ctype)
261{ 261{
262 c_type = ::eolian_type_c_type_get(eolian_type, ctype); 262 c_type = ::eolian_type_c_type_get(unit, eolian_type, ctype);
263 // ::eina_stringshare_del(stringshare); // this crashes 263 // ::eina_stringshare_del(stringshare); // this crashes
264 Eolian_Type const* stp = eolian_type_base_type_get(eolian_type); 264 Eolian_Type const* stp = eolian_type_base_type_get(eolian_type);
265 has_own = !!::eolian_type_is_owned(eolian_type); 265 has_own = !!::eolian_type_is_owned(eolian_type);
@@ -273,7 +273,7 @@ inline void type_def::set(Eolian_Type const* eolian_type, Eolian_Unit const* uni
273 if (!stp) 273 if (!stp)
274 { 274 {
275 bool is_undefined = false; 275 bool is_undefined = false;
276 Eolian_Typedecl const* decl = eolian_type_typedecl_get(eolian_type); 276 Eolian_Typedecl const* decl = eolian_type_typedecl_get(unit, eolian_type);
277 bool is_function_ptr = decl && eolian_typedecl_type_get(decl) == EOLIAN_TYPEDECL_FUNCTION_POINTER; 277 bool is_function_ptr = decl && eolian_typedecl_type_get(decl) == EOLIAN_TYPEDECL_FUNCTION_POINTER;
278 if(decl && eolian_typedecl_type_get(decl) == EOLIAN_TYPEDECL_ALIAS) 278 if(decl && eolian_typedecl_type_get(decl) == EOLIAN_TYPEDECL_ALIAS)
279 { 279 {