24 using namespace clang;
62 static inline Optional<unsigned>
67 const Optional<unsigned> NoLambdaIsCaptureReady;
70 isa<clang::sema::LambdaScopeInfo>(
71 FunctionScopes[FunctionScopes.size() - 1]) &&
72 "The function on the top of sema's function-info stack must be a lambda");
75 const bool IsCapturingThis = !VarToCapture;
76 const bool IsCapturingVariable = !IsCapturingThis;
79 unsigned CurScopeIndex = FunctionScopes.size() - 1;
81 cast<sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex])->CallOperator;
85 cast<sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex]);
93 if (IsCapturingVariable &&
94 VarToCapture->getDeclContext()->Equals(EnclosingDC))
95 return NoLambdaIsCaptureReady;
114 if (IsCapturingVariable && !LSI->
isCaptured(VarToCapture))
115 return NoLambdaIsCaptureReady;
117 return NoLambdaIsCaptureReady;
121 assert(CurScopeIndex);
127 assert(CurScopeIndex < (FunctionScopes.size() - 1));
131 return CurScopeIndex + 1;
132 return NoLambdaIsCaptureReady;
179 if (!OptionalStackIndex)
180 return NoLambdaIsCaptureCapable;
182 const unsigned IndexOfCaptureReadyLambda = OptionalStackIndex.getValue();
183 assert(((IndexOfCaptureReadyLambda != (FunctionScopes.size() - 1)) ||
185 "The capture ready lambda for a potential capture can only be the "
186 "current lambda if it is a generic lambda");
189 cast<sema::LambdaScopeInfo>(FunctionScopes[IndexOfCaptureReadyLambda]);
192 const bool IsCapturingThis = !VarToCapture;
193 const bool IsCapturingVariable = !IsCapturingThis;
195 if (IsCapturingVariable) {
200 const bool CanCaptureVariable =
206 DeclRefType, &IndexOfCaptureReadyLambda);
207 if (!CanCaptureVariable)
208 return NoLambdaIsCaptureCapable;
213 const bool CanCaptureThis =
217 &IndexOfCaptureReadyLambda);
219 return NoLambdaIsCaptureCapable;
221 return IndexOfCaptureReadyLambda;
267 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(DC))
279 Decl *&ManglingContextDecl) {
282 ManglingContextDecl = ExprEvalContexts.back().ManglingContextDecl;
294 if (ManglingContextDecl) {
295 if (
ParmVarDecl *Param = dyn_cast<ParmVarDecl>(ManglingContextDecl)) {
298 if (LexicalDC->isRecord())
299 Kind = DefaultArgument;
300 }
else if (
VarDecl *Var = dyn_cast<VarDecl>(ManglingContextDecl)) {
301 if (Var->getDeclContext()->isRecord())
302 Kind = StaticDataMember;
303 }
else if (isa<FieldDecl>(ManglingContextDecl)) {
311 bool IsInNonspecializedTemplate =
312 !ActiveTemplateInstantiations.empty() || CurContext->isDependentContext();
317 if ((IsInNonspecializedTemplate &&
318 !(ManglingContextDecl && isa<ParmVarDecl>(ManglingContextDecl))) ||
320 ManglingContextDecl =
nullptr;
324 ManglingContextDecl =
nullptr;
327 case StaticDataMember:
329 if (!IsInNonspecializedTemplate) {
330 ManglingContextDecl =
nullptr;
337 case DefaultArgument:
339 return &ExprEvalContexts.back().getMangleNumberingContext(
Context);
342 llvm_unreachable(
"unexpected context");
348 assert(ManglingContextDecl &&
"Need to have a context declaration");
349 if (!MangleNumbering)
351 return *MangleNumbering;
368 if (Result->isUndeducedType()) {
392 MethodType, MethodTypeInfo,
401 Method->setLexicalDeclContext(CurContext);
405 Method->getLocation(), MethodName,
408 if (TemplateMethod) {
409 TemplateMethod->setLexicalDeclContext(CurContext);
415 if (!Params.empty()) {
417 CheckParmsForFunctionDef(Params,
421 P->setOwningFunction(Method);
424 Decl *ManglingContextDecl;
426 getCurrentMangleNumberContext(Class->getDeclContext(),
427 ManglingContextDecl)) {
428 unsigned ManglingNumber = MCtx->getManglingNumber(Method);
441 bool ExplicitResultType,
445 LSI->
Lambda = LambdaClass;
455 if (ExplicitResultType) {
461 diag::err_lambda_incomplete_result)) {
476 for (
unsigned p = 0, NumParams = CallOperator->
getNumParams();
477 p < NumParams; ++p) {
482 CheckShadow(CurScope, Param);
484 PushOnScopeChains(Param, CurScope);
504 = dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
505 return cast<EnumDecl>(D->getDeclContext());
513 if (BO->getOpcode() == BO_Comma)
520 if (
StmtExpr *SE = dyn_cast<StmtExpr>(E)) {
521 if (
Expr *last = dyn_cast_or_null<Expr>(SE->getSubStmt()->body_back()))
542 if (ICE->getCastKind() == CK_IntegralCast)
550 return ET->getDecl();
573 if (!ED)
return nullptr;
576 for (++i; i != e; ++i) {
592 i = returns.begin(), e = returns.end(); i != e; ++i) {
604 Expr *
E = (cleanups ? cleanups->getSubExpr() : retValue);
608 cleanups->setSubExpr(E);
619 assert((!isa<LambdaScopeInfo>(CSI) || !getLangOpts().
CPlusPlus14) &&
620 "lambda expressions use auto deduction in C++14 onwards");
657 assert(!CSI.
ReturnType.
isNull() &&
"We should have a tentative return type.");
662 if (!getLangOpts().CPlusPlus) {
663 assert(isa<BlockScopeInfo>(CSI));
684 for (; I !=
E; ++
I) {
697 diag::err_typecheck_missing_return_type_incompatible)
699 << isa<LambdaScopeInfo>(CSI);
715 DeductType = BuildReferenceType(DeductType,
true, Loc, Id);
716 assert(!DeductType.
isNull() &&
"can't build reference to auto");
722 QualType DeducedType = deduceVarTypeFromInitializer(
738 Loc, Init->getLocStart(), Init->getLocEnd())
757 Result = ActOnFinishFullExpr(Init, Loc,
false,
760 if (Result.isInvalid())
763 Init = Result.getAs<
Expr>();
770 unsigned InitStyle,
Expr *Init) {
778 Loc, Id, InitCaptureType, TSI,
SC_Auto);
780 NewVD->setReferenced(
true);
782 NewVD->
setInitStyle(static_cast<VarDecl::InitializationStyle>(InitStyle));
790 Context, LSI->
Lambda, Var->getLocation(), Var->getLocation(),
793 Field->setImplicit(
true);
808 bool KnownDependent =
false;
810 assert(LSI &&
"LambdaScopeInfo should be on stack!");
816 KnownDependent =
true;
820 bool ExplicitParams =
true;
821 bool ExplicitResultType =
true;
822 bool ContainsUnexpandedParameterPack =
false;
839 QualType DefaultTypeForNoTrailingReturn =
845 ExplicitParams =
false;
846 ExplicitResultType =
false;
850 "lambda-declarator is a function");
857 if (!FTI.hasMutableQualifier())
860 MethodTyInfo = GetTypeForDeclarator(ParamInfo, CurScope);
861 assert(MethodTyInfo &&
"no type from lambda-declarator");
864 ExplicitResultType = FTI.hasTrailingReturnType();
867 Params.reserve(FTI.NumParams);
868 for (
unsigned i = 0, e = FTI.NumParams; i != e; ++i)
869 Params.push_back(cast<ParmVarDecl>(FTI.Params[i].Param));
874 ContainsUnexpandedParameterPack =
true;
878 KnownDependent, Intro.
Default);
881 MethodTyInfo, EndLoc, Params);
883 CheckCXXDefaultArguments(Method);
886 ProcessDeclAttributes(CurScope, Method, ParamInfo);
889 PushDeclContext(CurScope, Method);
893 ExplicitParams, ExplicitResultType, !Method->
isConst());
907 (getCurrentThisType().isNull() ||
913 llvm::SmallSet<IdentifierInfo*, 8> CaptureNames;
919 PrevCaptureLoc = C->Loc, ++C) {
923 ? diag::ext_star_this_lambda_capture_cxx1z
924 : diag::warn_cxx14_compat_star_this_lambda_capture);
930 Diag(C->Loc, diag::err_capture_more_than_once)
933 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
943 Diag(C->Loc, diag::err_this_capture_with_copy_default)
945 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
952 QualType ThisCaptureType = getCurrentThisType();
953 if (ThisCaptureType.
isNull()) {
954 Diag(C->Loc, diag::err_this_capture) <<
true;
958 CheckCXXThisCapture(C->Loc,
true,
true,
964 assert(C->Id &&
"missing identifier for capture");
966 if (C->Init.isInvalid())
970 if (C->Init.isUsable()) {
972 ? diag::warn_cxx11_compat_init_capture
973 : diag::ext_init_capture);
975 if (C->Init.get()->containsUnexpandedParameterPack())
976 ContainsUnexpandedParameterPack =
true;
982 if (C->InitCaptureType.get().isNull())
986 switch (C->InitKind) {
988 llvm_unreachable(
"not an init-capture?");
999 Var = createLambdaInitCaptureVarDecl(C->Loc, C->InitCaptureType.get(),
1000 C->Id, InitStyle, C->Init.get());
1006 PushOnScopeChains(Var, CurScope,
false);
1009 "init capture has valid but null init?");
1017 Diag(C->Loc, diag::err_reference_capture_with_reference_default)
1019 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1022 Diag(C->Loc, diag::err_copy_capture_with_copy_default)
1024 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1033 LookupName(R, CurScope);
1039 if (DiagnoseEmptyLookup(CurScope, ScopeSpec, R,
1045 if (Var && DiagnoseUseOfDecl(Var, C->Loc))
1052 if (!CaptureNames.insert(C->Id).second) {
1054 Diag(C->Loc, diag::err_capture_more_than_once)
1057 SourceRange(getLocForEndOfToken(PrevCaptureLoc), C->Loc));
1061 Diag(C->Loc, diag::err_capture_more_than_once) << C->Id;
1070 Diag(C->Loc, diag::err_capture_does_not_name_variable) << C->Id;
1075 if (Var->isInvalidDecl())
1079 Diag(C->Loc, diag::err_capture_non_automatic_variable) << C->Id;
1080 Diag(Var->getLocation(), diag::note_previous_decl) << C->Id;
1087 if (C->EllipsisLoc.isValid()) {
1088 if (Var->isParameterPack()) {
1089 EllipsisLoc = C->EllipsisLoc;
1091 Diag(C->EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1096 }
else if (Var->isParameterPack()) {
1097 ContainsUnexpandedParameterPack =
true;
1100 if (C->Init.isUsable()) {
1101 buildInitCaptureField(LSI, Var);
1104 TryCapture_ExplicitByVal;
1105 tryCaptureVariable(Var, C->Loc, Kind, EllipsisLoc);
1108 finishLambdaExplicitCaptures(LSI);
1113 addLambdaParameters(Method, CurScope);
1117 PushExpressionEvaluationContext(PotentiallyEvaluated);
1121 bool IsInstantiation) {
1125 DiscardCleanupsInEvaluationContext();
1126 PopExpressionEvaluationContext();
1129 if (!IsInstantiation)
1134 Class->setInvalidDecl();
1136 ActOnFields(
nullptr, Class->getLocation(), Class, Fields,
SourceLocation(),
1138 CheckCompletedCXXClass(Class);
1140 PopFunctionScopeInfo();
1152 std::mem_fn(&ParmVarDecl::hasAttr<PassObjectSizeAttr>)))
1169 "Lambda's call operator should not have a reference qualifier");
1245 From->getLocation(),
1251 CallOpConvTL.setParam(
I, From);
1252 CallOpConvNameTL.setParam(
I, From);
1263 CallOperator->
getBody()->getLocEnd());
1265 Conversion->setImplicit(
true);
1274 Loc, ConversionName,
1277 ConversionTemplate->setAccess(
AS_public);
1278 ConversionTemplate->setImplicit(
true);
1280 Class->
addDecl(ConversionTemplate);
1305 CallOperator->
getBody()->getLocEnd());
1307 InvokerParams[
I]->setOwningFunction(Invoke);
1310 Invoke->setImplicit(
true);
1315 S.
Context, Class, Loc, InvokerName,
1318 StaticInvokerTemplate->setAccess(
AS_private);
1319 StaticInvokerTemplate->setImplicit(
true);
1321 Class->
addDecl(StaticInvokerTemplate);
1341 BlockEPI.TypeQuals = 0;
1365 CallOperator->
getBody()->getLocEnd());
1367 Conversion->setImplicit(
true);
1372 Sema &
S, LambdaScopeInfo::Capture &Capture,
1376 assert(Capture.isVariableCapture() &&
"not a variable capture");
1378 auto *Var = Capture.getVariable();
1411 ArrayIndexStarts.push_back(ArrayIndexVars.size());
1418 llvm::raw_svector_ostream OS(Str);
1419 OS <<
"__i" << IndexVariables.size();
1425 IterationVar->setImplicit();
1426 IndexVariables.push_back(IterationVar);
1427 ArrayIndexVars.push_back(IterationVar);
1433 "Reference to invented variable cannot fail!");
1435 assert(!IterationVarRef.isInvalid() &&
1436 "Conversion of invented variable cannot fail!");
1441 if (Subscript.isInvalid())
1444 Ref = Subscript.get();
1445 BaseType = Array->getElementType();
1452 Entities.reserve(1 + IndexVariables.size());
1454 Var->getIdentifier(), FieldType, Loc));
1455 for (
unsigned I = 0, N = IndexVariables.size();
I != N; ++
I)
1461 return Init.
Perform(S, Entities.back(), InitKind, Ref);
1468 return BuildLambdaExpr(StartLoc, Body->getLocEnd(), &LSI);
1482 llvm_unreachable(
"block capture in lambda");
1484 llvm_unreachable(
"Unknown implicit capture style");
1498 bool ExplicitParams;
1499 bool ExplicitResultType;
1501 bool ContainsUnexpandedParameterPack;
1513 CallOperator->setLexicalDeclContext(Class);
1514 Decl *TemplateOrNonTemplateCallOperatorDecl =
1517 : cast<Decl>(CallOperator);
1519 TemplateOrNonTemplateCallOperatorDecl->setLexicalDeclContext(Class);
1520 Class->
addDecl(TemplateOrNonTemplateCallOperatorDecl);
1522 PopExpressionEvaluationContext();
1526 for (
unsigned I = 0, N = LSI->
Captures.size();
I != N; ++
I, ++CurField) {
1527 LambdaScopeInfo::Capture From = LSI->
Captures[
I];
1528 assert(!From.isBlockCapture() &&
"Cannot capture __block variables");
1532 if (From.isThisCapture()) {
1536 CaptureInits.push_back(From.getInitExpr());
1537 ArrayIndexStarts.push_back(ArrayIndexVars.size());
1540 if (From.isVLATypeCapture()) {
1543 CaptureInits.push_back(
nullptr);
1544 ArrayIndexStarts.push_back(ArrayIndexVars.size());
1548 VarDecl *Var = From.getVariable();
1551 Var, From.getEllipsisLoc()));
1552 Expr *Init = From.getInitExpr();
1555 *
this, From, *CurField, ArrayIndexVars, ArrayIndexStarts);
1556 if (InitResult.isInvalid())
1558 Init = InitResult.get();
1560 ArrayIndexStarts.push_back(ArrayIndexVars.size());
1562 CaptureInits.push_back(Init);
1570 if (Captures.empty() && CaptureDefault ==
LCD_None)
1580 if (getLangOpts().Blocks && getLangOpts().ObjC1 &&
1586 ActOnFields(
nullptr, Class->getLocation(), Class, Fields,
SourceLocation(),
1588 CheckCompletedCXXClass(Class);
1591 Cleanup.mergeFrom(LambdaCleanup);
1594 CaptureDefault, CaptureDefaultLoc,
1596 ExplicitParams, ExplicitResultType,
1597 CaptureInits, ArrayIndexVars,
1598 ArrayIndexStarts, EndLoc,
1599 ContainsUnexpandedParameterPack);
1601 if (!CurContext->isDependentContext()) {
1602 switch (ExprEvalContexts.back().Context) {
1607 case UnevaluatedAbstract:
1617 case ConstantEvaluated:
1621 ExprEvalContexts.back().Lambdas.push_back(Lambda);
1624 case DiscardedStatement:
1625 case PotentiallyEvaluated:
1626 case PotentiallyEvaluatedIfUsed:
1631 return MaybeBindToTemporary(Lambda);
1641 = cast<CXXMethodDecl>(
1644 CallOperator->setReferenced();
1645 CallOperator->markUsed(
Context);
1651 CurrentLocation, Src);
1653 Init = ActOnFinishFullExpr(Init.
get());
1672 From->getLocation(),
1689 ConvLocation,
nullptr,
1702 ExprCleanupObjects.push_back(Block);
1703 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...
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...
DeclClass * getAsSingle() 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...
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
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.
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, SourceLocation ConvLocation, CXXConversionDecl *Conv, Expr *Src)
ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, Expr *Idx, SourceLocation RLoc)
static InitializationKind CreateDirect(SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a direct initialization.
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.
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.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
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.
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.
static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc, QualType Type, bool NRVO)
bool isIntegralOrUnscopedEnumerationType() const
Determine whether this type is an integral or unscoped enumeration type.
void setNameLoc(SourceLocation Loc)
Represents the results of name lookup.
unsigned getNumTypeObjects() const
Return the number of types applied to this declarator.
< Capturing the *this object by copy
static LambdaCaptureDefault mapImplicitCaptureStyle(CapturingScopeInfo::ImplicitCaptureStyle ICS)
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.
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 ExprResult performLambdaVarCaptureInitialization(Sema &S, LambdaScopeInfo::Capture &Capture, FieldDecl *Field, SmallVectorImpl< VarDecl * > &ArrayIndexVars, SmallVectorImpl< unsigned > &ArrayIndexStarts)
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.
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.
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.
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.
TranslationUnitDecl * getTranslationUnitDecl() const
const ParmVarDecl * getParamDecl(unsigned i) const
ExtProtoInfo getExtProtoInfo() const
void setRetValue(Expr *E)
static TemplateParameterList * getGenericLambdaTemplateParameterList(LambdaScopeInfo *LSI, Sema &SemaRef)
MangleNumberingContext * createMangleNumberingContext() const
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.
CXXMethodDecl * startLambdaDefinition(CXXRecordDecl *Class, SourceRange IntroducerRange, TypeSourceInfo *MethodType, SourceLocation EndLoc, ArrayRef< ParmVarDecl * > Params)
Start the definition of a lambda expression.
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
Represents a C++ conversion function within a class.
The result type of a method or function.
bool hasNameForLinkage() const
Is this tag type named, either directly or via being defined in a typedef of this type...
TypeSourceInfo * getTypeSourceInfo() const
CallingConv
CallingConv - Specifies the calling convention that a function uses.
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)
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc)
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.
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.
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 InitializedEntity InitializeElement(ASTContext &Context, unsigned Index, const InitializedEntity &Parent)
Create the initialization entity for an array element.
Represents a static or instance method of a struct/union/class.
ExprResult DefaultLvalueConversion(Expr *E)
No ref-qualifier was provided.
C-style initialization with assignment.
ArrayRef< ParmVarDecl * > parameters() const
const ConstantArrayType * getAsConstantArrayType(QualType T) const
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 ...
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;}).
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...
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
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...
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>'.
Simple template class for restricting typo correction candidates to ones having a single Decl* of the...
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.
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)
ExprResult BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
Describes the sequence of initializations required to initialize a given object or reference with a s...
Represents a C++ struct/union/class.
CallingConv getDefaultCallingConvention(bool isVariadic, bool IsCXXMethod) const
Retrieves the default calling convention for the current target.
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
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)
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)
An l-value expression is a reference to an object with independent storage.
void setCaptures(ASTContext &Context, ArrayRef< Capture > Captures, bool CapturesCXXThis)
A trivial tuple used to represent a source range.
NamedDecl - This represents a decl with a name.
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)
Wrapper for source info for pointers.
static LambdaExpr * Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, ArrayRef< LambdaCapture > Captures, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr * > CaptureInits, ArrayRef< VarDecl * > ArrayIndexVars, ArrayRef< unsigned > ArrayIndexStarts, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
Construct a new lambda expression.
Represents the canonical version of C arrays with a specified constant size.
Declaration of a template function.
bool hasLocalStorage() const
hasLocalStorage - Returns true if a variable with function scope is a non-static local variable...
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.