clang 24.0.0git
SARIFDiagnostic.h
Go to the documentation of this file.
1//===--- SARIFDiagnostic.h - SARIF Diagnostic Formatting -----*- 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 file implements SARIF diagnostic emission, including the SARIFDiagnostic
10// renderer and helper utilities for mapping diagnostic levels and annotating
11// SARIF rules.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_FRONTEND_SARIFDIAGNOSTIC_H
16#define LLVM_CLANG_FRONTEND_SARIFDIAGNOSTIC_H
17
18#include "clang/Basic/Sarif.h"
20#include "llvm/ADT/StringRef.h"
21
22namespace clang {
23
24// Maps clang DiagnosticsEngine level to SARIF result levels.
26
27// Creates configuration for a SARIF rule based on the diagnostic level and sets
28// the rank.
31
33public:
34 SARIFDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
36
37 ~SARIFDiagnostic() = default;
38
43
44protected:
46 DiagnosticsEngine::Level Level, StringRef Message,
48 DiagOrStoredDiag D) override;
49
52 ArrayRef<CharSourceRange> Ranges) override;
53
57
58 void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override;
59
61 StringRef ModuleName) override;
62
64 StringRef ModuleName) override;
65
66private:
67 // Shared between SARIFDiagnosticPrinter and this renderer.
68 SarifDocumentWriter *Writer;
69
70 SarifResult addLocationToResult(SarifResult Result, FullSourceLoc Loc,
71 PresumedLoc PLoc,
73 const Diagnostic &Diag);
74
75 SarifResult addRelatedLocationToResult(SarifResult Result, FullSourceLoc Loc,
76 PresumedLoc PLoc);
77
79 getSarifLocation(FullSourceLoc Loc, PresumedLoc PLoc,
81
82 llvm::StringRef emitFilename(StringRef Filename, const SourceManager &SM);
83
85 RelatedLocationsCache;
86};
87
88} // end namespace clang
89
90#endif
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Defines clang::SarifDocumentWriter, clang::SarifRule, clang::SarifResult.
Options for controlling the compiler diagnostics engine.
const LangOptions & LangOpts
DiagnosticOptions & DiagOpts
DiagnosticRenderer(const LangOptions &LangOpts, DiagnosticOptions &DiagOpts)
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine a...
Level
The level of the diagnostic, after it has been through mapping.
Definition Diagnostic.h:245
A SourceLocation and its associated SourceManager.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Represents an unpacked "presumed" location which can be presented to the user.
SARIFDiagnostic(raw_ostream &OS, const LangOptions &LangOpts, DiagnosticOptions &DiagOpts, SarifDocumentWriter *Writer)
SARIFDiagnostic(const SARIFDiagnostic &)=delete
void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override
void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef< CharSourceRange > Ranges, DiagOrStoredDiag D) override
void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, ArrayRef< CharSourceRange > Ranges) override
Print out the file/line/column information and include trace.
SARIFDiagnostic & operator=(const SARIFDiagnostic &&)=delete
void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc, StringRef ModuleName) override
void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level, SmallVectorImpl< CharSourceRange > &Ranges, ArrayRef< FixItHint > Hints) override
SARIFDiagnostic(SARIFDiagnostic &&)=delete
void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc, StringRef ModuleName) override
SARIFDiagnostic & operator=(const SARIFDiagnostic &)=delete
This class handles creating a valid SARIF document given various input attributes.
Definition Sarif.h:422
A SARIF result (also called a "reporting item") is a unit of output produced when one of the tool's r...
Definition Sarif.h:322
A SARIF rule (reportingDescriptor object) contains information that describes a reporting item genera...
Definition Sarif.h:257
This class handles loading and caching of source files into memory.
Top level wrappers for InstallAPI frontend operations.
llvm::PointerUnion< const Diagnostic *, const StoredDiagnostic * > DiagOrStoredDiag
SarifResultLevel getSarifResultLevel(DiagnosticsEngine::Level level)
SarifResultLevel
The level of severity associated with a SarifResult.
Definition Sarif.h:165
@ Result
The result type of a method or function.
Definition TypeBase.h:906
SarifRule addDiagnosticLevelToRule(SarifRule Rule, DiagnosticsEngine::Level Level)