@eagleoutice/flowr 2.14.0 → 2.14.2
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 +169 -91
- package/abstract-interpretation/absint-visitor.d.ts +91 -25
- package/abstract-interpretation/absint-visitor.js +235 -74
- package/abstract-interpretation/data-frame/mappers/access-mapper.d.ts +1 -1
- package/abstract-interpretation/data-frame/mappers/access-mapper.js +4 -4
- package/abstract-interpretation/data-frame/mappers/arguments.d.ts +1 -1
- package/abstract-interpretation/data-frame/mappers/arguments.js +1 -1
- package/abstract-interpretation/data-frame/mappers/function-mapper.js +107 -254
- package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +5 -5
- package/abstract-interpretation/data-frame/resolve-args.d.ts +1 -1
- package/abstract-interpretation/data-frame/resolve-args.js +6 -4
- package/abstract-interpretation/data-frame/shape-inference.d.ts +4 -9
- package/abstract-interpretation/domains/bounded-set-domain.d.ts +1 -0
- package/abstract-interpretation/domains/bounded-set-domain.js +1 -0
- package/abstract-interpretation/domains/partial-product-domain.js +1 -1
- package/abstract-interpretation/domains/set-range-domain.d.ts +3 -2
- package/abstract-interpretation/domains/set-range-domain.js +3 -2
- package/abstract-interpretation/domains/set-upper-bound-domain.d.ts +3 -2
- package/abstract-interpretation/domains/set-upper-bound-domain.js +3 -2
- package/benchmark/calibration.d.ts +18 -11
- package/benchmark/calibration.js +37 -27
- package/benchmark/slicer.d.ts +9 -2
- package/benchmark/slicer.js +44 -37
- package/benchmark/stats/count-comments.d.ts +16 -0
- package/benchmark/stats/count-comments.js +30 -0
- package/benchmark/stats/print.js +2 -0
- package/benchmark/stats/size-of.d.ts +7 -3
- package/benchmark/stats/size-of.js +7 -3
- package/benchmark/stats/stats.d.ts +7 -0
- package/benchmark/summarizer/first-phase/process.js +2 -19
- package/benchmark/summarizer/second-phase/graph.js +13 -3
- package/benchmark/summarizer/second-phase/process.js +2 -0
- package/cli/benchmark-app.js +4 -1
- package/cli/benchmark-helper-app.d.ts +1 -0
- package/cli/benchmark-helper-app.js +2 -2
- package/cli/common/options.d.ts +5 -0
- package/cli/common/options.js +1 -0
- package/cli/common/scripts-info.d.ts +5 -0
- package/cli/repl/commands/repl-dataflow.js +70 -27
- package/cli/repl/core.d.ts +1 -1
- package/cli/repl/core.js +1 -1
- package/cli/repl/execute.d.ts +2 -2
- package/cli/repl/execute.js +2 -2
- package/cli/repl/parser/slice-query-parser.js +2 -1
- package/cli/repl/server/connection.d.ts +4 -0
- package/cli/repl/server/connection.js +19 -16
- package/cli/repl/server/messages/message-analysis.d.ts +1 -1
- package/config.d.ts +6 -0
- package/config.js +12 -9
- package/control-flow/basic-cfg-guided-visitor.d.ts +7 -2
- package/control-flow/basic-cfg-guided-visitor.js +37 -24
- package/control-flow/cfg-dead-code.js +44 -33
- package/control-flow/cfg-properties.js +2 -2
- package/control-flow/cfg-simplification.js +6 -5
- package/control-flow/cfg-to-basic-blocks.js +11 -13
- package/control-flow/control-flow-graph.d.ts +179 -189
- package/control-flow/control-flow-graph.js +400 -263
- package/control-flow/dfg-cfg-guided-visitor.d.ts +21 -3
- package/control-flow/dfg-cfg-guided-visitor.js +17 -13
- package/control-flow/diff-cfg.js +6 -14
- package/control-flow/happens-before.js +5 -4
- package/control-flow/semantic-cfg-guided-visitor.d.ts +44 -101
- package/control-flow/semantic-cfg-guided-visitor.js +6 -26
- package/control-flow/simple-visitor.js +14 -15
- package/control-flow/syntax-cfg-guided-visitor.d.ts +2 -1
- package/control-flow/useless-loop.js +18 -14
- package/core/steps/all/core/20-dataflow.d.ts +1 -3
- package/core/steps/pipeline/default-pipelines.d.ts +141 -157
- package/dataflow/cluster.js +7 -0
- package/dataflow/environments/apply-kill.d.ts +6 -0
- package/dataflow/environments/apply-kill.js +64 -32
- package/dataflow/environments/built-in-props.d.ts +10 -2
- package/dataflow/environments/built-in-props.js +9 -1
- package/dataflow/environments/built-in.d.ts +6 -3
- package/dataflow/environments/built-in.js +8 -5
- package/dataflow/environments/clone.d.ts +3 -3
- package/dataflow/environments/clone.js +5 -5
- package/dataflow/environments/default-builtin-config.d.ts +188 -8
- package/dataflow/environments/default-builtin-config.js +112 -39
- package/dataflow/environments/environment.d.ts +9 -1
- package/dataflow/environments/environment.js +25 -7
- package/dataflow/environments/identifier.d.ts +12 -1
- package/dataflow/environments/identifier.js +4 -1
- package/dataflow/environments/query-fn-props.d.ts +6 -0
- package/dataflow/environments/query-fn-props.js +20 -0
- package/dataflow/environments/resolve-by-name.d.ts +7 -0
- package/dataflow/environments/resolve-by-name.js +26 -2
- package/dataflow/environments/resolve-helper.d.ts +3 -1
- package/dataflow/environments/resolve-helper.js +2 -0
- package/dataflow/eval/resolve/alias-tracking.d.ts +2 -2
- package/dataflow/eval/resolve/alias-tracking.js +2 -2
- package/dataflow/eval/resolve/match-arguments.js +7 -5
- package/dataflow/eval/resolve/node-value.d.ts +3 -1
- package/dataflow/eval/resolve/node-value.js +12 -0
- package/dataflow/eval/resolve/resolve-argument.js +5 -4
- package/dataflow/eval/resolve/resolve-operators.js +10 -7
- package/dataflow/eval/resolve/resolve-strings.js +2 -2
- package/dataflow/eval/resolve/resolve-working-directory.d.ts +1 -1
- package/dataflow/eval/resolve/resolve-working-directory.js +5 -5
- package/dataflow/eval/resolve/resolve.js +3 -2
- package/dataflow/eval/values/general.js +8 -5
- package/dataflow/extractor.d.ts +1 -4
- package/dataflow/extractor.js +11 -10
- package/dataflow/fn/exceptions-of-function.d.ts +6 -2
- package/dataflow/fn/exceptions-of-function.js +85 -38
- package/dataflow/fn/strict-function.d.ts +40 -0
- package/dataflow/fn/strict-function.js +339 -0
- package/dataflow/graph/call-graph.js +2 -2
- package/dataflow/graph/df-helper.d.ts +17 -2
- package/dataflow/graph/df-helper.js +19 -3
- package/dataflow/graph/diff-dataflow-graph.d.ts +1 -1
- package/dataflow/graph/diff-dataflow-graph.js +19 -2
- package/dataflow/graph/edge.d.ts +38 -2
- package/dataflow/graph/edge.js +32 -2
- package/dataflow/graph/graph.d.ts +32 -5
- package/dataflow/graph/graph.js +65 -4
- package/dataflow/graph/match-args.d.ts +69 -0
- package/dataflow/graph/match-args.js +167 -0
- package/dataflow/info.d.ts +40 -0
- package/dataflow/info.js +28 -1
- package/dataflow/internal/control-flow.d.ts +102 -0
- package/dataflow/internal/control-flow.js +200 -0
- package/dataflow/internal/linker.d.ts +6 -31
- package/dataflow/internal/linker.js +24 -81
- package/dataflow/internal/process/functions/call/argument/unpack-argument.d.ts +1 -1
- package/dataflow/internal/process/functions/call/argument/unpack-argument.js +3 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-access.js +9 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +6 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +1 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +18 -37
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +3 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +11 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +6 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +18 -14
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +8 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +11 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +27 -20
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +3 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +35 -6
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +20 -17
- package/dataflow/internal/process/functions/call/built-in/built-in-list.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-list.js +6 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-load.js +4 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +8 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-namespace-access.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-namespace-access.js +5 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-new-env.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +5 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +7 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +15 -13
- package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +4 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +26 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +17 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +3 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +97 -33
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +6 -15
- package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +12 -13
- package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +15 -12
- package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +15 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +12 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-stop-if-not.js +6 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-string-template.d.ts +1 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-string-template.js +5 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +45 -10
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +19 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +6 -2
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +29 -8
- package/dataflow/internal/process/functions/call/common.js +5 -6
- package/dataflow/internal/process/functions/call/deferred.js +2 -2
- package/dataflow/internal/process/functions/call/known-call-handling.d.ts +12 -2
- package/dataflow/internal/process/functions/call/known-call-handling.js +23 -1
- package/dataflow/internal/process/functions/call/named-call-handling.js +2 -0
- package/dataflow/internal/process/functions/call/nse.d.ts +1 -1
- package/dataflow/internal/process/functions/call/nse.js +6 -1
- package/dataflow/internal/process/functions/call/quoted.js +2 -2
- package/dataflow/internal/process/functions/call/unnamed-call-handling.js +19 -6
- package/dataflow/internal/process/functions/process-argument.d.ts +1 -1
- package/dataflow/internal/process/functions/process-argument.js +12 -4
- package/dataflow/internal/process/functions/process-parameter.js +13 -0
- package/dataflow/internal/process/process-named-call.d.ts +2 -2
- package/dataflow/internal/process/process-named-call.js +9 -7
- package/documentation/data/server/doc-data-server-messages.js +4 -4
- package/documentation/doc-readme.js +45 -0
- package/documentation/doc-util/doc-cfg.d.ts +8 -7
- package/documentation/doc-util/doc-cfg.js +10 -10
- package/documentation/doc-util/doc-playground.d.ts +12 -0
- package/documentation/doc-util/doc-playground.js +21 -0
- package/documentation/doc-util/doc-query.d.ts +4 -1
- package/documentation/doc-util/doc-query.js +4 -2
- package/documentation/wiki-absint.d.ts +3 -4
- package/documentation/wiki-absint.js +12 -5
- package/documentation/wiki-analyzer.js +2 -2
- package/documentation/wiki-cfg.js +101 -106
- package/documentation/wiki-core.js +1 -1
- package/documentation/wiki-dataflow-graph.js +85 -53
- package/documentation/wiki-linter.js +16 -1
- package/documentation/wiki-linting-and-testing.js +1 -16
- package/documentation/wiki-mk/doc-maker.js +6 -4
- package/documentation/wiki-query.js +67 -4
- package/documentation/wiki-signature-database.js +28 -2
- package/linter/linter-fix.d.ts +16 -0
- package/linter/linter-fix.js +104 -0
- package/linter/linter-format.d.ts +18 -1
- package/linter/linter-format.js +31 -1
- package/linter/linter-output.js +47 -11
- package/linter/linter-rules.d.ts +64 -9
- package/linter/linter-rules.js +5 -1
- package/linter/rules/absolute-path.js +4 -2
- package/linter/rules/dataframe-access-validation.js +6 -7
- package/linter/rules/deprecated-functions.d.ts +107 -10
- package/linter/rules/deprecated-functions.js +309 -23
- package/linter/rules/file-path-validity.js +5 -4
- package/linter/rules/function-finder-util.d.ts +6 -0
- package/linter/rules/function-finder-util.js +21 -13
- package/linter/rules/naming-convention.js +1 -1
- package/linter/rules/network-functions.d.ts +3 -3
- package/linter/rules/stop-with-call-arg.js +2 -2
- package/linter/rules/unclosed-connection.d.ts +44 -0
- package/linter/rules/unclosed-connection.js +200 -0
- package/linter/rules/undefined-symbol-util.js +6 -4
- package/linter/rules/undefined-symbol.js +2 -2
- package/linter/rules/unused-definition.js +8 -4
- package/linter/rules/unused-import.d.ts +60 -0
- package/linter/rules/unused-import.js +179 -0
- package/package.json +5 -8
- package/project/attached-packages.js +2 -1
- package/project/cache/flowr-analyzer-cache.d.ts +2 -5
- package/project/cache/flowr-analyzer-cache.js +4 -7
- package/project/cache/flowr-analyzer-controlflow-cache.d.ts +9 -8
- package/project/cache/flowr-analyzer-controlflow-cache.js +17 -34
- package/project/cache/flowr-cache.d.ts +9 -0
- package/project/cache/flowr-cache.js +19 -0
- package/project/context/flowr-analyzer-context.d.ts +7 -3
- package/project/context/flowr-analyzer-context.js +15 -9
- package/project/context/flowr-analyzer-dependencies-context.d.ts +24 -3
- package/project/context/flowr-analyzer-dependencies-context.js +9 -14
- package/project/context/flowr-analyzer-files-context.js +15 -17
- package/project/context/flowr-analyzer-meta-context.js +2 -12
- package/project/dependency-version-space.d.ts +3 -10
- package/project/dependency-version-space.js +10 -9
- package/project/flowr-analyzer.d.ts +4 -6
- package/project/flowr-analyzer.js +4 -5
- package/project/plugins/file-plugins/files/flowr-description-file.d.ts +1 -1
- package/project/plugins/file-plugins/files/flowr-description-file.js +1 -1
- package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +1 -1
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +23 -35
- package/project/plugins/file-plugins/files/flowr-news-file.d.ts +1 -1
- package/project/plugins/file-plugins/files/flowr-news-file.js +1 -1
- package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +13 -13
- package/project/plugins/file-plugins/files/flowr-rda-file.js +131 -286
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +1 -0
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +1 -0
- package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.d.ts +2 -5
- package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.js +2 -8
- package/project/plugins/file-plugins/flowr-analyzer-file-plugin.d.ts +32 -0
- package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +43 -1
- package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.d.ts +4 -12
- package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.js +3 -16
- package/project/plugins/file-plugins/flowr-analyzer-license-file-plugin.d.ts +5 -8
- package/project/plugins/file-plugins/flowr-analyzer-license-file-plugin.js +4 -10
- package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +3 -10
- package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +1 -13
- package/project/plugins/file-plugins/flowr-analyzer-namespace-files-plugin.d.ts +3 -6
- package/project/plugins/file-plugins/flowr-analyzer-namespace-files-plugin.js +2 -8
- package/project/plugins/file-plugins/flowr-analyzer-news-file-plugin.d.ts +2 -5
- package/project/plugins/file-plugins/flowr-analyzer-news-file-plugin.js +2 -8
- package/project/plugins/file-plugins/flowr-analyzer-rda-file-plugin.d.ts +2 -5
- package/project/plugins/file-plugins/flowr-analyzer-rda-file-plugin.js +2 -8
- package/project/plugins/file-plugins/flowr-analyzer-rprofile-file-plugin.d.ts +3 -4
- package/project/plugins/file-plugins/flowr-analyzer-rprofile-file-plugin.js +3 -6
- package/project/plugins/file-plugins/flowr-analyzer-test-file-plugin.d.ts +4 -12
- package/project/plugins/file-plugins/flowr-analyzer-test-file-plugin.js +3 -16
- package/project/plugins/file-plugins/flowr-analyzer-vignette-file-plugin.d.ts +4 -12
- package/project/plugins/file-plugins/flowr-analyzer-vignette-file-plugin.js +3 -16
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +4 -12
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -16
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-jupyter-file-plugin.d.ts +2 -5
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-jupyter-file-plugin.js +2 -8
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.d.ts +2 -6
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.js +1 -10
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-sweave-file-plugin.d.ts +2 -5
- package/project/plugins/file-plugins/notebooks/flowr-analyzer-sweave-file-plugin.js +2 -8
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-library-plugin.js +2 -1
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +5 -5
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +33 -6
- package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
- package/project/sigdb/build.d.ts +2 -2
- package/project/sigdb/decode.d.ts +0 -5
- package/project/sigdb/decode.js +0 -8
- package/project/sigdb/index-format.d.ts +4 -4
- package/project/sigdb/manifest.d.ts +5 -3
- package/project/sigdb/manifest.js +50 -9
- package/project/sigdb/reader.d.ts +48 -13
- package/project/sigdb/reader.js +3 -2
- package/project/sigdb/schema.d.ts +5 -3
- package/project/sigdb/schema.js +2 -2
- package/project/sigdb/signature-db.d.ts +69 -0
- package/project/sigdb/signature-db.js +54 -0
- package/project/sigdb/signature-match.d.ts +10 -5
- package/project/sigdb/signature-match.js +13 -8
- package/queries/catalog/absint-query/absint-query-executor.js +1 -2
- package/queries/catalog/call-context-query/call-context-query-executor.js +2 -4
- package/queries/catalog/call-context-query/identify-link-to-last-call-relation.d.ts +1 -1
- package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +33 -6
- package/queries/catalog/control-flow-query/control-flow-query-executor.js +1 -2
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +2 -2
- package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +8 -7
- package/queries/catalog/dependencies-query/dependencies-query-format.js +22 -35
- package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +13 -1
- package/queries/catalog/dependencies-query/function-info/library-functions.js +26 -22
- package/queries/catalog/dependencies-query/function-info/statistics-functions.d.ts +9 -0
- package/queries/catalog/dependencies-query/function-info/statistics-functions.js +19 -0
- package/queries/catalog/dependencies-query/implicit-echo.d.ts +13 -0
- package/queries/catalog/dependencies-query/implicit-echo.js +133 -0
- package/queries/catalog/dependencies-query/link-devices.js +2 -8
- package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +2 -2
- package/queries/catalog/happens-before-query/happens-before-query-executor.js +1 -2
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +2 -1
- package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.d.ts +2 -2
- package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +1 -0
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-executor.d.ts +6 -0
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-executor.js +25 -0
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-format.d.ts +31 -0
- package/queries/catalog/inspect-strictness-query/inspect-strictness-query-format.js +56 -0
- package/queries/catalog/signature-query/signature-query-executor.js +4 -3
- package/queries/catalog/slice-query-options.d.ts +1 -1
- package/queries/catalog/slice-query-options.js +1 -1
- package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +1 -1
- package/queries/query-function-filter.d.ts +8 -2
- package/queries/query-function-filter.js +11 -1
- package/queries/query.d.ts +11 -1
- package/queries/query.js +2 -0
- package/r-bridge/lang-4.x/ast/model/model.d.ts +4 -4
- package/r-bridge/lang-4.x/ast/model/model.js +4 -4
- package/r-bridge/lang-4.x/ast/model/nodes/info/r-delimiter.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/info/r-delimiter.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-access.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +4 -1
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -2
- package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-break.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-comment.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +6 -4
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +6 -4
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-logical.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-next.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +6 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-number.js +13 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-project.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-project.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-string.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.js +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
- package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.js +1 -0
- package/r-bridge/lang-4.x/ast/model/processing/decorate.js +2 -1
- package/r-bridge/lang-4.x/ast/model/processing/stateful-fold.d.ts +1 -1
- package/r-bridge/lang-4.x/ast/model/processing/stateful-fold.js +3 -2
- package/r-bridge/lang-4.x/ast/parser/main/internal/control/normalize-if-then-else.js +2 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/control/normalize-if-then.js +2 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/expression/normalize-expression.js +1 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-argument.js +2 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-call.d.ts +2 -2
- package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-call.js +6 -3
- package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-definition.js +2 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-parameter.js +2 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-for.js +5 -3
- package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-repeat.js +2 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-while.js +2 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/normalize-access.js +2 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-binary.js +5 -3
- package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-unary.js +2 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.d.ts +1 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.js +2 -1
- package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-root.js +3 -1
- package/r-bridge/lang-4.x/ast/parser/main/normalize-meta.d.ts +1 -1
- package/r-bridge/lang-4.x/ast/parser/main/normalize-meta.js +2 -1
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +5 -3
- package/reconstruct/inline/source-inline-map.js +3 -3
- package/reconstruct/reconstruct.js +6 -4
- package/search/flowr-search-builder.d.ts +8 -8
- package/search/flowr-search-builder.js +4 -4
- package/search/flowr-search-filters.d.ts +2 -2
- package/search/flowr-search-filters.js +4 -15
- package/search/search-executor/search-enrichers.d.ts +6 -4
- package/search/search-executor/search-enrichers.js +44 -5
- package/slicing/criterion/filters/all-variables.js +2 -1
- package/slicing/criterion/parse.d.ts +2 -2
- package/slicing/criterion/parse.js +10 -8
- package/slicing/static/fingerprint.js +1 -1
- package/slicing/static/slice-call.js +2 -2
- package/util/arg-matching.d.ts +3 -0
- package/util/arg-matching.js +12 -1
- package/util/collections/arrays.d.ts +0 -4
- package/util/collections/arrays.js +4 -26
- package/util/diff-graph.d.ts +1 -1
- package/util/diff-graph.js +17 -3
- package/util/diff.d.ts +6 -0
- package/util/mermaid/ast.d.ts +1 -1
- package/util/mermaid/ast.js +5 -4
- package/util/mermaid/cfg.js +130 -24
- package/util/mermaid/dfg.js +31 -10
- package/util/mermaid/mermaid.js +2 -0
- package/util/objects.d.ts +21 -0
- package/util/objects.js +60 -0
- package/util/prefix.d.ts +1 -1
- package/util/simple-df/dfg-ascii.js +14 -3
- package/util/text/name-rank.d.ts +1 -1
- package/util/text/name-rank.js +1 -1
- package/util/text/playground-link.d.ts +131 -0
- package/util/text/playground-link.js +214 -0
- package/util/text/strings.js +7 -3
- package/util/version.js +1 -1
- package/control-flow/cfg-builder.d.ts +0 -30
- package/control-flow/cfg-builder.js +0 -79
- package/control-flow/extract-cfg.d.ts +0 -36
- package/control-flow/extract-cfg.js +0 -693
- package/project/cfg-kind.d.ts +0 -21
- package/project/cfg-kind.js +0 -26
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ControlFlowGraph = exports.CfgEdge = exports.CfgVertex = exports.CfgVertexType = void 0;
|
|
3
|
+
exports.ControlFlowGraph = exports.NoNeighbors = exports.CfgEdge = exports.CfgVertex = exports.CfgVertexType = void 0;
|
|
4
4
|
exports.emptyControlFlowInformation = emptyControlFlowInformation;
|
|
5
|
+
exports.extractCfg = extractCfg;
|
|
6
|
+
exports.cfg2quads = cfg2quads;
|
|
5
7
|
const node_id_1 = require("../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
8
|
+
const graph_1 = require("../dataflow/graph/graph");
|
|
9
|
+
const edge_1 = require("../dataflow/graph/edge");
|
|
10
|
+
const info_1 = require("../dataflow/info");
|
|
11
|
+
const vertex_1 = require("../dataflow/graph/vertex");
|
|
12
|
+
const quads_1 = require("../util/quads");
|
|
13
|
+
const control_flow_1 = require("../dataflow/internal/control-flow");
|
|
6
14
|
const convert_values_1 = require("../r-bridge/lang-4.x/convert-values");
|
|
7
15
|
const assert_1 = require("../util/assert");
|
|
16
|
+
const model_1 = require("../r-bridge/lang-4.x/ast/model/model");
|
|
8
17
|
/**
|
|
9
18
|
* The type of a vertex in the {@link ControlFlowGraph}.
|
|
10
19
|
* Please use the helper object (e.g. {@link CfgVertex#getType|getType()}) to work with vertices instead of directly accessing the properties.
|
|
11
20
|
*/
|
|
12
21
|
var CfgVertexType;
|
|
13
22
|
(function (CfgVertexType) {
|
|
14
|
-
/**
|
|
15
|
-
* The explicit exit-nodes to ensure the hammock property.
|
|
16
|
-
* @see {@link CfgVertex.makeMarker|CfgVertex.makeMarker()} - for a helper function to create end marker vertices
|
|
17
|
-
*/
|
|
18
|
-
CfgVertexType[CfgVertexType["Marker"] = 0] = "Marker";
|
|
19
23
|
/**
|
|
20
24
|
* something like an if, assignment, ... even though in the classical sense of R they are still expressions
|
|
21
25
|
* @see {@link CfgVertex.makeStatement|CfgVertex.makeStatement()} - for a helper function to create statement vertices
|
|
@@ -33,117 +37,49 @@ var CfgVertexType;
|
|
|
33
37
|
CfgVertexType[CfgVertexType["Block"] = 3] = "Block";
|
|
34
38
|
})(CfgVertexType || (exports.CfgVertexType = CfgVertexType = {}));
|
|
35
39
|
/**
|
|
36
|
-
* Helper object for {@link CfgVertex} - a vertex in the {@link ControlFlowGraph}
|
|
40
|
+
* Helper object for {@link CfgVertex} - a vertex in the {@link ControlFlowGraph}.
|
|
37
41
|
*/
|
|
38
42
|
exports.CfgVertex = {
|
|
39
43
|
name: 'CfgVertex',
|
|
40
44
|
/**
|
|
41
|
-
* Create a new expression vertex with the given id, children, call targets
|
|
45
|
+
* Create a new expression vertex with the given id, children, and call targets.
|
|
42
46
|
* @param id - the id of the vertex, which should directly relate to the AST node
|
|
43
47
|
* @param children - child nodes attached to this one
|
|
44
48
|
* @param callTargets - if the vertex calls a function, this links all targets of this call
|
|
45
|
-
* @param mid - the ids of the mid-markers attached to this vertex, which should directly relate to the AST nodes of the mid markers
|
|
46
|
-
* @param end - the ids of the end-markers attached to this vertex, which should directly relate to the AST nodes of the end markers
|
|
47
49
|
* @see {@link CfgVertex#isExpression|isExpression()} - for a way to check whether a vertex is an expression vertex
|
|
48
50
|
*/
|
|
49
|
-
makeExpression(id, { children,
|
|
51
|
+
makeExpression(id, { children, callTargets } = {}) {
|
|
50
52
|
if (children === undefined && callTargets === undefined) {
|
|
51
|
-
|
|
52
|
-
return [CfgVertexType.Expression, id];
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
return [CfgVertexType.Expression, id, mid, end];
|
|
56
|
-
}
|
|
53
|
+
return [CfgVertexType.Expression, id];
|
|
57
54
|
}
|
|
58
|
-
return [CfgVertexType.Expression, id,
|
|
59
|
-
},
|
|
60
|
-
/**
|
|
61
|
-
* A convenience function to create a new expression vertex with a canonical end marker ({@link CfgVertex#toExitId|toExitId()}) based on the given id and the given id as root id for the end marker.
|
|
62
|
-
* @param id - the id of the vertex, which should directly relate to the AST node
|
|
63
|
-
* @param children - child nodes attached to this one
|
|
64
|
-
* @param callTargets - if the vertex calls a function, this links all targets of this call
|
|
65
|
-
* @param mid - the ids of the mid-markers attached to this vertex, which should directly relate to the AST nodes of the mid markers
|
|
66
|
-
* @see {@link CfgVertex#makeExpression|makeExpression()} - for a way to create expression vertices with a custom end marker
|
|
67
|
-
* @see {@link CfgVertex#makeExitMarker|makeExitMarker()} - for a helper function to create end marker vertices with a canonical id#
|
|
68
|
-
* @see {@link CfgVertex#toExitId|toExitId()} - for a way to convert the given id to a canonical end marker id
|
|
69
|
-
*/
|
|
70
|
-
makeExpressionWithEnd(id, { children, mid, callTargets } = {}) {
|
|
71
|
-
return exports.CfgVertex.makeExpression(id, { children, mid, end: [exports.CfgVertex.toExitId(id)], callTargets });
|
|
55
|
+
return [CfgVertexType.Expression, id, children, callTargets];
|
|
72
56
|
},
|
|
73
57
|
/**
|
|
74
|
-
*
|
|
58
|
+
* Create a new statement vertex with the given id, children, and call targets.
|
|
75
59
|
* @param id - the id of the vertex, which should directly relate to the AST node
|
|
76
60
|
* @param children - child nodes attached to this one
|
|
77
61
|
* @param callTargets - if the vertex calls a function, this links all targets of this call
|
|
78
|
-
* @param mid - the ids of the mid-markers attached to this vertex, which should directly relate to the AST nodes of the mid markers
|
|
79
|
-
* @see {@link CfgVertex#makeExpression|makeExpression()} - for a way to create expression vertices with a custom end marker
|
|
80
|
-
* @see {@link CfgVertex#makeExitMarker|makeExitMarker()} - for a helper function to create end marker vertices with a canonical id#
|
|
81
|
-
* @see {@link CfgVertex#toExitId|toExitId()} - for a way to convert the given id to a canonical end marker id
|
|
82
|
-
*/
|
|
83
|
-
makeStatementWithEnd(id, { children, mid, callTargets } = {}) {
|
|
84
|
-
return exports.CfgVertex.makeStatement(id, { children, mid, end: [exports.CfgVertex.toExitId(id)], callTargets });
|
|
85
|
-
},
|
|
86
|
-
/**
|
|
87
|
-
* Create a new statement vertex with the given id, children, call targets, and markers.
|
|
88
|
-
* @param id - the id of the vertex, which should directly relate to the AST node
|
|
89
|
-
* @param children - child nodes attached to this one
|
|
90
|
-
* @param callTargets - if the vertex calls a function, this links all targets of this call
|
|
91
|
-
* @param mid - the ids of the mid-markers attached to this vertex, which should directly relate to the AST nodes of the mid markers
|
|
92
|
-
* @param end - the ids of the end-markers attached to this vertex, which should directly relate to the AST nodes of the end markers
|
|
93
62
|
* @see {@link CfgVertex#isStatement|isStatement()} - for a way to check whether a vertex is a statement vertex
|
|
94
63
|
*/
|
|
95
|
-
makeStatement(id, { children,
|
|
64
|
+
makeStatement(id, { children, callTargets } = {}) {
|
|
96
65
|
if (children === undefined && callTargets === undefined) {
|
|
97
|
-
|
|
98
|
-
return [CfgVertexType.Statement, id];
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
return [CfgVertexType.Statement, id, mid, end];
|
|
102
|
-
}
|
|
66
|
+
return [CfgVertexType.Statement, id];
|
|
103
67
|
}
|
|
104
|
-
return [CfgVertexType.Statement, id,
|
|
68
|
+
return [CfgVertexType.Statement, id, children, callTargets];
|
|
105
69
|
},
|
|
106
70
|
/**
|
|
107
71
|
* A convenience function to create a new vertex which is either a statement or an expression.
|
|
108
72
|
*/
|
|
109
|
-
makeExprOrStm(id, type, { children,
|
|
73
|
+
makeExprOrStm(id, type, { children, callTargets } = {}) {
|
|
110
74
|
if (children === undefined && callTargets === undefined) {
|
|
111
|
-
|
|
112
|
-
return [type, id];
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
return [type, id, mid, end];
|
|
116
|
-
}
|
|
75
|
+
return [type, id];
|
|
117
76
|
}
|
|
118
|
-
return [type, id,
|
|
77
|
+
return [type, id, children, callTargets];
|
|
119
78
|
},
|
|
120
79
|
/**
|
|
121
|
-
* Create a new
|
|
80
|
+
* Create a new basic block vertex with the given id and elements.
|
|
122
81
|
* @param id - the id of the vertex, which should directly relate to the AST node
|
|
123
|
-
* @param
|
|
124
|
-
* @see {@link CfgVertex#isMarker|isMarker()} - for a way to check whether a vertex is an end marker vertex
|
|
125
|
-
* @see {@link CfgVertex#getRootId|getRootId()} - for a way to get the root id of an end marker vertex
|
|
126
|
-
* @see {@link CfgVertex#makeExitMarker|makeExitMarker()} - for a helper function to create end marker vertices with a canonical id
|
|
127
|
-
*/
|
|
128
|
-
makeMarker(id, rootId) {
|
|
129
|
-
if (exports.CfgVertex.fromExitId(id) === rootId) {
|
|
130
|
-
return id;
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
return [CfgVertexType.Marker, id, rootId];
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
/**
|
|
137
|
-
* A convenience function to create a new marker vertex with a canonical id ({@link CfgVertex#toExitId|toExitId()}) based on the given id and the given id as root id.
|
|
138
|
-
* @see {@link CfgVertex#makeMarker|makeMarker()} - for a way to create end marker vertices with a custom id
|
|
139
|
-
*/
|
|
140
|
-
makeExitMarker(id) {
|
|
141
|
-
return exports.CfgVertex.toExitId(id);
|
|
142
|
-
},
|
|
143
|
-
/**
|
|
144
|
-
* Create a new basic block vertex with the given id, elements, children, and call targets.
|
|
145
|
-
* @param id - the id of the vertex, which should directly relate to the AST node
|
|
146
|
-
* @param elems - the vertices that are part of this block, only connected by FDs, vertices should never occur in multiple bbs
|
|
82
|
+
* @param elems - the vertices that are part of this block in the order they run, only connected by FDs; a vertex should never occur in multiple blocks
|
|
147
83
|
* @see {@link CfgVertex#isBlock|isBlock()} - for a way to check whether a vertex is a basic block vertex
|
|
148
84
|
*/
|
|
149
85
|
makeBlock(id, elems) {
|
|
@@ -155,7 +91,7 @@ exports.CfgVertex = {
|
|
|
155
91
|
* @see {@link CfgVertex#getType|getType()} - for a way to get the type of a vertex instead of checking against a given type
|
|
156
92
|
*/
|
|
157
93
|
isExpression(vertex) {
|
|
158
|
-
return
|
|
94
|
+
return vertex !== undefined && vertex[0] === CfgVertexType.Expression;
|
|
159
95
|
},
|
|
160
96
|
/**
|
|
161
97
|
* Check whether the given vertex is a statement vertex.
|
|
@@ -163,15 +99,7 @@ exports.CfgVertex = {
|
|
|
163
99
|
* @see {@link CfgVertex#getType|getType()} - for a way to get the type of a vertex instead of checking against a given type
|
|
164
100
|
*/
|
|
165
101
|
isStatement(vertex) {
|
|
166
|
-
return
|
|
167
|
-
},
|
|
168
|
-
/**
|
|
169
|
-
* Check whether the given vertex is an end marker vertex.
|
|
170
|
-
* @see {@link CfgVertex#makeMarker|makeMarker()} - for a way to create end marker vertices
|
|
171
|
-
* @see {@link CfgVertex#getType|getType()} - for a way to get the type of a vertex instead of checking against a given type
|
|
172
|
-
*/
|
|
173
|
-
isMarker(vertex) {
|
|
174
|
-
return vertex !== undefined && (!Array.isArray(vertex) || vertex[0] === CfgVertexType.Marker);
|
|
102
|
+
return vertex !== undefined && vertex[0] === CfgVertexType.Statement;
|
|
175
103
|
},
|
|
176
104
|
/**
|
|
177
105
|
* Check whether the given vertex is a basic block vertex.
|
|
@@ -179,21 +107,21 @@ exports.CfgVertex = {
|
|
|
179
107
|
* @see {@link CfgVertex#getType|getType()} - for a way to get the type of a vertex instead of checking against a given type
|
|
180
108
|
*/
|
|
181
109
|
isBlock(vertex) {
|
|
182
|
-
return
|
|
110
|
+
return vertex !== undefined && vertex[0] === CfgVertexType.Block;
|
|
183
111
|
},
|
|
184
112
|
/**
|
|
185
113
|
* Get the type of the given vertex.
|
|
186
114
|
* @example
|
|
187
115
|
* ```ts
|
|
188
|
-
* const vertex: CfgVertex = CfgVertex.
|
|
116
|
+
* const vertex: CfgVertex = CfgVertex.makeExpression('node-1')
|
|
189
117
|
* console.log(CfgVertex.getType(vertex)); // Output: CfgVertexType.Expression
|
|
190
118
|
* ```
|
|
191
|
-
* @see {@link CfgVertex#isExpression|isExpression()}, {@link CfgVertex#isStatement|isStatement()}, {@link CfgVertex#
|
|
119
|
+
* @see {@link CfgVertex#isExpression|isExpression()}, {@link CfgVertex#isStatement|isStatement()}, {@link CfgVertex#isBlock|isBlock()} - for ways to check the type of a vertex against a specific type
|
|
192
120
|
* @see {@link CfgVertex#getId|getId()} - for a way to get the id of a vertex
|
|
193
121
|
* @see {@link CfgVertex#typeToString|typeToString()} - for a way to convert the type of a vertex to a string for easier debugging and visualization
|
|
194
122
|
*/
|
|
195
123
|
getType(vertex) {
|
|
196
|
-
return
|
|
124
|
+
return vertex[0];
|
|
197
125
|
},
|
|
198
126
|
/**
|
|
199
127
|
* Convert the given vertex type to a string for easier debugging and visualization.
|
|
@@ -202,8 +130,6 @@ exports.CfgVertex = {
|
|
|
202
130
|
*/
|
|
203
131
|
typeToString(type) {
|
|
204
132
|
switch (type) {
|
|
205
|
-
case CfgVertexType.Marker:
|
|
206
|
-
return 'marker';
|
|
207
133
|
case CfgVertexType.Statement:
|
|
208
134
|
return 'statement';
|
|
209
135
|
case CfgVertexType.Expression:
|
|
@@ -215,27 +141,22 @@ exports.CfgVertex = {
|
|
|
215
141
|
}
|
|
216
142
|
},
|
|
217
143
|
/**
|
|
218
|
-
* Get the id of the given vertex, which
|
|
144
|
+
* Get the id of the given vertex, which directly relates to the AST node.
|
|
219
145
|
* @example
|
|
220
146
|
* ```ts
|
|
221
|
-
* const vertex: CfgVertex = CfgVertex.
|
|
147
|
+
* const vertex: CfgVertex = CfgVertex.makeExpression('node-1')
|
|
222
148
|
* console.log(CfgVertex.getId(vertex)); // Output: 'node-1'
|
|
223
149
|
* ```
|
|
224
150
|
* @see {@link CfgVertex#getType|getType()} - for a way to get the type of a vertex
|
|
225
|
-
* @see {@link CfgVertex#getRootId|getRootId()} - for a way to get the root id of a vertex
|
|
226
151
|
*/
|
|
227
152
|
getId(vertex) {
|
|
228
|
-
|
|
229
|
-
return id;
|
|
153
|
+
return (vertex === undefined ? undefined : vertex[1]);
|
|
230
154
|
},
|
|
231
155
|
/**
|
|
232
156
|
* Check whether two vertices are equal, i.e., they have the same type, id, and if they are basic block vertices, they also have the same elements in the same order.
|
|
233
157
|
*/
|
|
234
158
|
equal(a, b) {
|
|
235
|
-
if (
|
|
236
|
-
return a === b;
|
|
237
|
-
}
|
|
238
|
-
else if (a === b) {
|
|
159
|
+
if (a === b) {
|
|
239
160
|
return true;
|
|
240
161
|
}
|
|
241
162
|
else if (a[0] !== b[0] || a[1] !== b[1]) {
|
|
@@ -244,26 +165,8 @@ exports.CfgVertex = {
|
|
|
244
165
|
else if (a[0] === CfgVertexType.Block && b[0] === CfgVertexType.Block) {
|
|
245
166
|
return a[2].length === b[2].length && a[2].every((e, i) => exports.CfgVertex.equal(e, b[2][i]));
|
|
246
167
|
}
|
|
247
|
-
else if (a[0] === CfgVertexType.Marker && b[0] === CfgVertexType.Marker) {
|
|
248
|
-
return a[2] === b[2];
|
|
249
|
-
}
|
|
250
168
|
return true;
|
|
251
169
|
},
|
|
252
|
-
/**
|
|
253
|
-
* Get the root id of a vertex, i.e., the id of the AST node it corresponds to.
|
|
254
|
-
* For normal vertices, this is the same as the id of the vertex itself, for end marker vertices, this is the root id stored in the vertex.
|
|
255
|
-
* @see {@link CfgVertex#unpackRoot|unpackRoot()} - for a way to unpack the root id of a marker vertex
|
|
256
|
-
*/
|
|
257
|
-
getRootId(vertex) {
|
|
258
|
-
return exports.CfgVertex.isMarker(vertex) ? exports.CfgVertex.unpackRootId(vertex) : vertex[1];
|
|
259
|
-
},
|
|
260
|
-
/**
|
|
261
|
-
* Unpack the root id of a marker vertex, i.e., get the root id stored in the vertex or derive it from the canonical id if it is not explicitly stored.
|
|
262
|
-
* @see {@link CfgVertex#getRootId|getRootId()} - for a way to get the root id of a vertex, which uses this function for marker vertices
|
|
263
|
-
*/
|
|
264
|
-
unpackRootId(vertex) {
|
|
265
|
-
return Array.isArray(vertex) ? vertex[2] ?? exports.CfgVertex.fromExitId(vertex[1]) : exports.CfgVertex.fromExitId(vertex);
|
|
266
|
-
},
|
|
267
170
|
/**
|
|
268
171
|
* Get the elements of a basic block vertex, i.e., the vertices that are part of this block, only connected by FDs, vertices should never occur in multiple bbs.
|
|
269
172
|
* @see {@link CfgVertex#isBlock|isBlock()} - for a way to check whether a vertex is a basic block vertex before trying to get the elements
|
|
@@ -281,51 +184,6 @@ exports.CfgVertex = {
|
|
|
281
184
|
setBasicBlockElements(vertex, elems) {
|
|
282
185
|
vertex[2] = elems;
|
|
283
186
|
},
|
|
284
|
-
/**
|
|
285
|
-
* Get the ids of the mid-markers attached to this vertex, which should directly relate to the AST nodes of the mid markers.
|
|
286
|
-
* @see {@link CfgVertex#getMid|getMid()} - for a way to get the ids of the mid-markers attached to this vertex
|
|
287
|
-
* @see {@link CfgVertex#setEnd|setEnd()} - for a way to set the ids of the end-markers attached to this vertex
|
|
288
|
-
*/
|
|
289
|
-
getEnd(vertex) {
|
|
290
|
-
if (vertex === undefined) {
|
|
291
|
-
return undefined;
|
|
292
|
-
}
|
|
293
|
-
const type = exports.CfgVertex.getType(vertex);
|
|
294
|
-
if (type === CfgVertexType.Statement || type === CfgVertexType.Expression) {
|
|
295
|
-
return vertex[3];
|
|
296
|
-
}
|
|
297
|
-
return undefined;
|
|
298
|
-
},
|
|
299
|
-
/**
|
|
300
|
-
* **Sets in-place**
|
|
301
|
-
* Set the ids of the end-markers attached to this vertex, which should directly relate to the AST nodes of the end markers.
|
|
302
|
-
* @see {@link CfgVertex#getEnd|getEnd()} - for a way to get the ids of the end-markers attached to this vertex
|
|
303
|
-
*/
|
|
304
|
-
setEnd(vertex, endMarkers) {
|
|
305
|
-
vertex[3] = endMarkers;
|
|
306
|
-
},
|
|
307
|
-
/**
|
|
308
|
-
* Get the ids of the mid-markers attached to this vertex, which should directly relate to the AST nodes of the mid markers.
|
|
309
|
-
*/
|
|
310
|
-
getMid(vertex) {
|
|
311
|
-
if (vertex === undefined) {
|
|
312
|
-
return undefined;
|
|
313
|
-
}
|
|
314
|
-
const type = exports.CfgVertex.getType(vertex);
|
|
315
|
-
if (type === CfgVertexType.Statement || type === CfgVertexType.Expression) {
|
|
316
|
-
return vertex[2];
|
|
317
|
-
}
|
|
318
|
-
return undefined;
|
|
319
|
-
},
|
|
320
|
-
/**
|
|
321
|
-
* **Sets in-place**
|
|
322
|
-
* Set the ids of the mid-markers attached to this vertex, which should directly relate to the AST nodes of the mid markers.
|
|
323
|
-
* @see {@link CfgVertex#getMid|getMid()} - for a way to get the ids of the mid-markers attached to this vertex
|
|
324
|
-
* @see {@link CfgVertex#setEnd|setEnd()} - for a way to set the ids of the end-markers attached to this vertex
|
|
325
|
-
*/
|
|
326
|
-
setMid(vertex, midMarkers) {
|
|
327
|
-
vertex[2] = midMarkers;
|
|
328
|
-
},
|
|
329
187
|
/**
|
|
330
188
|
* Converts the given id to a, canonical, basic block lift (i.e., it adds 'bb-' as a prefix).
|
|
331
189
|
*/
|
|
@@ -333,68 +191,22 @@ exports.CfgVertex = {
|
|
|
333
191
|
return `bb-${id}`;
|
|
334
192
|
},
|
|
335
193
|
/**
|
|
336
|
-
*
|
|
337
|
-
* @see {@link CfgVertex#fromExitId|fromExitId()} - for a way to convert the given id from a canonical end marker lift to the original id (i.e., it removes '-end' as a suffix if it is present)
|
|
338
|
-
*/
|
|
339
|
-
toExitId(id) {
|
|
340
|
-
return `${id}-e`;
|
|
341
|
-
},
|
|
342
|
-
/**
|
|
343
|
-
* Converts the given id from a canonical end marker lift to the original id (i.e., it removes '-end' as a suffix if it is present).
|
|
344
|
-
* @see {@link CfgVertex#toExitId|toExitId()} - for a way to convert the given id to a canonical end marker lift (i.e., it adds '-end' as a suffix)
|
|
345
|
-
*/
|
|
346
|
-
fromExitId(exitId) {
|
|
347
|
-
if (typeof exitId === 'string' && exitId.endsWith('-e')) {
|
|
348
|
-
return node_id_1.NodeId.normalize(exitId.slice(0, -2));
|
|
349
|
-
}
|
|
350
|
-
else {
|
|
351
|
-
return exitId;
|
|
352
|
-
}
|
|
353
|
-
},
|
|
354
|
-
/**
|
|
355
|
-
* Get the call targets of a statement or expression vertex, which links all targets of this call.
|
|
194
|
+
* The functions a call may dispatch to, taken from the `calls` edges the dataflow analysis resolved.
|
|
356
195
|
*/
|
|
357
196
|
getCallTargets(vertex) {
|
|
358
|
-
if (vertex === undefined) {
|
|
197
|
+
if (vertex === undefined || vertex[0] === CfgVertexType.Block) {
|
|
359
198
|
return undefined;
|
|
360
199
|
}
|
|
361
|
-
|
|
362
|
-
if (type === CfgVertexType.Statement || type === CfgVertexType.Expression) {
|
|
363
|
-
return vertex[5];
|
|
364
|
-
}
|
|
365
|
-
return undefined;
|
|
366
|
-
},
|
|
367
|
-
/**
|
|
368
|
-
* **Sets in-place**
|
|
369
|
-
* Set the call targets of a statement or expression vertex, which links all targets of this call.
|
|
370
|
-
* @see {@link CfgVertex#getCallTargets|getCallTargets()} - for a way to get the call targets of a statement or expression vertex
|
|
371
|
-
* @see {@link CfgVertex#mapCallTargets|mapCallTargets()} - for a way to map the call targets of a statement or expression vertex to new call targets
|
|
372
|
-
*/
|
|
373
|
-
setCallTargets(vertex, callTargets) {
|
|
374
|
-
vertex[5] = callTargets;
|
|
375
|
-
},
|
|
376
|
-
/**
|
|
377
|
-
* Map the call targets of a statement or expression vertex, which links all targets of this call, to new call targets using the given mapping function.
|
|
378
|
-
* @see {@link CfgVertex#getCallTargets|getCallTargets()} - for a way to get the call targets of a statement or expression vertex
|
|
379
|
-
* @see {@link CfgVertex#setCallTargets|setCallTargets()} - for a way to set the call targets of a statement or expression vertex to new call targets
|
|
380
|
-
*/
|
|
381
|
-
mapCallTargets(vertex, mapFn) {
|
|
382
|
-
const currentTargets = exports.CfgVertex.getCallTargets(vertex);
|
|
383
|
-
const newTargets = mapFn(currentTargets);
|
|
384
|
-
exports.CfgVertex.setCallTargets(vertex, newTargets);
|
|
200
|
+
return (vertex)[3];
|
|
385
201
|
},
|
|
386
202
|
/**
|
|
387
203
|
* Get the children of a statement or expression vertex, i.e., the child nodes attached to this one.
|
|
388
204
|
*/
|
|
389
205
|
getChildren(vertex) {
|
|
390
|
-
if (vertex === undefined) {
|
|
206
|
+
if (vertex === undefined || vertex[0] === CfgVertexType.Block) {
|
|
391
207
|
return undefined;
|
|
392
208
|
}
|
|
393
|
-
|
|
394
|
-
if (type === CfgVertexType.Statement || type === CfgVertexType.Expression) {
|
|
395
|
-
return vertex[4];
|
|
396
|
-
}
|
|
397
|
-
return undefined;
|
|
209
|
+
return (vertex)[2];
|
|
398
210
|
}
|
|
399
211
|
};
|
|
400
212
|
/**
|
|
@@ -406,29 +218,28 @@ exports.CfgEdge = {
|
|
|
406
218
|
* Check whether the given edge is a flow dependency edge.
|
|
407
219
|
*/
|
|
408
220
|
isFlowDependency(edge) {
|
|
409
|
-
return edge === 0 /* CfgEdgeType.
|
|
221
|
+
return edge === 0 /* CfgEdgeType.Flow */;
|
|
410
222
|
},
|
|
411
223
|
/**
|
|
412
224
|
* Check whether the given edge is a control dependency edge.
|
|
413
225
|
*/
|
|
414
226
|
isControlDependency(edge) {
|
|
415
|
-
return
|
|
227
|
+
return typeof edge === 'object';
|
|
416
228
|
},
|
|
417
229
|
/**
|
|
418
230
|
* Create a flow dependency edge.
|
|
419
231
|
*/
|
|
420
232
|
makeFd() {
|
|
421
|
-
return 0 /* CfgEdgeType.
|
|
233
|
+
return 0 /* CfgEdgeType.Flow */;
|
|
422
234
|
},
|
|
423
235
|
/**
|
|
424
|
-
* Create a control dependency edge
|
|
425
|
-
* @param
|
|
426
|
-
* @
|
|
427
|
-
* @see {@link CfgEdge#
|
|
428
|
-
* @see {@link CfgEdge#makeCdFalse|makeCdFalse()} - for a version of this function that assumes the control dependency is negated (e.g., else-branch)
|
|
236
|
+
* Create a control dependency edge from the given control dependency, which is what the edge is.
|
|
237
|
+
* @param cd - the decision the edge follows, i.e. the vertex that causes it and the outcome it takes
|
|
238
|
+
* @see {@link CfgEdge#makeCdTrue|makeCdTrue()} - to build one for a true condition from the causing id alone
|
|
239
|
+
* @see {@link CfgEdge#makeCdFalse|makeCdFalse()} - to build one for a negated condition (e.g., else-branch)
|
|
429
240
|
*/
|
|
430
|
-
makeCd(
|
|
431
|
-
return
|
|
241
|
+
makeCd(cd) {
|
|
242
|
+
return cd;
|
|
432
243
|
},
|
|
433
244
|
/**
|
|
434
245
|
* Create a control dependency edge with the given cause and a true condition.
|
|
@@ -436,7 +247,7 @@ exports.CfgEdge = {
|
|
|
436
247
|
* @see {@link CfgEdge#makeCd|makeCd()} - for a version of this function that allows to specify the condition as well
|
|
437
248
|
*/
|
|
438
249
|
makeCdTrue(controlId) {
|
|
439
|
-
return
|
|
250
|
+
return { id: controlId, when: true };
|
|
440
251
|
},
|
|
441
252
|
/**
|
|
442
253
|
* Create a control dependency edge with the given cause and a negated condition (e.g., else-branch).
|
|
@@ -444,7 +255,7 @@ exports.CfgEdge = {
|
|
|
444
255
|
* @see {@link CfgEdge#makeCd|makeCd()} - for a version of this function that allows to specify the condition as well
|
|
445
256
|
*/
|
|
446
257
|
makeCdFalse(controlId) {
|
|
447
|
-
return
|
|
258
|
+
return { id: controlId, when: false };
|
|
448
259
|
},
|
|
449
260
|
/**
|
|
450
261
|
* Get the cause of a control dependency edge, i.e., the id of the vertex that causes the control dependency.
|
|
@@ -455,7 +266,7 @@ exports.CfgEdge = {
|
|
|
455
266
|
*/
|
|
456
267
|
getCause(edge) {
|
|
457
268
|
if (exports.CfgEdge.isControlDependency(edge)) {
|
|
458
|
-
return edge
|
|
269
|
+
return edge.id;
|
|
459
270
|
}
|
|
460
271
|
else {
|
|
461
272
|
return undefined;
|
|
@@ -465,7 +276,7 @@ exports.CfgEdge = {
|
|
|
465
276
|
* Get the cause of a control dependency edge, i.e., the id of the vertex that causes the control dependency.
|
|
466
277
|
*/
|
|
467
278
|
unpackCause(edge) {
|
|
468
|
-
return edge
|
|
279
|
+
return edge.id;
|
|
469
280
|
},
|
|
470
281
|
/**
|
|
471
282
|
* Get whether the control dependency edge is satisfied with a true condition or is it negated (e.g., else-branch).
|
|
@@ -476,7 +287,7 @@ exports.CfgEdge = {
|
|
|
476
287
|
*/
|
|
477
288
|
getWhen(edge) {
|
|
478
289
|
if (exports.CfgEdge.isControlDependency(edge)) {
|
|
479
|
-
return edge
|
|
290
|
+
return edge.when ? convert_values_1.RTrue : convert_values_1.RFalse;
|
|
480
291
|
}
|
|
481
292
|
else {
|
|
482
293
|
return undefined;
|
|
@@ -486,7 +297,7 @@ exports.CfgEdge = {
|
|
|
486
297
|
* Get whether the control dependency edge is satisfied with a true condition or is it negated (e.g., else-branch).
|
|
487
298
|
*/
|
|
488
299
|
unpackWhen(edge) {
|
|
489
|
-
return edge
|
|
300
|
+
return edge.when ? convert_values_1.RTrue : convert_values_1.RFalse;
|
|
490
301
|
},
|
|
491
302
|
/**
|
|
492
303
|
* Check whether two edges are equal.
|
|
@@ -496,7 +307,7 @@ exports.CfgEdge = {
|
|
|
496
307
|
return true;
|
|
497
308
|
}
|
|
498
309
|
else if (exports.CfgEdge.isControlDependency(a) && exports.CfgEdge.isControlDependency(b)) {
|
|
499
|
-
return a
|
|
310
|
+
return info_1.ControlDependency.same(a, b) && a.byIteration === b.byIteration;
|
|
500
311
|
}
|
|
501
312
|
return false;
|
|
502
313
|
},
|
|
@@ -512,60 +323,133 @@ exports.CfgEdge = {
|
|
|
512
323
|
* @see {@link CfgEdge#isOfType|isOfType()} - for a version of this function that checks whether the edge is of a given type
|
|
513
324
|
*/
|
|
514
325
|
getType(edge) {
|
|
515
|
-
return exports.CfgEdge.isFlowDependency(edge) ? 0 /* CfgEdgeType.
|
|
326
|
+
return exports.CfgEdge.isFlowDependency(edge) ? 0 /* CfgEdgeType.Flow */ : 1 /* CfgEdgeType.Control */;
|
|
516
327
|
},
|
|
517
328
|
/**
|
|
518
329
|
* Provide a string representation of the given edge, e.g., for debugging or visualization purposes.
|
|
519
330
|
* @see {@link CfgEdge#toString|toString()} - for a version of this function that also includes the details of the edge (e.g., cause and condition for control dependency edges)
|
|
520
331
|
*/
|
|
521
332
|
typeToString(edge) {
|
|
522
|
-
|
|
523
|
-
return 'FD';
|
|
524
|
-
}
|
|
525
|
-
else {
|
|
526
|
-
return 'CD';
|
|
527
|
-
}
|
|
333
|
+
return exports.CfgEdge.isFlowDependency(edge) ? 'flows to' : 'branches to';
|
|
528
334
|
},
|
|
529
335
|
/**
|
|
530
336
|
* Provide a string representation of the given edge, including its details (e.g., cause and condition for control dependency edges), e.g., for debugging or visualization purposes.
|
|
531
337
|
* @see {@link CfgEdge#typeToString|typeToString()} - for a version of this function that only includes the type of the edge
|
|
532
338
|
*/
|
|
533
339
|
toString(edge) {
|
|
534
|
-
|
|
535
|
-
return 'FD';
|
|
536
|
-
}
|
|
537
|
-
else {
|
|
538
|
-
return `CD(${edge[0]}, ${edge[1] === convert_values_1.RTrue ? 'T' : 'F'})`;
|
|
539
|
-
}
|
|
340
|
+
return exports.CfgEdge.isFlowDependency(edge) ? 'flows to' : `branch on ${edge.id} if ${edge.when ? 'T' : 'F'}`;
|
|
540
341
|
}
|
|
541
342
|
};
|
|
343
|
+
/** Shared empty result so navigating a vertex without neighbors allocates nothing. */
|
|
344
|
+
exports.NoNeighbors = [];
|
|
542
345
|
/**
|
|
543
346
|
* This class represents the control flow graph of an R program.
|
|
544
|
-
* The control flow may be hierarchical when confronted with function definitions (see {@link CfgVertex} and {@link
|
|
347
|
+
* The control flow may be hierarchical when confronted with function definitions (see {@link CfgVertex} and {@link ControlFlowGraph#rootIds|rootIds()}).
|
|
348
|
+
*
|
|
349
|
+
* Edges are in flow order: an edge from `a` to `b` means that `b` is evaluated after `a`.
|
|
350
|
+
* Reading them backwards (what leads into a vertex) goes through a reverse index built on the first such read.
|
|
545
351
|
*
|
|
546
352
|
* There are two very simple visitors to traverse a CFG:
|
|
547
|
-
* - {@link visitCfgInOrder} visits
|
|
548
|
-
* - {@link visitCfgInReverseOrder} visits
|
|
353
|
+
* - {@link visitCfgInOrder} visits it in the order the program runs
|
|
354
|
+
* - {@link visitCfgInReverseOrder} visits it in the opposite order
|
|
549
355
|
*
|
|
550
356
|
* If you want to prohibit modification, please refer to the {@link ReadOnlyControlFlowGraph} interface.
|
|
551
357
|
*/
|
|
552
358
|
class ControlFlowGraph {
|
|
359
|
+
/**
|
|
360
|
+
* The dataflow graph this control flow graph is a view on, if it is one.
|
|
361
|
+
* Reads are answered from it directly; the state below is only filled in when the graph is modified
|
|
362
|
+
* (see {@link ControlFlowGraph#materialize|materialize()}).
|
|
363
|
+
*/
|
|
364
|
+
dfg;
|
|
365
|
+
/** whether the state below has been filled in from {@link ControlFlowGraph#dfg|dfg} already */
|
|
366
|
+
projected = false;
|
|
367
|
+
/** the root ids of a view, which stay the same as long as it is one */
|
|
368
|
+
rootCache;
|
|
553
369
|
roots = new Set();
|
|
554
370
|
/** Nesting-Independent vertex information, mapping the id to the vertex */
|
|
555
371
|
vtxInfos = new Map();
|
|
556
372
|
/** the basic block children map contains a mapping of ids to all vertices that are nested in basic blocks, mapping them to the Id of the block they appear in */
|
|
557
373
|
bbChildren = new Map();
|
|
558
|
-
/** basic block agnostic edges */
|
|
374
|
+
/** basic block agnostic edges, in flow order: `edgeInfos[a][b]` means that `b` is evaluated after `a` */
|
|
559
375
|
edgeInfos = new Map();
|
|
560
376
|
/** reverse edges for bidirectional mapping, derived from `edgeInfos` on the first ingoing lookup */
|
|
561
377
|
revEdgeInfos;
|
|
562
378
|
/** used as an optimization to avoid unnecessary lookups */
|
|
563
379
|
_mayBB = false;
|
|
380
|
+
/**
|
|
381
|
+
* A control flow graph either owns its vertices and edges, or is a view on the {@link DataflowGraph} that
|
|
382
|
+
* carries them: the dataflow extraction records the control flow while it walks the program, so every
|
|
383
|
+
* vertex of that graph is a vertex here and its {@link EdgeType.FlowEdge|flow} and
|
|
384
|
+
* {@link EdgeType.ControlEdge|control} dependency edges are the edges here.
|
|
385
|
+
* @param dfg - the dataflow graph to view, or nothing to build a graph of your own
|
|
386
|
+
*/
|
|
387
|
+
constructor(dfg) {
|
|
388
|
+
/* without the AST there is no way to tell a vertex of the program from one the analysis synthesized */
|
|
389
|
+
(0, assert_1.guard)(dfg === undefined || dfg.idMap !== undefined, 'a control flow graph can only view a dataflow graph that knows its AST');
|
|
390
|
+
this.dfg = dfg;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Fill the state of this graph from the dataflow graph it views.
|
|
394
|
+
* Reading a view does not need this — the reads below are answered from the dataflow graph — but
|
|
395
|
+
* modifying one does, and so does asking for every vertex or edge at once.
|
|
396
|
+
*/
|
|
397
|
+
materialize() {
|
|
398
|
+
if (this.dfg === undefined || this.projected) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
/* set first so that anything the projection itself asks of this graph does not re-enter it */
|
|
402
|
+
this.projected = true;
|
|
403
|
+
for (const [id] of this.dfg.vertices(true)) {
|
|
404
|
+
if (!isControlFlowVertex(this.dfg, id)) {
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
this.vtxInfos.set(id, makeCfgVertex(this.dfg, id));
|
|
408
|
+
if (this.dfg.isRoot(id)) {
|
|
409
|
+
this.roots.add(id);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
/* both graphs record the control flow in the order it runs, so the edges carry straight over */
|
|
413
|
+
for (const [from, targets] of this.dfg.edges()) {
|
|
414
|
+
for (const [to, edge] of targets) {
|
|
415
|
+
const cfgEdge = toCfgEdge(edge);
|
|
416
|
+
if (cfgEdge === undefined) {
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
const after = this.edgeInfos.get(from);
|
|
420
|
+
if (after === undefined) {
|
|
421
|
+
this.edgeInfos.set(from, new Map([[to, cfgEdge]]));
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
after.set(to, cfgEdge);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Serializing a graph hands out its vertices and edges, never the dataflow graph a view reads them from,
|
|
431
|
+
* so a view and a graph of its own serialize alike.
|
|
432
|
+
*/
|
|
433
|
+
toJSON() {
|
|
434
|
+
this.materialize();
|
|
435
|
+
return {
|
|
436
|
+
roots: this.roots,
|
|
437
|
+
vtxInfos: this.vtxInfos,
|
|
438
|
+
bbChildren: this.bbChildren,
|
|
439
|
+
edgeInfos: this.edgeInfos,
|
|
440
|
+
mayHaveBasicBlocks: this._mayBB
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
/** Whether this graph still answers from the dataflow graph it views instead of a copy of it. */
|
|
444
|
+
get isView() {
|
|
445
|
+
return this.dfg !== undefined && !this.projected;
|
|
446
|
+
}
|
|
564
447
|
/**
|
|
565
448
|
* Add a new vertex to the control flow graph.
|
|
566
449
|
* @see {@link ControlFlowGraph#addEdge|addEdge()} - to add an edge
|
|
567
450
|
*/
|
|
568
451
|
addVertex(vertex, rootVertex = true) {
|
|
452
|
+
this.materialize();
|
|
569
453
|
const vid = exports.CfgVertex.getId(vertex);
|
|
570
454
|
if (exports.CfgVertex.isBlock(vertex)) {
|
|
571
455
|
this._mayBB = true;
|
|
@@ -587,11 +471,12 @@ class ControlFlowGraph {
|
|
|
587
471
|
return this;
|
|
588
472
|
}
|
|
589
473
|
/**
|
|
590
|
-
* Add a new edge to the control flow graph
|
|
474
|
+
* Add a new edge to the control flow graph, in flow order: `to` is evaluated after `from`.
|
|
591
475
|
* @see {@link ControlFlowGraph#addVertex|addVertex()} - to add vertices
|
|
592
476
|
* @see {@link ControlFlowGraph#addEdges|addEdges()} - to add multiple edges at once
|
|
593
477
|
*/
|
|
594
478
|
addEdge(from, to, edge) {
|
|
479
|
+
this.materialize();
|
|
595
480
|
const edgesFrom = this.edgeInfos.get(from);
|
|
596
481
|
if (!edgesFrom) {
|
|
597
482
|
this.edgeInfos.set(from, new Map([[to, edge]]));
|
|
@@ -631,21 +516,41 @@ class ControlFlowGraph {
|
|
|
631
516
|
* Add multiple edges from a given source vertex to the control flow graph.
|
|
632
517
|
*/
|
|
633
518
|
addEdges(from, to) {
|
|
519
|
+
this.materialize();
|
|
634
520
|
for (const [toNode, edge] of to) {
|
|
635
521
|
this.addEdge(from, toNode, edge);
|
|
636
522
|
}
|
|
637
523
|
return this;
|
|
638
524
|
}
|
|
639
525
|
outgoingEdges(node) {
|
|
526
|
+
if (this.isView) {
|
|
527
|
+
return controlFlowEdges(this.dfg.outgoingEdges(node));
|
|
528
|
+
}
|
|
640
529
|
return this.edgeInfos.get(node);
|
|
641
530
|
}
|
|
642
531
|
ingoingEdges(node) {
|
|
532
|
+
if (this.isView) {
|
|
533
|
+
return controlFlowEdges(this.dfg.ingoingEdges(node));
|
|
534
|
+
}
|
|
643
535
|
return this.reverse().get(node);
|
|
644
536
|
}
|
|
645
537
|
rootIds() {
|
|
538
|
+
if (this.isView) {
|
|
539
|
+
const dfg = this.dfg;
|
|
540
|
+
if (this.rootCache === undefined) {
|
|
541
|
+
this.rootCache = new Set();
|
|
542
|
+
for (const id of dfg.rootIds()) {
|
|
543
|
+
if (isControlFlowVertex(dfg, id)) {
|
|
544
|
+
this.rootCache.add(id);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return this.rootCache;
|
|
549
|
+
}
|
|
646
550
|
return this.roots;
|
|
647
551
|
}
|
|
648
552
|
vertices(includeBasicBlockElements = true) {
|
|
553
|
+
this.materialize();
|
|
649
554
|
if (includeBasicBlockElements) {
|
|
650
555
|
const all = new Map(this.vtxInfos);
|
|
651
556
|
for (const [id, block] of this.bbChildren.entries()) {
|
|
@@ -666,6 +571,9 @@ class ControlFlowGraph {
|
|
|
666
571
|
}
|
|
667
572
|
}
|
|
668
573
|
getBasicBlock(elemId) {
|
|
574
|
+
if (this.isView) {
|
|
575
|
+
return undefined;
|
|
576
|
+
}
|
|
669
577
|
const block = this.bbChildren.get(elemId);
|
|
670
578
|
if (block === undefined) {
|
|
671
579
|
return undefined;
|
|
@@ -677,12 +585,17 @@ class ControlFlowGraph {
|
|
|
677
585
|
return blockVertex;
|
|
678
586
|
}
|
|
679
587
|
edges() {
|
|
588
|
+
this.materialize();
|
|
680
589
|
return this.edgeInfos;
|
|
681
590
|
}
|
|
682
591
|
/**
|
|
683
592
|
* Retrieve a vertex by its id.
|
|
684
593
|
*/
|
|
685
594
|
getVertex(id, includeBlocks = true) {
|
|
595
|
+
if (this.isView) {
|
|
596
|
+
const dfg = this.dfg;
|
|
597
|
+
return isControlFlowVertex(dfg, id) ? makeCfgVertex(dfg, id) : undefined;
|
|
598
|
+
}
|
|
686
599
|
const res = this.vtxInfos.get(id);
|
|
687
600
|
if (res || !includeBlocks) {
|
|
688
601
|
return res;
|
|
@@ -699,10 +612,75 @@ class ControlFlowGraph {
|
|
|
699
612
|
return elems.find(e => exports.CfgVertex.getId(e) === id);
|
|
700
613
|
}
|
|
701
614
|
hasVertex(id, includeBlocks = true) {
|
|
615
|
+
if (this.isView) {
|
|
616
|
+
return isControlFlowVertex(this.dfg, id);
|
|
617
|
+
}
|
|
702
618
|
return this.vtxInfos.has(id) || (this._mayBB && includeBlocks && this.bbChildren.has(id));
|
|
703
619
|
}
|
|
704
620
|
mayHaveBasicBlocks() {
|
|
705
|
-
|
|
621
|
+
/* a view has none; only the pass that introduces them creates any, and modifying projects first */
|
|
622
|
+
return !this.isView && this._mayBB;
|
|
623
|
+
}
|
|
624
|
+
dataflow() {
|
|
625
|
+
return this.isView ? this.dfg : undefined;
|
|
626
|
+
}
|
|
627
|
+
childrenOf(id) {
|
|
628
|
+
if (this.isView) {
|
|
629
|
+
const vertex = this.dfg.getVertex(id);
|
|
630
|
+
return vertex_1.FunctionDefinitionVertex.is(vertex) ? bodyOf(vertex) : undefined;
|
|
631
|
+
}
|
|
632
|
+
return exports.CfgVertex.getChildren(this.getVertex(id));
|
|
633
|
+
}
|
|
634
|
+
decides(id) {
|
|
635
|
+
let result = undefined;
|
|
636
|
+
for (const [, edge] of this.outgoingEdges(id) ?? graph_1.NoEdges) {
|
|
637
|
+
if (exports.CfgEdge.isControlDependency(edge) && !result?.includes(edge.id)) {
|
|
638
|
+
(result ??= []).push(edge.id);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
return result ?? exports.NoNeighbors;
|
|
642
|
+
}
|
|
643
|
+
exitOf(id) {
|
|
644
|
+
/* everything the construct is made of runs before it, so the construct is over on its own vertex */
|
|
645
|
+
return id;
|
|
646
|
+
}
|
|
647
|
+
entryOf(id, idMap = this.dfg?.idMap) {
|
|
648
|
+
const node = idMap?.get(id);
|
|
649
|
+
if (node === undefined) {
|
|
650
|
+
return this.hasVertex(id) ? id : undefined;
|
|
651
|
+
}
|
|
652
|
+
/* the construct starts at the one vertex within it that nothing inside it leads to */
|
|
653
|
+
const within = model_1.RNode.collectAllIds(node);
|
|
654
|
+
let entry = undefined;
|
|
655
|
+
for (const candidate of within) {
|
|
656
|
+
if (!this.hasVertex(candidate)) {
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
let reachedFromWithin = false;
|
|
660
|
+
for (const previous of this.predecessors(candidate)) {
|
|
661
|
+
if (within.has(previous)) {
|
|
662
|
+
reachedFromWithin = true;
|
|
663
|
+
break;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
if (!reachedFromWithin) {
|
|
667
|
+
entry = candidate;
|
|
668
|
+
break;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return entry;
|
|
672
|
+
}
|
|
673
|
+
successors(id) {
|
|
674
|
+
if (this.isView) {
|
|
675
|
+
return controlFlowNeighbors(this.dfg.outgoingEdges(id));
|
|
676
|
+
}
|
|
677
|
+
return this.edgeInfos.get(id)?.keys() ?? exports.NoNeighbors;
|
|
678
|
+
}
|
|
679
|
+
predecessors(id) {
|
|
680
|
+
if (this.isView) {
|
|
681
|
+
return controlFlowNeighbors(this.dfg.ingoingEdges(id));
|
|
682
|
+
}
|
|
683
|
+
return this.reverse().get(id)?.keys() ?? exports.NoNeighbors;
|
|
706
684
|
}
|
|
707
685
|
/**
|
|
708
686
|
* This removes the vertex and all edges to and from it.
|
|
@@ -711,6 +689,7 @@ class ControlFlowGraph {
|
|
|
711
689
|
* @see {@link ControlFlowGraph#removeEdge|removeEdge()} - to remove a specific edge
|
|
712
690
|
*/
|
|
713
691
|
removeVertex(id) {
|
|
692
|
+
this.materialize();
|
|
714
693
|
const rev = this.reverse();
|
|
715
694
|
for (const to of this.edgeInfos.get(id)?.keys() ?? []) {
|
|
716
695
|
rev.get(to)?.delete(id);
|
|
@@ -737,6 +716,7 @@ class ControlFlowGraph {
|
|
|
737
716
|
* @see {@link ControlFlowGraph#removeVertex|removeVertex()} - to remove a vertex and all its edges
|
|
738
717
|
*/
|
|
739
718
|
removeEdge(from, to) {
|
|
719
|
+
this.materialize();
|
|
740
720
|
const edgesFrom = this.edgeInfos.get(from);
|
|
741
721
|
if (edgesFrom) {
|
|
742
722
|
edgesFrom.delete(to);
|
|
@@ -755,6 +735,7 @@ class ControlFlowGraph {
|
|
|
755
735
|
}
|
|
756
736
|
/** merges b into a */
|
|
757
737
|
mergeTwoBasicBlocks(a, b) {
|
|
738
|
+
this.materialize();
|
|
758
739
|
const aVertex = this.getVertex(a);
|
|
759
740
|
const bVertex = this.getVertex(b);
|
|
760
741
|
if (!aVertex || !bVertex || !exports.CfgVertex.isBlock(aVertex) || !exports.CfgVertex.isBlock(bVertex)) {
|
|
@@ -785,6 +766,9 @@ class ControlFlowGraph {
|
|
|
785
766
|
* This is the pendant of {@link DataflowGraph#mergeWith|mergeWith()} on a {@link DataflowGraph}.
|
|
786
767
|
*/
|
|
787
768
|
mergeWith(other, forceNested = false) {
|
|
769
|
+
this.materialize();
|
|
770
|
+
/* the other graph may be a projection that has not been asked for anything yet */
|
|
771
|
+
other.materialize();
|
|
788
772
|
this._mayBB ||= other._mayBB;
|
|
789
773
|
const roots = other.roots;
|
|
790
774
|
if (this._mayBB) {
|
|
@@ -822,4 +806,157 @@ function emptyControlFlowInformation() {
|
|
|
822
806
|
graph: new ControlFlowGraph()
|
|
823
807
|
};
|
|
824
808
|
}
|
|
809
|
+
/**
|
|
810
|
+
* Whether the given id is part of the control flow.
|
|
811
|
+
* A vertex the analysis synthesized (e.g. the call a higher-order function makes to a closure handed to it)
|
|
812
|
+
* stands for no point in the program, so the control flow does not pass through it; what it stands for is
|
|
813
|
+
* reachable through the `calls` edges instead.
|
|
814
|
+
*/
|
|
815
|
+
function isControlFlowVertex(dfg, id) {
|
|
816
|
+
return dfg.hasVertex(id) && dfg.idMap?.get(id) !== undefined;
|
|
817
|
+
}
|
|
818
|
+
/** The control flow part of the given edges, or `undefined` if none of them carries any. */
|
|
819
|
+
function controlFlowEdges(edges) {
|
|
820
|
+
let result = undefined;
|
|
821
|
+
for (const [id, edge] of edges ?? graph_1.NoEdges) {
|
|
822
|
+
const cfgEdge = toCfgEdge(edge);
|
|
823
|
+
if (cfgEdge !== undefined) {
|
|
824
|
+
result ??= new Map();
|
|
825
|
+
result.set(id, cfgEdge);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
return result;
|
|
829
|
+
}
|
|
830
|
+
/** The ids among the given edges that the control flow actually connects. */
|
|
831
|
+
function controlFlowNeighbors(edges) {
|
|
832
|
+
if (edges === undefined) {
|
|
833
|
+
return exports.NoNeighbors;
|
|
834
|
+
}
|
|
835
|
+
const result = [];
|
|
836
|
+
for (const [id, edge] of edges) {
|
|
837
|
+
if (edge_1.DfEdge.includesType(edge, edge_1.ControlFlowEdgeTypes)) {
|
|
838
|
+
result.push(id);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
return result;
|
|
842
|
+
}
|
|
843
|
+
/** Where a function body begins, which is the only way into that region. */
|
|
844
|
+
function bodyOf(vertex) {
|
|
845
|
+
return [vertex.subflow.cfgEntry ?? vertex.subflow.entryPoint];
|
|
846
|
+
}
|
|
847
|
+
/** The control flow part of a dataflow edge, or `undefined` if it carries none. */
|
|
848
|
+
function toCfgEdge(edge) {
|
|
849
|
+
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.ControlEdge)) {
|
|
850
|
+
return exports.CfgEdge.makeCd(edge.cd);
|
|
851
|
+
}
|
|
852
|
+
else if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.FlowEdge)) {
|
|
853
|
+
return exports.CfgEdge.makeFd();
|
|
854
|
+
}
|
|
855
|
+
return undefined;
|
|
856
|
+
}
|
|
857
|
+
function makeCfgVertex(dfg, id) {
|
|
858
|
+
const type = control_flow_1.ControlFlow.isStatement(dfg, id) ? CfgVertexType.Statement : CfgVertexType.Expression;
|
|
859
|
+
const vertex = dfg.getVertex(id);
|
|
860
|
+
if (vertex_1.FunctionDefinitionVertex.is(vertex)) {
|
|
861
|
+
/*
|
|
862
|
+
* The body is a region of its own: evaluating the definition produces the closure and does not run it,
|
|
863
|
+
* so nothing flows from here into the body. Naming the body as children is what lets a traversal step
|
|
864
|
+
* into the function when it wants to, without inventing an edge that does not exist.
|
|
865
|
+
*/
|
|
866
|
+
return exports.CfgVertex.makeExprOrStm(id, type, { children: bodyOf(vertex) });
|
|
867
|
+
}
|
|
868
|
+
const callTargets = collectCallTargets(dfg, id);
|
|
869
|
+
return exports.CfgVertex.makeExprOrStm(id, type, callTargets ? { callTargets } : {});
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* The functions a call may dispatch to, taken from the `calls` edges the dataflow analysis resolved.
|
|
873
|
+
* Keeping the interprocedural links on those edges is what lets the control flow stay intra-procedural
|
|
874
|
+
* while still naming what a call reaches.
|
|
875
|
+
*/
|
|
876
|
+
function collectCallTargets(dfg, id) {
|
|
877
|
+
const vertex = dfg.getVertex(id);
|
|
878
|
+
if (!vertex_1.FunctionCallVertex.is(vertex)) {
|
|
879
|
+
return undefined;
|
|
880
|
+
}
|
|
881
|
+
let targets = undefined;
|
|
882
|
+
for (const [target, edge] of dfg.outgoingEdges(id) ?? graph_1.NoEdges) {
|
|
883
|
+
/* a built-in has no definition in the source, so there is nothing for the control flow to point at */
|
|
884
|
+
if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Calls) && !node_id_1.NodeId.isBuiltIn(target)) {
|
|
885
|
+
targets ??= new Set();
|
|
886
|
+
targets.add(target);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
return targets;
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* The control flow of the program the given dataflow analysis describes.
|
|
893
|
+
* @see {@link ControlFlowGraph} - for the projection this is built on
|
|
894
|
+
*/
|
|
895
|
+
/**
|
|
896
|
+
*
|
|
897
|
+
*/
|
|
898
|
+
function extractCfg(dataflow) {
|
|
899
|
+
const returns = [];
|
|
900
|
+
const breaks = [];
|
|
901
|
+
const nexts = [];
|
|
902
|
+
const exitPoints = [];
|
|
903
|
+
for (const exit of dataflow.exitPoints) {
|
|
904
|
+
switch (exit.type) {
|
|
905
|
+
case 1 /* ExitPointType.Return */:
|
|
906
|
+
returns.push(exit.nodeId);
|
|
907
|
+
break;
|
|
908
|
+
case 2 /* ExitPointType.Break */:
|
|
909
|
+
breaks.push(exit.nodeId);
|
|
910
|
+
break;
|
|
911
|
+
case 3 /* ExitPointType.Next */:
|
|
912
|
+
nexts.push(exit.nodeId);
|
|
913
|
+
break;
|
|
914
|
+
default:
|
|
915
|
+
exitPoints.push(exit.nodeId);
|
|
916
|
+
break;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
if (dataflow.cfgExit !== undefined) {
|
|
920
|
+
exitPoints.length = 0;
|
|
921
|
+
exitPoints.push(dataflow.cfgExit);
|
|
922
|
+
}
|
|
923
|
+
const graph = new ControlFlowGraph(dataflow.graph);
|
|
924
|
+
const entry = control_flow_1.ControlFlow.entryOf(dataflow);
|
|
925
|
+
return {
|
|
926
|
+
graph,
|
|
927
|
+
/* a program without a single statement (only comments, say) has nothing to enter or leave */
|
|
928
|
+
entryPoints: graph.hasVertex(entry) ? [entry] : [],
|
|
929
|
+
exitPoints: exitPoints.filter(e => graph.hasVertex(e)),
|
|
930
|
+
returns,
|
|
931
|
+
breaks,
|
|
932
|
+
nexts
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Convert a cfg to RDF quads.
|
|
937
|
+
* @see {@link df2quads}
|
|
938
|
+
* @see {@link serialize2quads}
|
|
939
|
+
* @see {@link graph2quads}
|
|
940
|
+
*/
|
|
941
|
+
function cfg2quads(cfg, config) {
|
|
942
|
+
return (0, quads_1.graph2quads)({
|
|
943
|
+
rootIds: [...cfg.graph.rootIds()],
|
|
944
|
+
vertices: [...cfg.graph.vertices().entries()]
|
|
945
|
+
.map(([id, v]) => ({
|
|
946
|
+
id,
|
|
947
|
+
children: exports.CfgVertex.getChildren(v)
|
|
948
|
+
})),
|
|
949
|
+
edges: [...cfg.graph.edges()].flatMap(([fromId, targets]) => [...targets].map(([toId, info]) => ({
|
|
950
|
+
from: fromId,
|
|
951
|
+
to: toId,
|
|
952
|
+
type: exports.CfgEdge.getType(info),
|
|
953
|
+
when: exports.CfgEdge.getWhen(info)
|
|
954
|
+
}))),
|
|
955
|
+
entryPoints: cfg.entryPoints,
|
|
956
|
+
exitPoints: cfg.exitPoints,
|
|
957
|
+
breaks: cfg.breaks,
|
|
958
|
+
nexts: cfg.nexts,
|
|
959
|
+
returns: cfg.returns
|
|
960
|
+
}, config);
|
|
961
|
+
}
|
|
825
962
|
//# sourceMappingURL=control-flow-graph.js.map
|