Changes in src/AST/Type.hpp [c9f6983:361bf01]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Type.hpp
rc9f6983 r361bf01 36 36 37 37 template< typename T > class Pass; 38 39 struct ForallSubstitutor; 38 40 39 41 class Type : public Node { … … 270 272 /// Type of a function `[R1, R2](*)(P1, P2, P3)` 271 273 class 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 ); 277 public: 278 using ForallList = std::vector<ptr<TypeDecl>>; 275 279 ForallList forall; 276 AssertionList assertions;277 280 278 281 std::vector<ptr<Type>> returns; … … 289 292 : Type(q), returns(), params(), isVarArgs(va) {} 290 293 291 FunctionType( const FunctionType & o ) = default;294 FunctionType( const FunctionType & o ); 292 295 293 296 /// true if either the parameters or return values contain a tttype … … 394 397 public: 395 398 readonly<TypeDecl> base; 396 // previously from renameTyVars; now directly use integer fields instead of synthesized strings397 // 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)399 399 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; }418 400 419 401 TypeInstType( … … 427 409 TypeInstType( const TypeInstType & o ) = default; 428 410 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 432 411 /// sets `base`, updating `kind` correctly 433 412 void set_base( const TypeDecl * ); … … 439 418 440 419 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 }446 420 private: 447 421 TypeInstType * clone() const override { return new TypeInstType{ *this }; } … … 536 510 537 511 bool 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 }; 512 bool isUnboundType(const std::string & tname); 513 552 514 } 553 515
Note: See TracChangeset
for help on using the changeset viewer.