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 &&
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;
266 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(DC))
278 Decl *&ManglingContextDecl) {
281 ManglingContextDecl = ExprEvalContexts.back().ManglingContextDecl;
293 if (ManglingContextDecl) {
294 if (
ParmVarDecl *Param = dyn_cast<ParmVarDecl>(ManglingContextDecl)) {
297 if (LexicalDC->isRecord())
298 Kind = DefaultArgument;
299 }
else if (
VarDecl *Var = dyn_cast<VarDecl>(ManglingContextDecl)) {
300 if (Var->getDeclContext()->isRecord())
301 Kind = StaticDataMember;
302 }
else if (isa<FieldDecl>(ManglingContextDecl)) {
310 bool IsInNonspecializedTemplate =
311 !ActiveTemplateInstantiations.empty() || CurContext->isDependentContext();
316 if ((IsInNonspecializedTemplate &&
317 !(ManglingContextDecl && isa<ParmVarDecl>(ManglingContextDecl))) ||
319 ManglingContextDecl =
nullptr;
323 ManglingContextDecl =
nullptr;
326 case StaticDataMember:
328 if (!IsInNonspecializedTemplate) {
329 ManglingContextDecl =
nullptr;
336 case DefaultArgument:
338 return &ExprEvalContexts.back().getMangleNumberingContext(
Context);
341 llvm_unreachable(
"unexpected context");
347 assert(ManglingContextDecl &&
"Need to have a context declaration");
348 if (!MangleNumbering)
350 return *MangleNumbering;
367 if (Result->isUndeducedType()) {
391 MethodType, MethodTypeInfo,
407 if (TemplateMethod) {
414 if (!Params.empty()) {
416 CheckParmsForFunctionDef(const_cast<ParmVarDecl **>(Params.begin()),
417 const_cast<ParmVarDecl **>(Params.end()),
420 for (
auto P : Method->
params())
421 P->setOwningFunction(Method);
424 Decl *ManglingContextDecl;
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());
520 if (
StmtExpr *SE = dyn_cast<StmtExpr>(E)) {
521 if (
Expr *last = dyn_cast_or_null<Expr>(SE->getSubStmt()->body_back()))
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);
655 assert(!CSI.
ReturnType.
isNull() &&
"We should have a tentative return type.");
660 if (!getLangOpts().CPlusPlus) {
661 assert(isa<BlockScopeInfo>(CSI));
682 for (; I != E; ++I) {
694 diag::err_typecheck_missing_return_type_incompatible)
696 << isa<LambdaScopeInfo>(CSI);
711 const bool IsDirectInit = isa<ParenListExpr>(Init) || isa<InitListExpr>(Init);
719 DeductType = BuildReferenceType(DeductType,
true, Loc, Id);
720 assert(!DeductType.
isNull() &&
"can't build reference to auto");
728 Expr *DeduceInit = Init;
733 Diag(CXXDirectInit->
getLocStart(), diag::err_init_capture_no_expression)
738 diag::err_init_capture_multiple_expressions)
742 DeduceInit = CXXDirectInit->
getExpr(0);
743 if (isa<InitListExpr>(DeduceInit))
744 Diag(CXXDirectInit->
getLocStart(), diag::err_init_capture_paren_braces)
752 if (DeduceAutoType(TSI, DeduceInit, DeducedType) == DAR_Failed) {
753 if (isa<InitListExpr>(Init))
754 Diag(Loc, diag::err_init_capture_deduction_failure_from_init_list)
756 << (DeduceInit->getType().isNull() ? TSI->
getType()
757 : DeduceInit->getType())
758 << DeduceInit->getSourceRange();
760 Diag(Loc, diag::err_init_capture_deduction_failure)
762 << (DeduceInit->getType().isNull() ? TSI->
getType()
763 : DeduceInit->getType())
764 << DeduceInit->getSourceRange();
776 Loc, Init->getLocStart(), Init->getLocEnd())
795 Result = ActOnFinishFullExpr(Init, Loc,
false,
798 if (Result.isInvalid())
801 Init = Result.getAs<
Expr>();
815 Loc, Id, InitCaptureType, TSI,
SC_Auto);
843 bool KnownDependent =
false;
845 assert(LSI &&
"LambdaScopeInfo should be on stack!");
852 if (TemplateParams) {
853 TmplScope = TmplScope->getParent();
854 TmplScope = TmplScope ? TmplScope->getTemplateParamParent() :
nullptr;
856 if (TmplScope && !TmplScope->decl_empty())
857 KnownDependent =
true;
861 bool ExplicitParams =
true;
862 bool ExplicitResultType =
true;
863 bool ContainsUnexpandedParameterPack =
false;
880 QualType DefaultTypeForNoTrailingReturn =
886 ExplicitParams =
false;
887 ExplicitResultType =
false;
891 "lambda-declarator is a function");
898 if (!FTI.hasMutableQualifier())
901 MethodTyInfo = GetTypeForDeclarator(ParamInfo, CurScope);
902 assert(MethodTyInfo &&
"no type from lambda-declarator");
905 ExplicitResultType = FTI.hasTrailingReturnType();
908 Params.reserve(FTI.NumParams);
909 for (
unsigned i = 0, e = FTI.NumParams; i != e; ++i)
910 Params.push_back(cast<ParmVarDecl>(FTI.Params[i].Param));
915 ContainsUnexpandedParameterPack =
true;
919 KnownDependent, Intro.
Default);
922 MethodTyInfo, EndLoc, Params);
924 CheckCXXDefaultArguments(Method);
927 ProcessDeclAttributes(CurScope, Method, ParamInfo);
930 PushDeclContext(CurScope, Method);
934 ExplicitParams, ExplicitResultType, !Method->
isConst());
948 (getCurrentThisType().isNull() ||
954 llvm::SmallSet<IdentifierInfo*, 8> CaptureNames;
960 PrevCaptureLoc =
C->Loc, ++
C) {
966 Diag(
C->Loc, diag::err_capture_more_than_once)
969 SourceRange(getLocForEndOfToken(PrevCaptureLoc),
C->Loc));
977 Diag(
C->Loc, diag::err_this_capture_with_copy_default)
979 SourceRange(getLocForEndOfToken(PrevCaptureLoc),
C->Loc));
986 QualType ThisCaptureType = getCurrentThisType();
987 if (ThisCaptureType.
isNull()) {
988 Diag(
C->Loc, diag::err_this_capture) <<
true;
992 CheckCXXThisCapture(
C->Loc,
true);
996 assert(
C->Id &&
"missing identifier for capture");
998 if (
C->Init.isInvalid())
1002 if (
C->Init.isUsable()) {
1004 ? diag::warn_cxx11_compat_init_capture
1005 : diag::ext_init_capture);
1007 if (
C->Init.get()->containsUnexpandedParameterPack())
1008 ContainsUnexpandedParameterPack =
true;
1014 if (
C->InitCaptureType.get().isNull())
1016 Var = createLambdaInitCaptureVarDecl(
C->Loc,
C->InitCaptureType.get(),
1017 C->Id,
C->Init.get());
1023 PushOnScopeChains(Var, CurScope,
false);
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(PotentiallyEvaluated);
1135 bool IsInstantiation) {
1139 DiscardCleanupsInEvaluationContext();
1140 PopExpressionEvaluationContext();
1143 if (!IsInstantiation)
1152 CheckCompletedCXXClass(Class);
1154 PopFunctionScopeInfo();
1177 "Lambda's call operator should not have a reference qualifier");
1246 for (
unsigned I = 0, N = CallOperator->
getNumParams(); I != N; ++I) {
1259 CallOpConvTL.setParam(I, From);
1260 CallOpConvNameTL.setParam(I, From);
1271 CallOperator->
getBody()->getLocEnd());
1282 Loc, ConversionName,
1288 Class->
addDecl(ConversionTemplate);
1313 CallOperator->
getBody()->getLocEnd());
1314 for (
unsigned I = 0, N = CallOperator->
getNumParams(); I != N; ++I)
1315 InvokerParams[I]->setOwningFunction(Invoke);
1323 S.
Context, Class, Loc, InvokerName,
1329 Class->
addDecl(StaticInvokerTemplate);
1349 BlockEPI.TypeQuals = 0;
1373 CallOperator->
getBody()->getLocEnd());
1380 Sema &
S, LambdaScopeInfo::Capture &Capture,
1384 assert(Capture.isVariableCapture() &&
"not a variable capture");
1386 auto *Var = Capture.getVariable();
1419 ArrayIndexStarts.push_back(ArrayIndexVars.size());
1426 llvm::raw_svector_ostream OS(Str);
1427 OS <<
"__i" << IndexVariables.size();
1434 IndexVariables.push_back(IterationVar);
1435 ArrayIndexVars.push_back(IterationVar);
1441 "Reference to invented variable cannot fail!");
1443 assert(!IterationVarRef.isInvalid() &&
1444 "Conversion of invented variable cannot fail!");
1449 if (Subscript.isInvalid())
1452 Ref = Subscript.get();
1453 BaseType = Array->getElementType();
1460 Entities.reserve(1 + IndexVariables.size());
1462 Var->getIdentifier(), FieldType, Loc));
1463 for (
unsigned I = 0, N = IndexVariables.size(); I != N; ++I)
1469 return Init.
Perform(S, Entities.back(), InitKind, Ref);
1476 return BuildLambdaExpr(StartLoc, Body->getLocEnd(), &LSI);
1490 llvm_unreachable(
"block capture in lambda");
1492 llvm_unreachable(
"Unknown implicit capture style");
1506 bool ExplicitParams;
1507 bool ExplicitResultType;
1508 bool LambdaExprNeedsCleanups;
1509 bool ContainsUnexpandedParameterPack;
1522 Decl *TemplateOrNonTemplateCallOperatorDecl =
1525 : cast<Decl>(CallOperator);
1528 Class->
addDecl(TemplateOrNonTemplateCallOperatorDecl);
1530 PopExpressionEvaluationContext();
1534 for (
unsigned I = 0, N = LSI->
Captures.size(); I != N; ++I, ++CurField) {
1535 LambdaScopeInfo::Capture From = LSI->
Captures[I];
1536 assert(!From.isBlockCapture() &&
"Cannot capture __block variables");
1540 if (From.isThisCapture()) {
1544 getCurrentThisType(),
1546 ArrayIndexStarts.push_back(ArrayIndexVars.size());
1549 if (From.isVLATypeCapture()) {
1552 CaptureInits.push_back(
nullptr);
1553 ArrayIndexStarts.push_back(ArrayIndexVars.size());
1557 VarDecl *Var = From.getVariable();
1560 Var, From.getEllipsisLoc()));
1561 Expr *Init = From.getInitExpr();
1564 *
this, From, *CurField, ArrayIndexVars, ArrayIndexStarts);
1565 if (InitResult.isInvalid())
1567 Init = InitResult.get();
1569 ArrayIndexStarts.push_back(ArrayIndexVars.size());
1571 CaptureInits.push_back(Init);
1579 if (Captures.empty() && CaptureDefault ==
LCD_None)
1589 if (getLangOpts().Blocks && getLangOpts().ObjC1 &&
1597 CheckCompletedCXXClass(Class);
1600 if (LambdaExprNeedsCleanups)
1601 ExprNeedsCleanups =
true;
1604 CaptureDefault, CaptureDefaultLoc,
1606 ExplicitParams, ExplicitResultType,
1607 CaptureInits, ArrayIndexVars,
1608 ArrayIndexStarts, EndLoc,
1609 ContainsUnexpandedParameterPack);
1611 if (!CurContext->isDependentContext()) {
1612 switch (ExprEvalContexts.back().Context) {
1617 case UnevaluatedAbstract:
1627 case ConstantEvaluated:
1631 ExprEvalContexts.back().Lambdas.push_back(Lambda);
1634 case PotentiallyEvaluated:
1635 case PotentiallyEvaluatedIfUsed:
1640 return MaybeBindToTemporary(Lambda);
1650 = cast<CXXMethodDecl>(
1660 CurrentLocation, Src);
1662 Init = ActOnFinishFullExpr(Init.
get());
1677 for (
unsigned I = 0, N = CallOperator->
getNumParams(); I != N; ++I) {
1698 ConvLocation,
nullptr,
1712 ExprCleanupObjects.push_back(Block);
1713 ExprNeedsCleanups =
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)
SourceRange IntroducerRange
Source range covering the lambda introducer [...].
DeclaratorChunk::FunctionTypeInfo & getFunctionTypeInfo()
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.
VarDecl * createLambdaInitCaptureVarDecl(SourceLocation Loc, QualType InitCaptureType, IdentifierInfo *Id, Expr *Init)
Create a dummy variable within the declcontext of the lambda's call operator, for name lookup purpose...
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
IdentifierInfo * getIdentifier() const
DeclClass * getAsSingle() const
static EnumDecl * findCommonEnumForBlockReturns(ArrayRef< ReturnStmt * > returns)
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, NamedDecl **Params, unsigned NumParams, SourceLocation RAngleLoc)
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...
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.
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.
ExtProtoInfo - 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.
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
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.
void setBlockMissingReturnType(bool val)
void setCaptures(ASTContext &Context, const Capture *begin, const Capture *end, bool capturesCXXThis)
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. For the computed linkage of symbol, see getLinkage.
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 by copy (a.k.a., by value)
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
field_range fields() const
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 ExprNeedsCleanups
Whether any of the capture expressions requires cleanups.
bool isVariadic() const
Whether this function is variadic.
DeclContext * getLambdaAwareParentOfDeclContext(DeclContext *DC)
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)
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)
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. If this is a generic lambda, store the list of the auto parameters converted into TemplateTypeParmDecls into a vector that can be used to construct the generic lambda's template parameter list, during initial AST construction.
TypeSpecTypeLoc pushTypeSpec(QualType T)
Represents the this expression in C++.
TyLocType push(QualType T)
ImplicitCaptureStyle ImpCaptureStyle
Sema - This implements semantic analysis and AST building for C.
bool isFunctionDeclarator(unsigned &idx) const
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...
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. function call operator ...
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()
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
QualType getAutoDeductType() const
C++11 deduction pattern for 'auto' type.
ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, Scope *CurScope)
bool isUndeducedType() const
Determine whether this type is an undeduced type, meaning that it somehow involves a C++11 'auto' typ...
const Expr * getExpr(unsigned Init) const
This file defines the classes used to store parsed information about declaration-specifiers and decla...
void setInvalidDecl(bool Invalid=true)
TranslationUnitDecl * getTranslationUnitDecl() const
const ParmVarDecl * getParamDecl(unsigned i) const
ExtProtoInfo getExtProtoInfo() const
void setRetValue(Expr *E)
DeclContext * getDeclContext()
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
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.
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
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)
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
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
SourceLocation DefaultLoc
void setIsConversionFromLambda(bool val)
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
unsigned getNumParams() const
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
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.
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...
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.
const ConstantArrayType * getAsConstantArrayType(QualType T) const
Describes the kind of initialization being performed, along with location information for tokens rela...
QualType performLambdaInitCaptureInitialization(SourceLocation Loc, bool ByRef, IdentifierInfo *Id, Expr *&Init)
Perform initialization analysis of the init-capture and perform any implicit conversions such as an l...
SmallVector< Capture, 4 > Captures
Captures - The captures.
SourceLocation getBegin() const
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
const SourceRange & getSourceRange() const LLVM_READONLY
Get the source range that spans this declarator.
bool isFileContext() const
SourceLocation CaptureDefaultLoc
Source location of the '&' or '=' specifying the default capture type, if any.
MutableArrayRef< Expr * > MultiExprArg
QualType getType() const
Return the type wrapped by this type source info.
static EnumDecl * findEnumForBlockReturn(Expr *E)
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
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)
void setBody(CompoundStmt *B)
LambdaCaptureDefault Default
void deduceClosureReturnType(sema::CapturingScopeInfo &CSI)
Deduce a block or lambda's return type based on the return statements present in the body...
SourceLocation getLocStart() const LLVM_READONLY
static __inline__ uint32_t volatile uint32_t * p
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.
MangleNumberingContext & getManglingNumberContext(const DeclContext *DC)
Retrieve the context for computing mangling numbers in the given DeclContext.
SourceLocation getLocStart() const LLVM_READONLY
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 ...
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)
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
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.
static LambdaExpr * Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, ArrayRef< Capture > Captures, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr * > CaptureInits, ArrayRef< VarDecl * > ArrayIndexVars, ArrayRef< unsigned > ArrayIndexStarts, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
Construct a new lambda expression.
Capturing the this pointer.
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)
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.
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. a lambda or block with ...
A reference to a declared variable, function, enum, etc. [C99 6.5.1p2].
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.
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)
void setAccess(AccessSpecifier AS)
bool CheckCXXThisCapture(SourceLocation Loc, bool Explicit=false, bool BuildAndDiagnose=true, const unsigned *const FunctionScopeIndexToStopAt=nullptr)
Make sure the value of 'this' is actually available in the current context, if it is a potentially ev...
bool isNull() const
isNull - 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.
Declaration of a template function.
bool hasLocalStorage() const
Expr * IgnoreParens() LLVM_READONLY
static void adjustBlockReturnsToEnum(Sema &S, ArrayRef< ReturnStmt * > returns, QualType returnType)