Stmt *Body;
TypeSourceInfo *SignatureAsWritten;
- Capture *Captures;
+ const Capture *Captures;
unsigned NumCaptures;
unsigned ManglingNumber;
bool capturesVariable(const VarDecl *var) const;
- void setCaptures(ASTContext &Context,
- const Capture *begin,
- const Capture *end,
- bool capturesCXXThis);
+ void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
+ bool CapturesCXXThis);
unsigned getBlockManglingNumber() const {
return ManglingNumber;
}
}
-void BlockDecl::setCaptures(ASTContext &Context,
- const Capture *begin,
- const Capture *end,
- bool capturesCXXThis) {
- CapturesCXXThis = capturesCXXThis;
-
- if (begin == end) {
- NumCaptures = 0;
- Captures = nullptr;
+void BlockDecl::setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
+ bool CapturesCXXThis) {
+ this->CapturesCXXThis = CapturesCXXThis;
+ this->NumCaptures = Captures.size();
+
+ if (Captures.empty()) {
+ this->Captures = nullptr;
return;
}
- NumCaptures = end - begin;
-
- // Avoid new Capture[] because we don't want to provide a default
- // constructor.
- size_t allocationSize = NumCaptures * sizeof(Capture);
- void *buffer = Context.Allocate(allocationSize, /*alignment*/sizeof(void*));
- memcpy(buffer, begin, allocationSize);
- Captures = static_cast<Capture*>(buffer);
+ this->Captures = Captures.copy(Context).data();
}
bool BlockDecl::capturesVariable(const VarDecl *variable) const {
Cap.isNested(), Cap.getInitExpr());
Captures.push_back(NewCap);
}
- BSI->TheDecl->setCaptures(Context, Captures.begin(), Captures.end(),
- BSI->CXXThisCaptureIndex != 0);
+ BSI->TheDecl->setCaptures(Context, Captures, BSI->CXXThisCaptureIndex != 0);
// If the user wrote a function type in some form, try to use that.
if (!BSI->FunctionType.isNull()) {
SC_None);
BlockDecl::Capture Capture(/*Variable=*/CapVar, /*ByRef=*/false,
/*Nested=*/false, /*Copy=*/Init.get());
- Block->setCaptures(Context, &Capture, &Capture + 1,
- /*CapturesCXXThis=*/false);
+ Block->setCaptures(Context, Capture, /*CapturesCXXThis=*/false);
// Add a fake function body to the block. IR generation is responsible
// for filling in the actual body, which cannot be expressed as an AST.
captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
}
- BD->setCaptures(Reader.getContext(), captures.begin(),
- captures.end(), capturesCXXThis);
+ BD->setCaptures(Reader.getContext(), captures, capturesCXXThis);
}
void ASTDeclReader::VisitCapturedDecl(CapturedDecl *CD) {