]> granicus.if.org Git - clang/commitdiff
Add PTHManager::getOriginalSourceFile(), a method that returns the name of the
authorTed Kremenek <kremenek@apple.com>
Thu, 19 Mar 2009 22:19:30 +0000 (22:19 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 19 Mar 2009 22:19:30 +0000 (22:19 +0000)
original source file (if any) that was used to generate the PTH cache.

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

include/clang/Lex/PTHManager.h
lib/Lex/PTHLexer.cpp

index b937556e43a015e536ba299201c2c6dda0e9bdd2..6c3cabb1641598461eb40c3515e4f276bb2fae09 100644 (file)
@@ -69,12 +69,16 @@ class PTHManager : public IdentifierInfoLookup {
   ///  contains the cached spellings for literals.
   const unsigned char* const SpellingBase;
   
+  /// OriginalSourceFile - A null-terminated C-string that specifies the name
+  ///  if the file (if any) that was to used to generate the PTH cache.
+  const char* OriginalSourceFile;
+  
   /// This constructor is intended to only be called by the static 'Create'
   /// method.
   PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup,
              const unsigned char* idDataTable, IdentifierInfo** perIDCache,
              void* stringIdLookup, unsigned numIds,
-             const unsigned char* spellingBase);
+             const unsigned char* spellingBase, const char *originalSourceFile);
 
   // Do not implement.
   PTHManager();
@@ -96,10 +100,16 @@ class PTHManager : public IdentifierInfoLookup {
   
 public:
   // The current PTH version.
-  enum { Version = 8 };
+  enum { Version = 9 };
 
   ~PTHManager();
   
+  /// getOriginalSourceFile - Return the full path to the original header
+  ///  file name that was used to generate the PTH cache.
+  const char* getOriginalSourceFile() const {
+    return OriginalSourceFile;
+  }
+  
   /// get - Return the identifier token info for the specified named identifier.
   ///  Unlike the version in IdentifierTable, this returns a pointer instead
   ///  of a reference.  If the pointer is NULL then the IdentifierInfo cannot
index a5423d08f859121ce86b26e81d46496739487b3d..0a810ceaa6b798b51303e532fa21f21cc7b65f4c 100644 (file)
@@ -569,10 +569,12 @@ PTHManager::PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup,
                        const unsigned char* idDataTable,
                        IdentifierInfo** perIDCache, 
                        void* stringIdLookup, unsigned numIds,
-                       const unsigned char* spellingBase)
+                       const unsigned char* spellingBase,
+                       const char* originalSourceFile)
 : Buf(buf), PerIDCache(perIDCache), FileLookup(fileLookup),
   IdDataTable(idDataTable), StringIdLookup(stringIdLookup),
-  NumIds(numIds), PP(0), SpellingBase(spellingBase) {}
+  NumIds(numIds), PP(0), SpellingBase(spellingBase),
+  OriginalSourceFile(originalSourceFile) {}
 
 PTHManager::~PTHManager() {
   delete Buf;
@@ -701,10 +703,17 @@ PTHManager* PTHManager::Create(const std::string& file, Diagnostic* Diags) {
     }
   }
 
+  // Compute the address of the original source file.
+  const unsigned char* originalSourceBase = PrologueOffset + sizeof(uint32_t)*4;
+  unsigned len = ReadUnalignedLE16(originalSourceBase);
+  if (!len) originalSourceBase = 0;  
+  
   // Create the new PTHManager.
   return new PTHManager(File.take(), FL.take(), IData, PerIDCache,
-                        SL.take(), NumIds, spellingBase);
+                        SL.take(), NumIds, spellingBase,
+                        (const char*) originalSourceBase);
 }
+
 IdentifierInfo* PTHManager::LazilyCreateIdentifierInfo(unsigned PersistentID) {
   // Look in the PTH file for the string data for the IdentifierInfo object.
   const unsigned char* TableEntry = IdDataTable + sizeof(uint32_t)*PersistentID;