Ignore:
Timestamp:
Jan 7, 2021, 2:55:57 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
58fe85a
Parents:
bdfc032 (diff), 44e37ef (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' into dkobets-vector

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rbdfc032 reef8dfb  
    99// Author           : Thierry Delisle
    1010// Created On       : Thu May 09 15::37::05 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec 11 21:39:32 2019
    13 // Update Count     : 33
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Nov 12 10:07:00 2020
     13// Update Count     : 34
    1414//
    1515
     
    2020
    2121#include "AST/Attribute.hpp"
     22#include "AST/Copy.hpp"
    2223#include "AST/Decl.hpp"
    2324#include "AST/Expr.hpp"
    2425#include "AST/Init.hpp"
    2526#include "AST/Stmt.hpp"
     27#include "AST/TranslationUnit.hpp"
    2628#include "AST/TypeSubstitution.hpp"
    2729
     
    4648
    4749//================================================================================================
    48 namespace {
     50namespace ast {
    4951
    5052// This is to preserve the FindSpecialDecls hack. It does not (and perhaps should not)
    5153// allow us to use the same stratagy in the new ast.
    52 ast::Type * sizeType = nullptr;
    53 ast::FunctionDecl * dereferenceOperator = nullptr;
    54 ast::StructDecl   * dtorStruct = nullptr;
    55 ast::FunctionDecl * dtorStructDestroy = nullptr;
     54// xxx - since convert back pass works, this concern seems to be unnecessary.
     55
     56// these need to be accessed in new FixInit now
     57ast::ptr<ast::Type> sizeType = nullptr;
     58const ast::FunctionDecl * dereferenceOperator = nullptr;
     59const ast::StructDecl   * dtorStruct = nullptr;
     60const ast::FunctionDecl * dtorStructDestroy = nullptr;
    5661
    5762}
     
    6267        using Cache = std::unordered_map< const ast::Node *, BaseSyntaxNode * >;
    6368        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;
    6474
    6575        template<typename T>
     
    153163        }
    154164
    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 );
     165        const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {       
    160166                if ( inCache( node ) ) {
    161167                        return nullptr;
    162168                }
     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
    163173                auto decl = new ObjectDecl(
    164174                        node->name,
     
    166176                        LinkageSpec::Spec( node->linkage.val ),
    167177                        bfwd,
    168                         type,
    169                         init,
     178                        type->clone(),
     179                        nullptr, // prevent infinite loop
    170180                        attr,
    171181                        Type::FuncSpecifiers( node->funcSpec.val )
    172182                );
    173                 return declWithTypePostamble( decl, node );
     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;
    174192        }
    175193
    176194        const ast::DeclWithType * visit( const ast::FunctionDecl * node ) override final {
    177195                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
    178216                auto decl = new FunctionDecl(
    179217                        node->name,
    180218                        Type::StorageClasses( node->storage.val ),
    181219                        LinkageSpec::Spec( node->linkage.val ),
    182                         get<FunctionType>().accept1( node->type ),
     220                        ftype,
     221                        //get<FunctionType>().accept1( node->type ),
    183222                        {},
    184223                        get<Attribute>().acceptL( node->attributes ),
     
    188227                decl->statements = get<CompoundStmt>().accept1( node->stmts );
    189228                decl->withExprs = get<Expression>().acceptL( node->withExprs );
    190                 if ( dereferenceOperator == node ) {
     229                if ( ast::dereferenceOperator == node ) {
    191230                        Validate::dereferenceOperator = decl;
    192231                }
    193                 if ( dtorStructDestroy == node ) {
     232                if ( ast::dtorStructDestroy == node ) {
    194233                        Validate::dtorStructDestroy = decl;
    195234                }
     
    199238        const ast::Decl * namedTypePostamble( NamedTypeDecl * decl, const ast::NamedTypeDecl * node ) {
    200239                // base comes from constructor
    201                 decl->parameters = get<TypeDecl>().acceptL( node->params );
    202240                decl->assertions = get<DeclarationWithType>().acceptL( node->assertions );
    203241                declPostamble( decl, node );
     
    250288                );
    251289
    252                 if ( dtorStruct == node ) {
     290                if ( ast::dtorStruct == node ) {
    253291                        Validate::dtorStruct = decl;
    254292                }
     
    303341
    304342        const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) {
    305                 cache.emplace( node, stmt );
     343                // force statements in old tree to be unique.
     344                // cache.emplace( node, stmt );
     345                readonlyCache.emplace( node, stmt );
    306346                stmt->location = node->location;
    307347                stmt->labels = makeLabelL( stmt, node->labels );
     
    320360                if ( inCache( node ) ) return nullptr;
    321361                auto stmt = new ExprStmt( nullptr );
    322                 cache.emplace( node, stmt );
    323362                stmt->expr = get<Expression>().accept1( node->expr );
    324363                return stmtPostamble( stmt, node );
     
    493532        }
    494533
     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
    495546        const ast::Stmt * visit( const ast::WaitForStmt * node ) override final {
    496547                if ( inCache( node ) ) return nullptr;
     
    556607
    557608                for (decltype(src->begin()) src_i = src->begin(); src_i != src->end(); src_i++) {
    558                         rslt->add( src_i->first,
     609                        rslt->add( src_i->first.typeString(),
    559610                                   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) );
    565611                }
    566612
     
    575621                assert( tgtResnSlots.empty() );
    576622
    577                 if ( srcInferred.mode == ast::Expr::InferUnion::Params ) {
     623                if ( srcInferred.data.inferParams ) {
    578624                        const ast::InferredParams &srcParams = srcInferred.inferParams();
    579625                        for (auto & srcParam : srcParams) {
     
    581627                                        srcParam.second.decl,
    582628                                        get<Declaration>().accept1(srcParam.second.declptr),
    583                                         get<Type>().accept1(srcParam.second.actualType),
    584                                         get<Type>().accept1(srcParam.second.formalType),
    585                                         get<Expression>().accept1(srcParam.second.expr)
     629                                        get<Type>().accept1(srcParam.second.actualType)->clone(),
     630                                        get<Type>().accept1(srcParam.second.formalType)->clone(),
     631                                        get<Expression>().accept1(srcParam.second.expr)->clone()
    586632                                ));
    587633                                assert(res.second);
    588634                        }
    589                 } else if ( srcInferred.mode == ast::Expr::InferUnion::Slots  ) {
     635                }
     636                if ( srcInferred.data.resnSlots ) {
    590637                        const ast::ResnSlots &srcSlots = srcInferred.resnSlots();
    591638                        for (auto srcSlot : srcSlots) {
     
    608655
    609656                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                }
    610668                return visitBaseExpr_skipResultType(src, tgt);
    611669        }
     
    680738                        new KeywordCastExpr(
    681739                                get<Expression>().accept1(node->arg),
    682                                 castTarget
     740                                castTarget,
     741                                {node->concrete_target.field, node->concrete_target.getter}
    683742                        )
    684743                );
     
    9671026
    9681027        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
    9691032                auto rslt = new StmtExpr(
    970                         get<CompoundStmt>().accept1(node->stmts)
     1033                        get<CompoundStmt>().accept1(stmts)
    9711034                );
    9721035
    9731036                rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls);
    9741037                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                }
    9751042
    9761043                auto expr = visitBaseExpr( node, rslt );
     
    9891056
    9901057                auto expr = visitBaseExpr( node, rslt );
    991                 this->node = expr;
     1058                this->node = expr->clone();
    9921059                return nullptr;
    9931060        }
     
    10791146                auto type = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind };
    10801147                // I believe this should always be a BasicType.
    1081                 if ( sizeType == node ) {
     1148                if ( ast::sizeType == node ) {
    10821149                        Validate::SizeType = type;
    10831150                }
     
    11211188
    11221189        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
    11231193                auto ty = new FunctionType {
    11241194                        cv( node ),
    11251195                        (bool)node->isVarArgs
    11261196                };
    1127                 ty->returnVals = get<DeclarationWithType>().acceptL( node->returns );
    1128                 ty->parameters = get<DeclarationWithType>().acceptL( node->params );
    1129                 ty->forall = get<TypeDecl>().acceptL( node->forall );
     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
    11301235                return visitType( node, ty );
    11311236        }
    11321237
    1133         const ast::Type * postvisit( const ast::ReferenceToType * old, ReferenceToType * ty ) {
    1134                 ty->forall = get<TypeDecl>().acceptL( old->forall );
     1238        const ast::Type * postvisit( const ast::BaseInstType * old, ReferenceToType * ty ) {
    11351239                ty->parameters = get<Expression>().acceptL( old->params );
    11361240                ty->hoistType = old->hoistType;
     
    12151319                        ty = new TypeInstType{
    12161320                                cv( node ),
    1217                                 node->name,
     1321                                node->typeString(),
    12181322                                get<TypeDecl>().accept1( node->base ),
    12191323                                get<Attribute>().acceptL( node->attributes )
     
    12221326                        ty = new TypeInstType{
    12231327                                cv( node ),
    1224                                 node->name,
     1328                                node->typeString(),
    12251329                                node->kind == ast::TypeDecl::Ftype,
    12261330                                get<Attribute>().acceptL( node->attributes )
     
    13191423};
    13201424
    1321 std::list< Declaration * > convert( const std::list< ast::ptr< ast::Decl > > && translationUnit ) {
     1425std::list< Declaration * > convert( const ast::TranslationUnit && translationUnit ) {
    13221426        ConverterNewToOld c;
    13231427        std::list< Declaration * > decls;
    1324         for(auto d : translationUnit) {
     1428        for(auto d : translationUnit.decls) {
    13251429                decls.emplace_back( c.decl( d ) );
    13261430        }
     
    13431447        ast::Node * node = nullptr;
    13441448        /// cache of nodes that might be referenced by readonly<> for de-duplication
    1345         std::unordered_map< const BaseSyntaxNode *, ast::Node * > cache = {};
     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 = {};
    13461454
    13471455        // Local Utilities:
     
    14161524                auto it = cache.find( old );
    14171525                if ( it == cache.end() ) return false;
    1418                 node = it->second;
     1526                node = const_cast<ast::Node *>(it->second.get());
    14191527                return true;
    14201528        }
     
    14551563        virtual void visit( const FunctionDecl * old ) override final {
    14561564                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
    14571600                auto decl = new ast::FunctionDecl{
    14581601                        old->location,
    14591602                        old->name,
    1460                         GET_ACCEPT_1(type, FunctionType),
     1603                        // GET_ACCEPT_1(type, FunctionType),
     1604                        std::move(forall),
     1605                        std::move(paramVars),
     1606                        std::move(returnVars),
    14611607                        {},
    14621608                        { old->storageClasses.val },
    14631609                        { old->linkage.val },
    14641610                        GET_ACCEPT_V(attributes, Attribute),
    1465                         { old->get_funcSpec().val }
     1611                        { old->get_funcSpec().val },
     1612                        old->type->isVarArgs
    14661613                };
     1614
     1615                // decl->type = ftype;
    14671616                cache.emplace( old, decl );
     1617
     1618                decl->assertions = std::move(assertions);
    14681619                decl->withExprs = GET_ACCEPT_V(withExprs, Expr);
    14691620                decl->stmts = GET_ACCEPT_1(statements, CompoundStmt);
     
    14781629
    14791630                if ( Validate::dereferenceOperator == old ) {
    1480                         dereferenceOperator = decl;
     1631                        ast::dereferenceOperator = decl;
    14811632                }
    14821633
    14831634                if ( Validate::dtorStructDestroy == old ) {
    1484                         dtorStructDestroy = decl;
     1635                        ast::dtorStructDestroy = decl;
    14851636                }
    14861637        }
     
    15071658
    15081659                if ( Validate::dtorStruct == old ) {
    1509                         dtorStruct = decl;
     1660                        ast::dtorStruct = decl;
    15101661                }
    15111662        }
     
    15841735                cache.emplace( old, decl );
    15851736                decl->assertions = GET_ACCEPT_V(assertions, DeclWithType);
    1586                 decl->params     = GET_ACCEPT_V(parameters, TypeDecl);
    15871737                decl->extension  = old->extension;
    15881738                decl->uniqueId   = old->uniqueId;
     
    16001750                );
    16011751                decl->assertions = GET_ACCEPT_V(assertions, DeclWithType);
    1602                 decl->params     = GET_ACCEPT_V(parameters, TypeDecl);
    16031752                decl->extension  = old->extension;
    16041753                decl->uniqueId   = old->uniqueId;
     
    18592008        }
    18602009
     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
    18612028        virtual void visit( const WaitForStmt * old ) override final {
    18622029                if ( inCache( old ) ) return;
     
    19322099        }
    19332100
     2101        // TypeSubstitution shouldn't exist yet in old.
    19342102        ast::TypeSubstitution * convertTypeSubstitution(const TypeSubstitution * old) {
    1935 
     2103               
    19362104                if (!old) return nullptr;
    1937 
     2105                if (old->empty()) return nullptr;
     2106                assert(false);
     2107
     2108                /*
    19382109                ast::TypeSubstitution *rslt = new ast::TypeSubstitution();
    19392110
     
    19432114                }
    19442115
    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 
    19502116                return rslt;
     2117                */
    19512118        }
    19522119
     
    19562123
    19572124                assert( oldInferParams.empty() || oldResnSlots.empty() );
    1958                 assert( newInferred.mode == ast::Expr::InferUnion::Empty );
     2125                // assert( newInferred.mode == ast::Expr::InferUnion::Empty );
    19592126
    19602127                if ( !oldInferParams.empty() ) {
     
    20392206                                old->location,
    20402207                                GET_ACCEPT_1(arg, Expr),
    2041                                 castTarget
     2208                                castTarget,
     2209                                {old->concrete_target.field, old->concrete_target.getter}
    20422210                        )
    20432211                );
     
    20872255                                old->location,
    20882256                                GET_ACCEPT_1(member, DeclWithType),
    2089                                 GET_ACCEPT_1(aggregate, Expr)
     2257                                GET_ACCEPT_1(aggregate, Expr),
     2258                                ast::MemberExpr::NoOpConstructionChosen
    20902259                        )
    20912260                );
     
    24192588                // I believe this should always be a BasicType.
    24202589                if ( Validate::SizeType == old ) {
    2421                         sizeType = type;
     2590                        ast::sizeType = type;
    24222591                }
    24232592                visitType( old, type );
     
    24642633                        cv( old )
    24652634                };
    2466                 ty->returns = GET_ACCEPT_V( returnVals, DeclWithType );
    2467                 ty->params = GET_ACCEPT_V( parameters, DeclWithType );
    2468                 ty->forall = GET_ACCEPT_V( forall, TypeDecl );
     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                }
    24692655                visitType( old, ty );
    24702656        }
    24712657
    2472         void postvisit( const ReferenceToType * old, ast::ReferenceToType * ty ) {
    2473                 ty->forall = GET_ACCEPT_V( forall, TypeDecl );
     2658        void postvisit( const ReferenceToType * old, ast::BaseInstType * ty ) {
    24742659                ty->params = GET_ACCEPT_V( parameters, Expr );
    24752660                ty->hoistType = old->hoistType;
     
    26162801                        old->location,
    26172802                        GET_ACCEPT_1(value, Expr),
    2618                         (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct
     2803                        (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::NoConstruct
    26192804                );
    26202805        }
     
    26252810                        GET_ACCEPT_V(initializers, Init),
    26262811                        GET_ACCEPT_V(designations, Designation),
    2627                         (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::DoConstruct
     2812                        (old->get_maybeConstructed()) ? ast::MaybeConstruct : ast::NoConstruct
    26282813                );
    26292814        }
     
    26562841#undef GET_ACCEPT_1
    26572842
    2658 std::list< ast::ptr< ast::Decl > > convert( const std::list< Declaration * > && translationUnit ) {
     2843ast::TranslationUnit convert( const std::list< Declaration * > && translationUnit ) {
    26592844        ConverterOldToNew c;
    2660         std::list< ast::ptr< ast::Decl > > decls;
     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
    26612852        for(auto d : translationUnit) {
    26622853                d->accept( c );
    2663                 decls.emplace_back( c.decl() );
     2854                unit.decls.emplace_back( c.decl() );
    26642855        }
    26652856        deleteAll(translationUnit);
    2666         return decls;
     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;
    26672865}
Note: See TracChangeset for help on using the changeset viewer.