Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixInit.cc

    r62423350 rd56e5bc  
    5656                typedef std::unordered_map< int, int > UnqCount;
    5757
    58                 class InsertImplicitCalls : public WithTypeSubstitution {
     58                class InsertImplicitCalls {
    5959                public:
    6060                        /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which
     
    6969                        // collects environments for relevant nodes
    7070                        EnvMap & envMap;
     71                        TypeSubstitution * env; //Magically populated by the PassVisitor
    7172                };
    7273
     
    104105                        typedef AddStmtVisitor Parent;
    105106                        using Parent::visit;
    106                         // use ordered data structure to maintain ordering for set_difference and for consistent error messages
    107                         typedef std::list< ObjectDecl * > ObjectSet;
     107                        typedef std::set< ObjectDecl * > ObjectSet;
    108108                        virtual void visit( CompoundStmt *compoundStmt ) override;
    109109                        virtual void visit( DeclStmt *stmt ) override;
     
    117117
    118118                // debug
    119                 template<typename ObjectSet>
    120                 struct PrintSet {
    121                         PrintSet( const ObjectSet & objs ) : objs( objs ) {}
     119                struct printSet {
     120                        typedef ObjDeclCollector::ObjectSet ObjectSet;
     121                        printSet( const ObjectSet & objs ) : objs( objs ) {}
    122122                        const ObjectSet & objs;
    123123                };
    124                 template<typename ObjectSet>
    125                 PrintSet<ObjectSet> printSet( const ObjectSet & objs ) { return PrintSet<ObjectSet>( objs ); }
    126                 template<typename ObjectSet>
    127                 std::ostream & operator<<( std::ostream & out, const PrintSet<ObjectSet> & set) {
     124                std::ostream & operator<<( std::ostream & out, const printSet & set) {
    128125                        out << "{ ";
    129126                        for ( ObjectDecl * obj : set.objs ) {
     
    195192                };
    196193
    197                 class FixInit : public WithStmtsToAdd {
     194                class FixInit {
    198195                  public:
    199196                        /// expand each object declaration to use its constructor after it is declared.
     
    203200
    204201                        std::list< Declaration * > staticDtorDecls;
     202                        std::list< Statement * > stmtsToAddAfter; // found by PassVisitor
    205203                };
    206204
     
    728726                                                // static bool __objName_uninitialized = true
    729727                                                BasicType * boolType = new BasicType( Type::Qualifiers(), BasicType::Bool );
    730                                                 SingleInit * boolInitExpr = new SingleInit( new ConstantExpr( Constant::from_int( 1 ) ) );
     728                                                SingleInit * boolInitExpr = new SingleInit( new ConstantExpr( Constant::from_int( 1 ) ), noDesignators );
    731729                                                ObjectDecl * isUninitializedVar = new ObjectDecl( objDecl->get_mangleName() + "_uninitialized", Type::StorageClasses( Type::Static ), LinkageSpec::Cforall, 0, boolType, boolInitExpr );
    732730                                                isUninitializedVar->fixUniqueId();
     
    749747
    750748                                                Statement * dtor = ctorInit->get_dtor();
    751                                                 objDecl->set_init( nullptr );
    752                                                 ctorInit->set_ctor( nullptr );
     749                                                objDecl->set_init( NULL );
     750                                                ctorInit->set_ctor( NULL );
    753751                                                ctorInit->set_dtor( nullptr );
    754752                                                if ( dtor ) {
     
    803801                                                } else {
    804802                                                        stmtsToAddAfter.push_back( ctor );
    805                                                         objDecl->set_init( nullptr );
    806                                                         ctorInit->set_ctor( nullptr );
     803                                                        objDecl->set_init( NULL );
     804                                                        ctorInit->set_ctor( NULL );
    807805                                                }
    808806                                        } // if
    809807                                } else if ( Initializer * init = ctorInit->get_init() ) {
    810808                                        objDecl->set_init( init );
    811                                         ctorInit->set_init( nullptr );
     809                                        ctorInit->set_init( NULL );
    812810                                } else {
    813811                                        // no constructor and no initializer, which is okay
    814                                         objDecl->set_init( nullptr );
     812                                        objDecl->set_init( NULL );
    815813                                } // if
    816814                                delete ctorInit;
     
    820818
    821819                void ObjDeclCollector::visit( CompoundStmt * compoundStmt ) {
    822                         ObjectSet prevVars = curVars;
     820                        std::set< ObjectDecl * > prevVars = curVars;
    823821                        Parent::visit( compoundStmt );
    824822                        curVars = prevVars;
     
    828826                        // keep track of all variables currently in scope
    829827                        if ( ObjectDecl * objDecl = dynamic_cast< ObjectDecl * > ( stmt->get_decl() ) ) {
    830                                 curVars.push_back( objDecl );
     828                                curVars.insert( objDecl );
    831829                        } // if
    832830                        Parent::visit( stmt );
     
    943941                        )
    944942                        if ( ! diff.empty() ) {
    945                                 // create an auxilliary set for fast lookup -- can't make diff a set, because diff ordering should be consistent for error messages.
    946                                 std::unordered_set<ObjectDecl *> needsDestructor( diff.begin(), diff.end() );
    947 
    948943                                // go through decl ordered list of objectdecl. for each element that occurs in diff, output destructor
    949944                                OrderedDecls ordered;
    950945                                for ( OrderedDecls & rdo : reverseDeclOrder ) {
    951946                                        // add elements from reverseDeclOrder into ordered if they occur in diff - it is key that this happens in reverse declaration order.
    952                                         copy_if( rdo.begin(), rdo.end(), back_inserter( ordered ), [&]( ObjectDecl * objDecl ) { return needsDestructor.count( objDecl ); } );
     947                                        copy_if( rdo.begin(), rdo.end(), back_inserter( ordered ), [&]( ObjectDecl * objDecl ) { return diff.count( objDecl ); } );
    953948                                } // for
    954949                                insertDtors( ordered.begin(), ordered.end(), back_inserter( stmtsToAdd ) );
Note: See TracChangeset for help on using the changeset viewer.