@eagleoutice/flowr 2.14.1 → 2.14.3

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 (419) hide show
  1. package/README.md +142 -87
  2. package/abstract-interpretation/absint-visitor.d.ts +132 -25
  3. package/abstract-interpretation/absint-visitor.js +459 -99
  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 +21 -8
  41. package/config.js +12 -5
  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 -3
  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 +114 -3
  71. package/dataflow/environments/default-builtin-config.js +137 -35
  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 +3 -3
  81. package/dataflow/eval/resolve/alias-tracking.js +3 -3
  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 +15 -6
  106. package/dataflow/info.js +0 -17
  107. package/dataflow/internal/control-flow.d.ts +114 -0
  108. package/dataflow/internal/control-flow.js +224 -0
  109. package/dataflow/internal/linker.d.ts +6 -31
  110. package/dataflow/internal/linker.js +24 -81
  111. package/dataflow/internal/process/functions/call/argument/unpack-argument.d.ts +1 -1
  112. package/dataflow/internal/process/functions/call/argument/unpack-argument.js +3 -3
  113. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +2 -2
  114. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +9 -6
  115. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +1 -1
  116. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +6 -4
  117. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +1 -10
  118. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +18 -37
  119. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +1 -1
  120. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +3 -3
  121. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +1 -1
  122. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +11 -7
  123. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +6 -8
  124. package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +1 -1
  125. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +18 -14
  126. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +18 -2
  127. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +12 -1
  128. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +2 -1
  129. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +38 -30
  130. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +3 -2
  131. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.d.ts +1 -1
  132. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +36 -8
  133. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +1 -1
  134. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +20 -17
  135. package/dataflow/internal/process/functions/call/built-in/built-in-list.d.ts +1 -1
  136. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +6 -4
  137. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +4 -3
  138. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +9 -4
  139. package/dataflow/internal/process/functions/call/built-in/built-in-namespace-access.d.ts +2 -2
  140. package/dataflow/internal/process/functions/call/built-in/built-in-namespace-access.js +5 -5
  141. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.d.ts +1 -1
  142. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +5 -4
  143. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +7 -5
  144. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.d.ts +1 -1
  145. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +15 -13
  146. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +1 -1
  147. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +11 -2
  148. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +2 -2
  149. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +4 -3
  150. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.d.ts +1 -1
  151. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +26 -4
  152. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +2 -2
  153. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +17 -4
  154. package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +2 -2
  155. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +71 -33
  156. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +6 -15
  157. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +13 -14
  158. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +1 -1
  159. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +14 -11
  160. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +15 -1
  161. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +1 -1
  162. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +12 -8
  163. package/dataflow/internal/process/functions/call/built-in/built-in-stop-if-not.js +6 -5
  164. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.d.ts +1 -1
  165. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.js +5 -4
  166. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +2 -2
  167. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +50 -10
  168. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +2 -2
  169. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +20 -4
  170. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +6 -2
  171. package/dataflow/internal/process/functions/call/common.js +5 -6
  172. package/dataflow/internal/process/functions/call/deferred.js +2 -2
  173. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +12 -2
  174. package/dataflow/internal/process/functions/call/known-call-handling.js +41 -15
  175. package/dataflow/internal/process/functions/call/named-call-handling.js +2 -0
  176. package/dataflow/internal/process/functions/call/nse.d.ts +1 -1
  177. package/dataflow/internal/process/functions/call/nse.js +6 -1
  178. package/dataflow/internal/process/functions/call/quoted.js +2 -2
  179. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +19 -6
  180. package/dataflow/internal/process/functions/process-argument.d.ts +1 -1
  181. package/dataflow/internal/process/functions/process-argument.js +12 -4
  182. package/dataflow/internal/process/functions/process-parameter.js +13 -0
  183. package/dataflow/internal/process/process-named-call.d.ts +2 -2
  184. package/dataflow/internal/process/process-named-call.js +9 -7
  185. package/documentation/data/server/doc-data-server-messages.js +4 -4
  186. package/documentation/doc-readme.js +33 -0
  187. package/documentation/doc-util/doc-cfg.d.ts +8 -7
  188. package/documentation/doc-util/doc-cfg.js +10 -10
  189. package/documentation/doc-util/doc-playground.d.ts +12 -0
  190. package/documentation/doc-util/doc-playground.js +21 -0
  191. package/documentation/doc-util/doc-query.d.ts +4 -1
  192. package/documentation/doc-util/doc-query.js +4 -2
  193. package/documentation/wiki-absint.d.ts +3 -4
  194. package/documentation/wiki-absint.js +17 -5
  195. package/documentation/wiki-analyzer.js +2 -2
  196. package/documentation/wiki-cfg.js +101 -106
  197. package/documentation/wiki-dataflow-graph.js +84 -53
  198. package/documentation/wiki-interface.js +1 -0
  199. package/documentation/wiki-linter.js +15 -1
  200. package/documentation/wiki-linting-and-testing.js +1 -16
  201. package/documentation/wiki-mk/doc-maker.js +6 -4
  202. package/documentation/wiki-query.js +14 -4
  203. package/documentation/wiki-signature-database.js +28 -2
  204. package/linter/linter-fix.d.ts +16 -0
  205. package/linter/linter-fix.js +104 -0
  206. package/linter/linter-format.d.ts +18 -1
  207. package/linter/linter-format.js +31 -1
  208. package/linter/linter-output.js +46 -10
  209. package/linter/linter-rules.d.ts +40 -9
  210. package/linter/linter-rules.js +2 -0
  211. package/linter/rules/absolute-path.js +4 -2
  212. package/linter/rules/dataframe-access-validation.js +6 -7
  213. package/linter/rules/deprecated-functions.d.ts +107 -10
  214. package/linter/rules/deprecated-functions.js +311 -23
  215. package/linter/rules/file-path-validity.js +5 -4
  216. package/linter/rules/function-finder-util.d.ts +6 -0
  217. package/linter/rules/function-finder-util.js +21 -13
  218. package/linter/rules/naming-convention.js +1 -1
  219. package/linter/rules/network-functions.d.ts +2 -2
  220. package/linter/rules/stop-with-call-arg.js +2 -2
  221. package/linter/rules/unclosed-connection.js +2 -2
  222. package/linter/rules/undefined-symbol-util.js +6 -4
  223. package/linter/rules/undefined-symbol.js +2 -2
  224. package/linter/rules/unused-definition.js +8 -4
  225. package/linter/rules/unused-import.d.ts +60 -0
  226. package/linter/rules/unused-import.js +179 -0
  227. package/package.json +2 -2
  228. package/project/attached-packages.js +2 -1
  229. package/project/cache/flowr-analyzer-cache.d.ts +2 -5
  230. package/project/cache/flowr-analyzer-cache.js +4 -7
  231. package/project/cache/flowr-analyzer-controlflow-cache.d.ts +9 -8
  232. package/project/cache/flowr-analyzer-controlflow-cache.js +17 -34
  233. package/project/cache/flowr-cache.d.ts +9 -0
  234. package/project/cache/flowr-cache.js +19 -0
  235. package/project/context/flowr-analyzer-context.d.ts +7 -3
  236. package/project/context/flowr-analyzer-context.js +15 -9
  237. package/project/context/flowr-analyzer-dependencies-context.d.ts +24 -3
  238. package/project/context/flowr-analyzer-dependencies-context.js +9 -14
  239. package/project/context/flowr-analyzer-files-context.js +15 -17
  240. package/project/context/flowr-analyzer-meta-context.js +2 -12
  241. package/project/dependency-version-space.d.ts +1 -7
  242. package/project/dependency-version-space.js +9 -8
  243. package/project/flowr-analyzer-builder.d.ts +4 -4
  244. package/project/flowr-analyzer.d.ts +4 -6
  245. package/project/flowr-analyzer.js +4 -5
  246. package/project/plugins/file-plugins/files/flowr-namespace-file.js +22 -34
  247. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +13 -13
  248. package/project/plugins/file-plugins/files/flowr-rda-file.js +131 -286
  249. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +1 -0
  250. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +1 -0
  251. package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.d.ts +2 -5
  252. package/project/plugins/file-plugins/flowr-analyzer-description-file-plugin.js +2 -8
  253. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.d.ts +32 -0
  254. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +43 -1
  255. package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.d.ts +4 -12
  256. package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.js +3 -16
  257. package/project/plugins/file-plugins/flowr-analyzer-license-file-plugin.d.ts +5 -8
  258. package/project/plugins/file-plugins/flowr-analyzer-license-file-plugin.js +4 -10
  259. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +3 -10
  260. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +1 -13
  261. package/project/plugins/file-plugins/flowr-analyzer-namespace-files-plugin.d.ts +3 -6
  262. package/project/plugins/file-plugins/flowr-analyzer-namespace-files-plugin.js +2 -8
  263. package/project/plugins/file-plugins/flowr-analyzer-news-file-plugin.d.ts +2 -5
  264. package/project/plugins/file-plugins/flowr-analyzer-news-file-plugin.js +2 -8
  265. package/project/plugins/file-plugins/flowr-analyzer-rda-file-plugin.d.ts +2 -5
  266. package/project/plugins/file-plugins/flowr-analyzer-rda-file-plugin.js +2 -8
  267. package/project/plugins/file-plugins/flowr-analyzer-rprofile-file-plugin.d.ts +3 -4
  268. package/project/plugins/file-plugins/flowr-analyzer-rprofile-file-plugin.js +3 -6
  269. package/project/plugins/file-plugins/flowr-analyzer-test-file-plugin.d.ts +4 -12
  270. package/project/plugins/file-plugins/flowr-analyzer-test-file-plugin.js +3 -16
  271. package/project/plugins/file-plugins/flowr-analyzer-vignette-file-plugin.d.ts +4 -12
  272. package/project/plugins/file-plugins/flowr-analyzer-vignette-file-plugin.js +3 -16
  273. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +4 -12
  274. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -16
  275. package/project/plugins/file-plugins/notebooks/flowr-analyzer-jupyter-file-plugin.d.ts +2 -5
  276. package/project/plugins/file-plugins/notebooks/flowr-analyzer-jupyter-file-plugin.js +2 -8
  277. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.d.ts +2 -6
  278. package/project/plugins/file-plugins/notebooks/flowr-analyzer-rmarkdown-file-plugin.js +1 -10
  279. package/project/plugins/file-plugins/notebooks/flowr-analyzer-sweave-file-plugin.d.ts +2 -5
  280. package/project/plugins/file-plugins/notebooks/flowr-analyzer-sweave-file-plugin.js +2 -8
  281. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-library-plugin.js +2 -1
  282. package/project/sigdb/build.d.ts +2 -2
  283. package/project/sigdb/decode.d.ts +0 -5
  284. package/project/sigdb/decode.js +0 -8
  285. package/project/sigdb/index-format.d.ts +4 -4
  286. package/project/sigdb/manifest.d.ts +2 -2
  287. package/project/sigdb/reader.d.ts +54 -13
  288. package/project/sigdb/reader.js +4 -3
  289. package/project/sigdb/schema.d.ts +3 -1
  290. package/project/sigdb/signature-db.d.ts +69 -0
  291. package/project/sigdb/signature-db.js +54 -0
  292. package/project/sigdb/signature-match.d.ts +10 -5
  293. package/project/sigdb/signature-match.js +13 -8
  294. package/queries/catalog/absint-query/absint-query-executor.js +1 -2
  295. package/queries/catalog/call-context-query/call-context-query-executor.js +2 -4
  296. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.d.ts +1 -1
  297. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +33 -6
  298. package/queries/catalog/control-flow-query/control-flow-query-executor.js +1 -2
  299. package/queries/catalog/dependencies-query/dependencies-query-executor.js +2 -2
  300. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +8 -7
  301. package/queries/catalog/dependencies-query/dependencies-query-format.js +22 -35
  302. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +13 -1
  303. package/queries/catalog/dependencies-query/function-info/library-functions.js +26 -22
  304. package/queries/catalog/dependencies-query/function-info/statistics-functions.d.ts +9 -0
  305. package/queries/catalog/dependencies-query/function-info/statistics-functions.js +19 -0
  306. package/queries/catalog/dependencies-query/implicit-echo.d.ts +13 -0
  307. package/queries/catalog/dependencies-query/implicit-echo.js +133 -0
  308. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +2 -2
  309. package/queries/catalog/happens-before-query/happens-before-query-executor.js +1 -2
  310. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.d.ts +2 -2
  311. package/queries/catalog/signature-query/signature-query-executor.js +4 -3
  312. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +1 -1
  313. package/r-bridge/lang-4.x/ast/model/nodes/info/r-delimiter.d.ts +1 -0
  314. package/r-bridge/lang-4.x/ast/model/nodes/info/r-delimiter.js +1 -0
  315. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  316. package/r-bridge/lang-4.x/ast/model/nodes/r-access.js +1 -0
  317. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +4 -1
  318. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -2
  319. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  320. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.js +1 -0
  321. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  322. package/r-bridge/lang-4.x/ast/model/nodes/r-break.js +1 -0
  323. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  324. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.js +1 -0
  325. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  326. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.js +1 -0
  327. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  328. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.js +1 -0
  329. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +6 -4
  330. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +6 -4
  331. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  332. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.js +1 -0
  333. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  334. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.js +1 -0
  335. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  336. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.js +1 -0
  337. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  338. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.js +1 -0
  339. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  340. package/r-bridge/lang-4.x/ast/model/nodes/r-next.js +1 -0
  341. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +6 -0
  342. package/r-bridge/lang-4.x/ast/model/nodes/r-number.js +13 -0
  343. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +8 -0
  344. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.js +8 -0
  345. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  346. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.js +1 -0
  347. package/r-bridge/lang-4.x/ast/model/nodes/r-project.d.ts +1 -0
  348. package/r-bridge/lang-4.x/ast/model/nodes/r-project.js +1 -0
  349. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  350. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.js +1 -0
  351. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  352. package/r-bridge/lang-4.x/ast/model/nodes/r-string.js +1 -0
  353. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  354. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.js +1 -0
  355. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  356. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.js +1 -0
  357. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  358. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.js +1 -0
  359. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +2 -1
  360. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +5 -1
  361. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +0 -5
  362. package/r-bridge/lang-4.x/ast/model/processing/stateful-fold.d.ts +1 -1
  363. package/r-bridge/lang-4.x/ast/model/processing/stateful-fold.js +3 -2
  364. package/r-bridge/lang-4.x/ast/parser/main/internal/control/normalize-if-then-else.js +2 -1
  365. package/r-bridge/lang-4.x/ast/parser/main/internal/control/normalize-if-then.js +2 -1
  366. package/r-bridge/lang-4.x/ast/parser/main/internal/expression/normalize-expression.js +1 -1
  367. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-argument.js +2 -1
  368. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-call.d.ts +2 -2
  369. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-call.js +6 -3
  370. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-definition.js +2 -1
  371. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-parameter.js +2 -1
  372. package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-for.js +5 -3
  373. package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-repeat.js +2 -1
  374. package/r-bridge/lang-4.x/ast/parser/main/internal/loops/normalize-while.js +2 -1
  375. package/r-bridge/lang-4.x/ast/parser/main/internal/normalize-access.js +2 -1
  376. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-binary.js +5 -3
  377. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-unary.js +2 -1
  378. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.d.ts +1 -1
  379. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.js +2 -1
  380. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-root.js +3 -1
  381. package/r-bridge/lang-4.x/ast/parser/main/normalize-meta.d.ts +1 -1
  382. package/r-bridge/lang-4.x/ast/parser/main/normalize-meta.js +2 -1
  383. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +5 -3
  384. package/reconstruct/inline/source-inline-map.js +3 -3
  385. package/reconstruct/reconstruct.js +6 -4
  386. package/search/flowr-search-builder.d.ts +8 -8
  387. package/search/flowr-search-builder.js +4 -4
  388. package/search/flowr-search-filters.d.ts +2 -2
  389. package/search/flowr-search-filters.js +3 -2
  390. package/search/search-executor/search-enrichers.d.ts +6 -0
  391. package/search/search-executor/search-enrichers.js +44 -5
  392. package/slicing/criterion/filters/all-variables.js +2 -1
  393. package/slicing/criterion/parse.js +8 -6
  394. package/slicing/static/slice-call.js +2 -2
  395. package/util/arg-matching.d.ts +3 -0
  396. package/util/arg-matching.js +12 -1
  397. package/util/collections/arrays.d.ts +0 -4
  398. package/util/collections/arrays.js +4 -26
  399. package/util/diff-graph.d.ts +1 -1
  400. package/util/diff-graph.js +17 -3
  401. package/util/diff.d.ts +6 -0
  402. package/util/mermaid/ast.d.ts +1 -1
  403. package/util/mermaid/ast.js +5 -4
  404. package/util/mermaid/cfg.js +130 -24
  405. package/util/mermaid/dfg.js +31 -10
  406. package/util/mermaid/mermaid.js +2 -0
  407. package/util/objects.d.ts +24 -4
  408. package/util/objects.js +12 -0
  409. package/util/prefix.d.ts +1 -1
  410. package/util/text/playground-link.d.ts +131 -0
  411. package/util/text/playground-link.js +214 -0
  412. package/util/text/strings.js +7 -3
  413. package/util/version.js +1 -1
  414. package/control-flow/cfg-builder.d.ts +0 -30
  415. package/control-flow/cfg-builder.js +0 -79
  416. package/control-flow/extract-cfg.d.ts +0 -36
  417. package/control-flow/extract-cfg.js +0 -693
  418. package/project/cfg-kind.d.ts +0 -21
  419. package/project/cfg-kind.js +0 -26
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.RDAParser = exports.SerializationFormat = exports.SexpType = exports.SerializationTypeTag = exports.CompressionType = exports.FlowrRDAFile = void 0;
7
7
  const flowr_file_1 = require("../../../context/flowr-file");
