]> granicus.if.org Git - clang/commitdiff
Added storage of the FileID of the the main source file of a translation unit
authorTed Kremenek <kremenek@apple.com>
Wed, 19 Dec 2007 22:29:55 +0000 (22:29 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 19 Dec 2007 22:29:55 +0000 (22:29 +0000)
in SourceManager.

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

Basic/SourceManager.cpp
Driver/clang.cpp
include/clang/Basic/SourceManager.h

index d7039b3651ca95e550e2d9a2abf9faf87d236177..fe213426b9be4e198dde834fd3a51f9095d9ad9e 100644 (file)
@@ -508,6 +508,7 @@ MacroIDInfo MacroIDInfo::ReadVal(llvm::Deserializer& D) {
 void SourceManager::Emit(llvm::Serializer& S) const {
   S.EnterBlock();
   S.EmitPtr(this);
+  S.EmitInt(MainFileID);
   
   // Emit: FileInfos.  Just emit the file name.
   S.EnterBlock();    
@@ -541,6 +542,9 @@ SourceManager::CreateAndRegister(llvm::Deserializer& D, FileManager& FMgr){
   SourceManager *M = new SourceManager();
   D.RegisterPtr(M);
   
+  // Read: the FileID of the main source file of the translation unit.
+  M->MainFileID = D.ReadInt();
+  
   std::vector<char> Buf;
     
   { // Read: FileInfos.
index 63f43497ceb5b4df777c370e9bf32eae9b60af4f..20900c2f6b928eed54117e3d3a82fe10bf15f132 100644 (file)
@@ -1175,7 +1175,10 @@ int main(int argc, char **argv) {
       std::vector<char> PredefineBuffer;
       unsigned MainFileID = InitializePreprocessor(PP, InFile, PredefineBuffer);
       
-      if (!MainFileID) continue;
+      if (!MainFileID)
+        continue;
+      
+      SourceMgr.setMainFileID(MainFileID);
 
       ProcessInputFile(PP, MainFileID, InFile, *DiagClient);
       
index 325f9ed106da092197759a283ff674f9e39ac992..311bea1d3ca8706faf37ac2c37243e56dcfd16ff 100644 (file)
@@ -220,8 +220,11 @@ class SourceManager {
   unsigned LastLineNoFilePos;
   unsigned LastLineNoResult;
   
+  /// MainFileID - The file ID for the main source file of the translation unit.
+  unsigned MainFileID;
+  
 public:
-  SourceManager() : LastLineNoFileIDQuery(~0U) {}
+  SourceManager() : LastLineNoFileIDQuery(~0U), MainFileID(0) {}
   ~SourceManager() {}
   
   void clearIDTables() {
@@ -231,6 +234,12 @@ public:
     LastLineNoContentCache = 0;
   }
   
+  /// getMainFileID - Returns the FileID of the main source file.
+  unsigned getMainFileID() const { return MainFileID; }
+  
+  /// setMainFileID - Set the FileID of the main source file.
+  void setMainFileID(unsigned ID) { MainFileID = ID; }
+  
   /// createFileID - Create a new FileID that represents the specified file
   /// being #included from the specified IncludePosition.  This returns 0 on
   /// error and translates NULL into standard input.