Changes in src/InitTweak/FixInit.cc [d56e5bc:62423350]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixInit.cc
rd56e5bc r62423350 56 56 typedef std::unordered_map< int, int > UnqCount; 57 57 58 class InsertImplicitCalls {58 class InsertImplicitCalls : public WithTypeSubstitution { 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 PassVisitor72 71 }; 73 72 … … 105 104 typedef AddStmtVisitor Parent; 106 105 using Parent::visit; 107 typedef std::set< ObjectDecl * > ObjectSet; 106 // use ordered data structure to maintain ordering for set_difference and for consistent error messages 107 typedef std::list< ObjectDecl * > ObjectSet; 108 108 virtual void visit( CompoundStmt *compoundStmt ) override; 109 109 virtual void visit( DeclStmt *stmt ) override; … … 117 117 118 118 // debug 119 struct printSet {120 typedef ObjDeclCollector::ObjectSet ObjectSet;121 printSet( const ObjectSet & objs ) : objs( objs ) {}119 template<typename ObjectSet> 120 struct PrintSet { 121 PrintSet( const ObjectSet & objs ) : objs( objs ) {} 122 122 const ObjectSet & objs; 123 123 }; 124 std::ostream & operator<<( std::ostream & out, const printSet & set) { 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) { 125 128 out << "{ "; 126 129 for ( ObjectDecl * obj : set.objs ) { … … 192 195 }; 193 196 194 class FixInit {197 class FixInit : public WithStmtsToAdd { 195 198 public: 196 199 /// expand each object declaration to use its constructor after it is declared. … … 200 203 201 204 std::list< Declaration * > staticDtorDecls; 202 std::list< Statement * > stmtsToAddAfter; // found by PassVisitor203 205 }; 204 206 … … 726 728 // static bool __objName_uninitialized = true 727 729 BasicType * boolType = new BasicType( Type::Qualifiers(), BasicType::Bool ); 728 SingleInit * boolInitExpr = new SingleInit( new ConstantExpr( Constant::from_int( 1 ) ) , noDesignators);730 SingleInit * boolInitExpr = new SingleInit( new ConstantExpr( Constant::from_int( 1 ) ) ); 729 731 ObjectDecl * isUninitializedVar = new ObjectDecl( objDecl->get_mangleName() + "_uninitialized", Type::StorageClasses( Type::Static ), LinkageSpec::Cforall, 0, boolType, boolInitExpr ); 730 732 isUninitializedVar->fixUniqueId(); … … 747 749 748 750 Statement * dtor = ctorInit->get_dtor(); 749 objDecl->set_init( NULL);750 ctorInit->set_ctor( NULL);751 objDecl->set_init( nullptr ); 752 ctorInit->set_ctor( nullptr ); 751 753 ctorInit->set_dtor( nullptr ); 752 754 if ( dtor ) { … … 801 803 } else { 802 804 stmtsToAddAfter.push_back( ctor ); 803 objDecl->set_init( NULL);804 ctorInit->set_ctor( NULL);805 objDecl->set_init( nullptr ); 806 ctorInit->set_ctor( nullptr ); 805 807 } 806 808 } // if 807 809 } else if ( Initializer * init = ctorInit->get_init() ) { 808 810 objDecl->set_init( init ); 809 ctorInit->set_init( NULL);811 ctorInit->set_init( nullptr ); 810 812 } else { 811 813 // no constructor and no initializer, which is okay 812 objDecl->set_init( NULL);814 objDecl->set_init( nullptr ); 813 815 } // if 814 816 delete ctorInit; … … 818 820 819 821 void ObjDeclCollector::visit( CompoundStmt * compoundStmt ) { 820 std::set< ObjectDecl * >prevVars = curVars;822 ObjectSet prevVars = curVars; 821 823 Parent::visit( compoundStmt ); 822 824 curVars = prevVars; … … 826 828 // keep track of all variables currently in scope 827 829 if ( ObjectDecl * objDecl = dynamic_cast< ObjectDecl * > ( stmt->get_decl() ) ) { 828 curVars. insert( objDecl );830 curVars.push_back( objDecl ); 829 831 } // if 830 832 Parent::visit( stmt ); … … 941 943 ) 942 944 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 943 948 // go through decl ordered list of objectdecl. for each element that occurs in diff, output destructor 944 949 OrderedDecls ordered; 945 950 for ( OrderedDecls & rdo : reverseDeclOrder ) { 946 951 // add elements from reverseDeclOrder into ordered if they occur in diff - it is key that this happens in reverse declaration order. 947 copy_if( rdo.begin(), rdo.end(), back_inserter( ordered ), [&]( ObjectDecl * objDecl ) { return diff.count( objDecl ); } );952 copy_if( rdo.begin(), rdo.end(), back_inserter( ordered ), [&]( ObjectDecl * objDecl ) { return needsDestructor.count( objDecl ); } ); 948 953 } // for 949 954 insertDtors( ordered.begin(), ordered.end(), back_inserter( stmtsToAdd ) );
Note:
See TracChangeset
for help on using the changeset viewer.