From f314c03bdf62b83fe4d2b8d600d15d839a0c32b9 Mon Sep 17 00:00:00 2001 From: Teddy Date: Thu, 10 Apr 2014 18:27:48 +0800 Subject: ... --- TODO.rst | 2 +- const.h | 2 ++ semantics.c | 18 ++++++++++-------- testcases/pass.c | 2 ++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/TODO.rst b/TODO.rst index 0b1d01c..0495efd 100644 --- a/TODO.rst +++ b/TODO.rst @@ -9,7 +9,7 @@ TODO - Fix: - check global definition (if type is complete) when semantic analysis finishes - - local function declaration is not in a local scope (external linkage issue) + - local function declaration is not in a local scope (external linkage issue) (will not be fixed) - incomplete type issues - function **definition** requires complete return type (function declaration does not) (done) - array requires **complete** elem type (done) diff --git a/const.h b/const.h index fab99d9..9e242c0 100644 --- a/const.h +++ b/const.h @@ -24,3 +24,5 @@ #define MAX_ERROR_BUFF 1024 #define INT_SIZE 4 #define CHAR_SIZE 1 +#define EXT_LINKAGE 1 +#define NO_LINKAGE 0 diff --git a/semantics.c b/semantics.c index 4c87ebb..6e2075c 100644 --- a/semantics.c +++ b/semantics.c @@ -457,11 +457,6 @@ CVar_t semantics_p_decl(CNode *p, CScope_t scope) { CVar_t var = semantics_declr(p->chd->next, semantics_type_spec(p->chd, scope), scope, 0); - if (!type_is_complete(var->type)) - { - sprintf(err_buff, "parameter '%s' has incomplete type", var->name); - ERROR(var->ast); - } return var; } @@ -1377,7 +1372,7 @@ CVar_t semantics_func(CNode *p, CScope_t scope) { the global scope, while all the types specified in parameters retain in local scope. The key point is to make sure semantics_params does not push any var */ CSNode *ntop = scope->top; - CVar_t p; + CVar_t var; scope->top = ntop->next; scope->lvl--; if (cscope_push_var(scope, res)) @@ -1385,8 +1380,15 @@ CVar_t semantics_func(CNode *p, CScope_t scope) { scope->top = ntop; scope->lvl++; - for (p = func->rec.func.params; p; p = p->next) - cscope_push_var(scope, p); + for (var = func->rec.func.params; var; var = var->next) + { + cscope_push_var(scope, var); + if (!type_is_complete(var->type)) + { + sprintf(err_buff, "parameter '%s' has incomplete type", var->name); + ERROR(var->ast); + } + } } func->rec.func.local = semantics_comp(p->chd->next->next, scope); /* check comp */ func->rec.func.body = p->chd->next->next; diff --git a/testcases/pass.c b/testcases/pass.c index 4d9041e..4b4dfed 100644 --- a/testcases/pass.c +++ b/testcases/pass.c @@ -86,6 +86,8 @@ int f(int f()) { f(complex_pointer); } +int incomp(struct I a); + struct Node n; struct Node {int x, y;} n; /* global forward declaration is ok */ -- cgit v1.2.3-70-g09d2