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

Diff of /bison/src/conflicts.c

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

revision 1.66 by akim, Sun Jan 6 20:49:53 2002 UTC revision 1.67 by akim, Mon Mar 4 12:03:35 2002 UTC
# Line 1  Line 1 
1  /* Find and resolve or report look-ahead conflicts for bison,  /* Find and resolve or report look-ahead conflicts for bison,
2     Copyright 1984, 1989, 1992, 2000, 2001 Free Software Foundation, Inc.     Copyright 1984, 1989, 1992, 2000, 2001, 2002 Free Software Foundation, Inc.
3    
4     This file is part of Bison, the GNU Compiler Compiler.     This file is part of Bison, the GNU Compiler Compiler.
5    
# Line 19  Line 19 
19     02111-1307, USA.  */     02111-1307, USA.  */
20    
21  #include "system.h"  #include "system.h"
22    #include "bitset.h"
23  #include "complain.h"  #include "complain.h"
24  #include "getargs.h"  #include "getargs.h"
25  #include "symtab.h"  #include "symtab.h"
# Line 78  flush_shift (state_t *state, int token) Line 79  flush_shift (state_t *state, int token)
79  static void  static void
80  flush_reduce (int lookahead, int token)  flush_reduce (int lookahead, int token)
81  {  {
82    RESETBIT (LA (lookahead), token);    bitset_reset (LA[lookahead], token);
83  }  }
84    
85    
# Line 99  resolve_sr_conflict (state_t *state, int Line 100  resolve_sr_conflict (state_t *state, int
100    errp->nerrs = 0;    errp->nerrs = 0;
101    
102    for (i = 0; i < ntokens; i++)    for (i = 0; i < ntokens; i++)
103      if (BITISSET (LA (lookahead), i)      if (bitset_test (LA[lookahead], i)
104          && BITISSET (lookaheadset, i)          && BITISSET (lookaheadset, i)
105          && symbols[i]->prec)          && symbols[i]->prec)
106        {        {
# Line 173  set_conflicts (state_t *state) Line 174  set_conflicts (state_t *state)
174       precedence */       precedence */
175    for (i = 0; i < state->nlookaheads; ++i)    for (i = 0; i < state->nlookaheads; ++i)
176      if (rules[LAruleno[state->lookaheadsp + i]].prec)      if (rules[LAruleno[state->lookaheadsp + i]].prec)
177        for (j = 0; j < tokensetsize; ++j)        for (j = 0; j < ntokens; ++j)
178          if (LA (state->lookaheadsp + i)[j] & lookaheadset[j])          if (bitset_test (LA[state->lookaheadsp + i], j)
179                && BITISSET (lookaheadset, j))
180            {            {
181              resolve_sr_conflict (state, state->lookaheadsp + i);              resolve_sr_conflict (state, state->lookaheadsp + i);
182              break;              break;
# Line 185  set_conflicts (state_t *state) Line 187  set_conflicts (state_t *state)
187       for conflicts not resolved above.  */       for conflicts not resolved above.  */
188    for (i = 0; i < state->nlookaheads; ++i)    for (i = 0; i < state->nlookaheads; ++i)
189      {      {
190        for (j = 0; j < tokensetsize; ++j)        for (j = 0; j < ntokens; ++j)
191          if (LA (state->lookaheadsp + i)[j] & lookaheadset[j])          if (bitset_test (LA[state->lookaheadsp + i], j)
192                && BITISSET (lookaheadset, j))
193            conflicts[state->number] = 1;            conflicts[state->number] = 1;
194    
195        for (j = 0; j < tokensetsize; ++j)        for (j = 0; j < ntokens; ++j)
196          lookaheadset[j] |= LA (state->lookaheadsp + i)[j];          if (bitset_test (LA[state->lookaheadsp + i], j))
197              SETBIT (lookaheadset, j);
198      }      }
199  }  }
200    
201  void  void
202  solve_conflicts (void)  solve_conflicts (void)
203  {  {
204    int i;    size_t i;
205    
206    conflicts = XCALLOC (char, nstates);    conflicts = XCALLOC (char, nstates);
207    shiftset = XCALLOC (unsigned, tokensetsize);    shiftset = XCALLOC (unsigned, tokensetsize);
# Line 233  count_sr_conflicts (state_t *state) Line 237  count_sr_conflicts (state_t *state)
237        SETBIT (shiftset, SHIFT_SYMBOL (shiftp, i));        SETBIT (shiftset, SHIFT_SYMBOL (shiftp, i));
238    
239    for (i = 0; i < state->nlookaheads; ++i)    for (i = 0; i < state->nlookaheads; ++i)
240      for (k = 0; k < tokensetsize; ++k)      for (k = 0; k < ntokens; ++k)
241        lookaheadset[k] |= LA (state->lookaheadsp + i)[k];        if (bitset_test (LA[state->lookaheadsp + i], k))
242            SETBIT (lookaheadset, k);
243    
244    for (k = 0; k < tokensetsize; ++k)    for (k = 0; k < tokensetsize; ++k)
245      lookaheadset[k] &= shiftset[k];      lookaheadset[k] &= shiftset[k];
# Line 265  count_rr_conflicts (state_t *state) Line 270  count_rr_conflicts (state_t *state)
270        int count = 0;        int count = 0;
271        int j;        int j;
272        for (j = 0; j < state->nlookaheads; ++j)        for (j = 0; j < state->nlookaheads; ++j)
273          if (BITISSET (LA (state->lookaheadsp + j), i))          if (bitset_test (LA[state->lookaheadsp + j], i))
274            count++;            count++;
275    
276        if (count >= 2)        if (count >= 2)
# Line 322  void Line 327  void
327  conflicts_output (FILE *out)  conflicts_output (FILE *out)
328  {  {
329    bool printed_sth = FALSE;    bool printed_sth = FALSE;
330    int i;    size_t i;
331    for (i = 0; i < nstates; i++)    for (i = 0; i < nstates; i++)
332      if (conflicts[i])      if (conflicts[i])
333        {        {
# Line 343  conflicts_output (FILE *out) Line 348  conflicts_output (FILE *out)
348  void  void
349  conflicts_print (void)  conflicts_print (void)
350  {  {
351    int i;    size_t i;
352    
353    /* Is the number of SR conflicts OK?  Either EXPECTED_CONFLICTS is    /* Is the number of SR conflicts OK?  Either EXPECTED_CONFLICTS is
354       not set, and then we want 0 SR, or else it is specified, in which       not set, and then we want 0 SR, or else it is specified, in which

Legend:
Removed from v.1.66  
changed lines
  Added in v.1.67

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