Changeset f4c2f1a


Ignore:
Timestamp:
May 22, 2019, 3:23:25 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
6380f78, 8abee136, dff6452
Parents:
e9b44489 (diff), dd6d7c6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • doc/proposals/vtable.md

    re9b44489 rf4c2f1a  
    220220    trait iterator(otype T, otype Item) {
    221221        bool has_next(T const &);
    222         Item get_next(T const *);
     222        Item get_next(T &);
    223223    }
    224224
  • src/AST/Convert.cpp

    re9b44489 rf4c2f1a  
    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
     
    628654
    629655        const ast::Expr * visit( const ast::VirtualCastExpr * node ) override final {
    630                 auto expr = visitBaseExpr( node,
     656                auto expr = visitBaseExpr_skipResultType( node,
    631657                        new VirtualCastExpr(
    632658                                get<Expression>().accept1(node->arg),
    633                                 nullptr // cast's "to" type is expr's result type; converted in visitBaseExpr
     659                                get<Type>().accept1(node->result)
    634660                        )
    635661                );
     
    849875
    850876        const ast::Expr * visit( const ast::TypeExpr * node ) override final {
    851                 (void)node;
     877                auto expr = visitBaseExpr( node,
     878                        new TypeExpr(
     879                                get<Type>().accept1(node->type)
     880                        )
     881                );
     882                this->node = expr;
    852883                return nullptr;
    853884        }
    854885
    855886        const ast::Expr * visit( const ast::AsmExpr * node ) override final {
    856                 (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;
    857895                return nullptr;
    858896        }
    859897
    860898        const ast::Expr * visit( const ast::ImplicitCopyCtorExpr * node ) override final {
    861                 (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;
    862909                return nullptr;
    863910        }
    864911
    865912        const ast::Expr * visit( const ast::ConstructorExpr * node ) override final {
    866                 (void)node;
     913                auto expr = visitBaseExpr( node,
     914                        new ConstructorExpr(
     915                                get<Expression>().accept1(node->callExpr)
     916                        )
     917                );
     918                this->node = expr;
    867919                return nullptr;
    868920        }
    869921
    870922        const ast::Expr * visit( const ast::CompoundLiteralExpr * node ) override final {
    871                 (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;
    872930                return nullptr;
    873931        }
    874932
    875933        const ast::Expr * visit( const ast::RangeExpr * node ) override final {
    876                 (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;
    877941                return nullptr;
    878942        }
    879943
    880944        const ast::Expr * visit( const ast::UntypedTupleExpr * node ) override final {
    881                 (void)node;
     945                auto expr = visitBaseExpr( node,
     946                        new UntypedTupleExpr(
     947                                get<Expression>().acceptL(node->exprs)
     948                        )
     949                );
     950                this->node = expr;
    882951                return nullptr;
    883952        }
    884953
    885954        const ast::Expr * visit( const ast::TupleExpr * node ) override final {
    886                 (void)node;
     955                auto expr = visitBaseExpr( node,
     956                        new UntypedTupleExpr(
     957                                get<Expression>().acceptL(node->exprs)
     958                        )
     959                );
     960                this->node = expr;
    887961                return nullptr;
    888962        }
    889963
    890964        const ast::Expr * visit( const ast::TupleIndexExpr * node ) override final {
    891                 (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;
    892972                return nullptr;
    893973        }
    894974
    895975        const ast::Expr * visit( const ast::TupleAssignExpr * node ) override final {
    896                 (void)node;
     976                auto expr = visitBaseExpr( node,
     977                        new TupleAssignExpr(
     978                                get<StmtExpr>().accept1(node->stmtExpr)
     979                        )
     980                );
     981                this->node = expr;
    897982                return nullptr;
    898983        }
    899984
    900985        const ast::Expr * visit( const ast::StmtExpr * node ) override final {
    901                 (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;
    902995                return nullptr;
    903996        }
    904997
    905998        const ast::Expr * visit( const ast::UniqueExpr * node ) override final {
    906                 (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;
    9071008                return nullptr;
    9081009        }
    9091010
    9101011        const ast::Expr * visit( const ast::UntypedInitExpr * node ) override final {
    911                 (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;
    9121026                return nullptr;
    9131027        }
    9141028
    9151029        const ast::Expr * visit( const ast::InitExpr * node ) override final {
    916                 (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;
    9171037                return nullptr;
    9181038        }
    9191039
    9201040        const ast::Expr * visit( const ast::DeletedExpr * node ) override final {
    921                 (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;
    9221050                return nullptr;
    9231051        }
    9241052
    9251053        const ast::Expr * visit( const ast::DefaultArgExpr * node ) override final {
    926                 (void)node;
     1054                auto expr = visitBaseExpr( node,
     1055                        new DefaultArgExpr(
     1056                                get<Expression>().accept1(node->expr)
     1057                        )
     1058                );
     1059                this->node = expr;
    9271060                return nullptr;
    9281061        }
    9291062
    9301063        const ast::Expr * visit( const ast::GenericExpr * node ) override final {
    931                 (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;
    9321078                return nullptr;
    9331079        }
     
    11411287
    11421288        const ast::Designation * visit( const ast::Designation * node ) override final {
    1143                 (void)node;
     1289                auto designation = new Designation( get<Expression>().acceptL( node->designators ) );
     1290                designation->location = node->location;
     1291                this->node = designation;
    11441292                return nullptr;
    11451293        }
    11461294
    11471295        const ast::Init * visit( const ast::SingleInit * node ) override final {
    1148                 (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;
    11491302                return nullptr;
    11501303        }
    11511304
    11521305        const ast::Init * visit( const ast::ListInit * node ) override final {
    1153                 (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;
    11541313                return nullptr;
    11551314        }
    11561315
    11571316        const ast::Init * visit( const ast::ConstructorInit * node ) override final {
    1158                 (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;
    11591324                return nullptr;
    11601325        }
    11611326
    11621327        const ast::Attribute * visit( const ast::Attribute * node ) override final {
    1163                 (void)node;
     1328                auto attr = new Attribute(
     1329                        node->name,
     1330                        get<Expression>().acceptL(node->parameters)
     1331                );
     1332                this->node = attr;
    11641333                return nullptr;
    11651334        }
    11661335
    11671336        const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final {
    1168                 (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 );
    11691340                return nullptr;
    11701341        }
     
    12771448        virtual void visit( FunctionDecl * old ) override final {
    12781449                if ( inCache( old ) ) return;
    1279                 // TODO
    1280                 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;
    12811465                cache.emplace( old, decl );
     1466
     1467                this->node = decl;
    12821468        }
    12831469
     
    13641550
    13651551        virtual void visit( TypeDecl * old ) override final {
    1366                 if ( inCache( old ) ) return;
    1367                 // TODO
    1368                 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;
    13691566                cache.emplace( old, decl );
     1567
     1568                this->node = decl;
    13701569        }
    13711570
     
    13871586        }
    13881587
    1389         virtual void visit( AsmDecl * ) override final {
    1390 
    1391         }
    1392 
    1393         virtual void visit( StaticAssertDecl * ) override final {
    1394 
     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;
    13951611        }
    13961612
    13971613        virtual void visit( CompoundStmt * old ) override final {
     1614                if ( inCache( old ) ) return;
    13981615                auto stmt = new ast::CompoundStmt(
    13991616                        old->location,
     
    14031620
    14041621                this->node = stmt;
     1622                cache.emplace( old, this->node );
    14051623        }
    14061624
    14071625        virtual void visit( ExprStmt * old ) override final {
     1626                if ( inCache( old ) ) return;
    14081627                this->node = new ast::ExprStmt(
    14091628                        old->location,
     
    14111630                        GET_LABELS_V(old->labels)
    14121631                );
     1632                cache.emplace( old, this->node );
    14131633        }
    14141634
    14151635        virtual void visit( AsmStmt * old ) override final {
     1636                if ( inCache( old ) ) return;
    14161637                this->node = new ast::AsmStmt(
    14171638                        old->location,
     
    14241645                        GET_LABELS_V(old->labels)
    14251646                );
     1647                cache.emplace( old, this->node );
    14261648        }
    14271649
    14281650        virtual void visit( DirectiveStmt * old ) override final {
     1651                if ( inCache( old ) ) return;
    14291652                this->node = new ast::DirectiveStmt(
    14301653                        old->location,
     
    14321655                        GET_LABELS_V(old->labels)
    14331656                );
     1657                cache.emplace( old, this->node );
    14341658        }
    14351659
    14361660        virtual void visit( IfStmt * old ) override final {
     1661                if ( inCache( old ) ) return;
    14371662                this->node = new ast::IfStmt(
    14381663                        old->location,
     
    14431668                        GET_LABELS_V(old->labels)
    14441669                );
     1670                cache.emplace( old, this->node );
    14451671        }
    14461672
    14471673        virtual void visit( SwitchStmt * old ) override final {
     1674                if ( inCache( old ) ) return;
    14481675                this->node = new ast::SwitchStmt(
    14491676                        old->location,
     
    14521679                        GET_LABELS_V(old->labels)
    14531680                );
     1681                cache.emplace( old, this->node );
    14541682        }
    14551683
    14561684        virtual void visit( CaseStmt * old ) override final {
     1685                if ( inCache( old ) ) return;
    14571686                this->node = new ast::CaseStmt(
    14581687                        old->location,
     
    14611690                        GET_LABELS_V(old->labels)
    14621691                );
     1692                cache.emplace( old, this->node );
    14631693        }
    14641694
    14651695        virtual void visit( WhileStmt * old ) override final {
     1696                if ( inCache( old ) ) return;
    14661697                this->node = new ast::WhileStmt(
    14671698                        old->location,
     
    14721703                        GET_LABELS_V(old->labels)
    14731704                );
     1705                cache.emplace( old, this->node );
    14741706        }
    14751707
    14761708        virtual void visit( ForStmt * old ) override final {
     1709                if ( inCache( old ) ) return;
    14771710                this->node = new ast::ForStmt(
    14781711                        old->location,
     
    14831716                        GET_LABELS_V(old->labels)
    14841717                );
     1718                cache.emplace( old, this->node );
    14851719        }
    14861720
    14871721        virtual void visit( BranchStmt * old ) override final {
     1722                if ( inCache( old ) ) return;
    14881723                if (old->computedTarget) {
    14891724                        this->node = new ast::BranchStmt(
     
    15191754                        this->node = stmt;
    15201755                }
     1756                cache.emplace( old, this->node );
    15211757        }
    15221758
    15231759        virtual void visit( ReturnStmt * old ) override final {
     1760                if ( inCache( old ) ) return;
    15241761                this->node = new ast::ReturnStmt(
    15251762                        old->location,
     
    15271764                        GET_LABELS_V(old->labels)
    15281765                );
     1766                cache.emplace( old, this->node );
    15291767        }
    15301768
    15311769        virtual void visit( ThrowStmt * old ) override final {
     1770                if ( inCache( old ) ) return;
    15321771                ast::ThrowStmt::Kind kind;
    15331772                switch (old->kind) {
     
    15491788                        GET_LABELS_V(old->labels)
    15501789                );
     1790                cache.emplace( old, this->node );
    15511791        }
    15521792
    15531793        virtual void visit( TryStmt * old ) override final {
     1794                if ( inCache( old ) ) return;
    15541795                this->node = new ast::TryStmt(
    15551796                        old->location,
     
    15591800                        GET_LABELS_V(old->labels)
    15601801                );
     1802                cache.emplace( old, this->node );
    15611803        }
    15621804
    15631805        virtual void visit( CatchStmt * old ) override final {
     1806                if ( inCache( old ) ) return;
    15641807                ast::CatchStmt::Kind kind;
    15651808                switch (old->kind) {
     
    15821825                        GET_LABELS_V(old->labels)
    15831826                );
     1827                cache.emplace( old, this->node );
    15841828        }
    15851829
    15861830        virtual void visit( FinallyStmt * old ) override final {
     1831                if ( inCache( old ) ) return;
    15871832                this->node = new ast::FinallyStmt(
    15881833                        old->location,
     
    15901835                        GET_LABELS_V(old->labels)
    15911836                );
     1837                cache.emplace( old, this->node );
    15921838        }
    15931839
    15941840        virtual void visit( WaitForStmt * old ) override final {
     1841                if ( inCache( old ) ) return;
    15951842                ast::WaitForStmt * stmt = new ast::WaitForStmt(
    15961843                        old->location,
     
    16201867
    16211868                this->node = stmt;
     1869                cache.emplace( old, this->node );
    16221870        }
    16231871
    16241872        virtual void visit( WithStmt * old ) override final {
     1873                if ( inCache( old ) ) return;
    16251874                this->node = new ast::WithStmt(
    16261875                        old->location,
     
    16291878                        GET_LABELS_V(old->labels)
    16301879                );
     1880                cache.emplace( old, this->node );
    16311881        }
    16321882
    16331883        virtual void visit( NullStmt * old ) override final {
     1884                if ( inCache( old ) ) return;
    16341885                this->node = new ast::NullStmt(
    16351886                        old->location,
    16361887                        GET_LABELS_V(old->labels)
    16371888                );
     1889                cache.emplace( old, this->node );
    16381890        }
    16391891
    16401892        virtual void visit( DeclStmt * old ) override final {
     1893                if ( inCache( old ) ) return;
    16411894                this->node = new ast::DeclStmt(
    16421895                        old->location,
     
    16441897                        GET_LABELS_V(old->labels)
    16451898                );
     1899                cache.emplace( old, this->node );
    16461900        }
    16471901
    16481902        virtual void visit( ImplicitCtorDtorStmt * old ) override final {
     1903                if ( inCache( old ) ) return;
    16491904                this->node = new ast::ImplicitCtorDtorStmt(
    16501905                        old->location,
     
    16521907                        GET_LABELS_V(old->labels)
    16531908                );
     1909                cache.emplace( old, this->node );
    16541910        }
    16551911
     
    16961952        }
    16971953
    1698         ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) {
    1699 
    1700                 nw->result = GET_ACCEPT_1(result, Type);
     1954        ast::Expr * visitBaseExpr_SkipResultType(Expression * old, ast::Expr * nw) {
     1955
    17011956                nw->env    = convertTypeSubstitution(old->env);
    17021957
     
    17051960
    17061961                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);;
    17071968        }
    17081969
     
    17722033
    17732034        virtual void visit( VirtualCastExpr * old ) override final {
    1774                 this->node = visitBaseExpr( old,
     2035                this->node = visitBaseExpr_SkipResultType( old,
    17752036                        new ast::VirtualCastExpr(
    17762037                                old->location,
    17772038                                GET_ACCEPT_1(arg, Expr),
    1778                                 nullptr // cast's "to" type is expr's result type; converted in visitBaseExpr
     2039                                GET_ACCEPT_1(result, Type)
    17792040                        )
    17802041                );
     
    20012262        }
    20022263
    2003         virtual void visit( TypeExpr * ) override final {
    2004 
    2005         }
    2006 
    2007         virtual void visit( AsmExpr * ) override final {
    2008 
    2009         }
    2010 
    2011         virtual void visit( ImplicitCopyCtorExpr * ) override final {
    2012 
    2013         }
    2014 
    2015         virtual void visit( ConstructorExpr *  ) override final {
    2016 
    2017         }
    2018 
    2019         virtual void visit( CompoundLiteralExpr * ) override final {
    2020 
    2021         }
    2022 
    2023         virtual void visit( RangeExpr * ) override final {
    2024 
    2025         }
    2026 
    2027         virtual void visit( UntypedTupleExpr * ) override final {
    2028 
    2029         }
    2030 
    2031         virtual void visit( TupleExpr * ) override final {
    2032 
    2033         }
    2034 
    2035         virtual void visit( TupleIndexExpr * ) override final {
    2036 
    2037         }
    2038 
    2039         virtual void visit( TupleAssignExpr * ) override final {
    2040 
    2041         }
    2042 
    2043         virtual void visit( StmtExpr *  ) override final {
    2044 
    2045         }
    2046 
    2047         virtual void visit( UniqueExpr *  ) override final {
    2048 
    2049         }
    2050 
    2051         virtual void visit( UntypedInitExpr *  ) override final {
    2052 
    2053         }
    2054 
    2055         virtual void visit( InitExpr *  ) override final {
    2056 
    2057         }
    2058 
    2059         virtual void visit( DeletedExpr * ) override final {
    2060 
    2061         }
    2062 
    2063         virtual void visit( DefaultArgExpr * ) override final {
    2064 
    2065         }
    2066 
    2067         virtual void visit( GenericExpr * ) override final {
    2068 
     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                );
    20692449        }
    20702450
     
    22622642        }
    22632643
    2264         virtual void visit( Designation * ) override final {
    2265 
    2266         }
    2267 
    2268         virtual void visit( SingleInit * ) override final {
    2269 
    2270         }
    2271 
    2272         virtual void visit( ListInit * ) override final {
    2273 
    2274         }
    2275 
    2276         virtual void visit( ConstructorInit * ) override final {
    2277 
     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                );
    22782675        }
    22792676
    22802677        virtual void visit( Constant * ) override final {
    2281 
    2282         }
    2283 
    2284         virtual void visit( Attribute * ) override final {
    2285 
     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                );
    22862688        }
    22872689
    22882690        virtual void visit( AttrExpr * ) override final {
    2289 
    2290                 assert( 0 );
     2691                assertf( false, "AttrExpr deprecated in new AST." );
    22912692        }
    22922693};
  • src/AST/Expr.cpp

    re9b44489 rf4c2f1a  
    335335}
    336336
     337TupleAssignExpr::TupleAssignExpr(
     338        const CodeLocation & loc, const Type * result, const StmtExpr * s )
     339: Expr( loc, result ), stmtExpr() {
     340        stmtExpr = s;
     341}
     342
    337343// --- StmtExpr
    338344
  • src/AST/Expr.hpp

    re9b44489 rf4c2f1a  
    3030#define MUTATE_FRIEND template<typename node_t> friend node_t * mutate(const node_t * node);
    3131
     32class ConverterOldToNew;
     33
    3234namespace ast {
    3335
     
    528530        std::vector<ptr<ObjectDecl>> tempDecls;
    529531        std::vector<ptr<ObjectDecl>> returnDecls;
    530         std::vector<ptr<ObjectDecl>> dtors;
     532        std::vector<ptr<Expr>> dtors;
    531533
    532534        ImplicitCopyCtorExpr( const CodeLocation& loc, const ApplicationExpr * call )
     
    635637
    636638        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     639
     640        friend class ::ConverterOldToNew;
     641
    637642private:
    638643        TupleAssignExpr * clone() const override { return new TupleAssignExpr{ *this }; }
     644    TupleAssignExpr( const CodeLocation & loc, const Type * result, const StmtExpr * s );
     645
    639646        MUTATE_FRIEND
    640647};
  • src/AST/Stmt.hpp

    re9b44489 rf4c2f1a  
    9696};
    9797
     98/// Assembly statement `asm ... ( "..." : ... )`
    9899class AsmStmt final : public Stmt {
    99100public:
     
    118119};
    119120
     121/// C-preprocessor directive `#...`
    120122class DirectiveStmt final : public Stmt {
    121123public:
     
    132134};
    133135
     136/// If conditional statement `if (...) ... else ...`
    134137class IfStmt final : public Stmt {
    135138public:
     
    151154};
    152155
     156/// Switch or choose conditional statement `switch (...) { ... }`
    153157class SwitchStmt final : public Stmt {
    154158public:
     
    166170};
    167171
     172/// Case label `case ...:` `default:`
    168173class CaseStmt final : public Stmt {
    169174public:
     
    183188};
    184189
     190/// While loop `while (...) ...` `do ... while (...);
    185191class WhileStmt final : public Stmt {
    186192public:
     
    201207};
    202208
     209/// For loop `for (... ; ... ; ...) ...`
    203210class ForStmt final : public Stmt {
    204211public:
     
    219226};
    220227
     228/// Branch control flow statement `goto ...` `break` `continue` `fallthru`
    221229class BranchStmt final : public Stmt {
    222230public:
     
    246254};
    247255
     256/// Return statement `return ...`
    248257class ReturnStmt final : public Stmt {
    249258public:
     
    259268};
    260269
     270/// Throw statement `throw ...`
    261271class ThrowStmt final : public Stmt {
    262272public:
     
    277287};
    278288
     289/// Try statement `try { ... } ...`
    279290class TryStmt final : public Stmt {
    280291public:
     
    294305};
    295306
     307/// Catch clause of try statement
    296308class CatchStmt final : public Stmt {
    297309public:
     
    313325};
    314326
     327/// Finally clause of try statement
    315328class FinallyStmt final : public Stmt {
    316329public:
     
    327340};
    328341
     342/// Wait for concurrency statement `when (...) waitfor (... , ...) ... timeout(...) ... else ...`
    329343class WaitForStmt final : public Stmt {
    330344public:
     
    364378};
    365379
     380/// With statement `with (...) ...`
    366381class WithStmt final : public Stmt {
    367382public:
     
    379394};
    380395
     396/// Any declaration in a (compound) statement.
    381397class DeclStmt final : public Stmt {
    382398public:
     
    392408};
    393409
     410/// Represents an implicit application of a constructor or destructor.
    394411class ImplicitCtorDtorStmt final : public Stmt {
    395412public:
  • src/SynTree/Expression.h

    re9b44489 rf4c2f1a  
    741741        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    742742        virtual void print( std::ostream & os, Indenter indent = {} ) const;
     743
     744        friend class ConverterNewToOld;
     745  private:
     746    TupleAssignExpr( StmtExpr * stmts );
    743747};
    744748
  • src/SynTree/TupleExpr.cc

    re9b44489 rf4c2f1a  
    105105}
    106106
     107TupleAssignExpr::TupleAssignExpr(
     108        StmtExpr * s )
     109: Expression(), stmtExpr(s) {
     110}
     111
     112
    107113TupleAssignExpr::~TupleAssignExpr() {
    108114        delete stmtExpr;
Note: See TracChangeset for help on using the changeset viewer.