class Twine

Declaration

class Twine { /* full declaration omitted */ };

Description

Twine - A lightweight data structure for efficiently representing the concatenation of temporary values as strings. A Twine is a kind of rope, it represents a concatenated string using a binary-tree, where the string is the preorder of the nodes. Since the Twine can be efficiently rendered into a buffer when its result is used, it avoids the cost of generating temporary values for intermediate string results -- particularly in cases when the Twine result is never required. By explicitly tracking the type of leaf nodes, we can also avoid the creation of temporary strings for conversions operations (such as appending an integer to a string). A Twine is not intended for use directly and should not be stored, its implementation relies on the ability to store pointers to temporary stack objects which may be deallocated at the end of a statement. Twines should only be used accepted as const references in arguments, when an API wishes to accept possibly-concatenated strings. Twines support a special 'null' value, which always concatenates to form itself, and renders as an empty string. This can be returned from APIs to effectively nullify any concatenations performed on the result. \b Implementation Given the nature of a Twine, it is not possible for the Twine's concatenation method to construct interior nodes; the result must be represented inside the returned value. For this reason a Twine object actually holds two values, the left- and right-hand sides of a concatenation. We also have nullary Twine objects, which are effectively sentinel values that represent empty strings. Thus, a Twine can effectively have zero, one, or two children. The We maintain a number of invariants on Twine objects (FIXME: Why): - Nullary twines are always represented with their Kind on the left-hand side, and the Empty kind on the right-hand side. - Unary twines are always represented with the value on the left-hand side, and the Empty kind on the right-hand side. - If a Twine has another Twine as a child, that child should always be binary (otherwise it could have been folded into the parent). These invariants are check by \b Efficiency Considerations The Twine is designed to yield efficient and small code for common situations. For this reason, the concat() method is inlined so that concatenations of leaf nodes can be optimized into stores directly into a single stack allocated object. In practice, not all compilers can be trusted to optimize concat() fully, so we provide two additional methods (and accompanying operator+ overloads) to guarantee that particularly important cases (cstring plus StringRef) codegen as desired.

Declared at: llvm/include/llvm/ADT/Twine.h:83

Member Variables

private llvm::Twine::Child LHS
LHS - The prefix in the concatenation, which may be uninitialized for Null or Empty kinds.
private llvm::Twine::Child RHS
RHS - The suffix in the concatenation, which may be uninitialized for Null or Empty kinds.
private llvm::Twine::NodeKind LHSKind = EmptyKind
LHSKind - The NodeKind of the left hand side,
private llvm::Twine::NodeKind RHSKind = EmptyKind
RHSKind - The NodeKind of the right hand side,

Method Overview

  • private Twine(const llvm::Twine & LHS, const llvm::Twine & RHS)
  • public Twine(const llvm::StringRef & LHS, const char * RHS)
  • public Twine(const char * LHS, const llvm::StringRef & RHS)
  • public Twine(const long long & Val)
  • public Twine(const unsigned long long & Val)
  • public Twine(const long & Val)
  • public Twine(const unsigned long & Val)
  • public Twine(int Val)
  • public Twine(unsigned int Val)
  • public Twine(unsigned char Val)
  • public Twine(signed char Val)
  • public Twine(char Val)
  • public Twine(const llvm::formatv_object_base & Fmt)
  • public Twine(const SmallVectorImpl<char> & Str)
  • public Twine(const llvm::StringRef & Str)
  • public Twine(const std::string & Str)
  • public Twine(const char * Str)
  • private Twine(llvm::Twine::NodeKind Kind)
  • private Twine(llvm::Twine::Child LHS, llvm::Twine::NodeKind LHSKind, llvm::Twine::Child RHS, llvm::Twine::NodeKind RHSKind)
  • public Twine()
  • public Twine(std::nullptr_t)
  • public Twine(const llvm::Twine &)
  • public llvm::Twine concat(const llvm::Twine & Suffix) const
  • public static llvm::Twine createNull()
  • public void dump() const
  • public void dumpRepr() const
  • private llvm::Twine::NodeKind getLHSKind() const
  • private llvm::Twine::NodeKind getRHSKind() const
  • public llvm::StringRef getSingleStringRef() const
  • private bool isBinary() const
  • private bool isEmpty() const
  • private bool isNull() const
  • private bool isNullary() const
  • public bool isSingleStringRef() const
  • public bool isTriviallyEmpty() const
  • private bool isUnary() const
  • private bool isValid() const
  • public void print(llvm::raw_ostream & OS) const
  • private void printOneChild(llvm::raw_ostream & OS, llvm::Twine::Child Ptr, llvm::Twine::NodeKind Kind) const
  • private void printOneChildRepr(llvm::raw_ostream & OS, llvm::Twine::Child Ptr, llvm::Twine::NodeKind Kind) const
  • public void printRepr(llvm::raw_ostream & OS) const
  • public std::string str() const
  • public llvm::StringRef toNullTerminatedStringRef(SmallVectorImpl<char> & Out) const
  • public llvm::StringRef toStringRef(SmallVectorImpl<char> & Out) const
  • public void toVector(SmallVectorImpl<char> & Out) const
  • public static llvm::Twine utohexstr(const uint64_t & Val)

