Changes in src/ResolvExpr/RenameVars.cc [e0e9a0b:f5edcb4]
- File:
-
- 1 edited
-
src/ResolvExpr/RenameVars.cc (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/RenameVars.cc
re0e9a0b rf5edcb4 19 19 #include <utility> // for pair 20 20 21 #include "AST/ForallSubstitutionTable.hpp"22 21 #include "AST/Pass.hpp" 23 22 #include "AST/Type.hpp" … … 38 37 int resetCount = 0; 39 38 ScopedMap< std::string, std::string > nameMap; 39 40 40 public: 41 ast::ForallSubstitutionTable subs;42 43 41 void reset() { 44 42 level = 0; … … 46 44 } 47 45 46 using mapConstIterator = ScopedMap< std::string, std::string >::const_iterator; 47 48 48 void rename( TypeInstType * type ) { 49 autoit = nameMap.find( type->name );49 mapConstIterator it = nameMap.find( type->name ); 50 50 if ( it != nameMap.end() ) { 51 51 type->name = it->second; … … 65 65 // ditto for assertion names, the next level in 66 66 level++; 67 } 68 } 67 // acceptAll( td->assertions, *this ); 68 } // for 69 } // if 69 70 } 70 71 … … 76 77 77 78 const ast::TypeInstType * rename( const ast::TypeInstType * type ) { 78 // re-linking of base type handled by WithForallSubstitutor 79 80 // rename 81 auto it = nameMap.find( type->name ); 79 mapConstIterator it = nameMap.find( type->name ); 82 80 if ( it != nameMap.end() ) { 83 // unconditionally mutate because map will *always* have different name, 84 // if this mutates, will *always* have been mutated by ForallSubstitutor above 85 ast::TypeInstType * mut = ast::mutate( type ); 86 mut->name = it->second; 87 type = mut; 81 ast::TypeInstType * mutType = ast::mutate( type ); 82 mutType->name = it->second; 83 type = mutType; 88 84 } 89 90 85 return type; 91 86 } … … 93 88 template<typename NodeT> 94 89 const NodeT * openLevel( const NodeT * type ) { 95 if ( type->forall.empty() ) return type; 96 97 nameMap.beginScope(); 90 if ( !type->forall.empty() ) { 91 nameMap.beginScope(); 92 // Load new names from this forall clause and perform renaming. 93 NodeT * mutType = ast::mutate( type ); 94 for ( ast::ptr< ast::TypeDecl > & td : mutType->forall ) { 95 std::ostringstream output; 96 output << "_" << resetCount << "_" << level << "_" << td->name; 97 std::string newname( output.str() ); 98 nameMap[ td->name ] = newname; 99 ++level; 98 100 99 // Load new names from this forall clause and perform renaming. 100 NodeT * mutType = ast::mutate( type ); 101 assert( type == mutType && "mutated type must be unique from ForallSubstitutor" ); 102 for ( ast::ptr< ast::TypeDecl > & td : mutType->forall ) { 103 std::ostringstream output; 104 output << "_" << resetCount << "_" << level << "_" << td->name; 105 std::string newname = output.str(); 106 nameMap[ td->name ] = newname; 107 ++level; 108 109 ast::TypeDecl * mutDecl = ast::mutate( td.get() ); 110 assert( td == mutDecl && "mutated decl must be unique from ForallSubstitutor" ); 111 mutDecl->name = newname; 112 // assertion above means `td = mutDecl;` is unnecessary 101 ast::TypeDecl * decl = ast::mutate( td.get() ); 102 decl->name = newname; 103 td = decl; 104 } 113 105 } 114 // assertion above means `type = mutType;` is unnecessary115 116 106 return type; 117 107 } 118 108 119 void closeLevel( const ast::ParameterizedType * type ) { 120 if ( type->forall.empty() ) return; 121 122 nameMap.endScope(); 109 template<typename NodeT> 110 const NodeT * closeLevel( const NodeT * type ) { 111 if ( !type->forall.empty() ) { 112 nameMap.endScope(); 113 } 114 return type; 123 115 } 124 116 }; … … 127 119 RenamingData renaming; 128 120 129 struct RenameVars _old{121 struct RenameVars { 130 122 void previsit( TypeInstType * instType ) { 131 123 renaming.openLevel( (Type*)instType ); … … 138 130 renaming.closeLevel( type ); 139 131 } 140 };141 142 struct RenameVars_new /*: public ast::WithForallSubstitutor*/ {143 #warning when old RenameVars goes away, replace hack below with global pass inheriting from WithForallSubstitutor144 ast::ForallSubstitutionTable & subs = renaming.subs;145 132 146 133 const ast::FunctionType * previsit( const ast::FunctionType * type ) { … … 159 146 return renaming.rename( renaming.openLevel( type ) ); 160 147 } 161 voidpostvisit( const ast::ParameterizedType * type ) {162 re naming.closeLevel( type );148 const ast::ParameterizedType * postvisit( const ast::ParameterizedType * type ) { 149 return renaming.closeLevel( type ); 163 150 } 164 151 }; … … 167 154 168 155 void renameTyVars( Type * t ) { 169 PassVisitor<RenameVars _old> renamer;156 PassVisitor<RenameVars> renamer; 170 157 t->accept( renamer ); 171 158 } 172 159 173 160 const ast::Type * renameTyVars( const ast::Type * t ) { 174 ast::Pass<RenameVars _new> renamer;161 ast::Pass<RenameVars> renamer; 175 162 return t->accept( renamer ); 176 163 }
Note:
See TracChangeset
for help on using the changeset viewer.