clang  6.0.0svn
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
clang::sema::LambdaScopeInfo Class Referencefinal

#include "clang/Sema/ScopeInfo.h"

Inheritance diagram for clang::sema::LambdaScopeInfo:
Inheritance graph
[legend]
Collaboration diagram for clang::sema::LambdaScopeInfo:
Collaboration graph
[legend]

Classes

struct  ShadowedOuterDecl
 Contains all of the variables defined in this lambda that shadow variables that were defined in parent contexts. More...
 

Public Member Functions

 LambdaScopeInfo (DiagnosticsEngine &Diag)
 
void finishedExplicitCaptures ()
 Note when all explicit captures have been added. More...
 
bool isGenericLambda () const
 Is this scope known to be for a generic lambda? (This will be false until we parse the first 'auto'-typed parameter. More...
 
void addPotentialCapture (Expr *VarExpr)
 Add a variable that might potentially be captured by the lambda and therefore the enclosing lambdas. More...
 
void addPotentialThisCapture (SourceLocation Loc)
 
bool hasPotentialThisCapture () const
 
void markVariableExprAsNonODRUsed (Expr *CapturingVarExpr)
 Mark a variable's reference in a lambda as non-odr using. More...
 
bool isVariableExprMarkedAsNonODRUsed (Expr *CapturingVarExpr) const
 
void removePotentialCapture (Expr *E)
 
void clearPotentialCaptures ()
 
unsigned getNumPotentialVariableCaptures () const
 
bool hasPotentialCaptures () const
 
void getPotentialVariableCapture (unsigned Idx, VarDecl *&VD, Expr *&E) const
 
- Public Member Functions inherited from clang::sema::CapturingScopeInfo
 CapturingScopeInfo (DiagnosticsEngine &Diag, ImplicitCaptureStyle Style)
 
void addCapture (VarDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, Expr *Cpy)
 
void addVLATypeCapture (SourceLocation Loc, QualType CaptureType)
 
void addThisCapture (bool isNested, SourceLocation Loc, Expr *Cpy, bool ByCopy)
 
bool isCXXThisCaptured () const
 Determine whether the C++ 'this' is captured. More...
 
CapturegetCXXThisCapture ()
 Retrieve the capture of C++ 'this', if it has been captured. More...
 
bool isCaptured (VarDecl *Var) const
 Determine whether the given variable has been captured. More...
 
bool isVLATypeCaptured (const VariableArrayType *VAT) const
 Determine whether the given variable-array type has been captured. More...
 
CapturegetCapture (VarDecl *Var)
 Retrieve the capture of the given variable, if it has been captured already. More...
 
const CapturegetCapture (VarDecl *Var) const
 
- Public Member Functions inherited from clang::sema::FunctionScopeInfo
template<typename ExprT >
void recordUseOfWeak (const ExprT *E, bool IsRead=true)
 Record that a weak object was accessed. More...
 
void recordUseOfWeak (const ObjCMessageExpr *Msg, const ObjCPropertyDecl *Prop)
 
void markSafeWeakUse (const Expr *E)
 Record that a given expression is a "safe" access of a weak object (e.g. More...
 
const WeakObjectUseMapgetWeakObjectUses () const
 
void setHasBranchIntoScope ()
 
void setHasBranchProtectedScope ()
 
void setHasIndirectGoto ()
 
void setHasDroppedStmt ()
 
void setHasOMPDeclareReductionCombiner ()
 
void setHasFallthroughStmt ()
 
void setHasCXXTry (SourceLocation TryLoc)
 
void setHasSEHTry (SourceLocation TryLoc)
 
bool NeedsScopeChecking () const
 
bool isCoroutine () const
 
void setFirstCoroutineStmt (SourceLocation Loc, StringRef Keyword)
 
StringRef getFirstCoroutineStmtKeyword () const
 
void setNeedsCoroutineSuspends (bool value=true)
 
bool hasInvalidCoroutineSuspends () const
 
void setCoroutineSuspends (Stmt *Initial, Stmt *Final)
 
 FunctionScopeInfo (DiagnosticsEngine &Diag)
 
virtual ~FunctionScopeInfo ()
 
void Clear ()
 Clear out the information in this function scope, making it suitable for reuse. More...
 

Static Public Member Functions

static bool classof (const FunctionScopeInfo *FSI)
 
- Static Public Member Functions inherited from clang::sema::CapturingScopeInfo
static bool classof (const FunctionScopeInfo *FSI)
 

Public Attributes

CXXRecordDeclLambda
 The class that describes the lambda. More...
 
CXXMethodDeclCallOperator
 The lambda's compiler-generated operator(). More...
 
SourceRange IntroducerRange
 Source range covering the lambda introducer [...]. More...
 
SourceLocation CaptureDefaultLoc
 Source location of the '&' or '=' specifying the default capture type, if any. More...
 
unsigned NumExplicitCaptures
 The number of captures in the Captures list that are explicit captures. More...
 
bool Mutable
 Whether this is a mutable lambda. More...
 
bool ExplicitParams
 Whether the (empty) parameter list is explicit. More...
 
CleanupInfo Cleanup
 Whether any of the capture expressions requires cleanups. More...
 
bool ContainsUnexpandedParameterPack
 Whether the lambda contains an unexpanded parameter pack. More...
 
unsigned AutoTemplateParameterDepth
 If this is a generic lambda, use this as the depth of each 'auto' parameter, during initial AST construction. More...
 
SmallVector< TemplateTypeParmDecl *, 4 > AutoTemplateParams
 Store the list of the auto parameters for a generic lambda. More...
 
TemplateParameterListGLTemplateParameterList
 If this is a generic lambda, and the template parameter list has been created (from the AutoTemplateParams) then store a reference to it (cache it to avoid reconstructing it). More...
 
llvm::SmallVector< Expr *, 4 > PotentiallyCapturingExprs
 Contains all variable-referring-expressions (i.e. More...
 
llvm::SmallSet< Expr *, 8 > NonODRUsedCapturingExprs
 Contains all variable-referring-expressions that refer to local variables that are usable as constant expressions and do not involve an odr-use (they may still need to be captured if the enclosing full-expression is instantiation dependent). More...
 
llvm::SmallVector< ShadowedOuterDecl, 4 > ShadowingDecls
 
SourceLocation PotentialThisCaptureLocation
 
- Public Attributes inherited from clang::sema::CapturingScopeInfo
ImplicitCaptureStyle ImpCaptureStyle
 
llvm::DenseMap< VarDecl *, unsigned > CaptureMap
 CaptureMap - A map of captured variables to (index+1) into Captures. More...
 
unsigned CXXThisCaptureIndex
 CXXThisCaptureIndex - The (index+1) of the capture of 'this'; zero if 'this' is not captured. More...
 
SmallVector< Capture, 4 > Captures
 Captures - The captures. More...
 
bool HasImplicitReturnType
 
  • Whether the target type of return statements in this context is deduced (e.g.
More...
 
QualType ReturnType
 ReturnType - The target type of return statements in this context, or null if unknown. More...
 
- Public Attributes inherited from clang::sema::FunctionScopeInfo
ScopeKind Kind: 3
 What kind of scope we are describing. More...
 
bool HasBranchProtectedScope: 1
 Whether this function contains a VLA, @try, try, C++ initializer, or anything else that can't be jumped past. More...
 
bool HasBranchIntoScope: 1
 Whether this function contains any switches or direct gotos. More...
 
bool HasIndirectGoto: 1
 Whether this function contains any indirect gotos. More...
 
bool HasDroppedStmt: 1
 Whether a statement was dropped because it was invalid. More...
 
bool HasOMPDeclareReductionCombiner: 1
 True if current scope is for OpenMP declare reduction combiner. More...
 
bool HasFallthroughStmt: 1
 Whether there is a fallthrough statement in this function. More...
 
bool HasPotentialAvailabilityViolations: 1
 Whether we make reference to a declaration that could be unavailable. More...
 
bool ObjCShouldCallSuper: 1
 A flag that is set when parsing a method that must call super's implementation, such as -dealloc, -finalize, or any method marked with attribute((objc_requires_super)). More...
 
bool ObjCIsDesignatedInit: 1
 True when this is a method marked as a designated initializer. More...
 
bool ObjCWarnForNoDesignatedInitChain: 1
 This starts true for a method marked as designated initializer and will be set to false if there is an invocation to a designated initializer of the super class. More...
 
bool ObjCIsSecondaryInit: 1
 True when this is an initializer method not marked as a designated initializer within a class that has at least one initializer marked as a designated initializer. More...
 
bool ObjCWarnForNoInitDelegation: 1
 This starts true for a secondary initializer method and will be set to false if there is an invocation of an initializer on 'self'. More...
 
bool NeedsCoroutineSuspends: 1
 True only when this function has not already built, or attempted to build, the initial and final coroutine suspend points. More...
 
unsigned char FirstCoroutineStmtKind: 2
 An enumeration represeting the kind of the first coroutine statement in the function. More...
 
SourceLocation FirstCoroutineStmtLoc
 First coroutine statement in the current function. More...
 
SourceLocation FirstReturnLoc
 First 'return' statement in the current function. More...
 
SourceLocation FirstCXXTryLoc
 First C++ 'try' statement in the current function. More...
 
SourceLocation FirstSEHTryLoc
 First SEH '__try' statement in the current function. More...
 
DiagnosticErrorTrap ErrorTrap
 Used to determine if errors occurred in this function or block. More...
 
SmallVector< SwitchStmt *, 8 > SwitchStack
 SwitchStack - This is the current set of active switch statements in the block. More...
 
SmallVector< ReturnStmt *, 4 > Returns
 The list of return statements that occur within the function or block, if there is any chance of applying the named return value optimization, or if we need to infer a return type. More...
 
VarDeclCoroutinePromise = nullptr
 The promise object for this coroutine, if any. More...
 
std::pair< Stmt *, Stmt * > CoroutineSuspends
 The initial and final coroutine suspend points. More...
 
SmallVector< CompoundScopeInfo, 4 > CompoundScopes
 The stack of currently active compound stamement scopes in the function. More...
 
SmallVector< PossiblyUnreachableDiag, 4 > PossiblyUnreachableDiags
 A list of PartialDiagnostics created but delayed within the current function scope. More...
 
llvm::SmallPtrSet< const ParmVarDecl *, 8 > ModifiedNonNullParams
 A list of parameters which have the nonnull attribute and are modified in the function. More...
 

Additional Inherited Members

- Public Types inherited from clang::sema::CapturingScopeInfo
enum  ImplicitCaptureStyle {
  ImpCap_None, ImpCap_LambdaByval, ImpCap_LambdaByref, ImpCap_Block,
  ImpCap_CapturedRegion
}
 
- Public Types inherited from clang::sema::FunctionScopeInfo
typedef SmallVector< WeakUseTy, 4 > WeakUseVector
 Used to collect uses of a particular weak object in a function body. More...
 
typedef llvm::SmallDenseMap< WeakObjectProfileTy, WeakUseVector, 8, WeakObjectProfileTy::DenseMapInfoWeakObjectUseMap
 Used to collect all uses of weak objects in a function body. More...
 
- Protected Types inherited from clang::sema::FunctionScopeInfo
enum  ScopeKind { SK_Function, SK_Block, SK_Lambda, SK_CapturedRegion }
 
- Protected Member Functions inherited from clang::sema::CapturingScopeInfo
 CapturingScopeInfo (const CapturingScopeInfo &)=default
 
- Protected Member Functions inherited from clang::sema::FunctionScopeInfo
 FunctionScopeInfo (const FunctionScopeInfo &)=default
 

Detailed Description

Definition at line 739 of file ScopeInfo.h.

Constructor & Destructor Documentation

◆ LambdaScopeInfo()

clang::sema::LambdaScopeInfo::LambdaScopeInfo ( DiagnosticsEngine Diag)
inline

Definition at line 819 of file ScopeInfo.h.

Member Function Documentation

◆ addPotentialCapture()

void clang::sema::LambdaScopeInfo::addPotentialCapture ( Expr VarExpr)
inline

Add a variable that might potentially be captured by the lambda and therefore the enclosing lambdas.

This is also used by enclosing lambda's to speculatively capture variables that nested lambda's - depending on their enclosing specialization - might need to capture. Consider: void f(int, int); <– don't capture void f(const int&, double); <– capture void foo() { const int x = 10; auto L = [=](auto a) { // capture 'x' return [=](auto b) { f(x, a); // we may or may not need to capture 'x' }; }; }

Definition at line 861 of file ScopeInfo.h.

◆ addPotentialThisCapture()

void clang::sema::LambdaScopeInfo::addPotentialThisCapture ( SourceLocation  Loc)
inline

◆ classof()

static bool clang::sema::LambdaScopeInfo::classof ( const FunctionScopeInfo FSI)
inlinestatic

Definition at line 833 of file ScopeInfo.h.

References clang::sema::FunctionScopeInfo::Kind.

◆ clearPotentialCaptures()

void clang::sema::LambdaScopeInfo::clearPotentialCaptures ( )
inline

Definition at line 929 of file ScopeInfo.h.

◆ finishedExplicitCaptures()

void clang::sema::LambdaScopeInfo::finishedExplicitCaptures ( )
inline

Note when all explicit captures have been added.

Definition at line 829 of file ScopeInfo.h.

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

◆ getNumPotentialVariableCaptures()

unsigned clang::sema::LambdaScopeInfo::getNumPotentialVariableCaptures ( ) const
inline

◆ getPotentialVariableCapture()

void LambdaScopeInfo::getPotentialVariableCapture ( unsigned  Idx,
VarDecl *&  VD,
Expr *&  E 
) const

Definition at line 232 of file ScopeInfo.cpp.

◆ hasPotentialCaptures()

bool clang::sema::LambdaScopeInfo::hasPotentialCaptures ( ) const
inline

Definition at line 937 of file ScopeInfo.h.

References clang::SourceLocation::isValid().

◆ hasPotentialThisCapture()

bool clang::sema::LambdaScopeInfo::hasPotentialThisCapture ( ) const
inline

Definition at line 869 of file ScopeInfo.h.

References clang::SourceLocation::isValid().

◆ isGenericLambda()

bool clang::sema::LambdaScopeInfo::isGenericLambda ( ) const
inline

Is this scope known to be for a generic lambda? (This will be false until we parse the first 'auto'-typed parameter.

Definition at line 839 of file ScopeInfo.h.

◆ isVariableExprMarkedAsNonODRUsed()

bool clang::sema::LambdaScopeInfo::isVariableExprMarkedAsNonODRUsed ( Expr CapturingVarExpr) const
inline

Definition at line 918 of file ScopeInfo.h.

◆ markVariableExprAsNonODRUsed()

void clang::sema::LambdaScopeInfo::markVariableExprAsNonODRUsed ( Expr CapturingVarExpr)
inline

Mark a variable's reference in a lambda as non-odr using.

For generic lambdas, if a variable is named in a potentially evaluated expression, where the enclosing full expression is dependent then we must capture the variable (given a default capture). This is accomplished by recording all references to variables (DeclRefExprs or MemberExprs) within said nested lambda in its array of PotentialCaptures. All such variables have to be captured by that lambda, except for as described below. If that variable is usable as a constant expression and is named in a manner that does not involve its odr-use (e.g. undergoes lvalue-to-rvalue conversion, or discarded) record that it is so. Upon the act of analyzing the enclosing full expression (ActOnFinishFullExpr) if we can determine that the full expression is not instantiation- dependent, then we can entirely avoid its capture.

const int n = 0; [&] (auto x) { (void)+n + x; }; Interestingly, this strategy would involve a capture of n, even though it's obviously not odr-used here, because the full-expression is instantiation-dependent. It could be useful to avoid capturing such variables, even when they are referred to in an instantiation-dependent expression, if we can unambiguously determine that they shall never be odr-used. This would involve removal of the variable-referring-expression from the array of PotentialCaptures during the lvalue-to-rvalue conversions. But per the working draft N3797, (post-chicago 2013) we must capture such variables. Before anyone is tempted to implement a strategy for not-capturing 'n', consider the insightful warning in: /cfe-commits/Week-of-Mon-20131104/092596.html "The problem is that the set of captures for a lambda is part of the ABI (since lambda layout can be made visible through inline functions and the like), and there are no guarantees as to which cases we'll manage to build an lvalue-to-rvalue conversion in, when parsing a template – some seemingly harmless change elsewhere in Sema could cause us to start or stop building such a node. So we need a rule that anyone can implement and get exactly the same result".

Definition at line 913 of file ScopeInfo.h.

◆ removePotentialCapture()

void clang::sema::LambdaScopeInfo::removePotentialCapture ( Expr E)
inline

Definition at line 923 of file ScopeInfo.h.

Member Data Documentation

◆ AutoTemplateParameterDepth

unsigned clang::sema::LambdaScopeInfo::AutoTemplateParameterDepth

If this is a generic lambda, use this as the depth of each 'auto' parameter, during initial AST construction.

Definition at line 772 of file ScopeInfo.h.

Referenced by GetDeclSpecTypeForDeclarator().

◆ AutoTemplateParams

SmallVector<TemplateTypeParmDecl*, 4> clang::sema::LambdaScopeInfo::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.

Definition at line 779 of file ScopeInfo.h.

Referenced by GetDeclSpecTypeForDeclarator(), and getGenericLambdaTemplateParameterList().

◆ CallOperator

CXXMethodDecl* clang::sema::LambdaScopeInfo::CallOperator

◆ CaptureDefaultLoc

SourceLocation clang::sema::LambdaScopeInfo::CaptureDefaultLoc

Source location of the '&' or '=' specifying the default capture type, if any.

Definition at line 752 of file ScopeInfo.h.

Referenced by clang::Sema::BuildLambdaExpr(), and clang::Sema::buildLambdaScope().

◆ Cleanup

CleanupInfo clang::sema::LambdaScopeInfo::Cleanup

Whether any of the capture expressions requires cleanups.

Definition at line 765 of file ScopeInfo.h.

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

◆ ContainsUnexpandedParameterPack

bool clang::sema::LambdaScopeInfo::ContainsUnexpandedParameterPack

Whether the lambda contains an unexpanded parameter pack.

Definition at line 768 of file ScopeInfo.h.

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

◆ ExplicitParams

bool clang::sema::LambdaScopeInfo::ExplicitParams

Whether the (empty) parameter list is explicit.

Definition at line 762 of file ScopeInfo.h.

Referenced by clang::Sema::BuildLambdaExpr(), and clang::Sema::buildLambdaScope().

◆ GLTemplateParameterList

TemplateParameterList* clang::sema::LambdaScopeInfo::GLTemplateParameterList

If this is a generic lambda, and the template parameter list has been created (from the AutoTemplateParams) then store a reference to it (cache it to avoid reconstructing it).

Definition at line 784 of file ScopeInfo.h.

Referenced by getGenericLambdaTemplateParameterList().

◆ IntroducerRange

SourceRange clang::sema::LambdaScopeInfo::IntroducerRange

Source range covering the lambda introducer [...].

Definition at line 748 of file ScopeInfo.h.

Referenced by clang::Sema::BuildLambdaExpr(), clang::Sema::buildLambdaScope(), and getGenericLambdaTemplateParameterList().

◆ Lambda

CXXRecordDecl* clang::sema::LambdaScopeInfo::Lambda

The class that describes the lambda.

Definition at line 742 of file ScopeInfo.h.

Referenced by clang::Sema::ActOnLambdaError(), clang::Sema::BuildLambdaExpr(), clang::Sema::buildLambdaScope(), and clang::Sema::tryCaptureVariable().

◆ Mutable

bool clang::sema::LambdaScopeInfo::Mutable

Whether this is a mutable lambda.

Definition at line 759 of file ScopeInfo.h.

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

◆ NonODRUsedCapturingExprs

llvm::SmallSet<Expr *, 8> clang::sema::LambdaScopeInfo::NonODRUsedCapturingExprs

Contains all variable-referring-expressions that refer to local variables that are usable as constant expressions and do not involve an odr-use (they may still need to be captured if the enclosing full-expression is instantiation dependent).

Definition at line 806 of file ScopeInfo.h.

◆ NumExplicitCaptures

unsigned clang::sema::LambdaScopeInfo::NumExplicitCaptures

The number of captures in the Captures list that are explicit captures.

Definition at line 756 of file ScopeInfo.h.

◆ PotentiallyCapturingExprs

llvm::SmallVector<Expr*, 4> clang::sema::LambdaScopeInfo::PotentiallyCapturingExprs

Contains all variable-referring-expressions (i.e.

DeclRefExprs or MemberExprs) that refer to local variables in a generic lambda or a lambda in a potentially-evaluated-if-used context.

Potentially capturable variables of a nested lambda that might need to be captured by the lambda are housed here. This is specifically useful for generic lambdas or lambdas within a a potentially evaluated-if-used context. If an enclosing variable is named in an expression of a lambda nested within a generic lambda, we don't always know know whether the variable will truly be odr-used (i.e. need to be captured) by that nested lambda, until its instantiation. But we still need to capture it in the enclosing lambda if all intervening lambdas can capture the variable.

Definition at line 800 of file ScopeInfo.h.

◆ PotentialThisCaptureLocation

SourceLocation clang::sema::LambdaScopeInfo::PotentialThisCaptureLocation

Definition at line 817 of file ScopeInfo.h.

◆ ShadowingDecls

llvm::SmallVector<ShadowedOuterDecl, 4> clang::sema::LambdaScopeInfo::ShadowingDecls

Definition at line 815 of file ScopeInfo.h.

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


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