24 using namespace clang;
70 unsigned CurScopeIndex = FunctionScopes.size() - 1;
71 while (CurScopeIndex > 0 && isa<clang::sema::CapturedRegionScopeInfo>(
72 FunctionScopes[CurScopeIndex]))
75 isa<clang::sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex]) &&
76 "The function on the top of sema's function-info stack must be a lambda");
79 const bool IsCapturingThis = !VarToCapture;
80 const bool IsCapturingVariable = !IsCapturingThis;
84 cast<sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex])->CallOperator;
88 cast<sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex]);
96 if (IsCapturingVariable &&
98 return NoLambdaIsCaptureReady;
117 if (IsCapturingVariable && !LSI->
isCaptured(VarToCapture))
118 return NoLambdaIsCaptureReady;
120 return NoLambdaIsCaptureReady;
124 assert(CurScopeIndex);
130 assert(CurScopeIndex < (FunctionScopes.size() - 1));
134 return CurScopeIndex + 1;
135 return NoLambdaIsCaptureReady;
182 if (!OptionalStackIndex)
183 return NoLambdaIsCaptureCapable;
185 const unsigned IndexOfCaptureReadyLambda = OptionalStackIndex.getValue();
186 assert(((IndexOfCaptureReadyLambda != (FunctionScopes.size() - 1)) ||
188 "The capture ready lambda for a potential capture can only be the "
189 "current lambda if it is a generic lambda");
192 cast<sema::LambdaScopeInfo>(FunctionScopes[IndexOfCaptureReadyLambda]);
195 const bool IsCapturingThis = !VarToCapture;
196 const bool IsCapturingVariable = !IsCapturingThis;
198 if (IsCapturingVariable) {
203 const bool CanCaptureVariable =
209 DeclRefType, &IndexOfCaptureReadyLambda);
210 if (!CanCaptureVariable)
211 return NoLambdaIsCaptureCapable;
216 const bool CanCaptureThis =
220 &IndexOfCaptureReadyLambda);
222 return NoLambdaIsCaptureCapable;
224 return IndexOfCaptureReadyLambda;
270 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(DC))
282 Decl *&ManglingContextDecl) {
285 ManglingContextDecl = ExprEvalContexts.back().ManglingContextDecl;
297 if (ManglingContextDecl) {
298 if (
ParmVarDecl *Param = dyn_cast<ParmVarDecl>(ManglingContextDecl)) {
301 if (LexicalDC->isRecord())
302 Kind = DefaultArgument;
303 }
else if (
VarDecl *Var = dyn_cast<VarDecl>(ManglingContextDecl)) {
304 if (Var->getDeclContext()->isRecord())
305 Kind = StaticDataMember;
306 }
else if (isa<FieldDecl>(ManglingContextDecl)) {
314 bool IsInNonspecializedTemplate =
315 inTemplateInstantiation() || CurContext->isDependentContext();
320 if ((IsInNonspecializedTemplate &&
321 !(ManglingContextDecl && isa<ParmVarDecl>(ManglingContextDecl))) ||
323 ManglingContextDecl =
nullptr;
324 while (
auto *CD = dyn_cast<CapturedDecl>(DC))
329 ManglingContextDecl =
nullptr;
333 case StaticDataMember:
335 if (!IsInNonspecializedTemplate) {
336 ManglingContextDecl =
nullptr;
344 case DefaultArgument:
346 return &ExprEvalContexts.back().getMangleNumberingContext(
Context);
349 llvm_unreachable(
"unexpected context");
355 assert(ManglingContextDecl &&
"Need to have a context declaration");
356 if (!MangleNumbering)
358 return *MangleNumbering;
366 const bool IsConstexprSpecified) {
376 if (Result->isUndeducedType()) {
400 MethodType, MethodTypeInfo,
403 IsConstexprSpecified,
416 if (TemplateMethod) {
423 if (!Params.empty()) {
425 CheckParmsForFunctionDef(Params,
429 P->setOwningFunction(Method);
432 Decl *ManglingContextDecl;
435 ManglingContextDecl)) {
436 unsigned ManglingNumber = MCtx->getManglingNumber(Method);
449 bool ExplicitResultType,
453 LSI->
Lambda = LambdaClass;
463 if (ExplicitResultType) {
469 diag::err_lambda_incomplete_result)) {
484 for (
unsigned p = 0, NumParams = CallOperator->
getNumParams();
485 p < NumParams; ++p) {
490 CheckShadow(CurScope, Param);
492 PushOnScopeChains(Param, CurScope);
512 = dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
513 return cast<EnumDecl>(D->getDeclContext());
521 if (BO->getOpcode() == BO_Comma)
528 if (
StmtExpr *SE = dyn_cast<StmtExpr>(E)) {
529 if (
Expr *last = dyn_cast_or_null<Expr>(SE->getSubStmt()->body_back()))
550 if (ICE->getCastKind() == CK_IntegralCast)
558 return ET->getDecl();
581 if (!ED)
return nullptr;
584 for (++i; i != e; ++i) {
600 i = returns.begin(), e = returns.end(); i != e; ++i) {
612 Expr *
E = (cleanups ? cleanups->getSubExpr() : retValue);
616 cleanups->setSubExpr(E);
627 assert((!isa<LambdaScopeInfo>(CSI) || !getLangOpts().
CPlusPlus14) &&
628 "lambda expressions use auto deduction in C++14 onwards");
665 assert(!CSI.
ReturnType.
isNull() &&
"We should have a tentative return type.");
670 if (!getLangOpts().CPlusPlus) {
671 assert(isa<BlockScopeInfo>(CSI));
692 for (; I !=
E; ++
I) {
705 diag::err_typecheck_missing_return_type_incompatible)
707 << isa<LambdaScopeInfo>(CSI);
723 DeductType = BuildReferenceType(DeductType,
true, Loc, Id);
724 assert(!DeductType.
isNull() &&
"can't build reference to auto");
765 Result = ActOnFinishFullExpr(Init, Loc,
false,
768 if (Result.isInvalid())
771 Init = Result.getAs<
Expr>();
778 unsigned InitStyle,
Expr *Init) {
786 Loc, Id, InitCaptureType, TSI,
SC_Auto);
790 NewVD->
setInitStyle(static_cast<VarDecl::InitializationStyle>(InitStyle));
816 bool KnownDependent =
false;
818 assert(LSI &&
"LambdaScopeInfo should be on stack!");
824 KnownDependent =
true;
828 bool ExplicitParams =
true;
829 bool ExplicitResultType =
true;
830 bool ContainsUnexpandedParameterPack =
false;
847 QualType DefaultTypeForNoTrailingReturn =
853 ExplicitParams =
false;
854 ExplicitResultType =
false;
858 "lambda-declarator is a function");
865 if (!FTI.hasMutableQualifier())
868 MethodTyInfo = GetTypeForDeclarator(ParamInfo, CurScope);
869 assert(MethodTyInfo &&
"no type from lambda-declarator");
872 ExplicitResultType = FTI.hasTrailingReturnType();
875 Params.reserve(FTI.NumParams);
876 for (
unsigned i = 0, e = FTI.NumParams; i != e; ++i)
877 Params.push_back(cast<ParmVarDecl>(FTI.Params[i].Param));
882 ContainsUnexpandedParameterPack =
true;
886 KnownDependent, Intro.
Default);
889 startLambdaDefinition(Class, Intro.
Range, MethodTyInfo, EndLoc, Params,
892 CheckCXXDefaultArguments(Method);
895 ProcessDeclAttributes(CurScope, Method, ParamInfo);
899 if (getLangOpts().CUDA)
900 CUDASetLambdaAttrs(Method);
903 PushDeclContext(CurScope, Method);
907 ExplicitParams, ExplicitResultType, !Method->
isConst());
921 (getCurrentThisType().isNull() ||
927 llvm::SmallSet<IdentifierInfo*, 8> CaptureNames;
933 PrevCaptureLoc = C->Loc, ++C) {
937 ? diag::ext_star_this_lambda_capture_cxx1z
938 : diag::warn_cxx14_compat_star_this_lambda_capture);
944 Diag(C->Loc, diag::err_capture_more_than_once)
947 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
957 Diag(C->Loc, diag::err_this_capture_with_copy_default)
959 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
966 QualType ThisCaptureType = getCurrentThisType();
967 if (ThisCaptureType.
isNull()) {
968 Diag(C->Loc, diag::err_this_capture) <<
true;
972 CheckCXXThisCapture(C->Loc,
true,
true,
978 assert(C->Id &&
"missing identifier for capture");
980 if (C->Init.isInvalid())
984 if (C->Init.isUsable()) {
986 ? diag::warn_cxx11_compat_init_capture
987 : diag::ext_init_capture);
989 if (C->Init.get()->containsUnexpandedParameterPack())
990 ContainsUnexpandedParameterPack =
true;
996 if (C->InitCaptureType.get().isNull())
1000 switch (C->InitKind) {
1002 llvm_unreachable(
"not an init-capture?");
1013 Var = createLambdaInitCaptureVarDecl(C->Loc, C->InitCaptureType.get(),
1014 C->Id, InitStyle, C->Init.get());
1020 PushOnScopeChains(Var, CurScope,
false);
1023 "init capture has valid but null init?");
1031 Diag(C->Loc, diag::err_reference_capture_with_reference_default)
1033 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1036 Diag(C->Loc, diag::err_copy_capture_with_copy_default)
1038 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1047 LookupName(R, CurScope);
1053 if (DiagnoseEmptyLookup(CurScope, ScopeSpec, R,
1059 if (Var && DiagnoseUseOfDecl(Var, C->Loc))
1066 if (!CaptureNames.insert(C->Id).second) {
1068 Diag(C->Loc, diag::err_capture_more_than_once)
1071 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1075 Diag(C->Loc, diag::err_capture_more_than_once) << C->Id;
1084 Diag(C->Loc, diag::err_capture_does_not_name_variable) << C->Id;
1093 Diag(C->Loc, diag::err_capture_non_automatic_variable) << C->Id;
1101 if (C->EllipsisLoc.isValid()) {
1103 EllipsisLoc = C->EllipsisLoc;
1105 Diag(C->EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1111 ContainsUnexpandedParameterPack =
true;
1114 if (C->Init.isUsable()) {
1115 buildInitCaptureField(LSI, Var);
1118 TryCapture_ExplicitByVal;
1119 tryCaptureVariable(Var, C->Loc, Kind, EllipsisLoc);
1122 finishLambdaExplicitCaptures(LSI);
1127 addLambdaParameters(Method, CurScope);
1131 PushExpressionEvaluationContext(
1132 ExpressionEvaluationContext::PotentiallyEvaluated);
1136 bool IsInstantiation) {
1140 DiscardCleanupsInEvaluationContext();
1141 PopExpressionEvaluationContext();
1144 if (!IsInstantiation)
1153 CheckCompletedCXXClass(Class);
1155 PopFunctionScopeInfo();
1166 auto HasPassObjectSizeAttr = [](
const ParmVarDecl *
P) {
1167 return P->hasAttr<PassObjectSizeAttr>();
1169 if (llvm::any_of(CallOperator->
parameters(), HasPassObjectSizeAttr))
1186 "Lambda's call operator should not have a reference qualifier");
1268 CallOpConvTL.setParam(
I, From);
1269 CallOpConvNameTL.setParam(
I, From);
1291 Loc, ConversionName,
1297 Class->
addDecl(ConversionTemplate);
1324 InvokerParams[
I]->setOwningFunction(Invoke);
1332 S.
Context, Class, Loc, InvokerName,
1338 Class->
addDecl(StaticInvokerTemplate);
1358 BlockEPI.TypeQuals = 0;
1389 Sema &
S,
const LambdaScopeInfo::Capture &Capture,
FieldDecl *Field) {
1390 assert(Capture.isVariableCapture() &&
"not a variable capture");
1392 auto *Var = Capture.getVariable();
1414 Var->getIdentifier(), Field->
getType(), Loc);
1417 return Init.
Perform(S, Entity, InitKind, Ref);
1424 return BuildLambdaExpr(StartLoc, Body->
getLocEnd(), &LSI);
1438 llvm_unreachable(
"block capture in lambda");
1440 llvm_unreachable(
"Unknown implicit capture style");
1444 if (!From.isVLATypeCapture()) {
1445 Expr *Init = From.getInitExpr();
1450 if (!From.isCopyCapture())
1453 const QualType T = From.isThisCapture()
1455 : From.getCaptureType();
1462 return !RD->isCompleteDefinition() || !RD->hasTrivialCopyConstructor() ||
1463 !RD->hasTrivialDestructor();
1469 if (CaptureHasSideEffects(From))
1472 auto diag =
Diag(From.getLocation(), diag::warn_unused_lambda_capture);
1473 if (From.isThisCapture())
1476 diag << From.getVariable();
1477 diag << From.isNonODRUsed();
1491 bool ExplicitParams;
1492 bool ExplicitResultType;
1494 bool ContainsUnexpandedParameterPack;
1495 bool IsGenericLambda;
1507 Decl *TemplateOrNonTemplateCallOperatorDecl =
1510 : cast<Decl>(CallOperator);
1513 Class->
addDecl(TemplateOrNonTemplateCallOperatorDecl);
1515 PopExpressionEvaluationContext();
1519 for (
unsigned I = 0, N = LSI->
Captures.size();
I != N; ++
I, ++CurField) {
1520 const LambdaScopeInfo::Capture &From = LSI->
Captures[
I];
1521 assert(!From.isBlockCapture() &&
"Cannot capture __block variables");
1525 if (!CurContext->isDependentContext() && !IsImplicit && !From.isODRUsed()) {
1527 bool NonODRUsedInitCapture =
1528 IsGenericLambda && From.isNonODRUsed() && From.getInitExpr();
1529 if (!NonODRUsedInitCapture)
1530 DiagnoseUnusedLambdaCapture(From);
1534 if (From.isThisCapture()) {
1538 CaptureInits.push_back(From.getInitExpr());
1541 if (From.isVLATypeCapture()) {
1544 CaptureInits.push_back(
nullptr);
1548 VarDecl *Var = From.getVariable();
1551 Var, From.getEllipsisLoc()));
1552 Expr *Init = From.getInitExpr();
1556 if (InitResult.isInvalid())
1558 Init = InitResult.get();
1560 CaptureInits.push_back(Init);
1568 if (Captures.empty() && CaptureDefault ==
LCD_None)
1578 if (getLangOpts().Blocks && getLangOpts().ObjC1 && !IsGenericLambda)
1585 CheckCompletedCXXClass(Class);
1588 Cleanup.mergeFrom(LambdaCleanup);
1591 CaptureDefault, CaptureDefaultLoc,
1593 ExplicitParams, ExplicitResultType,
1594 CaptureInits, EndLoc,
1595 ContainsUnexpandedParameterPack);
1601 !isa<CoroutineBodyStmt>(CallOperator->
getBody()) &&
1605 CheckConstexprFunctionDecl(CallOperator) &&
1606 CheckConstexprFunctionBody(CallOperator, CallOperator->
getBody()));
1610 DiagnoseShadowingLambdaDecls(LSI);
1612 if (!CurContext->isDependentContext()) {
1613 switch (ExprEvalContexts.back().Context) {
1617 case ExpressionEvaluationContext::Unevaluated:
1618 case ExpressionEvaluationContext::UnevaluatedList:
1619 case ExpressionEvaluationContext::UnevaluatedAbstract:
1629 case ExpressionEvaluationContext::ConstantEvaluated:
1633 ExprEvalContexts.back().Lambdas.push_back(Lambda);
1636 case ExpressionEvaluationContext::DiscardedStatement:
1637 case ExpressionEvaluationContext::PotentiallyEvaluated:
1638 case ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed:
1643 return MaybeBindToTemporary(Lambda);
1653 = cast<CXXMethodDecl>(
1662 CurrentLocation, Src);
1664 Init = ActOnFinishFullExpr(Init.
get());
1700 ConvLocation,
nullptr,
1713 ExprCleanupObjects.push_back(Block);
1714 Cleanup.setExprNeedsCleanups(
true);
SourceLocation getEnd() const
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
void setImplicit(bool I=true)
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
SourceRange IntroducerRange
Source range covering the lambda introducer [...].
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
getFunctionTypeInfo - Retrieves the function type info object (looking through parentheses).
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.
A class which contains all the information about a particular captured value.
A (possibly-)qualified type.
bool ExplicitParams
Whether the (empty) parameter list is explicit.
ExtInfo withCallingConv(CallingConv cc) const
QualType getConversionType() const
Returns the type that this conversion function is converting to.
TemplateParameterList * GLTemplateParameterList
If this is a generic lambda, and the template parameter list has been created (from the AutoTemplateP...
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
VarDecl * createLambdaInitCaptureVarDecl(SourceLocation Loc, QualType InitCaptureType, IdentifierInfo *Id, unsigned InitStyle, Expr *Init)
Create a dummy variable within the declcontext of the lambda's call operator, for name lookup purpose...
const LangOptions & getLangOpts() const
DeclClass * getAsSingle() const
Stmt - This represents one statement.
static EnumDecl * findCommonEnumForBlockReturns(ArrayRef< ReturnStmt * > returns)
Attempt to find a common type T for which all of the returned expressions in a block are enumerator-l...
EnumConstantDecl - An instance of this object exists for each enum constant that is defined...
QualType ReturnType
ReturnType - The target type of return statements in this context, or null if unknown.
Decl - This represents one declaration (or definition), e.g.
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, SourceLocation ConvLocation, CXXConversionDecl *Conv, Expr *Src)
static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a direct initialization.
The base class of the type hierarchy.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
const Expr * getInit() const
RefQualifierKind RefQualifier
A container of type source information.
SourceLocation getLocStart() const LLVM_READONLY
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
void setInitStyle(InitializationStyle Style)
Describes the capture of a variable or of this, or of a C++1y init-capture.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
This file provides some common utility functions for processing Lambda related AST Constructs...
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
VarDecl - An instance of this class is created to represent a variable declaration or definition...
static CXXConversionDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, bool isInline, bool isExplicit, bool isConstexpr, SourceLocation EndLocation)
Information about one declarator, including the parsed type information and the identifier.
Extra information about a function prototype.
field_iterator field_begin() const
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
Stores a list of template parameters for a TemplateDecl and its derived classes.
MangleNumberingContext & getMangleNumberingContext(ASTContext &Ctx)
Retrieve the mangling numbering context, used to consistently number constructs like lambdas for mang...
static InitializationKind CreateDirectList(SourceLocation InitLoc)
bool tryCaptureVariable(VarDecl *Var, SourceLocation Loc, TryCaptureKind Kind, SourceLocation EllipsisLoc, bool BuildAndDiagnose, QualType &CaptureType, QualType &DeclRefType, const unsigned *const FunctionScopeIndexToStopAt)
Try to capture the given variable.
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
ParmVarDecl - Represents a parameter to a function.
CXXRecordDecl * createLambdaClosureType(SourceRange IntroducerRange, TypeSourceInfo *Info, bool KnownDependent, LambdaCaptureDefault CaptureDefault)
Create a new lambda closure type.
Defines the clang::Expr interface and subclasses for C++ expressions.
bool isCXXThisCaptured() const
Determine whether the C++ 'this' is captured.
tok::TokenKind ContextKind
bool FTIHasNonVoidParameters(const DeclaratorChunk::FunctionTypeInfo &FTI)
Scope * getTemplateParamParent()
FunctionType::ExtInfo ExtInfo
One of these records is kept for each identifier that is lexed.
sema::LambdaScopeInfo * getCurGenericLambda()
Retrieve the current generic lambda info, if any.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
ArrayRef< QualType > getParamTypes() const
bool isReferenceType() const
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
QualType getReturnType() const
LambdaCaptureKind
The different capture forms in a lambda introducer.
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
void setBlockMissingReturnType(bool val)
unsigned TypeQuals
The type qualifiers: const/volatile/restrict/__unaligned The qualifier bitmask values are the same as...
bool isTranslationUnit() const
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, bool DependentLambda, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
bool ContainsUnexpandedParameterPack
Whether the lambda contains an unexpanded parameter pack.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
static ExprResult performLambdaVarCaptureInitialization(Sema &S, const LambdaScopeInfo::Capture &Capture, FieldDecl *Field)
StorageClass getStorageClass() const
Returns the storage class as written in the source.
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
bool isIntegralOrUnscopedEnumerationType() const
Determine whether this type is an integral or unscoped enumeration type.
void setNameLoc(SourceLocation Loc)
Represents the results of name lookup.
RAII class used to indicate that we are performing provisional semantic analysis to determine the val...
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
< Capturing the *this object by copy
static LambdaCaptureDefault mapImplicitCaptureStyle(CapturingScopeInfo::ImplicitCaptureStyle ICS)
std::unique_ptr< MangleNumberingContext > createMangleNumberingContext() const
static Optional< unsigned > getStackIndexOfNearestEnclosingCaptureReadyLambda(ArrayRef< const clang::sema::FunctionScopeInfo * > FunctionScopes, VarDecl *VarToCapture)
Examines the FunctionScopeInfo stack to determine the nearest enclosing lambda (to the current lambda...
void addLambdaParameters(CXXMethodDecl *CallOperator, Scope *CurScope)
Introduce the lambda parameters into scope.
static InitializedEntity InitializeLambdaToBlock(SourceLocation BlockVarLoc, QualType Type, bool NRVO)
Keeps track of the mangled names of lambda expressions and block literals within a particular context...
QualType getReturnType() const
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
field_range fields() const
bool CheckCXXThisCapture(SourceLocation Loc, bool Explicit=false, bool BuildAndDiagnose=true, const unsigned *const FunctionScopeIndexToStopAt=nullptr, bool ByCopy=false)
Make sure the value of 'this' is actually available in the current context, if it is a potentially ev...
A builtin binary operation expression such as "x + y" or "x <= y".
void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl)
Set the mangling number and context declaration for a lambda class.
void finishedExplicitCaptures()
Note when all explicit captures have been added.
bool isVariadic() const
Whether this function is variadic.
DeclContext * getLambdaAwareParentOfDeclContext(DeclContext *DC)
Scope - A scope is a transient data structure that is used while parsing the program.
ExprResult Perform(Sema &S, const InitializedEntity &Entity, const InitializationKind &Kind, MultiExprArg Args, QualType *ResultType=nullptr)
Perform the actual initialization of the given entity based on the computed initialization sequence...
Represents a C++ nested-name-specifier or a global scope specifier.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
static VarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S)
bool isLambdaCallOperator(const CXXMethodDecl *MD)
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
static FunctionTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
StringRef getLambdaStaticInvokerName()
detail::InMemoryDirectory::const_iterator I
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
static void addFunctionPointerConversion(Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator)
Add a lambda's conversion to function pointer, as described in C++11 [expr.prim.lambda]p6.
SmallVector< TemplateTypeParmDecl *, 4 > AutoTemplateParams
Store the list of the auto parameters for a generic lambda.
TypeSpecTypeLoc pushTypeSpec(QualType T)
Pushes space for a typespec TypeLoc.
CleanupInfo Cleanup
Whether any of the capture expressions requires cleanups.
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
bool CaptureHasSideEffects(const sema::LambdaScopeInfo::Capture &From)
Does copying/destroying the captured variable have side effects?
ImplicitCaptureStyle ImpCaptureStyle
ConditionalOperator - The ?: ternary operator.
Sema - This implements semantic analysis and AST building for C.
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
CompoundStmt - This represents a group of statements like { stmt stmt }.
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...
Represents a prototype with parameter type info, e.g.
SourceLocation getLocEnd() const LLVM_READONLY
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat)
DeclarationNameTable DeclarationNames
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI)
Note that we have finished the explicit captures for the given lambda.
SmallVector< LambdaCapture, 4 > Captures
SourceLocation PotentialThisCaptureLocation
unsigned NumExplicitCaptures
The number of captures in the Captures list that are explicit captures.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
unsigned getNumExprs() const
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
QualType getAutoDeductType() const
C++11 deduction pattern for 'auto' type.
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, Scope *CurScope)
ActOnLambdaExpr - This is called when the body of a lambda expression was successfully completed...
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
Expr - This represents one expression.
CanQualType getCanonicalFunctionResultType(QualType ResultType) const
Adjust the given function result type.
QualType buildLambdaInitCaptureInitialization(SourceLocation Loc, bool ByRef, IdentifierInfo *Id, bool DirectInit, Expr *&Init)
This file defines the classes used to store parsed information about declaration-specifiers and decla...
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
TranslationUnitDecl * getTranslationUnitDecl() const
const ParmVarDecl * getParamDecl(unsigned i) const
ExtProtoInfo getExtProtoInfo() const
void setRetValue(Expr *E)
DeclContext * getDeclContext()
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
static TemplateParameterList * getGenericLambdaTemplateParameterList(LambdaScopeInfo *LSI, Sema &SemaRef)
void buildLambdaScope(sema::LambdaScopeInfo *LSI, CXXMethodDecl *CallOperator, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, bool ExplicitParams, bool ExplicitResultType, bool Mutable)
Endow the lambda scope info with the relevant properties.
bool isConstexprSpecified() const
Capture & getCapture(VarDecl *Var)
Retrieve the capture of the given variable, if it has been captured already.
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Direct list-initialization (C++11)
bool isFunctionOrMethod() const
static bool isInInlineFunction(const DeclContext *DC)
Determine whether the given context is or is enclosed in an inline function.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
ReturnStmt - This represents a return, optionally of an expression: return; return 4;...
void setParams(ArrayRef< ParmVarDecl * > NewParamInfo)
struct CXXOpName CXXOperatorName
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
Represents a C++ conversion function within a class.
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type...
TypeSourceInfo * getTypeSourceInfo() const
CXXMethodDecl * startLambdaDefinition(CXXRecordDecl *Class, SourceRange IntroducerRange, TypeSourceInfo *MethodType, SourceLocation EndLoc, ArrayRef< ParmVarDecl * > Params, bool IsConstexprSpecified)
Start the definition of a lambda expression.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
static InitializationKind CreateCopy(SourceLocation InitLoc, SourceLocation EqualLoc, bool AllowExplicitConvs=false)
Create a copy initialization.
FieldDecl * buildInitCaptureField(sema::LambdaScopeInfo *LSI, VarDecl *Var)
Build the implicit field for an init-capture.
void setIsVariadic(bool value)
ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, sema::LambdaScopeInfo *LSI)
Complete a lambda-expression having processed and attached the lambda body.
Stmt * getBody(const FunctionDecl *&Definition) const
getBody - Retrieve the body (definition) of the function.
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
SourceLocation DefaultLoc
void setIsConversionFromLambda(bool val)
Encodes a location in the source.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
unsigned getNumParams() const
getNumParams - Return the number of parameters this function must have based on its FunctionType...
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
static InitializedEntity InitializeLambdaCapture(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
Create the initialization entity for a lambda capture.
void DiagnoseUnusedLambdaCapture(const sema::LambdaScopeInfo::Capture &From)
Diagnose if an explicit lambda capture is unused.
CXXRecordDecl * Lambda
The class that describes the lambda.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location, which defaults to the empty location.
void setReferenced(bool R=true)
Optional< unsigned > getStackIndexOfNearestEnclosingCaptureCapableLambda(ArrayRef< const sema::FunctionScopeInfo * > FunctionScopes, VarDecl *VarToCapture, Sema &S)
Examines the FunctionScopeInfo stack to determine the nearest enclosing lambda (to the current lambda...
Represents a static or instance method of a struct/union/class.
No ref-qualifier was provided.
C-style initialization with assignment.
ArrayRef< ParmVarDecl * > parameters() const
Describes the kind of initialization being performed, along with location information for tokens rela...
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
SmallVector< Capture, 4 > Captures
Captures - The captures.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
SourceLocation getBegin() const
const T * castAs() const
Member-template castAs<specific type>.
MangleNumberingContext * getCurrentMangleNumberContext(const DeclContext *DC, Decl *&ManglingContextDecl)
Compute the mangling number context for a lambda expression or block literal.
TypeLoc getReturnLoc() const
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool isFileContext() const
SourceLocation CaptureDefaultLoc
Source location of the '&' or '=' specifying the default capture type, if any.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
static LambdaExpr * Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, ArrayRef< LambdaCapture > Captures, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr * > CaptureInits, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
Construct a new lambda expression.
MutableArrayRef< Expr * > MultiExprArg
QualType getType() const
Return the type wrapped by this type source info.
static EnumDecl * findEnumForBlockReturn(Expr *E)
If this expression is an enumerator-like expression of some type T, return the type T; otherwise...
DeclarationNameLoc - Additional source/type location info for a declaration name. ...
SourceRange getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
This file provides some common utility functions for processing Lambdas.
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, bool IsInstantiation=false)
ActOnLambdaError - If there is an error parsing a lambda, this callback is invoked to pop the informa...
void setBody(CompoundStmt *B)
LambdaCaptureDefault Default
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
void deduceClosureReturnType(sema::CapturingScopeInfo &CSI)
Deduce a block or lambda's return type based on the return statements present in the body...
bool isInvalidDecl() const
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static void addBlockPointerConversion(Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator)
Add a lambda's conversion to block pointer.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
DeclarationName - The name of a declaration.
MangleNumberingContext & getManglingNumberContext(const DeclContext *DC)
Retrieve the context for computing mangling numbers in the given DeclContext.
SourceLocation getLocStart() const LLVM_READONLY
EnumDecl - Represents an enum.
detail::InMemoryDirectory::const_iterator E
const Expr * getRetValue() const
bool isCaptured(VarDecl *Var) const
Determine whether the given variable has been captured.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
void setInitCapture(bool IC)
Capturing variable-length array type.
bool empty() const
Return true if no decls were found.
void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, Declarator &ParamInfo, Scope *CurScope)
ActOnStartOfLambdaDefinition - This is called just before we start parsing the body of a lambda; it a...
const T * getAs() const
Member-template getAs<specific type>'.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
Simple template class for restricting typo correction candidates to ones having a single Decl* of the...
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
static CXXMethodDecl * Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc, const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo, StorageClass SC, bool isInline, bool isConstexpr, SourceLocation EndLocation)
void addDecl(Decl *D)
Add the declaration D into this context.
Capturing the *this object by reference.
void markUsed(ASTContext &C)
Mark the declaration used, in the sense of odr-use.
Capture & getCXXThisCapture()
Retrieve the capture of C++ 'this', if it has been captured.
void setSignatureAsWritten(TypeSourceInfo *Sig)
static BlockDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L)
Call-style initialization (C++98)
Describes the sequence of initializations required to initialize a given object or reference with a s...
Represents a C++ struct/union/class.
void setConstexpr(bool IC)
CallingConv getDefaultCallingConvention(bool isVariadic, bool IsCXXMethod) const
Retrieves the default calling convention for the current target.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Defines the clang::TargetInfo interface.
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
Represents a complete lambda introducer.
bool HasImplicitReturnType
Whether the target type of return statements in this context is deduced (e.g.
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
A reference to a declared variable, function, enum, etc.
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
void addCapture(VarDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, Expr *Cpy)
void setCaptures(ASTContext &Context, ArrayRef< Capture > Captures, bool CapturesCXXThis)
bool isParameterPack() const
Whether this declaration is a parameter pack.
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
void setLexicalDeclContext(DeclContext *DC)
NamedDecl - This represents a decl with a name.
void setAccess(AccessSpecifier AS)
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Describes an entity that is being initialized.
static FieldDecl * Create(const ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, InClassInitStyle InitStyle)
SourceLocation getLocStart() const LLVM_READONLY
Wrapper for source info for pointers.
Declaration of a template function.
bool hasLocalStorage() const
hasLocalStorage - Returns true if a variable with function scope is a non-static local variable...
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.
static void adjustBlockReturnsToEnum(Sema &S, ArrayRef< ReturnStmt * > returns, QualType returnType)
Adjust the given return statements so that they formally return the given type.