hokein updated this revision to Diff 55398.
hokein added a comment.

Don't append absolute path to build directory.

We will get the absolute file paths in some cases, such as STL.


http://reviews.llvm.org/D19647

Files:
  include-fixer/find-all-symbols/FindAllSymbols.cpp

Index: include-fixer/find-all-symbols/FindAllSymbols.cpp
===================================================================
--- include-fixer/find-all-symbols/FindAllSymbols.cpp
+++ include-fixer/find-all-symbols/FindAllSymbols.cpp
@@ -16,6 +16,7 @@
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang::ast_matchers;
 
@@ -47,19 +48,37 @@
   SetContext(ND, Symbol);
 
   Symbol->Name = ND->getNameAsString();
-  SourceLocation Loc = 
Result.SourceManager->getExpansionLoc(ND->getLocation());
+
+  const SourceManager *SM = Result.SourceManager;
+  SourceLocation Loc = SM->getExpansionLoc(ND->getLocation());
   if (!Loc.isValid()) {
     llvm::errs() << "Declaration " << ND->getNameAsString() << "("
                  << ND->getDeclKindName()
                  << ") has invalid declaration location.";
     return false;
   }
-  std::string FilePath = Result.SourceManager->getFilename(Loc).str();
+
+  Symbol->LineNumber = SM->getExpansionLineNumber(Loc);
+
+  llvm::StringRef FilePath = SM->getFilename(Loc);
   if (FilePath.empty())
     return false;
 
-  Symbol->FilePath = FilePath;
-  Symbol->LineNumber = Result.SourceManager->getExpansionLineNumber(Loc);
+  llvm::SmallString<128> AbsolutePath;
+  if (llvm::sys::path::is_absolute(FilePath)) {
+    AbsolutePath = FilePath;
+  } else {
+    auto WorkingDir = SM->getFileManager()
+                          .getVirtualFileSystem()
+                          ->getCurrentWorkingDirectory();
+    if (!WorkingDir)
+      return false;
+    AbsolutePath = *WorkingDir;
+    llvm::sys::path::append(AbsolutePath, FilePath);
+  }
+
+  llvm::sys::path::remove_dots(AbsolutePath, true);
+  Symbol->FilePath = AbsolutePath.str();
   return true;
 }
 } // namespace


Index: include-fixer/find-all-symbols/FindAllSymbols.cpp
===================================================================
--- include-fixer/find-all-symbols/FindAllSymbols.cpp
+++ include-fixer/find-all-symbols/FindAllSymbols.cpp
@@ -16,6 +16,7 @@
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang::ast_matchers;
 
@@ -47,19 +48,37 @@
   SetContext(ND, Symbol);
 
   Symbol->Name = ND->getNameAsString();
-  SourceLocation Loc = Result.SourceManager->getExpansionLoc(ND->getLocation());
+
+  const SourceManager *SM = Result.SourceManager;
+  SourceLocation Loc = SM->getExpansionLoc(ND->getLocation());
   if (!Loc.isValid()) {
     llvm::errs() << "Declaration " << ND->getNameAsString() << "("
                  << ND->getDeclKindName()
                  << ") has invalid declaration location.";
     return false;
   }
-  std::string FilePath = Result.SourceManager->getFilename(Loc).str();
+
+  Symbol->LineNumber = SM->getExpansionLineNumber(Loc);
+
+  llvm::StringRef FilePath = SM->getFilename(Loc);
   if (FilePath.empty())
     return false;
 
-  Symbol->FilePath = FilePath;
-  Symbol->LineNumber = Result.SourceManager->getExpansionLineNumber(Loc);
+  llvm::SmallString<128> AbsolutePath;
+  if (llvm::sys::path::is_absolute(FilePath)) {
+    AbsolutePath = FilePath;
+  } else {
+    auto WorkingDir = SM->getFileManager()
+                          .getVirtualFileSystem()
+                          ->getCurrentWorkingDirectory();
+    if (!WorkingDir)
+      return false;
+    AbsolutePath = *WorkingDir;
+    llvm::sys::path::append(AbsolutePath, FilePath);
+  }
+
+  llvm::sys::path::remove_dots(AbsolutePath, true);
+  Symbol->FilePath = AbsolutePath.str();
   return true;
 }
 } // namespace
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to