Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r490fb92e r954c954  
    4747
    4848//================================================================================================
    49 namespace ast {
     49namespace {
    5050
    5151// This is to preserve the FindSpecialDecls hack. It does not (and perhaps should not)
    5252// allow us to use the same stratagy in the new ast.
    53 // xxx - since convert back pass works, this concern seems to be unnecessary.
    54 
    55 // these need to be accessed in new FixInit now
    5653ast::Type * sizeType = nullptr;
    5754ast::FunctionDecl * dereferenceOperator = nullptr;
     
    6663        using Cache = std::unordered_map< const ast::Node *, BaseSyntaxNode * >;
    6764        Cache cache;
    68 
    69         // Statements can no longer be shared.
    70         // however, since StmtExprResult is now implemented, need to still maintain
    71         // readonly references.
    72         Cache readonlyCache;
    7365
    7466        template<typename T>
     
    162154        }
    163155
    164         const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {       
     156        const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {
     157                auto&& bfwd = get<Expression>().accept1( node->bitfieldWidth );
     158                auto&& type = get<Type>().accept1( node->type );
     159                auto&& init = get<Initializer>().accept1( node->init );
     160                auto&& attr = get<Attribute>().acceptL( node->attributes );
    165161                if ( inCache( node ) ) {
    166162                        return nullptr;
    167163                }
    168                 auto bfwd = get<Expression>().accept1( node->bitfieldWidth );
    169                 auto type = get<Type>().accept1( node->type );
    170                 auto attr = get<Attribute>().acceptL( node->attributes );
    171 
    172164                auto decl = new ObjectDecl(
    173165                        node->name,
     
    176168                        bfwd,
    177169                        type->clone(),
    178                         nullptr, // prevent infinite loop
     170                        init,
    179171                        attr,
    180172                        Type::FuncSpecifiers( node->funcSpec.val )
    181173                );
    182 
    183                 // handles the case where node->init references itself
    184                 // xxx - does it really happen?
    185                 declWithTypePostamble(decl, node);
    186                 auto init = get<Initializer>().accept1( node->init );
    187                 decl->init = init;
    188                
    189                 this->node = decl;
    190                 return nullptr;
     174                return declWithTypePostamble( decl, node );
    191175        }
    192176
     
    221205                decl->statements = get<CompoundStmt>().accept1( node->stmts );
    222206                decl->withExprs = get<Expression>().acceptL( node->withExprs );
    223                 if ( ast::dereferenceOperator == node ) {
     207                if ( dereferenceOperator == node ) {
    224208                        Validate::dereferenceOperator = decl;
    225209                }
    226                 if ( ast::dtorStructDestroy == node ) {
     210                if ( dtorStructDestroy == node ) {
    227211                        Validate::dtorStructDestroy = decl;
    228212                }
     
    283267                );
    284268
    285                 if ( ast::dtorStruct == node ) {
     269                if ( dtorStruct == node ) {
    286270                        Validate::dtorStruct = decl;
    287271                }
     
    336320
    337321        const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) {
    338                 // force statements in old tree to be unique.
    339                 // cache.emplace( node, stmt );
    340                 readonlyCache.emplace( node, stmt );
     322                cache.emplace( node, stmt );
    341323                stmt->location = node->location;
    342324                stmt->labels = makeLabelL( stmt, node->labels );
     
    355337                if ( inCache( node ) ) return nullptr;
    356338                auto stmt = new ExprStmt( nullptr );
     339                cache.emplace( node, stmt );
    357340                stmt->expr = get<Expression>().accept1( node->expr );
    358341                return stmtPostamble( stmt, node );
     
    10281011                auto stmts = node->stmts;
    10291012                // disable sharing between multiple StmtExprs explicitly.
    1030                 // this should no longer be true.
    1031 
     1013                if (inCache(stmts)) {
     1014                        stmts = ast::deepCopy(stmts.get());
     1015                }
    10321016                auto rslt = new StmtExpr(
    10331017                        get<CompoundStmt>().accept1(stmts)
     
    10361020                rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls);
    10371021                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                 }
    10421022
    10431023                auto expr = visitBaseExpr( node, rslt );
     
    10561036
    10571037                auto expr = visitBaseExpr( node, rslt );
    1058                 this->node = expr->clone();
     1038                this->node = expr;
    10591039                return nullptr;
    10601040        }
     
    11461126                auto type = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind };
    11471127                // I believe this should always be a BasicType.
    1148                 if ( ast::sizeType == node ) {
     1128                if ( sizeType == node ) {
    11491129                        Validate::SizeType = type;
    11501130                }
     
    15491529
    15501530                // function type is now derived from parameter decls instead of storing them
    1551 
    1552                 /*
    15531531                auto ftype = new ast::FunctionType((ast::ArgumentFlag)old->type->isVarArgs, cv(old->type));
    15541532                ftype->params.reserve(paramVars.size());
     
    15621540                }
    15631541                ftype->forall = std::move(forall);
    1564                 */
    1565 
    1566                 // can function type have attributes? seems not to be the case.
    1567                 // visitType(old->type, ftype);
     1542                visitType(old->type, ftype);
    15681543
    15691544                auto decl = new ast::FunctionDecl{
     
    15711546                        old->name,
    15721547                        // GET_ACCEPT_1(type, FunctionType),
    1573                         std::move(forall),
    15741548                        std::move(paramVars),
    15751549                        std::move(returnVars),
     
    15781552                        { old->linkage.val },
    15791553                        GET_ACCEPT_V(attributes, Attribute),
    1580                         { old->get_funcSpec().val },
    1581                         old->type->isVarArgs
     1554                        { old->get_funcSpec().val }
    15821555                };
    15831556
    1584                 // decl->type = ftype;
     1557                decl->type = ftype;
    15851558                cache.emplace( old, decl );
    15861559
     
    15971570
    15981571                if ( Validate::dereferenceOperator == old ) {
    1599                         ast::dereferenceOperator = decl;
     1572                        dereferenceOperator = decl;
    16001573                }
    16011574
    16021575                if ( Validate::dtorStructDestroy == old ) {
    1603                         ast::dtorStructDestroy = decl;
     1576                        dtorStructDestroy = decl;
    16041577                }
    16051578        }
     
    16261599
    16271600                if ( Validate::dtorStruct == old ) {
    1628                         ast::dtorStruct = decl;
     1601                        dtorStruct = decl;
    16291602                }
    16301603        }
     
    25582531                // I believe this should always be a BasicType.
    25592532                if ( Validate::SizeType == old ) {
    2560                         ast::sizeType = type;
     2533                        sizeType = type;
    25612534                }
    25622535                visitType( old, type );
Note: See TracChangeset for help on using the changeset viewer.