diff options
-rw-r--r-- | clang/include/clang/Basic/VirtualFileSystem.h | 4 | ||||
-rw-r--r-- | clang/lib/Basic/VirtualFileSystem.cpp | 7 | ||||
-rw-r--r-- | clang/unittests/Basic/VirtualFileSystemTest.cpp | 58 |
3 files changed, 39 insertions, 30 deletions
diff --git a/clang/include/clang/Basic/VirtualFileSystem.h b/clang/include/clang/Basic/VirtualFileSystem.h index a5f7f302f93..b592024fa98 100644 --- a/clang/include/clang/Basic/VirtualFileSystem.h +++ b/clang/include/clang/Basic/VirtualFileSystem.h @@ -166,7 +166,9 @@ llvm::sys::fs::UniqueID getNextVirtualUniqueID(); /// /// 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 diff --git a/clang/lib/Basic/VirtualFileSystem.cpp b/clang/lib/Basic/VirtualFileSystem.cpp index a107db68e44..6aef524abae 100644 --- a/clang/lib/Basic/VirtualFileSystem.cpp +++ b/clang/lib/Basic/VirtualFileSystem.cpp @@ -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::DeleteContainerPointers(Roots); } 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(const Twine &Path, 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() { diff --git a/clang/unittests/Basic/VirtualFileSystemTest.cpp b/clang/unittests/Basic/VirtualFileSystemTest.cpp index 50d11019f30..1231c949885 100644 --- a/clang/unittests/Basic/VirtualFileSystemTest.cpp +++ b/clang/unittests/Basic/VirtualFileSystemTest.cpp @@ -218,28 +218,36 @@ TEST(VirtualFileSystemTest, MergedDirPermissions) { EXPECT_EQ(0200, Status->getPermissions()); } -static int NumDiagnostics = 0; -static void CountingDiagHandler(const SMDiagnostic &, void *) { - ++NumDiagnostics; -} +class VFSFromYAMLTest : public ::testing::Test { +public: + int NumDiagnostics; + void SetUp() { + NumDiagnostics = 0; + } -static IntrusiveRefCntPtr<vfs::FileSystem> -getFromYAMLRawString(StringRef Content, - IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS) { - MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(Content); - return getVFSFromYAML(Buffer, CountingDiagHandler, ExternalFS); -} + static void CountingDiagHandler(const SMDiagnostic &, void *Context) { + VFSFromYAMLTest *Test = static_cast<VFSFromYAMLTest *>(Context); + ++Test->NumDiagnostics; + } -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); -} + 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); + } + +}; -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, BasicVFSFromYAML) { 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, CaseInsensitive) { 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, CaseSensitive) { EXPECT_EQ(0, NumDiagnostics); } -TEST(VirtualFileSystemTest, IllegalVFSFile) { - NumDiagnostics = 0; +TEST_F(VFSFromYAMLTest, IllegalVFSFile) { IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); // invalid YAML at top-level |