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;
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,
408 if (TemplateMethod) {
415 if (!Params.empty()) {
417 CheckParmsForFunctionDef(const_cast<ParmVarDecl **>(Params.begin()),
418 const_cast<ParmVarDecl **>(Params.end()),
421 for (
auto P : Method->
params())
422 P->setOwningFunction(Method);
425 Decl *ManglingContextDecl;
428 ManglingContextDecl)) {
429 unsigned ManglingNumber = MCtx->getManglingNumber(Method);
442 bool ExplicitResultType,
446 LSI->
Lambda = LambdaClass;
456 if (ExplicitResultType) {
462 diag::err_lambda_incomplete_result)) {
477 for (
unsigned p = 0, NumParams = CallOperator->
getNumParams();
478 p < NumParams; ++
p) {
483 CheckShadow(CurScope, Param);
485 PushOnScopeChains(Param, CurScope);
505 = dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
506 return cast<EnumDecl>(D->getDeclContext());
521 if (
StmtExpr *SE = dyn_cast<StmtExpr>(E)) {
522 if (
Expr *last = dyn_cast_or_null<Expr>(SE->getSubStmt()->body_back()))
551 return ET->getDecl();
574 if (!ED)
return nullptr;
577 for (++i; i != e; ++i) {
593 i = returns.begin(), e = returns.end(); i != e; ++i) {
605 Expr *
E = (cleanups ? cleanups->getSubExpr() : retValue);
609 cleanups->setSubExpr(E);
656 assert(!CSI.
ReturnType.
isNull() &&
"We should have a tentative return type.");
661 if (!getLangOpts().CPlusPlus) {
662 assert(isa<BlockScopeInfo>(CSI));
683 for (; I !=
E; ++
I) {
696 diag::err_typecheck_missing_return_type_incompatible)
698 << isa<LambdaScopeInfo>(CSI);
714 DeductType = BuildReferenceType(DeductType,
true, Loc, Id);
715 assert(!DeductType.
isNull() &&
"can't build reference to auto");
721 QualType DeducedType = deduceVarTypeFromInitializer(
737 Loc, Init->getLocStart(), Init->getLocEnd())
756 Result = ActOnFinishFullExpr(Init, Loc,
false,
759 if (Result.isInvalid())
762 Init = Result.getAs<
Expr>();
769 unsigned InitStyle,
Expr *Init) {
777 Loc, Id, InitCaptureType, TSI,
SC_Auto);
781 NewVD->
setInitStyle(static_cast<VarDecl::InitializationStyle>(InitStyle));
807 bool KnownDependent =
false;
809 assert(LSI &&
"LambdaScopeInfo should be on stack!");
816 if (TemplateParams) {
817 TmplScope = TmplScope->getParent();
818 TmplScope = TmplScope ? TmplScope->getTemplateParamParent() :
nullptr;
820 if (TmplScope && !TmplScope->decl_empty())
821 KnownDependent =
true;
825 bool ExplicitParams =
true;
826 bool ExplicitResultType =
true;
827 bool ContainsUnexpandedParameterPack =
false;
844 QualType DefaultTypeForNoTrailingReturn =
850 ExplicitParams =
false;
851 ExplicitResultType =
false;
855 "lambda-declarator is a function");
862 if (!FTI.hasMutableQualifier())
865 MethodTyInfo = GetTypeForDeclarator(ParamInfo, CurScope);
866 assert(MethodTyInfo &&
"no type from lambda-declarator");
869 ExplicitResultType = FTI.hasTrailingReturnType();
872 Params.reserve(FTI.NumParams);
873 for (
unsigned i = 0, e = FTI.NumParams; i != e; ++i)
874 Params.push_back(cast<ParmVarDecl>(FTI.Params[i].Param));
879 ContainsUnexpandedParameterPack =
true;
883 KnownDependent, Intro.
Default);
886 MethodTyInfo, EndLoc, Params);
888 CheckCXXDefaultArguments(Method);
891 ProcessDeclAttributes(CurScope, Method, ParamInfo);
894 PushDeclContext(CurScope, Method);
898 ExplicitParams, ExplicitResultType, !Method->
isConst());
912 (getCurrentThisType().isNull() ||
918 llvm::SmallSet<IdentifierInfo*, 8> CaptureNames;
924 PrevCaptureLoc =
C->Loc, ++
C) {
930 Diag(
C->Loc, diag::err_capture_more_than_once)
933 SourceRange(getLocForEndOfToken(PrevCaptureLoc),
C->Loc));
941 Diag(
C->Loc, diag::err_this_capture_with_copy_default)
943 SourceRange(getLocForEndOfToken(PrevCaptureLoc),
C->Loc));
950 QualType ThisCaptureType = getCurrentThisType();
951 if (ThisCaptureType.
isNull()) {
952 Diag(
C->Loc, diag::err_this_capture) <<
true;
956 CheckCXXThisCapture(
C->Loc,
true);
960 assert(
C->Id &&
"missing identifier for capture");
962 if (
C->Init.isInvalid())
966 if (
C->Init.isUsable()) {
968 ? diag::warn_cxx11_compat_init_capture
969 : diag::ext_init_capture);
971 if (
C->Init.get()->containsUnexpandedParameterPack())
972 ContainsUnexpandedParameterPack =
true;
978 if (
C->InitCaptureType.get().isNull())
982 switch (
C->InitKind) {
984 llvm_unreachable(
"not an init-capture?");
995 Var = createLambdaInitCaptureVarDecl(
C->Loc,
C->InitCaptureType.get(),
996 C->Id, InitStyle,
C->Init.get());
1002 PushOnScopeChains(Var, CurScope,
false);
1005 "init capture has valid but null init?");
1013 Diag(
C->Loc, diag::err_reference_capture_with_reference_default)
1015 SourceRange(getLocForEndOfToken(PrevCaptureLoc),
C->Loc));
1018 Diag(
C->Loc, diag::err_copy_capture_with_copy_default)
1020 SourceRange(getLocForEndOfToken(PrevCaptureLoc),
C->Loc));
1029 LookupName(R, CurScope);
1035 if (DiagnoseEmptyLookup(CurScope, ScopeSpec, R,
1041 if (Var && DiagnoseUseOfDecl(Var,
C->Loc))
1048 if (!CaptureNames.insert(
C->Id).second) {
1050 Diag(
C->Loc, diag::err_capture_more_than_once)
1053 SourceRange(getLocForEndOfToken(PrevCaptureLoc),
C->Loc));
1057 Diag(
C->Loc, diag::err_capture_more_than_once) <<
C->Id;
1066 Diag(
C->Loc, diag::err_capture_does_not_name_variable) <<
C->Id;
1075 Diag(
C->Loc, diag::err_capture_non_automatic_variable) <<
C->Id;
1083 if (
C->EllipsisLoc.isValid()) {
1085 EllipsisLoc =
C->EllipsisLoc;
1087 Diag(
C->EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
1093 ContainsUnexpandedParameterPack =
true;
1096 if (
C->Init.isUsable()) {
1097 buildInitCaptureField(LSI, Var);
1100 TryCapture_ExplicitByVal;
1101 tryCaptureVariable(Var,
C->Loc, Kind, EllipsisLoc);
1104 finishLambdaExplicitCaptures(LSI);
1109 addLambdaParameters(Method, CurScope);
1113 PushExpressionEvaluationContext(PotentiallyEvaluated);
1117 bool IsInstantiation) {
1121 DiscardCleanupsInEvaluationContext();
1122 PopExpressionEvaluationContext();
1125 if (!IsInstantiation)
1134 CheckCompletedCXXClass(Class);
1136 PopFunctionScopeInfo();
1148 std::mem_fn(&ParmVarDecl::hasAttr<PassObjectSizeAttr>)))
1165 "Lambda's call operator should not have a reference qualifier");
1247 CallOpConvTL.setParam(
I, From);
1248 CallOpConvNameTL.setParam(
I, From);
1259 CallOperator->
getBody()->getLocEnd());
1270 Loc, ConversionName,
1276 Class->
addDecl(ConversionTemplate);
1301 CallOperator->
getBody()->getLocEnd());
1303 InvokerParams[
I]->setOwningFunction(Invoke);
1311 S.
Context, Class, Loc, InvokerName,
1317 Class->
addDecl(StaticInvokerTemplate);
1337 BlockEPI.TypeQuals = 0;
1361 CallOperator->
getBody()->getLocEnd());
1368 Sema &
S, LambdaScopeInfo::Capture &Capture,
1372 assert(Capture.isVariableCapture() &&
"not a variable capture");
1374 auto *Var = Capture.getVariable();
1407 ArrayIndexStarts.push_back(ArrayIndexVars.size());
1414 llvm::raw_svector_ostream OS(Str);
1415 OS <<
"__i" << IndexVariables.size();
1422 IndexVariables.push_back(IterationVar);
1423 ArrayIndexVars.push_back(IterationVar);
1429 "Reference to invented variable cannot fail!");
1431 assert(!IterationVarRef.isInvalid() &&
1432 "Conversion of invented variable cannot fail!");
1437 if (Subscript.isInvalid())
1440 Ref = Subscript.get();
1441 BaseType = Array->getElementType();
1448 Entities.reserve(1 + IndexVariables.size());
1450 Var->getIdentifier(), FieldType, Loc));
1451 for (
unsigned I = 0, N = IndexVariables.size();
I != N; ++
I)
1457 return Init.
Perform(S, Entities.back(), InitKind, Ref);
1464 return BuildLambdaExpr(StartLoc, Body->getLocEnd(), &LSI);
1478 llvm_unreachable(
"block capture in lambda");
1480 llvm_unreachable(
"Unknown implicit capture style");
1494 bool ExplicitParams;
1495 bool ExplicitResultType;
1496 bool LambdaExprNeedsCleanups;
1497 bool ContainsUnexpandedParameterPack;
1510 Decl *TemplateOrNonTemplateCallOperatorDecl =
1513 : cast<Decl>(CallOperator);
1516 Class->
addDecl(TemplateOrNonTemplateCallOperatorDecl);
1518 PopExpressionEvaluationContext();
1522 for (
unsigned I = 0, N = LSI->
Captures.size();
I != N; ++
I, ++CurField) {
1523 LambdaScopeInfo::Capture From = LSI->
Captures[
I];
1524 assert(!From.isBlockCapture() &&
"Cannot capture __block variables");
1528 if (From.isThisCapture()) {
1532 getCurrentThisType(),
1534 ArrayIndexStarts.push_back(ArrayIndexVars.size());
1537 if (From.isVLATypeCapture()) {
1540 CaptureInits.push_back(
nullptr);
1541 ArrayIndexStarts.push_back(ArrayIndexVars.size());
1545 VarDecl *Var = From.getVariable();
1548 Var, From.getEllipsisLoc()));
1549 Expr *Init = From.getInitExpr();
1552 *
this, From, *CurField, ArrayIndexVars, ArrayIndexStarts);
1553 if (InitResult.isInvalid())
1555 Init = InitResult.get();
1557 ArrayIndexStarts.push_back(ArrayIndexVars.size());
1559 CaptureInits.push_back(Init);
1567 if (Captures.empty() && CaptureDefault ==
LCD_None)
1577 if (getLangOpts().Blocks && getLangOpts().ObjC1 &&
1585 CheckCompletedCXXClass(Class);
1588 if (LambdaExprNeedsCleanups)
1589 ExprNeedsCleanups =
true;
1592 CaptureDefault, CaptureDefaultLoc,
1594 ExplicitParams, ExplicitResultType,
1595 CaptureInits, ArrayIndexVars,
1596 ArrayIndexStarts, EndLoc,
1597 ContainsUnexpandedParameterPack);
1599 if (!CurContext->isDependentContext()) {
1600 switch (ExprEvalContexts.back().Context) {
1605 case UnevaluatedAbstract:
1615 case ConstantEvaluated:
1619 ExprEvalContexts.back().Lambdas.push_back(Lambda);
1622 case PotentiallyEvaluated:
1623 case PotentiallyEvaluatedIfUsed:
1628 return MaybeBindToTemporary(Lambda);
1638 = cast<CXXMethodDecl>(
1648 CurrentLocation, Src);
1650 Init = ActOnFinishFullExpr(Init.
get());
1686 ConvLocation,
nullptr,
1699 ExprCleanupObjects.push_back(Block);
1700 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)
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.
Decl - This represents one declaration (or definition), e.g.
LambdaCaptureDefault
The default, if any, capture method for a lambda expression.
ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, SourceLocation ConvLocation, CXXConversionDecl *Conv, Expr *Src)
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...
CK_IntegralCast - A cast between integral types (other than to boolean).
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.
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 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
Returns the parent of this method declaration, which is the class in which this method is defined...
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)
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.
param_iterator param_begin()
Represents the this expression in C++.
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.
void setInvalidDecl(bool Invalid=true)
setInvalidDecl - Indicates the Decl had a semantic error.
TranslationUnitDecl * getTranslationUnitDecl() const
const ParmVarDecl * getParamDecl(unsigned i) const
ExtProtoInfo getExtProtoInfo() const
void setRetValue(Expr *E)
DeclContext * getDeclContext()
static TemplateParameterList * 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.
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.
C-style initialization with assignment.
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 __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.
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...
param_iterator param_end()
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 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)
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.
bool Equals(const DeclContext *DC) const
Determine whether this declaration context is equivalent to the declaration context DC...
Represents a complete lambda introducer.
bool HasImplicitReturnType
Whether the target type of return statements in this context is deduced (e.g.
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
A reference to a declared variable, function, enum, etc.
SourceLocation getLocation() const
Retrieve the location at which this variable was captured.
void addCapture(VarDecl *Var, bool isBlock, bool isByref, bool isNested, SourceLocation Loc, SourceLocation EllipsisLoc, QualType CaptureType, Expr *Cpy)
An l-value expression is a reference to an object with independent storage.
void setCaptures(ASTContext &Context, ArrayRef< Capture > Captures, bool CapturesCXXThis)
bool isParameterPack() const
Whether this declaration is a parameter pack.
A trivial tuple used to represent a source range.
SourceLocation getLocation() const
void setLexicalDeclContext(DeclContext *DC)
NamedDecl - This represents a decl with a name.
void setAccess(AccessSpecifier AS)
bool 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
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.