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:80

Method Overview

  • public Twine(const llvm::Twine &)
  • 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(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(std::nullptr_t)
  • public Twine(const char * Str)
  • public Twine()
  • public Twine(signed char Val)
  • public llvm::Twine concat(const llvm::Twine & Suffix) const
  • public static llvm::Twine createNull()
  • public void dump() const
  • public void dumpRepr() const
  • public llvm::StringRef getSingleStringRef() const
  • public bool isSingleStringRef() const
  • public bool isTriviallyEmpty() const
  • public void print(llvm::raw_ostream & OS) 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&)

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

Parameters

const llvm::Twine&

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:365

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:357

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:347

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:342

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:337

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:332

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:327

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:322

Parameters

unsigned int Val

Twine(unsigned char Val)

Description

Construct from an unsigned char.

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

Parameters

unsigned char Val

Twine(char Val)

Description

Construct from a char.

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

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:300

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:293

Parameters

const SmallVectorImpl<char>& Str

Twine(const llvm::StringRef& Str)

Description

Construct from a StringRef.

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

Parameters

const llvm::StringRef& Str

Twine(const std::string& Str)

Description

Construct from an std::string.

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

Parameters

const std::string& Str

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:278

Parameters

std::nullptr_t

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:267

Parameters

const char* Str

Twine()

Description

Construct from an empty string.

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

Twine(signed char Val)

Description

Construct from a signed char.

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

Parameters

signed char Val

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

Description

@ } @ {

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

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:378

void dump() const

Description

Dump the concatenated string represented by this twine to stderr.

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

void dumpRepr() const

Description

Dump the representation of this twine to stderr.

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

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:439

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:406

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:400

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:471

Parameters

llvm::raw_ostream& OS

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:477

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:432

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:467

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:455

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:435

Parameters

SmallVectorImpl<char>& Out

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

Description

@ } @ {

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

Parameters

const uint64_t& Val