9#ifndef LLVM_ADT_TWINE_H
10#define LLVM_ADT_TWINE_H
84 enum NodeKind :
unsigned char {
141 const std::string *stdString;
152 unsigned long long decULL;
166 NodeKind LHSKind = EmptyKind;
169 NodeKind RHSKind = EmptyKind;
172 explicit Twine(NodeKind Kind) : LHSKind(Kind) {
173 assert(isNullary() &&
"Invalid kind!");
177 explicit Twine(
const Twine &LHS,
const Twine &RHS)
178 : LHSKind(TwineKind), RHSKind(TwineKind) {
179 this->LHS.twine = &LHS;
180 this->RHS.twine = &RHS;
181 assert(isValid() &&
"Invalid twine!");
185 explicit Twine(Child LHS, NodeKind LHSKind, Child RHS, NodeKind RHSKind)
186 :
LHS(LHS),
RHS(RHS), LHSKind(LHSKind), RHSKind(RHSKind) {
187 assert(isValid() &&
"Invalid twine!");
191 bool isNull()
const {
return getLHSKind() == NullKind; }
194 bool isEmpty()
const {
return getLHSKind() == EmptyKind; }
197 bool isNullary()
const {
return isNull() || isEmpty(); }
200 bool isUnary()
const {
return getRHSKind() == EmptyKind && !isNullary(); }
203 bool isBinary()
const {
204 return getLHSKind() != NullKind && getRHSKind() != EmptyKind;
209 bool isValid()
const {
211 if (isNullary() && getRHSKind() != EmptyKind)
215 if (getRHSKind() == NullKind)
219 if (getRHSKind() != EmptyKind && getLHSKind() == EmptyKind)
223 if (getLHSKind() == TwineKind && !LHS.twine->isBinary())
225 if (getRHSKind() == TwineKind && !RHS.twine->isBinary())
232 NodeKind getLHSKind()
const {
return LHSKind; }
235 NodeKind getRHSKind()
const {
return RHSKind; }
238 void printOneChild(
raw_ostream &OS, Child
Ptr, NodeKind Kind)
const;
241 void printOneChildRepr(
raw_ostream &OS, Child
Ptr, NodeKind Kind)
const;
258 if (Str[0] !=
'\0') {
260 LHSKind = CStringKind;
265 assert(isValid() &&
"Invalid twine!");
272 Twine(
const std::string &Str) : LHSKind(StdStringKind) {
273 LHS.stdString = &Str;
274 assert(isValid() &&
"Invalid twine!");
281 Twine(
const std::string_view &Str) : LHSKind(PtrAndLengthKind) {
282 LHS.ptrAndLength.ptr = Str.data();
283 LHS.ptrAndLength.length = Str.length();
284 assert(isValid() &&
"Invalid twine!");
289 LHS.ptrAndLength.ptr = Str.data();
290 LHS.ptrAndLength.length = Str.size();
291 assert(isValid() &&
"Invalid twine!");
296 LHS.ptrAndLength.ptr = Str.data();
297 LHS.ptrAndLength.length = Str.size();
298 assert(isValid() &&
"Invalid twine!");
303 : LHSKind(PtrAndLengthKind) {
304 LHS.ptrAndLength.ptr = Str.data();
305 LHS.ptrAndLength.length = Str.size();
306 assert(isValid() &&
"Invalid twine!");
311 : LHSKind(FormatvObjectKind) {
312 LHS.formatvObject = &Fmt;
313 assert(isValid() &&
"Invalid twine!");
317 explicit Twine(
char Val) : LHSKind(CharKind) { LHS.character = Val; }
320 explicit Twine(
signed char Val) : LHSKind(CharKind) {
321 LHS.character =
static_cast<char>(Val);
325 explicit Twine(
unsigned char Val) : LHSKind(CharKind) {
326 LHS.character =
static_cast<char>(Val);
330 explicit Twine(
unsigned Val) : LHSKind(DecUIKind) { LHS.decUI = Val; }
333 explicit Twine(
int Val) : LHSKind(DecIKind) { LHS.decI = Val; }
336 explicit Twine(
unsigned long Val) : LHSKind(DecULKind) { LHS.decUL = Val; }
339 explicit Twine(
long Val) : LHSKind(DecLKind) { LHS.decL = Val; }
342 explicit Twine(
unsigned long long Val) : LHSKind(DecULLKind) {
347 explicit Twine(
long long Val) : LHSKind(DecLLKind) { LHS.decLL = Val; }
356 : LHSKind(CStringKind), RHSKind(PtrAndLengthKind) {
357 this->LHS.cString = LHS;
358 this->RHS.ptrAndLength.ptr = RHS.
data();
359 this->RHS.ptrAndLength.length = RHS.
size();
360 assert(isValid() &&
"Invalid twine!");
365 : LHSKind(PtrAndLengthKind), RHSKind(CStringKind) {
366 this->LHS.ptrAndLength.ptr = LHS.
data();
367 this->LHS.ptrAndLength.length = LHS.
size();
368 this->RHS.cString = RHS;
369 assert(isValid() &&
"Invalid twine!");
389 return Twine(LHS, UHexKind, RHS, EmptyKind);
402 return isUnary() && getLHSKind() == StringLiteralKind;
408 if (getRHSKind() != EmptyKind)
411 switch (getLHSKind()) {
415 case PtrAndLengthKind:
416 case StringLiteralKind:
443 switch (getLHSKind()) {
452 case PtrAndLengthKind:
453 case StringLiteralKind:
454 return StringRef(LHS.ptrAndLength.ptr, LHS.ptrAndLength.length);
483#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
499 if (isNull() || Suffix.isNull())
500 return Twine(NullKind);
505 if (Suffix.isEmpty())
510 Child NewLHS, NewRHS;
512 NewRHS.twine = &Suffix;
513 NodeKind NewLHSKind = TwineKind, NewRHSKind = TwineKind;
516 NewLHSKind = getLHSKind();
518 if (Suffix.isUnary()) {
520 NewRHSKind = Suffix.getLHSKind();
523 return Twine(NewLHS, NewLHSKind, NewRHS, NewRHSKind);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file defines the SmallVector class.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
pointer data()
Return a pointer to the vector's buffer, even if empty().
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Twine()
Construct from an empty string.
Twine(const formatv_object_base &Fmt)
Construct from a formatv_object_base.
Twine & operator=(const Twine &)=delete
Since the intended use of twines is as temporary objects, assignments when concatenating might cause ...
bool isSingleStringRef() const
Return true if this twine can be dynamically accessed as a single StringRef value with getSingleStrin...
Twine(long Val)
Construct a twine to print Val as a signed decimal integer.
Twine(const SmallVectorImpl< char > &Str)
Construct from a SmallString.
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
Twine(unsigned long long Val)
Construct a twine to print Val as an unsigned decimal integer.
Twine concat(const Twine &Suffix) const
Twine(unsigned Val)
Construct a twine to print Val as an unsigned decimal integer.
LLVM_ABI void print(raw_ostream &OS) const
Write the concatenated string represented by this twine to the stream OS.
LLVM_ABI StringRef toNullTerminatedStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single null terminated StringRef if it can be represented as such.
Twine(const std::string &Str)
Construct from an std::string.
Twine(unsigned char Val)
Construct from an unsigned char.
LLVM_DUMP_METHOD void dump() const
Dump the concatenated string represented by this twine to stderr.
Twine(const char *LHS, const StringRef &RHS)
Construct as the concatenation of a C string and a StringRef.
Twine(std::nullptr_t)=delete
Delete the implicit conversion from nullptr as Twine(const char *) cannot take nullptr.
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
bool isSingleStringLiteral() const
Check if this twine is guaranteed to refer to single string literal.
static Twine createNull()
Create a 'null' string, which is an empty string that always concatenates to form another empty strin...
LLVM_ABI void printRepr(raw_ostream &OS) const
Write the representation of this twine to the stream OS.
Twine(signed char Val)
Construct from a signed char.
Twine(const Twine &)=default
Twine(const std::string_view &Str)
Construct from an std::string_view by converting it to a pointer and length.
Twine(const StringLiteral &Str)
Construct from a StringLiteral.
Twine(long long Val)
Construct a twine to print Val as a signed decimal integer.
Twine(const StringRef &LHS, const char *RHS)
Construct as the concatenation of a StringRef and a C string.
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Twine(int Val)
Construct a twine to print Val as a signed decimal integer.
Twine(const StringRef &Str)
Construct from a StringRef.
StringRef getSingleStringRef() const
This returns the twine as a single StringRef.
static Twine utohexstr(uint64_t Val)
Twine(unsigned long Val)
Construct a twine to print Val as an unsigned decimal integer.
LLVM_ABI void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
Twine(char Val)
Construct from a char.
LLVM_DUMP_METHOD void dumpRepr() const
Dump the representation of this twine to stderr.
Twine(const char *Str)
Construct from a C string.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
APInt operator+(APInt a, const APInt &b)