Remove uses of 'short int' and 'unsigned short int' in the parser generators.

* src/LR0.c (allocate_itemsets, new_itemsets, save_reductions):
Use size_t, not int or short int, to count objects.
* src/closure.c (nritemset, closure): Likewise.
* src/closure.h (nritemset, closure): Likewise.
* src/nullable.c (nullable_compute): Likewise.
* src/print.c (print_core): Likewise.
* src/print_graph.c (print_core): Likewise.
* src/state.c (state_compare, state_hash): Likewise.
* src/state.h (struct state): Likewise.
* src/tables.c (default_goto, goto_actions): Likewise.

* src/gram.h (rule_number, rule): Use int, not short int.
* src/output.c (prepare_rules): Likewise.
* src/state.h (state_number, STATE_NUMBER_MAXIMUM, transitions,
errs, reductions): Likewise.
* src/symtab.h (symbol_number, SYMBOL_NUMBER_MAXIMUM, struct symbol):
Likewise.
* src/tables.c (vector_number, tally, action_number,
ACTION_NUMBER_MINIMUM): Likewise.
* src/output.c (muscle_insert_short_int_table): Remove.
This commit is contained in:
Paul Eggert
2004-12-17 20:29:19 +00:00
parent efeed02327
commit f6fbd3da9d
13 changed files with 75 additions and 41 deletions

View File

@@ -1,3 +1,38 @@
2004-12-17 Paul Eggert <eggert@cs.ucla.edu>
Remove uses of 'short int' and 'unsigned short int'. This raises
some arbitrary limits. It uses more memory but nowadays that's
not much of an issue.
This change does not affect the generated parsers; that's a different
task, as some users will want to conserve memory there.
Ideally we should use size_t to represent all object counts, and
something like ptrdiff_t to represent signed differences of object
counts; but that will require more code-cleanup than I have the
time to do right now.
* src/LR0.c (allocate_itemsets, new_itemsets, save_reductions):
Use size_t, not int or short int, to count objects.
* src/closure.c (nritemset, closure): Likewise.
* src/closure.h (nritemset, closure): Likewise.
* src/nullable.c (nullable_compute): Likewise.
* src/print.c (print_core): Likewise.
* src/print_graph.c (print_core): Likewise.
* src/state.c (state_compare, state_hash): Likewise.
* src/state.h (struct state): Likewise.
* src/tables.c (default_goto, goto_actions): Likewise.
* src/gram.h (rule_number, rule): Use int, not short int.
* src/output.c (prepare_rules): Likewise.
* src/state.h (state_number, STATE_NUMBER_MAXIMUM, transitions,
errs, reductions): Likewise.
* src/symtab.h (symbol_number, SYMBOL_NUMBER_MAXIMUM, struct symbol):
Likewise.
* src/tables.c (vector_number, tally, action_number,
ACTION_NUMBER_MINIMUM): Likewise.
* src/output.c (muscle_insert_short_int_table): Remove.
2004-12-17 Akim Demaille <akim@epita.fr> 2004-12-17 Akim Demaille <akim@epita.fr>
* data/lalr1.cc: Extensive Doxygenation. * data/lalr1.cc: Extensive Doxygenation.

View File

