diff options
Diffstat (limited to 'src/hir/type.hpp')
-rw-r--r-- | src/hir/type.hpp | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/src/hir/type.hpp b/src/hir/type.hpp index 652abfa8..480b32c4 100644 --- a/src/hir/type.hpp +++ b/src/hir/type.hpp @@ -84,11 +84,47 @@ extern ::std::ostream& operator<<(::std::ostream& os, const BorrowType& bt); struct LifetimeRef { - // Can either reference a named parameter, or an inferred region - ::std::string name; + static const uint32_t UNKNOWN = 0; + static const uint32_t STATIC = 0xFFFF; + + // Values below 2^16 are parameters/static, values above are per-function region IDs allocated during region inferrence. + uint32_t binding = UNKNOWN; + + static LifetimeRef new_static() { + LifetimeRef rv; + rv.binding = STATIC; + return rv; + } bool operator==(const LifetimeRef& x) const { - return name == x.name; + return binding == x.binding; + } + bool operator!=(const LifetimeRef& x) const { + return !(*this == x); + } + friend ::std::ostream& operator<<(::std::ostream& os, const LifetimeRef& x) { + if( x.binding == UNKNOWN ) + { + os << "'_"; + } + else if( x.binding == STATIC ) + { + os << "'static"; + } + else if( x.binding < 0xFFFF ) + { + switch( x.binding & 0xFF00 ) + { + case 0: os << "'I" << (x.binding & 0xFF); break; + case 1: os << "'M" << (x.binding & 0xFF); break; + default: os << "'unk" << x.binding; break; + } + } + else + { + os << "'_" << (x.binding - 0x1000); + } + return os; } }; |