]> granicus.if.org Git - clang/commitdiff
Add 'OverridenFilesKeepOriginalName' field in SourceManager which if true the SourceM...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 8 Mar 2011 23:35:24 +0000 (23:35 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 8 Mar 2011 23:35:24 +0000 (23:35 +0000)
should report the original file name for contents of files that were overriden by other files,
otherwise it should report the name of the new file. Default is true.

Also add similar field in PreprocessorOptions and pass similar parameter in ASTUnit::LoadFromCommandLine.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127289 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/SourceManager.h
include/clang/Frontend/ASTUnit.h
include/clang/Frontend/PreprocessorOptions.h
lib/Basic/SourceManager.cpp
lib/Frontend/ASTUnit.cpp
lib/Frontend/InitPreprocessor.cpp
tools/libclang/CIndex.cpp

index dea08840423cf6346b5f6223c18862ee0b3b564d..799ee3438f2335325b014dd3ef7c770a137b90e5 100644 (file)
@@ -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.
   //===--------------------------------------------------------------------===//
index e73d7fb687247a0be4fa8ab0071d8a699ae635f0..3138d7db46ef6919b5f7d3fe9dd02447b7eee7d5 100644 (file)
@@ -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,
index 0d52e53ea16a18844cdebcba8c1b2a727074c11c..078b22e7192f7e747ecae8db95e2f44041762f42 100644 (file)
@@ -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) {
index cffdb937bf09c5d63d39fbe737c0cabcdbe5bb7b..b6939ec7d55512cb320c1dfc1fb9d0b861bf0b58 100644 (file)
@@ -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;
 }
index 9252c6a7a0edada1bca08fa2068a991f591bb57c..5e534b3d57bb04e210b1e9eabe6fe9a073e22623 100644 (file)
@@ -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;
index 91b5280a87ef8ae7cf31d9ac840971b4003f2d49..d9a2ef66b96e4c4edc217d52d1318424f36190b2 100644 (file)
@@ -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
index c7af7555d2392a09d31d7962ddc6dbee31cae3c2..16672ca70401f8036d9a7c8478c863d5a2de1dde 100644 (file)
@@ -2424,6 +2424,7 @@ static void clang_parseTranslationUnit_Impl(void *UserData) {
                                  /*CaptureDiagnostics=*/true,
                                  RemappedFiles.data(),
                                  RemappedFiles.size(),
+                                 /*RemappedFilesKeepOriginalName=*/true,
                                  PrecompilePreamble,
                                  CompleteTranslationUnit,
                                  CacheCodeCompetionResults,