diff --git a/ps3/src/tree.c b/ps3/src/tree.c index 254bea5..289c104 100644 --- a/ps3/src/tree.c +++ b/ps3/src/tree.c @@ -265,12 +265,13 @@ static node_t* flatten_variable_declarations(node_t* block) assert(block->type == BLOCK); node_t *new_children = node_create(LIST, 0); - - for (int i = 0; i < block->n_children; i++) { - node_t *statement = block->children[i]; + node_t *list = block->children[0]; + for (int i = 0; i < list->n_children; i++) { + node_t *statement = list->children[i]; if (statement->type == LOCAL_VARIABLE_DECLARATION) { - for (int j = 0; j < statement->n_children; j++) { - node_t *var = statement->children[j]; + node_t *llist = statement->children[0]; + for (int j = 0; j < llist->n_children; j++) { + node_t *var = llist->children[j]; assert(var->type == LOCAL_VARIABLE); switch (var->n_children) { case 1: @@ -294,9 +295,9 @@ static node_t* flatten_variable_declarations(node_t* block) } } - free(block->children); - block->children = new_children; - + node_finalize(list); + block->children[0] = new_children; + return block; }