13#include "llvm/ADT/STLExtras.h"
14#include "llvm/Support/JSON.h"
22 "failed to read {0} from field '{1}': expected JSON {2}";
24 "failed to read {0} from index '{1}': expected JSON {2}";
32 json::Array DirectCalleesArray;
33 DirectCalleesArray.reserve(S.DirectCallees.size());
34 append_range(DirectCalleesArray, map_range(S.DirectCallees, ToJSON));
36 json::Array VirtualCalleesArray;
37 VirtualCalleesArray.reserve(S.VirtualCallees.size());
38 append_range(VirtualCalleesArray, map_range(S.VirtualCallees, ToJSON));
41 {
"pretty_name", json::Value(S.PrettyName)},
42 {
"direct_callees", std::move(DirectCalleesArray)},
43 {
"virtual_callees", std::move(VirtualCalleesArray)},
46 {
"file", json::Value(S.Definition.File)},
47 {
"line", json::Value(S.Definition.Line)},
48 {
"col", json::Value(S.Definition.Column)},
56 auto Result = std::make_unique<CallGraphSummary>();
58 auto PrettyName = Obj.getString(
"pretty_name");
62 "pretty_name",
"string")
65 Result->PrettyName = PrettyName->str();
67 const json::Array *CalleesArray = Obj.getArray(
"direct_callees");
71 "direct_callees",
"array")
74 for (
const auto &[Index,
Value] : llvm::enumerate(*CalleesArray)) {
75 const json::Object *CalleeObj =
Value.getAsObject();
83 auto ExpectedId = FromJSON(*CalleeObj);
90 Result->DirectCallees.insert(*ExpectedId);
93 const json::Array *VirtualCalleesArray = Obj.getArray(
"virtual_callees");
94 if (!VirtualCalleesArray) {
97 "virtual_callees",
"array")
100 for (
const auto &[Index,
Value] : llvm::enumerate(*VirtualCalleesArray)) {
101 const json::Object *CalleeObj =
Value.getAsObject();
109 auto ExpectedId = FromJSON(*CalleeObj);
116 Result->VirtualCallees.insert(*ExpectedId);
119 const json::Object *DefObj = Obj.getObject(
"def");
126 auto File = DefObj->getString(
"file");
134 auto Line = DefObj->getInteger(
"line");
142 auto Col = DefObj->getInteger(
"col");
150 Result->Definition = {
152 static_cast<unsigned>(*Line),
153 static_cast<unsigned>(*Col),
156 return std::move(Result);
161 CallGraphJSONFormatInfo()
162 : JSONFormat::FormatInfo(SummaryName(CallGraphSummary::Name.str()),
167static llvm::Registry<JSONFormat::FormatInfo>::Add<CallGraphJSONFormatInfo>
169 "JSON Format info for CallGraph summary");
volatile int CallGraphJSONFormatAnchorSource
Manages entity name interning and provides efficient EntityId handles.
Base class for analysis-specific summary data.
static ErrorBuilder create(std::error_code EC, const char *Fmt, Args &&...ArgVals)
Create an ErrorBuilder with an error code and formatted message.
ErrorBuilder & context(const char *Msg)
Add context information as a plain string.
llvm::Error build() const
Build and return the final error.
static ErrorBuilder wrap(llvm::Error E)
Wrap an existing error and optionally add context.
The JSON file list parser is used to communicate input to InstallAPI.
Diagnostic wrappers for TextAPI types for error reporting.
Summary of direct call-graph edges for a single function entity.
static constexpr llvm::StringLiteral Name