/[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.22.2.3 by akim, Tue Sep 25 18:35:04 2001 UTC revision 1.22.2.4 by akim, Mon Nov 12 09:15:25 2001 UTC
# Line 28  Line 28 
28  #include "reader.h"  #include "reader.h"
29  #include "LR0.h"  #include "LR0.h"
30    
 int any_conflicts = 0;  
31  errs **err_table = NULL;  errs **err_table = NULL;
32  int expected_conflicts;  int expected_conflicts;
33  static char *conflicts = NULL;  static char *conflicts = NULL;
34    
35  static unsigned *shiftset = NULL;  static unsigned *shiftset = NULL;
36  static unsigned *lookaheadset = NULL;  static unsigned *lookaheadset = NULL;
 static int src_total;  
 static int rrc_total;  
 static int src_count;  
 static int rrc_count;  
37    
38    
39  static inline void  static inline void
# Line 246  set_conflicts (int state) Line 241  set_conflicts (int state)
241        fp3 = lookaheadset;        fp3 = lookaheadset;
242    
243        while (fp3 < fp4)        while (fp3 < fp4)
244          {          if (*fp2++ & *fp3++)
245            if (*fp2++ & *fp3++)            conflicts[state] = 1;
             {  
               conflicts[state] = 1;  
               any_conflicts = 1;  
             }  
         }  
246    
247        fp2 = fp1;        fp2 = fp1;
248        fp3 = lookaheadset;        fp3 = lookaheadset;
# Line 273  solve_conflicts (void) Line 263  solve_conflicts (void)
263    
264    err_table = XCALLOC (errs *, nstates);    err_table = XCALLOC (errs *, nstates);
265    
   any_conflicts = 0;  
   
266    for (i = 0; i < nstates; i++)    for (i = 0; i < nstates; i++)
267      set_conflicts (i);      set_conflicts (i);
268  }  }
# Line 284  solve_conflicts (void) Line 272  solve_conflicts (void)
272  | Count the number of shift/reduce conflicts.  |  | Count the number of shift/reduce conflicts.  |
273  `---------------------------------------------*/  `---------------------------------------------*/
274    
275  static void  static int
276  count_sr_conflicts (int state)  count_sr_conflicts (int state)
277  {  {
278    int i;    int i;
# Line 296  count_sr_conflicts (int state) Line 284  count_sr_conflicts (int state)
284    unsigned *fp3;    unsigned *fp3;
285    int symbol;    int symbol;
286    
287    src_count = 0;    int src_count = 0;
288    
289    shiftp = shift_table[state];    shiftp = shift_table[state];
290    if (!shiftp)    if (!shiftp)
291      return;      return 0;
292    
293    for (i = 0; i < tokensetsize; i++)    for (i = 0; i < tokensetsize; i++)
294      {      {
# Line 351  count_sr_conflicts (int state) Line 339  count_sr_conflicts (int state)
339            fp2++;            fp2++;
340          }          }
341      }      }
342    
343      return src_count;
344  }  }
345    
346    
# Line 358  count_sr_conflicts (int state) Line 348  count_sr_conflicts (int state)
348  | Count the number of reduce/reduce conflicts.  |  | Count the number of reduce/reduce conflicts.  |
349  `----------------------------------------------*/  `----------------------------------------------*/
350    
351  static void  static int
352  count_rr_conflicts (int state)  count_rr_conflicts (int state)
353  {  {
354    int i;    int i;
   int j;  
   int count;  
355    unsigned mask;    unsigned mask;
356    unsigned *baseword;    unsigned *baseword;
   unsigned *wordp;  
   int m;  
   int n;  
357    
358    rrc_count = 0;    int rrc_count = 0;
359    
360    m = lookaheads[state];    int m = lookaheads[state];
361    n = lookaheads[state + 1];    int n = lookaheads[state + 1];
362    
363    if (n - m < 2)    if (n - m < 2)
364      return;      return 0;
365    
366    mask = 1;    mask = 1;
367    baseword = LA + m * tokensetsize;    baseword = LA + m * tokensetsize;
368    for (i = 0; i < ntokens; i++)    for (i = 0; i < ntokens; i++)
369      {      {
370        wordp = baseword;        unsigned *wordp = baseword;
371    
372        count = 0;        int count = 0;
373          int j;
374        for (j = m; j < n; j++)        for (j = m; j < n; j++)
375          {          {
376            if (mask & *wordp)            if (mask & *wordp)
# Line 403  count_rr_conflicts (int state) Line 389  count_rr_conflicts (int state)
389            baseword++;            baseword++;
390          }          }
391      }      }
392    
393      return rrc_count;
394  }  }
395    
396  /*--------------------------------------------------------------.  /*--------------------------------------------------------------.
# Line 452  conflict_report (int src_num, int rrc_nu Line 440  conflict_report (int src_num, int rrc_nu
440  }  }
441    
442    
443  /*---------------------------------------------.  /*-----------------------------------------------------------.
444  | Compute and give a report on the conflicts.  |  | Output the detailed description of states with conflicts.  |
445  `---------------------------------------------*/  `-----------------------------------------------------------*/
446    
447  void  void
448  print_conflicts (FILE *out)  conflicts_output (FILE *out)
449  {  {
450    int i;    int i;
451      for (i = 0; i < nstates; i++)
452        if (conflicts[i])
453          {
454            fprintf (out, _("State %d contains"), i);
455            fputs (conflict_report (count_sr_conflicts (i),
456                                    count_rr_conflicts (i)), out);
457          }
458    }
459    
   src_total = 0;  
   rrc_total = 0;  
460    
461    /* Count the total number of conflicts, and if wanted, give a  /*------------------------------------------.
462       detailed report in FOUTPUT.  */  | Reporting the total number of conflicts.  |
463    for (i = 0; i < nstates; i++)  `------------------------------------------*/
     {  
       if (conflicts[i])  
         {  
           count_sr_conflicts (i);  
           count_rr_conflicts (i);  
           src_total += src_count;  
           rrc_total += rrc_count;  
464    
465            if (verbose_flag)  void
466              {  conflicts_print (void)
467                fprintf (out, _("State %d contains"), i);  {
468                fputs (conflict_report (src_count, rrc_count), out);    int i;
469              }  
470          }    int src_total = 0;
471      }    int rrc_total = 0;
472    
473      /* Conflicts by state.  */
474      for (i = 0; i < nstates; i++)
475        if (conflicts[i])
476          {
477            src_total += count_sr_conflicts (i);
478            rrc_total += count_rr_conflicts (i);
479          }
480    
481    /* Report the total number of conflicts on STDERR.  */    /* Report the total number of conflicts on STDERR.  */
482    if (yacc_flag)    if (src_total || rrc_total)
483      {      if (yacc_flag)
484        /* If invoked with `--yacc', use the output format specified by        {
485           POSIX.  */          /* If invoked with `--yacc', use the output format specified by
486        fprintf (stderr, _("conflicts: "));             POSIX.  */
487        if (src_total > 0)          fprintf (stderr, _("conflicts: "));
488          fprintf (stderr, _(" %d shift/reduce"), src_total);          if (src_total > 0)
489        if (src_total > 0 && rrc_total > 0)            fprintf (stderr, _(" %d shift/reduce"), src_total);
490          fprintf (stderr, ",");          if (src_total > 0 && rrc_total > 0)
491        if (rrc_total > 0)            fprintf (stderr, ",");
492          fprintf (stderr, _(" %d reduce/reduce"), rrc_total);          if (rrc_total > 0)
493        putc ('\n', stderr);            fprintf (stderr, _(" %d reduce/reduce"), rrc_total);
494      }          putc ('\n', stderr);
495    else        }
496      {      else
497        fprintf (stderr, _("%s contains"), infile);        {
498        fputs (conflict_report (src_total, rrc_total), stderr);          fprintf (stderr, _("%s contains"), infile);
499      }          fputs (conflict_report (src_total, rrc_total), stderr);
500          }
501  }  }
502    
503    

Legend:
Removed from v.1.22.2.3  
changed lines
  Added in v.1.22.2.4

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