Changeset 0bd3faf for src/CodeGen


Ignore:
Timestamp:
Nov 13, 2023, 1:40:12 PM (13 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
6ea85b22
Parents:
25f2798
Message:

Removed forward declarations missed in the BaseSyntaxNode? removal. Removed code and modified names to support two versions of the ast.

Location:
src/CodeGen
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGeneratorNew.cpp

    r25f2798 r0bd3faf  
    2424namespace CodeGen {
    2525
    26 int CodeGenerator_new::tabsize = 4;
     26int CodeGenerator::tabsize = 4;
    2727
    2828// The kinds of statements that should be followed by whitespace.
     
    3535}
    3636
    37 void CodeGenerator_new::extension( ast::Expr const * expr ) {
     37void CodeGenerator::extension( ast::Expr const * expr ) {
    3838        if ( expr->extension ) output << "__extension__ ";
    3939}
    4040
    41 void CodeGenerator_new::extension( ast::Decl const * decl ) {
     41void CodeGenerator::extension( ast::Decl const * decl ) {
    4242        if ( decl->extension ) output << "__extension__ ";
    4343}
    4444
    45 void CodeGenerator_new::asmName( ast::DeclWithType const * decl ) {
     45void CodeGenerator::asmName( ast::DeclWithType const * decl ) {
    4646        if ( auto asmName = decl->asmName.as<ast::ConstantExpr>() ) {
    4747                output << " asm ( " << asmName->rep << " )";
     
    4949}
    5050
    51 CodeGenerator_new::LabelPrinter & CodeGenerator_new::LabelPrinter::operator()(
     51CodeGenerator::LabelPrinter & CodeGenerator::LabelPrinter::operator()(
    5252                std::vector<ast::Label> const & l ) {
    5353        labels = &l;
     
    5555}
    5656
    57 std::ostream & CodeGenerator_new::LabelPrinter::operator()( std::ostream & output ) const {
     57std::ostream & CodeGenerator::LabelPrinter::operator()( std::ostream & output ) const {
    5858        const std::vector<ast::Label> & labels = *this->labels;
    5959        for ( const ast::Label & label : labels ) {
     
    6666// Using updateLocation at the beginning of a node and endl within a node
    6767// should become the method of formating.
    68 void CodeGenerator_new::updateLocation( CodeLocation const & to ) {
     68void CodeGenerator::updateLocation( CodeLocation const & to ) {
    6969        // Skip if linemarks shouldn't appear or if location is unset.
    7070        if ( !options.lineMarks || to.isUnset() ) return;
     
    8686}
    8787
    88 void CodeGenerator_new::updateLocation( ast::ParseNode const * to ) {
     88void CodeGenerator::updateLocation( ast::ParseNode const * to ) {
    8989        updateLocation( to->location );
    9090}
    9191
    92 std::ostream & CodeGenerator_new::LineEnder::operator()( std::ostream & os ) const {
     92std::ostream & CodeGenerator::LineEnder::operator()( std::ostream & os ) const {
    9393        os << "\n" << std::flush;
    9494        cg.currentLocation.first_line++;
     
    9696}
    9797
    98 CodeGenerator_new::CodeGenerator_new( std::ostream & os, const Options & options ) :
    99                 indent( 0, CodeGenerator_new::tabsize ), output( os ),
     98CodeGenerator::CodeGenerator( std::ostream & os, const Options & options ) :
     99                indent( 0, CodeGenerator::tabsize ), output( os ),
    100100                options( options ), printLabels( *this ), endl( *this )
    101101{}
    102102
    103 std::string CodeGenerator_new::mangleName( ast::DeclWithType const * decl ) {
     103std::string CodeGenerator::mangleName( ast::DeclWithType const * decl ) {
    104104        // GCC builtins should always be printed unmangled.
    105105        if ( options.pretty || decl->linkage.is_gcc_builtin ) {
     
    112112}
    113113
    114 void CodeGenerator_new::genAttributes(
     114void CodeGenerator::genAttributes(
    115115                const std::vector<ast::ptr<ast::Attribute>> & attributes ) {
    116116        if ( attributes.empty() ) return;
     
    129129}
    130130
    131 void CodeGenerator_new::previsit( ast::Node const * ) {
     131void CodeGenerator::previsit( ast::Node const * ) {
    132132        // All traversal is manual.
    133133        // TODO: Which means the ast::Pass is just providing a default no visit?
     
    135135}
    136136
    137 void CodeGenerator_new::previsit( ast::ParseNode const * node ) {
     137void CodeGenerator::previsit( ast::ParseNode const * node ) {
    138138        previsit( (ast::Node const *)node );
    139139        updateLocation( node );
    140140}
    141141
    142 void CodeGenerator_new::postvisit( ast::Node const * node ) {
     142void CodeGenerator::postvisit( ast::Node const * node ) {
    143143        std::stringstream ss;
    144144        ast::print( ss, node );
     
    146146}
    147147
    148 void CodeGenerator_new::previsit( ast::Expr const * expr ) {
     148void CodeGenerator::previsit( ast::Expr const * expr ) {
    149149        previsit( (ast::ParseNode const *)expr );
    150150        GuardAction( [this, expr](){
     
    155155}
    156156
    157 void CodeGenerator_new::postvisit( ast::FunctionDecl const * decl ) {
     157void CodeGenerator::postvisit( ast::FunctionDecl const * decl ) {
    158158        // Deleted decls should never be used, so don't print them in C.
    159159        if ( decl->isDeleted && options.genC ) return;
     
    168168
    169169        std::ostringstream acc;
    170         ast::Pass<CodeGenerator_new> subCG( acc, subOptions );
     170        ast::Pass<CodeGenerator> subCG( acc, subOptions );
    171171        // Add the forall clause.
    172172        // TODO: These probably should be removed by now and the assert used.
     
    213213}
    214214
    215 //void CodeGenerator_new::postvisit( ast::ObjectDecl const * decl_ ) {
    216 ast::ObjectDecl const * CodeGenerator_new::postvisit(
     215ast::ObjectDecl const * CodeGenerator::postvisit(
    217216                ast::ObjectDecl const * decl ) {
    218217        // Deleted decls should never be used, so don't print them in C.
     
    262261}
    263262
    264 void CodeGenerator_new::handleStorageClass( ast::DeclWithType const * decl ) {
     263void CodeGenerator::handleStorageClass( ast::DeclWithType const * decl ) {
    265264        if ( decl->storage.any() ) {
    266265                ast::print( output, decl->storage );
     
    268267}
    269268
    270 void CodeGenerator_new::handleAggregate(
     269void CodeGenerator::handleAggregate(
    271270                ast::AggregateDecl const * decl, std::string const & kind ) {
    272271        if ( !decl->params.empty() && !options.genC ) {
     
    296295}
    297296
    298 void CodeGenerator_new::postvisit( ast::StructDecl const * decl ) {
     297void CodeGenerator::postvisit( ast::StructDecl const * decl ) {
    299298        extension( decl );
    300299        handleAggregate( decl, "struct " );
    301300}
    302301
    303 void CodeGenerator_new::postvisit( ast::UnionDecl const * decl ) {
     302void CodeGenerator::postvisit( ast::UnionDecl const * decl ) {
    304303        extension( decl );
    305304        handleAggregate( decl, "union " );
     
    332331}
    333332
    334 void CodeGenerator_new::postvisit( ast::EnumDecl const * decl ) {
     333void CodeGenerator::postvisit( ast::EnumDecl const * decl ) {
    335334        extension( decl );
    336335        auto members = decl->members;
     
    370369}
    371370
    372 void CodeGenerator_new::postvisit( ast::TraitDecl const * decl ) {
     371void CodeGenerator::postvisit( ast::TraitDecl const * decl ) {
    373372        assertf( !options.genC, "TraitDecls should not reach code generation." );
    374373        extension( decl );
     
    376375}
    377376
    378 void CodeGenerator_new::postvisit( ast::TypedefDecl const * decl ) {
     377void CodeGenerator::postvisit( ast::TypedefDecl const * decl ) {
    379378        assertf( !options.genC, "Typedefs should not reach code generation." );
    380379        output << "typedef " << genType( decl->base, decl->name, options ) << endl;
    381380}
    382381
    383 void CodeGenerator_new::postvisit( ast::TypeDecl const * decl ) {
     382void CodeGenerator::postvisit( ast::TypeDecl const * decl ) {
    384383        assertf( !options.genC, "TypeDecls should not reach code generation." );
    385384        output << decl->genTypeString() << " " << decl->name;
     
    397396}
    398397
    399 void CodeGenerator_new::postvisit( ast::StaticAssertDecl const * decl ) {
     398void CodeGenerator::postvisit( ast::StaticAssertDecl const * decl ) {
    400399        output << "_Static_assert(";
    401400        decl->cond->accept( *visitor );
     
    405404}
    406405
    407 void CodeGenerator_new::postvisit( ast::Designation const * designation ) {
     406void CodeGenerator::postvisit( ast::Designation const * designation ) {
    408407        auto designators = designation->designators;
    409408        if ( 0 == designators.size() ) return;
     
    423422}
    424423
    425 void CodeGenerator_new::postvisit( ast::SingleInit const * init ) {
     424void CodeGenerator::postvisit( ast::SingleInit const * init ) {
    426425        init->value->accept( *visitor );
    427426}
    428427
    429 void CodeGenerator_new::postvisit( ast::ListInit const * init ) {
     428void CodeGenerator::postvisit( ast::ListInit const * init ) {
    430429        auto initBegin = init->initializers.begin();
    431430        auto initEnd = init->initializers.end();
     
    446445}
    447446
    448 void CodeGenerator_new::postvisit( ast::ConstructorInit const * init ) {
     447void CodeGenerator::postvisit( ast::ConstructorInit const * init ) {
    449448        assertf( !options.genC, "ConstructorInit nodes should not reach code generation." );
    450449        // This isn't actual code, but labels the constructor/destructor pairs.
     
    456455}
    457456
    458 void CodeGenerator_new::postvisit( ast::ApplicationExpr const * expr ) {
     457void CodeGenerator::postvisit( ast::ApplicationExpr const * expr ) {
    459458        extension( expr );
    460459        if ( auto var = expr->func.as<ast::VariableExpr>() ) {
     
    550549}
    551550
    552 void CodeGenerator_new::postvisit( ast::UntypedExpr const * expr ) {
     551void CodeGenerator::postvisit( ast::UntypedExpr const * expr ) {
    553552        extension( expr );
    554553        if ( auto name = expr->func.as<ast::NameExpr>() ) {
     
    638637}
    639638
    640 void CodeGenerator_new::postvisit( ast::RangeExpr const * expr ) {
     639void CodeGenerator::postvisit( ast::RangeExpr const * expr ) {
    641640        expr->low->accept( *visitor );
    642641        output << " ... ";
     
    644643}
    645644
    646 void CodeGenerator_new::postvisit( ast::NameExpr const * expr ) {
     645void CodeGenerator::postvisit( ast::NameExpr const * expr ) {
    647646        extension( expr );
    648647        if ( const OperatorInfo * opInfo = operatorLookup( expr->name ) ) {
     
    657656}
    658657
    659 void CodeGenerator_new::postvisit( ast::DimensionExpr const * expr ) {
     658void CodeGenerator::postvisit( ast::DimensionExpr const * expr ) {
    660659        extension( expr );
    661660        output << "/*non-type*/" << expr->name;
    662661}
    663662
    664 void CodeGenerator_new::postvisit( ast::AddressExpr const * expr ) {
     663void CodeGenerator::postvisit( ast::AddressExpr const * expr ) {
    665664        extension( expr );
    666665        output << "(&";
     
    669668}
    670669
    671 void CodeGenerator_new::postvisit( ast::LabelAddressExpr const * expr ) {
     670void CodeGenerator::postvisit( ast::LabelAddressExpr const * expr ) {
    672671        extension( expr );
    673672        output << "(&&" << expr->arg << ")";
    674673}
    675674
    676 void CodeGenerator_new::postvisit( ast::CastExpr const * expr ) {
     675void CodeGenerator::postvisit( ast::CastExpr const * expr ) {
    677676        extension( expr );
    678677        output << "(";
     
    688687}
    689688
    690 void CodeGenerator_new::postvisit( ast::KeywordCastExpr const * expr ) {
     689void CodeGenerator::postvisit( ast::KeywordCastExpr const * expr ) {
    691690        assertf( !options.genC, "KeywordCastExpr should not reach code generation." );
    692691        extension( expr );
     
    696695}
    697696
    698 void CodeGenerator_new::postvisit( ast::VirtualCastExpr const * expr ) {
     697void CodeGenerator::postvisit( ast::VirtualCastExpr const * expr ) {
    699698        assertf( !options.genC, "VirtualCastExpr should not reach code generation." );
    700699        extension( expr );
     
    705704}
    706705
    707 void CodeGenerator_new::postvisit( ast::UntypedMemberExpr const * expr ) {
     706void CodeGenerator::postvisit( ast::UntypedMemberExpr const * expr ) {
    708707        assertf( !options.genC, "UntypedMemberExpr should not reach code generation." );
    709708        extension( expr );
     
    713712}
    714713
    715 void CodeGenerator_new::postvisit( ast::MemberExpr const * expr ) {
     714void CodeGenerator::postvisit( ast::MemberExpr const * expr ) {
    716715        extension( expr );
    717716        expr->aggregate->accept( *visitor );
     
    719718}
    720719
    721 void CodeGenerator_new::postvisit( ast::VariableExpr const * expr ) {
     720void CodeGenerator::postvisit( ast::VariableExpr const * expr ) {
    722721        extension( expr );
    723722        const OperatorInfo * opInfo;
     
    733732}
    734733
    735 void CodeGenerator_new::postvisit( ast::ConstantExpr const * expr ) {
     734void CodeGenerator::postvisit( ast::ConstantExpr const * expr ) {
    736735        extension( expr );
    737736        output << expr->rep;
    738737}
    739738
    740 void CodeGenerator_new::postvisit( ast::SizeofExpr const * expr ) {
     739void CodeGenerator::postvisit( ast::SizeofExpr const * expr ) {
    741740        extension( expr );
    742741        output << "sizeof(";
     
    749748}
    750749
    751 void CodeGenerator_new::postvisit( ast::AlignofExpr const * expr ) {
     750void CodeGenerator::postvisit( ast::AlignofExpr const * expr ) {
    752751        // Using the GCC extension to avoid changing the std to C11.
    753752        extension( expr );
     
    761760}
    762761
    763 void CodeGenerator_new::postvisit( ast::UntypedOffsetofExpr const * expr ) {
     762void CodeGenerator::postvisit( ast::UntypedOffsetofExpr const * expr ) {
    764763        assertf( !options.genC, "UntypedOffsetofExpr should not reach code generation." );
    765764        output << "offsetof(";
     
    769768}
    770769
    771 void CodeGenerator_new::postvisit( ast::OffsetofExpr const * expr ) {
     770void CodeGenerator::postvisit( ast::OffsetofExpr const * expr ) {
    772771        // Use GCC builtin
    773772        output << "__builtin_offsetof(";
     
    777776}
    778777
    779 void CodeGenerator_new::postvisit( ast::OffsetPackExpr const * expr ) {
     778void CodeGenerator::postvisit( ast::OffsetPackExpr const * expr ) {
    780779        assertf( !options.genC, "OffsetPackExpr should not reach code generation." );
    781780        output << "__CFA_offsetpack(" << genType( expr->type, "", options ) << ")";
    782781}
    783782
    784 void CodeGenerator_new::postvisit( ast::LogicalExpr const * expr ) {
     783void CodeGenerator::postvisit( ast::LogicalExpr const * expr ) {
    785784        extension( expr );
    786785        output << "(";
     
    791790}
    792791
    793 void CodeGenerator_new::postvisit( ast::ConditionalExpr const * expr ) {
     792void CodeGenerator::postvisit( ast::ConditionalExpr const * expr ) {
    794793        extension( expr );
    795794        output << "(";
     
    802801}
    803802
    804 void CodeGenerator_new::postvisit( ast::CommaExpr const * expr ) {
     803void CodeGenerator::postvisit( ast::CommaExpr const * expr ) {
    805804        extension( expr );
    806805        output << "(";
     
    818817}
    819818
    820 void CodeGenerator_new::postvisit( ast::TupleAssignExpr const * expr ) {
     819void CodeGenerator::postvisit( ast::TupleAssignExpr const * expr ) {
    821820        assertf( !options.genC, "TupleAssignExpr should not reach code generation." );
    822821        expr->stmtExpr->accept( *visitor );
    823822}
    824823
    825 void CodeGenerator_new::postvisit( ast::UntypedTupleExpr const * expr ) {
     824void CodeGenerator::postvisit( ast::UntypedTupleExpr const * expr ) {
    826825        assertf( !options.genC, "UntypedTupleExpr should not reach code generation." );
    827826        extension( expr );
     
    831830}
    832831
    833 void CodeGenerator_new::postvisit( ast::TupleExpr const * expr ) {
     832void CodeGenerator::postvisit( ast::TupleExpr const * expr ) {
    834833        assertf( !options.genC, "TupleExpr should not reach code generation." );
    835834        extension( expr );
     
    839838}
    840839
    841 void CodeGenerator_new::postvisit( ast::TupleIndexExpr const * expr ) {
     840void CodeGenerator::postvisit( ast::TupleIndexExpr const * expr ) {
    842841        assertf( !options.genC, "TupleIndexExpr should not reach code generation." );
    843842        extension( expr );
     
    846845}
    847846
    848 void CodeGenerator_new::postvisit( ast::TypeExpr const * expr ) {
     847void CodeGenerator::postvisit( ast::TypeExpr const * expr ) {
    849848        // TODO: Should there be an assertion there?
    850849        if ( !options.genC ) {
     
    853852}
    854853
    855 void CodeGenerator_new::postvisit( ast::AsmExpr const * expr ) {
     854void CodeGenerator::postvisit( ast::AsmExpr const * expr ) {
    856855        if ( !expr->inout.empty() ) {
    857856                output << "[ " << expr->inout << " ] ";
     
    863862}
    864863
    865 void CodeGenerator_new::postvisit( ast::CompoundLiteralExpr const * expr ) {
     864void CodeGenerator::postvisit( ast::CompoundLiteralExpr const * expr ) {
    866865        //assert( expr->result && dynamic_cast<ast::ListInit const *>( expr->init ) );
    867866        assert( expr->result && expr->init.as<ast::ListInit>() );
     
    870869}
    871870
    872 void CodeGenerator_new::postvisit( ast::UniqueExpr const * expr ) {
     871void CodeGenerator::postvisit( ast::UniqueExpr const * expr ) {
    873872        assertf( !options.genC, "UniqueExpr should not reach code generation." );
    874873        output << "unq<" << expr->id << ">{ ";
     
    877876}
    878877
    879 void CodeGenerator_new::postvisit( ast::StmtExpr const * expr ) {
     878void CodeGenerator::postvisit( ast::StmtExpr const * expr ) {
    880879        auto stmts = expr->stmts->kids;
    881880        output << "({" << endl;
     
    905904}
    906905
    907 void CodeGenerator_new::postvisit( ast::ConstructorExpr const * expr ) {
     906void CodeGenerator::postvisit( ast::ConstructorExpr const * expr ) {
    908907        assertf( !options.genC, "ConstructorExpr should not reach code generation." );
    909908        expr->callExpr->accept( *visitor );
    910909}
    911910
    912 void CodeGenerator_new::postvisit( ast::DeletedExpr const * expr ) {
     911void CodeGenerator::postvisit( ast::DeletedExpr const * expr ) {
    913912        assertf( !options.genC, "DeletedExpr should not reach code generation." );
    914913        expr->expr->accept( *visitor );
    915914}
    916915
    917 void CodeGenerator_new::postvisit( ast::DefaultArgExpr const * expr ) {
     916void CodeGenerator::postvisit( ast::DefaultArgExpr const * expr ) {
    918917        assertf( !options.genC, "DefaultArgExpr should not reach code generation." );
    919918        expr->expr->accept( *visitor );
    920919}
    921920
    922 void CodeGenerator_new::postvisit( ast::GenericExpr const * expr ) {
     921void CodeGenerator::postvisit( ast::GenericExpr const * expr ) {
    923922        assertf( !options.genC, "GenericExpr should not reach code generation." );
    924923        output << "_Generic(";
     
    940939}
    941940
    942 void CodeGenerator_new::postvisit( ast::CompoundStmt const * stmt ) {
     941void CodeGenerator::postvisit( ast::CompoundStmt const * stmt ) {
    943942        output << "{" << endl;
    944943
     
    955954}
    956955
    957 void CodeGenerator_new::postvisit( ast::ExprStmt const * stmt ) {
     956void CodeGenerator::postvisit( ast::ExprStmt const * stmt ) {
    958957        assert( stmt );
    959958        // Cast the top-level expression to void to reduce gcc warnings.
     
    967966}
    968967
    969 void CodeGenerator_new::postvisit( ast::AsmStmt const * stmt ) {
     968void CodeGenerator::postvisit( ast::AsmStmt const * stmt ) {
    970969        output << "asm ";
    971970        if ( stmt->isVolatile ) output << "volatile ";
     
    991990}
    992991
    993 void CodeGenerator_new::postvisit( ast::AsmDecl const * decl ) {
     992void CodeGenerator::postvisit( ast::AsmDecl const * decl ) {
    994993        output << "asm ";
    995994        ast::AsmStmt const * stmt = decl->stmt;
     
    999998}
    1000999
    1001 void CodeGenerator_new::postvisit( ast::DirectiveDecl const * decl ) {
     1000void CodeGenerator::postvisit( ast::DirectiveDecl const * decl ) {
    10021001        // endl prevents spaces before the directive.
    10031002        output << endl << decl->stmt->directive;
    10041003}
    10051004
    1006 void CodeGenerator_new::postvisit( ast::DirectiveStmt const * stmt ) {
     1005void CodeGenerator::postvisit( ast::DirectiveStmt const * stmt ) {
    10071006        // endl prevents spaces before the directive.
    10081007        output << endl << stmt->directive;
    10091008}
    10101009
    1011 void CodeGenerator_new::postvisit( ast::IfStmt const * stmt ) {
     1010void CodeGenerator::postvisit( ast::IfStmt const * stmt ) {
    10121011        output << "if ( ";
    10131012        stmt->cond->accept( *visitor );
     
    10221021}
    10231022
    1024 void CodeGenerator_new::postvisit( ast::SwitchStmt const * stmt ) {
     1023void CodeGenerator::postvisit( ast::SwitchStmt const * stmt ) {
    10251024        output << "switch ( ";
    10261025        stmt->cond->accept( *visitor );
     
    10361035}
    10371036
    1038 void CodeGenerator_new::postvisit( ast::CaseClause const * clause ) {
     1037void CodeGenerator::postvisit( ast::CaseClause const * clause ) {
    10391038        updateLocation( clause );
    10401039        output << indent;
     
    10561055}
    10571056
    1058 void CodeGenerator_new::postvisit( ast::BranchStmt const * stmt ) {
     1057void CodeGenerator::postvisit( ast::BranchStmt const * stmt ) {
    10591058        switch ( stmt->kind ) {
    10601059        case ast::BranchStmt::Goto:
     
    10911090}
    10921091
    1093 void CodeGenerator_new::postvisit( ast::ReturnStmt const * stmt ) {
     1092void CodeGenerator::postvisit( ast::ReturnStmt const * stmt ) {
    10941093        output << "return ";
    10951094        if ( stmt->expr ) stmt->expr->accept( *visitor );
     
    10971096}
    10981097
    1099 void CodeGenerator_new::postvisit( ast::ThrowStmt const * stmt ) {
     1098void CodeGenerator::postvisit( ast::ThrowStmt const * stmt ) {
    11001099        assertf( !options.genC, "ThrowStmt should not reach code generation." );
    11011100
     
    11121111}
    11131112
    1114 void CodeGenerator_new::postvisit( ast::CatchClause const * stmt ) {
     1113void CodeGenerator::postvisit( ast::CatchClause const * stmt ) {
    11151114        assertf( !options.genC, "CatchClause should not reach code generation." );
    11161115
     
    11261125}
    11271126
    1128 void CodeGenerator_new::postvisit( ast::WaitForStmt const * stmt ) {
     1127void CodeGenerator::postvisit( ast::WaitForStmt const * stmt ) {
    11291128        assertf( !options.genC, "WaitforStmt should not reach code generation." );
    11301129
     
    11721171}
    11731172
    1174 void CodeGenerator_new::postvisit( ast::WithStmt const * stmt ) {
     1173void CodeGenerator::postvisit( ast::WithStmt const * stmt ) {
    11751174        assertf( !options.genC, "WithStmt should not reach code generation." );
    11761175
     
    11811180}
    11821181
    1183 void CodeGenerator_new::postvisit( ast::WhileDoStmt const * stmt ) {
     1182void CodeGenerator::postvisit( ast::WhileDoStmt const * stmt ) {
    11841183        if ( stmt->isDoWhile ) {
    11851184                output << "do";
     
    11911190        output << " ";
    11921191
    1193         output << CodeGenerator_new::printLabels( stmt->body->labels );
     1192        output << CodeGenerator::printLabels( stmt->body->labels );
    11941193        stmt->body->accept( *visitor );
    11951194
     
    12031202}
    12041203
    1205 void CodeGenerator_new::postvisit( ast::ForStmt const * stmt ) {
     1204void CodeGenerator::postvisit( ast::ForStmt const * stmt ) {
    12061205        // Initializer is always hoised so don't generate it.
    12071206        // TODO: Do an assertion check?
     
    12261225}
    12271226
    1228 void CodeGenerator_new::postvisit( ast::NullStmt const * ) {
     1227void CodeGenerator::postvisit( ast::NullStmt const * ) {
    12291228        output << "/* null statement */ ;";
    12301229}
    12311230
    1232 void CodeGenerator_new::postvisit( ast::DeclStmt const * stmt ) {
     1231void CodeGenerator::postvisit( ast::DeclStmt const * stmt ) {
    12331232        stmt->decl->accept( *visitor );
    12341233
     
    12361235}
    12371236
    1238 void CodeGenerator_new::postvisit( ast::ImplicitCtorDtorStmt const * stmt ) {
     1237void CodeGenerator::postvisit( ast::ImplicitCtorDtorStmt const * stmt ) {
    12391238        assertf( !options.genC, "ImplicitCtorCtorStmt should not reach code generation." );
    12401239        stmt->callStmt->accept( *visitor );
    12411240}
    12421241
    1243 void CodeGenerator_new::postvisit( ast::MutexStmt const * stmt ) {
     1242void CodeGenerator::postvisit( ast::MutexStmt const * stmt ) {
    12441243        assertf( !options.genC, "MutexStmt should not reach code generation." );
    12451244        // TODO: But this isn't what a mutex statement looks like.
  • src/CodeGen/CodeGeneratorNew.hpp

    r25f2798 r0bd3faf  
    2525namespace CodeGen {
    2626
    27 #warning Remove the _new when old version is removed.
    28 struct CodeGenerator_new :
     27struct CodeGenerator final :
    2928                public ast::WithGuards,
    3029                public ast::WithShortCircuiting,
    31                 public ast::WithVisitorRef<CodeGenerator_new> {
    32         CodeGenerator_new( std::ostream & out, Options const & options );
     30                public ast::WithVisitorRef<CodeGenerator> {
     31        CodeGenerator( std::ostream & out, Options const & options );
    3332
    3433        // Turn off visit_children for all nodes.
     
    119118        /// Custom local implementation of endl that updates print location.
    120119        struct LineEnder {
    121                 CodeGenerator_new & cg;
    122                 LineEnder( CodeGenerator_new & cg ) : cg( cg ) {}
     120                CodeGenerator & cg;
     121                LineEnder( CodeGenerator & cg ) : cg( cg ) {}
    123122                std::ostream & operator()( std::ostream & ) const;
    124123        };
     
    129128        /// Wrapper class to help print vectors of Labels.
    130129        struct LabelPrinter {
    131                 LabelPrinter( CodeGenerator_new & cg ) : cg( cg ), labels( nullptr ) {}
     130                LabelPrinter( CodeGenerator & cg ) : cg( cg ), labels( nullptr ) {}
    132131                LabelPrinter & operator()( std::vector<ast::Label> const & l );
    133132                std::ostream & operator()( std::ostream & ) const;
    134                 CodeGenerator_new & cg;
     133                CodeGenerator & cg;
    135134                std::vector<ast::Label> const * labels;
    136135        };
  • src/CodeGen/GenType.cc

    r25f2798 r0bd3faf  
    2121#include "AST/Print.hpp"          // for print
    2222#include "AST/Vector.hpp"         // for vector
    23 #include "CodeGeneratorNew.hpp"   // for CodeGenerator_new
     23#include "CodeGeneratorNew.hpp"   // for CodeGenerator
    2424#include "Common/UniqueName.h"    // for UniqueName
    2525
     
    2828namespace {
    2929
    30 #warning Remove the _new when old version is removed.
    31 struct GenType_new :
     30struct GenType final :
    3231                public ast::WithShortCircuiting,
    33                 public ast::WithVisitorRef<GenType_new> {
     32                public ast::WithVisitorRef<GenType> {
    3433        std::string result;
    35         GenType_new( const std::string &typeString, const Options &options );
     34        GenType( const std::string &typeString, const Options &options );
    3635
    3736        void previsit( ast::Node const * );
     
    6766};
    6867
    69 GenType_new::GenType_new( const std::string &typeString, const Options &options ) : result( typeString ), options( options ) {}
    70 
    71 void GenType_new::previsit( ast::Node const * ) {
     68GenType::GenType( const std::string &typeString, const Options &options ) : result( typeString ), options( options ) {}
     69
     70void GenType::previsit( ast::Node const * ) {
    7271        // Turn off automatic recursion for all nodes, to allow each visitor to
    7372        // precisely control the order in which its children are visited.
     
    7574}
    7675
    77 void GenType_new::postvisit( ast::Node const * node ) {
     76void GenType::postvisit( ast::Node const * node ) {
    7877        std::stringstream ss;
    7978        ast::print( ss, node );
     
    8180}
    8281
    83 void GenType_new::postvisit( ast::VoidType const * type ) {
     82void GenType::postvisit( ast::VoidType const * type ) {
    8483        result = "void " + result;
    8584        handleQualifiers( type );
    8685}
    8786
    88 void GenType_new::postvisit( ast::BasicType const * type ) {
     87void GenType::postvisit( ast::BasicType const * type ) {
    8988        ast::BasicType::Kind kind = type->kind;
    9089        assert( 0 <= kind && kind < ast::BasicType::NUMBER_OF_BASIC_TYPES );
     
    9392}
    9493
    95 void GenType_new::genArray( const ast::CV::Qualifiers & qualifiers, ast::Type const * base, ast::Expr const *dimension, bool isVarLen, bool isStatic ) {
     94void GenType::genArray( const ast::CV::Qualifiers & qualifiers, ast::Type const * base, ast::Expr const *dimension, bool isVarLen, bool isStatic ) {
    9695        std::ostringstream os;
    9796        if ( result != "" ) {
     
    119118        }
    120119        if ( dimension != 0 ) {
    121                 ast::Pass<CodeGenerator_new>::read( dimension, os, options );
     120                ast::Pass<CodeGenerator>::read( dimension, os, options );
    122121        } else if ( isVarLen ) {
    123122                // no dimension expression on a VLA means it came in with the * token
     
    131130}
    132131
    133 void GenType_new::postvisit( ast::PointerType const * type ) {
     132void GenType::postvisit( ast::PointerType const * type ) {
    134133        if ( type->isStatic || type->isVarLen || type->dimension ) {
    135134                genArray( type->qualifiers, type->base, type->dimension, type->isVarLen, type->isStatic );
     
    145144}
    146145
    147 void GenType_new::postvisit( ast::ArrayType const * type ) {
     146void GenType::postvisit( ast::ArrayType const * type ) {
    148147        genArray( type->qualifiers, type->base, type->dimension, type->isVarLen, type->isStatic );
    149148}
    150149
    151 void GenType_new::postvisit( ast::ReferenceType const * type ) {
     150void GenType::postvisit( ast::ReferenceType const * type ) {
    152151        assertf( !options.genC, "Reference types should not reach code generation." );
    153152        handleQualifiers( type );
     
    156155}
    157156
    158 void GenType_new::postvisit( ast::FunctionType const * type ) {
     157void GenType::postvisit( ast::FunctionType const * type ) {
    159158        std::ostringstream os;
    160159
     
    196195                //assertf( !options.genC, "FunctionDecl type parameters should not reach code generation." );
    197196                std::ostringstream os;
    198                 ast::Pass<CodeGenerator_new> cg( os, options );
     197                ast::Pass<CodeGenerator> cg( os, options );
    199198                os << "forall(";
    200199                cg.core.genCommaList( type->forall );
     
    204203}
    205204
    206 std::string GenType_new::handleGeneric( ast::BaseInstType const * type ) {
     205std::string GenType::handleGeneric( ast::BaseInstType const * type ) {
    207206        if ( !type->params.empty() ) {
    208207                std::ostringstream os;
    209                 ast::Pass<CodeGenerator_new> cg( os, options );
     208                ast::Pass<CodeGenerator> cg( os, options );
    210209                os << "(";
    211210                cg.core.genCommaList( type->params );
     
    216215}
    217216
    218 void GenType_new::postvisit( ast::StructInstType const * type )  {
     217void GenType::postvisit( ast::StructInstType const * type )  {
    219218        result = type->name + handleGeneric( type ) + " " + result;
    220219        if ( options.genC ) result = "struct " + result;
     
    222221}
    223222
    224 void GenType_new::postvisit( ast::UnionInstType const * type ) {
     223void GenType::postvisit( ast::UnionInstType const * type ) {
    225224        result = type->name + handleGeneric( type ) + " " + result;
    226225        if ( options.genC ) result = "union " + result;
     
    228227}
    229228
    230 void GenType_new::postvisit( ast::EnumInstType const * type ) {
     229void GenType::postvisit( ast::EnumInstType const * type ) {
    231230        if ( type->base && type->base->base ) {
    232231                result = genType( type->base->base, result, options );
     
    240239}
    241240
    242 void GenType_new::postvisit( ast::TypeInstType const * type ) {
     241void GenType::postvisit( ast::TypeInstType const * type ) {
    243242        assertf( !options.genC, "TypeInstType should not reach code generation." );
    244243        result = type->name + " " + result;
     
    246245}
    247246
    248 void GenType_new::postvisit( ast::TupleType const * type ) {
     247void GenType::postvisit( ast::TupleType const * type ) {
    249248        assertf( !options.genC, "TupleType should not reach code generation." );
    250249        unsigned int i = 0;
     
    259258}
    260259
    261 void GenType_new::postvisit( ast::VarArgsType const * type ) {
     260void GenType::postvisit( ast::VarArgsType const * type ) {
    262261        result = "__builtin_va_list " + result;
    263262        handleQualifiers( type );
    264263}
    265264
    266 void GenType_new::postvisit( ast::ZeroType const * type ) {
     265void GenType::postvisit( ast::ZeroType const * type ) {
    267266        // Ideally these wouldn't hit codegen at all, but should be safe to make them ints.
    268267        result = (options.pretty ? "zero_t " : "long int ") + result;
     
    270269}
    271270
    272 void GenType_new::postvisit( ast::OneType const * type ) {
     271void GenType::postvisit( ast::OneType const * type ) {
    273272        // Ideally these wouldn't hit codegen at all, but should be safe to make them ints.
    274273        result = (options.pretty ? "one_t " : "long int ") + result;
     
    276275}
    277276
    278 void GenType_new::postvisit( ast::GlobalScopeType const * type ) {
     277void GenType::postvisit( ast::GlobalScopeType const * type ) {
    279278        assertf( !options.genC, "GlobalScopeType should not reach code generation." );
    280279        handleQualifiers( type );
    281280}
    282281
    283 void GenType_new::postvisit( ast::TraitInstType const * type ) {
     282void GenType::postvisit( ast::TraitInstType const * type ) {
    284283        assertf( !options.genC, "TraitInstType should not reach code generation." );
    285284        result = type->name + " " + result;
     
    287286}
    288287
    289 void GenType_new::postvisit( ast::TypeofType const * type ) {
     288void GenType::postvisit( ast::TypeofType const * type ) {
    290289        std::ostringstream os;
    291290        os << "typeof(";
    292         ast::Pass<CodeGenerator_new>::read( type, os, options );
     291        ast::Pass<CodeGenerator>::read( type, os, options );
    293292        os << ") " << result;
    294293        result = os.str();
     
    296295}
    297296
    298 void GenType_new::postvisit( ast::VTableType const * type ) {
     297void GenType::postvisit( ast::VTableType const * type ) {
    299298        assertf( !options.genC, "Virtual table types should not reach code generation." );
    300299        std::ostringstream os;
     
    304303}
    305304
    306 void GenType_new::postvisit( ast::QualifiedType const * type ) {
     305void GenType::postvisit( ast::QualifiedType const * type ) {
    307306        assertf( !options.genC, "QualifiedType should not reach code generation." );
    308307        std::ostringstream os;
     
    312311}
    313312
    314 void GenType_new::handleQualifiers( ast::Type const * type ) {
     313void GenType::handleQualifiers( ast::Type const * type ) {
    315314        if ( type->is_const() ) {
    316315                result = "const " + result;
     
    327326}
    328327
    329 std::string GenType_new::genParamList( const ast::vector<ast::Type> & range ) {
     328std::string GenType::genParamList( const ast::vector<ast::Type> & range ) {
    330329        auto cur = range.begin();
    331330        auto end = range.end();
     
    346345        std::ostringstream os;
    347346        if ( !type->attributes.empty() ) {
    348                 ast::Pass<CodeGenerator_new> cg( os, options );
     347                ast::Pass<CodeGenerator> cg( os, options );
    349348                cg.core.genAttributes( type->attributes );
    350349        }
    351350
    352         return os.str() + ast::Pass<GenType_new>::read( type, base, options );
     351        return os.str() + ast::Pass<GenType>::read( type, base, options );
    353352}
    354353
    355354std::string genTypeNoAttr( ast::Type const * type, const std::string & base, const Options & options ) {
    356         return ast::Pass<GenType_new>::read( type, base, options );
     355        return ast::Pass<GenType>::read( type, base, options );
    357356}
    358357
  • src/CodeGen/Generate.cc

    r25f2798 r0bd3faf  
    1919#include <string>                    // for operator<<
    2020
    21 #include "CodeGeneratorNew.hpp"      // for CodeGenerator_new, doSemicolon, ...
     21#include "CodeGeneratorNew.hpp"      // for CodeGenerator, doSemicolon, ...
    2222#include "GenType.h"                 // for genPrettyType
    2323
     
    3232
    3333        /// Removes various nodes that should not exist in CodeGen.
    34         struct TreeCleaner_new {
     34        struct TreeCleaner final {
    3535                ast::CompoundStmt const * previsit( ast::CompoundStmt const * stmt ) {
    3636                        auto mutStmt = ast::mutate( stmt );
     
    5151                bool pretty, bool generateC, bool lineMarks, bool printExprTypes ) {
    5252        erase_if( translationUnit.decls, shouldClean );
    53         ast::Pass<TreeCleaner_new>::run( translationUnit );
     53        ast::Pass<TreeCleaner>::run( translationUnit );
    5454
    55         ast::Pass<CodeGenerator_new> cgv( os,
     55        ast::Pass<CodeGenerator> cgv( os,
    5656                        Options( pretty, generateC, lineMarks, printExprTypes ) );
    5757        for ( auto & decl : translationUnit.decls ) {
  • src/CodeGen/Generate.h

    r25f2798 r0bd3faf  
    1717
    1818#include <iostream>  // for ostream
    19 #include <list>      // for list
    20 
    21 class BaseSyntaxNode;
    22 class Declaration;
    2319
    2420namespace ast {
Note: See TracChangeset for help on using the changeset viewer.