From e68c2cb502718aa1f11addde1e609e7a5052fa0e Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 18 Oct 2012 21:18:25 +0000 Subject: [PATCH] Move information about the "original file" from the ASTReader into the module files. llvm-svn: 166228 --- clang/include/clang/Serialization/ASTReader.h | 19 ++++---------- clang/include/clang/Serialization/Module.h | 17 ++++++++++++ clang/lib/Serialization/ASTReader.cpp | 38 +++++++++++++++------------ 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index 48b97c1..0306187 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -645,18 +645,6 @@ private: SmallVector ImportedModules; //@} - /// \brief The original file name that was used to build the primary AST file, - /// which may have been modified for relocatable-pch support. - std::string OriginalFileName; - - /// \brief The actual original file name that was used to build the primary - /// AST file. - std::string ActualOriginalFileName; - - /// \brief The file ID for the original file that was used to build the - /// primary AST file. - FileID OriginalFileID; - /// \brief The directory that the PCH was originally created in. Used to /// allow resolving headers even after headers+PCH was moved to a new path. std::string OriginalDir; @@ -1106,8 +1094,11 @@ public: /// \brief Retrieve the preprocessor. Preprocessor &getPreprocessor() const { return PP; } - /// \brief Retrieve the name of the original source file name - const std::string &getOriginalSourceFile() { return OriginalFileName; } + /// \brief Retrieve the name of the original source file name for the primary + /// module file. + const std::string &getOriginalSourceFile() { + return ModuleMgr.getPrimaryModule().OriginalSourceFileName; + } /// \brief Retrieve the name of the original source file name directly from /// the AST file, without actually loading the AST file. diff --git a/clang/include/clang/Serialization/Module.h b/clang/include/clang/Serialization/Module.h index ecf0ae1..a4c156e 100644 --- a/clang/include/clang/Serialization/Module.h +++ b/clang/include/clang/Serialization/Module.h @@ -75,6 +75,23 @@ public: /// \brief The file name of the module file. std::string FileName; + /// \brief The original source file name that was used to build the + /// primary AST file, which may have been modified for + /// relocatable-pch support. + std::string OriginalSourceFileName; + + /// \brief The actual original source file name that was used to + /// build this AST file. + std::string ActualOriginalSourceFileName; + + /// \brief The file ID for the original source file that was used to + /// build this AST file. + FileID OriginalSourceFileID; + + /// \brief The directory that the PCH was originally created in. Used to + /// allow resolving headers even after headers+PCH was moved to a new path. + std::string OriginalDir; + /// \brief The file entry for the module file. const FileEntry *File; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 489e0a6..deb5ade 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -819,11 +819,14 @@ void ASTReader::Error(unsigned DiagID, /// \brief Tell the AST listener about the predefines buffers in the chain. bool ASTReader::CheckPredefinesBuffers() { - if (Listener) + if (Listener) { + // We only care about the primary module. + ModuleFile &M = ModuleMgr.getPrimaryModule(); return Listener->ReadPredefinesBuffer(PCHPredefinesBuffers, - ActualOriginalFileName, + M.ActualOriginalSourceFileName, SuggestedPredefines, FileMgr); + } return false; } @@ -1833,7 +1836,7 @@ ASTReader::ASTReadResult ASTReader::ReadControlBlock(ModuleFile &F, } case LANGUAGE_OPTIONS: - if (&F == *ModuleMgr.begin() && + if (Listener && &F == *ModuleMgr.begin() && ParseLanguageOptions(F, Record) && !DisableValidation) return IgnorePCH; break; @@ -1854,7 +1857,7 @@ ASTReader::ASTReadResult ASTReader::ReadControlBlock(ModuleFile &F, TargetOpts.Features.push_back(ReadString(Record, Idx)); } - if (Listener->ReadTargetOptions(F, TargetOpts)) + if (Listener->ReadTargetOptions(F, TargetOpts) && !DisableValidation) return IgnorePCH; } break; @@ -1863,11 +1866,10 @@ ASTReader::ASTReadResult ASTReader::ReadControlBlock(ModuleFile &F, case ORIGINAL_FILE: // Only record from the primary AST file. if (&F == *ModuleMgr.begin()) { - OriginalFileID = FileID::get(Record[0]); - - ActualOriginalFileName.assign(BlobStart, BlobLen); - OriginalFileName = ActualOriginalFileName; - MaybeAddSystemRootToFilename(OriginalFileName); + F.OriginalSourceFileID = FileID::get(Record[0]); + F.ActualOriginalSourceFileName.assign(BlobStart, BlobLen); + F.OriginalSourceFileName = F.ActualOriginalSourceFileName; + MaybeAddSystemRootToFilename(F.OriginalSourceFileName); } break; @@ -2980,17 +2982,19 @@ ASTReader::ASTReadResult ASTReader::ReadAST(const std::string &FileName, if (DeserializationListener) DeserializationListener->ReaderInitialized(this); - if (!OriginalFileID.isInvalid()) { - OriginalFileID = FileID::get(ModuleMgr.getPrimaryModule().SLocEntryBaseID - + OriginalFileID.getOpaqueValue() - 1); + ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule(); + if (!PrimaryModule.OriginalSourceFileID.isInvalid()) { + PrimaryModule.OriginalSourceFileID + = FileID::get(PrimaryModule.SLocEntryBaseID + + PrimaryModule.OriginalSourceFileID.getOpaqueValue() - 1); - // If this AST file is a precompiled preamble, then set the preamble file ID - // of the source manager to the file source file from which the preamble was - // built. + // If this AST file is a precompiled preamble, then set the + // preamble file ID of the source manager to the file source file + // from which the preamble was built. if (Type == MK_Preamble) { - SourceMgr.setPreambleFileID(OriginalFileID); + SourceMgr.setPreambleFileID(PrimaryModule.OriginalSourceFileID); } else if (Type == MK_MainFile) { - SourceMgr.setMainFileID(OriginalFileID); + SourceMgr.setMainFileID(PrimaryModule.OriginalSourceFileID); } } -- 2.7.4