summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2018-02-23 15:14:13 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2018-02-23 15:25:55 +0100
commit1a7dabeb74fa6a039b431b0e8442f43ead15282e (patch)
treed1faeaa67c8ca32389892e6e8bdc56fb17162c68
parent411e140eaf9f51b9018e089d42ec1c8a8b5419ed (diff)
eolian: proper in-unit storage for all declarations
This makes sure variables are stored as well as types within their respective units. Also, declarations are now refcounted just like any other Eolian object.
-rw-r--r--src/lib/eolian/database_type.c6
-rw-r--r--src/lib/eolian/database_var.c28
-rw-r--r--src/lib/eolian/eo_parser.c4
-rw-r--r--src/lib/eolian/eolian_database.c22
-rw-r--r--src/lib/eolian/eolian_database.h5
5 files changed, 40 insertions, 25 deletions
diff --git a/src/lib/eolian/database_type.c b/src/lib/eolian/database_type.c
index d8954ec5ae..052a2ea577 100644
--- a/src/lib/eolian/database_type.c
+++ b/src/lib/eolian/database_type.c
@@ -48,7 +48,7 @@ database_type_add(Eolian_Unit *unit, Eolian_Typedecl *tp)
48 eina_hash_set(unit->state->aliases_f, tp->base.file, eina_list_append 48 eina_hash_set(unit->state->aliases_f, tp->base.file, eina_list_append
49 ((Eina_List*)eina_hash_find(unit->state->aliases_f, tp->base.file), 49 ((Eina_List*)eina_hash_find(unit->state->aliases_f, tp->base.file),
50 tp)); 50 tp));
51 database_decl_add(unit->state, tp->full_name, EOLIAN_DECL_ALIAS, tp->base.file, tp); 51 database_decl_add(unit, tp->full_name, EOLIAN_DECL_ALIAS, tp->base.file, tp);
52} 52}
53 53
54void 54void
@@ -58,7 +58,7 @@ database_struct_add(Eolian_Unit *unit, Eolian_Typedecl *tp)
58 eolian_object_add(&tp->base, tp->full_name, unit->structs); 58 eolian_object_add(&tp->base, tp->full_name, unit->structs);
59 eina_hash_set(unit->state->structs_f, tp->base.file, eina_list_append 59 eina_hash_set(unit->state->structs_f, tp->base.file, eina_list_append
60 ((Eina_List*)eina_hash_find(unit->state->structs_f, tp->base.file), tp)); 60 ((Eina_List*)eina_hash_find(unit->state->structs_f, tp->base.file), tp));
61 database_decl_add(unit->state, tp->full_name, EOLIAN_DECL_STRUCT, tp->base.file, tp); 61 database_decl_add(unit, tp->full_name, EOLIAN_DECL_STRUCT, tp->base.file, tp);
62} 62}
63 63
64void 64void
@@ -68,7 +68,7 @@ database_enum_add(Eolian_Unit *unit, Eolian_Typedecl *tp)
68 eolian_object_add(&tp->base, tp->full_name, unit->enums); 68 eolian_object_add(&tp->base, tp->full_name, unit->enums);
69 eina_hash_set(unit->state->enums_f, tp->base.file, eina_list_append 69 eina_hash_set(unit->state->enums_f, tp->base.file, eina_list_append
70 ((Eina_List*)eina_hash_find(unit->state->enums_f, tp->base.file), tp)); 70 ((Eina_List*)eina_hash_find(unit->state->enums_f, tp->base.file), tp));
71 database_decl_add(unit->state, tp->full_name, EOLIAN_DECL_ENUM, tp->base.file, tp); 71 database_decl_add(unit, tp->full_name, EOLIAN_DECL_ENUM, tp->base.file, tp);
72} 72}
73 73
74Eina_Bool 74Eina_Bool
diff --git a/src/lib/eolian/database_var.c b/src/lib/eolian/database_var.c
index 30ea60a9fd..c33df7261d 100644
--- a/src/lib/eolian/database_var.c
+++ b/src/lib/eolian/database_var.c
@@ -23,28 +23,30 @@ database_var_del(Eolian_Variable *var)
23} 23}
24 24
25static void 25static void
26database_var_global_add(Eolian *state, Eolian_Variable *var) 26database_var_global_add(Eolian_Unit *unit, Eolian_Variable *var)
27{ 27{
28 eina_hash_set(state->unit.globals, var->full_name, var); 28 eolian_object_add(&var->base, var->full_name, unit->state->unit.globals);
29 eina_hash_set(state->globals_f, var->base.file, eina_list_append 29 eolian_object_add(&var->base, var->full_name, unit->globals);
30 ((Eina_List*)eina_hash_find(state->globals_f, var->base.file), var)); 30 eina_hash_set(unit->state->globals_f, var->base.file, eina_list_append
31 database_decl_add(state, var->full_name, EOLIAN_DECL_VAR, var->base.file, var); 31 ((Eina_List*)eina_hash_find(unit->state->globals_f, var->base.file), var));
32 database_decl_add(unit, var->full_name, EOLIAN_DECL_VAR, var->base.file, var);
32} 33}
33 34
34static void 35static void
35database_var_constant_add(Eolian *state, Eolian_Variable *var) 36database_var_constant_add(Eolian_Unit *unit, Eolian_Variable *var)
36{ 37{
37 eina_hash_set(state->unit.constants, var->full_name, var); 38 eolian_object_add(&var->base, var->full_name, unit->state->unit.constants);
38 eina_hash_set(state->constants_f, var->base.file, eina_list_append 39 eolian_object_add(&var->base, var->full_name, unit->constants);
39 ((Eina_List*)eina_hash_find(state->constants_f, var->base.file), var)); 40 eina_hash_set(unit->state->constants_f, var->base.file, eina_list_append
40 database_decl_add(state, var->full_name, EOLIAN_DECL_VAR, var->base.file, var); 41 ((Eina_List*)eina_hash_find(unit->state->constants_f, var->base.file), var));
42 database_decl_add(unit, var->full_name, EOLIAN_DECL_VAR, var->base.file, var);
41} 43}
42 44
43void 45void
44database_var_add(Eolian *state, Eolian_Variable *var) 46database_var_add(Eolian_Unit *unit, Eolian_Variable *var)
45{ 47{
46 if (var->type == EOLIAN_VAR_GLOBAL) 48 if (var->type == EOLIAN_VAR_GLOBAL)
47 database_var_global_add(state, var); 49 database_var_global_add(unit, var);
48 else 50 else
49 database_var_constant_add(state, var); 51 database_var_constant_add(unit, var);
50} 52}
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index 56c6a4bfa3..7d9eaad525 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -2165,7 +2165,7 @@ parse_unit(Eo_Lexer *ls, Eina_Bool eot)
2165 case KW_const: 2165 case KW_const:
2166 case KW_var: 2166 case KW_var:
2167 { 2167 {
2168 database_var_add(ls->state, parse_variable(ls, ls->t.kw == KW_var)); 2168 database_var_add(ls->unit, parse_variable(ls, ls->t.kw == KW_var));
2169 eolian_object_ref(&ls->tmp.var->base); 2169 eolian_object_ref(&ls->tmp.var->base);
2170 ls->tmp.var = NULL; 2170 ls->tmp.var = NULL;
2171 break; 2171 break;
@@ -2226,7 +2226,7 @@ parse_unit(Eo_Lexer *ls, Eina_Bool eot)
2226 } 2226 }
2227 return EINA_FALSE; 2227 return EINA_FALSE;
2228found_class: 2228found_class:
2229 database_decl_add(ls->state, ls->tmp.kls->full_name, EOLIAN_DECL_CLASS, 2229 database_decl_add(ls->unit, ls->tmp.kls->full_name, EOLIAN_DECL_CLASS,
2230 ls->tmp.kls->base.file, ls->tmp.kls); 2230 ls->tmp.kls->base.file, ls->tmp.kls);
2231 return EINA_TRUE; 2231 return EINA_TRUE;
2232} 2232}
diff --git a/src/lib/eolian/eolian_database.c b/src/lib/eolian/eolian_database.c
index 514d4bf63a..e5b816e18f 100644
--- a/src/lib/eolian/eolian_database.c
+++ b/src/lib/eolian/eolian_database.c
@@ -9,17 +9,29 @@
9#include "eolian_priv.h" 9#include "eolian_priv.h"
10 10
11void 11void
12database_decl_add(Eolian *state, Eina_Stringshare *name, 12database_decl_add(Eolian_Unit *unit, Eina_Stringshare *name,
13 Eolian_Declaration_Type type, 13 Eolian_Declaration_Type type,
14 Eina_Stringshare *file, void *ptr) 14 Eina_Stringshare *file, void *ptr)
15{ 15{
16 Eolian_Declaration *decl = calloc(1, sizeof(Eolian_Declaration)); 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.refcount = 0;
17 decl->type = type; 20 decl->type = type;
18 decl->name = name; 21 decl->name = name;
19 decl->data = ptr; 22 decl->data = ptr;
20 eina_hash_set(state->unit.decls, name, decl); 23 eolian_object_add(&decl->base, name, unit->state->unit.decls);
21 eina_hash_set(state->decls_f, file, eina_list_append 24 eolian_object_add(&decl->base, name, unit->decls);
22 ((Eina_List*)eina_hash_find(state->decls_f, file), decl)); 25 eina_hash_set(unit->state->decls_f, file, eina_list_append
26 ((Eina_List*)eina_hash_find(unit->state->decls_f, file), decl));
27}
28
29static void
30database_decl_del(Eolian_Declaration *decl)
31{
32 if (!decl || eolian_object_unref(&decl->base)) return;
33 eina_stringshare_del(decl->base.file);
34 free(decl);
23} 35}
24 36
25EAPI const Eolian_Declaration * 37EAPI const Eolian_Declaration *
@@ -514,7 +526,7 @@ database_unit_init(Eolian *state, Eolian_Unit *unit)
514 unit->aliases = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del)); 526 unit->aliases = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del));
515 unit->structs = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del)); 527 unit->structs = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del));
516 unit->enums = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del)); 528 unit->enums = eina_hash_stringshared_new(EINA_FREE_CB(database_typedecl_del));
517 unit->decls = eina_hash_stringshared_new(free); 529 unit->decls = eina_hash_stringshared_new(EINA_FREE_CB(database_decl_del));
518} 530}
519 531
520void 532void
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index c8cc6dd0fb..3e87e9c933 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -101,6 +101,7 @@ struct _Eolian_Documentation
101 101
102struct _Eolian_Declaration 102struct _Eolian_Declaration
103{ 103{
104 Eolian_Object base;
104 Eolian_Declaration_Type type; 105 Eolian_Declaration_Type type;
105 Eina_Stringshare *name; 106 Eina_Stringshare *name;
106 void *data; 107 void *data;
@@ -333,7 +334,7 @@ struct _Eolian_Variable
333char *database_class_to_filename(const char *cname); 334char *database_class_to_filename(const char *cname);
334Eina_Bool database_validate(Eolian *state, const Eolian_Unit *src); 335Eina_Bool database_validate(Eolian *state, const Eolian_Unit *src);
335 336
336void database_decl_add(Eolian *state, Eina_Stringshare *name, 337void database_decl_add(Eolian_Unit *unit, Eina_Stringshare *name,
337 Eolian_Declaration_Type type, 338 Eolian_Declaration_Type type,
338 Eina_Stringshare *file, void *ptr); 339 Eina_Stringshare *file, void *ptr);
339 340
@@ -367,7 +368,7 @@ void database_expr_print(Eolian_Expression *expr);
367/* variables */ 368/* variables */
368 369
369void database_var_del(Eolian_Variable *var); 370void database_var_del(Eolian_Variable *var);
370void database_var_add(Eolian *state, Eolian_Variable *var); 371void database_var_add(Eolian_Unit *unit, Eolian_Variable *var);
371 372
372/* classes */ 373/* classes */
373void database_class_del(Eolian_Class *cl); 374void database_class_del(Eolian_Class *cl);