Changeset e0e9a0b for src/ResolvExpr


Ignore:
Timestamp:
Jun 27, 2019, 5:16:54 PM (5 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
7d0881c
Parents:
6be3b7d6
Message:

Somewhat deeper clone for types with forall qualifiers.

Location:
src/ResolvExpr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r6be3b7d6 re0e9a0b  
    548548                genStart = genEnd;
    549549
    550                 return genEnd != results.size();
     550                return genEnd != results.size();  // were any new results added?
    551551        }
    552552
     
    677677                        ast::TypeEnvironment funcEnv{ func->env };
    678678                        makeUnifiableVars( funcType, funcOpen, funcNeed );
    679                         // add all type variables as open variables now so that those not used in the parameter
    680                         // list are still considered open
     679                        // add all type variables as open variables now so that those not used in the
     680                        // parameter list are still considered open
    681681                        funcEnv.add( funcType->forall );
    682682
  • src/ResolvExpr/RenameVars.cc

    r6be3b7d6 re0e9a0b  
    1919#include <utility>                 // for pair
    2020
     21#include "AST/ForallSubstitutionTable.hpp"
    2122#include "AST/Pass.hpp"
    2223#include "AST/Type.hpp"
     
    3738                int resetCount = 0;
    3839                ScopedMap< std::string, std::string > nameMap;
     40        public:
     41                ast::ForallSubstitutionTable subs;
    3942
    40         public:
    4143                void reset() {
    4244                        level = 0;
     
    4446                }
    4547
    46                 using mapConstIterator = ScopedMap< std::string, std::string >::const_iterator;
    47 
    4848                void rename( TypeInstType * type ) {
    49                         mapConstIterator it = nameMap.find( type->name );
     49                        auto it = nameMap.find( type->name );
    5050                        if ( it != nameMap.end() ) {
    5151                                type->name = it->second;
     
    6565                                        // ditto for assertion names, the next level in
    6666                                        level++;
    67                                         // acceptAll( td->assertions, *this );
    68                                 } // for
    69                         } // if
     67                                }
     68                        }
    7069                }
    7170
     
    7776
    7877                const ast::TypeInstType * rename( const ast::TypeInstType * type ) {
    79                         mapConstIterator it = nameMap.find( type->name );
     78                        // re-linking of base type handled by WithForallSubstitutor
     79
     80                        // rename
     81                        auto it = nameMap.find( type->name );
    8082                        if ( it != nameMap.end() ) {
    81                                 ast::TypeInstType * mutType = ast::mutate( type );
    82                                 mutType->name = it->second;
    83                     type = mutType;
     83                                // unconditionally mutate because map will *always* have different name,
     84                                // if this mutates, will *always* have been mutated by ForallSubstitutor above
     85                                ast::TypeInstType * mut = ast::mutate( type );
     86                                mut->name = it->second;
     87                    type = mut;
    8488                        }
     89
    8590                        return type;
    8691                }
     
    8893                template<typename NodeT>
    8994                const NodeT * openLevel( const NodeT * type ) {
    90                         if ( !type->forall.empty() ) {
    91                                 nameMap.beginScope();
    92                                 // Load new names from this forall clause and perform renaming.
    93                                 NodeT * mutType = ast::mutate( type );
    94                                 for ( ast::ptr< ast::TypeDecl > & td : mutType->forall ) {
    95                                         std::ostringstream output;
    96                                         output << "_" << resetCount << "_" << level << "_" << td->name;
    97                                         std::string newname( output.str() );
    98                                         nameMap[ td->name ] = newname;
    99                                         ++level;
     95                        if ( type->forall.empty() ) return type;
     96                       
     97                        nameMap.beginScope();
    10098
    101                                         ast::TypeDecl * decl = ast::mutate( td.get() );
    102                                         decl->name = newname;
    103                                         td = decl;
    104                                 }
     99                        // Load new names from this forall clause and perform renaming.
     100                        NodeT * mutType = ast::mutate( type );
     101                        assert( type == mutType && "mutated type must be unique from ForallSubstitutor" );
     102                        for ( ast::ptr< ast::TypeDecl > & td : mutType->forall ) {
     103                                std::ostringstream output;
     104                                output << "_" << resetCount << "_" << level << "_" << td->name;
     105                                std::string newname =  output.str();
     106                                nameMap[ td->name ] = newname;
     107                                ++level;
     108
     109                                ast::TypeDecl * mutDecl = ast::mutate( td.get() );
     110                                assert( td == mutDecl && "mutated decl must be unique from ForallSubstitutor" );
     111                                mutDecl->name = newname;
     112                                // assertion above means `td = mutDecl;` is unnecessary
    105113                        }
     114                        // assertion above means `type = mutType;` is unnecessary
     115
    106116                        return type;
    107117                }
    108118
    109                 template<typename NodeT>
    110                 const NodeT * closeLevel( const NodeT * type ) {
    111                         if ( !type->forall.empty() ) {
    112                                 nameMap.endScope();
    113                         }
    114                         return type;
     119                void closeLevel( const ast::ParameterizedType * type ) {
     120                        if ( type->forall.empty() ) return;
     121                       
     122                        nameMap.endScope();
    115123                }
    116124        };
     
    119127        RenamingData renaming;
    120128
    121         struct RenameVars {
     129        struct RenameVars_old {
    122130                void previsit( TypeInstType * instType ) {
    123131                        renaming.openLevel( (Type*)instType );
     
    130138                        renaming.closeLevel( type );
    131139                }
     140        };
     141       
     142        struct RenameVars_new /*: public ast::WithForallSubstitutor*/ {
     143                #warning when old RenameVars goes away, replace hack below with global pass inheriting from WithForallSubstitutor
     144                ast::ForallSubstitutionTable & subs = renaming.subs;
    132145
    133146                const ast::FunctionType * previsit( const ast::FunctionType * type ) {
     
    146159                        return renaming.rename( renaming.openLevel( type ) );
    147160                }
    148                 const ast::ParameterizedType * postvisit( const ast::ParameterizedType * type ) {
    149                         return renaming.closeLevel( type );
     161                void postvisit( const ast::ParameterizedType * type ) {
     162                        renaming.closeLevel( type );
    150163                }
    151164        };
     
    154167
    155168void renameTyVars( Type * t ) {
    156         PassVisitor<RenameVars> renamer;
     169        PassVisitor<RenameVars_old> renamer;
    157170        t->accept( renamer );
    158171}
    159172
    160173const ast::Type * renameTyVars( const ast::Type * t ) {
    161         ast::Pass<RenameVars> renamer;
     174        ast::Pass<RenameVars_new> renamer;
    162175        return t->accept( renamer );
    163176}
Note: See TracChangeset for help on using the changeset viewer.