9#ifndef LLVM_ADT_TWINE_H
10#define LLVM_ADT_TWINE_H
23 class formatv_object_base;
145 const std::string *stdString;
154 const unsigned long *decUL;
156 const unsigned long long *decULL;
157 const long long *decLL;
177 assert(isNullary() &&
"Invalid kind!");
182 : LHSKind(TwineKind), RHSKind(TwineKind) {
183 this->LHS.twine = &
LHS;
184 this->RHS.twine = &
RHS;
185 assert(isValid() &&
"Invalid twine!");
190 :
LHS(
LHS),
RHS(
RHS), LHSKind(LHSKind), RHSKind(RHSKind) {
191 assert(isValid() &&
"Invalid twine!");
195 bool isNull()
const {
196 return getLHSKind() == NullKind;
200 bool isEmpty()
const {
201 return getLHSKind() == EmptyKind;
205 bool isNullary()
const {
206 return isNull() || isEmpty();
210 bool isUnary()
const {
211 return getRHSKind() == EmptyKind && !isNullary();
215 bool isBinary()
const {
216 return getLHSKind() != NullKind && getRHSKind() != EmptyKind;
221 bool isValid()
const {
223 if (isNullary() && getRHSKind() != EmptyKind)
227 if (getRHSKind() == NullKind)
231 if (getRHSKind() != EmptyKind && getLHSKind() == EmptyKind)
235 if (getLHSKind() == TwineKind &&
236 !
LHS.twine->isBinary())
238 if (getRHSKind() == TwineKind &&
239 !
RHS.twine->isBinary())
246 NodeKind getLHSKind()
const {
return LHSKind; }
249 NodeKind getRHSKind()
const {
return RHSKind; }
264 assert(isValid() &&
"Invalid twine!");
275 if (Str[0] !=
'\0') {
277 LHSKind = CStringKind;
282 assert(isValid() &&
"Invalid twine!");
289 Twine(
const std::string &Str) : LHSKind(StdStringKind) {
290 LHS.stdString = &Str;
291 assert(isValid() &&
"Invalid twine!");
299 : LHSKind(PtrAndLengthKind) {
300 LHS.ptrAndLength.ptr = Str.data();
301 LHS.ptrAndLength.length = Str.length();
302 assert(isValid() &&
"Invalid twine!");
307 LHS.ptrAndLength.ptr = Str.data();
308 LHS.ptrAndLength.length = Str.size();
309 assert(isValid() &&
"Invalid twine!");
314 : LHSKind(StringLiteralKind) {
315 LHS.ptrAndLength.ptr = Str.data();
316 LHS.ptrAndLength.length = Str.size();
317 assert(isValid() &&
"Invalid twine!");
322 : LHSKind(PtrAndLengthKind) {
323 LHS.ptrAndLength.ptr = Str.data();
324 LHS.ptrAndLength.length = Str.size();
325 assert(isValid() &&
"Invalid twine!");
330 : LHSKind(FormatvObjectKind) {
331 LHS.formatvObject = &Fmt;
332 assert(isValid() &&
"Invalid twine!");
336 explicit Twine(
char Val) : LHSKind(CharKind) {
341 explicit Twine(
signed char Val) : LHSKind(CharKind) {
342 LHS.character =
static_cast<char>(Val);
346 explicit Twine(
unsigned char Val) : LHSKind(CharKind) {
347 LHS.character =
static_cast<char>(Val);
351 explicit Twine(
unsigned Val) : LHSKind(DecUIKind) {
356 explicit Twine(
int Val) : LHSKind(DecIKind) {
361 explicit Twine(
const unsigned long &Val) : LHSKind(DecULKind) {
366 explicit Twine(
const long &Val) : LHSKind(DecLKind) {
371 explicit Twine(
const unsigned long long &Val) : LHSKind(DecULLKind) {
376 explicit Twine(
const long long &Val) : LHSKind(DecLLKind) {
387 : LHSKind(CStringKind), RHSKind(PtrAndLengthKind) {
388 this->LHS.cString =
LHS;
389 this->RHS.ptrAndLength.ptr =
RHS.data();
390 this->RHS.ptrAndLength.length =
RHS.size();
391 assert(isValid() &&
"Invalid twine!");
396 : LHSKind(PtrAndLengthKind), RHSKind(CStringKind) {
397 this->LHS.ptrAndLength.ptr =
LHS.data();
398 this->LHS.ptrAndLength.length =
LHS.size();
399 this->RHS.cString =
RHS;
400 assert(isValid() &&
"Invalid twine!");
410 return Twine(NullKind);
437 return isUnary() && getLHSKind() == StringLiteralKind;
443 if (getRHSKind() != EmptyKind)
return false;
445 switch (getLHSKind()) {
449 case PtrAndLengthKind:
450 case StringLiteralKind:
477 switch (getLHSKind()) {
485 case PtrAndLengthKind:
486 case StringLiteralKind:
516#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
532 if (isNull() || Suffix.isNull())
533 return Twine(NullKind);
538 if (Suffix.isEmpty())
543 Child NewLHS, NewRHS;
545 NewRHS.twine = &Suffix;
546 NodeKind NewLHSKind = TwineKind, NewRHSKind = TwineKind;
549 NewLHSKind = getLHSKind();
551 if (Suffix.isUnary()) {
553 NewRHSKind = Suffix.getLHSKind();
556 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.
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.
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
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)
Determine the kind of a node from its type.