10 #ifndef LLVM_ADT_TWINE_H
11 #define LLVM_ADT_TWINE_H
14 #include "llvm/Support/DataTypes.h"
21 class SmallVectorImpl;
137 const std::string *stdString;
142 const unsigned long *decUL;
144 const unsigned long long *decULL;
145 const long long *decLL;
146 const uint64_t *uHex;
159 unsigned char LHSKind;
161 unsigned char RHSKind;
166 : LHSKind(Kind), RHSKind(EmptyKind) {
167 assert(isNullary() &&
"Invalid kind!");
172 : LHSKind(TwineKind), RHSKind(TwineKind) {
175 assert(isValid() &&
"Invalid twine!");
179 explicit Twine(Child _LHS, NodeKind _LHSKind,
180 Child _RHS, NodeKind _RHSKind)
181 : LHS(_LHS), RHS(_RHS), LHSKind(_LHSKind), RHSKind(_RHSKind) {
182 assert(isValid() &&
"Invalid twine!");
186 bool isNull()
const {
187 return getLHSKind() == NullKind;
191 bool isEmpty()
const {
192 return getLHSKind() == EmptyKind;
196 bool isNullary()
const {
197 return isNull() || isEmpty();
201 bool isUnary()
const {
202 return getRHSKind() == EmptyKind && !isNullary();
206 bool isBinary()
const {
207 return getLHSKind() != NullKind && getRHSKind() != EmptyKind;
212 bool isValid()
const {
214 if (isNullary() && getRHSKind() != EmptyKind)
218 if (getRHSKind() == NullKind)
222 if (getRHSKind() != EmptyKind && getLHSKind() == EmptyKind)
226 if (getLHSKind() == TwineKind &&
227 !LHS.twine->isBinary())
229 if (getRHSKind() == TwineKind &&
230 !RHS.twine->isBinary())
237 NodeKind getLHSKind()
const {
return (NodeKind) LHSKind; }
240 NodeKind getRHSKind()
const {
return (NodeKind) RHSKind; }
243 void printOneChild(
raw_ostream &OS, Child Ptr, NodeKind Kind)
const;
247 NodeKind Kind)
const;
254 Twine() : LHSKind(EmptyKind), RHSKind(EmptyKind) {
255 assert(isValid() &&
"Invalid twine!");
264 : RHSKind(EmptyKind) {
265 if (Str[0] !=
'\0') {
267 LHSKind = CStringKind;
271 assert(isValid() &&
"Invalid twine!");
276 : LHSKind(StdStringKind), RHSKind(EmptyKind) {
277 LHS.stdString = &Str;
278 assert(isValid() &&
"Invalid twine!");
283 : LHSKind(StringRefKind), RHSKind(EmptyKind) {
284 LHS.stringRef = &Str;
285 assert(isValid() &&
"Invalid twine!");
290 : LHSKind(CharKind), RHSKind(EmptyKind) {
296 : LHSKind(CharKind), RHSKind(EmptyKind) {
297 LHS.character =
static_cast<char>(Val);
302 : LHSKind(CharKind), RHSKind(EmptyKind) {
303 LHS.character =
static_cast<char>(Val);
308 : LHSKind(DecUIKind), RHSKind(EmptyKind) {
314 : LHSKind(DecIKind), RHSKind(EmptyKind) {
319 explicit Twine(
const unsigned long &Val)
320 : LHSKind(DecULKind), RHSKind(EmptyKind) {
326 : LHSKind(DecLKind), RHSKind(EmptyKind) {
331 explicit Twine(
const unsigned long long &Val)
332 : LHSKind(DecULLKind), RHSKind(EmptyKind) {
337 explicit Twine(
const long long &Val)
338 : LHSKind(DecLLKind), RHSKind(EmptyKind) {
349 : LHSKind(CStringKind), RHSKind(StringRefKind) {
351 RHS.stringRef = &_RHS;
352 assert(isValid() &&
"Invalid twine!");
357 : LHSKind(StringRefKind), RHSKind(CStringKind) {
358 LHS.stringRef = &_LHS;
360 assert(isValid() &&
"Invalid twine!");
366 return Twine(NullKind);
378 return Twine(LHS, UHexKind, RHS, EmptyKind);
394 if (getRHSKind() != EmptyKind)
return false;
396 switch (getLHSKind()) {
418 std::string
str()
const;
428 switch (getLHSKind()) {
431 case CStringKind:
return StringRef(LHS.cString);
432 case StdStringKind:
return StringRef(*LHS.stdString);
433 case StringRefKind:
return *LHS.stringRef;
471 if (isNull() || Suffix.isNull())
472 return Twine(NullKind);
477 if (Suffix.isEmpty())
482 Child NewLHS, NewRHS;
484 NewRHS.twine = &Suffix;
485 NodeKind NewLHSKind = TwineKind, NewRHSKind = TwineKind;
488 NewLHSKind = getLHSKind();
490 if (Suffix.isUnary()) {
492 NewRHSKind = Suffix.getLHSKind();
495 return Twine(NewLHS, NewLHSKind, NewRHS, NewRHSKind);
506 return Twine(LHS, RHS);
513 return Twine(LHS, RHS);
void toVector(SmallVectorImpl< char > &Out) const
Twine(signed char Val)
Construct from a signed char.
bool isSingleStringRef() const
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 char *_LHS, const StringRef &_RHS)
Construct as the concatenation of a C string and a StringRef.
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
str - Return the twine contents as a std::string.
#define llvm_unreachable(msg)
void operator+(int, ilist_iterator< T >) LLVM_DELETED_FUNCTION
StringRef getSingleStringRef() const
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()
Twine(const StringRef &Str)
Construct from a StringRef.
Twine(unsigned char Val)
Construct from an unsigned char.
Twine concat(const Twine &Suffix) const
static Twine utohexstr(const uint64_t &Val)
StringRef toStringRef(SmallVectorImpl< char > &Out) const
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.
Twine(const long &Val)
Construct a twine to print Val as a signed decimal integer.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
StringRef toNullTerminatedStringRef(SmallVectorImpl< char > &Out) const
void print(raw_ostream &OS) const
bool isTriviallyEmpty() const
Twine(const unsigned long &Val)
Construct a twine to print Val as an unsigned decimal integer.