Changes in / [b7fd9daf:1622af5]


Ignore:
Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rb7fd9daf r1622af5  
    10411041
    10421042        const ast::Expr * visit( const ast::StmtExpr * node ) override final {
     1043                auto stmts = node->stmts;
     1044                // disable sharing between multiple StmtExprs explicitly.
     1045                // this should no longer be true.
     1046
    10431047                auto rslt = new StmtExpr(
    1044                         get<CompoundStmt>().accept1(node->stmts)
     1048                        get<CompoundStmt>().accept1(stmts)
    10451049                );
    10461050
    10471051                rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls);
    10481052                rslt->dtors       = get<Expression>().acceptL(node->dtors);
    1049 
    1050                 // is this even used after convert?
    1051                 //if (tmp->resultExpr) {
    1052                 //      // this MUST be found by children visit
    1053                 //      rslt->resultExpr  = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(tmp->resultExpr));
    1054                 //}
     1053                if (node->resultExpr) {
     1054                        // this MUST be found by children visit
     1055                        rslt->resultExpr  = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(node->resultExpr));
     1056                }
    10551057
    10561058                auto expr = visitBaseExpr( node, rslt );
  • src/AST/Copy.hpp

    rb7fd9daf r1622af5  
    8888        }
    8989
    90         void postvisit( const StmtExpr * node ) {
    91                 readonlyInsert( &node->resultExpr );
    92         }
    93 
    9490        void postvisit( const MemberExpr * node ) {
    9591                readonlyInsert( &node->member );
     
    126122node_t * deepCopy( const node_t * localRoot ) {
    127123        Pass< DeepCopyCore > dc;
    128         node_t const * newRoot = strict_dynamic_cast<node_t const*>(localRoot->accept( dc ));
     124        node_t const * newRoot = localRoot->accept( dc );
    129125        dc.core.readonlyUpdates();
    130126        return const_cast< node_t * >( newRoot );
  • src/AST/Expr.hpp

    rb7fd9daf r1622af5  
    767767
    768768/// An expression which must only be evaluated once
    769 class
    770 UniqueExpr final : public Expr {
     769class UniqueExpr final : public Expr {
    771770        static unsigned long long nextId;
    772771public:
  • src/Tuples/TupleExpansionNew.cpp

    rb7fd9daf r1622af5  
    2121                void previsit( const ast::UntypedMemberExpr * ) { visit_children = false; }
    2222        const ast::Expr * postvisit( const ast::UntypedMemberExpr * memberExpr );
    23         };
    24         struct UniqueExprExpander final : public ast::WithDeclsToAdd<> {
    25                 const ast::Expr * postvisit( const ast::UniqueExpr * unqExpr );
    26                 std::map< int, ast::ptr<ast::Expr> > decls; // not vector, because order added may not be increasing order
    2723        };
    2824} // namespace
     
    7066        }
    7167} // namespace
    72 
    73 void expandUniqueExpr( ast::TranslationUnit & translationUnit ) {
    74         ast::Pass< UniqueExprExpander >::run( translationUnit );
    75 }
    76 
    77 namespace {
    78         const ast::Expr * UniqueExprExpander::postvisit( const ast::UniqueExpr * unqExpr ) {
    79                 const CodeLocation loc = unqExpr->location;
    80                 const int id = unqExpr->id;
    81 
    82                 // on first time visiting a unique expr with a particular ID, generate the expression that replaces all UniqueExprs with that ID,
    83                 // and lookup on subsequent hits. This ensures that all unique exprs with the same ID reference the same variable.
    84                 if ( ! decls.count( id ) ) {
    85                         ast::ptr< ast::Expr > assignUnq;
    86                         const ast::VariableExpr * var = unqExpr->var;
    87                         if ( unqExpr->object ) {
    88                                 // an object was generated to represent this unique expression -- it should be added to the list of declarations now
    89                                 declsToAddBefore.push_back( unqExpr->object.as< ast::Decl >() );
    90                                 // deep copy required due to unresolved issues with UniqueExpr
    91                                 assignUnq = ast::UntypedExpr::createAssign( loc, var, unqExpr->expr );
    92                         } else {
    93                                 const auto commaExpr = unqExpr->expr.strict_as< ast::CommaExpr >();
    94                                 assignUnq = commaExpr->arg1;
    95                         }
    96                         auto finished = new ast::ObjectDecl( loc, toString( "_unq", id, "_finished_" ), new ast::BasicType( ast::BasicType::Kind::Bool ),
    97                                 new ast::SingleInit( loc, ast::ConstantExpr::from_int( loc, 0 ) ), {}, ast::Linkage::Cforall );
    98                         declsToAddBefore.push_back( finished );
    99                         // (finished ? _unq_expr_N : (_unq_expr_N = <unqExpr->get_expr()>, finished = 1, _unq_expr_N))
    100                         // This pattern ensures that each unique expression is evaluated once, regardless of evaluation order of the generated C code.
    101                         auto assignFinished = ast::UntypedExpr::createAssign( loc, new ast::VariableExpr( loc, finished ),
    102                                 ast::ConstantExpr::from_int( loc, 1 ) );
    103                         auto condExpr = new ast::ConditionalExpr( loc, new ast::VariableExpr( loc, finished ), var,
    104                                 new ast::CommaExpr( loc, new ast::CommaExpr( loc, assignUnq, assignFinished ), var ) );
    105                         condExpr->result = var->result;
    106                         condExpr->env = unqExpr->env;
    107                         decls[id] = condExpr;
    108                 }
    109                 //delete unqExpr;
    110                 return ast::deepCopy(decls[id].get());
    111         }
    112 } // namespace
    11368} // namespace Tuples
  • src/Tuples/Tuples.h

    rb7fd9daf r1622af5  
    4646        /// replaces UniqueExprs with a temporary variable and one call
    4747        void expandUniqueExpr( std::list< Declaration * > & translationUnit );
    48         void expandUniqueExpr( ast::TranslationUnit & translationUnit );
    4948
    5049        /// returns VoidType if any of the expressions have Voidtype, otherwise TupleType of the Expression result types
  • src/main.cc

    rb7fd9daf r1622af5  
    381381                        PASS( "Fix Init", InitTweak::fix(transUnit, buildingLibrary()));
    382382
    383                         // fix ObjectDecl - replaces ConstructorInit nodes
    384                         if ( ctorinitp ) {
    385                                 dump( move( transUnit ) );
    386                                 return EXIT_SUCCESS;
    387                         } // if
    388 
    389                         // Currently not working due to unresolved issues with UniqueExpr
    390                         PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( transUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused
    391383                        translationUnit = convert( move( transUnit ) );
    392384                } else {
     
    443435
    444436                        PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) );
    445 
    446                         // fix ObjectDecl - replaces ConstructorInit nodes
    447                         if ( ctorinitp ) {
    448                                 dump ( translationUnit );
    449                                 return EXIT_SUCCESS;
    450                         } // if
    451 
    452                         PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( translationUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused
    453437                }
     438
     439                // fix ObjectDecl - replaces ConstructorInit nodes
     440                if ( ctorinitp ) {
     441                        dump ( translationUnit );
     442                        return EXIT_SUCCESS;
     443                } // if
     444
     445                PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( translationUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused
    454446
    455447                PASS( "Translate Tries" , ControlStruct::translateTries( translationUnit ) );
Note: See TracChangeset for help on using the changeset viewer.