10 #ifndef LLVM_ADT_TWINE_H 11 #define LLVM_ADT_TWINE_H 22 class formatv_object_base;
83 enum NodeKind :
unsigned char {
141 const std::string *stdString;
148 const unsigned long *decUL;
150 const unsigned long long *decULL;
151 const long long *decLL;
152 const uint64_t *uHex;
164 NodeKind LHSKind = EmptyKind;
167 NodeKind RHSKind = EmptyKind;
170 explicit Twine(NodeKind
Kind) : LHSKind(Kind) {
171 assert(isNullary() &&
"Invalid kind!");
176 : LHSKind(TwineKind), RHSKind(TwineKind) {
177 this->LHS.twine = &LHS;
178 this->RHS.twine = &RHS;
179 assert(isValid() &&
"Invalid twine!");
183 explicit Twine(Child LHS, NodeKind LHSKind, Child RHS, NodeKind RHSKind)
184 : LHS(LHS), RHS(RHS), LHSKind(LHSKind), RHSKind(RHSKind) {
185 assert(isValid() &&
"Invalid twine!");
189 bool isNull()
const {
190 return getLHSKind() == NullKind;
194 bool isEmpty()
const {
195 return getLHSKind() == EmptyKind;
199 bool isNullary()
const {
200 return isNull() || isEmpty();
204 bool isUnary()
const {
205 return getRHSKind() == EmptyKind && !isNullary();
209 bool isBinary()
const {
210 return getLHSKind() != NullKind && getRHSKind() != EmptyKind;
215 bool isValid()
const {
217 if (isNullary() && getRHSKind() != EmptyKind)
221 if (getRHSKind() == NullKind)
225 if (getRHSKind() != EmptyKind && getLHSKind() == EmptyKind)
229 if (getLHSKind() == TwineKind &&
230 !LHS.twine->isBinary())
232 if (getRHSKind() == TwineKind &&
233 !RHS.twine->isBinary())
240 NodeKind getLHSKind()
const {
return LHSKind; }
243 NodeKind getRHSKind()
const {
return RHSKind; }
246 void printOneChild(
raw_ostream &OS, Child Ptr, NodeKind Kind)
const;
250 NodeKind Kind)
const;
258 assert(isValid() &&
"Invalid twine!");
269 if (Str[0] !=
'\0') {
271 LHSKind = CStringKind;
275 assert(isValid() &&
"Invalid twine!");
279 Twine(
const std::string &Str) : LHSKind(StdStringKind) {
280 LHS.stdString = &Str;
281 assert(isValid() &&
"Invalid twine!");
286 LHS.stringRef = &Str;
287 assert(isValid() &&
"Invalid twine!");
292 : LHSKind(SmallStringKind) {
293 LHS.smallString = &Str;
294 assert(isValid() &&
"Invalid twine!");
299 : LHSKind(FormatvObjectKind) {
300 LHS.formatvObject = &Fmt;
301 assert(isValid() &&
"Invalid twine!");
305 explicit Twine(
char Val) : LHSKind(CharKind) {
310 explicit Twine(
signed char Val) : LHSKind(CharKind) {
311 LHS.character =
static_cast<char>(Val);
315 explicit Twine(
unsigned char Val) : LHSKind(CharKind) {
316 LHS.character =
static_cast<char>(Val);
320 explicit Twine(
unsigned Val) : LHSKind(DecUIKind) {
325 explicit Twine(
int Val) : LHSKind(DecIKind) {
330 explicit Twine(
const unsigned long &Val) : LHSKind(DecULKind) {
335 explicit Twine(
const long &Val) : LHSKind(DecLKind) {
340 explicit Twine(
const unsigned long long &Val) : LHSKind(DecULLKind) {
345 explicit Twine(
const long long &Val) : LHSKind(DecLLKind) {
356 : LHSKind(CStringKind), RHSKind(StringRefKind) {
357 this->LHS.cString = LHS;
358 this->RHS.stringRef = &RHS;
359 assert(isValid() &&
"Invalid twine!");
364 : LHSKind(StringRefKind), RHSKind(CStringKind) {
365 this->LHS.stringRef = &LHS;
366 this->RHS.cString = RHS;
367 assert(isValid() &&
"Invalid twine!");
377 return Twine(NullKind);
389 return Twine(LHS, UHexKind, RHS, EmptyKind);
405 if (getRHSKind() != EmptyKind)
return false;
407 switch (getLHSKind()) {
412 case SmallStringKind:
430 std::string
str()
const;
439 switch (getLHSKind()) {
442 case CStringKind:
return StringRef(LHS.cString);
443 case StdStringKind:
return StringRef(*LHS.stdString);
444 case StringRefKind:
return *LHS.stringRef;
445 case SmallStringKind:
446 return StringRef(LHS.smallString->data(), LHS.smallString->size());
488 if (isNull() || Suffix.isNull())
489 return Twine(NullKind);
494 if (Suffix.isEmpty())
499 Child NewLHS, NewRHS;
501 NewRHS.twine = &Suffix;
502 NodeKind NewLHSKind = TwineKind, NewRHSKind = TwineKind;
505 NewLHSKind = getLHSKind();
507 if (Suffix.isUnary()) {
509 NewRHSKind = Suffix.getLHSKind();
512 return Twine(NewLHS, NewLHSKind, NewRHS, NewRHSKind);
523 return Twine(LHS, RHS);
530 return Twine(LHS, RHS);
542 #endif // LLVM_ADT_TWINE_H Twine(signed char Val)
Construct from a signed char.
Twine(const char *Str)
Construct from a C string.
Twine(const formatv_object_base &Fmt)
Construct from a formatv_object_base.
APInt operator+(APInt a, const APInt &b)
Twine(const unsigned long long &Val)
Construct a twine to print Val as an unsigned decimal integer.
This class represents lattice values for constants.
Twine(const StringRef &LHS, const char *RHS)
Construct as the concatenation of a StringRef and a C string.
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Twine(const SmallVectorImpl< char > &Str)
Construct from a SmallString.
Twine & operator=(const Twine &)=delete
Since the intended use of twines is as temporary objects, assignments when concatenating might cause ...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void dumpRepr() const
Dump the representation of this twine to stderr.
StringRef getSingleStringRef() const
This returns the twine as a single StringRef.
bool isSingleStringRef() const
Return true if this twine can be dynamically accessed as a single StringRef value with getSingleStrin...
void dump() const
Dump the concatenated string represented by this twine to stderr.
Twine(char Val)
Construct from a char.
Twine()
Construct from an empty string.
Twine(const long long &Val)
Construct a twine to print Val as a signed decimal integer.
static Twine createNull()
Create a 'null' string, which is an empty string that always concatenates to form another empty strin...
Twine(const StringRef &Str)
Construct from a StringRef.
StringRef toNullTerminatedStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single null terminated StringRef if it can be represented as such...
void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Twine(unsigned char Val)
Construct from an unsigned char.
static Twine utohexstr(const uint64_t &Val)
Twine(const std::string &Str)
Construct from an std::string.
Twine(int Val)
Construct a twine to print Val as a signed decimal integer.
Twine(unsigned Val)
Construct a twine to print Val as an unsigned decimal integer.
pointer data()
Return a pointer to the vector's buffer, even if empty().
Twine(const long &Val)
Construct a twine to print Val as a signed decimal integer.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
std::string str() const
Return the twine contents as a std::string.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Twine(const char *LHS, const StringRef &RHS)
Construct as the concatenation of a C string and a StringRef.
void printRepr(raw_ostream &OS) const
Write the representation of this twine to the stream OS.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
Twine(const unsigned long &Val)
Construct a twine to print Val as an unsigned decimal integer.
Twine concat(const Twine &Suffix) const
void print(raw_ostream &OS) const
Write the concatenated string represented by this twine to the stream OS.