9 #ifndef LLVM_ADT_TWINE_H 10 #define LLVM_ADT_TWINE_H 21 class formatv_object_base;
140 const std::string *stdString;
147 const unsigned long *decUL;
149 const unsigned long long *decULL;
150 const long long *decLL;
151 const uint64_t *uHex;
170 assert(isNullary() &&
"Invalid kind!");
175 : LHSKind(TwineKind), RHSKind(TwineKind) {
176 this->LHS.twine = &LHS;
177 this->RHS.twine = &RHS;
178 assert(isValid() &&
"Invalid twine!");
183 : LHS(LHS), RHS(RHS), LHSKind(LHSKind), RHSKind(RHSKind) {
184 assert(isValid() &&
"Invalid twine!");
188 bool isNull()
const {
189 return getLHSKind() == NullKind;
193 bool isEmpty()
const {
194 return getLHSKind() == EmptyKind;
198 bool isNullary()
const {
199 return isNull() || isEmpty();
203 bool isUnary()
const {
204 return getRHSKind() == EmptyKind && !isNullary();
208 bool isBinary()
const {
209 return getLHSKind() != NullKind && getRHSKind() != EmptyKind;
214 bool isValid()
const {
216 if (isNullary() && getRHSKind() != EmptyKind)
220 if (getRHSKind() == NullKind)
224 if (getRHSKind() != EmptyKind && getLHSKind() == EmptyKind)
228 if (getLHSKind() == TwineKind &&
229 !LHS.twine->isBinary())
231 if (getRHSKind() == TwineKind &&
232 !RHS.twine->isBinary())
239 NodeKind getLHSKind()
const {
return LHSKind; }
242 NodeKind getRHSKind()
const {
return RHSKind; }
257 assert(isValid() &&
"Invalid twine!");
268 if (Str[0] !=
'\0') {
270 LHSKind = CStringKind;
274 assert(isValid() &&
"Invalid twine!");
278 Twine(std::nullptr_t) =
delete;
281 Twine(
const std::string &Str) : LHSKind(StdStringKind) {
282 LHS.stdString = &Str;
283 assert(isValid() &&
"Invalid twine!");
288 LHS.stringRef = &Str;
289 assert(isValid() &&
"Invalid twine!");
294 : LHSKind(SmallStringKind) {
295 LHS.smallString = &Str;
296 assert(isValid() &&
"Invalid twine!");
301 : LHSKind(FormatvObjectKind) {
302 LHS.formatvObject = &Fmt;
303 assert(isValid() &&
"Invalid twine!");
307 explicit Twine(
char Val) : LHSKind(CharKind) {
312 explicit Twine(
signed char Val) : LHSKind(CharKind) {
313 LHS.character =
static_cast<char>(Val);
317 explicit Twine(
unsigned char Val) : LHSKind(CharKind) {
318 LHS.character =
static_cast<char>(Val);
322 explicit Twine(
unsigned Val) : LHSKind(DecUIKind) {
327 explicit Twine(
int Val) : LHSKind(DecIKind) {
332 explicit Twine(
const unsigned long &Val) : LHSKind(DecULKind) {
337 explicit Twine(
const long &Val) : LHSKind(DecLKind) {
342 explicit Twine(
const unsigned long long &Val) : LHSKind(DecULLKind) {
347 explicit Twine(
const long long &Val) : LHSKind(DecLLKind) {
358 : LHSKind(CStringKind), RHSKind(StringRefKind) {
359 this->LHS.cString = LHS;
360 this->RHS.stringRef = &RHS;
361 assert(isValid() &&
"Invalid twine!");
366 : LHSKind(StringRefKind), RHSKind(CStringKind) {
367 this->LHS.stringRef = &LHS;
368 this->RHS.cString = RHS;
369 assert(isValid() &&
"Invalid twine!");
379 return Twine(NullKind);
391 return Twine(LHS, UHexKind, RHS, EmptyKind);
407 if (getRHSKind() != EmptyKind)
return false;
409 switch (getLHSKind()) {
414 case SmallStringKind:
432 std::string
str()
const;
441 switch (getLHSKind()) {
444 case CStringKind:
return StringRef(LHS.cString);
445 case StdStringKind:
return StringRef(*LHS.stdString);
446 case StringRefKind:
return *LHS.stringRef;
447 case SmallStringKind:
448 return StringRef(LHS.smallString->data(), LHS.smallString->size());
490 if (isNull() || Suffix.isNull())
491 return Twine(NullKind);
496 if (Suffix.isEmpty())
501 Child NewLHS, NewRHS;
503 NewRHS.twine = &Suffix;
504 NodeKind NewLHSKind = TwineKind, NewRHSKind = TwineKind;
507 NewLHSKind = getLHSKind();
509 if (Suffix.isUnary()) {
511 NewRHSKind = Suffix.getLHSKind();
514 return Twine(NewLHS, NewLHSKind, NewRHS, NewRHSKind);
525 return Twine(LHS, RHS);
532 return Twine(LHS, RHS);
544 #endif // LLVM_ADT_TWINE_H Twine(signed char Val)
Construct from a signed char.
Twine(const char *Str)
Construct from a C string.
Twine(const formatv_object_base &Fmt)
Construct from a formatv_object_base.
APInt operator+(APInt a, const APInt &b)
Twine(const unsigned long long &Val)
Construct a twine to print Val as an unsigned decimal integer.
This class represents lattice values for constants.
Twine(const StringRef &LHS, const char *RHS)
Construct as the concatenation of a StringRef and a C string.
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Twine(const SmallVectorImpl< char > &Str)
Construct from a SmallString.
Twine & operator=(const Twine &)=delete
Since the intended use of twines is as temporary objects, assignments when concatenating might cause ...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void dumpRepr() const
Dump the representation of this twine to stderr.
StringRef getSingleStringRef() const
This returns the twine as a single StringRef.
bool isSingleStringRef() const
Return true if this twine can be dynamically accessed as a single StringRef value with getSingleStrin...
void dump() const
Dump the concatenated string represented by this twine to stderr.
Twine(char Val)
Construct from a char.
Twine()
Construct from an empty string.
Twine(const long long &Val)
Construct a twine to print Val as a signed decimal integer.
static Twine createNull()
Create a 'null' string, which is an empty string that always concatenates to form another empty strin...
Twine(const StringRef &Str)
Construct from a StringRef.
StringRef toNullTerminatedStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single null terminated StringRef if it can be represented as such...
void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
Determine the kind of a node from its type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Twine(unsigned char Val)
Construct from an unsigned char.
static Twine utohexstr(const uint64_t &Val)
Twine(const std::string &Str)
Construct from an std::string.
Twine(int Val)
Construct a twine to print Val as a signed decimal integer.
Twine(unsigned Val)
Construct a twine to print Val as an unsigned decimal integer.
pointer data()
Return a pointer to the vector's buffer, even if empty().
Twine(const long &Val)
Construct a twine to print Val as a signed decimal integer.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
std::string str() const
Return the twine contents as a std::string.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Twine(const char *LHS, const StringRef &RHS)
Construct as the concatenation of a C string and a StringRef.
void printRepr(raw_ostream &OS) const
Write the representation of this twine to the stream OS.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
Twine(const unsigned long &Val)
Construct a twine to print Val as an unsigned decimal integer.
Twine concat(const Twine &Suffix) const
void print(raw_ostream &OS) const
Write the concatenated string represented by this twine to the stream OS.