aboutsummaryrefslogtreecommitdiff
path: root/pc.y
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-09-05 10:50:02 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-09-05 10:50:02 -0400
commitd8a7a9b0ed653ec8061896efc0c8e11b5df6b166 (patch)
tree8fe8cb78ee8b0a99a20e5685a0518d62703fb9b5 /pc.y
parent30a16a2fdfd527e89a83f49f53cb448aafcb4e9a (diff)
Add counting of function arguments
Diffstat (limited to 'pc.y')
-rw-r--r--pc.y15
1 files changed, 10 insertions, 5 deletions
diff --git a/pc.y b/pc.y
index 1bb4a4f..3f3f7ad 100644
--- a/pc.y
+++ b/pc.y
@@ -173,17 +173,22 @@ sub_prog_head
:FUNC ID arguments ':' standard_type ';'
{
node *tmp;
- int i = -1;
+ int i = 0;
check_id(cur_scope->prev, $2);
tmp = scope_insert(cur_scope->prev, $2);
- assert(tmp->func_info = malloc(sizeof struct fi));
- /*TODO add count of parameters*/
+ if ($3->type == ID)
+ i = 1;
+ else
+ i = count_args($3);
+
+ tmp->func_info = malloc(sizeof(struct fi));
+ assert(tmp->func_info);
tmp->func_info->argc = i;
- assert(tmp->func_info->argv = malloc(i * sizeof int));
+ assert(tmp->func_info->argv = malloc(i * sizeof(int)));
- tmp->var_type = $5
+ tmp->var_type = $5;
cur_scope->ret_var = scope_insert(cur_scope, $2);
cur_scope->ret_var->var_type = $5;