clang 20.0.0git
SARIFDiagnosticPrinter.h
Go to the documentation of this file.
1//===-- SARIFDiagnosticPrinter.h - SARIF Diagnostic Client -------*- 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// This is a concrete diagnostic client, which prints the diagnostics to
10// standard error in SARIF format.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_FRONTEND_SARIFDIAGNOSTICPRINTER_H
15#define LLVM_CLANG_FRONTEND_SARIFDIAGNOSTICPRINTER_H
16
18#include "clang/Basic/LLVM.h"
19#include "clang/Basic/Sarif.h"
20#include "llvm/ADT/IntrusiveRefCntPtr.h"
21#include "llvm/ADT/StringRef.h"
22#include <memory>
23
24namespace clang {
25class DiagnosticOptions;
26class LangOptions;
27class SARIFDiagnostic;
28class SarifDocumentWriter;
29
31public:
32 SARIFDiagnosticPrinter(raw_ostream &OS, DiagnosticOptions *Diags);
34
39
40 /// setPrefix - Set the diagnostic printer prefix string, which will be
41 /// printed at the start of any diagnostics. If empty, no prefix string is
42 /// used.
43 void setPrefix(llvm::StringRef Value) { Prefix = Value; }
44
45 bool hasSarifWriter() const { return Writer != nullptr; }
46
48 assert(Writer && "SarifWriter not set!");
49 return *Writer;
50 }
51
52 void setSarifWriter(std::unique_ptr<SarifDocumentWriter> SarifWriter) {
53 Writer = std::move(SarifWriter);
54 }
55
56 void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override;
57 void EndSourceFile() override;
59 const Diagnostic &Info) override;
60
61private:
62 raw_ostream &OS;
64
65 /// Handle to the currently active SARIF diagnostic emitter.
66 std::unique_ptr<SARIFDiagnostic> SARIFDiag;
67
68 /// A string to prefix to error messages.
69 std::string Prefix;
70
71 std::unique_ptr<SarifDocumentWriter> Writer;
72};
73
74} // end namespace clang
75
76#endif
Defines the Diagnostic-related interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines clang::SarifDocumentWriter, clang::SarifRule, clang::SarifResult.
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Definition: Diagnostic.h:1745
Options for controlling the compiler diagnostics engine.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1571
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:195
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:461
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:137
void setPrefix(llvm::StringRef Value)
setPrefix - Set the diagnostic printer prefix string, which will be printed at the start of any diagn...
void EndSourceFile() override
Callback to inform the diagnostic client that processing of a source file has ended.
void setSarifWriter(std::unique_ptr< SarifDocumentWriter > SarifWriter)
void HandleDiagnostic(DiagnosticsEngine::Level Level, const Diagnostic &Info) override
Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override
Callback to inform the diagnostic client that processing of a source file is beginning.
SARIFDiagnosticPrinter(const SARIFDiagnosticPrinter &)=delete
SarifDocumentWriter & getSarifWriter() const
SARIFDiagnosticPrinter & operator=(const SARIFDiagnosticPrinter &)=delete
SARIFDiagnosticPrinter(SARIFDiagnosticPrinter &&)=delete
SARIFDiagnosticPrinter & operator=(const SARIFDiagnosticPrinter &&)=delete
This class handles creating a valid SARIF document given various input attributes.
Definition: Sarif.h:380
The JSON file list parser is used to communicate input to InstallAPI.