public:
static CapturedDecl *Create(ASTContext &C, DeclContext *DC, unsigned NumParams);
+ static CapturedDecl *CreateDeserialized(ASTContext &C, unsigned ID,
+ unsigned NumParams);
Stmt *getBody() const { return Body; }
void setBody(Stmt *B) { Body = B; }
+ unsigned getNumParams() const { return NumParams; }
+
ImplicitParamDecl *getParam(unsigned i) const {
assert(i < NumParams);
return getParams()[i];
static CapturedDecl *castFromDeclContext(const DeclContext *DC) {
return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC));
}
+
+ friend class ASTDeclReader;
+ friend class ASTDeclWriter;
};
/// \brief Describes a module import declaration, which makes the contents
assert(!capturesThis() && "No variable available for 'this' capture");
return VarAndKind.getPointer();
}
+ friend class ASTStmtReader;
};
private:
Capture *getStoredCaptures() const;
+ void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; }
+
public:
static CapturedStmt *Create(ASTContext &Context, Stmt *S,
ArrayRef<Capture> Captures,
bool capturesVariable(const VarDecl *Var) const;
/// \brief An iterator that walks over the captures.
- typedef const Capture *capture_iterator;
+ typedef Capture *capture_iterator;
+ typedef const Capture *const_capture_iterator;
/// \brief Retrieve an iterator pointing to the first capture.
- capture_iterator capture_begin() const { return getStoredCaptures(); }
+ capture_iterator capture_begin() { return getStoredCaptures(); }
+ const_capture_iterator capture_begin() const { return getStoredCaptures(); }
/// \brief Retrieve an iterator pointing past the end of the sequence of
/// captures.
}
child_range children();
+
+ friend class ASTStmtReader;
};
} // end namespace clang
CapturedDecl *CapturedDecl::Create(ASTContext &C, DeclContext *DC,
unsigned NumParams) {
- unsigned Size = sizeof(CapturedDecl) + NumParams *sizeof(ImplicitParamDecl*);
+ unsigned Size = sizeof(CapturedDecl) + NumParams * sizeof(ImplicitParamDecl*);
return new (C.Allocate(Size)) CapturedDecl(DC, NumParams);
}
+CapturedDecl *CapturedDecl::CreateDeserialized(ASTContext &C, unsigned ID,
+ unsigned NumParams) {
+ unsigned Size = sizeof(CapturedDecl) + NumParams * sizeof(ImplicitParamDecl*);
+ void *Mem = AllocateDeserializedDecl(C, ID, Size);
+ return new (Mem) CapturedDecl(0, NumParams);
+}
+
EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD,
SourceLocation L,
IdentifierInfo *Id, QualType T,
}
bool CapturedStmt::capturesVariable(const VarDecl *Var) const {
- for (capture_iterator I = capture_begin(),
- E = capture_end(); I != E; ++I) {
+ for (const_capture_iterator I = capture_begin(),
+ E = capture_end(); I != E; ++I) {
if (I->capturesThis())
continue;
captures.end(), capturesCXXThis);
}
-void ASTDeclReader::VisitCapturedDecl(CapturedDecl *) {
- llvm_unreachable("not implemented yet");
+void ASTDeclReader::VisitCapturedDecl(CapturedDecl *CD) {
+ VisitDecl(CD);
+ // Body is set by VisitCapturedStmt.
+ for (unsigned i = 0; i < CD->NumParams; ++i)
+ CD->setParam(i, ReadDeclAs<ImplicitParamDecl>(Record, Idx));
}
void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
D = MSPropertyDecl::CreateDeserialized(Context, ID);
break;
case DECL_CAPTURED:
- llvm_unreachable("not implemented yet");
+ D = CapturedDecl::CreateDeserialized(Context, ID, Record[Idx++]);
break;
case DECL_CXX_BASE_SPECIFIERS:
Error("attempt to read a C++ base-specifier record as a declaration");
}
void ASTStmtReader::VisitCapturedStmt(CapturedStmt *S) {
- llvm_unreachable("not implemented yet");
+ VisitStmt(S);
+ S->TheCapturedDecl = ReadDeclAs<CapturedDecl>(Record, Idx);
+ S->TheRecordDecl = ReadDeclAs<RecordDecl>(Record, Idx);
+
+ // Capture inits
+ for (CapturedStmt::capture_init_iterator I = S->capture_init_begin(),
+ E = S->capture_init_end();
+ I != E; ++I)
+ *I = Reader.ReadSubExpr();
+
+ // Body
+ S->setCapturedStmt(Reader.ReadSubStmt());
+ S->TheCapturedDecl->setBody(S->getCapturedStmt());
+
+ // Captures
+ for (CapturedStmt::capture_iterator I = S->capture_begin(),
+ E = S->capture_end();
+ I != E; ++I) {
+ I->VarAndKind.setPointer(ReadDeclAs<VarDecl>(Record, Idx));
+ I->VarAndKind
+ .setInt(static_cast<CapturedStmt::VariableCaptureKind>(Record[Idx++]));
+ I->Loc = ReadSourceLocation(Record, Idx);
+ }
}
void ASTStmtReader::VisitExpr(Expr *E) {
break;
case STMT_CAPTURED:
- llvm_unreachable("not implemented yet");
+ S = CapturedStmt::CreateDeserialized(Context,
+ Record[ASTStmtReader::NumExprFields]);
break;
case EXPR_PREDEFINED:
Code = serialization::DECL_BLOCK;
}
-void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *) {
- llvm_unreachable("not implemented yet");
+void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
+ Record.push_back(CD->getNumParams());
+ VisitDecl(CD);
+ // Body is stored by VisitCapturedStmt.
+ for (unsigned i = 0; i < CD->getNumParams(); ++i)
+ Writer.AddDeclRef(CD->getParam(i), Record);
+ Code = serialization::DECL_CAPTURED;
}
void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) {
VisitStmt(S);
- Code = serialization::STMT_CAPTURED;
+ // NumCaptures
+ Record.push_back(std::distance(S->capture_begin(), S->capture_end()));
+
+ Writer.AddDeclRef(S->getCapturedDecl(), Record);
+ Writer.AddDeclRef(S->getCapturedRecordDecl(), Record);
+
+ // Capture inits
+ for (CapturedStmt::capture_init_iterator I = S->capture_init_begin(),
+ E = S->capture_init_end();
+ I != E; ++I)
+ Writer.AddStmt(*I);
- llvm_unreachable("not implemented yet");
+ // Body
+ Writer.AddStmt(S->getCapturedStmt());
+
+ // Captures
+ for (CapturedStmt::capture_iterator I = S->capture_begin(),
+ E = S->capture_end();
+ I != E; ++I) {
+ if (I->capturesThis())
+ Writer.AddDeclRef(0, Record);
+ else
+ Writer.AddDeclRef(I->getCapturedVar(), Record);
+ Record.push_back(I->getCaptureKind());
+ Writer.AddSourceLocation(I->getLocation(), Record);
+ }
+
+ Code = serialization::STMT_CAPTURED;
}
void ASTStmtWriter::VisitExpr(Expr *E) {
--- /dev/null
+// RUN: %clang_cc1 -x c++-header -emit-pch %s -o %t
+// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+#ifndef HEADER_INCLUDED
+#define HEADER_INCLUDED
+
+static inline void foo(int &x, int y) {
+ // Capturing x and y
+ #pragma clang __debug captured
+ {
+ x += y;
+ }
+}
+
+struct C {
+ int val;
+
+ explicit C(int v) : val(v) { }
+
+ void bar(int &x) {
+ // Capturing x and this
+ #pragma clang __debug captured
+ {
+ x += val;
+ }
+ }
+};
+
+#else
+
+void test_foo(int &x) {
+ foo(x, 10);
+}
+
+void test_bar(int &x) {
+ C Obj(10);
+ Obj.bar(x);
+}
+
+#endif