aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-10-15 19:23:27 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-10-15 19:23:27 -0400
commite9ac92f439c57c5ce7a39482215363315155270b (patch)
tree9f83947dd99a2f3edc83b5ab54f8744245ca1733
parent3cb61d07beb3d9589f668da4e998ab3efc1af777 (diff)
Fix function scope bounds
Function now can access vars outside of their scopes but cannot assign values to these vars.
-rw-r--r--sem_check.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/sem_check.c b/sem_check.c
index 64db636..4393086 100644
--- a/sem_check.c
+++ b/sem_check.c
@@ -8,6 +8,8 @@
#include "y.tab.h"
#include "pc.h"
+extern scope *cur_scope;
+
void check_id(s, n)
scope *s;
char *n;
@@ -27,7 +29,7 @@ char *n;
node *tmp;
char buf[100];
- if(!(tmp = scope_safe_search(s,n))) {
+ if(!(tmp = scope_search_all(s,n))) {
snprintf(buf, 100, "Cannot find \"%s\"\n", n);
yyerror(buf);
}
@@ -40,6 +42,7 @@ ptree *t;
{
char buf[100];
int type;
+ ptree *tmp;
if (!t)
fprintf(stderr, "TYPE: %d\n", t->type);
@@ -106,9 +109,18 @@ ptree *t;
if (!(t->r && t->l))
yyerror("Incomplete parse tree\n");
- if (t->l->ret_type == t->r->ret_type)
- return 1;
- else
+ if (t->l->ret_type == t->r->ret_type){
+ tmp = t->l->type == ARRAY_ACCESS ? t->l->l : t->l;
+ snprintf(buf, 100, "WHERES THE ERROR\n");
+ if(!(scope_safe_search(cur_scope,
+ tmp->attr.nval->name))) {
+ snprintf(buf, 100, "Cannot find \"%s\"\n",
+ tmp->attr.nval->name);
+ break;
+ } else {
+ return 1;
+ }
+ } else
snprintf(buf, 100, "Mismached types: "
"Cannot assign type %s "
"to variable \"%s\" of type %s\n",