aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pc.y2
-rw-r--r--scope.c13
2 files changed, 11 insertions, 4 deletions
diff --git a/pc.y b/pc.y
index 32be027..72ac10b 100644
--- a/pc.y
+++ b/pc.y
@@ -222,7 +222,7 @@ sub_prog_head
/* Need to duplicate ID.name so it is not freed with inner
* scope*/
- cur_scope->ret_var = scope_insert(cur_scope, strdup($2));
+ cur_scope->ret_var = mknode(strdup($2));
cur_scope->ret_var->var_type = $5;
$$ = $2;
diff --git a/scope.c b/scope.c
index 8b70c5b..ef9e4f5 100644
--- a/scope.c
+++ b/scope.c
@@ -36,7 +36,9 @@ scope *s;
free_list(s->table[i]);
}
- /*free_list takes care of freeing s->ret_var*/
+ if (s->ret_var)
+ free(s->ret_var);
+ s->ret_var = NULL;
free(s);
s = NULL;
@@ -100,9 +102,14 @@ node* scope_search(root, name)
scope *root;
char *name;
{
- int hash = hashpjw(name);
+ int hash;
+ node *tmp;
- node *tmp = root->table[hash];
+ if (root->ret_var && !strcmp(root->ret_var->name, name))
+ return root->ret_var;
+
+ hash = hashpjw(name);
+ tmp = root->table[hash];
return list_search(tmp, name);
}