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
void outputString (raw_ostream &OS) const
uint32_t getCodeUnit (size_t i) const
unsigned getByteLength () const
unsigned getLength () const
unsigned getCharByteWidth () const
void setString (const 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
 getLocationOfByte - Return a source location that points to the specified byte of this string literal.
tokloc_iterator tokloc_begin () const
tokloc_iterator tokloc_end () const
SourceLocation getLocStart () const LLVM_READONLY
SourceLocation getLocEnd () const LLVM_READONLY
child_range children ()

Static Public Member Functions

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

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 getBytes() 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 1464 of file Expr.h.


Member Typedef Documentation

Definition at line 1594 of file Expr.h.


Member Enumeration Documentation

Enumerator:
Ascii 
Wide 
UTF8 
UTF16 
UTF32 

Definition at line 1466 of file Expr.h.


Member Function Documentation

Reimplemented from clang::Stmt.

Definition at line 1608 of file Expr.h.

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

Reimplemented from clang::Expr.

Definition at line 1603 of file Expr.h.

References clang::Stmt::getStmtClass().

Definition at line 1562 of file Expr.h.

References getString(), and clang::isASCII().

Referenced by GetConstantCFStringEntry().

StringLiteral * StringLiteral::Create ( const 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 831 of file Expr.cpp.

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

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

static StringLiteral* clang::StringLiteral::Create ( const 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 1503 of file Expr.h.

References Create().

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

Construct an empty string literal.

Definition at line 856 of file Expr.cpp.

References clang::ASTContext::Allocate().

Definition at line 1544 of file Expr.h.

Referenced by getBytes(), and getString().

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

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

Definition at line 1520 of file Expr.h.

References getByteLength().

Referenced by isIdenticalStmt().

uint32_t clang::StringLiteral::getCodeUnit ( size_t  i) const [inline]

Definition at line 1552 of file Expr.h.

Referenced by IsStringInit(), and outputString().

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.

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.

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 1005 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(), getStrTokenLoc(), and UTF8.

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

Reimplemented from clang::Stmt.

Definition at line 1599 of file Expr.h.

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

Definition at line 1572 of file Expr.h.

Referenced by getLocationOfByte().

StringRef clang::StringLiteral::getString ( ) const [inline]
bool clang::StringLiteral::isAscii ( ) const [inline]

Definition at line 1560 of file Expr.h.

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

Definition at line 1558 of file Expr.h.

References UTF16.

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

Definition at line 1559 of file Expr.h.

References UTF32.

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

Definition at line 1557 of file Expr.h.

References UTF8.

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

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

Definition at line 1556 of file Expr.h.

References Wide.

void StringLiteral::outputString ( raw_ostream &  OS) const
void StringLiteral::setString ( const ASTContext C,
StringRef  Str,
StringKind  Kind,
bool  IsPascal 
)

Sets the string data to the given string data.

Definition at line 961 of file Expr.cpp.

References AttributeLangSupport::C, and clang::ASTContext::getTargetInfo().

Referenced by Create().

Definition at line 1578 of file Expr.h.

Definition at line 1595 of file Expr.h.

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

Definition at line 1596 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 1475 of file Expr.h.


Member Data Documentation

Definition at line 1478 of file Expr.h.

Definition at line 1479 of file Expr.h.

Definition at line 1480 of file Expr.h.


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