(state_number_to_vector_number,

symbol_number_to_vector_number):
Now inline functions rather than macros, to avoid casts.
(table_size): Now int, to pacify GCC.
(table_grow, table_ninf_remap): Use signed table size.
(save_row): Don't bother initializing locals when not needed.
(default_goto, goto_actions, pack_vector): Remove unnecessary casts.
This commit is contained in:
Paul Eggert
2002-12-13 08:45:38 +00:00
parent deedb0b77c
commit ff5c8b8557

View File

@@ -1,4 +1,5 @@
/* Output the generated parsing program for Bison. /* Output the generated parsing program for Bison.
Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002 Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002
Free Software Foundation, Inc. Free Software Foundation, Inc.
@@ -42,10 +43,18 @@
Of course vector_number_t ought to be wide enough to contain Of course vector_number_t ought to be wide enough to contain
state_number and symbol_number. */ state_number and symbol_number. */
typedef short vector_number; typedef short vector_number;
#define state_number_to_vector_number(State) \
((vector_number) State) static inline vector_number
#define symbol_number_to_vector_number(Symbol) \ state_number_to_vector_number (state_number s)
((vector_number) (state_number_as_int (nstates) + Symbol - ntokens)) {
return s;
}
static inline vector_number
symbol_number_to_vector_number (symbol_number s)
{
return state_number_as_int (nstates) + s - ntokens;
}
int nvectors; int nvectors;
@@ -112,7 +121,7 @@ static int conflict_list_free;
/* TABLE_SIZE is the allocated size of both TABLE and CHECK. We start /* TABLE_SIZE is the allocated size of both TABLE and CHECK. We start
with more or less the original hard-coded value (which was with more or less the original hard-coded value (which was
SHRT_MAX). */ SHRT_MAX). */
static size_t table_size = 32768; static int table_size = 32768;
base_number *table = NULL; base_number *table = NULL;
base_number *check = NULL; base_number *check = NULL;
/* The value used in TABLE to denote explicit syntax errors /* The value used in TABLE to denote explicit syntax errors
@@ -133,9 +142,9 @@ rule_number *yydefact;
`----------------------------------------------------------------*/ `----------------------------------------------------------------*/
static void static void
table_grow (size_t desired) table_grow (int desired)
{ {
size_t old_size = table_size; int old_size = table_size;
while (table_size <= desired) while (table_size <= desired)
table_size *= 2; table_size *= 2;
@@ -144,9 +153,9 @@ table_grow (size_t desired)
fprintf (stderr, "growing table and check from: %d to %d\n", fprintf (stderr, "growing table and check from: %d to %d\n",
old_size, table_size); old_size, table_size);
table = XREALLOC (table, base_number, table_size); REALLOC (table, table_size);
check = XREALLOC (check, base_number, table_size); REALLOC (check, table_size);
conflict_table = XREALLOC (conflict_table, unsigned int, table_size); REALLOC (conflict_table, table_size);
for (/* Nothing. */; old_size < table_size; ++old_size) for (/* Nothing. */; old_size < table_size; ++old_size)
{ {
@@ -355,10 +364,10 @@ save_row (state_number s)
{ {
symbol_number i; symbol_number i;
int count; int count;
base_number *sp = NULL; base_number *sp;
base_number *sp1 = NULL; base_number *sp1;
base_number *sp2 = NULL; base_number *sp2;
unsigned int *sp3 = NULL; unsigned int *sp3 IF_LINT (= NULL);
/* Number of non default actions in S. */ /* Number of non default actions in S. */
count = 0; count = 0;
@@ -370,12 +379,9 @@ save_row (state_number s)
return; return;
/* Allocate non defaulted actions. */ /* Allocate non defaulted actions. */
froms[s] = sp1 = sp = XCALLOC (base_number, count); froms[s] = sp = CALLOC (sp1, count);
tos[s] = sp2 = XCALLOC (base_number, count); tos[s] = CALLOC (sp2, count);
if (glr_parser) conflict_tos[s] = glr_parser ? CALLOC (sp3, count) : NULL;
conflict_tos[s] = sp3 = XCALLOC (unsigned int, count);
else
conflict_tos[s] = NULL;
/* Store non defaulted actions. */ /* Store non defaulted actions. */
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)
@@ -409,12 +415,12 @@ token_actions (void)
int nconflict = glr_parser ? conflicts_total_count () : 0; int nconflict = glr_parser ? conflicts_total_count () : 0;
yydefact = XCALLOC (rule_number, nstates); CALLOC (yydefact, nstates);
actrow = XCALLOC (action_number, ntokens); CALLOC (actrow, ntokens);
conflrow = XCALLOC (unsigned int, ntokens); CALLOC (conflrow, ntokens);
conflict_list = XCALLOC (unsigned int, 1 + 2 * nconflict); CALLOC (conflict_list, 1 + 2 * nconflict);
conflict_list_free = 2 * nconflict; conflict_list_free = 2 * nconflict;
conflict_list_cnt = 1; conflict_list_cnt = 1;
@@ -466,8 +472,8 @@ save_column (symbol_number sym, state_number default_state)
int count; int count;
vector_number symno = symbol_number_to_vector_number (sym); vector_number symno = symbol_number_to_vector_number (sym);
goto_number begin = goto_map[sym]; goto_number begin = goto_map[sym - ntokens];
goto_number end = goto_map[sym + 1]; goto_number end = goto_map[sym - ntokens + 1];
/* Number of non default GOTO. */ /* Number of non default GOTO. */
count = 0; count = 0;
@@ -479,8 +485,8 @@ save_column (symbol_number sym, state_number default_state)
return; return;
/* Allocate room for non defaulted gotos. */ /* Allocate room for non defaulted gotos. */
froms[symno] = sp1 = sp = XCALLOC (base_number, count); froms[symno] = sp = CALLOC (sp1, count);
tos[symno] = sp2 = XCALLOC (base_number, count); tos[symno] = CALLOC (sp2, count);
/* Store the state numbers of the non defaulted gotos. */ /* Store the state numbers of the non defaulted gotos. */
for (i = begin; i < end; i++) for (i = begin; i < end; i++)
@@ -504,13 +510,13 @@ default_goto (symbol_number sym, short state_count[])
{ {
state_number s; state_number s;
int i; int i;
goto_number m = goto_map[sym]; goto_number m = goto_map[sym - ntokens];
goto_number n = goto_map[sym + 1]; goto_number n = goto_map[sym - ntokens + 1];
state_number default_state = (state_number) -1; state_number default_state = -1;
int max = 0; int max = 0;
if (m == n) if (m == n)
return (state_number) -1; return -1;
for (s = 0; s < nstates; s++) for (s = 0; s < nstates; s++)
state_count[s] = 0; state_count[s] = 0;
@@ -542,8 +548,8 @@ static void
goto_actions (void) goto_actions (void)
{ {
symbol_number i; symbol_number i;
short *state_count = XCALLOC (short, nstates); short *state_count = CALLOC (state_count, nstates);
yydefgoto = XMALLOC (state_number, nvars); MALLOC (yydefgoto, nvars);
/* For a given nterm I, STATE_COUNT[S] is the number of times there /* For a given nterm I, STATE_COUNT[S] is the number of times there
is a GOTO to S on I. */ is a GOTO to S on I. */
@@ -607,7 +613,7 @@ matching_state (vector_number vector)
int prev; int prev;
/* If VECTOR is a nterm, return -1. */ /* If VECTOR is a nterm, return -1. */
if (i >= (int) nstates) if (nstates <= i)
return -1; return -1;
t = tally[i]; t = tally[i];
@@ -665,13 +671,13 @@ pack_vector (vector_number vector)
int k; int k;
int ok = 1; int ok = 1;
if ((int) table_size <= j) if (table_size <= j)
abort (); abort ();
for (k = 0; ok && k < t; k++) for (k = 0; ok && k < t; k++)
{ {
loc = j + state_number_as_int (from[k]); loc = j + state_number_as_int (from[k]);
if (loc >= (int) table_size) if (table_size <= loc)
table_grow (loc); table_grow (loc);
if (table[loc] != 0) if (table[loc] != 0)
@@ -716,10 +722,10 @@ pack_vector (vector_number vector)
`-------------------------------------------------------------*/ `-------------------------------------------------------------*/
static base_number static base_number
table_ninf_remap (base_number tab[], size_t size, base_number ninf) table_ninf_remap (base_number tab[], int size, base_number ninf)
{ {
base_number res = 0; base_number res = 0;
size_t i; int i;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
if (tab[i] < res && tab[i] != ninf) if (tab[i] < res && tab[i] != ninf)
@@ -739,11 +745,11 @@ pack_table (void)
{ {
int i; int i;
base = XCALLOC (base_number, nvectors); CALLOC (base, nvectors);
pos = XCALLOC (base_number, nentries); CALLOC (pos, nentries);
table = XCALLOC (base_number, table_size); CALLOC (table, table_size);
conflict_table = XCALLOC (unsigned int, table_size); CALLOC (conflict_table, table_size);
check = XCALLOC (base_number, table_size); CALLOC (check, table_size);
lowzero = 0; lowzero = 0;
high = 0; high = 0;
@@ -751,7 +757,7 @@ pack_table (void)
for (i = 0; i < nvectors; i++) for (i = 0; i < nvectors; i++)
base[i] = BASE_MINIMUM; base[i] = BASE_MINIMUM;
for (i = 0; i < (int) table_size; i++) for (i = 0; i < table_size; i++)
check[i] = -1; check[i] = -1;
for (i = 0; i < nentries; i++) for (i = 0; i < nentries; i++)
@@ -798,20 +804,20 @@ tables_generate (void)
nvectors = state_number_as_int (nstates) + nvars; nvectors = state_number_as_int (nstates) + nvars;
froms = XCALLOC (base_number *, nvectors); CALLOC (froms, nvectors);
tos = XCALLOC (base_number *, nvectors); CALLOC (tos, nvectors);
conflict_tos = XCALLOC (unsigned int *, nvectors); CALLOC (conflict_tos, nvectors);
tally = XCALLOC (short, nvectors); CALLOC (tally, nvectors);
width = XCALLOC (base_number, nvectors); CALLOC (width, nvectors);
token_actions (); token_actions ();
goto_actions (); goto_actions ();
free (goto_map + ntokens); free (goto_map);
free (from_state); free (from_state);
free (to_state); free (to_state);
order = XCALLOC (vector_number, nvectors); CALLOC (order, nvectors);
sort_actions (); sort_actions ();
pack_table (); pack_table ();
free (order); free (order);