Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Type.hpp

    rc9f6983 r361bf01  
    3636
    3737template< typename T > class Pass;
     38
     39struct ForallSubstitutor;
    3840
    3941class Type : public Node {
     
    270272/// Type of a function `[R1, R2](*)(P1, P2, P3)`
    271273class FunctionType final : public Type {
    272 public:
    273         using ForallList = std::vector<ptr<TypeInstType>>;
    274         using AssertionList = std::vector<ptr<VariableExpr>>;
     274        protected:
     275        /// initializes forall with substitutor
     276        void initWithSub( const FunctionType & o, Pass< ForallSubstitutor > & sub );
     277public:
     278        using ForallList = std::vector<ptr<TypeDecl>>;
    275279        ForallList forall;
    276         AssertionList assertions;
    277280
    278281        std::vector<ptr<Type>> returns;
     
    289292        : Type(q), returns(), params(), isVarArgs(va) {}
    290293
    291         FunctionType( const FunctionType & o ) = default;
     294        FunctionType( const FunctionType & o );
    292295
    293296        /// true if either the parameters or return values contain a tttype
     
    394397public:
    395398        readonly<TypeDecl> base;
    396         // previously from renameTyVars; now directly use integer fields instead of synthesized strings
    397         // a nonzero value of formal_usage indicates a formal type (only used in function type)
    398         // a zero value of formal_usage indicates an actual type (referenced inside body of parametric structs and functions)
    399399        TypeDecl::Kind kind;
    400         int formal_usage = 0;
    401         int expr_id = 0;
    402 
    403         // compact representation used for map lookups.
    404         struct TypeEnvKey {
    405                 const TypeDecl * base;
    406                 int formal_usage;
    407                 int expr_id;
    408 
    409                 TypeEnvKey() = default;
    410                 TypeEnvKey(const TypeDecl * base, int formal_usage = 0, int expr_id = 0): base(base), formal_usage(formal_usage), expr_id(expr_id) {}
    411                 TypeEnvKey(const TypeInstType & inst): base(inst.base), formal_usage(inst.formal_usage), expr_id(inst.expr_id) {}
    412                 std::string typeString() const { return std::string("_") + std::to_string(formal_usage) + "_" + std::to_string(expr_id) + "_" + base->name; }
    413                 bool operator==(const TypeEnvKey & other) const { return base == other.base && formal_usage == other.formal_usage && expr_id == other.expr_id; }
    414 
    415         };
    416 
    417         bool operator==(const TypeInstType & other) const { return base == other.base && formal_usage == other.formal_usage && expr_id == other.expr_id; }
    418400
    419401        TypeInstType(
     
    427409        TypeInstType( const TypeInstType & o ) = default;
    428410
    429         TypeInstType( const TypeEnvKey & key )
    430         : BaseInstType(key.base->name), base(key.base), kind(key.base->kind), formal_usage(key.formal_usage), expr_id(key.expr_id) {}
    431 
    432411        /// sets `base`, updating `kind` correctly
    433412        void set_base( const TypeDecl * );
     
    439418
    440419        const Type * accept( Visitor & v ) const override { return v.visit( this ); }
    441 
    442         std::string typeString() const {
    443                 if (formal_usage > 0) return std::string("_") + std::to_string(formal_usage) + "_" + std::to_string(expr_id) + "_" + name;
    444                 else return name;
    445         }
    446420private:
    447421        TypeInstType * clone() const override { return new TypeInstType{ *this }; }
     
    536510
    537511bool isUnboundType(const Type * type);
    538 
    539 }
    540 
    541 namespace std {
    542         template<>
    543         struct hash<typename ast::TypeInstType::TypeEnvKey> {
    544                 size_t operator() (const ast::TypeInstType::TypeEnvKey & x) const {
    545                         const size_t p = 1000007;
    546                         size_t res = reinterpret_cast<size_t>(x.base);
    547                         res = p * res + x.formal_usage;
    548                         res = p * res + x.expr_id;
    549                         return res;
    550                 }
    551         };
     512bool isUnboundType(const std::string & tname);
     513
    552514}
    553515
Note: See TracChangeset for help on using the changeset viewer.