diff options
author | John Hodge <tpg@mutabah.net> | 2018-05-25 19:52:39 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2018-05-25 19:52:39 +0800 |
commit | c9475a45f05f73fc669d784c1ca48c720077af31 (patch) | |
tree | fcedef8d900479dd2b74f4ffdf5716845cc80582 /src/hir/type.hpp | |
parent | 704bb17db9a9610b409d729ac511976ea42514c5 (diff) | |
download | mrust-c9475a45f05f73fc669d784c1ca48c720077af31.tar.gz |
HIR - No more name in lifetime params
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; } }; |