Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/RenameVars.cc

    rc6b4432 rf76dd1a  
    2121#include "AST/Pass.hpp"
    2222#include "AST/Type.hpp"
     23#include "Common/PassVisitor.h"
    2324#include "Common/ScopedMap.h"
    2425#include "Common/SemanticError.h"  // for SemanticError
    2526#include "RenameVars.h"
     27#include "SynTree/Declaration.h"   // for DeclarationWithType, TypeDecl, Dec...
     28#include "SynTree/Expression.h"    // for Expression
     29#include "SynTree/Type.h"          // for Type, TypeInstType, TraitInstType
     30#include "SynTree/Visitor.h"       // for acceptAll, maybeAccept
    2631
    2732#include "AST/Copy.hpp"
     
    4449                }
    4550
     51                void rename( TypeInstType * type ) {
     52                        auto it = nameMap.find( type->name );
     53                        if ( it != nameMap.end() ) {
     54                                type->name = it->second;
     55                        }
     56                }
     57
    4658                void nextUsage() {
    4759                        ++next_usage_id;
     60                }
     61
     62                void openLevel( Type * type ) {
     63                        if ( ! type->forall.empty() ) {
     64                                nameMap.beginScope();
     65                                // renames all "forall" type names to `_${level}_${name}'
     66                                for ( auto td : type->forall ) {
     67                                        std::ostringstream output;
     68                                        output << "_" << resetCount << "_" << level << "_" << td->name;
     69                                        std::string newname( output.str() );
     70                                        nameMap[ td->get_name() ] = newname;
     71                                        td->name = newname;
     72                                        // ditto for assertion names, the next level in
     73                                        level++;
     74                                }
     75                        }
     76                }
     77
     78                void closeLevel( Type * type ) {
     79                        if ( !type->forall.empty() ) {
     80                                nameMap.endScope();
     81                        }
    4882                }
    4983
     
    101135        RenamingData renaming;
    102136
     137        struct RenameVars_old {
     138                void previsit( TypeInstType * instType ) {
     139                        renaming.openLevel( (Type*)instType );
     140                        renaming.rename( instType );
     141                }
     142                void previsit( Type * type ) {
     143                        renaming.openLevel( type );
     144                }
     145                void postvisit( Type * type ) {
     146                        renaming.closeLevel( type );
     147                }
     148        };
     149
    103150        struct RenameVars_new : public ast::PureVisitor /*: public ast::WithForallSubstitutor*/ {
    104151                RenameMode mode;
     
    130177
    131178} // namespace
     179
     180void renameTyVars( Type * t ) {
     181        PassVisitor<RenameVars_old> renamer;
     182        t->accept( renamer );
     183}
    132184
    133185const ast::Type * renameTyVars( const ast::Type * t, RenameMode mode, bool reset ) {
Note: See TracChangeset for help on using the changeset viewer.