diff options
author | Teddy <[email protected]> | 2014-04-12 15:58:42 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2014-04-12 15:58:42 +0800 |
commit | 63e795cad88cb52ecdf46f90584867ae22939058 (patch) | |
tree | 67ab49199561dffefa16d25543b83d8a9fe270d5 | |
parent | 08fcf7d83c36596660f5841d14052f6f3c46e04d (diff) |
now works
-rw-r--r-- | const.h | 2 | ||||
-rw-r--r-- | semantics.c | 13 |
2 files changed, 9 insertions, 6 deletions
@@ -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)); } |