[PR testsuite/116860] Testsuite adjustment for recently added tests
[official-gcc.git] / gcc / rust / typecheck / rust-tyty-region.h
blobb34a2115e7a15bb01a6e6eeeb4a219a88c9bb508
1 #ifndef RUST_TYTY_REGION_H
2 #define RUST_TYTY_REGION_H
4 namespace Rust {
5 namespace TyTy {
7 class Region
9 enum Variant : uint8_t
11 UNRESOLVED,
12 STATIC,
13 EARLY_BOUND,
14 LATE_BOUND,
15 NAMED,
16 ANONYMOUS,
17 ERASED,
20 uint32_t index;
21 uint16_t debruijn_index;
22 Variant variant;
24 public:
25 Region () : Region (UNRESOLVED) {}
26 Region (const Region &other)
27 : index (other.index), debruijn_index (other.debruijn_index),
28 variant (other.variant)
30 Region (Region &&other) noexcept
31 : index (other.index), debruijn_index (other.debruijn_index),
32 variant (other.variant)
34 Region &operator= (const Region &other)
36 if (this == &other)
37 return *this;
38 index = other.index;
39 debruijn_index = other.debruijn_index;
40 variant = other.variant;
41 return *this;
43 Region &operator= (Region &&other) noexcept
45 if (this == &other)
46 return *this;
47 index = other.index;
48 debruijn_index = other.debruijn_index;
49 variant = other.variant;
50 return *this;
53 static Region make_static () { return Region (STATIC); }
54 static Region make_early_bound (uint32_t index)
56 return Region (EARLY_BOUND, index);
58 static Region make_late_bound (uint32_t index, uint16_t debruijn_index)
60 return Region (LATE_BOUND, index, debruijn_index);
62 static Region make_named (uint32_t index) { return Region (NAMED, index); }
63 static Region make_anonymous () { return Region (ANONYMOUS); }
64 static Region make_erased () { return Region (ERASED); }
66 size_t get_index () const { return index; }
68 bool is_static () const { return variant == STATIC; }
69 bool is_early_bound () const { return variant == EARLY_BOUND; }
70 bool is_late_bound () const { return variant == LATE_BOUND; }
71 bool is_named () const { return variant == NAMED; }
72 bool is_anonymous () const { return variant == ANONYMOUS; }
74 void shift_down () { debruijn_index++; }
76 WARN_UNUSED_RESULT std::string as_string () const
78 switch (variant)
80 case UNRESOLVED:
81 return "'unresolved";
82 case STATIC:
83 return "'static";
84 case EARLY_BOUND:
85 return "'early(" + std::to_string (index) + ")";
86 case LATE_BOUND:
87 return "'late(" + std::to_string (debruijn_index) + ", "
88 + std::to_string (index) + ")";
89 case NAMED:
90 return "'named(" + std::to_string (index) + "";
91 case ANONYMOUS:
92 return "'_";
93 case ERASED:
94 return "'erased";
97 rust_unreachable ();
100 private:
101 explicit Region (Variant variant, uint32_t index = 0,
102 uint16_t debruijn_index = 0)
103 : index (index), debruijn_index (debruijn_index), variant (variant)
107 } // namespace TyTy
108 } // namespace Rust
110 #endif // RUST_TYTY_REGION_H