bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

removal of some arbitrary 16-bit limits from Bison


From: Paul Eggert
Subject: removal of some arbitrary 16-bit limits from Bison
Date: Fri, 17 Dec 2004 12:40:05 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

It is annoying that Bison has 16-bit internal limits, e.g., it doesn't
allow more than 32767 symbols.  I installed the following obvious
patches to remove all the arbitrary internal limits related to the
'short' type.  Of course this doesn't fix all of Bison's problems
related to large grammars (among other things, m4 becomes a huge
bottleneck with large grammars, due to Bison's many O(N**2) algorithms
in m4 code, maybe worse) but one step at a time.

I did not attempt to tackle Bison's arbitrary 32-bit internal limits.
(That issue is less pressing.  :-)

2004-12-17  Paul Eggert  <address@hidden>

        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.

Index: src/LR0.c
===================================================================
RCS file: /cvsroot/bison/bison/src/LR0.c,v
retrieving revision 1.90
diff -p -u -r1.90 LR0.c
--- src/LR0.c   10 Dec 2004 07:48:43 -0000      1.90
+++ src/LR0.c   17 Dec 2004 20:27:58 -0000
@@ -105,9 +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 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)
@@ -178,7 +178,7 @@ 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);
@@ -274,7 +274,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)
Index: src/closure.c
===================================================================
RCS file: /cvsroot/bison/bison/src/closure.c,v
retrieving revision 1.69
diff -p -u -r1.69 closure.c
--- src/closure.c       10 Dec 2004 07:50:44 -0000      1.69
+++ src/closure.c       17 Dec 2004 20:27:58 -0000
@@ -36,7 +36,7 @@
 
 /* NITEMSET is the size of the array ITEMSET.  */
 item_number *itemset;
-int nritemset;
+size_t nritemset;
 
 static bitset ruleset;
 
@@ -193,10 +193,10 @@ new_closure (unsigned int n)
 
 
 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;
Index: src/closure.h
===================================================================
RCS file: /cvsroot/bison/bison/src/closure.h,v
retrieving revision 1.12
diff -p -u -r1.12 closure.h
--- src/closure.h       10 Dec 2004 07:50:44 -0000      1.12
+++ src/closure.h       17 Dec 2004 20:27:58 -0000
@@ -46,7 +46,7 @@ void new_closure (unsigned int n);
    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.  */
@@ -54,6 +54,6 @@ void closure (item_number *items, int n)
 void free_closure (void);
 
 extern item_number *itemset;
-extern int nritemset;
+extern size_t nritemset;
 
 #endif /* !CLOSURE_H_ */
Index: src/gram.h
===================================================================
RCS file: /cvsroot/bison/bison/src/gram.h,v
retrieving revision 1.55
diff -p -u -r1.55 gram.h
--- src/gram.h  31 Mar 2004 00:37:20 -0000      1.55
+++ src/gram.h  17 Dec 2004 20:27:58 -0000
@@ -139,7 +139,7 @@ item_number_as_symbol_number (item_numbe
 }
 
 /* Rule numbers.  */
-typedef short int rule_number;
+typedef int rule_number;
 extern rule_number nrules;
 
 static inline item_number
@@ -175,8 +175,8 @@ typedef struct
   /* 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;
Index: src/nullable.c
===================================================================
RCS file: /cvsroot/bison/bison/src/nullable.c,v
retrieving revision 1.44
diff -p -u -r1.44 nullable.c
--- src/nullable.c      10 Dec 2004 07:50:44 -0000      1.44
+++ src/nullable.c      17 Dec 2004 20:27:58 -0000
@@ -62,7 +62,7 @@ nullable_compute (void)
   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);
Index: src/output.c
===================================================================
RCS file: /cvsroot/bison/bison/src/output.c,v
retrieving revision 1.228
diff -p -u -r1.228 output.c
--- src/output.c        10 Dec 2004 07:50:44 -0000      1.228
+++ src/output.c        17 Dec 2004 20:27:58 -0000
@@ -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_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)
@@ -217,8 +216,8 @@ prepare_rules (void)
   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)
     {
@@ -249,8 +248,8 @@ prepare_rules (void)
   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);
Index: src/print.c
===================================================================
RCS file: /cvsroot/bison/bison/src/print.c,v
retrieving revision 1.95
diff -p -u -r1.95 print.c
--- src/print.c 21 Jun 2004 20:20:31 -0000      1.95
+++ src/print.c 17 Dec 2004 20:27:58 -0000
@@ -71,9 +71,9 @@ max_length (size_t *width, const char *s
 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.  */
