diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2015-10-09 13:03:22 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2015-10-09 13:03:22 +0000 |
commit | decb2aeab3445a377f19c09116112e097d1b91c0 (patch) | |
tree | 7b9d10c65b237d7cede0eed983f0bd16dc255fc1 /clang/lib/Basic/VirtualFileSystem.cpp | |
parent | c5862f08de48298ca5883c806806331df22fe34a (diff) | |
download | llvm-decb2aeab3445a377f19c09116112e097d1b91c0.zip llvm-decb2aeab3445a377f19c09116112e097d1b91c0.tar.gz llvm-decb2aeab3445a377f19c09116112e097d1b91c0.tar.bz2 |
[VFS] Just normalize away .. and . in paths for in-memory file systems.
This simplifies the code and gets us support for .. for free.
llvm-svn: 249830
Diffstat (limited to 'clang/lib/Basic/VirtualFileSystem.cpp')
-rw-r--r-- | clang/lib/Basic/VirtualFileSystem.cpp | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/clang/lib/Basic/VirtualFileSystem.cpp b/clang/lib/Basic/VirtualFileSystem.cpp index 04383db..6e55d2e 100644 --- a/clang/lib/Basic/VirtualFileSystem.cpp +++ b/clang/lib/Basic/VirtualFileSystem.cpp @@ -10,6 +10,7 @@ //===----------------------------------------------------------------------===// #include "clang/Basic/VirtualFileSystem.h" +#include "clang/Basic/FileManager.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" @@ -482,7 +483,7 @@ InMemoryFileSystem::InMemoryFileSystem() InMemoryFileSystem::~InMemoryFileSystem() {} -StringRef InMemoryFileSystem::toString() const { +std::string InMemoryFileSystem::toString() const { return Root->toString(/*Indent=*/0); } @@ -496,17 +497,14 @@ void InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime, assert(!EC); (void)EC; + FileManager::removeDotPaths(Path, /*RemoveDotDot=*/true); + if (Path.empty()) + return; + detail::InMemoryDirectory *Dir = Root.get(); auto I = llvm::sys::path::begin(Path), E = llvm::sys::path::end(Path); while (true) { StringRef Name = *I; - // Skip over ".". - // FIXME: Also handle "..". - if (Name == ".") { - ++I; - continue; - } - detail::InMemoryNode *Node = Dir->getChild(Name); ++I; if (!Node) { @@ -558,17 +556,12 @@ lookupInMemoryNode(const InMemoryFileSystem &FS, detail::InMemoryDirectory *Dir, assert(!EC); (void)EC; + FileManager::removeDotPaths(Path, /*RemoveDotDot=*/true); + if (Path.empty()) + return Dir; + auto I = llvm::sys::path::begin(Path), E = llvm::sys::path::end(Path); while (true) { - // Skip over ".". - // FIXME: Also handle "..". - if (*I == ".") { - ++I; - if (I == E) - return Dir; - continue; - } - detail::InMemoryNode *Node = Dir->getChild(*I); ++I; if (!Node) |