From c6d13abfc122c15ecc182b1fc5645628e8eb4d18 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Thu, 5 Sep 2019 17:59:44 -0400 Subject: Add function argument types --- main.c | 23 +++++++++++++++++++++++ pc.h | 3 ++- pc.y | 3 +++ scope.c | 7 ++++++- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index d6cffdd..6c601ff 100644 --- a/main.c +++ b/main.c @@ -162,6 +162,29 @@ ptree *t; return l + r; } +int set_func_types(t, nxt, size) +ptree *t; +int size, *nxt; +{ + int tmp; + + if (!t) + return size; + + if (t->type == LIST){ + tmp = set_func_types(t->l, nxt, size); + for (;size > tmp; --size) ++nxt; + size = set_func_types(t->r, nxt, size); + } else if (t->type == ID){ + if (--size == -1) + yyerror("VARIABLE COUNT CHANGED!!!\n"); + + *nxt = t->attr.nval->var_type; + return size; + } + return size; +} + int main() { #ifdef DEBUG_TYPES diff --git a/pc.h b/pc.h index ea49612..653b720 100644 --- a/pc.h +++ b/pc.h @@ -9,8 +9,9 @@ char* pretty_type(int); void debug_print(int, union YYSTYPE*); int yyerror(char*); -#endif int count_args(ptree*); +int set_func_types(ptree*, int*, int); +#endif #define DEBUG diff --git a/pc.y b/pc.y index 3f3f7ad..8991403 100644 --- a/pc.y +++ b/pc.y @@ -188,6 +188,9 @@ sub_prog_head tmp->func_info->argc = i; assert(tmp->func_info->argv = malloc(i * sizeof(int))); + print_tree($3); + assert(!set_func_types($3, tmp->func_info->argv, i)); + tmp->var_type = $5; cur_scope->ret_var = scope_insert(cur_scope, $2); diff --git a/scope.c b/scope.c index 00e2417..9d9da5e 100644 --- a/scope.c +++ b/scope.c @@ -146,8 +146,13 @@ scope *s; for (i = 0; i < HASH_SIZE; i++) { for( tmp=s->table[i]; tmp; tmp = tmp->next) { - fprintf(stderr, "\t%s:%s\n", tmp->name, + fprintf(stderr, "\t%s:%s\t", tmp->name, pretty_type(tmp->var_type)); + if (tmp->func_info && tmp->func_info->argv) { + for (int i = 0; i < tmp->func_info->argc; i++) + fprintf(stderr, " %s ", pretty_type(tmp->func_info->argv[i])); + } + fprintf(stderr, "\n"); } } } -- cgit v1.1