aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-08-29 11:53:06 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-08-29 11:53:06 -0400
commit227b13eccaecc05d76ca8dceb922a9d280ead0c4 (patch)
tree6f293ebb87d4aa36779c0f650826759ff567fcc1
parentec98dd863237aa4a1853e0efb589f2da597c5640 (diff)
Fix return value for correctly typed statements
Change okay return value to 1 so 0 can be used to denote an unset return type
-rw-r--r--sem_check.c6
-rw-r--r--tree.c9
2 files changed, 9 insertions, 6 deletions
diff --git a/sem_check.c b/sem_check.c
index 3d42996..c5e9fb6 100644
--- a/sem_check.c
+++ b/sem_check.c
@@ -107,7 +107,7 @@ ptree *t;
yyerror("Incomplete parse tree\n");
if (t->l->ret_type == t->r->ret_type)
- return 0;
+ return 1;
else {
snprintf(buf, 100, "Mismached types: "
"Cannot assign type %s "
@@ -142,13 +142,13 @@ ptree *t;
if (t->l->ret_type != BOOL)
yyerror("If condition must be of type BOOL\n");
- return 0;
+ return 1;
case FOR:
/*TODO add for type checking after parsing is correct*/
break;
default:
return -200;
- snprintf(buf, 101, "Unknown tree node: %d...\n", t->type);
+ snprintf(buf, 100, "Unknown tree node: %d...\n", t->type);
yyerror(buf);
}
diff --git a/tree.c b/tree.c
index fd40781..bb025f5 100644
--- a/tree.c
+++ b/tree.c
@@ -21,6 +21,7 @@ ptree *l, *r;
t->type = type;
t->l = l;
t->r = r;
+ t->ret_type = 0;
return t;
}
@@ -90,10 +91,12 @@ ptree *t;
{
if (!t)
return;
-
- set_ret_type(t->l);
- set_ret_type(t->r);
+ if (! (t->l && t->l->ret_type == 1))
+ set_ret_type(t->l);
+ if (! (t->r && t->r->ret_type == 1))
+ set_ret_type(t->r);
+
t->ret_type = check_ret_type(t);
return;