r202072 - Pass through context for DiagHandler in VFS
Ben Langmuir
blangmuir at apple.com
Mon Feb 24 12:56:38 PST 2014
Author: benlangmuir
Date: Mon Feb 24 14:56:37 2014
New Revision: 202072
URL: http://llvm.org/viewvc/llvm-project?rev=202072&view=rev
Log:
Pass through context for DiagHandler in VFS
This allows the unit tests to not use global state when checking
diagnostics.
Modified:
cfe/trunk/include/clang/Basic/VirtualFileSystem.h
cfe/trunk/lib/Basic/VirtualFileSystem.cpp
cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp
Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=202072&r1=202071&r2=202072&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original)
+++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Mon Feb 24 14:56:37 2014
@@ -166,7 +166,9 @@ llvm::sys::fs::UniqueID getNextVirtualUn
///
/// Takes ownership of \p Buffer.
IntrusiveRefCntPtr<FileSystem>
-getVFSFromYAML(llvm::MemoryBuffer *Buffer, llvm::SourceMgr::DiagHandlerTy,
+getVFSFromYAML(llvm::MemoryBuffer *Buffer,
+ llvm::SourceMgr::DiagHandlerTy DiagHandler,
+ void *DiagContext = 0,
IntrusiveRefCntPtr<FileSystem> ExternalFS = getRealFileSystem());
} // end namespace vfs
Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=202072&r1=202071&r2=202072&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Mon Feb 24 14:56:37 2014
@@ -357,6 +357,7 @@ public:
/// Takes ownership of \p Buffer.
static VFSFromYAML *create(MemoryBuffer *Buffer,
SourceMgr::DiagHandlerTy DiagHandler,
+ void *DiagContext,
IntrusiveRefCntPtr<FileSystem> ExternalFS);
ErrorOr<Status> status(const Twine &Path) LLVM_OVERRIDE;
@@ -645,12 +646,13 @@ VFSFromYAML::~VFSFromYAML() { llvm::Dele
VFSFromYAML *VFSFromYAML::create(MemoryBuffer *Buffer,
SourceMgr::DiagHandlerTy DiagHandler,
+ void *DiagContext,
IntrusiveRefCntPtr<FileSystem> ExternalFS) {
SourceMgr SM;
yaml::Stream Stream(Buffer, SM);
- SM.setDiagHandler(DiagHandler);
+ SM.setDiagHandler(DiagHandler, DiagContext);
yaml::document_iterator DI = Stream.begin();
yaml::Node *Root = DI->getRoot();
if (DI == Stream.end() || !Root) {
@@ -753,8 +755,9 @@ error_code VFSFromYAML::openFileForRead(
IntrusiveRefCntPtr<FileSystem>
vfs::getVFSFromYAML(MemoryBuffer *Buffer, SourceMgr::DiagHandlerTy DiagHandler,
+ void *DiagContext,
IntrusiveRefCntPtr<FileSystem> ExternalFS) {
- return VFSFromYAML::create(Buffer, DiagHandler, ExternalFS);
+ return VFSFromYAML::create(Buffer, DiagHandler, DiagContext, ExternalFS);
}
UniqueID vfs::getNextVirtualUniqueID() {
Modified: cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp?rev=202072&r1=202071&r2=202072&view=diff
==============================================================================
--- cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp (original)
+++ cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Mon Feb 24 14:56:37 2014
@@ -218,28 +218,36 @@ TEST(VirtualFileSystemTest, MergedDirPer
EXPECT_EQ(0200, Status->getPermissions());
}
-static int NumDiagnostics = 0;
-static void CountingDiagHandler(const SMDiagnostic &, void *) {
- ++NumDiagnostics;
-}
-
-static IntrusiveRefCntPtr<vfs::FileSystem>
-getFromYAMLRawString(StringRef Content,
- IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS) {
- MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Content);
- return getVFSFromYAML(Buffer, CountingDiagHandler, ExternalFS);
-}
+class VFSFromYAMLTest : public ::testing::Test {
+public:
+ int NumDiagnostics;
+ void SetUp() {
+ NumDiagnostics = 0;
+ }
+
+ static void CountingDiagHandler(const SMDiagnostic &, void *Context) {
+ VFSFromYAMLTest *Test = static_cast<VFSFromYAMLTest *>(Context);
+ ++Test->NumDiagnostics;
+ }
+
+ IntrusiveRefCntPtr<vfs::FileSystem>
+ getFromYAMLRawString(StringRef Content,
+ IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS) {
+ MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Content);
+ return getVFSFromYAML(Buffer, CountingDiagHandler, this, ExternalFS);
+ }
+
+ IntrusiveRefCntPtr<vfs::FileSystem> getFromYAMLString(
+ StringRef Content,
+ IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS = new DummyFileSystem()) {
+ std::string VersionPlusContent("{\n 'version':0,\n");
+ VersionPlusContent += Content.slice(Content.find('{') + 1, StringRef::npos);
+ return getFromYAMLRawString(VersionPlusContent, ExternalFS);
+ }
-static IntrusiveRefCntPtr<vfs::FileSystem> getFromYAMLString(
- StringRef Content,
- IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS = new DummyFileSystem()) {
- std::string VersionPlusContent("{\n 'version':0,\n");
- VersionPlusContent += Content.slice(Content.find('{') + 1, StringRef::npos);
- return getFromYAMLRawString(VersionPlusContent, ExternalFS);
-}
+};
-TEST(VirtualFileSystemTest, BasicVFSFromYAML) {
- NumDiagnostics = 0;
+TEST_F(VFSFromYAMLTest, BasicVFSFromYAML) {
IntrusiveRefCntPtr<vfs::FileSystem> FS;
FS = getFromYAMLString("");
EXPECT_EQ(NULL, FS.getPtr());
@@ -250,8 +258,7 @@ TEST(VirtualFileSystemTest, BasicVFSFrom
EXPECT_EQ(3, NumDiagnostics);
}
-TEST(VirtualFileSystemTest, MappedFiles) {
- NumDiagnostics = 0;
+TEST_F(VFSFromYAMLTest, MappedFiles) {
IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
Lower->addRegularFile("/foo/bar/a");
IntrusiveRefCntPtr<vfs::FileSystem> FS =
@@ -301,8 +308,7 @@ TEST(VirtualFileSystemTest, MappedFiles)
EXPECT_EQ(0, NumDiagnostics);
}
-TEST(VirtualFileSystemTest, CaseInsensitive) {
- NumDiagnostics = 0;
+TEST_F(VFSFromYAMLTest, CaseInsensitive) {
IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
Lower->addRegularFile("/foo/bar/a");
IntrusiveRefCntPtr<vfs::FileSystem> FS =
@@ -338,8 +344,7 @@ TEST(VirtualFileSystemTest, CaseInsensit
EXPECT_EQ(0, NumDiagnostics);
}
-TEST(VirtualFileSystemTest, CaseSensitive) {
- NumDiagnostics = 0;
+TEST_F(VFSFromYAMLTest, CaseSensitive) {
IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
Lower->addRegularFile("/foo/bar/a");
IntrusiveRefCntPtr<vfs::FileSystem> FS =
@@ -371,8 +376,7 @@ TEST(VirtualFileSystemTest, CaseSensitiv
EXPECT_EQ(0, NumDiagnostics);
}
-TEST(VirtualFileSystemTest, IllegalVFSFile) {
- NumDiagnostics = 0;
+TEST_F(VFSFromYAMLTest, IllegalVFSFile) {
IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
// invalid YAML at top-level
More information about the cfe-commits
mailing list