/* Generate the nondeterministic finite state machine for bison,
- Copyright (C) 1984, 1986, 1989, 2000 Free Software Foundation, Inc.
+ Copyright 1984, 1986, 1989, 2000 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
The entry point is generate_states. */
#include "system.h"
-#include "xalloc.h"
#include "gram.h"
#include "state.h"
#include "complain.h"
int nstates;
int final_state;
-core *first_state;
-shifts *first_shift;
-reductions *first_reduction;
+core *first_state = NULL;
+shifts *first_shift = NULL;
+reductions *first_reduction = NULL;
-static core *this_state;
-static core *last_state;
-static shifts *last_shift;
-static reductions *last_reduction;
+static core *this_state = NULL;
+static core *last_state = NULL;
+static shifts *last_shift = NULL;
+static reductions *last_reduction = NULL;
static int nshifts;
-static short *shift_symbol;
+static short *shift_symbol = NULL;
-static short *redset;
-static short *shiftset;
+static short *redset = NULL;
+static short *shiftset = NULL;
-static short **kernel_base;
-static short **kernel_end;
-static short *kernel_items;
+static short **kernel_base = NULL;
+static short **kernel_end = NULL;
+static short *kernel_items = NULL;
/* hash table for states, to recognize equivalent ones. */
#define STATE_TABLE_SIZE 1009
-static core **state_table;
+static core **state_table = NULL;
\f
static void
allocate_itemsets (void)
{
- short *itemp;
+ short *itemp = NULL;
int symbol;
int i;
int count;
- short *symbol_count;
+ short *symbol_count = NULL;
count = 0;
symbol_count = XCALLOC (short, nsyms);
We allocate that much space for each symbol. */
kernel_base = XCALLOC (short *, nsyms);
- kernel_items = XCALLOC (short, count);
+ if (count)
+ kernel_items = XCALLOC (short, count);
count = 0;
for (i = 0; i < nsyms; i++)
int symbol;
#if TRACE
- fprintf (stderr, "Entering new_itemsets\n");
+ fprintf (stderr, "Entering new_itemsets, state = %d\n",
+ this_state->number);
#endif
for (i = 0; i < nsyms; i++)
short *iend;
#if TRACE
- fprintf (stderr, "Entering new_state, symbol = %d\n", symbol);
+ fprintf (stderr, "Entering new_state, symbol = %d, state = %d\n",
+ symbol, nstates);
#endif
if (nstates >= MAXSHORT)
iend = kernel_end[symbol];
n = iend - isp1;
- p =
- (core *) xcalloc ((unsigned) (sizeof (core) + (n - 1) * sizeof (short)), 1);
+ p = CORE_ALLOC (n);
p->accessing_symbol = symbol;
p->number = nstates;
p->nitems = n;
{
core *p;
- p = (core *) xcalloc ((unsigned) (sizeof (core) - sizeof (short)), 1);
+ p = CORE_ALLOC (0);
first_state = last_state = this_state = p;
nstates = 1;
}
short *sp2;
short *send;
- p = (shifts *) xcalloc ((unsigned) (sizeof (shifts) +
- (nshifts - 1) * sizeof (short)), 1);
+ p = SHIFTS_ALLOC (nshifts);
p->number = this_state->number;
p->nshifts = nshifts;
core *statep;
shifts *sp;
- statep = (core *) xcalloc ((unsigned) (sizeof (core) - sizeof (short)), 1);
+ statep = CORE_ALLOC (0);
statep->number = nstates;
statep->accessing_symbol = start_symbol;
last_state = statep;
/* Make a shift from this state to (what will be) the final state. */
- sp = XCALLOC (shifts, 1);
+ sp = SHIFTS_ALLOC (1);
sp->number = nstates++;
sp->nshifts = 1;
sp->shifts[0] = nstates;
if (sp && sp->number == k)
{
- sp2 = (shifts *) xcalloc ((unsigned) (sizeof (shifts)
- +
- sp->nshifts *
- sizeof (short)), 1);
+ sp2 = SHIFTS_ALLOC (sp->nshifts + 1);
sp2->number = k;
sp2->nshifts = sp->nshifts + 1;
sp2->shifts[0] = nstates;
}
else
{
- sp2 = XCALLOC (shifts, 1);
+ sp2 = SHIFTS_ALLOC (1);
sp2->number = k;
sp2->nshifts = 1;
sp2->shifts[0] = nstates;
going to the next-to-final state (yet to be made). */
sp = first_shift;
- sp2 = (shifts *) xcalloc (sizeof (shifts)
- + sp->nshifts * sizeof (short), 1);
+ sp2 = SHIFTS_ALLOC (sp->nshifts + 1);
sp2->nshifts = sp->nshifts + 1;
/* Stick this shift into the vector at the proper place. */
{
/* The initial state didn't even have any shifts.
Give it one shift, to the next-to-final state. */
- sp = XCALLOC (shifts, 1);
+ sp = SHIFTS_ALLOC (1);
sp->nshifts = 1;
sp->shifts[0] = nstates;
/* There are no shifts for any state.
Make one shift, from the initial state to the next-to-final state. */
- sp = XCALLOC (shifts, 1);
+ sp = SHIFTS_ALLOC (1);
sp->nshifts = 1;
sp->shifts[0] = nstates;
/* Make the final state--the one that follows a shift from the
next-to-final state.
The symbol for that shift is 0 (end-of-file). */
- statep = (core *) xcalloc ((unsigned) (sizeof (core) - sizeof (short)), 1);
+ statep = CORE_ALLOC (0);
statep->number = nstates;
last_state->next = statep;
last_state = statep;
/* Make the shift from the final state to the termination state. */
- sp = XCALLOC (shifts, 1);
+ sp = SHIFTS_ALLOC (1);
sp->number = nstates++;
sp->nshifts = 1;
sp->shifts[0] = nstates;
final_state = nstates;
/* Make the termination state. */
- statep = (core *) xcalloc ((unsigned) (sizeof (core) - sizeof (short)), 1);
+ statep = CORE_ALLOC (0);
statep->number = nstates++;
last_state->next = statep;
last_state = statep;
if (count)
{
- p = (reductions *) xcalloc ((unsigned) (sizeof (reductions) +
- (count - 1) * sizeof (short)), 1);
+ p = REDUCTIONS_ALLOC (count);
p->number = this_state->number;
p->nreds = count;