9#ifndef LLVM_ADT_TWINE_H
10#define LLVM_ADT_TWINE_H
84 enum NodeKind :
unsigned char {
144 const std::string *stdString;
153 const unsigned long *decUL;
155 const unsigned long long *decULL;
156 const long long *decLL;
169 NodeKind LHSKind = EmptyKind;
172 NodeKind RHSKind = EmptyKind;
175 explicit Twine(NodeKind Kind) : LHSKind(Kind) {
176 assert(isNullary() &&
"Invalid kind!");
180 explicit Twine(
const Twine &LHS,
const Twine &RHS)
181 : LHSKind(TwineKind), RHSKind(TwineKind) {
182 this->LHS.twine = &LHS;
183 this->RHS.twine = &RHS;
184 assert(isValid() &&
"Invalid twine!");
188 explicit Twine(Child LHS, NodeKind LHSKind, Child RHS, NodeKind RHSKind)
189 :
LHS(LHS),
RHS(RHS), LHSKind(LHSKind), RHSKind(RHSKind) {
190 assert(isValid() &&
"Invalid twine!");
194 bool isNull()
const {
return getLHSKind() == NullKind; }
197 bool isEmpty()
const {
return getLHSKind() == EmptyKind; }
200 bool isNullary()
const {
return isNull() || isEmpty(); }
203 bool isUnary()
const {
return getRHSKind() == EmptyKind && !isNullary(); }
206 bool isBinary()
const {
207 return getLHSKind() != NullKind && getRHSKind() != EmptyKind;
212 bool isValid()
const {
214 if (isNullary() && getRHSKind() != EmptyKind)
218 if (getRHSKind() == NullKind)
222 if (getRHSKind() != EmptyKind && getLHSKind() == EmptyKind)
226 if (getLHSKind() == TwineKind && !LHS.twine->isBinary())
228 if (getRHSKind() == TwineKind && !RHS.twine->isBinary())
235 NodeKind getLHSKind()
const {
return LHSKind; }
238 NodeKind getRHSKind()
const {
return RHSKind; }
241 void printOneChild(
raw_ostream &OS, Child
Ptr, NodeKind Kind)
const;
244 void printOneChildRepr(
raw_ostream &OS, Child
Ptr, NodeKind Kind)
const;
261 if (Str[0] !=
'\0') {
263 LHSKind = CStringKind;
268 assert(isValid() &&
"Invalid twine!");
275 Twine(
const std::string &Str) : LHSKind(StdStringKind) {
276 LHS.stdString = &Str;
277 assert(isValid() &&
"Invalid twine!");
284 Twine(
const std::string_view &Str) : LHSKind(PtrAndLengthKind) {
285 LHS.ptrAndLength.ptr = Str.data();
286 LHS.ptrAndLength.length = Str.length();
287 assert(isValid() &&
"Invalid twine!");
292 LHS.ptrAndLength.ptr = Str.data();
293 LHS.ptrAndLength.length = Str.size();
294 assert(isValid() &&
"Invalid twine!");
299 LHS.ptrAndLength.ptr = Str.data();
300 LHS.ptrAndLength.length = Str.size();
301 assert(isValid() &&
"Invalid twine!");
306 : LHSKind(PtrAndLengthKind) {
307 LHS.ptrAndLength.ptr = Str.data();
308 LHS.ptrAndLength.length = Str.size();
309 assert(isValid() &&
"Invalid twine!");
314 : LHSKind(FormatvObjectKind) {
315 LHS.formatvObject = &Fmt;
316 assert(isValid() &&
"Invalid twine!");
320 explicit Twine(
char Val) : LHSKind(CharKind) { LHS.character = Val; }
323 explicit Twine(
signed char Val) : LHSKind(CharKind) {
324 LHS.character =
static_cast<char>(Val);
328 explicit Twine(
unsigned char Val) : LHSKind(CharKind) {
329 LHS.character =
static_cast<char>(Val);
333 explicit Twine(
unsigned Val) : LHSKind(DecUIKind) { LHS.decUI = Val; }
336 explicit Twine(
int Val) : LHSKind(DecIKind) { LHS.decI = Val; }
339 explicit Twine(
const unsigned long &Val) : LHSKind(DecULKind) {
344 explicit Twine(
const long &Val) : LHSKind(DecLKind) { LHS.decL = &Val; }
347 explicit Twine(
const unsigned long long &Val) : LHSKind(DecULLKind) {
352 explicit Twine(
const long long &Val) : LHSKind(DecLLKind) {
363 : LHSKind(CStringKind), RHSKind(PtrAndLengthKind) {
364 this->LHS.cString = LHS;
365 this->RHS.ptrAndLength.ptr = RHS.
data();
366 this->RHS.ptrAndLength.length = RHS.
size();
367 assert(isValid() &&
"Invalid twine!");
372 : LHSKind(PtrAndLengthKind), RHSKind(CStringKind) {
373 this->LHS.ptrAndLength.ptr = LHS.
data();
374 this->LHS.ptrAndLength.length = LHS.
size();
375 this->RHS.cString = RHS;
376 assert(isValid() &&
"Invalid twine!");
396 return Twine(LHS, UHexKind, RHS, EmptyKind);
409 return isUnary() && getLHSKind() == StringLiteralKind;
415 if (getRHSKind() != EmptyKind)
418 switch (getLHSKind()) {
422 case PtrAndLengthKind:
423 case StringLiteralKind:
450 switch (getLHSKind()) {
459 case PtrAndLengthKind:
460 case StringLiteralKind:
461 return StringRef(LHS.ptrAndLength.ptr, LHS.ptrAndLength.length);
490#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
506 if (isNull() || Suffix.isNull())
507 return Twine(NullKind);
512 if (Suffix.isEmpty())
517 Child NewLHS, NewRHS;
519 NewRHS.twine = &Suffix;
520 NodeKind NewLHSKind = TwineKind, NewRHSKind = TwineKind;
523 NewLHSKind = getLHSKind();
525 if (Suffix.isUnary()) {
527 NewRHSKind = Suffix.getLHSKind();
530 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 ...
Twine(const long long &Val)
Construct a twine to print Val as a signed decimal integer.
bool isSingleStringRef() const
Return true if this twine can be dynamically accessed as a single StringRef value with getSingleStrin...
Twine(const unsigned long &Val)
Construct a twine to print Val as an unsigned 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 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...
Twine(const long &Val)
Construct a twine to print Val as a signed decimal integer.
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(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.
static Twine utohexstr(const uint64_t &Val)
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.
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 unsigned long long &Val)
Construct a twine to print Val as an unsigned decimal integer.
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)