Changeset 5916272
- Timestamp:
- Aug 20, 2017, 9:26:42 AM (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:
- 39f4100, d82daa1
- Parents:
- 4cc585b (diff), 0dd18fd (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r4cc585b r5916272 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 } … … 194 204 ++indent; 195 205 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) { 196 output << lineDirective( *i ) << indent;206 updateLocation( *i ); 197 207 (*i)->accept( *this ); 198 208 output << ";" << endl; … … 217 227 void CodeGenerator::visit( EnumDecl * enumDecl ) { 218 228 extension( enumDecl ); 219 output << lineDirective( enumDecl );229 updateLocation( enumDecl ); 220 230 output << "enum "; 221 231 genAttributes( enumDecl->get_attributes() ); … … 233 243 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 234 244 assert( obj ); 235 output << lineDirective( obj ) << indent << mangleName( obj ); 245 updateLocation( obj ); 246 output << mangleName( obj ); 236 247 if ( obj->get_init() ) { 237 248 output << " = "; … … 251 262 void CodeGenerator::visit( TypedefDecl * typeDecl ) { 252 263 assertf( ! genC, "Typedefs are removed and substituted in earlier passes." ); 253 output << lineDirective( typeDecl );264 updateLocation( typeDecl ); 254 265 output << "typedef "; 255 266 output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl; … … 752 763 void CodeGenerator::visit( StmtExpr * stmtExpr ) { 753 764 std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids(); 754 output << lineDirective( stmtExpr) << "({" << std::endl; 765 updateLocation( stmtExpr ); 766 output << "({" << std::endl; 755 767 ++indent; 756 768 unsigned int numStmts = stmts.size(); 757 769 unsigned int i = 0; 758 770 for ( Statement * stmt : stmts ) { 759 output << lineDirective( stmt ) << indent;771 updateLocation( stmt ); 760 772 output << printLabels( stmt->get_labels() ); 761 773 if ( i+1 == numStmts ) { … … 844 856 845 857 void CodeGenerator::visit( IfStmt * ifStmt ) { 846 output << lineDirective( ifStmt );858 updateLocation( ifStmt ); 847 859 output << "if ( "; 848 860 ifStmt->get_condition()->accept( *this ); … … 858 870 859 871 void CodeGenerator::visit( SwitchStmt * switchStmt ) { 860 output << lineDirective( switchStmt );872 updateLocation( switchStmt ); 861 873 output << "switch ( " ; 862 874 switchStmt->get_condition()->accept( *this ); … … 871 883 872 884 void CodeGenerator::visit( CaseStmt * caseStmt ) { 873 output << lineDirective( caseStmt ); 874 output << indent; 885 updateLocation( caseStmt ); 875 886 if ( caseStmt->isDefault()) { 876 887 output << "default"; -
src/CodeGen/CodeGenerator.h
r4cc585b r5916272 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 15:40:00 2017 13 // Update Count : 56 14 14 // 15 15 … … 108 108 }; 109 109 110 struct LineMarker {111 CodeLocation const & loc;112 bool toPrint;113 114 LineMarker(CodeLocation const & loc, bool toPrint);115 };116 117 LineMarker lineDirective(BaseSyntaxNode const * node);118 119 110 void asmName( DeclarationWithType *decl ); 120 111 121 112 void extension( Expression *expr ); 122 113 void extension( Declaration *decl ); 114 115 void updateLocation( BaseSyntaxNode const * to ); 123 116 private: 124 117 Indenter indent; … … 129 122 bool genC = false; // true if output has to be C code 130 123 bool lineMarks = false; 124 125 CodeLocation currentLocation; 126 void updateLocation( CodeLocation const & to ); 127 void nextLine(); 131 128 132 129 void handleStorageClass( DeclarationWithType *decl ); … … 155 152 /// returns C-compatible name of declaration 156 153 std::string genName( DeclarationWithType * decl ); 157 158 std::ostream & operator<<(std::ostream &,159 CodeGenerator::LineMarker const &);160 154 } // namespace CodeGen 161 155 -
src/CodeGen/Generate.cc
r4cc585b r5916272 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 19 13:05:00 201713 // Update Count : 612 // Last Modified On : Fri Aug 18 15:39:00 2017 13 // Update Count : 7 14 14 // 15 15 #include "Generate.h" … … 33 33 for ( auto & dcl : translationUnit ) { 34 34 if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) { 35 os << cgv.lineDirective(dcl);35 cgv.updateLocation( dcl ); 36 36 dcl->accept(cgv); 37 37 if ( doSemicolon( dcl ) ) { -
src/ControlStruct/ForExprMutator.cc
r4cc585b r5916272 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.