Ignore:
Timestamp:
Jun 12, 2023, 2:45:32 PM (2 years ago)
Author:
Fangren Yu <f37yu@…>
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.
Message:

Merge branch 'master' into ast-experimental

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/ScrubTyVars.cc

    r34b4268 r24d6572  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Oct  7 15:42:00 2022
    13 // Update Count     : 5
     12// Last Modified On : Wed Dec  7 17:01:00 2022
     13// Update Count     : 6
    1414//
    1515
     
    117117namespace {
    118118
    119 enum class ScrubMode {
    120         FromMap,
    121         DynamicFromMap,
    122         All,
    123 };
    124 
    125119struct ScrubTypeVars :
    126120        public ast::WithGuards,
     
    184178
    185179ast::Type const * ScrubTypeVars::postvisit( ast::TypeInstType const * type ) {
     180        ast::TypeDecl::Kind kind;
    186181        // This implies that mode == ScrubMode::All.
    187182        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:
    205196                return new ast::PointerType(
    206197                        new ast::VoidType( type->qualifiers ) );
    207         case ::TypeDecl::Ftype:
     198        case ast::TypeDecl::Ftype:
    208199                return new ast::PointerType(
    209200                        new ast::FunctionType( ast::VariableArgs ) );
    210201        default:
    211                 assertf( false,
    212                         "Unhandled type variable kind: %d", typeVar->second.kind );
     202                assertf( false, "Unhandled type variable kind: %d", kind );
    213203                throw; // Just in case the assert is removed, stop here.
    214204        }
     
    253243}
    254244
     245} // namespace
     246
    255247const ast::Node * scrubTypeVarsBase(
    256                 const ast::Node * target,
    257                 ScrubMode mode, const TypeVarMap * typeVars ) {
     248                const ast::Node * node, const TypeVarMap * typeVars, ScrubMode mode ) {
    258249        if ( ScrubMode::All == mode ) {
    259250                assert( nullptr == typeVars );
     
    262253        }
    263254        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 );
    284256}
    285257
Note: See TracChangeset for help on using the changeset viewer.