Changeset c9383ee for tools/prettyprinter/filter.cc
- Timestamp:
- Jun 29, 2017, 9:39:17 AM (6 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/prettyprinter/filter.cc
rc89503c rc9383ee 10 10 // Created On : Tue Apr 9 22:33:44 2002 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 28 22:56:58201713 // Update Count : 7 212 // Last Modified On : Thu Jun 29 08:56:46 2017 13 // Update Count : 73 14 14 // 15 15 … … 22 22 23 23 24 void (* filter)( Token *tree ) = 0;25 26 27 void freeTree( Token * tree ) {// postfix tree traversal24 void (* filter)( Token * tree ) = 0; 25 26 27 void freeTree( Token * tree ) { // postfix tree traversal 28 28 if ( tree == NULL ) return; 29 29 if ( tree->down != NULL ) freeTree( tree->down ); … … 34 34 35 35 36 void Identity( Token * tree ) {// prefix tree traversal36 void Identity( Token * tree ) { // prefix tree traversal 37 37 if ( tree == NULL ) return; 38 38 // print only the terminals … … 43 43 44 44 45 static void Parse_Tree1( Token * tree, int indent ) { // prefix tree traversal45 static void Parse_Tree1( Token * tree, int indent ) { // prefix tree traversal 46 46 cout << string( indent, ' ' ); 47 if ( tree->isTerminal() ) { // terminals47 if ( tree->isTerminal() ) { // terminals 48 48 cout << "\"" << tree->getText() << "\""; 49 } else { // non-terminals49 } else { // non-terminals 50 50 cout << tree->getText(); 51 51 } // if … … 57 57 } // Parse_Tree1 58 58 59 void Parse_Tree( Token * tree ) {59 void Parse_Tree( Token * tree ) { 60 60 if ( tree == NULL ) return; 61 61 Parse_Tree1( tree, 0 ); … … 63 63 64 64 65 void Nocode( Token * tree ) {// prefix tree traversal65 void Nocode( Token * tree ) { // prefix tree traversal 66 66 static bool declprt = true; 67 67 if ( tree == NULL ) return; 68 68 69 if ( tree->isTerminal() ) { // terminals69 if ( tree->isTerminal() ) { // terminals 70 70 cout << tree->getWS() << tree->getText(); 71 } else { // non-terminals71 } else { // non-terminals 72 72 switch ( tree->getKind() ) { 73 73 case _RHS: { 74 int first = 0; // first RHS after ':' or '|' treated specially74 int first = 0; // first RHS after ':' or '|' treated specially 75 75 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 ) { 77 77 switch ( i->getKind() ) { 78 78 case _ACTION: … … 82 82 break; 83 83 case _PREC: 84 Nocode( i->down ); // print verbatim85 break; 86 case '|': // start of alternative and special case84 Nocode( i->down ); // print verbatim 85 break; 86 case '|': // start of alternative and special case 87 87 first = 0; 88 case ';': // print with whitespace88 case ';': // print with whitespace 89 89 cout << string( (push * 4 + pop * 3) / 7, '\t' ); 90 90 push = pop = 0; … … 95 95 if ( i->getText() == "push" ) { 96 96 push += 1; 97 if ( first == 0 ) { // first RHS after ':' or '|' ?97 if ( first == 0 ) { // first RHS after ':' or '|' ? 98 98 cout << i->getComment(); // ignore rhs but print its comment, if any 99 99 } // if … … 101 101 } else if ( i->getText() == "pop" ) { 102 102 pop += 1; 103 if ( first == 0 ) { // first RHS after ':' or '|' ?103 if ( first == 0 ) { // first RHS after ':' or '|' ? 104 104 cout << i->getComment(); // ignore rhs but print its comment, if any 105 105 } // if … … 107 107 } // if 108 108 } // 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. 113 111 string t1( i->getText() ); 114 112 if ( i->isComment() || first == 0 ) { … … 128 126 break; 129 127 } 130 case _LITERALBLOCK: // ignore code but print its comment, if any128 case _LITERALBLOCK: // ignore code but print its comment, if any 131 129 cout << tree->down->getComment(); 132 130 break; 133 case _DECLARATION: { // ignore certain declarations134 int kind = tree->down->getKind(); // get kind of declaration131 case _DECLARATION: { // ignore certain declarations 132 int kind = tree->down->getKind(); // get kind of declaration 135 133 if ( kind != UNION && kind != TYPE ) { 136 134 declprt = true; 137 Nocode( tree->down ); // print verbatim138 } else if ( declprt ) { // ignore declaration but print its comment, if any135 Nocode( tree->down ); // print verbatim 136 } else if ( declprt ) { // ignore declaration but print its comment, if any 139 137 declprt = false; 140 138 cout << tree->down->getComment(); … … 142 140 break; 143 141 } 144 case _USERSECTION_OPT: // ignore but add newline at the end142 case _USERSECTION_OPT: // ignore but add newline at the end 145 143 cout << endl; 146 144 break; … … 153 151 154 152 155 void LaTeX( Token * tree ) {// prefix tree traversal156 if ( tree == NULL ) return; 157 158 if ( tree->isTerminal() ) { // terminals153 void LaTeX( Token * tree ) { // prefix tree traversal 154 if ( tree == NULL ) return; 155 156 if ( tree->isTerminal() ) { // terminals 159 157 cout << tree->getWS() << tree->getText(); 160 158 if ( tree->getKind() == IDENTIFIER ) { … … 162 160 cout << "\\(\\index{" << id << "@\\protect\\LGbegin\\protect\\lgrinde\\)" << id << "\\(\\protect\\endlgrinde\\protect\\LGend{}}\\)"; 163 161 } // if 164 } else { // non-terminals162 } else { // non-terminals 165 163 switch ( tree->getKind() ) { 166 164 case _RHS: { 167 int first = 0; // first RHS after ':' or '|' treated specially165 int first = 0; // first RHS after ':' or '|' treated specially 168 166 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 ) { 170 168 switch ( i->getKind() ) { 171 169 case _ACTION: … … 173 171 break; 174 172 case _PREC: 175 LaTeX( i->down ); // print verbatim176 break; 177 case '|': // start of alternative and special case173 LaTeX( i->down ); // print verbatim 174 break; 175 case '|': // start of alternative and special case 178 176 first = 0; 179 177 push = pop = 0; 180 case ';': // print with whitespace178 case ';': // print with whitespace 181 179 cout << i->getWS() << i->getText(); 182 180 break; … … 191 189 } // if 192 190 } // 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. 197 193 string t1( i->getText() ); 198 194 if ( i->isComment() || first == 0 ) { … … 216 212 break; 217 213 } 218 case _LITERALBLOCK: // ignore code but print its comment, if any214 case _LITERALBLOCK: // ignore code but print its comment, if any 219 215 cout << tree->down->getComment(); 220 216 break; 221 case _DECLARATION: { // ignore certain declarations222 int kind = tree->down->getKind(); // get kind of declaration217 case _DECLARATION: { // ignore certain declarations 218 int kind = tree->down->getKind(); // get kind of declaration 223 219 if ( kind != UNION && kind != TYPE ) { 224 LaTeX( tree->down ); // print verbatim220 LaTeX( tree->down ); // print verbatim 225 221 } // if 226 222 break; 227 223 } 228 case _USERSECTION_OPT: // ignore but add newline at the end224 case _USERSECTION_OPT: // ignore but add newline at the end 229 225 cout << endl; 230 226 break; … … 237 233 238 234 239 void HTML( Token * tree ) {// prefix tree traversal235 void HTML( Token * tree ) { // prefix tree traversal 240 236 cerr << "ERROR: html style not implemented" << endl; 241 237 } // HTML
Note: See TracChangeset
for help on using the changeset viewer.