Methods

Twine(const llvm::Twine& LHS,
      const llvm::Twine& RHS)

Description

Construct a binary twine.

Declared at: llvm/include/llvm/ADT/Twine.h:178

Parameters

const llvm::Twine& LHS
const llvm::Twine& RHS

Twine(const llvm::StringRef& LHS, const char* RHS)

Description

Construct as the concatenation of a StringRef and a C string.

Declared at: llvm/include/llvm/ADT/Twine.h:385

Parameters

const llvm::StringRef& LHS
const char* RHS

Twine(const char* LHS, const llvm::StringRef& RHS)

Description

Construct as the concatenation of a C string and a StringRef.

Declared at: llvm/include/llvm/ADT/Twine.h:376

Parameters

const char* LHS
const llvm::StringRef& RHS

Twine(const long long& Val)

Description

Construct a twine to print \p Val as a signed decimal integer.

Declared at: llvm/include/llvm/ADT/Twine.h:366

Parameters

const long long& Val

Twine(const unsigned long long& Val)

Description

Construct a twine to print \p Val as an unsigned decimal integer.

Declared at: llvm/include/llvm/ADT/Twine.h:361

Parameters

const unsigned long long& Val

Twine(const long& Val)

Description

Construct a twine to print \p Val as a signed decimal integer.

Declared at: llvm/include/llvm/ADT/Twine.h:356

Parameters

const long& Val

Twine(const unsigned long& Val)

Description

Construct a twine to print \p Val as an unsigned decimal integer.

Declared at: llvm/include/llvm/ADT/Twine.h:351

Parameters

const unsigned long& Val

Twine(int Val)

Description

Construct a twine to print \p Val as a signed decimal integer.

Declared at: llvm/include/llvm/ADT/Twine.h:346

Parameters

int Val

Twine(unsigned int Val)

Description

Construct a twine to print \p Val as an unsigned decimal integer.

Declared at: llvm/include/llvm/ADT/Twine.h:341

Parameters

unsigned int Val

Twine(unsigned char Val)

Description

Construct from an unsigned char.

Declared at: llvm/include/llvm/ADT/Twine.h:336

Parameters

unsigned char Val

Twine(signed char Val)

Description

Construct from a signed char.

Declared at: llvm/include/llvm/ADT/Twine.h:331

Parameters

signed char Val

Twine(char Val)

Description

Construct from a char.

Declared at: llvm/include/llvm/ADT/Twine.h:326

Parameters

char Val

Twine(const llvm::formatv_object_base& Fmt)

Description

Construct from a formatv_object_base.

Declared at: llvm/include/llvm/ADT/Twine.h:319

Parameters

const llvm::formatv_object_base& Fmt

Twine(const SmallVectorImpl<char>& Str)

Description

Construct from a SmallString.

Declared at: llvm/include/llvm/ADT/Twine.h:311

Parameters

const SmallVectorImpl<char>& Str

Twine(const llvm::StringRef& Str)

Description

Construct from a StringRef.

Declared at: llvm/include/llvm/ADT/Twine.h:304

Parameters

const llvm::StringRef& Str

Twine(const std::string& Str)

Description

Construct from an std::string.

Declared at: llvm/include/llvm/ADT/Twine.h:285

Parameters

const std::string& Str

Twine(const char* Str)

Description

Construct from a C string. We take care here to optimize "" into the empty twine -- this will be optimized out for string constants. This allows Twine arguments have default "" values, without introducing unnecessary string constants.

Declared at: llvm/include/llvm/ADT/Twine.h:271

Parameters

const char* Str

Twine(llvm::Twine::NodeKind Kind)

Description

Construct a nullary twine; the kind must be NullKind or EmptyKind.

Declared at: llvm/include/llvm/ADT/Twine.h:173

Parameters

llvm::Twine::NodeKind Kind

Twine(llvm::Twine::Child LHS,
      llvm::Twine::NodeKind LHSKind,
      llvm::Twine::Child RHS,
      llvm::Twine::NodeKind RHSKind)

Description

Construct a twine from explicit values.

Declared at: llvm/include/llvm/ADT/Twine.h:186

Parameters

llvm::Twine::Child LHS
llvm::Twine::NodeKind LHSKind
llvm::Twine::Child RHS
llvm::Twine::NodeKind RHSKind

Twine()

Description

Construct from an empty string.

Declared at: llvm/include/llvm/ADT/Twine.h:260

Twine(std::nullptr_t)

Description

Delete the implicit conversion from nullptr as Twine(const char *) cannot take nullptr.

Declared at: llvm/include/llvm/ADT/Twine.h:282

Parameters

std::nullptr_t

Twine(const llvm::Twine&)

Declared at: llvm/include/llvm/ADT/Twine.h:264

Parameters

const llvm::Twine&

