17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/SmallString.h"
19#include "llvm/ADT/StringExtras.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/Support/Casting.h"
22#include "llvm/Support/ConvertUTF.h"
23#include "llvm/Support/ErrorHandling.h"
24#include "llvm/Support/ErrorOr.h"
25#include "llvm/Support/Locale.h"
26#include "llvm/Support/Path.h"
27#include "llvm/Support/raw_ostream.h"
51 Rule = addDiagnosticLevelToRule(Rule, Level);
71 FileID FID =
Loc.getFileID();
74 emitFilename(FE->getName(),
Loc.getManager());
81 FileID CaretFileID =
Loc.getExpansionLoc().getFileID();
83 for (
const CharSourceRange
Range : Ranges) {
85 if (
Range.isInvalid())
88 auto &
SM =
Loc.getManager();
89 SourceLocation B =
SM.getExpansionLoc(
Range.getBegin());
90 CharSourceRange ERange =
SM.getExpansionRange(
Range.getEnd());
91 SourceLocation
E = ERange.getEnd();
92 bool IsTokenRange = ERange.isTokenRange();
94 std::pair<FileID, unsigned> BInfo =
SM.getDecomposedLoc(B);
95 std::pair<FileID, unsigned> EInfo =
SM.getDecomposedLoc(
E);
99 if (BInfo.first != CaretFileID || EInfo.first != CaretFileID)
104 unsigned TokSize = 0;
108 FullSourceLoc BF(B,
SM), EF(
E,
SM);
109 SourceLocation BeginLoc =
SM.translateLineCol(
110 BF.getFileID(), BF.getLineNumber(), BF.getColumnNumber());
111 SourceLocation EndLoc =
SM.translateLineCol(
112 EF.getFileID(), EF.getLineNumber(), EF.getColumnNumber() + TokSize);
115 CharSourceRange{SourceRange{BeginLoc, EndLoc},
false});
120 auto &
SM =
Loc.getManager();
123 unsigned int ColNo = (
LangOpts.MSCompatibilityVersion &&
127 SourceLocation DiagLoc =
SM.translateLineCol(FID, PLoc.
getLine(), ColNo);
131 CharSourceRange{SourceRange{DiagLoc, DiagLoc},
false});
133 return Result.setLocations(Locations);
137SARIFDiagnostic::addDiagnosticLevelToRule(SarifRule Rule,
158 assert(
false &&
"Invalid diagnostic type");
161 return Rule.setDefaultConfiguration(Config);
164llvm::StringRef SARIFDiagnostic::emitFilename(StringRef
Filename,
165 const SourceManager &
SM) {
184 SmallString<256> TmpFilename =
File->getName();
185 llvm::sys::fs::make_absolute(TmpFilename);
186 llvm::sys::path::native(TmpFilename);
187 llvm::sys::path::remove_dots(TmpFilename,
true);
188 Filename = StringRef(TmpFilename.data(), TmpFilename.size());
207 assert(
false &&
"Not implemented in SARIF mode");
211 assert(
false &&
"Not implemented in SARIF mode");
215 StringRef ModuleName) {
216 assert(
false &&
"Not implemented in SARIF mode");
221 StringRef ModuleName) {
222 assert(
false &&
"Not implemented in SARIF mode");
Defines the clang::FileManager interface and associated types.
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.
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
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) ...
Level
The level of the diagnostic, after it has been through mapping.
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...
bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const
static unsigned MeasureTokenLength(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts)
MeasureTokenLength - Relex the token at the specified location and return its length in bytes in the ...
Represents an unpacked "presumed" location which can be presented to the user.
unsigned getColumn() const
Return the presumed column number of this location.
unsigned getLine() const
Return the presumed line number of this location.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
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.
void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc, StringRef ModuleName) override
void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc, StringRef ModuleName) override
This class handles creating a valid SARIF document given various input attributes.
size_t createRule(const SarifRule &Rule)
Associate the given rule with the current run.
void appendResult(const SarifResult &SarifResult)
Append a new result to the currently in-flight run.
static SarifReportingConfiguration create()
A SARIF result (also called a "reporting item") is a unit of output produced when one of the tool's r...
SarifResult setDiagnosticMessage(llvm::StringRef Message)
static SarifResult create(uint32_t RuleIdx)
A SARIF rule (reportingDescriptor object) contains information that describes a reporting item genera...
SarifRule setRuleId(llvm::StringRef RuleId)
static SarifRule create()
const Regex Rule("(.+)/(.+)\\.framework/")
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
llvm::PointerUnion< const Diagnostic *, const StoredDiagnostic * > DiagOrStoredDiag
CustomizableOptional< FileEntryRef > OptionalFileEntryRef