Ignore:
Timestamp:
Nov 4, 2020, 2:56:30 PM (5 years ago)
Author:
Colby Alexander Parsons <caparsons@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
eeb5023
Parents:
4b30e8cc (diff), a3f5208a (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r4b30e8cc rc28ea4e  
    2525#include "AST/Init.hpp"
    2626#include "AST/Stmt.hpp"
     27#include "AST/TranslationUnit.hpp"
    2728#include "AST/TypeSubstitution.hpp"
    2829
     
    4748
    4849//================================================================================================
    49 namespace {
     50namespace ast {
    5051
    5152// This is to preserve the FindSpecialDecls hack. It does not (and perhaps should not)
    5253// 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
    5357ast::Type * sizeType = nullptr;
    5458ast::FunctionDecl * dereferenceOperator = nullptr;
     
    6367        using Cache = std::unordered_map< const ast::Node *, BaseSyntaxNode * >;
    6468        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;
    6574
    6675        template<typename T>
     
    154163        }
    155164
    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 );
     165        const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {       
    161166                if ( inCache( node ) ) {
    162167                        return nullptr;
    163168                }
     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
    164173                auto decl = new ObjectDecl(
    165174                        node->name,
     
    168177                        bfwd,
    169178                        type->clone(),
    170                         init,
     179                        nullptr, // prevent infinite loop
    171180                        attr,
    172181                        Type::FuncSpecifiers( node->funcSpec.val )
    173182                );
    174                 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;
    175192        }
    176193
     
    205222                decl->statements = get<CompoundStmt>().accept1( node->stmts );
    206223                decl->withExprs = get<Expression>().acceptL( node->withExprs );
    207                 if ( dereferenceOperator == node ) {
     224                if ( ast::dereferenceOperator == node ) {
    208225                        Validate::dereferenceOperator = decl;
    209226                }
    210                 if ( dtorStructDestroy == node ) {
     227                if ( ast::dtorStructDestroy == node ) {
    211228                        Validate::dtorStructDestroy = decl;
    212229                }
     
    267284                );
    268285
    269                 if ( dtorStruct == node ) {
     286                if ( ast::dtorStruct == node ) {
    270287                        Validate::dtorStruct = decl;
    271288                }
     
    320337
    321338        const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) {
    322                 cache.emplace( node, stmt );
     339                // force statements in old tree to be unique.
     340                // cache.emplace( node, stmt );
     341                readonlyCache.emplace( node, stmt );
    323342                stmt->location = node->location;
    324343                stmt->labels = makeLabelL( stmt, node->labels );
     
    337356                if ( inCache( node ) ) return nullptr;
    338357                auto stmt = new ExprStmt( nullptr );
    339                 cache.emplace( node, stmt );
    340358                stmt->expr = get<Expression>().accept1( node->expr );
    341359                return stmtPostamble( stmt, node );
     
    10111029                auto stmts = node->stmts;
    10121030                // disable sharing between multiple StmtExprs explicitly.
    1013                 if (inCache(stmts)) {
    1014                         stmts = ast::deepCopy(stmts.get());
    1015                 }
     1031                // this should no longer be true.
     1032
    10161033                auto rslt = new StmtExpr(
    10171034                        get<CompoundStmt>().accept1(stmts)
     
    10201037                rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls);
    10211038                rslt->dtors       = get<Expression>().acceptL(node->dtors);
     1039                if (node->resultExpr) {
     1040                        // this MUST be found by children visit
     1041                        rslt->resultExpr  = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(node->resultExpr));
     1042                }
    10221043
    10231044                auto expr = visitBaseExpr( node, rslt );
     
    10361057
    10371058                auto expr = visitBaseExpr( node, rslt );
    1038                 this->node = expr;
     1059                this->node = expr->clone();
    10391060                return nullptr;
    10401061        }
     
    11261147                auto type = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind };
    11271148                // I believe this should always be a BasicType.
    1128                 if ( sizeType == node ) {
     1149                if ( ast::sizeType == node ) {
    11291150                        Validate::SizeType = type;
    11301151                }
     
    13841405};
    13851406
    1386 std::list< Declaration * > convert( const std::list< ast::ptr< ast::Decl > > && translationUnit ) {
     1407std::list< Declaration * > convert( const ast::TranslationUnit && translationUnit ) {
    13871408        ConverterNewToOld c;
    13881409        std::list< Declaration * > decls;
    1389         for(auto d : translationUnit) {
     1410        for(auto d : translationUnit.decls) {
    13901411                decls.emplace_back( c.decl( d ) );
    13911412        }
     
    15291550
    15301551                // function type is now derived from parameter decls instead of storing them
     1552
     1553                /*
    15311554                auto ftype = new ast::FunctionType((ast::ArgumentFlag)old->type->isVarArgs, cv(old->type));
    15321555                ftype->params.reserve(paramVars.size());
     
    15401563                }
    15411564                ftype->forall = std::move(forall);
    1542                 visitType(old->type, ftype);
     1565                */
     1566
     1567                // can function type have attributes? seems not to be the case.
     1568                // visitType(old->type, ftype);
    15431569
    15441570                auto decl = new ast::FunctionDecl{
     
    15461572                        old->name,
    15471573                        // GET_ACCEPT_1(type, FunctionType),
     1574                        std::move(forall),
    15481575                        std::move(paramVars),
    15491576                        std::move(returnVars),
     
    15521579                        { old->linkage.val },
    15531580                        GET_ACCEPT_V(attributes, Attribute),
    1554                         { old->get_funcSpec().val }
     1581                        { old->get_funcSpec().val },
     1582                        old->type->isVarArgs
    15551583                };
    15561584
    1557                 decl->type = ftype;
     1585                // decl->type = ftype;
    15581586                cache.emplace( old, decl );
    15591587
     
    15701598
    15711599                if ( Validate::dereferenceOperator == old ) {
    1572                         dereferenceOperator = decl;
     1600                        ast::dereferenceOperator = decl;
    15731601                }
    15741602
    15751603                if ( Validate::dtorStructDestroy == old ) {
    1576                         dtorStructDestroy = decl;
     1604                        ast::dtorStructDestroy = decl;
    15771605                }
    15781606        }
     
    15991627
    16001628                if ( Validate::dtorStruct == old ) {
    1601                         dtorStruct = decl;
     1629                        ast::dtorStruct = decl;
    16021630                }
    16031631        }
     
    25312559                // I believe this should always be a BasicType.
    25322560                if ( Validate::SizeType == old ) {
    2533                         sizeType = type;
     2561                        ast::sizeType = type;
    25342562                }
    25352563                visitType( old, type );
     
    27762804#undef GET_ACCEPT_1
    27772805
    2778 std::list< ast::ptr< ast::Decl > > convert( const std::list< Declaration * > && translationUnit ) {
     2806ast::TranslationUnit convert( const std::list< Declaration * > && translationUnit ) {
    27792807        ConverterOldToNew c;
    2780         std::list< ast::ptr< ast::Decl > > decls;
     2808        ast::TranslationUnit unit;
    27812809        for(auto d : translationUnit) {
    27822810                d->accept( c );
    2783                 decls.emplace_back( c.decl() );
     2811                unit.decls.emplace_back( c.decl() );
    27842812        }
    27852813        deleteAll(translationUnit);
    2786         return decls;
     2814        return unit;
    27872815}
Note: See TracChangeset for help on using the changeset viewer.