[clang] [clang][ssaf] Add `JSONFormat` support for `TUSummaryEncoding` (PR #183401)
Aviral Goel via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 27 09:13:09 PST 2026
================
@@ -0,0 +1,406 @@
+//===- TUSummaryEncoding.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/Analysis/Scalable/EntityLinker/EntitySummaryEncoding.h"
+#include "clang/Analysis/Scalable/EntityLinker/TUSummaryEncoding.h"
+
+namespace clang::ssaf {
+
+//----------------------------------------------------------------------------
+// JSONEntitySummaryEncoding
+//----------------------------------------------------------------------------
+
+namespace {
+
+class JSONEntitySummaryEncoding : public EntitySummaryEncoding {
+public:
+ explicit JSONEntitySummaryEncoding(Value Data) : Data(std::move(Data)) {}
+
+ void
+ patch(const std::map<EntityId, EntityId> &EntityResolutionTable) override {
+ llvm_unreachable("not implemented");
+ }
+
+ Value Data;
+};
+
+} // namespace
+
+//----------------------------------------------------------------------------
+// EncodingDataMapEntry
+//----------------------------------------------------------------------------
+
+llvm::Expected<std::pair<EntityId, std::unique_ptr<EntitySummaryEncoding>>>
+JSONFormat::encodingDataMapEntryFromJSON(
+ const Object &EntityDataMapEntryObject) const {
+
+ const Value *EntityIdIntValue = EntityDataMapEntryObject.get("entity_id");
+ if (!EntityIdIntValue) {
+ return ErrorBuilder::create(std::errc::invalid_argument,
+ ErrorMessages::FailedToReadObjectAtField,
+ "EntityId", "entity_id",
+ "number (unsigned 64-bit integer)")
+ .build();
+ }
+
+ const std::optional<uint64_t> OptEntityIdInt =
+ EntityIdIntValue->getAsUINT64();
+ if (!OptEntityIdInt) {
+ return ErrorBuilder::create(std::errc::invalid_argument,
+ ErrorMessages::FailedToReadObjectAtField,
+ "EntityId", "entity_id",
+ "number (unsigned 64-bit integer)")
+ .build();
+ }
+
+ EntityId EI = entityIdFromJSON(*OptEntityIdInt);
+
+ const Object *OptEntitySummaryObject =
+ EntityDataMapEntryObject.getObject("entity_summary");
+ if (!OptEntitySummaryObject) {
+ return ErrorBuilder::create(std::errc::invalid_argument,
+ ErrorMessages::FailedToReadObjectAtField,
+ "EntitySummary", "entity_summary", "object")
+ .build();
+ }
+
+ std::unique_ptr<EntitySummaryEncoding> Encoding =
+ std::make_unique<JSONEntitySummaryEncoding>(
+ Value(Object(*OptEntitySummaryObject)));
+
+ return std::make_pair(std::move(EI), std::move(Encoding));
+}
+
+Object JSONFormat::encodingDataMapEntryToJSON(
+ EntityId EI, const std::unique_ptr<EntitySummaryEncoding> &Encoding) const {
+ Object Entry;
+ Entry["entity_id"] = entityIdToJSON(EI);
+
+ // All EntitySummaryEncoding objects stored in a TUSummaryEncoding read by
+ // JSONFormat are JSONEntitySummaryEncoding instances, since
+ // encodingDataMapEntryFromJSON is the only place that creates them.
+ auto *JSONEncoding = static_cast<JSONEntitySummaryEncoding *>(Encoding.get());
----------------
aviralg wrote:
Indeed! Fixed.
https://github.com/llvm/llvm-project/pull/183401
More information about the cfe-commits
mailing list