aboutsummaryrefslogtreecommitdiff
path: root/sem_check.c
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-08-17 16:30:28 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-08-17 16:30:28 -0400
commitee21031fb16f5ed89dd1dbaf73bc2a1201f955b1 (patch)
tree9a134aa149b0756dba0e35ca8372f4916a8ccadc /sem_check.c
parente1d044ff79638cf781816e8723fa78f1e9a7b34e (diff)
Fix deal with and/or ops correctly in type checking
Diffstat (limited to 'sem_check.c')
-rw-r--r--sem_check.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/sem_check.c b/sem_check.c
index 7e6e338..d18fb59 100644
--- a/sem_check.c
+++ b/sem_check.c
@@ -56,6 +56,21 @@ ptree *t;
if (!(t->r && t->l))
yyerror("Missing nodes\n");
+ if (t->attr.opval == ADD || t->attr.opval == OR) {
+ if(t->l->ret_type == BOOL && t->r->ret_type ==BOOL)
+ return BOOL;
+ else {
+ type = t->l->ret_type == BOOL ?
+ t->r->ret_type : t->l->ret_type;
+
+ snprintf(buf, 100, "Mismached types:"
+ "Cannot use boolean "
+ "operator on type %s\n",
+ pretty_type(type));
+ yyerror(buf);
+ }
+ }
+
if (t->r->ret_type == t->l->ret_type)
return t->r->ret_type;
else {
@@ -70,7 +85,6 @@ ptree *t;
case RELOP :
if (!(t->r && t->l))
yyerror("Missing nodes\n");
-
if (t->r->ret_type == t->l->ret_type)
return BOOL;
else