================ @@ -0,0 +1,89 @@ +//===---------- UnsafeBufferUsage.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 "clang/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsage.h" +#include "clang/ScalableStaticAnalysisFramework/SSAFForceLinker.h" // IWYU pragma: keep + +namespace { +constexpr const char *const UnsafeBuffersKey = "UnsafeBuffers"; +} // namespace + +namespace clang::ssaf { +using Object = llvm::json::Object; +using Array = llvm::json::Array; +using Value = llvm::json::Value; + +llvm::json::Object UnsafeBufferUsageEntitySummary::jsonSerializeFn( + const EntitySummary &ES, JSONFormat::EntityIdToJSONFn EntityId2JSON) { + // Writes a EntityPointerLevel as + // Array { + // Object { + // "@" : [entity-id] + // }, + // [pointer-level] + // } + Array UnsafeBuffersData; + + for (const auto &EPL : + static_cast<const UnsafeBufferUsageEntitySummary &>(ES).UnsafeBuffers) + UnsafeBuffersData.push_back( + Value(Array{// EntityId: + Value(EntityId2JSON(EPL.getEntity())), + // PointerLevel: + Value(EPL.getPointerLevel())})); + + Object Data; + + Data[UnsafeBuffersKey] = Value(std::move(UnsafeBuffersData)); + return Data; +} + +llvm::Expected<std::unique_ptr<EntitySummary>> +UnsafeBufferUsageEntitySummary::jsonDeserializeFn( + const llvm::json::Object &Data, EntityIdTable &, + JSONFormat::EntityIdFromJSONFn EntityIdFromJSON) { ---------------- ziqingluo-90 wrote:
In later PRs, I renamed these function to summaryFrom/ToJSON. EntityIdFromJSON is good fit along with those. https://github.com/llvm/llvm-project/pull/187156 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
