warn global variable redefinition

This commit is contained in:
Yuichi Nishiwaki 2014-02-07 02:12:43 +09:00
parent 620fee4236
commit d74b82b1a5
1 changed files with 7 additions and 1 deletions

View File

@ -228,8 +228,14 @@ define_var(analyze_state *state, pic_sym sym)
{ {
pic_state *pic = state->pic; pic_state *pic = state->pic;
analyze_scope *scope = state->scope; analyze_scope *scope = state->scope;
xh_entry *e;
xh_put_int(state->scope->var_tbl, sym, 0); if ((e = xh_get_int(scope->var_tbl, sym))) {
pic_warn(pic, "redefining global variable");
return;
}
xh_put_int(scope->var_tbl, sym, 0);
scope->localc++; scope->localc++;
scope->vars = (pic_sym *)pic_realloc(pic, scope->vars, sizeof(pic_sym) * (scope->argc + scope->localc)); scope->vars = (pic_sym *)pic_realloc(pic, scope->vars, sizeof(pic_sym) * (scope->argc + scope->localc));