eolian: validate classes in a recursive manner
authorDaniel Kolesa <d.kolesa@osg.samsung.com>
Tue, 24 Oct 2017 21:19:22 +0000 (23:19 +0200)
committerDaniel Kolesa <d.kolesa@osg.samsung.com>
Tue, 24 Oct 2017 21:21:24 +0000 (23:21 +0200)
This allows for proper order of validation which will improve our
performance when also validating for name duplicates.

src/lib/eolian/database_validate.c
src/lib/eolian/eo_parser.c
src/lib/eolian/eolian_database.h

index 274c563..edd5d2c 100644 (file)
@@ -1,4 +1,5 @@
 #include <ctype.h>
+#include <assert.h>
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
@@ -369,10 +370,20 @@ _validate_class(Eolian_Class *cl)
    Eolian_Function *func;
    Eolian_Event *event;
    Eolian_Implement *impl;
+   const char *iname;
+
+   if (!cl)
+     return EINA_FALSE; /* if this happens something is very wrong though */
 
    if (cl->base.validated)
      return EINA_TRUE;
 
+   EINA_LIST_FOREACH(cl->inherits, l, iname)
+     {
+        if (!_validate_class(eina_hash_find(_classes, iname)))
+          return EINA_FALSE;
+     }
+
    EINA_LIST_FOREACH(cl->properties, l, func)
      if (!_validate_function(func))
        return EINA_FALSE;
@@ -435,7 +446,7 @@ database_validate()
    /* FIXME: pass unit properly */
    Eina_Iterator *iter = eolian_all_classes_get(NULL);
    EINA_ITERATOR_FOREACH(iter, cl)
-     if (!_validate_class(cl))
+     if (cl->toplevel && !_validate_class(cl))
        {
           eina_iterator_free(iter);
           return EINA_FALSE;
index ef19fc3..a7649e0 100644 (file)
@@ -1985,7 +1985,7 @@ _inherit_dep(Eo_Lexer *ls, Eina_Strbuf *buf, Eina_Bool check_inherit,
      }
    _parse_dep(ls, fname, iname);
    /* FIXME: pass unit properly */
-   const Eolian_Class *dep = eolian_class_get_by_name(NULL, iname);
+   Eolian_Class *dep = (Eolian_Class *)eolian_class_get_by_name(NULL, iname);
    if (!dep)
      {
         char ebuf[PATH_MAX];
@@ -2023,6 +2023,7 @@ _inherit_dep(Eo_Lexer *ls, Eina_Strbuf *buf, Eina_Bool check_inherit,
      }
    ls->tmp.kls->inherits = eina_list_append(ls->tmp.kls->inherits,
                                             eina_stringshare_add(iname));
+   dep->toplevel = EINA_FALSE;
    eo_lexer_context_pop(ls);
 }
 
@@ -2036,6 +2037,7 @@ parse_class(Eo_Lexer *ls, Eolian_Class_Type type)
    int line, col;
    Eina_Strbuf *buf = push_strbuf(ls);
    ls->tmp.kls = calloc(1, sizeof(Eolian_Class));
+   ls->tmp.kls->toplevel = EINA_TRUE;
    FILL_BASE(ls->tmp.kls->base, ls, ls->line_number, ls->column);
    eo_lexer_get(ls);
    ls->tmp.kls->type = type;
index 301caf4..5389267 100644 (file)
@@ -99,6 +99,7 @@ struct _Eolian_Class
    Eina_List *events; /* List event_name -> Eolian_Event */
    Eina_Bool class_ctor_enable:1;
    Eina_Bool class_dtor_enable:1;
+   Eina_Bool toplevel:1;
 };
 
 struct _Eolian_Function