summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Basic/SourceManager.h10
-rw-r--r--clang/include/clang/Frontend/ASTUnit.h1
-rw-r--r--clang/include/clang/Frontend/PreprocessorOptions.h5
-rw-r--r--clang/lib/Basic/SourceManager.cpp6
-rw-r--r--clang/lib/Frontend/ASTUnit.cpp3
-rw-r--r--clang/lib/Frontend/InitPreprocessor.cpp15
-rw-r--r--clang/tools/libclang/CIndex.cpp1
7 files changed, 28 insertions, 13 deletions
diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h
index dea08840423..799ee3438f2 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -392,6 +392,10 @@ class SourceManager {
/// non-null, FileEntry pointers.
llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*> FileInfos;
+ /// \brief True if the ContentCache for files that are overriden by other
+ /// files, should report the original file name. Defaults to true.
+ bool OverridenFilesKeepOriginalName;
+
/// \brief Files that have been overriden with the contents from another file.
llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles;
@@ -453,6 +457,12 @@ public:
FileManager &getFileManager() const { return FileMgr; }
+ /// \brief Set true if the SourceManager should report the original file name
+ /// for contents of files that were overriden by other files.Defaults to true.
+ void setOverridenFilesKeepOriginalName(bool value) {
+ OverridenFilesKeepOriginalName = value;
+ }
+
//===--------------------------------------------------------------------===//
// MainFileID creation and querying methods.
//===--------------------------------------------------------------------===//
diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h
index e73d7fb6872..3138d7db46e 100644
--- a/clang/include/clang/Frontend/ASTUnit.h
+++ b/clang/include/clang/Frontend/ASTUnit.h
@@ -611,6 +611,7 @@ public:
bool CaptureDiagnostics = false,
RemappedFile *RemappedFiles = 0,
unsigned NumRemappedFiles = 0,
+ bool RemappedFilesKeepOriginalName = true,
bool PrecompilePreamble = false,
bool CompleteTranslationUnit = true,
bool CacheCodeCompletionResults = false,
diff --git a/clang/include/clang/Frontend/PreprocessorOptions.h b/clang/include/clang/Frontend/PreprocessorOptions.h
index 0d52e53ea16..078b22e7192 100644
--- a/clang/include/clang/Frontend/PreprocessorOptions.h
+++ b/clang/include/clang/Frontend/PreprocessorOptions.h
@@ -73,6 +73,10 @@ public:
/// If given, a PTH cache file to use for speeding up header parsing.
std::string TokenCache;
+ /// \brief True if the SourceManager should report the original file name for
+ /// contents of files that were remapped to other files. Defaults to true.
+ bool RemappedFilesKeepOriginalName;
+
/// \brief The set of file remappings, which take existing files on
/// the system (the first part of each pair) and gives them the
/// contents of other files on the system (the second part of each
@@ -132,6 +136,7 @@ public:
DisablePCHValidation(false), DisableStatCache(false),
DumpDeserializedPCHDecls(false),
PrecompiledPreambleBytes(0, true),
+ RemappedFilesKeepOriginalName(true),
RetainRemappedFileBuffers(false) { }
void addMacroDef(llvm::StringRef Name) {
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index cffdb937bf0..b6939ec7d55 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -340,7 +340,7 @@ LineTableInfo &SourceManager::getLineTable() {
//===----------------------------------------------------------------------===//
SourceManager::SourceManager(Diagnostic &Diag, FileManager &FileMgr)
- : Diag(Diag), FileMgr(FileMgr),
+ : Diag(Diag), FileMgr(FileMgr), OverridenFilesKeepOriginalName(true),
ExternalSLocEntries(0), LineTable(0), NumLinearScans(0),
NumBinaryProbes(0) {
clearIDTables();
@@ -403,7 +403,9 @@ SourceManager::getOrCreateContentCache(const FileEntry *FileEnt) {
if (overI == OverriddenFiles.end())
new (Entry) ContentCache(FileEnt);
else
- new (Entry) ContentCache(FileEnt, overI->second);
+ new (Entry) ContentCache(OverridenFilesKeepOriginalName ? FileEnt
+ : overI->second,
+ overI->second);
return Entry;
}
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index 9252c6a7a0e..5e534b3d57b 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -1576,6 +1576,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
bool CaptureDiagnostics,
RemappedFile *RemappedFiles,
unsigned NumRemappedFiles,
+ bool RemappedFilesKeepOriginalName,
bool PrecompilePreamble,
bool CompleteTranslationUnit,
bool CacheCodeCompletionResults,
@@ -1658,6 +1659,8 @@ ASTUnit *ASTUnit::LoadFromCommandLine(const char **ArgBegin,
CI->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, fname);
}
}
+ CI->getPreprocessorOpts().RemappedFilesKeepOriginalName =
+ RemappedFilesKeepOriginalName;
// Override the resources path.
CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath;
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 91b5280a87e..d9a2ef66b96 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -531,20 +531,13 @@ static void InitializeFileRemapping(Diagnostic &Diags,
continue;
}
- // Load the contents of the file we're mapping to.
- std::string ErrorStr;
- const llvm::MemoryBuffer *Buffer
- = FileMgr.getBufferForFile(ToFile->getName(), &ErrorStr);
- if (!Buffer) {
- Diags.Report(diag::err_fe_error_opening)
- << Remap->second << ErrorStr;
- continue;
- }
-
// Override the contents of the "from" file with the contents of
// the "to" file.
- SourceMgr.overrideFileContents(FromFile, Buffer);
+ SourceMgr.overrideFileContents(FromFile, ToFile);
}
+
+ SourceMgr.setOverridenFilesKeepOriginalName(
+ InitOpts.RemappedFilesKeepOriginalName);
}
/// InitializePreprocessor - Initialize the preprocessor getting it and the
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index c7af7555d23..16672ca7040 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -2424,6 +2424,7 @@ static void clang_parseTranslationUnit_Impl(void *UserData) {
/*CaptureDiagnostics=*/true,
RemappedFiles.data(),
RemappedFiles.size(),
+ /*RemappedFilesKeepOriginalName=*/true,
PrecompilePreamble,
CompleteTranslationUnit,
CacheCodeCompetionResults,
OpenPOWER on IntegriCloud