Expand description
Analysis algorithms for the Code Property Graph.
This module provides functions that operate on a CodePropertyGraph to
detect call cycles, dead code, and compute function complexity based on
AST subtree sizes.
§Cycle detection
detect_call_cycles builds a directed graph of function nodes
connected by Edge::Call edges and runs Kosaraju’s algorithm for
strongly connected components (SCC). Every SCC with more than one node
is reported as a cycle. Self‑loops (single‑node SCCs with a call to
themselves) are also reported.
§Dead code detection
detect_dead_code finds functions that are not reachable from a given
set of entry points (e.g., main) via call edges.
§Complexity analysis
detect_complex_functions traverses the AstChild subtree of each
function to count the number of AST nodes it contains. This is a
lightweight proxy for cyclomatic complexity. The traversal uses a
visited set and a per‑function node limit to prevent infinite loops on
structurally cyclic graphs (e.g., when a class contains methods that
reference the class itself).
Structs§
- Call
Cycle - A cycle of function calls.
- Complexity
Record - A record produced by
detect_complex_functions.
Functions§
- detect_
call_ cycles - Detects all call cycles involving one or more functions.
- detect_
complex_ functions - Computes the AST‑node count for every function (and method) in the graph.
- detect_
dead_ code - Finds functions that are not reachable from any of the specified entry functions via call edges.