9#ifndef LLVM_ADT_TWINE_H
10#define LLVM_ADT_TWINE_H
22 class formatv_object_base;
140 const std::string *stdString;
149 const unsigned long *decUL;
151 const unsigned long long *decULL;
152 const long long *decLL;
172 assert(isNullary() &&
"Invalid kind!");
177 : LHSKind(TwineKind), RHSKind(TwineKind) {
178 this->LHS.twine = &
LHS;
179 this->RHS.twine = &
RHS;
180 assert(isValid() &&
"Invalid twine!");
185 :
LHS(
LHS),
RHS(
RHS), LHSKind(LHSKind), RHSKind(RHSKind) {
186 assert(isValid() &&
"Invalid twine!");
190 bool isNull()
const {
191 return getLHSKind() == NullKind;
195 bool isEmpty()
const {
196 return getLHSKind() == EmptyKind;
200 bool isNullary()
const {
201 return isNull() || isEmpty();
205 bool isUnary()
const {
206 return getRHSKind() == EmptyKind && !isNullary();
210 bool isBinary()
const {
211 return getLHSKind() != NullKind && getRHSKind() != EmptyKind;
216 bool isValid()
const {
218 if (isNullary() && getRHSKind() != EmptyKind)
222 if (getRHSKind() == NullKind)
226 if (getRHSKind() != EmptyKind && getLHSKind() == EmptyKind)
230 if (getLHSKind() == TwineKind &&
231 !
LHS.twine->isBinary())
233 if (getRHSKind() == TwineKind &&
234 !
RHS.twine->isBinary())
241 NodeKind getLHSKind()
const {
return LHSKind; }
244 NodeKind getRHSKind()
const {
return RHSKind; }
259 assert(isValid() &&
"Invalid twine!");
270 if (Str[0] !=
'\0') {
272 LHSKind = CStringKind;
276 assert(isValid() &&
"Invalid twine!");
283 Twine(
const std::string &Str) : LHSKind(StdStringKind) {
284 LHS.stdString = &Str;
285 assert(isValid() &&
"Invalid twine!");
293 : LHSKind(PtrAndLengthKind) {
294 LHS.ptrAndLength.ptr = Str.data();
295 LHS.ptrAndLength.length = Str.length();
296 assert(isValid() &&
"Invalid twine!");
301 LHS.ptrAndLength.ptr = Str.data();
302 LHS.ptrAndLength.length = Str.size();
303 assert(isValid() &&
"Invalid twine!");
308 : LHSKind(PtrAndLengthKind) {
309 LHS.ptrAndLength.ptr = Str.data();
310 LHS.ptrAndLength.length = Str.size();
311 assert(isValid() &&
"Invalid twine!");
316 : LHSKind(FormatvObjectKind) {
317 LHS.formatvObject = &Fmt;
318 assert(isValid() &&
"Invalid twine!");
322 explicit Twine(
char Val) : LHSKind(CharKind) {
327 explicit Twine(
signed char Val) : LHSKind(CharKind) {
328 LHS.character =
static_cast<char>(Val);
332 explicit Twine(
unsigned char Val) : LHSKind(CharKind) {
333 LHS.character =
static_cast<char>(Val);
337 explicit Twine(
unsigned Val) : LHSKind(DecUIKind) {
342 explicit Twine(
int Val) : LHSKind(DecIKind) {
347 explicit Twine(
const unsigned long &Val) : LHSKind(DecULKind) {
352 explicit Twine(
const long &Val) : LHSKind(DecLKind) {
357 explicit Twine(
const unsigned long long &Val) : LHSKind(DecULLKind) {
362 explicit Twine(
const long long &Val) : LHSKind(DecLLKind) {
373 : LHSKind(CStringKind), RHSKind(PtrAndLengthKind) {
374 this->LHS.cString =
LHS;
375 this->RHS.ptrAndLength.ptr =
RHS.data();
376 this->RHS.ptrAndLength.length =
RHS.size();
377 assert(isValid() &&
"Invalid twine!");
382 : LHSKind(PtrAndLengthKind), RHSKind(CStringKind) {
383 this->LHS.ptrAndLength.ptr =
LHS.data();
384 this->LHS.ptrAndLength.length =
LHS.size();
385 this->RHS.cString =
RHS;
386 assert(isValid() &&
"Invalid twine!");
396 return Twine(NullKind);
424 if (getRHSKind() != EmptyKind)
return false;
426 switch (getLHSKind()) {
430 case PtrAndLengthKind:
448 std::string
str()
const;
457 switch (getLHSKind()) {
465 case PtrAndLengthKind:
508 if (isNull() || Suffix.isNull())
509 return Twine(NullKind);
514 if (Suffix.isEmpty())
519 Child NewLHS, NewRHS;
521 NewRHS.twine = &Suffix;
522 NodeKind NewLHSKind = TwineKind, NewRHSKind = TwineKind;
525 NewLHSKind = getLHSKind();
527 if (Suffix.isUnary()) {
529 NewRHSKind = Suffix.getLHSKind();
532 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().
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...
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 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.