From 6f3310ddead0a00c6b8c1d2085fd0e83a1ada827 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Thu, 29 Aug 2019 11:54:46 -0400 Subject: Fix consolidate yyerror calls to after switch Any failed type checking now sets buf string to error message and breaks out of switch case and will then call yyerror with buf string. --- sem_check.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/sem_check.c b/sem_check.c index c5e9fb6..88f41ad 100644 --- a/sem_check.c +++ b/sem_check.c @@ -65,20 +65,19 @@ ptree *t; "Cannot use boolean " "operator on type %s\n", pretty_type(type)); - yyerror(buf); + break; } } if (t->r->ret_type == t->l->ret_type) return t->r->ret_type; - else { + else snprintf(buf, 100, "Mismached types: " "Type %s " "cannot be used with type %s\n", pretty_type(t->r->ret_type), pretty_type(t->l->ret_type)); - yyerror(buf); - } + break; case RELOP : if (!(t->r && t->l)) @@ -91,7 +90,6 @@ ptree *t; "cannot be compared to type %s\n", pretty_type(t->r->ret_type), pretty_type(t->l->ret_type)); - yyerror(buf); break; case NOT: if (t->l && t->l->ret_type == BOOL) @@ -108,15 +106,14 @@ ptree *t; if (t->l->ret_type == t->r->ret_type) return 1; - else { + else snprintf(buf, 100, "Mismached types: " "Cannot assign type %s " "to variable \"%s\" of type %s\n", pretty_type(t->r->ret_type), t->l->attr.nval->name, pretty_type(t->l->attr.nval->var_type)); - yyerror(buf); - } + break; @@ -128,7 +125,7 @@ ptree *t; snprintf(buf, 100, "Cannot access array" "with type %s\n", pretty_type(t->r->ret_type)); - yyerror(buf); + break; } type = t->l->attr.nval -> var_type; @@ -149,9 +146,9 @@ ptree *t; default: return -200; snprintf(buf, 100, "Unknown tree node: %d...\n", t->type); - yyerror(buf); } + yyerror(buf); return -1; } -- cgit v1.1