class CXXRecordDecl;
class Decl;
class FieldDecl;
+ class LambdaExpr;
class MangleContext;
class ObjCIvarDecl;
class ObjCIvarRefExpr;
llvm::DenseMap<const FunctionDecl*, FunctionDecl*>
ClassScopeSpecializationPattern;
+ /// \brief Mapping from closure types to the lambda expressions that
+ /// create instances of them.
+ llvm::DenseMap<const CXXRecordDecl *, LambdaExpr *> Lambdas;
+
/// \brief Representation of a "canonical" template template parameter that
/// is used in canonical template names.
class CanonicalTemplateTemplateParm : public llvm::FoldingSetNode {
friend class ASTDeclReader;
friend class ASTReader;
friend class ASTWriter;
-
+ friend class CXXRecordDecl;
+
const TargetInfo *Target;
clang::PrintingPolicy PrintingPolicy;
#include "clang/AST/Decl.h"
#include "clang/AST/TypeLoc.h"
#include "clang/AST/UnresolvedSet.h"
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SmallPtrSet.h"
class CXXFinalOverriderMap;
class CXXIndirectPrimaryBaseSet;
class FriendDecl;
+class LambdaExpr;
/// \brief Represents any kind of function declaration, whether it is a
/// concrete function or a function template.
/// \brief Determine whether this class describes a lambda function object.
bool isLambda() const { return hasDefinition() && data().IsLambda; }
- void setLambda(bool Lambda = true) { data().IsLambda = Lambda; }
+ /// \brief Mark this as a closure type from a lambda expression.
+ void makeLambda() { data().IsLambda = true; }
+
+ /// \brief Set the lambda expression associated with this closure type.
+ void setLambda(LambdaExpr *Lambda);
+
+ /// \brief For a closure type, retrieve the mapping from captured
+ /// variables and this to the non-static data members that store the
+ /// values or references of the captures.
+ ///
+ /// \param Captures Will be populated with the mapping from captured
+ /// variables to the corresponding fields.
+ ///
+ /// \param ThisCapture Will be set to the field declaration for the
+ /// 'this' capture.
+ void getCaptureFields(llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
+ FieldDecl *&ThisCapture);
/// getConversions - Retrieve the overload set containing all of the
/// conversion functions in this class.
return isPOD() && data().HasOnlyCMembers;
}
+void CXXRecordDecl::setLambda(LambdaExpr *Lambda) {
+ if (!Lambda)
+ return;
+
+ data().IsLambda = true;
+ getASTContext().Lambdas[this] = Lambda;
+}
+
+void CXXRecordDecl::getCaptureFields(
+ llvm::DenseMap<const VarDecl *, FieldDecl *> &Captures,
+ FieldDecl *&ThisCapture) {
+ Captures.clear();
+ ThisCapture = 0;
+
+ LambdaExpr *Lambda = getASTContext().Lambdas[this];
+ RecordDecl::field_iterator Field = field_begin();
+ for (LambdaExpr::capture_iterator C = Lambda->capture_begin(),
+ CEnd = Lambda->capture_end();
+ C != CEnd; ++C, ++Field) {
+ if (C->capturesThis()) {
+ ThisCapture = *Field;
+ continue;
+ }
+
+ Captures[C->getCapturedVar()] = *Field;
+ }
+}
+
+
static CanQualType GetConversionType(ASTContext &Context, NamedDecl *Conv) {
QualType T;
if (isa<UsingShadowDecl>(Conv))
/*IdLoc=*/Intro.Range.getBegin(),
/*Id=*/0);
Class->startDefinition();
- Class->setLambda(true);
+ Class->makeLambda();
CurContext->addDecl(Class);
// Build the call operator; we don't really have all the relevant information
CaptureDefault, Captures,
ExplicitParams, CaptureInits,
Body->getLocEnd());
+ Class->setLambda(Lambda);
// C++11 [expr.prim.lambda]p2:
// A lambda-expression shall not appear in an unevaluated operand