2018-08-15 00:03:32 +08:00
|
|
|
//===--- Compiler.h ----------------------------------------------*- C++-*-===//
|
2017-12-04 21:49:59 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-12-04 21:49:59 +08:00
|
|
|
//
|
2018-08-15 00:03:32 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2017-12-04 21:49:59 +08:00
|
|
|
//
|
|
|
|
// Shared utilities for invoking the clang compiler.
|
2019-09-04 15:35:00 +08:00
|
|
|
// Most callers will use this through Preamble/ParsedAST, but some features like
|
|
|
|
// CodeComplete run their own compile actions that share these low-level pieces.
|
2017-12-04 21:49:59 +08:00
|
|
|
//
|
2018-08-15 00:03:32 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-12-04 21:49:59 +08:00
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H
|
2017-12-15 05:22:03 +08:00
|
|
|
|
2021-03-12 21:23:45 +08:00
|
|
|
#include "FeatureModule.h"
|
2019-04-15 20:32:28 +08:00
|
|
|
#include "GlobalCompilationDatabase.h"
|
2020-11-26 02:35:34 +08:00
|
|
|
#include "TidyProvider.h"
|
2019-01-28 22:01:55 +08:00
|
|
|
#include "index/Index.h"
|
2020-06-17 17:53:32 +08:00
|
|
|
#include "support/ThreadsafeFS.h"
|
2017-12-04 21:49:59 +08:00
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
|
|
|
#include "clang/Frontend/PrecompiledPreamble.h"
|
2019-01-22 17:58:53 +08:00
|
|
|
#include "clang/Tooling/CompilationDatabase.h"
|
2021-03-12 21:23:45 +08:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
2017-12-04 21:49:59 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
|
|
|
|
class IgnoreDiagnostics : public DiagnosticConsumer {
|
|
|
|
public:
|
2018-02-12 20:48:51 +08:00
|
|
|
static void log(DiagnosticsEngine::Level DiagLevel,
|
|
|
|
const clang::Diagnostic &Info);
|
|
|
|
|
2017-12-04 21:49:59 +08:00
|
|
|
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
|
2018-02-12 20:48:51 +08:00
|
|
|
const clang::Diagnostic &Info) override;
|
2017-12-04 21:49:59 +08:00
|
|
|
};
|
|
|
|
|
2019-01-28 22:01:55 +08:00
|
|
|
// Options to run clang e.g. when parsing AST.
|
|
|
|
struct ParseOptions {
|
2021-01-15 06:50:35 +08:00
|
|
|
// (empty at present, formerly controlled recovery AST, include-fixer etc)
|
2019-01-28 22:01:55 +08:00
|
|
|
};
|
|
|
|
|
2019-01-22 17:58:53 +08:00
|
|
|
/// Information required to run clang, e.g. to parse AST or do code completion.
|
|
|
|
struct ParseInputs {
|
|
|
|
tooling::CompileCommand CompileCommand;
|
2020-06-18 00:09:54 +08:00
|
|
|
const ThreadsafeFS *TFS;
|
2019-01-22 17:58:53 +08:00
|
|
|
std::string Contents;
|
[clangd] Track document versions, include them with diags, enhance logs
Summary:
This ties to an LSP feature (diagnostic versioning) but really a lot
of the value is in being able to log what's happening with file versions
and queues more descriptively and clearly.
As such it's fairly invasive, for a logging patch :-\
Key decisions:
- at the LSP layer, we don't reqire the client to provide versions (LSP
makes it mandatory but we never enforced it). If not provided,
versions start at 0 and increment. DraftStore handles this.
- don't propagate magically using contexts, but rather manually:
addDocument -> ParseInputs -> (ParsedAST, Preamble, various callbacks)
Context-propagation would hide the versions from ClangdServer, which
would make producing good log messages hard
- within ClangdServer, treat versions as opaque and unordered.
std::string is a convenient type for this, and allows richer versions
for embedders. They're "mandatory" but "null" is a reasonable default.
Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75582
2020-03-04 07:33:29 +08:00
|
|
|
// Version identifier for Contents, provided by the client and opaque to us.
|
|
|
|
std::string Version = "null";
|
2020-02-04 04:14:49 +08:00
|
|
|
// Prevent reuse of the cached preamble/AST. Slow! Useful to workaround
|
|
|
|
// clangd's assumption that missing header files will stay missing.
|
|
|
|
bool ForceRebuild = false;
|
2019-01-28 22:01:55 +08:00
|
|
|
// Used to recover from diagnostics (e.g. find missing includes for symbol).
|
|
|
|
const SymbolIndex *Index = nullptr;
|
2020-06-03 16:34:05 +08:00
|
|
|
ParseOptions Opts = ParseOptions();
|
2020-11-26 02:35:34 +08:00
|
|
|
TidyProviderRef ClangTidyProvider = {};
|
2021-03-12 21:23:45 +08:00
|
|
|
// Used to acquire ASTListeners when parsing files.
|
|
|
|
FeatureModuleSet *FeatureModules = nullptr;
|
2019-01-22 17:58:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Builds compiler invocation that could be used to build AST or preamble.
|
|
|
|
std::unique_ptr<CompilerInvocation>
|
2019-11-29 02:22:50 +08:00
|
|
|
buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
|
|
|
|
std::vector<std::string> *CC1Args = nullptr);
|
2019-01-22 17:58:53 +08:00
|
|
|
|
2018-01-18 23:17:00 +08:00
|
|
|
/// Creates a compiler instance, configured so that:
|
|
|
|
/// - Contents of the parsed file are remapped to \p MainFile.
|
|
|
|
/// - Preamble is overriden to use PCH passed to this function. It means the
|
|
|
|
/// changes to the preamble headers or files included in the preamble are
|
|
|
|
/// not visible to this compiler instance.
|
2018-10-10 21:27:25 +08:00
|
|
|
/// - llvm::vfs::FileSystem is used for all underlying file accesses. The
|
|
|
|
/// actual vfs used by the compiler may be an overlay over the passed vfs.
|
2018-01-18 23:17:00 +08:00
|
|
|
/// Returns null on errors. When non-null value is returned, it is expected to
|
|
|
|
/// be consumed by FrontendAction::BeginSourceFile to properly destroy \p
|
|
|
|
/// MainFile.
|
2017-12-04 21:49:59 +08:00
|
|
|
std::unique_ptr<CompilerInstance> prepareCompilerInstance(
|
|
|
|
std::unique_ptr<clang::CompilerInvocation>, const PrecompiledPreamble *,
|
|
|
|
std::unique_ptr<llvm::MemoryBuffer> MainFile,
|
2018-10-10 21:27:25 +08:00
|
|
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem>, DiagnosticConsumer &);
|
2017-12-04 21:49:59 +08:00
|
|
|
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|
|
|
|
|
2018-08-15 00:03:32 +08:00
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H
|