@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.
Files changed (413) hide show
  1. package/README.md +154 -87
  2. package/abstract-interpretation/absint-visitor.d.ts +91 -25
  3. package/abstract-interpretation/absint-visitor.js +235 -74
  4. package/abstract-interpretation/data-frame/mappers/access-mapper.d.ts +1 -1
  5. package/abstract-interpretation/data-frame/mappers/access-mapper.js +4 -4
  6. package/abstract-interpretation/data-frame/mappers/arguments.d.ts +1 -1
  7. package/abstract-interpretation/data-frame/mappers/arguments.js +1 -1
  8. package/abstract-interpretation/data-frame/mappers/function-mapper.js +107 -254
  9. package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +5 -5
  10. package/abstract-interpretation/data-frame/resolve-args.d.ts +1 -1
  11. package/abstract-interpretation/data-frame/resolve-args.js +6 -4
  12. package/abstract-interpretation/data-frame/shape-inference.d.ts +4 -9
  13. package/abstract-interpretation/domains/bounded-set-domain.d.ts +1 -0
  14. package/abstract-interpretation/domains/bounded-set-domain.js +1 -0
  15. package/abstract-interpretation/domains/partial-product-domain.js +1 -1
  16. package/abstract-interpretation/domains/set-range-domain.d.ts +3 -2
  17. package/abstract-interpretation/domains/set-range-domain.js +3 -2
  18. package/abstract-interpretation/domains/set-upper-bound-domain.d.ts +3 -2
  19. package/abstract-interpretation/domains/set-upper-bound-domain.js +3 -2
  20. package/benchmark/calibration.d.ts +11 -6
  21. package/benchmark/calibration.js +19 -8
  22. package/benchmark/slicer.d.ts +7 -1
  23. package/benchmark/slicer.js +38 -34
  24. package/benchmark/stats/count-comments.d.ts +16 -0
  25. package/benchmark/stats/count-comments.js +30 -0
  26. package/benchmark/stats/print.js +2 -0
  27. package/benchmark/stats/size-of.d.ts +7 -3
  28. package/benchmark/stats/size-of.js +7 -3
  29. package/benchmark/stats/stats.d.ts +7 -0
  30. package/benchmark/summarizer/first-phase/process.js +2 -19
  31. package/benchmark/summarizer/second-phase/graph.js +13 -3
  32. package/benchmark/summarizer/second-phase/process.js +2 -0
  33. package/cli/repl/commands/repl-dataflow.js +70 -27
  34. package/cli/repl/core.d.ts +1 -1
  35. package/cli/repl/core.js +1 -1
  36. package/cli/repl/parser/slice-query-parser.js +2 -1
  37. package/cli/repl/server/connection.d.ts +4 -0
  38. package/cli/repl/server/connection.js +19 -16
  39. package/cli/repl/server/messages/message-analysis.d.ts +1 -1
  40. package/config.d.ts +6 -0
  41. package/config.js +8 -4
  42. package/control-flow/basic-cfg-guided-visitor.d.ts +7 -2
  43. package/control-flow/basic-cfg-guided-visitor.js +37 -24
  44. package/control-flow/cfg-dead-code.js +44 -33
  45. package/control-flow/cfg-properties.js +2 -2
  46. package/control-flow/cfg-simplification.js +6 -5
  47. package/control-flow/cfg-to-basic-blocks.js +11 -13
  48. package/control-flow/control-flow-graph.d.ts +179 -189
  49. package/control-flow/control-flow-graph.js +400 -263
  50. package/control-flow/dfg-cfg-guided-visitor.d.ts +21 -3
  51. package/control-flow/dfg-cfg-guided-visitor.js +17 -13
  52. package/control-flow/diff-cfg.js +6 -14
  53. package/control-flow/happens-before.js +5 -4
  54. package/control-flow/semantic-cfg-guided-visitor.d.ts +44 -101
  55. package/control-flow/semantic-cfg-guided-visitor.js +6 -26
  56. package/control-flow/simple-visitor.js +14 -15
  57. package/control-flow/syntax-cfg-guided-visitor.d.ts +2 -1
  58. package/control-flow/useless-loop.js +18 -14
  59. package/core/steps/all/core/20-dataflow.d.ts +1 -3
  60. package/core/steps/pipeline/default-pipelines.d.ts +141 -157
  61. package/dataflow/cluster.js +7 -0
  62. package/dataflow/environments/apply-kill.d.ts +6 -0
  63. package/dataflow/environments/apply-kill.js +63 -31
  64. package/dataflow/environments/built-in-props.d.ts +5 -1
  65. package/dataflow/environments/built-in-props.js +4 -0
  66. package/dataflow/environments/built-in.d.ts +6 -3
  67. package/dataflow/environments/built-in.js +8 -5
  68. package/dataflow/environments/clone.d.ts +3 -3
  69. package/dataflow/environments/clone.js +5 -5
  70. package/dataflow/environments/default-builtin-config.d.ts +112 -7
  71. package/dataflow/environments/default-builtin-config.js +82 -34
  72. package/dataflow/environments/environment.d.ts +5 -5
  73. package/dataflow/environments/environment.js +5 -5
  74. package/dataflow/environments/identifier.d.ts +11 -1
  75. package/dataflow/environments/identifier.js +4 -1
  76. package/dataflow/environments/resolve-by-name.d.ts +7 -0
  77. package/dataflow/environments/resolve-by-name.js +12 -0
  78. package/dataflow/environments/resolve-helper.d.ts +3 -1
  79. package/dataflow/environments/resolve-helper.js +2 -0
  80. package/dataflow/eval/resolve/alias-tracking.d.ts +2 -2
  81. package/dataflow/eval/resolve/alias-tracking.js +2 -2
  82. package/dataflow/eval/resolve/match-arguments.js +7 -5
  83. package/dataflow/eval/resolve/node-value.d.ts +3 -1
  84. package/dataflow/eval/resolve/node-value.js +12 -0
  85. package/dataflow/eval/resolve/resolve-argument.js +5 -4
  86. package/dataflow/eval/resolve/resolve-operators.js +9 -6
  87. package/dataflow/eval/resolve/resolve-strings.js +2 -2
  88. package/dataflow/eval/resolve/resolve-working-directory.js +4 -3
  89. package/dataflow/eval/resolve/resolve.js +3 -2
  90. package/dataflow/eval/values/general.js +8 -5
  91. package/dataflow/extractor.d.ts +1 -4
  92. package/dataflow/extractor.js +11 -10
  93. package/dataflow/fn/exceptions-of-function.d.ts +3 -1
  94. package/dataflow/fn/strict-function.js +7 -5
  95. package/dataflow/graph/call-graph.js +2 -2
  96. package/dataflow/graph/df-helper.d.ts +8 -1
  97. package/dataflow/graph/diff-dataflow-graph.d.ts +1 -1
  98. package/dataflow/graph/diff-dataflow-graph.js +19 -2
  99. package/dataflow/graph/edge.d.ts +38 -2
  100. package/dataflow/graph/edge.js +32 -2
  101. package/dataflow/graph/graph.d.ts +4 -3
  102. package/dataflow/graph/graph.js +6 -2
  103. package/dataflow/graph/match-args.d.ts +69 -0
  104. package/dataflow/graph/match-args.js +167 -0
  105. package/dataflow/info.d.ts +14 -0
  106. package/dataflow/internal/control-flow.d.ts +102 -0
  107. package/dataflow/internal/control-flow.js +200 -0
  108. package/dataflow/internal/linker.d.ts +6 -31
  109. package/dataflow/internal/linker.js +24 -81
  110. package/dataflow/internal/process/functions/call/argument/unpack-argument.d.ts +1 -1
  111. package/dataflow/internal/process/functions/call/argument/unpack-argument.js +3 -3
  112. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +2 -2
  113. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +9 -6
  114. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +1 -1
  115. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +6 -4
  116. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +1 -10
  117. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +18 -37
  118. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +1 -1
  119. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +3 -3
  120. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +1 -1
  121. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +11 -7
  122. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +6 -8
  123. package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +1 -1
  124. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +18 -14
  125. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +8 -1
  126. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +11 -0
  127. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +2 -1
  128. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +27 -20
  129. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +3 -2
  130. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.d.ts +1 -1
  131. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +35 -6
  132. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +1 -1
  133. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +20 -17
  134. package/dataflow/internal/process/functions/call/built-in/built-in-list.d.ts +1 -1
  135. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +6 -4
  136. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +4 -3
  137. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +8 -3
  138. package/dataflow/internal/process/functions/call/built-in/built-in-namespace-access.d.ts +2 -2
  139. package/dataflow/internal/process/functions/call/built-in/built-in-namespace-access.js +5 -5
  140. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.d.ts +1 -1
  141. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +5 -4
  142. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +7 -5
  143. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.d.ts +1 -1
  144. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +15 -13
  145. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +2 -2
  146. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +2 -2
  147. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +4 -3
  148. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.d.ts +1 -1
  149. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +26 -4
  150. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +2 -2
  151. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +17 -4
  152. package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +2 -2
  153. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +71 -33
  154. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +6 -15
  155. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +12 -13
  156. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +1 -1
  157. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +14 -11
  158. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +15 -1
  159. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +1 -1
  160. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +12 -8
  161. package/dataflow/internal/process/functions/call/built-in/built-in-stop-if-not.js +6 -5
  162. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.d.ts +1 -1
  163. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.js +5 -4
  164. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +2 -2
  165. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +45 -10
  166. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +2 -2
  167. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +19 -3
  168. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +6 -2
  169. package/dataflow/internal/process/functions/call/common.js +5 -6
  170. package/dataflow/internal/process/functions/call/deferred.js +2 -2
  171. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +12 -2
  172. package/dataflow/internal/process/functions/call/known-call-handling.js +23 -1
  173. package/dataflow/internal/process/functions/call/named-call-handling.js +2 -0
  174. package/dataflow/internal/process/functions/call/nse.d.ts +1 -1
  175. package/dataflow/internal/process/functions/call/nse.js +6 -1
  176. package/dataflow/internal/process/functions/call/quoted.js +2 -2
  177. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +19 -6
  178. package/dataflow/internal/process/functions/process-argument.d.ts +1 -1
  179. package/dataflow/internal/process/functions/process-argument.js +12 -4
  180. package/dataflow/internal/process/functions/process-parameter.js +13 -0
  181. package/dataflow/internal/process/process-named-call.d.ts +2 -2
  182. package/dataflow/internal/process/process-named-call.js +9 -7
  183. package/documentation/data/server/doc-data-server-messages.js +4 -4
  184. package/documentation/doc-readme.js +45 -0
  185. package/documentation/doc-util/doc-cfg.d.ts +8 -7
  186. package/documentation/doc-util/doc-cfg.js +10 -10
  187. package/documentation/doc-util/doc-playground.d.ts +12 -0
  188. package/documentation/doc-util/doc-playground.js +21 -0
  189. package/documentation/doc-util/doc-query.d.ts +4 -1
  190. package/documentation/doc-util/doc-query.js +4 -2
  191. package/documentation/wiki-absint.d.ts +3 -4
  192. package/documentation/wiki-absint.js +12 -5
  193. package/documentation/wiki-analyzer.js +2 -2
  194. package/documentation/wiki-cfg.js +101 -106
  195. package/documentation/wiki-dataflow-graph.js +84 -53
  196. package/documentation/wiki-linter.js +15 -1
  197. package/documentation/wiki-linting-and-testing.js +1 -16
  198. package/documentation/wiki-mk/doc-maker.js +6 -4
  199. package/documentation/wiki-query.js +14 -4
  200. package/documentation/wiki-signature-database.js +28 -2
  201. package/linter/linter-fix.d.ts +16 -0
  202. package/linter/linter-fix.js +104 -0
  203. package/linter/linter-format.d.ts +18 -1
  204. package/linter/linter-format.js +31 -1
  205. package/linter/linter-output.js +46 -10
  206. package/linter/linter-rules.d.ts +40 -9
  207. package/linter/linter-rules.js +2 -0
  208. package/linter/rules/absolute-path.js +4 -2
  209. package/linter/rules/dataframe-access-validation.js +6 -7
  210. package/linter/rules/deprecated-functions.d.ts +107 -10
  211. package/linter/rules/deprecated-functions.js +309 -23
  212. package/linter/rules/file-path-validity.js +5 -4
  213. package/linter/rules/function-finder-util.d.ts +6 -0
  214. package/linter/rules/function-finder-util.js +21 -13
  215. package/linter/rules/naming-convention.js +1 -1
  216. package/linter/rules/network-functions.d.ts +2 -2
  217. package/linter/rules/stop-with-call-arg.js +2 -2
  218. package/linter/rules/unclosed-connection.js +2 -2
  219. package/linter/rules/undefined-symbol-util.js +6 -4
  220. package/linter/rules/undefined-symbol.js +2 -2
  221. package/linter/rules/unused-definition.js +8 -4
  222. package/linter/rules/unused-import.d.ts +60 -0
  223. package/linter/rules/unused-import.js +179 -0
  224. package/package.json +2 -2
  225. package/project/attached-packages.js +2 -1
  226. package/project/cache/flowr-analyzer-cache.d.ts +2 -5
  227. package/project/cache/flowr-analyzer-cache.js +4 -7
  228. package/project/cache/flowr-analyzer-controlflow-cache.d.ts +9 -8
  229. package/project/cache/flowr-analyzer-controlflow-cache.js +17 -34
  230. package/project/cache/flowr-cache.d.ts +9 -0
  231. package/project/cache/flowr-cache.js +19 -0
  232. package/project/context/flowr-analyzer-context.d.ts +7 -3
  233. package/project/context/flowr-analyzer-context.js +15 -9
  234. package/project/context/flowr-analyzer-dependencies-context.d.ts +24 -3
  235. package/project/context/flowr-analyzer-dependencies-context.js +9 -14
  236. package/project/context/flowr-analyzer-files-context.js +15 -17
  237. package/project/context/flowr-analyzer-meta-context.js +2 -12
  238. package/project/dependency-version-space.d.ts +0 -7
  239. package/project/dependency-version-space.js +8 -7
  240. package/project/flowr-analyzer.d.ts +4 -6
  241. package/project/flowr-analyzer.js +4 -5
  242. package/project/plugins/file-plugins/files/flowr-namespace-file.js +22 -34
  243. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +13 -13
  244. package/project/plugins/file-plugins/files/flowr-rda-file.js +131 -286
  245. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +1 -0
  246. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +1 -0
  247. package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.d.ts +2 -5
  248. package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.js +2 -8
  249. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.d.ts +32 -0
  250. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +43 -1
  251. package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.d.ts +4 -12
  252. package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.js +3 -16
  253. package/project/plugins/file-plugins/flowr-analyzer-license-file-plugin.d.ts +5 -8
  254. package/project/plugins/file-plugins/flowr-analyzer-license-file-plugin.js +4 -10
  255. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +3 -10
  256. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +1 -13
  257. package/project/plugins/file-plugins/flowr-analyzer-namespace-files-plugin.d.ts +3 -6
  258. package/project/plugins/file-plugins/flowr-analyzer-namespace-files-plugin.js +2 -8
  259. package/project/plugins/file-plugins/flowr-analyzer-news-file-plugin.d.ts +2 -5
  260. package/project/plugins/file-plugins/flowr-analyzer-news-file-plugin.js +2 -8
  261. package/project/plugins/file-plugins/flowr-analyzer-rda-file-plugin.d.ts +2 -5
  262. package/project/plugins/file-plugins/flowr-analyzer-rda-file-plugin.js +2 -8
  263. package/project/plugins/file-plugins/flowr-analyzer-rprofile-file-plugin.d.ts +3 -4
  264. package/project/plugins/file-plugins/flowr-analyzer-rprofile-file-plugin.js +3 -6
  265. package/project/plugins/file-plugins/flowr-analyzer-test-file-plugin.d.ts +4 -12
  266. package/project/plugins/file-plugins/flowr-analyzer-test-file-plugin.js +3 -16
  267. package/project/plugins/file-plugins/flowr-analyzer-vignette-file-plugin.d.ts +4 -12
  268. package/project/plugins/file-plugins/flowr-analyzer-vignette-file-plugin.js +3 -16
  269. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +4 -12
  270. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -16
  271. package/project/plugins/file-plugins/notebooks/flowr-analyzer-jupyter-file-plugin.d.ts +2 -5
  272. package/project/plugins/file-plugins/notebooks/flowr-analyzer-jupyter-file-plugin.js +2 -8
  273. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.d.ts +2 -6
  274. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.js +1 -10
  275. package/project/plugins/file-plugins/notebooks/flowr-analyzer-sweave-file-plugin.d.ts +2 -5
  276. package/project/plugins/file-plugins/notebooks/flowr-analyzer-sweave-file-plugin.js +2 -8
  277. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-library-plugin.js +2 -1
  278. package/project/sigdb/build.d.ts +2 -2
  279. package/project/sigdb/decode.d.ts +0 -5
  280. package/project/sigdb/decode.js +0 -8
  281. package/project/sigdb/index-format.d.ts +4 -4
  282. package/project/sigdb/manifest.d.ts +2 -2
  283. package/project/sigdb/reader.d.ts +48 -13
  284. package/project/sigdb/reader.js +2 -1
  285. package/project/sigdb/schema.d.ts +3 -1
  286. package/project/sigdb/signature-db.d.ts +69 -0
  287. package/project/sigdb/signature-db.js +54 -0
  288. package/project/sigdb/signature-match.d.ts +10 -5
  289. package/project/sigdb/signature-match.js +13 -8
  290. package/queries/catalog/absint-query/absint-query-executor.js +1 -2
  291. package/queries/catalog/call-context-query/call-context-query-executor.js +2 -4
  292. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.d.ts +1 -1
  293. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +33 -6
  294. package/queries/catalog/control-flow-query/control-flow-query-executor.js +1 -2
  295. package/queries/catalog/dependencies-query/dependencies-query-executor.js +2 -2
  296. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +8 -7
  297. package/queries/catalog/dependencies-query/dependencies-query-format.js +22 -35
  298. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +13 -1
  299. package/queries/catalog/dependencies-query/function-info/library-functions.js +26 -22
  300. package/queries/catalog/dependencies-query/function-info/statistics-functions.d.ts +9 -0
  301. package/queries/catalog/dependencies-query/function-info/statistics-functions.js +19 -0
  302. package/queries/catalog/dependencies-query/implicit-echo.d.ts +13 -0
  303. package/queries/catalog/dependencies-query/implicit-echo.js +133 -0
  304. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +2 -2
  305. package/queries/catalog/happens-before-query/happens-before-query-executor.js +1 -2
  306. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.d.ts +2 -2
  307. package/queries/catalog/signature-query/signature-query-executor.js +4 -3
  308. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +1 -1
  309. package/r-bridge/lang-4.x/ast/model/nodes/info/r-delimiter.d.ts +1 -0
  310. package/r-bridge/lang-4.x/ast/model/nodes/info/r-delimiter.js +1 -0
  311. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  312. package/r-bridge/lang-4.x/ast/model/nodes/r-access.js +1 -0
  313. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +4 -1
  314. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -2
  315. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  316. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.js +1 -0
  317. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  318. package/r-bridge/lang-4.x/ast/model/nodes/r-break.js +1 -0
  319. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  320. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.js +1 -0
  321. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  322. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.js +1 -0
  323. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  324. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.js +1 -0
  325. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +6 -4
  326. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +6 -4
  327. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  328. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.js +1 -0
  329. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  330. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.js +1 -0
  331. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  332. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.js +1 -0
  333. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  334. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.js +1 -0
  335. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  336. package/r-bridge/lang-4.x/ast/model/nodes/r-next.js +1 -0
  337. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +6 -0
  338. package/r-bridge/lang-4.x/ast/model/nodes/r-number.js +13 -0
  339. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  340. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.js +1 -0
  341. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  342. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.js +1 -0
  343. package/r-bridge/lang-4.x/ast/model/nodes/r-project.d.ts +1 -0
  344. package/r-bridge/lang-4.x/ast/model/nodes/r-project.js +1 -0
  345. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  346. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.js +1 -0
  347. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  348. package/r-bridge/lang-4.x/ast/model/nodes/r-string.js +1 -0
  349. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  350. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.js +1 -0
  351. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  352. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.js +1 -0
  353. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  354. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.js +1 -0
  355. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +2 -1
  356. package/r-bridge/lang-4.x/ast/model/processing/stateful-fold.d.ts +1 -1
  357. package/r-bridge/lang-4.x/ast/model/processing/stateful-fold.js +3 -2
  358. package/r-bridge/lang-4.x/ast/parser/main/internal/control/normalize-if-then-else.js +2 -1
  359. package/r-bridge/lang-4.x/ast/parser/main/internal/control/normalize-if-then.js +2 -1
  360. package/r-bridge/lang-4.x/ast/parser/main/internal/expression/normalize-expression.js +1 -1
  361. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-argument.js +2 -1
  362. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-call.d.ts +2 -2
  363. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-call.js +6 -3
  364. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-definition.js +2 -1
  365. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-parameter.js +2 -1
  366. package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-for.js +5 -3
  367. package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-repeat.js +2 -1
  368. package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-while.js +2 -1
  369. package/r-bridge/lang-4.x/ast/parser/main/internal/normalize-access.js +2 -1
  370. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-binary.js +5 -3
  371. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-unary.js +2 -1
  372. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.d.ts +1 -1
  373. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.js +2 -1
  374. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-root.js +3 -1
  375. package/r-bridge/lang-4.x/ast/parser/main/normalize-meta.d.ts +1 -1
  376. package/r-bridge/lang-4.x/ast/parser/main/normalize-meta.js +2 -1
  377. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +5 -3
  378. package/reconstruct/inline/source-inline-map.js +3 -3
  379. package/reconstruct/reconstruct.js +6 -4
  380. package/search/flowr-search-builder.d.ts +8 -8
  381. package/search/flowr-search-builder.js +4 -4
  382. package/search/flowr-search-filters.d.ts +2 -2
  383. package/search/flowr-search-filters.js +3 -2
  384. package/search/search-executor/search-enrichers.d.ts +6 -4
  385. package/search/search-executor/search-enrichers.js +44 -5
  386. package/slicing/criterion/filters/all-variables.js +2 -1
  387. package/slicing/criterion/parse.js +8 -6
  388. package/slicing/static/slice-call.js +2 -2
  389. package/util/arg-matching.d.ts +3 -0
  390. package/util/arg-matching.js +12 -1
  391. package/util/collections/arrays.d.ts +0 -4
  392. package/util/collections/arrays.js +4 -26
  393. package/util/diff-graph.d.ts +1 -1
  394. package/util/diff-graph.js +17 -3
  395. package/util/diff.d.ts +6 -0
  396. package/util/mermaid/ast.d.ts +1 -1
  397. package/util/mermaid/ast.js +5 -4
  398. package/util/mermaid/cfg.js +130 -24
  399. package/util/mermaid/dfg.js +31 -10
  400. package/util/mermaid/mermaid.js +2 -0
  401. package/util/objects.d.ts +9 -0
  402. package/util/objects.js +12 -0
  403. package/util/prefix.d.ts +1 -1
  404. package/util/text/playground-link.d.ts +131 -0
  405. package/util/text/playground-link.js +214 -0
  406. package/util/text/strings.js +7 -3
  407. package/util/version.js +1 -1
  408. package/control-flow/cfg-builder.d.ts +0 -30
  409. package/control-flow/cfg-builder.js +0 -79
  410. package/control-flow/extract-cfg.d.ts +0 -36
  411. package/control-flow/extract-cfg.js +0 -693
  412. package/project/cfg-kind.d.ts +0 -21
  413. package/project/cfg-kind.js +0 -26
