Changes in src/GenPoly/ScrubTyVars.cc [2f61765:0026d67]
- File:
-
- 1 edited
-
src/GenPoly/ScrubTyVars.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/ScrubTyVars.cc
r2f61765 r0026d67 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Dec 7 17:01:00 202213 // Update Count : 612 // Last Modified On : Fri Oct 7 15:42:00 2022 13 // Update Count : 5 14 14 // 15 15 … … 117 117 namespace { 118 118 119 enum class ScrubMode { 120 FromMap, 121 DynamicFromMap, 122 All, 123 }; 124 119 125 struct ScrubTypeVars : 120 126 public ast::WithGuards, … … 178 184 179 185 ast::Type const * ScrubTypeVars::postvisit( ast::TypeInstType const * type ) { 180 ast::TypeDecl::Kind kind;181 186 // This implies that mode == ScrubMode::All. 182 187 if ( !typeVars ) { 183 kind = type->kind; 184 } else { 185 // Otherwise, only scrub the type var if it is in map. 186 auto typeVar = typeVars->find( *type ); 187 if ( typeVar == typeVars->end() ) { 188 return type; 189 } 190 kind = typeVar->second.kind; 191 } 192 193 switch ( kind ) { 194 case ast::TypeDecl::Dtype: 195 case ast::TypeDecl::Ttype: 188 if ( ast::TypeDecl::Ftype == type->kind ) { 189 return new ast::PointerType( 190 new ast::FunctionType( ast::FixedArgs ) ); 191 } else { 192 return new ast::PointerType( 193 new ast::VoidType( type->qualifiers ) ); 194 } 195 } 196 197 auto typeVar = typeVars->find( *type ); 198 if ( typeVar == typeVars->end() ) { 199 return type; 200 } 201 202 switch ( typeVar->second.kind ) { 203 case ::TypeDecl::Dtype: 204 case ::TypeDecl::Ttype: 196 205 return new ast::PointerType( 197 206 new ast::VoidType( type->qualifiers ) ); 198 case ast::TypeDecl::Ftype:207 case ::TypeDecl::Ftype: 199 208 return new ast::PointerType( 200 209 new ast::FunctionType( ast::VariableArgs ) ); 201 210 default: 202 assertf( false, "Unhandled type variable kind: %d", kind ); 211 assertf( false, 212 "Unhandled type variable kind: %d", typeVar->second.kind ); 203 213 throw; // Just in case the assert is removed, stop here. 204 214 } … … 243 253 } 244 254 245 } // namespace246 247 255 const ast::Node * scrubTypeVarsBase( 248 const ast::Node * node, const TypeVarMap * typeVars, ScrubMode mode ) { 256 const ast::Node * target, 257 ScrubMode mode, const TypeVarMap * typeVars ) { 249 258 if ( ScrubMode::All == mode ) { 250 259 assert( nullptr == typeVars ); … … 253 262 } 254 263 ast::Pass<ScrubTypeVars> visitor( mode, typeVars ); 255 return node->accept( visitor ); 264 return target->accept( visitor ); 265 } 266 267 } // namespace 268 269 template<> 270 ast::Node const * scrubTypeVars<ast::Node>( 271 const ast::Node * target, const TypeVarMap & typeVars ) { 272 return scrubTypeVarsBase( target, ScrubMode::FromMap, &typeVars ); 273 } 274 275 template<> 276 ast::Node const * scrubTypeVarsDynamic<ast::Node>( 277 ast::Node const * target, const TypeVarMap & typeVars ) { 278 return scrubTypeVarsBase( target, ScrubMode::DynamicFromMap, &typeVars ); 279 } 280 281 template<> 282 ast::Node const * scrubAllTypeVars<ast::Node>( const ast::Node * target ) { 283 return scrubTypeVarsBase( target, ScrubMode::All, nullptr ); 256 284 } 257 285
Note:
See TracChangeset
for help on using the changeset viewer.