summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2018-03-08 23:59:40 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2018-03-08 23:59:40 +0100
commit7a4669b1b776652c76a1c629446819890962ac1b (patch)
tree62c3cae01036c21780a52fcf8d4c9a527af214e9 /src
parentb6fa5aa844c5be37b344ebaab0a01b60a971afb3 (diff)
eolian: remove old declaration APIs
Diffstat (limited to 'src')
-rw-r--r--src/lib/eolian/Eolian.h110
-rw-r--r--src/lib/eolian/database_type.c13
-rw-r--r--src/lib/eolian/database_var.c5
-rw-r--r--src/lib/eolian/eo_parser.c79
-rw-r--r--src/lib/eolian/eolian_database.c151
-rw-r--r--src/lib/eolian/eolian_database.h13
6 files changed, 98 insertions, 273 deletions
diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h
index d5ba7e0..4c460fa 100644
--- a/src/lib/eolian/Eolian.h
+++ b/src/lib/eolian/Eolian.h
@@ -179,12 +179,6 @@ typedef struct _Eolian_Struct_Type_Field Eolian_Struct_Type_Field;
179 */ 179 */
180typedef struct _Eolian_Enum_Type_Field Eolian_Enum_Type_Field; 180typedef struct _Eolian_Enum_Type_Field Eolian_Enum_Type_Field;
181 181
182/* Declaration information
183 *
184 * @ingroup Eolian
185 */
186typedef struct _Eolian_Declaration Eolian_Declaration;
187
188/* Documentation information 182/* Documentation information
189 * 183 *
190 * @ingroup Eolian 184 * @ingroup Eolian
@@ -213,8 +207,7 @@ typedef enum
213 EOLIAN_OBJECT_PART, 207 EOLIAN_OBJECT_PART,
214 EOLIAN_OBJECT_IMPLEMENT, 208 EOLIAN_OBJECT_IMPLEMENT,
215 EOLIAN_OBJECT_CONSTRUCTOR, 209 EOLIAN_OBJECT_CONSTRUCTOR,
216 EOLIAN_OBJECT_DOCUMENTATION, 210 EOLIAN_OBJECT_DOCUMENTATION
217 EOLIAN_OBJECT_DECLARATION
218} Eolian_Object_Type; 211} Eolian_Object_Type;
219 212
220typedef enum 213typedef enum
@@ -446,16 +439,6 @@ typedef enum
446 439
447typedef enum 440typedef enum
448{ 441{
449 EOLIAN_DECL_UNKNOWN = 0,
450 EOLIAN_DECL_CLASS,
451 EOLIAN_DECL_ALIAS,
452 EOLIAN_DECL_STRUCT,
453 EOLIAN_DECL_ENUM,
454 EOLIAN_DECL_VAR
455} Eolian_Declaration_Type;
456
457typedef enum
458{
459 EOLIAN_DOC_TOKEN_UNKNOWN = 0, 442 EOLIAN_DOC_TOKEN_UNKNOWN = 0,
460 EOLIAN_DOC_TOKEN_TEXT, 443 EOLIAN_DOC_TOKEN_TEXT,
461 EOLIAN_DOC_TOKEN_REF, 444 EOLIAN_DOC_TOKEN_REF,
@@ -2690,97 +2673,6 @@ EAPI Eina_Iterator *eolian_variable_namespaces_get(const Eolian_Variable *var);
2690EAPI Eina_Bool eolian_variable_is_extern(const Eolian_Variable *var); 2673EAPI Eina_Bool eolian_variable_is_extern(const Eolian_Variable *var);
2691 2674
2692/* 2675/*
2693 * @brief Get a declaration by name.
2694 *
2695 * @param[in] unit the unit to look in
2696 * @param[in] name the declaration name.
2697 * @return the declaration.
2698 *
2699 * @ingroup Eolian
2700 */
2701EAPI const Eolian_Declaration *eolian_declaration_get_by_name(const Eolian_Unit *unit, const char *name);
2702
2703/*
2704 * @brief Get a list of declarations in a file.
2705 *
2706 * This function gets an iterator to a list of declarations in a particular
2707 * file. Declarations are either a class, a type alias, a struct, an enum
2708 * or a variable. This way you can get them all in the original order they
2709 * were declared in, which is useful during generation.
2710 *
2711 * @param[in] state the state to look in
2712 * @param[in] fname the filename.
2713 * @return the iterator or NULL.
2714 *
2715 * @ingroup Eolian
2716 */
2717EAPI Eina_Iterator *eolian_declarations_get_by_file(const Eolian_State *state, const char *fname);
2718
2719/*
2720 * @brief Get an iterator to all declarations in the Eolian database.
2721 *
2722 * @param[in] unit the unit to look in
2723 * @return the iterator or NULL.
2724 *
2725 * Thanks to internal caching this is an O(1) operation.
2726 *
2727 * @ingroup Eolian
2728 */
2729EAPI Eina_Iterator *eolian_all_declarations_get(const Eolian_Unit *unit);
2730
2731/*
2732 * @brief Get the type of a declaration
2733 *
2734 * @param[in] decl the declaration
2735 * @return the declaration type
2736 *
2737 * @ingroup Eolian
2738 */
2739EAPI Eolian_Declaration_Type eolian_declaration_type_get(const Eolian_Declaration *decl);
2740
2741/*
2742 * @brief Get the name of a declaration
2743 *
2744 * This matches the full namespaced name of the data it's holding.
2745 *
2746 * @param[in] decl the declaration
2747 * @return the declaration name
2748 *
2749 * @ingroup Eolian
2750 */
2751EAPI Eina_Stringshare *eolian_declaration_name_get(const Eolian_Declaration *decl);
2752
2753/*
2754 * @brief Get the class of a class declaration.
2755 *
2756 * @param[in] decl the declaration
2757 * @return the class
2758 *
2759 * @ingroup Eolian
2760 */
2761EAPI const Eolian_Class *eolian_declaration_class_get(const Eolian_Declaration *decl);
2762
2763/*
2764 * @brief Get the type of a type (alias, struct, enum) declaration.
2765 *
2766 * @param[in] decl the declaration
2767 * @return the type
2768 *
2769 * @ingroup Eolian
2770 */
2771EAPI const Eolian_Typedecl *eolian_declaration_data_type_get(const Eolian_Declaration *decl);
2772
2773/*
2774 * @brief Get the variable of a variable (constant, global) declaration.
2775 *
2776 * @param[in] decl the declaration
2777 * @return the class
2778 *
2779 * @ingroup Eolian
2780 */
2781EAPI const Eolian_Variable *eolian_declaration_variable_get(const Eolian_Declaration *decl);
2782
2783/*
2784 * @brief Get the summary of the documentation. 2676 * @brief Get the summary of the documentation.
2785 * 2677 *
2786 * This should never return NULL unless the input is invalid. 2678 * This should never return NULL unless the input is invalid.
diff --git a/src/lib/eolian/database_type.c b/src/lib/eolian/database_type.c
index b89cb0d..bdceda7 100644
--- a/src/lib/eolian/database_type.c
+++ b/src/lib/eolian/database_type.c
@@ -47,7 +47,7 @@ database_type_add(Eolian_Unit *unit, Eolian_Typedecl *tp)
47 eina_hash_set(unit->state->aliases_f, tp->base.file, eina_list_append 47 eina_hash_set(unit->state->aliases_f, tp->base.file, eina_list_append
48 ((Eina_List*)eina_hash_find(unit->state->aliases_f, tp->base.file), 48 ((Eina_List*)eina_hash_find(unit->state->aliases_f, tp->base.file),
49 tp)); 49 tp));
50 database_decl_add(unit, tp->base.name, EOLIAN_DECL_ALIAS, tp->base.file, tp); 50 database_object_add(unit, &tp->base);
51} 51}
52 52
53void 53void
@@ -56,7 +56,7 @@ database_struct_add(Eolian_Unit *unit, Eolian_Typedecl *tp)
56 EOLIAN_OBJECT_ADD(unit, tp->base.name, tp, structs); 56 EOLIAN_OBJECT_ADD(unit, tp->base.name, tp, structs);
57 eina_hash_set(unit->state->structs_f, tp->base.file, eina_list_append 57 eina_hash_set(unit->state->structs_f, tp->base.file, eina_list_append
58 ((Eina_List*)eina_hash_find(unit->state->structs_f, tp->base.file), tp)); 58 ((Eina_List*)eina_hash_find(unit->state->structs_f, tp->base.file), tp));
59 database_decl_add(unit, tp->base.name, EOLIAN_DECL_STRUCT, tp->base.file, tp); 59 database_object_add(unit, &tp->base);
60} 60}
61 61
62void 62void
@@ -65,7 +65,7 @@ database_enum_add(Eolian_Unit *unit, Eolian_Typedecl *tp)
65 EOLIAN_OBJECT_ADD(unit, tp->base.name, tp, enums); 65 EOLIAN_OBJECT_ADD(unit, tp->base.name, tp, enums);
66 eina_hash_set(unit->state->enums_f, tp->base.file, eina_list_append 66 eina_hash_set(unit->state->enums_f, tp->base.file, eina_list_append
67 ((Eina_List*)eina_hash_find(unit->state->enums_f, tp->base.file), tp)); 67 ((Eina_List*)eina_hash_find(unit->state->enums_f, tp->base.file), tp));
68 database_decl_add(unit, tp->base.name, EOLIAN_DECL_ENUM, tp->base.file, tp); 68 database_object_add(unit, &tp->base);
69} 69}
70 70
71Eina_Bool 71Eina_Bool
@@ -278,10 +278,9 @@ Eolian_Typedecl *database_type_decl_find(const Eolian_Unit *unit, const Eolian_T
278 int kw = eo_lexer_keyword_str_to_id(tp->base.name); 278 int kw = eo_lexer_keyword_str_to_id(tp->base.name);
279 if (!kw || kw < KW_byte || kw >= KW_true) 279 if (!kw || kw < KW_byte || kw >= KW_true)
280 { 280 {
281 Eolian_Declaration *decl = eina_hash_find(unit->decls, tp->base.name); 281 Eolian_Object *decl = eina_hash_find(unit->objects, tp->base.name);
282 if (decl && decl->type != EOLIAN_DECL_CLASS 282 if (decl && decl->type == EOLIAN_OBJECT_TYPEDECL)
283 && decl->type != EOLIAN_DECL_VAR) 283 return (Eolian_Typedecl *)decl;
284 return decl->data;
285 } 284 }
286 return NULL; 285 return NULL;
287} 286}
diff --git a/src/lib/eolian/database_var.c b/src/lib/eolian/database_var.c
index 36d22b3..796a5ec 100644
--- a/src/lib/eolian/database_var.c
+++ b/src/lib/eolian/database_var.c
@@ -28,16 +28,14 @@ database_var_global_add(Eolian_Unit *unit, Eolian_Variable *var)
28 EOLIAN_OBJECT_ADD(unit, var->base.name, var, globals); 28 EOLIAN_OBJECT_ADD(unit, var->base.name, var, globals);
29 eina_hash_set(unit->state->globals_f, var->base.file, eina_list_append 29 eina_hash_set(unit->state->globals_f, var->base.file, eina_list_append
30 ((Eina_List*)eina_hash_find(unit->state->globals_f, var->base.file), var)); 30 ((Eina_List*)eina_hash_find(unit->state->globals_f, var->base.file), var));
31 database_decl_add(unit, var->base.name, EOLIAN_DECL_VAR, var->base.file, var);
32} 31}
33 32
34static void 33static void
35database_var_constant_add(Eolian_Unit *unit, Eolian_Variable *var) 34database_var_constant_add(Eolian_Unit *unit, Eolian_Variable *var)
36{ 35{
37 EOLIAN_OBJECT_ADD(unit, var->base.name, var, constants); 36 EOLIAN_OBJECT_ADD(unit, var->base.name, var, constants);
38 eina_hash_set(unit->state->constants_f, var->base.file, eina_list_append 37 eina_hash_set(unit->state->constants_f, var->base.file, eina_list_append
39 ((Eina_List*)eina_hash_find(unit->state->constants_f, var->base.file), var)); 38 ((Eina_List*)eina_hash_find(unit->state->constants_f, var->base.file), var));
40 database_decl_add(unit, var->base.name, EOLIAN_DECL_VAR, var->base.file, var);
41} 39}
42 40
43void 41void
@@ -47,4 +45,5 @@ database_var_add(Eolian_Unit *unit, Eolian_Variable *var)
47 database_var_global_add(unit, var); 45 database_var_global_add(unit, var);
48 else 46 else
49 database_var_constant_add(unit, var); 47 database_var_constant_add(unit, var);
48 database_object_add(unit, &var->base);
50} 49}
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index 89a5ccd..ad592fa 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -161,26 +161,63 @@ compare_class_file(const char *fn1, const char *fn2)
161 return !strcmp(fn1, fn2); 161 return !strcmp(fn1, fn2);
162} 162}
163 163
164static const char *declnames[] = { 164
165 "class", "type alias", "struct", "enum", "variable" 165static Eolian_Object *
166}; 166_eolian_decl_get(Eo_Lexer *ls, const char *name)
167{
168 Eolian_Object *obj = eina_hash_find(ls->state->unit.objects, name);
169 if (obj && ((obj->type == EOLIAN_OBJECT_CLASS) ||
170 (obj->type == EOLIAN_OBJECT_TYPEDECL) ||
171 (obj->type == EOLIAN_OBJECT_VARIABLE)))
172 return obj;
173
174 return NULL;
175}
176
177static const char *
178_eolian_decl_name_get(Eolian_Object *obj)
179{
180 switch (obj->type)
181 {
182 case EOLIAN_OBJECT_CLASS:
183 return "class";
184 case EOLIAN_OBJECT_TYPEDECL:
185 switch (((Eolian_Typedecl *)obj)->type)
186 {
187 case EOLIAN_TYPEDECL_ALIAS:
188 return "type alias";
189 case EOLIAN_TYPEDECL_STRUCT:
190 case EOLIAN_TYPEDECL_STRUCT_OPAQUE:
191 return "struct";
192 case EOLIAN_TYPEDECL_ENUM:
193 return "enum";
194 default:
195 break;
196 }
197 case EOLIAN_OBJECT_VARIABLE:
198 return "variable";
199 default:
200 break;
201 }
202 return "unknown";
203}
167 204
168static void 205static void
169redef_error(Eo_Lexer *ls, Eolian_Declaration *decl, Eolian_Declaration_Type newt) 206redef_error(Eo_Lexer *ls, Eolian_Object *obj, Eolian_Object *nobj)
170{ 207{
171 Eolian_Object *obj = (Eolian_Object *)decl->data;
172 char buf[256], fbuf[256] = { '\0' }; 208 char buf[256], fbuf[256] = { '\0' };
173 if (ls->filename != obj->file) 209 if (ls->filename != obj->file)
174 snprintf(fbuf, sizeof(fbuf), "%s:%d:%d", obj->file, obj->line, obj->column); 210 snprintf(fbuf, sizeof(fbuf), "%s:%d:%d", obj->file, obj->line, obj->column);
175 else 211 else
176 snprintf(fbuf, sizeof(fbuf), "%d:%d", obj->line, obj->column); 212 snprintf(fbuf, sizeof(fbuf), "%d:%d", obj->line, obj->column);
177 213
178 if (newt != decl->type) 214 if (nobj->type != obj->type)
179 snprintf(buf, sizeof(buf), "%s '%s' redefined as %s (originally at %s)", 215 snprintf(buf, sizeof(buf), "%s '%s' redefined as %s (originally at %s)",
180 declnames[decl->type], decl->base.name, declnames[newt], fbuf); 216 _eolian_decl_name_get(obj), obj->name,
217 _eolian_decl_name_get(nobj), fbuf);
181 else 218 else
182 snprintf(buf, sizeof(buf), "%s '%s' redefined (originally at %s)", 219 snprintf(buf, sizeof(buf), "%s '%s' redefined (originally at %s)",
183 declnames[decl->type], decl->base.name, fbuf); 220 _eolian_decl_name_get(obj), obj->name, fbuf);
184 221
185 eo_lexer_syntax_error(ls, buf); 222 eo_lexer_syntax_error(ls, buf);
186} 223}
@@ -832,7 +869,6 @@ parse_type_void(Eo_Lexer *ls)
832static Eolian_Typedecl * 869static Eolian_Typedecl *
833parse_typedef(Eo_Lexer *ls) 870parse_typedef(Eo_Lexer *ls)
834{ 871{
835 Eolian_Declaration *decl;
836 Eolian_Typedecl *def = push_typedecl(ls); 872 Eolian_Typedecl *def = push_typedecl(ls);
837 Eina_Bool has_extern; 873 Eina_Bool has_extern;
838 const char *freefunc; 874 const char *freefunc;
@@ -849,11 +885,11 @@ parse_typedef(Eo_Lexer *ls)
849 parse_name(ls, buf); 885 parse_name(ls, buf);
850 _fill_name(eina_stringshare_add(eina_strbuf_string_get(buf)), 886 _fill_name(eina_stringshare_add(eina_strbuf_string_get(buf)),
851 &def->base.name, &def->name, &def->namespaces); 887 &def->base.name, &def->name, &def->namespaces);
852 decl = (Eolian_Declaration *)eina_hash_find(ls->state->unit.decls, def->base.name); 888 Eolian_Object *decl = _eolian_decl_get(ls, def->base.name);
853 if (decl) 889 if (decl)
854 { 890 {
855 eo_lexer_context_restore(ls); 891 eo_lexer_context_restore(ls);
856 redef_error(ls, decl, EOLIAN_DECL_ALIAS); 892 redef_error(ls, decl, &def->base);
857 } 893 }
858 eo_lexer_context_pop(ls); 894 eo_lexer_context_pop(ls);
859 check_next(ls, ':'); 895 check_next(ls, ':');
@@ -868,7 +904,6 @@ parse_typedef(Eo_Lexer *ls)
868static Eolian_Variable * 904static Eolian_Variable *
869parse_variable(Eo_Lexer *ls, Eina_Bool global) 905parse_variable(Eo_Lexer *ls, Eina_Bool global)
870{ 906{
871 Eolian_Declaration *decl;
872 Eolian_Variable *def = calloc(1, sizeof(Eolian_Variable)); 907 Eolian_Variable *def = calloc(1, sizeof(Eolian_Variable));
873 Eina_Strbuf *buf; 908 Eina_Strbuf *buf;
874 ls->tmp.var = def; 909 ls->tmp.var = def;
@@ -885,11 +920,11 @@ parse_variable(Eo_Lexer *ls, Eina_Bool global)
885 parse_name(ls, buf); 920 parse_name(ls, buf);
886 _fill_name(eina_stringshare_add(eina_strbuf_string_get(buf)), 921 _fill_name(eina_stringshare_add(eina_strbuf_string_get(buf)),
887 &def->base.name, &def->name, &def->namespaces); 922 &def->base.name, &def->name, &def->namespaces);
888 decl = (Eolian_Declaration *)eina_hash_find(ls->state->unit.decls, def->base.name); 923 Eolian_Object *decl = _eolian_decl_get(ls, def->base.name);
889 if (decl) 924 if (decl)
890 { 925 {
891 eo_lexer_context_restore(ls); 926 eo_lexer_context_restore(ls);
892 redef_error(ls, decl, EOLIAN_DECL_VAR); 927 redef_error(ls, decl, &def->base);
893 } 928 }
894 eo_lexer_context_pop(ls); 929 eo_lexer_context_pop(ls);
895 check_next(ls, ':'); 930 check_next(ls, ':');
@@ -2048,7 +2083,6 @@ _inherit_dep(Eo_Lexer *ls, Eina_Strbuf *buf)
2048static void 2083static void
2049parse_class(Eo_Lexer *ls, Eolian_Class_Type type) 2084parse_class(Eo_Lexer *ls, Eolian_Class_Type type)
2050{ 2085{
2051 Eolian_Declaration *decl;
2052 const char *bnm; 2086 const char *bnm;
2053 char *fnm; 2087 char *fnm;
2054 Eina_Bool same; 2088 Eina_Bool same;
@@ -2073,11 +2107,11 @@ parse_class(Eo_Lexer *ls, Eolian_Class_Type type)
2073 _fill_name(eina_stringshare_add(eina_strbuf_string_get(buf)), 2107 _fill_name(eina_stringshare_add(eina_strbuf_string_get(buf)),
2074 &ls->tmp.kls->base.name, &ls->tmp.kls->name, 2108 &ls->tmp.kls->base.name, &ls->tmp.kls->name,
2075 &ls->tmp.kls->namespaces); 2109 &ls->tmp.kls->namespaces);
2076 decl = (Eolian_Declaration *)eina_hash_find(ls->state->unit.decls, ls->tmp.kls->base.name); 2110 Eolian_Object *decl = _eolian_decl_get(ls, ls->tmp.kls->base.name);
2077 if (decl) 2111 if (decl)
2078 { 2112 {
2079 eo_lexer_context_restore(ls); 2113 eo_lexer_context_restore(ls);
2080 redef_error(ls, decl, EOLIAN_DECL_CLASS); 2114 redef_error(ls, decl, &ls->tmp.kls->base);
2081 } 2115 }
2082 eo_lexer_context_pop(ls); 2116 eo_lexer_context_pop(ls);
2083 pop_strbuf(ls); 2117 pop_strbuf(ls);
@@ -2177,7 +2211,6 @@ parse_unit(Eo_Lexer *ls, Eina_Bool eot)
2177 Eina_Bool is_enum = (ls->t.kw == KW_enum); 2211 Eina_Bool is_enum = (ls->t.kw == KW_enum);
2178 const char *name; 2212 const char *name;
2179 int line, col; 2213 int line, col;
2180 Eolian_Declaration *decl;
2181 Eina_Bool has_extern; 2214 Eina_Bool has_extern;
2182 const char *freefunc; 2215 const char *freefunc;
2183 Eina_Strbuf *buf; 2216 Eina_Strbuf *buf;
@@ -2189,12 +2222,15 @@ parse_unit(Eo_Lexer *ls, Eina_Bool eot)
2189 col = ls->column; 2222 col = ls->column;
2190 parse_name(ls, buf); 2223 parse_name(ls, buf);
2191 name = eina_stringshare_add(eina_strbuf_string_get(buf)); 2224 name = eina_stringshare_add(eina_strbuf_string_get(buf));
2192 decl = (Eolian_Declaration *)eina_hash_find(ls->state->unit.decls, name); 2225 Eolian_Object *decl = _eolian_decl_get(ls, name);
2193 if (decl) 2226 if (decl)
2194 { 2227 {
2195 eina_stringshare_del(name); 2228 eina_stringshare_del(name);
2196 eo_lexer_context_restore(ls); 2229 eo_lexer_context_restore(ls);
2197 redef_error(ls, decl, is_enum ? EOLIAN_DECL_ENUM : EOLIAN_DECL_STRUCT); 2230 Eolian_Typedecl tdecl;
2231 tdecl.base.type = EOLIAN_OBJECT_TYPEDECL;
2232 tdecl.type = is_enum ? EOLIAN_TYPEDECL_ENUM : EOLIAN_TYPEDECL_STRUCT;
2233 redef_error(ls, decl, &tdecl.base);
2198 } 2234 }
2199 eo_lexer_context_pop(ls); 2235 eo_lexer_context_pop(ls);
2200 pop_strbuf(ls); 2236 pop_strbuf(ls);
@@ -2227,8 +2263,7 @@ parse_unit(Eo_Lexer *ls, Eina_Bool eot)
2227 } 2263 }
2228 return EINA_FALSE; 2264 return EINA_FALSE;
2229found_class: 2265found_class:
2230 database_decl_add(ls->unit, ls->tmp.kls->base.name, EOLIAN_DECL_CLASS, 2266 database_object_add(ls->unit, &ls->tmp.kls->base);
2231 ls->tmp.kls->base.file, ls->tmp.kls);
2232 return EINA_TRUE; 2267 return EINA_TRUE;
2233} 2268}
2234 2269
diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c
index 4c3b4ff..412f295 100644
--- a/src/lib/eolian/eolian_database.c
+++ b/src/lib/eolian/eolian_database.c
@@ -9,102 +9,13 @@
9#include "eolian_priv.h" 9#include "eolian_priv.h"
10 10
11void 11void
12database_decl_add(Eolian_Unit *unit, Eina_Stringshare *name, 12database_object_add(Eolian_Unit *unit, const Eolian_Object *obj)
13 Eolian_Declaration_Type type,
14 Eina_Stringshare *file, void *ptr)
15{
16 Eolian_Declaration *decl = calloc(1, sizeof(Eolian_Declaration));
17 decl->base = *((Eolian_Object *)ptr);
18 decl->base.file = eina_stringshare_ref(decl->base.file);
19 decl->base.name = eina_stringshare_ref(decl->base.name);
20 decl->base.refcount = 0;
21 decl->type = type;
22 decl->data = ptr;
23 EOLIAN_OBJECT_ADD(unit, name, decl, decls);
24 eina_hash_set(unit->state->decls_f, file, eina_list_append
25 ((Eina_List *)eina_hash_find(unit->state->decls_f, file), decl));
26 /* object storage */
27 eina_hash_add(unit->objects, name, ptr);
28 eina_hash_add(unit->state->unit.objects, name, ptr);
29 eina_hash_set(unit->state->objects_f, file, eina_list_append
30 ((Eina_List *)eina_hash_find(unit->state->objects_f, file), ptr));
31}
32
33static void
34database_decl_del(Eolian_Declaration *decl)
35{
36 if (!decl || eolian_object_unref(&decl->base)) return;
37 eina_stringshare_del(decl->base.file);
38 eina_stringshare_del(decl->base.name);
39 free(decl);
40}
41
42EAPI const Eolian_Declaration *
43eolian_declaration_get_by_name(const Eolian_Unit *unit, const char *name)
44{
45 if (!unit) return NULL;
46 Eina_Stringshare *shr = eina_stringshare_add(name);
47 const Eolian_Declaration *decl = eina_hash_find(unit->decls, shr);
48 eina_stringshare_del(shr);
49 return decl;
50}
51
52EAPI Eina_Iterator *
53eolian_declarations_get_by_file(const Eolian_State *state, const char *fname)
54{
55 if (!state) return NULL;
56 Eina_Stringshare *shr = eina_stringshare_add(fname);
57 Eina_List *l = eina_hash_find(state->decls_f, shr);
58 eina_stringshare_del(shr);
59 if (!l) return NULL;
60 return eina_list_iterator_new(l);
61}
62
63EAPI Eina_Iterator *
64eolian_all_declarations_get(const Eolian_Unit *unit)
65{ 13{
66 return (unit ? eina_hash_iterator_data_new(unit->decls) : NULL); 14 /* object storage */
67} 15 eina_hash_add(unit->objects, obj->name, obj);
68 16 eina_hash_add(unit->state->unit.objects, obj->name, obj);
69EAPI Eolian_Declaration_Type 17 eina_hash_set(unit->state->objects_f, obj->file, eina_list_append
70eolian_declaration_type_get(const Eolian_Declaration *decl) 18 ((Eina_List *)eina_hash_find(unit->state->objects_f, obj->file), obj));
71{
72 EINA_SAFETY_ON_NULL_RETURN_VAL(decl, EOLIAN_DECL_UNKNOWN);
73 return decl->type;
74}
75
76EAPI Eina_Stringshare *
77eolian_declaration_name_get(const Eolian_Declaration *decl)
78{
79 EINA_SAFETY_ON_NULL_RETURN_VAL(decl, NULL);
80 return decl->base.name;
81}
82
83EAPI const Eolian_Class *
84eolian_declaration_class_get(const Eolian_Declaration *decl)
85{
86 EINA_SAFETY_ON_NULL_RETURN_VAL(decl, NULL);
87 EINA_SAFETY_ON_FALSE_RETURN_VAL(decl->type == EOLIAN_DECL_CLASS, NULL);
88 return (const Eolian_Class *)decl->data;
89}
90
91EAPI const Eolian_Typedecl *
92eolian_declaration_data_type_get(const Eolian_Declaration *decl)
93{
94 EINA_SAFETY_ON_NULL_RETURN_VAL(decl, NULL);
95 EINA_SAFETY_ON_FALSE_RETURN_VAL(decl->type == EOLIAN_DECL_ALIAS ||
96 decl->type == EOLIAN_DECL_STRUCT ||
97 decl->type == EOLIAN_DECL_ENUM, NULL);
98 return (const Eolian_Typedecl *)decl->data;
99}
100
101
102EAPI const Eolian_Variable *
103eolian_declaration_variable_get(const Eolian_Declaration *decl)
104{
105 EINA_SAFETY_ON_NULL_RETURN_VAL(decl, NULL);
106 EINA_SAFETY_ON_FALSE_RETURN_VAL(decl->type == EOLIAN_DECL_VAR, NULL);
107 return (const Eolian_Variable *)decl->data;
108} 19}
109 20
110void database_doc_del(Eolian_Documentation *doc) 21void database_doc_del(Eolian_Documentation *doc)
@@ -428,27 +339,32 @@ eolian_doc_token_ref_get(const Eolian_Unit *unit, const Eolian_Doc_Token *tok,
428 memcpy(name, tok->text, nlen); 339 memcpy(name, tok->text, nlen);
429 name[nlen] = '\0'; 340 name[nlen] = '\0';
430 341
431 const Eolian_Declaration *decl = eolian_declaration_get_by_name(unit, name); 342 const Eolian_Object *decl = eolian_unit_object_by_name_get(unit, name);
432 if (decl) switch (eolian_declaration_type_get(decl)) 343 if (decl)
433 { 344 {
434 case EOLIAN_DECL_CLASS: 345 if (data) *data = decl;
435 if (data) *data = eolian_declaration_class_get(decl); 346 switch (eolian_object_type_get(decl))
436 return EOLIAN_DOC_REF_CLASS; 347 {
437 case EOLIAN_DECL_ALIAS: 348 case EOLIAN_OBJECT_CLASS:
438 if (data) *data = eolian_declaration_data_type_get(decl); 349 return EOLIAN_DOC_REF_CLASS;
439 return EOLIAN_DOC_REF_ALIAS; 350 case EOLIAN_OBJECT_TYPEDECL:
440 case EOLIAN_DECL_STRUCT: 351 switch (eolian_typedecl_type_get((Eolian_Typedecl *)decl))
441 if (data) *data = eolian_declaration_data_type_get(decl); 352 {
442 return EOLIAN_DOC_REF_STRUCT; 353 case EOLIAN_TYPEDECL_ALIAS:
443 case EOLIAN_DECL_ENUM: 354 return EOLIAN_DOC_REF_ALIAS;
444 if (data) *data = eolian_declaration_data_type_get(decl); 355 case EOLIAN_TYPEDECL_STRUCT:
445 return EOLIAN_DOC_REF_ENUM; 356 case EOLIAN_TYPEDECL_STRUCT_OPAQUE:
446 case EOLIAN_DECL_VAR: 357 return EOLIAN_DOC_REF_STRUCT;
447 if (data) *data = eolian_declaration_variable_get(decl); 358 case EOLIAN_TYPEDECL_ENUM:
448 return EOLIAN_DOC_REF_VAR; 359 return EOLIAN_DOC_REF_ENUM;
449 default: 360 default:
450 /* this will not happen but silence static analyzers */ 361 return EOLIAN_DOC_REF_INVALID;
451 return EOLIAN_DOC_REF_INVALID; 362 }
363 case EOLIAN_OBJECT_VARIABLE:
364 return EOLIAN_DOC_REF_VAR;
365 default:
366 return EOLIAN_DOC_REF_INVALID;
367 }
452 } 368 }
453 369
454 /* from here it can only be a function, a struct field or an enum field */ 370 /* from here it can only be a function, a struct field or an enum field */
@@ -533,7 +449,6 @@ database_unit_init(Eolian_State *state, Eolian_Unit *unit, const char *file)
533 unit->structs = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del)); 449 unit->structs = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del));
534 unit->enums = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del)); 450 unit->enums = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del));
535 unit->objects = eina_hash_stringshared_new(NULL); 451 unit->objects = eina_hash_stringshared_new(NULL);
536 unit->decls = eina_hash_stringshared_new(EINA_FREE_CB(database_decl_del));
537} 452}
538 453
539void 454void
@@ -550,7 +465,6 @@ database_unit_del(Eolian_Unit *unit)
550 eina_hash_free(unit->structs); 465 eina_hash_free(unit->structs);
551 eina_hash_free(unit->enums); 466 eina_hash_free(unit->enums);
552 eina_hash_free(unit->objects); 467 eina_hash_free(unit->objects);
553 eina_hash_free(unit->decls);
554} 468}
555 469
556static void 470static void
@@ -581,7 +495,6 @@ eolian_state_new(void)
581 state->globals_f = eina_hash_stringshared_new(_hashlist_free); 495 state->globals_f = eina_hash_stringshared_new(_hashlist_free);
582 state->constants_f = eina_hash_stringshared_new(_hashlist_free); 496 state->constants_f = eina_hash_stringshared_new(_hashlist_free);
583 state->objects_f = eina_hash_stringshared_new(_hashlist_free); 497 state->objects_f = eina_hash_stringshared_new(_hashlist_free);
584 state->decls_f = eina_hash_stringshared_new(_hashlist_free);
585 498
586 return state; 499 return state;
587} 500}
@@ -607,7 +520,6 @@ eolian_state_free(Eolian_State *state)
607 eina_hash_free(state->globals_f); 520 eina_hash_free(state->globals_f);
608 eina_hash_free(state->constants_f); 521 eina_hash_free(state->constants_f);
609 eina_hash_free(state->objects_f); 522 eina_hash_free(state->objects_f);
610 eina_hash_free(state->decls_f);
611 523
612 free(state); 524 free(state);
613} 525}
@@ -793,7 +705,6 @@ _merge_unit(Eolian_Unit *dest, Eolian_Unit *src)
793 eina_hash_foreach(src->aliases, _merge_unit_cb, dest->aliases); 705 eina_hash_foreach(src->aliases, _merge_unit_cb, dest->aliases);
794 eina_hash_foreach(src->structs, _merge_unit_cb, dest->structs); 706 eina_hash_foreach(src->structs, _merge_unit_cb, dest->structs);
795 eina_hash_foreach(src->enums, _merge_unit_cb, dest->enums); 707 eina_hash_foreach(src->enums, _merge_unit_cb, dest->enums);
796 eina_hash_foreach(src->decls, _merge_unit_cb, dest->decls);
797} 708}
798 709
799typedef struct _Merge_Data 710typedef struct _Merge_Data
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index 526fba0..bca488b 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -43,7 +43,6 @@ struct _Eolian_Unit
43 Eina_Hash *structs; 43 Eina_Hash *structs;
44 Eina_Hash *enums; 44 Eina_Hash *enums;
45 Eina_Hash *objects; 45 Eina_Hash *objects;
46 Eina_Hash *decls;
47}; 46};
48 47
49struct _Eolian_State 48struct _Eolian_State
@@ -63,7 +62,6 @@ struct _Eolian_State
63 Eina_Hash *globals_f; 62 Eina_Hash *globals_f;
64 Eina_Hash *constants_f; 63 Eina_Hash *constants_f;
65 Eina_Hash *objects_f; 64 Eina_Hash *objects_f;
66 Eina_Hash *decls_f;
67}; 65};
68 66
69struct _Eolian_Object 67struct _Eolian_Object
@@ -110,13 +108,6 @@ struct _Eolian_Documentation
110 Eina_Stringshare *since; 108 Eina_Stringshare *since;
111}; 109};
112 110
113struct _Eolian_Declaration
114{
115 Eolian_Object base;
116 Eolian_Declaration_Type type;
117 void *data;
118};
119
120struct _Eolian_Class 111struct _Eolian_Class
121{ 112{
122 Eolian_Object base; 113 Eolian_Object base;
@@ -332,9 +323,7 @@ struct _Eolian_Variable
332char *database_class_to_filename(const char *cname); 323char *database_class_to_filename(const char *cname);
333Eina_Bool database_validate(Eolian_State *state, const Eolian_Unit *src); 324Eina_Bool database_validate(Eolian_State *state, const Eolian_Unit *src);
334 325
335void database_decl_add(Eolian_Unit *unit, Eina_Stringshare *name, 326void database_object_add(Eolian_Unit *unit, const Eolian_Object *obj);
336 Eolian_Declaration_Type type,
337 Eina_Stringshare *file, void *ptr);
338 327
339void database_doc_del(Eolian_Documentation *doc); 328void database_doc_del(Eolian_Documentation *doc);
340 329