Fixed canonical path function.
authorJohn Thompson <John.Thompson.JTSoftware@gmail.com>
Thu, 26 Feb 2015 19:31:10 +0000 (19:31 +0000)
committerJohn Thompson <John.Thompson.JTSoftware@gmail.com>
Thu, 26 Feb 2015 19:31:10 +0000 (19:31 +0000)
llvm-svn: 230665

clang-tools-extra/modularize/ModularizeUtilities.cpp
clang-tools-extra/modularize/PreprocessorTracker.cpp

index 6038800..50dd8b1 100644 (file)
@@ -341,13 +341,31 @@ bool ModularizeUtilities::collectUmbrellaHeaders(StringRef UmbrellaDirName,
   }
   return true;
 }
+\r
+std::string normalize(StringRef Path) {\r
+  SmallString<128> Buffer;\r
+  llvm::sys::path::const_iterator B = llvm::sys::path::begin(Path),\r
+    E = llvm::sys::path::end(Path);\r
+  while (B != E) {\r
+    if (B->compare(".") == 0) {\r
+    }\r
+    else if (B->compare("..") == 0)\r
+      llvm::sys::path::remove_filename(Buffer);\r
+    else\r
+      llvm::sys::path::append(Buffer, *B);\r
+    ++B;\r
+  }\r
+  if (Path.endswith("/") || Path.endswith("\\"))\r
+    Buffer.append(1, Path.back());\r
+  return Buffer.c_str();\r
+}\r
 
 // Convert header path to canonical form.
 // The canonical form is basically just use forward slashes, and remove "./".
 // \param FilePath The file path, relative to the module map directory.
 // \returns The file path in canonical form.
 std::string ModularizeUtilities::getCanonicalPath(StringRef FilePath) {
-  std::string Tmp(FilePath);
+  std::string Tmp(normalize(FilePath));
   std::replace(Tmp.begin(), Tmp.end(), '\\', '/');
   StringRef Tmp2(Tmp);
   if (Tmp2.startswith("./"))
index bda7669..0b76146 100644 (file)
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/Support/StringPool.h"
 #include "llvm/Support/raw_ostream.h"
+#include "ModularizeUtilities.h"
 
 namespace Modularize {
 
@@ -930,8 +931,8 @@ public:
     // and block statement.
     clang::FileID FileID = PP.getSourceManager().getFileID(BlockStartLoc);
     std::string SourcePath = getSourceLocationFile(PP, BlockStartLoc);
+    SourcePath = ModularizeUtilities::getCanonicalPath(SourcePath);
     HeaderHandle SourceHandle = findHeaderHandle(SourcePath);
-    // FIXME: Go back and fix getSourceLocation to use a canonical form.
     if (SourceHandle == -1)
       return true;
     int BlockStartLine, BlockStartColumn, BlockEndLine, BlockEndColumn;