Changeset e0e9a0b for src/ResolvExpr
- Timestamp:
- Jun 27, 2019, 5:16:54 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 7d0881c
- Parents:
- 6be3b7d6
- Location:
- src/ResolvExpr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r6be3b7d6 re0e9a0b 548 548 genStart = genEnd; 549 549 550 return genEnd != results.size(); 550 return genEnd != results.size(); // were any new results added? 551 551 } 552 552 … … 677 677 ast::TypeEnvironment funcEnv{ func->env }; 678 678 makeUnifiableVars( funcType, funcOpen, funcNeed ); 679 // add all type variables as open variables now so that those not used in the parameter680 // list are still considered open679 // add all type variables as open variables now so that those not used in the 680 // parameter list are still considered open 681 681 funcEnv.add( funcType->forall ); 682 682 -
src/ResolvExpr/RenameVars.cc
r6be3b7d6 re0e9a0b 19 19 #include <utility> // for pair 20 20 21 #include "AST/ForallSubstitutionTable.hpp" 21 22 #include "AST/Pass.hpp" 22 23 #include "AST/Type.hpp" … … 37 38 int resetCount = 0; 38 39 ScopedMap< std::string, std::string > nameMap; 40 public: 41 ast::ForallSubstitutionTable subs; 39 42 40 public:41 43 void reset() { 42 44 level = 0; … … 44 46 } 45 47 46 using mapConstIterator = ScopedMap< std::string, std::string >::const_iterator;47 48 48 void rename( TypeInstType * type ) { 49 mapConstIteratorit = nameMap.find( type->name );49 auto 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 // acceptAll( td->assertions, *this ); 68 } // for 69 } // if 67 } 68 } 70 69 } 71 70 … … 77 76 78 77 const ast::TypeInstType * rename( const ast::TypeInstType * type ) { 79 mapConstIterator it = nameMap.find( type->name ); 78 // re-linking of base type handled by WithForallSubstitutor 79 80 // rename 81 auto it = nameMap.find( type->name ); 80 82 if ( it != nameMap.end() ) { 81 ast::TypeInstType * mutType = ast::mutate( type ); 82 mutType->name = it->second; 83 type = mutType; 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; 84 88 } 89 85 90 return type; 86 91 } … … 88 93 template<typename NodeT> 89 94 const NodeT * openLevel( const NodeT * type ) { 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; 95 if ( type->forall.empty() ) return type; 96 97 nameMap.beginScope(); 100 98 101 ast::TypeDecl * decl = ast::mutate( td.get() ); 102 decl->name = newname; 103 td = decl; 104 } 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 105 113 } 114 // assertion above means `type = mutType;` is unnecessary 115 106 116 return type; 107 117 } 108 118 109 template<typename NodeT> 110 const NodeT * closeLevel( const NodeT * type ) { 111 if ( !type->forall.empty() ) { 112 nameMap.endScope(); 113 } 114 return type; 119 void closeLevel( const ast::ParameterizedType * type ) { 120 if ( type->forall.empty() ) return; 121 122 nameMap.endScope(); 115 123 } 116 124 }; … … 119 127 RenamingData renaming; 120 128 121 struct RenameVars {129 struct RenameVars_old { 122 130 void previsit( TypeInstType * instType ) { 123 131 renaming.openLevel( (Type*)instType ); … … 130 138 renaming.closeLevel( type ); 131 139 } 140 }; 141 142 struct RenameVars_new /*: public ast::WithForallSubstitutor*/ { 143 #warning when old RenameVars goes away, replace hack below with global pass inheriting from WithForallSubstitutor 144 ast::ForallSubstitutionTable & subs = renaming.subs; 132 145 133 146 const ast::FunctionType * previsit( const ast::FunctionType * type ) { … … 146 159 return renaming.rename( renaming.openLevel( type ) ); 147 160 } 148 const ast::ParameterizedType *postvisit( const ast::ParameterizedType * type ) {149 re turn renaming.closeLevel( type );161 void postvisit( const ast::ParameterizedType * type ) { 162 renaming.closeLevel( type ); 150 163 } 151 164 }; … … 154 167 155 168 void renameTyVars( Type * t ) { 156 PassVisitor<RenameVars > renamer;169 PassVisitor<RenameVars_old> renamer; 157 170 t->accept( renamer ); 158 171 } 159 172 160 173 const ast::Type * renameTyVars( const ast::Type * t ) { 161 ast::Pass<RenameVars > renamer;174 ast::Pass<RenameVars_new> renamer; 162 175 return t->accept( renamer ); 163 176 }
Note: See TracChangeset
for help on using the changeset viewer.