Kirill Bobyrev | 8e35f1e | 2018-08-14 16:03:32 +0000 | [diff] [blame] | 1 | //===--- Compiler.h ----------------------------------------------*- C++-*-===// |
Sam McCall | 98775c5 | 2017-12-04 13:49:59 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Sam McCall | 98775c5 | 2017-12-04 13:49:59 +0000 | [diff] [blame] | 6 | // |
Kirill Bobyrev | 8e35f1e | 2018-08-14 16:03:32 +0000 | [diff] [blame] | 7 | //===----------------------------------------------------------------------===// |
Sam McCall | 98775c5 | 2017-12-04 13:49:59 +0000 | [diff] [blame] | 8 | // |
| 9 | // Shared utilities for invoking the clang compiler. |
| 10 | // ClangdUnit takes care of much of this, but some features like CodeComplete |
| 11 | // run their own compile actions that share logic. |
| 12 | // |
Kirill Bobyrev | 8e35f1e | 2018-08-14 16:03:32 +0000 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Sam McCall | 98775c5 | 2017-12-04 13:49:59 +0000 | [diff] [blame] | 15 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H |
| 16 | #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H |
Eric Liu | b99d5e8 | 2017-12-14 21:22:03 +0000 | [diff] [blame] | 17 | |
Sam McCall | 98775c5 | 2017-12-04 13:49:59 +0000 | [diff] [blame] | 18 | #include "clang/Frontend/CompilerInstance.h" |
| 19 | #include "clang/Frontend/CompilerInvocation.h" |
| 20 | #include "clang/Frontend/PrecompiledPreamble.h" |
| 21 | |
| 22 | namespace clang { |
| 23 | namespace clangd { |
| 24 | |
| 25 | class IgnoreDiagnostics : public DiagnosticConsumer { |
| 26 | public: |
Ilya Biryukov | 2d4cdac | 2018-02-12 12:48:51 +0000 | [diff] [blame] | 27 | static void log(DiagnosticsEngine::Level DiagLevel, |
| 28 | const clang::Diagnostic &Info); |
| 29 | |
Sam McCall | 98775c5 | 2017-12-04 13:49:59 +0000 | [diff] [blame] | 30 | void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, |
Ilya Biryukov | 2d4cdac | 2018-02-12 12:48:51 +0000 | [diff] [blame] | 31 | const clang::Diagnostic &Info) override; |
Sam McCall | 98775c5 | 2017-12-04 13:49:59 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
Ilya Biryukov | 295c8e1 | 2018-01-18 15:17:00 +0000 | [diff] [blame] | 34 | /// Creates a compiler instance, configured so that: |
| 35 | /// - Contents of the parsed file are remapped to \p MainFile. |
| 36 | /// - Preamble is overriden to use PCH passed to this function. It means the |
| 37 | /// changes to the preamble headers or files included in the preamble are |
| 38 | /// not visible to this compiler instance. |
Jonas Devlieghere | fc51490 | 2018-10-10 13:27:25 +0000 | [diff] [blame] | 39 | /// - llvm::vfs::FileSystem is used for all underlying file accesses. The |
| 40 | /// actual vfs used by the compiler may be an overlay over the passed vfs. |
Ilya Biryukov | 295c8e1 | 2018-01-18 15:17:00 +0000 | [diff] [blame] | 41 | /// Returns null on errors. When non-null value is returned, it is expected to |
| 42 | /// be consumed by FrontendAction::BeginSourceFile to properly destroy \p |
| 43 | /// MainFile. |
Sam McCall | 98775c5 | 2017-12-04 13:49:59 +0000 | [diff] [blame] | 44 | std::unique_ptr<CompilerInstance> prepareCompilerInstance( |
| 45 | std::unique_ptr<clang::CompilerInvocation>, const PrecompiledPreamble *, |
| 46 | std::unique_ptr<llvm::MemoryBuffer> MainFile, |
| 47 | std::shared_ptr<PCHContainerOperations>, |
Jonas Devlieghere | fc51490 | 2018-10-10 13:27:25 +0000 | [diff] [blame] | 48 | IntrusiveRefCntPtr<llvm::vfs::FileSystem>, DiagnosticConsumer &); |
Sam McCall | 98775c5 | 2017-12-04 13:49:59 +0000 | [diff] [blame] | 49 | |
| 50 | } // namespace clangd |
| 51 | } // namespace clang |
| 52 | |
Kirill Bobyrev | 8e35f1e | 2018-08-14 16:03:32 +0000 | [diff] [blame] | 53 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H |