aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pc.y6
-rw-r--r--scope.c7
-rw-r--r--tree.c40
-rw-r--r--tree.h2
4 files changed, 45 insertions, 10 deletions
diff --git a/pc.y b/pc.y
index c144043..26d766f 100644
--- a/pc.y
+++ b/pc.y
@@ -81,7 +81,7 @@ extern scope *cur_scope;
%type <tval> proc_statement
%type <tval> var
-%type <ival> type
+%type <tval> type
%type <ival> standard_type
%type <ival> TD
@@ -131,11 +131,11 @@ var_declarations
type
:standard_type
{
- $$ = $1;
+ $$ = mktree($1, NULL, NULL);
}
|ARRAY '[' INUM DOTS INUM ']' OF standard_type
{
- $$ = ARRAY - $8;
+ $$ = mktree(ARRAY - $8, mkinum($3), mkinum($5));
}
;
diff --git a/scope.c b/scope.c
index 9d9da5e..0355014 100644
--- a/scope.c
+++ b/scope.c
@@ -146,8 +146,15 @@ scope *s;
for (i = 0; i < HASH_SIZE; i++) {
for( tmp=s->table[i]; tmp; tmp = tmp->next) {
+ if(!tmp->array_info)
fprintf(stderr, "\t%s:%s\t", tmp->name,
pretty_type(tmp->var_type));
+ else
+ fprintf(stderr, "\t%s:%s [%d:%d]\t", tmp->name,
+ pretty_type(tmp->var_type),
+ tmp->array_info->start_idx,
+ tmp->array_info->start_idx
+ + tmp->array_info->size);
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]));
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");
diff --git a/tree.h b/tree.h
index 23edf8f..0c0cd74 100644
--- a/tree.h
+++ b/tree.h
@@ -27,7 +27,7 @@ ptree* mkinum(int);
ptree* mkrnum(float);
ptree* mkop(int, int, ptree*, ptree*);
-void update_type_info(ptree*, int);
+void update_type_info(ptree*, ptree*);
void set_ret_type(ptree*);
#endif