]> granicus.if.org Git - clang/commitdiff
Moving FileManager::removeDotPaths to llvm::sys::path::remove_dots
authorMike Aizatsky <aizatsky@chromium.org>
Mon, 9 Nov 2015 19:12:18 +0000 (19:12 +0000)
committerMike Aizatsky <aizatsky@chromium.org>
Mon, 9 Nov 2015 19:12:18 +0000 (19:12 +0000)
Differential Revision: http://reviews.llvm.org/D14394

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252501 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/FileManager.h
lib/Basic/FileManager.cpp
lib/Basic/VirtualFileSystem.cpp
lib/Frontend/ModuleDependencyCollector.cpp
lib/Serialization/ASTWriter.cpp

index c76da25dd54780e16c9223a7f11b47625104cf70..cf74d4951d8cd93143e81de1c1ae908ce32829b0 100644 (file)
@@ -273,9 +273,6 @@ public:
   static void modifyFileEntry(FileEntry *File, off_t Size,
                               time_t ModificationTime);
 
-  /// \brief Remove any './' components from a path.
-  static bool removeDotPaths(SmallVectorImpl<char> &Path, bool RemoveDotDot = false);
-
   /// \brief Retrieve the canonical name for a given directory.
   ///
   /// This is a very expensive operation, despite its results being cached,
index 21e6ea3ab4bbb298535ef0fb2dcf402d54fc45b1..8a523d26dec13718a28a8af886a0a953e2024417 100644 (file)
@@ -526,39 +526,6 @@ void FileManager::modifyFileEntry(FileEntry *File,
   File->ModTime = ModificationTime;
 }
 
-/// Remove '.' and '..' path components from the given absolute path.
-/// \return \c true if any changes were made.
-// FIXME: Move this to llvm::sys::path.
-bool FileManager::removeDotPaths(SmallVectorImpl<char> &Path, bool RemoveDotDot) {
-  using namespace llvm::sys;
-
-  SmallVector<StringRef, 16> ComponentStack;
-  StringRef P(Path.data(), Path.size());
-
-  // Skip the root path, then look for traversal in the components.
-  StringRef Rel = path::relative_path(P);
-  for (StringRef C : llvm::make_range(path::begin(Rel), path::end(Rel))) {
-    if (C == ".")
-      continue;
-    if (RemoveDotDot) {
-      if (C == "..") {
-        if (!ComponentStack.empty())
-          ComponentStack.pop_back();
-        continue;
-      }
-    }
-    ComponentStack.push_back(C);
-  }
-
-  SmallString<256> Buffer = path::root_path(P);
-  for (StringRef C : ComponentStack)
-    path::append(Buffer, C);
-
-  bool Changed = (Path != Buffer);
-  Path.swap(Buffer);
-  return Changed;
-}
-
 StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
   // FIXME: use llvm::sys::fs::canonical() when it gets implemented
   llvm::DenseMap<const DirectoryEntry *, llvm::StringRef>::iterator Known
@@ -582,7 +549,7 @@ StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
   // '..' is pretty safe.
   // Ideally we'd have an equivalent of `realpath` and could implement
   // sys::fs::canonical across all the platforms.
-  removeDotPaths(CanonicalNameBuf, /*RemoveDotDot*/true);
+  llvm::sys::path::remove_dots(CanonicalNameBuf, /* remove_dot_dot */ true);
   CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
 #endif
 
index a20132b3de892cd4fa43acf4c136948e30774f0a..8acf0a997d5492aefd522633f45a4e6cbe1bf615 100644 (file)
@@ -499,7 +499,7 @@ bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime,
   (void)EC;
 
   if (useNormalizedPaths())
-    FileManager::removeDotPaths(Path, /*RemoveDotDot=*/true);
+    llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
 
   if (Path.empty())
     return false;
@@ -572,7 +572,7 @@ lookupInMemoryNode(const InMemoryFileSystem &FS, detail::InMemoryDirectory *Dir,
   (void)EC;
 
   if (FS.useNormalizedPaths())
-    FileManager::removeDotPaths(Path, /*RemoveDotDot=*/true);
+    llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
 
   if (Path.empty())
     return Dir;
index 78bb0279d90f4da95bf40b5b6bca436883a20e2a..9768a164acbc45abc5dbb93a17f343e4d4754088 100644 (file)
@@ -67,7 +67,7 @@ std::error_code ModuleDependencyListener::copyToRoot(StringRef Src) {
   path::native(AbsoluteSrc);
   // TODO: We probably need to handle .. as well as . in order to have valid
   // input to the YAMLVFSWriter.
-  FileManager::removeDotPaths(AbsoluteSrc);
+  path::remove_dots(AbsoluteSrc);
 
   // Build the destination path.
   SmallString<256> Dest = Collector.getDest();
index 8fc32eaaa93910b15da71b6233f5eab48ac8e335..5508b6eceac756eaebcbb947c5455a44bb433518 100644 (file)
@@ -1112,7 +1112,7 @@ void ASTWriter::WriteBlockInfoBlock() {
 static bool cleanPathForOutput(FileManager &FileMgr,
                                SmallVectorImpl<char> &Path) {
   bool Changed = FileMgr.makeAbsolutePath(Path);
-  return Changed | FileMgr.removeDotPaths(Path);
+  return Changed | llvm::sys::path::remove_dots(Path);
 }
 
 /// \brief Adjusts the given filename to only write out the portion of the