31#ifndef LLVM_CLANG_BASIC_SARIF_H
32#define LLVM_CLANG_BASIC_SARIF_H
36#include "llvm/ADT/ArrayRef.h"
37#include "llvm/ADT/SmallVector.h"
38#include "llvm/ADT/StringMap.h"
39#include "llvm/ADT/StringRef.h"
40#include "llvm/Support/JSON.h"
44#include <initializer_list>
50class SarifDocumentWriter;
75 std::optional<uint32_t> Index;
108 std::optional<uint32_t> Offset;
109 std::optional<size_t> Length;
110 std::string MimeType;
124 Offset = ArtifactOffset;
134 Roles.assign(ArtifactRoles.begin(), ArtifactRoles.end());
139 MimeType = ArtifactMimeType.str();
189 "ThreadFlows require a character granular source range!");
195 Importance = ItemImportance;
200 Message = ItemMessage.str();
239 assert(TheRank >= 0.0f &&
"Rule rank cannot be smaller than 0.0");
240 assert(TheRank <= 100.0f &&
"Rule rank cannot be larger than 100.0");
262 std::string Description;
272 Name = RuleName.str();
282 Description = RuleDesc.str();
287 HelpURI = RuleHelpURI.str();
293 DefaultConfiguration = Configuration;
324 std::string DiagnosticMessage;
327 std::optional<SarifResultLevel> LevelOverride;
330 explicit SarifResult(uint32_t RuleIdx) : RuleIdx(RuleIdx) {}
346 DiagnosticMessage = Message.str();
352 for (
const auto &
Loc : DiagLocs) {
353 assert(
Loc.isCharRange() &&
354 "SARIF Results require character granular source ranges!");
357 Locations.assign(DiagLocs.begin(), DiagLocs.end());
361 ThreadFlows.assign(ThreadFlowResults.begin(), ThreadFlowResults.end());
366 LevelOverride = TheLevel;
382 const llvm::StringRef SchemaURI{
383 "https://docs.oasis-open.org/sarif/sarif/v2.1.0/cos02/schemas/"
384 "sarif-schema-2.1.0.json"};
385 const llvm::StringRef SchemaVersion{
"2.1.0"};
389 llvm::json::Object &getCurrentTool();
407 llvm::json::Object &getCurrentRun();
436 void createRun(
const llvm::StringRef ShortToolName,
437 const llvm::StringRef LongToolName,
438 const llvm::StringRef ToolVersion = CLANG_VERSION_STRING);
493 llvm::json::Array Runs;
509 llvm::StringMap<detail::SarifArtifact> CurrentArtifacts;
Defines the clang::SourceLocation class and associated facilities.
Defines version macros and version-related utility functions for Clang.
Represents a character-granular source range.
This class handles creating a valid SARIF document given various input attributes.
~SarifDocumentWriter()=default
Release resources held by this SARIF document.
SarifDocumentWriter()=delete
SarifDocumentWriter(const SourceManager &SourceMgr)
Create a new empty SARIF document with the given source manager.
void createRun(const llvm::StringRef ShortToolName, const llvm::StringRef LongToolName, const llvm::StringRef ToolVersion=CLANG_VERSION_STRING)
Create a new run with which any upcoming analysis will be associated.
size_t createRule(const SarifRule &Rule)
Associate the given rule with the current run.
llvm::json::Object createDocument()
Return the SARIF document in its current state.
void endRun()
If there is a current run, end it.
void appendResult(const SarifResult &SarifResult)
Append a new result to the currently in-flight run.
A SARIF Reporting Configuration (reportingConfiguration) object contains properties for a SarifRule t...
static SarifReportingConfiguration create()
SarifReportingConfiguration disable()
SarifReportingConfiguration enable()
SarifReportingConfiguration setLevel(SarifResultLevel TheLevel)
SarifReportingConfiguration setRank(float TheRank)
A SARIF result (also called a "reporting item") is a unit of output produced when one of the tool's r...
SarifResult setIndex(uint32_t Idx)
SarifResult setThreadFlows(llvm::ArrayRef< ThreadFlow > ThreadFlowResults)
SarifResult setDiagnosticMessage(llvm::StringRef Message)
SarifResult setRuleId(llvm::StringRef Id)
SarifResult setLocations(llvm::ArrayRef< CharSourceRange > DiagLocs)
SarifResult setDiagnosticLevel(const SarifResultLevel &TheLevel)
static SarifResult create(uint32_t RuleIdx)
A SARIF rule (reportingDescriptor object) contains information that describes a reporting item genera...
SarifRule setDescription(llvm::StringRef RuleDesc)
SarifRule setHelpURI(llvm::StringRef RuleHelpURI)
SarifRule setRuleId(llvm::StringRef RuleId)
static SarifRule create()
SarifRule setDefaultConfiguration(const SarifReportingConfiguration &Configuration)
SarifRule setName(llvm::StringRef RuleName)
This class handles loading and caching of source files into memory.
A thread flow is a sequence of code locations that specify a possible path through a single thread of...
ThreadFlow setImportance(const ThreadFlowImportance &ItemImportance)
ThreadFlow setRange(const CharSourceRange &ItemRange)
static ThreadFlow create()
ThreadFlow setMessage(llvm::StringRef ItemMessage)
SarifArtifactLocation setIndex(uint32_t Idx)
static SarifArtifactLocation create(llvm::StringRef URI)
Since every clang artifact MUST have a location (there being no nested artifacts),...
SarifArtifact setOffset(uint32_t ArtifactOffset)
SarifArtifact setMimeType(llvm::StringRef ArtifactMimeType)
static SarifArtifact create(const SarifArtifactLocation &Loc)
SarifArtifact setRoles(std::initializer_list< llvm::StringRef > ArtifactRoles)
SarifArtifact setLength(size_t NumBytes)
The JSON file list parser is used to communicate input to InstallAPI.
SarifResultLevel
The level of severity associated with a SarifResult.
@ None
The alignment was not explicit in code.