clang-tools  10.0.0svn
Compiler.h
Go to the documentation of this file.
1 //===--- Compiler.h ----------------------------------------------*- C++-*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Shared utilities for invoking the clang compiler.
10 // Most callers will use this through Preamble/ParsedAST, but some features like
11 // CodeComplete run their own compile actions that share these low-level pieces.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H
16 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H
17 
18 #include "../clang-tidy/ClangTidyOptions.h"
20 #include "index/Index.h"
21 #include "clang/Frontend/CompilerInstance.h"
22 #include "clang/Frontend/PrecompiledPreamble.h"
23 #include "clang/Tooling/CompilationDatabase.h"
24 
25 namespace clang {
26 namespace clangd {
27 
29 public:
30  static void log(DiagnosticsEngine::Level DiagLevel,
31  const clang::Diagnostic &Info);
32 
33  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
34  const clang::Diagnostic &Info) override;
35 };
36 
37 // Options to run clang e.g. when parsing AST.
38 struct ParseOptions {
40  bool SuggestMissingIncludes = false;
41 };
42 
43 /// Information required to run clang, e.g. to parse AST or do code completion.
44 struct ParseInputs {
45  tooling::CompileCommand CompileCommand;
46  IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS;
47  std::string Contents;
48  // Used to recover from diagnostics (e.g. find missing includes for symbol).
49  const SymbolIndex *Index = nullptr;
51 };
52 
53 /// Builds compiler invocation that could be used to build AST or preamble.
54 std::unique_ptr<CompilerInvocation>
56  clang::DiagnosticConsumer &D);
57 
58 /// Creates a compiler instance, configured so that:
59 /// - Contents of the parsed file are remapped to \p MainFile.
60 /// - Preamble is overriden to use PCH passed to this function. It means the
61 /// changes to the preamble headers or files included in the preamble are
62 /// not visible to this compiler instance.
63 /// - llvm::vfs::FileSystem is used for all underlying file accesses. The
64 /// actual vfs used by the compiler may be an overlay over the passed vfs.
65 /// Returns null on errors. When non-null value is returned, it is expected to
66 /// be consumed by FrontendAction::BeginSourceFile to properly destroy \p
67 /// MainFile.
68 std::unique_ptr<CompilerInstance> prepareCompilerInstance(
69  std::unique_ptr<clang::CompilerInvocation>, const PrecompiledPreamble *,
70  std::unique_ptr<llvm::MemoryBuffer> MainFile,
71  IntrusiveRefCntPtr<llvm::vfs::FileSystem>, DiagnosticConsumer &);
72 
73 } // namespace clangd
74 } // namespace clang
75 
76 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H
static void log(DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info)
Definition: Compiler.cpp:20
Interface for symbol indexes that can be used for searching or matching symbols among a set of symbol...
Definition: Index.h:85
Contains options for clang-tidy.
std::unique_ptr< CompilerInstance > prepareCompilerInstance(std::unique_ptr< clang::CompilerInvocation > CI, const PrecompiledPreamble *Preamble, std::unique_ptr< llvm::MemoryBuffer > Buffer, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, DiagnosticConsumer &DiagsClient)
Definition: Compiler.cpp:70
tidy::ClangTidyOptions ClangTidyOpts
Definition: Compiler.h:39
std::string MainFile
tooling::CompileCommand CompileCommand
Definition: Compiler.h:45
const Decl * D
Definition: XRefs.cpp:849
std::unique_ptr< CompilerInvocation > buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D)
Builds compiler invocation that could be used to build AST or preamble.
Definition: Compiler.cpp:44
An information message.
Information required to run clang, e.g. to parse AST or do code completion.
Definition: Compiler.h:44
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info) override
Definition: Compiler.cpp:38
IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS
Definition: Compiler.h:46
const SymbolIndex * Index
Definition: Dexp.cpp:84