From abd7892a4bd9546ec3c7c65b1a1478a19fc18d61 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 22 Dec 2017 12:41:29 +0100 Subject: [PATCH] eolian: move inherit type checking to validation --- src/lib/eolian/database_validate.c | 26 ++++++++++++++++++++++++++ src/lib/eolian/eo_parser.c | 34 +++------------------------------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/lib/eolian/database_validate.c b/src/lib/eolian/database_validate.c index 6706464..cf5f741 100644 --- a/src/lib/eolian/database_validate.c +++ b/src/lib/eolian/database_validate.c @@ -445,6 +445,32 @@ _validate_class(const Eolian_Unit *src, Eolian_Class *cl, Eina_Hash *nhash) EINA_LIST_FOREACH(cl->inherits, l, icl) { + /* first inherit needs some checking done on it */ + if (l == cl->inherits) switch (cl->type) + { + case EOLIAN_CLASS_REGULAR: + case EOLIAN_CLASS_ABSTRACT: + if (icl->type != EOLIAN_CLASS_REGULAR && icl->type != EOLIAN_CLASS_ABSTRACT) + { + char buf[PATH_MAX]; + snprintf(buf, sizeof(buf), "regular classes ('%s') cannot inherit from non-regular classes ('%s')", + cl->full_name, icl->full_name); + return _obj_error(&cl->base, buf); + } + break; + case EOLIAN_CLASS_MIXIN: + case EOLIAN_CLASS_INTERFACE: + if (icl->type != EOLIAN_CLASS_MIXIN && icl->type != EOLIAN_CLASS_INTERFACE) + { + char buf[PATH_MAX]; + snprintf(buf, sizeof(buf), "non-regular classes ('%s') cannot inherit from regular classes ('%s')", + cl->full_name, icl->full_name); + return _obj_error(&cl->base, buf); + } + break; + default: + break; + } if (!(res = _validate_class(src, icl, nhash))) goto freehash; } diff --git a/src/lib/eolian/eo_parser.c b/src/lib/eolian/eo_parser.c index 882a8be..556ac70 100644 --- a/src/lib/eolian/eo_parser.c +++ b/src/lib/eolian/eo_parser.c @@ -2018,8 +2018,7 @@ parse_class_body(Eo_Lexer *ls, Eolian_Class_Type type) } static void -_inherit_dep(Eo_Lexer *ls, Eina_Strbuf *buf, Eina_Bool check_inherit, - Eolian_Class_Type type) +_inherit_dep(Eo_Lexer *ls, Eina_Strbuf *buf) { const char *fname, *iname; char *fnm; @@ -2056,33 +2055,6 @@ _inherit_dep(Eo_Lexer *ls, Eina_Strbuf *buf, Eina_Bool check_inherit, eo_lexer_syntax_error(ls, ebuf); return; } - if (check_inherit) switch (type) - { - case EOLIAN_CLASS_REGULAR: - case EOLIAN_CLASS_ABSTRACT: - if (dep->type != EOLIAN_CLASS_REGULAR && dep->type != EOLIAN_CLASS_ABSTRACT) - { - char ebuf[PATH_MAX]; - eo_lexer_context_restore(ls); - snprintf(ebuf, sizeof(ebuf), "regular classes ('%s') cannot inherit from non-regular classes ('%s')", - ls->tmp.kls->full_name, iname); - eo_lexer_syntax_error(ls, ebuf); - } - break; - case EOLIAN_CLASS_MIXIN: - case EOLIAN_CLASS_INTERFACE: - if (dep->type != EOLIAN_CLASS_MIXIN && dep->type != EOLIAN_CLASS_INTERFACE) - { - char ebuf[PATH_MAX]; - eo_lexer_context_restore(ls); - snprintf(ebuf, sizeof(ebuf), "non-regular classes ('%s') cannot inherit from regular classes ('%s')", - ls->tmp.kls->full_name, iname); - eo_lexer_syntax_error(ls, ebuf); - } - break; - default: - break; - } ls->tmp.kls->inherits = eina_list_append(ls->tmp.kls->inherits, dep); dep->toplevel = EINA_FALSE; eo_lexer_context_pop(ls); @@ -2133,9 +2105,9 @@ parse_class(Eo_Lexer *ls, Eolian_Class_Type type) if (ls->t.token != ')') { Eina_Strbuf *ibuf = push_strbuf(ls); - _inherit_dep(ls, ibuf, EINA_TRUE, type); + _inherit_dep(ls, ibuf); while (test_next(ls, ',')) - _inherit_dep(ls, ibuf, EINA_FALSE, type); + _inherit_dep(ls, ibuf); pop_strbuf(ls); } check_match(ls, ')', '(', line, col); -- 2.7.4