Ignore:
Timestamp:
Jun 29, 2017, 9:39:17 AM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
288eede, 8c680e9, ae47a23
Parents:
c89503c
Message:

update input file and formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/prettyprinter/filter.cc

    rc89503c rc9383ee  
    1010// Created On       : Tue Apr  9 22:33:44 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun 28 22:56:58 2017
    13 // Update Count     : 72
     12// Last Modified On : Thu Jun 29 08:56:46 2017
     13// Update Count     : 73
    1414//
    1515
     
    2222
    2323
    24 void (*filter)( Token *tree ) = 0;
    25 
    26 
    27 void freeTree( Token *tree ) {                          // postfix tree traversal
     24void (* filter)( Token * tree ) = 0;
     25
     26
     27void freeTree( Token * tree ) {                                                 // postfix tree traversal
    2828        if ( tree == NULL ) return;
    2929        if ( tree->down != NULL ) freeTree( tree->down );
     
    3434
    3535
    36 void Identity( Token *tree ) {                          // prefix tree traversal
     36void Identity( Token * tree ) {                                                 // prefix tree traversal
    3737        if ( tree == NULL ) return;
    3838        // print only the terminals
     
    4343
    4444
    45 static void Parse_Tree1( Token *tree, int indent ) {    // prefix tree traversal
     45static void Parse_Tree1( Token * tree, int indent ) {   // prefix tree traversal
    4646        cout << string( indent, ' ' );
    47         if ( tree->isTerminal() ) {                             // terminals
     47        if ( tree->isTerminal() ) {                                                     // terminals
    4848                cout << "\"" << tree->getText() << "\"";
    49         } else {                                                // non-terminals
     49        } else {                                                                                        // non-terminals
    5050                cout << tree->getText();
    5151        } // if
     
    5757} // Parse_Tree1
    5858
    59 void Parse_Tree( Token *tree ) {
     59void Parse_Tree( Token * tree ) {
    6060        if ( tree == NULL ) return;
    6161        Parse_Tree1( tree, 0 );
     
    6363
    6464
    65 void Nocode( Token *tree ) {                            // prefix tree traversal
     65void Nocode( Token * tree ) {                                                   // prefix tree traversal
    6666        static bool declprt = true;
    6767        if ( tree == NULL ) return;
    6868
    69         if ( tree->isTerminal() ) {                             // terminals
     69        if ( tree->isTerminal() ) {                                                     // terminals
    7070                cout << tree->getWS() << tree->getText();
    71         } else {                                                // non-terminals
     71        } else {                                                                                        // non-terminals
    7272                switch ( tree->getKind() ) {
    7373                  case _RHS: {
    74                           int first = 0;                                // first RHS after ':' or '|' treated specially
     74                          int first = 0;                                                        // first RHS after ':' or '|' treated specially
    7575                          int push = 0, pop = 0;
    76                           for ( Token *i = tree->down; i != 0; i = i->left ) {
     76                          for ( Token * i = tree->down; i != 0; i = i->left ) {
    7777                                  switch ( i->getKind() ) {
    7878                                        case _ACTION:
     
    8282                                          break;
    8383                                        case _PREC:
    84                                           Nocode( i->down );            // print verbatim
    85                                           break;
    86                                         case '|':                               // start of alternative and special case
     84                                          Nocode( i->down );                            // print verbatim
     85                                          break;
     86                                        case '|':                                                       // start of alternative and special case
    8787                                          first = 0;
    88                                         case ';':                               // print with whitespace
     88                                        case ';':                                                       // print with whitespace
    8989                                          cout << string( (push * 4 + pop * 3) / 7, '\t' );
    9090                                          push = pop = 0;
     
    9595                                                  if ( i->getText() == "push" ) {
    9696                                                          push += 1;
    97                                                           if ( first == 0 ) {   // first RHS after ':' or '|' ?
     97                                                          if ( first == 0 ) {              // first RHS after ':' or '|' ?
    9898                                                                  cout << i->getComment(); // ignore rhs but print its comment, if any
    9999                                                          } // if
     
    101101                                                  } else if ( i->getText() == "pop" ) {
    102102                                                          pop += 1;
    103                                                           if ( first == 0 ) {   // first RHS after ':' or '|' ?
     103                                                          if ( first == 0 ) {              // first RHS after ':' or '|' ?
    104104                                                                  cout << i->getComment(); // ignore rhs but print its comment, if any
    105105                                                          } // if
     
    107107                                                  } // if
    108108                                          } // if
    109                                           // If there is a comment or this is the first RHS after
    110                                           // ':' or '|', then include the whitespace before the
    111                                           // token. Otherwise, fold the token onto the same line
    112                                           // separated with a blank.
     109                                          // If there is a comment or this is the first RHS after ':' or '|', then include the whitespace
     110                                          // before the token. Otherwise, fold the token onto the same line separated with a blank.
    113111                                          string t1( i->getText() );
    114112                                          if ( i->isComment() || first == 0 ) {
     
    128126                          break;
    129127                  }
    130                   case _LITERALBLOCK:                           // ignore code but print its comment, if any
     128                  case _LITERALBLOCK:                                                   // ignore code but print its comment, if any
    131129                        cout << tree->down->getComment();
    132130                        break;
    133                   case _DECLARATION: {                          // ignore certain declarations
    134                           int kind = tree->down->getKind();             // get kind of declaration
     131                  case _DECLARATION: {                                                  // ignore certain declarations
     132                          int kind = tree->down->getKind();                     // get kind of declaration
    135133                          if ( kind != UNION && kind != TYPE ) {
    136134                                  declprt = true;
    137                                   Nocode( tree->down );                 // print verbatim
    138                           } else if ( declprt ) {                       // ignore declaration but print its comment, if any
     135                                  Nocode( tree->down );                                 // print verbatim
     136                          } else if ( declprt ) {                                       // ignore declaration but print its comment, if any
    139137                                  declprt = false;
    140138                                  cout << tree->down->getComment();
     
    142140                          break;
    143141                  }
    144                   case _USERSECTION_OPT:                        // ignore but add newline at the end
     142                  case _USERSECTION_OPT:                                                // ignore but add newline at the end
    145143                        cout << endl;
    146144                        break;
     
    153151
    154152
    155 void LaTeX( Token *tree ) {                             // prefix tree traversal
    156         if ( tree == NULL ) return;
    157 
    158         if ( tree->isTerminal() ) {                             // terminals
     153void LaTeX( Token * tree ) {                                                    // prefix tree traversal
     154        if ( tree == NULL ) return;
     155
     156        if ( tree->isTerminal() ) {                                                     // terminals
    159157                cout << tree->getWS() << tree->getText();
    160158                if ( tree->getKind() == IDENTIFIER ) {
     
    162160                        cout << "\\(\\index{" << id << "@\\protect\\LGbegin\\protect\\lgrinde\\)" << id << "\\(\\protect\\endlgrinde\\protect\\LGend{}}\\)";
    163161                } // if
    164         } else {                                                // non-terminals
     162        } else {                                                                                        // non-terminals
    165163                switch ( tree->getKind() ) {
    166164                  case _RHS: {
    167                           int first = 0;                                // first RHS after ':' or '|' treated specially
     165                          int first = 0;                                                        // first RHS after ':' or '|' treated specially
    168166                          int push = 0, pop = 0;
    169                           for ( Token *i = tree->down; i != 0; i = i->left ) {
     167                          for ( Token * i = tree->down; i != 0; i = i->left ) {
    170168                                  switch ( i->getKind() ) {
    171169                                        case _ACTION:
     
    173171                                          break;
    174172                                        case _PREC:
    175                                           LaTeX( i->down );                     // print verbatim
    176                                           break;
    177                                         case '|':                               // start of alternative and special case
     173                                          LaTeX( i->down );                                     // print verbatim
     174                                          break;
     175                                        case '|':                                                       // start of alternative and special case
    178176                                          first = 0;
    179177                                          push = pop = 0;
    180                                         case ';':                               // print with whitespace
     178                                        case ';':                                                       // print with whitespace
    181179                                          cout << i->getWS() << i->getText();
    182180                                          break;
     
    191189                                                  } // if
    192190                                          } // if
    193                                           // If there is a comment or this is the first RHS after
    194                                           // ':' or '|', then include the whitespace before the
    195                                           // token. Otherwise, fold the token onto the same line
    196                                           // separated with a blank.
     191                                          // If there is a comment or this is the first RHS after ':' or '|', then include the whitespace
     192                                          // before the token. Otherwise, fold the token onto the same line separated with a blank.
    197193                                          string t1( i->getText() );
    198194                                          if ( i->isComment() || first == 0 ) {
     
    216212                          break;
    217213                  }
    218                   case _LITERALBLOCK:                           // ignore code but print its comment, if any
     214                  case _LITERALBLOCK:                                                   // ignore code but print its comment, if any
    219215                        cout << tree->down->getComment();
    220216                        break;
    221                   case _DECLARATION: {                          // ignore certain declarations
    222                           int kind = tree->down->getKind();     // get kind of declaration
     217                  case _DECLARATION: {                                                  // ignore certain declarations
     218                          int kind = tree->down->getKind();                     // get kind of declaration
    223219                          if ( kind != UNION && kind != TYPE ) {
    224                                   LaTeX( tree->down );          // print verbatim
     220                                  LaTeX( tree->down );                                  // print verbatim
    225221                          } // if
    226222                          break;
    227223                  }
    228                   case _USERSECTION_OPT:                        // ignore but add newline at the end
     224                  case _USERSECTION_OPT:                                                // ignore but add newline at the end
    229225                        cout << endl;
    230226                        break;
     
    237233
    238234
    239 void HTML( Token *tree ) {                              // prefix tree traversal
     235void HTML( Token * tree ) {                                                             // prefix tree traversal
    240236        cerr << "ERROR: html style not implemented" << endl;
    241237} // HTML
Note: See TracChangeset for help on using the changeset viewer.