clang  3.7.0
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
clang::StringLiteral Class Reference

#include <Expr.h>

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

Public Types

enum  StringKind {
  Ascii, Wide, UTF8, UTF16,
  UTF32
}
 
typedef const SourceLocationtokloc_iterator
 
- Public Types inherited from clang::Expr
enum  LValueClassification {
  LV_Valid, LV_NotObjectType, LV_IncompleteVoidType, LV_DuplicateVectorComponents,
  LV_InvalidExpression, LV_InvalidMessageExpression, LV_MemberFunction, LV_SubObjCPropertySetting,
  LV_ClassTemporary, LV_ArrayTemporary
}
 
enum  isModifiableLvalueResult {
  MLV_Valid, MLV_NotObjectType, MLV_IncompleteVoidType, MLV_DuplicateVectorComponents,
  MLV_InvalidExpression, MLV_LValueCast, MLV_IncompleteType, MLV_ConstQualified,
  MLV_ConstAddrSpace, MLV_ArrayType, MLV_NoSetterProperty, MLV_MemberFunction,
  MLV_SubObjCPropertySetting, MLV_InvalidMessageExpression, MLV_ClassTemporary, MLV_ArrayTemporary
}
 
enum  SideEffectsKind { SE_NoSideEffects, SE_AllowSideEffects }
 
enum  NullPointerConstantKind {
  NPCK_NotNull = 0, NPCK_ZeroExpression, NPCK_ZeroLiteral, NPCK_CXX11_nullptr,
  NPCK_GNUNull
}
 Enumeration used to describe the kind of Null pointer constant returned from isNullPointerConstant(). More...
 
enum  NullPointerConstantValueDependence { NPC_NeverValueDependent = 0, NPC_ValueDependentIsNull, NPC_ValueDependentIsNotNull }
 Enumeration used to describe how isNullPointerConstant() should cope with value-dependent expressions. More...
 

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. More...
 
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
 
SourceLocation getLocStart () const LLVM_READONLY
 
SourceLocation getLocEnd () const LLVM_READONLY
 
child_range children ()
 
- Public Member Functions inherited from clang::Expr
QualType getType () const
 
void setType (QualType t)
 
bool isValueDependent () const
 
void setValueDependent (bool VD)
 Set whether this expression is value-dependent or not. More...
 
bool isTypeDependent () const
 
void setTypeDependent (bool TD)
 Set whether this expression is type-dependent or not. More...
 
bool isInstantiationDependent () const
 Whether this expression is instantiation-dependent, meaning that it depends in some way on a template parameter, even if neither its type nor (constant) value can change due to the template instantiation. More...
 
void setInstantiationDependent (bool ID)
 Set whether this expression is instantiation-dependent or not. More...
 
bool containsUnexpandedParameterPack () const
 Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates). More...
 
void setContainsUnexpandedParameterPack (bool PP=true)
 Set the bit that describes whether this expression contains an unexpanded parameter pack. More...
 
SourceLocation getExprLoc () const LLVM_READONLY
 
bool isUnusedResultAWarning (const Expr *&WarnExpr, SourceLocation &Loc, SourceRange &R1, SourceRange &R2, ASTContext &Ctx) const
 
bool isLValue () const
 
bool isRValue () const
 
bool isXValue () const
 
bool isGLValue () const
 
LValueClassification ClassifyLValue (ASTContext &Ctx) const
 Reasons why an expression might not be an l-value. More...
 
isModifiableLvalueResult isModifiableLvalue (ASTContext &Ctx, SourceLocation *Loc=nullptr) const
 
Classification Classify (ASTContext &Ctx) const
 Classify - Classify this expression according to the C++11 expression taxonomy. More...
 
Classification ClassifyModifiable (ASTContext &Ctx, SourceLocation &Loc) const
 ClassifyModifiable - Classify this expression according to the C++11 expression taxonomy, and see if it is valid on the left side of an assignment. More...
 
ExprValueKind getValueKind () const
 getValueKind - The value kind that this expression produces. More...
 
ExprObjectKind getObjectKind () const
 
bool isOrdinaryOrBitFieldObject () const
 
void setValueKind (ExprValueKind Cat)
 setValueKind - Set the value kind produced by this expression. More...
 
void setObjectKind (ExprObjectKind Cat)
 setObjectKind - Set the object kind produced by this expression. More...
 
