-/* Generate the nondeterministic finite state machine for bison,
+/* Generate the nondeterministic finite state machine for Bison.
- Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002 Free Software
- Foundation, Inc.
+ Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002, 2004 Free
+ Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
static state *
state_list_append (symbol_number sym, size_t core_size, item_number *core)
{
- state_list *node = XMALLOC (state_list, 1);
+ state_list *node = xmalloc (sizeof *node);
state *s = state_new (sym, core_size, core);
if (trace_flag & trace_automaton)
}
static int nshifts;
-static symbol_number *shift_symbol = NULL;
+static symbol_number *shift_symbol;
-static rule **redset = NULL;
-static state **shiftset = NULL;
+static rule **redset;
+static state **shiftset;
-static item_number **kernel_base = NULL;
-static int *kernel_size = NULL;
-static item_number *kernel_items = NULL;
+static item_number **kernel_base;
+static int *kernel_size;
+static item_number *kernel_items;
\f
static void
Note that useless productions (hence useless nonterminals) are
browsed too, hence we need to allocate room for _all_ the
symbols. */
- int count = 0;
- short *symbol_count = XCALLOC (short, nsyms + nuseless_nonterminals);
+ size_t count = 0;
+ size_t *symbol_count = xcalloc (nsyms + nuseless_nonterminals,
+ sizeof *symbol_count);
for (r = 0; r < nrules; ++r)
for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
appears as an item, which is SYMBOL_COUNT[S].
We allocate that much space for each symbol. */
- kernel_base = XCALLOC (item_number *, nsyms);
- if (count)
- kernel_items = XCALLOC (item_number, count);
+ kernel_base = xnmalloc (nsyms, sizeof *kernel_base);
+ kernel_items = xnmalloc (count, sizeof *kernel_items);
count = 0;
for (i = 0; i < nsyms; i++)
}
free (symbol_count);
- kernel_size = XCALLOC (int, nsyms);
+ kernel_size = xnmalloc (nsyms, sizeof *kernel_size);
}
{
allocate_itemsets ();
- shiftset = XCALLOC (state *, nsyms);
- redset = XCALLOC (rule *, nrules);
+ shiftset = xnmalloc (nsyms, sizeof *shiftset);
+ redset = xnmalloc (nrules, sizeof *redset);
state_hash_new ();
- shift_symbol = XCALLOC (symbol_number, nsyms);
+ shift_symbol = xnmalloc (nsyms, sizeof *shift_symbol);
}
free (shiftset);
free (kernel_base);
free (kernel_size);
- XFREE (kernel_items);
+ free (kernel_items);
state_hash_free ();
}
static void
new_itemsets (state *s)
{
- int i;
+ size_t i;
if (trace_flag & trace_automaton)
fprintf (stderr, "Entering new_itemsets, state = %d\n", s->number);
- for (i = 0; i < nsyms; i++)
- kernel_size[i] = 0;
+ memset (kernel_size, 0, nsyms * sizeof *kernel_size);
nshifts = 0;
{
symbol_number sym = shift_symbol[i];
int j;
- for (j = i; 0 < j && sym < shift_symbol [j - 1]; j--)
+ for (j = i; 0 < j && sym < shift_symbol[j - 1]; j--)
shift_symbol[j] = shift_symbol[j - 1];
shift_symbol[j] = sym;
}
save_reductions (state *s)
{
int count = 0;
- int i;
+ size_t i;
/* Find and count the active items that represent ends of rules. */
for (i = 0; i < nritemset; ++i)
static void
set_states (void)
{
- states = XCALLOC (state *, nstates);
+ states = xcalloc (nstates, sizeof *states);
while (first_state)
{
void
generate_states (void)
{
+ item_number initial_core = 0;
state_list *list = NULL;
allocate_storage ();
new_closure (nritems);
/* Create the initial state. The 0 at the lhs is the index of the
item of this initial rule. */
- kernel_base[0][0] = 0;
- kernel_size[0] = 1;
- state_list_append (0, kernel_size[0], kernel_base[0]);
+ state_list_append (0, 1, &initial_core);
list = first_state;