Changeset eb5962a for src/AST


Ignore:
Timestamp:
Jun 21, 2022, 1:39:24 PM (23 months ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
b62d1d6
Parents:
1df492a (diff), 1dbbef6 (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/AST
Files:
3 edited

Legend:

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

    r1df492a reb5962a  
    182182
    183183                // get the stmts/decls that will need to be spliced in
    184                 auto stmts_before = __pass::stmtsToAddBefore( core, 0);
    185                 auto stmts_after  = __pass::stmtsToAddAfter ( core, 0);
    186                 auto decls_before = __pass::declsToAddBefore( core, 0);
    187                 auto decls_after  = __pass::declsToAddAfter ( core, 0);
     184                auto stmts_before = __pass::stmtsToAddBefore( core, 0 );
     185                auto stmts_after  = __pass::stmtsToAddAfter ( core, 0 );
     186                auto decls_before = __pass::declsToAddBefore( core, 0 );
     187                auto decls_after  = __pass::declsToAddAfter ( core, 0 );
    188188
    189189                // These may be modified by subnode but most be restored once we exit this statemnet.
     
    287287
    288288                // get the stmts/decls that will need to be spliced in
    289                 auto stmts_before = __pass::stmtsToAddBefore( core, 0);
    290                 auto stmts_after  = __pass::stmtsToAddAfter ( core, 0);
    291                 auto decls_before = __pass::declsToAddBefore( core, 0);
    292                 auto decls_after  = __pass::declsToAddAfter ( core, 0);
     289                auto stmts_before = __pass::stmtsToAddBefore( core, 0 );
     290                auto stmts_after  = __pass::stmtsToAddAfter ( core, 0 );
     291                auto decls_before = __pass::declsToAddBefore( core, 0 );
     292                auto decls_after  = __pass::declsToAddAfter ( core, 0 );
    293293
    294294                // These may be modified by subnode but most be restored once we exit this statemnet.
     
    317317                                assert(( empty( stmts_before ) && empty( stmts_after ))
    318318                                    || ( empty( decls_before ) && empty( decls_after )) );
    319 
    320 
    321319
    322320                                // Take all the statements which should have gone after, N/A for first iteration
     
    21162114        if ( __visit_children() ) {
    21172115                bool mutated = false;
    2118                 std::unordered_map< ast::TypeInstType::TypeEnvKey, ast::ptr< ast::Type > > new_map;
    2119                 for ( const auto & p : node->typeEnv ) {
     2116                ast::TypeSubstitution::TypeMap new_map;
     2117                for ( const auto & p : node->typeMap ) {
    21202118                        guard_symtab guard { *this };
    21212119                        auto new_node = p.second->accept( *this );
     
    21252123                if (mutated) {
    21262124                        auto new_node = __pass::mutate<core_t>( node );
    2127                         new_node->typeEnv.swap( new_map );
     2125                        new_node->typeMap.swap( new_map );
    21282126                        node = new_node;
    21292127                }
  • src/AST/TypeSubstitution.cpp

    r1df492a reb5962a  
    3838
    3939void TypeSubstitution::initialize( const TypeSubstitution &src, TypeSubstitution &dest ) {
    40         dest.typeEnv.clear();
     40        dest.typeMap.clear();
    4141        dest.add( src );
    4242}
    4343
    4444void TypeSubstitution::add( const TypeSubstitution &other ) {
    45         for ( TypeEnvType::const_iterator i = other.typeEnv.begin(); i != other.typeEnv.end(); ++i ) {
    46                 typeEnv[ i->first ] = i->second;
     45        for ( TypeMap::const_iterator i = other.typeMap.begin(); i != other.typeMap.end(); ++i ) {
     46                typeMap[ i->first ] = i->second;
    4747        } // for
    4848}
    4949
    5050void TypeSubstitution::add( const TypeInstType * formalType, const Type *actualType ) {
    51         typeEnv[ *formalType ] = actualType;
     51        typeMap[ *formalType ] = actualType;
    5252}
    5353
    5454void TypeSubstitution::add( const TypeInstType::TypeEnvKey & key, const Type * actualType) {
    55         typeEnv[ key ] = actualType;
     55        typeMap[ key ] = actualType;
    5656}
    5757
    5858void TypeSubstitution::remove( const TypeInstType * formalType ) {
    59         TypeEnvType::iterator i = typeEnv.find( *formalType );
    60         if ( i != typeEnv.end() ) {
    61                 typeEnv.erase( *formalType );
    62         } // if
    63 }
    64 
    65 const Type *TypeSubstitution::lookup( const TypeInstType * formalType ) const {
    66         TypeEnvType::const_iterator i = typeEnv.find( *formalType );
     59        TypeMap::iterator i = typeMap.find( *formalType );
     60        if ( i != typeMap.end() ) {
     61                typeMap.erase( *formalType );
     62        } // if
     63}
     64
     65const Type *TypeSubstitution::lookup(
     66                const TypeInstType::TypeEnvKey & formalType ) const {
     67        TypeMap::const_iterator i = typeMap.find( formalType );
    6768
    6869        // break on not in substitution set
    69         if ( i == typeEnv.end() ) return 0;
     70        if ( i == typeMap.end() ) return 0;
    7071
    7172        // attempt to transitively follow TypeInstType links.
    7273        while ( const TypeInstType *actualType = i->second.as<TypeInstType>()) {
    7374                // break cycles in the transitive follow
    74                 if ( *formalType == *actualType ) break;
     75                if ( formalType == *actualType ) break;
    7576
    7677                // Look for the type this maps to, returning previous mapping if none-such
    77                 i = typeEnv.find( *actualType );
    78                 if ( i == typeEnv.end() ) return actualType;
     78                i = typeMap.find( *actualType );
     79                if ( i == typeMap.end() ) return actualType;
    7980        }
    8081
     
    8384}
    8485
     86const Type *TypeSubstitution::lookup( const TypeInstType * formalType ) const {
     87        return lookup( ast::TypeInstType::TypeEnvKey( *formalType ) );
     88}
     89
    8590bool TypeSubstitution::empty() const {
    86         return typeEnv.empty();
     91        return typeMap.empty();
    8792}
    8893
     
    119124                sub.core.subCount = 0;
    120125                sub.core.freeOnly = true;
    121                 for ( TypeEnvType::iterator i = typeEnv.begin(); i != typeEnv.end(); ++i ) {
     126                for ( TypeMap::iterator i = typeMap.begin(); i != typeMap.end(); ++i ) {
    122127                        i->second = i->second->accept( sub );
    123128                }
     
    129134        if ( bound != boundVars.end() ) return inst;
    130135
    131         TypeEnvType::const_iterator i = sub.typeEnv.find( *inst );
    132         if ( i == sub.typeEnv.end() ) {
     136        TypeMap::const_iterator i = sub.typeMap.find( *inst );
     137        if ( i == sub.typeMap.end() ) {
    133138                return inst;
    134139        } else {
  • src/AST/TypeSubstitution.hpp

    r1df492a reb5962a  
    7575        void add( const TypeSubstitution &other );
    7676        void remove( const TypeInstType * formalType );
     77        const Type *lookup( const TypeInstType::TypeEnvKey & formalType ) const;
    7778        const Type *lookup( const TypeInstType * formalType ) const;
    7879        bool empty() const;
     
    104105        friend class Pass;
    105106
    106         typedef std::unordered_map< TypeInstType::TypeEnvKey, ptr<Type> > TypeEnvType;
    107         TypeEnvType typeEnv;
     107        typedef std::unordered_map< TypeInstType::TypeEnvKey, ptr<Type> > TypeMap;
     108        TypeMap typeMap;
    108109
    109110  public:
    110         // has to come after declaration of typeEnv
    111         auto begin()       -> decltype( typeEnv.begin() ) { return typeEnv.begin(); }
    112         auto   end()       -> decltype( typeEnv.  end() ) { return typeEnv.  end(); }
    113         auto begin() const -> decltype( typeEnv.begin() ) { return typeEnv.begin(); }
    114         auto   end() const -> decltype( typeEnv.  end() ) { return typeEnv.  end(); }
     111        // has to come after declaration of typeMap
     112        auto begin()       -> decltype( typeMap.begin() ) { return typeMap.begin(); }
     113        auto   end()       -> decltype( typeMap.  end() ) { return typeMap.  end(); }
     114        auto begin() const -> decltype( typeMap.begin() ) { return typeMap.begin(); }
     115        auto   end() const -> decltype( typeMap.  end() ) { return typeMap.  end(); }
    115116
    116117};
     
    144145                        if ( const TypeExpr *actual = actualIt->template as<TypeExpr>() ) {
    145146                                if ( formal->name != "" ) {
    146                                         typeEnv[ formal ] = actual->type;
     147                                        typeMap[ formal ] = actual->type;
    147148                                } // if
    148149                        } else {
Note: See TracChangeset for help on using the changeset viewer.