r252501 - Moving FileManager::removeDotPaths to llvm::sys::path::remove_dots

Mike Aizatsky via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 9 11:12:19 PST 2015


Author: aizatsky
Date: Mon Nov  9 13:12:18 2015
New Revision: 252501

URL: http://llvm.org/viewvc/llvm-project?rev=252501&view=rev
Log:
Moving FileManager::removeDotPaths to llvm::sys::path::remove_dots

Differential Revision: http://reviews.llvm.org/D14394

Modified:
    cfe/trunk/include/clang/Basic/FileManager.h
    cfe/trunk/lib/Basic/FileManager.cpp
    cfe/trunk/lib/Basic/VirtualFileSystem.cpp
    cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=252501&r1=252500&r2=252501&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Mon Nov  9 13:12:18 2015
@@ -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,

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=252501&r1=252500&r2=252501&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Mon Nov  9 13:12:18 2015
@@ -526,39 +526,6 @@ void FileManager::modifyFileEntry(FileEn
   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(
   // '..' 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
 

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=252501&r1=252500&r2=252501&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Mon Nov  9 13:12:18 2015
@@ -499,7 +499,7 @@ bool InMemoryFileSystem::addFile(const T
   (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 InMemoryFileSys
   (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;

Modified: cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp?rev=252501&r1=252500&r2=252501&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp (original)
+++ cfe/trunk/lib/Frontend/ModuleDependencyCollector.cpp Mon Nov  9 13:12:18 2015
@@ -67,7 +67,7 @@ std::error_code ModuleDependencyListener
   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();

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=252501&r1=252500&r2=252501&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Mon Nov  9 13:12:18 2015
@@ -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




More information about the cfe-commits mailing list