llvm::Twine concat(
    const llvm::Twine& Suffix) const

Description

@ } @ {

Declared at: llvm/include/llvm/ADT/Twine.h:445

Parameters

const llvm::Twine& Suffix

static llvm::Twine createNull()

Description

Create a 'null' string, which is an empty string that always concatenates to form another empty string.

Declared at: llvm/include/llvm/ADT/Twine.h:399

void dump() const

Description

Dump the concatenated string represented by this twine to stderr.

Declared at: llvm/include/llvm/ADT/Twine.h:496

void dumpRepr() const

Description

Dump the representation of this twine to stderr.

Declared at: llvm/include/llvm/ADT/Twine.h:502

llvm::Twine::NodeKind getLHSKind() const

Description

Get the NodeKind of the left-hand side.

Declared at: llvm/include/llvm/ADT/Twine.h:243

llvm::Twine::NodeKind getRHSKind() const

Description

Get the NodeKind of the right-hand side.

Declared at: llvm/include/llvm/ADT/Twine.h:246

llvm::StringRef getSingleStringRef() const

Description

This returns the twine as a single StringRef. This method is only valid if isSingleStringRef() is true.

Declared at: llvm/include/llvm/ADT/Twine.h:459

bool isBinary() const

Description

Check if this is a binary twine.

Declared at: llvm/include/llvm/ADT/Twine.h:212

bool isEmpty() const

Description

Check for the empty twine.

Declared at: llvm/include/llvm/ADT/Twine.h:197

bool isNull() const

Description

Check for the null twine.

Declared at: llvm/include/llvm/ADT/Twine.h:192

bool isNullary() const

Description

Check if this is a nullary twine (null or empty).

Declared at: llvm/include/llvm/ADT/Twine.h:202

bool isSingleStringRef() const

Description

Return true if this twine can be dynamically accessed as a single StringRef value with getSingleStringRef().

Declared at: llvm/include/llvm/ADT/Twine.h:427

bool isTriviallyEmpty() const

Description

Check if this twine is trivially empty; a false return value does not necessarily mean the twine is empty.

Declared at: llvm/include/llvm/ADT/Twine.h:421

bool isUnary() const

Description

Check if this is a unary twine.

Declared at: llvm/include/llvm/ADT/Twine.h:207

bool isValid() const

Description

Check if this is a valid twine (satisfying the invariants on order and number of arguments).

Declared at: llvm/include/llvm/ADT/Twine.h:218

void print(llvm::raw_ostream& OS) const

Description

Write the concatenated string represented by this twine to the stream \p OS.

Declared at: llvm/include/llvm/ADT/Twine.h:493

Parameters

llvm::raw_ostream& OS

void printOneChild(
    llvm::raw_ostream& OS,
    llvm::Twine::Child Ptr,
    llvm::Twine::NodeKind Kind) const

Description

Print one child from a twine.

Declared at: llvm/include/llvm/ADT/Twine.h:249

Parameters

llvm::raw_ostream& OS
llvm::Twine::Child Ptr
llvm::Twine::NodeKind Kind

void printOneChildRepr(
    llvm::raw_ostream& OS,
    llvm::Twine::Child Ptr,
    llvm::Twine::NodeKind Kind) const

Description

Print the representation of one child from a twine.

Declared at: llvm/include/llvm/ADT/Twine.h:252

Parameters

llvm::raw_ostream& OS
llvm::Twine::Child Ptr
llvm::Twine::NodeKind Kind

void printRepr(llvm::raw_ostream& OS) const

Description

Write the representation of this twine to the stream \p OS.

Declared at: llvm/include/llvm/ADT/Twine.h:499

Parameters

llvm::raw_ostream& OS

std::string str() const

Description

Return the twine contents as a std::string.

Declared at: llvm/include/llvm/ADT/Twine.h:452

llvm::StringRef toNullTerminatedStringRef(
    SmallVectorImpl<char>& Out) const

Description

This returns the twine as a single null terminated StringRef if it can be represented as such. Otherwise the twine is written into the given SmallVector and a StringRef to the SmallVector's data is returned. The returned StringRef's size does not include the null terminator.

Declared at: llvm/include/llvm/ADT/Twine.h:489

Parameters

SmallVectorImpl<char>& Out

llvm::StringRef toStringRef(
    SmallVectorImpl<char>& Out) const

Description

This returns the twine as a single StringRef if it can be represented as such. Otherwise the twine is written into the given SmallVector and a StringRef to the SmallVector's data is returned.

Declared at: llvm/include/llvm/ADT/Twine.h:477

Parameters

SmallVectorImpl<char>& Out

void toVector(SmallVectorImpl<char>& Out) const

Description

Append the concatenated string into the given SmallString or SmallVector.

Declared at: llvm/include/llvm/ADT/Twine.h:455

Parameters

SmallVectorImpl<char>& Out

static llvm::Twine utohexstr(const uint64_t& Val)

Description

@ } @ {

Declared at: llvm/include/llvm/ADT/Twine.h:408

Parameters

const uint64_t& Val