@eagleoutice/flowr 2.14.1 → 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 +154 -87
- 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 +11 -6
- package/benchmark/calibration.js +19 -8
- package/benchmark/slicer.d.ts +7 -1
- package/benchmark/slicer.js +38 -34
- 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/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/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 +8 -4
- 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 +63 -31
- package/dataflow/environments/built-in-props.d.ts +5 -1
- package/dataflow/environments/built-in-props.js +4 -0
- 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 +112 -7
- package/dataflow/environments/default-builtin-config.js +82 -34
- package/dataflow/environments/environment.d.ts +5 -5
- package/dataflow/environments/environment.js +5 -5
- package/dataflow/environments/identifier.d.ts +11 -1
- package/dataflow/environments/identifier.js +4 -1
- package/dataflow/environments/resolve-by-name.d.ts +7 -0
- package/dataflow/environments/resolve-by-name.js +12 -0
- 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 +9 -6
- package/dataflow/eval/resolve/resolve-strings.js +2 -2
- package/dataflow/eval/resolve/resolve-working-directory.js +4 -3
- 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 +3 -1
- package/dataflow/fn/strict-function.js +7 -5
- package/dataflow/graph/call-graph.js +2 -2
- package/dataflow/graph/df-helper.d.ts +8 -1
- 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 +4 -3
- package/dataflow/graph/graph.js +6 -2
- package/dataflow/graph/match-args.d.ts +69 -0
- package/dataflow/graph/match-args.js +167 -0
- package/dataflow/info.d.ts +14 -0
- 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 +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +71 -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 +14 -11
- 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/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-dataflow-graph.js +84 -53
- package/documentation/wiki-linter.js +15 -1
- package/documentation/wiki-linting-and-testing.js +1 -16
- package/documentation/wiki-mk/doc-maker.js +6 -4
- package/documentation/wiki-query.js +14 -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 +46 -10
- package/linter/linter-rules.d.ts +40 -9
- package/linter/linter-rules.js +2 -0
- 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 +2 -2
- package/linter/rules/stop-with-call-arg.js +2 -2
- package/linter/rules/unclosed-connection.js +2 -2
- 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 +2 -2
- 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 +0 -7
- package/project/dependency-version-space.js +8 -7
- package/project/flowr-analyzer.d.ts +4 -6
- package/project/flowr-analyzer.js +4 -5
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +22 -34
- 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/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 +2 -2
- package/project/sigdb/reader.d.ts +48 -13
- package/project/sigdb/reader.js +2 -1
- package/project/sigdb/schema.d.ts +3 -1
- 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/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-format.d.ts +2 -2
- package/queries/catalog/signature-query/signature-query-executor.js +4 -3
- package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +1 -1
- 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 +3 -2
- 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.js +8 -6
- 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 +9 -0
- package/util/objects.js +12 -0
- package/util/prefix.d.ts +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
|
@@ -8,10 +8,10 @@ const interval_domain_1 = require("../abstract-interpretation/domains/interval-d
|
|
|
8
8
|
const lattice_1 = require("../abstract-interpretation/domains/lattice");
|
|
9
9
|
const multi_value_state_domain_1 = require("../abstract-interpretation/domains/multi-value-state-domain");
|
|
10
10
|
const state_abstract_domain_1 = require("../abstract-interpretation/domains/state-abstract-domain");
|
|
11
|
+
const basic_cfg_guided_visitor_1 = require("../control-flow/basic-cfg-guided-visitor");
|
|
11
12
|
const semantic_cfg_guided_visitor_1 = require("../control-flow/semantic-cfg-guided-visitor");
|
|
12
13
|
const identifier_1 = require("../dataflow/environments/identifier");
|
|
13
14
|
const graph_1 = require("../dataflow/graph/graph");
|
|
14
|
-
const cfg_kind_1 = require("../project/cfg-kind");
|
|
15
15
|
const flowr_analyzer_builder_1 = require("../project/flowr-analyzer-builder");
|
|
16
16
|
const doc_code_1 = require("./doc-util/doc-code");
|
|
17
17
|
const doc_files_1 = require("./doc-util/doc-files");
|
|
@@ -57,7 +57,7 @@ async function inferIntervals() {
|
|
|
57
57
|
`.trim());
|
|
58
58
|
const ast = await analyzer.normalize();
|
|
59
59
|
const dfg = (await analyzer.dataflow()).graph;
|
|
60
|
-
const cfg = await analyzer.controlflow(undefined
|
|
60
|
+
const cfg = await analyzer.controlflow(undefined);
|
|
61
61
|
const ctx = analyzer.inspectContext();
|
|
62
62
|
const inference = new IntervalInferenceVisitor({ controlFlow: cfg, dfg: dfg, normalizedAst: ast, ctx: ctx });
|
|
63
63
|
inference.start();
|
|
@@ -121,7 +121,7 @@ All boxes link to their respective implementation in the source code.
|
|
|
121
121
|
${(0, doc_code_1.codeBlock)('mermaid', ctx.mermaid(abstract_domain_1.AbstractDomain))}
|
|
122
122
|
`.trim())}
|
|
123
123
|
|
|
124
|
-
The ${ctx.link('Top')} and ${ctx.link('Bottom')} symbols can be used to explicitly represent the top or bottom elment of an abstract domain. Additionally, for value abstract domains, there is the ${ctx.link('
|
|
124
|
+
The ${ctx.link('Top')} and ${ctx.link('Bottom')} symbols can be used to explicitly represent the top or bottom elment of an abstract domain. Additionally, for value abstract domains, there is the ${ctx.link('ValueDomain')} interface that provides the function ${ctx.link('ValueDomain:::satisfies')} to check whether the current abstract value of the abstract domain satisfies a concrete value (see also ${ctx.link('NumericalComparator')} and ${ctx.link('SetComparator')}).
|
|
125
125
|
|
|
126
126
|
_flowR_ already provides different abstract domains for abstract interpretation in ${(0, doc_files_1.linkFlowRSourceFile)('src/abstract-interpretation/domains')}. Many of the abstract domains are generic and can be used for differend kinds of analyses. The existing abstract domains are presented in the following. Some of the listed abstract domains can be expanded to show the inherited abstract domains.
|
|
127
127
|
|
|
@@ -138,7 +138,14 @@ ${ctx.code(multiValueExample, { dropLinesStart: 1, dropLinesEnd: 1, hideDefinedA
|
|
|
138
138
|
|
|
139
139
|
${(0, doc_structure_1.section)('Abstract Interpretation', 2, 'abstract-interpretation')}
|
|
140
140
|
|
|
141
|
-
We perform abstract interpretation by forward-traversing the ${ctx.linkPage('wiki/Control Flow Graph', 'control flow graph')} of _flowR_ using an ${ctx.link(absint_visitor_1.AbstractInterpretationVisitor)}. For each visited control flow vertex, the visitor retrieves the current abstract state by joining the abstract states of the predecessors, applies the abstract semantics of the visited control flow vertex to the current state, and updates the abstract state of the currently visited vertex to the current state. The visitor already handles assignments and (delayed) widening at widening points.
|
|
141
|
+
We perform abstract interpretation by forward-traversing the ${ctx.linkPage('wiki/Control Flow Graph', 'control flow graph')} of _flowR_ using an ${ctx.link(absint_visitor_1.AbstractInterpretationVisitor)}. For each visited control flow vertex, the visitor retrieves the current abstract state by joining the abstract states of the predecessors, applies the abstract semantics of the visited control flow vertex to the current state, and updates the abstract state of the currently visited vertex to the current state. The visitor already handles assignments and (delayed) widening at widening points.
|
|
142
|
+
|
|
143
|
+
Joining the predecessors goes through ${ctx.link(`${absint_visitor_1.AbstractInterpretationVisitor.name}::getPredecessorState`)}, which is handed the branch that was taken to get to the vertex.
|
|
144
|
+
For \`if(u) 3 else 2\` the step onto \`3\` reports the condition \`u\` as the predecessor and the \`if\` as the branch, together with the outcome \`u\` had, so an analysis can pin the condition down on the way into a branch.
|
|
145
|
+
The other direction is ${ctx.link(`${basic_cfg_guided_visitor_1.BasicCfgGuidedVisitor.name}::getDecidedConstructs`)}: standing on \`u\`, it names the \`if\` that \`u\` decides.
|
|
146
|
+
|
|
147
|
+
Calls are not followed by default. Overriding ${ctx.link(`${absint_visitor_1.AbstractInterpretationVisitor.name}::shouldEnterCall`)} makes the visitor step into what a call dispatches to and continue with the state at the exit points of those functions, using ${ctx.link(`${absint_visitor_1.AbstractInterpretationVisitor.name}::enterCall`)}.
|
|
148
|
+
A function that is already being interpreted is not entered again, so a recursive call stops at the second entry.
|
|
142
149
|
|
|
143
150
|
To implement a custom abstract interpretation analysis, we can just create a new class and extend the ${ctx.link(absint_visitor_1.AbstractInterpretationVisitor)}. The abstract interpretation visitor uses a \`StateDomain\` (e.g., a ${ctx.link(state_abstract_domain_1.StateAbstractDomain)}) to capture the current abstract state at each vertex in the control flow graph. We can then extend the callback functions of the ${ctx.link(absint_visitor_1.AbstractInterpretationVisitor)} to implement the abstract semantics of expressions, such as ${ctx.link(`${semantic_cfg_guided_visitor_1.SemanticCfgGuidedVisitor.name}:::onNumberConstant`)}, ${ctx.link(`${absint_visitor_1.AbstractInterpretationVisitor.name}:::onFunctionCall`)} and ${ctx.link(`${semantic_cfg_guided_visitor_1.SemanticCfgGuidedVisitor.name}:::onReplacementCall`)} (make sure to still call the respective super function). The abstract interpretation visitor provides the following functions to retrieve the currently inferred values:
|
|
144
151
|
|
|
@@ -159,7 +166,7 @@ If we now want to run the interval inference, we can write the following code:
|
|
|
159
166
|
|
|
160
167
|
${ctx.code(inferIntervals, { dropLinesStart: 1, dropLinesEnd: 5, hideDefinedAt: true })}
|
|
161
168
|
|
|
162
|
-
We first need a ${ctx.linkPage('wiki/Analyzer', 'flowR analyzer')} (in this case, using the ${ctx.linkPage('wiki/Engines', 'tree-sitter engine')}). In this example, we want to analyze a small example code that assigns \`42\` to the variable \`x\`, randomly assigns \`6\` or \`12\` to the variable \`y\`, and assignes the sum of \`x\` and \`y\` to the variable \`z\`. For the abstract interpretation visitor, we need to retrieve the ${ctx.linkPage('wiki/Normalized AST', 'normalized AST')}, ${ctx.linkPage('wiki/Dataflow Graph', 'dataflow graph')}, ${ctx.linkPage('wiki/Control Flow Graph', 'control flow graph')}, and context of the flowR anaylzer. For performance reasons, we
|
|
169
|
+
We first need a ${ctx.linkPage('wiki/Analyzer', 'flowR analyzer')} (in this case, using the ${ctx.linkPage('wiki/Engines', 'tree-sitter engine')}). In this example, we want to analyze a small example code that assigns \`42\` to the variable \`x\`, randomly assigns \`6\` or \`12\` to the variable \`y\`, and assignes the sum of \`x\` and \`y\` to the variable \`z\`. For the abstract interpretation visitor, we need to retrieve the ${ctx.linkPage('wiki/Normalized AST', 'normalized AST')}, ${ctx.linkPage('wiki/Dataflow Graph', 'dataflow graph')}, ${ctx.linkPage('wiki/Control Flow Graph', 'control flow graph')}, and context of the flowR anaylzer. For performance reasons, we request the control flow graph without simplification passes; it is a view on the dataflow graph and is only projected once something walks it. We then create a new ${ctx.link(IntervalInferenceVisitor)} using the control flow graph, dataflow graph, normalized AST, and analyzer context, and start the visitor using ${ctx.linkM(absint_visitor_1.AbstractInterpretationVisitor, 'start', { hideClass: true })}. After the visitor is finished, we retrieve the inferred abstract state at the end of the program using ${ctx.linkM(absint_visitor_1.AbstractInterpretationVisitor, 'getEndState', { hideClass: true })}.
|
|
163
170
|
|
|
164
171
|
If we now print the inferred abstract state at the end of the program, we get the following output:
|
|
165
172
|
|
|
@@ -500,7 +500,7 @@ For one file, the incremental state follows a fixed lifecycle:
|
|
|
500
500
|
${ctx.linkM(flowr_analyzer_incremental_analysis_context_1.FlowrAnalyzerIncrementalAnalysisContext, 'storeOldParseResults', { codeFont: true, realNameWrapper: 'i' })}.
|
|
501
501
|
This tree is the baseline for the next incremental parse of that file.
|
|
502
502
|
2. When a mutable file provider such as ${ctx.link('FlowrInlineTextFile')} is invalidated via
|
|
503
|
-
${ctx.linkM(flowr_file_1.
|
|
503
|
+
${ctx.linkM(flowr_file_1.FlowrFile, 'invalidate', { codeFont: true, realNameWrapper: 'i' })},
|
|
504
504
|
the analyzer receives a file invalidation event and stores the file path together with the old source text.
|
|
505
505
|
If the same file is invalidated again before the next parse, this stored old text is intentionally **not** replaced:
|
|
506
506
|
the stored parse tree still belongs to the version from before the first invalidation, so the incremental parse must keep that matching old-content baseline.
|
|
@@ -510,7 +510,7 @@ For one file, the incremental state follows a fixed lifecycle:
|
|
|
510
510
|
* the stored old source text from
|
|
511
511
|
${ctx.linkM(flowr_analyzer_incremental_analysis_context_1.FlowrAnalyzerIncrementalAnalysisContext, 'getOldContentOf', { codeFont: true, realNameWrapper: 'i' })}
|
|
512
512
|
|
|
513
|
-
Using these together with the current file content,
|
|
513
|
+
Using these together with the current file content, ${ctx.link('computeEditRegion')} derives a minimal tree-sitter \`Parser.Edit\`, only when a new parse is actually requested.
|
|
514
514
|
If the file content did not change, the previous tree can be reused directly.
|
|
515
515
|
Otherwise, the edit is applied to the previous tree and Tree-sitter reparses incrementally instead of starting from scratch.
|
|
516
516
|
4. The stored old-content entry is removed when it is used because it belongs only to that previous parse snapshot.
|
|
@@ -8,7 +8,7 @@ const doc_cfg_1 = require("./doc-util/doc-cfg");
|
|
|
8
8
|
const simple_visitor_1 = require("../control-flow/simple-visitor");
|
|
9
9
|
const control_flow_graph_1 = require("../control-flow/control-flow-graph");
|
|
10
10
|
const cfg_simplification_1 = require("../control-flow/cfg-simplification");
|
|
11
|
-
const
|
|
11
|
+
const control_flow_graph_2 = require("../control-flow/control-flow-graph");
|
|
12
12
|
const doc_dfg_1 = require("./doc-util/doc-dfg");
|
|
13
13
|
const cfg_to_basic_blocks_1 = require("../control-flow/cfg-to-basic-blocks");
|
|
14
14
|
const r_number_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-number");
|
|
@@ -17,7 +17,7 @@ const cfg_properties_1 = require("../control-flow/cfg-properties");
|
|
|
17
17
|
const basic_cfg_guided_visitor_1 = require("../control-flow/basic-cfg-guided-visitor");
|
|
18
18
|
const syntax_cfg_guided_visitor_1 = require("../control-flow/syntax-cfg-guided-visitor");
|
|
19
19
|
const diff_cfg_1 = require("../control-flow/diff-cfg");
|
|
20
|
-
const
|
|
20
|
+
const model_1 = require("../r-bridge/lang-4.x/ast/model/model");
|
|
21
21
|
const dfg_cfg_guided_visitor_1 = require("../control-flow/dfg-cfg-guided-visitor");
|
|
22
22
|
const semantic_cfg_guided_visitor_1 = require("../control-flow/semantic-cfg-guided-visitor");
|
|
23
23
|
const doc_issue_1 = require("./doc-util/doc-issue");
|
|
@@ -28,6 +28,7 @@ const doc_maker_1 = require("./wiki-mk/doc-maker");
|
|
|
28
28
|
const doc_general_1 = require("./doc-util/doc-general");
|
|
29
29
|
const doc_code_1 = require("./doc-util/doc-code");
|
|
30
30
|
const df_helper_1 = require("../dataflow/graph/df-helper");
|
|
31
|
+
const objects_1 = require("../util/objects");
|
|
31
32
|
const CfgLongExample = `f <- function(a, b = 3) {
|
|
32
33
|
if(a > b) {
|
|
33
34
|
return(a * b);
|
|
@@ -84,9 +85,6 @@ class CollectNumbersSyntaxVisitor extends syntax_cfg_guided_visitor_1.SyntaxAwar
|
|
|
84
85
|
}
|
|
85
86
|
class CollectNumbersDataflowVisitor extends dfg_cfg_guided_visitor_1.DataflowAwareCfgGuidedVisitor {
|
|
86
87
|
numbers = [];
|
|
87
|
-
constructor(controlFlow, dataflow) {
|
|
88
|
-
super({ controlFlow, dfg: dataflow, defaultVisitingOrder: 'forward' });
|
|
89
|
-
}
|
|
90
88
|
visitValue(node) {
|
|
91
89
|
const astNode = this.config.dfg.idMap?.get(node.id);
|
|
92
90
|
if (r_number_1.RNumber.is(astNode)) {
|
|
@@ -99,12 +97,9 @@ class CollectNumbersDataflowVisitor extends dfg_cfg_guided_visitor_1.DataflowAwa
|
|
|
99
97
|
}
|
|
100
98
|
class CollectSourcesSemanticVisitor extends semantic_cfg_guided_visitor_1.SemanticCfgGuidedVisitor {
|
|
101
99
|
sources = [];
|
|
102
|
-
constructor(controlFlow, normalizedAst, dataflow, ctx) {
|
|
103
|
-
super({ controlFlow, normalizedAst, dfg: dataflow, ctx, defaultVisitingOrder: 'forward' });
|
|
104
|
-
}
|
|
105
100
|
onAssignmentCall({ source }) {
|
|
106
101
|
if (source) {
|
|
107
|
-
this.sources.push((
|
|
102
|
+
this.sources.push(model_1.RNode.lexeme(this.getNormalizedAst(source)) ?? '??');
|
|
108
103
|
}
|
|
109
104
|
}
|
|
110
105
|
getSources() {
|
|
@@ -120,13 +115,12 @@ class WikiCfg extends doc_maker_1.DocMaker {
|
|
|
120
115
|
}
|
|
121
116
|
async text({ ctx, shell }) {
|
|
122
117
|
return `
|
|
123
|
-
_flowR_ produces three main perspectives of the program: 1)
|
|
124
|
-
|
|
118
|
+
_flowR_ produces three main perspectives of the program: 1) a ${ctx.linkPage('wiki/Normalized AST', 'normalized version of the AST')},
|
|
119
|
+
2) a ${ctx.linkPage('wiki/Dataflow Graph', 'dataflow graph')}, and 3) a control flow graph (CFG).
|
|
125
120
|
flowR uses this CFG interweaved with its data flow analysis and for some of its queries (e.g., to link to the last call in a ${(0, doc_query_1.linkToQueryOfName)('call-context')}).
|
|
126
121
|
|
|
127
|
-
Please note that
|
|
128
|
-
|
|
129
|
-
In contrast, the CFG describes a complete view of the program's control flow.
|
|
122
|
+
Please note that the control flow graph is a view on the ${ctx.linkPage('wiki/Dataflow Graph', 'dataflow graph')},
|
|
123
|
+
similar to the ${ctx.linkPage('wiki/Dataflow Graph', 'call graph', 'perspectives-cg')}.
|
|
130
124
|
|
|
131
125
|
${(0, doc_structure_1.block)({
|
|
132
126
|
type: 'TIP',
|
|
@@ -161,45 +155,57 @@ For now, let's look at a CFG for a program without any branching:
|
|
|
161
155
|
|
|
162
156
|
${(0, doc_code_1.codeBlock)('r', 'x <- 2 * 3 + 1')}
|
|
163
157
|
|
|
164
|
-
The corresponding CFG is a directed, labeled graph with two
|
|
158
|
+
The corresponding CFG is a directed, labeled graph with two kinds of edges: flow edges and control edges.
|
|
165
159
|
|
|
166
|
-
${await (0, doc_cfg_1.printCfgCode)(shell, 'x <- 2 * 3 + 1', { showCode: false, prefix: 'flowchart
|
|
160
|
+
${await (0, doc_cfg_1.printCfgCode)(shell, 'x <- 2 * 3 + 1', { showCode: false, prefix: 'flowchart LR\n', ctx })}
|
|
167
161
|
|
|
168
162
|
${(0, doc_structure_1.block)({
|
|
169
163
|
type: 'IMPORTANT',
|
|
170
|
-
content: '
|
|
164
|
+
content: 'Edges are in flow order: an edge from `a` to `b` means that `b` is evaluated after `a`. Use `outgoingEdges` (or `successors`) to ask what may run next and `ingoingEdges` (or `predecessors`) to ask what ran before. The [visitors](#cfg-working) can walk either way.'
|
|
171
165
|
})}
|
|
172
166
|
|
|
173
|
-
Every
|
|
174
|
-
|
|
175
|
-
|
|
167
|
+
Every vertex of the ${ctx.linkPage('wiki/Dataflow Graph', 'dataflow graph')} is a vertex here as well, carrying the same id
|
|
168
|
+
and hence linking back to the ${ctx.linkPage('wiki/Normalized AST', 'normalized AST')}.
|
|
169
|
+
The control flow is modeled in post-order, so an expression such as \`2 * 3\` is reached once both operands have been
|
|
170
|
+
evaluated: the \`*\` vertex itself is where the calculation is over, and no extra node is needed.
|
|
176
171
|
|
|
177
172
|
To gain a better understanding, let's have a look at a simple program with a single branching structure:
|
|
178
173
|
|
|
179
|
-
${await (0, doc_cfg_1.printCfgCode)(shell, 'if(u) 3 else 2', { showCode: true, openCode: false, prefix: 'flowchart
|
|
174
|
+
${await (0, doc_cfg_1.printCfgCode)(shell, 'if(u) 3 else 2', { showCode: true, openCode: false, prefix: 'flowchart LR\n', ctx })}
|
|
175
|
+
|
|
176
|
+
The condition \`u\` runs first and splits into the two branches, which join again on the \`if\` vertex itself.
|
|
177
|
+
The \`if\` is therefore where the structure is left (see the [structure](#cfg-structure) section for more details).
|
|
180
178
|
|
|
181
|
-
|
|
182
|
-
|
|
179
|
+
Standing on \`u\`, the edges leaving it are control edges that name the \`if\`, so what a condition belongs to can be
|
|
180
|
+
read off locally. ${ctx.linkM(control_flow_graph_1.ControlFlowGraph, 'decides')} lists the constructs a vertex decides,
|
|
181
|
+
and ${ctx.linkM(control_flow_graph_1.ControlFlowGraph, 'entryOf')} goes the other way, from the \`if\` to the condition it starts with.
|
|
183
182
|
|
|
184
183
|
For you to compare, the following shows the CFG of an \`if\` without an \`else\` branch:
|
|
185
184
|
|
|
186
|
-
${await (0, doc_cfg_1.printCfgCode)(shell, 'if(u || v) 3', { showCode: true, openCode: false, prefix: 'flowchart
|
|
185
|
+
${await (0, doc_cfg_1.printCfgCode)(shell, 'if(u || v) 3', { showCode: true, openCode: false, prefix: 'flowchart LR\n', ctx })}
|
|
186
|
+
|
|
187
|
+
The \`||\` branches as well, as it only evaluates \`v\` when \`u\` did not already decide the answer.
|
|
188
|
+
|
|
189
|
+
Basic blocks group what always runs together. A block ends where the flow may go more than one way, and starts
|
|
190
|
+
where more than one way may arrive:
|
|
187
191
|
|
|
188
|
-
|
|
192
|
+
${await (0, doc_cfg_1.printCfgCode)(shell, 'x <- 1\ny <- x + 2\nif(y) print(y)', { showCode: true, openCode: false, prefix: 'flowchart LR\n', simplifications: ['to-basic-blocks'], ctx })}
|
|
189
193
|
|
|
190
|
-
|
|
194
|
+
Compacting them is easier to read (although the reconstructed code can be slightly misleading, as flowR tries its
|
|
195
|
+
best to make it syntactically correct and hence adds closing braces which are technically not part of the block):
|
|
191
196
|
|
|
192
|
-
|
|
197
|
+
${await (0, doc_cfg_1.printCfgCode)(shell, 'x <- 1\ny <- x + 2\nif(y) print(y)', { showCode: true, openCode: false, prefix: 'flowchart LR\n', simplifications: ['to-basic-blocks'], simplify: true, ctx })}
|
|
193
198
|
|
|
194
|
-
|
|
199
|
+
Branch-heavy code gains nothing from this: in \`if(u || v) 3\` every vertex may be reached or left in more than
|
|
200
|
+
one way, so every block holds a single vertex.
|
|
195
201
|
|
|
196
202
|
The control flow graph also harmonizes with function definitions, and calls:
|
|
197
203
|
|
|
198
|
-
${await (0, doc_cfg_1.printCfgCode)(shell, 'f <- function() { 3 }\nf()', { showCode: true, openCode: true, prefix: 'flowchart
|
|
204
|
+
${await (0, doc_cfg_1.printCfgCode)(shell, 'f <- function() { 3 }\nf()', { showCode: true, openCode: true, prefix: 'flowchart LR\n', ctx })}
|
|
199
205
|
|
|
200
206
|
${(0, doc_structure_1.section)('Structure of the Control Flow Graph', 2, 'cfg-structure')}
|
|
201
207
|
|
|
202
|
-
You can produce your very own control flow graph with ${ctx.link(
|
|
208
|
+
You can produce your very own control flow graph with ${ctx.link(control_flow_graph_2.extractCfg)}.
|
|
203
209
|
The ${ctx.link(control_flow_graph_1.ControlFlowGraph)} class describes everything required to model the control flow graph, with its edge types described by
|
|
204
210
|
${ctx.link('CfgEdge')} and its vertices by ${ctx.link('CfgVertex')}.
|
|
205
211
|
However, you should be aware of the ${ctx.link('ControlFlowInformation')} interface which adds some additional information the CFG
|
|
@@ -210,28 +216,23 @@ ${ctx.hierarchy('ControlFlowInformation', { openTop: true })}
|
|
|
210
216
|
To check whether the CFG has the expected shape, you can use the test function ${ctx.link('assertCfg')} which supports testing for
|
|
211
217
|
sub-graphs as well (it provides diffing capabilities similar to ${ctx.link('assertDataflow')}).
|
|
212
218
|
As the CFG may become unhandy for larger programs, there are simplifications available with ${ctx.link(cfg_simplification_1.simplifyControlFlowInformation)}
|
|
213
|
-
(
|
|
219
|
+
(the ${ctx.linkPage('wiki/Analyzer', 'analyzer')} applies the ones you ask for when you request the control flow).
|
|
214
220
|
|
|
215
221
|
${(0, doc_structure_1.section)('CFG Vertices', 3, 'cfg-structure-vertices')}
|
|
216
222
|
|
|
217
223
|
All vertex types are summarized in the ${ctx.link('CfgVertexType')} enum which currently contains the following types:
|
|
218
224
|
|
|
219
|
-
${
|
|
225
|
+
${(0, objects_1.enumMembers)(control_flow_graph_1.CfgVertexType).map(([name, value]) => `- \`${name}\` (${value})`).join('\n')}
|
|
220
226
|
|
|
221
227
|
We use the ${ctx.link('CfgBasicBlockVertex')} to represent [basic blocks](#cfg-basic-blocks) and separate
|
|
222
228
|
expressions (${ctx.link('CfgExpressionVertex')}) and statements (${ctx.link('CfgStatementVertex')})
|
|
223
229
|
as control flow units with and without side effects (if you want to, you can see view statements as effectful expressions).
|
|
224
|
-
The markers (${ctx.link('CfgMarkerVertex')}) indicate the end of larger expressions/statements.
|
|
225
230
|
|
|
226
|
-
|
|
231
|
+
Every vertex corresponds to a vertex of the ${ctx.linkPage('wiki/Dataflow Graph', 'dataflow graph')}: the control flow
|
|
232
|
+
is modeled in post-order, so a vertex is reached once everything it is made of has been evaluated, which makes it the
|
|
233
|
+
point at which the construct is left. That is why there are no separate marker vertices to close an \`if\` or a loop.
|
|
227
234
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
Similarly, the markers contain a link to their root:
|
|
231
|
-
|
|
232
|
-
${ctx.hierarchy('CfgWithRoot', { openTop: true })}
|
|
233
|
-
|
|
234
|
-
In mermaid visualizations, we use rectangles for statements, rounded rectangles for expressions and circles for exit markers.
|
|
235
|
+
In mermaid visualizations, we use rectangles for statements and rounded rectangles for expressions.
|
|
235
236
|
Blocks are visualized as boxes around the contained vertices.
|
|
236
237
|
|
|
237
238
|
${(0, doc_structure_1.block)({
|
|
@@ -239,88 +240,86 @@ ${(0, doc_structure_1.block)({
|
|
|
239
240
|
content: `
|
|
240
241
|
Every CFG vertex has a ${ctx.link('NodeId')} that links it to the ${ctx.linkPage('wiki/Normalized AST', 'normalized AST')} (although basic blocks will find no counterpart as they are a structuring element of the CFG).
|
|
241
242
|
Additionally, it may provide information on the called functions (in case that the current element is a function call).
|
|
242
|
-
|
|
243
|
+
Additionally, a function definition names the vertices of its body as children, which is the only way into that region.
|
|
243
244
|
`.trim()
|
|
244
245
|
})}
|
|
245
246
|
|
|
246
247
|
${(0, doc_structure_1.section)('CFG Edges', 3, 'cfg-structure-edges')}
|
|
247
248
|
|
|
248
|
-
|
|
249
|
-
|
|
249
|
+
Every edge points the way execution goes: an edge from \`a\` to \`b\` means that \`b\` runs after \`a\`.
|
|
250
|
+
There are two kinds, told apart by the ${ctx.link('CfgEdgeType')} enum.
|
|
250
251
|
|
|
251
|
-
${(0, doc_structure_1.section)('Flow
|
|
252
|
+
${(0, doc_structure_1.section)('Flow Edges', 4, 'cfg-flow-edge')}
|
|
252
253
|
|
|
253
|
-
|
|
254
|
-
So \`x; y\` would produce a flow dependency from \`y\` to \`x\` (additionally to the program-enveloping root expression list):
|
|
254
|
+
A flow edge says that the target simply runs next. In \`x; y\` there is one from \`x\` to \`y\`:
|
|
255
255
|
|
|
256
|
-
${await (0, doc_cfg_1.printCfgCode)(shell, 'x; y', { showCode: false, prefix: 'flowchart
|
|
256
|
+
${await (0, doc_cfg_1.printCfgCode)(shell, 'x; y', { showCode: false, prefix: 'flowchart LR\n', ctx })}
|
|
257
257
|
|
|
258
|
-
${(0, doc_structure_1.section)('Control
|
|
258
|
+
${(0, doc_structure_1.section)('Control Edges', 4, 'cfg-control-edge')}
|
|
259
259
|
|
|
260
|
-
|
|
261
|
-
|
|
260
|
+
A control edge says the same, but only when a condition holds, which is how the branches of an \`if\` or the
|
|
261
|
+
body of a loop are attached. Diagrams draw these dashed.
|
|
262
262
|
|
|
263
|
-
${ctx.
|
|
263
|
+
The edge *is* the ${ctx.link('ControlDependency')} it stands for, the same one the vertices behind it carry in
|
|
264
|
+
their \`cds\`, so it names the deciding vertex, whether it is the true or the false case, and whether the
|
|
265
|
+
decision comes from iterating a loop:
|
|
264
266
|
|
|
265
|
-
|
|
267
|
+
${ctx.hierarchy('ControlDependency', { openTop: true })}
|
|
266
268
|
|
|
267
269
|
|
|
268
270
|
${await (async () => {
|
|
269
|
-
const exa = await (0, doc_cfg_1.printCfgCode)(shell, 'if(u) 3 else 2', { showCode: true, prefix: 'flowchart
|
|
271
|
+
const exa = await (0, doc_cfg_1.printCfgCode)(shell, 'if(u) 3 else 2', { showCode: true, prefix: 'flowchart LR\n', ctx });
|
|
270
272
|
return (0, doc_structure_1.details)('Example: if-else', exa);
|
|
271
273
|
})()}
|
|
272
274
|
|
|
273
275
|
${await (async () => {
|
|
274
|
-
const exa = await (0, doc_cfg_1.printCfgCode)(shell, 'while(u) b', { showCode: true, prefix: 'flowchart
|
|
276
|
+
const exa = await (0, doc_cfg_1.printCfgCode)(shell, 'while(u) b', { showCode: true, prefix: 'flowchart LR\n', ctx });
|
|
275
277
|
return (0, doc_structure_1.details)('Example: while-loop', exa);
|
|
276
278
|
})()}
|
|
277
279
|
<br/>
|
|
278
280
|
|
|
279
|
-
Please note that repeat loops
|
|
281
|
+
Please note that repeat loops have no control edges, as they repeat their body unconditionally.
|
|
280
282
|
Additionally, the control flow graph does not have to be connected. If you use a repeat without any exit condition,
|
|
281
|
-
the
|
|
283
|
+
the loop is never left, so its vertex is not reachable from the entry:
|
|
282
284
|
|
|
283
285
|
${await (async () => {
|
|
284
|
-
const exa = await (0, doc_cfg_1.printCfgCode)(shell, 'repeat { b }; after', { showCode: true, prefix: 'flowchart
|
|
286
|
+
const exa = await (0, doc_cfg_1.printCfgCode)(shell, 'repeat { b }; after', { showCode: true, prefix: 'flowchart LR\n', ctx });
|
|
285
287
|
return (0, doc_structure_1.details)('Example: repeat-loop (infinite)', exa);
|
|
286
288
|
})()}
|
|
287
289
|
|
|
288
290
|
${await (async () => {
|
|
289
|
-
const exa = await (0, doc_cfg_1.printCfgCode)(shell, 'repeat { b; if(u) break; }; after', { showCode: true, prefix: 'flowchart
|
|
291
|
+
const exa = await (0, doc_cfg_1.printCfgCode)(shell, 'repeat { b; if(u) break; }; after', { showCode: true, prefix: 'flowchart LR\n', ctx });
|
|
290
292
|
return (0, doc_structure_1.details)('Example: repeat-loop (with break)', exa);
|
|
291
293
|
})()}
|
|
292
294
|
<br/>
|
|
293
295
|
|
|
294
|
-
|
|
296
|
+
For a for-loop, the control edge says whether the sequence still has values to iterate over.
|
|
295
297
|
|
|
296
298
|
${await (async () => {
|
|
297
|
-
const exa = await (0, doc_cfg_1.printCfgCode)(shell, 'for(i in 1:10) b', { showCode: true, prefix: 'flowchart
|
|
299
|
+
const exa = await (0, doc_cfg_1.printCfgCode)(shell, 'for(i in 1:10) b', { showCode: true, prefix: 'flowchart LR\n', ctx });
|
|
298
300
|
return (0, doc_structure_1.details)('Example: for-loop', exa);
|
|
299
301
|
})()}
|
|
300
302
|
|
|
301
303
|
${(0, doc_structure_1.section)('Extra: Call Links', 4, 'cfg-call-links')}
|
|
302
304
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
305
|
+
The control flow graph is a view on the ${ctx.linkPage('wiki/Dataflow Graph', 'dataflow graph')}: the dataflow analysis
|
|
306
|
+
records the control flow while it walks the program, and ${ctx.link(control_flow_graph_2.extractCfg)} projects it into the shape the control
|
|
307
|
+
flow analyses expect. Because of that, the interprocedural knowledge the dataflow analysis gained is available without
|
|
308
|
+
a second pass over the program.
|
|
307
309
|
|
|
308
|
-
|
|
310
|
+
Control flow itself stays intra-procedural. A call does not flow into the body of what it calls, and the body of a
|
|
311
|
+
function definition is not entered when the definition is evaluated ‐ it only produces the closure. What a call
|
|
312
|
+
may reach is named separately:
|
|
309
313
|
|
|
310
|
-
|
|
314
|
+
${await (0, doc_cfg_1.printCfgCode)(shell, 'f <- function() b; f()', { showCode: true, prefix: 'flowchart LR\n', ctx })}
|
|
311
315
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
There are two important additions:
|
|
315
|
-
|
|
316
|
-
1. A new exit marker, canonically suffixed with \`${extract_cfg_1.ResolvedCallSuffix}\` signals that we are aware of the function call target.
|
|
317
|
-
This marker always follows the exit marker of the function call and links not just the call but also the exit points of the function definition.
|
|
318
|
-
2. A new _calls_ attribute attached to the function call vertex. This holds the ${ctx.link('NodeId')} of the function definitions that are called from this vertex.
|
|
316
|
+
A _calls_ attribute attached to the function call vertex holds the ${ctx.link('NodeId')} of the function definitions that
|
|
317
|
+
are called from this vertex, taken from the \`calls\` edges the dataflow analysis resolved.
|
|
319
318
|
|
|
320
319
|
For built-in functions that are provided by flowR's built-in configuration (see the ${ctx.linkPage('wiki/Interface', 'interface wiki page')}) the CFG does not contain
|
|
321
320
|
the additional information directly:
|
|
322
321
|
|
|
323
|
-
${await (0, doc_cfg_1.printCfgCode)(shell, 'print(3)', { showCode: true, prefix: 'flowchart
|
|
322
|
+
${await (0, doc_cfg_1.printCfgCode)(shell, 'print(3)', { showCode: true, prefix: 'flowchart LR\n', ctx })}
|
|
324
323
|
|
|
325
324
|
This is due to the fact that the ${ctx.linkPage('wiki/Dataflow Graph', 'dataflow graph')} does contain the required call information (and there are no new control vertices to add as the built-in call has no target in the source code):
|
|
326
325
|
|
|
@@ -335,16 +334,16 @@ Yet, we can request basic blocks or transform an existing CFG into basic blocks
|
|
|
335
334
|
|
|
336
335
|
Any program without any (un-)conditional jumps now contains a single basic block:
|
|
337
336
|
|
|
338
|
-
${await (0, doc_cfg_1.printCfgCode)(shell, 'x <- 2 * 3 + 1', { showCode: true, openCode: true, prefix: 'flowchart
|
|
337
|
+
${await (0, doc_cfg_1.printCfgCode)(shell, 'x <- 2 * 3 + 1', { showCode: true, openCode: true, prefix: 'flowchart LR\n', simplifications: ['to-basic-blocks'], simplify: true, ctx })}
|
|
339
338
|
|
|
340
339
|
While the CFG without basic blocks is much bigger:
|
|
341
340
|
|
|
342
|
-
${await (0, doc_cfg_1.printCfgCode)(shell, 'x <- 2 * 3 + 1', { showCode: false, prefix: 'flowchart
|
|
341
|
+
${await (0, doc_cfg_1.printCfgCode)(shell, 'x <- 2 * 3 + 1', { showCode: false, prefix: 'flowchart LR\n', ctx })}
|
|
343
342
|
|
|
344
343
|
In a way, using the basic blocks perspective does not remove any of these vertices (we just usually visualize them compacted as their execution order should be "obvious").
|
|
345
344
|
The vertices are still there, as elems of the ${ctx.link('CfgBasicBlockVertex')}:
|
|
346
345
|
|
|
347
|
-
${await (0, doc_cfg_1.printCfgCode)(shell, 'x <- 2 * 3 + 1', { showCode: false, prefix: 'flowchart
|
|
346
|
+
${await (0, doc_cfg_1.printCfgCode)(shell, 'x <- 2 * 3 + 1', { showCode: false, prefix: 'flowchart LR\n', simplifications: ['to-basic-blocks'], simplify: false, ctx })}
|
|
348
347
|
|
|
349
348
|
The benefit (for comprehensibility and algorithms) becomes more apparent when we look at a more complicated program:
|
|
350
349
|
|
|
@@ -352,12 +351,12 @@ ${(0, doc_code_1.codeBlock)('r', CfgLongExample)}
|
|
|
352
351
|
|
|
353
352
|
With basic blocks, this code looks like this:
|
|
354
353
|
|
|
355
|
-
${await (0, doc_cfg_1.printCfgCode)(shell, CfgLongExample, { showCode: false, prefix: 'flowchart
|
|
354
|
+
${await (0, doc_cfg_1.printCfgCode)(shell, CfgLongExample, { showCode: false, prefix: 'flowchart LR\n', simplifications: ['to-basic-blocks'], simplify: true, ctx })}
|
|
356
355
|
|
|
357
356
|
Now, without basic blocks, this is a different story...
|
|
358
357
|
|
|
359
358
|
${await (async () => {
|
|
360
|
-
const exa = await (0, doc_cfg_1.printCfgCode)(shell, CfgLongExample, { showCode: false, prefix: 'flowchart
|
|
359
|
+
const exa = await (0, doc_cfg_1.printCfgCode)(shell, CfgLongExample, { showCode: false, prefix: 'flowchart LR\n', ctx });
|
|
361
360
|
return (0, doc_structure_1.details)('The full CFG', exa);
|
|
362
361
|
})()}
|
|
363
362
|
|
|
@@ -423,6 +422,11 @@ visitors that incorporate various alternative perspectives:
|
|
|
423
422
|
- [Semantic CFG Visitor](#cfg-traversal-semantic):\\
|
|
424
423
|
Currently the most advanced visitor that combines syntactic with dataflow information.
|
|
425
424
|
|
|
425
|
+
The later ones need the dataflow graph and the ast as well. As the CFG is a view on the dataflow graph, and that
|
|
426
|
+
graph knows the ast, ${ctx.link(dfg_cfg_guided_visitor_1.cfgVisitorConfig)} takes both from the control flow you hand it:
|
|
427
|
+
|
|
428
|
+
${(0, doc_code_1.codeBlock)('ts', "new MyVisitor(cfgVisitorConfig({ controlFlow, defaultVisitingOrder: 'forward' }))")}
|
|
429
|
+
|
|
426
430
|
${(0, doc_structure_1.section)('Basic CFG Visitor', 4, 'cfg-traversal-basic')}
|
|
427
431
|
|
|
428
432
|
The ${ctx.link(basic_cfg_guided_visitor_1.BasicCfgGuidedVisitor)} class essential provides the same functionality as the [simple traversal](#cfg-simple-traversal) functions but in a class-based version.
|
|
@@ -476,7 +480,7 @@ Again, executing it with the CFG and Dataflow of the expression \`x - 1 + 2L * 3
|
|
|
476
480
|
|
|
477
481
|
${await (async () => {
|
|
478
482
|
const res = await (0, doc_cfg_1.getCfg)(shell, 'x - 1 + 2L * 3');
|
|
479
|
-
const visitor = new CollectNumbersDataflowVisitor(res.info,
|
|
483
|
+
const visitor = new CollectNumbersDataflowVisitor((0, dfg_cfg_guided_visitor_1.cfgVisitorConfig)({ controlFlow: res.info, defaultVisitingOrder: 'forward' }));
|
|
480
484
|
visitor.start();
|
|
481
485
|
const collected = visitor.getNumbers();
|
|
482
486
|
return collected.map(n => '\n- `' + JSON.stringify(n) + '`').join('');
|
|
@@ -501,7 +505,7 @@ Executing it with the CFG and Dataflow of the expression \`x <- 2; 3 -> x; assig
|
|
|
501
505
|
|
|
502
506
|
${await (async () => {
|
|
503
507
|
const res = await (0, doc_cfg_1.getCfg)(shell, 'x <- 2; 3 -> x; assign("x", 42 + 21)');
|
|
504
|
-
const visitor = new CollectSourcesSemanticVisitor(
|
|
508
|
+
const visitor = new CollectSourcesSemanticVisitor((0, dfg_cfg_guided_visitor_1.cfgVisitorConfig)({ controlFlow: res.info, ctx: (0, flowr_analyzer_context_1.contextFromInput)(''), defaultVisitingOrder: 'forward' }));
|
|
505
509
|
visitor.start();
|
|
506
510
|
const collected = visitor.getSources();
|
|
507
511
|
return collected.map(n => '\n- `' + n + '`').join('');
|
|
@@ -524,39 +528,30 @@ With the ${ctx.linkPage('wiki/Dataflow Graph')} you already get a \`${edge_1.DfE
|
|
|
524
528
|
(given that this function call does neither transform nor create a value).
|
|
525
529
|
But the control flow perspective gives you more! Given a simple addition like \`x + 1\`, the CFG looks like this:
|
|
526
530
|
|
|
527
|
-
${await (
|
|
528
|
-
const cfg = await (0, doc_cfg_1.getCfg)(shell, 'x + 1');
|
|
529
|
-
const [plusVertexId, plusVertex] = cfg.info.graph.vertices().entries().filter(([n]) => (0, node_id_1.recoverName)(n, cfg.ast.idMap) === '+').toArray()[0];
|
|
530
|
-
(0, assert_1.guard)(control_flow_graph_1.CfgVertex.isExpression(plusVertex));
|
|
531
|
-
const numOfExits = control_flow_graph_1.CfgVertex.getEnd(plusVertex)?.length ?? 0;
|
|
532
|
-
(0, assert_1.guard)(numOfExits === 1);
|
|
533
|
-
return `${await (0, doc_cfg_1.printCfgCode)(shell, 'x + 1', { showCode: true, prefix: 'flowchart RL\n', ctx })}
|
|
534
|
-
|
|
535
|
-
Looking at the binary operation vertex for \`+\` (with id \`${plusVertexId}\`) we see that it is linked to a single exit ("end marker") point: \`${control_flow_graph_1.CfgVertex.getEnd(plusVertex)?.[0] ?? '??'}\`.
|
|
536
|
-
Checking this vertex essentially reveals all exit points of the expression ‐ in this case, this simply refers to the operands of the addition.
|
|
537
|
-
However, the idea transfers to more complex expressions as well...
|
|
538
|
-
`;
|
|
539
|
-
})()}
|
|
531
|
+
${await (0, doc_cfg_1.printCfgCode)(shell, 'x + 1', { showCode: true, prefix: 'flowchart LR\n', ctx })}
|
|
540
532
|
|
|
541
|
-
|
|
533
|
+
The control flow is modeled in post-order: a vertex is reached once everything it is made of has been evaluated.
|
|
534
|
+
For the addition above that means both operands come first and the \`+\` vertex itself is where they join again,
|
|
535
|
+
so the vertex of an expression *is* its exit point ‐ there are no separate marker vertices.
|
|
536
|
+
|
|
537
|
+
${(0, doc_structure_1.details)('Example: Where an if joins again', await (async function () {
|
|
542
538
|
const expr = 'if(u) 3 else 2';
|
|
543
539
|
const cfg = await (0, doc_cfg_1.getCfg)(shell, expr);
|
|
544
|
-
const [ifVertexId, ifVertex] = [...cfg.info.graph.vertices()].filter(([n]) =>
|
|
545
|
-
(0, assert_1.guard)(control_flow_graph_1.CfgVertex.isStatement(ifVertex));
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
Looking at the if vertex for (with id \`${ifVertexId}\`) we see that it is again linked to a single exit point: \`${control_flow_graph_1.CfgVertex.getEnd(ifVertex)?.[0] ?? '??'}\`.
|
|
551
|
-
Yet, now this exit vertex is linked to the two branches of the if statement (the \`then\` and \`else\` branch).
|
|
540
|
+
const [ifVertexId, ifVertex] = [...cfg.info.graph.vertices()].filter(([n]) => cfg.ast.idMap.get(n)?.lexeme === 'if')[0];
|
|
541
|
+
(0, assert_1.guard)(control_flow_graph_1.CfgVertex.isStatement(ifVertex) || control_flow_graph_1.CfgVertex.isExpression(ifVertex));
|
|
542
|
+
return `${await (0, doc_cfg_1.printCfgCode)(shell, expr, { showCode: true, prefix: 'flowchart LR\n', ctx })}
|
|
543
|
+
|
|
544
|
+
Both branches of the if (with id \`${ifVertexId}\`) flow into the if vertex itself, which is therefore the single
|
|
545
|
+
point at which the statement is left, whichever branch ran.
|
|
552
546
|
`;
|
|
553
547
|
})())}
|
|
554
548
|
|
|
555
|
-
Hence,
|
|
549
|
+
Hence, the vertex of an expression names all of its exits, which is what keeps the graph a hammock graph without
|
|
550
|
+
any auxiliary vertices.
|
|
556
551
|
|
|
557
552
|
${(0, doc_structure_1.block)({
|
|
558
553
|
type: 'WARNING',
|
|
559
|
-
content: 'Using basic blocks, this works just the same. However, please keep in mind that the
|
|
554
|
+
content: 'Using basic blocks, this works just the same. However, please keep in mind that the vertex a control statement joins on does not have to be part of the same basic block as the branches leading to it.'
|
|
560
555
|
})}
|
|
561
556
|
|
|
562
557
|
`;
|