From: Douglas Gregor Date: Fri, 2 Sep 2011 00:26:20 +0000 (+0000) Subject: Always construct an ASTReader with a non-NULL ASTContext and X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f8a1e51c48761ee1d7803c3fa35ac94f42ebb55e;p=clang Always construct an ASTReader with a non-NULL ASTContext and Preprocessor, eliminating the constructor that was used by ASTUnit (which didn't provide an ASTContext or Prepreprocessor). Ensuring that both objects are non-NULL will simplify module loading (but none of that is done yet). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138986 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 71a597f9a5..e7019f311d 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -729,37 +729,9 @@ public: /// help when an AST file is being used in cases where the /// underlying files in the file system may have changed, but /// parsing should still continue. - ASTReader(Preprocessor &PP, ASTContext *Context, StringRef isysroot = "", + ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot = "", bool DisableValidation = false, bool DisableStatCache = false); - /// \brief Load the AST file without using any pre-initialized Preprocessor. - /// - /// The necessary information to initialize a Preprocessor later can be - /// obtained by setting a ASTReaderListener. - /// - /// \param SourceMgr the source manager into which the AST file will be loaded - /// - /// \param FileMgr the file manager into which the AST file will be loaded. - /// - /// \param Diags the diagnostics system to use for reporting errors and - /// warnings relevant to loading the AST file. - /// - /// \param isysroot If non-NULL, the system include path specified by the - /// user. This is only used with relocatable PCH files. If non-NULL, - /// a relocatable PCH file will use the default path "/". - /// - /// \param DisableValidation If true, the AST reader will suppress most - /// of its regular consistency checking, allowing the use of precompiled - /// headers that cannot be determined to be compatible. - /// - /// \param DisableStatCache If true, the AST reader will ignore the - /// stat cache in the AST files. This performance pessimization can - /// help when an AST file is being used in cases where the - /// underlying files in the file system may have changed, but - /// parsing should still continue. - ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, - Diagnostic &Diags, StringRef isysroot = "", - bool DisableValidation = false, bool DisableStatCache = false); ~ASTReader(); /// \brief Load the AST file designated by the given file name. diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index 34a6dabf64..b8551e9a42 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -624,8 +624,7 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename, /*DelayInitialization=*/true); ASTContext &Context = *AST->Ctx; - Reader.reset(new ASTReader(AST->getSourceManager(), AST->getFileManager(), - AST->getDiagnostics())); + Reader.reset(new ASTReader(PP, Context)); // Recover resources if we crash before exiting this method. llvm::CrashRecoveryContextCleanupRegistrar @@ -649,11 +648,7 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename, PP.setPredefines(Reader->getSuggestedPredefines()); PP.setCounterValue(Counter); - Reader->setPreprocessor(PP); - // Create and initialize the ASTContext. - Reader->InitializeContext(Context); - // Attach the AST reader to the AST context as an external AST // source, so that declarations will be deserialized from the // AST file as needed. diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index 2252cd6f95..bd019e0cf2 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -273,7 +273,7 @@ CompilerInstance::createPCHExternalASTSource(StringRef Path, void *DeserializationListener, bool Preamble) { llvm::OwningPtr Reader; - Reader.reset(new ASTReader(PP, &Context, + Reader.reset(new ASTReader(PP, Context, Sysroot.empty() ? "" : Sysroot.c_str(), DisablePCHValidation, DisableStatCache)); @@ -655,7 +655,7 @@ ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc, if (!ModuleManager) { std::string Sysroot = getHeaderSearchOpts().Sysroot; const PreprocessorOptions &PPOpts = getPreprocessorOpts(); - ModuleManager = new ASTReader(getPreprocessor(), &*Context, + ModuleManager = new ASTReader(getPreprocessor(), *Context, Sysroot.empty() ? "" : Sysroot.c_str(), PPOpts.DisablePCHValidation, PPOpts.DisableStatCache); diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 10b01d8c9f..37a23faf0d 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -5515,12 +5515,12 @@ void ASTReader::FinishedDeserializing() { --NumCurrentElementsDeserializing; } -ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, +ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, StringRef isysroot, bool DisableValidation, bool DisableStatCache) : Listener(new PCHValidator(PP, *this)), DeserializationListener(0), SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), - Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(Context), + Diags(PP.getDiagnostics()), SemaObj(0), PP(&PP), Context(&Context), Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), RelocatablePCH(false), isysroot(isysroot), DisableValidation(DisableValidation), @@ -5537,26 +5537,6 @@ ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, SourceMgr.setExternalSLocEntrySource(this); } -ASTReader::ASTReader(SourceManager &SourceMgr, FileManager &FileMgr, - Diagnostic &Diags, StringRef isysroot, - bool DisableValidation, bool DisableStatCache) - : DeserializationListener(0), SourceMgr(SourceMgr), FileMgr(FileMgr), - Diags(Diags), SemaObj(0), PP(0), Context(0), - Consumer(0), ModuleMgr(FileMgr.getFileSystemOptions()), - RelocatablePCH(false), isysroot(isysroot), - DisableValidation(DisableValidation), DisableStatCache(DisableStatCache), - NumStatHits(0), NumStatMisses(0), NumSLocEntriesRead(0), - TotalNumSLocEntries(0), NumStatementsRead(0), - TotalNumStatements(0), NumMacrosRead(0), TotalNumMacros(0), - NumSelectorsRead(0), NumMethodPoolEntriesRead(0), NumMethodPoolMisses(0), - TotalNumMethodPoolEntries(0), NumLexicalDeclContextsRead(0), - TotalLexicalDeclContexts(0), NumVisibleDeclContextsRead(0), - TotalVisibleDeclContexts(0), TotalModulesSizeInBits(0), - NumCurrentElementsDeserializing(0), NumCXXBaseSpecifiersLoaded(0) -{ - SourceMgr.setExternalSLocEntrySource(this); -} - ASTReader::~ASTReader() { for (DeclContextVisibleUpdatesPending::iterator I = PendingVisibleUpdates.begin(), diff --git a/lib/Serialization/ChainedIncludesSource.cpp b/lib/Serialization/ChainedIncludesSource.cpp index e354054fb1..04c3f81e9b 100644 --- a/lib/Serialization/ChainedIncludesSource.cpp +++ b/lib/Serialization/ChainedIncludesSource.cpp @@ -32,7 +32,7 @@ static ASTReader *createASTReader(CompilerInstance &CI, ASTDeserializationListener *deserialListener = 0) { Preprocessor &PP = CI.getPreprocessor(); llvm::OwningPtr Reader; - Reader.reset(new ASTReader(PP, &CI.getASTContext(), /*isysroot=*/"", + Reader.reset(new ASTReader(PP, CI.getASTContext(), /*isysroot=*/"", /*DisableValidation=*/true)); for (unsigned ti = 0; ti < bufNames.size(); ++ti) { StringRef sr(bufNames[ti]);