Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r746ae82 rdd6d7c6  
    265265                stmt->location = node->location;
    266266                stmt->labels = makeLabelL( stmt, node->labels );
     267                cache.emplace( node, stmt );
    267268                this->node = stmt;
    268269                return nullptr;
     
    270271
    271272        const ast::CompoundStmt * visit( const ast::CompoundStmt * node ) override final {
     273                if ( inCache( node ) ) return nullptr;
    272274                auto stmt = new CompoundStmt( get<Statement>().acceptL( node->kids ) );
    273275                stmtPostamble( stmt, node );
     
    276278
    277279        const ast::Stmt * visit( const ast::ExprStmt * node ) override final {
     280                if ( inCache( node ) ) return nullptr;
    278281                auto stmt = new ExprStmt( get<Expression>().accept1( node->expr ) );
    279282                return stmtPostamble( stmt, node );
     
    281284
    282285        const ast::Stmt * visit( const ast::AsmStmt * node ) override final {
     286                if ( inCache( node ) ) return nullptr;
    283287                auto stmt = new AsmStmt(
    284288                        node->isVolatile,
     
    293297
    294298        const ast::Stmt * visit( const ast::DirectiveStmt * node ) override final {
     299                if ( inCache( node ) ) return nullptr;
    295300                auto stmt = new DirectiveStmt( node->directive );
    296301                return stmtPostamble( stmt, node );
     
    298303
    299304        const ast::Stmt * visit( const ast::IfStmt * node ) override final {
     305                if ( inCache( node ) ) return nullptr;
    300306                auto stmt = new IfStmt(
    301307                        get<Expression>().accept1( node->cond ),
     
    308314
    309315        const ast::Stmt * visit( const ast::SwitchStmt * node ) override final {
     316                if ( inCache( node ) ) return nullptr;
    310317                auto stmt = new SwitchStmt(
    311318                        get<Expression>().accept1( node->cond ),
     
    316323
    317324        const ast::Stmt * visit( const ast::CaseStmt * node ) override final {
     325                if ( inCache( node ) ) return nullptr;
    318326                auto stmt = new CaseStmt(
    319327                        get<Expression>().accept1( node->cond ),
     
    325333
    326334        const ast::Stmt * visit( const ast::WhileStmt * node ) override final {
     335                if ( inCache( node ) ) return nullptr;
    327336                auto inits = get<Statement>().acceptL( node->inits );
    328337                auto stmt = new WhileStmt(
     
    336345
    337346        const ast::Stmt * visit( const ast::ForStmt * node ) override final {
     347                if ( inCache( node ) ) return nullptr;
    338348                auto stmt = new ForStmt(
    339349                        get<Statement>().acceptL( node->inits ),
     
    346356
    347357        const ast::Stmt * visit( const ast::BranchStmt * node ) override final {
     358                if ( inCache( node ) ) return nullptr;
    348359                BranchStmt * stmt;
    349360                if (node->computedTarget) {
     
    375386
    376387        const ast::Stmt * visit( const ast::ReturnStmt * node ) override final {
     388                if ( inCache( node ) ) return nullptr;
    377389                auto stmt = new ReturnStmt( get<Expression>().accept1( node->expr ) );
    378390                return stmtPostamble( stmt, node );
     
    380392
    381393        const ast::Stmt * visit( const ast::ThrowStmt * node ) override final {
     394                if ( inCache( node ) ) return nullptr;
    382395                ThrowStmt::Kind kind;
    383396                switch (node->kind) {
     
    400413
    401414        const ast::Stmt * visit( const ast::TryStmt * node ) override final {
     415                if ( inCache( node ) ) return nullptr;
    402416                auto handlers = get<CatchStmt>().acceptL( node->handlers );
    403417                auto stmt = new TryStmt(
     
    410424
    411425        const ast::Stmt * visit( const ast::CatchStmt * node ) override final {
     426                if ( inCache( node ) ) return nullptr;
    412427                CatchStmt::Kind kind;
    413428                switch (node->kind) {
     
    431446
    432447        const ast::Stmt * visit( const ast::FinallyStmt * node ) override final {
     448                if ( inCache( node ) ) return nullptr;
    433449                auto stmt = new FinallyStmt( get<CompoundStmt>().accept1( node->body ) );
    434450                return stmtPostamble( stmt, node );
     
    436452
    437453        const ast::Stmt * visit( const ast::WaitForStmt * node ) override final {
     454                if ( inCache( node ) ) return nullptr;
    438455                auto stmt = new WaitForStmt;
    439456                stmt->clauses.reserve( node->clauses.size() );
     
    460477
    461478        const ast::Stmt * visit( const ast::WithStmt * node ) override final {
     479                if ( inCache( node ) ) return nullptr;
    462480                auto stmt = new WithStmt(
    463481                        get<Expression>().acceptL( node->exprs ),
     
    468486
    469487        const ast::NullStmt * visit( const ast::NullStmt * node ) override final {
     488                if ( inCache( node ) ) return nullptr;
    470489                auto stmt = new NullStmt();
    471490                stmtPostamble( stmt, node );
     
    474493
    475494        const ast::Stmt * visit( const ast::DeclStmt * node ) override final {
     495                if ( inCache( node ) ) return nullptr;
    476496                auto stmt = new DeclStmt( get<Declaration>().accept1( node->decl ) );
    477497                return stmtPostamble( stmt, node );
     
    479499
    480500        const ast::Stmt * visit( const ast::ImplicitCtorDtorStmt * node ) override final {
    481                 (void)node;
    482                 return nullptr;
     501                if ( inCache( node ) ) return nullptr;
     502                auto stmt = new ImplicitCtorDtorStmt{
     503                        get<Statement>().accept1( node->callStmt )
     504                };
     505                return stmtPostamble( stmt, node );
    483506        }
    484507
     
    525548        }
    526549
     550        Expression * visitBaseExpr_skipResultType(const ast::Expr * src, Expression * tgt) {
     551
     552                tgt->location  = src->location;
     553                tgt->env       = convertTypeSubstitution(src->env);
     554                tgt->extension = src->extension;
     555
     556                convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred);
     557                return tgt;
     558        }
     559
    527560        Expression * visitBaseExpr(const ast::Expr * src, Expression * tgt) {
    528561
    529                 tgt->location = src->location;
    530 
    531562                tgt->result = get<Type>().accept1(src->result);
    532                 tgt->env    = convertTypeSubstitution(src->env);
    533 
    534                 tgt->extension = src->extension;
    535                 convertInferUnion(tgt->inferParams, tgt->resnSlots, src->inferred);
    536 
    537                 return tgt;
     563                return visitBaseExpr_skipResultType(src, tgt);
    538564        }
    539565
     
    571597
    572598        const ast::Expr * visit( const ast::AddressExpr * node ) override final {
    573                 (void)node;
     599                auto expr = visitBaseExpr( node,
     600                        new AddressExpr(
     601                                get<Expression>().accept1(node->arg)
     602                        )
     603                );
     604                this->node = expr;
    574605                return nullptr;
    575606        }
    576607
    577608        const ast::Expr * visit( const ast::LabelAddressExpr * node ) override final {
    578                 (void)node;
     609                auto expr = visitBaseExpr( node,
     610                        new LabelAddressExpr(
     611                                makeLabel(nullptr, node->arg)
     612                        )
     613                );
     614                this->node = expr;
    579615                return nullptr;
    580616        }
    581617
    582618        const ast::Expr * visit( const ast::CastExpr * node ) override final {
    583                 (void)node;
     619                auto expr = visitBaseExpr( node,
     620                        new CastExpr(
     621                                get<Expression>().accept1(node->arg),
     622                                (node->isGenerated == ast::GeneratedCast)
     623                        )
     624                );
     625                this->node = expr;
    584626                return nullptr;
    585627        }
    586628
    587629        const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final {
    588                 (void)node;
     630                KeywordCastExpr::Target castTarget = KeywordCastExpr::NUMBER_OF_TARGETS;
     631                switch (node->target) {
     632                        case ast::KeywordCastExpr::Coroutine:
     633                                castTarget = KeywordCastExpr::Coroutine;
     634                                break;
     635                        case ast::KeywordCastExpr::Thread:
     636                                castTarget = KeywordCastExpr::Thread;
     637                                break;
     638                        case ast::KeywordCastExpr::Monitor:
     639                                castTarget = KeywordCastExpr::Monitor;
     640                                break;
     641                        default:
     642                                break;
     643                }
     644                assert ( castTarget < KeywordCastExpr::NUMBER_OF_TARGETS );
     645                auto expr = visitBaseExpr( node,
     646                        new KeywordCastExpr(
     647                                get<Expression>().accept1(node->arg),
     648                                castTarget
     649                        )
     650                );
     651                this->node = expr;
    589652                return nullptr;
    590653        }
    591654
    592655        const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final {
    593                 (void)node;
     656                auto expr = visitBaseExpr_skipResultType( node,
     657                        new VirtualCastExpr(
     658                                get<Expression>().accept1(node->arg),
     659                                get<Type>().accept1(node->result)
     660                        )
     661                );
     662                this->node = expr;
    594663                return nullptr;
    595664        }
    596665
    597666        const ast::Expr * visit( const ast::UntypedMemberExpr * node ) override final {
    598                 (void)node;
     667                auto expr = visitBaseExpr( node,
     668                        new UntypedMemberExpr(
     669                                get<Expression>().accept1(node->member),
     670                                get<Expression>().accept1(node->aggregate)
     671                        )
     672                );
     673                this->node = expr;
    599674                return nullptr;
    600675        }
    601676
    602677        const ast::Expr * visit( const ast::MemberExpr * node ) override final {
    603                 (void)node;
     678                auto expr = visitBaseExpr( node,
     679                        new MemberExpr(
     680                                inCache(node->member) ?
     681                                        dynamic_cast<DeclarationWithType *>(this->node) :
     682                                        get<DeclarationWithType>().accept1(node->member),
     683                                get<Expression>().accept1(node->aggregate)
     684                        )
     685                );
     686                this->node = expr;
    604687                return nullptr;
    605688        }
    606689
    607690        const ast::Expr * visit( const ast::VariableExpr * node ) override final {
    608                 (void)node;
    609                 return nullptr;
     691                auto expr = visitBaseExpr( node,
     692                        new VariableExpr(
     693                                inCache(node->var) ?
     694                                        dynamic_cast<DeclarationWithType *>(this->node) :
     695                                        get<DeclarationWithType>().accept1(node->var)
     696                        )
     697                );
     698                this->node = expr;
     699                return nullptr;
     700        }
     701
     702        bool isIntlikeConstantType(const ast::Type *t) {
     703                if ( const ast::BasicType * basicType = dynamic_cast< const ast::BasicType * >( t ) ) {
     704                        if ( basicType->isInteger() ) {
     705                                return true;
     706                        }
     707                } else if ( dynamic_cast< const ast::OneType * >( t ) ) {
     708                        return true;
     709                } else if ( dynamic_cast< const ast::ZeroType * >( t ) ) {
     710                        return true;
     711                } else if ( dynamic_cast< const ast::PointerType * >( t ) ) {
     712                        // null pointer constants, with zero int-values
     713                        return true;
     714                }
     715                return false;
     716        }
     717
     718        bool isFloatlikeConstantType(const ast::Type *t) {
     719                if ( const ast::BasicType * bty = dynamic_cast< const ast::BasicType * >( t ) ) {
     720                        if ( ! bty->isInteger() ) {
     721                                return true;
     722                        }
     723                }
     724                return false;
     725        }
     726
     727        bool isStringlikeConstantType(const ast::Type *t) {
     728                if ( const ast::ArrayType * aty = dynamic_cast< const ast::ArrayType * >( t ) ) {
     729                        if ( const ast::BasicType * bty = aty->base.as<ast::BasicType>() ) {
     730                           if ( bty->kind == ast::BasicType::Kind::Char ) {
     731                                   return true;
     732                           }
     733                        }
     734                }
     735                return false;
    610736        }
    611737
    612738        const ast::Expr * visit( const ast::ConstantExpr * node ) override final {
    613                 (void)node;
     739                ConstantExpr *rslt = nullptr;
     740                if (isIntlikeConstantType(node->result)) {
     741                        rslt = new ConstantExpr(Constant(
     742                                get<Type>().accept1(node->result),
     743                                node->rep,
     744                                (unsigned long long) node->intValue()
     745                        ));
     746                } else if (isFloatlikeConstantType(node->result)) {
     747                        rslt = new ConstantExpr(Constant(
     748                                get<Type>().accept1(node->result),
     749                                node->rep,
     750                                (double) node->floatValue()
     751                        ));
     752                } else if (isStringlikeConstantType(node->result)) {
     753                        rslt = new ConstantExpr(Constant::from_string(
     754                                node->rep
     755                        ));
     756                }
     757                assert(rslt);
     758                auto expr = visitBaseExpr( node, rslt );
     759                this->node = expr;
    614760                return nullptr;
    615761        }
    616762
    617763        const ast::Expr * visit( const ast::SizeofExpr * node ) override final {
    618                 (void)node;
     764                assert (node->expr || node->type);
     765                assert (! (node->expr && node->type));
     766                SizeofExpr *rslt;
     767                if (node->expr) {
     768                        rslt = new SizeofExpr(
     769                                get<Expression>().accept1(node->expr)
     770                        );
     771                        assert (!rslt->isType);
     772                }
     773                if (node->type) {
     774                        rslt = new SizeofExpr(
     775                                get<Type>().accept1(node->type)
     776                        );
     777                        assert (rslt->isType);
     778                }
     779                auto expr = visitBaseExpr( node, rslt );
     780                this->node = expr;
    619781                return nullptr;
    620782        }
    621783
    622784        const ast::Expr * visit( const ast::AlignofExpr * node ) override final {
    623                 (void)node;
     785                assert (node->expr || node->type);
     786                assert (! (node->expr && node->type));
     787                AlignofExpr *rslt;
     788                if (node->expr) {
     789                        rslt = new AlignofExpr(
     790                                get<Expression>().accept1(node->expr)
     791                        );
     792                        assert (!rslt->isType);
     793                }
     794                if (node->type) {
     795                        rslt = new AlignofExpr(
     796                                get<Type>().accept1(node->type)
     797                        );
     798                        assert (rslt->isType);
     799                }
     800                auto expr = visitBaseExpr( node, rslt );
     801                this->node = expr;
    624802                return nullptr;
    625803        }
    626804
    627805        const ast::Expr * visit( const ast::UntypedOffsetofExpr * node ) override final {
    628                 (void)node;
     806                auto expr = visitBaseExpr( node,
     807                        new UntypedOffsetofExpr(
     808                                get<Type>().accept1(node->type),
     809                                node->member
     810                        )
     811                );
     812                this->node = expr;
    629813                return nullptr;
    630814        }
    631815
    632816        const ast::Expr * visit( const ast::OffsetofExpr * node ) override final {
    633                 (void)node;
     817                auto expr = visitBaseExpr( node,
     818                        new OffsetofExpr(
     819                                get<Type>().accept1(node->type),
     820                                inCache(node->member) ?
     821                                        dynamic_cast<DeclarationWithType *>(this->node) :
     822                                        get<DeclarationWithType>().accept1(node->member)
     823                        )
     824                );
     825                this->node = expr;
    634826                return nullptr;
    635827        }
    636828
    637829        const ast::Expr * visit( const ast::OffsetPackExpr * node ) override final {
    638                 (void)node;
     830                auto expr = visitBaseExpr( node,
     831                        new OffsetPackExpr(
     832                                get<StructInstType>().accept1(node->type)
     833                        )
     834                );
     835                this->node = expr;
    639836                return nullptr;
    640837        }
    641838
    642839        const ast::Expr * visit( const ast::LogicalExpr * node ) override final {
    643                 (void)node;
     840                assert (node->isAnd == ast::LogicalFlag::AndExpr ||
     841                                node->isAnd == ast::LogicalFlag::OrExpr );
     842                auto expr = visitBaseExpr( node,
     843                        new LogicalExpr(
     844                                get<Expression>().accept1(node->arg1),
     845                                get<Expression>().accept1(node->arg2),
     846                                (node->isAnd == ast::LogicalFlag::AndExpr)
     847                        )
     848                );
     849                this->node = expr;
    644850                return nullptr;
    645851        }
    646852
    647853        const ast::Expr * visit( const ast::ConditionalExpr * node ) override final {
    648                 (void)node;
     854                auto expr = visitBaseExpr( node,
     855                        new ConditionalExpr(
     856                                get<Expression>().accept1(node->arg1),
     857                                get<Expression>().accept1(node->arg2),
     858                                get<Expression>().accept1(node->arg3)
     859                        )
     860                );
     861                this->node = expr;
    649862                return nullptr;
    650863        }
    651864
    652865        const ast::Expr * visit( const ast::CommaExpr * node ) override final {
    653                 (void)node;
     866                auto expr = visitBaseExpr( node,
     867                        new CommaExpr(
     868                                get<Expression>().accept1(node->arg1),
     869                                get<Expression>().accept1(node->arg2)
     870                        )
     871                );
     872                this->node = expr;
    654873                return nullptr;
    655874        }
    656875
    657876        const ast::Expr * visit( const ast::TypeExpr * node ) override final {
    658                 (void)node;
     877                auto expr = visitBaseExpr( node,
     878                        new TypeExpr(
     879                                get<Type>().accept1(node->type)
     880                        )
     881                );
     882                this->node = expr;
    659883                return nullptr;
    660884        }
    661885
    662886        const ast::Expr * visit( const ast::AsmExpr * node ) override final {
    663                 (void)node;
     887                auto expr = visitBaseExpr( node,
     888                        new AsmExpr(
     889                                get<Expression>().accept1(node->inout),
     890                                get<Expression>().accept1(node->constraint),
     891                                get<Expression>().accept1(node->operand)
     892                        )
     893                );
     894                this->node = expr;
    664895                return nullptr;
    665896        }
    666897
    667898        const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final {
    668                 (void)node;
     899                auto rslt = new ImplicitCopyCtorExpr(
     900                        get<ApplicationExpr>().accept1(node->callExpr)
     901                );
     902
     903                rslt->tempDecls = get<ObjectDecl>().acceptL(node->tempDecls);
     904                rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls);
     905                rslt->dtors = get<Expression>().acceptL(node->dtors);
     906
     907                auto expr = visitBaseExpr( node, rslt );
     908                this->node = expr;
    669909                return nullptr;
    670910        }
    671911
    672912        const ast::Expr * visit( const ast::ConstructorExpr * node ) override final {
    673                 (void)node;
     913                auto expr = visitBaseExpr( node,
     914                        new ConstructorExpr(
     915                                get<Expression>().accept1(node->callExpr)
     916                        )
     917                );
     918                this->node = expr;
    674919                return nullptr;
    675920        }
    676921
    677922        const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final {
    678                 (void)node;
     923                auto expr = visitBaseExpr_skipResultType( node,
     924                        new CompoundLiteralExpr(
     925                                get<Type>().accept1(node->result),
     926                                get<Initializer>().accept1(node->init)
     927                        )
     928                );
     929                this->node = expr;
    679930                return nullptr;
    680931        }
    681932
    682933        const ast::Expr * visit( const ast::RangeExpr * node ) override final {
    683                 (void)node;
     934                auto expr = visitBaseExpr( node,
     935                        new RangeExpr(
     936                                get<Expression>().accept1(node->low),
     937                                get<Expression>().accept1(node->high)
     938                        )
     939                );
     940                this->node = expr;
    684941                return nullptr;
    685942        }
    686943
    687944        const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final {
    688                 (void)node;
     945                auto expr = visitBaseExpr( node,
     946                        new UntypedTupleExpr(
     947                                get<Expression>().acceptL(node->exprs)
     948                        )
     949                );
     950                this->node = expr;
    689951                return nullptr;
    690952        }
    691953
    692954        const ast::Expr * visit( const ast::TupleExpr * node ) override final {
    693                 (void)node;
     955                auto expr = visitBaseExpr( node,
     956                        new UntypedTupleExpr(
     957                                get<Expression>().acceptL(node->exprs)
     958                        )
     959                );
     960                this->node = expr;
    694961                return nullptr;
    695962        }
    696963
    697964        const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final {
    698                 (void)node;
     965                auto expr = visitBaseExpr( node,
     966                        new TupleIndexExpr(
     967                                get<Expression>().accept1(node->tuple),
     968                                node->index
     969                        )
     970                );
     971                this->node = expr;
    699972                return nullptr;
    700973        }
    701974
    702975        const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final {
    703                 (void)node;
     976                auto expr = visitBaseExpr( node,
     977                        new TupleAssignExpr(
     978                                get<StmtExpr>().accept1(node->stmtExpr)
     979                        )
     980                );
     981                this->node = expr;
    704982                return nullptr;
    705983        }
    706984
    707985        const ast::Expr * visit( const ast::StmtExpr * node ) override final {
    708                 (void)node;
     986                auto rslt = new StmtExpr(
     987                        get<CompoundStmt>().accept1(node->stmts)
     988                );
     989
     990                rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls);
     991                rslt->dtors       = get<Expression>().acceptL(node->dtors);
     992
     993                auto expr = visitBaseExpr( node, rslt );
     994                this->node = expr;
    709995                return nullptr;
    710996        }
    711997
    712998        const ast::Expr * visit( const ast::UniqueExpr * node ) override final {
    713                 (void)node;
     999                auto rslt = new UniqueExpr(
     1000                        get<Expression>().accept1(node->expr)
     1001                );
     1002
     1003                rslt->object = get<ObjectDecl>  ().accept1(node->object);
     1004                rslt->var    = get<VariableExpr>().accept1(node->var);
     1005
     1006                auto expr = visitBaseExpr( node, rslt );
     1007                this->node = expr;
    7141008                return nullptr;
    7151009        }
    7161010
    7171011        const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final {
    718                 (void)node;
     1012                std::list<InitAlternative> initAlts;
     1013                for (auto ia : node->initAlts) {
     1014                        initAlts.push_back(InitAlternative(
     1015                                get<Type>       ().accept1(ia.type),
     1016                                get<Designation>().accept1(ia.designation)
     1017                        ));
     1018                }
     1019                auto expr = visitBaseExpr( node,
     1020                        new UntypedInitExpr(
     1021                                get<Expression>().accept1(node->expr),
     1022                                initAlts
     1023                        )
     1024                );
     1025                this->node = expr;
    7191026                return nullptr;
    7201027        }
    7211028
    7221029        const ast::Expr * visit( const ast::InitExpr * node ) override final {
    723                 (void)node;
     1030                auto expr = visitBaseExpr( node,
     1031                        new InitExpr(
     1032                                get<Expression>().accept1(node->expr),
     1033                                get<Designation>().accept1(node->designation)
     1034                        )
     1035                );
     1036                this->node = expr;
    7241037                return nullptr;
    7251038        }
    7261039
    7271040        const ast::Expr * visit( const ast::DeletedExpr * node ) override final {
    728                 (void)node;
     1041                auto expr = visitBaseExpr( node,
     1042                        new DeletedExpr(
     1043                                get<Expression>().accept1(node->expr),
     1044                                inCache(node->deleteStmt) ?
     1045                                        this->node :
     1046                                        get<BaseSyntaxNode>().accept1(node->deleteStmt)
     1047                        )
     1048                );
     1049                this->node = expr;
    7291050                return nullptr;
    7301051        }
    7311052
    7321053        const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final {
    733                 (void)node;
     1054                auto expr = visitBaseExpr( node,
     1055                        new DefaultArgExpr(
     1056                                get<Expression>().accept1(node->expr)
     1057                        )
     1058                );
     1059                this->node = expr;
    7341060                return nullptr;
    7351061        }
    7361062
    7371063        const ast::Expr * visit( const ast::GenericExpr * node ) override final {
    738                 (void)node;
     1064                std::list<GenericExpr::Association> associations;
     1065                for (auto association : node->associations) {
     1066                        associations.push_back(GenericExpr::Association(
     1067                                get<Type>      ().accept1(association.type),
     1068                                get<Expression>().accept1(association.expr)
     1069                        ));
     1070                }
     1071                auto expr = visitBaseExpr( node,
     1072                        new GenericExpr(
     1073                                get<Expression>().accept1(node->control),
     1074                                associations
     1075                        )
     1076                );
     1077                this->node = expr;
    7391078                return nullptr;
    7401079        }
     
    9481287
    9491288        const ast::Designation * visit( const ast::Designation * node ) override final {
    950                 (void)node;
     1289                auto designation = new Designation( get<Expression>().acceptL( node->designators ) );
     1290                designation->location = node->location;
     1291                this->node = designation;
    9511292                return nullptr;
    9521293        }
    9531294
    9541295        const ast::Init * visit( const ast::SingleInit * node ) override final {
    955                 (void)node;
     1296                auto init = new SingleInit(
     1297                        get<Expression>().accept1( node->value ),
     1298                        ast::MaybeConstruct == node->maybeConstructed
     1299                );
     1300                init->location = node->location;
     1301                this->node = init;
    9561302                return nullptr;
    9571303        }
    9581304
    9591305        const ast::Init * visit( const ast::ListInit * node ) override final {
    960                 (void)node;
     1306                auto init = new ListInit(
     1307                        get<Initializer>().acceptL( node->initializers ),
     1308                        get<Designation>().acceptL( node->designations ),
     1309                        ast::MaybeConstruct == node->maybeConstructed
     1310                );
     1311                init->location = node->location;
     1312                this->node = init;
    9611313                return nullptr;
    9621314        }
    9631315
    9641316        const ast::Init * visit( const ast::ConstructorInit * node ) override final {
    965                 (void)node;
     1317                auto init = new ConstructorInit(
     1318                        get<Statement>().accept1( node->ctor ),
     1319                        get<Statement>().accept1( node->dtor ),
     1320                        get<Initializer>().accept1( node->init )
     1321                );
     1322                init->location = node->location;
     1323                this->node = init;
    9661324                return nullptr;
    9671325        }
    9681326
    9691327        const ast::Attribute * visit( const ast::Attribute * node ) override final {
    970                 (void)node;
     1328                auto attr = new Attribute(
     1329                        node->name,
     1330                        get<Expression>().acceptL(node->parameters)
     1331                );
     1332                this->node = attr;
    9711333                return nullptr;
    9721334        }
    9731335
    9741336        const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final {
    975                 (void)node;
     1337                // Handled by convertTypeSubstitution helper instead.
     1338                // TypeSubstitution is not a node in the old model, so the conversion result wouldn't fit in this->node.
     1339                assert( 0 );
    9761340                return nullptr;
    9771341        }
     
    10841448        virtual void visit( FunctionDecl * old ) override final {
    10851449                if ( inCache( old ) ) return;
    1086                 // TODO
    1087                 auto decl = (ast::FunctionDecl *)nullptr;
     1450                auto decl = new ast::FunctionDecl{
     1451                        old->location,
     1452                        old->name,
     1453                        GET_ACCEPT_1(type, FunctionType),
     1454                        GET_ACCEPT_1(statements, CompoundStmt),
     1455                        { old->storageClasses.val },
     1456                        { old->linkage.val },
     1457                        GET_ACCEPT_V(attributes, Attribute),
     1458                        { old->get_funcSpec().val }
     1459                };
     1460                decl->scopeLevel = old->scopeLevel;
     1461                decl->mangleName = old->mangleName;
     1462                decl->isDeleted  = old->isDeleted;
     1463                decl->uniqueId   = old->uniqueId;
     1464                decl->extension  = old->extension;
    10881465                cache.emplace( old, decl );
     1466
     1467                this->node = decl;
    10891468        }
    10901469
     
    11711550
    11721551        virtual void visit( TypeDecl * old ) override final {
    1173                 if ( inCache( old ) ) return;
    1174                 // TODO
    1175                 auto decl = (ast::TypeDecl *)nullptr;
     1552                if ( inCache( old ) ) return;   
     1553                auto decl = new ast::TypeDecl{
     1554                        old->location,
     1555                        old->name,
     1556                        { old->storageClasses.val },
     1557                        GET_ACCEPT_1(base, Type),
     1558                        (ast::TypeVar::Kind)(unsigned)old->kind,
     1559                        old->sized,
     1560                        GET_ACCEPT_1(init, Type)
     1561                };
     1562                decl->assertions = GET_ACCEPT_V(assertions, DeclWithType);
     1563                decl->params     = GET_ACCEPT_V(parameters, TypeDecl);
     1564                decl->extension  = old->extension;
     1565                decl->uniqueId   = old->uniqueId;
    11761566                cache.emplace( old, decl );
     1567
     1568                this->node = decl;
    11771569        }
    11781570
     
    11941586        }
    11951587
    1196         virtual void visit( AsmDecl * ) override final {
    1197 
    1198         }
    1199 
    1200         virtual void visit( StaticAssertDecl * ) override final {
    1201 
     1588        virtual void visit( AsmDecl * old ) override final {
     1589                auto decl = new ast::AsmDecl{
     1590                        old->location,
     1591                        GET_ACCEPT_1(stmt, AsmStmt)
     1592                };
     1593                decl->extension  = old->extension;
     1594                decl->uniqueId   = old->uniqueId;
     1595                decl->storage    = { old->storageClasses.val };
     1596
     1597                this->node = decl;
     1598        }
     1599
     1600        virtual void visit( StaticAssertDecl * old ) override final {
     1601                auto decl = new ast::StaticAssertDecl{
     1602                        old->location,
     1603                        GET_ACCEPT_1(condition, Expr),
     1604                        GET_ACCEPT_1(message, ConstantExpr)
     1605                };
     1606                decl->extension  = old->extension;
     1607                decl->uniqueId   = old->uniqueId;
     1608                decl->storage    = { old->storageClasses.val };
     1609
     1610                this->node = decl;
    12021611        }
    12031612
    12041613        virtual void visit( CompoundStmt * old ) override final {
     1614                if ( inCache( old ) ) return;
    12051615                auto stmt = new ast::CompoundStmt(
    12061616                        old->location,
     
    12101620
    12111621                this->node = stmt;
     1622                cache.emplace( old, this->node );
    12121623        }
    12131624
    12141625        virtual void visit( ExprStmt * old ) override final {
     1626                if ( inCache( old ) ) return;
    12151627                this->node = new ast::ExprStmt(
    12161628                        old->location,
     
    12181630                        GET_LABELS_V(old->labels)
    12191631                );
     1632                cache.emplace( old, this->node );
    12201633        }
    12211634
    12221635        virtual void visit( AsmStmt * old ) override final {
     1636                if ( inCache( old ) ) return;
    12231637                this->node = new ast::AsmStmt(
    12241638                        old->location,
     
    12311645                        GET_LABELS_V(old->labels)
    12321646                );
     1647                cache.emplace( old, this->node );
    12331648        }
    12341649
    12351650        virtual void visit( DirectiveStmt * old ) override final {
     1651                if ( inCache( old ) ) return;
    12361652                this->node = new ast::DirectiveStmt(
    12371653                        old->location,
     
    12391655                        GET_LABELS_V(old->labels)
    12401656                );
     1657                cache.emplace( old, this->node );
    12411658        }
    12421659
    12431660        virtual void visit( IfStmt * old ) override final {
     1661                if ( inCache( old ) ) return;
    12441662                this->node = new ast::IfStmt(
    12451663                        old->location,
     
    12501668                        GET_LABELS_V(old->labels)
    12511669                );
     1670                cache.emplace( old, this->node );
    12521671        }
    12531672
    12541673        virtual void visit( SwitchStmt * old ) override final {
     1674                if ( inCache( old ) ) return;
    12551675                this->node = new ast::SwitchStmt(
    12561676                        old->location,
     
    12591679                        GET_LABELS_V(old->labels)
    12601680                );
     1681                cache.emplace( old, this->node );
    12611682        }
    12621683
    12631684        virtual void visit( CaseStmt * old ) override final {
     1685                if ( inCache( old ) ) return;
    12641686                this->node = new ast::CaseStmt(
    12651687                        old->location,
     
    12681690                        GET_LABELS_V(old->labels)
    12691691                );
     1692                cache.emplace( old, this->node );
    12701693        }
    12711694
    12721695        virtual void visit( WhileStmt * old ) override final {
     1696                if ( inCache( old ) ) return;
    12731697                this->node = new ast::WhileStmt(
    12741698                        old->location,
     
    12791703                        GET_LABELS_V(old->labels)
    12801704                );
     1705                cache.emplace( old, this->node );
    12811706        }
    12821707
    12831708        virtual void visit( ForStmt * old ) override final {
     1709                if ( inCache( old ) ) return;
    12841710                this->node = new ast::ForStmt(
    12851711                        old->location,
     
    12901716                        GET_LABELS_V(old->labels)
    12911717                );
     1718                cache.emplace( old, this->node );
    12921719        }
    12931720
    12941721        virtual void visit( BranchStmt * old ) override final {
     1722                if ( inCache( old ) ) return;
    12951723                if (old->computedTarget) {
    12961724                        this->node = new ast::BranchStmt(
     
    13261754                        this->node = stmt;
    13271755                }
     1756                cache.emplace( old, this->node );
    13281757        }
    13291758
    13301759        virtual void visit( ReturnStmt * old ) override final {
     1760                if ( inCache( old ) ) return;
    13311761                this->node = new ast::ReturnStmt(
    13321762                        old->location,
     
    13341764                        GET_LABELS_V(old->labels)
    13351765                );
     1766                cache.emplace( old, this->node );
    13361767        }
    13371768
    13381769        virtual void visit( ThrowStmt * old ) override final {
     1770                if ( inCache( old ) ) return;
    13391771                ast::ThrowStmt::Kind kind;
    13401772                switch (old->kind) {
     
    13561788                        GET_LABELS_V(old->labels)
    13571789                );
     1790                cache.emplace( old, this->node );
    13581791        }
    13591792
    13601793        virtual void visit( TryStmt * old ) override final {
     1794                if ( inCache( old ) ) return;
    13611795                this->node = new ast::TryStmt(
    13621796                        old->location,
     
    13661800                        GET_LABELS_V(old->labels)
    13671801                );
     1802                cache.emplace( old, this->node );
    13681803        }
    13691804
    13701805        virtual void visit( CatchStmt * old ) override final {
     1806                if ( inCache( old ) ) return;
    13711807                ast::CatchStmt::Kind kind;
    13721808                switch (old->kind) {
     
    13891825                        GET_LABELS_V(old->labels)
    13901826                );
     1827                cache.emplace( old, this->node );
    13911828        }
    13921829
    13931830        virtual void visit( FinallyStmt * old ) override final {
     1831                if ( inCache( old ) ) return;
    13941832                this->node = new ast::FinallyStmt(
    13951833                        old->location,
     
    13971835                        GET_LABELS_V(old->labels)
    13981836                );
     1837                cache.emplace( old, this->node );
    13991838        }
    14001839
    14011840        virtual void visit( WaitForStmt * old ) override final {
     1841                if ( inCache( old ) ) return;
    14021842                ast::WaitForStmt * stmt = new ast::WaitForStmt(
    14031843                        old->location,
     
    14271867
    14281868                this->node = stmt;
     1869                cache.emplace( old, this->node );
    14291870        }
    14301871
    14311872        virtual void visit( WithStmt * old ) override final {
     1873                if ( inCache( old ) ) return;
    14321874                this->node = new ast::WithStmt(
    14331875                        old->location,
     
    14361878                        GET_LABELS_V(old->labels)
    14371879                );
     1880                cache.emplace( old, this->node );
    14381881        }
    14391882
    14401883        virtual void visit( NullStmt * old ) override final {
     1884                if ( inCache( old ) ) return;
    14411885                this->node = new ast::NullStmt(
    14421886                        old->location,
    14431887                        GET_LABELS_V(old->labels)
    14441888                );
     1889                cache.emplace( old, this->node );
    14451890        }
    14461891
    14471892        virtual void visit( DeclStmt * old ) override final {
     1893                if ( inCache( old ) ) return;
    14481894                this->node = new ast::DeclStmt(
    14491895                        old->location,
     
    14511897                        GET_LABELS_V(old->labels)
    14521898                );
     1899                cache.emplace( old, this->node );
    14531900        }
    14541901
    14551902        virtual void visit( ImplicitCtorDtorStmt * old ) override final {
     1903                if ( inCache( old ) ) return;
    14561904                this->node = new ast::ImplicitCtorDtorStmt(
    14571905                        old->location,
     
    14591907                        GET_LABELS_V(old->labels)
    14601908                );
     1909                cache.emplace( old, this->node );
    14611910        }
    14621911
     
    15031952        }
    15041953
    1505         ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) {
    1506 
    1507                 nw->result = GET_ACCEPT_1(result, Type);
     1954        ast::Expr * visitBaseExpr_SkipResultType(Expression * old, ast::Expr * nw) {
     1955
    15081956                nw->env    = convertTypeSubstitution(old->env);
    15091957
     
    15121960
    15131961                return nw;
     1962        }
     1963
     1964        ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) {
     1965
     1966                nw->result = GET_ACCEPT_1(result, Type);
     1967                return visitBaseExpr_SkipResultType(old, nw);;
    15141968        }
    15151969
     
    15472001                        new ast::CastExpr(
    15482002                                old->location,
    1549                                 nullptr, // cast's "to" type is expr's result type; converted in visitBaseExpr
     2003                                GET_ACCEPT_1(arg, Expr),
    15502004                                old->isGenerated ? ast::GeneratedCast : ast::ExplicitCast
    15512005                        )
     
    15532007        }
    15542008
    1555         virtual void visit( KeywordCastExpr * ) override final {
    1556 
    1557         }
    1558 
    1559         virtual void visit( VirtualCastExpr * ) override final {
    1560 
    1561         }
    1562 
    1563         virtual void visit( AddressExpr * ) override final {
    1564 
    1565         }
    1566 
    1567         virtual void visit( LabelAddressExpr * ) override final {
    1568 
    1569         }
    1570 
    1571         virtual void visit( UntypedMemberExpr * ) override final {
    1572 
    1573         }
    1574 
    1575         virtual void visit( MemberExpr * ) override final {
    1576 
    1577         }
    1578 
    1579         virtual void visit( VariableExpr * ) override final {
    1580 
    1581         }
    1582 
    1583         virtual void visit( ConstantExpr * ) override final {
    1584 
    1585         }
    1586 
    1587         virtual void visit( SizeofExpr * ) override final {
    1588 
    1589         }
    1590 
    1591         virtual void visit( AlignofExpr * ) override final {
    1592 
    1593         }
    1594 
    1595         virtual void visit( UntypedOffsetofExpr * ) override final {
    1596 
    1597         }
    1598 
    1599         virtual void visit( OffsetofExpr * ) override final {
    1600 
    1601         }
    1602 
    1603         virtual void visit( OffsetPackExpr * ) override final {
    1604 
    1605         }
    1606 
    1607         virtual void visit( LogicalExpr * ) override final {
    1608 
    1609         }
    1610 
    1611         virtual void visit( ConditionalExpr * ) override final {
    1612 
    1613         }
    1614 
    1615         virtual void visit( CommaExpr * ) override final {
    1616 
    1617         }
    1618 
    1619         virtual void visit( TypeExpr * ) override final {
    1620 
    1621         }
    1622 
    1623         virtual void visit( AsmExpr * ) override final {
    1624 
    1625         }
    1626 
    1627         virtual void visit( ImplicitCopyCtorExpr * ) override final {
    1628 
    1629         }
    1630 
    1631         virtual void visit( ConstructorExpr *  ) override final {
    1632 
    1633         }
    1634 
    1635         virtual void visit( CompoundLiteralExpr * ) override final {
    1636 
    1637         }
    1638 
    1639         virtual void visit( RangeExpr * ) override final {
    1640 
    1641         }
    1642 
    1643         virtual void visit( UntypedTupleExpr * ) override final {
    1644 
    1645         }
    1646 
    1647         virtual void visit( TupleExpr * ) override final {
    1648 
    1649         }
    1650 
    1651         virtual void visit( TupleIndexExpr * ) override final {
    1652 
    1653         }
    1654 
    1655         virtual void visit( TupleAssignExpr * ) override final {
    1656 
    1657         }
    1658 
    1659         virtual void visit( StmtExpr *  ) override final {
    1660 
    1661         }
    1662 
    1663         virtual void visit( UniqueExpr *  ) override final {
    1664 
    1665         }
    1666 
    1667         virtual void visit( UntypedInitExpr *  ) override final {
    1668 
    1669         }
    1670 
    1671         virtual void visit( InitExpr *  ) override final {
    1672 
    1673         }
    1674 
    1675         virtual void visit( DeletedExpr * ) override final {
    1676 
    1677         }
    1678 
    1679         virtual void visit( DefaultArgExpr * ) override final {
    1680 
    1681         }
    1682 
    1683         virtual void visit( GenericExpr * ) override final {
    1684 
     2009        virtual void visit( KeywordCastExpr * old) override final {
     2010                ast::KeywordCastExpr::Target castTarget = ast::KeywordCastExpr::NUMBER_OF_TARGETS;
     2011                switch (old->target) {
     2012                        case KeywordCastExpr::Coroutine:
     2013                                castTarget = ast::KeywordCastExpr::Coroutine;
     2014                                break;
     2015                        case KeywordCastExpr::Thread:
     2016                                castTarget = ast::KeywordCastExpr::Thread;
     2017                                break;
     2018                        case KeywordCastExpr::Monitor:
     2019                                castTarget = ast::KeywordCastExpr::Monitor;
     2020                                break;
     2021                        default:
     2022                                break;
     2023                }
     2024                assert ( castTarget < ast::KeywordCastExpr::NUMBER_OF_TARGETS );
     2025                this->node = visitBaseExpr( old,
     2026                        new ast::KeywordCastExpr(
     2027                                old->location,
     2028                                GET_ACCEPT_1(arg, Expr),
     2029                                castTarget
     2030                        )
     2031                );
     2032        }
     2033
     2034        virtual void visit( VirtualCastExpr * old ) override final {
     2035                this->node = visitBaseExpr_SkipResultType( old,
     2036                        new ast::VirtualCastExpr(
     2037                                old->location,
     2038                                GET_ACCEPT_1(arg, Expr),
     2039                                GET_ACCEPT_1(result, Type)
     2040                        )
     2041                );
     2042        }
     2043
     2044        virtual void visit( AddressExpr * old ) override final {
     2045                this->node = visitBaseExpr( old,
     2046                        new ast::AddressExpr(
     2047                                old->location,
     2048                                GET_ACCEPT_1(arg, Expr)
     2049                        )
     2050                );
     2051        }
     2052
     2053        virtual void visit( LabelAddressExpr * old ) override final {
     2054                this->node = visitBaseExpr( old,
     2055                        new ast::LabelAddressExpr(
     2056                                old->location,
     2057                                make_label(&old->arg)
     2058                        )
     2059                );
     2060        }
     2061
     2062        virtual void visit( UntypedMemberExpr * old ) override final {
     2063                this->node = visitBaseExpr( old,
     2064                        new ast::UntypedMemberExpr(
     2065                                old->location,
     2066                                GET_ACCEPT_1(member, Expr),
     2067                                GET_ACCEPT_1(aggregate, Expr)
     2068                        )
     2069                );
     2070        }
     2071
     2072        virtual void visit( MemberExpr * old ) override final {
     2073                this->node = visitBaseExpr( old,
     2074                        new ast::MemberExpr(
     2075                                old->location,
     2076                                inCache(old->member) ?
     2077                                        dynamic_cast<ast::DeclWithType *>(this->node) :
     2078                                        GET_ACCEPT_1(member, DeclWithType),
     2079                                GET_ACCEPT_1(aggregate, Expr)
     2080                        )
     2081                );
     2082        }
     2083
     2084        virtual void visit( VariableExpr * old ) override final {
     2085                this->node = visitBaseExpr( old,
     2086                        new ast::VariableExpr(
     2087                                old->location,
     2088                                inCache(old->var) ?
     2089                                        dynamic_cast<ast::DeclWithType *>(this->node) :
     2090                                        GET_ACCEPT_1(var, DeclWithType)
     2091                        )
     2092                );
     2093        }
     2094
     2095        bool isIntlikeConstantType(const Type *t) {
     2096                if ( const BasicType * basicType = dynamic_cast< const BasicType * >( t ) ) {
     2097                        if ( basicType->isInteger() ) {
     2098                                return true;
     2099                        }
     2100                } else if ( dynamic_cast< const OneType * >( t ) ) {
     2101                        return true;
     2102                } else if ( dynamic_cast< const ZeroType * >( t ) ) {
     2103                        return true;
     2104                } else if ( dynamic_cast< const PointerType * >( t ) ) {
     2105                        // null pointer constants, with zero int-values
     2106                        return true;
     2107                }
     2108                return false;
     2109        }
     2110
     2111        int isFloatlikeConstantType(const Type *t) {
     2112                if ( const BasicType * bty = dynamic_cast< const BasicType * >( t ) ) {
     2113                        if ( ! bty->isInteger() ) {
     2114                                return true;
     2115                        }
     2116                }
     2117                return false;
     2118        }
     2119
     2120        int isStringlikeConstantType(const Type *t) {
     2121                if ( const ArrayType * aty = dynamic_cast< const ArrayType * >( t ) ) {
     2122                        if ( const BasicType * bty = dynamic_cast< const BasicType * >( aty->base ) ) {
     2123                           if ( bty->kind == BasicType::Kind::Char ) {
     2124                                   return true;
     2125                           }
     2126                        }
     2127                }
     2128                return false;
     2129        }
     2130
     2131        virtual void visit( ConstantExpr * old ) override final {
     2132                ast::ConstantExpr *rslt = nullptr;
     2133                if (isIntlikeConstantType(old->result)) {
     2134                        rslt = new ast::ConstantExpr(
     2135                                old->location,
     2136                                GET_ACCEPT_1(result, Type),
     2137                                old->constant.get_value(),
     2138                                (unsigned long long) old->intValue()
     2139                        );
     2140                } else if (isFloatlikeConstantType(old->result)) {
     2141                        rslt = new ast::ConstantExpr(
     2142                                old->location,
     2143                                GET_ACCEPT_1(result, Type),
     2144                                old->constant.get_value(),
     2145                                (double) old->constant.get_dval()
     2146                        );
     2147                } else if (isStringlikeConstantType(old->result)) {
     2148                        rslt = ast::ConstantExpr::from_string(
     2149                                old->location,
     2150                                old->constant.get_value()
     2151                        );
     2152                }
     2153                assert(rslt);
     2154                this->node = visitBaseExpr( old, rslt );
     2155        }
     2156
     2157        virtual void visit( SizeofExpr * old ) override final {
     2158                assert (old->expr || old->type);
     2159                assert (! (old->expr && old->type));
     2160                ast::SizeofExpr *rslt;
     2161                if (old->expr) {
     2162                        assert(!old->isType);
     2163                        rslt = new ast::SizeofExpr(
     2164                                old->location,
     2165                                GET_ACCEPT_1(expr, Expr)
     2166                        );
     2167                }
     2168                if (old->type) {
     2169                        assert(old->isType);
     2170                        rslt = new ast::SizeofExpr(
     2171                                old->location,
     2172                                GET_ACCEPT_1(type, Type)
     2173                        );
     2174                }
     2175                this->node = visitBaseExpr( old, rslt );
     2176        }
     2177
     2178        virtual void visit( AlignofExpr * old ) override final {
     2179                assert (old->expr || old->type);
     2180                assert (! (old->expr && old->type));
     2181                ast::AlignofExpr *rslt;
     2182                if (old->expr) {
     2183                        assert(!old->isType);
     2184                        rslt = new ast::AlignofExpr(
     2185                                old->location,
     2186                                GET_ACCEPT_1(expr, Expr)
     2187                        );
     2188                }
     2189                if (old->type) {
     2190                        assert(old->isType);
     2191                        rslt = new ast::AlignofExpr(
     2192                                old->location,
     2193                                GET_ACCEPT_1(type, Type)
     2194                        );
     2195                }
     2196                this->node = visitBaseExpr( old, rslt );
     2197        }
     2198
     2199        virtual void visit( UntypedOffsetofExpr * old ) override final {
     2200                this->node = visitBaseExpr( old,
     2201                        new ast::UntypedOffsetofExpr(
     2202                                old->location,
     2203                                GET_ACCEPT_1(type, Type),
     2204                                old->member
     2205                        )
     2206                );
     2207        }
     2208
     2209        virtual void visit( OffsetofExpr * old ) override final {
     2210                this->node = visitBaseExpr( old,
     2211                        new ast::OffsetofExpr(
     2212                                old->location,
     2213                                GET_ACCEPT_1(type, Type),
     2214                                inCache(old->member) ?
     2215                                        dynamic_cast<ast::DeclWithType *>(this->node) :
     2216                                        GET_ACCEPT_1(member, DeclWithType)
     2217                        )
     2218                );
     2219        }
     2220
     2221        virtual void visit( OffsetPackExpr * old ) override final {
     2222                this->node = visitBaseExpr( old,
     2223                        new ast::OffsetPackExpr(
     2224                                old->location,
     2225                                GET_ACCEPT_1(type, StructInstType)
     2226                        )
     2227                );
     2228        }
     2229
     2230        virtual void visit( LogicalExpr * old ) override final {
     2231                this->node = visitBaseExpr( old,
     2232                        new ast::LogicalExpr(
     2233                                old->location,
     2234                                GET_ACCEPT_1(arg1, Expr),
     2235                                GET_ACCEPT_1(arg2, Expr),
     2236                                old->get_isAnd() ?
     2237                                        ast::LogicalFlag::AndExpr :
     2238                                        ast::LogicalFlag::OrExpr
     2239                        )
     2240                );
     2241        }
     2242
     2243        virtual void visit( ConditionalExpr * old ) override final {
     2244                this->node = visitBaseExpr( old,
     2245                        new ast::ConditionalExpr(
     2246                                old->location,
     2247                                GET_ACCEPT_1(arg1, Expr),
     2248                                GET_ACCEPT_1(arg2, Expr),
     2249                                GET_ACCEPT_1(arg3, Expr)
     2250                        )
     2251                );
     2252        }
     2253
     2254        virtual void visit( CommaExpr * old ) override final {
     2255                this->node = visitBaseExpr( old,
     2256                        new ast::CommaExpr(
     2257                                old->location,
     2258                                GET_ACCEPT_1(arg1, Expr),
     2259                                GET_ACCEPT_1(arg2, Expr)
     2260                        )
     2261                );
     2262        }
     2263
     2264        virtual void visit( TypeExpr * old ) override final {
     2265                this->node = visitBaseExpr( old,
     2266                        new ast::TypeExpr(
     2267                                old->location,
     2268                                GET_ACCEPT_1(type, Type)
     2269                        )
     2270                );
     2271        }
     2272
     2273        virtual void visit( AsmExpr * old ) override final {
     2274                this->node = visitBaseExpr( old,
     2275                        new ast::AsmExpr(
     2276                                old->location,
     2277                                GET_ACCEPT_1(inout, Expr),
     2278                                GET_ACCEPT_1(constraint, Expr),
     2279                                GET_ACCEPT_1(operand, Expr)
     2280                        )
     2281                );
     2282        }
     2283
     2284        virtual void visit( ImplicitCopyCtorExpr * old ) override final {
     2285                auto rslt = new ast::ImplicitCopyCtorExpr(
     2286                        old->location,
     2287                        GET_ACCEPT_1(callExpr, ApplicationExpr)
     2288                );
     2289
     2290                rslt->tempDecls = GET_ACCEPT_V(tempDecls, ObjectDecl);
     2291                rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl);
     2292                rslt->dtors = GET_ACCEPT_V(dtors, Expr);
     2293
     2294                this->node = visitBaseExpr( old, rslt );
     2295        }
     2296
     2297        virtual void visit( ConstructorExpr * old ) override final {
     2298                this->node = visitBaseExpr( old,
     2299                        new ast::ConstructorExpr(
     2300                                old->location,
     2301                                GET_ACCEPT_1(callExpr, Expr)
     2302                        )
     2303                );
     2304        }
     2305
     2306        virtual void visit( CompoundLiteralExpr * old ) override final {
     2307                this->node = visitBaseExpr_SkipResultType( old,
     2308                        new ast::CompoundLiteralExpr(
     2309                                old->location,
     2310                                GET_ACCEPT_1(result, Type),
     2311                                GET_ACCEPT_1(initializer, Init)
     2312                        )
     2313                );
     2314        }
     2315
     2316        virtual void visit( RangeExpr * old ) override final {
     2317                this->node = visitBaseExpr( old,
     2318                        new ast::RangeExpr(
     2319                                old->location,
     2320                                GET_ACCEPT_1(low, Expr),
     2321                                GET_ACCEPT_1(high, Expr)
     2322                        )
     2323                );
     2324        }
     2325
     2326        virtual void visit( UntypedTupleExpr * old ) override final {
     2327                this->node = visitBaseExpr( old,
     2328                        new ast::UntypedTupleExpr(
     2329                                old->location,
     2330                                GET_ACCEPT_V(exprs, Expr)
     2331                        )
     2332                );
     2333        }
     2334
     2335        virtual void visit( TupleExpr * old ) override final {
     2336                this->node = visitBaseExpr( old,
     2337                        new ast::TupleExpr(
     2338                                old->location,
     2339                                GET_ACCEPT_V(exprs, Expr)
     2340                        )
     2341                );
     2342        }
     2343
     2344        virtual void visit( TupleIndexExpr * old ) override final {
     2345                this->node = visitBaseExpr( old,
     2346                        new ast::TupleIndexExpr(
     2347                                old->location,
     2348                                GET_ACCEPT_1(tuple, Expr),
     2349                                old->index
     2350                        )
     2351                );
     2352        }
     2353
     2354        virtual void visit( TupleAssignExpr * old ) override final {
     2355                this->node = visitBaseExpr_SkipResultType( old,
     2356                        new ast::TupleAssignExpr(
     2357                                old->location,
     2358                                GET_ACCEPT_1(result, Type),
     2359                                GET_ACCEPT_1(stmtExpr, StmtExpr)
     2360                        )
     2361                );
     2362        }
     2363
     2364        virtual void visit( StmtExpr * old ) override final {
     2365                auto rslt = new ast::StmtExpr(
     2366                        old->location,
     2367                        GET_ACCEPT_1(statements, CompoundStmt)
     2368                );
     2369                rslt->returnDecls = GET_ACCEPT_V(returnDecls, ObjectDecl);
     2370                rslt->dtors       = GET_ACCEPT_V(dtors      , Expr);
     2371
     2372                this->node = visitBaseExpr_SkipResultType( old, rslt );
     2373        }
     2374
     2375        virtual void visit( UniqueExpr * old ) override final {
     2376                auto rslt = new ast::UniqueExpr(
     2377                        old->location,
     2378                        GET_ACCEPT_1(expr, Expr)
     2379                );
     2380                rslt->object = GET_ACCEPT_1(object, ObjectDecl);
     2381                rslt->var    = GET_ACCEPT_1(var   , VariableExpr);
     2382
     2383                this->node = visitBaseExpr( old, rslt );
     2384        }
     2385
     2386        virtual void visit( UntypedInitExpr * old ) override final {
     2387                std::vector<ast::InitAlternative> initAlts;
     2388                for (auto ia : old->initAlts) {
     2389                        initAlts.push_back(ast::InitAlternative(
     2390                                getAccept1< ast::Type, Type * >( ia.type ),
     2391                                getAccept1< ast::Designation, Designation * >( ia.designation )
     2392                        ));
     2393                }
     2394                this->node = visitBaseExpr( old,
     2395                        new ast::UntypedInitExpr(
     2396                                old->location,
     2397                                GET_ACCEPT_1(expr, Expr),
     2398                                std::move(initAlts)
     2399                        )
     2400                );
     2401        }
     2402
     2403        virtual void visit( InitExpr * old ) override final {
     2404                this->node = visitBaseExpr( old,
     2405                        new ast::InitExpr(
     2406                                old->location,
     2407                                GET_ACCEPT_1(expr, Expr),
     2408                                GET_ACCEPT_1(designation, Designation)
     2409                        )
     2410                );
     2411        }
     2412
     2413        virtual void visit( DeletedExpr * old ) override final {
     2414                this->node = visitBaseExpr( old,
     2415                        new ast::DeletedExpr(
     2416                                old->location,
     2417                                GET_ACCEPT_1(expr, Expr),
     2418                                inCache(old->deleteStmt) ?
     2419                                        this->node :
     2420                                        GET_ACCEPT_1(deleteStmt, Node)
     2421                        )
     2422                );
     2423        }
     2424
     2425        virtual void visit( DefaultArgExpr * old ) override final {
     2426                this->node = visitBaseExpr( old,
     2427                        new ast::DefaultArgExpr(
     2428                                old->location,
     2429                                GET_ACCEPT_1(expr, Expr)
     2430                        )
     2431                );
     2432        }
     2433
     2434        virtual void visit( GenericExpr * old ) override final {
     2435                std::vector<ast::GenericExpr::Association> associations;
     2436                for (auto association : old->associations) {
     2437                        associations.push_back(ast::GenericExpr::Association(
     2438                                getAccept1< ast::Type, Type * >( association.type ),
     2439                                getAccept1< ast::Expr, Expression * >( association.expr )
     2440                        ));
     2441                }
     2442                this->node = visitBaseExpr( old,
     2443                        new ast::GenericExpr(
     2444                                old->location,
     2445                                GET_ACCEPT_1(control, Expr),
     2446                                std::move(associations)
     2447                        )
     2448                );
    16852449        }
    16862450
     
    18782642        }
    18792643
    1880         virtual void visit( Designation * ) override final {
    1881 
    1882         }
    1883 
    1884         virtual void visit( SingleInit * ) override final {
    1885 
    1886         }
    1887 
    1888         virtual void visit( ListInit * ) override final {
    1889 
    1890         }
    1891 
    1892         virtual void visit( ConstructorInit * ) override final {
    1893 
     2644        virtual void visit( Designation * old ) override final {
     2645                this->node = new ast::Designation(
     2646                        old->location,
     2647                        GET_ACCEPT_V(designators, Expr)
     2648                );
     2649        }
     2650
     2651        virtual void visit( SingleInit * old ) override final {
     2652                this->node = new ast::SingleInit(
     2653                        old->location,
     2654                        GET_ACCEPT_1(value, Expr),
     2655                        (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct
     2656                );
     2657        }
     2658
     2659        virtual void visit( ListInit * old ) override final {
     2660                this->node = new ast::ListInit(
     2661                        old->location,
     2662                        GET_ACCEPT_V(initializers, Init),
     2663                        GET_ACCEPT_V(designations, Designation),
     2664                        (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct
     2665                );
     2666        }
     2667
     2668        virtual void visit( ConstructorInit * old ) override final {
     2669                this->node = new ast::ConstructorInit(
     2670                        old->location,
     2671                        GET_ACCEPT_1(ctor, Stmt),
     2672                        GET_ACCEPT_1(dtor, Stmt),
     2673                        GET_ACCEPT_1(init, Init)
     2674                );
    18942675        }
    18952676
    18962677        virtual void visit( Constant * ) override final {
    1897 
    1898         }
    1899 
    1900         virtual void visit( Attribute * ) override final {
    1901 
     2678                // Handled in visit( ConstantEpxr * ).
     2679                // In the new tree, Constant fields are inlined into containing ConstantExpression.
     2680                assert( 0 );
     2681        }
     2682
     2683        virtual void visit( Attribute * old ) override final {
     2684                this->node = new ast::Attribute(
     2685                        old->name,
     2686                        GET_ACCEPT_V( parameters, Expr )
     2687                );
    19022688        }
    19032689
    19042690        virtual void visit( AttrExpr * ) override final {
    1905 
    1906                 assert( 0 );
     2691                assertf( false, "AttrExpr deprecated in new AST." );
    19072692        }
    19082693};
Note: See TracChangeset for help on using the changeset viewer.