Changes in src/CodeGen/CodeGenerator.cc [bd06384:da9d79b]
- File:
-
- 1 edited
-
src/CodeGen/CodeGenerator.cc (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rbd06384 rda9d79b 116 116 } 117 117 118 CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks ) : indent( CodeGenerator::tabsize ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ), endl( *this ) {}118 CodeGenerator::CodeGenerator( std::ostream & os, bool pretty, bool genC, bool lineMarks, bool printExprTypes ) : indent( CodeGenerator::tabsize ), output( os ), printLabels( *this ), pretty( pretty ), genC( genC ), lineMarks( lineMarks ), printExprTypes( printExprTypes ), endl( *this ) {} 119 119 120 120 string CodeGenerator::mangleName( DeclarationWithType * decl ) { … … 159 159 } 160 160 161 // *** Expression 162 void CodeGenerator::previsit( Expression * node ) { 163 previsit( (BaseSyntaxNode *)node ); 164 GuardAction( [this, node](){ 165 if ( printExprTypes ) { 166 output << " /* " << genType( node->result, "", pretty, genC ) << " */ "; 167 } 168 } ); 169 } 170 161 171 // *** Declarations 162 172 void CodeGenerator::postvisit( FunctionDecl * functionDecl ) { … … 203 213 204 214 void CodeGenerator::handleAggregate( AggregateDecl * aggDecl, const std::string & kind ) { 205 genAttributes( aggDecl->get_attributes() );206 207 215 if( ! aggDecl->get_parameters().empty() && ! genC ) { 208 216 // assertf( ! genC, "Aggregate type parameters should not reach code generation." ); … … 213 221 } 214 222 215 output << kind << aggDecl->get_name(); 223 output << kind; 224 genAttributes( aggDecl->get_attributes() ); 225 output << aggDecl->get_name(); 216 226 217 227 if ( aggDecl->has_body() ) { … … 298 308 output << " }"; 299 309 } 310 } 311 312 void CodeGenerator::postvisit( StaticAssertDecl * assertDecl ) { 313 output << "_Static_assert("; 314 assertDecl->condition->accept( *visitor ); 315 output << ", "; 316 assertDecl->message->accept( *visitor ); 317 output << ")"; 300 318 } 301 319 … … 578 596 output << ")"; 579 597 } // if 580 castExpr->get_arg()->accept( *visitor ); 598 castExpr->arg->accept( *visitor ); 599 output << ")"; 600 } 601 602 void CodeGenerator::postvisit( KeywordCastExpr * castExpr ) { 603 assertf( ! genC, "KeywordCast should not reach code generation." ); 604 extension( castExpr ); 605 output << "((" << castExpr->targetString() << " &)"; 606 castExpr->arg->accept( *visitor ); 581 607 output << ")"; 582 608 } … … 928 954 output << "continue"; 929 955 break; 956 case BranchStmt::FallThrough: 957 case BranchStmt::FallThroughDefault: 958 assertf( ! genC, "fallthru should not reach code generation." ); 959 output << "fallthru"; 960 break; 930 961 } // switch 962 // print branch target for labelled break/continue/fallthru in debug mode 963 if ( ! genC && branchStmt->get_type() != BranchStmt::Goto ) { 964 if ( ! branchStmt->get_target().empty() ) { 965 output << " " << branchStmt->get_target(); 966 } else if ( branchStmt->get_type() == BranchStmt::FallThrough ) { 967 output << " default"; 968 } 969 } 931 970 output << ";"; 932 971 } … … 1106 1145 unsigned Indenter::tabsize = 2; 1107 1146 1147 std::ostream & operator<<( std::ostream & out, const BaseSyntaxNode * node ) { 1148 if ( node ) { 1149 node->print( out ); 1150 } else { 1151 out << "nullptr"; 1152 } 1153 return out; 1154 } 1155 1108 1156 // Local Variables: // 1109 1157 // tab-width: 4 //
Note:
See TracChangeset
for help on using the changeset viewer.