8
8
  const fs_1 = __importDefault(require("fs"));
9
+ const assert_1 = require("../../../../util/assert");
9
10
  const r_fun_tab_1 = require("./r-fun-tab");
10
11
  const shell_executor_1 = require("../../../../r-bridge/shell-executor");
11
12
  /**
@@ -24,7 +25,7 @@ class FlowrRDAFile extends flowr_file_1.FlowrFile {
24
25
  constructor(file, shortcut = true) {
25
26
  super(file.path(), file.roles);
26
27
  this.wrapped = file;
27
- this.shortcut = shortcut ?? false;
28
+ this.shortcut = shortcut;
28
29
  }
29
30
  /**
30
31
  * Loads and parses the content of the wrapped file as an RDA structure.
@@ -62,6 +63,30 @@ var CompressionType;
62
63
  CompressionType["CompZstd"] = "COMP_ZSTD";
63
64
  CompressionType["CompUnknownOrNo"] = "COMP_UNKNOWN_OR_NO";
64
65
  })(CompressionType || (exports.CompressionType = CompressionType = {}));
66
+ /**
67
+ * The magic bytes {@link RDAParser.detectCompression} tries, in order: the first match wins, so a longer
68
+ * signature has to come before any shorter one it starts with.
69
+ * @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/connections.c#L2675-L2710 | R source: comp_type_from_memory}
70
+ */
71
+ const CompressionSignatures = [
72
+ { type: CompressionType.CompGz, magic: [0x1f, 0x8b] },
73
+ /* a zlib header is only two bytes and thus easy to hit by accident, so it is asked for explicitly */
74
+ { type: CompressionType.CompGz, zlibOnly: true, magic: [0x78, 0x9c] },
75
+ /* `BZh` + the block size as a digit, then one of the two block magics bzip2 opens a stream with */
76
+ { type: CompressionType.CompBz, magic: [0x42, 0x5a, 0x68, [0x31, 0x39], 0x31, 0x41, 0x59, 0x26, 0x53, 0x59] },
77
+ { type: CompressionType.CompBz, magic: [0x42, 0x5a, 0x68, [0x31, 0x39], 0x17, 0x72, 0x45, 0x38, 0x50, 0x90] },
78
+ { unsupported: 'this is a lzop-compressed file which this build of R does not support', magic: [0x89, 0x4c, 0x5a, 0x4f] },
79
+ { type: CompressionType.CompZstd, magic: [0x28, 0xb5, 0x2f, 0xfd] },
80
+ { type: CompressionType.CompXz, magic: [0xfd, 0x37, 0x7a, 0x58, 0x5a] },
81
+ { type: CompressionType.CompLzma, magic: [0xff, 0x4c, 0x5a, 0x4d, 0x41] },
82
+ /* lzma_alone, which has no magic of its own: this is the default filter/dictionary header */
83
+ { type: CompressionType.CompLzma, magic: [0x5d, 0x00, 0x00, 0x80, 0x00] }
84
+ ];
85
+ /** Whether `buf` starts with the given magic. */
86
+ function startsWithMagic(buf, magic) {
87
+ return buf.length >= magic.length
88
+ && magic.every((byte, i) => typeof byte === 'number' ? buf[i] === byte : buf[i] >= byte[0] && buf[i] <= byte[1]);
89
+ }
65
90
  /**
66
91
  * RDA file serialization format and version.
67
92
  * @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/saveload.c#L61-L72 | R source: saveload.c}
@@ -81,6 +106,27 @@ var SerializationTypeTag;
81
106
  SerializationTypeTag["MagicXdrV3"] = "R_MAGIC_XDR_V3";
82
107
  SerializationTypeTag["MagicMaybeTooNew"] = "R_MAGIC_MAYBE_TOONEW";
83
108
  })(SerializationTypeTag || (exports.SerializationTypeTag = SerializationTypeTag = {}));
109
+ /** The five-byte magic each serialization variant starts with. */
110
+ const SerializationMagic = {
111
+ 'RDA1\n': SerializationTypeTag.MagicAsciiV1,
112
+ 'RDB1\n': SerializationTypeTag.MagicBinaryV1,
113
+ 'RDX1\n': SerializationTypeTag.MagicXdrV1,
114
+ 'RDA2\n': SerializationTypeTag.MagicAsciiV2,
115
+ 'RDB2\n': SerializationTypeTag.MagicBinaryV2,
116
+ 'RDX2\n': SerializationTypeTag.MagicXdrV2,
117
+ 'RDA3\n': SerializationTypeTag.MagicAsciiV3,
118
+ 'RDB3\n': SerializationTypeTag.MagicBinaryV3,
119
+ 'RDX3\n': SerializationTypeTag.MagicXdrV3,
120
+ };
121
+ /** The variants {@link RDAParser.deserialize} handles. */
122
+ const SupportedSerializationTypes = new Set([
123
+ SerializationTypeTag.MagicAsciiV2, SerializationTypeTag.MagicBinaryV2, SerializationTypeTag.MagicXdrV2,
124
+ SerializationTypeTag.MagicAsciiV3, SerializationTypeTag.MagicBinaryV3, SerializationTypeTag.MagicXdrV3
125
+ ]);
126
+ /** The variants that would need the version one reader, see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/saveload.c#L2157-L2196 | R source: R_LoadSavedData}. */
127
+ const VersionOneSerializationTypes = new Set([
128
+ SerializationTypeTag.MagicAsciiV1, SerializationTypeTag.MagicBinaryV1, SerializationTypeTag.MagicXdrV1
129
+ ]);
84
130
  /**
85
131
  * Numeric identifiers for R SEXP types.
86
132
  * @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/include/Rinternals.h#L111-L144 | R source: SEXP}
@@ -174,33 +220,28 @@ class RDAParser {
174
220
  currentDepth = 0;
175
221
  static INITIAL_DEPTH = 1;
176
222
  lastName = undefined;
177
- setLastName = false;
178
223
  offset = 0;
179
224
  static R_CODE_SET_MAX = 2 ** 6 - 1;
180
225
  RWeakRefs = null;
181
- static CHUNK_SIZE = 8906;
182
226
  static SIZE_OF_DOUBLE = 2 ** 3;
183
227
  static WORD_SIZE = 2 ** 7;
184
228
  static MAX_VECTOR_LENGTH = 2 ** 16;
185
229
  format;
186
230
  refTable = [];
187
231
  Registry = null;
188
- opinfo = {
189
- addr: null,
190
- argc: null,
191
- instName: null
192
- };
232
+ /**
233
+ * @param file - The RDA file to read.
234
+ * @param shortcut - When `true`, only top-level object names and types are collected, payloads are skipped.
235
+ */
193
236
  constructor(file, shortcut = true) {
194
237
  this.file = file;
195
- this.shortcut = shortcut ?? true;
238
+ this.shortcut = shortcut;
196
239
  }
