Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r3e5dd913 r07de76b  
    99// Author           : Thierry Delisle
    1010// Created On       : Thu May 09 15::37::05 2019
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Nov 12 10:07:00 2020
    13 // Update Count     : 34
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 21:39:32 2019
     13// Update Count     : 33
    1414//
    1515
     
    2020
    2121#include "AST/Attribute.hpp"
    22 #include "AST/Copy.hpp"
    2322#include "AST/Decl.hpp"
    2423#include "AST/Expr.hpp"
    2524#include "AST/Init.hpp"
    2625#include "AST/Stmt.hpp"
    27 #include "AST/TranslationUnit.hpp"
    2826#include "AST/TypeSubstitution.hpp"
    2927
     
    4846
    4947//================================================================================================
    50 namespace ast {
     48namespace {
    5149
    5250// This is to preserve the FindSpecialDecls hack. It does not (and perhaps should not)
    5351// allow us to use the same stratagy in the new ast.
    54 // xxx - since convert back pass works, this concern seems to be unnecessary.
    55 
    56 // these need to be accessed in new FixInit now
    57 ast::ptr<ast::Type> sizeType = nullptr;
    58 const ast::FunctionDecl * dereferenceOperator = nullptr;
    59 const ast::StructDecl   * dtorStruct = nullptr;
    60 const ast::FunctionDecl * dtorStructDestroy = nullptr;
     52ast::Type * sizeType = nullptr;
     53ast::FunctionDecl * dereferenceOperator = nullptr;
     54ast::StructDecl   * dtorStruct = nullptr;
     55ast::FunctionDecl * dtorStructDestroy = nullptr;
    6156
    6257}
     
    6762        using Cache = std::unordered_map< const ast::Node *, BaseSyntaxNode * >;
    6863        Cache cache;
    69 
    70         // Statements can no longer be shared.
    71         // however, since StmtExprResult is now implemented, need to still maintain
    72         // readonly references.
    73         Cache readonlyCache;
    7464
    7565        template<typename T>
     
    163153        }
    164154
    165         const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {       
     155        const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {
     156                auto&& bfwd = get<Expression>().accept1( node->bitfieldWidth );
     157                auto&& type = get<Type>().accept1( node->type );
     158                auto&& init = get<Initializer>().accept1( node->init );
     159                auto&& attr = get<Attribute>().acceptL( node->attributes );
    166160                if ( inCache( node ) ) {
    167161                        return nullptr;
    168162                }
    169                 auto bfwd = get<Expression>().accept1( node->bitfieldWidth );
    170                 auto type = get<Type>().accept1( node->type );
    171                 auto attr = get<Attribute>().acceptL( node->attributes );
    172 
    173163                auto decl = new ObjectDecl(
    174164                        node->name,
     
    176166                        LinkageSpec::Spec( node->linkage.val ),
    177167                        bfwd,
    178                         type->clone(),
    179                         nullptr, // prevent infinite loop
     168                        type,
     169                        init,
    180170                        attr,
    181171                        Type::FuncSpecifiers( node->funcSpec.val )
    182172                );
    183 
    184                 // handles the case where node->init references itself
    185                 // xxx - does it really happen?
    186                 declWithTypePostamble(decl, node);
    187                 auto init = get<Initializer>().accept1( node->init );
    188                 decl->init = init;
    189 
    190                 this->node = decl;
    191                 return nullptr;
     173                return declWithTypePostamble( decl, node );
    192174        }
    193175
    194176        const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final {
    195177                if ( inCache( node ) ) return nullptr;
    196 
    197                 // function decl contains real variables that the type must use.
    198                 // the structural change means function type in and out of decl
    199                 // must be handled **differently** on convert back to old.
    200                 auto ftype = new FunctionType(
    201                         cv(node->type),
    202                         (bool)node->type->isVarArgs
    203                 );
    204                 ftype->returnVals = get<DeclarationWithType>().acceptL(node->returns);
    205                 ftype->parameters = get<DeclarationWithType>().acceptL(node->params);
    206 
    207                 ftype->forall = get<TypeDecl>().acceptL( node->type_params );
    208                 if (!node->assertions.empty()) {
    209                         assert(!ftype->forall.empty());
    210                         // find somewhere to place assertions back, for convenience it is the last slot
    211                         ftype->forall.back()->assertions = get<DeclarationWithType>().acceptL(node->assertions);
    212                 }
    213 
    214                 visitType(node->type, ftype);
    215 
    216178                auto decl = new FunctionDecl(
    217179                        node->name,
    218180                        Type::StorageClasses( node->storage.val ),
    219181                        LinkageSpec::Spec( node->linkage.val ),
    220                         ftype,
    221                         //get<FunctionType>().accept1( node->type ),
     182                        get<FunctionType>().accept1( node->type ),
    222183                        {},
    223184                        get<Attribute>().acceptL( node->attributes ),
     
    227188                decl->statements = get<CompoundStmt>().accept1( node->stmts );
    228189                decl->withExprs = get<Expression>().acceptL( node->withExprs );
    229                 if ( ast::dereferenceOperator == node ) {
     190                if ( dereferenceOperator == node ) {
    230191                        Validate::dereferenceOperator = decl;
    231192                }
    232                 if ( ast::dtorStructDestroy == node ) {
     193                if ( dtorStructDestroy == node ) {
    233194                        Validate::dtorStructDestroy = decl;
    234195                }
     
    238199        const ast::Decl * namedTypePostamble( NamedTypeDecl * decl, const ast::NamedTypeDecl * node ) {
    239200                // base comes from constructor
     201                decl->parameters = get<TypeDecl>().acceptL( node->params );
    240202                decl->assertions = get<DeclarationWithType>().acceptL( node->assertions );
    241203                declPostamble( decl, node );
     
    288250                );
    289251
    290                 if ( ast::dtorStruct == node ) {
     252                if ( dtorStruct == node ) {
    291253                        Validate::dtorStruct = decl;
    292254                }
     
    341303
    342304        const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) {
    343                 // force statements in old tree to be unique.
    344                 // cache.emplace( node, stmt );
    345                 readonlyCache.emplace( node, stmt );
     305                cache.emplace( node, stmt );
    346306                stmt->location = node->location;
    347307                stmt->labels = makeLabelL( stmt, node->labels );
     
    360320                if ( inCache( node ) ) return nullptr;
    361321                auto stmt = new ExprStmt( nullptr );
     322                cache.emplace( node, stmt );
    362323                stmt->expr = get<Expression>().accept1( node->expr );
    363324                return stmtPostamble( stmt, node );
     
    532493        }
    533494
    534         const ast::Stmt * visit(const ast::SuspendStmt * node ) override final {
    535                 if ( inCache( node ) ) return nullptr;
    536                 auto stmt = new SuspendStmt();
    537                 stmt->then   = get<CompoundStmt>().accept1( node->then   );
    538                 switch(node->type) {
    539                         case ast::SuspendStmt::None     : stmt->type = SuspendStmt::None     ; break;
    540                         case ast::SuspendStmt::Coroutine: stmt->type = SuspendStmt::Coroutine; break;
    541                         case ast::SuspendStmt::Generator: stmt->type = SuspendStmt::Generator; break;
    542                 }
    543                 return stmtPostamble( stmt, node );
    544         }
    545 
    546495        const ast::Stmt * visit( const ast::WaitForStmt * node ) override final {
    547496                if ( inCache( node ) ) return nullptr;
     
    607556
    608557                for (decltype(src->begin()) src_i = src->begin(); src_i != src->end(); src_i++) {
    609                         rslt->add( src_i->first.typeString(),
     558                        rslt->add( src_i->first,
    610559                                   get<Type>().accept1(src_i->second) );
     560                }
     561
     562                for (decltype(src->beginVar()) src_i = src->beginVar(); src_i != src->endVar(); src_i++) {
     563                        rslt->addVar( src_i->first,
     564                                      get<Expression>().accept1(src_i->second) );
    611565                }
    612566
     
    621575                assert( tgtResnSlots.empty() );
    622576
    623                 if ( srcInferred.data.inferParams ) {
     577                if ( srcInferred.mode == ast::Expr::InferUnion::Params ) {
    624578                        const ast::InferredParams &srcParams = srcInferred.inferParams();
    625579                        for (auto & srcParam : srcParams) {
     
    627581                                        srcParam.second.decl,
    628582                                        get<Declaration>().accept1(srcParam.second.declptr),
    629                                         get<Type>().accept1(srcParam.second.actualType)->clone(),
    630                                         get<Type>().accept1(srcParam.second.formalType)->clone(),
    631                                         get<Expression>().accept1(srcParam.second.expr)->clone()
     583                                        get<Type>().accept1(srcParam.second.actualType),
     584                                        get<Type>().accept1(srcParam.second.formalType),
     585                                        get<Expression>().accept1(srcParam.second.expr)
    632586                                ));
    633587                                assert(res.second);
    634588                        }
    635                 }
    636                 if ( srcInferred.data.resnSlots ) {
     589                } else if ( srcInferred.mode == ast::Expr::InferUnion::Slots  ) {
    637590                        const ast::ResnSlots &srcSlots = srcInferred.resnSlots();
    638591                        for (auto srcSlot : srcSlots) {
     
    655608
    656609                tgt->result = get<Type>().accept1(src->result);
    657                 // Unconditionally use a clone of the result type.
    658                 // We know this will leak some objects: much of the immediate conversion result.
    659                 // In some cases, using the conversion result directly gives unintended object sharing.
    660                 // A parameter (ObjectDecl, a child of a FunctionType) is shared by the weak-ref cache.
    661                 // But tgt->result must be fully owned privately by tgt.
    662                 // Applying these conservative copies here means
    663                 // - weak references point at the declaration's copy, not these expr.result copies (good)
    664                 // - we copy more objects than really needed (bad, tolerated)
    665                 if (tgt->result) {
    666                         tgt->result = tgt->result->clone();
    667                 }
    668610                return visitBaseExpr_skipResultType(src, tgt);
    669611        }
     
    738680                        new KeywordCastExpr(
    739681                                get<Expression>().accept1(node->arg),
    740                                 castTarget,
    741                                 {node->concrete_target.field, node->concrete_target.getter}
     682                                castTarget
    742683                        )
    743684                );
     
    1026967
    1027968        const ast::Expr * visit( const ast::StmtExpr * node ) override final {
    1028                 auto stmts = node->stmts;
    1029                 // disable sharing between multiple StmtExprs explicitly.
    1030                 // this should no longer be true.
    1031 
    1032969                auto rslt = new StmtExpr(
    1033                         get<CompoundStmt>().accept1(stmts)
     970                        get<CompoundStmt>().accept1(node->stmts)
    1034971                );
    1035972
    1036973                rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls);
    1037974                rslt->dtors       = get<Expression>().acceptL(node->dtors);
    1038                 if (node->resultExpr) {
    1039                         // this MUST be found by children visit
    1040                         rslt->resultExpr  = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(node->resultExpr));
    1041                 }
    1042975
    1043976                auto expr = visitBaseExpr( node, rslt );
     
    1056989
    1057990                auto expr = visitBaseExpr( node, rslt );
    1058                 this->node = expr->clone();
     991                this->node = expr;
    1059992                return nullptr;
    1060993        }
     
    11461079                auto type = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind };
    11471080                // I believe this should always be a BasicType.
    1148                 if ( ast::sizeType == node ) {
     1081                if ( sizeType == node ) {
    11491082                        Validate::SizeType = type;
    11501083                }
     
    11881121
    11891122        const ast::Type * visit( const ast::FunctionType * node ) override final {
    1190                 static std::string dummy_paramvar_prefix = "__param_";
    1191                 static std::string dummy_returnvar_prefix = "__retval_";
    1192 
    11931123                auto ty = new FunctionType {
    11941124                        cv( node ),
    11951125                        (bool)node->isVarArgs
    11961126                };
    1197                 auto returns = get<Type>().acceptL(node->returns);
    1198                 auto params = get<Type>().acceptL(node->params);
    1199 
    1200                 int ret_index = 0;
    1201                 for (auto t: returns) {
    1202                         // xxx - LinkageSpec shouldn't matter but needs to be something
    1203                         ObjectDecl * dummy = new ObjectDecl(dummy_returnvar_prefix + std::to_string(ret_index++), {}, LinkageSpec::C, nullptr, t, nullptr);
    1204                         ty->returnVals.push_back(dummy);
    1205                 }
    1206                 int param_index = 0;
    1207                 for (auto t: params) {
    1208                         ObjectDecl * dummy = new ObjectDecl(dummy_paramvar_prefix + std::to_string(param_index++), {}, LinkageSpec::C, nullptr, t, nullptr);
    1209                         ty->parameters.push_back(dummy);
    1210                 }
    1211 
    1212                 // ty->returnVals = get<DeclarationWithType>().acceptL( node->returns );
    1213                 // ty->parameters = get<DeclarationWithType>().acceptL( node->params );
    1214 
    1215                 auto types = get<TypeInstType>().acceptL( node->forall );
    1216                 for (auto t : types) {
    1217                         auto newT = new TypeDecl(*t->baseType);
    1218                         newT->name = t->name; // converted by typeString()
    1219                         for (auto asst : newT->assertions) delete asst;
    1220                         newT->assertions.clear();
    1221                         ty->forall.push_back(newT);
    1222                 }
    1223                 auto assts = get<VariableExpr>().acceptL( node->assertions );
    1224                 if (!assts.empty()) {
    1225                         assert(!types.empty());
    1226                         for (auto asst : assts) {
    1227                                 auto newDecl = new ObjectDecl(*strict_dynamic_cast<ObjectDecl*>(asst->var));
    1228                                 delete newDecl->type;
    1229                                 newDecl->type = asst->result->clone();
    1230                                 newDecl->storageClasses.is_extern = true; // hack
    1231                                 ty->forall.back()->assertions.push_back(newDecl);
    1232                         }
    1233                 }
    1234 
     1127                ty->returnVals = get<DeclarationWithType>().acceptL( node->returns );
     1128                ty->parameters = get<DeclarationWithType>().acceptL( node->params );
     1129                ty->forall = get<TypeDecl>().acceptL( node->forall );
    12351130                return visitType( node, ty );
    12361131        }
    12371132
    1238         const ast::Type * postvisit( const ast::BaseInstType * old, ReferenceToType * ty ) {
     1133        const ast::Type * postvisit( const ast::ReferenceToType * old, ReferenceToType * ty ) {
     1134                ty->forall = get<TypeDecl>().acceptL( old->forall );
    12391135                ty->parameters = get<Expression>().acceptL( old->params );
    12401136                ty->hoistType = old->hoistType;
     
    13191215                        ty = new TypeInstType{
    13201216                                cv( node ),
    1321                                 node->typeString(),
     1217                                node->name,
    13221218                                get<TypeDecl>().accept1( node->base ),
    13231219                                get<Attribute>().acceptL( node->attributes )
     
    13261222                        ty = new TypeInstType{
    13271223                                cv( node ),
    1328                                 node->typeString(),
     1224                                node->name,
    13291225                                node->kind == ast::TypeDecl::Ftype,
    13301226                                get<Attribute>().acceptL( node->attributes )
     
    14231319};
    14241320
    1425 std::list< Declaration * > convert( const ast::TranslationUnit && translationUnit ) {
     1321std::list< Declaration * > convert( const std::list< ast::ptr< ast::Decl > > && translationUnit ) {
    14261322        ConverterNewToOld c;
    14271323        std::list< Declaration * > decls;
    1428         for(auto d : translationUnit.decls) {
     1324        for(auto d : translationUnit) {
    14291325                decls.emplace_back( c.decl( d ) );
    14301326        }
     
    14471343        ast::Node * node = nullptr;
    14481344        /// cache of nodes that might be referenced by readonly<> for de-duplication
    1449         /// in case that some nodes are dropped by conversion (due to possible structural change)
    1450         /// use smart pointers in cache value to prevent accidental invalidation.
    1451         /// at conversion stage, all created nodes are guaranteed to be unique, therefore
    1452         /// const_casting out of smart pointers is permitted.
    1453         std::unordered_map< const BaseSyntaxNode *, ast::readonly<ast::Node> > cache = {};
     1345        std::unordered_map< const BaseSyntaxNode *, ast::Node * > cache = {};
    14541346
    14551347        // Local Utilities:
     
    15241416                auto it = cache.find( old );
    15251417                if ( it == cache.end() ) return false;
    1526                 node = const_cast<ast::Node *>(it->second.get());
     1418                node = it->second;
    15271419                return true;
    15281420        }
     
    15631455        virtual void visit( const FunctionDecl * old ) override final {
    15641456                if ( inCache( old ) ) return;
    1565                 auto paramVars = GET_ACCEPT_V(type->parameters, DeclWithType);
    1566                 auto returnVars = GET_ACCEPT_V(type->returnVals, DeclWithType);
    1567                 auto forall = GET_ACCEPT_V(type->forall, TypeDecl);
    1568 
    1569                 // function type is now derived from parameter decls instead of storing them
    1570 
    1571                 /*
    1572                 auto ftype = new ast::FunctionType((ast::ArgumentFlag)old->type->isVarArgs, cv(old->type));
    1573                 ftype->params.reserve(paramVars.size());
    1574                 ftype->returns.reserve(returnVars.size());
    1575 
    1576                 for (auto & v: paramVars) {
    1577                         ftype->params.emplace_back(v->get_type());
    1578                 }
    1579                 for (auto & v: returnVars) {
    1580                         ftype->returns.emplace_back(v->get_type());
    1581                 }
    1582                 ftype->forall = std::move(forall);
    1583                 */
    1584 
    1585                 // can function type have attributes? seems not to be the case.
    1586                 // visitType(old->type, ftype);
    1587 
    1588                 // collect assertions and put directly in FunctionDecl
    1589                 std::vector<ast::ptr<ast::DeclWithType>> assertions;
    1590                 for (auto & param: forall) {
    1591                         for (auto & asst: param->assertions) {
    1592                                 assertf(asst->unique(), "newly converted decl must be unique");
    1593                                 assertions.emplace_back(asst);
    1594                         }
    1595                         auto mut = param.get_and_mutate();
    1596                         assertf(mut == param, "newly converted decl must be unique");
    1597                         mut->assertions.clear();
    1598                 }
    1599 
    16001457                auto decl = new ast::FunctionDecl{
    16011458                        old->location,
    16021459                        old->name,
    1603                         // GET_ACCEPT_1(type, FunctionType),
    1604                         std::move(forall),
    1605                         std::move(paramVars),
    1606                         std::move(returnVars),
     1460                        GET_ACCEPT_1(type, FunctionType),
    16071461                        {},
    16081462                        { old->storageClasses.val },
    16091463                        { old->linkage.val },
    16101464                        GET_ACCEPT_V(attributes, Attribute),
    1611                         { old->get_funcSpec().val },
    1612                         old->type->isVarArgs
     1465                        { old->get_funcSpec().val }
    16131466                };
    1614 
    1615                 // decl->type = ftype;
    16161467                cache.emplace( old, decl );
    1617 
    1618                 decl->assertions = std::move(assertions);
    16191468                decl->withExprs = GET_ACCEPT_V(withExprs, Expr);
    16201469                decl->stmts = GET_ACCEPT_1(statements, CompoundStmt);
     
    16291478
    16301479                if ( Validate::dereferenceOperator == old ) {
    1631                         ast::dereferenceOperator = decl;
     1480                        dereferenceOperator = decl;
    16321481                }
    16331482
    16341483                if ( Validate::dtorStructDestroy == old ) {
    1635                         ast::dtorStructDestroy = decl;
     1484                        dtorStructDestroy = decl;
    16361485                }
    16371486        }
     
    16581507
    16591508                if ( Validate::dtorStruct == old ) {
    1660                         ast::dtorStruct = decl;
     1509                        dtorStruct = decl;
    16611510                }
    16621511        }
     
    17351584                cache.emplace( old, decl );
    17361585                decl->assertions = GET_ACCEPT_V(assertions, DeclWithType);
     1586                decl->params     = GET_ACCEPT_V(parameters, TypeDecl);
    17371587                decl->extension  = old->extension;
    17381588                decl->uniqueId   = old->uniqueId;
     
    17501600                );
    17511601                decl->assertions = GET_ACCEPT_V(assertions, DeclWithType);
     1602                decl->params     = GET_ACCEPT_V(parameters, TypeDecl);
    17521603                decl->extension  = old->extension;
    17531604                decl->uniqueId   = old->uniqueId;
     
    20081859        }
    20091860
    2010         virtual void visit( const SuspendStmt * old ) override final {
    2011                 if ( inCache( old ) ) return;
    2012                 ast::SuspendStmt::Type type;
    2013                 switch (old->type) {
    2014                         case SuspendStmt::Coroutine: type = ast::SuspendStmt::Coroutine; break;
    2015                         case SuspendStmt::Generator: type = ast::SuspendStmt::Generator; break;
    2016                         case SuspendStmt::None     : type = ast::SuspendStmt::None     ; break;
    2017                         default: abort();
    2018                 }
    2019                 this->node = new ast::SuspendStmt(
    2020                         old->location,
    2021                         GET_ACCEPT_1(then  , CompoundStmt),
    2022                         type,
    2023                         GET_LABELS_V(old->labels)
    2024                 );
    2025                 cache.emplace( old, this->node );
    2026         }
    2027 
    20281861        virtual void visit( const WaitForStmt * old ) override final {
    20291862                if ( inCache( old ) ) return;
     
    20991932        }
    21001933
    2101         // TypeSubstitution shouldn't exist yet in old.
    21021934        ast::TypeSubstitution * convertTypeSubstitution(const TypeSubstitution * old) {
    2103                
     1935
    21041936                if (!old) return nullptr;
    2105                 if (old->empty()) return nullptr;
    2106                 assert(false);
    2107 
    2108                 /*
     1937
    21091938                ast::TypeSubstitution *rslt = new ast::TypeSubstitution();
    21101939
     
    21141943                }
    21151944
     1945                for (decltype(old->beginVar()) old_i = old->beginVar(); old_i != old->endVar(); old_i++) {
     1946                        rslt->addVar( old_i->first,
     1947                                      getAccept1<ast::Expr>(old_i->second) );
     1948                }
     1949
    21161950                return rslt;
    2117                 */
    21181951        }
    21191952
     
    21231956
    21241957                assert( oldInferParams.empty() || oldResnSlots.empty() );
    2125                 // assert( newInferred.mode == ast::Expr::InferUnion::Empty );
     1958                assert( newInferred.mode == ast::Expr::InferUnion::Empty );
    21261959
    21271960                if ( !oldInferParams.empty() ) {
     
    22062039                                old->location,
    22072040                                GET_ACCEPT_1(arg, Expr),
    2208                                 castTarget,
    2209                                 {old->concrete_target.field, old->concrete_target.getter}
     2041                                castTarget
    22102042                        )
    22112043                );
     
    22552087                                old->location,
    22562088                                GET_ACCEPT_1(member, DeclWithType),
    2257                                 GET_ACCEPT_1(aggregate, Expr),
    2258                                 ast::MemberExpr::NoOpConstructionChosen
     2089                                GET_ACCEPT_1(aggregate, Expr)
    22592090                        )
    22602091                );
     
    25882419                // I believe this should always be a BasicType.
    25892420                if ( Validate::SizeType == old ) {
    2590                         ast::sizeType = type;
     2421                        sizeType = type;
    25912422                }
    25922423                visitType( old, type );
     
    26332464                        cv( old )
    26342465                };
    2635                 auto returnVars = GET_ACCEPT_V(returnVals, DeclWithType);
    2636                 auto paramVars = GET_ACCEPT_V(parameters, DeclWithType);
    2637                 // ty->returns = GET_ACCEPT_V( returnVals, DeclWithType );
    2638                 // ty->params = GET_ACCEPT_V( parameters, DeclWithType );
    2639                 for (auto & v: returnVars) {
    2640                         ty->returns.emplace_back(v->get_type());
    2641                 }
    2642                 for (auto & v: paramVars) {
    2643                         ty->params.emplace_back(v->get_type());
    2644                 }
    2645                 // xxx - when will this be non-null?
    2646                 // will have to create dangling (no-owner) decls to be pointed to
    2647                 auto foralls = GET_ACCEPT_V( forall, TypeDecl );
    2648 
    2649                 for (auto & param : foralls) {
    2650                         ty->forall.emplace_back(new ast::TypeInstType(param->name, param));
    2651                         for (auto asst : param->assertions) {
    2652                                 ty->assertions.emplace_back(new ast::VariableExpr({}, asst));
    2653                         }
    2654                 }
     2466                ty->returns = GET_ACCEPT_V( returnVals, DeclWithType );
     2467                ty->params = GET_ACCEPT_V( parameters, DeclWithType );
     2468                ty->forall = GET_ACCEPT_V( forall, TypeDecl );
    26552469                visitType( old, ty );
    26562470        }
    26572471
    2658         void postvisit( const ReferenceToType * old, ast::BaseInstType * ty ) {
     2472        void postvisit( const ReferenceToType * old, ast::ReferenceToType * ty ) {
     2473                ty->forall = GET_ACCEPT_V( forall, TypeDecl );
    26592474                ty->params = GET_ACCEPT_V( parameters, Expr );
    26602475                ty->hoistType = old->hoistType;
     
    28012616                        old->location,
    28022617                        GET_ACCEPT_1(value, Expr),
    2803                         (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::NoConstruct
     2618                        (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct
    28042619                );
    28052620        }
     
    28102625                        GET_ACCEPT_V(initializers, Init),
    28112626                        GET_ACCEPT_V(designations, Designation),
    2812                         (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::NoConstruct
     2627                        (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct
    28132628                );
    28142629        }
     
    28412656#undef GET_ACCEPT_1
    28422657
    2843 ast::TranslationUnit convert( const std::list< Declaration * > && translationUnit ) {
     2658std::list< ast::ptr< ast::Decl > > convert( const std::list< Declaration * > && translationUnit ) {
    28442659        ConverterOldToNew c;
    2845         ast::TranslationUnit unit;
    2846         if (Validate::SizeType) {
    2847                 // this should be a BasicType.
    2848                 auto old = strict_dynamic_cast<BasicType *>(Validate::SizeType);
    2849                 ast::sizeType = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind };
    2850         }
    2851 
     2660        std::list< ast::ptr< ast::Decl > > decls;
    28522661        for(auto d : translationUnit) {
    28532662                d->accept( c );
    2854                 unit.decls.emplace_back( c.decl() );
     2663                decls.emplace_back( c.decl() );
    28552664        }
    28562665        deleteAll(translationUnit);
    2857 
    2858         // Load the local static varables into the global store.
    2859         unit.global.sizeType = ast::sizeType;
    2860         unit.global.dereference = ast::dereferenceOperator;
    2861         unit.global.dtorStruct = ast::dtorStruct;
    2862         unit.global.dtorDestroy = ast::dtorStructDestroy;
    2863 
    2864         return unit;
     2666        return decls;
    28652667}
Note: See TracChangeset for help on using the changeset viewer.