From 6130381c23c2ca4e050e83b7a20e3ba56d0fc283 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sun, 8 Sep 2019 22:00:47 -0400 Subject: Adds type checking procedure arguments --- pc.y | 2 ++ sem_check.c | 6 ++++-- sem_check.h | 2 ++ tree.c | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pc.y b/pc.y index 8d142a2..c144043 100644 --- a/pc.y +++ b/pc.y @@ -270,6 +270,7 @@ statement |proc_statement { $$ = $1; + check_call($$); } |compound_statement { @@ -346,6 +347,7 @@ proc_statement tmp = check_exists(cur_scope, $1); $$ = mktree(PCALL, mkid(tmp), $3); } + /*calls checked with proc_statement*/ ; expr_list diff --git a/sem_check.c b/sem_check.c index f6e412a..af97507 100644 --- a/sem_check.c +++ b/sem_check.c @@ -183,10 +183,12 @@ ptree *t; { int argc, *argv; - print_tree(t); - if (!(t && t->attr.nval && t->attr.nval->func_info)) + if (!(t && (t->type == FCALL || t->type == PCALL))) yyerror("Tree is not a function call\n"); + if (!(t->l && t->l->attr.nval && t->l->attr.nval->func_info)) + yyerror("Incorrect Call Tree\n"); + argc = t->l->attr.nval->func_info->argc; if (t->l->attr.nval->func_info->argc != count_args(t->r)) /*TODO add info about expected argument count*/ diff --git a/sem_check.h b/sem_check.h index ce7d7fb..0da2cc9 100644 --- a/sem_check.h +++ b/sem_check.h @@ -10,4 +10,6 @@ node* check_exists(scope*, char*); int check_ret_type(ptree*); +void check_call(ptree*); + #endif diff --git a/tree.c b/tree.c index a1a3f0f..b30fa35 100644 --- a/tree.c +++ b/tree.c @@ -22,6 +22,7 @@ ptree *l, *r; t->l = l; t->r = r; t->ret_type = 0; + t->attr.nval = 0; return t; } -- cgit v1.1