aboutsummaryrefslogtreecommitdiff
path: root/scope.c
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-09-30 23:19:04 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-09-30 23:28:25 -0400
commit59f7f4ccb71eb489690ada8821977455ab377699 (patch)
treee23b192f57e5bc836b733e5eea19637c9f700b19 /scope.c
parent6b3e004224ccba39199606f2683265c9e4606e43 (diff)
Fix search now uses scope->ret_var
Allows for the scope to contain the function without having to worry about multiple nodes with the same name.
Diffstat (limited to 'scope.c')
-rw-r--r--scope.c13
1 files changed, 10 insertions, 3 deletions
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);
}