Changes in / [bfbf97f:a8541d9]
- Location:
- src
- Files:
-
- 404 added
- 121 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rbfbf97f ra8541d9 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jun 04 15:00:00201513 // Update Count : 1 2512 // Last Modified On : Thu Jun 11 13:22:39 2015 13 // Update Count : 137 14 14 // 15 15 … … 43 43 } 44 44 45 CodeGenerator::CodeGenerator( std::ostream &os ) : cur_indent( 0 ), insideFunction( false ), output( os ) { } 46 47 CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indent, bool infunp ) 48 : cur_indent( indent ), insideFunction( infunp ), output( os ) { 45 ostream & CodeGenerator::Indenter::operator()( ostream & output ) { 46 return output << string( cg.cur_indent, ' ' ); 47 } 48 49 ostream & operator<<( ostream & output, CodeGenerator::Indenter &indent ) { 50 return indent( output ); 51 } 52 53 CodeGenerator::CodeGenerator( std::ostream &os ) : indent(*this), cur_indent( 0 ), insideFunction( false ), output( os ) { } 54 55 CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indentation, bool infunp ) 56 : indent(*this), cur_indent( indentation ), insideFunction( infunp ), output( os ) { 49 57 //output << std::string( init ); 50 58 } 51 59 52 CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indent , bool infunp )53 : cur_indent( indent), insideFunction( infunp ), output( os ) {60 CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indentation, bool infunp ) 61 : indent(*this), cur_indent( indentation ), insideFunction( infunp ), output( os ) { 54 62 //output << std::string( init ); 55 63 } … … 62 70 } // if 63 71 } 64 72 65 73 //*** Declarations 66 74 void CodeGenerator::visit( FunctionDecl *functionDecl ) { … … 104 112 105 113 if ( ! memb.empty() ) { 106 output << endl << string( cur_indent, ' ' )<< "{" << endl;114 output << endl << indent << "{" << endl; 107 115 108 116 cur_indent += CodeGenerator::tabsize; 109 117 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++) { 110 output << string( cur_indent, ' ' );118 output << indent; 111 119 (*i)->accept(*this ); 112 120 output << ";" << endl; … … 115 123 cur_indent -= CodeGenerator::tabsize; 116 124 117 output << string( cur_indent, ' ' )<< "}";125 output << indent << "}"; 118 126 } // if 119 127 } … … 138 146 139 147 if ( ! memb.empty() ) { 140 output << endl << "{" << endl;148 output << " {" << endl; 141 149 142 150 cur_indent += CodeGenerator::tabsize; … … 144 152 ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i ); 145 153 assert( obj ); 146 output << string( cur_indent, ' ' )<< mangleName( obj );154 output << indent << mangleName( obj ); 147 155 if ( obj->get_init() ) { 148 156 output << " = "; … … 154 162 cur_indent -= CodeGenerator::tabsize; 155 163 156 output << "}" << endl;164 output << indent << "}"; 157 165 } // if 158 166 } … … 444 452 445 453 for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end(); i++) { 446 output << string( cur_indent, ' ' )<< printLabels( (*i)->get_labels() );454 output << indent << printLabels( (*i)->get_labels() ); 447 455 (*i)->accept(*this ); 448 456 … … 454 462 cur_indent -= CodeGenerator::tabsize; 455 463 456 output << string( cur_indent, ' ' )<< "}";464 output << indent << "}"; 457 465 } 458 466 … … 494 502 cur_indent -= CodeGenerator::tabsize; 495 503 496 output << string( cur_indent, ' ' )<< "}";504 output << indent << "}"; 497 505 } 498 506 499 507 void CodeGenerator::visit( CaseStmt *caseStmt ) { 500 output << string( cur_indent, ' ' );508 output << indent; 501 509 if ( caseStmt->isDefault()) { 502 510 output << "default"; … … 511 519 cur_indent += CodeGenerator::tabsize; 512 520 for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end(); i++) { 513 output << string( cur_indent, ' ' )<< printLabels( (*i)->get_labels() ) ;521 output << indent << printLabels( (*i)->get_labels() ) ; 514 522 (*i)->accept(*this ); 515 523 output << endl; … … 564 572 whileStmt->get_body()->accept( *this ); 565 573 566 output << string( cur_indent, ' ' );574 output << indent; 567 575 568 576 if ( whileStmt->get_isDoWhile() ) { … … 596 604 597 605 void CodeGenerator::visit( NullStmt *nullStmt ) { 598 //output << string( cur_indent, ' ' )<< CodeGenerator::printLabels( nullStmt->get_labels() );606 //output << indent << CodeGenerator::printLabels( nullStmt->get_labels() ); 599 607 output << "/* null statement */ ;"; 600 608 } -
src/CodeGen/CodeGenerator.h
rbfbf97f ra8541d9 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon Jun 8 14:34:43 201513 // Update Count : 1511 // Last Modified By : Rob Schluntz 12 // Last Modified On : Thu Jun 11 13:24:23 2015 13 // Update Count : 23 14 14 // 15 15 … … 80 80 81 81 template< class Iterator > void genCommaList( Iterator begin, Iterator end ); 82 83 struct Indenter { 84 Indenter(CodeGenerator &cg) : cg(cg) {} 85 CodeGenerator & cg; 86 std::ostream& operator()(std::ostream & os); 87 }; 82 88 private: 89 90 Indenter indent; 83 91 int cur_indent; 84 92 bool insideFunction; -
src/Parser/parser.cc
rbfbf97f ra8541d9 9272 9272 std::cout << "in file " << yyfilename << " "; 9273 9273 } // if 9274 // std::cout << "at line " << yylineno << " reading token \"" << *(yylval.tok.str) << "\"" << std::endl; 9275 std::cout << "at line " << yylineno << " reading token \"" << yytext << "\"" << std::endl; 9274 std::cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << std::endl; 9276 9275 } 9277 9276 -
src/Parser/parser.yy
rbfbf97f ra8541d9 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jun 10 14:22:15201513 // Update Count : 10 3912 // Last Modified On : Wed Jun 10 20:31:54 2015 13 // Update Count : 1040 14 14 // 15 15 … … 2723 2723 std::cout << "in file " << yyfilename << " "; 2724 2724 } // if 2725 std::cout << "at line " << yylineno << " reading token \"" << yytext<< "\"" << std::endl;2725 std::cout << "at line " << yylineno << " reading token \"" << (yytext[0] == '\0' ? "EOF" : yytext) << "\"" << std::endl; 2726 2726 } 2727 2727 -
src/main.cc
rbfbf97f ra8541d9 9 9 // Author : Richard C. Bilson 10 10 // Created On : Fri May 15 23:12:02 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : T ue Jun 09 15:10:05201513 // Update Count : 6 811 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 11 11:06:04 2015 13 // Update Count : 69 14 14 // 15 15 … … 71 71 errorp = false; 72 72 73 enum { Ast, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, P rototypes, Resolver, Symbol, Parse, };73 enum { Ast, Expr, ExprAlt, Grammar, LibCFA, Nopreamble, Parse, Prototypes, Resolver, Symbol, Validate, }; 74 74 75 75 static struct option long_opts[] = { … … 80 80 { "libcfa", no_argument, 0, LibCFA }, 81 81 { "nopreamble", no_argument, 0, Nopreamble }, 82 { "parse", no_argument, 0, Parse }, 82 83 { "prototypes", no_argument, 0, Prototypes }, 83 84 { "resolver", no_argument, 0, Resolver }, 84 85 { "symbol", no_argument, 0, Symbol }, 85 { " parse", no_argument, 0, Parse },86 { "validate", no_argument, 0, Validate }, 86 87 { 0, 0, 0, 0 } 87 88 }; … … 96 97 97 98 int c; 98 while ( (c = getopt_long( argc, argv, "aefglnpqrs xyzD:", long_opts, &long_index )) != -1 ) {99 while ( (c = getopt_long( argc, argv, "aefglnpqrsvyzD:", long_opts, &long_index )) != -1 ) { 99 100 switch ( c ) { 100 101 case Ast: … … 138 139 symtabp = true; 139 140 break; 140 case ' x': // dump AST after decl validation pass141 case 'v': // dump AST after decl validation pass 141 142 validp = true; 142 143 break;
Note: See TracChangeset
for help on using the changeset viewer.