-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall_graph_builder.py
More file actions
35 lines (30 loc) · 1.01 KB
/
Copy pathcall_graph_builder.py
File metadata and controls
35 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Build call graph-only views from AST summaries."""
from __future__ import annotations
from typing import Any
try:
from code_graph_demo.graph_builder import build_code_graph
except ImportError:
from graph_builder import build_code_graph
def build_call_graph(ast_items: list[dict[str, Any]]) -> dict[str, Any]:
"""Build a graph containing only local callables and CALLS edges."""
graph = build_code_graph(
ast_items,
source_root="",
features={"cfg": False, "dfg": False},
)
callable_ids = {
node["id"]
for node in graph["nodes"]
if node.get("type") in {"Function", "Method"}
}
return {
"metadata": graph["metadata"],
"nodes": [node for node in graph["nodes"] if node["id"] in callable_ids],
"edges": [
edge
for edge in graph["edges"]
if edge.get("type") == "CALLS"
and edge.get("source") in callable_ids
and edge.get("target") in callable_ids
],
}