aboutsummaryrefslogtreecommitdiff
path: root/sem_check.c
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-09-30 19:05:12 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-09-30 21:34:31 -0400
commit6b3e004224ccba39199606f2683265c9e4606e43 (patch)
tree23ae258b00651f97a7f5e7bbeb3758312371ac45 /sem_check.c
parent46fa458c879ab784f6e320fdf793dd4294efcd56 (diff)
Add check that function returns value
Diffstat (limited to 'sem_check.c')
-rw-r--r--sem_check.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/sem_check.c b/sem_check.c
index fd85c98..e30d8c5 100644
--- a/sem_check.c
+++ b/sem_check.c
@@ -206,3 +206,30 @@ ptree *t;
yyerror("Incorrect types in fuction arguments");
}
+
+int func_ret(t, name)
+ptree *t;
+char *name;
+{
+ if (!t)
+ return 0;
+
+ if (t->type == ASSIGNOP && t->l)
+ if (t->l->type == ID && !strcmp(t->l->attr.nval->name, name))
+ return 1;
+
+ return func_ret(t->l, name) || func_ret(t->r, name);
+}
+
+void check_func_return(t,name)
+ptree *t;
+char *name;
+{
+ char buf[100];
+
+ if (!func_ret(t,name)) {
+ snprintf(buf, 100, "Function %s does not return a value\n",
+ name);
+ yyerror(buf);
+ }
+}