Changeset 41cde266 for src/AST/Type.hpp


Ignore:
Timestamp:
Dec 17, 2020, 4:18:23 PM (10 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
089b1a9, f4f79dd
Parents:
c5a98f3 (diff), 68a867ee (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Type.hpp

    rc5a98f3 r41cde266  
    3636
    3737template< typename T > class Pass;
    38 
    39 struct ForallSubstitutor;
    4038
    4139class Type : public Node {
     
    272270/// Type of a function `[R1, R2](*)(P1, P2, P3)`
    273271class FunctionType final : public Type {
    274         protected:
    275         /// initializes forall with substitutor
    276         void initWithSub( const FunctionType & o, Pass< ForallSubstitutor > & sub );
    277 public:
    278         using ForallList = std::vector<ptr<TypeDecl>>;
     272public:
     273        using ForallList = std::vector<ptr<TypeInstType>>;
     274        using AssertionList = std::vector<ptr<VariableExpr>>;
    279275        ForallList forall;
     276        AssertionList assertions;
    280277
    281278        std::vector<ptr<Type>> returns;
     
    292289        : Type(q), returns(), params(), isVarArgs(va) {}
    293290
    294         FunctionType( const FunctionType & o );
     291        FunctionType( const FunctionType & o ) = default;
    295292
    296293        /// true if either the parameters or return values contain a tttype
     
    397394public:
    398395        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; }
    400418
    401419        TypeInstType(
     
    409427        TypeInstType( const TypeInstType & o ) = default;
    410428
     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
    411432        /// sets `base`, updating `kind` correctly
    412433        void set_base( const TypeDecl * );
     
    418439
    419440        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        }
    420446private:
    421447        TypeInstType * clone() const override { return new TypeInstType{ *this }; }
     
    510536
    511537bool isUnboundType(const Type * type);
    512 bool isUnboundType(const std::string & tname);
    513 
     538
     539}
     540
     541namespace 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        };
    514552}
    515553
Note: See TracChangeset for help on using the changeset viewer.