/// 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;
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.
//===--------------------------------------------------------------------===//
bool CaptureDiagnostics = false,
RemappedFile *RemappedFiles = 0,
unsigned NumRemappedFiles = 0,
+ bool RemappedFilesKeepOriginalName = true,
bool PrecompilePreamble = false,
bool CompleteTranslationUnit = true,
bool CacheCodeCompletionResults = false,
/// 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
DisablePCHValidation(false), DisableStatCache(false),
DumpDeserializedPCHDecls(false),
PrecompiledPreambleBytes(0, true),
+ RemappedFilesKeepOriginalName(true),
RetainRemappedFileBuffers(false) { }
void addMacroDef(llvm::StringRef Name) {
//===----------------------------------------------------------------------===//
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();
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;
}
bool CaptureDiagnostics,
RemappedFile *RemappedFiles,
unsigned NumRemappedFiles,
+ bool RemappedFilesKeepOriginalName,
bool PrecompilePreamble,
bool CompleteTranslationUnit,
bool CacheCodeCompletionResults,
CI->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, fname);
}
}
+ CI->getPreprocessorOpts().RemappedFilesKeepOriginalName =
+ RemappedFilesKeepOriginalName;
// Override the resources path.
CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath;
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
/*CaptureDiagnostics=*/true,
RemappedFiles.data(),
RemappedFiles.size(),
+ /*RemappedFilesKeepOriginalName=*/true,
PrecompilePreamble,
CompleteTranslationUnit,
CacheCodeCompetionResults,