summaryrefslogtreecommitdiffstats
path: root/clang/lib/Tooling/Refactoring.cpp
diff options
context:
space:
mode:
authorAriel J. Bernal <ariel.j.bernal@intel.com>2013-10-01 14:59:00 +0000
committerAriel J. Bernal <ariel.j.bernal@intel.com>2013-10-01 14:59:00 +0000
commit31c181b06172be253f3411be8c9cb048dfc71d36 (patch)
treef6f2ab5dfe3b90bc2b2def20ed68e3d0adfcbd57 /clang/lib/Tooling/Refactoring.cpp
parenta9ac0e0f75e7269b61e77f1fd333b5fc8a3a4f70 (diff)
downloadbcm5719-llvm-31c181b06172be253f3411be8c9cb048dfc71d36.tar.gz
bcm5719-llvm-31c181b06172be253f3411be8c9cb048dfc71d36.zip
Fixed replacements for files with relative paths are not applied.
Replacements were no applied when using a compilation database with paths in the compilation command relative to the compile directory. This patch makes those paths abosulte. llvm-svn: 191776
Diffstat (limited to 'clang/lib/Tooling/Refactoring.cpp')
-rw-r--r--clang/lib/Tooling/Refactoring.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/Tooling/Refactoring.cpp b/clang/lib/Tooling/Refactoring.cpp
index b03fb50b383..13811648eef 100644
--- a/clang/lib/Tooling/Refactoring.cpp
+++ b/clang/lib/Tooling/Refactoring.cpp
@@ -19,6 +19,8 @@
#include "clang/Rewrite/Core/Rewriter.h"
#include "clang/Tooling/Refactoring.h"
#include "llvm/Support/raw_os_ostream.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
namespace clang {
namespace tooling {
@@ -103,7 +105,16 @@ void Replacement::setFromSourceLocation(SourceManager &Sources,
const std::pair<FileID, unsigned> DecomposedLocation =
Sources.getDecomposedLoc(Start);
const FileEntry *Entry = Sources.getFileEntryForID(DecomposedLocation.first);
- this->FilePath = Entry != NULL ? Entry->getName() : InvalidLocation;
+
+ if (Entry != NULL) {
+ // Make FilePath absolute so replacements can be applied correctly when
+ // relative paths for files are used.
+ llvm::SmallString<256> FilePath(Entry->getName());
+ llvm::error_code EC = llvm::sys::fs::make_absolute(FilePath);
+ // Don't change the FilePath if the file is a virtual file.
+ this->FilePath = EC ? FilePath.c_str() : Entry->getName();
+ } else
+ this->FilePath = InvalidLocation;
this->ReplacementRange = Range(DecomposedLocation.second, Length);
this->ReplacementText = ReplacementText;
}
OpenPOWER on IntegriCloud