eolian: unified node allocation api
authorDaniel Kolesa <d.kolesa@osg.samsung.com>
Thu, 15 Mar 2018 12:53:50 +0000 (13:53 +0100)
committerWonki Kim <wonki_.kim@samsung.com>
Tue, 10 Apr 2018 11:21:56 +0000 (20:21 +0900)
src/lib/eolian/eo_lexer.c
src/lib/eolian/eo_lexer.h

index 4d3f11c..b1cd087 100644 (file)
@@ -1052,12 +1052,60 @@ eo_lexer_set_input(Eo_Lexer *ls, Eolian_State *state, const char *source)
    next_char(ls);
 }
 
+Eolian_Object *
+eo_lexer_node_new(Eo_Lexer *ls, size_t objsize)
+{
+   Eolian_Object *obj = calloc(1, objsize);
+   ls->tmp.nodes = eina_list_prepend(ls->tmp.nodes, obj);
+   eolian_object_ref(obj);
+   return obj;
+}
+
+int
+_node_free(Eolian_Object *obj)
+{
+   int rc = obj->refcount;
+#if 0
+   /* for when we have a proper node allocator and collect on shutdown */
+   if (rc > 1)
+     {
+        _eolian_log("node %p (type %d, name %s at %s:%d:%d)"
+                    " dangling ref (count: %d)", obj, obj->type, obj->name,
+                    obj->file, obj->line, obj->column);
+     }
+#endif
+   switch (obj->type)
+     {
+      case EOLIAN_OBJECT_CLASS:
+        database_class_del((Eolian_Class *)obj);
+        break;
+      case EOLIAN_OBJECT_TYPEDECL:
+        database_typedecl_del((Eolian_Typedecl *)obj);
+        break;
+      case EOLIAN_OBJECT_TYPE:
+        database_type_del((Eolian_Type *)obj);
+        break;
+      case EOLIAN_OBJECT_VARIABLE:
+        database_var_del((Eolian_Variable *)obj);
+        break;
+      case EOLIAN_OBJECT_EXPRESSION:
+        database_expr_del((Eolian_Expression *)obj);
+        break;
+      default:
+        /* normally unreachable, just for debug */
+        assert(0);
+        break;
+     }
+   return rc;
+}
+
 static void
 _temps_free(Eo_Lexer_Temps *tmp)
 {
    Eina_Strbuf *buf;
    Eolian_Type *tp;
    Eolian_Typedecl *tpd;
+   Eolian_Object *obj;
    const char *s;
 
    if (tmp->kls)
@@ -1077,6 +1125,9 @@ _temps_free(Eo_Lexer_Temps *tmp)
 
    EINA_LIST_FREE(tmp->strs, s)
      if (s) eina_stringshare_del(s);
+
+   EINA_LIST_FREE(tmp->nodes, obj)
+     _node_free(obj);
 }
 
 static void
index c99ecd6..d6a53aa 100644 (file)
@@ -128,6 +128,7 @@ typedef struct _Eo_Lexer_Temps
    Eina_List *type_decls;
    Eina_List *expr_defs;
    Eina_List *strs;
+   Eina_List *nodes;
 } Eo_Lexer_Temps;
 
 /* keeps all lexer state */
@@ -219,4 +220,7 @@ void eo_lexer_context_pop    (Eo_Lexer *ls);
 void eo_lexer_context_restore(Eo_Lexer *ls);
 void eo_lexer_context_clear  (Eo_Lexer *ls);
 
+Eolian_Object *eo_lexer_node_new(Eo_Lexer *ls, size_t objsize);
+
+
 #endif /* __EO_LEXER_H__ */