Changes in src/CodeGen/CodeGenerator.cc [d104b02:87e08e24]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rd104b02 r87e08e24 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Jul 25 15:29:00 201713 // Update Count : 48 612 // Last Modified On : Fri Aug 18 15:34:00 2017 13 // Update Count : 488 14 14 // 15 15 #include "CodeGenerator.h" … … 79 79 } 80 80 81 CodeGenerator::LineMarker::LineMarker( 82 CodeLocation const & loc, bool toPrint) : 83 loc(loc), toPrint(toPrint) 84 {} 85 86 CodeGenerator::LineMarker CodeGenerator::lineDirective( 87 BaseSyntaxNode const * node) { 88 return LineMarker(node->location, lineMarks); 89 } 90 91 std::ostream & operator<<(std::ostream & out, 92 CodeGenerator::LineMarker const & marker) { 93 if (marker.toPrint && marker.loc.isSet()) { 94 return out << "\n# " << marker.loc.linenumber << " \"" 95 << marker.loc.filename << "\"\n"; 96 } else if (marker.toPrint) { 97 return out << "\n/* Missing CodeLocation */\n"; 98 } else { 99 return out; 81 /* Using updateLocation at the beginning of a node and nextLine 82 * within a node should become the method of formating. 83 */ 84 void CodeGenerator::updateLocation( CodeLocation const & to ) { 85 if ( !lineMarks ) { 86 return; 87 } else if ( currentLocation.followedBy( to, 0 ) ) { 88 return; 89 } else if ( currentLocation.followedBy( to, 1 ) ) { 90 output << "\n" << indent; 91 currentLocation.linenumber += 1; 92 } else if ( currentLocation.followedBy( to, 2 ) ) { 93 output << "\n\n" << indent; 94 currentLocation.linenumber += 2; 95 } else { 96 output << "\n# " << to.linenumber << " \"" << to.filename 97 << "\"\n" << indent; 98 currentLocation = to; 99 } 100 output << std::flush; 101 } 102 103 void CodeGenerator::updateLocation( BaseSyntaxNode const * to ) { 104 updateLocation( to->location ); 105 } 106 107 void CodeGenerator::nextLine() { 108 if ( !lineMarks ) { 109 output << "\n" << indent << std::flush; 100 110 } 101 111 } … … 195 205 ++indent; 196 206 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) { 197 output << lineDirective( *i ) << indent; 207 updateLocation( *i ); 208 output << indent; 198 209 (*i)->accept( *this ); 199 210 output << ";" << endl; … … 218 229 void CodeGenerator::visit( EnumDecl * enumDecl ) { 219 230 extension( enumDecl ); 220 output << lineDirective( enumDecl );231 updateLocation( enumDecl ); 221 232 output << "enum "; 222 233 genAttributes( enumDecl->get_attributes() ); … … 234 245 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 235 246 assert( obj ); 236 output << lineDirective( obj ) << indent << mangleName( obj ); 247 updateLocation( obj ); 248 output << indent << mangleName( obj ); 237 249 if ( obj->get_init() ) { 238 250 output << " = "; … … 252 264 void CodeGenerator::visit( TypedefDecl * typeDecl ) { 253 265 assertf( ! genC, "Typedefs are removed and substituted in earlier passes." ); 254 output << lineDirective( typeDecl );266 updateLocation( typeDecl ); 255 267 output << "typedef "; 256 268 output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl; … … 741 753 void CodeGenerator::visit( StmtExpr * stmtExpr ) { 742 754 std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids(); 743 output << lineDirective( stmtExpr) << "({" << std::endl; 755 updateLocation( stmtExpr ); 756 output << "({" << std::endl; 744 757 ++indent; 745 758 unsigned int numStmts = stmts.size(); 746 759 unsigned int i = 0; 747 760 for ( Statement * stmt : stmts ) { 748 output << lineDirective( stmt ) << indent;761 updateLocation( stmt ); 749 762 output << printLabels( stmt->get_labels() ); 750 763 if ( i+1 == numStmts ) { … … 832 845 833 846 void CodeGenerator::visit( IfStmt * ifStmt ) { 834 output << lineDirective( ifStmt );847 updateLocation( ifStmt ); 835 848 output << "if ( "; 836 849 ifStmt->get_condition()->accept( *this ); … … 846 859 847 860 void CodeGenerator::visit( SwitchStmt * switchStmt ) { 848 output << lineDirective( switchStmt );861 updateLocation( switchStmt ); 849 862 output << "switch ( " ; 850 863 switchStmt->get_condition()->accept( *this ); … … 859 872 860 873 void CodeGenerator::visit( CaseStmt * caseStmt ) { 861 output << lineDirective( caseStmt ); 862 output << indent; 874 updateLocation( caseStmt ); 863 875 if ( caseStmt->isDefault()) { 864 876 output << "default";
Note: See TracChangeset
for help on using the changeset viewer.