15 #ifndef LLVM_CLANG_SEMA_SCOPEINFO_H
16 #define LLVM_CLANG_SEMA_SCOPEINFO_H
23 #include "llvm/ADT/DenseMap.h"
24 #include "llvm/ADT/SmallSet.h"
25 #include "llvm/ADT/SmallVector.h"
35 class ObjCPropertyDecl;
37 class ImplicitParamDecl;
42 class TemplateTypeParmDecl;
43 class TemplateParameterList;
45 class ObjCIvarRefExpr;
46 class ObjCPropertyRefExpr;
47 class ObjCMessageExpr;
75 : PD(PD), Loc(Loc), stmt(stmt) {}
187 typedef llvm::PointerIntPair<const NamedDecl *, 1, bool> BaseInfoTy;
197 static BaseInfoTy getBaseInfo(
const Expr *BaseE);
223 return Base.getInt();
227 return Base == Other.Base && Property == Other.Property;
240 return WeakObjectProfileTy::getSentinel();
244 typedef std::pair<BaseInfoTy, const NamedDecl *> Pair;
263 llvm::PointerIntPair<const Expr *, 1, bool> Rep;
272 return Rep == Other.Rep;
298 template <
typename ExprT>
311 return WeakObjectUses;
390 Cap_ByCopy, Cap_ByRef, Cap_Block, Cap_This
395 llvm::PointerIntPair<VarDecl*, 1, bool> VarAndNested;
401 llvm::PointerIntPair<void *, 2, CaptureKind> InitExprAndCaptureKind;
417 : VarAndNested(Var, IsNested),
418 InitExprAndCaptureKind(Cpy, Block ? Cap_Block :
419 ByRef ? Cap_ByRef : Cap_ByCopy),
420 Loc(Loc), EllipsisLoc(EllipsisLoc), CaptureType(CaptureType) {}
425 : VarAndNested(nullptr, IsNested),
426 InitExprAndCaptureKind(Cpy, Cap_This),
427 Loc(Loc), EllipsisLoc(), CaptureType(CaptureType) {}
430 return InitExprAndCaptureKind.getInt() == Cap_This;
436 return InitExprAndCaptureKind.getInt() == Cap_ByCopy &&
440 return InitExprAndCaptureKind.getInt() == Cap_ByRef;
443 return InitExprAndCaptureKind.getInt() == Cap_Block;
446 return InitExprAndCaptureKind.getInt() == Cap_ByCopy &&
449 bool isNested()
const {
return VarAndNested.getInt(); }
452 return VarAndNested.getPointer();
469 return static_cast<Expr *
>(InitExprAndCaptureKind.getPointer());
500 EllipsisLoc, CaptureType, Cpy));
534 assert(
isCaptured(Var) &&
"Variable has not been captured");
539 llvm::DenseMap<VarDecl*, unsigned>::const_iterator Known
541 assert(Known !=
CaptureMap.end() &&
"Variable has not been captured");
608 return "default captured statement";
610 return "OpenMP region";
612 llvm_unreachable(
"Invalid captured region kind!");
730 assert(isa<DeclRefExpr>(VarExpr) || isa<MemberExpr>(VarExpr));
782 assert(isa<DeclRefExpr>(CapturingVarExpr)
783 || isa<MemberExpr>(CapturingVarExpr));
787 assert(isa<DeclRefExpr>(CapturingVarExpr)
788 || isa<MemberExpr>(CapturingVarExpr));
815 FunctionScopeInfo::WeakObjectProfileTy::WeakObjectProfileTy()
818 FunctionScopeInfo::WeakObjectProfileTy
819 FunctionScopeInfo::WeakObjectProfileTy::getSentinel() {
820 FunctionScopeInfo::WeakObjectProfileTy Result;
821 Result.Base.setInt(
true);
825 template <
typename ExprT>
835 Captures.push_back(
Capture(Capture::ThisCapture, isNested, Loc, CaptureType,
837 CXXThisCaptureIndex = Captures.size();
void clearPotentialCaptures()
SourceRange IntroducerRange
Source range covering the lambda introducer [...].
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
bool ExplicitParams
Whether the (empty) parameter list is explicit.
bool isThisCapture() const
TemplateParameterList * GLTemplateParameterList
Expr * getInitExpr() const
bool HasEmptyLoopBodies
Whether this compound stamement contains `for' or `while' loops with empty bodies.
~LambdaScopeInfo() override
CapturedRegionScopeInfo(DiagnosticsEngine &Diag, Scope *S, CapturedDecl *CD, RecordDecl *RD, ImplicitParamDecl *Context, CapturedRegionKind K)
static WeakObjectProfileTy getTombstoneKey()
static unsigned getHashValue(const WeakObjectProfileTy &Val)
bool hasPotentialThisCapture() const
bool NeedsScopeChecking() const
static bool classof(const FunctionScopeInfo *FSI)
Retains information about a function, method, or block that is currently being parsed.
static bool classof(const FunctionScopeInfo *FSI)
SmallVector< SwitchStmt *, 8 > SwitchStack
static bool classof(const FunctionScopeInfo *FSI)
RAII class that determines when any errors have occurred between the time the instance was created an...
Stores a list of template parameters for a TemplateDecl and its derived classes.
bool isCXXThisCaptured() const
Determine whether the C++ 'this' is captured.
void setHasBranchProtectedScope()
CapturedDecl * TheCapturedDecl
The CapturedDecl for this statement.
bool HasDroppedStmt
Whether a statement was dropped because it was invalid.
QualType getCaptureType() const
Retrieve the capture type for this capture, which is effectively the type of the non-static data memb...
SourceLocation getEllipsisLoc() const
Retrieve the source location of the ellipsis, whose presence indicates that the capture is a pack exp...
const Capture & getCapture(VarDecl *Var) const
void setHasIndirectGoto()
ScopeKind Kind
What kind of scope we are describing.
Scope * TheScope
This is the enclosing scope of the captured region.
~CapturedRegionScopeInfo() override
VarDecl * getVariable() const
bool ContainsUnexpandedParameterPack
Whether the lambda contains an unexpanded parameter pack.
SourceLocation FirstSEHTryLoc
First SEH '__try' statement in the current function.
const NamedDecl * getBase() const
void setHasBranchIntoScope()
DiagnosticErrorTrap ErrorTrap
Used to determine if errors occurred in this function or block.
void getPotentialVariableCapture(unsigned Idx, VarDecl *&VD, Expr *&E) const
bool hasPotentialCaptures() const
WeakUseTy(const Expr *Use, bool IsRead)
Concrete class used by the front-end to report problems and issues.
void finishedExplicitCaptures()
Note when all explicit captures have been added.
bool ExprNeedsCleanups
Whether any of the capture expressions requires cleanups.
static WeakObjectProfileTy getEmptyKey()
FunctionScopeInfo(DiagnosticsEngine &Diag)
This represents the body of a CapturedStmt, and serves as its DeclContext.
PossiblyUnreachableDiag(const PartialDiagnostic &PD, SourceLocation Loc, const Stmt *stmt)
SmallVector< TemplateTypeParmDecl *, 4 > AutoTemplateParams
Store the list of the auto parameters for a generic lambda. If this is a generic lambda, store the list of the auto parameters converted into TemplateTypeParmDecls into a vector that can be used to construct the generic lambda's template parameter list, during initial AST construction.
SmallVector< WeakUseTy, 4 > WeakUseVector
Contains information about the compound statement currently being parsed.
SourceLocation FirstCXXTryLoc
First C++ 'try' statement in the current function.
ImplicitCaptureStyle ImpCaptureStyle
void addPotentialCapture(Expr *VarExpr)
Add a variable that might potentially be captured by the lambda and therefore the enclosing lambdas...
bool isBlockCapture() const
void markVariableExprAsNonODRUsed(Expr *CapturingVarExpr)
Mark a variable's reference in a lambda as non-odr using.
bool Mutable
Whether this is a mutable lambda.
SmallVector< ReturnStmt *, 4 > Returns
The list of return statements that occur within the function or block, if there is any chance of appl...
Retains information about a captured region.
virtual ~FunctionScopeInfo()
void recordUseOfWeak(const ExprT *E, bool IsRead=true)
SourceLocation PotentialThisCaptureLocation
unsigned NumExplicitCaptures
The number of captures in the Captures list that are explicit captures.
Retains information about a block that is currently being parsed.
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
void removePotentialCapture(Expr *E)
const NamedDecl * getProperty() const
bool HasBranchProtectedScope
Whether this function contains a VLA, @try, try, C++ initializer, or anything else that can't be jump...
bool operator==(const WeakObjectProfileTy &Other) const
Capture & getCapture(VarDecl *Var)
Retrieve the capture of the given variable, if it has been captured already.
bool isVLATypeCaptured(const VariableArrayType *VAT) const
Determine whether the given variable-array type has been captured.
An expression that sends a message to the given Objective-C object or class.
void setHasCXXTry(SourceLocation TryLoc)
llvm::SmallPtrSet< const ParmVarDecl *, 8 > ModifiedNonNullParams
A list of parameters which have the nonnull attribute and are modified in the function.
Capture(IsThisCapture, bool IsNested, SourceLocation Loc, QualType CaptureType, Expr *Cpy)
CapturingScopeInfo(DiagnosticsEngine &Diag, ImplicitCaptureStyle Style)
void setHasSEHTry(SourceLocation TryLoc)
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
CXXRecordDecl * Lambda
The class that describes the lambda.
bool isValid() const
Return true if this is a valid SourceLocation object.
bool ObjCWarnForNoDesignatedInitChain
StringRef getRegionName() const
A descriptive name for the kind of captured region this is.
Represents a static or instance method of a struct/union/class.
SmallVector< Capture, 4 > Captures
Captures - The captures.
Represents one property declaration in an Objective-C interface.
void addPotentialThisCapture(SourceLocation Loc)
bool ObjCIsDesignatedInit
True when this is a method marked as a designated initializer.
SourceLocation CaptureDefaultLoc
Source location of the '&' or '=' specifying the default capture type, if any.
llvm::SmallVector< Expr *, 4 > PotentiallyCapturingExprs
Contains all variable-referring-expressions (i.e. DeclRefExprs or MemberExprs) that refer to local va...
CapturedRegionKind CapRegionKind
The kind of captured region.
llvm::SmallDenseMap< WeakObjectProfileTy, WeakUseVector, 8, WeakObjectProfileTy::DenseMapInfo > WeakObjectUseMap
bool isVLATypeCapture() const
bool HasIndirectGoto
Whether this function contains any indirect gotos.
unsigned CXXThisCaptureIndex
const WeakObjectUseMap & getWeakObjectUses() const
bool isCopyCapture() const
bool ObjCWarnForNoInitDelegation
BlockScopeInfo(DiagnosticsEngine &Diag, Scope *BlockScope, BlockDecl *Block)
bool isCaptured(VarDecl *Var) const
Determine whether the given variable has been captured.
LambdaScopeInfo(DiagnosticsEngine &Diag)
bool isReferenceCapture() const
void markSafeWeakUse(const Expr *E)
RecordDecl * TheRecordDecl
The captured record type.
void addThisCapture(bool isNested, SourceLocation Loc, QualType CaptureType, Expr *Cpy)
bool isExactProfile() const
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream...
llvm::DenseMap< VarDecl *, unsigned > CaptureMap
CaptureMap - A map of captured variables to (index+1) into Captures.
Capture & getCXXThisCapture()
Retrieve the capture of C++ 'this', if it has been captured.
ObjCIvarRefExpr - A reference to an ObjC instance variable.
static bool isEqual(const WeakObjectProfileTy &LHS, const WeakObjectProfileTy &RHS)
unsigned AutoTemplateParameterDepth
If this is a generic lambda, use this as the depth of each 'auto' parameter, during initial AST const...
SmallVector< PossiblyUnreachableDiag, 4 > PossiblyUnreachableDiags
A list of PartialDiagnostics created but delayed within the current function scope. These diagnostics are vetted for reachability prior to being emitted.
Represents a C++ struct/union/class.
llvm::SmallSet< Expr *, 8 > NonODRUsedCapturingExprs
Contains all variable-referring-expressions that refer to local variables that are usable as constant...
void setHasEmptyLoopBodies()
static bool classof(const FunctionScopeInfo *FSI)
Capture(VarDecl *Var, bool Block, bool ByRef, bool IsNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, Expr *Cpy)
void addVLATypeCapture(SourceLocation Loc, QualType CaptureType)
bool HasImplicitReturnType
Whether the target type of return statements in this context is deduced (e.g. a lambda or block with ...
const Expr * getUseExpr() const
A reference to a declared variable, function, enum, etc. [C99 6.5.1p2].
~BlockScopeInfo() override
unsigned getNumPotentialVariableCaptures() const
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
CapturedRegionKind
The different kinds of captured statement.
void addCapture(VarDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, Expr *Cpy)
ImplicitParamDecl * ContextParam
The implicit parameter for the captured variables.
SmallVector< CompoundScopeInfo, 4 > CompoundScopes
The stack of currently active compound stamement scopes in the function.
A trivial tuple used to represent a source range.
bool isVariableExprMarkedAsNonODRUsed(Expr *CapturingVarExpr) const
void Clear()
Clear out the information in this function scope, making it suitable for reuse.
bool isVariableCapture() const
bool HasBranchIntoScope
Whether this function contains any switches or direct gotos.
bool operator==(const WeakUseTy &Other) const