From e9ac92f439c57c5ce7a39482215363315155270b Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Tue, 15 Oct 2019 19:23:27 -0400 Subject: Fix function scope bounds Function now can access vars outside of their scopes but cannot assign values to these vars. --- sem_check.c | 20 ++++++++++++++++---- 1 file 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", -- cgit v1.1