clang API Documentation
#include <ScopeInfo.h>
Public Member Functions | |
LambdaScopeInfo (DiagnosticsEngine &Diag) | |
virtual | ~LambdaScopeInfo () |
void | finishedExplicitCaptures () |
Note when all explicit captures have been added. | |
void | addPotentialCapture (Expr *VarExpr) |
Add a variable that might potentially be captured by the lambda and therefore the enclosing lambdas. | |
void | addPotentialThisCapture (SourceLocation Loc) |
bool | hasPotentialThisCapture () const |
void | markVariableExprAsNonODRUsed (Expr *CapturingVarExpr) |
Mark a variable's reference in a lambda as non-odr using. | |
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 |
Static Public Member Functions | |
static bool | classof (const FunctionScopeInfo *FSI) |
Public Attributes | |
CXXRecordDecl * | Lambda |
The class that describes the lambda. | |
CXXMethodDecl * | CallOperator |
The lambda's compiler-generated operator() . | |
SourceRange | IntroducerRange |
Source range covering the lambda introducer [...]. | |
SourceLocation | CaptureDefaultLoc |
Source location of the '&' or '=' specifying the default capture type, if any. | |
unsigned | NumExplicitCaptures |
The number of captures in the Captures list that are explicit captures. | |
bool | Mutable |
Whether this is a mutable lambda. | |
bool | ExplicitParams |
Whether the (empty) parameter list is explicit. | |
bool | ExprNeedsCleanups |
Whether any of the capture expressions requires cleanups. | |
bool | ContainsUnexpandedParameterPack |
Whether the lambda contains an unexpanded parameter pack. | |
SmallVector< VarDecl *, 4 > | ArrayIndexVars |
Variables used to index into by-copy array captures. | |
SmallVector< unsigned, 4 > | ArrayIndexStarts |
Offsets into the ArrayIndexVars array at which each capture starts its list of array index variables. | |
unsigned | AutoTemplateParameterDepth |
If this is a generic lambda, use this as the depth of each 'auto' parameter, during initial AST construction. | |
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. | |
TemplateParameterList * | GLTemplateParameterList |
llvm::SmallVector< Expr *, 4 > | 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. | |
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). | |
SourceLocation | PotentialThisCaptureLocation |
Definition at line 600 of file ScopeInfo.h.
clang::sema::LambdaScopeInfo::LambdaScopeInfo | ( | DiagnosticsEngine & | Diag | ) | [inline] |
Definition at line 678 of file ScopeInfo.h.
References clang::sema::FunctionScopeInfo::SK_Lambda.
LambdaScopeInfo::~LambdaScopeInfo | ( | ) | [virtual] |
Definition at line 232 of file ScopeInfo.cpp.
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 716 of file ScopeInfo.h.
References PotentiallyCapturingExprs.
void clang::sema::LambdaScopeInfo::addPotentialThisCapture | ( | SourceLocation | Loc | ) | [inline] |
Definition at line 721 of file ScopeInfo.h.
References PotentialThisCaptureLocation.
Referenced by clang::Sema::BuildMemberReferenceExpr().
static bool clang::sema::LambdaScopeInfo::classof | ( | const FunctionScopeInfo * | FSI | ) | [inline, static] |
Reimplemented from clang::sema::CapturingScopeInfo.
Definition at line 694 of file ScopeInfo.h.
References clang::sema::FunctionScopeInfo::Kind, and clang::sema::FunctionScopeInfo::SK_Lambda.
void clang::sema::LambdaScopeInfo::clearPotentialCaptures | ( | ) | [inline] |
Definition at line 784 of file ScopeInfo.h.
References PotentiallyCapturingExprs, and PotentialThisCaptureLocation.
Referenced by CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures().
void clang::sema::LambdaScopeInfo::finishedExplicitCaptures | ( | ) | [inline] |
Note when all explicit captures have been added.
Definition at line 690 of file ScopeInfo.h.
References clang::sema::CapturingScopeInfo::Captures, and NumExplicitCaptures.
Referenced by clang::Sema::finishLambdaExplicitCaptures().
unsigned clang::sema::LambdaScopeInfo::getNumPotentialVariableCaptures | ( | ) | const [inline] |
Definition at line 788 of file ScopeInfo.h.
References PotentiallyCapturingExprs.
Referenced by CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures(), and hasPotentialCaptures().
void LambdaScopeInfo::getPotentialVariableCapture | ( | unsigned | Idx, |
VarDecl *& | VD, | ||
Expr *& | E | ||
) | const |
Definition at line 214 of file ScopeInfo.cpp.
References clang::MemberExpr::getMemberDecl().
Referenced by CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures().
bool clang::sema::LambdaScopeInfo::hasPotentialCaptures | ( | ) | const [inline] |
Definition at line 792 of file ScopeInfo.h.
References getNumPotentialVariableCaptures(), clang::SourceLocation::isValid(), and PotentialThisCaptureLocation.
bool clang::sema::LambdaScopeInfo::hasPotentialThisCapture | ( | ) | const [inline] |
Definition at line 724 of file ScopeInfo.h.
References clang::SourceLocation::isValid(), and PotentialThisCaptureLocation.
Referenced by CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures().
bool clang::sema::LambdaScopeInfo::isVariableExprMarkedAsNonODRUsed | ( | Expr * | CapturingVarExpr | ) | const [inline] |
Definition at line 773 of file ScopeInfo.h.
References NonODRUsedCapturingExprs.
Referenced by CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures().
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 768 of file ScopeInfo.h.
References NonODRUsedCapturingExprs.
void clang::sema::LambdaScopeInfo::removePotentialCapture | ( | Expr * | E | ) | [inline] |
Definition at line 778 of file ScopeInfo.h.
References PotentiallyCapturingExprs.
SmallVector<unsigned, 4> clang::sema::LambdaScopeInfo::ArrayIndexStarts |
Offsets into the ArrayIndexVars array at which each capture starts its list of array index variables.
Definition at line 636 of file ScopeInfo.h.
Referenced by clang::Sema::ActOnLambdaExpr(), and addAsFieldToClosureType().
SmallVector<VarDecl *, 4> clang::sema::LambdaScopeInfo::ArrayIndexVars |
Variables used to index into by-copy array captures.
Definition at line 632 of file ScopeInfo.h.
Referenced by clang::Sema::ActOnLambdaExpr(), and addAsFieldToClosureType().
If this is a generic lambda, use this as the depth of each 'auto' parameter, during initial AST construction.
Definition at line 640 of file ScopeInfo.h.
Referenced by ConvertDeclSpecToType().
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 647 of file ScopeInfo.h.
Referenced by ConvertDeclSpecToType(), and getGenericLambdaTemplateParameterList().
The lambda's compiler-generated operator()
.
Definition at line 606 of file ScopeInfo.h.
Referenced by clang::Sema::ActOnCapScopeReturnStmt(), clang::Sema::ActOnLambdaExpr(), clang::Sema::buildLambdaScope(), clang::Sema::CheckCXXThisCapture(), CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures(), and RebuildLambdaScopeInfo().
Source location of the '&' or '=' specifying the default capture type, if any.
Definition at line 613 of file ScopeInfo.h.
Referenced by clang::Sema::ActOnLambdaExpr(), and clang::Sema::buildLambdaScope().
Whether the lambda contains an unexpanded parameter pack.
Definition at line 629 of file ScopeInfo.h.
Referenced by clang::Sema::ActOnLambdaExpr(), and clang::Sema::ActOnStartOfLambdaDefinition().
Whether the (empty) parameter list is explicit.
Definition at line 623 of file ScopeInfo.h.
Referenced by clang::Sema::ActOnLambdaExpr(), and clang::Sema::buildLambdaScope().
Whether any of the capture expressions requires cleanups.
Definition at line 626 of file ScopeInfo.h.
Referenced by clang::Sema::ActOnLambdaExpr(), and addAsFieldToClosureType().
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 652 of file ScopeInfo.h.
Referenced by getGenericLambdaTemplateParameterList().
Source range covering the lambda introducer [...].
Definition at line 609 of file ScopeInfo.h.
Referenced by clang::Sema::ActOnLambdaExpr(), clang::Sema::buildLambdaScope(), getGenericLambdaTemplateParameterList(), and RebuildLambdaScopeInfo().
The class that describes the lambda.
Definition at line 603 of file ScopeInfo.h.
Referenced by clang::Sema::ActOnLambdaError(), clang::Sema::ActOnLambdaExpr(), addAsFieldToClosureType(), clang::Sema::buildInitCaptureField(), clang::Sema::buildLambdaScope(), RebuildLambdaScopeInfo(), and clang::Sema::tryCaptureVariable().
Whether this is a mutable lambda.
Definition at line 620 of file ScopeInfo.h.
Referenced by clang::Sema::buildLambdaScope(), captureInLambda(), and RebuildLambdaScopeInfo().
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 674 of file ScopeInfo.h.
Referenced by isVariableExprMarkedAsNonODRUsed(), and markVariableExprAsNonODRUsed().
The number of captures in the Captures
list that are explicit captures.
Definition at line 617 of file ScopeInfo.h.
Referenced by clang::Sema::ActOnLambdaExpr(), and finishedExplicitCaptures().
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 668 of file ScopeInfo.h.
Referenced by addPotentialCapture(), clearPotentialCaptures(), getNumPotentialVariableCaptures(), and removePotentialCapture().
Definition at line 676 of file ScopeInfo.h.
Referenced by addPotentialThisCapture(), CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures(), clearPotentialCaptures(), clang::getStackIndexOfNearestEnclosingCaptureCapableLambda(), hasPotentialCaptures(), and hasPotentialThisCapture().