LLVM: include/llvm/ADT/StringTable.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9#ifndef LLVM_ADT_STRING_TABLE_H
10#define LLVM_ADT_STRING_TABLE_H
11
14#include
15#include
16#include
17
18namespace llvm {
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
36
37public:
38
39
40
41
42
43
44
45
46
47
48
50
51 unsigned Value = 0;
52
53 public:
55 constexpr Offset(unsigned Value) : Value(Value) {}
56
58 return LHS.Value == RHS.Value;
59 }
60
62 return LHS.Value != RHS.Value;
63 }
64
65 constexpr unsigned value() const { return Value; }
66 };
67
68
69
70
71
72 template <size_t N>
73 constexpr StringTable(const char (&RawTable)[N]) : Table(RawTable, N) {
74 static_assert(N <= std::numeric_limits::max(),
75 "We only support table sizes that can be indexed by an "
76 "`unsigned` offset.");
77
78
79
80 assert(!Table.empty() && "Requires at least a valid empty string.");
81 assert(Table.data()[0] == '\0' && "Offset zero must be the empty string.");
82
83
84
85 assert(Table.data()[Table.size() - 1] == '\0' &&
86 "Last byte must be a null byte.");
87 }
88
89
90
92 assert(O.value() < Table.size() && "Out of bounds offset!");
93 return Table.data() + O.value();
94 }
95
96
97
98
100
101
102 constexpr size_t size() const { return Table.size(); }
103
104 class Iterator
106 const StringRef> {
107 friend StringTable;
108
109 const StringTable *Table;
111
112
114
115 explicit constexpr Iterator(const StringTable &Table, Offset O)
116 : Table(&Table), O(O) {}
117
118 public:
121
122 constexpr Iterator &operator=(const Iterator &RHS) = default;
124
126 assert(Table == RHS.Table && "Compared iterators for unrelated tables!");
127 return O == RHS.O;
128 }
129
131 S = (*Table)[O];
132 return S;
133 }
134
136 O = O.value() + (*Table)[O].size() + 1;
137 return *this;
138 }
139
141 };
142
145};
146
147}
148
149#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
StringRef - Represent a constant reference to a string, i.e.
Definition StringTable.h:106
bool operator==(const Iterator &RHS) const
Definition StringTable.h:125
Iterator & operator++()
Definition StringTable.h:135
const StringRef & operator*() const
Definition StringTable.h:130
constexpr Iterator & operator=(const Iterator &RHS)=default
constexpr Iterator(Iterator &&RHS)=default
constexpr Iterator & operator=(Iterator &&RHS)=default
constexpr Iterator(const Iterator &RHS)=default
Offset offset() const
Definition StringTable.h:140
Definition StringTable.h:49
constexpr Offset(unsigned Value)
Definition StringTable.h:55
constexpr unsigned value() const
Definition StringTable.h:65
friend constexpr bool operator==(const Offset &LHS, const Offset &RHS)
Definition StringTable.h:57
friend constexpr bool operator!=(const Offset &LHS, const Offset &RHS)
Definition StringTable.h:61
constexpr Offset()=default
constexpr size_t size() const
Returns the byte size of the table.
Definition StringTable.h:102
constexpr StringRef operator[](Offset O) const
Definition StringTable.h:99
constexpr Iterator begin() const
Definition StringTable.h:143
constexpr Iterator end() const
Definition StringTable.h:144
constexpr const char * getCString(Offset O) const
Definition StringTable.h:91
constexpr StringTable(const char(&RawTable)[N])
Definition StringTable.h:73
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
This is an optimization pass for GlobalISel generic memory operations.