X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/6c5f863aec6753f9df7225a5746e82fa82ad5c4c..c70fdfcd207a394121c7dac271bbd04ce2a91c98:/src/LR0.c?ds=sidebyside diff --git a/src/LR0.c b/src/LR0.c index ae39b7ce..43030fc5 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -1,7 +1,7 @@ /* 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. @@ -17,8 +17,8 @@ You should have received a copy of the GNU General Public License along with Bison; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ /* See comments in state.h for the data structures that represent it. @@ -59,7 +59,7 @@ static state_list *last_state = NULL; static state * state_list_append (symbol_number sym, size_t core_size, item_number *core) { - state_list *node = MALLOC (node, 1); + state_list *node = xmalloc (sizeof *node); state *s = state_new (sym, core_size, core); if (trace_flag & trace_automaton) @@ -84,14 +84,14 @@ state_list_append (symbol_number sym, size_t core_size, item_number *core) } 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; static void @@ -105,8 +105,9 @@ allocate_itemsets (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 = CALLOC (symbol_count, 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) @@ -121,9 +122,8 @@ allocate_itemsets (void) appears as an item, which is SYMBOL_COUNT[S]. We allocate that much space for each symbol. */ - CALLOC (kernel_base, nsyms); - if (count) - CALLOC (kernel_items, count); + kernel_base = xnmalloc (nsyms, sizeof *kernel_base); + kernel_items = xnmalloc (count, sizeof *kernel_items); count = 0; for (i = 0; i < nsyms; i++) @@ -133,7 +133,7 @@ allocate_itemsets (void) } free (symbol_count); - CALLOC (kernel_size, nsyms); + kernel_size = xnmalloc (nsyms, sizeof *kernel_size); } @@ -142,10 +142,10 @@ allocate_storage (void) { allocate_itemsets (); - CALLOC (shiftset, nsyms); - CALLOC (redset, nrules); + shiftset = xnmalloc (nsyms, sizeof *shiftset); + redset = xnmalloc (nrules, sizeof *redset); state_hash_new (); - CALLOC (shift_symbol, nsyms); + shift_symbol = xnmalloc (nsyms, sizeof *shift_symbol); } @@ -157,7 +157,7 @@ free_storage (void) free (shiftset); free (kernel_base); free (kernel_size); - XFREE (kernel_items); + free (kernel_items); state_hash_free (); } @@ -178,13 +178,12 @@ free_storage (void) 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; @@ -251,7 +250,7 @@ append_states (state *s) { 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; } @@ -274,7 +273,7 @@ static void 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) @@ -296,7 +295,7 @@ save_reductions (state *s) static void set_states (void) { - CALLOC (states, nstates); + states = xcalloc (nstates, sizeof *states); while (first_state) { @@ -330,15 +329,14 @@ set_states (void) 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;