@optave/codegraph 3.4.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -22
- package/dist/ast-analysis/engine.d.ts.map +1 -1
- package/dist/ast-analysis/engine.js +3 -9
- package/dist/ast-analysis/engine.js.map +1 -1
- package/dist/ast-analysis/rules/javascript.d.ts.map +1 -1
- package/dist/ast-analysis/rules/javascript.js +1 -0
- package/dist/ast-analysis/rules/javascript.js.map +1 -1
- package/dist/ast-analysis/shared.d.ts.map +1 -1
- package/dist/ast-analysis/shared.js +0 -1
- package/dist/ast-analysis/shared.js.map +1 -1
- package/dist/ast-analysis/visitors/ast-store-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/ast-store-visitor.js +103 -35
- package/dist/ast-analysis/visitors/ast-store-visitor.js.map +1 -1
- package/dist/ast-analysis/visitors/cfg-conditionals.d.ts +5 -0
- package/dist/ast-analysis/visitors/cfg-conditionals.d.ts.map +1 -0
- package/dist/ast-analysis/visitors/cfg-conditionals.js +166 -0
- package/dist/ast-analysis/visitors/cfg-conditionals.js.map +1 -0
- package/dist/ast-analysis/visitors/cfg-loops.d.ts +7 -0
- package/dist/ast-analysis/visitors/cfg-loops.d.ts.map +1 -0
- package/dist/ast-analysis/visitors/cfg-loops.js +73 -0
- package/dist/ast-analysis/visitors/cfg-loops.js.map +1 -0
- package/dist/ast-analysis/visitors/cfg-shared.d.ts +56 -0
- package/dist/ast-analysis/visitors/cfg-shared.d.ts.map +1 -0
- package/dist/ast-analysis/visitors/cfg-shared.js +107 -0
- package/dist/ast-analysis/visitors/cfg-shared.js.map +1 -0
- package/dist/ast-analysis/visitors/cfg-try-catch.d.ts +4 -0
- package/dist/ast-analysis/visitors/cfg-try-catch.d.ts.map +1 -0
- package/dist/ast-analysis/visitors/cfg-try-catch.js +100 -0
- package/dist/ast-analysis/visitors/cfg-try-catch.js.map +1 -0
- package/dist/ast-analysis/visitors/cfg-visitor.d.ts +2 -2
- package/dist/ast-analysis/visitors/cfg-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/cfg-visitor.js +11 -445
- package/dist/ast-analysis/visitors/cfg-visitor.js.map +1 -1
- package/dist/ast-analysis/visitors/complexity-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/complexity-visitor.js.map +1 -1
- package/dist/ast-analysis/visitors/dataflow-visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitors/dataflow-visitor.js.map +1 -1
- package/dist/cli/commands/batch.d.ts.map +1 -1
- package/dist/cli/commands/batch.js +4 -3
- package/dist/cli/commands/batch.js.map +1 -1
- package/dist/cli/commands/branch-compare.js +1 -1
- package/dist/cli/commands/branch-compare.js.map +1 -1
- package/dist/cli/commands/build.js +1 -1
- package/dist/cli/commands/build.js.map +1 -1
- package/dist/cli/commands/info.d.ts.map +1 -1
- package/dist/cli/commands/info.js +1 -2
- package/dist/cli/commands/info.js.map +1 -1
- package/dist/cli/commands/path.d.ts.map +1 -1
- package/dist/cli/commands/path.js +7 -2
- package/dist/cli/commands/path.js.map +1 -1
- package/dist/cli/commands/plot.d.ts.map +1 -1
- package/dist/cli/commands/plot.js +2 -2
- package/dist/cli/commands/plot.js.map +1 -1
- package/dist/cli/commands/watch.js +1 -1
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/cli/index.js +2 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/shared/open-graph.d.ts +2 -2
- package/dist/cli/shared/open-graph.d.ts.map +1 -1
- package/dist/cli/shared/open-graph.js.map +1 -1
- package/dist/cli/types.d.ts +1 -1
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/cli.js +2 -3
- package/dist/cli.js.map +1 -1
- package/dist/db/better-sqlite3.d.ts +3 -0
- package/dist/db/better-sqlite3.d.ts.map +1 -0
- package/dist/db/better-sqlite3.js +19 -0
- package/dist/db/better-sqlite3.js.map +1 -0
- package/dist/db/connection.d.ts +30 -2
- package/dist/db/connection.d.ts.map +1 -1
- package/dist/db/connection.js +167 -4
- package/dist/db/connection.js.map +1 -1
- package/dist/db/index.d.ts +2 -2
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +1 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/migrations.d.ts.map +1 -1
- package/dist/db/migrations.js +9 -0
- package/dist/db/migrations.js.map +1 -1
- package/dist/db/query-builder.d.ts +5 -5
- package/dist/db/query-builder.d.ts.map +1 -1
- package/dist/db/query-builder.js +20 -4
- package/dist/db/query-builder.js.map +1 -1
- package/dist/db/repository/index.d.ts +1 -0
- package/dist/db/repository/index.d.ts.map +1 -1
- package/dist/db/repository/index.js +1 -0
- package/dist/db/repository/index.js.map +1 -1
- package/dist/db/repository/native-repository.d.ts +58 -0
- package/dist/db/repository/native-repository.d.ts.map +1 -0
- package/dist/db/repository/native-repository.js +261 -0
- package/dist/db/repository/native-repository.js.map +1 -0
- package/dist/db/repository/nodes.d.ts +4 -4
- package/dist/db/repository/nodes.d.ts.map +1 -1
- package/dist/db/repository/nodes.js +6 -6
- package/dist/db/repository/nodes.js.map +1 -1
- package/dist/domain/analysis/brief.d.ts.map +1 -1
- package/dist/domain/analysis/brief.js +1 -3
- package/dist/domain/analysis/brief.js.map +1 -1
- package/dist/domain/analysis/context.d.ts.map +1 -1
- package/dist/domain/analysis/context.js +2 -4
- package/dist/domain/analysis/context.js.map +1 -1
- package/dist/domain/analysis/dependencies.d.ts +49 -0
- package/dist/domain/analysis/dependencies.d.ts.map +1 -1
- package/dist/domain/analysis/dependencies.js +145 -0
- package/dist/domain/analysis/dependencies.js.map +1 -1
- package/dist/domain/analysis/diff-impact.d.ts +76 -0
- package/dist/domain/analysis/diff-impact.d.ts.map +1 -0
- package/dist/domain/analysis/diff-impact.js +282 -0
- package/dist/domain/analysis/diff-impact.js.map +1 -0
- package/dist/domain/analysis/exports.d.ts.map +1 -1
- package/dist/domain/analysis/exports.js +0 -1
- package/dist/domain/analysis/exports.js.map +1 -1
- package/dist/domain/analysis/fn-impact.d.ts +66 -0
- package/dist/domain/analysis/fn-impact.d.ts.map +1 -0
- package/dist/domain/analysis/fn-impact.js +189 -0
- package/dist/domain/analysis/fn-impact.js.map +1 -0
- package/dist/domain/analysis/impact.d.ts +8 -148
- package/dist/domain/analysis/impact.d.ts.map +1 -1
- package/dist/domain/analysis/impact.js +8 -568
- package/dist/domain/analysis/impact.js.map +1 -1
- package/dist/domain/analysis/module-map.d.ts.map +1 -1
- package/dist/domain/analysis/module-map.js +1 -3
- package/dist/domain/analysis/module-map.js.map +1 -1
- package/dist/domain/graph/builder/context.d.ts +3 -3
- package/dist/domain/graph/builder/context.d.ts.map +1 -1
- package/dist/domain/graph/builder/context.js +1 -0
- package/dist/domain/graph/builder/context.js.map +1 -1
- package/dist/domain/graph/builder/helpers.d.ts +4 -5
- package/dist/domain/graph/builder/helpers.d.ts.map +1 -1
- package/dist/domain/graph/builder/helpers.js +1 -2
- package/dist/domain/graph/builder/helpers.js.map +1 -1
- package/dist/domain/graph/builder/incremental.d.ts +2 -3
- package/dist/domain/graph/builder/incremental.d.ts.map +1 -1
- package/dist/domain/graph/builder/incremental.js.map +1 -1
- package/dist/domain/graph/builder/pipeline.d.ts.map +1 -1
- package/dist/domain/graph/builder/pipeline.js +34 -6
- package/dist/domain/graph/builder/pipeline.js.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.js +113 -15
- package/dist/domain/graph/builder/stages/build-edges.js.map +1 -1
- package/dist/domain/graph/builder/stages/build-structure.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/build-structure.js +186 -62
- package/dist/domain/graph/builder/stages/build-structure.js.map +1 -1
- package/dist/domain/graph/builder/stages/collect-files.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/collect-files.js +71 -7
- package/dist/domain/graph/builder/stages/collect-files.js.map +1 -1
- package/dist/domain/graph/builder/stages/detect-changes.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/detect-changes.js +42 -20
- package/dist/domain/graph/builder/stages/detect-changes.js.map +1 -1
- package/dist/domain/graph/builder/stages/finalize.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/finalize.js +111 -64
- package/dist/domain/graph/builder/stages/finalize.js.map +1 -1
- package/dist/domain/graph/builder/stages/insert-nodes.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/insert-nodes.js +104 -9
- package/dist/domain/graph/builder/stages/insert-nodes.js.map +1 -1
- package/dist/domain/graph/builder/stages/resolve-imports.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/resolve-imports.js +58 -11
- package/dist/domain/graph/builder/stages/resolve-imports.js.map +1 -1
- package/dist/domain/graph/cycles.js +2 -2
- package/dist/domain/graph/cycles.js.map +1 -1
- package/dist/domain/graph/resolve.d.ts.map +1 -1
- package/dist/domain/graph/resolve.js +10 -8
- package/dist/domain/graph/resolve.js.map +1 -1
- package/dist/domain/graph/watcher.d.ts.map +1 -1
- package/dist/domain/graph/watcher.js +1 -3
- package/dist/domain/graph/watcher.js.map +1 -1
- package/dist/domain/parser.d.ts.map +1 -1
- package/dist/domain/parser.js +12 -12
- package/dist/domain/parser.js.map +1 -1
- package/dist/domain/queries.d.ts +3 -2
- package/dist/domain/queries.d.ts.map +1 -1
- package/dist/domain/queries.js +3 -2
- package/dist/domain/queries.js.map +1 -1
- package/dist/domain/search/generator.d.ts.map +1 -1
- package/dist/domain/search/generator.js.map +1 -1
- package/dist/extractors/csharp.js +2 -2
- package/dist/extractors/csharp.js.map +1 -1
- package/dist/extractors/go.js +2 -2
- package/dist/extractors/go.js.map +1 -1
- package/dist/extractors/helpers.d.ts +5 -0
- package/dist/extractors/helpers.d.ts.map +1 -1
- package/dist/extractors/helpers.js +5 -0
- package/dist/extractors/helpers.js.map +1 -1
- package/dist/extractors/javascript.js +111 -98
- package/dist/extractors/javascript.js.map +1 -1
- package/dist/extractors/php.js +2 -2
- package/dist/extractors/php.js.map +1 -1
- package/dist/extractors/python.js +2 -2
- package/dist/extractors/python.js.map +1 -1
- package/dist/extractors/rust.js +4 -3
- package/dist/extractors/rust.js.map +1 -1
- package/dist/features/ast.d.ts +14 -1
- package/dist/features/ast.d.ts.map +1 -1
- package/dist/features/ast.js +38 -1
- package/dist/features/ast.js.map +1 -1
- package/dist/features/audit.d.ts.map +1 -1
- package/dist/features/audit.js +1 -2
- package/dist/features/audit.js.map +1 -1
- package/dist/features/branch-compare.d.ts.map +1 -1
- package/dist/features/branch-compare.js +5 -4
- package/dist/features/branch-compare.js.map +1 -1
- package/dist/features/cfg.d.ts.map +1 -1
- package/dist/features/cfg.js +2 -4
- package/dist/features/cfg.js.map +1 -1
- package/dist/features/cochange.js +4 -4
- package/dist/features/cochange.js.map +1 -1
- package/dist/features/communities.js +4 -4
- package/dist/features/communities.js.map +1 -1
- package/dist/features/complexity-query.d.ts +37 -0
- package/dist/features/complexity-query.d.ts.map +1 -0
- package/dist/features/complexity-query.js +263 -0
- package/dist/features/complexity-query.js.map +1 -0
- package/dist/features/complexity.d.ts +2 -30
- package/dist/features/complexity.d.ts.map +1 -1
- package/dist/features/complexity.js +7 -261
- package/dist/features/complexity.js.map +1 -1
- package/dist/features/dataflow.d.ts.map +1 -1
- package/dist/features/dataflow.js +8 -24
- package/dist/features/dataflow.js.map +1 -1
- package/dist/features/export.d.ts +7 -8
- package/dist/features/export.d.ts.map +1 -1
- package/dist/features/export.js.map +1 -1
- package/dist/features/flow.d.ts.map +1 -1
- package/dist/features/flow.js.map +1 -1
- package/dist/features/graph-enrichment.d.ts.map +1 -1
- package/dist/features/graph-enrichment.js +1 -3
- package/dist/features/graph-enrichment.js.map +1 -1
- package/dist/features/manifesto.js +8 -8
- package/dist/features/manifesto.js.map +1 -1
- package/dist/features/snapshot.js +2 -2
- package/dist/features/snapshot.js.map +1 -1
- package/dist/features/structure-query.d.ts +76 -0
- package/dist/features/structure-query.d.ts.map +1 -0
- package/dist/features/structure-query.js +245 -0
- package/dist/features/structure-query.js.map +1 -0
- package/dist/features/structure.d.ts +12 -67
- package/dist/features/structure.d.ts.map +1 -1
- package/dist/features/structure.js +188 -244
- package/dist/features/structure.js.map +1 -1
- package/dist/features/triage.js +2 -2
- package/dist/features/triage.js.map +1 -1
- package/dist/graph/algorithms/leiden/adapter.d.ts.map +1 -1
- package/dist/graph/algorithms/leiden/adapter.js +2 -9
- package/dist/graph/algorithms/leiden/adapter.js.map +1 -1
- package/dist/graph/classifiers/roles.d.ts +5 -1
- package/dist/graph/classifiers/roles.d.ts.map +1 -1
- package/dist/graph/classifiers/roles.js +20 -12
- package/dist/graph/classifiers/roles.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/config.d.ts.map +1 -1
- package/dist/infrastructure/config.js +12 -11
- package/dist/infrastructure/config.js.map +1 -1
- package/dist/infrastructure/native.d.ts.map +1 -1
- package/dist/infrastructure/native.js +7 -3
- package/dist/infrastructure/native.js.map +1 -1
- package/dist/infrastructure/registry.d.ts.map +1 -1
- package/dist/infrastructure/registry.js +1 -1
- package/dist/infrastructure/registry.js.map +1 -1
- package/dist/infrastructure/update-check.js +3 -3
- package/dist/infrastructure/update-check.js.map +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +4 -17
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tool-registry.d.ts.map +1 -1
- package/dist/mcp/tool-registry.js +9 -4
- package/dist/mcp/tool-registry.js.map +1 -1
- package/dist/mcp/tools/audit.js +1 -1
- package/dist/mcp/tools/audit.js.map +1 -1
- package/dist/mcp/tools/cfg.js +1 -1
- package/dist/mcp/tools/cfg.js.map +1 -1
- package/dist/mcp/tools/check.js +2 -2
- package/dist/mcp/tools/check.js.map +1 -1
- package/dist/mcp/tools/dataflow.js +2 -2
- package/dist/mcp/tools/dataflow.js.map +1 -1
- package/dist/mcp/tools/export-graph.js +1 -1
- package/dist/mcp/tools/export-graph.js.map +1 -1
- package/dist/mcp/tools/index.d.ts.map +1 -1
- package/dist/mcp/tools/index.js.map +1 -1
- package/dist/mcp/tools/path.d.ts +1 -0
- package/dist/mcp/tools/path.d.ts.map +1 -1
- package/dist/mcp/tools/path.js +9 -0
- package/dist/mcp/tools/path.js.map +1 -1
- package/dist/mcp/tools/query.js +1 -1
- package/dist/mcp/tools/query.js.map +1 -1
- package/dist/mcp/tools/semantic-search.js +1 -1
- package/dist/mcp/tools/semantic-search.js.map +1 -1
- package/dist/mcp/tools/sequence.js +1 -1
- package/dist/mcp/tools/sequence.js.map +1 -1
- package/dist/mcp/tools/symbol-children.js +1 -1
- package/dist/mcp/tools/symbol-children.js.map +1 -1
- package/dist/mcp/tools/triage.js +1 -1
- package/dist/mcp/tools/triage.js.map +1 -1
- package/dist/presentation/audit.d.ts.map +1 -1
- package/dist/presentation/audit.js +0 -1
- package/dist/presentation/audit.js.map +1 -1
- package/dist/presentation/diff-impact-mermaid.d.ts +11 -0
- package/dist/presentation/diff-impact-mermaid.d.ts.map +1 -0
- package/dist/presentation/diff-impact-mermaid.js +105 -0
- package/dist/presentation/diff-impact-mermaid.js.map +1 -0
- package/dist/presentation/flow.d.ts.map +1 -1
- package/dist/presentation/flow.js +0 -2
- package/dist/presentation/flow.js.map +1 -1
- package/dist/presentation/manifesto.d.ts.map +1 -1
- package/dist/presentation/manifesto.js +0 -1
- package/dist/presentation/manifesto.js.map +1 -1
- package/dist/presentation/queries-cli/inspect.d.ts.map +1 -1
- package/dist/presentation/queries-cli/inspect.js.map +1 -1
- package/dist/presentation/queries-cli/path.d.ts.map +1 -1
- package/dist/presentation/queries-cli/path.js +45 -1
- package/dist/presentation/queries-cli/path.js.map +1 -1
- package/dist/presentation/result-formatter.d.ts.map +1 -1
- package/dist/presentation/result-formatter.js +1 -3
- package/dist/presentation/result-formatter.js.map +1 -1
- package/dist/presentation/sequence.d.ts.map +1 -1
- package/dist/presentation/sequence.js +0 -1
- package/dist/presentation/sequence.js.map +1 -1
- package/dist/presentation/structure.d.ts.map +1 -1
- package/dist/presentation/structure.js.map +1 -1
- package/dist/presentation/triage.d.ts.map +1 -1
- package/dist/presentation/triage.js +0 -1
- package/dist/presentation/triage.js.map +1 -1
- package/dist/shared/constants.d.ts +9 -3
- package/dist/shared/constants.d.ts.map +1 -1
- package/dist/shared/constants.js +6 -3
- package/dist/shared/constants.js.map +1 -1
- package/dist/shared/errors.d.ts +2 -0
- package/dist/shared/errors.d.ts.map +1 -1
- package/dist/shared/errors.js +4 -0
- package/dist/shared/errors.js.map +1 -1
- package/dist/shared/version.d.ts +2 -0
- package/dist/shared/version.d.ts.map +1 -0
- package/dist/shared/version.js +5 -0
- package/dist/shared/version.js.map +1 -0
- package/dist/types.d.ts +230 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +62 -11
- package/src/ast-analysis/engine.ts +3 -9
- package/src/ast-analysis/rules/javascript.ts +1 -0
- package/src/ast-analysis/shared.ts +0 -1
- package/src/ast-analysis/visitors/ast-store-visitor.ts +102 -33
- package/src/ast-analysis/visitors/cfg-conditionals.ts +227 -0
- package/src/ast-analysis/visitors/cfg-loops.ts +136 -0
- package/src/ast-analysis/visitors/cfg-shared.ts +196 -0
- package/src/ast-analysis/visitors/cfg-try-catch.ts +142 -0
- package/src/ast-analysis/visitors/cfg-visitor.ts +34 -655
- package/src/ast-analysis/visitors/complexity-visitor.ts +0 -1
- package/src/ast-analysis/visitors/dataflow-visitor.ts +0 -1
- package/src/cli/commands/batch.ts +4 -3
- package/src/cli/commands/branch-compare.ts +1 -1
- package/src/cli/commands/build.ts +1 -1
- package/src/cli/commands/info.ts +1 -2
- package/src/cli/commands/path.ts +7 -2
- package/src/cli/commands/plot.ts +2 -2
- package/src/cli/commands/watch.ts +1 -1
- package/src/cli/index.ts +2 -2
- package/src/cli/shared/open-graph.ts +2 -2
- package/src/cli/types.ts +1 -1
- package/src/cli.ts +2 -3
- package/src/db/better-sqlite3.ts +20 -0
- package/src/db/connection.ts +191 -16
- package/src/db/index.ts +5 -1
- package/src/db/migrations.ts +9 -0
- package/src/db/query-builder.ts +30 -5
- package/src/db/repository/index.ts +1 -0
- package/src/db/repository/native-repository.ts +361 -0
- package/src/db/repository/nodes.ts +7 -3
- package/src/domain/analysis/brief.ts +0 -1
- package/src/domain/analysis/context.ts +2 -6
- package/src/domain/analysis/dependencies.ts +165 -0
- package/src/domain/analysis/diff-impact.ts +354 -0
- package/src/domain/analysis/exports.ts +0 -2
- package/src/domain/analysis/fn-impact.ts +241 -0
- package/src/domain/analysis/impact.ts +8 -718
- package/src/domain/analysis/module-map.ts +1 -5
- package/src/domain/graph/builder/context.ts +4 -2
- package/src/domain/graph/builder/helpers.ts +14 -11
- package/src/domain/graph/builder/incremental.ts +33 -28
- package/src/domain/graph/builder/pipeline.ts +37 -5
- package/src/domain/graph/builder/stages/build-edges.ts +131 -20
- package/src/domain/graph/builder/stages/build-structure.ts +245 -80
- package/src/domain/graph/builder/stages/collect-files.ts +84 -7
- package/src/domain/graph/builder/stages/detect-changes.ts +49 -32
- package/src/domain/graph/builder/stages/finalize.ts +132 -84
- package/src/domain/graph/builder/stages/insert-nodes.ts +141 -18
- package/src/domain/graph/builder/stages/resolve-imports.ts +75 -10
- package/src/domain/graph/cycles.ts +2 -2
- package/src/domain/graph/resolve.ts +14 -8
- package/src/domain/graph/watcher.ts +2 -4
- package/src/domain/parser.ts +12 -13
- package/src/domain/queries.ts +2 -2
- package/src/domain/search/generator.ts +3 -4
- package/src/extractors/csharp.ts +2 -2
- package/src/extractors/go.ts +2 -2
- package/src/extractors/helpers.ts +6 -0
- package/src/extractors/javascript.ts +112 -97
- package/src/extractors/php.ts +2 -2
- package/src/extractors/python.ts +2 -2
- package/src/extractors/rust.ts +4 -3
- package/src/features/ast.ts +66 -1
- package/src/features/audit.ts +1 -2
- package/src/features/branch-compare.ts +6 -10
- package/src/features/cfg.ts +2 -4
- package/src/features/cochange.ts +4 -4
- package/src/features/communities.ts +4 -4
- package/src/features/complexity-query.ts +370 -0
- package/src/features/complexity.ts +6 -365
- package/src/features/dataflow.ts +48 -70
- package/src/features/export.ts +12 -16
- package/src/features/flow.ts +0 -1
- package/src/features/graph-enrichment.ts +1 -3
- package/src/features/manifesto.ts +8 -8
- package/src/features/snapshot.ts +3 -3
- package/src/features/structure-query.ts +387 -0
- package/src/features/structure.ts +231 -376
- package/src/features/triage.ts +2 -2
- package/src/graph/algorithms/leiden/adapter.ts +2 -9
- package/src/graph/classifiers/roles.ts +22 -13
- package/src/index.ts +1 -0
- package/src/infrastructure/config.ts +12 -13
- package/src/infrastructure/native.ts +7 -3
- package/src/infrastructure/registry.ts +1 -1
- package/src/infrastructure/update-check.ts +3 -3
- package/src/mcp/server.ts +4 -20
- package/src/mcp/tool-registry.ts +11 -4
- package/src/mcp/tools/audit.ts +1 -1
- package/src/mcp/tools/cfg.ts +1 -1
- package/src/mcp/tools/check.ts +2 -2
- package/src/mcp/tools/dataflow.ts +2 -2
- package/src/mcp/tools/export-graph.ts +1 -1
- package/src/mcp/tools/index.ts +0 -1
- package/src/mcp/tools/path.ts +10 -0
- package/src/mcp/tools/query.ts +1 -1
- package/src/mcp/tools/semantic-search.ts +1 -1
- package/src/mcp/tools/sequence.ts +1 -1
- package/src/mcp/tools/symbol-children.ts +1 -1
- package/src/mcp/tools/triage.ts +1 -1
- package/src/presentation/audit.ts +0 -1
- package/src/presentation/diff-impact-mermaid.ts +127 -0
- package/src/presentation/flow.ts +0 -2
- package/src/presentation/manifesto.ts +0 -1
- package/src/presentation/queries-cli/inspect.ts +0 -1
- package/src/presentation/queries-cli/path.ts +71 -1
- package/src/presentation/result-formatter.ts +0 -1
- package/src/presentation/sequence.ts +0 -1
- package/src/presentation/structure.ts +0 -12
- package/src/presentation/triage.ts +0 -1
- package/src/shared/constants.ts +33 -19
- package/src/shared/errors.ts +5 -0
- package/src/shared/version.ts +10 -0
- package/src/types.ts +277 -10
- package/src/vendor.d.ts +0 -39
|
@@ -237,6 +237,7 @@ export const dataflow: DataflowRulesConfig = makeDataflowRules({
|
|
|
237
237
|
// ─── AST Node Types ───────────────────────────────────────────────────────
|
|
238
238
|
|
|
239
239
|
export const astTypes: Record<string, string> | null = {
|
|
240
|
+
call_expression: 'call',
|
|
240
241
|
new_expression: 'new',
|
|
241
242
|
throw_statement: 'throw',
|
|
242
243
|
await_expression: 'await',
|
|
@@ -44,6 +44,14 @@ function extractExpressionText(node: TreeSitterNode): string | null {
|
|
|
44
44
|
return truncate(node.text);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
function extractCallName(node: TreeSitterNode): string {
|
|
48
|
+
for (const field of ['function', 'method', 'name']) {
|
|
49
|
+
const fn = node.childForFieldName(field);
|
|
50
|
+
if (fn) return fn.text;
|
|
51
|
+
}
|
|
52
|
+
return node.text?.split('(')[0] || '?';
|
|
53
|
+
}
|
|
54
|
+
|
|
47
55
|
function extractName(kind: string, node: TreeSitterNode): string | null {
|
|
48
56
|
if (kind === 'throw') {
|
|
49
57
|
for (let i = 0; i < node.childCount; i++) {
|
|
@@ -102,6 +110,93 @@ export function createAstStoreVisitor(
|
|
|
102
110
|
return nodeIdMap.get(`${parentDef.name}|${parentDef.kind}|${parentDef.line}`) || null;
|
|
103
111
|
}
|
|
104
112
|
|
|
113
|
+
/** Recursively walk a subtree collecting AST nodes — used for arguments-only traversal. */
|
|
114
|
+
function walkSubtree(node: TreeSitterNode | null): void {
|
|
115
|
+
if (!node) return;
|
|
116
|
+
if (matched.has(node.id)) return;
|
|
117
|
+
|
|
118
|
+
const kind = astTypeMap[node.type];
|
|
119
|
+
if (kind === 'call') {
|
|
120
|
+
// Capture this call and recurse only into its arguments
|
|
121
|
+
collectNode(node, kind);
|
|
122
|
+
walkCallArguments(node);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (kind) {
|
|
126
|
+
collectNode(node, kind);
|
|
127
|
+
if (kind !== 'string' && kind !== 'regex') return; // skipChildren for non-leaf kinds
|
|
128
|
+
}
|
|
129
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
130
|
+
walkSubtree(node.child(i));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Recurse into only the arguments of a call node — mirrors the native engine's
|
|
136
|
+
* strategy that prevents double-counting nested calls in the function field
|
|
137
|
+
* (e.g. chained calls like `a().b()`).
|
|
138
|
+
*/
|
|
139
|
+
function walkCallArguments(callNode: TreeSitterNode): void {
|
|
140
|
+
// Try field-based lookup first, fall back to kind-based matching
|
|
141
|
+
const argsNode =
|
|
142
|
+
callNode.childForFieldName('arguments') ??
|
|
143
|
+
findChildByKind(callNode, ['arguments', 'argument_list', 'method_arguments']);
|
|
144
|
+
if (!argsNode) return;
|
|
145
|
+
for (let i = 0; i < argsNode.childCount; i++) {
|
|
146
|
+
walkSubtree(argsNode.child(i));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function findChildByKind(node: TreeSitterNode, kinds: string[]): TreeSitterNode | null {
|
|
151
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
152
|
+
const child = node.child(i);
|
|
153
|
+
if (child && kinds.includes(child.type)) return child;
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function collectNode(node: TreeSitterNode, kind: string): void {
|
|
159
|
+
if (matched.has(node.id)) return;
|
|
160
|
+
|
|
161
|
+
const line = node.startPosition.row + 1;
|
|
162
|
+
let name: string | null | undefined;
|
|
163
|
+
let text: string | null = null;
|
|
164
|
+
|
|
165
|
+
if (kind === 'call') {
|
|
166
|
+
name = extractCallName(node);
|
|
167
|
+
text = truncate(node.text);
|
|
168
|
+
} else if (kind === 'new') {
|
|
169
|
+
name = extractNewName(node);
|
|
170
|
+
text = truncate(node.text);
|
|
171
|
+
} else if (kind === 'throw') {
|
|
172
|
+
name = extractName('throw', node);
|
|
173
|
+
text = extractExpressionText(node);
|
|
174
|
+
} else if (kind === 'await') {
|
|
175
|
+
name = extractName('await', node);
|
|
176
|
+
text = extractExpressionText(node);
|
|
177
|
+
} else if (kind === 'string') {
|
|
178
|
+
const content = node.text?.replace(/^['"`]|['"`]$/g, '') || '';
|
|
179
|
+
if (content.length < 2) return;
|
|
180
|
+
name = truncate(content, 100);
|
|
181
|
+
text = truncate(node.text);
|
|
182
|
+
} else if (kind === 'regex') {
|
|
183
|
+
name = node.text || '?';
|
|
184
|
+
text = truncate(node.text);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
rows.push({
|
|
188
|
+
file: relPath,
|
|
189
|
+
line,
|
|
190
|
+
kind,
|
|
191
|
+
name,
|
|
192
|
+
text,
|
|
193
|
+
receiver: null,
|
|
194
|
+
parentNodeId: resolveParentNodeId(line),
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
matched.add(node.id);
|
|
198
|
+
}
|
|
199
|
+
|
|
105
200
|
return {
|
|
106
201
|
name: 'ast-store',
|
|
107
202
|
|
|
@@ -111,40 +206,14 @@ export function createAstStoreVisitor(
|
|
|
111
206
|
const kind = astTypeMap[node.type];
|
|
112
207
|
if (!kind) return;
|
|
113
208
|
|
|
114
|
-
|
|
115
|
-
let name: string | null | undefined;
|
|
116
|
-
let text: string | null = null;
|
|
117
|
-
|
|
118
|
-
if (kind === 'new') {
|
|
119
|
-
name = extractNewName(node);
|
|
120
|
-
text = truncate(node.text);
|
|
121
|
-
} else if (kind === 'throw') {
|
|
122
|
-
name = extractName('throw', node);
|
|
123
|
-
text = extractExpressionText(node);
|
|
124
|
-
} else if (kind === 'await') {
|
|
125
|
-
name = extractName('await', node);
|
|
126
|
-
text = extractExpressionText(node);
|
|
127
|
-
} else if (kind === 'string') {
|
|
128
|
-
const content = node.text?.replace(/^['"`]|['"`]$/g, '') || '';
|
|
129
|
-
if (content.length < 2) return;
|
|
130
|
-
name = truncate(content, 100);
|
|
131
|
-
text = truncate(node.text);
|
|
132
|
-
} else if (kind === 'regex') {
|
|
133
|
-
name = node.text || '?';
|
|
134
|
-
text = truncate(node.text);
|
|
135
|
-
}
|
|
209
|
+
collectNode(node, kind);
|
|
136
210
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
receiver: null,
|
|
144
|
-
parentNodeId: resolveParentNodeId(line),
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
matched.add(node.id);
|
|
211
|
+
if (kind === 'call') {
|
|
212
|
+
// Mirror native: skip full subtree, recurse only into arguments.
|
|
213
|
+
// Prevents double-counting chained calls like service.getUser().getName().
|
|
214
|
+
walkCallArguments(node);
|
|
215
|
+
return { skipChildren: true };
|
|
216
|
+
}
|
|
148
217
|
|
|
149
218
|
if (kind !== 'string' && kind !== 'regex') {
|
|
150
219
|
return { skipChildren: true };
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import type { TreeSitterNode } from '../../types.js';
|
|
2
|
+
import type {
|
|
3
|
+
AnyRules,
|
|
4
|
+
CfgBlockInternal,
|
|
5
|
+
FuncState,
|
|
6
|
+
LoopCtx,
|
|
7
|
+
ProcessStatementsFn,
|
|
8
|
+
} from './cfg-shared.js';
|
|
9
|
+
import { getBodyStatements, isCaseNode, isIfNode, nn } from './cfg-shared.js';
|
|
10
|
+
|
|
11
|
+
export function processIf(
|
|
12
|
+
ifStmt: TreeSitterNode,
|
|
13
|
+
currentBlock: CfgBlockInternal,
|
|
14
|
+
S: FuncState,
|
|
15
|
+
cfgRules: AnyRules,
|
|
16
|
+
processStatements: ProcessStatementsFn,
|
|
17
|
+
): CfgBlockInternal {
|
|
18
|
+
currentBlock.endLine = ifStmt.startPosition.row + 1;
|
|
19
|
+
|
|
20
|
+
const condBlock = S.makeBlock(
|
|
21
|
+
'condition',
|
|
22
|
+
ifStmt.startPosition.row + 1,
|
|
23
|
+
ifStmt.startPosition.row + 1,
|
|
24
|
+
'if',
|
|
25
|
+
);
|
|
26
|
+
S.addEdge(currentBlock, condBlock, 'fallthrough');
|
|
27
|
+
|
|
28
|
+
const joinBlock = S.makeBlock('body');
|
|
29
|
+
|
|
30
|
+
const consequentField = cfgRules.ifConsequentField || 'consequence';
|
|
31
|
+
const consequent = ifStmt.childForFieldName(consequentField);
|
|
32
|
+
const trueBlock = S.makeBlock('branch_true', null, null, 'then');
|
|
33
|
+
S.addEdge(condBlock, trueBlock, 'branch_true');
|
|
34
|
+
const trueStmts = getBodyStatements(consequent, cfgRules);
|
|
35
|
+
const trueEnd = processStatements(trueStmts, trueBlock, S, cfgRules);
|
|
36
|
+
if (trueEnd) {
|
|
37
|
+
S.addEdge(trueEnd, joinBlock, 'fallthrough');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (cfgRules.elifNode) {
|
|
41
|
+
processElifSiblings(ifStmt, condBlock, joinBlock, S, cfgRules, processStatements);
|
|
42
|
+
} else {
|
|
43
|
+
processAlternative(ifStmt, condBlock, joinBlock, S, cfgRules, processStatements);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return joinBlock;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function processAlternative(
|
|
50
|
+
ifStmt: TreeSitterNode,
|
|
51
|
+
condBlock: CfgBlockInternal,
|
|
52
|
+
joinBlock: CfgBlockInternal,
|
|
53
|
+
S: FuncState,
|
|
54
|
+
cfgRules: AnyRules,
|
|
55
|
+
processStatements: ProcessStatementsFn,
|
|
56
|
+
): void {
|
|
57
|
+
const alternative = ifStmt.childForFieldName('alternative');
|
|
58
|
+
if (!alternative) {
|
|
59
|
+
S.addEdge(condBlock, joinBlock, 'branch_false');
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (cfgRules.elseViaAlternative && alternative.type !== cfgRules.elseClause) {
|
|
64
|
+
if (isIfNode(alternative.type, cfgRules)) {
|
|
65
|
+
const falseBlock = S.makeBlock('branch_false', null, null, 'else-if');
|
|
66
|
+
S.addEdge(condBlock, falseBlock, 'branch_false');
|
|
67
|
+
const elseIfEnd = processIf(alternative, falseBlock, S, cfgRules, processStatements);
|
|
68
|
+
if (elseIfEnd) S.addEdge(elseIfEnd, joinBlock, 'fallthrough');
|
|
69
|
+
} else {
|
|
70
|
+
const falseBlock = S.makeBlock('branch_false', null, null, 'else');
|
|
71
|
+
S.addEdge(condBlock, falseBlock, 'branch_false');
|
|
72
|
+
const falseStmts = getBodyStatements(alternative, cfgRules);
|
|
73
|
+
const falseEnd = processStatements(falseStmts, falseBlock, S, cfgRules);
|
|
74
|
+
if (falseEnd) S.addEdge(falseEnd, joinBlock, 'fallthrough');
|
|
75
|
+
}
|
|
76
|
+
} else if (alternative.type === cfgRules.elseClause) {
|
|
77
|
+
const elseChildren: TreeSitterNode[] = [];
|
|
78
|
+
for (let i = 0; i < alternative.namedChildCount; i++) {
|
|
79
|
+
elseChildren.push(nn(alternative.namedChild(i)));
|
|
80
|
+
}
|
|
81
|
+
const firstChild = elseChildren[0];
|
|
82
|
+
if (elseChildren.length === 1 && firstChild && isIfNode(firstChild.type, cfgRules)) {
|
|
83
|
+
const falseBlock = S.makeBlock('branch_false', null, null, 'else-if');
|
|
84
|
+
S.addEdge(condBlock, falseBlock, 'branch_false');
|
|
85
|
+
const elseIfEnd = processIf(firstChild, falseBlock, S, cfgRules, processStatements);
|
|
86
|
+
if (elseIfEnd) S.addEdge(elseIfEnd, joinBlock, 'fallthrough');
|
|
87
|
+
} else {
|
|
88
|
+
const falseBlock = S.makeBlock('branch_false', null, null, 'else');
|
|
89
|
+
S.addEdge(condBlock, falseBlock, 'branch_false');
|
|
90
|
+
const falseEnd = processStatements(elseChildren, falseBlock, S, cfgRules);
|
|
91
|
+
if (falseEnd) S.addEdge(falseEnd, joinBlock, 'fallthrough');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function processElifSiblings(
|
|
97
|
+
ifStmt: TreeSitterNode,
|
|
98
|
+
firstCondBlock: CfgBlockInternal,
|
|
99
|
+
joinBlock: CfgBlockInternal,
|
|
100
|
+
S: FuncState,
|
|
101
|
+
cfgRules: AnyRules,
|
|
102
|
+
processStatements: ProcessStatementsFn,
|
|
103
|
+
): void {
|
|
104
|
+
let lastCondBlock = firstCondBlock;
|
|
105
|
+
let foundElse = false;
|
|
106
|
+
|
|
107
|
+
for (let i = 0; i < ifStmt.namedChildCount; i++) {
|
|
108
|
+
const child = nn(ifStmt.namedChild(i));
|
|
109
|
+
|
|
110
|
+
if (child.type === cfgRules.elifNode) {
|
|
111
|
+
const elifCondBlock = S.makeBlock(
|
|
112
|
+
'condition',
|
|
113
|
+
child.startPosition.row + 1,
|
|
114
|
+
child.startPosition.row + 1,
|
|
115
|
+
'else-if',
|
|
116
|
+
);
|
|
117
|
+
S.addEdge(lastCondBlock, elifCondBlock, 'branch_false');
|
|
118
|
+
|
|
119
|
+
const elifConsequentField = cfgRules.ifConsequentField || 'consequence';
|
|
120
|
+
const elifConsequent = child.childForFieldName(elifConsequentField);
|
|
121
|
+
const elifTrueBlock = S.makeBlock('branch_true', null, null, 'then');
|
|
122
|
+
S.addEdge(elifCondBlock, elifTrueBlock, 'branch_true');
|
|
123
|
+
const elifTrueStmts = getBodyStatements(elifConsequent, cfgRules);
|
|
124
|
+
const elifTrueEnd = processStatements(elifTrueStmts, elifTrueBlock, S, cfgRules);
|
|
125
|
+
if (elifTrueEnd) S.addEdge(elifTrueEnd, joinBlock, 'fallthrough');
|
|
126
|
+
|
|
127
|
+
lastCondBlock = elifCondBlock;
|
|
128
|
+
} else if (child.type === cfgRules.elseClause) {
|
|
129
|
+
const elseBlock = S.makeBlock('branch_false', null, null, 'else');
|
|
130
|
+
S.addEdge(lastCondBlock, elseBlock, 'branch_false');
|
|
131
|
+
|
|
132
|
+
const elseBody = child.childForFieldName('body');
|
|
133
|
+
let elseStmts: TreeSitterNode[];
|
|
134
|
+
if (elseBody) {
|
|
135
|
+
elseStmts = getBodyStatements(elseBody, cfgRules);
|
|
136
|
+
} else {
|
|
137
|
+
elseStmts = [];
|
|
138
|
+
for (let j = 0; j < child.namedChildCount; j++) {
|
|
139
|
+
elseStmts.push(nn(child.namedChild(j)));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const elseEnd = processStatements(elseStmts, elseBlock, S, cfgRules);
|
|
143
|
+
if (elseEnd) S.addEdge(elseEnd, joinBlock, 'fallthrough');
|
|
144
|
+
|
|
145
|
+
foundElse = true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (!foundElse) {
|
|
150
|
+
S.addEdge(lastCondBlock, joinBlock, 'branch_false');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function processSwitch(
|
|
155
|
+
switchStmt: TreeSitterNode,
|
|
156
|
+
currentBlock: CfgBlockInternal,
|
|
157
|
+
S: FuncState,
|
|
158
|
+
cfgRules: AnyRules,
|
|
159
|
+
processStatements: ProcessStatementsFn,
|
|
160
|
+
): CfgBlockInternal {
|
|
161
|
+
currentBlock.endLine = switchStmt.startPosition.row + 1;
|
|
162
|
+
|
|
163
|
+
const switchHeader = S.makeBlock(
|
|
164
|
+
'condition',
|
|
165
|
+
switchStmt.startPosition.row + 1,
|
|
166
|
+
switchStmt.startPosition.row + 1,
|
|
167
|
+
'switch',
|
|
168
|
+
);
|
|
169
|
+
S.addEdge(currentBlock, switchHeader, 'fallthrough');
|
|
170
|
+
|
|
171
|
+
const joinBlock = S.makeBlock('body');
|
|
172
|
+
const switchCtx: LoopCtx = { headerBlock: switchHeader, exitBlock: joinBlock };
|
|
173
|
+
S.loopStack.push(switchCtx);
|
|
174
|
+
|
|
175
|
+
const switchBody = switchStmt.childForFieldName('body');
|
|
176
|
+
const container = switchBody || switchStmt;
|
|
177
|
+
|
|
178
|
+
let hasDefault = false;
|
|
179
|
+
for (let i = 0; i < container.namedChildCount; i++) {
|
|
180
|
+
const caseClause = nn(container.namedChild(i));
|
|
181
|
+
|
|
182
|
+
const isDefault = caseClause.type === cfgRules.defaultNode;
|
|
183
|
+
const isCase = isDefault || isCaseNode(caseClause.type, cfgRules);
|
|
184
|
+
if (!isCase) continue;
|
|
185
|
+
|
|
186
|
+
const caseLabel = isDefault ? 'default' : 'case';
|
|
187
|
+
const caseBlock = S.makeBlock('case', caseClause.startPosition.row + 1, null, caseLabel);
|
|
188
|
+
S.addEdge(switchHeader, caseBlock, isDefault ? 'branch_false' : 'branch_true');
|
|
189
|
+
if (isDefault) hasDefault = true;
|
|
190
|
+
|
|
191
|
+
const caseStmts = extractCaseBody(caseClause, cfgRules);
|
|
192
|
+
const caseEnd = processStatements(caseStmts, caseBlock, S, cfgRules);
|
|
193
|
+
if (caseEnd) S.addEdge(caseEnd, joinBlock, 'fallthrough');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (!hasDefault) {
|
|
197
|
+
S.addEdge(switchHeader, joinBlock, 'branch_false');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
S.loopStack.pop();
|
|
201
|
+
return joinBlock;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function extractCaseBody(caseClause: TreeSitterNode, cfgRules: AnyRules): TreeSitterNode[] {
|
|
205
|
+
const caseBodyNode =
|
|
206
|
+
caseClause.childForFieldName('body') || caseClause.childForFieldName('consequence');
|
|
207
|
+
if (caseBodyNode) {
|
|
208
|
+
return getBodyStatements(caseBodyNode, cfgRules);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const stmts: TreeSitterNode[] = [];
|
|
212
|
+
const valueNode = caseClause.childForFieldName('value');
|
|
213
|
+
const patternNode = caseClause.childForFieldName('pattern');
|
|
214
|
+
for (let j = 0; j < caseClause.namedChildCount; j++) {
|
|
215
|
+
const child = nn(caseClause.namedChild(j));
|
|
216
|
+
if (child !== valueNode && child !== patternNode && child.type !== 'switch_label') {
|
|
217
|
+
if (child.type === 'statement_list') {
|
|
218
|
+
for (let k = 0; k < child.namedChildCount; k++) {
|
|
219
|
+
stmts.push(nn(child.namedChild(k)));
|
|
220
|
+
}
|
|
221
|
+
} else {
|
|
222
|
+
stmts.push(child);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return stmts;
|
|
227
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { TreeSitterNode } from '../../types.js';
|
|
2
|
+
import type {
|
|
3
|
+
AnyRules,
|
|
4
|
+
CfgBlockInternal,
|
|
5
|
+
FuncState,
|
|
6
|
+
LoopCtx,
|
|
7
|
+
ProcessStatementsFn,
|
|
8
|
+
} from './cfg-shared.js';
|
|
9
|
+
import { getBodyStatements, registerLabelCtx } from './cfg-shared.js';
|
|
10
|
+
|
|
11
|
+
export function processForLoop(
|
|
12
|
+
forStmt: TreeSitterNode,
|
|
13
|
+
currentBlock: CfgBlockInternal,
|
|
14
|
+
S: FuncState,
|
|
15
|
+
cfgRules: AnyRules,
|
|
16
|
+
processStatements: ProcessStatementsFn,
|
|
17
|
+
): CfgBlockInternal {
|
|
18
|
+
const headerBlock = S.makeBlock(
|
|
19
|
+
'loop_header',
|
|
20
|
+
forStmt.startPosition.row + 1,
|
|
21
|
+
forStmt.startPosition.row + 1,
|
|
22
|
+
'for',
|
|
23
|
+
);
|
|
24
|
+
S.addEdge(currentBlock, headerBlock, 'fallthrough');
|
|
25
|
+
|
|
26
|
+
const loopExitBlock = S.makeBlock('body');
|
|
27
|
+
const loopCtx: LoopCtx = { headerBlock, exitBlock: loopExitBlock };
|
|
28
|
+
S.loopStack.push(loopCtx);
|
|
29
|
+
registerLabelCtx(S, headerBlock, loopExitBlock);
|
|
30
|
+
|
|
31
|
+
const body = forStmt.childForFieldName('body');
|
|
32
|
+
const bodyBlock = S.makeBlock('loop_body');
|
|
33
|
+
S.addEdge(headerBlock, bodyBlock, 'branch_true');
|
|
34
|
+
|
|
35
|
+
const bodyStmts = getBodyStatements(body, cfgRules);
|
|
36
|
+
const bodyEnd = processStatements(bodyStmts, bodyBlock, S, cfgRules);
|
|
37
|
+
if (bodyEnd) S.addEdge(bodyEnd, headerBlock, 'loop_back');
|
|
38
|
+
|
|
39
|
+
S.addEdge(headerBlock, loopExitBlock, 'loop_exit');
|
|
40
|
+
S.loopStack.pop();
|
|
41
|
+
return loopExitBlock;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function processWhileLoop(
|
|
45
|
+
whileStmt: TreeSitterNode,
|
|
46
|
+
currentBlock: CfgBlockInternal,
|
|
47
|
+
S: FuncState,
|
|
48
|
+
cfgRules: AnyRules,
|
|
49
|
+
processStatements: ProcessStatementsFn,
|
|
50
|
+
): CfgBlockInternal {
|
|
51
|
+
const headerBlock = S.makeBlock(
|
|
52
|
+
'loop_header',
|
|
53
|
+
whileStmt.startPosition.row + 1,
|
|
54
|
+
whileStmt.startPosition.row + 1,
|
|
55
|
+
'while',
|
|
56
|
+
);
|
|
57
|
+
S.addEdge(currentBlock, headerBlock, 'fallthrough');
|
|
58
|
+
|
|
59
|
+
const loopExitBlock = S.makeBlock('body');
|
|
60
|
+
const loopCtx: LoopCtx = { headerBlock, exitBlock: loopExitBlock };
|
|
61
|
+
S.loopStack.push(loopCtx);
|
|
62
|
+
registerLabelCtx(S, headerBlock, loopExitBlock);
|
|
63
|
+
|
|
64
|
+
const body = whileStmt.childForFieldName('body');
|
|
65
|
+
const bodyBlock = S.makeBlock('loop_body');
|
|
66
|
+
S.addEdge(headerBlock, bodyBlock, 'branch_true');
|
|
67
|
+
|
|
68
|
+
const bodyStmts = getBodyStatements(body, cfgRules);
|
|
69
|
+
const bodyEnd = processStatements(bodyStmts, bodyBlock, S, cfgRules);
|
|
70
|
+
if (bodyEnd) S.addEdge(bodyEnd, headerBlock, 'loop_back');
|
|
71
|
+
|
|
72
|
+
S.addEdge(headerBlock, loopExitBlock, 'loop_exit');
|
|
73
|
+
S.loopStack.pop();
|
|
74
|
+
return loopExitBlock;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function processDoWhileLoop(
|
|
78
|
+
doStmt: TreeSitterNode,
|
|
79
|
+
currentBlock: CfgBlockInternal,
|
|
80
|
+
S: FuncState,
|
|
81
|
+
cfgRules: AnyRules,
|
|
82
|
+
processStatements: ProcessStatementsFn,
|
|
83
|
+
): CfgBlockInternal {
|
|
84
|
+
const bodyBlock = S.makeBlock('loop_body', doStmt.startPosition.row + 1, null, 'do');
|
|
85
|
+
S.addEdge(currentBlock, bodyBlock, 'fallthrough');
|
|
86
|
+
|
|
87
|
+
const condBlock = S.makeBlock('loop_header', null, null, 'do-while');
|
|
88
|
+
const loopExitBlock = S.makeBlock('body');
|
|
89
|
+
|
|
90
|
+
const loopCtx: LoopCtx = { headerBlock: condBlock, exitBlock: loopExitBlock };
|
|
91
|
+
S.loopStack.push(loopCtx);
|
|
92
|
+
registerLabelCtx(S, condBlock, loopExitBlock);
|
|
93
|
+
|
|
94
|
+
const body = doStmt.childForFieldName('body');
|
|
95
|
+
const bodyStmts = getBodyStatements(body, cfgRules);
|
|
96
|
+
const bodyEnd = processStatements(bodyStmts, bodyBlock, S, cfgRules);
|
|
97
|
+
if (bodyEnd) S.addEdge(bodyEnd, condBlock, 'fallthrough');
|
|
98
|
+
|
|
99
|
+
S.addEdge(condBlock, bodyBlock, 'loop_back');
|
|
100
|
+
S.addEdge(condBlock, loopExitBlock, 'loop_exit');
|
|
101
|
+
|
|
102
|
+
S.loopStack.pop();
|
|
103
|
+
return loopExitBlock;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function processInfiniteLoop(
|
|
107
|
+
loopStmt: TreeSitterNode,
|
|
108
|
+
currentBlock: CfgBlockInternal,
|
|
109
|
+
S: FuncState,
|
|
110
|
+
cfgRules: AnyRules,
|
|
111
|
+
processStatements: ProcessStatementsFn,
|
|
112
|
+
): CfgBlockInternal {
|
|
113
|
+
const headerBlock = S.makeBlock(
|
|
114
|
+
'loop_header',
|
|
115
|
+
loopStmt.startPosition.row + 1,
|
|
116
|
+
loopStmt.startPosition.row + 1,
|
|
117
|
+
'loop',
|
|
118
|
+
);
|
|
119
|
+
S.addEdge(currentBlock, headerBlock, 'fallthrough');
|
|
120
|
+
|
|
121
|
+
const loopExitBlock = S.makeBlock('body');
|
|
122
|
+
const loopCtx: LoopCtx = { headerBlock, exitBlock: loopExitBlock };
|
|
123
|
+
S.loopStack.push(loopCtx);
|
|
124
|
+
registerLabelCtx(S, headerBlock, loopExitBlock);
|
|
125
|
+
|
|
126
|
+
const body = loopStmt.childForFieldName('body');
|
|
127
|
+
const bodyBlock = S.makeBlock('loop_body');
|
|
128
|
+
S.addEdge(headerBlock, bodyBlock, 'branch_true');
|
|
129
|
+
|
|
130
|
+
const bodyStmts = getBodyStatements(body, cfgRules);
|
|
131
|
+
const bodyEnd = processStatements(bodyStmts, bodyBlock, S, cfgRules);
|
|
132
|
+
if (bodyEnd) S.addEdge(bodyEnd, headerBlock, 'loop_back');
|
|
133
|
+
|
|
134
|
+
S.loopStack.pop();
|
|
135
|
+
return loopExitBlock;
|
|
136
|
+
}
|