summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2017-12-04 14:44:29 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2017-12-05 16:41:42 +0100
commit67e1c2ab8818eda7d88ac61741824b1a903bc69d (patch)
tree60d74eb203b3d79a0d2a5748ec1d2daeaa2e4ee2
parent2a0f873c8427e08bc855b3ad03913c627e7dd939 (diff)
eolian: add initial refcounting for database objects
This will be necessary once the unit system is in (it will be used to keep track of multiple references to objects across units).
-rw-r--r--src/lib/eolian/eo_parser.c17
-rw-r--r--src/lib/eolian/eolian_database.h17
2 files changed, 32 insertions, 2 deletions
diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c
index aa25b2be40..dcdfc0600a 100644
--- a/src/lib/eolian/eo_parser.c
+++ b/src/lib/eolian/eo_parser.c
@@ -131,12 +131,14 @@ push_typedecl(Eo_Lexer *ls)
131static void 131static void
132pop_type(Eo_Lexer *ls) 132pop_type(Eo_Lexer *ls)
133{ 133{
134 eolian_object_ref((Eolian_Object *)eina_list_data_get(ls->tmp.type_defs));
134 ls->tmp.type_defs = eina_list_remove_list(ls->tmp.type_defs, ls->tmp.type_defs); 135 ls->tmp.type_defs = eina_list_remove_list(ls->tmp.type_defs, ls->tmp.type_defs);
135} 136}
136 137
137static void 138static void
138pop_typedecl(Eo_Lexer *ls) 139pop_typedecl(Eo_Lexer *ls)
139{ 140{
141 eolian_object_ref((Eolian_Object *)eina_list_data_get(ls->tmp.type_decls));
140 ls->tmp.type_decls = eina_list_remove_list(ls->tmp.type_decls, ls->tmp.type_decls); 142 ls->tmp.type_decls = eina_list_remove_list(ls->tmp.type_decls, ls->tmp.type_decls);
141} 143}
142 144
@@ -240,6 +242,7 @@ push_expr(Eo_Lexer *ls)
240static void 242static void
241pop_expr(Eo_Lexer *ls) 243pop_expr(Eo_Lexer *ls)
242{ 244{
245 eolian_object_ref((Eolian_Object *)eina_list_data_get(ls->tmp.expr_defs));
243 ls->tmp.expr_defs = eina_list_remove_list(ls->tmp.expr_defs, ls->tmp.expr_defs); 246 ls->tmp.expr_defs = eina_list_remove_list(ls->tmp.expr_defs, ls->tmp.expr_defs);
244} 247}
245 248
@@ -510,6 +513,7 @@ parse_struct(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
510 fname = eina_stringshare_ref(ls->t.value.s); 513 fname = eina_stringshare_ref(ls->t.value.s);
511 eina_hash_add(def->fields, fname, fdef); 514 eina_hash_add(def->fields, fname, fdef);
512 def->field_list = eina_list_append(def->field_list, fdef); 515 def->field_list = eina_list_append(def->field_list, fdef);
516 eolian_object_ref(&fdef->base);
513 eo_lexer_get(ls); 517 eo_lexer_get(ls);
514 check_next(ls, ':'); 518 check_next(ls, ':');
515 tp = parse_type(ls); 519 tp = parse_type(ls);
@@ -578,6 +582,7 @@ parse_enum(Eo_Lexer *ls, const char *name, Eina_Bool is_extern,
578 fname = eina_stringshare_ref(ls->t.value.s); 582 fname = eina_stringshare_ref(ls->t.value.s);
579 eina_hash_add(def->fields, fname, fdef); 583 eina_hash_add(def->fields, fname, fdef);
580 def->field_list = eina_list_append(def->field_list, fdef); 584 def->field_list = eina_list_append(def->field_list, fdef);
585 eolian_object_ref(&fdef->base);
581 eo_lexer_get(ls); 586 eo_lexer_get(ls);
582 FILL_BASE(fdef->base, ls, fline, fcol); 587 FILL_BASE(fdef->base, ls, fline, fcol);
583 fdef->base_enum = def; 588 fdef->base_enum = def;
@@ -989,6 +994,7 @@ parse_param(Eo_Lexer *ls, Eina_List **params, Eina_Bool allow_inout,
989 par->param_dir = EOLIAN_IN_PARAM; 994 par->param_dir = EOLIAN_IN_PARAM;
990 FILL_BASE(par->base, ls, ls->line_number, ls->column); 995 FILL_BASE(par->base, ls, ls->line_number, ls->column);
991 *params = eina_list_append(*params, par); 996 *params = eina_list_append(*params, par);
997 eolian_object_ref(&par->base);
992 if (cref || (allow_inout && (ls->t.kw == KW_at_in))) 998 if (cref || (allow_inout && (ls->t.kw == KW_at_in)))
993 { 999 {
994 par->param_dir = EOLIAN_IN_PARAM; 1000 par->param_dir = EOLIAN_IN_PARAM;
@@ -1256,6 +1262,8 @@ parse_property(Eo_Lexer *ls)
1256 prop->impl = impl; 1262 prop->impl = impl;
1257 ls->tmp.kls->properties = eina_list_append(ls->tmp.kls->properties, prop); 1263 ls->tmp.kls->properties = eina_list_append(ls->tmp.kls->properties, prop);
1258 ls->tmp.kls->implements = eina_list_append(ls->tmp.kls->implements, impl); 1264 ls->tmp.kls->implements = eina_list_append(ls->tmp.kls->implements, impl);
1265 eolian_object_ref(&prop->base);
1266 eolian_object_ref(&impl->base);
1259 check(ls, TOK_VALUE); 1267 check(ls, TOK_VALUE);
1260 if (ls->t.kw == KW_get || ls->t.kw == KW_set) 1268 if (ls->t.kw == KW_get || ls->t.kw == KW_set)
1261 { 1269 {
@@ -1360,6 +1368,7 @@ parse_function_pointer(Eo_Lexer *ls)
1360 meth->name = eina_stringshare_ref(def->name); 1368 meth->name = eina_stringshare_ref(def->name);
1361 1369
1362 def->function_pointer = meth; 1370 def->function_pointer = meth;
1371 eolian_object_ref(&meth->base);
1363 1372
1364 meth->is_beta = (ls->t.kw == KW_at_beta); 1373 meth->is_beta = (ls->t.kw == KW_at_beta);
1365 if (meth->is_beta) 1374 if (meth->is_beta)
@@ -1419,6 +1428,8 @@ parse_method(Eo_Lexer *ls)
1419 meth->impl = impl; 1428 meth->impl = impl;
1420 ls->tmp.kls->methods = eina_list_append(ls->tmp.kls->methods, meth); 1429 ls->tmp.kls->methods = eina_list_append(ls->tmp.kls->methods, meth);
1421 ls->tmp.kls->implements = eina_list_append(ls->tmp.kls->implements, impl); 1430 ls->tmp.kls->implements = eina_list_append(ls->tmp.kls->implements, impl);
1431 eolian_object_ref(&meth->base);
1432 eolian_object_ref(&impl->base);
1422 check(ls, TOK_VALUE); 1433 check(ls, TOK_VALUE);
1423 if (ls->t.kw == KW_get || ls->t.kw == KW_set) 1434 if (ls->t.kw == KW_get || ls->t.kw == KW_set)
1424 { 1435 {
@@ -1505,6 +1516,7 @@ parse_part(Eo_Lexer *ls)
1505{ 1516{
1506 Eolian_Part *part = calloc(1, sizeof(Eolian_Part)); 1517 Eolian_Part *part = calloc(1, sizeof(Eolian_Part));
1507 ls->tmp.kls->parts = eina_list_append(ls->tmp.kls->parts, part); 1518 ls->tmp.kls->parts = eina_list_append(ls->tmp.kls->parts, part);
1519 eolian_object_ref(&part->base);
1508 check(ls, TOK_VALUE); 1520 check(ls, TOK_VALUE);
1509 part->name = eina_stringshare_ref(ls->t.value.s); 1521 part->name = eina_stringshare_ref(ls->t.value.s);
1510 eo_lexer_get(ls); 1522 eo_lexer_get(ls);
@@ -1609,6 +1621,7 @@ parse_implement(Eo_Lexer *ls, Eina_Bool iface)
1609 impl = calloc(1, sizeof(Eolian_Implement)); 1621 impl = calloc(1, sizeof(Eolian_Implement));
1610 FILL_BASE(impl->base, ls, iline, icol); 1622 FILL_BASE(impl->base, ls, iline, icol);
1611 ls->tmp.kls->implements = eina_list_append(ls->tmp.kls->implements, impl); 1623 ls->tmp.kls->implements = eina_list_append(ls->tmp.kls->implements, impl);
1624 eolian_object_ref(&impl->base);
1612 } 1625 }
1613 if (ls->t.token != TOK_VALUE) 1626 if (ls->t.token != TOK_VALUE)
1614 eo_lexer_syntax_error(ls, "class name expected"); 1627 eo_lexer_syntax_error(ls, "class name expected");
@@ -1713,6 +1726,7 @@ parse_constructor(Eo_Lexer *ls)
1713 ctor = calloc(1, sizeof(Eolian_Constructor)); 1726 ctor = calloc(1, sizeof(Eolian_Constructor));
1714 FILL_BASE(ctor->base, ls, ls->line_number, ls->column); 1727 FILL_BASE(ctor->base, ls, ls->line_number, ls->column);
1715 ls->tmp.kls->constructors = eina_list_append(ls->tmp.kls->constructors, ctor); 1728 ls->tmp.kls->constructors = eina_list_append(ls->tmp.kls->constructors, ctor);
1729 eolian_object_ref(&ctor->base);
1716 if (ls->t.token == '.') 1730 if (ls->t.token == '.')
1717 { 1731 {
1718 check_next(ls, '.'); 1732 check_next(ls, '.');
@@ -1763,6 +1777,7 @@ parse_event(Eo_Lexer *ls)
1763 ev->scope = EOLIAN_SCOPE_PUBLIC; 1777 ev->scope = EOLIAN_SCOPE_PUBLIC;
1764 Eina_Strbuf *buf = push_strbuf(ls); 1778 Eina_Strbuf *buf = push_strbuf(ls);
1765 ls->tmp.kls->events = eina_list_append(ls->tmp.kls->events, ev); 1779 ls->tmp.kls->events = eina_list_append(ls->tmp.kls->events, ev);
1780 eolian_object_ref(&ev->base);
1766 check(ls, TOK_VALUE); 1781 check(ls, TOK_VALUE);
1767 eina_strbuf_append(buf, ls->t.value.s); 1782 eina_strbuf_append(buf, ls->t.value.s);
1768 eo_lexer_get(ls); 1783 eo_lexer_get(ls);
@@ -2196,6 +2211,7 @@ parse_unit(Eo_Lexer *ls, Eina_Bool eot)
2196 case KW_var: 2211 case KW_var:
2197 { 2212 {
2198 database_var_add(parse_variable(ls, ls->t.kw == KW_var)); 2213 database_var_add(parse_variable(ls, ls->t.kw == KW_var));
2214 eolian_object_ref(&ls->tmp.var->base);
2199 ls->tmp.var = NULL; 2215 ls->tmp.var = NULL;
2200 break; 2216 break;
2201 } 2217 }
@@ -2523,6 +2539,7 @@ eo_parser_database_fill(const char *filename, Eina_Bool eot, Eolian_Class **fcl)
2523 2539
2524 eina_hash_set(_classes, cl->full_name, cl); 2540 eina_hash_set(_classes, cl->full_name, cl);
2525 eina_hash_set(_classesf, cl->base.file, cl); 2541 eina_hash_set(_classesf, cl->base.file, cl);
2542 eolian_object_ref(&cl->base);
2526 2543
2527 if (fcl) *fcl = cl; 2544 if (fcl) *fcl = cl;
2528 2545
diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h
index ad8dfdba54..44878aefff 100644
--- a/src/lib/eolian/eolian_database.h
+++ b/src/lib/eolian/eolian_database.h
@@ -81,9 +81,22 @@ typedef struct _Eolian_Object
81 const char *file; 81 const char *file;
82 int line; 82 int line;
83 int column; 83 int column;
84 int refcount;
84 Eina_Bool validated; 85 Eina_Bool validated;
85} Eolian_Object; 86} Eolian_Object;
86 87
88static inline void
89eolian_object_ref(Eolian_Object *obj)
90{
91 ++obj->refcount;
92}
93
94static inline Eina_Bool
95eolian_object_unref(Eolian_Object *obj)
96{
97 return (--obj->refcount > 0);
98}
99
87struct _Eolian_Documentation 100struct _Eolian_Documentation
88{ 101{
89 Eolian_Object base; 102 Eolian_Object base;
@@ -259,17 +272,17 @@ struct _Eolian_Event
259 272
260struct _Eolian_Struct_Type_Field 273struct _Eolian_Struct_Type_Field
261{ 274{
262 Eina_Stringshare *name;
263 Eolian_Object base; 275 Eolian_Object base;
276 Eina_Stringshare *name;
264 Eolian_Type *type; 277 Eolian_Type *type;
265 Eolian_Documentation *doc; 278 Eolian_Documentation *doc;
266}; 279};
267 280
268struct _Eolian_Enum_Type_Field 281struct _Eolian_Enum_Type_Field
269{ 282{
283 Eolian_Object base;
270 Eolian_Typedecl *base_enum; 284 Eolian_Typedecl *base_enum;
271 Eina_Stringshare *name; 285 Eina_Stringshare *name;
272 Eolian_Object base;
273 Eolian_Expression *value; 286 Eolian_Expression *value;
274 Eolian_Documentation *doc; 287 Eolian_Documentation *doc;
275 Eina_Bool is_public_value :1; 288 Eina_Bool is_public_value :1;