eolian: move inherit type checking to validation

This commit is contained in:
Daniel Kolesa 2017-12-22 12:41:29 +01:00
parent 6ecad5b873
commit e1bcd61bdf
2 changed files with 29 additions and 31 deletions

View File

@ -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;
}

View File

@ -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);