197
240
  /**
198
241
  * Parses an RDA file.
199
242
  *
200
- * The file is decompressed, deserialized, and converted into a flattened
201
- * object representation.
202
- * @param file - RDA file provider.
203
- * @param shortcut - When `true`, only names and types are collected.
243
+ * The file is decompressed, deserialized, and converted into a flattened object representation,
244
+ * as far as the `shortcut` the parser was constructed with asks for.
204
245
  * @returns List of found {@link RObjectData} or `null` if the file is empty.
205
246
  */
206
247
  parse() {
@@ -217,47 +258,21 @@ class RDAParser {
217
258
  }
218
259
  /**
219
260
  * Detects the compression algorithm used for an RDA file.
220
- * @param buf - Raw file buffer.
221
- * @param with_zlib - Whether zlib headers should also be considered.
222
- * @returns Detected {@link CompressionType}.
261
+ * @param buf - Raw file buffer.
262
+ * @param withZlib - Whether a bare zlib header should count as gzip, see {@link CompressionSignatures}.
263
+ * @returns The first {@link CompressionSignatures} entry the buffer matches, {@link CompressionType.CompUnknownOrNo} if none does.
264
+ * @throws Error if the file is of a recognized but unreadable kind.
223
265
  * @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/connections.c#L2675-L2710 | R source: comp_type_from_memory}
224
266
  */
225
- detectCompression(buf, with_zlib = false) {
226
- if (buf.length >= 2 && buf[0] == 0x1f && buf[1] == 0x8b) {
227
- return CompressionType.CompGz;
228
- }
229
- if (with_zlib && buf.length >= 2 && buf[0] == 0x78 && buf[1] == 0x9c) {
230
- return CompressionType.CompGz;
231
- }
232
- if (buf.length >= 10 && buf[0] === 0x42 && buf[1] === 0x5a && buf[2] === 0x68) {
233
- if (buf[3] >= 0x31 && buf[3] <= 0x39) {
234
- const magic1 = [0x31, 0x41, 0x59, 0x26, 0x53, 0x59];
235
- const magic2 = [0x17, 0x72, 0x45, 0x38, 0x50, 0x90];
236
- const isMagic1 = magic1.every((v, i) => buf[4 + i] === v);
237
- const isMagic2 = magic2.every((v, i) => buf[4 + i] === v);
238
- if (isMagic1 || isMagic2) {
239
- return CompressionType.CompBz;
240
- }
267
+ detectCompression(buf, withZlib = false) {
268
+ for (const signature of CompressionSignatures) {
269
+ if (!startsWithMagic(buf, signature.magic) || ('zlibOnly' in signature && signature.zlibOnly && !withZlib)) {
270
+ continue;
241
271
  }
242
- }
243
- if (buf.length >= 4) {
244
- if (buf.length >= 4 && buf[0] == 0x89 && buf[1] === 0x4c && buf[2] === 0x5a && buf[3] === 0x4f) {
245
- throw new Error('this is a lzop-compressed file which this build of R does not support');
246
- }
247
- else if (buf.length >= 4 && buf[0] === 0x28 && buf[1] === 0xB5 && buf[2] === 0x2F && buf[3] === 0xFD) {
248
- return CompressionType.CompZstd;
249
- }
250
- }
251
- if (buf.length >= 5) {
252
- if (buf[0] === 0xFD && buf[1] === 0x37 && buf[2] === 0x7a && buf[3] === 0x58 && buf[4] === 0x5a) {
253
- return CompressionType.CompXz;
254
- }
255
- else if (buf[0] === 0xFF && buf[1] === 0x4C && buf[2] === 0x5A && buf[3] === 0x4D && buf[4] === 0x41) {
256
- return CompressionType.CompLzma;
257
- }
258
- else if (buf[0] === 0x5D && buf[1] === 0x00 && buf[2] === 0x00 && buf[3] === 0x80 && buf[4] === 0x00) {
259
- return CompressionType.CompLzma;
272
+ else if ('unsupported' in signature) {
273
+ throw new Error(signature.unsupported);
260
274
  }
275
+ return signature.type;
261
276
  }
262
277
  return CompressionType.CompUnknownOrNo;
263
278
  }
@@ -295,14 +310,13 @@ class RDAParser {
295
310
  }
296
311
  case CompressionType.CompXz:
297
312
  case CompressionType.CompLzma:
298
- case CompressionType.CompZstd: {
299
- throw new Error(compressionType + 'not supported yet.');
300
- }
313
+ case CompressionType.CompZstd:
314
+ throw new Error(`${compressionType} is not supported yet.`);
301
315
  case CompressionType.CompUnknownOrNo:
302
316
  buffer = fileContent;
303
317
  break;
304
318
  default:
305
- throw new Error('Unknown or unsupported compression type.');
319
+ (0, assert_1.assertUnreachable)(compressionType);
306
320
  }
307
321
  return buffer;
308
322
  }
@@ -322,29 +336,13 @@ class RDAParser {
322
336
  }
323
337
  }
324
338
  const magic = buf.toString('ascii', 0, 5);
325
- switch (magic) {
326
- case 'RDA1\n':
327
- return SerializationTypeTag.MagicAsciiV1;
328
- case 'RDB1\n':
329
- return SerializationTypeTag.MagicBinaryV1;
330
- case 'RDX1\n':
331
- return SerializationTypeTag.MagicXdrV1;
332
- case 'RDA2\n':
333
- return SerializationTypeTag.MagicAsciiV2;
334
- case 'RDB2\n':
335
- return SerializationTypeTag.MagicBinaryV2;
336
- case 'RDX2\n':
337
- return SerializationTypeTag.MagicXdrV2;
338
- case 'RDA3\n':
339
- return SerializationTypeTag.MagicAsciiV3;
340
- case 'RDB3\n':
341
- return SerializationTypeTag.MagicBinaryV3;
342
- case 'RDX3\n':
343
- return SerializationTypeTag.MagicXdrV3;
344
- }
345
- if (magic.startsWith('RD')) {
339
+ if (magic in SerializationMagic) {
340
+ return SerializationMagic[magic];
341
+ }
342
+ else if (magic.startsWith('RD')) {
346
343
  return SerializationTypeTag.MagicMaybeTooNew;
347
344
  }
345
+ /* no magic at all: the first four bytes are the version number of a pre-magic workspace */
348
346
  return Number(buf.toString('ascii', 0, 4));
349
347
  }
350
348
  /**
@@ -356,26 +354,15 @@ class RDAParser {
356
354
  this.offset = 0;
357
355
  const serializationType = this.determineSerializationType(this.buffer);
358
356
  this.offset += 5;
359
- if (serializationType === undefined ||
360
- serializationType === 'R_MAGIC_CORRUPT' ||
361
- serializationType === 'R_MAGIC_EMPTY' ||
362
- serializationType === 'R_MAGIC_MAYBE_TOONEW') {
357
+ if (serializationType === SerializationTypeTag.MagicCorrupt ||
358
+ serializationType === SerializationTypeTag.MagicEmpty ||
359
+ serializationType === SerializationTypeTag.MagicMaybeTooNew) {
363
360
  throw new Error('Could not determine serialization type');
364
361
  }
365
- if (serializationType === 'R_MAGIC_ASCII_V2' ||
366
- serializationType === 'R_MAGIC_ASCII_V3' ||
367
- serializationType === 'R_MAGIC_XDR_V2' ||
368
- serializationType === 'R_MAGIC_XDR_V3' ||
369
- serializationType === 'R_MAGIC_BINARY_V2' ||
370
- serializationType === 'R_MAGIC_BINARY_V3') {
371
- const result = this.deserialize();
372
- this.currentDepth--;
373
- return result;
362
+ if (SupportedSerializationTypes.has(serializationType)) {
363
+ return this.deserialize();
374
364
  }
375
- if (serializationType === 'R_MAGIC_ASCII_V1' ||
376
- serializationType === 'R_MAGIC_XDR_V1' ||
377
- serializationType === 'R_MAGIC_BINARY_V1') {
378
- // https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/saveload.c#L2157-L2196
365
+ else if (VersionOneSerializationTypes.has(serializationType)) {
379
366
  console.warn('Version one rda files are not supported yet');
380
367
  }
381
368
  return RValues.NilValue;
@@ -397,10 +384,12 @@ class RDAParser {
397
384
  this.format = SerializationFormat.Xdr;
398
385
  break;
399
386
  case '\n':
400
- if (String.fromCodePoint(this.buffer[this.offset + 1]) === 'A') {
401
- this.format = SerializationFormat.Ascii;
402
- this.offset += 1;
387
+ /* an ASCII stream may leave a trailing newline behind, so the format follows in the next two bytes */
388
+ if (String.fromCodePoint(this.buffer[this.offset + 1]) !== 'A') {
389
+ throw new Error('unknown input format');
403
390
  }
391
+ this.format = SerializationFormat.Ascii;
392
+ this.offset += 2;
404
393
  break;
405
394
  default:
406
395
  throw new Error('unknown input format');
@@ -478,9 +467,6 @@ class RDAParser {
478
467
  else if (this.format === SerializationFormat.Binary || this.format === SerializationFormat.Xdr) {
479
468
  this.offset += 4;
480
469
  }
481
- else {
482
- return;
483
- }
484
470
  }
485
471
  /**
486
472
  * Ensures that the given value is not {@link RValues.NaInteger}.
@@ -528,7 +514,7 @@ class RDAParser {
528
514
  c = this.inChar();
529
515
  }
530
516
  if (i >= size) {
531
- throw new Error(`$\{i} >= ${size} when reading word.`);
517
+ throw new Error(`${i} >= ${size} when reading word.`);
532
518
  }
533
519
  return word.join('');
534
520
  }
@@ -540,21 +526,7 @@ class RDAParser {
540
526
  * @throws Error if EOF is reached or the word exceeds {@link RDAParser.WORD_SIZE}.
541
527
  */
542
528
  skipWord() {
543
- let c;
544
- let i = 0;
545
- do {
546
- c = this.inChar();
547
- if (c === -1) {
548
- throw new Error('Read character is -1.');
549
- }
550
- } while (this.isSpace(c));
551
- while (!this.isSpace(c) && i < RDAParser.WORD_SIZE) {
552
- i++;
553
- c = this.inChar();
554
- }
555
- if (i >= RDAParser.WORD_SIZE) {
556
- throw new Error(`$\{i} >= ${RDAParser.WORD_SIZE} when reading word.`);
557
- }
529
+ this.inWord(RDAParser.WORD_SIZE);
558
530
  return '';
559
531
  }
560
532
  /**
@@ -677,39 +649,8 @@ class RDAParser {
677
649
  */
678
650
  skipString(len) {
679
651
  if (this.format === SerializationFormat.Ascii) {
680
- if (len > 0) {
681
- while (this.offset < this.buffer.length) {
682
- const c = this.buffer[this.offset++];
683
- if (!this.isSpace(c)) {
684
- break;
685
- }
686
- }
687
- this.offset--;
688
- for (let i = 0; i < len; i++) {
689
- let c = String.fromCodePoint(this.buffer[this.offset++]);
690
- if (c === '\\') {
691
- c = String.fromCodePoint(this.buffer[this.offset++]);
692
- switch (c) {
693
- case '0':
694
- case '1':
695
- case '2':
696
- case '3':
697
- case '4':
698
- case '5':
699
- case '6':
700
- case '7': {
701
- let j = 0;
702
- while ('0' <= c && c < '8' && j < 3) {
703
- c = String.fromCodePoint(this.buffer[this.offset++]);
704
- j++;
705
- }
706
- this.offset--;
707
- break;
708
- }
709
- }
710
- }
711
- }
712
- }
652
+ // the escape handling makes the consumed length depend on the content, so we have to decode it
653
+ this.inString(len);
713
654
  }
714
655
  else {
715
656
  this.offset += len;
@@ -722,9 +663,9 @@ class RDAParser {
722
663
  * @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L2230-L2235 | R source: decodeVersion}
723
664
  */
724
665
  decodeVersion(writerVersion) {
725
- const v = writerVersion / RDAParser.MAX_VECTOR_LENGTH;
666
+ const v = Math.trunc(writerVersion / RDAParser.MAX_VECTOR_LENGTH);
726
667
  writerVersion = writerVersion % RDAParser.MAX_VECTOR_LENGTH;
727
- const p = writerVersion / 2 ** 8;
668
+ const p = Math.trunc(writerVersion / 2 ** 8);
728
669
  writerVersion = writerVersion % 2 ** 8;
729
670
  const s = writerVersion;
730
671
  return [v, p, s];
@@ -920,14 +861,11 @@ class RDAParser {
920
861
  throw new Error('invalid length');
921
862
  }
922
863
  const name = this.inString(len);
923
- const index = r_fun_tab_1.RFunTabOffsets[name];
924
- if (name in r_fun_tab_1.RFunTabOffsets) {
925
- s = this.mkPrimSxp(index, type === SexpType.BuiltInSxp ? 1 : 0);
926
- }
927
- else {
928
- s.value = RValues.NilValue;
864
+ if (!(name in r_fun_tab_1.RFunTabOffsets)) {
929
865
  throw new Error(`unrecognized internal function name "${name}"`);
930
866
  }
867
+ const index = r_fun_tab_1.RFunTabOffsets[name];
868
+ s = this.mkPrimSxp(index, type === SexpType.BuiltInSxp ? 1 : 0);
931
869
  }
932
870
  break;
933
871
  case SexpType.CharSxp: {
@@ -938,9 +876,6 @@ class RDAParser {
938
876
  else if (len == -1) {
939
877
  s.name = RValues.NaString;
940
878
  }
941
- else if (len < 1000) {
942
- s.name = this.readChar(len, levels);
943
- }
944
879
  else {
945
880
  s.name = this.readChar(len, levels);
946
881
  }
@@ -1143,9 +1078,6 @@ class RDAParser {
1143
1078
  else if (len == -1) {
1144
1079
  s.name = RValues.NaString;
1145
1080
  }
1146
- else if (len < 1000) {
1147
- s.name = this.readChar(len, levels);
1148
- }
1149
1081
  else {
1150
1082
  s.name = this.readChar(len, levels);
1151
1083
  }
@@ -1235,13 +1167,8 @@ class RDAParser {
1235
1167
  }
1236
1168
  break;
1237
1169
  default: {
1238
- for (let done = 0; done < len;) {
1239
- const t = Math.min(RDAParser.CHUNK_SIZE, len - done);
1240
- for (let i = 0; i < t; i++) {
1241
- result[done + i] = this.buffer[this.offset];
1242
- this.offset += 1;
1243
- }
1244
- done += t;
1170
+ for (let i = 0; i < len; i++) {
1171
+ result[i] = this.buffer[this.offset++];
1245
1172
  }
1246
1173
  }
1247
1174
  }
@@ -1260,13 +1187,7 @@ class RDAParser {
1260
1187
  }
1261
1188
  }
1262
1189
  else {
1263
- for (let done = 0; done < len;) {
1264
- const t = Math.min(RDAParser.CHUNK_SIZE, len - done);
1265
- for (let i = 0; i < t; i++) {
1266
- this.offset += 1;
1267
- }
1268
- done += t;
1269
- }
1190
+ this.offset += len;
1270
1191
  }
1271
1192
  }
1272
1193
  /**
@@ -1430,7 +1351,6 @@ class RDAParser {
1430
1351
  s.tag = hasTag ? this.readItem() : RValues.NilValue;
1431
1352
  if (hasTag && this.currentDepth == RDAParser.INITIAL_DEPTH && typeof s.tag === 'object') {
1432
1353
  this.lastName = s.tag.name;
1433
- this.setLastName = true;
1434
1354
  }
1435
1355
  s.car = this.shortcut ? this.skipItem() : this.readItem();
1436
1356
  this.currentDepth--;
@@ -1535,34 +1455,18 @@ class RDAParser {
1535
1455
  * @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/dstruct.c#L37-L68 | R source: mkPRIMSXP}
1536
1456
  */
1537
1457
  mkPrimSxp(index, evaluation) {
1538
- const type = evaluation ? SexpType.BuiltInSxp : SexpType.SpecialSxp;
1539
- let primCache = RValues.NilValue;
1540
- let funTabSize = 0;
1541
- if (!primCache || primCache === RValues.NilValue) {
1542
- funTabSize = Object.keys(r_fun_tab_1.RFunTabOffsets).length;
1543
- primCache = {};
1544
- primCache.type = SexpType.VecSxp;
1545
- primCache.value = new Array(funTabSize);
1546
- }
1547
- if (index < 0 || index >= funTabSize) {
1458
+ if (index < 0 || index >= Object.keys(r_fun_tab_1.RFunTabOffsets).length) {
1548
1459
  throw new Error('offset is out of R_FunTab range');
1549
1460
  }
1550
- let result = this.VECTOR_ELT(primCache, index);
1551
- if (!result || result === RValues.NilValue) {
1552
- result = {};
1553
- result.type = type;
1554
- result.offset = index;
1555
- // SET_VECTOR_ELT(primCache, index, result);
1556
- }
1557
- else if (result.type !== type) {
1558
- throw new Error('requested primitive type is not consistent with cached value');
1559
- }
1560
- return result;
1461
+ return {
1462
+ type: evaluation ? SexpType.BuiltInSxp : SexpType.SpecialSxp,
1463
+ offset: index
1464
+ };
1561
1465
  }
1562
1466
  /**
1563
1467
  * Reads `len` bytes as a character string and applies encoding from the GP bits.
1564
1468
  *
1565
- * Encoding flags: bit 3 = UTF-8, bit 2 = Latin-1, bit 6 = bytes (returned as-is).
1469
+ * Encoding flags: bit 3 = UTF-8, bit 2 = Latin-1, bit 1 = raw bytes, bit 6 = ASCII (native-safe).
1566
1470
  * @param len - Number of bytes to read.
1567
1471
  * @param levels - GP levels bits from the `CharSxp` flags word.
1568
1472
  * @returns The decoded string, or `''` when the encoding is not yet handled.
@@ -1577,7 +1481,7 @@ class RDAParser {
1577
1481
  if (levels & (1 << 2)) {
1578
1482
  return new TextDecoder('iso-8859-1').decode(bytes);
1579
1483
  }
1580
- if (levels & (1 << 6)) {
1484
+ if (levels & (1 << 1) || levels & (1 << 6)) {
1581
1485
  return bytes.toString('latin1');
1582
1486
  }
1583
1487
  console.warn('Native encoding detected! Native encoding not supported yet! Value will be empty');
@@ -1597,12 +1501,12 @@ class RDAParser {
1597
1501
  if (len == -1) {
1598
1502
  const len1 = this.assertInteger(this.inInteger());
1599
1503
  const len2 = this.assertInteger(this.inInteger());
1600
- const xLen = len1;
1601
1504
  /* sanity check for now */
1602
1505
  if (len1 > RDAParser.MAX_VECTOR_LENGTH) {
1603
1506
  throw new Error('invalid upper part of serialized vector length');
1604
1507
  }
1605
- return (xLen << 32) + len2;
1508
+ /* both halves are written as unsigned; a shift would wrap at 32 bit, so the high half is scaled instead */
1509
+ return len1 * 2 ** 32 + (len2 >>> 0);
1606
1510
  }
1607
1511
  else {
1608
1512
  return len;
@@ -1620,16 +1524,12 @@ class RDAParser {
1620
1524
  case SerializationFormat.Xdr:
1621
1525
  {
1622
1526
  const result = [];
1623
- for (let done = 0; done < len;) {
1624
- const t = Math.min(RDAParser.CHUNK_SIZE, len - done);
1625
- for (let cnt = 0; cnt < t; cnt++) {
1626
- if (this.offset + 4 > this.buffer.length) {
1627
- throw new Error('XDR read failed');
1628
- }
1629
- result[done + cnt] = this.buffer.readInt32BE(this.offset);
1630
- this.offset += 4;
1527
+ for (let cnt = 0; cnt < len; cnt++) {
1528
+ if (this.offset + 4 > this.buffer.length) {
1529
+ throw new Error('XDR read failed');
1631
1530
  }
1632
- done += t;
1531
+ result[cnt] = this.buffer.readInt32BE(this.offset);
1532
+ this.offset += 4;
1633
1533
  }
1634
1534
  return result;
1635
1535
  }
@@ -1658,16 +1558,10 @@ class RDAParser {
1658
1558
  switch (this.format) {
1659
1559
  case SerializationFormat.Xdr:
1660
1560
  {
1661
- for (let done = 0; done < len;) {
1662
- const t = Math.min(RDAParser.CHUNK_SIZE, len - done);
1663
- for (let cnt = 0; cnt < t; cnt++) {
1664
- if (this.offset + 4 > this.buffer.length) {
1665
- throw new Error('XDR read failed');
1666
- }
1667
- this.offset += 4;
1668
- }
1669
- done += t;
1561
+ if (this.offset + 4 * len > this.buffer.length) {
1562
+ throw new Error('XDR read failed');
1670
1563
  }
1564
+ this.offset += 4 * len;
1671
1565
  break;
1672
1566
  }
1673
1567
  case SerializationFormat.Binary:
@@ -1693,16 +1587,9 @@ class RDAParser {
1693
1587
  switch (this.format) {
1694
1588
  case SerializationFormat.Xdr: {
1695
1589
  const result = [];
1696
- for (let done = 0; done < len;) {
1697
- const t = Math.min(RDAParser.CHUNK_SIZE, len - done);
1698
- const chunkBytes = t * RDAParser.SIZE_OF_DOUBLE;
1699
- const chunk = this.buffer.subarray(this.offset, this.offset + chunkBytes);
1700
- this.offset += chunkBytes;
1701
- for (let i = 0; i < t; i++) {
1702
- const value = chunk.readDoubleBE(i * RDAParser.SIZE_OF_DOUBLE);
1703
- result.push(value);
1704
- }
1705
- done += t;
1590
+ for (let i = 0; i < len; i++) {
1591
+ result.push(this.buffer.readDoubleBE(this.offset));
1592
+ this.offset += RDAParser.SIZE_OF_DOUBLE;
1706
1593
  }
1707
1594
  return result;
1708
1595
  }
@@ -1730,12 +1617,7 @@ class RDAParser {
1730
1617
  skipRealVec(len) {
1731
1618
  switch (this.format) {
1732
1619
  case SerializationFormat.Xdr: {
1733
- for (let done = 0; done < len;) {
1734
- const t = Math.min(RDAParser.CHUNK_SIZE, len - done);
1735
- const chunkBytes = t * RDAParser.SIZE_OF_DOUBLE;
1736
- this.offset += chunkBytes;
1737
- done += t;
1738
- }
1620
+ this.offset += len * RDAParser.SIZE_OF_DOUBLE;
1739
1621
  break;
1740
1622
  }
1741
1623
  case SerializationFormat.Binary:
@@ -1802,11 +1684,9 @@ class RDAParser {
1802
1684
  skipReal() {
1803
1685
  if (this.format === SerializationFormat.Ascii) {
1804
1686
  this.skipWord();
1805
- return;
1806
1687
  }
1807
1688
  else if (this.format === SerializationFormat.Binary || this.format === SerializationFormat.Xdr) {
1808
1689
  this.offset += 8;
1809
- return;
1810
1690
  }
1811
1691
  }
1812
1692
  /**
@@ -1819,29 +1699,14 @@ class RDAParser {
1819
1699
  * @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/serialize.c#L1579-L1616 | R source: InComplexVec}
1820
1700
  */
1821
1701
  inComplexVec(len) {
1822
- switch (this.format) {
1823
- case SerializationFormat.Xdr: {
1824
- const result = [];
1825
- for (let done = 0; done < len;) {
1826
- const t = Math.min(RDAParser.CHUNK_SIZE, len - done);
1827
- for (let cnt = 0; cnt < t; cnt++) {
1828
- result[done] = this.inComplex();
1829
- }
1830
- done += t;
1831
- }
1832
- return result;
1833
- }
1834
- case SerializationFormat.Binary: {
1835
- throw new Error('No binary support yet.');
1836
- }
1837
- default: {
1838
- const result = [];
1839
- for (let cnt = 0; cnt < len; cnt++) {
1840
- result[cnt] = this.inComplex();
1841
- }
1842
- return result;
1843
- }
1702
+ if (this.format === SerializationFormat.Binary) {
1703
+ throw new Error('No binary support yet.');
1704
+ }
1705
+ const result = [];
1706
+ for (let cnt = 0; cnt < len; cnt++) {
1707
+ result[cnt] = this.inComplex();
1844
1708
  }
1709
+ return result;
1845
1710
  }
1846
1711
  /**
1847
1712
  * Advances the buffer past `len` serialized complex numbers.
@@ -1851,25 +1716,11 @@ class RDAParser {
1851
1716
  * @throws Error for BINARY format.
1852
1717
  */
1853
1718
  skipComplexVec(len) {
1854
- switch (this.format) {
1855
- case SerializationFormat.Xdr: {
1856
- for (let done = 0; done < len;) {
1857
- const t = Math.min(RDAParser.CHUNK_SIZE, len - done);
1858
- for (let cnt = 0; cnt < t; cnt++) {
1859
- this.skipComplex();
1860
- }
1861
- done += t;
1862
- }
1863
- break;
1864
- }
1865
- case SerializationFormat.Binary: {
1866
- throw new Error('No binary support yet.');
1867
- }
1868
- default: {
1869
- for (let cnt = 0; cnt < len; cnt++) {
1870
- this.skipComplex();
1871
- }
1872
- }
1719
+ if (this.format === SerializationFormat.Binary) {
1720
+ throw new Error('No binary support yet.');
1721
+ }
1722
+ for (let cnt = 0; cnt < len; cnt++) {
1723
+ this.skipComplex();
1873
1724
  }
1874
1725
  }
1875
1726
  /**
@@ -1897,21 +1748,15 @@ class RDAParser {
1897
1748
  * @throws Error if `x` is not a {@link SexpType.StrSxp} or `i` is out of bounds.
1898
1749
  * @see {@link https://github.com/wch/r-source/blob/2196e6982a8f49082ee5c3d3521f6dd6596ea72c/src/main/memory.c#L4283-L4301 | R source: SET_STRING_ELT}
1899
1750
  */
1900
- SET_STRING_ELT(x, i, _v) {
1751
+ SET_STRING_ELT(x, i, v) {
1901
1752
  if (x.type !== SexpType.StrSxp) {
1902
1753
  throw new Error(`SET_STRING_ELT() can only be applied to a 'character vector', not a '${x.type}'`);
1903
1754
  }
1904
- // if(v.type !== SexpType.CharSxp) {
1905
- // throw new Error(`Value of SET_STRING_ELT() must be a 'CHARSXP' not a '${v.type}'`);
1906
- // }
1907
1755
  const arr = x.value;
1908
1756
  if (i < 0 || i >= arr.length) {
1909
1757
  throw new Error(`attempt to set index ${i}/${arr.length} in SET_STRING_ELT`);
1910
1758
  }
1911
- // if(x.altRep){
1912
- // this.ALTSTRING_SET_ELT(x, i, v);
1913
- // }
1914
- // arr[i] = v.name;
1759
+ arr[i] = v.name ?? RValues.NaString;
1915
1760
  }
1916
1761
  /**
1917
1762
  * Sets the `i`-th element of a generic list or vector.