Commit 698b509
authored
feat: CFG visitor rewrite (Phase 3.1 completion) (#392)
* feat: cfg visitor rewrite — unified walk, derived cyclomatic, removed standalone impl
Rewrite CFG construction as a visitor (createCfgVisitor) that plugs into the
walkWithVisitors framework, eliminating the last redundant tree traversal
(Mode B) in engine.js. All 4 analyses now run in a single DFS walk.
- Create src/ast-analysis/visitors/cfg-visitor.js (~570 lines) with full
control-flow support: if patterns A/B/C, for/while/do-while/infinite loops,
switch/match, try/catch/finally, break/continue with labels, nested functions
- Derive cyclomatic complexity from CFG (E - N + 2) as single source of truth,
overriding the independently-computed value from the complexity visitor
- Replace 813-line buildFunctionCFG with 15-line thin visitor wrapper
- Simplify buildCFGData WASM fallback: file-level visitor walk instead of
per-function findFunctionNode calls
- Remove Mode A/B split from engine.js; simplify WASM pre-parse (CFG no
longer triggers it)
- cfg.js reduced from 1242 to 518 lines (-724 lines)
- Add 31 new tests: 23 parity (visitor vs original) + 8 cyclomatic formula
Impact: 35 functions changed, 61 affected
* fix: allow nested function CFG and recompute MI on cyclomatic override
Remove skipChildren from cfg-visitor's enterNode so the walker recurses
into nested function definitions, enabling the funcStateStack to work as
designed. Recompute maintainabilityIndex in engine.js whenever the
CFG-derived cyclomatic overrides the complexity visitor's value, keeping
metrics consistent.
Addresses Greptile review feedback on PR #392.
Impact: 3 functions changed, 1 affected
* fix: match CFG results by node identity and disambiguate line collisions
- buildFunctionCFG: use .find() with node identity instead of cfgResults[0]
so nested functions don't shadow the target function's CFG
- engine.js: replace line-only Map keying with line → results[] grouping,
disambiguating by function name when multiple functions share a line
Addresses Greptile re-review feedback on PR #392.
Impact: 2 functions changed, 0 affected
* fix: disambiguate line collisions in buildCFGData WASM fallback
Apply the same array-plus-name-disambiguation pattern from engine.js to
the visitorCfgByLine map in buildCFGData, preventing silent overwrites
when multiple functions share a source line.
Addresses Greptile re-review feedback on PR #392.
Impact: 1 functions changed, 0 affected1 parent d33388a commit 698b509
5 files changed
Lines changed: 1334 additions & 808 deletions
File tree
- docs/roadmap
- src
- ast-analysis
- visitors
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
591 | 591 | | |
592 | 592 | | |
593 | 593 | | |
594 | | - | |
| 594 | + | |
595 | 595 | | |
596 | 596 | | |
597 | 597 | | |
598 | 598 | | |
599 | 599 | | |
600 | 600 | | |
601 | 601 | | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
602 | 606 | | |
603 | 607 | | |
604 | 608 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
| 10 | + | |
13 | 11 | | |
14 | 12 | | |
15 | | - | |
16 | | - | |
17 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
| |||
32 | 30 | | |
33 | 31 | | |
34 | 32 | | |
| 33 | + | |
35 | 34 | | |
36 | 35 | | |
37 | 36 | | |
| |||
74 | 73 | | |
75 | 74 | | |
76 | 75 | | |
77 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
| 84 | + | |
96 | 85 | | |
97 | 86 | | |
98 | 87 | | |
| |||
185 | 174 | | |
186 | 175 | | |
187 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
188 | 195 | | |
189 | 196 | | |
190 | 197 | | |
| |||
216 | 223 | | |
217 | 224 | | |
218 | 225 | | |
219 | | - | |
| 226 | + | |
| 227 | + | |
220 | 228 | | |
221 | 229 | | |
222 | 230 | | |
223 | 231 | | |
224 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
225 | 241 | | |
226 | 242 | | |
227 | 243 | | |
| |||
247 | 263 | | |
248 | 264 | | |
249 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
250 | 314 | | |
251 | 315 | | |
252 | 316 | | |
| |||
0 commit comments