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;
299 if (ManglingContextDecl) {
300 if (
ParmVarDecl *Param = dyn_cast<ParmVarDecl>(ManglingContextDecl)) {
303 if (LexicalDC->isRecord())
304 Kind = DefaultArgument;
305 }
else if (
VarDecl *Var = dyn_cast<VarDecl>(ManglingContextDecl)) {
306 if (Var->getDeclContext()->isRecord())
307 Kind = StaticDataMember;
308 else if (Var->getMostRecentDecl()->isInline())
309 Kind = InlineVariable;
310 else if (Var->getDescribedVarTemplate())
311 Kind = VariableTemplate;
312 else if (
auto *VTS = dyn_cast<VarTemplateSpecializationDecl>(Var)) {
313 if (!VTS->isExplicitSpecialization())
314 Kind = VariableTemplate;
316 }
else if (isa<FieldDecl>(ManglingContextDecl)) {
324 bool IsInNonspecializedTemplate =
325 inTemplateInstantiation() || CurContext->isDependentContext();
330 if ((IsInNonspecializedTemplate &&
331 !(ManglingContextDecl && isa<ParmVarDecl>(ManglingContextDecl))) ||
333 ManglingContextDecl =
nullptr;
334 while (
auto *CD = dyn_cast<CapturedDecl>(DC))
339 ManglingContextDecl =
nullptr;
343 case StaticDataMember:
345 if (!IsInNonspecializedTemplate) {
346 ManglingContextDecl =
nullptr;
354 case DefaultArgument:
358 case VariableTemplate:
360 return &ExprEvalContexts.back().getMangleNumberingContext(Context);
363 llvm_unreachable(
"unexpected context");
369 assert(ManglingContextDecl &&
"Need to have a context declaration");
370 if (!MangleNumbering)
372 return *MangleNumbering;
380 const bool IsConstexprSpecified) {
390 if (Result->isUndeducedType()) {
391 Result = SubstAutoType(Result, Context.
DependentTy);
414 MethodType, MethodTypeInfo,
417 IsConstexprSpecified,
430 if (TemplateMethod) {
437 if (!Params.empty()) {
439 CheckParmsForFunctionDef(Params,
443 P->setOwningFunction(Method);
446 Decl *ManglingContextDecl;
449 ManglingContextDecl)) {
450 unsigned ManglingNumber = MCtx->getManglingNumber(Method);
463 bool ExplicitResultType,
467 LSI->
Lambda = LambdaClass;
477 if (ExplicitResultType) {
483 diag::err_lambda_incomplete_result)) {
498 for (
unsigned p = 0, NumParams = CallOperator->
getNumParams();
499 p < NumParams; ++p) {
504 CheckShadow(CurScope, Param);
506 PushOnScopeChains(Param, CurScope);
526 = dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
527 return cast<EnumDecl>(D->getDeclContext());
535 if (BO->getOpcode() == BO_Comma)
542 if (
StmtExpr *SE = dyn_cast<StmtExpr>(E)) {
543 if (
Expr *last = dyn_cast_or_null<Expr>(SE->getSubStmt()->body_back()))
564 if (ICE->getCastKind() == CK_IntegralCast)
572 return ET->getDecl();
595 if (!ED)
return nullptr;
598 for (++i; i != e; ++i) {
614 i = returns.begin(), e = returns.end(); i != e; ++i) {
626 Expr *E = (cleanups ? cleanups->getSubExpr() : retValue);
630 cleanups->setSubExpr(E);
641 assert((!isa<LambdaScopeInfo>(CSI) || !getLangOpts().
CPlusPlus14) &&
642 "lambda expressions use auto deduction in C++14 onwards");
679 assert(!CSI.
ReturnType.
isNull() &&
"We should have a tentative return type.");
684 if (!getLangOpts().CPlusPlus) {
685 assert(isa<BlockScopeInfo>(CSI));
706 for (; I != E; ++I) {
711 (RetE ? RetE->
getType() : Context.
VoidTy).getUnqualifiedType();
719 diag::err_typecheck_missing_return_type_incompatible)
721 << isa<LambdaScopeInfo>(CSI);
737 DeductType = BuildReferenceType(DeductType,
true, Loc, Id);
738 assert(!DeductType.
isNull() &&
"can't build reference to auto");
779 Result = ActOnFinishFullExpr(Init, Loc,
false,
782 if (Result.isInvalid())
785 Init = Result.getAs<
Expr>();
792 unsigned InitStyle,
Expr *Init) {
800 Loc, Id, InitCaptureType, TSI,
SC_Auto);
804 NewVD->
setInitStyle(static_cast<VarDecl::InitializationStyle>(InitStyle));
830 bool KnownDependent =
false;
832 assert(LSI &&
"LambdaScopeInfo should be on stack!");
838 KnownDependent =
true;
842 bool ExplicitParams =
true;
843 bool ExplicitResultType =
true;
844 bool ContainsUnexpandedParameterPack =
false;
861 QualType DefaultTypeForNoTrailingReturn =
867 ExplicitParams =
false;
868 ExplicitResultType =
false;
872 "lambda-declarator is a function");
879 if (!FTI.hasMutableQualifier())
882 MethodTyInfo = GetTypeForDeclarator(ParamInfo, CurScope);
883 assert(MethodTyInfo &&
"no type from lambda-declarator");
886 ExplicitResultType = FTI.hasTrailingReturnType();
889 Params.reserve(FTI.NumParams);
890 for (
unsigned i = 0, e = FTI.NumParams; i != e; ++i)
891 Params.push_back(cast<ParmVarDecl>(FTI.Params[i].Param));
896 ContainsUnexpandedParameterPack =
true;
900 KnownDependent, Intro.
Default);
903 startLambdaDefinition(Class, Intro.
Range, MethodTyInfo, EndLoc, Params,
906 CheckCXXDefaultArguments(Method);
909 ProcessDeclAttributes(CurScope, Method, ParamInfo);
913 if (getLangOpts().CUDA)
914 CUDASetLambdaAttrs(Method);
917 PushDeclContext(CurScope, Method);
921 ExplicitParams, ExplicitResultType, !Method->
isConst());
935 (getCurrentThisType().isNull() ||
941 llvm::SmallSet<IdentifierInfo*, 8> CaptureNames;
947 PrevCaptureLoc = C->Loc, ++C) {
951 ? diag::ext_star_this_lambda_capture_cxx17
952 : diag::warn_cxx14_compat_star_this_lambda_capture);
958 Diag(C->Loc, diag::err_capture_more_than_once)
961 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
972 ? diag::ext_equals_this_lambda_capture_cxx2a
973 : diag::warn_cxx17_compat_equals_this_lambda_capture);
978 QualType ThisCaptureType = getCurrentThisType();
979 if (ThisCaptureType.
isNull()) {
980 Diag(C->Loc, diag::err_this_capture) <<
true;
984 CheckCXXThisCapture(C->Loc,
true,
true,
990 assert(C->Id &&
"missing identifier for capture");
992 if (C->Init.isInvalid())
996 if (C->Init.isUsable()) {
998 ? diag::warn_cxx11_compat_init_capture
999 : diag::ext_init_capture);
1001 if (C->Init.get()->containsUnexpandedParameterPack())
1002 ContainsUnexpandedParameterPack =
true;
1008 if (C->InitCaptureType.get().isNull())
1012 switch (C->InitKind) {
1014 llvm_unreachable(
"not an init-capture?");
1025 Var = createLambdaInitCaptureVarDecl(C->Loc, C->InitCaptureType.get(),
1026 C->Id, InitStyle, C->Init.get());
1032 PushOnScopeChains(Var, CurScope,
false);
1035 "init capture has valid but null init?");
1043 Diag(C->Loc, diag::err_reference_capture_with_reference_default)
1045 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1048 Diag(C->Loc, diag::err_copy_capture_with_copy_default)
1050 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1059 LookupName(R, CurScope);
1065 if (DiagnoseEmptyLookup(CurScope, ScopeSpec, R,
1071 if (Var && DiagnoseUseOfDecl(Var, C->Loc))
1078 if (!CaptureNames.insert(C->Id).second) {
1080 Diag(C->Loc, diag::err_capture_more_than_once)
1083 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1087 Diag(C->Loc, diag::err_capture_more_than_once) << C->Id;
1096 Diag(C->Loc, diag::err_capture_does_not_name_variable) << C->Id;
1105 Diag(C->Loc, diag::err_capture_non_automatic_variable) << C->Id;
1113 if (C->EllipsisLoc.isValid()) {
1115 EllipsisLoc = C->EllipsisLoc;
1117 Diag(C->EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1123 ContainsUnexpandedParameterPack =
true;
1126 if (C->Init.isUsable()) {
1127 buildInitCaptureField(LSI, Var);
1130 TryCapture_ExplicitByVal;
1131 tryCaptureVariable(Var, C->Loc, Kind, EllipsisLoc);
1134 finishLambdaExplicitCaptures(LSI);
1139 addLambdaParameters(Method, CurScope);
1143 PushExpressionEvaluationContext(
1144 ExpressionEvaluationContext::PotentiallyEvaluated);
1148 bool IsInstantiation) {
1152 DiscardCleanupsInEvaluationContext();
1153 PopExpressionEvaluationContext();
1156 if (!IsInstantiation)
1165 CheckCompletedCXXClass(Class);
1167 PopFunctionScopeInfo();
1183 "Lambda's call operator should not have a reference qualifier");
1196 auto HasPassObjectSizeAttr = [](
const ParmVarDecl *
P) {
1197 return P->hasAttr<PassObjectSizeAttr>();
1199 if (llvm::any_of(CallOperator->
parameters(), HasPassObjectSizeAttr))
1269 for (
unsigned I = 0, N = CallOperator->
getNumParams(); I != N; ++I) {
1282 CallOpConvTL.setParam(I, From);
1283 CallOpConvNameTL.setParam(I, From);
1305 Loc, ConversionName,
1311 Class->
addDecl(ConversionTemplate);
1337 for (
unsigned I = 0, N = CallOperator->
getNumParams(); I != N; ++I)
1338 InvokerParams[I]->setOwningFunction(Invoke);
1346 S.
Context, Class, Loc, InvokerName,
1352 Class->
addDecl(StaticInvokerTemplate);
1392 Sema &S,
const LambdaScopeInfo::Capture &Capture,
FieldDecl *Field) {
1393 assert(Capture.isVariableCapture() &&
"not a variable capture");
1395 auto *Var = Capture.getVariable();
1417 Var->getIdentifier(), Field->
getType(), Loc);
1420 return Init.
Perform(S, Entity, InitKind, Ref);
1427 return BuildLambdaExpr(StartLoc, Body->
getLocEnd(), &LSI);
1441 llvm_unreachable(
"block capture in lambda");
1443 llvm_unreachable(
"Unknown implicit capture style");
1447 if (!From.isVLATypeCapture()) {
1448 Expr *Init = From.getInitExpr();
1453 if (!From.isCopyCapture())
1458 : From.getCaptureType();
1465 return !RD->isCompleteDefinition() || !RD->hasTrivialCopyConstructor() ||
1466 !RD->hasTrivialDestructor();
1472 if (CaptureHasSideEffects(From))
1475 if (From.isVLATypeCapture())
1478 auto diag =
Diag(From.getLocation(), diag::warn_unused_lambda_capture);
1479 if (From.isThisCapture())
1482 diag << From.getVariable();
1483 diag << From.isNonODRUsed();
1497 bool ExplicitParams;
1498 bool ExplicitResultType;
1500 bool ContainsUnexpandedParameterPack;
1501 bool IsGenericLambda;
1513 Decl *TemplateOrNonTemplateCallOperatorDecl =
1516 : cast<Decl>(CallOperator);
1519 Class->
addDecl(TemplateOrNonTemplateCallOperatorDecl);
1521 PopExpressionEvaluationContext();
1525 for (
unsigned I = 0, N = LSI->
Captures.size(); I != N; ++I, ++CurField) {
1526 const LambdaScopeInfo::Capture &From = LSI->
Captures[I];
1527 assert(!From.isBlockCapture() &&
"Cannot capture __block variables");
1531 if (!CurContext->isDependentContext() && !IsImplicit && !From.isODRUsed()) {
1533 bool NonODRUsedInitCapture =
1534 IsGenericLambda && From.isNonODRUsed() && From.getInitExpr();
1535 if (!NonODRUsedInitCapture)
1536 DiagnoseUnusedLambdaCapture(From);
1540 if (From.isThisCapture()) {
1544 CaptureInits.push_back(From.getInitExpr());
1547 if (From.isVLATypeCapture()) {
1550 CaptureInits.push_back(
nullptr);
1554 VarDecl *Var = From.getVariable();
1557 Var, From.getEllipsisLoc()));
1558 Expr *Init = From.getInitExpr();
1562 if (InitResult.isInvalid())
1564 Init = InitResult.get();
1566 CaptureInits.push_back(Init);
1574 if (Captures.empty() && CaptureDefault ==
LCD_None)
1584 if (getLangOpts().Blocks && getLangOpts().ObjC1 && !IsGenericLambda)
1591 CheckCompletedCXXClass(Class);
1594 Cleanup.mergeFrom(LambdaCleanup);
1597 CaptureDefault, CaptureDefaultLoc,
1599 ExplicitParams, ExplicitResultType,
1600 CaptureInits, EndLoc,
1601 ContainsUnexpandedParameterPack);
1607 !isa<CoroutineBodyStmt>(CallOperator->
getBody()) &&
1611 CheckConstexprFunctionDecl(CallOperator) &&
1612 CheckConstexprFunctionBody(CallOperator, CallOperator->
getBody()));
1616 DiagnoseShadowingLambdaDecls(LSI);
1618 if (!CurContext->isDependentContext()) {
1619 switch (ExprEvalContexts.back().Context) {
1623 case ExpressionEvaluationContext::Unevaluated:
1624 case ExpressionEvaluationContext::UnevaluatedList:
1625 case ExpressionEvaluationContext::UnevaluatedAbstract:
1635 case ExpressionEvaluationContext::ConstantEvaluated:
1639 ExprEvalContexts.back().Lambdas.push_back(Lambda);
1642 case ExpressionEvaluationContext::DiscardedStatement:
1643 case ExpressionEvaluationContext::PotentiallyEvaluated:
1644 case ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed:
1649 return MaybeBindToTemporary(Lambda);
1659 = cast<CXXMethodDecl>(
1668 CurrentLocation, Src);
1670 Init = ActOnFinishFullExpr(Init.
get());
1685 for (
unsigned I = 0, N = CallOperator->
getNumParams(); I != N; ++I) {
1706 ConvLocation,
nullptr,
1719 ExprCleanupObjects.push_back(Block);
1720 Cleanup.setExprNeedsCleanups(
true);
void setImplicit(bool I=true)
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.
unsigned getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it...
A (possibly-)qualified type.
bool ExplicitParams
Whether the (empty) parameter list is explicit.
TemplateParameterList * GLTemplateParameterList
If this is a generic lambda, and the template parameter list has been created (from the AutoTemplateP...
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...
Stmt - This represents one statement.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
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.
StorageClass getStorageClass() const
Returns the storage class as written in the source.
bool isConstexpr() const
Whether this is a (C++11) constexpr function or constexpr constructor.
Decl - This represents one declaration (or definition), e.g.
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
CanQualType getCanonicalFunctionResultType(QualType ResultType) const
Adjust the given function result type.
ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, SourceLocation ConvLocation, CXXConversionDecl *Conv, Expr *Src)
static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a direct initialization.
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
The base class of the type hierarchy.
void setParams(ArrayRef< ParmVarDecl *> NewParamInfo)
bool isFunctionDeclarator(unsigned &idx) const
isFunctionDeclarator - This method returns true if the declarator is a function declarator (looking t...
RefQualifierKind RefQualifier
A container of type source information.
SourceLocation getLocStart() const LLVM_READONLY
QualType getConversionType() const
Returns the type that this conversion function is converting to.
void setInitStyle(InitializationStyle Style)
Describes the capture of a variable or of this, or of a C++1y init-capture.
This file provides some common utility functions for processing Lambda related AST Constructs...
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.
QualType getReturnType() const
const T * getAs() const
Member-template getAs<specific type>'.
Extra information about a function prototype.
bool isInvalidDecl() const
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 isParameterPack() const
Whether this declaration is a parameter pack.
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 ...
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.
tok::TokenKind ContextKind
bool FTIHasNonVoidParameters(const DeclaratorChunk::FunctionTypeInfo &FTI)
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
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
field_range fields() const
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
std::unique_ptr< MangleNumberingContext > createMangleNumberingContext() 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...
const Expr * getRetValue() const
bool isReferenceType() const
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
void setParams(ArrayRef< ParmVarDecl *> NewParamInfo)
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.
static ExprResult performLambdaVarCaptureInitialization(Sema &S, const LambdaScopeInfo::Capture &Capture, FieldDecl *Field)
An r-value expression (a pr-value in the C++11 taxonomy) produces a temporary value.
ArrayRef< ParmVarDecl * > parameters() const
DeclClass * getAsSingle() const
void setNameLoc(SourceLocation Loc)
Represents the results of name lookup.
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
RAII class used to indicate that we are performing provisional semantic analysis to determine the val...
< Capturing the *this object by copy
static LambdaCaptureDefault mapImplicitCaptureStyle(CapturingScopeInfo::ImplicitCaptureStyle ICS)
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...
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
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...
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
A builtin binary operation expression such as "x + y" or "x <= y".
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
void setLambdaMangling(unsigned ManglingNumber, Decl *ContextDecl)
Set the mangling number and context declaration for a lambda class.
CXXMethodDecl * startLambdaDefinition(CXXRecordDecl *Class, SourceRange IntroducerRange, TypeSourceInfo *MethodType, SourceLocation EndLoc, ArrayRef< ParmVarDecl *> Params, bool IsConstexprSpecified)
Start the definition of a lambda expression.
void finishedExplicitCaptures()
Note when all explicit captures have been added.
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...
field_iterator field_begin() const
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...
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type...
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)
const LangOptions & getLangOpts() const
bool isLambdaCallOperator(const CXXMethodDecl *MD)
static FunctionTemplateDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L, DeclarationName Name, TemplateParameterList *Params, NamedDecl *Decl)
Create a function template node.
StringRef getLambdaStaticInvokerName()
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
QualType getLambdaConversionFunctionResultType(const FunctionProtoType *CallOpType)
Get the return type to use for a lambda's conversion function(s) to function pointer type...
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.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
bool CaptureHasSideEffects(const sema::LambdaScopeInfo::Capture &From)
Does copying/destroying the captured variable have side effects?
ExtInfo withCallingConv(CallingConv cc) const
ImplicitCaptureStyle ImpCaptureStyle
bool isIntegralOrUnscopedEnumerationType() const
Determine whether this type is an integral or unscoped enumeration type.
ConditionalOperator - The ?: ternary operator.
Sema - This implements semantic analysis and AST building for C.
CompoundStmt - This represents a group of statements like { stmt stmt }.
bool Mutable
Whether this is a mutable lambda.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
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
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.
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.
bool HasSideEffects(const ASTContext &Ctx, bool IncludePossibleEffects=true) const
HasSideEffects - This routine returns true for all those expressions which have any effect other than...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
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...
Expr - This represents one expression.
bool isVariadic() const
Whether this function is variadic.
bool hasLocalStorage() const
hasLocalStorage - Returns true if a variable with function scope is a non-static local variable...
QualType buildLambdaInitCaptureInitialization(SourceLocation Loc, bool ByRef, IdentifierInfo *Id, bool DirectInit, Expr *&Init)
const FunctionProtoType * T
This file defines the classes used to store parsed information about declaration-specifiers and decla...
const T * castAs() const
Member-template castAs<specific type>.
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
void setRetValue(Expr *E)
bool isFileContext() const
DeclContext * getDeclContext()
bool isConstexprSpecified() const
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 isCaptured(VarDecl *Var) const
Determine whether the given variable has been captured.
bool isFunctionOrMethod() const
Capture & getCapture(VarDecl *Var)
Retrieve the capture of the given variable, if it has been captured already.
Direct list-initialization (C++11)
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.
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;...
SourceLocation getEnd() const
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
struct CXXOpName CXXOperatorName
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Common base class for placeholders for types that get replaced by placeholder type deduction: C++11 a...
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Represents a C++ conversion function within a class.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
TypeLoc getReturnLoc() const
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl *> Params, SourceLocation RAngleLoc, Expr *RequiresClause)
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.
SourceLocation DefaultLoc
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
void setIsConversionFromLambda(bool val)
ExtProtoInfo getExtProtoInfo() const
unsigned getNumExprs() const
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
Encodes a location in the source.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
QualType getReturnType() const
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.
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 setReferenced(bool R=true)
Represents a static or instance method of a struct/union/class.
No ref-qualifier was provided.
C-style initialization with assignment.
const ParmVarDecl * getParamDecl(unsigned i) const
bool isGenericLambda() const
Determine whether this class describes a generic lambda function object (i.e.
Describes the kind of initialization being performed, along with location information for tokens rela...
SmallVector< Capture, 4 > Captures
Captures - The captures.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
MangleNumberingContext * getCurrentMangleNumberContext(const DeclContext *DC, Decl *&ManglingContextDecl)
Compute the mangling number context for a lambda expression or block literal.
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;}).
MutableArrayRef< Expr * > MultiExprArg
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.
CallingConv getDefaultCallingConvention(bool IsVariadic, bool IsCXXMethod) const
Retrieves the default calling convention for the current target.
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)
Dataflow Directional Tag Classes.
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...
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...
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
const Expr * getInit() const
static void addBlockPointerConversion(Sema &S, SourceRange IntroducerRange, CXXRecordDecl *Class, CXXMethodDecl *CallOperator)
Add a lambda's conversion to block pointer.
DeclarationName - The name of a declaration.
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
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.
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspnd...
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
void setInitCapture(bool IC)
Capturing variable-length array type.
void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, Declarator &ParamInfo, Scope *CurScope)
ActOnStartOfLambdaDefinition - This is called just before we start parsing the body of a lambda; it a...
TypeSourceInfo * getTypeSourceInfo() const
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Simple template class for restricting typo correction candidates to ones having a single Decl* of the...
QualType getAutoDeductType() const
C++11 deduction pattern for 'auto' type.
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.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
void setSignatureAsWritten(TypeSourceInfo *Sig)
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
static BlockDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation L)
Call-style initialization (C++98)
TranslationUnitDecl * getTranslationUnitDecl() const
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)
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
bool isCXXThisCaptured() const
Determine whether the C++ 'this' is captured.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
Defines the clang::TargetInfo interface.
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)
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
A reference to a declared variable, function, enum, etc.
void addCapture(VarDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, Expr *Cpy)
bool empty() const
Return true if no decls were found.
void setCaptures(ASTContext &Context, ArrayRef< Capture > Captures, bool CapturesCXXThis)
A trivial tuple used to represent a source range.
void setLexicalDeclContext(DeclContext *DC)
NamedDecl - This represents a decl with a name.
bool isTranslationUnit() const
void setAccess(AccessSpecifier AS)
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)
unsigned getNumParams() const
Return the number of parameters this function must have based on its FunctionType.
SourceLocation getLocStart() const LLVM_READONLY
Wrapper for source info for pointers.
SourceLocation getBegin() const
static void adjustBlockReturnsToEnum(Sema &S, ArrayRef< ReturnStmt *> returns, QualType returnType)
Adjust the given return statements so that they formally return the given type.
Declaration of a template function.
SourceLocation getLocation() const
QualType getType() const
Return the type wrapped by this type source info.
Expr * IgnoreParens() LLVM_READONLY
IgnoreParens - Ignore parentheses.