Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/ScrubTyVars.cc

    r2f61765 r0026d67  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Dec  7 17:01:00 2022
    13 // Update Count     : 6
     12// Last Modified On : Fri Oct  7 15:42:00 2022
     13// Update Count     : 5
    1414//
    1515
     
    117117namespace {
    118118
     119enum class ScrubMode {
     120        FromMap,
     121        DynamicFromMap,
     122        All,
     123};
     124
    119125struct ScrubTypeVars :
    120126        public ast::WithGuards,
     
    178184
    179185ast::Type const * ScrubTypeVars::postvisit( ast::TypeInstType const * type ) {
    180         ast::TypeDecl::Kind kind;
    181186        // This implies that mode == ScrubMode::All.
    182187        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:
    196205                return new ast::PointerType(
    197206                        new ast::VoidType( type->qualifiers ) );
    198         case ast::TypeDecl::Ftype:
     207        case ::TypeDecl::Ftype:
    199208                return new ast::PointerType(
    200209                        new ast::FunctionType( ast::VariableArgs ) );
    201210        default:
    202                 assertf( false, "Unhandled type variable kind: %d", kind );
     211                assertf( false,
     212                        "Unhandled type variable kind: %d", typeVar->second.kind );
    203213                throw; // Just in case the assert is removed, stop here.
    204214        }
     
    243253}
    244254
    245 } // namespace
    246 
    247255const ast::Node * scrubTypeVarsBase(
    248                 const ast::Node * node, const TypeVarMap * typeVars, ScrubMode mode ) {
     256                const ast::Node * target,
     257                ScrubMode mode, const TypeVarMap * typeVars ) {
    249258        if ( ScrubMode::All == mode ) {
    250259                assert( nullptr == typeVars );
     
    253262        }
    254263        ast::Pass<ScrubTypeVars> visitor( mode, typeVars );
    255         return node->accept( visitor );
     264        return target->accept( visitor );
     265}
     266
     267} // namespace
     268
     269template<>
     270ast::Node const * scrubTypeVars<ast::Node>(
     271        const ast::Node * target, const TypeVarMap & typeVars ) {
     272        return scrubTypeVarsBase( target, ScrubMode::FromMap, &typeVars );
     273}
     274
     275template<>
     276ast::Node const * scrubTypeVarsDynamic<ast::Node>(
     277        ast::Node const * target, const TypeVarMap & typeVars ) {
     278        return scrubTypeVarsBase( target, ScrubMode::DynamicFromMap, &typeVars );
     279}
     280
     281template<>
     282ast::Node const * scrubAllTypeVars<ast::Node>( const ast::Node * target ) {
     283        return scrubTypeVarsBase( target, ScrubMode::All, nullptr );
    256284}
    257285
Note: See TracChangeset for help on using the changeset viewer.