class StringLiteral

Declaration

class StringLiteral : public Expr, private TrailingObjects { /* full declaration omitted */ };

Description

StringLiteral - This represents a string literal expression, e.g. "foo" or L"bar" (wide strings). The actual string data can be obtained with getBytes() and is NOT null-terminated. The length of the string data is determined by calling getByteLength(). The C type for a string is always a ConstantArrayType. In C++, the char type is const qualified, in C it is not. Note that strings in C can be formed by concatenation of multiple string literal pptokens in translation phase #6. This keeps track of the locations of each of these pieces. Strings in C can also be truncated and extended by assigning into arrays, e.g. with constructs like: char X[2] = "foobar"; In this case, getByteLength() will return 6, but the string literal will have type "char[2]".

Declared at: clang/include/clang/AST/Expr.h:1767

Inherits from: Expr, TrailingObjects

Member Variables

Inherited from Stmt:

protected

Method Overview

  • public static clang::StringLiteral * Create(const clang::ASTContext & Ctx, llvm::StringRef Str, clang::StringLiteral::StringKind Kind, bool Pascal, clang::QualType Ty, const clang::SourceLocation * Loc, unsigned int NumConcatenated)
  • public static clang::StringLiteral * Create(const clang::ASTContext & Ctx, llvm::StringRef Str, clang::StringLiteral::StringKind Kind, bool Pascal, clang::QualType Ty, clang::SourceLocation Loc)
  • public static clang::StringLiteral * CreateEmpty(const clang::ASTContext & Ctx, unsigned int NumConcatenated, unsigned int Length, unsigned int CharByteWidth)
  • private StringLiteral(const clang::ASTContext & Ctx, llvm::StringRef Str, clang::StringLiteral::StringKind Kind, bool Pascal, clang::QualType Ty, const clang::SourceLocation * Loc, unsigned int NumConcatenated)
  • private StringLiteral(clang::Stmt::EmptyShell Empty, unsigned int NumConcatenated, unsigned int Length, unsigned int CharByteWidth)
  • public clang::Stmt::const_child_range children() const
  • public clang::Stmt::child_range children()
  • public static bool classof(const clang::Stmt * T)
  • public bool containsNonAscii() const
  • public bool containsNonAsciiOrNull() const
  • public clang::SourceLocation getBeginLoc() const
  • public unsigned int getByteLength() const
  • public llvm::StringRef getBytes() const
  • public unsigned int getCharByteWidth() const
  • public uint32_t getCodeUnit(size_t i) const
  • public clang::SourceLocation getEndLoc() const
  • public clang::StringLiteral::StringKind getKind() const
  • public unsigned int getLength() const
  • public clang::SourceLocation getLocationOfByte(unsigned int ByteNo, const clang::SourceManager & SM, const clang::LangOptions & Features, const clang::TargetInfo & Target, unsigned int * StartToken = nullptr, unsigned int * StartTokenByteOffset = nullptr) const
  • public unsigned int getNumConcatenated() const
  • private const char * getStrDataAsChar() const
  • private char * getStrDataAsChar()
  • private const uint16_t * getStrDataAsUInt16() const
  • private const uint32_t * getStrDataAsUInt32() const
  • public clang::SourceLocation getStrTokenLoc(unsigned int TokNum) const
  • public llvm::StringRef getString() const
  • public bool isOrdinary() const
  • public bool isPascal() const
  • public bool isUTF16() const
  • public bool isUTF32() const
  • public bool isUTF8() const
  • public bool isWide() const
  • private static unsigned int mapCharByteWidth(const clang::TargetInfo & Target, clang::StringLiteral::StringKind SK)
  • private unsigned int numTrailingObjects(OverloadToken<char>) const
  • private unsigned int numTrailingObjects(OverloadToken<clang::SourceLocation>) const
  • private unsigned int numTrailingObjects(OverloadToken<unsigned int>) const
  • public void outputString(llvm::raw_ostream & OS) const
  • private void setStrTokenLoc(unsigned int TokNum, clang::SourceLocation L)
  • public clang::StringLiteral::tokloc_iterator tokloc_begin() const
  • public clang::StringLiteral::tokloc_iterator tokloc_end() const

