Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/TypeSubstitution.hpp

    r3e5dd913 r361bf01  
    6969        }
    7070
    71         void add( const TypeInstType * formalType, const Type *actualType );
    72         void add( const TypeInstType::TypeEnvKey & key, const Type *actualType );
     71        void add( std::string formalType, const Type *actualType );
    7372        void add( const TypeSubstitution &other );
    74         void remove( const TypeInstType * formalType );
    75         const Type *lookup( const TypeInstType * formalType ) const;
     73        void remove( std::string formalType );
     74        const Type *lookup( std::string formalType ) const;
    7675        bool empty() const;
     76
     77        void addVar( std::string formalExpr, const Expr *actualExpr );
    7778
    7879        template< typename FormalIterator, typename ActualIterator >
     
    100101        friend class Pass;
    101102
    102         typedef std::unordered_map< TypeInstType::TypeEnvKey, ptr<Type> > TypeEnvType;
     103        typedef std::unordered_map< std::string, ptr<Type> > TypeEnvType;
     104        typedef std::unordered_map< std::string, ptr<Expr> > VarEnvType;
    103105        TypeEnvType typeEnv;
     106        VarEnvType varEnv;
    104107
    105108  public:
     
    110113        auto   end() const -> decltype( typeEnv.  end() ) { return typeEnv.  end(); }
    111114
     115        auto beginVar()       -> decltype( varEnv.begin() ) { return varEnv.begin(); }
     116        auto   endVar()       -> decltype( varEnv.  end() ) { return varEnv.  end(); }
     117        auto beginVar() const -> decltype( varEnv.begin() ) { return varEnv.begin(); }
     118        auto   endVar() const -> decltype( varEnv.  end() ) { return varEnv.  end(); }
    112119};
    113120
    114 // this is the only place where type parameters outside a function formal may be substituted.
    115121template< typename FormalIterator, typename ActualIterator >
    116122void TypeSubstitution::add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ) {
     
    123129                        if ( const TypeExpr *actual = actualIt->template as<TypeExpr>() ) {
    124130                                if ( formal->name != "" ) {
    125                                         typeEnv[ formal ] = actual->type;
     131                                        typeEnv[ formal->name ] = actual->type;
    126132                                } // if
    127133                        } else {
     
    129135                        } // if
    130136                } else {
    131                        
     137                        // TODO: type check the formal and actual parameters
     138                        if ( (*formalIt)->name != "" ) {
     139                                varEnv[ (*formalIt)->name ] = *actualIt;
     140                        } // if
    132141                } // if
    133142        } // for
    134143}
    135 
    136 
    137144
    138145template< typename FormalIterator, typename ActualIterator >
     
    140147        add( formalBegin, formalEnd, actualBegin );
    141148}
    142 
    143149
    144150} // namespace ast
     
    158164
    159165                const Type * postvisit( const TypeInstType * aggregateUseType );
     166                const Expr * postvisit( const NameExpr * nameExpr );
    160167
    161168                /// Records type variable bindings from forall-statements
    162169                void previsit( const FunctionType * type );
    163170                /// Records type variable bindings from forall-statements and instantiations of generic types
    164                 // void handleAggregateType( const BaseInstType * type );
    165 
    166                 // void previsit( const StructInstType * aggregateUseType );
    167                 // void previsit( const UnionInstType * aggregateUseType );
     171                void handleAggregateType( const BaseInstType * type );
     172
     173                void previsit( const StructInstType * aggregateUseType );
     174                void previsit( const UnionInstType * aggregateUseType );
    168175
    169176                const TypeSubstitution & sub;
    170177                int subCount = 0;
    171178                bool freeOnly;
    172                 typedef std::unordered_set< TypeInstType::TypeEnvKey > BoundVarsType;
     179                typedef std::unordered_set< std::string > BoundVarsType;
    173180                BoundVarsType boundVars;
    174181
Note: See TracChangeset for help on using the changeset viewer.