Changeset eb5962a for src/AST/TypeSubstitution.cpp
- Timestamp:
- Jun 21, 2022, 1:39:24 PM (22 months ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- b62d1d6
- Parents:
- 1df492a (diff), 1dbbef6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/TypeSubstitution.cpp
r1df492a reb5962a 38 38 39 39 void TypeSubstitution::initialize( const TypeSubstitution &src, TypeSubstitution &dest ) { 40 dest.type Env.clear();40 dest.typeMap.clear(); 41 41 dest.add( src ); 42 42 } 43 43 44 44 void TypeSubstitution::add( const TypeSubstitution &other ) { 45 for ( Type EnvType::const_iterator i = other.typeEnv.begin(); i != other.typeEnv.end(); ++i ) {46 type Env[ i->first ] = i->second;45 for ( TypeMap::const_iterator i = other.typeMap.begin(); i != other.typeMap.end(); ++i ) { 46 typeMap[ i->first ] = i->second; 47 47 } // for 48 48 } 49 49 50 50 void TypeSubstitution::add( const TypeInstType * formalType, const Type *actualType ) { 51 type Env[ *formalType ] = actualType;51 typeMap[ *formalType ] = actualType; 52 52 } 53 53 54 54 void TypeSubstitution::add( const TypeInstType::TypeEnvKey & key, const Type * actualType) { 55 type Env[ key ] = actualType;55 typeMap[ key ] = actualType; 56 56 } 57 57 58 58 void TypeSubstitution::remove( const TypeInstType * formalType ) { 59 TypeEnvType::iterator i = typeEnv.find( *formalType ); 60 if ( i != typeEnv.end() ) { 61 typeEnv.erase( *formalType ); 62 } // if 63 } 64 65 const Type *TypeSubstitution::lookup( const TypeInstType * formalType ) const { 66 TypeEnvType::const_iterator i = typeEnv.find( *formalType ); 59 TypeMap::iterator i = typeMap.find( *formalType ); 60 if ( i != typeMap.end() ) { 61 typeMap.erase( *formalType ); 62 } // if 63 } 64 65 const Type *TypeSubstitution::lookup( 66 const TypeInstType::TypeEnvKey & formalType ) const { 67 TypeMap::const_iterator i = typeMap.find( formalType ); 67 68 68 69 // break on not in substitution set 69 if ( i == type Env.end() ) return 0;70 if ( i == typeMap.end() ) return 0; 70 71 71 72 // attempt to transitively follow TypeInstType links. 72 73 while ( const TypeInstType *actualType = i->second.as<TypeInstType>()) { 73 74 // break cycles in the transitive follow 74 if ( *formalType == *actualType ) break;75 if ( formalType == *actualType ) break; 75 76 76 77 // Look for the type this maps to, returning previous mapping if none-such 77 i = type Env.find( *actualType );78 if ( i == type Env.end() ) return actualType;78 i = typeMap.find( *actualType ); 79 if ( i == typeMap.end() ) return actualType; 79 80 } 80 81 … … 83 84 } 84 85 86 const Type *TypeSubstitution::lookup( const TypeInstType * formalType ) const { 87 return lookup( ast::TypeInstType::TypeEnvKey( *formalType ) ); 88 } 89 85 90 bool TypeSubstitution::empty() const { 86 return type Env.empty();91 return typeMap.empty(); 87 92 } 88 93 … … 119 124 sub.core.subCount = 0; 120 125 sub.core.freeOnly = true; 121 for ( Type EnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {126 for ( TypeMap::iterator i = typeMap.begin(); i != typeMap.end(); ++i ) { 122 127 i->second = i->second->accept( sub ); 123 128 } … … 129 134 if ( bound != boundVars.end() ) return inst; 130 135 131 Type EnvType::const_iterator i = sub.typeEnv.find( *inst );132 if ( i == sub.type Env.end() ) {136 TypeMap::const_iterator i = sub.typeMap.find( *inst ); 137 if ( i == sub.typeMap.end() ) { 133 138 return inst; 134 139 } else {
Note: See TracChangeset
for help on using the changeset viewer.