clang API Documentation

Public Types | Public Member Functions | Static Public Member Functions | Friends
clang::StringLiteral Class Reference

#include <Expr.h>

Inheritance diagram for clang::StringLiteral:
Inheritance graph
[legend]
Collaboration diagram for clang::StringLiteral:
Collaboration graph
[legend]

List of all members.

Public Types

enum  StringKind {
  Ascii, Wide, UTF8, UTF16,
  UTF32
}
typedef const SourceLocationtokloc_iterator

Public Member Functions

StringRef getString () const
StringRef getBytes () const
uint32_t getCodeUnit (size_t i) const
unsigned getByteLength () const
unsigned getLength () const
unsigned getCharByteWidth () const
void setString (ASTContext &C, StringRef Str, StringKind Kind, bool IsPascal)
 Sets the string data to the given string data.
StringKind getKind () const
bool isAscii () const
bool isWide () const
bool isUTF8 () const
bool isUTF16 () const
bool isUTF32 () const
bool isPascal () const
bool containsNonAsciiOrNull () const
unsigned getNumConcatenated () const
SourceLocation getStrTokenLoc (unsigned TokNum) const
void setStrTokenLoc (unsigned TokNum, SourceLocation L)
SourceLocation getLocationOfByte (unsigned ByteNo, const SourceManager &SM, const LangOptions &Features, const TargetInfo &Target) const
tokloc_iterator tokloc_begin () const
tokloc_iterator tokloc_end () const
SourceRange getSourceRange () const LLVM_READONLY
child_range children ()

Static Public Member Functions

static StringLiteralCreate (ASTContext &C, StringRef Str, StringKind Kind, bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumStrs)
static StringLiteralCreate (ASTContext &C, StringRef Str, StringKind Kind, bool Pascal, QualType Ty, SourceLocation Loc)
 Simple constructor for string literals made from one token.
static StringLiteralCreateEmpty (ASTContext &C, unsigned NumStrs)
 Construct an empty string literal.
static bool classof (const Stmt *T)
static bool classof (const StringLiteral *)

Friends

class ASTStmtReader

Detailed Description

StringLiteral - This represents a string literal expression, e.g. "foo" or L"bar" (wide strings). The actual string is returned by getStrData() is NOT null-terminated, and the length of the string 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]".

Definition at line 1330 of file Expr.h.


Member Typedef Documentation

Definition at line 1458 of file Expr.h.


Member Enumeration Documentation

Enumerator:
Ascii 
Wide 
UTF8 
UTF16 
UTF32 

Definition at line 1332 of file Expr.h.


Member Function Documentation

child_range clang::StringLiteral::children ( ) [inline]

Reimplemented from clang::Stmt.

Definition at line 1471 of file Expr.h.

static bool clang::StringLiteral::classof ( const Stmt T) [inline, static]

Reimplemented from clang::Expr.

Definition at line 1465 of file Expr.h.

References clang::Stmt::getStmtClass().

static bool clang::StringLiteral::classof ( const StringLiteral ) [inline, static]

Definition at line 1468 of file Expr.h.

bool clang::StringLiteral::containsNonAsciiOrNull ( ) const [inline]

Definition at line 1426 of file Expr.h.

References getString().

Referenced by GetConstantCFStringEntry().

StringLiteral * StringLiteral::Create ( ASTContext C,
StringRef  Str,
StringKind  Kind,
bool  Pascal,
QualType  Ty,
const SourceLocation Loc,
unsigned  NumStrs 
) [static]

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

Definition at line 603 of file Expr.cpp.

References clang::ASTContext::Allocate(), and setString().

Referenced by clang::Sema::ActOnNumericConstant(), clang::Sema::ActOnStringLiteral(), Create(), and clang::Sema::ParseObjCStringLiteral().

static StringLiteral* clang::StringLiteral::Create ( ASTContext C,
StringRef  Str,
StringKind  Kind,
bool  Pascal,
QualType  Ty,
SourceLocation  Loc 
) [inline, static]

Simple constructor for string literals made from one token.

Definition at line 1369 of file Expr.h.

References Create().

StringLiteral * StringLiteral::CreateEmpty ( ASTContext C,
unsigned  NumStrs 
) [static]

Construct an empty string literal.

Definition at line 625 of file Expr.cpp.

References clang::ASTContext::Allocate().

