Changeset 66ef082
- Timestamp:
- May 9, 2017, 4:25:20 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:
- 0961bf4
- Parents:
- 19801aa (diff), 6e300d9 (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
r19801aa r66ef082 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : T hu Mar 30 16:38:01201713 // Update Count : 48 211 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus May 9 14:32:00 2017 13 // Update Count : 483 14 14 // 15 15 … … 41 41 namespace CodeGen { 42 42 int CodeGenerator::tabsize = 4; 43 44 // Pseudo Function: output << lineDirective(*currentNode); 45 struct lineDirective { 46 CodeLocation const & loc; 47 lineDirective(CodeLocation const & location) : loc(location) {} 48 lineDirective(BaseSyntaxNode const * node) : loc(node->location) {} 49 }; 50 std::ostream & operator<<(std::ostream & out, lineDirective const & ld) { 51 if (ld.loc.isSet()) 52 return out << "\n# " << ld.loc.linenumber << " \"" 53 << ld.loc.filename << "\"\n"; 54 return out << "\n// Unset Location\n"; 55 } 43 56 44 57 // the kinds of statements that would ideally be followed by whitespace … … 128 141 129 142 130 // *** Declarations143 // *** Declarations 131 144 void CodeGenerator::visit( FunctionDecl * functionDecl ) { 132 145 extension( functionDecl ); … … 182 195 } 183 196 184 output << kind;197 output << lineDirective( aggDecl ) << kind; 185 198 if ( aggDecl->get_name() != "" ) 186 199 output << aggDecl->get_name(); … … 192 205 cur_indent += CodeGenerator::tabsize; 193 206 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) { 194 output << indent;207 output << lineDirective( *i ) << indent; 195 208 (*i)->accept( *this ); 196 209 output << ";" << endl; … … 215 228 void CodeGenerator::visit( EnumDecl * enumDecl ) { 216 229 extension( enumDecl ); 230 output << lineDirective ( enumDecl ); 217 231 output << "enum "; 218 232 genAttributes( enumDecl->get_attributes() ); … … 230 244 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 231 245 assert( obj ); 232 output << indent << mangleName( obj );246 output << lineDirective( obj ) << indent << mangleName( obj ); 233 247 if ( obj->get_init() ) { 234 248 output << " = "; … … 248 262 void CodeGenerator::visit( TypedefDecl * typeDecl ) { 249 263 assertf( ! genC, "Typedefs are removed and substituted in earlier passes." ); 264 output << lineDirective( typeDecl ); 250 265 output << "typedef "; 251 266 output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl; … … 319 334 } 320 335 321 // *** Expressions336 // *** Expressions 322 337 void CodeGenerator::visit( ApplicationExpr * applicationExpr ) { 323 338 extension( applicationExpr ); … … 722 737 void CodeGenerator::visit( StmtExpr * stmtExpr ) { 723 738 std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids(); 724 output << "({" << std::endl;739 output << lineDirective( stmtExpr) << "({" << std::endl; 725 740 cur_indent += CodeGenerator::tabsize; 726 741 unsigned int numStmts = stmts.size(); 727 742 unsigned int i = 0; 728 743 for ( Statement * stmt : stmts ) { 729 output << indent << printLabels( stmt->get_labels() ); 744 output << lineDirective( stmt ) << indent; 745 output << printLabels( stmt->get_labels() ); 730 746 if ( i+1 == numStmts ) { 731 747 // last statement in a statement expression needs to be handled specially - … … 749 765 } 750 766 751 // *** Statements767 // *** Statements 752 768 void CodeGenerator::visit( CompoundStmt * compoundStmt ) { 753 769 std::list<Statement*> ks = compoundStmt->get_kids(); … … 813 829 814 830 void CodeGenerator::visit( IfStmt * ifStmt ) { 831 output << lineDirective( ifStmt ); 815 832 output << "if ( "; 816 833 ifStmt->get_condition()->accept( *this ); … … 826 843 827 844 void CodeGenerator::visit( SwitchStmt * switchStmt ) { 845 output << lineDirective( switchStmt ); 828 846 output << "switch ( " ; 829 847 switchStmt->get_condition()->accept( *this ); … … 838 856 839 857 void CodeGenerator::visit( CaseStmt * caseStmt ) { 858 output << lineDirective( caseStmt ); 840 859 output << indent; 841 860 if ( caseStmt->isDefault()) { -
src/CodeGen/LineStream.cc
r19801aa r66ef082 10 10 // Created On : Thr May 4 13:15:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri May 5 14:29:00 201712 // Last Modified On : Mon May 8 12:08:00 2017 13 13 // Update Count : 0 14 14 // … … 17 17 18 18 namespace CodeGen { 19 20 LineStream::LineStream(std::ostream & baseStream, bool insertLines) :21 baseStream(baseStream), insertLines(insertLines)22 {}23 19 24 20 void LineStream::printLineDirective(CodeLocation const & location) { … … 44 40 actualLocation.unset(); 45 41 46 if (addNew Line) {42 if (addNewline) { 47 43 expectedLocation.linenumber += 1; 48 44 buffer.put('\n'); … … 79 75 80 76 LineStream & LineStream::operator<<(StreamFlag flag) { 81 static Str ingFlag const endlCopy = std::endl;77 static StreamFlag const endlCopy = std::endl; 82 78 if (!insertLines) { 83 79 baseStream << flag; -
src/CodeGen/LineStream.h
r19801aa r66ef082 10 10 // Created On : Wed May 4 09:15:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri May 5 14:29:00 201712 // Last Modified On : Mon May 8 14:03:00 2017 13 13 // Update Count : 1 14 14 // … … 25 25 namespace CodeGen { 26 26 27 class LineStream : public std::ostream{27 class LineStream { 28 28 std::ostream & baseStream; 29 29 std::ostringstream buffer; … … 49 49 50 50 /// Formated output is buffered until flushed. 51 std::ostream & operator<<(char const *str); 52 std::ostream & operator<<(std::string str); 53 std::ostream & operator<<(StreamFlag flag); 51 LineStream & operator<<(char const *str); 52 LineStream & operator<<(std::string const & str); 53 LineStream & operator<<(StreamFlag flag); 54 55 /// Flush all buffered output. 56 LineStream & flush(); 54 57 55 58 }; // LineStream -
src/main.cc
r19801aa r66ef082 37 37 #include "CodeGen/FixMain.h" 38 38 #include "CodeTools/DeclStats.h" 39 #include "CodeTools/TrackLoc.h" 39 40 #include "ControlStruct/Mutate.h" 40 41 #include "SymTab/Validate.h" … … 308 309 } // if 309 310 311 CodeTools::fillLocations( translationUnit ); 310 312 CodeGen::generate( translationUnit, *output, ! noprotop, prettycodegenp, true ); 311 313
Note: See TracChangeset
for help on using the changeset viewer.