diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-06-29 23:23:46 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-06-29 23:23:46 +0000 |
commit | 9f28442d72ed8db4ce56d163e9ea2355cf7cb4ae (patch) | |
tree | 1ff185037d33207158f2a19a7aea2a88126ca271 /include | |
parent | fe7b37a8ff38f40535f98de2e7b72bdd185cd1ae (diff) |
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
Diffstat (limited to 'include')
-rw-r--r-- | include/clang/Frontend/ASTUnit.h | 11 | ||||
-rw-r--r-- | include/clang/Serialization/ASTReader.h | 11 |
2 files changed, 17 insertions, 5 deletions
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<DiagnosticsEngine> 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<ASTUnit> LoadFromASTFile( const std::string &Filename, const PCHContainerReader &PCHContainerRdr, - IntrusiveRefCntPtr<DiagnosticsEngine> Diags, + WhatToLoad ToLoad, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, const FileSystemOptions &FileSystemOpts, bool UseDebugInfo = false, bool OnlyLocalDecls = false, ArrayRef<RemappedFile> 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<std::shared_ptr<ModuleFileExtension>> 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. |