From 227b13eccaecc05d76ca8dceb922a9d280ead0c4 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Thu, 29 Aug 2019 11:53:06 -0400 Subject: Fix return value for correctly typed statements Change okay return value to 1 so 0 can be used to denote an unset return type --- sem_check.c | 6 +++--- tree.c | 9 ++++++--- 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; -- cgit v1.1