/[bison]/bison/src/tables.c
ViewVC logotype

Diff of /bison/src/tables.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.15 by eggert, Wed Dec 11 06:54:42 2002 UTC revision 1.16 by eggert, Fri Dec 13 08:45:38 2002 UTC
# Line 1  Line 1 
1  /* Output the generated parsing program for Bison.  /* Output the generated parsing program for Bison.
2    
3     Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002     Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002
4     Free Software Foundation, Inc.     Free Software Foundation, Inc.
5    
# Line 42  Line 43 
43     Of course vector_number_t ought to be wide enough to contain     Of course vector_number_t ought to be wide enough to contain
44     state_number and symbol_number.  */     state_number and symbol_number.  */
45  typedef short vector_number;  typedef short vector_number;
46  #define state_number_to_vector_number(State) \  
47     ((vector_number) State)  static inline vector_number
48  #define symbol_number_to_vector_number(Symbol) \  state_number_to_vector_number (state_number s)
49     ((vector_number) (state_number_as_int (nstates) + Symbol - ntokens))  {
50      return s;
51    }
52    
53    static inline vector_number
54    symbol_number_to_vector_number (symbol_number s)
55    {
56      return state_number_as_int (nstates) + s - ntokens;
57    }
58    
59  int nvectors;  int nvectors;
60    
# Line 112  static int conflict_list_free; Line 121  static int conflict_list_free;
121  /* 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
122     with more or less the original hard-coded value (which was     with more or less the original hard-coded value (which was
123     SHRT_MAX).  */     SHRT_MAX).  */
124  static size_t table_size = 32768;  static int table_size = 32768;
125  base_number *table = NULL;  base_number *table = NULL;
126  base_number *check = NULL;  base_number *check = NULL;
127  /* The value used in TABLE to denote explicit syntax errors  /* The value used in TABLE to denote explicit syntax errors
# Line 133  rule_number *yydefact; Line 142  rule_number *yydefact;
142  `----------------------------------------------------------------*/  `----------------------------------------------------------------*/
143    
144  static void  static void
145  table_grow (size_t desired)  table_grow (int desired)
146  {  {
147    size_t old_size = table_size;    int old_size = table_size;
148    
149    while (table_size <= desired)    while (table_size <= desired)
150      table_size *= 2;      table_size *= 2;
# Line 144  table_grow (size_t desired) Line 153  table_grow (size_t desired)
153      fprintf (stderr, "growing table and check from: %d to %d\n",      fprintf (stderr, "growing table and check from: %d to %d\n",
154               old_size, table_size);               old_size, table_size);
155    
156    table = XREALLOC (table, base_number, table_size);    REALLOC (table, table_size);
157    check = XREALLOC (check, base_number, table_size);    REALLOC (check, table_size);
158    conflict_table = XREALLOC (conflict_table, unsigned int, table_size);    REALLOC (conflict_table, table_size);
159    
160    for (/* Nothing. */; old_size < table_size; ++old_size)    for (/* Nothing. */; old_size < table_size; ++old_size)
161      {      {
# Line 355  save_row (state_number s) Line 364  save_row (state_number s)
364  {  {
365    symbol_number i;    symbol_number i;
366    int count;    int count;
367    base_number *sp = NULL;    base_number *sp;
368    base_number *sp1 = NULL;    base_number *sp1;
369    base_number *sp2 = NULL;    base_number *sp2;
370    unsigned int *sp3 = NULL;    unsigned int *sp3 IF_LINT (= NULL);
371    
372    /* Number of non default actions in S.  */    /* Number of non default actions in S.  */
373    count = 0;    count = 0;
# Line 370  save_row (state_number s) Line 379  save_row (state_number s)
379      return;      return;
380    
381    /* Allocate non defaulted actions.  */    /* Allocate non defaulted actions.  */
382    froms[s] = sp1 = sp = XCALLOC (base_number, count);    froms[s] = sp = CALLOC (sp1, count);
383    tos[s] = sp2 = XCALLOC (base_number, count);    tos[s] = CALLOC (sp2, count);
384    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;  
385    
386    /* Store non defaulted actions.  */    /* Store non defaulted actions.  */
387    for (i = 0; i < ntokens; i++)    for (i = 0; i < ntokens; i++)
# Line 409  token_actions (void) Line 415  token_actions (void)
415    
416    int nconflict = glr_parser ? conflicts_total_count () : 0;    int nconflict = glr_parser ? conflicts_total_count () : 0;
417    
418    yydefact = XCALLOC (rule_number, nstates);    CALLOC (yydefact, nstates);
419    
420    actrow = XCALLOC (action_number, ntokens);    CALLOC (actrow, ntokens);
421    conflrow = XCALLOC (unsigned int, ntokens);    CALLOC (conflrow, ntokens);
422    
423    conflict_list = XCALLOC (unsigned int, 1 + 2 * nconflict);    CALLOC (conflict_list, 1 + 2 * nconflict);
424    conflict_list_free = 2 * nconflict;    conflict_list_free = 2 * nconflict;
425    conflict_list_cnt = 1;    conflict_list_cnt = 1;
426    
# Line 466  save_column (symbol_number sym, state_nu Line 472  save_column (symbol_number sym, state_nu
472    int count;    int count;
473    vector_number symno = symbol_number_to_vector_number (sym);    vector_number symno = symbol_number_to_vector_number (sym);
474    
475    goto_number begin = goto_map[sym];    goto_number begin = goto_map[sym - ntokens];
476    goto_number end = goto_map[sym + 1];    goto_number end = goto_map[sym - ntokens + 1];
477    
478    /* Number of non default GOTO.  */    /* Number of non default GOTO.  */
479    count = 0;    count = 0;
# Line 479  save_column (symbol_number sym, state_nu Line 485  save_column (symbol_number sym, state_nu
485      return;      return;
486    
487    /* Allocate room for non defaulted gotos.  */    /* Allocate room for non defaulted gotos.  */
488    froms[symno] = sp1 = sp = XCALLOC (base_number, count);    froms[symno] = sp = CALLOC (sp1, count);
489    tos[symno] = sp2 = XCALLOC (base_number, count);    tos[symno] = CALLOC (sp2, count);
490    
491    /* Store the state numbers of the non defaulted gotos.  */    /* Store the state numbers of the non defaulted gotos.  */
492    for (i = begin; i < end; i++)    for (i = begin; i < end; i++)
# Line 504  default_goto (symbol_number sym, short s Line 510  default_goto (symbol_number sym, short s
510  {  {
511    state_number s;    state_number s;
512    int i;    int i;
513    goto_number m = goto_map[sym];    goto_number m = goto_map[sym - ntokens];
514    goto_number n = goto_map[sym + 1];    goto_number n = goto_map[sym - ntokens + 1];
515    state_number default_state = (state_number) -1;    state_number default_state = -1;
516    int max = 0;    int max = 0;
517    
518    if (m == n)    if (m == n)
519      return (state_number) -1;      return -1;
520    
521    for (s = 0; s < nstates; s++)    for (s = 0; s < nstates; s++)
522      state_count[s] = 0;      state_count[s] = 0;
# Line 542  static void Line 548  static void
548  goto_actions (void)  goto_actions (void)
549  {  {
550    symbol_number i;    symbol_number i;
551    short *state_count = XCALLOC (short, nstates);    short *state_count = CALLOC (state_count, nstates);
552    yydefgoto = XMALLOC (state_number, nvars);    MALLOC (yydefgoto, nvars);
553    
554    /* 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
555       is a GOTO to S on I.  */       is a GOTO to S on I.  */
# Line 607  matching_state (vector_number vector) Line 613  matching_state (vector_number vector)
613    int prev;    int prev;
614    
615    /* If VECTOR is a nterm, return -1.  */    /* If VECTOR is a nterm, return -1.  */
616    if (i >= (int) nstates)    if (nstates <= i)
617      return -1;      return -1;
618    
619    t = tally[i];    t = tally[i];
# Line 665  pack_vector (vector_number vector) Line 671  pack_vector (vector_number vector)
671        int k;        int k;
672        int ok = 1;        int ok = 1;
673    
674        if ((int) table_size <= j)        if (table_size <= j)
675          abort ();          abort ();
676    
677        for (k = 0; ok && k < t; k++)        for (k = 0; ok && k < t; k++)
678          {          {
679            loc = j + state_number_as_int (from[k]);            loc = j + state_number_as_int (from[k]);
680            if (loc >= (int) table_size)            if (table_size <= loc)
681              table_grow (loc);              table_grow (loc);
682    
683            if (table[loc] != 0)            if (table[loc] != 0)
# Line 716  pack_vector (vector_number vector) Line 722  pack_vector (vector_number vector)
722  `-------------------------------------------------------------*/  `-------------------------------------------------------------*/
723    
724  static base_number  static base_number
725  table_ninf_remap (base_number tab[], size_t size, base_number ninf)  table_ninf_remap (base_number tab[], int size, base_number ninf)
726  {  {
727    base_number res = 0;    base_number res = 0;
728    size_t i;    int i;
729    
730    for (i = 0; i < size; i++)    for (i = 0; i < size; i++)
731      if (tab[i] < res && tab[i] != ninf)      if (tab[i] < res && tab[i] != ninf)
# Line 739  pack_table (void) Line 745  pack_table (void)
745  {  {
746    int i;    int i;
747    
748    base = XCALLOC (base_number, nvectors);    CALLOC (base, nvectors);
749    pos = XCALLOC (base_number, nentries);    CALLOC (pos, nentries);
750    table = XCALLOC (base_number, table_size);    CALLOC (table, table_size);
751    conflict_table = XCALLOC (unsigned int, table_size);    CALLOC (conflict_table, table_size);
752    check = XCALLOC (base_number, table_size);    CALLOC (check, table_size);
753    
754    lowzero = 0;    lowzero = 0;
755    high = 0;    high = 0;
# Line 751  pack_table (void) Line 757  pack_table (void)
757    for (i = 0; i < nvectors; i++)    for (i = 0; i < nvectors; i++)
758      base[i] = BASE_MINIMUM;      base[i] = BASE_MINIMUM;
759    
760    for (i = 0; i < (int) table_size; i++)    for (i = 0; i < table_size; i++)
761      check[i] = -1;      check[i] = -1;
762    
763    for (i = 0; i < nentries; i++)    for (i = 0; i < nentries; i++)
# Line 798  tables_generate (void) Line 804  tables_generate (void)
804    
805    nvectors = state_number_as_int (nstates) + nvars;    nvectors = state_number_as_int (nstates) + nvars;
806    
807    froms = XCALLOC (base_number *, nvectors);    CALLOC (froms, nvectors);
808    tos = XCALLOC (base_number *, nvectors);    CALLOC (tos, nvectors);
809    conflict_tos = XCALLOC (unsigned int *, nvectors);    CALLOC (conflict_tos, nvectors);
810    tally = XCALLOC (short, nvectors);    CALLOC (tally, nvectors);
811    width = XCALLOC (base_number, nvectors);    CALLOC (width, nvectors);
812    
813    token_actions ();    token_actions ();
814    
815    goto_actions ();    goto_actions ();
816    free (goto_map + ntokens);    free (goto_map);
817    free (from_state);    free (from_state);
818    free (to_state);    free (to_state);
819    
820    order = XCALLOC (vector_number, nvectors);    CALLOC (order, nvectors);
821    sort_actions ();    sort_actions ();
822    pack_table ();    pack_table ();
823    free (order);    free (order);

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26