home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / jikepg12.zip / jikespg / src / prntstat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-04  |  10.8 KB  |  305 lines

  1. /* $Id: prntstat.c,v 1.2 1999/11/04 14:02:23 shields Exp $ */
  2. /*
  3.  This software is subject to the terms of the IBM Jikes Compiler
  4.  License Agreement available at the following URL:
  5.  http://www.ibm.com/research/jikes.
  6.  Copyright (C) 1983, 1999, International Business Machines Corporation
  7.  and others.  All Rights Reserved.
  8.  You must accept the terms of that agreement to use this software.
  9. */
  10. static char hostfile[] = __FILE__;
  11.  
  12. #include <string.h>
  13. #include "common.h"
  14. #include "header.h"
  15.  
  16. /*****************************************************************************/
  17. /*                                 PTSTATS:                                  */
  18. /*****************************************************************************/
  19. /*          PT_STATS prints all the states of the parser.                    */
  20. /*****************************************************************************/
  21. void ptstats(void)
  22. {
  23.     int max_size,
  24.         state_no,
  25.         symbol,
  26.         number,
  27.         i;
  28.  
  29.     struct goto_header_type   go_to;
  30.     struct shift_header_type  sh;
  31.     struct reduce_header_type red;
  32.  
  33.     char temp[SYMBOL_SIZE + 1],
  34.     line[MAX_LINE_SIZE + 1];
  35.  
  36.     PR_HEADING;
  37.     fprintf(syslis,"Shift STATES: ");
  38.  
  39.     for ALL_STATES(state_no)  /* iterate over the states */
  40.     {
  41.         print_state(state_no);
  42.  
  43.         max_size = 0;
  44.  
  45.         /****************************************************************/
  46.         /* Compute the size of the largest symbol.  The MAX_SIZE cannot */
  47.         /* be larger than PRINT_LINE_SIZE - 17 to allow for printing of */
  48.         /* headers for actions to be taken on the symbols.              */
  49.         /****************************************************************/
  50.         sh = shift[statset[state_no].shift_number];
  51.         for (i = 1; i <= sh.size; i++)
  52.         {
  53.             symbol = SHIFT_SYMBOL(sh, i);
  54.             restore_symbol(temp, RETRIEVE_STRING(symbol));
  55.             max_size = MAX(max_size, strlen(temp));
  56.         }
  57.  
  58.         go_to = statset[state_no].go_to;
  59.         for (i = 1; i <= go_to.size; i++)
  60.         {
  61.             symbol = GOTO_SYMBOL(go_to, i);
  62.             restore_symbol(temp, RETRIEVE_STRING(symbol));
  63.             max_size = MAX(max_size, strlen(temp));
  64.         }
  65.  
  66.         red = reduce[state_no];
  67.         for (i = 1; i <= red.size; i++)
  68.         {
  69.             symbol = REDUCE_SYMBOL(red, i);
  70.             restore_symbol(temp, RETRIEVE_STRING(symbol));
  71.             max_size = MAX(max_size, strlen(temp));
  72.         }
  73.  
  74.         max_size = MIN(max_size, PRINT_LINE_SIZE - 17);
  75.  
  76.         /**************************************************************/
  77.         /* 1) Print all Shift actions.                                */
  78.         /* 2) Print all Goto actions.                                 */
  79.         /* 3) Print all reduce actions.                               */
  80.         /* 4) If there is a default then print it.                    */
  81.         /**************************************************************/
  82.         if (sh.size > 0)
  83.         {
  84.             fprintf(syslis, "\n");
  85.             ENDPAGE_CHECK;
  86.             for (i = 1; i <= sh.size; i++)
  87.             {
  88.                 symbol = SHIFT_SYMBOL(sh, i);
  89.                 restore_symbol(temp, RETRIEVE_STRING(symbol));
  90.                 print_large_token(line, temp, "", max_size);
  91.                 number = ABS(SHIFT_ACTION(sh, i));
  92.                 if (SHIFT_ACTION(sh, i) > (short) num_states)
  93.                 {
  94.                     fprintf(syslis,
  95.                             "\n%-*s    La/Sh  %d",
  96.                             max_size, line, number);
  97.                     ENDPAGE_CHECK;
  98.                 }
  99.                 else if (SHIFT_ACTION(sh, i) > 0)
  100.                 {
  101.                     fprintf(syslis,
  102.                             "\n%-*s    Shift  %d",
  103.                             max_size, line, number);
  104.                     ENDPAGE_CHECK;
  105.                 }
  106.                 else
  107.                 {
  108.                     fprintf(syslis,
  109.                             "\n%-*s    Sh/Rd  %d",
  110.                             max_size, line, number);
  111.                     ENDPAGE_CHECK;
  112.                 }
  113.             }
  114.         }
  115.  
  116.         if (go_to.size > 0)
  117.         {
  118.             fprintf(syslis, "\n");
  119.             ENDPAGE_CHECK;
  120.             for (i = 1; i <= go_to.size; i++)
  121.             {
  122.                 symbol = GOTO_SYMBOL(go_to, i);
  123.                 restore_symbol(temp, RETRIEVE_STRING(symbol));
  124.                 print_large_token(line, temp, "", max_size);
  125.                 number = ABS(GOTO_ACTION(go_to, i));
  126.                 if (GOTO_ACTION(go_to, i) > 0)
  127.                 {
  128.                     fprintf(syslis,
  129.                             "\n%-*s    Goto   %d",
  130.                             max_size, line, number);
  131.                     ENDPAGE_CHECK;
  132.                 }
  133.                 else
  134.                 {
  135.                     fprintf(syslis,
  136.                             "\n%-*s    Gt/Rd  %d",
  137.                             max_size, line, number);
  138.                     ENDPAGE_CHECK;
  139.                 }
  140.             }
  141.         }
  142.  
  143.         if (red.size != 0)
  144.         {
  145.             fprintf(syslis, "\n");
  146.             ENDPAGE_CHECK;
  147.             for (i = 1; i <= red.size; i++)
  148.             {
  149.                 symbol = REDUCE_SYMBOL(red, i);
  150.                 restore_symbol(temp, RETRIEVE_STRING(symbol));
  151.                 print_large_token(line, temp, "", max_size);
  152.                 number = REDUCE_RULE_NO(red, i);
  153.                 if (rules[number].lhs != accept_image)
  154.                 {
  155.                     fprintf(syslis,
  156.                             "\n%-*s    Reduce %d",
  157.                             max_size, line, number);
  158.                     ENDPAGE_CHECK;
  159.                 }
  160.                 else
  161.                 {
  162.                     fprintf(syslis, "\n%-*s    Accept",max_size, line);
  163.                     ENDPAGE_CHECK;
  164.                 }
  165.             }
  166.         }
  167.  
  168.         if (default_opt > 0)
  169.         {
  170.             if (REDUCE_RULE_NO(red, 0) != OMEGA)
  171.             {
  172.                 fprintf(syslis,
  173.                         "\n\nDefault reduction to rule  %d",
  174.                         REDUCE_RULE_NO(red, 0));
  175.                 output_line_no++;
  176.                 ENDPAGE_CHECK;
  177.             }
  178.         }
  179.     }
  180.  
  181.     if (max_la_state > num_states)
  182.     {
  183.         PR_HEADING;
  184.         fprintf(syslis,"Look-Ahead STATES:");
  185.     }
  186.     for ALL_LA_STATES(state_no)
  187.     {
  188.         char buffer[PRINT_LINE_SIZE + 1];
  189.  
  190.         i = number_len(state_no) + 8; /* 8 = length of "STATE" */
  191.                                       /* + 2 spaces + newline  */
  192.         fill_in(buffer, (PRINT_LINE_SIZE - i) ,'-');
  193.  
  194.         fprintf(syslis, "\n\n\nSTATE %d %s",state_no, buffer);
  195.         output_line_no += 2;
  196.         ENDPAGE_CHECK;
  197.  
  198.         /**************************************************************/
  199.         /* Print the set of states that have transitions to STATE_NO. */
  200.         /**************************************************************/
  201.         if (lastats[state_no].in_state == state_no)
  202.         {
  203.             fprintf(syslis,"\n(Unreachable State)\n");
  204.             output_line_no++;
  205.             ENDPAGE_CHECK;
  206.         }
  207.         else
  208.         {
  209.             fprintf(syslis,"\n(%d)\n", lastats[state_no].in_state);
  210.             output_line_no++;
  211.             ENDPAGE_CHECK;
  212.  
  213.             max_size = 0;
  214.  
  215.             /*********************************************************/
  216.             /* Compute the size of the largest symbol.  The MAX_SIZE */
  217.             /* cannot be larger than PRINT_LINE_SIZE - 17 to allow   */
  218.             /* for printing of headers for actions to be taken on    */
  219.             /* the symbols.                                          */
  220.             /*********************************************************/
  221.             sh = shift[lastats[state_no].shift_number];
  222.             for (i = 1; i <= sh.size; i++)
  223.             {
  224.                 symbol = SHIFT_SYMBOL(sh, i);
  225.                 restore_symbol(temp, RETRIEVE_STRING(symbol));
  226.                 max_size = MAX(max_size, strlen(temp));
  227.             }
  228.  
  229.             red = lastats[state_no].reduce;
  230.             for (i = 1; i <= red.size; i++)
  231.             {
  232.                 symbol = REDUCE_SYMBOL(red, i);
  233.                 restore_symbol(temp, RETRIEVE_STRING(symbol));
  234.                 max_size = MAX(max_size, strlen(temp));
  235.             }
  236.  
  237.             max_size = MIN(max_size, PRINT_LINE_SIZE - 17);
  238.  
  239.             /**********************************************************/
  240.             /* 1) Print all Shift actions.                            */
  241.             /* 2) Print all Goto actions.                             */
  242.             /* 3) Print all reduce actions.                           */
  243.             /* 4) If there is a default then print it.                */
  244.             /**********************************************************/
  245.             fprintf(syslis, "\n");
  246.             ENDPAGE_CHECK;
  247.             for (i = 1; i <= sh.size; i++)
  248.             {
  249.                 symbol = SHIFT_SYMBOL(sh, i);
  250.                 restore_symbol(temp, RETRIEVE_STRING(symbol));
  251.                 print_large_token(line, temp, "", max_size);
  252.                 number = ABS(SHIFT_ACTION(sh, i));
  253.                 if (SHIFT_ACTION(sh, i) > (short) num_states)
  254.                 {
  255.                     fprintf(syslis,
  256.                             "\n%-*s    La/Sh  %d",
  257.                             max_size, line, number);
  258.                     ENDPAGE_CHECK;
  259.                 }
  260.                 else if (SHIFT_ACTION(sh, i) > 0)
  261.                 {
  262.                     fprintf(syslis,
  263.                             "\n%-*s    Shift  %d",
  264.                             max_size, line, number);
  265.                     ENDPAGE_CHECK;
  266.                 }
  267.                 else
  268.                 {
  269.                     fprintf(syslis,
  270.                             "\n%-*s    Sh/Rd  %d",
  271.                             max_size, line, number);
  272.                     ENDPAGE_CHECK;
  273.                 }
  274.             }
  275.  
  276.             fprintf(syslis, "\n");
  277.             ENDPAGE_CHECK;
  278.             for (i = 1; i <= red.size; i++)
  279.             {
  280.                 symbol = REDUCE_SYMBOL(red, i);
  281.                 restore_symbol(temp, RETRIEVE_STRING(symbol));
  282.                 print_large_token(line, temp, "", max_size);
  283.                 number = REDUCE_RULE_NO(red, i);
  284.                 fprintf(syslis,
  285.                         "\n%-*s    Reduce %d", max_size, line, number);
  286.                 ENDPAGE_CHECK;
  287.             }
  288.  
  289.             if (default_opt > 0 && REDUCE_RULE_NO(red, 0) != OMEGA)
  290.             {
  291.                 fprintf(syslis,
  292.                         "\n\nDefault reduction to rule  %d",
  293.                         REDUCE_RULE_NO(red, 0));
  294.                 output_line_no++;
  295.                 ENDPAGE_CHECK;
  296.             }
  297.         }
  298.     }
  299.  
  300.     fprintf(syslis,"\n");
  301.     ENDPAGE_CHECK;
  302.  
  303.     return;
  304. }
  305.