[clang] [clang][ssaf] Add JSONFormat support for WPASuite (PR #187403)
Balázs Benics via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 31 09:55:49 PDT 2026
================
@@ -0,0 +1,209 @@
+//===- WPASuite.cpp -------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "JSONFormatImpl.h"
+
+#include "clang/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/WPASuite.h"
+
+namespace clang::ssaf {
+
+//----------------------------------------------------------------------------
+// AnalysisResultMapEntry
+//----------------------------------------------------------------------------
+
+llvm::Expected<std::pair<AnalysisName, std::unique_ptr<AnalysisResult>>>
+JSONFormat::analysisResultMapEntryFromJSON(const Object &Entry) const {
+ auto OptName = Entry.getString("analysis_name");
+ if (!OptName) {
+ return ErrorBuilder::create(std::errc::invalid_argument,
+ ErrorMessages::FailedToReadObjectAtField,
+ "AnalysisName", "analysis_name", "string")
+ .build();
+ }
+
+ AnalysisName Name = analysisNameFromJSON(*OptName);
+
+ auto ExpectedFns = AnalysisResultRegistry::lookup(Name);
+ if (!ExpectedFns) {
+ return ExpectedFns.takeError();
+ }
+
+ const Object *ResultObj = Entry.getObject("result");
+ if (!ResultObj) {
+ return ErrorBuilder::create(std::errc::invalid_argument,
+ ErrorMessages::FailedToReadObjectAtField,
+ "AnalysisResult", "result", "object")
+ .build();
+ }
+
+ auto ExpectedResult =
+ ExpectedFns->second(*ResultObj, &entityIdFromJSONObject);
----------------
steakhal wrote:
I was scratching my head and thinking about what is `second` here. When I looked it up, it made sense, but maybe using a structured binding decomposing the `*ExpectedFns` would have helped with a more appropriate name.
Similar note goes for calling `first` in the next fn.
https://github.com/llvm/llvm-project/pull/187403
More information about the cfe-commits
mailing list