aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-09-05 17:59:44 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-09-05 18:03:17 -0400
commitc6d13abfc122c15ecc182b1fc5645628e8eb4d18 (patch)
tree3cc20de947e6cea8d725d9efd0dd6aeb1b2e95eb
parentd8a7a9b0ed653ec8061896efc0c8e11b5df6b166 (diff)
Add function argument types
-rw-r--r--main.c23
-rw-r--r--pc.h3
-rw-r--r--pc.y3
-rw-r--r--scope.c7
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");
}
}
}