aboutsummaryrefslogtreecommitdiff
path: root/tree.c
diff options
context:
space:
mode:
authorTucker Evans <tuckerevans24@gmail.com>2019-09-12 19:50:14 -0400
committerTucker Evans <tuckerevans24@gmail.com>2019-09-12 19:50:14 -0400
commit11b46650941f54bf7b95648de04c897656b9867b (patch)
treeba91e63ad94530905439f7daf7f2e8281efe8ada /tree.c
parent6130381c23c2ca4e050e83b7a20e3ba56d0fc283 (diff)
Fix setting type for multiple declared arrays
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/tree.c b/tree.c
index b30fa35..35fe071 100644
--- a/tree.c
+++ b/tree.c
@@ -60,31 +60,51 @@ ptree *l, *r;
return p;
}
-void update_type_info(list, type)
-int type;
-ptree *list;
+void update_type_info(list, t)
+ptree *list, *t;
{
- assert(list);
+ int type;
+ struct ai *info = NULL;
+ assert(list && t);
+
+ type = t->type;
+ if (type != INT && type != REAL){
+ assert(info = malloc(sizeof(struct ai)));
+ info->size = t->r->attr.ival - t->l->attr.ival;
+ info->start_idx = t->l->attr.ival;
+ }
+
if (list->type == ID) {
list->attr.nval->var_type = type;
+ if (info)
+ list->attr.nval->array_info = info;
return;
}
while (list->r && list->r->type == ID) {
/*Set type of right child through list*/
list->r->attr.nval->var_type = type;
+ if (info)
+ list->r->attr.nval->array_info = info;
if (list->l) {
if (list->l->type == LIST) {
list = list->l;
continue; /*Continue down list*/
- } else if (list->l->type == ID)
+ } else if (list->l->type == ID) {
/*Set type of first declared ID
(only left node in LIST)*/
list->l->attr.nval->var_type = type;
+ if (info){
+ list->l->attr.nval->array_info = info;
+ }
+ }
}
- return; /*At _end_ of list (did not continue)*/
+ break; /*At _end_ of list (did not continue)*/
}
+
+ /*TODO free t. and list?*/
+ return;
}
void set_ret_type(t)
@@ -189,6 +209,14 @@ int spaces;
case FCALL:
fprintf(stderr, "[CALL]");
break;
+ case INT:
+ case REAL:
+ fprintf(stderr, "[STD TYPE]");
+ break;
+ case ARRAY - INT:
+ case ARRAY - REAL:
+ fprintf(stderr, "[ARRAY]");
+ break;
default:
fprintf(stderr, "[?: %d]", t->type);
yyerror("Error in tree_print");