+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>
* data/lalr1.cc: Extensive Doxygenation.
Note that useless productions (hence useless nonterminals) are
browsed too, hence we need to allocate room for _all_ the
symbols. */
- int count = 0;
- short int *symbol_count = xcalloc (nsyms + nuseless_nonterminals,
- sizeof *symbol_count);
+ 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)
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);
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)
/* NITEMSET is the size of the array ITEMSET. */
item_number *itemset;
-int nritemset;
+size_t nritemset;
static bitset ruleset;
void
-closure (item_number *core, int n)
+closure (item_number *core, size_t n)
{
/* Index over CORE. */
- int c;
+ size_t c;
/* A bit index over RULESET. */
rule_number ruleno;
significant). CLOSURE places there the indices of all items which
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. */
void free_closure (void);
extern item_number *itemset;
-extern int nritemset;
+extern size_t nritemset;
#endif /* !CLOSURE_H_ */
}
/* Rule numbers. */
-typedef short int rule_number;
+typedef int rule_number;
extern rule_number nrules;
static inline item_number
/* This symbol provides both the associativity, and the precedence. */
symbol *prec;
- short int dprec;
- short int merger;
+ int dprec;
+ int merger;
/* This symbol was attached to the rule via %prec. */
symbol *precsym;
rule_list *p;
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.
Hence we must allocate room for useless nonterminals too. */
rule_list **rsets = xcalloc (nvars, sizeof *rsets);
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_short_int_table, short int)
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_symbol_number_table, symbol_number)
unsigned int *rline = xnmalloc (nrules, sizeof *rline);
symbol_number *r1 = xnmalloc (nrules, sizeof *r1);
unsigned int *r2 = xnmalloc (nrules, sizeof *r2);
- short int *dprec = xnmalloc (nrules, sizeof *dprec);
- short int *merger = xnmalloc (nrules, sizeof *merger);
+ int *dprec = xnmalloc (nrules, sizeof *dprec);
+ int *merger = xnmalloc (nrules, sizeof *merger);
for (r = 0; r < nrules; ++r)
{
muscle_insert_unsigned_int_table ("rline", rline, 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_short_int_table ("dprec", dprec, 0, 0, nrules);
- muscle_insert_short_int_table ("merger", merger, 0, 0, nrules);
+ muscle_insert_int_table ("dprec", dprec, 0, 0, nrules);
+ muscle_insert_int_table ("merger", merger, 0, 0, nrules);
MUSCLE_INSERT_INT ("rules_number", nrules);
MUSCLE_INSERT_INT ("max_left_semantic_context", max_left_semantic_context);
static void
print_core (FILE *out, state *s)
{
- int i;
+ size_t i;
item_number *sitems = s->items;
- int snritems = s->nitems;
+ size_t snritems = s->nitems;
symbol *previous_lhs = NULL;
/* Output all the items of a state, not only its kernel. */
static void
print_core (struct obstack *oout, state *s)
{
- int i;
+ size_t i;
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. */
if (report_flag & report_itemsets)
static inline bool
state_compare (state const *s1, state const *s2)
{
- int i;
+ size_t i;
if (s1->nitems != s2->nitems)
return false;
{
/* Add up the state's item numbers to get a hash key. */
size_t key = 0;
- int i;
+ size_t i;
for (i = 0; i < s->nitems; ++i)
key += s->items[i];
return key % tablesize;
| Numbering states. |
`-------------------*/
-typedef short int state_number;
-# define STATE_NUMBER_MAXIMUM SHRT_MAX
+typedef int state_number;
+# define STATE_NUMBER_MAXIMUM INT_MAX
/* Be ready to map a state_number to an int. */
static inline int
typedef struct
{
- short int num;
+ int num;
state *states[1];
} transitions;
typedef struct
{
- short int num;
+ int num;
symbol *symbols[1];
} errs;
typedef struct
{
- short int num;
+ int num;
bitset *look_ahead_tokens;
rule *rules[1];
} reductions;
/* Its items. Must be last, since ITEMS can be arbitrarily large.
*/
- unsigned short int nitems;
+ size_t nitems;
item_number items[1];
};
/* Internal token numbers. */
-typedef short int symbol_number;
-#define SYMBOL_NUMBER_MAXIMUM SHRT_MAX
+typedef int symbol_number;
+#define SYMBOL_NUMBER_MAXIMUM INT_MAX
typedef struct symbol symbol;
symbol_number number;
location prec_location;
- short int prec;
+ int prec;
assoc assoc;
int user_token_number;
Of course vector_number_t ought to be wide enough to contain
state_number and symbol_number. */
-typedef short int vector_number;
+typedef int vector_number;
static inline vector_number
state_number_to_vector_number (state_number s)
static base_number **froms;
static base_number **tos;
static unsigned int **conflict_tos;
-static short int *tally;
+static int *tally;
static base_number *width;
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 `reduce -N'. */
-typedef short int action_number;
-#define ACTION_NUMBER_MINIMUM SHRT_MIN
+typedef int action_number;
+#define ACTION_NUMBER_MINIMUM INT_MIN
static action_number *actrow;
`-------------------------------------------------------------*/
static state_number
-default_goto (symbol_number sym, short int state_count[])
+default_goto (symbol_number sym, size_t state_count[])
{
state_number s;
goto_number i;
goto_number m = goto_map[sym - ntokens];
goto_number n = goto_map[sym - ntokens + 1];
state_number default_state = -1;
- int max = 0;
+ size_t max = 0;
if (m == n)
return -1;
goto_actions (void)
{
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);
/* For a given nterm I, STATE_COUNT[S] is the number of times there