Changeset 8bafacc
- 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
- Files:
-
- 3 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 ); -
src/ControlStruct/ForExprMutator.cc
r274ce8c r8bafacc 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Aug 17 15:32:46201713 // Update Count : 1 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 18 10:22:00 2017 13 // Update Count : 12 14 14 // 15 15 … … 21 21 22 22 namespace ControlStruct { 23 Statement * ForExprMutator::postmutate( IfStmt *ifStmt ) {24 std::list<Statement *> &init = ifStmt->get_initialization();25 if ( init.size() == 0) {26 return ifStmt;27 } // if23 Statement *hoist( Statement *originalStmt, std::list<Statement *> &init ) { 24 // If no hoisting is needed, skip: 25 if ( 0 == init.size() ) { 26 return originalStmt; 27 } 28 28 29 // create compound statement, move initializers outside, leave _for_ as-is 29 // Create compound statement, move initializers outside, 30 // the resut of the original stays as is. 30 31 CompoundStmt *block = new CompoundStmt( std::list< Label >() ); 31 32 std::list<Statement *> &stmts = block->get_kids(); 32 33 stmts.splice( stmts.end(), init ); 33 34 34 // add for to the new block35 stmts.push_back( ifStmt );35 // Add for to the new block. 36 stmts.push_back( originalStmt ); 36 37 return block; 37 38 } 38 39 40 Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) { 41 return hoist( ifStmt, ifStmt->initialization ); 42 } 39 43 Statement *ForExprMutator::postmutate( ForStmt *forStmt ) { 40 44 // hoist any initializer declarations to make them C89 (rather than C99) 41 std::list<Statement *> &init = forStmt->get_initialization(); 42 if ( init.size() == 0 ) { 43 return forStmt; 44 } // if 45 46 // create compound statement, move initializers outside, leave _for_ as-is 47 CompoundStmt *block = new CompoundStmt( std::list< Label >() ); 48 std::list<Statement *> &stmts = block->get_kids(); 49 stmts.splice( stmts.end(), init ); 50 51 // add for to the new block 52 stmts.push_back( forStmt ); 53 return block; 45 return hoist( forStmt, forStmt->initialization ); 54 46 } 55 47 } // namespace ControlStruct
Note: See TracChangeset
for help on using the changeset viewer.