Inherited from Expr:

Inherited from ValueStmt:

Inherited from Stmt:

Methods

static clang::StringLiteral* Create(
    const clang::ASTContext& Ctx,
    llvm::StringRef Str,
    clang::StringLiteral::StringKind Kind,
    bool Pascal,
    clang::QualType Ty,
    const clang::SourceLocation* Loc,
    unsigned int NumConcatenated)

Description

This is the "fully general" constructor that allows representation of strings formed from multiple concatenated tokens.

Declared at: clang/include/clang/AST/Expr.h:1833

Parameters

const clang::ASTContext& Ctx
llvm::StringRef Str
clang::StringLiteral::StringKind Kind
bool Pascal
clang::QualType Ty
const clang::SourceLocation* Loc
unsigned int NumConcatenated

static clang::StringLiteral* Create(
    const clang::ASTContext& Ctx,
    llvm::StringRef Str,
    clang::StringLiteral::StringKind Kind,
    bool Pascal,
    clang::QualType Ty,
    clang::SourceLocation Loc)

Description

Simple constructor for string literals made from one token.

Declared at: clang/include/clang/AST/Expr.h:1839

Parameters

const clang::ASTContext& Ctx
llvm::StringRef Str
clang::StringLiteral::StringKind Kind
bool Pascal
clang::QualType Ty
clang::SourceLocation Loc

static clang::StringLiteral* CreateEmpty(
    const clang::ASTContext& Ctx,
    unsigned int NumConcatenated,
    unsigned int Length,
    unsigned int CharByteWidth)

Description

Construct an empty string literal.

Declared at: clang/include/clang/AST/Expr.h:1846

Parameters

const clang::ASTContext& Ctx
unsigned int NumConcatenated
unsigned int Length
unsigned int CharByteWidth

StringLiteral(
    const clang::ASTContext& Ctx,
    llvm::StringRef Str,
    clang::StringLiteral::StringKind Kind,
    bool Pascal,
    clang::QualType Ty,
    const clang::SourceLocation* Loc,
    unsigned int NumConcatenated)

Description

Build a string literal.

Declared at: clang/include/clang/AST/Expr.h:1813

Parameters

const clang::ASTContext& Ctx
llvm::StringRef Str
clang::StringLiteral::StringKind Kind
bool Pascal
clang::QualType Ty
const clang::SourceLocation* Loc
unsigned int NumConcatenated

StringLiteral(clang::Stmt::EmptyShell Empty,
              unsigned int NumConcatenated,
              unsigned int Length,
              unsigned int CharByteWidth)

Description

Build an empty string literal.

Declared at: clang/include/clang/AST/Expr.h:1818

Parameters

clang::Stmt::EmptyShell Empty
unsigned int NumConcatenated
unsigned int Length
unsigned int CharByteWidth

clang::Stmt::const_child_range children() const

Declared at: clang/include/clang/AST/Expr.h:1953

clang::Stmt::child_range children()

Declared at: clang/include/clang/AST/Expr.h:1950

static bool classof(const clang::Stmt* T)

Declared at: clang/include/clang/AST/Expr.h:1945

Parameters

const clang::Stmt* T

bool containsNonAscii() const

Declared at: clang/include/clang/AST/Expr.h:1893

bool containsNonAsciiOrNull() const

Declared at: clang/include/clang/AST/Expr.h:1900

clang::SourceLocation getBeginLoc() const

Declared at: clang/include/clang/AST/Expr.h:1942

unsigned int getByteLength() const

Declared at: clang/include/clang/AST/Expr.h:1878

llvm::StringRef getBytes() const

Description

Allow access to clients that need the byte representation, such as ASTWriterStmt::VisitStringLiteral().

Declared at: clang/include/clang/AST/Expr.h:1858

unsigned int getCharByteWidth() const

Declared at: clang/include/clang/AST/Expr.h:1880

uint32_t getCodeUnit(size_t i) const

Declared at: clang/include/clang/AST/Expr.h:1865

Parameters

size_t i

clang::SourceLocation getEndLoc() const

Declared at: clang/include/clang/AST/Expr.h:1943

