Changeset 8bafacc for src/CodeGen
- Timestamp:
- Aug 18, 2017, 2:23:02 PM (7 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:
- 0dd18fd
- Parents:
- 274ce8c
- Location:
- src/CodeGen
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r274ce8c r8bafacc 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 14:20:00 2017 13 // Update Count : 487 14 14 // 15 15 #include "CodeGenerator.h" … … 101 101 } 102 102 103 /* Using updateLocation at the beginning of a node and nextLine 104 * within a node should become the method of formating. 105 */ 106 void CodeGenerator::updateLocation( CodeLocation const & to ) { 107 if ( !lineMarks ) { 108 return; 109 } else if ( currentLocation.followedBy( to, 0 ) ) { 110 return; 111 } else if ( currentLocation.followedBy( to, 1 ) ) { 112 output << "\n" << indent; 113 currentLocation.linenumber += 1; 114 } else if ( currentLocation.followedBy( to, 2 ) ) { 115 output << "\n\n" << indent; 116 currentLocation.linenumber += 2; 117 } else { 118 output << "\n# " << to.linenumber << " \"" << to.filename 119 << "\"\n" << indent; 120 currentLocation = to; 121 } 122 output << std::flush; 123 } 124 125 void CodeGenerator::updateLocation( BaseSyntaxNode const * to ) { 126 updateLocation( to->location ); 127 } 128 129 void CodeGenerator::nextLine() { 130 if ( !lineMarks ) { 131 output << "\n" << indent << std::flush; 132 } 133 } 134 103 135 CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks ) : indent( CodeGenerator::tabsize ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ) {} 104 136 … … 194 226 ++indent; 195 227 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) { 196 output << lineDirective( *i ) << indent;228 updateLocation( *i ); 197 229 (*i)->accept( *this ); 198 230 output << ";" << endl; … … 217 249 void CodeGenerator::visit( EnumDecl * enumDecl ) { 218 250 extension( enumDecl ); 219 output << lineDirective( enumDecl );251 updateLocation( enumDecl ); 220 252 output << "enum "; 221 253 genAttributes( enumDecl->get_attributes() ); … … 233 265 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 234 266 assert( obj ); 235 output << lineDirective( obj ) << indent << mangleName( obj ); 267 updateLocation( obj ); 268 output << mangleName( obj ); 236 269 if ( obj->get_init() ) { 237 270 output << " = "; … … 251 284 void CodeGenerator::visit( TypedefDecl * typeDecl ) { 252 285 assertf( ! genC, "Typedefs are removed and substituted in earlier passes." ); 253 output << lineDirective( typeDecl );286 updateLocation( typeDecl ); 254 287 output << "typedef "; 255 288 output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl; … … 752 785 void CodeGenerator::visit( StmtExpr * stmtExpr ) { 753 786 std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids(); 754 output << lineDirective( stmtExpr) << "({" << std::endl; 787 updateLocation( stmtExpr ); 788 output << "({" << std::endl; 755 789 ++indent; 756 790 unsigned int numStmts = stmts.size(); 757 791 unsigned int i = 0; 758 792 for ( Statement * stmt : stmts ) { 759 output << lineDirective( stmt ) << indent;793 updateLocation( stmt ); 760 794 output << printLabels( stmt->get_labels() ); 761 795 if ( i+1 == numStmts ) { … … 844 878 845 879 void CodeGenerator::visit( IfStmt * ifStmt ) { 846 output << lineDirective( ifStmt );880 updateLocation( ifStmt ); 847 881 output << "if ( "; 848 882 ifStmt->get_condition()->accept( *this ); … … 858 892 859 893 void CodeGenerator::visit( SwitchStmt * switchStmt ) { 860 output << lineDirective( switchStmt );894 updateLocation( switchStmt ); 861 895 output << "switch ( " ; 862 896 switchStmt->get_condition()->accept( *this ); … … 871 905 872 906 void CodeGenerator::visit( CaseStmt * caseStmt ) { 873 output << lineDirective( caseStmt ); 874 output << indent; 907 updateLocation( caseStmt ); 875 908 if ( caseStmt->isDefault()) { 876 909 output << "default"; -
src/CodeGen/CodeGenerator.h
r274ce8c r8bafacc 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 25:30:00 201713 // Update Count : 5 412 // Last Modified On : Fri Aug 18 13:52:00 2017 13 // Update Count : 55 14 14 // 15 15 … … 130 130 bool lineMarks = false; 131 131 132 CodeLocation currentLocation; 133 void updateLocation( CodeLocation const & to ); 134 void updateLocation( BaseSyntaxNode const * to ); 135 void nextLine(); 136 132 137 void handleStorageClass( DeclarationWithType *decl ); 133 138 void handleAggregate( AggregateDecl *aggDecl, const std::string & kind );
Note: See TracChangeset
for help on using the changeset viewer.