bool refersToBitField () const
 Returns true if this expression is a gl-value that potentially refers to a bit-field. More...
 
FieldDeclgetSourceBitField ()
 If this expression refers to a bit-field, retrieve the declaration of that bit-field. More...
 
const FieldDeclgetSourceBitField () const
 
const ObjCPropertyRefExprgetObjCProperty () const
 If this expression is an l-value for an Objective C property, find the underlying property reference expression. More...
 
bool isObjCSelfExpr () const
 Check if this expression is the ObjC 'self' implicit parameter. More...
 
bool refersToVectorElement () const
 Returns whether this expression refers to a vector element. More...
 
bool hasPlaceholderType () const
 Returns whether this expression has a placeholder type. More...
 
bool hasPlaceholderType (BuiltinType::Kind K) const
 Returns whether this expression has a specific placeholder type. More...
 
bool isKnownToHaveBooleanValue () const
 
bool isIntegerConstantExpr (llvm::APSInt &Result, const ASTContext &Ctx, SourceLocation *Loc=nullptr, bool isEvaluated=true) const
 
bool isIntegerConstantExpr (const ASTContext &Ctx, SourceLocation *Loc=nullptr) const
 
bool isCXX98IntegralConstantExpr (const ASTContext &Ctx) const
 
bool isCXX11ConstantExpr (const ASTContext &Ctx, APValue *Result=nullptr, SourceLocation *Loc=nullptr) const
 
bool isConstantInitializer (ASTContext &Ctx, bool ForRef, const Expr **Culprit=nullptr) const
 
bool EvaluateAsRValue (EvalResult &Result, const ASTContext &Ctx) const
 
bool EvaluateAsBooleanCondition (bool &Result, const ASTContext &Ctx) const
 
bool EvaluateAsInt (llvm::APSInt &Result, const ASTContext &Ctx, SideEffectsKind AllowSideEffects=SE_NoSideEffects) const
 
bool isEvaluatable (const ASTContext &Ctx) const
 
bool HasSideEffects (const ASTContext &Ctx, bool IncludePossibleEffects=true) const
 
bool hasNonTrivialCall (const ASTContext &Ctx) const
 Determine whether this expression involves a call to any function that is not trivial. More...
 
llvm::APSInt EvaluateKnownConstInt (const ASTContext &Ctx, SmallVectorImpl< PartialDiagnosticAt > *Diag=nullptr) const
 
void EvaluateForOverflow (const ASTContext &Ctx) const
 
bool EvaluateAsLValue (EvalResult &Result, const ASTContext &Ctx) const
 
bool EvaluateAsInitializer (APValue &Result, const ASTContext &Ctx, const VarDecl *VD, SmallVectorImpl< PartialDiagnosticAt > &Notes) const
 
bool EvaluateWithSubstitution (APValue &Value, ASTContext &Ctx, const FunctionDecl *Callee, ArrayRef< const Expr * > Args) const
 
