12 #include "clang/Basic/TargetInfo.h" 13 #include "clang/Lex/PreprocessorOptions.h" 14 #include "llvm/Support/Format.h" 15 #include "llvm/Support/FormatVariadic.h" 21 const clang::Diagnostic &
Info) {
24 Info.FormatDiagnostic(Message);
27 if (Info.hasSourceManager() && Info.getLocation().isValid()) {
28 auto &SourceMgr = Info.getSourceManager();
29 auto Loc = SourceMgr.getFileLoc(Info.getLocation());
30 llvm::raw_svector_ostream OS(Location);
31 Loc.print(OS, SourceMgr);
35 clangd::vlog(
"Ignored diagnostic. {0}{1}", Location, Message);
39 const clang::Diagnostic &
Info) {
43 std::unique_ptr<CompilerInstance>
46 std::unique_ptr<llvm::MemoryBuffer> Buffer,
47 std::shared_ptr<PCHContainerOperations>
PCHs,
48 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
VFS,
50 assert(VFS &&
"VFS is null");
51 assert(!CI->getPreprocessorOpts().RetainRemappedFileBuffers &&
52 "Setting RetainRemappedFileBuffers to true will cause a memory leak " 58 Preamble->OverridePreamble(*CI, VFS, Buffer.get());
60 CI->getPreprocessorOpts().addRemappedFile(
61 CI->getFrontendOpts().Inputs[0].getFile(), Buffer.get());
64 auto Clang = llvm::make_unique<CompilerInstance>(
PCHs);
65 Clang->setInvocation(std::move(CI));
66 Clang->createDiagnostics(&DiagsClient,
false);
68 if (
auto VFSWithRemapping = createVFSFromCompilerInvocation(
69 Clang->getInvocation(), Clang->getDiagnostics(),
VFS))
70 VFS = VFSWithRemapping;
71 Clang->setVirtualFileSystem(VFS);
73 Clang->setTarget(TargetInfo::CreateTargetInfo(
74 Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
75 if (!Clang->hasTarget())
SourceLocation Loc
'#' location in the include directive
static void log(DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info)
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS
static const StringRef Message
void vlog(const char *Fmt, Ts &&... Vals)
const PreambleData * Preamble
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::shared_ptr< PCHContainerOperations > PCHs
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info) override
std::unique_ptr< CompilerInstance > prepareCompilerInstance(std::unique_ptr< clang::CompilerInvocation > CI, const PrecompiledPreamble *Preamble, std::unique_ptr< llvm::MemoryBuffer > Buffer, std::shared_ptr< PCHContainerOperations > PCHs, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, DiagnosticConsumer &DiagsClient)