Skip to main content

Module analysis

Module analysis 

Source
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§

CallCycle
A cycle of function calls.
ComplexityRecord
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.