NullPointerConstantKind isNullPointerConstant (ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
 
bool isOBJCGCCandidate (ASTContext &Ctx) const
 
bool isBoundMemberFunction (ASTContext &Ctx) const
 Returns true if this expression is a bound member function. More...
 
ExprIgnoreImpCasts () LLVM_READONLY
 
ExprIgnoreImplicit () LLVM_READONLY
 
const ExprIgnoreImplicit () const LLVM_READONLY
 
ExprIgnoreParens () LLVM_READONLY
 
ExprIgnoreParenCasts () LLVM_READONLY
 
ExprIgnoreCasts () LLVM_READONLY
 Ignore casts. Strip off any CastExprs, returning their operand. More...
 
ExprIgnoreParenImpCasts () LLVM_READONLY
 
ExprIgnoreConversionOperator () LLVM_READONLY
 
const ExprIgnoreConversionOperator () const LLVM_READONLY
 
const ExprIgnoreParenImpCasts () const LLVM_READONLY
 
ExprIgnoreParenLValueCasts () LLVM_READONLY
 
const ExprIgnoreParenLValueCasts () const LLVM_READONLY
 
ExprIgnoreParenNoopCasts (ASTContext &Ctx) LLVM_READONLY
 
ExprignoreParenBaseCasts () LLVM_READONLY
 Ignore parentheses and derived-to-base casts. More...
 
const ExprignoreParenBaseCasts () const LLVM_READONLY
 
bool isDefaultArgument () const
 Determine whether this expression is a default function argument. More...
 
bool isTemporaryObject (ASTContext &Ctx, const CXXRecordDecl *TempTy) const
 Determine whether the result of this expression is a temporary object of the given class type. More...
 
bool isImplicitCXXThis () const
 Whether this expression is an implicit reference to 'this' in C++. More...
 
const ExprIgnoreImpCasts () const LLVM_READONLY
 
const ExprIgnoreParens () const LLVM_READONLY
 
const ExprIgnoreParenCasts () const LLVM_READONLY
 
const ExprIgnoreCasts () const LLVM_READONLY
 Strip off casts, but keep parentheses. More...
 
const ExprIgnoreParenNoopCasts (ASTContext &Ctx) const LLVM_READONLY
 
const CXXRecordDeclgetBestDynamicClassType () const
 For an expression of class type or pointer to class type, return the most derived class decl the expression is known to refer to. More...
 
const ExprskipRValueSubobjectAdjustments (SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
 

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. More...
 
static StringLiteralCreateEmpty (const ASTContext &C, unsigned NumStrs)
 Construct an empty string literal. More...
 
static bool classof (const Stmt *T)
 
- Static Public Member Functions inherited from clang::Expr
static ExprValueKind getValueKindForType (QualType T)
 
static bool isPotentialConstantExpr (const FunctionDecl *FD, SmallVectorImpl< PartialDiagnosticAt > &Diags)
 
static bool isPotentialConstantExprUnevaluated (Expr *E, const FunctionDecl *FD, SmallVectorImpl< PartialDiagnosticAt > &Diags)
 
static QualType findBoundMemberType (const Expr *expr)
 Given an expression of bound-member type, find the type of the member. Returns null if this is an overloaded bound member expression. More...
 
static bool hasAnyTypeDependentArguments (ArrayRef< Expr * > Exprs)
 
static bool classof (const Stmt *T)
 

Friends

class ASTStmtReader
 

Additional Inherited Members

- Protected Member Functions inherited from clang::Expr
 Expr (StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack)
 
 Expr (StmtClass SC, EmptyShell)
 Construct an empty expression. More...
 

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 1473 of file Expr.h.

Member Typedef Documentation

Definition at line 1603 of file Expr.h.

Member Enumeration Documentation

Enumerator
Ascii 
Wide 
UTF8 
UTF16 
UTF32 

Definition at line 1475 of file Expr.h.

Member Function Documentation

child_range clang::StringLiteral::children ( )
inline

Definition at line 1617 of file Expr.h.

static bool clang::StringLiteral::classof ( const Stmt T)
inlinestatic

Definition at line 1612 of file Expr.h.

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

Definition at line 1571 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 832 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 
)
inlinestatic

Simple constructor for string literals made from one token.

Definition at line 1512 of file Expr.h.

References Create().

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

Construct an empty string literal.

Definition at line 857 of file Expr.cpp.

References clang::ASTContext::Allocate().

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

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

References getByteLength().

Referenced by isIdenticalStmt().

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 1561 of file Expr.h.

Referenced by IsStringInit(), and outputString().

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 1006 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

Definition at line 1608 of file Expr.h.

SourceLocation clang::StringLiteral::getLocStart ( ) const
inline
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 1581 of file Expr.h.

Referenced by getLocationOfByte().

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 1569 of file Expr.h.

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

Definition at line 1567 of file Expr.h.

References UTF16.

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

Definition at line 1568 of file Expr.h.

References UTF32.

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

Definition at line 1566 of file Expr.h.

References UTF8.

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

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

Definition at line 1565 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 962 of file Expr.cpp.

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

Referenced by Create().

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

Definition at line 1587 of file Expr.h.

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

Definition at line 1604 of file Expr.h.

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

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

Definition at line 1605 of file Expr.h.

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

Friends And Related Function Documentation

friend class ASTStmtReader
friend

Definition at line 1484 of file Expr.h.

Member Data Documentation

const char* clang::StringLiteral::asChar

Definition at line 1487 of file Expr.h.

const uint16_t* clang::StringLiteral::asUInt16

Definition at line 1488 of file Expr.h.

const uint32_t* clang::StringLiteral::asUInt32

Definition at line 1489 of file Expr.h.


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