9#ifndef LLVM_ADT_TWINE_H
10#define LLVM_ADT_TWINE_H
22 class formatv_object_base;
144 const std::string *stdString;
153 const unsigned long *decUL;
155 const unsigned long long *decULL;
156 const long long *decLL;
176 assert(isNullary() &&
"Invalid kind!");
181 : LHSKind(TwineKind), RHSKind(TwineKind) {
182 this->LHS.twine = &
LHS;
183 this->RHS.twine = &
RHS;
184 assert(isValid() &&
"Invalid twine!");
189 :
LHS(
LHS),
RHS(
RHS), LHSKind(LHSKind), RHSKind(RHSKind) {
190 assert(isValid() &&
"Invalid twine!");
194 bool isNull()
const {
195 return getLHSKind() == NullKind;
199 bool isEmpty()
const {
200 return getLHSKind() == EmptyKind;
204 bool isNullary()
const {
205 return isNull() || isEmpty();
209 bool isUnary()
const {
210 return getRHSKind() == EmptyKind && !isNullary();
214 bool isBinary()
const {
215 return getLHSKind() != NullKind && getRHSKind() != EmptyKind;
220 bool isValid()
const {
222 if (isNullary() && getRHSKind() != EmptyKind)
226 if (getRHSKind() == NullKind)
230 if (getRHSKind() != EmptyKind && getLHSKind() == EmptyKind)
234 if (getLHSKind() == TwineKind &&
235 !
LHS.twine->isBinary())
237 if (getRHSKind() == TwineKind &&
238 !
RHS.twine->isBinary())
245 NodeKind getLHSKind()
const {
return LHSKind; }
248 NodeKind getRHSKind()
const {
return RHSKind; }
263 assert(isValid() &&
"Invalid twine!");
274 if (Str[0] !=
'\0') {
276 LHSKind = CStringKind;
280 assert(isValid() &&
"Invalid twine!");
287 Twine(
const std::string &Str) : LHSKind(StdStringKind) {
288 LHS.stdString = &Str;
289 assert(isValid() &&
"Invalid twine!");
297 : LHSKind(PtrAndLengthKind) {
298 LHS.ptrAndLength.ptr = Str.data();
299 LHS.ptrAndLength.length = Str.length();
300 assert(isValid() &&
"Invalid twine!");
305 LHS.ptrAndLength.ptr = Str.data();
306 LHS.ptrAndLength.length = Str.size();
307 assert(isValid() &&
"Invalid twine!");
312 : LHSKind(StringLiteralKind) {
313 LHS.ptrAndLength.ptr = Str.data();
314 LHS.ptrAndLength.length = Str.size();
315 assert(isValid() &&
"Invalid twine!");
320 : LHSKind(PtrAndLengthKind) {
321 LHS.ptrAndLength.ptr = Str.data();
322 LHS.ptrAndLength.length = Str.size();
323 assert(isValid() &&
"Invalid twine!");
328 : LHSKind(FormatvObjectKind) {
329 LHS.formatvObject = &Fmt;
330 assert(isValid() &&
"Invalid twine!");
334 explicit Twine(
char Val) : LHSKind(CharKind) {
339 explicit Twine(
signed char Val) : LHSKind(CharKind) {
340 LHS.character =
static_cast<char>(Val);
344 explicit Twine(
unsigned char Val) : LHSKind(CharKind) {
345 LHS.character =
static_cast<char>(Val);
349 explicit Twine(
unsigned Val) : LHSKind(DecUIKind) {
354 explicit Twine(
int Val) : LHSKind(DecIKind) {
359 explicit Twine(
const unsigned long &Val) : LHSKind(DecULKind) {
364 explicit Twine(
const long &Val) : LHSKind(DecLKind) {
369 explicit Twine(
const unsigned long long &Val) : LHSKind(DecULLKind) {
374 explicit Twine(
const long long &Val) : LHSKind(DecLLKind) {
385 : LHSKind(CStringKind), RHSKind(PtrAndLengthKind) {
386 this->LHS.cString =
LHS;
387 this->RHS.ptrAndLength.ptr =
RHS.data();
388 this->RHS.ptrAndLength.length =
RHS.size();
389 assert(isValid() &&
"Invalid twine!");
394 : LHSKind(PtrAndLengthKind), RHSKind(CStringKind) {
395 this->LHS.ptrAndLength.ptr =
LHS.data();
396 this->LHS.ptrAndLength.length =
LHS.size();
397 this->RHS.cString =
RHS;
398 assert(isValid() &&
"Invalid twine!");
408 return Twine(NullKind);
435 return isUnary() && getLHSKind() == StringLiteralKind;
441 if (getRHSKind() != EmptyKind)
return false;
443 switch (getLHSKind()) {
447 case PtrAndLengthKind:
448 case StringLiteralKind:
466 std::string
str()
const;
475 switch (getLHSKind()) {
483 case PtrAndLengthKind:
484 case StringLiteralKind:
527 if (isNull() || Suffix.isNull())
528 return Twine(NullKind);
533 if (Suffix.isEmpty())
538 Child NewLHS, NewRHS;
540 NewRHS.twine = &Suffix;
541 NodeKind NewLHSKind = TwineKind, NewRHSKind = TwineKind;
544 NewLHSKind = getLHSKind();
546 if (Suffix.isUnary()) {
548 NewRHSKind = Suffix.getLHSKind();
551 return Twine(NewLHS, NewLHSKind, NewRHS, NewRHSKind);
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
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.
void print(raw_ostream &OS) const
Write the concatenated string represented by this twine to the stream OS.
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.
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.
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.
void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
Twine(char Val)
Construct from a char.
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.
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.