Changes in src/CodeGen/CodeGenerator.cc [6e300d9:262f085f]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r6e300d9 r262f085f 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()) {
Note: See TracChangeset
for help on using the changeset viewer.