diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-02-13 17:20:40 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-02-13 17:20:40 +0000 |
commit | 7ae282fde0a12635893931ebf31b35b0d5d5cab3 (patch) | |
tree | 1760be025d78047b19cbc76822042ef8876289f7 /lib/AST/DeclCXX.cpp | |
parent | 9daa7bfdff7256cef693d7bf10084881bcb9253c (diff) |
Split the storage of lambda information between the LambdaExpr and the
CXXRecordDecl in a way that actually makes some sense:
- LambdaExpr contains all of the information for initializing the
lambda object, including the capture initializers and associated
array index variables.
- CXXRecordDecl's LambdaDefinitionData contains the captures, which
are needed to understand the captured variable references in the
body of the lambda.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150401 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclCXX.cpp')
-rw-r--r-- | lib/AST/DeclCXX.cpp | 52 |
1 files changed, 1 insertions, 51 deletions
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index fcd45088c2..5b9ab4ff5c 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -35,55 +35,6 @@ AccessSpecDecl *AccessSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) { return new (Mem) AccessSpecDecl(EmptyShell()); } -void CXXRecordDecl::LambdaDefinitionData::allocateExtra( - ArrayRef<LambdaExpr::Capture> Captures, - ArrayRef<Expr *> CaptureInits, - ArrayRef<VarDecl *> ArrayIndexVars, - ArrayRef<unsigned> ArrayIndexStarts, - Stmt *Body) { - NumCaptures = Captures.size(); - NumExplicitCaptures = 0; - - ASTContext &Context = Definition->getASTContext(); - unsigned ArrayIndexSize = 0; - if (ArrayIndexVars.size() > 0) { - HasArrayIndexVars = true; - ArrayIndexSize = sizeof(unsigned) * (Captures.size() + 1) - + sizeof(VarDecl *) * ArrayIndexVars.size(); - } - - this->Extra = Context.Allocate(sizeof(Capture) * Captures.size() + - sizeof(Stmt*) * (Captures.size() + 1) + - ArrayIndexSize); - - // Copy captures. - Capture *ToCapture = getCaptures(); - for (unsigned I = 0, N = Captures.size(); I != N; ++I) { - if (Captures[I].isExplicit()) - ++NumExplicitCaptures; - - *ToCapture++ = Captures[I]; - } - - // Copy initialization expressions for the non-static data members. - Stmt **Stored = getStoredStmts(); - for (unsigned I = 0, N = CaptureInits.size(); I != N; ++I) - *Stored++ = CaptureInits[I]; - - // Copy the body of the lambda. - *Stored++ = Body; - - if (ArrayIndexVars.size() > 0) { - assert(ArrayIndexStarts.size() == Captures.size()); - memcpy(getArrayIndexVars(), ArrayIndexVars.data(), - sizeof(VarDecl *) * ArrayIndexVars.size()); - memcpy(getArrayIndexStarts(), ArrayIndexStarts.data(), - sizeof(unsigned) * Captures.size()); - getArrayIndexStarts()[Captures.size()] = ArrayIndexVars.size(); - } -} - - CXXRecordDecl::DefinitionData::DefinitionData(CXXRecordDecl *D) : UserDeclaredConstructor(false), UserDeclaredCopyConstructor(false), UserDeclaredMoveConstructor(false), UserDeclaredCopyAssignment(false), @@ -1035,8 +986,7 @@ void CXXRecordDecl::getCaptureFields( LambdaDefinitionData &Lambda = getLambdaData(); RecordDecl::field_iterator Field = field_begin(); - for (LambdaExpr::Capture *C = Lambda.getCaptures(), - *CEnd = C + Lambda.NumCaptures; + for (LambdaExpr::Capture *C = Lambda.Captures, *CEnd = C + Lambda.NumCaptures; C != CEnd; ++C, ++Field) { if (C->capturesThis()) { ThisCapture = *Field; |