From e8482f39eab18f788b134eae9bcb95f877254639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind?= Date: Mon, 21 Feb 2022 13:48:13 +0100 Subject: [PATCH] Added return of node_init --- exercises/03/vslc/include/ir.h | 12 ++++++++++-- exercises/03/vslc/src/tree.c | 6 ++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/exercises/03/vslc/include/ir.h b/exercises/03/vslc/include/ir.h index bdfdedc..b27cc88 100644 --- a/exercises/03/vslc/include/ir.h +++ b/exercises/03/vslc/include/ir.h @@ -10,8 +10,16 @@ typedef struct n { struct n **children; } node_t; -// Export the initializer function, it is needed by the parser -void node_init ( +/**Export the initializer function, it is needed by the parser + * @param *nd node to initialize + * @param type type of node (see nodetype.h) + * @param *data associated data. Declared void to allow any type + * @param n_children number of children + * @param ... variable argument list of child nodes (node_t *) + * + * @return Pointer to the initialized node + * */ +node_t* node_init ( node_t *nd, node_index_t type, void *data, uint64_t n_children, ... ); #endif diff --git a/exercises/03/vslc/src/tree.c b/exercises/03/vslc/src/tree.c index f5963f5..072100f 100644 --- a/exercises/03/vslc/src/tree.c +++ b/exercises/03/vslc/src/tree.c @@ -73,8 +73,8 @@ print_syntax_tree ( void ) //tree_print(root, 0); } - -void +// Changed so it returns the pointer to the new node, can be used as before, but makes the parser file cleaner +node_t* node_init (node_t *nd, node_index_t type, void *data, uint64_t n_children, ...) { va_list child_list; @@ -89,6 +89,8 @@ node_init (node_t *nd, node_index_t type, void *data, uint64_t n_children, ...) for ( uint64_t i=0; ichildren[i] = va_arg ( child_list, node_t * ); va_end ( child_list ); + + return nd; }