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) {
23 Info.FormatDiagnostic(Message);
26 if (Info.hasSourceManager() && Info.getLocation().isValid()) {
27 auto &SourceMgr = Info.getSourceManager();
28 auto Loc = SourceMgr.getFileLoc(Info.getLocation());
29 llvm::raw_svector_ostream OS(Location);
30 Loc.print(OS, SourceMgr);
34 clangd::log(
"Ignored diagnostic. {0}{1}", Location, Message);
38 const clang::Diagnostic &
Info) {
42 std::unique_ptr<CompilerInstance>
45 std::unique_ptr<llvm::MemoryBuffer> Buffer,
46 std::shared_ptr<PCHContainerOperations>
PCHs,
47 IntrusiveRefCntPtr<vfs::FileSystem>
VFS,
49 assert(VFS &&
"VFS is null");
50 assert(!CI->getPreprocessorOpts().RetainRemappedFileBuffers &&
51 "Setting RetainRemappedFileBuffers to true will cause a memory leak " 57 Preamble->OverridePreamble(*CI, VFS, Buffer.get());
59 CI->getPreprocessorOpts().addRemappedFile(
60 CI->getFrontendOpts().Inputs[0].getFile(), Buffer.get());
63 auto Clang = llvm::make_unique<CompilerInstance>(
PCHs);
64 Clang->setInvocation(std::move(CI));
65 Clang->createDiagnostics(&DiagsClient,
false);
67 if (
auto VFSWithRemapping = createVFSFromCompilerInvocation(
68 Clang->getInvocation(), Clang->getDiagnostics(),
VFS))
69 VFS = VFSWithRemapping;
70 Clang->setVirtualFileSystem(VFS);
72 Clang->setTarget(TargetInfo::CreateTargetInfo(
73 Clang->getDiagnostics(), Clang->getInvocation().TargetOpts));
74 if (!Clang->hasTarget())
SourceLocation Loc
'#' location in the include directive
static void log(DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info)
static const StringRef Message
void log(const char *Fmt, Ts &&... Vals)
PrecompiledPreamble const * Preamble
IntrusiveRefCntPtr< vfs::FileSystem > VFS
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
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, IntrusiveRefCntPtr< vfs::FileSystem > VFS, DiagnosticConsumer &DiagsClient)
Creates a compiler instance, configured so that:
std::shared_ptr< PCHContainerOperations > PCHs
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &Info) override