From d74b82b1a5d7a3530262912d662e298982a5d34a Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Fri, 7 Feb 2014 02:12:43 +0900 Subject: [PATCH] warn global variable redefinition --- src/codegen.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/codegen.c b/src/codegen.c index 482e9222..33129291 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -228,8 +228,14 @@ define_var(analyze_state *state, pic_sym sym) { pic_state *pic = state->pic; 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->vars = (pic_sym *)pic_realloc(pic, scope->vars, sizeof(pic_sym) * (scope->argc + scope->localc));