Changes in src/CodeGen/CodeGenerator.cc [262f085f:6e300d9]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r262f085f r6e300d9 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 : T hu Mar 30 16:38:01201713 // Update Count : 48 211 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus May 9 14:32:00 2017 13 // Update Count : 483 14 14 // 15 15 … … 41 41 namespace CodeGen { 42 42 int CodeGenerator::tabsize = 4; 43 44 // Pseudo Function: output << lineDirective(*currentNode); 45 struct lineDirective { 46 CodeLocation const & loc; 47 lineDirective(CodeLocation const & location) : loc(location) {} 48 lineDirective(BaseSyntaxNode const * node) : loc(node->location) {} 49 }; 50 std::ostream & operator<<(std::ostream & out, lineDirective const & ld) { 51 if (ld.loc.isSet()) 52 return out << "\n# " << ld.loc.linenumber << " \"" 53 << ld.loc.filename << "\"\n"; 54 return out << "\n// Unset Location\n"; 55 } 43 56 44 57 // the kinds of statements that would ideally be followed by whitespace … … 128 141 129 142 130 // *** Declarations143 // *** Declarations 131 144 void CodeGenerator::visit( FunctionDecl * functionDecl ) { 132 145 extension( functionDecl ); … … 182 195 } 183 196 184 output << kind;197 output << lineDirective( aggDecl ) << kind; 185 198 if ( aggDecl->get_name() != "" ) 186 199 output << aggDecl->get_name(); … … 192 205 cur_indent += CodeGenerator::tabsize; 193 206 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) { 194 output << indent;207 output << lineDirective( *i ) << indent; 195 208 (*i)->accept( *this ); 196 209 output << ";" << endl; … … 215 228 void CodeGenerator::visit( EnumDecl * enumDecl ) { 216 229 extension( enumDecl ); 230 output << lineDirective ( enumDecl ); 217 231 output << "enum "; 218 232 genAttributes( enumDecl->get_attributes() ); … … 230 244 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 231 245 assert( obj ); 232 output << indent << mangleName( obj );246 output << lineDirective( obj ) << indent << mangleName( obj ); 233 247 if ( obj->get_init() ) { 234 248 output << " = "; … … 248 262 void CodeGenerator::visit( TypedefDecl * typeDecl ) { 249 263 assertf( ! genC, "Typedefs are removed and substituted in earlier passes." ); 264 output << lineDirective( typeDecl ); 250 265 output << "typedef "; 251 266 output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl; … … 319 334 } 320 335 321 // *** Expressions336 // *** Expressions 322 337 void CodeGenerator::visit( ApplicationExpr * applicationExpr ) { 323 338 extension( applicationExpr ); … … 722 737 void CodeGenerator::visit( StmtExpr * stmtExpr ) { 723 738 std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids(); 724 output << "({" << std::endl;739 output << lineDirective( stmtExpr) << "({" << std::endl; 725 740 cur_indent += CodeGenerator::tabsize; 726 741 unsigned int numStmts = stmts.size(); 727 742 unsigned int i = 0; 728 743 for ( Statement * stmt : stmts ) { 729 output << indent << printLabels( stmt->get_labels() ); 744 output << lineDirective( stmt ) << indent; 745 output << printLabels( stmt->get_labels() ); 730 746 if ( i+1 == numStmts ) { 731 747 // last statement in a statement expression needs to be handled specially - … … 749 765 } 750 766 751 // *** Statements767 // *** Statements 752 768 void CodeGenerator::visit( CompoundStmt * compoundStmt ) { 753 769 std::list<Statement*> ks = compoundStmt->get_kids(); … … 813 829 814 830 void CodeGenerator::visit( IfStmt * ifStmt ) { 831 output << lineDirective( ifStmt ); 815 832 output << "if ( "; 816 833 ifStmt->get_condition()->accept( *this ); … … 826 843 827 844 void CodeGenerator::visit( SwitchStmt * switchStmt ) { 845 output << lineDirective( switchStmt ); 828 846 output << "switch ( " ; 829 847 switchStmt->get_condition()->accept( *this ); … … 838 856 839 857 void CodeGenerator::visit( CaseStmt * caseStmt ) { 858 output << lineDirective( caseStmt ); 840 859 output << indent; 841 860 if ( caseStmt->isDefault()) {
Note: See TracChangeset
for help on using the changeset viewer.