From 89fca11404f818b1ece0abb03b42acbcb1f3a280 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sun, 4 Aug 2019 11:52:30 -0400 Subject: Fix tree print with variable types --- tree.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tree.c b/tree.c index 8a2c3bf..e0216fd 100644 --- a/tree.c +++ b/tree.c @@ -27,7 +27,7 @@ ptree* mkid(n) node *n; { ptree *p = mktree(ID, NULL, NULL); - p->attr.nval = n; /* memory leak? double strdup*/ + p->attr.nval = n; return p; } @@ -70,7 +70,8 @@ ptree *list; list = list->l; continue; /*Continue down list*/ } else if (list->l->type == ID) - /*Set type of first declared ID (only left node in LIST)*/ + /*Set type of first declared ID + (only left node in LIST)*/ list->l->attr.nval->var_type = type; } return; /*At _end_ of list (did not continue)*/ @@ -120,7 +121,16 @@ int spaces; fprintf(stderr, "[LIST]"); break; case ID: - fprintf(stderr, "[ID: %s %d]", t->attr.nval->name, t->attr.nval->var_type); + if (t->r && t->r->attr.nval) + fprintf(stderr, "[ID: %s %s]", + t->r->attr.nval->name, + pretty_type( + t->attr.nval->var_type)); + else + fprintf(stderr, "[ID: %s %s]", + t->attr.nval->name, + pretty_type( + t->attr.nval->var_type)); break; case INUM: fprintf(stderr, "[INUM: %d]", t->attr.ival); -- cgit v1.1