From 0bfed6d77c9b91607babc85886093f238e354c8b Mon Sep 17 00:00:00 2001 From: Alexander Klauer Date: Thu, 22 Nov 2018 22:16:51 +0100 Subject: [PATCH] Remove global n_parse_{term,abstract,alt}_nodes Required for #12. --- src/yaep.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/yaep.c b/src/yaep.c index 8607fa4..10d4115 100644 --- a/src/yaep.c +++ b/src/yaep.c @@ -167,6 +167,10 @@ struct grammar 6 - print additionally lookaheads. */ int debug_level; + /* The following is number of created terminal, abstract, and + alternative nodes. */ + int n_parse_term_nodes, n_parse_abstract_nodes, n_parse_alt_nodes; + /* The following value is TRUE if we need only one parse. */ int one_parse_p; @@ -5194,10 +5198,6 @@ print_parse (FILE * f, struct yaep_tree_node *root) #endif -/* The following is number of created terminal, abstract, and - alternative nodes. */ -static int n_parse_term_nodes, n_parse_abstract_nodes, n_parse_alt_nodes; - /* The following function places translation NODE into *PLACE and creates alternative nodes if it is necessary. */ #if MAKE_INLINE @@ -5216,7 +5216,7 @@ place_translation (struct yaep_tree_node **place, struct yaep_tree_node *node) } /* We need an alternative. */ #ifndef NO_YAEP_DEBUG_PRINT - n_parse_alt_nodes++; + grammar->n_parse_alt_nodes++; #endif alt = (struct yaep_tree_node *) (*parse_alloc) (sizeof (struct yaep_tree_node)); @@ -5228,7 +5228,7 @@ place_translation (struct yaep_tree_node **place, struct yaep_tree_node *node) { /* We need alternative node for the 1st alternative too. */ - n_parse_alt_nodes++; + grammar->n_parse_alt_nodes++; next_alt = alt->val.alt.next = ((struct yaep_tree_node *) (*parse_alloc) (sizeof (struct yaep_tree_node))); @@ -5489,7 +5489,8 @@ make_parse (int *ambiguous_p) vlo_t *stack, *orig_states; #endif - n_parse_term_nodes = n_parse_abstract_nodes = n_parse_alt_nodes = 0; + grammar->n_parse_term_nodes = grammar->n_parse_abstract_nodes + = grammar->n_parse_alt_nodes = 0; set = pl[pl_curr]; assert (grammar->axiom != NULL); /* We have only one start situation: "$S : $eof .". */ @@ -5639,7 +5640,7 @@ make_parse (int *ambiguous_p) ; else { - n_parse_term_nodes++; + grammar->n_parse_term_nodes++; node = ((struct yaep_tree_node *) (*parse_alloc) (sizeof (struct yaep_tree_node))); node->type = YAEP_TERM; @@ -5816,7 +5817,7 @@ make_parse (int *ambiguous_p) if (table_state == NULL || new_p) { /* We need new abtract node. */ - n_parse_abstract_nodes++; + grammar->n_parse_abstract_nodes++; node = ((struct yaep_tree_node *) (*parse_alloc) (sizeof (struct yaep_tree_node) @@ -5985,7 +5986,7 @@ make_parse (int *ambiguous_p) } assert (result != NULL - && (!grammar->one_parse_p || n_parse_alt_nodes == 0)); + && (!grammar->one_parse_p || grammar->n_parse_alt_nodes == 0)); return result; } @@ -6147,12 +6148,12 @@ yaep_parse (struct grammar *g, n_reduce_vects, n_reduce_vect_len); fprintf (stderr, " #term nodes = %d, #abstract nodes = %d\n", - n_parse_term_nodes, n_parse_abstract_nodes); + g->n_parse_term_nodes, g->n_parse_abstract_nodes); fprintf (stderr, " #alternative nodes = %d, #all nodes = %d\n", - n_parse_alt_nodes, - n_parse_term_nodes + n_parse_abstract_nodes - + n_parse_alt_nodes); + g->n_parse_alt_nodes, + g->n_parse_term_nodes + g->n_parse_abstract_nodes + + g->n_parse_alt_nodes); if (tab_searches == 0) tab_searches++; fprintf (stderr,