[PATCH] Fix replacements for files with relative paths are not applied.
Ariel Bernal
ariel.j.bernal at intel.com
Tue Oct 1 13:30:20 PDT 2013
Hi klimek, tareqsiraj,
D1771 was supposed to fix this but it didn't, make_absolute can't be use to check if a file is virtual. I didn't break anything either.
This patch exposes virtual entries in the FileManager to check if a filepath is a virtual file that has already been allocated.
http://llvm-reviews.chandlerc.com/D1800
Files:
include/clang/Basic/FileManager.h
lib/Basic/FileManager.cpp
lib/Tooling/Refactoring.cpp
Index: include/clang/Basic/FileManager.h
===================================================================
--- include/clang/Basic/FileManager.h
+++ include/clang/Basic/FileManager.h
@@ -273,6 +273,10 @@
/// required, which is (almost) never.
StringRef getCanonicalName(const DirectoryEntry *Dir);
+
+ /// \brief Check if a FilePath is a virtual file that we have allocated.
+ bool isFileVirtual(StringRef FilePath);
+
void PrintStats() const;
};
Index: lib/Basic/FileManager.cpp
===================================================================
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -580,6 +580,16 @@
#endif
}
+bool FileManager::isFileVirtual(StringRef FilePath) {
+ for (SmallVectorImpl<FileEntry *>::const_iterator
+ I = VirtualFileEntries.begin(),
+ E = VirtualFileEntries.end();
+ I != E; ++I)
+ if ((*I)->getName() == FilePath)
+ return true;
+ return false;
+}
+
void FileManager::PrintStats() const {
llvm::errs() << "\n*** File Manager Stats:\n";
llvm::errs() << UniqueRealFiles.size() << " real files found, "
Index: lib/Tooling/Refactoring.cpp
===================================================================
--- lib/Tooling/Refactoring.cpp
+++ lib/Tooling/Refactoring.cpp
@@ -105,15 +105,18 @@
const std::pair<FileID, unsigned> DecomposedLocation =
Sources.getDecomposedLoc(Start);
const FileEntry *Entry = Sources.getFileEntryForID(DecomposedLocation.first);
-
- if (Entry != NULL) {
+ 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
+ // relative paths for file are used. But we don't want to change virtual
+ // files.
+ if (Sources.getFileManager().isFileVirtual(Entry->getName())) {
+ this->FilePath = Entry->getName();
+ } else {
+ llvm::SmallString<256> FilePath(Entry->getName());
+ llvm::sys::fs::make_absolute(FilePath);
+ this->FilePath = FilePath.c_str();
+ }
+ else
this->FilePath = InvalidLocation;
this->ReplacementRange = Range(DecomposedLocation.second, Length);
this->ReplacementText = ReplacementText;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1800.1.patch
Type: text/x-patch
Size: 2443 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131001/28455535/attachment.bin>
More information about the cfe-commits
mailing list