unsigned clang::StringLiteral::getByteLength ( ) const [inline]

Definition at line 1408 of file Expr.h.

Referenced by getBytes(), and getString().

StringRef clang::StringLiteral::getBytes ( ) const [inline]

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

Definition at line 1386 of file Expr.h.

References getByteLength().

unsigned clang::StringLiteral::getCharByteWidth ( ) const [inline]
uint32_t clang::StringLiteral::getCodeUnit ( size_t  i) const [inline]
StringKind clang::StringLiteral::getKind ( ) const [inline]

Definition at line 1416 of file Expr.h.

Referenced by IsStringInit().

unsigned clang::StringLiteral::getLength ( ) const [inline]
SourceLocation StringLiteral::getLocationOfByte ( unsigned  ByteNo,
const SourceManager SM,
const LangOptions Features,
const TargetInfo Target 
) const

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.

Definition at line 680 of file Expr.cpp.

References clang::Lexer::AdvanceToTokenCharacter(), Ascii, clang::SourceManager::getBufferData(), clang::SourceManager::getDecomposedLoc(), clang::SourceManager::getLocForStartOfFile(), getNumConcatenated(), clang::StringLiteralParser::getOffsetOfStringByte(), clang::SourceManager::getSpellingLoc(), clang::StringLiteralParser::GetStringLength(), and getStrTokenLoc().

Referenced by getAsmSrcLocInfo(), and clang::Sema::getLocationOfStringLiteralByte().

unsigned clang::StringLiteral::getNumConcatenated ( ) const [inline]

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

Definition at line 1436 of file Expr.h.

Referenced by getLocationOfByte().

SourceRange clang::StringLiteral::getSourceRange ( ) const [inline]

SourceLocation tokens are not useful in isolation - they are low level value objects created/interpreted by SourceManager. We assume AST clients will have a pointer to the respective SourceManager.

Reimplemented from clang::Stmt.

Definition at line 1462 of file Expr.h.

Referenced by clang::Sema::ActOnAsmStmt(), clang::Sema::BuildObjCStringLiteral(), and clang::Sema::ParseObjCStringLiteral().

StringRef clang::StringLiteral::getString ( ) const [inline]
SourceLocation clang::StringLiteral::getStrTokenLoc ( unsigned  TokNum) const [inline]
bool clang::StringLiteral::isAscii ( ) const [inline]
bool clang::StringLiteral::isPascal ( ) const [inline]

Definition at line 1424 of file Expr.h.

bool clang::StringLiteral::isUTF16 ( ) const [inline]

Definition at line 1422 of file Expr.h.

References UTF16.

bool clang::StringLiteral::isUTF32 ( ) const [inline]

Definition at line 1423 of file Expr.h.

References UTF32.

bool clang::StringLiteral::isUTF8 ( ) const [inline]

Definition at line 1421 of file Expr.h.

References UTF8.

Referenced by clang::CodeGen::CodeGenModule::GetAddrOfConstantStringFromLiteral().

bool clang::StringLiteral::isWide ( ) const [inline]

Definition at line 1420 of file Expr.h.

References Wide.

void StringLiteral::setString ( ASTContext C,
StringRef  Str,
StringKind  Kind,
bool  IsPascal 
)

Sets the string data to the given string data.

Definition at line 636 of file Expr.cpp.

References clang::ASTContext::getTargetInfo().

Referenced by Create().

void clang::StringLiteral::setStrTokenLoc ( unsigned  TokNum,
SourceLocation  L 
) [inline]

Definition at line 1442 of file Expr.h.

tokloc_iterator clang::StringLiteral::tokloc_begin ( ) const [inline]

Definition at line 1459 of file Expr.h.

Referenced by clang::Sema::ParseObjCStringLiteral().

tokloc_iterator clang::StringLiteral::tokloc_end ( ) const [inline]

Definition at line 1460 of file Expr.h.

Referenced by clang::Sema::ParseObjCStringLiteral().


Friends And Related Function Documentation

friend class ASTStmtReader [friend]

Reimplemented from clang::Stmt.

Definition at line 1341 of file Expr.h.


Member Data Documentation

Definition at line 1344 of file Expr.h.

Definition at line 1345 of file Expr.h.

Definition at line 1346 of file Expr.h.


The documentation for this class was generated from the following files: