diff options
Diffstat (limited to 'src/lib/eolian/database_type.c')
-rw-r--r-- | src/lib/eolian/database_type.c | 35 |
1 files changed, 20 insertions, 15 deletions
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 | ||
53 | void | 53 | void |
@@ -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 | ||
62 | void | 62 | void |
@@ -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 | ||
71 | Eina_Bool | 71 | Eina_Bool |
72 | database_type_is_ownable(const Eolian_Type *tp) | 72 | database_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 | ||
105 | void | 105 | void |
106 | database_type_to_str(const Eolian_Type *tp, Eina_Strbuf *buf, const char *name, | 106 | database_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 | ||
152 | static void | 154 | static 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 | ||
224 | static void | 228 | static 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; |