Changeset a8b87d3
- Timestamp:
- Jun 14, 2022, 10:55:46 AM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- aec20700
- Parents:
- 1f0ee71
- Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Pass.impl.hpp
r1f0ee71 ra8b87d3 182 182 183 183 // get the stmts/decls that will need to be spliced in 184 auto stmts_before = __pass::stmtsToAddBefore( core, 0 );185 auto stmts_after = __pass::stmtsToAddAfter ( core, 0 );186 auto decls_before = __pass::declsToAddBefore( core, 0 );187 auto decls_after = __pass::declsToAddAfter ( core, 0 );184 auto stmts_before = __pass::stmtsToAddBefore( core, 0 ); 185 auto stmts_after = __pass::stmtsToAddAfter ( core, 0 ); 186 auto decls_before = __pass::declsToAddBefore( core, 0 ); 187 auto decls_after = __pass::declsToAddAfter ( core, 0 ); 188 188 189 189 // These may be modified by subnode but most be restored once we exit this statemnet. … … 317 317 assert(( empty( stmts_before ) && empty( stmts_after )) 318 318 || ( empty( decls_before ) && empty( decls_after )) ); 319 320 321 319 322 320 // Take all the statements which should have gone after, N/A for first iteration … … 2115 2113 if ( __visit_children() ) { 2116 2114 bool mutated = false; 2117 std::unordered_map< ast::TypeInstType::TypeEnvKey, ast::ptr< ast::Type > >new_map;2118 for ( const auto & p : node->type Env) {2115 ast::TypeSubstitution::TypeMap new_map; 2116 for ( const auto & p : node->typeMap ) { 2119 2117 guard_symtab guard { *this }; 2120 2118 auto new_node = p.second->accept( *this ); … … 2124 2122 if (mutated) { 2125 2123 auto new_node = __pass::mutate<core_t>( node ); 2126 new_node->type Env.swap( new_map );2124 new_node->typeMap.swap( new_map ); 2127 2125 node = new_node; 2128 2126 } -
src/AST/TypeSubstitution.cpp
r1f0ee71 ra8b87d3 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 { -
src/AST/TypeSubstitution.hpp
r1f0ee71 ra8b87d3 75 75 void add( const TypeSubstitution &other ); 76 76 void remove( const TypeInstType * formalType ); 77 const Type *lookup( const TypeInstType::TypeEnvKey & formalType ) const; 77 78 const Type *lookup( const TypeInstType * formalType ) const; 78 79 bool empty() const; … … 104 105 friend class Pass; 105 106 106 typedef std::unordered_map< TypeInstType::TypeEnvKey, ptr<Type> > Type EnvType;107 Type EnvType typeEnv;107 typedef std::unordered_map< TypeInstType::TypeEnvKey, ptr<Type> > TypeMap; 108 TypeMap typeMap; 108 109 109 110 public: 110 // has to come after declaration of type Env111 auto begin() -> decltype( type Env.begin() ) { return typeEnv.begin(); }112 auto end() -> decltype( type Env. end() ) { return typeEnv. end(); }113 auto begin() const -> decltype( type Env.begin() ) { return typeEnv.begin(); }114 auto end() const -> decltype( type Env. end() ) { return typeEnv. end(); }111 // has to come after declaration of typeMap 112 auto begin() -> decltype( typeMap.begin() ) { return typeMap.begin(); } 113 auto end() -> decltype( typeMap. end() ) { return typeMap. end(); } 114 auto begin() const -> decltype( typeMap.begin() ) { return typeMap.begin(); } 115 auto end() const -> decltype( typeMap. end() ) { return typeMap. end(); } 115 116 116 117 }; … … 144 145 if ( const TypeExpr *actual = actualIt->template as<TypeExpr>() ) { 145 146 if ( formal->name != "" ) { 146 type Env[ formal ] = actual->type;147 typeMap[ formal ] = actual->type; 147 148 } // if 148 149 } else { -
src/GenPoly/Specialize.cc
r1f0ee71 ra8b87d3 247 247 structureArg( (*actualBegin)->get_type(), argBegin, argEnd, back_inserter( appExpr->get_args() ) ); 248 248 } 249 assertf( argBegin == argEnd, "Did not structure all arguments." ); 249 250 250 251 appExpr->env = TypeSubstitution::newFromExpr( appExpr, env );
Note: See TracChangeset
for help on using the changeset viewer.