Ignore:
Timestamp:
Dec 16, 2020, 2:43:12 PM (3 years ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
53449a4
Parents:
13fece5
Message:

reimplement function type and eliminate deep copy

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.impl.hpp

    r13fece5 r3e5dd913  
    367367        }
    368368
    369 
    370         template< typename core_t >
    371         template< typename node_t >
    372         void ast::Pass< core_t >::mutate_forall( const node_t *& node ) {
    373                 if ( auto subs = __pass::forall::subs( core, 0 ) ) {
    374                         // tracking TypeDecl substitution, full clone
    375                         if ( node->forall.empty() ) return;
    376 
    377                         node_t * mut = __pass::mutate<core_t>( node );
    378                         mut->forall = subs->clone( node->forall, *this );
    379                         node = mut;
    380                 } else {
    381                         // not tracking TypeDecl substitution, just mutate
    382                         maybe_accept( node, &node_t::forall );
    383                 }
    384         }
    385369}
    386370
     
    504488                        __pass::symtab::addId( core, 0, func );
    505489                        VISIT(
    506                                 // parameter declarations are now directly here
     490                                // parameter declarations
    507491                                maybe_accept( node, &FunctionDecl::params );
    508492                                maybe_accept( node, &FunctionDecl::returns );
    509                                 // foralls are still in function type
    510                                 maybe_accept( node, &FunctionDecl::type );
     493                                // type params and assertions
     494                                maybe_accept( node, &FunctionDecl::type_params );
     495                                maybe_accept( node, &FunctionDecl::assertions );
    511496                                // First remember that we are now within a function.
    512497                                ValueGuard< bool > oldInFunction( inFunction );
     
    17581743
    17591744        VISIT({
    1760                 guard_forall_subs forall_guard { *this, node };
    1761                 mutate_forall( node );
     1745                // guard_forall_subs forall_guard { *this, node };
     1746                // mutate_forall( node );
     1747                maybe_accept( node, &FunctionType::assertions );
    17621748                maybe_accept( node, &FunctionType::returns );
    17631749                maybe_accept( node, &FunctionType::params  );
     
    19811967                {
    19821968                        bool mutated = false;
    1983                         std::unordered_map< std::string, ast::ptr< ast::Type > > new_map;
     1969                        std::unordered_map< ast::TypeInstType::TypeEnvKey, ast::ptr< ast::Type > > new_map;
    19841970                        for ( const auto & p : node->typeEnv ) {
    19851971                                guard_symtab guard { *this };
     
    19941980                        }
    19951981                }
    1996 
    1997                 {
    1998                         bool mutated = false;
    1999                         std::unordered_map< std::string, ast::ptr< ast::Expr > > new_map;
    2000                         for ( const auto & p : node->varEnv ) {
    2001                                 guard_symtab guard { *this };
    2002                                 auto new_node = p.second->accept( *this );
    2003                                 if (new_node != p.second) mutated = true;
    2004                                 new_map.insert({ p.first, new_node });
    2005                         }
    2006                         if (mutated) {
    2007                                 auto new_node = __pass::mutate<core_t>( node );
    2008                                 new_node->varEnv.swap( new_map );
    2009                                 node = new_node;
    2010                         }
    2011                 }
    20121982        )
    20131983
Note: See TracChangeset for help on using the changeset viewer.