eolian: check redefinitions in the parser instead (provides line info)

This commit is contained in:
Daniel Kolesa 2014-07-21 11:34:14 +01:00
parent 9262a82ed3
commit 6f805a9998
3 changed files with 11 additions and 10 deletions

View File

@ -459,18 +459,12 @@ nodeloop:
break;
case NODE_TYPEDEF:
if (!database_type_add(nd->def_typedef))
{
ERR("Redefinition of typedef %s\n", nd->def_typedef->alias);
goto error;
}
goto error;
nd->def_typedef = NULL;
break;
case NODE_STRUCT:
if (!database_struct_add(nd->def_struct))
{
ERR("Redefinition of struct %s\n", nd->def_struct->name);
goto error;
}
goto error;
nd->def_struct = NULL;
break;
default:

View File

@ -37,7 +37,6 @@ Eina_Bool
database_type_add(Eolian_Typedef *def)
{
if (!_types) return EINA_FALSE;
if (eina_hash_find(_types, def->alias)) return EINA_FALSE;
eina_hash_set(_types, def->alias, def);
return EINA_TRUE;
}
@ -45,7 +44,6 @@ database_type_add(Eolian_Typedef *def)
Eina_Bool database_struct_add(Eolian_Type *tp)
{
if (!_structs) return EINA_FALSE;
if (eina_hash_find(_structs, tp->name)) return EINA_FALSE;
eina_hash_set(_structs, tp->name, tp);
return EINA_TRUE;
}

View File

@ -329,6 +329,9 @@ parse_type_struct(Eo_Lexer *ls, Eina_Bool allow_struct, Eina_Bool allow_anon)
check(ls, TOK_VALUE);
if (eo_lexer_get_c_type(ls->t.kw))
eo_lexer_syntax_error(ls, "invalid struct name");
/* todo: see typedef */
if (eina_hash_find(_structs, ls->t.value))
eo_lexer_syntax_error(ls, "struct redefinition");
sname = eina_stringshare_ref(ls->t.value);
eo_lexer_get(ls);
if (ls->t.token == '{')
@ -407,6 +410,9 @@ parse_typedef(Eo_Lexer *ls)
eo_lexer_get(ls);
}
check(ls, TOK_VALUE);
/* todo: store info about the previous definition and mention it here */
if (eina_hash_find(_types, ls->t.value))
eo_lexer_syntax_error(ls, "typedef redefinition");
ls->tmp.typedef_def->alias = eina_stringshare_ref(ls->t.value);
eo_lexer_get(ls);
(void)!!test_next(ls, ':');
@ -1071,6 +1077,9 @@ parse_unit(Eo_Lexer *ls, Eina_Bool eot)
check(ls, TOK_VALUE);
if (eo_lexer_get_c_type(ls->t.kw))
eo_lexer_syntax_error(ls, "invalid struct name");
/* todo: see typedef */
if (eina_hash_find(_structs, ls->t.value))
eo_lexer_syntax_error(ls, "struct redefinition");
name = eina_stringshare_ref(ls->t.value);
eo_lexer_get(ls);
parse_struct(ls, name, is_extern);