aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeddy <[email protected]>2014-04-05 14:12:35 +0800
committerTeddy <[email protected]>2014-04-05 14:12:35 +0800
commit28989b9fcb9970000cf1c5cc7e44b7c5d573e33b (patch)
tree96bff75ac458193c3aa083dad75381ba3f0be490
parent0859752127a67a5fbc9ee7b3bd6c8492632371c9 (diff)
add a dirty hack to `semantic_func`
-rw-r--r--semantics.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/semantics.c b/semantics.c
index cc7bd5e..aa97c6b 100644
--- a/semantics.c
+++ b/semantics.c
@@ -455,8 +455,8 @@ CVar_t semantics_declr(CNode *, CType_t, CScope_t);
CVar_t semantics_p_decl(CNode *p, CScope_t scope) {
CHECK_TYPE(p, PLAIN_DECL);
CVar_t var = semantics_declr(p->chd->next,
- semantics_type_spec(p->chd, scope),
- scope);
+ semantics_type_spec(p->chd, scope),
+ scope);
if (!type_is_complete(var->type))
{
sprintf(err_buff, "parameter '%s' has incomplete type", var->name);
@@ -1368,12 +1368,20 @@ CVar_t semantics_func(CNode *p, CScope_t scope) {
}
scope->func = func;
+ cscope_enter(scope); /* enter function local scope */
func->rec.func.params = semantics_params(chd, scope); /* check params */
- if (cscope_push_var(scope, res))
- old = res;
- cscope_enter(scope); /* enter into function local scope */
- {
+ { /* Note: here is a dirty hack to forcibly push function definition to
+ 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;
+ scope->top = ntop->next;
+ scope->lvl--;
+ if (cscope_push_var(scope, res))
+ old = res;
+ scope->top = ntop;
+ scope->lvl++;
+
for (p = func->rec.func.params; p; p = p->next)
cscope_push_var(scope, p);
}