Lines Matching +full:json +full:- +full:schema
1 //===-- clang/Basic/Sarif.cpp - SarifDocumentWriter class definition ------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 /// - \ref SarifArtifact
13 /// - \ref SarifArtifactLocation
14 /// - \ref SarifRule
15 /// - \ref SarifResult
16 //===----------------------------------------------------------------------===//
25 #include "llvm/Support/JSON.h"
60 if (llvm::isAlnum(C) || StringRef("-._~:@!$&'()*+,;=").contains(C))
85 assert(Iter != End && "Expected there to be a non-root path component.");
109 /// \brief Calculate the column position expressed in the number of UTF-8 code
115 /// \return The column number as a UTF-8 aware byte offset from column start to
125 assert(Buf->getBufferSize() >= (LocInfo.second + TokenLen) &&
130 unsigned int Off = LocInfo.second - (Loc.getExpansionColumnNumber() - 1);
133 Off += getNumBytesForUTF8(Buf->getBuffer()[Off]);
144 json::Object createMessage(StringRef Text) {
145 return json::Object{{"text", Text.str()}};
150 static json::Object createTextRegion(const SourceManager &SM,
154 json::Object Region{{"startLine", BeginCharLoc.getExpansionLineNumber()},
166 static json::Object createLocation(json::Object &&PhysicalLocation,
168 json::Object Ret{{"physicalLocation", std::move(PhysicalLocation)}};
197 llvm_unreachable("Potentially un-handled SarifResultLevel. "
201 static json::Object
202 createThreadFlowLocation(json::Object &&Location,
204 return json::Object{{"location", std::move(Location)},
209 json::Object
228 .setLength(FE->getSize())
237 const SarifArtifactLocation &Location = I->second.Location;
238 json::Object ArtifactLocationObject{{"uri", Location.URI}};
241 return json::Object{{{"artifactLocation", std::move(ArtifactLocationObject)},
245 json::Object &SarifDocumentWriter::getCurrentTool() {
253 return *Runs.back().getAsObject()->get("tool")->getAsObject();
273 json::Object &Tool = getCurrentTool();
274 json::Array Rules;
276 json::Object Config{
280 json::Object Rule{
283 {"fullDescription", json::Object{{"text", R.Description}}},
289 json::Object &Driver = *Tool.getObject("driver");
293 json::Object &Run = getCurrentRun();
294 json::Array *Artifacts = Run.getArray("artifacts");
300 json::Object Loc{{"uri", A.Location.URI}};
304 json::Object Artifact;
309 Artifact["roles"] = json::Array(A.Roles);
314 Artifacts->push_back(json::Value(std::move(Artifact)));
324 json::Array
326 json::Object Ret{{"locations", json::Array{}}};
327 json::Array Locs;
329 json::Object PLoc = createPhysicalLocation(ThreadFlow.Range);
330 json::Object Loc = createLocation(std::move(PLoc), ThreadFlow.Message);
335 return json::Array{std::move(Ret)};
338 json::Object
340 return json::Object{{"threadFlows", createThreadFlows(ThreadFlows)}};
352 json::Object Tool{
354 json::Object{{"name", ShortToolName},
356 {"language", "en-US"},
360 json::Object TheRun{{"tool", std::move(Tool)},
367 json::Object &SarifDocumentWriter::getCurrentRun() {
392 json::Object Ret{{"message", createMessage(Result.DiagnosticMessage)},
396 json::Array Locs;
403 Ret["codeFlows"] = json::Array{createCodeFlow(Result.ThreadFlows)};
408 json::Object &Run = getCurrentRun();
409 json::Array *Results = Run.getArray("results");
410 Results->emplace_back(std::move(Ret));
413 json::Object SarifDocumentWriter::createDocument() {
417 json::Object Doc{
418 {"$schema", SchemaURI},
422 Doc["runs"] = json::Array(Runs);