10 #ifndef LLVM_ADT_TWINE_H
11 #define LLVM_ADT_TWINE_H
15 #include "llvm/Support/DataTypes.h"
81 enum NodeKind :
unsigned char {
138 const std::string *stdString;
144 const unsigned long *decUL;
146 const unsigned long long *decULL;
147 const long long *decLL;
148 const uint64_t *uHex;
166 : LHSKind(Kind), RHSKind(EmptyKind) {
167 assert(isNullary() &&
"Invalid kind!");
172 : LHSKind(TwineKind), RHSKind(TwineKind) {
173 this->LHS.twine = &LHS;
174 this->RHS.twine = &RHS;
175 assert(isValid() &&
"Invalid twine!");
179 explicit Twine(Child LHS, NodeKind LHSKind, Child RHS, NodeKind RHSKind)
180 : LHS(LHS), RHS(RHS), LHSKind(LHSKind), RHSKind(RHSKind) {
181 assert(isValid() &&
"Invalid twine!");
189 bool isNull()
const {
190 return getLHSKind() == NullKind;
194 bool isEmpty()
const {
195 return getLHSKind() == EmptyKind;
199 bool isNullary()
const {
200 return isNull() || isEmpty();
204 bool isUnary()
const {
205 return getRHSKind() == EmptyKind && !isNullary();
209 bool isBinary()
const {
210 return getLHSKind() != NullKind && getRHSKind() != EmptyKind;
215 bool isValid()
const {
217 if (isNullary() && getRHSKind() != EmptyKind)
221 if (getRHSKind() == NullKind)
225 if (getRHSKind() != EmptyKind && getLHSKind() == EmptyKind)
229 if (getLHSKind() == TwineKind &&
230 !LHS.twine->isBinary())
232 if (getRHSKind() == TwineKind &&
233 !RHS.twine->isBinary())
240 NodeKind getLHSKind()
const {
return LHSKind; }
243 NodeKind getRHSKind()
const {
return RHSKind; }
246 void printOneChild(
raw_ostream &OS, Child Ptr, NodeKind Kind)
const;
250 NodeKind Kind)
const;
257 Twine() : LHSKind(EmptyKind), RHSKind(EmptyKind) {
258 assert(isValid() &&
"Invalid twine!");
269 : RHSKind(EmptyKind) {
270 if (Str[0] !=
'\0') {
272 LHSKind = CStringKind;
276 assert(isValid() &&
"Invalid twine!");
281 : LHSKind(StdStringKind), RHSKind(EmptyKind) {
282 LHS.stdString = &Str;
283 assert(isValid() &&
"Invalid twine!");
288 : LHSKind(StringRefKind), RHSKind(EmptyKind) {
289 LHS.stringRef = &Str;
290 assert(isValid() &&
"Invalid twine!");
295 : LHSKind(SmallStringKind), RHSKind(EmptyKind) {
296 LHS.smallString = &Str;
297 assert(isValid() &&
"Invalid twine!");
302 : LHSKind(CharKind), RHSKind(EmptyKind) {
308 : LHSKind(CharKind), RHSKind(EmptyKind) {
309 LHS.character =
static_cast<char>(Val);
314 : LHSKind(CharKind), RHSKind(EmptyKind) {
315 LHS.character =
static_cast<char>(Val);
320 : LHSKind(DecUIKind), RHSKind(EmptyKind) {
326 : LHSKind(DecIKind), RHSKind(EmptyKind) {
331 explicit Twine(
const unsigned long &Val)
332 : LHSKind(DecULKind), RHSKind(EmptyKind) {
338 : LHSKind(DecLKind), RHSKind(EmptyKind) {
343 explicit Twine(
const unsigned long long &Val)
344 : LHSKind(DecULLKind), RHSKind(EmptyKind) {
349 explicit Twine(
const long long &Val)
350 : LHSKind(DecLLKind), RHSKind(EmptyKind) {
361 : LHSKind(CStringKind), RHSKind(StringRefKind) {
362 this->LHS.cString = LHS;
363 this->RHS.stringRef = &RHS;
364 assert(isValid() &&
"Invalid twine!");
369 : LHSKind(StringRefKind), RHSKind(CStringKind) {
370 this->LHS.stringRef = &LHS;
371 this->RHS.cString = RHS;
372 assert(isValid() &&
"Invalid twine!");
378 return Twine(NullKind);
390 return Twine(LHS, UHexKind, RHS, EmptyKind);
406 if (getRHSKind() != EmptyKind)
return false;
408 switch (getLHSKind()) {
413 case SmallStringKind:
431 std::string
str()
const;
440 switch (getLHSKind()) {
443 case CStringKind:
return StringRef(LHS.cString);
444 case StdStringKind:
return StringRef(*LHS.stdString);
445 case StringRefKind:
return *LHS.stringRef;
446 case SmallStringKind:
447 return StringRef(LHS.smallString->data(), LHS.smallString->size());
489 if (isNull() || Suffix.isNull())
490 return Twine(NullKind);
495 if (Suffix.isEmpty())
500 Child NewLHS, NewRHS;
502 NewRHS.twine = &Suffix;
503 NodeKind NewLHSKind = TwineKind, NewRHSKind = TwineKind;
506 NewLHSKind = getLHSKind();
508 if (Suffix.isUnary()) {
510 NewRHSKind = Suffix.getLHSKind();
513 return Twine(NewLHS, NewLHSKind, NewRHS, NewRHSKind);
524 return Twine(LHS, RHS);
531 return Twine(LHS, RHS);
void toVector(SmallVectorImpl< char > &Out) const
Append the concatenated string into the given SmallString or SmallVector.
Twine(signed char Val)
Construct from a signed char.
Twine(const char *Str)
Construct from a C string.
bool isSingleStringRef() const
Return true if this twine can be dynamically accessed as a single StringRef value with getSingleStrin...
Twine(const unsigned long long &Val)
Construct a twine to print Val as an unsigned decimal integer.
Twine(const StringRef &LHS, const char *RHS)
Construct as the concatenation of a StringRef and a C string.
Twine(const SmallVectorImpl< char > &Str)
Construct from a SmallString.
void dump() const
Dump the concatenated string represented by this twine to stderr.
void dumpRepr() const
Dump the representation of this twine to stderr.
std::string str() const
Return the twine contents as a std::string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
StringRef getSingleStringRef() const
This returns the twine as a single StringRef.
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.
void printRepr(raw_ostream &OS) const
Write the representation of this twine to the stream OS.
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.
Twine(unsigned char Val)
Construct from an unsigned char.
Twine concat(const Twine &Suffix) const
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(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().
void operator+(int, ilist_iterator< T >)=delete
Twine(const long &Val)
Construct a twine to print Val as a signed decimal integer.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
const ARM::ArchExtKind Kind
Twine(const char *LHS, const StringRef &RHS)
Construct as the concatenation of a C string and 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 print(raw_ostream &OS) const
Write the concatenated string represented by this twine to the stream OS.
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
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.