From 05b395be47f49dfa9b3ded75ab1de95ef8ab07bf Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Tue, 24 Oct 2017 23:19:22 +0200 Subject: [PATCH] eolian: validate classes in a recursive manner This allows for proper order of validation which will improve our performance when also validating for name duplicates. --- src/lib/eolian/database_validate.c | 13 ++++++++++++- src/lib/eolian/eo_parser.c | 4 +++- src/lib/eolian/eolian_database.h | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/lib/eolian/database_validate.c b/src/lib/eolian/database_validate.c index 274c563dba..edd5d2c4c6 100644 --- a/src/lib/eolian/database_validate.c +++ b/src/lib/eolian/database_validate.c @@ -1,4 +1,5 @@ #include +#include #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; diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c index ef19fc3486..a7649e0a0b 100644 --- a/src/lib/eolian/eo_parser.c +++ b/src/lib/eolian/eo_parser.c @@ -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; diff --git a/src/lib/eolian/eolian_database.h b/src/lib/eolian/eolian_database.h index 301caf4294..5389267a7e 100644 --- a/src/lib/eolian/eolian_database.h +++ b/src/lib/eolian/eolian_database.h @@ -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