Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rbd06384 rda9d79b  
    116116        }
    117117
    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 ) {}
    119119
    120120        string CodeGenerator::mangleName( DeclarationWithType * decl ) {
     
    159159        }
    160160
     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
    161171        // *** Declarations
    162172        void CodeGenerator::postvisit( FunctionDecl * functionDecl ) {
     
    203213
    204214        void CodeGenerator::handleAggregate( AggregateDecl * aggDecl, const std::string & kind ) {
    205                 genAttributes( aggDecl->get_attributes() );
    206 
    207215                if( ! aggDecl->get_parameters().empty() && ! genC ) {
    208216                        // assertf( ! genC, "Aggregate type parameters should not reach code generation." );
     
    213221                }
    214222
    215                 output << kind << aggDecl->get_name();
     223                output << kind;
     224                genAttributes( aggDecl->get_attributes() );
     225                output << aggDecl->get_name();
    216226
    217227                if ( aggDecl->has_body() ) {
     
    298308                        output << " }";
    299309                }
     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 << ")";
    300318        }
    301319
     
    578596                        output << ")";
    579597                } // 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 );
    581607                output << ")";
    582608        }
     
    928954                        output << "continue";
    929955                        break;
     956                  case BranchStmt::FallThrough:
     957                  case BranchStmt::FallThroughDefault:
     958                        assertf( ! genC, "fallthru should not reach code generation." );
     959                  output << "fallthru";
     960                        break;
    930961                } // 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                }
    931970                output << ";";
    932971        }
     
    11061145unsigned Indenter::tabsize = 2;
    11071146
     1147std::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
    11081156// Local Variables: //
    11091157// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.