mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 21:03:04 +00:00
lists: fix various issues with the use of gnulib's list
First, we should avoid code such as
gl_list_iterator_t it = gl_list_iterator (deriv->children);
derivation *child = NULL;
while (gl_list_iterator_next (&it, (const void **) &child, NULL))
{
derivation_print (child, f);
because of -Wstrict-aliasing (whose job is to catch type-punning
issues). See https://lists.gnu.org/r/bug-bison/2020-05/msg00039.html.
Rather we need
gl_list_iterator_t it = gl_list_iterator (deriv->children);
const void **p = NULL;
while (gl_list_iterator_next (&it, &p, NULL))
{
derivation *child = (derivation *) p;
derivation_print (child, f);
Second, list iterators actually have destructors. Even though they
are noop in the case of linked-lists, we should use them.
Let's address both issues with typed wrappers (such as
derivation_list_next) that take care of both issues, and besides allow
to scope the iterators within the loop:
derivation *child;
for (gl_list_iterator_t it = gl_list_iterator (deriv->children);
derivation_list_next (&it, &child);
)
{
derivation_print (child, f);
* src/derivation.h, src/derivation.c (derivation_list_next): New.
Use it where appropriate.
* src/counterexample.c (search_state_list_next): New.
Use it where appropriate.
* src/parse-simulation.h, src/parse-simulation.c
* src/state-item.h (state_item_list_next): New.
Use it where appropriate.
This commit is contained in:
@@ -253,10 +253,12 @@ parse_state_completed_steps (const parse_state *ps, int *shifts, int *production
|
||||
|
||||
gl_list_t sis = root_ps->state_items.contents;
|
||||
int count = 0;
|
||||
gl_list_iterator_t it = gl_list_iterator (sis);
|
||||
|
||||
state_item *last = NULL;
|
||||
state_item *next = NULL;
|
||||
while (gl_list_iterator_next (&it, (const void **) &next, NULL))
|
||||
for (gl_list_iterator_t it = gl_list_iterator (sis);
|
||||
state_item_list_next (&it, &next);
|
||||
)
|
||||
{
|
||||
if (last && last->state == next->state)
|
||||
++count;
|
||||
@@ -285,22 +287,24 @@ list_flatten_and_split (gl_list_t *list, gl_list_t *rets, int split, int n,
|
||||
int ret_array = 0;
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
const void *p = NULL;
|
||||
gl_list_iterator_t it = gl_list_iterator (list[i]);
|
||||
gl_list_t l;
|
||||
while (gl_list_iterator_next (&it, (const void **) &l, NULL))
|
||||
{
|
||||
if (!l)
|
||||
continue;
|
||||
gl_list_iterator_t it2 = gl_list_iterator (l);
|
||||
void *si;
|
||||
while (gl_list_iterator_next (&it2, (const void **) &si, NULL))
|
||||
{
|
||||
if (ret_index++ == split)
|
||||
++ret_array;
|
||||
if (rets[ret_array])
|
||||
append_fn (rets[ret_array], si);
|
||||
}
|
||||
}
|
||||
while (gl_list_iterator_next (&it, &p, NULL))
|
||||
if (p)
|
||||
{
|
||||
gl_list_t l = (gl_list_t) p;
|
||||
const void *si = NULL;
|
||||
gl_list_iterator_t it2 = gl_list_iterator (l);
|
||||
while (gl_list_iterator_next (&it2, &si, NULL))
|
||||
{
|
||||
if (ret_index++ == split)
|
||||
++ret_array;
|
||||
if (rets[ret_array])
|
||||
append_fn (rets[ret_array], si);
|
||||
}
|
||||
gl_list_iterator_free (&it2);
|
||||
}
|
||||
gl_list_iterator_free (&it);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -540,11 +544,12 @@ simulate_reduction (parse_state *ps, int rule_len, bitset symbol_set)
|
||||
}
|
||||
else
|
||||
{
|
||||
gl_list_iterator_t it = gl_list_iterator (prev);
|
||||
state_item *psis;
|
||||
while (gl_list_iterator_next (&it, (const void **) &psis, NULL))
|
||||
state_item *psis = NULL;
|
||||
for (gl_list_iterator_t it = gl_list_iterator (prev);
|
||||
state_item_list_next (&it, &psis);
|
||||
)
|
||||
{
|
||||
//Prepend the result from the reverse production
|
||||
// Prepend the result from the reverse production.
|
||||
parse_state *copy = copy_parse_state (true, new_root);
|
||||
ps_si_prepend (copy, psis);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user