From 63e795cad88cb52ecdf46f90584867ae22939058 Mon Sep 17 00:00:00 2001 From: Teddy Date: Sat, 12 Apr 2014 15:58:42 +0800 Subject: now works --- const.h | 2 -- semantics.c | 13 +++++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/const.h b/const.h index ef869c8..29d1123 100644 --- a/const.h +++ b/const.h @@ -30,6 +30,4 @@ enum { #define MAX_ERROR_BUFF 1024 #define INT_SIZE 4 #define CHAR_SIZE 1 -#define EXT_LINKAGE 1 -#define NO_LINKAGE 0 #endif diff --git a/semantics.c b/semantics.c index a403b8a..92d7f0b 100644 --- a/semantics.c +++ b/semantics.c @@ -461,7 +461,7 @@ static CVar_t var_merge(CVar_t new, CScope_t scope) { old = cscope_lookup(scope, new->name, NS_ID)->rec.var; if (!is_same_type(old->type, new->type)) ERROR((new->ast, "conflicting types of '%s'", new->name)); - else if (scope->lvl > 0) + else if (scope->lvl) ERROR((new->ast, "redeclaration of '%s' with no linkage", new->name)); type_merge(old->type, new->type); free(new); @@ -735,9 +735,14 @@ CVar_t semantics_decl(CNode *p, CScope_t scope) { CType_t func = var->type; func->name = var->name; if (!cscope_push(scope, type2sym(func), NS_ID)) - type_merge( - cscope_lookup(scope, func->name, NS_ID)->rec.type, - func); + { + CSymbol_t lu = cscope_lookup(scope, func->name, NS_ID); + if (lu->kind != CTYPE) + ERROR((func->ast, "'%s' redeclared as different kind of symbol", func->name)); + if (!is_same_type(lu->rec.type, func)) + ERROR((func->ast, "conflicting types of '%s'", func->name)); + type_merge(lu->rec.type, func); + } if (initr->type == INITR) ERROR((var->ast, "function '%s' is initialized like a variable", func->name)); } -- cgit v1.2.3