From 76edd0e4ae0592a7225d50d0bad6732ac64dca2a Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 19 Dec 2007 22:29:55 +0000 Subject: [PATCH] Added storage of the FileID of the the main source file of a translation unit in SourceManager. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45225 91177308-0d34-0410-b5e6-96231b3b80d8 --- Basic/SourceManager.cpp | 4 ++++ Driver/clang.cpp | 5 ++++- include/clang/Basic/SourceManager.h | 11 ++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Basic/SourceManager.cpp b/Basic/SourceManager.cpp index d7039b3651..fe213426b9 100644 --- a/Basic/SourceManager.cpp +++ b/Basic/SourceManager.cpp @@ -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 Buf; { // Read: FileInfos. diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 63f43497ce..20900c2f6b 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -1175,7 +1175,10 @@ int main(int argc, char **argv) { std::vector PredefineBuffer; unsigned MainFileID = InitializePreprocessor(PP, InFile, PredefineBuffer); - if (!MainFileID) continue; + if (!MainFileID) + continue; + + SourceMgr.setMainFileID(MainFileID); ProcessInputFile(PP, MainFileID, InFile, *DiagClient); diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 325f9ed106..311bea1d3c 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -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. -- 2.50.1