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;
168 : LHSKind(Kind), RHSKind(EmptyKind) {
169 assert(isNullary() &&
"Invalid kind!");
174 : LHSKind(TwineKind), RHSKind(TwineKind) {
175 this->LHS.twine = &LHS;
176 this->RHS.twine = &RHS;
177 assert(isValid() &&
"Invalid twine!");
181 explicit Twine(Child LHS, NodeKind LHSKind, Child RHS, NodeKind RHSKind)
182 : LHS(LHS), RHS(RHS), LHSKind(LHSKind), RHSKind(RHSKind) {
183 assert(isValid() &&
"Invalid twine!");
187 bool isNull()
const {
188 return getLHSKind() == NullKind;
192 bool isEmpty()
const {
193 return getLHSKind() == EmptyKind;
197 bool isNullary()
const {
198 return isNull() || isEmpty();
202 bool isUnary()
const {
203 return getRHSKind() == EmptyKind && !isNullary();
207 bool isBinary()
const {
208 return getLHSKind() != NullKind && getRHSKind() != EmptyKind;
213 bool isValid()
const {
215 if (isNullary() && getRHSKind() != EmptyKind)
219 if (getRHSKind() == NullKind)
223 if (getRHSKind() != EmptyKind && getLHSKind() == EmptyKind)
227 if (getLHSKind() == TwineKind &&
228 !LHS.twine->isBinary())
230 if (getRHSKind() == TwineKind &&
231 !RHS.twine->isBinary())
238 NodeKind getLHSKind()
const {
return LHSKind; }
241 NodeKind getRHSKind()
const {
return RHSKind; }
244 void printOneChild(
raw_ostream &OS, Child
Ptr, NodeKind Kind)
const;
248 NodeKind Kind)
const;
255 Twine() : LHSKind(EmptyKind), RHSKind(EmptyKind) {
256 assert(isValid() &&
"Invalid twine!");
267 : RHSKind(EmptyKind) {
268 if (Str[0] !=
'\0') {
270 LHSKind = CStringKind;
274 assert(isValid() &&
"Invalid twine!");
279 : LHSKind(StdStringKind), RHSKind(EmptyKind) {
280 LHS.stdString = &Str;
281 assert(isValid() &&
"Invalid twine!");
286 : LHSKind(StringRefKind), RHSKind(EmptyKind) {
287 LHS.stringRef = &Str;
288 assert(isValid() &&
"Invalid twine!");
293 : LHSKind(SmallStringKind), RHSKind(EmptyKind) {
294 LHS.smallString = &Str;
295 assert(isValid() &&
"Invalid twine!");
300 : LHSKind(FormatvObjectKind), RHSKind(EmptyKind) {
301 LHS.formatvObject = &Fmt;
302 assert(isValid() &&
"Invalid twine!");
307 : LHSKind(CharKind), RHSKind(EmptyKind) {
313 : LHSKind(CharKind), RHSKind(EmptyKind) {
314 LHS.character =
static_cast<char>(Val);
319 : LHSKind(CharKind), RHSKind(EmptyKind) {
320 LHS.character =
static_cast<char>(Val);
325 : LHSKind(DecUIKind), RHSKind(EmptyKind) {
331 : LHSKind(DecIKind), RHSKind(EmptyKind) {
336 explicit Twine(
const unsigned long &Val)
337 : LHSKind(DecULKind), RHSKind(EmptyKind) {
343 : LHSKind(DecLKind), RHSKind(EmptyKind) {
348 explicit Twine(
const unsigned long long &Val)
349 : LHSKind(DecULLKind), RHSKind(EmptyKind) {
354 explicit Twine(
const long long &Val)
355 : LHSKind(DecLLKind), RHSKind(EmptyKind) {
366 : LHSKind(CStringKind), RHSKind(StringRefKind) {
367 this->LHS.cString = LHS;
368 this->RHS.stringRef = &RHS;
369 assert(isValid() &&
"Invalid twine!");
374 : LHSKind(StringRefKind), RHSKind(CStringKind) {
375 this->LHS.stringRef = &LHS;
376 this->RHS.cString = RHS;
377 assert(isValid() &&
"Invalid twine!");
387 return Twine(NullKind);
399 return Twine(LHS, UHexKind, RHS, EmptyKind);
415 if (getRHSKind() != EmptyKind)
return false;
417 switch (getLHSKind()) {
422 case SmallStringKind:
440 std::string
str()
const;
449 switch (getLHSKind()) {
452 case CStringKind:
return StringRef(LHS.cString);
453 case StdStringKind:
return StringRef(*LHS.stdString);
454 case StringRefKind:
return *LHS.stringRef;
455 case SmallStringKind:
456 return StringRef(LHS.smallString->data(), LHS.smallString->size());
498 if (isNull() || Suffix.isNull())
499 return Twine(NullKind);
504 if (Suffix.isEmpty())
509 Child NewLHS, NewRHS;
511 NewRHS.twine = &Suffix;
512 NodeKind NewLHSKind = TwineKind, NewRHSKind = TwineKind;
515 NewLHSKind = getLHSKind();
517 if (Suffix.isUnary()) {
519 NewRHSKind = Suffix.getLHSKind();
522 return Twine(NewLHS, NewLHSKind, NewRHS, NewRHSKind);
533 return Twine(LHS, RHS);
540 return Twine(LHS, RHS);
552 #endif // LLVM_ADT_TWINE_H
void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
Twine(signed char Val)
Construct from a signed char.
Twine(const char *Str)
Construct from a C string.
bool isSingleStringRef() const
Return true if this twine can be dynamically accessed as a single StringRef value with getSingleStrin...
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.
void dump() const
Dump the concatenated string represented by this twine to stderr.
Twine(const StringRef &LHS, const char *RHS)
Construct as the concatenation of a StringRef and a C string.
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 ...
void dumpRepr() const
Dump the representation of this twine to stderr.
std::string str() const
Return the twine contents as a std::string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
StringRef getSingleStringRef() const
This returns the twine as a single StringRef.
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.
void printRepr(raw_ostream &OS) const
Write the representation of this twine to the stream OS.
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.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Twine(unsigned char Val)
Construct from an unsigned char.
Twine concat(const Twine &Suffix) const
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
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().
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Twine(const long &Val)
Construct a twine to print Val as a signed decimal integer.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
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.
StringRef toNullTerminatedStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single null terminated StringRef if it can be represented as such...
void print(raw_ostream &OS) const
Write the concatenated string represented by this twine to the stream OS.
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
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.