Changeset 3bd1eb4 for src/CodeGen/CodeGenerator.cc
- Timestamp:
- May 15, 2017, 3:27:47 PM (8 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:
- db0fa7c
- Parents:
- dbfb35d (diff), 9ff8310 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rdbfb35d r3bd1eb4 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus May 9 16:50:00 201712 // Last Modified On : Wed May 10 14:45:00 2017 13 13 // Update Count : 484 14 14 // … … 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 … … 102 89 } 103 90 104 CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ) {} 91 CodeGenerator::LineMarker::LineMarker( 92 CodeLocation const & loc, bool toPrint) : 93 loc(loc), toPrint(toPrint) 94 {} 95 96 CodeGenerator::LineMarker CodeGenerator::lineDirective( 97 BaseSyntaxNode const * node) { 98 return LineMarker(node->location, lineMarks); 99 } 100 101 std::ostream & operator<<(std::ostream & out, 102 CodeGenerator::LineMarker const & marker) { 103 if (marker.toPrint && marker.loc.isSet()) { 104 return out << "\n# " << marker.loc.linenumber << " \"" 105 << marker.loc.filename << "\"\n"; 106 } else if (marker.toPrint) { 107 return out << "\n/* Missing CodeLocation */\n"; 108 } else { 109 return out; 110 } 111 } 112 113 CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ) {} 105 114 106 115 CodeGenerator::CodeGenerator( std::ostream & os, std::string init, int indentation, bool infunp ) … … 143 152 // *** Declarations 144 153 void CodeGenerator::visit( FunctionDecl * functionDecl ) { 145 output << lineDirective( functionDecl );146 147 154 extension( functionDecl ); 148 155 genAttributes( functionDecl->get_attributes() ); … … 168 175 } 169 176 170 output << lineDirective( objectDecl );171 172 177 extension( objectDecl ); 173 178 genAttributes( objectDecl->get_attributes() ); … … 221 226 222 227 void CodeGenerator::visit( StructDecl * structDecl ) { 223 output << lineDirective( structDecl );224 225 228 extension( structDecl ); 226 229 handleAggregate( structDecl, "struct " ); … … 228 231 229 232 void CodeGenerator::visit( UnionDecl * unionDecl ) { 230 output << lineDirective( unionDecl );231 232 233 extension( unionDecl ); 233 234 handleAggregate( unionDecl, "union " ); … … 708 709 void CodeGenerator::visit( UntypedTupleExpr * tupleExpr ) { 709 710 assertf( ! genC, "UntypedTupleExpr should not reach code generation." ); 711 extension( tupleExpr ); 710 712 output << "["; 711 713 genCommaList( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end() ); … … 715 717 void CodeGenerator::visit( TupleExpr * tupleExpr ) { 716 718 assertf( ! genC, "TupleExpr should not reach code generation." ); 719 extension( tupleExpr ); 717 720 output << "["; 718 721 genCommaList( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end() ); 719 722 output << "]"; 723 } 724 725 void CodeGenerator::visit( TupleIndexExpr * tupleExpr ) { 726 assertf( ! genC, "TupleIndexExpr should not reach code generation." ); 727 extension( tupleExpr ); 728 tupleExpr->get_tuple()->accept( *this ); 729 output << "." << tupleExpr->get_index(); 720 730 } 721 731
Note:
See TracChangeset
for help on using the changeset viewer.