topos.functors.probes.cfg.complexity

CFG complexity probes.

McCabe cyclomatic complexity (E - N + 2P) and structural derivatives, computed directly on the ControlFlowGraph. The CFG builder guarantees a single connected component (P = 1) so the formula reduces to E - N + 2.

topos.functors.probes.cfg.complexity.cyclomatic_complexity(cfg)[source]

McCabe cyclomatic complexity = E - N + 2P.

With P = 1 (single connected component, guaranteed by the builder via the entry/exit synthetic blocks), this equals E - N + 2.

A function with no branches yields exactly 1.

topos.functors.probes.cfg.complexity.essential_complexity(cfg)[source]

Essential complexity (Cabe 1989): cyclomatic complexity after iteratively collapsing every D-structured primitive (single-entry single-exit decision/loop/switch substructure).

Implementation note: a full structured-decomposition pass is non-trivial. We approximate by counting decision blocks whose successors do not converge cleanly to a single join — i.e. blocks that issue a BREAK / CONTINUE / RETURN mid-substructure. These are the “unstructured” branches McCabe’s metric is built to surface.

topos.functors.probes.cfg.complexity.max_nesting_depth(cfg)[source]

Maximum static nesting depth via longest path from entry to any block, walking only TRUE / SWITCH_CASE forward edges. A flat function returns 0.