Index: src/print_graph.c
===================================================================
RCS file: /cvsroot/bison/bison/src/print_graph.c,v
retrieving revision 1.56
diff -p -u -r1.56 print_graph.c
--- src/print_graph.c   16 Dec 2004 09:09:56 -0000      1.56
+++ src/print_graph.c   17 Dec 2004 20:27:58 -0000
@@ -49,9 +49,9 @@ static FILE *fgraph = NULL;
 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)
Index: src/state.c
===================================================================
RCS file: /cvsroot/bison/bison/src/state.c,v
retrieving revision 1.32
diff -p -u -r1.32 state.c
--- src/state.c 21 Jun 2004 20:20:31 -0000      1.32
+++ src/state.c 17 Dec 2004 20:27:58 -0000
@@ -261,7 +261,7 @@ static struct hash_table *state_table = 
 static inline bool
 state_compare (state const *s1, state const *s2)
 {
-  int i;
+  size_t i;
 
   if (s1->nitems != s2->nitems)
     return false;
@@ -284,7 +284,7 @@ state_hash (state const *s, size_t table
 {
   /* 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;
Index: src/state.h
===================================================================
RCS file: /cvsroot/bison/bison/src/state.h,v
retrieving revision 1.47
diff -p -u -r1.47 state.h
--- src/state.h 21 Jun 2004 20:20:31 -0000      1.47
+++ src/state.h 17 Dec 2004 20:27:58 -0000
@@ -94,8 +94,8 @@
 | 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
@@ -113,7 +113,7 @@ typedef struct state state;
 
 typedef struct
 {
-  short int num;
+  int num;
   state *states[1];
 } transitions;
 
@@ -171,7 +171,7 @@ struct state *transitions_to (transition
 
 typedef struct
 {
-  short int num;
+  int num;
   symbol *symbols[1];
 } errs;
 
@@ -184,7 +184,7 @@ errs *errs_new (int num, symbol **tokens
 
 typedef struct
 {
-  short int num;
+  int num;
   bitset *look_ahead_tokens;
   rule *rules[1];
 } reductions;
@@ -212,7 +212,7 @@ struct state
 
   /* Its items.  Must be last, since ITEMS can be arbitrarily large.
      */
-  unsigned short int nitems;
+  size_t nitems;
   item_number items[1];
 };
 
Index: src/symtab.h
===================================================================
RCS file: /cvsroot/bison/bison/src/symtab.h,v
retrieving revision 1.53
diff -p -u -r1.53 symtab.h
--- src/symtab.h        11 Oct 2004 09:03:55 -0000      1.53
+++ src/symtab.h        17 Dec 2004 20:27:58 -0000
@@ -41,8 +41,8 @@ typedef enum
 
 
 /* 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;
@@ -68,7 +68,7 @@ struct symbol
 
   symbol_number number;
   location prec_location;
-  short int prec;
+  int prec;
   assoc assoc;
   int user_token_number;
 
Index: src/tables.c
===================================================================
RCS file: /cvsroot/bison/bison/src/tables.c,v
retrieving revision 1.24
diff -p -u -r1.24 tables.c
--- src/tables.c        10 Dec 2004 07:50:44 -0000      1.24
+++ src/tables.c        17 Dec 2004 20:27:58 -0000
@@ -42,7 +42,7 @@
 
    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)
@@ -84,7 +84,7 @@ int nvectors;
 static base_number **froms;
 static base_number **tos;
 static unsigned int **conflict_tos;
-static short int *tally;
+static int *tally;
 static base_number *width;
 
 
@@ -94,8 +94,8 @@ 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;
 
@@ -516,14 +516,14 @@ save_column (symbol_number sym, state_nu
 `-------------------------------------------------------------*/
 
 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;
@@ -558,7 +558,7 @@ static void
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]