================
@@ -439,10 +439,26 @@ json::Object SarifDocumentWriter::createDocument() {
endRun();
json::Object Doc{
- {"$schema", SchemaURI},
- {"version", SchemaVersion},
+ {"$schema", Version.SchemaURI},
+ {"version", Version.SchemaVersion},
};
if (!Runs.empty())
Doc["runs"] = json::Array(Runs);
return Doc;
}
+
+ArrayRef<SarifVersion> SarifDocumentWriter::getSupportedVersions() {
+ static const SarifVersion Versions[] = {
+ {"2.1.0", "2.1",
+ "https://docs.oasis-open.org/sarif/sarif/v2.1.0/cos02/schemas/"
+ "sarif-schema-2.1.0.json",
+ true}};
+
+ return Versions;
+}
+
+const SarifVersion &SarifDocumentWriter::getDefaultVersion() {
+ const auto Versions = getSupportedVersions();
+ return *std::find_if(Versions.begin(), Versions.end(),
+ [](const SarifVersion &V) { return V.IsDefault; });
+}
----------------
steakhal wrote:
For a moment I was thinking if we should enforce that only a single entry can
have IsDefault=true;
That could be achieved by using:
```c++
const SarifVersion &getDefaultVersion() {
return *llvm::find_singleton<SarifVersion>(
getSupportedVersions(), std::mem_fn(&SarifVersion::IsDefault));
}
```
https://github.com/llvm/llvm-project/pull/185201
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits