From 9f28442d72ed8db4ce56d163e9ea2355cf7cb4ae Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 29 Jun 2017 23:23:46 +0000 Subject: Teach ASTReader how to read only the Preprocessor state from an AST file, not the ASTContext state. We use this when running a preprocessor-only action on an AST file in order to avoid paying the runtime cost of loading the extra information. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306760 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/ASTUnit.h | 11 ++++++++++- include/clang/Serialization/ASTReader.h | 11 +++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index 2950c31c2d..1ac4f07a35 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -628,6 +628,15 @@ public: IntrusiveRefCntPtr Diags, bool CaptureDiagnostics, bool UserFilesAreVolatile); + enum WhatToLoad { + /// Load options and the preprocessor state. + LoadPreprocessorOnly, + /// Load the AST, but do not restore Sema state. + LoadASTOnly, + /// Load everything, including Sema. + LoadEverything + }; + /// \brief Create a ASTUnit from an AST file. /// /// \param Filename - The AST file to load. @@ -640,7 +649,7 @@ public: /// \returns - The initialized ASTUnit or null if the AST failed to load. static std::unique_ptr LoadFromASTFile( const std::string &Filename, const PCHContainerReader &PCHContainerRdr, - IntrusiveRefCntPtr Diags, + WhatToLoad ToLoad, IntrusiveRefCntPtr Diags, const FileSystemOptions &FileSystemOpts, bool UseDebugInfo = false, bool OnlyLocalDecls = false, ArrayRef RemappedFiles = None, bool CaptureDiagnostics = false, bool AllowPCHWithCompilerErrors = false, diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 9b94aadd76..eafa051758 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -400,7 +400,7 @@ private: Preprocessor &PP; /// \brief The AST context into which we'll read the AST files. - ASTContext &Context; + ASTContext *ContextObj = nullptr; /// \brief The AST consumer. ASTConsumer *Consumer = nullptr; @@ -1387,7 +1387,7 @@ public: /// precompiled header will be loaded. /// /// \param Context the AST context that this precompiled header will be - /// loaded into. + /// loaded into, if any. /// /// \param PCHContainerRdr the PCHContainerOperations to use for loading and /// creating modules. @@ -1419,7 +1419,7 @@ public: /// /// \param ReadTimer If non-null, a timer used to track the time spent /// deserializing. - ASTReader(Preprocessor &PP, ASTContext &Context, + ASTReader(Preprocessor &PP, ASTContext *Context, const PCHContainerReader &PCHContainerRdr, ArrayRef> Extensions, StringRef isysroot = "", bool DisableValidation = false, @@ -2208,7 +2208,10 @@ public: void completeVisibleDeclsMap(const DeclContext *DC) override; /// \brief Retrieve the AST context that this AST reader supplements. - ASTContext &getContext() { return Context; } + ASTContext &getContext() { + assert(ContextObj && "requested AST context when not loading AST"); + return *ContextObj; + } // \brief Contains the IDs for declarations that were requested before we have // access to a Sema object. -- cgit v1.2.3