clang  19.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 is a utility class that provides support for constructing a SARIF object
10 // containing diagnostics.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_FRONTEND_SARIFDIAGNOSTIC_H
15 #define LLVM_CLANG_FRONTEND_SARIFDIAGNOSTIC_H
16 
17 #include "clang/Basic/Sarif.h"
19 #include "llvm/ADT/StringRef.h"
20 
21 namespace clang {
22 
24 public:
25  SARIFDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
27 
28  ~SARIFDiagnostic() = default;
29 
33  SARIFDiagnostic(const SARIFDiagnostic &) = delete;
34 
35 protected:
37  DiagnosticsEngine::Level Level, StringRef Message,
39  DiagOrStoredDiag D) override;
40 
43  ArrayRef<CharSourceRange> Ranges) override;
44 
47  ArrayRef<FixItHint> Hints) override {}
48 
49  void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override;
50 
52  StringRef ModuleName) override;
53 
55  StringRef ModuleName) override;
56 
57 private:
58  // Shared between SARIFDiagnosticPrinter and this renderer.
59  SarifDocumentWriter *Writer;
60 
61  SarifResult addLocationToResult(SarifResult Result, FullSourceLoc Loc,
62  PresumedLoc PLoc,
64  const Diagnostic &Diag);
65 
66  SarifRule addDiagnosticLevelToRule(SarifRule Rule,
68 
69  llvm::StringRef emitFilename(StringRef Filename, const SourceManager &SM);
70 };
71 
72 } // end namespace clang
73 
74 #endif
#define SM(sm)
Definition: Cuda.cpp:83
StringRef Filename
Definition: Format.cpp:2976
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.
SourceLocation Loc
Definition: SemaObjC.cpp:755
Options for controlling the compiler diagnostics engine.
Class to encapsulate the logic for formatting a diagnostic message.
const LangOptions & LangOpts
IntrusiveRefCntPtr< DiagnosticOptions > DiagOpts
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1577
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:196
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...
Definition: LangOptions.h:482
Represents an unpacked "presumed" location which can be presented to the user.
SARIFDiagnostic(const SARIFDiagnostic &)=delete
void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override
SARIFDiagnostic(raw_ostream &OS, const LangOptions &LangOpts, DiagnosticOptions *DiagOpts, SarifDocumentWriter *Writer)
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
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
This class handles creating a valid SARIF document given various input attributes.
Definition: Sarif.h:380
A SARIF result (also called a "reporting item") is a unit of output produced when one of the tool's r...
Definition: Sarif.h:315
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.
The JSON file list parser is used to communicate input to InstallAPI.
llvm::PointerUnion< const Diagnostic *, const StoredDiagnostic * > DiagOrStoredDiag