@@ -1,22 +1,42 @@
1
- import { type CfgExpressionVertex, type CfgStatementVertex, CfgVertex, type ControlFlowInformation } from '../control-flow/control-flow-graph';
2
- import { SemanticCfgGuidedVisitor, type SemanticCfgGuidedVisitorConfiguration } from '../control-flow/semantic-cfg-guided-visitor';
1
+ import { CfgVertex, type ControlFlowInformation } from '../control-flow/control-flow-graph';
2
+ import { SemanticCfgGuidedVisitor, type SemanticCfgGuidedVisitorConfiguration, type OnCall } from '../control-flow/semantic-cfg-guided-visitor';
3
3
  import { BuiltInProcName } from '../dataflow/environments/built-in-proc-name';
4
- import type { DataflowGraph } from '../dataflow/graph/graph';
4
+ import { type DataflowGraph } from '../dataflow/graph/graph';
5
5
  import { type DataflowGraphVertexFunctionCall, type DataflowGraphVertexVariableDefinition } from '../dataflow/graph/vertex';
6
- import { type NoInfo, RNode } from '../r-bridge/lang-4.x/ast/model/model';
6
+ import type { NoInfo, RNode } from '../r-bridge/lang-4.x/ast/model/model';
7
7
  import type { NormalizedAst, ParentInformation } from '../r-bridge/lang-4.x/ast/model/processing/decorate';
