clang 22.0.0git
Sarif.cpp File Reference

This file contains the declaration of the SARIFDocumentWriter class, and associated builders such as: More...

#include "clang/Basic/Sarif.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/Path.h"
#include <optional>
#include <string>
#include <utility>

Go to the source code of this file.

Classes

class  SarifArtifact
 Since every clang artifact MUST have a location (there being no nested artifacts), the creation method SarifArtifact::create requires a SarifArtifactLocation object. More...
class  SarifArtifactLocation

Functions

static StringRef getFileName (FileEntryRef FE)
static unsigned int adjustColumnPos (FullSourceLoc Loc, unsigned int TokenLen=0)
 Calculate the column position expressed in the number of UTF-8 code points from column start to the source location.
URI
static std::string percentEncodeURICharacter (char C)
static std::string fileNameToURI (StringRef Filename)
SARIF Utilities
static json::Object createMessage (StringRef Text)
static json::Object createTextRegion (const SourceManager &SM, const CharSourceRange &R)
static json::Object createLocation (json::Object &&PhysicalLocation, StringRef Message="")
static StringRef importanceToStr (ThreadFlowImportance I)
static StringRef resultLevelToStr (SarifResultLevel R)
static json::Object createThreadFlowLocation (json::Object &&Location, const ThreadFlowImportance &Importance)

Detailed Description

This file contains the declaration of the SARIFDocumentWriter class, and associated builders such as:

Definition in file Sarif.cpp.

Function Documentation

◆ adjustColumnPos()

unsigned int adjustColumnPos ( FullSourceLoc Loc,
unsigned int TokenLen = 0 )
static

Calculate the column position expressed in the number of UTF-8 code points from column start to the source location.

Parameters
LocThe source location whose column needs to be calculated.
TokenLenOptional hint for when the token is multiple bytes long.
Returns
The column number as a UTF-8 aware byte offset from column start to the effective source location.

Definition at line 116 of file Sarif.cpp.

References clang::SourceManager::getBufferOrNone(), clang::FullSourceLoc::getDecomposedExpansionLoc(), clang::FullSourceLoc::getExpansionColumnNumber(), clang::FullSourceLoc::getManager(), and clang::SourceLocation::isInvalid().

Referenced by createTextRegion().

◆ createLocation()

json::Object createLocation ( json::Object && PhysicalLocation,
StringRef Message = "" )
static

Definition at line 165 of file Sarif.cpp.

References createMessage().

Referenced by clang::SarifDocumentWriter::appendResult().

◆ createMessage()

json::Object createMessage ( StringRef Text)
static

Definition at line 143 of file Sarif.cpp.

References clang::Text.

Referenced by clang::SarifDocumentWriter::appendResult(), and createLocation().

◆ createTextRegion()

json::Object createTextRegion ( const SourceManager & SM,
const CharSourceRange & R )
static

◆ createThreadFlowLocation()

json::Object createThreadFlowLocation ( json::Object && Location,
const ThreadFlowImportance & Importance )
static

Definition at line 201 of file Sarif.cpp.

References importanceToStr().

◆ fileNameToURI()

std::string fileNameToURI ( StringRef Filename)
static

Definition at line 70 of file Sarif.cpp.

References clang::C, and percentEncodeURICharacter().

◆ getFileName()

StringRef getFileName ( FileEntryRef FE)
static

◆ importanceToStr()

StringRef importanceToStr ( ThreadFlowImportance I)
static

Definition at line 173 of file Sarif.cpp.

References clang::Essential, clang::Important, and clang::Unimportant.

Referenced by createThreadFlowLocation().

◆ percentEncodeURICharacter()

std::string percentEncodeURICharacter ( char C)
static

Definition at line 53 of file Sarif.cpp.

References clang::C, and contains().

Referenced by fileNameToURI().

◆ resultLevelToStr()

StringRef resultLevelToStr ( SarifResultLevel R)
static