@@ -105,9 +105,9 @@ allocate_itemsets (void)
Note that useless productions (hence useless nonterminals) are Note that useless productions (hence useless nonterminals) are
browsed too, hence we need to allocate room for _all_ the browsed too, hence we need to allocate room for _all_ the
symbols. */ symbols. */
int count = 0; size_t count = 0;
short int *symbol_count = xcalloc (nsyms + nuseless_nonterminals, size_t *symbol_count = xcalloc (nsyms + nuseless_nonterminals,
sizeof *symbol_count); sizeof *symbol_count);
for (r = 0; r < nrules; ++r) for (r = 0; r < nrules; ++r)
for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
@@ -178,7 +178,7 @@ free_storage (void)
static void static void
new_itemsets (state *s) new_itemsets (state *s)
{ {
int i; size_t i;
if (trace_flag & trace_automaton) if (trace_flag & trace_automaton)
fprintf (stderr, "Entering new_itemsets, state = %d\n", s->number); fprintf (stderr, "Entering new_itemsets, state = %d\n", s->number);
@@ -274,7 +274,7 @@ static void
save_reductions (state *s) save_reductions (state *s)
{ {
int count = 0; int count = 0;
int i; size_t i;
/* Find and count the active items that represent ends of rules. */ /* Find and count the active items that represent ends of rules. */
for (i = 0; i < nritemset; ++i) for (i = 0; i < nritemset; ++i)

View File

@@ -36,7 +36,7 @@
/* NITEMSET is the size of the array ITEMSET. */ /* NITEMSET is the size of the array ITEMSET. */
item_number *itemset; item_number *itemset;
int nritemset; size_t nritemset;
static bitset ruleset; static bitset ruleset;
@@ -193,10 +193,10 @@ new_closure (unsigned int n)
void void
closure (item_number *core, int n) closure (item_number *core, size_t n)
{ {
/* Index over CORE. */ /* Index over CORE. */
int c; size_t c;
/* A bit index over RULESET. */ /* A bit index over RULESET. */
rule_number ruleno; rule_number ruleno;

View File

@@ -46,7 +46,7 @@ void new_closure (unsigned int n);
significant). CLOSURE places there the indices of all items which significant). CLOSURE places there the indices of all items which
represent units of input that could arrive next. */ represent units of input that could arrive next. */
void closure (item_number *items, int n); void closure (item_number *items, size_t n);
/* Frees ITEMSET, RULESET and internal data. */ /* Frees ITEMSET, RULESET and internal data. */
@@ -54,6 +54,6 @@ void closure (item_number *items, int n);
void free_closure (void); void free_closure (void);
extern item_number *itemset; extern item_number *itemset;
extern int nritemset; extern size_t nritemset;
#endif /* !CLOSURE_H_ */ #endif /* !CLOSURE_H_ */

View File

@@ -139,7 +139,7 @@ item_number_as_symbol_number (item_number i)
} }
/* Rule numbers. */ /* Rule numbers. */
typedef short int rule_number; typedef int rule_number;
extern rule_number nrules; extern rule_number nrules;
static inline item_number static inline item_number
@@ -175,8 +175,8 @@ typedef struct
/* This symbol provides both the associativity, and the precedence. */ /* This symbol provides both the associativity, and the precedence. */
symbol *prec; symbol *prec;
short int dprec; int dprec;
short int merger; int merger;
/* This symbol was attached to the rule via %prec. */ /* This symbol was attached to the rule via %prec. */
symbol *precsym; symbol *precsym;

View File

@@ -62,7 +62,7 @@ nullable_compute (void)
rule_list *p; rule_list *p;
symbol_number *squeue = xnmalloc (nvars, sizeof *squeue); symbol_number *squeue = xnmalloc (nvars, sizeof *squeue);
short int *rcount = xcalloc (nrules, sizeof *rcount); size_t *rcount = xcalloc (nrules, sizeof *rcount);
/* RITEM contains all the rules, including useless productions. /* RITEM contains all the rules, including useless productions.
Hence we must allocate room for useless nonterminals too. */ Hence we must allocate room for useless nonterminals too. */
rule_list **rsets = xcalloc (nvars, sizeof *rsets); rule_list **rsets = xcalloc (nvars, sizeof *rsets);

View File

@@ -106,7 +106,6 @@ Name (const char *name, \
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_unsigned_int_table, unsigned int) GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_unsigned_int_table, unsigned int)
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_int_table, int) GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_int_table, int)
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_short_int_table, short int)
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_base_table, base_number) GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_base_table, base_number)
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_rule_number_table, rule_number) GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_rule_number_table, rule_number)
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_symbol_number_table, symbol_number) GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_symbol_number_table, symbol_number)
@@ -217,8 +216,8 @@ prepare_rules (void)
unsigned int *rline = xnmalloc (nrules, sizeof *rline); unsigned int *rline = xnmalloc (nrules, sizeof *rline);
symbol_number *r1 = xnmalloc (nrules, sizeof *r1); symbol_number *r1 = xnmalloc (nrules, sizeof *r1);
unsigned int *r2 = xnmalloc (nrules, sizeof *r2); unsigned int *r2 = xnmalloc (nrules, sizeof *r2);
short int *dprec = xnmalloc (nrules, sizeof *dprec); int *dprec = xnmalloc (nrules, sizeof *dprec);
short int *merger = xnmalloc (nrules, sizeof *merger); int *merger = xnmalloc (nrules, sizeof *merger);
for (r = 0; r < nrules; ++r) for (r = 0; r < nrules; ++r)
{ {
@@ -249,8 +248,8 @@ prepare_rules (void)
muscle_insert_unsigned_int_table ("rline", rline, 0, 0, nrules); muscle_insert_unsigned_int_table ("rline", rline, 0, 0, nrules);
muscle_insert_symbol_number_table ("r1", r1, 0, 0, nrules); muscle_insert_symbol_number_table ("r1", r1, 0, 0, nrules);
muscle_insert_unsigned_int_table ("r2", r2, 0, 0, nrules); muscle_insert_unsigned_int_table ("r2", r2, 0, 0, nrules);
muscle_insert_short_int_table ("dprec", dprec, 0, 0, nrules); muscle_insert_int_table ("dprec", dprec, 0, 0, nrules);
muscle_insert_short_int_table ("merger", merger, 0, 0, nrules); muscle_insert_int_table ("merger", merger, 0, 0, nrules);
MUSCLE_INSERT_INT ("rules_number", nrules); MUSCLE_INSERT_INT ("rules_number", nrules);
MUSCLE_INSERT_INT ("max_left_semantic_context", max_left_semantic_context); MUSCLE_INSERT_INT ("max_left_semantic_context", max_left_semantic_context);

View File

@@ -71,9 +71,9 @@ max_length (size_t *width, const char *str)
static void static void
print_core (FILE *out, state *s) print_core (FILE *out, state *s)
{ {
int i; size_t i;
item_number *sitems = s->items; item_number *sitems = s->items;
int snritems = s->nitems; size_t snritems = s->nitems;
symbol *previous_lhs = NULL; symbol *previous_lhs = NULL;
/* Output all the items of a state, not only its kernel. */ /* Output all the items of a state, not only its kernel. */

View File

@@ -49,9 +49,9 @@ static FILE *fgraph = NULL;
static void static void
print_core (struct obstack *oout, state *s) print_core (struct obstack *oout, state *s)
{ {
int i; size_t i;
item_number *sitems = s->items; item_number *sitems = s->items;
int snritems = s->nitems; size_t snritems = s->nitems;
/* Output all the items of a state, not only its kernel. */ /* Output all the items of a state, not only its kernel. */
if (report_flag & report_itemsets) if (report_flag & report_itemsets)

View File

@@ -261,7 +261,7 @@ static struct hash_table *state_table = NULL;
static inline bool static inline bool
state_compare (state const *s1, state const *s2) state_compare (state const *s1, state const *s2)
{ {
int i; size_t i;
if (s1->nitems != s2->nitems) if (s1->nitems != s2->nitems)
return false; return false;
@@ -284,7 +284,7 @@ state_hash (state const *s, size_t tablesize)
{ {
/* Add up the state's item numbers to get a hash key. */ /* Add up the state's item numbers to get a hash key. */
size_t key = 0; size_t key = 0;
int i; size_t i;
for (i = 0; i < s->nitems; ++i) for (i = 0; i < s->nitems; ++i)
key += s->items[i]; key += s->items[i];
return key % tablesize; return key % tablesize;

View File

@@ -94,8 +94,8 @@
| Numbering states. | | Numbering states. |
`-------------------*/ `-------------------*/
typedef short int state_number; typedef int state_number;
# define STATE_NUMBER_MAXIMUM SHRT_MAX # define STATE_NUMBER_MAXIMUM INT_MAX
/* Be ready to map a state_number to an int. */ /* Be ready to map a state_number to an int. */
static inline int static inline int
@@ -113,7 +113,7 @@ typedef struct state state;
typedef struct typedef struct
{ {
short int num; int num;
state *states[1]; state *states[1];
} transitions; } transitions;
@@ -171,7 +171,7 @@ struct state *transitions_to (transitions *shifts, symbol_number sym);
typedef struct typedef struct
{ {
short int num; int num;
symbol *symbols[1]; symbol *symbols[1];
} errs; } errs;
@@ -184,7 +184,7 @@ errs *errs_new (int num, symbol **tokens);
typedef struct typedef struct
{ {
short int num; int num;
bitset *look_ahead_tokens; bitset *look_ahead_tokens;
rule *rules[1]; rule *rules[1];
} reductions; } reductions;
@@ -212,7 +212,7 @@ struct state
/* Its items. Must be last, since ITEMS can be arbitrarily large. /* Its items. Must be last, since ITEMS can be arbitrarily large.
*/ */
unsigned short int nitems; size_t nitems;
item_number items[1]; item_number items[1];
}; };

View File

@@ -41,8 +41,8 @@ typedef enum
/* Internal token numbers. */ /* Internal token numbers. */
typedef short int symbol_number; typedef int symbol_number;
#define SYMBOL_NUMBER_MAXIMUM SHRT_MAX #define SYMBOL_NUMBER_MAXIMUM INT_MAX
typedef struct symbol symbol; typedef struct symbol symbol;
@@ -68,7 +68,7 @@ struct symbol
symbol_number number; symbol_number number;
location prec_location; location prec_location;
short int prec; int prec;
assoc assoc; assoc assoc;
int user_token_number; int user_token_number;

View File

@@ -42,7 +42,7 @@
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 int vector_number; typedef int vector_number;
static inline vector_number static inline vector_number
state_number_to_vector_number (state_number s) state_number_to_vector_number (state_number s)
@@ -84,7 +84,7 @@ int nvectors;
static base_number **froms; static base_number **froms;
static base_number **tos; static base_number **tos;
static unsigned int **conflict_tos; static unsigned int **conflict_tos;
static short int *tally; static int *tally;
static base_number *width; static base_number *width;
@@ -94,8 +94,8 @@ static base_number *width;
If N = MIN, stands for `raise a syntax error'. If N = MIN, stands for `raise a syntax error'.
If N > 0, stands for `shift SYMBOL and go to n'. If N > 0, stands for `shift SYMBOL and go to n'.
If N < 0, stands for `reduce -N'. */ If N < 0, stands for `reduce -N'. */
typedef short int action_number; typedef int action_number;
#define ACTION_NUMBER_MINIMUM SHRT_MIN #define ACTION_NUMBER_MINIMUM INT_MIN
static action_number *actrow; static action_number *actrow;
@@ -516,14 +516,14 @@ save_column (symbol_number sym, state_number default_state)
`-------------------------------------------------------------*/ `-------------------------------------------------------------*/
static state_number static state_number
default_goto (symbol_number sym, short int state_count[]) default_goto (symbol_number sym, size_t state_count[])
{ {
state_number s; state_number s;
goto_number i; goto_number i;
goto_number m = goto_map[sym - ntokens]; goto_number m = goto_map[sym - ntokens];
goto_number n = goto_map[sym - ntokens + 1]; goto_number n = goto_map[sym - ntokens + 1];
state_number default_state = -1; state_number default_state = -1;
int max = 0; size_t max = 0;
if (m == n) if (m == n)
return -1; return -1;
@@ -558,7 +558,7 @@ static void
goto_actions (void) goto_actions (void)
{ {
symbol_number i; symbol_number i;
short int *state_count = xnmalloc (nstates, sizeof *state_count); size_t *state_count = xnmalloc (nstates, sizeof *state_count);
yydefgoto = xnmalloc (nvars, sizeof *yydefgoto); yydefgoto = xnmalloc (nvars, sizeof *yydefgoto);
/* 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