diff options
author | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2018-05-17 09:24:37 +0000 |
---|---|---|
committer | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2018-05-17 09:24:37 +0000 |
commit | 6e89528c557fe7e41b2c4946d75d1e5b36f62fd5 (patch) | |
tree | 2f8458fec27372b1304faa4349faef6897b602a1 /clang/lib/Frontend/ASTUnit.cpp | |
parent | 270ef5b85c9c0898ef76fee3e4ba5e3e5cb46c29 (diff) | |
download | bcm5719-llvm-6e89528c557fe7e41b2c4946d75d1e5b36f62fd5.tar.gz bcm5719-llvm-6e89528c557fe7e41b2c4946d75d1e5b36f62fd5.zip |
[libclang] Allow skipping function bodies in preamble only
Second attempt. Fix line endings and warning.
As an addition to CXTranslationUnit_SkipFunctionBodies, provide the
new option CXTranslationUnit_LimitSkipFunctionBodiesToPreamble,
which constraints the skipping of functions bodies to the preamble
only. Function bodies in the main file are not affected if this
option is set.
Skipping function bodies only in the preamble is what clangd already
does and the introduced flag implements it for libclang clients.
Patch by Nikolai Kosjar.
Differential Revision: https://reviews.llvm.org/D45815
llvm-svn: 332587
Diffstat (limited to 'clang/lib/Frontend/ASTUnit.cpp')
-rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 9b672d97551..2214d827455 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -1271,7 +1271,7 @@ makeStandaloneDiagnostic(const LangOptions &LangOpts, std::unique_ptr<llvm::MemoryBuffer> ASTUnit::getMainBufferWithPrecompiledPreamble( std::shared_ptr<PCHContainerOperations> PCHContainerOps, - const CompilerInvocation &PreambleInvocationIn, + CompilerInvocation &PreambleInvocationIn, IntrusiveRefCntPtr<vfs::FileSystem> VFS, bool AllowRebuild, unsigned MaxLines) { auto MainFilePath = @@ -1338,9 +1338,18 @@ ASTUnit::getMainBufferWithPrecompiledPreamble( SimpleTimer PreambleTimer(WantTiming); PreambleTimer.setOutput("Precompiling preamble"); + const bool PreviousSkipFunctionBodies = + PreambleInvocationIn.getFrontendOpts().SkipFunctionBodies; + if (SkipFunctionBodies == SkipFunctionBodiesScope::Preamble) + PreambleInvocationIn.getFrontendOpts().SkipFunctionBodies = true; + llvm::ErrorOr<PrecompiledPreamble> NewPreamble = PrecompiledPreamble::Build( PreambleInvocationIn, MainFileBuffer.get(), Bounds, *Diagnostics, VFS, PCHContainerOps, /*StoreInMemory=*/false, Callbacks); + + PreambleInvocationIn.getFrontendOpts().SkipFunctionBodies = + PreviousSkipFunctionBodies; + if (NewPreamble) { Preamble = std::move(*NewPreamble); PreambleRebuildCounter = 1; @@ -1691,7 +1700,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine( ArrayRef<RemappedFile> RemappedFiles, bool RemappedFilesKeepOriginalName, unsigned PrecompilePreambleAfterNParses, TranslationUnitKind TUKind, bool CacheCodeCompletionResults, bool IncludeBriefCommentsInCodeCompletion, - bool AllowPCHWithCompilerErrors, bool SkipFunctionBodies, + bool AllowPCHWithCompilerErrors, SkipFunctionBodiesScope SkipFunctionBodies, bool SingleFileParse, bool UserFilesAreVolatile, bool ForSerialization, llvm::Optional<StringRef> ModuleFormat, std::unique_ptr<ASTUnit> *ErrAST, IntrusiveRefCntPtr<vfs::FileSystem> VFS) { @@ -1724,7 +1733,8 @@ ASTUnit *ASTUnit::LoadFromCommandLine( // Override the resources path. CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath; - CI->getFrontendOpts().SkipFunctionBodies = SkipFunctionBodies; + CI->getFrontendOpts().SkipFunctionBodies = + SkipFunctionBodies == SkipFunctionBodiesScope::PreambleAndMainFile; if (ModuleFormat) CI->getHeaderSearchOpts().ModuleFormat = ModuleFormat.getValue(); @@ -1750,6 +1760,7 @@ ASTUnit *ASTUnit::LoadFromCommandLine( = IncludeBriefCommentsInCodeCompletion; AST->UserFilesAreVolatile = UserFilesAreVolatile; AST->Invocation = CI; + AST->SkipFunctionBodies = SkipFunctionBodies; if (ForSerialization) AST->WriterData.reset(new ASTWriterData(*AST->PCMCache)); // Zero out now to ease cleanup during crash recovery. |