[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
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() {}
 
-StringRef InMemoryFileSystem::toString() const {
+std::string InMemoryFileSystem::toString() const {
   return Root->toString(/*Indent=*/0);
 }
 
@@ -496,17 +497,14 @@
   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 @@
   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)