Changes in src/InitTweak/FixInit.cc [62423350:d56e5bc]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
r62423350 rd56e5bc 56 56 typedef std::unordered_map< int, int > UnqCount; 57 57 58 class InsertImplicitCalls : public WithTypeSubstitution{58 class InsertImplicitCalls { 59 59 public: 60 60 /// wrap function application expressions as ImplicitCopyCtorExpr nodes so that it is easy to identify which … … 69 69 // collects environments for relevant nodes 70 70 EnvMap & envMap; 71 TypeSubstitution * env; //Magically populated by the PassVisitor 71 72 }; 72 73 … … 104 105 typedef AddStmtVisitor Parent; 105 106 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; 108 108 virtual void visit( CompoundStmt *compoundStmt ) override; 109 109 virtual void visit( DeclStmt *stmt ) override; … … 117 117 118 118 // 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 ) {} 122 122 const ObjectSet & objs; 123 123 }; 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) { 128 125 out << "{ "; 129 126 for ( ObjectDecl * obj : set.objs ) { … … 195 192 }; 196 193 197 class FixInit : public WithStmtsToAdd{194 class FixInit { 198 195 public: 199 196 /// expand each object declaration to use its constructor after it is declared. … … 203 200 204 201 std::list< Declaration * > staticDtorDecls; 202 std::list< Statement * > stmtsToAddAfter; // found by PassVisitor 205 203 }; 206 204 … … 728 726 // static bool __objName_uninitialized = true 729 727 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 ); 731 729 ObjectDecl * isUninitializedVar = new ObjectDecl( objDecl->get_mangleName() + "_uninitialized", Type::StorageClasses( Type::Static ), LinkageSpec::Cforall, 0, boolType, boolInitExpr ); 732 730 isUninitializedVar->fixUniqueId(); … … 749 747 750 748 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 ); 753 751 ctorInit->set_dtor( nullptr ); 754 752 if ( dtor ) { … … 803 801 } else { 804 802 stmtsToAddAfter.push_back( ctor ); 805 objDecl->set_init( nullptr);806 ctorInit->set_ctor( nullptr);803 objDecl->set_init( NULL ); 804 ctorInit->set_ctor( NULL ); 807 805 } 808 806 } // if 809 807 } else if ( Initializer * init = ctorInit->get_init() ) { 810 808 objDecl->set_init( init ); 811 ctorInit->set_init( nullptr);809 ctorInit->set_init( NULL ); 812 810 } else { 813 811 // no constructor and no initializer, which is okay 814 objDecl->set_init( nullptr);812 objDecl->set_init( NULL ); 815 813 } // if 816 814 delete ctorInit; … … 820 818 821 819 void ObjDeclCollector::visit( CompoundStmt * compoundStmt ) { 822 ObjectSetprevVars = curVars;820 std::set< ObjectDecl * > prevVars = curVars; 823 821 Parent::visit( compoundStmt ); 824 822 curVars = prevVars; … … 828 826 // keep track of all variables currently in scope 829 827 if ( ObjectDecl * objDecl = dynamic_cast< ObjectDecl * > ( stmt->get_decl() ) ) { 830 curVars. push_back( objDecl );828 curVars.insert( objDecl ); 831 829 } // if 832 830 Parent::visit( stmt ); … … 943 941 ) 944 942 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 948 943 // go through decl ordered list of objectdecl. for each element that occurs in diff, output destructor 949 944 OrderedDecls ordered; 950 945 for ( OrderedDecls & rdo : reverseDeclOrder ) { 951 946 // 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 ); } ); 953 948 } // for 954 949 insertDtors( ordered.begin(), ordered.end(), back_inserter( stmtsToAdd ) );
Note:
See TracChangeset
for help on using the changeset viewer.