clang API Documentation
#include <Expr.h>
Public Types | |
enum | StringKind { Ascii, Wide, UTF8, UTF16, UTF32 } |
typedef const SourceLocation * | tokloc_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 StringLiteral * | Create (const ASTContext &C, StringRef Str, StringKind Kind, bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumStrs) |
static StringLiteral * | Create (const ASTContext &C, StringRef Str, StringKind Kind, bool Pascal, QualType Ty, SourceLocation Loc) |
Simple constructor for string literals made from one token. | |
static StringLiteral * | CreateEmpty (const ASTContext &C, unsigned NumStrs) |
Construct an empty string literal. | |
static bool | classof (const Stmt *T) |
Friends | |
class | ASTStmtReader |
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]".
typedef const SourceLocation* clang::StringLiteral::tokloc_iterator |
child_range clang::StringLiteral::children | ( | ) | [inline] |
Reimplemented from clang::Stmt.
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().
bool clang::StringLiteral::containsNonAsciiOrNull | ( | ) | const [inline] |
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] |
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().
unsigned clang::StringLiteral::getByteLength | ( | ) | const [inline] |
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().
unsigned clang::StringLiteral::getCharByteWidth | ( | ) | const [inline] |
Definition at line 1546 of file Expr.h.
Referenced by expandStringLiteral(), extractStringLiteralCharacter(), and clang::CodeGen::CodeGenModule::GetConstantArrayFromStringLiteral().
uint32_t clang::StringLiteral::getCodeUnit | ( | size_t | i | ) | const [inline] |
Definition at line 1534 of file Expr.h.
Referenced by clang::Sema::ActOnStringLiteral(), expandStringLiteral(), extractStringLiteralCharacter(), clang::CodeGen::CodeGenModule::GetConstantArrayFromStringLiteral(), and outputString().
StringKind clang::StringLiteral::getKind | ( | ) | const [inline] |
Definition at line 1552 of file Expr.h.
Referenced by IsStringInit(), and outputString().
unsigned clang::StringLiteral::getLength | ( | ) | const [inline] |
Definition at line 1545 of file Expr.h.
Referenced by clang::Sema::ActOnStringLiteral(), diagnoseStringPlusInt(), expandStringLiteral(), clang::CodeGen::CodeGenModule::GetConstantArrayFromStringLiteral(), 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().
SourceLocation clang::StringLiteral::getLocEnd | ( | ) | const [inline] |
Reimplemented from clang::Stmt.
SourceLocation clang::StringLiteral::getLocStart | ( | ) | const [inline] |
Reimplemented from clang::Stmt.
Definition at line 1598 of file Expr.h.
Referenced by clang::Sema::ActOnGCCAsmStmt(), clang::Sema::BuildObjCStringLiteral(), clang::Sema::CheckFormatString(), clang::Sema::ConversionToObjCStringLiteralCheck(), getAsmSrcLocInfo(), and clang::Sema::ParseObjCStringLiteral().
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 1572 of file Expr.h.
Referenced by getLocationOfByte().
StringRef clang::StringLiteral::getString | ( | ) | const [inline] |
Definition at line 1512 of file Expr.h.
References getByteLength().
Referenced by clang::Sema::ActOnFunctionDeclarator(), clang::Sema::ActOnGCCAsmStmt(), clang::Sema::ActOnPragmaMSInitSeg(), clang::Sema::ActOnPragmaMSSection(), clang::Sema::ActOnStartLinkageSpecification(), clang::Sema::ActOnVariableDeclarator(), clang::GCCAsmStmt::AnalyzeAsmString(), clang::Sema::CheckCompleteVariableDeclaration(), clang::Sema::CheckFormatString(), checkFormatStringExpr(), CheckObjCCollectionLiteralElement(), clang::Sema::checkStringLiteralArgumentAttr(), containsNonAsciiOrNull(), DiagnoseCStringFormatDirectiveInCFAPI(), DiagnoseCStringFormatDirectiveInObjCAPI(), clang::Sema::FormatStringHasSArg(), getAsmSrcLocInfo(), clang::GCCAsmStmt::getClobber(), clang::CodeGen::CodeGenModule::GetConstantArrayFromStringLiteral(), GetConstantCFStringEntry(), GetConstantStringEntry(), clang::GCCAsmStmt::getInputConstraint(), clang::GCCAsmStmt::getOutputConstraint(), clang::Sema::ParseObjCStringLiteral(), and TryEvaluateBuiltinNaN().
SourceLocation clang::StringLiteral::getStrTokenLoc | ( | unsigned | TokNum | ) | const [inline] |
Definition at line 1574 of file Expr.h.
Referenced by clang::Sema::ActOnFunctionDeclarator(), clang::Sema::ActOnVariableDeclarator(), clang::CodeGen::CodeGenModule::GetAddrOfConstantStringFromLiteral(), and getLocationOfByte().
bool clang::StringLiteral::isAscii | ( | ) | const [inline] |
Definition at line 1555 of file Expr.h.
References Ascii.
Referenced by clang::Sema::ActOnGCCAsmStmt(), clang::Sema::ActOnStartLinkageSpecification(), clang::Sema::CheckFormatString(), clang::Sema::checkStringLiteralArgumentAttr(), clang::Sema::ConversionToObjCStringLiteralCheck(), clang::Sema::ParseObjCStringLiteral(), and SemaBuiltinAnnotation().
bool clang::StringLiteral::isPascal | ( | ) | const [inline] |
bool clang::StringLiteral::isUTF16 | ( | ) | const [inline] |
bool clang::StringLiteral::isUTF32 | ( | ) | const [inline] |
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] |
void StringLiteral::outputString | ( | raw_ostream & | OS | ) | const |
Definition at line 868 of file Expr.cpp.
References Ascii, getCodeUnit(), getKind(), getLength(), clang::isPrintable(), clang::prec::Shift, UTF16, UTF32, UTF8, and Wide.
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().
void clang::StringLiteral::setStrTokenLoc | ( | unsigned | TokNum, |
SourceLocation | L | ||
) | [inline] |
tokloc_iterator clang::StringLiteral::tokloc_begin | ( | ) | const [inline] |
Definition at line 1595 of file Expr.h.
Referenced by clang::Sema::ParseObjCStringLiteral().
tokloc_iterator clang::StringLiteral::tokloc_end | ( | ) | const [inline] |
Definition at line 1596 of file Expr.h.
Referenced by clang::Sema::ParseObjCStringLiteral().
friend class ASTStmtReader [friend] |
Reimplemented from clang::Stmt.
const char* clang::StringLiteral::asChar |
const uint16_t* clang::StringLiteral::asUInt16 |
const uint32_t* clang::StringLiteral::asUInt32 |