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