Changeset 24d6572 for src/GenPoly/ScrubTyVars.cc
- Timestamp:
- Jun 12, 2023, 2:45:32 PM (2 years ago)
- Branches:
- ast-experimental, master
- Children:
- 62d62db
- Parents:
- 34b4268 (diff), 251ce80 (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
-
src/GenPoly/ScrubTyVars.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/ScrubTyVars.cc
r34b4268 r24d6572 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Oct 7 15:42:00 202213 // Update Count : 512 // Last Modified On : Wed Dec 7 17:01:00 2022 13 // Update Count : 6 14 14 // 15 15 … … 117 117 namespace { 118 118 119 enum class ScrubMode {120 FromMap,121 DynamicFromMap,122 All,123 };124 125 119 struct ScrubTypeVars : 126 120 public ast::WithGuards, … … 184 178 185 179 ast::Type const * ScrubTypeVars::postvisit( ast::TypeInstType const * type ) { 180 ast::TypeDecl::Kind kind; 186 181 // This implies that mode == ScrubMode::All. 187 182 if ( !typeVars ) { 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: 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: 205 196 return new ast::PointerType( 206 197 new ast::VoidType( type->qualifiers ) ); 207 case ::TypeDecl::Ftype:198 case ast::TypeDecl::Ftype: 208 199 return new ast::PointerType( 209 200 new ast::FunctionType( ast::VariableArgs ) ); 210 201 default: 211 assertf( false, 212 "Unhandled type variable kind: %d", typeVar->second.kind ); 202 assertf( false, "Unhandled type variable kind: %d", kind ); 213 203 throw; // Just in case the assert is removed, stop here. 214 204 } … … 253 243 } 254 244 245 } // namespace 246 255 247 const ast::Node * scrubTypeVarsBase( 256 const ast::Node * target, 257 ScrubMode mode, const TypeVarMap * typeVars ) { 248 const ast::Node * node, const TypeVarMap * typeVars, ScrubMode mode ) { 258 249 if ( ScrubMode::All == mode ) { 259 250 assert( nullptr == typeVars ); … … 262 253 } 263 254 ast::Pass<ScrubTypeVars> visitor( mode, typeVars ); 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 ); 255 return node->accept( visitor ); 284 256 } 285 257
Note:
See TracChangeset
for help on using the changeset viewer.