diff options
author | Tucker Evans <tuckerevans24@gmail.com> | 2019-09-05 17:59:44 -0400 |
---|---|---|
committer | Tucker Evans <tuckerevans24@gmail.com> | 2019-09-05 18:03:17 -0400 |
commit | c6d13abfc122c15ecc182b1fc5645628e8eb4d18 (patch) | |
tree | 3cc20de947e6cea8d725d9efd0dd6aeb1b2e95eb | |
parent | d8a7a9b0ed653ec8061896efc0c8e11b5df6b166 (diff) |
Add function argument types
-rw-r--r-- | main.c | 23 | ||||
-rw-r--r-- | pc.h | 3 | ||||
-rw-r--r-- | pc.y | 3 | ||||
-rw-r--r-- | scope.c | 7 |
4 files changed, 34 insertions, 2 deletions
@@ -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 @@ -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 @@ -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); @@ -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"); } } } |