clang::StringLiteral::StringKind getKind() const

Declared at: clang/include/clang/AST/Expr.h:1882

unsigned int getLength() const

Declared at: clang/include/clang/AST/Expr.h:1879

clang::SourceLocation getLocationOfByte(
    unsigned int ByteNo,
    const clang::SourceManager& SM,
    const clang::LangOptions& Features,
    const clang::TargetInfo& Target,
    unsigned int* StartToken = nullptr,
    unsigned int* StartTokenByteOffset =
        nullptr) const

Description

getLocationOfByte - Return a source location that points to the specified byte of this string literal. Strings are amazingly complex. They can be formed from multiple tokens and can have escape sequences in them in addition to the usual trigraph and escaped newline business. This routine handles this complexity.

Declared at: clang/include/clang/AST/Expr.h:1927

Parameters

unsigned int ByteNo
const clang::SourceManager& SM
const clang::LangOptions& Features
const clang::TargetInfo& Target
unsigned int* StartToken = nullptr
unsigned int* StartTokenByteOffset = nullptr

unsigned int getNumConcatenated() const

Description

getNumConcatenated - Get the number of string literal tokens that were concatenated in translation phase #6 to form this string literal.

Declared at: clang/include/clang/AST/Expr.h:1909

const char* getStrDataAsChar() const

Declared at: clang/include/clang/AST/Expr.h:1802

char* getStrDataAsChar()

Declared at: clang/include/clang/AST/Expr.h:1801

const uint16_t* getStrDataAsUInt16() const

Declared at: clang/include/clang/AST/Expr.h:1804

const uint32_t* getStrDataAsUInt32() const

Declared at: clang/include/clang/AST/Expr.h:1808

clang::SourceLocation getStrTokenLoc(
    unsigned int TokNum) const

Description

Get one of the string literal token.

Declared at: clang/include/clang/AST/Expr.h:1914

Parameters

unsigned int TokNum

llvm::StringRef getString() const

Declared at: clang/include/clang/AST/Expr.h:1850

bool isOrdinary() const

Declared at: clang/include/clang/AST/Expr.h:1886

bool isPascal() const

Declared at: clang/include/clang/AST/Expr.h:1891

bool isUTF16() const

Declared at: clang/include/clang/AST/Expr.h:1889

bool isUTF32() const

Declared at: clang/include/clang/AST/Expr.h:1890

bool isUTF8() const

Declared at: clang/include/clang/AST/Expr.h:1888

bool isWide() const

Declared at: clang/include/clang/AST/Expr.h:1887

static unsigned int mapCharByteWidth(
    const clang::TargetInfo& Target,
    clang::StringLiteral::StringKind SK)

Description

Map a target and string kind to the appropriate character width.

Declared at: clang/include/clang/AST/Expr.h:1822

Parameters

const clang::TargetInfo& Target
clang::StringLiteral::StringKind SK

unsigned int numTrailingObjects(
    OverloadToken<char>) const

Declared at: clang/include/clang/AST/Expr.h:1797

Parameters

OverloadToken<char>

unsigned int numTrailingObjects(
    OverloadToken<clang::SourceLocation>) const

Declared at: clang/include/clang/AST/Expr.h:1793

Parameters

OverloadToken<clang::SourceLocation>

unsigned int numTrailingObjects(
    OverloadToken<unsigned int>) const

Declared at: clang/include/clang/AST/Expr.h:1792

Parameters

OverloadToken<unsigned int>

void outputString(llvm::raw_ostream& OS) const

Declared at: clang/include/clang/AST/Expr.h:1863

Parameters

llvm::raw_ostream& OS

void setStrTokenLoc(unsigned int TokNum,
                    clang::SourceLocation L)

Description

Set one of the string literal token.

Declared at: clang/include/clang/AST/Expr.h:1825

Parameters

unsigned int TokNum
clang::SourceLocation L

clang::StringLiteral::tokloc_iterator
tokloc_begin() const

Declared at: clang/include/clang/AST/Expr.h:1934

clang::StringLiteral::tokloc_iterator tokloc_end()
    const

Declared at: clang/include/clang/AST/Expr.h:1938