8
- import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
8
+ import { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
9
+ import type { ControlDependency } from '../dataflow/info';
9
10
  import type { AnyStateDomain, ValueDomain } from './domains/state-domain-like';
10
11
  export type DomainOfVisitor<AbsintVisitor extends AbstractInterpretationVisitor<AnyStateDomain>> = AbsintVisitor extends AbstractInterpretationVisitor<infer StateDomain> ? StateDomain : never;
11
- export type AbsintVisitorConfiguration = Omit<SemanticCfgGuidedVisitorConfiguration<NoInfo, ControlFlowInformation, NormalizedAst>, 'defaultVisitingOrder' | 'defaultVisitingType'>;
12
+ export type AbsintVisitorConfiguration = Omit<SemanticCfgGuidedVisitorConfiguration<NoInfo, ControlFlowInformation, NormalizedAst>, 'defaultVisitingOrder'>;
13
+ /**
14
+ * Where an abstract state arrives from, and which way the branch went if the step was one.
15
+ *
16
+ * For `if(u) a else b` the step onto `a` carries `{ id: <u>, branch: { id: <the if>, when: true } }`,
17
+ * so the predecessor is the condition and `when` is the outcome it had.
18
+ */
19
+ export interface AbsintPredecessor {
20
+ /** the vertex the abstract state comes from */
21
+ readonly id: NodeId;
22
+ /** the branch taken to get here, `undefined` if control simply flows on */
23
+ readonly branch?: ControlDependency;
24
+ }
12
25
  /**
13
26
  * A control flow graph visitor to perform abstract interpretation.
14
27
  *
15
- * However, the visitor does not yet support inter-procedural abstract interpretation and abstract condition semantics.
28
+ * The worklist below stays within the function it starts in: a function definition produces a closure and its
29
+ * body is a region of its own, which nothing flows into.
30
+ *
31
+ * Calls are not followed by default: flip {@link AbstractInterpretationVisitor#shouldEnterCall|shouldEnterCall()} to
32
+ * step into what a call dispatches to and continue with the state at the function's exit points.
33
+ * Condition semantics are not applied by default either, but everything needed for them is there:
34
+ * {@link AbstractInterpretationVisitor#getPredecessorState|getPredecessorState()} is handed the branch that was
35
+ * taken, and {@link BasicCfgGuidedVisitor#getDecidedConstructs|getDecidedConstructs()} names the construct a
36
+ * condition belongs to.
16
37
  */
17
38
  export declare abstract class AbstractInterpretationVisitor<StateDomain extends AnyStateDomain, Config extends AbsintVisitorConfiguration = AbsintVisitorConfiguration> extends SemanticCfgGuidedVisitor<NoInfo, ControlFlowInformation, NormalizedAst, DataflowGraph, Config & {
18
39
  defaultVisitingOrder: 'forward';
19
- defaultVisitingType: 'exit';
20
40
  }> {
21
41
  /**
22
42
  * The abstract trace of the abstract interpretation visitor mapping node IDs to the abstract state at the respective node.
@@ -31,13 +51,18 @@ export declare abstract class AbstractInterpretationVisitor<StateDomain extends
31
51
  */
32
52
  private stack;
33
53
  /**
34
- * A set of nodes representing variable definitions that have already been visited but whose assignment has not yet been processed.
54
+ * The nodes a back edge of the control flow graph leads to, computed on demand.
55
+ * @see {@link AbstractInterpretationVisitor#isWideningPoint|isWideningPoint()}
35
56
  */
36
- private readonly unassigned;
57
+ private wideningPoints;
37
58
  /**
38
- * A map mapping assignments of replacement calls to their replacement calls for replacement calls that have already been visited but whose assignment has not yet been processed.
59
+ * A set of nodes representing variable definitions that have already been visited but whose assignment has not yet been processed.
39
60
  */
40
- private readonly replacements;
61
+ private readonly unassigned;
62
+ /** The call a function body is currently being interpreted for, mapping the body's entry to it. */
63
+ private readonly enteredFrom;
64
+ /** The function definitions currently being interpreted, which is what stops a recursive call from running forever. */
65
+ private readonly running;
41
66
  constructor(config: Config, stateDomain: StateDomain);
42
67
  /**
43
68
  * Resolves the inferred abstract value of an AST node.
@@ -68,18 +93,15 @@ export declare abstract class AbstractInterpretationVisitor<StateDomain extends
68
93
  start(): void;
69
94
  protected startVisitor(start: readonly NodeId[]): void;
70
95
  protected visitNode(vertexId: NodeId): boolean;
71
- protected visitUnknown(vertex: CfgStatementVertex | CfgExpressionVertex): void;
72
96
  protected onDispatchFunctionCallOrigin(call: DataflowGraphVertexFunctionCall, origin: BuiltInProcName): void;
73
97
  protected onVariableDefinition({ vertex }: {
74
98
  vertex: DataflowGraphVertexVariableDefinition;
75
99
  }): void;
76
- protected onAssignmentCall({ target, source }: {
77
- call: DataflowGraphVertexFunctionCall;
100
+ protected onAssignmentCall({ target, source }: OnCall & {
78
101
  target?: NodeId;
79
102
  source?: NodeId;
80
103
  }): void;
81
- protected onReplacementCall({ target }: {
82
- call: DataflowGraphVertexFunctionCall;
104
+ protected onReplacementCall({ target }: OnCall & {
83
105
  target?: NodeId;
84
106
  source?: NodeId;
85
107
  }): void;
@@ -92,22 +114,66 @@ export declare abstract class AbstractInterpretationVisitor<StateDomain extends
92
114
  * This bundles all function calls that are no conditions, loops, assignments, replacement calls, and access operations.
93
115
  * @protected
94
116
  */
95
- protected onFunctionCall(_data: {
96
- call: DataflowGraphVertexFunctionCall;
97
- }): void;
98
- /** Gets all AST nodes for the predecessor vertices that are leaf nodes and exit vertices */
99
- protected getPredecessorNodes(vertexId: NodeId): NodeId[];
117
+ protected onFunctionCall(_data: OnCall): void;
118
+ /**
119
+ * Everything the control flow may come from to reach this vertex, together with the branch it took to get here.
120
+ * Skipped vertices hold no state of their own, so what led into them is reported instead.
121
+ */
122
+ protected getPredecessors(vertexId: NodeId): readonly AbsintPredecessor[];
123
+ /**
124
+ * The abstract state one predecessor contributes, joined into the state at the current vertex.
125
+ *
126
+ * By default, this is the state as the predecessor left it. Override it to apply condition semantics:
127
+ * on the then-branch of `if(u) a else b` the predecessor is `u` and `branch.when` is `true`, so `u` held.
128
+ */
129
+ protected getPredecessorState({ id }: AbsintPredecessor): StateDomain | undefined;
130
+ protected visitFunctionCall(call: DataflowGraphVertexFunctionCall): void;
131
+ /**
132
+ * Whether the traversal should step into what the given call dispatches to.
133
+ * Returning `true` runs the bodies and continues with the state at their exit points.
134
+ */
135
+ protected shouldEnterCall(_call: DataflowGraphVertexFunctionCall): boolean;
136
+ /**
137
+ * The function definitions the given call may dispatch to.
138
+ * Built-in functions have no definition in the source, so they are not part of this.
139
+ */
140
+ protected getCallTargets(callId: NodeId): readonly NodeId[];
141
+ /** Where a function definition starts, i.e. the first thing that runs when it is called. */
142
+ protected getFunctionEntry(defId: NodeId): NodeId | undefined;
143
+ /** Where a function definition is left, i.e. its last expressions and `return` calls. */
144
+ protected getFunctionExits(defId: NodeId): readonly NodeId[];
145
+ /**
146
+ * Runs the bodies the given call dispatches to, starting from the state at the call, and returns the state
147
+ * control comes back with: the states at their exit points joined.
148
+ * A call already being interpreted is not entered again, so recursion stops at the second entry.
149
+ * @returns the state at the exit points, or `undefined` if the call reaches nothing to step into
150
+ */
151
+ protected enterCall(callId: NodeId): StateDomain | undefined;
152
+ /**
153
+ * Hand the arguments of the call to the parameters of the function it enters, so the body can read them.
154
+ * Only the arguments of this very call are used, whichever other calls the function has.
155
+ */
156
+ protected bindParameters(callId: NodeId, defId: NodeId): void;
100
157
  /** Gets each variable origin that has already been visited and whose assignment has already been processed */
101
158
  protected getVariableOrigins(nodeId: NodeId): NodeId[];
102
159
  /** Checks whether a node represents a unsupported (environment-changing) function call (e.g. `eval`, `load`, `attach`, `rm`, ...) */
103
160
  protected isUnsupportedFunctionCall(nodeId: NodeId): boolean;
104
- /** We only perform widening at `for`, `while`, or `repeat` loops with more than one ingoing CFG edge */
161
+ /**
162
+ * We widen wherever the control flow comes back around, i.e. at the node a back edge leads to.
163
+ * That is what makes the iteration terminate, and it is the loop head whichever loop the code used:
164
+ * the condition of a `while`, the binding of a `for`, or the first statement of a `repeat`.
165
+ */
105
166
  protected isWideningPoint(nodeId: NodeId): boolean;
167
+ /** The targets of the back edges of the control flow graph, found with one depth-first search. */
168
+ private findWideningPoints;
169
+ /** Everywhere the control flow may start: the program itself, and every function body, as nothing flows into one. */
170
+ private startingPoints;
106
171
  /**
107
172
  * Checks whether a control flow graph vertex should be skipped during visitation.
108
- * By default, we only process entry vertices of widening points, vertices of leaf nodes, and exit vertices (no entry nodes of complex nodes).
173
+ * Every node has exactly one vertex, reached once its operands are evaluated, so nothing is skipped
174
+ * by default; overriding this lets an analysis ignore parts of the program.
109
175
  */
110
- protected shouldSkipVertex(vertex: CfgVertex): boolean;
176
+ protected shouldSkipVertex(_vertex: CfgVertex): boolean;
111
177
  /**
112
178
  * Whether widening should be performed at a widening point.
113
179
  * By default, we perform widening when the number of visits of the widening point reaches the widening threshold of the config.
@@ -5,17 +5,35 @@ const control_flow_graph_1 = require("../control-flow/control-flow-graph");
5
5
  const semantic_cfg_guided_visitor_1 = require("../control-flow/semantic-cfg-guided-visitor");
6
6
  const built_in_proc_name_1 = require("../dataflow/environments/built-in-proc-name");
7
7
  const df_helper_1 = require("../dataflow/graph/df-helper");
8
+ const graph_1 = require("../dataflow/graph/graph");
9
+ const edge_1 = require("../dataflow/graph/edge");
8
10
  const vertex_1 = require("../dataflow/graph/vertex");
9
- const model_1 = require("../r-bridge/lang-4.x/ast/model/model");
10
11
  const r_function_call_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
11
- const type_1 = require("../r-bridge/lang-4.x/ast/model/type");
12
+ const node_id_1 = require("../r-bridge/lang-4.x/ast/model/processing/node-id");
12
13
  const assert_1 = require("../util/assert");
13
14
  const abstract_domain_1 = require("./domains/abstract-domain");
14
15
  const unsupported_functions_1 = require("./unsupported-functions");
16
+ const r_argument_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-argument");
17
+ const r_binary_op_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
18
+ const r_expression_list_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
19
+ const r_if_then_else_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-if-then-else");
20
+ const r_pipe_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-pipe");
21
+ const r_symbol_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
22
+ function stepFrom(graph, node) {
23
+ return { node, successors: [...graph.successors(node)], at: 0 };
24
+ }
15
25
  /**
16
26
  * A control flow graph visitor to perform abstract interpretation.
17
27
  *
18
- * However, the visitor does not yet support inter-procedural abstract interpretation and abstract condition semantics.
28
+ * The worklist below stays within the function it starts in: a function definition produces a closure and its
29
+ * body is a region of its own, which nothing flows into.
30
+ *
31
+ * Calls are not followed by default: flip {@link AbstractInterpretationVisitor#shouldEnterCall|shouldEnterCall()} to
32
+ * step into what a call dispatches to and continue with the state at the function's exit points.
33
+ * Condition semantics are not applied by default either, but everything needed for them is there:
34
+ * {@link AbstractInterpretationVisitor#getPredecessorState|getPredecessorState()} is handed the branch that was
35
+ * taken, and {@link BasicCfgGuidedVisitor#getDecidedConstructs|getDecidedConstructs()} names the construct a
36
+ * condition belongs to.
19
37
  */
20
38
  class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.SemanticCfgGuidedVisitor {
21
39
  /**
@@ -31,15 +49,20 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
31
49
  */
32
50
  stack = [];
33
51
  /**
34
- * A set of nodes representing variable definitions that have already been visited but whose assignment has not yet been processed.
52
+ * The nodes a back edge of the control flow graph leads to, computed on demand.
53
+ * @see {@link AbstractInterpretationVisitor#isWideningPoint|isWideningPoint()}
35
54
  */
36
- unassigned = new Set();
55
+ wideningPoints;
37
56
  /**
38
- * A map mapping assignments of replacement calls to their replacement calls for replacement calls that have already been visited but whose assignment has not yet been processed.
57
+ * A set of nodes representing variable definitions that have already been visited but whose assignment has not yet been processed.
39
58
  */
40
- replacements = new Map();
59
+ unassigned = new Set();
60
+ /** The call a function body is currently being interpreted for, mapping the body's entry to it. */
61
+ enteredFrom = new Map();
62
+ /** The function definitions currently being interpreted, which is what stops a recursive call from running forever. */
63
+ running = new Set();
41
64
  constructor(config, stateDomain) {
42
- super({ ...config, defaultVisitingOrder: 'forward', defaultVisitingType: 'exit' });
65
+ super({ ...config, defaultVisitingOrder: 'forward' });
43
66
  this.currentState = stateDomain.top();
44
67
  }
45
68
  /**
@@ -64,21 +87,21 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
64
87
  const vertex = this.getDataflowGraph(node.info.id);
65
88
  const call = vertex_1.FunctionCallVertex.is(vertex) ? vertex : undefined;
66
89
  const origins = Array.isArray(call?.origin) ? call.origin : [];
67
- if (node.type === type_1.RType.Symbol) {
90
+ if (r_symbol_1.RSymbol.is(node)) {
68
91
  const values = this.getVariableOrigins(node.info.id)
69
92
  .map(origin => (this.getAbstractState(origin)?.isBottom() ? this.currentState.domain.bottom() : state?.get(origin)));
70
93
  if (values.length > 0 && values.every(assert_1.isNotUndefined)) {
71
94
  return abstract_domain_1.AbstractDomain.joinAll(values);
72
95
  }
73
96
  }
74
- else if (node.type === type_1.RType.Argument && node.value !== undefined) {
97
+ else if (r_argument_1.RArgument.isWithValue(node)) {
75
98
  return this.getAbstractValue(node.value, state);
76
99
  }
77
- else if (node.type === type_1.RType.ExpressionList && node.children.length > 0) {
100
+ else if (r_expression_list_1.RExpressionList.is(node) && node.children.length > 0) {
78
101
  return this.getAbstractValue(node.children.at(-1), state);
79
102
  }
80
103
  else if (origins.includes(built_in_proc_name_1.BuiltInProcName.Pipe)) {
81
- if (node.type === type_1.RType.Pipe || node.type === type_1.RType.BinaryOp) {
104
+ if (r_pipe_1.RPipe.is(node) || r_binary_op_1.RBinaryOp.is(node)) {
82
105
  return this.getAbstractValue(node.rhs, state);
83
106
  }
84
107
  else if (call?.args.length === 2 && call?.args[1] !== r_function_call_1.EmptyArgument) {
@@ -87,7 +110,7 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
87
110
  }
88
111
  else if (origins.includes(built_in_proc_name_1.BuiltInProcName.IfThenElse)) {
89
112
  let values = [];
90
- if (node.type === type_1.RType.IfThenElse && node.otherwise !== undefined) {
113
+ if (r_if_then_else_1.RIfThenElse.is(node) && node.otherwise !== undefined) {
91
114
  values = [node.then, node.otherwise].map(entry => this.getAbstractValue(entry, state));
92
115
  }
93
116
  else if (call?.args.every(arg => arg !== r_function_call_1.EmptyArgument) && call.args.length === 3) {
@@ -113,9 +136,7 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
113
136
  * @returns The inferred abstract state at the end of the program
114
137
  */
115
138
  getEndState() {
116
- const exitPoints = this.config.controlFlow.exitPoints.map(id => this.getCfgVertex(id)).filter(assert_1.isNotUndefined);
117
- const exitNodes = exitPoints.map(control_flow_graph_1.CfgVertex.getRootId).filter(assert_1.isNotUndefined);
118
- const states = exitNodes.map(node => this.trace.get(node)).filter(assert_1.isNotUndefined);
139
+ const states = this.config.controlFlow.exitPoints.map(node => this.trace.get(node)).filter(assert_1.isNotUndefined);
119
140
  return abstract_domain_1.AbstractDomain.joinAll(states, this.currentState.bottom());
120
141
  }
121
142
  /**
@@ -137,7 +158,7 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
137
158
  if (!this.visitNode(current)) {
138
159
  continue;
139
160
  }
140
- const successors = this.config.controlFlow.graph.ingoingEdges(current)?.keys().toArray().reverse() ?? [];
161
+ const successors = [...this.config.controlFlow.graph.successors(current)].reverse();
141
162
  for (const next of successors) {
142
163
  if (!this.stack.includes(next)) { // prevent double entries in working list
143
164
  this.stack.push(next);
@@ -147,15 +168,14 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
147
168
  }
148
169
  visitNode(vertexId) {
149
170
  const vertex = this.getCfgVertex(vertexId);
150
- // skip exit vertices of widening points and entry vertices of complex nodes
151
171
  if (vertex === undefined || this.shouldSkipVertex(vertex)) {
152
172
  return true;
153
173
  }
154
174
  // retrieve new abstract state by joining states of predecessor nodes
155
- const predecessors = this.getPredecessorNodes(control_flow_graph_1.CfgVertex.getId(vertex));
156
- const predecessorStates = predecessors.map(pred => this.trace.get(pred)).filter(assert_1.isNotUndefined);
175
+ const nodeId = control_flow_graph_1.CfgVertex.getId(vertex);
176
+ const predecessors = this.getPredecessors(nodeId);
177
+ const predecessorStates = predecessors.map(pred => this.getPredecessorState(pred)).filter(assert_1.isNotUndefined);
157
178
  this.currentState = abstract_domain_1.AbstractDomain.joinAll(predecessorStates, this.currentState.top());
158
- const nodeId = control_flow_graph_1.CfgVertex.getRootId(vertex);
159
179
  // differentiate between widening points and other vertices
160
180
  if (this.isWideningPoint(nodeId)) {
161
181
  const oldState = this.trace.get(nodeId);
@@ -175,37 +195,21 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
175
195
  this.currentState = this.currentState.top();
176
196
  }
177
197
  this.trace.set(nodeId, this.currentState);
178
- const predecessorVisits = predecessors.map(pred => this.visited.get(pred) ?? 0);
198
+ const predecessorVisits = predecessors.map(pred => this.visited.get(pred.id) ?? 0);
179
199
  const visitedCount = this.visited.get(nodeId) ?? 0;
180
200
  this.visited.set(nodeId, visitedCount + 1);
181
201
  // continue visiting if vertex is not a join vertex or number of visits of predecessors is the same
182
202
  return predecessors.length <= 1 || this.stack.length === 0 || predecessorVisits.every(visits => visits === predecessorVisits[0]);
183
203
  }
184
204
  }
185
- visitUnknown(vertex) {
186
- const nodeId = control_flow_graph_1.CfgVertex.getRootId(vertex);
187
- const replacements = this.replacements.get(nodeId);
188
- if (replacements !== undefined) {
189
- this.replacements.delete(nodeId);
190
- for (const replacement of replacements) {
191
- const call = this.getDataflowGraph(replacement);
192
- if (vertex_1.FunctionCallVertex.is(call)) {
193
- this.onReplacementCall({ call, ...this.getSourceAndTarget(call) });
194
- }
195
- }
196
- }
197
- }
198
205
  onDispatchFunctionCallOrigin(call, origin) {
199
206
  if (origin === built_in_proc_name_1.BuiltInProcName.Replacement) {
200
- const node = this.getNormalizedAst(call.id);
201
- const assignment = model_1.RNode.iterateParents(node, this.config.normalizedAst.idMap)
202
- .find(parent => this.getDataflowGraph(parent.info.id) === undefined);
203
- if (node !== undefined && assignment !== undefined) {
204
- const replacements = this.replacements.get(assignment.info.id) ?? [];
205
- replacements.push(node.info.id);
206
- this.replacements.set(assignment.info.id, replacements);
207
- return;
208
- }
207
+ /*
208
+ * A replacement is the last thing its statement does (the target and the value are evaluated first),
209
+ * so it is handled where it is visited; the `<-` it was rewritten from has no vertex to defer to.
210
+ */
211
+ this.onReplacementCall({ call, ...this.getSourceAndTarget(call) });
212
+ return;
209
213
  }
210
214
  super.onDispatchFunctionCallOrigin(call, origin);
211
215
  switch (origin) {
@@ -218,7 +222,6 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
218
222
  case built_in_proc_name_1.BuiltInProcName.Assignment:
219
223
  case built_in_proc_name_1.BuiltInProcName.AssignmentLike:
220
224
  case built_in_proc_name_1.BuiltInProcName.TableAssignment:
221
- case built_in_proc_name_1.BuiltInProcName.Replacement:
222
225
  case built_in_proc_name_1.BuiltInProcName.Access:
223
226
  case built_in_proc_name_1.BuiltInProcName.Pipe:
224
227
  case built_in_proc_name_1.BuiltInProcName.Break:
@@ -262,22 +265,148 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
262
265
  * @protected
263
266
  */
264
267
  onFunctionCall(_data) { }
265
- /** Gets all AST nodes for the predecessor vertices that are leaf nodes and exit vertices */
266
- getPredecessorNodes(vertexId) {
267
- return this.config.controlFlow.graph.outgoingEdges(vertexId)?.keys() // outgoing dependency edges are ingoing CFG edges
268
- .map(id => this.getCfgVertex(id))
269
- .flatMap(vertex => {
268
+ /**
269
+ * Everything the control flow may come from to reach this vertex, together with the branch it took to get here.
270
+ * Skipped vertices hold no state of their own, so what led into them is reported instead.
271
+ */
272
+ getPredecessors(vertexId) {
273
+ const result = [];
274
+ for (const [id, edge] of this.config.controlFlow.graph.ingoingEdges(vertexId) ?? graph_1.NoEdges) {
275
+ const branch = control_flow_graph_1.CfgEdge.isControlDependency(edge) ? edge : undefined;
276
+ const vertex = this.getCfgVertex(id);
270
277
  if (vertex === undefined) {
271
- return [];
278
+ continue;
272
279
  }
273
280
  else if (this.shouldSkipVertex(vertex)) {
274
- return this.getPredecessorNodes(control_flow_graph_1.CfgVertex.getId(vertex));
281
+ /* the branch closest to us is the one that decided we get here at all, so it wins */
282
+ result.push(...this.getPredecessors(id).map(pred => branch ? { ...pred, branch } : pred));
275
283
  }
276
284
  else {
277
- return [control_flow_graph_1.CfgVertex.getRootId(vertex)];
285
+ result.push({ id, branch });
278
286
  }
279
- })
280
- .toArray() ?? [];
287
+ }
288
+ /* a body has no predecessor of its own, so what runs before it is the call we stepped in from */
289
+ const enteredFrom = this.enteredFrom.get(vertexId);
290
+ if (enteredFrom !== undefined) {
291
+ result.push({ id: enteredFrom });
292
+ }
293
+ return result;
294
+ }
295
+ /**
296
+ * The abstract state one predecessor contributes, joined into the state at the current vertex.
297
+ *
298
+ * By default, this is the state as the predecessor left it. Override it to apply condition semantics:
299
+ * on the then-branch of `if(u) a else b` the predecessor is `u` and `branch.when` is `true`, so `u` held.
300
+ */
301
+ getPredecessorState({ id }) {
302
+ return this.trace.get(id);
303
+ }
304
+ visitFunctionCall(call) {
305
+ super.visitFunctionCall(call);
306
+ if (this.shouldEnterCall(call)) {
307
+ this.currentState = this.enterCall(call.id) ?? this.currentState;
308
+ }
309
+ }
310
+ /**
311
+ * Whether the traversal should step into what the given call dispatches to.
312
+ * Returning `true` runs the bodies and continues with the state at their exit points.
313
+ */
314
+ shouldEnterCall(_call) {
315
+ return false;
316
+ }
317
+ /**
318
+ * The function definitions the given call may dispatch to.
319
+ * Built-in functions have no definition in the source, so they are not part of this.
320
+ */
321
+ getCallTargets(callId) {
322
+ const targets = control_flow_graph_1.CfgVertex.getCallTargets(this.getCfgVertex(callId));
323
+ return targets === undefined ? control_flow_graph_1.NoNeighbors : [...targets];
324
+ }
325
+ /** Where a function definition starts, i.e. the first thing that runs when it is called. */
326
+ getFunctionEntry(defId) {
327
+ const def = this.getDataflowGraph(defId);
328
+ return vertex_1.FunctionDefinitionVertex.is(def) ? def.subflow.cfgEntry ?? def.subflow.entryPoint : undefined;
329
+ }
330
+ /** Where a function definition is left, i.e. its last expressions and `return` calls. */
331
+ getFunctionExits(defId) {
332
+ const def = this.getDataflowGraph(defId);
333
+ return vertex_1.FunctionDefinitionVertex.is(def) ? def.exitPoints.map(exit => exit.nodeId) : control_flow_graph_1.NoNeighbors;
334
+ }
335
+ /**
336
+ * Runs the bodies the given call dispatches to, starting from the state at the call, and returns the state
337
+ * control comes back with: the states at their exit points joined.
338
+ * A call already being interpreted is not entered again, so recursion stops at the second entry.
339
+ * @returns the state at the exit points, or `undefined` if the call reaches nothing to step into
340
+ */
341
+ enterCall(callId) {
342
+ const states = [];
343
+ const values = [];
344
+ const outerState = this.currentState;
345
+ for (const def of this.getCallTargets(callId)) {
346
+ const entry = this.getFunctionEntry(def);
347
+ if (entry === undefined || this.running.has(def)) {
348
+ continue;
349
+ }
350
+ this.running.add(def);
351
+ this.bindParameters(callId, def);
352
+ /* the entry picks its state up from the call, which is what makes the arguments visible in the body */
353
+ this.trace.set(callId, outerState);
354
+ this.enteredFrom.set(entry, callId);
355
+ const outerStack = this.stack;
356
+ this.startVisitor([entry]);
357
+ this.stack = outerStack;
358
+ this.enteredFrom.delete(entry);
359
+ this.running.delete(def);
360
+ for (const exit of this.getFunctionExits(def)) {
361
+ const state = this.trace.get(exit);
362
+ if (state === undefined) {
363
+ continue;
364
+ }
365
+ states.push(state);
366
+ const value = this.getAbstractValue(exit, state);
367
+ if (value !== undefined) {
368
+ values.push(value);
369
+ }
370
+ }
371
+ }
372
+ this.currentState = outerState;
373
+ if (states.length === 0) {
374
+ return undefined;
375
+ }
376
+ const returned = abstract_domain_1.AbstractDomain.joinAll(states);
377
+ if (values.length > 0) {
378
+ /* what the call is worth is what its function leaves behind at its exits */
379
+ returned.set(callId, abstract_domain_1.AbstractDomain.joinAll(values));
380
+ }
381
+ return returned;
382
+ }
383
+ /**
384
+ * Hand the arguments of the call to the parameters of the function it enters, so the body can read them.
385
+ * Only the arguments of this very call are used, whichever other calls the function has.
386
+ */
387
+ bindParameters(callId, defId) {
388
+ const call = this.getDataflowGraph(callId);
389
+ const definition = this.getDataflowGraph(defId);
390
+ if (!vertex_1.FunctionCallVertex.is(call) || !vertex_1.FunctionDefinitionVertex.is(definition)) {
391
+ return;
392
+ }
393
+ const args = new Set(call.args.filter(graph_1.FunctionArgument.isNotEmpty).map(arg => arg.nodeId));
394
+ for (const key of Object.keys(definition.params)) {
395
+ /* object keys are strings, the graph keys its vertices by the id itself */
396
+ const parameter = node_id_1.NodeId.normalize(key);
397
+ for (const [target, edge] of this.config.dfg.outgoingEdges(parameter) ?? graph_1.NoEdges) {
398
+ if (!edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinedByOnCall) || !args.has(target)) {
399
+ continue;
400
+ }
401
+ const value = this.getAbstractValue(target, this.currentState);
402
+ if (value !== undefined) {
403
+ this.currentState.set(parameter, value);
404
+ /* the parameter is a definition like any other, so the body only reads it once it counts as assigned */
405
+ this.trace.set(parameter, this.currentState);
406
+ this.unassigned.delete(parameter);
407
+ }
408
+ }
409
+ }
281
410
  }
282
411
  /** Gets each variable origin that has already been visited and whose assignment has already been processed */
283
412
  getVariableOrigins(nodeId) {
@@ -290,32 +419,64 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
290
419
  isUnsupportedFunctionCall(nodeId) {
291
420
  return unsupported_functions_1.UnsupportedFunctions.isUnsupportedCall(this.getDataflowGraph(nodeId), this.config.dfg);
292
421
  }
293
- /** We only perform widening at `for`, `while`, or `repeat` loops with more than one ingoing CFG edge */
422
+ /**
423
+ * We widen wherever the control flow comes back around, i.e. at the node a back edge leads to.
424
+ * That is what makes the iteration terminate, and it is the loop head whichever loop the code used:
425
+ * the condition of a `while`, the binding of a `for`, or the first statement of a `repeat`.
426
+ */
294
427
  isWideningPoint(nodeId) {
295
- const ingoingEdges = this.config.controlFlow.graph.outgoingEdges(nodeId)?.size; // outgoing dependency edges are ingoing CFG edges
296
- if (ingoingEdges === undefined || ingoingEdges <= 1) {
297
- return false;
298
- }
299
- else if (model_1.RLoopConstructs.is(this.getNormalizedAst(nodeId))) {
300
- return true;
428
+ this.wideningPoints ??= this.findWideningPoints();
429
+ return this.wideningPoints.has(nodeId);
430
+ }
431
+ /** The targets of the back edges of the control flow graph, found with one depth-first search. */
432
+ findWideningPoints() {
433
+ const graph = this.config.controlFlow.graph;
434
+ const heads = new Set();
435
+ const onPath = new Set();
436
+ const done = new Set();
437
+ for (const start of this.startingPoints()) {
438
+ if (done.has(start)) {
439
+ continue;
440
+ }
441
+ const stack = [stepFrom(graph, start)];
442
+ onPath.add(start);
443
+ while (stack.length > 0) {
444
+ const step = stack[stack.length - 1];
445
+ if (step.at >= step.successors.length) {
446
+ onPath.delete(step.node);
447
+ done.add(step.node);
448
+ stack.pop();
449
+ continue;
450
+ }
451
+ const next = step.successors[step.at++];
452
+ if (onPath.has(next)) {
453
+ /* the path leads back to a node it already runs through, so this is where the loop closes */
454
+ heads.add(next);
455
+ }
456
+ else if (!done.has(next)) {
457
+ onPath.add(next);
458
+ stack.push(stepFrom(graph, next));
459
+ }
460
+ }
301
461
  }
302
- const dataflowVertex = this.getDataflowGraph(nodeId);
303
- if (!vertex_1.FunctionCallVertex.is(dataflowVertex) || !Array.isArray(dataflowVertex.origin)) {
304
- return false;
462
+ return heads;
463
+ }
464
+ /** Everywhere the control flow may start: the program itself, and every function body, as nothing flows into one. */
465
+ startingPoints() {
466
+ const graph = this.config.controlFlow.graph;
467
+ const starts = [...this.config.controlFlow.entryPoints];
468
+ for (const [id] of graph.vertices(false)) {
469
+ starts.push(...graph.childrenOf(id) ?? control_flow_graph_1.NoNeighbors);
305
470
  }
306
- const origin = dataflowVertex.origin;
307
- return origin.includes(built_in_proc_name_1.BuiltInProcName.ForLoop) || origin.includes(built_in_proc_name_1.BuiltInProcName.WhileLoop) || origin.includes(built_in_proc_name_1.BuiltInProcName.RepeatLoop);
471
+ return starts;
308
472
  }
309
473
  /**
310
474
  * Checks whether a control flow graph vertex should be skipped during visitation.
311
- * By default, we only process entry vertices of widening points, vertices of leaf nodes, and exit vertices (no entry nodes of complex nodes).
475
+ * Every node has exactly one vertex, reached once its operands are evaluated, so nothing is skipped
476
+ * by default; overriding this lets an analysis ignore parts of the program.
312
477
  */
313
- shouldSkipVertex(vertex) {
314
- if (this.isWideningPoint(control_flow_graph_1.CfgVertex.getRootId(vertex))) {
315
- // skip exit vertices of widening points
316
- return control_flow_graph_1.CfgVertex.isMarker(vertex);
317
- }
318
- return !control_flow_graph_1.CfgVertex.isMarker(vertex) && !control_flow_graph_1.CfgVertex.isBlock(vertex) && control_flow_graph_1.CfgVertex.getEnd(vertex) !== undefined;
478
+ shouldSkipVertex(_vertex) {
479
+ return false;
319
480
  }
320
481
  /**
321
482
  * Whether widening should be performed at a widening point.
@@ -1,7 +1,7 @@
1
1
  import type { DataflowGraph } from '../../../dataflow/graph/graph';
2
2
  import type { ReadOnlyFlowrAnalyzerContext } from '../../../project/context/flowr-analyzer-context';
3
3
  import type { RNode } from '../../../r-bridge/lang-4.x/ast/model/model';
4
- import type { RAccess, RNamedAccess } from '../../../r-bridge/lang-4.x/ast/model/nodes/r-access';
4
+ import { RAccess, type RNamedAccess } from '../../../r-bridge/lang-4.x/ast/model/nodes/r-access';
5
5
  import type { ParentInformation } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
6
6
  import type { DataFrameOperations, DataFrameShapeInferenceVisitor } from '../shape-inference';
7
7
  /**