Changes in src/CodeGen/CodeGenerator.cc [87e08e24:d104b02]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r87e08e24 rd104b02 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 18 15:34:00 201713 // Update Count : 48 812 // Last Modified On : Tus Jul 25 15:29:00 2017 13 // Update Count : 486 14 14 // 15 15 #include "CodeGenerator.h" … … 79 79 } 80 80 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; 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; 110 100 } 111 101 } … … 205 195 ++indent; 206 196 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) { 207 updateLocation( *i ); 208 output << indent; 197 output << lineDirective( *i ) << indent; 209 198 (*i)->accept( *this ); 210 199 output << ";" << endl; … … 229 218 void CodeGenerator::visit( EnumDecl * enumDecl ) { 230 219 extension( enumDecl ); 231 updateLocation( enumDecl );220 output << lineDirective ( enumDecl ); 232 221 output << "enum "; 233 222 genAttributes( enumDecl->get_attributes() ); … … 245 234 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 246 235 assert( obj ); 247 updateLocation( obj ); 248 output << indent << mangleName( obj ); 236 output << lineDirective( obj ) << indent << mangleName( obj ); 249 237 if ( obj->get_init() ) { 250 238 output << " = "; … … 264 252 void CodeGenerator::visit( TypedefDecl * typeDecl ) { 265 253 assertf( ! genC, "Typedefs are removed and substituted in earlier passes." ); 266 updateLocation( typeDecl );254 output << lineDirective( typeDecl ); 267 255 output << "typedef "; 268 256 output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl; … … 753 741 void CodeGenerator::visit( StmtExpr * stmtExpr ) { 754 742 std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids(); 755 updateLocation( stmtExpr ); 756 output << "({" << std::endl; 743 output << lineDirective( stmtExpr) << "({" << std::endl; 757 744 ++indent; 758 745 unsigned int numStmts = stmts.size(); 759 746 unsigned int i = 0; 760 747 for ( Statement * stmt : stmts ) { 761 updateLocation( stmt );748 output << lineDirective( stmt ) << indent; 762 749 output << printLabels( stmt->get_labels() ); 763 750 if ( i+1 == numStmts ) { … … 845 832 846 833 void CodeGenerator::visit( IfStmt * ifStmt ) { 847 updateLocation( ifStmt );834 output << lineDirective( ifStmt ); 848 835 output << "if ( "; 849 836 ifStmt->get_condition()->accept( *this ); … … 859 846 860 847 void CodeGenerator::visit( SwitchStmt * switchStmt ) { 861 updateLocation( switchStmt );848 output << lineDirective( switchStmt ); 862 849 output << "switch ( " ; 863 850 switchStmt->get_condition()->accept( *this ); … … 872 859 873 860 void CodeGenerator::visit( CaseStmt * caseStmt ) { 874 updateLocation( caseStmt ); 861 output << lineDirective( caseStmt ); 862 output << indent; 875 863 if ( caseStmt->isDefault()) { 876 864 output << "default";
Note: See TracChangeset
for help on using the changeset viewer.