@eagleoutice/flowr 2.14.4 → 2.15.1

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 (384) hide show
  1. package/README.md +77 -64
  2. package/abstract-interpretation/absint-inference.d.ts +347 -0
  3. package/abstract-interpretation/{absint-visitor.js → absint-inference.js} +327 -97
  4. package/abstract-interpretation/abstract-semantics.d.ts +246 -0
  5. package/abstract-interpretation/abstract-semantics.js +3 -0
  6. package/abstract-interpretation/data-frame/{mappers/arguments.d.ts → arguments.d.ts} +18 -16
  7. package/abstract-interpretation/data-frame/{mappers/arguments.js → arguments.js} +20 -21
  8. package/abstract-interpretation/data-frame/dataframe-semantics.d.ts +52 -0
  9. package/abstract-interpretation/data-frame/dataframe-semantics.js +1665 -0
  10. package/abstract-interpretation/data-frame/resolve-args.js +4 -4
  11. package/abstract-interpretation/data-frame/semantics.d.ts +15 -21
  12. package/abstract-interpretation/data-frame/semantics.js +27 -29
  13. package/abstract-interpretation/data-frame/shape-inference.d.ts +28 -24
  14. package/abstract-interpretation/data-frame/shape-inference.js +14 -79
  15. package/abstract-interpretation/domains/interval-domain.d.ts +5 -1
  16. package/abstract-interpretation/domains/interval-domain.js +25 -33
  17. package/abstract-interpretation/domains/multi-value-state-domain.d.ts +6 -3
  18. package/abstract-interpretation/domains/multi-value-state-domain.js +24 -4
  19. package/abstract-interpretation/domains/partial-product-domain.d.ts +12 -6
  20. package/abstract-interpretation/domains/partial-product-domain.js +26 -43
  21. package/abstract-interpretation/domains/positive-interval-domain.d.ts +1 -6
  22. package/abstract-interpretation/domains/positive-interval-domain.js +3 -29
  23. package/abstract-interpretation/domains/product-domain.d.ts +1 -1
  24. package/abstract-interpretation/domains/set-range-domain.d.ts +6 -0
  25. package/abstract-interpretation/domains/set-range-domain.js +29 -62
  26. package/abstract-interpretation/domains/state-abstract-domain.d.ts +9 -2
  27. package/abstract-interpretation/domains/state-abstract-domain.js +26 -37
  28. package/abstract-interpretation/domains/{state-domain-like.d.ts → state-domain.d.ts} +10 -6
  29. package/abstract-interpretation/domains/{state-domain-like.js → state-domain.js} +1 -1
  30. package/abstract-interpretation/value-semantics.d.ts +113 -0
  31. package/abstract-interpretation/value-semantics.js +115 -0
  32. package/benchmark/slicer.js +12 -6
  33. package/benchmark/stats/feature-counts.d.ts +2 -1
  34. package/benchmark/stats/feature-counts.js +25 -1
  35. package/benchmark/stats/stats.d.ts +4 -0
  36. package/benchmark/summarizer/second-phase/graph.js +7 -0
  37. package/cli/repl/commands/repl-parse.js +11 -22
  38. package/cli/repl/parser/slice-query-parser.d.ts +2 -0
  39. package/cli/repl/parser/slice-query-parser.js +1 -0
  40. package/config.d.ts +30 -205
  41. package/config.js +37 -3
  42. package/control-flow/cfg-properties.d.ts +5 -0
  43. package/control-flow/cfg-properties.js +25 -7
  44. package/control-flow/control-flow-graph.d.ts +11 -37
  45. package/control-flow/control-flow-graph.js +33 -77
  46. package/control-flow/semantic-cfg-guided-visitor.d.ts +63 -320
  47. package/control-flow/semantic-cfg-guided-visitor.js +65 -320
  48. package/dataflow/environments/built-in-config.d.ts +2 -0
  49. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  50. package/dataflow/environments/built-in-proc-name.js +4 -0
  51. package/dataflow/environments/built-in-props.d.ts +192 -82
  52. package/dataflow/environments/built-in-props.js +336 -106
  53. package/dataflow/environments/built-in.d.ts +21 -9
  54. package/dataflow/environments/built-in.js +43 -12
  55. package/dataflow/environments/default-builtin-config.d.ts +3219 -313
  56. package/dataflow/environments/default-builtin-config.js +803 -1012
  57. package/dataflow/environments/environment.d.ts +26 -49
  58. package/dataflow/environments/environment.js +34 -47
  59. package/dataflow/environments/group-generics.d.ts +11 -2
  60. package/dataflow/environments/group-generics.js +22 -3
  61. package/dataflow/environments/identifier.d.ts +106 -6
  62. package/dataflow/environments/identifier.js +19 -1
  63. package/dataflow/environments/query-fn-props.d.ts +16 -8
  64. package/dataflow/environments/query-fn-props.js +45 -21
  65. package/dataflow/environments/resolve-by-name.js +9 -2
  66. package/dataflow/environments/scoping.d.ts +5 -0
  67. package/dataflow/environments/scoping.js +11 -0
  68. package/dataflow/eval/resolve/alias-tracking.d.ts +1 -1
  69. package/dataflow/eval/resolve/alias-tracking.js +24 -6
  70. package/dataflow/eval/resolve/resolve-numbers.d.ts +182 -7
  71. package/dataflow/eval/resolve/resolve-numbers.js +44 -9
  72. package/dataflow/eval/resolve/resolve-strings.d.ts +79 -2
  73. package/dataflow/eval/resolve/resolve-strings.js +16 -7
  74. package/dataflow/eval/resolve/resolve.d.ts +5 -22
  75. package/dataflow/eval/resolve/resolve.js +34 -34
  76. package/dataflow/eval/values/general.d.ts +9 -1
  77. package/dataflow/eval/values/general.js +22 -3
  78. package/dataflow/eval/values/sets/set-constants.d.ts +5 -0
  79. package/dataflow/eval/values/sets/set-constants.js +9 -1
  80. package/dataflow/eval/values/string/string-constants.d.ts +16 -15
  81. package/dataflow/eval/values/string/string-constants.js +59 -27
  82. package/dataflow/extractor.d.ts +2 -1
  83. package/dataflow/extractor.js +16 -4
  84. package/dataflow/fn/argument-roles.d.ts +35 -0
  85. package/dataflow/fn/argument-roles.js +252 -0
  86. package/dataflow/fn/class-declaration.d.ts +148 -0
  87. package/dataflow/fn/class-declaration.js +317 -0
  88. package/dataflow/fn/condition-handlers.d.ts +5 -0
  89. package/dataflow/fn/condition-handlers.js +13 -0
  90. package/dataflow/fn/exceptions-of-function.d.ts +21 -7
  91. package/dataflow/fn/exceptions-of-function.js +74 -43
  92. package/dataflow/fn/frame-reflection.d.ts +46 -0
  93. package/dataflow/fn/frame-reflection.js +169 -0
  94. package/dataflow/fn/function-props.d.ts +32 -0
  95. package/dataflow/fn/function-props.js +160 -0
  96. package/dataflow/fn/higher-order-function.d.ts +23 -5
  97. package/dataflow/fn/higher-order-function.js +64 -18
  98. package/dataflow/fn/strict-function.d.ts +24 -2
  99. package/dataflow/fn/strict-function.js +49 -19
  100. package/dataflow/graph/call-graph.js +10 -2
  101. package/dataflow/graph/df-helper.d.ts +1 -12
  102. package/dataflow/graph/df-helper.js +2 -19
  103. package/dataflow/graph/diff-dataflow-graph.d.ts +1 -1
  104. package/dataflow/graph/diff-dataflow-graph.js +2 -2
  105. package/dataflow/graph/graph.d.ts +39 -188
  106. package/dataflow/graph/graph.js +46 -163
  107. package/dataflow/graph/match-args.d.ts +34 -2
  108. package/dataflow/graph/match-args.js +45 -12
  109. package/dataflow/graph/vertex.d.ts +8 -0
  110. package/dataflow/info.d.ts +7 -5
  111. package/dataflow/info.js +1 -5
  112. package/dataflow/internal/control-flow.js +20 -17
  113. package/dataflow/internal/linker.d.ts +8 -37
  114. package/dataflow/internal/linker.js +22 -55
  115. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +1 -2
  116. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +7 -8
  117. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +3 -4
  118. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +8 -14
  119. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +43 -50
  120. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +4 -1
  121. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +5 -2
  122. package/dataflow/internal/process/functions/call/built-in/built-in-class-relation.d.ts +23 -0
  123. package/dataflow/internal/process/functions/call/built-in/built-in-class-relation.js +24 -0
  124. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +2 -2
  125. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +2 -1
  126. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +0 -4
  127. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +73 -27
  128. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +2 -11
  129. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +131 -92
  130. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +17 -12
  131. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +187 -99
  132. package/dataflow/internal/process/functions/call/built-in/built-in-load.d.ts +4 -0
  133. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +2 -0
  134. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +2 -3
  135. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +4 -3
  136. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -1
  137. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +1 -2
  138. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +0 -1
  139. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +2 -1
  140. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +31 -0
  141. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +101 -0
  142. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-dispatch.js +2 -1
  143. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +7 -0
  144. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +23 -21
  145. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.d.ts +1 -2
  146. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +2 -2
  147. package/dataflow/internal/process/functions/call/built-in/built-in-string-template.js +2 -1
  148. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +22 -1
  149. package/dataflow/internal/process/functions/call/common.d.ts +4 -6
  150. package/dataflow/internal/process/functions/call/common.js +2 -2
  151. package/dataflow/internal/process/functions/call/deferred.d.ts +1 -1
  152. package/dataflow/internal/process/functions/call/deferred.js +2 -2
  153. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +5 -3
  154. package/dataflow/internal/process/functions/call/known-call-handling.js +6 -4
  155. package/dataflow/internal/process/functions/call/named-call-handling.js +19 -13
  156. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -2
  157. package/dataflow/internal/process/functions/call/quoted.js +144 -28
  158. package/dataflow/origin/dfg-get-origin.js +23 -10
  159. package/dataflow/processor.d.ts +2 -1
  160. package/dataflow/processor.js +6 -0
  161. package/documentation/data/interface/doc-writing-code.js +2 -0
  162. package/documentation/doc-util/doc-search.js +1 -1
  163. package/documentation/wiki-absint.d.ts +11 -14
  164. package/documentation/wiki-absint.js +73 -59
  165. package/documentation/wiki-core.js +64 -24
  166. package/documentation/wiki-linter.js +1 -0
  167. package/documentation/wiki-query.js +82 -264
  168. package/documentation/wiki-signature-database.js +17 -5
  169. package/gas.d.ts +91 -47
  170. package/gas.js +97 -13
  171. package/index.d.ts +31 -0
  172. package/index.js +52 -0
  173. package/linter/linter-rules.d.ts +87 -23
  174. package/linter/linter-rules.js +3 -1
  175. package/linter/rules/absolute-path.d.ts +1 -1
  176. package/linter/rules/dataframe-access-validation.d.ts +1 -1
  177. package/linter/rules/dataframe-access-validation.js +10 -8
  178. package/linter/rules/dead-code.d.ts +1 -1
  179. package/linter/rules/deprecated-functions.js +14 -5
  180. package/linter/rules/file-path-validity.d.ts +1 -1
  181. package/linter/rules/naming-convention.d.ts +1 -1
  182. package/linter/rules/naming-convention.js +13 -2
  183. package/linter/rules/network-functions.d.ts +10 -5
  184. package/linter/rules/network-functions.js +48 -36
  185. package/linter/rules/no-leaked-credentials.d.ts +1 -1
  186. package/linter/rules/problematic-inputs.d.ts +1 -1
  187. package/linter/rules/problematic-inputs.js +1 -1
  188. package/linter/rules/seeded-randomness.d.ts +3 -2
  189. package/linter/rules/seeded-randomness.js +7 -3
  190. package/linter/rules/software-has-license.d.ts +1 -1
  191. package/linter/rules/software-has-tests.d.ts +1 -1
  192. package/linter/rules/stop-with-call-arg.d.ts +1 -1
  193. package/linter/rules/syntactically-valid.d.ts +1 -1
  194. package/linter/rules/unclosed-connection.d.ts +3 -3
  195. package/linter/rules/unclosed-connection.js +3 -4
  196. package/linter/rules/undefined-symbol.d.ts +1 -1
  197. package/linter/rules/unescaped-arguments.d.ts +161 -0
  198. package/linter/rules/unescaped-arguments.js +293 -0
  199. package/linter/rules/unused-definition.d.ts +1 -1
  200. package/linter/rules/unused-definition.js +49 -4
  201. package/linter/rules/unused-import.d.ts +1 -1
  202. package/linter/rules/useless-loop.d.ts +1 -1
  203. package/package.json +3 -198
  204. package/project/context/flowr-analyzer-environment-context.d.ts +12 -1
  205. package/project/context/flowr-analyzer-environment-context.js +33 -1
  206. package/project/context/flowr-analyzer-files-context.d.ts +24 -1
  207. package/project/context/flowr-analyzer-files-context.js +42 -21
  208. package/project/context/flowr-analyzer-functions-context.d.ts +8 -0
  209. package/project/context/flowr-analyzer-functions-context.js +2 -0
  210. package/project/context/flowr-analyzer-gas-context.d.ts +9 -1
  211. package/project/context/flowr-analyzer-gas-context.js +21 -0
  212. package/project/context/flowr-file.d.ts +16 -1
  213. package/project/context/flowr-file.js +26 -2
  214. package/project/plugins/file-plugins/files/flowr-description-file.d.ts +19 -20
  215. package/project/plugins/file-plugins/files/flowr-description-file.js +55 -41
  216. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +9 -4
  217. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +11 -3
  218. package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +6 -9
  219. package/project/plugins/file-plugins/files/flowr-manifest-files.js +5 -21
  220. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +11 -12
  221. package/project/plugins/file-plugins/files/flowr-namespace-file.js +48 -61
  222. package/project/plugins/file-plugins/files/flowr-news-file.d.ts +3 -12
  223. package/project/plugins/file-plugins/files/flowr-news-file.js +2 -19
  224. package/project/plugins/file-plugins/files/flowr-rd-file.d.ts +145 -0
  225. package/project/plugins/file-plugins/files/flowr-rd-file.js +676 -0
  226. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +122 -422
  227. package/project/plugins/file-plugins/files/flowr-rda-file.js +517 -1005
  228. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +8 -2
  229. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +10 -1
  230. package/project/plugins/file-plugins/files/flowr-sweave-file.d.ts +7 -2
  231. package/project/plugins/file-plugins/files/flowr-sweave-file.js +9 -1
  232. package/project/plugins/file-plugins/files/flowr-sysdata-file.d.ts +17 -0
  233. package/project/plugins/file-plugins/files/flowr-sysdata-file.js +40 -0
  234. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.d.ts +2 -0
  235. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +3 -1
  236. package/project/plugins/file-plugins/flowr-analyzer-rd-file-plugin.d.ts +58 -0
  237. package/project/plugins/file-plugins/flowr-analyzer-rd-file-plugin.js +95 -0
  238. package/project/plugins/file-plugins/flowr-analyzer-sysdata-file-plugin.d.ts +23 -0
  239. package/project/plugins/file-plugins/flowr-analyzer-sysdata-file-plugin.js +33 -0
  240. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +33 -72
  241. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.js +17 -15
  242. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +20 -37
  243. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +29 -53
  244. package/project/plugins/package-version-plugins/package.js +2 -1
  245. package/project/plugins/plugin-registry.d.ts +3 -1
  246. package/project/plugins/plugin-registry.js +11 -0
  247. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +20 -4
  248. package/project/sigdb/build.d.ts +9 -15
  249. package/project/sigdb/build.js +101 -42
  250. package/project/sigdb/decode.d.ts +10 -4
  251. package/project/sigdb/decode.js +60 -21
  252. package/project/sigdb/memory-source.d.ts +4 -0
  253. package/project/sigdb/memory-source.js +8 -0
  254. package/project/sigdb/reader.d.ts +57 -100
  255. package/project/sigdb/reader.js +157 -108
  256. package/project/sigdb/schema.d.ts +90 -26
  257. package/project/sigdb/schema.js +12 -6
  258. package/queries/base-query-format.d.ts +7 -0
  259. package/queries/base-query-format.js +29 -0
  260. package/queries/catalog/absint-query/absint-query-executor.js +8 -6
  261. package/queries/catalog/absint-query/absint-query-format.d.ts +20 -9
  262. package/queries/catalog/absint-query/absint-query-format.js +32 -19
  263. package/queries/catalog/call-context-query/call-context-query-executor.js +3 -3
  264. package/queries/catalog/call-graph-query/call-graph-query-format.d.ts +1 -1
  265. package/queries/catalog/cluster-query/cluster-query-format.d.ts +1 -1
  266. package/queries/catalog/control-flow-query/control-flow-query-format.d.ts +1 -1
  267. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.js +1 -1
  268. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.d.ts +1 -1
  269. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +1 -1
  270. package/queries/catalog/dependencies-query/dependencies-query-executor.js +33 -7
  271. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +1 -1
  272. package/queries/catalog/dependencies-query/function-info/derived-functions.d.ts +2 -2
  273. package/queries/catalog/dependencies-query/function-info/derived-functions.js +14 -4
  274. package/queries/catalog/dependencies-query/function-info/read-functions.js +7 -121
  275. package/queries/catalog/dependencies-query/function-info/statistics-functions.d.ts +1 -1
  276. package/queries/catalog/dependencies-query/function-info/statistics-functions.js +2 -2
  277. package/queries/catalog/dependencies-query/function-info/visualize-functions.js +4 -46
  278. package/queries/catalog/dependencies-query/function-info/write-functions.js +3 -76
  279. package/queries/catalog/dependencies-query/implicit-echo.js +2 -2
  280. package/queries/catalog/dependencies-query/link-devices.d.ts +2 -2
  281. package/queries/catalog/dependencies-query/link-devices.js +6 -7
  282. package/queries/catalog/dice-query/dice-query-executor.js +1 -1
  283. package/queries/catalog/dice-query/dice-query-format.d.ts +1 -1
  284. package/queries/catalog/does-call-query/does-call-query-executor.js +4 -0
  285. package/queries/catalog/does-call-query/does-call-query-format.d.ts +7 -1
  286. package/queries/catalog/files-query/files-query-format.d.ts +1 -1
  287. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +1 -1
  288. package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +1 -1
  289. package/queries/catalog/id-map-query/id-map-query-format.d.ts +1 -1
  290. package/queries/catalog/input-sources-query/input-source-functions.d.ts +1 -1
  291. package/queries/catalog/input-sources-query/input-source-functions.js +2 -2
  292. package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +7 -17
  293. package/queries/catalog/input-sources-query/input-sources-query-format.js +11 -27
  294. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +1 -1
  295. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.d.ts +3 -8
  296. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.js +2 -11
  297. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-executor.d.ts +4 -0
  298. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-executor.js +60 -0
  299. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.d.ts +35 -0
  300. package/queries/catalog/inspect-fn-props-query/inspect-fn-props-query-format.js +63 -0
  301. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +3 -6
  302. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.d.ts +3 -8
  303. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.js +2 -11
  304. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.d.ts +3 -8
  305. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.js +2 -12
  306. package/queries/catalog/linter-query/linter-query-format.d.ts +1 -1
  307. package/queries/catalog/normalized-ast-query/normalized-ast-query-format.d.ts +1 -1
  308. package/queries/catalog/origin-query/origin-query-format.d.ts +1 -1
  309. package/queries/catalog/project-query/project-query-format.d.ts +1 -1
  310. package/queries/catalog/provenance-query/provenance-query-format.d.ts +3 -8
  311. package/queries/catalog/provenance-query/provenance-query-format.js +2 -14
  312. package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +1 -1
  313. package/queries/catalog/search-query/search-query-format.d.ts +1 -1
  314. package/queries/catalog/signature-query/signature-query-executor.d.ts +5 -10
  315. package/queries/catalog/signature-query/signature-query-executor.js +87 -93
  316. package/queries/catalog/signature-query/signature-query-format.d.ts +20 -5
  317. package/queries/catalog/signature-query/signature-query-format.js +16 -4
  318. package/queries/catalog/signature-query/signature-query-render.js +18 -4
  319. package/queries/catalog/slice-query-options.d.ts +14 -0
  320. package/queries/catalog/slice-query-options.js +15 -0
  321. package/queries/catalog/static-slice-query/static-slice-query-executor.d.ts +2 -1
  322. package/queries/catalog/static-slice-query/static-slice-query-executor.js +3 -2
  323. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +4 -3
  324. package/queries/catalog/static-slice-query/static-slice-query-format.js +7 -5
  325. package/queries/query-function-filter.d.ts +8 -3
  326. package/queries/query-function-filter.js +16 -6
  327. package/queries/query.d.ts +38 -38
  328. package/queries/query.js +30 -4
  329. package/r-bridge/lang-4.x/ast/model/model.d.ts +5 -0
  330. package/r-bridge/lang-4.x/ast/model/model.js +14 -0
  331. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  332. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +1 -0
  333. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  334. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  335. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  336. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  337. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  338. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  339. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  340. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  341. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  342. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  343. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  344. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  345. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  346. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  347. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  348. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +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-unary-op.d.ts +1 -0
  351. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  352. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +17 -9
  353. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +35 -27
  354. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +33 -22
  355. package/reconstruct/reconstruct.d.ts +9 -20
  356. package/reconstruct/reconstruct.js +66 -28
  357. package/search/flowr-search-filters.d.ts +7 -6
  358. package/search/flowr-search-filters.js +6 -4
  359. package/search/search-executor/search-enrichers.d.ts +10 -10
  360. package/search/search-executor/search-enrichers.js +32 -3
  361. package/search/search-executor/search-transformer.js +15 -23
  362. package/slicing/criterion/parse.js +2 -12
  363. package/slicing/static/slice-call.js +1 -8
  364. package/slicing/static/static-slicer.js +1 -1
  365. package/util/collections/bimap.js +14 -6
  366. package/util/objects.js +16 -17
  367. package/util/r-value.d.ts +5 -4
  368. package/util/record.d.ts +38 -3
  369. package/util/record.js +48 -1
  370. package/util/simple-df/dfg-ascii.js +1 -1
  371. package/util/text/strings.d.ts +5 -0
  372. package/util/text/strings.js +10 -0
  373. package/util/version.js +2 -2
  374. package/abstract-interpretation/absint-visitor.d.ts +0 -223
  375. package/abstract-interpretation/data-frame/mappers/access-mapper.d.ts +0 -19
  376. package/abstract-interpretation/data-frame/mappers/access-mapper.js +0 -151
  377. package/abstract-interpretation/data-frame/mappers/function-mapper.d.ts +0 -287
  378. package/abstract-interpretation/data-frame/mappers/function-mapper.js +0 -1096
  379. package/abstract-interpretation/data-frame/mappers/replacement-mapper.d.ts +0 -15
  380. package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +0 -207
  381. package/queries/catalog/inspect-strictness-query/inspect-strictness-query-executor.d.ts +0 -6
  382. package/queries/catalog/inspect-strictness-query/inspect-strictness-query-executor.js +0 -25
  383. package/queries/catalog/inspect-strictness-query/inspect-strictness-query-format.d.ts +0 -31
  384. package/queries/catalog/inspect-strictness-query/inspect-strictness-query-format.js +0 -56
@@ -0,0 +1,1665 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataFrameShapeSemantics = void 0;
4
+ const config_1 = require("../../config");
5
+ const built_in_proc_name_1 = require("../../dataflow/environments/built-in-proc-name");
6
+ const identifier_1 = require("../../dataflow/environments/identifier");
7
+ const resolve_helper_1 = require("../../dataflow/environments/resolve-helper");
8
+ const vertex_1 = require("../../dataflow/graph/vertex");
9
+ const make_argument_1 = require("../../dataflow/internal/process/functions/call/argument/make-argument");
10
+ const built_in_source_1 = require("../../dataflow/internal/process/functions/call/built-in/built-in-source");
11
+ const r_access_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-access");
12
+ const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
13
+ const r_binary_op_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
14
+ const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
15
+ const r_number_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-number");
16
+ const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
17
+ const r_symbol_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
18
+ const r_unary_op_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-unary-op");
19
+ const retriever_1 = require("../../r-bridge/retriever");
20
+ const assert_1 = require("../../util/assert");
21
+ const record_1 = require("../../util/record");
22
+ const value_semantics_1 = require("../value-semantics");
23
+ const arguments_1 = require("./arguments");
24
+ const dataframe_domain_1 = require("./dataframe-domain");
25
+ const resolve_args_1 = require("./resolve-args");
26
+ const semantics_1 = require("./semantics");
27
+ /**
28
+ * Represents the different types of data frames in R
29
+ */
30
+ var DataFrameType;
31
+ (function (DataFrameType) {
32
+ DataFrameType["DataFrame"] = "data.frame";
33
+ DataFrameType["Tibble"] = "tibble";
34
+ DataFrameType["DataTable"] = "data.table";
35
+ })(DataFrameType || (DataFrameType = {}));
36
+ /** Shared parameters of the `read.csv`/`read.delim` wrappers around `read.table`, which only differ in their separator. */
37
+ const ReadTableVariantParams = {
38
+ fileName: { pos: 0, name: 'file' },
39
+ header: { pos: 1, name: 'header', default: true },
40
+ separator: { pos: 2, name: 'sep', default: ',' },
41
+ quote: { pos: 3, name: 'quote', default: '"' },
42
+ comment: { pos: 6, name: 'comment.char', default: '' },
43
+ skipLines: { pos: -1, name: 'skip', default: 0 },
44
+ checkNames: { pos: -1, name: 'check.names', default: true },
45
+ noDupNames: { pos: -1, name: 'check.names', default: true },
46
+ text: { pos: -1, name: 'text' },
47
+ critical: [
48
+ { pos: -1, name: 'row.names' },
49
+ { pos: -1, name: 'col.names' },
50
+ { pos: -1, name: 'nrows', default: -1 },
51
+ { pos: -1, name: 'strip.white', default: false },
52
+ { pos: -1, name: 'blank.lines.skip', default: true },
53
+ { pos: -1, name: 'allow.escapes', default: false },
54
+ ]
55
+ };
56
+ /** Shared parameters of the readr `read_csv`/`read_tsv` wrappers around `read_delim`, which only differ in their separator. */
57
+ const ReadrDelimitedParams = {
58
+ fileName: { pos: 0, name: 'file' },
59
+ header: { pos: 1, name: 'col_names', default: true },
60
+ separator: { pos: -1, default: ',' },
61
+ quote: { pos: 8, name: 'quote', default: '"' },
62
+ comment: { pos: 9, name: 'comment', default: '' },
63
+ skipLines: { pos: 11, name: 'skip', default: 0 },
64
+ checkNames: { pos: -1, default: false },
65
+ noDupNames: { pos: -1, default: true },
66
+ critical: [
67
+ { pos: 3, name: 'col_select' },
68
+ { pos: 4, name: 'id' },
69
+ { pos: 10, name: 'trim_ws', default: true },
70
+ { pos: 12, name: 'n_max', default: Infinity },
71
+ { pos: 14, name: 'name_repair', default: 'unique' },
72
+ { pos: 18, name: 'skip_empty_rows', default: true }
73
+ ],
74
+ noEmptyNames: true
75
+ };
76
+ /** Shared parameters of the dplyr `*_join` functions, which only differ in the sides they keep. */
77
+ const DplyrJoinParams = {
78
+ dataFrame: { pos: 0, name: 'x' },
79
+ otherDataFrame: { pos: 1, name: 'y' },
80
+ by: { pos: 2, name: 'by' },
81
+ joinAll: { pos: -1, default: false },
82
+ joinLeft: { pos: -1, default: false },
83
+ joinRight: { pos: -1, default: false },
84
+ critical: [{ pos: -1, name: 'keep' }]
85
+ };
86
+ /**
87
+ * The abstract semantics of the supported concrete data frame functions, access operations, and replacement functions,
88
+ * mapping each supported function to the abstract data frame operations the function is composed of,
89
+ * including information about the type of the returned data frame
90
+ * and the location of all relevant function parameters (see {@link FunctionParameterLocation}).
91
+ */
92
+ const DataFrameSemantics = {
93
+ functionCalls: {
94
+ 'base::data.frame': applyFunctionCall(mapDataFrameCreate, {
95
+ checkNames: { pos: -1, name: 'check.names', default: true },
96
+ noDupNames: { pos: -1, name: 'check.names', default: true },
97
+ special: ['row.names', 'check.rows', 'check.names', 'fix.empty.names', 'stringsAsFactors'],
98
+ critical: [{ pos: -1, name: 'row.names' }]
99
+ }, DataFrameType.DataFrame, true),
100
+ 'base::as.data.frame': applyFunctionCall(mapDataFrameConvert, {
101
+ dataFrame: { pos: 0, name: 'x' },
102
+ critical: []
103
+ }, DataFrameType.DataFrame, true),
104
+ 'utils::read.table': applyFunctionCall(mapDataFrameRead, {
105
+ fileName: { pos: 0, name: 'file' },
106
+ header: { pos: 1, name: 'header', default: false },
107
+ separator: { pos: 2, name: 'sep', default: '\\s' },
108
+ quote: { pos: 3, name: 'quote', default: '"\'' },
109
+ skipLines: { pos: 12, name: 'skip', default: 0 },
110
+ checkNames: { pos: 13, name: 'check.names', default: true },
111
+ noDupNames: { pos: 13, name: 'check.names', default: true },
112
+ comment: { pos: 17, name: 'comment.char', default: '#' },
113
+ text: { pos: 23, name: 'text' },
114
+ critical: [
115
+ { pos: 6, name: 'row.names' },
116
+ { pos: 7, name: 'col.names' },
117
+ { pos: 11, name: 'nrows', default: -1 },
118
+ { pos: 15, name: 'strip.white', default: false },
119
+ { pos: 16, name: 'blank.lines.skip', default: true },
120
+ { pos: 18, name: 'allow.escapes', default: false },
121
+ ]
122
+ }, DataFrameType.DataFrame, true),
123
+ 'utils::read.csv': applyFunctionCall(mapDataFrameRead, {
124
+ ...ReadTableVariantParams,
125
+ separator: { pos: 2, name: 'sep', default: ',' }
126
+ }, DataFrameType.DataFrame, true),
127
+ 'utils::read.csv2': applyFunctionCall(mapDataFrameRead, {
128
+ ...ReadTableVariantParams,
129
+ separator: { pos: 2, name: 'sep', default: ';' }
130
+ }, DataFrameType.DataFrame, true),
131
+ 'utils::read.delim': applyFunctionCall(mapDataFrameRead, {
132
+ ...ReadTableVariantParams,
133
+ separator: { pos: 2, name: 'sep', default: '\\t' }
134
+ }, DataFrameType.DataFrame, true),
135
+ 'utils::read.delim2': applyFunctionCall(mapDataFrameRead, {
136
+ ...ReadTableVariantParams,
137
+ separator: { pos: 2, name: 'sep', default: '\\t' }
138
+ }, DataFrameType.DataFrame, true),
139
+ 'readr::read_table': applyFunctionCall(mapDataFrameRead, {
140
+ fileName: { pos: 0, name: 'file' },
141
+ header: { pos: 1, name: 'col_names', default: true },
142
+ separator: { pos: -1, default: '\\s' },
143
+ quote: { pos: -1, default: '"' },
144
+ skipLines: { pos: 5, name: 'skip', default: 0 },
145
+ comment: { pos: 9, name: 'comment', default: '' },
146
+ checkNames: { pos: -1, default: false },
147
+ noDupNames: { pos: -1, default: true },
148
+ critical: [
149
+ { pos: 6, name: 'n_max', default: Infinity },
150
+ { pos: 11, name: 'skip_empty_rows', default: true }
151
+ ],
152
+ noEmptyNames: true
153
+ }, DataFrameType.Tibble, true),
154
+ 'readr::read_csv': applyFunctionCall(mapDataFrameRead, {
155
+ ...ReadrDelimitedParams,
156
+ separator: { pos: -1, default: ',' }
157
+ }, DataFrameType.Tibble, true),
158
+ 'readr::read_csv2': applyFunctionCall(mapDataFrameRead, {
159
+ ...ReadrDelimitedParams,
160
+ separator: { pos: -1, default: ';' }
161
+ }, DataFrameType.Tibble, true),
162
+ 'readr::read_tsv': applyFunctionCall(mapDataFrameRead, {
163
+ ...ReadrDelimitedParams,
164
+ separator: { pos: -1, default: '\\t' }
165
+ }, DataFrameType.Tibble, true),
166
+ 'readr::read_delim': applyFunctionCall(mapDataFrameRead, {
167
+ fileName: { pos: 0, name: 'file' },
168
+ separator: { pos: 1, name: 'delim', default: '\t' },
169
+ quote: { pos: 2, name: 'quote', default: '"' },
170
+ header: { pos: 5, name: 'col_names', default: true },
171
+ comment: { pos: 12, name: 'comment', default: '' },
172
+ skipLines: { pos: 14, name: 'skip', default: 0 },
173
+ checkNames: { pos: -1, default: false },
174
+ noDupNames: { pos: -1, default: true },
175
+ critical: [
176
+ { pos: 3, name: 'escape_backslash', default: false },
177
+ { pos: 4, name: 'escape_double', default: true },
178
+ { pos: 7, name: 'col_select' },
179
+ { pos: 8, name: 'id' },
180
+ { pos: 13, name: 'trim_ws', default: false },
181
+ { pos: 15, name: 'n_max', default: Infinity },
182
+ { pos: 17, name: 'name_repair', default: 'unique' },
183
+ { pos: 21, name: 'skip_empty_rows', default: true }
184
+ ],
185
+ noEmptyNames: true
186
+ }, DataFrameType.Tibble, true),
187
+ 'base::cbind': applyFunctionCall(mapDataFrameColBind, {
188
+ special: ['deparse.level', 'make.row.names', 'stringsAsFactors', 'factor.exclude']
189
+ }, DataFrameType.DataFrame),
190
+ 'base::rbind': applyFunctionCall(mapDataFrameRowBind, {
191
+ special: ['deparse.level', 'make.row.names', 'stringsAsFactors', 'factor.exclude']
192
+ }, DataFrameType.DataFrame),
193
+ 'utils::head': applyFunctionCall(mapDataFrameHeadTail, {
194
+ dataFrame: { pos: 0, name: 'x' },
195
+ amount: { pos: 1, name: 'n', default: 6 }
196
+ }, DataFrameType.DataFrame),
197
+ 'utils::tail': applyFunctionCall(mapDataFrameHeadTail, {
198
+ dataFrame: { pos: 0, name: 'x' },
199
+ amount: { pos: 1, name: 'n', default: 6 },
200
+ fromEnd: true
201
+ }, DataFrameType.DataFrame),
202
+ 'base::subset': applyFunctionCall(mapDataFrameSubset, {
203
+ dataFrame: { pos: 0, name: 'x' },
204
+ subset: { pos: 1, name: 'subset' },
205
+ select: { pos: 2, name: 'select' },
206
+ drop: { pos: 3, name: 'drop', default: false }
207
+ }, DataFrameType.DataFrame),
208
+ 'dplyr::filter': applyFunctionCall(mapDataFrameFilter, {
209
+ dataFrame: { pos: 0, name: '.data' },
210
+ special: ['.by', '.preserve']
211
+ }, DataFrameType.DataFrame, true),
212
+ 'dplyr::select': applyFunctionCall(mapDataFrameSelect, {
213
+ dataFrame: { pos: 0, name: '.data' },
214
+ special: []
215
+ }, DataFrameType.DataFrame, true),
216
+ 'dplyr::mutate': applyFunctionCall(mapDataFrameMutate, {
217
+ dataFrame: { pos: 0, name: '.data' },
218
+ special: ['.by', '.keep', '.before', '.after'],
219
+ critical: [{ pos: -1, name: '.keep' }],
220
+ checkNames: false,
221
+ noDupNames: false
222
+ }, DataFrameType.DataFrame, true),
223
+ 'base::transform': applyFunctionCall(mapDataFrameMutate, {
224
+ dataFrame: { pos: 0, name: '_data' },
225
+ special: [],
226
+ checkNames: true,
227
+ noDupNames: true
228
+ }, DataFrameType.DataFrame, true),
229
+ 'dplyr::group_by': applyFunctionCall(mapDataFrameGroupBy, {
230
+ dataFrame: { pos: 0, name: '.data' },
231
+ by: { pos: 1 },
232
+ special: ['.add', '.drop']
233
+ }, DataFrameType.Tibble, true),
234
+ 'dplyr::summarise': applyFunctionCall(mapDataFrameSummarize, {
235
+ dataFrame: { pos: 0, name: '.data' },
236
+ special: ['.by', '.groups']
237
+ }, DataFrameType.DataFrame, true),
238
+ 'dplyr::summarize': applyFunctionCall(mapDataFrameSummarize, {
239
+ dataFrame: { pos: 0, name: '.data' },
240
+ special: ['.by', '.groups']
241
+ }, DataFrameType.DataFrame, true),
242
+ 'dplyr::inner_join': applyFunctionCall(mapDataFrameJoin, {
243
+ ...DplyrJoinParams
244
+ }, DataFrameType.DataFrame, true),
245
+ 'dplyr::left_join': applyFunctionCall(mapDataFrameJoin, {
246
+ ...DplyrJoinParams,
247
+ joinLeft: { pos: -1, default: true }
248
+ }, DataFrameType.DataFrame, true),
249
+ 'dplyr::right_join': applyFunctionCall(mapDataFrameJoin, {
250
+ ...DplyrJoinParams,
251
+ joinRight: { pos: -1, default: true },
252
+ }, DataFrameType.DataFrame, true),
253
+ 'dplyr::full_join': applyFunctionCall(mapDataFrameJoin, {
254
+ ...DplyrJoinParams,
255
+ joinAll: { pos: -1, default: true }
256
+ }, DataFrameType.DataFrame, true),
257
+ 'base::merge': applyFunctionCall(mapDataFrameJoin, {
258
+ dataFrame: { pos: 0, name: 'x' },
259
+ otherDataFrame: { pos: 1, name: 'y' },
260
+ by: { pos: 2, name: 'by' },
261
+ joinAll: { pos: 5, name: 'all', default: false },
262
+ joinLeft: { pos: 6, name: 'all.x', default: false },
263
+ joinRight: { pos: 7, name: 'all.y', default: false },
264
+ critical: [
265
+ { pos: 3, name: 'by.x' },
266
+ { pos: 4, name: 'by.y' }
267
+ ]
268
+ }, DataFrameType.DataFrame, true),
269
+ 'dplyr::relocate': applyFunctionCall(mapDataFrameIdentity, {
270
+ dataFrame: { pos: 0, name: '.data' },
271
+ special: ['.before', '.after'],
272
+ disallowNamedArgs: true
273
+ }, DataFrameType.DataFrame, true),
274
+ 'dplyr::arrange': applyFunctionCall(mapDataFrameIdentity, {
275
+ dataFrame: { pos: 0, name: '.data' },
276
+ special: ['.by_group', '.locale']
277
+ }, DataFrameType.DataFrame, true),
278
+ /* Other functions that are not explicitly supported but always return data frames */
279
+ 'base::as.data.frame.matrix': applyEntryPoint(DataFrameType.DataFrame), // S3 dispatch of `as.data.frame`
280
+ 'stats::anova': applyEntryPoint(DataFrameType.DataFrame),
281
+ 'stats::AIC': applyEntryPoint(DataFrameType.DataFrame),
282
+ 'stats::BIC': applyEntryPoint(DataFrameType.DataFrame),
283
+ 'car::Anova': applyEntryPoint(DataFrameType.DataFrame),
284
+ 'car::Manova': applyEntryPoint(DataFrameType.DataFrame),
285
+ 'dplyr::data_frame': applyEntryPoint(DataFrameType.DataFrame),
286
+ 'dplyr::as_data_frame': applyEntryPoint(DataFrameType.DataFrame),
287
+ 'dplyr::tbl': applyEntryPoint(DataFrameType.Tibble),
288
+ 'dplyr::as.tbl': applyEntryPoint(DataFrameType.Tibble),
289
+ 'readr::read_fwf': applyEntryPoint(DataFrameType.Tibble),
290
+ 'readr::read_log': applyEntryPoint(DataFrameType.Tibble),
291
+ 'readxl::read_excel': applyEntryPoint(DataFrameType.Tibble),
292
+ 'readxl::read_xls': applyEntryPoint(DataFrameType.Tibble),
293
+ 'readxl::read_xlsx': applyEntryPoint(DataFrameType.Tibble),
294
+ 'tibble::tibble': applyEntryPoint(DataFrameType.Tibble),
295
+ 'tibble::tibble_row': applyEntryPoint(DataFrameType.Tibble),
296
+ 'tibble::as_tibble': applyEntryPoint(DataFrameType.Tibble),
297
+ 'tibble::tribble': applyEntryPoint(DataFrameType.Tibble),
298
+ 'dplyr::tibble': applyEntryPoint(DataFrameType.Tibble), // re-export of `tibble::tibble`
299
+ 'dplyr::as_tibble': applyEntryPoint(DataFrameType.Tibble), // re-export of `tibble::as_tibble`
300
+ 'dplyr::tribble': applyEntryPoint(DataFrameType.Tibble), // re-export of `tibble::tribble`
301
+ 'data.table::data.table': applyEntryPoint(DataFrameType.DataTable),
302
+ 'data.table::as.data.table': applyEntryPoint(DataFrameType.DataTable),
303
+ 'data.table::fread': applyEntryPoint(DataFrameType.DataTable),
304
+ /* Other transformations that are not explicitly supported but return data frames if an argument is a data frame */
305
+ 'stats::na.omit': applyUnknownCall({ pos: 0, name: 'object' }, DataFrameType.DataFrame),
306
+ 'base::unique': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame),
307
+ 'base::droplevels': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame),
308
+ 'stats::aggregate': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame),
309
+ 'base::with': applyUnknownCall({ pos: 0, name: 'data' }, DataFrameType.DataFrame),
310
+ 'base::within': applyUnknownCall({ pos: 0, name: 'data' }, DataFrameType.DataFrame),
311
+ 'stats::reshape': applyUnknownCall({ pos: 0, name: 'data' }, DataFrameType.DataFrame),
312
+ 'reshape2::melt': applyUnknownCall({ pos: 0, name: 'data' }, DataFrameType.DataFrame),
313
+ 'data.table::melt': applyUnknownCall({ pos: 0, name: 'data' }, DataFrameType.DataTable),
314
+ 'data.table::dcast': applyUnknownCall({ pos: 0, name: 'data' }, DataFrameType.DataTable),
315
+ 'tidyr::drop_na': applyUnknownCall({ pos: 0, name: 'data' }, DataFrameType.DataFrame),
316
+ 'tidyr::replace_na': applyUnknownCall({ pos: 0, name: 'data' }, DataFrameType.DataFrame),
317
+ 'tidyr::pivot_longer': applyUnknownCall({ pos: 0, name: 'data' }, DataFrameType.DataFrame),
318
+ 'tidyr::pivot_wider': applyUnknownCall({ pos: 0, name: 'data' }, DataFrameType.DataFrame),
319
+ 'tidyr::separate': applyUnknownCall({ pos: 0, name: 'data' }, DataFrameType.DataFrame),
320
+ 'tidyr::separate_wider_position': applyUnknownCall({ pos: 0, name: 'data' }, DataFrameType.DataFrame),
321
+ 'tidyr::separate_wider_delim': applyUnknownCall({ pos: 0, name: 'data' }, DataFrameType.DataFrame),
322
+ 'tidyr::unite': applyUnknownCall({ pos: 0, name: 'data' }, DataFrameType.DataFrame),
323
+ 'dplyr::transmute': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.DataFrame, true),
324
+ 'dplyr::distinct': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.DataFrame, true),
325
+ 'dplyr::distinct_prepare': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.DataFrame, true),
326
+ 'dplyr::group_by_prepare': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.DataFrame, true),
327
+ 'dplyr::rename': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.DataFrame, true),
328
+ 'dplyr::rename_with': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.DataFrame, true),
329
+ 'dplyr::reframe': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.DataFrame, true),
330
+ 'dplyr::slice': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.DataFrame, true),
331
+ 'dplyr::slice_head': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.DataFrame, true),
332
+ 'dplyr::slice_tail': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.DataFrame, true),
333
+ 'dplyr::slice_min': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.DataFrame, true),
334
+ 'dplyr::slice_max': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.DataFrame, true),
335
+ 'dplyr::slice_sample': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.DataFrame, true),
336
+ 'dplyr::filter_if': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
337
+ 'dplyr::filter_at': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
338
+ 'dplyr::filter_all': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
339
+ 'dplyr::select_if': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
340
+ 'dplyr::select_at': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
341
+ 'dplyr::select_all': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
342
+ 'dplyr::mutate_if': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
343
+ 'dplyr::mutate_at': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
344
+ 'dplyr::mutate_all': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
345
+ 'dplyr::transmute_if': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
346
+ 'dplyr::transmute_at': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
347
+ 'dplyr::transmute_all': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
348
+ 'dplyr::distinct_if': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
349
+ 'dplyr::distinct_at': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
350
+ 'dplyr::distinct_all': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
351
+ 'dplyr::group_by_if': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
352
+ 'dplyr::group_by_at': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
353
+ 'dplyr::group_by_all': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
354
+ 'dplyr::summarize_if': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
355
+ 'dplyr::summarise_if': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
356
+ 'dplyr::summarize_at': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
357
+ 'dplyr::summarise_at': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
358
+ 'dplyr::summarize_all': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
359
+ 'dplyr::summarise_all': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
360
+ 'dplyr::arrange_if': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
361
+ 'dplyr::arrange_at': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
362
+ 'dplyr::arrange_all': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
363
+ 'dplyr::rename_if': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
364
+ 'dplyr::rename_at': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
365
+ 'dplyr::rename_all': applyUnknownCall({ pos: 0, name: '.tbl' }, DataFrameType.Tibble, true),
366
+ 'dplyr::semi_join': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame, true),
367
+ 'dplyr::anti_join': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame, true),
368
+ 'dplyr::nest_join': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame, true),
369
+ 'dplyr::cross_join': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame, true),
370
+ 'dplyr::ungroup': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame, true),
371
+ 'dplyr::count': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame, true),
372
+ 'dplyr::tally': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame, true),
373
+ 'dplyr::add_count': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame, true),
374
+ 'dplyr::add_tally': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame, true),
375
+ 'dplyr::rows_insert': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame, true),
376
+ 'dplyr::rows_append': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame, true),
377
+ 'dplyr::rows_update': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame, true),
378
+ 'dplyr::rows_patch': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame, true),
379
+ 'dplyr::rows_upsert': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame, true),
380
+ 'dplyr::rows_delete': applyUnknownCall({ pos: 0, name: 'x' }, DataFrameType.DataFrame, true),
381
+ 'dplyr::bind_cols': applyUnknownCall(undefined, DataFrameType.DataFrame, true),
382
+ 'dplyr::bind_rows': applyUnknownCall(undefined, DataFrameType.DataFrame, true),
383
+ 'tibble::add_column': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.Tibble, true),
384
+ 'tibble::add_row': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.Tibble, true),
385
+ 'tibble::add_case': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.Tibble, true),
386
+ 'dplyr::add_row': applyUnknownCall({ pos: 0, name: '.data' }, DataFrameType.Tibble, true), // re-export of `tibble::add_row`
387
+ /* Other functions that are not explicitly supported but modify their data frame argument in place */
388
+ 'stats::setNames': applyUnknownCall({ pos: 0, name: 'object' }, DataFrameType.DataFrame, false, semantics_1.ConstraintType.OperandModification),
389
+ 'base::unname': applyUnknownCall({ pos: 0, name: 'obj' }, DataFrameType.DataFrame, false, semantics_1.ConstraintType.OperandModification)
390
+ },
391
+ accessCalls: {
392
+ 'base::$': applyAccessCall(mapDataFrameAccess),
393
+ 'base::[': applyAccessCall(mapDataFrameAccess),
394
+ 'base::[[': applyAccessCall(mapDataFrameAccess)
395
+ },
396
+ replacementCall: {
397
+ 'base::$<-': applyReplacementCall(mapDataFrameAccessAssignment),
398
+ 'base::[<-': applyReplacementCall(mapDataFrameAccessAssignment),
399
+ 'base::[[<-': applyReplacementCall(mapDataFrameAccessAssignment),
400
+ 'base::names<-': applyReplacementCall(mapDataFrameColNamesAssignment),
401
+ 'base::colnames<-': applyReplacementCall(mapDataFrameColNamesAssignment),
402
+ 'base::rownames<-': applyReplacementCall(mapDataFrameRowNamesAssignment),
403
+ 'base::dimnames<-': applyReplacementCall(mapDataFrameDimNamesAssignment)
404
+ },
405
+ conditionSemantics: {}
406
+ };
407
+ /**
408
+ * The abstract semantics of the data frame shape inference, applying the abstract semantics defined for the supported
409
+ * data frame functions, access operations, and replacement functions (see {@link DataFrameSemantics}).
410
+ *
411
+ * Besides the defined semantics, all other replacement functions applied to a data frame are over-approximated
412
+ * by mapping the modified data frame operand to the `unknown` abstract operation.
413
+ *
414
+ * The semantics store the abstract data frame operations the expressions of the analyzed program are mapped to,
415
+ * which can be retrieved with {@link getAbstractOperations} after the analysis was performed.
416
+ */
417
+ class DataFrameShapeSemantics extends value_semantics_1.ValueSemantics {
418
+ /** The map storing the abstract data frame operations the expressions of the analyzed program are mapped to */
419
+ operations;
420
+ /**
421
+ * Creates the abstract semantics of the data frame shape inference.
422
+ * @param options - The options of the semantics, i.e. whether the mapped abstract operations should be stored
423
+ */
424
+ constructor({ trackOperations = true } = {}) {
425
+ const operations = trackOperations ? new Map() : undefined;
426
+ super(createDataFrameSemantics(operations));
427
+ this.operations = operations;
428
+ }
429
+ /**
430
+ * Gets the mapped abstract data frame operations for an AST node (this only includes direct function calls, replacement calls, or access operations).
431
+ * This requires that the abstract interpretation visitor applying the semantics has been completed, or at least started.
432
+ * @param id - The ID of the node to get the mapped abstract operations for
433
+ * @returns The mapped abstract data frame operations for the node, or `undefined` if no abstract operation was mapped for the node or storing mapped abstract operations is disabled via the options.
434
+ */
435
+ getAbstractOperations(id) {
436
+ return id !== undefined ? this.operations?.get(id) : undefined;
437
+ }
438
+ /**
439
+ * Applies the abstract semantics defined for the called replacement function, or over-approximates
440
+ * the modified data frame operand of any other replacement function by the `unknown` abstract operation.
441
+ */
442
+ handleReplacementCall(state, vertex, ctx, target, source) {
443
+ if (this.getSemantics('replacementCall', vertex, ctx) !== undefined) {
444
+ super.handleReplacementCall(state, vertex, ctx, target, source);
445
+ }
446
+ else {
447
+ applyUnknownAssignment(state, vertex, ctx, this.operations);
448
+ }
449
+ }
450
+ }
451
+ exports.DataFrameShapeSemantics = DataFrameShapeSemantics;
452
+ /**
453
+ * Creates the declarative definition of the abstract semantics of the data frame domain (see {@link DataFrameSemantics}).
454
+ * @param operations - An optional map to store the abstract data frame operations the expressions are mapped to
455
+ * @returns The definition of the abstract semantics of the data frame domain
456
+ */
457
+ function createDataFrameSemantics(operations) {
458
+ return {
459
+ functionCalls: record_1.Record.mapProps(DataFrameSemantics.functionCalls, semantics => semantics(operations)),
460
+ accessCalls: record_1.Record.mapProps(DataFrameSemantics.accessCalls, semantics => semantics(operations)),
461
+ replacementCall: record_1.Record.mapProps(DataFrameSemantics.replacementCall, semantics => semantics(operations)),
462
+ conditionSemantics: record_1.Record.mapProps(DataFrameSemantics.conditionSemantics, (semantics) => semantics(operations))
463
+ };
464
+ }
465
+ /**
466
+ * Creates the abstract semantics of a data frame function, by mapping calls of the function to abstract data frame operations and applying their semantics.
467
+ * @param mapper - The mapper function mapping the arguments of the function call to abstract data frame operations
468
+ * @param params - The expected location of all relevant function parameters, including all `critical` parameters whose presence makes the call unsupported
469
+ * @param returnType - The type of the data frame returned by the function
470
+ * @param alwaysReturnsDataFrame - Whether the function always returns a data frame, so that unsuccessful mappings are over-approximated by the `unknown` operation
471
+ * @returns The function call semantics applying the abstract data frame operations of the function
472
+ */
473
+ function applyFunctionCall(mapper, params, returnType, alwaysReturnsDataFrame) {
474
+ return operations => (state, vertex, ctx) => {
475
+ const resolveInfo = getResolveInfo(ctx);
476
+ const node = ctx.getAstNode(vertex.id);
477
+ if (!r_function_call_1.RFunctionCall.isNamed(node)) {
478
+ return;
479
+ }
480
+ let result;
481
+ const args = (0, arguments_1.getFunctionArguments)(node, ctx.dfg);
482
+ if ((0, arguments_1.hasCriticalArgument)(args, params.critical, resolveInfo)) {
483
+ result = [{ operation: 'unknown', operand: undefined }];
484
+ }
485
+ else {
486
+ result = mapper(args, params, ctx, resolveInfo) ?? (alwaysReturnsDataFrame ? [{ operation: 'unknown', operand: undefined }] : undefined);
487
+ }
488
+ applyDataFrameExpression(state, node, result, ctx, operations);
489
+ };
490
+ }
491
+ /**
492
+ * Creates the abstract semantics of a data frame function that is not explicitly supported but always returns a data frame, such as `tibble(id = 1:5)`.
493
+ * @param returnType - The type of the data frame returned by the function
494
+ * @returns The function call semantics over-approximating the result of the function by the `unknown` operation
495
+ */
496
+ function applyEntryPoint(returnType) {
497
+ return applyFunctionCall(() => [{ operation: 'unknown', operand: undefined }], {}, returnType);
498
+ }
499
+ /**
500
+ * Creates the abstract semantics of a data frame function that is not explicitly supported but returns or modifies a data frame, such as `na.omit(df)`.
501
+ * @param dataFrame - The expected location of the data frame parameter (if `undefined`, the first argument that is a data frame is used)
502
+ * @param returnType - The type of the data frame returned by the function
503
+ * @param alwaysReturnsDataFrame - Whether the function always returns a data frame, so that unsuccessful mappings are over-approximated by the `unknown` operation
504
+ * @param constraintType - The optional constraint type to overwrite the default type of the `unknown` operation (e.g. for functions modifying their operand in place)
505
+ * @returns The function call semantics over-approximating the result of the function by the `unknown` operation
506
+ */
507
+ function applyUnknownCall(dataFrame, returnType, alwaysReturnsDataFrame, constraintType) {
508
+ return applyFunctionCall(mapDataFrameUnknown, { dataFrame, constraintType }, returnType, alwaysReturnsDataFrame);
509
+ }
510
+ /**
511
+ * Creates the abstract semantics of a data frame access operation, by mapping the access to abstract data frame operations and applying their semantics.
512
+ * @param mapper - The mapper function mapping the access operation to abstract data frame operations
513
+ * @returns The access call semantics applying the abstract data frame operations of the access operation
514
+ */
515
+ function applyAccessCall(mapper) {
516
+ return operations => (state, vertex, ctx) => {
517
+ const node = ctx.getAstNode(vertex.id);
518
+ if (!r_access_1.RAccess.is(node)) {
519
+ return;
520
+ }
521
+ applyDataFrameExpression(state, node, mapper(node, ctx, getResolveInfo(ctx)), ctx, operations);
522
+ };
523
+ }
524
+ /**
525
+ * Creates the abstract semantics of a data frame replacement function, by mapping the replacement call to abstract data frame operations and applying their semantics.
526
+ * @param mapper - The mapper function mapping the replacement call to abstract data frame operations
527
+ * @returns The replacement call semantics applying the abstract data frame operations of the replacement function
528
+ */
529
+ function applyReplacementCall(mapper) {
530
+ return operations => (state, vertex, ctx, target, source) => {
531
+ const node = ctx.getAstNode(vertex.id);
532
+ const expression = ctx.getAstNode(source);
533
+ if (node === undefined || ctx.getAstNode(target) === undefined || expression === undefined) {
534
+ return;
535
+ }
536
+ applyDataFrameExpression(state, node, mapper(node, expression, ctx, getResolveInfo(ctx)), ctx, operations);
537
+ };
538
+ }
539
+ /**
540
+ * Applies the abstract semantics of a replacement function that is not explicitly supported, such as `levels(df) <- c("A", "B")`,
541
+ * by over-approximating the modified data frame operand with the `unknown` abstract operation.
542
+ * @param state - The abstract state to apply the semantics to
543
+ * @param vertex - The dataflow graph vertex of the replacement call
544
+ * @param ctx - The context of the abstract interpretation analysis
545
+ * @param operations - An optional map to store the mapped abstract data frame operations in
546
+ */
547
+ function applyUnknownAssignment(state, vertex, ctx, operations) {
548
+ const node = ctx.getAstNode(vertex.id);
549
+ const operand = node !== undefined ? getReplacementOperand(node, ctx) : undefined;
550
+ if (node === undefined || operand === undefined) {
551
+ return;
552
+ }
553
+ applyDataFrameExpression(state, node, [{
554
+ operation: 'unknown',
555
+ operand: operand.value.info.id,
556
+ type: semantics_1.ConstraintType.OperandModification
557
+ }], ctx, operations);
558
+ }
559
+ /**
560
+ * Creates the resolve information for resolving the arguments of a data frame function call.
561
+ */
562
+ function getResolveInfo(ctx) {
563
+ return { graph: ctx.dfg, idMap: ctx.ast.idMap, full: true, resolve: config_1.VariableResolve.Alias, ctx: ctx.context };
564
+ }
565
+ /**
566
+ * Applies the semantics of abstract data frame operations to an abstract state,
567
+ * by storing the inferred abstract value either at the modified operand or at the result of the expression, depending on the {@link ConstraintType} of the operation.
568
+ * @param state - The abstract state to apply the semantics to
569
+ * @param node - The R node of the expression the abstract operations were mapped from
570
+ * @param operations - The abstract data frame operations to apply
571
+ * @param ctx - The context of the abstract interpretation analysis
572
+ * @param operationsMap - An optional map to store the mapped abstract data frame operations in
573
+ */
574
+ function applyDataFrameExpression(state, node, operations, ctx, operationsMap) {
575
+ if (operations === undefined) {
576
+ return;
577
+ }
578
+ operationsMap?.set(node.info.id, operations);
579
+ const maxColNames = ctx.context.config.abstractInterpretation.dataFrame.maxColNames;
580
+ let value = dataframe_domain_1.DataFrameDomain.top(maxColNames);
581
+ for (const { operation, operand, type, options, ...args } of operations) {
582
+ const operandValue = operand !== undefined ? ctx.getAbstractValue(operand, state) : value;
583
+ value = (0, semantics_1.applyDataFrameSemantics)(operation, operandValue ?? dataframe_domain_1.DataFrameDomain.top(maxColNames), args, options);
584
+ const constraintType = type ?? (0, semantics_1.getConstraintType)(operation);
585
+ if (operand !== undefined && constraintType === semantics_1.ConstraintType.OperandModification) {
586
+ state.set(operand, value);
587
+ for (const origin of ctx.getVariableOrigins(operand)) {
588
+ state.set(origin, value);
589
+ }
590
+ }
591
+ else if (constraintType === semantics_1.ConstraintType.ResultPostcondition) {
592
+ state.set(node.info.id, value);
593
+ }
594
+ }
595
+ }
596
+ /**
597
+ * Maps a data frame creation function, such as `data.frame(id = 1:5, name = c("A", "B"))`, to abstract data frame operations.
598
+ */
599
+ function mapDataFrameCreate(args, params, ctx, info) {
600
+ const checkNames = (0, arguments_1.getArgumentValue)(args, params.checkNames, info);
601
+ const noDupNames = (0, arguments_1.getArgumentValue)(args, params.noDupNames, info);
602
+ args = (0, arguments_1.getEffectiveArgs)(args, params.special);
603
+ const argNames = args.map(arg => resolve_helper_1.Resolve.argument.toName(arg, info));
604
+ const argLengths = args.map(arg => resolve_helper_1.Resolve.argument.vectorLength(arg, info));
605
+ const allVectors = argLengths.every(assert_1.isNotUndefined);
606
+ const rows = allVectors ? argLengths.reduce((max, length) => Math.max(max, length), 0) : undefined;
607
+ let colnames = argNames;
608
+ // over-approximate the column names if arguments are present but cannot be resolved to values
609
+ if (!allVectors || typeof checkNames !== 'boolean' || typeof noDupNames !== 'boolean') {
610
+ colnames = undefined;
611
+ }
612
+ else if (rows === 0) {
613
+ colnames = [];
614
+ }
615
+ else {
616
+ colnames = (0, arguments_1.filterValidNames)(colnames, checkNames, noDupNames);
617
+ }
618
+ return [{
619
+ operation: 'create',
620
+ operand: undefined,
621
+ colnames,
622
+ rows
623
+ }];
624
+ }
625
+ /**
626
+ * Maps a data frame conversion function, such as `as.data.frame(x)`, to abstract data frame operations.
627
+ */
628
+ function mapDataFrameConvert(args, params, ctx, info) {
629
+ const dataFrame = (0, arguments_1.getFunctionArgument)(args, params.dataFrame, info);
630
+ if (r_argument_1.RArgument.isEmpty(dataFrame) || !r_argument_1.RArgument.isWithValue(dataFrame)) {
631
+ return [{ operation: 'unknown', operand: undefined }];
632
+ }
633
+ return [{
634
+ operation: 'identity',
635
+ operand: dataFrame.value.info.id
636
+ }];
637
+ }
638
+ /**
639
+ * Maps a data frame read function, such as `read.csv("file.csv")`, to abstract data frame operations.
640
+ * If reading external files is enabled in the configuration, the content of the read file or text is parsed to infer the column names and the number of rows.
641
+ */
642
+ function mapDataFrameRead(args, params, ctx, info) {
643
+ const fileNameArg = (0, arguments_1.getFunctionArgument)(args, params.fileName, info);
644
+ const textArg = params.text ? (0, arguments_1.getFunctionArgument)(args, params.text, info) : undefined;
645
+ const { source, request } = getRequestFromRead(fileNameArg, textArg, params, info);
646
+ const header = (0, arguments_1.getArgumentValue)(args, params.header, info);
647
+ const separator = (0, arguments_1.getArgumentValue)(args, params.separator, info);
648
+ const quote = (0, arguments_1.getArgumentValue)(args, params.quote, info);
649
+ const comment = (0, arguments_1.getArgumentValue)(args, params.comment, info);
650
+ const skipLines = (0, arguments_1.getArgumentValue)(args, params.skipLines, info);
651
+ const checkNames = (0, arguments_1.getArgumentValue)(args, params.checkNames, info);
652
+ const noDupNames = (0, arguments_1.getArgumentValue)(args, params.noDupNames, info);
653
+ const validArguments = typeof header === 'boolean' && typeof separator === 'string' && typeof quote === 'string' && typeof comment === 'string' &&
654
+ typeof skipLines === 'number' && typeof checkNames === 'boolean' && typeof noDupNames === 'boolean';
655
+ if (request === undefined || !info.ctx.config.abstractInterpretation.dataFrame.readLoadedData.readExternalFiles || !validArguments) {
656
+ return [{
657
+ operation: 'read',
658
+ operand: undefined,
659
+ source,
660
+ colnames: undefined,
661
+ rows: undefined
662
+ }];
663
+ }
664
+ const LineCommentRegex = new RegExp(`\\s*[${(0, arguments_1.escapeRegExp)(comment, true)}].*`);
665
+ let firstLine = undefined;
666
+ let firstLineNumber = 0;
667
+ let rowCount = 0;
668
+ const parseLine = (line, lineNumber) => {
669
+ const text = comment ? line.toString().replace(LineCommentRegex, '') : line.toString();
670
+ if (text.length > 0 && lineNumber >= (skipLines ?? 0)) {
671
+ if (firstLine === undefined) {
672
+ firstLine = getEntriesFromCsvLine(text, separator, quote, comment);
673
+ firstLineNumber = lineNumber;
674
+ }
675
+ if (!header || lineNumber > firstLineNumber) {
676
+ rowCount++;
677
+ }
678
+ }
679
+ };
680
+ const allLines = (0, arguments_1.parseRequestContent)(request, parseLine, info.ctx.config.abstractInterpretation.dataFrame.readLoadedData.maxReadLines);
681
+ let colnames;
682
+ if (header) {
683
+ colnames = (0, arguments_1.filterValidNames)(firstLine, checkNames, noDupNames, params.noEmptyNames);
684
+ }
685
+ else if (firstLine !== undefined) {
686
+ colnames = Array(firstLine.length).fill(undefined);
687
+ }
688
+ return [{
689
+ operation: 'read',
690
+ operand: undefined,
691
+ source,
692
+ colnames,
693
+ rows: allLines ? rowCount : [rowCount, Infinity]
694
+ }];
695
+ }
696
+ /**
697
+ * Maps a function adding columns to a data frame, such as `cbind(df, id = 1:5)`, to abstract data frame operations.
698
+ */
699
+ function mapDataFrameColBind(args, params, ctx, info) {
700
+ args = (0, arguments_1.getEffectiveArgs)(args, params.special);
701
+ const dataFrame = args.find(arg => (0, arguments_1.isDataFrameArgument)(arg, ctx));
702
+ if (dataFrame === undefined) {
703
+ return;
704
+ }
705
+ else if (args.length === 1) {
706
+ return [{ operation: 'identity', operand: dataFrame.value.info.id }];
707
+ }
708
+ const result = [];
709
+ let operand = dataFrame.value;
710
+ let colnames = [];
711
+ for (const arg of args) {
712
+ if (arg !== dataFrame && r_argument_1.RArgument.isNotEmpty(arg)) {
713
+ const otherDataFrame = ctx.getAbstractValue(arg.value);
714
+ if (otherDataFrame !== undefined) {
715
+ result.push({
716
+ operation: 'concatCols',
717
+ operand: operand?.info.id,
718
+ other: otherDataFrame
719
+ });
720
+ operand = undefined;
721
+ // added columns are top if argument cannot be resolved to constant (vector-like) value
722
+ }
723
+ else if (resolve_helper_1.Resolve.argument.value(arg, info) !== undefined) {
724
+ const colname = resolve_helper_1.Resolve.argument.toName(arg, info);
725
+ colnames?.push(colname);
726
+ }
727
+ else {
728
+ colnames = undefined;
729
+ }
730
+ }
731
+ }
732
+ if (colnames === undefined || colnames.length > 0) {
733
+ result.push({
734
+ operation: 'addCols',
735
+ operand: operand?.info.id,
736
+ colnames
737
+ });
738
+ }
739
+ return result;
740
+ }
741
+ /**
742
+ * Maps a function adding rows to a data frame, such as `rbind(df, c(1, "A"))`, to abstract data frame operations.
743
+ */
744
+ function mapDataFrameRowBind(args, params, ctx, info) {
745
+ args = (0, arguments_1.getEffectiveArgs)(args, params.special);
746
+ const dataFrame = args.find(arg => (0, arguments_1.isDataFrameArgument)(arg, ctx));
747
+ if (dataFrame === undefined) {
748
+ return;
749
+ }
750
+ else if (args.length === 1) {
751
+ return [{ operation: 'identity', operand: dataFrame.value.info.id }];
752
+ }
753
+ const result = [];
754
+ let operand = dataFrame.value;
755
+ let rows = 0;
756
+ for (const arg of args) {
757
+ if (arg !== dataFrame && r_argument_1.RArgument.isNotEmpty(arg)) {
758
+ const otherDataFrame = ctx.getAbstractValue(arg.value);
759
+ if (otherDataFrame !== undefined) {
760
+ result.push({
761
+ operation: 'concatRows',
762
+ operand: operand?.info.id,
763
+ other: otherDataFrame
764
+ });
765
+ operand = undefined;
766
+ // number of added rows is top if arguments cannot be resolved to constant (vector-like) value
767
+ }
768
+ else if (resolve_helper_1.Resolve.argument.value(arg, info) !== undefined) {
769
+ rows = rows !== undefined ? rows + 1 : undefined;
770
+ }
771
+ else {
772
+ rows = undefined;
773
+ }
774
+ }
775
+ }
776
+ if (rows === undefined || rows > 0) {
777
+ result.push({
778
+ operation: 'addRows',
779
+ operand: operand?.info.id,
780
+ rows
781
+ });
782
+ }
783
+ return result;
784
+ }
785
+ /**
786
+ * Maps a function returning the first or last rows of a data frame, such as `head(df, 3)` or `tail(df, 3)`, to abstract data frame operations.
787
+ */
788
+ function mapDataFrameHeadTail(args, params, ctx, info) {
789
+ const dataFrame = (0, arguments_1.getFunctionArgument)(args, params.dataFrame, info);
790
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, ctx)) {
791
+ return;
792
+ }
793
+ const result = [];
794
+ const amount = (0, arguments_1.getArgumentValue)(args, params.amount, info);
795
+ let rows = undefined;
796
+ let cols = undefined;
797
+ if (typeof amount === 'number') {
798
+ rows = amount;
799
+ }
800
+ else if (Array.isArray(amount) && amount.length <= 2 && amount.every(value => typeof value === 'number')) {
801
+ rows = amount[0];
802
+ cols = amount[1];
803
+ }
804
+ const amountOfRows = rows !== undefined ? wholeAmount(rows, params.fromEnd) : undefined;
805
+ if (rows !== undefined && rows < 0) {
806
+ result.push({ operation: 'removeRows', operand: dataFrame.value.info.id, rows: amountOfRows });
807
+ }
808
+ else {
809
+ /* `head`/`tail` take what the frame has, so asking for more than it holds is not asking for `NA` rows */
810
+ result.push({ operation: 'subsetRows', operand: dataFrame.value.info.id, rows: amountOfRows, options: { atMost: true } });
811
+ }
812
+ if (cols !== undefined) {
813
+ result.push({
814
+ operation: cols >= 0 ? 'subsetCols' : 'removeCols',
815
+ operand: undefined,
816
+ colnames: unnamedColumns(wholeAmount(cols, params.fromEnd))
817
+ });
818
+ }
819
+ return result;
820
+ }
821
+ /**
822
+ * How many entries `head`/`tail` keep or drop for a fractional count. R rounds differently on each side: `head`
823
+ * takes the floor of what it keeps and the ceiling of what it drops, while `tail` rounds either way (`fromEnd`).
824
+ */
825
+ function wholeAmount(amount, fromEnd) {
826
+ const size = Math.abs(amount);
827
+ if (fromEnd) {
828
+ return amount < 0 ? Math.floor(size) : Math.round(size);
829
+ }
830
+ return amount < 0 ? Math.ceil(size) : Math.floor(size);
831
+ }
832
+ /**
833
+ * The most columns an answer names one by one. A count comes out of the analyzed source, so it may say anything
834
+ * at all -- `head(df, c(2, 2e9))` asks for two billion -- and no answer is worth the memory of writing that out.
835
+ */
836
+ const MaxNamedColumns = 4096;
837
+ /**
838
+ * The `count` columns an operation names without knowing what they are called, or `undefined` when there are more
839
+ * of them than {@link MaxNamedColumns}, which widens the answer instead of allocating for it.
840
+ */
841
+ function unnamedColumns(count) {
842
+ return Number.isSafeInteger(count) && count >= 0 && count <= MaxNamedColumns ? Array(count).fill(undefined) : undefined;
843
+ }
844
+ /**
845
+ * Maps a function subsetting the rows and columns of a data frame, such as `subset(df, id > 1, select = c(id, name))`, to abstract data frame operations.
846
+ */
847
+ function mapDataFrameSubset(args, params, ctx, info) {
848
+ const dataFrame = (0, arguments_1.getFunctionArgument)(args, params.dataFrame, info);
849
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, ctx)) {
850
+ return;
851
+ }
852
+ else if (args.length === 1) {
853
+ return [{ operation: 'identity', operand: dataFrame.value.info.id }];
854
+ }
855
+ const result = [];
856
+ let operand = dataFrame.value;
857
+ const filterArg = (0, arguments_1.getFunctionArgument)(args, params.subset, info);
858
+ const filterValue = resolve_helper_1.Resolve.argument.value(filterArg, info);
859
+ const selectArg = (0, arguments_1.getFunctionArgument)(args, params.select, info);
860
+ const dropArg = (0, arguments_1.getFunctionArgument)(args, params.drop, info);
861
+ const condition = typeof filterValue === 'boolean' ? filterValue : undefined;
862
+ const filterNames = (0, arguments_1.getUnresolvedSymbolsInExpression)(filterArg, info.graph);
863
+ const { selectedCols, unselectedCols } = getSelectedColumns([selectArg], info);
864
+ const accessedCols = [...filterNames, ...selectedCols ?? [], ...unselectedCols ?? []];
865
+ const mixedAccess = accessedCols.some(isColName) && accessedCols.some(isIndex);
866
+ const duplicateCols = accessedCols.some((col, index, list) => col !== undefined && list.indexOf(col) !== index);
867
+ if (accessedCols.some(isColName)) {
868
+ result.push({
869
+ operation: 'accessCols',
870
+ operand: operand?.info.id,
871
+ columns: accessedCols.filter(isColName)
872
+ });
873
+ }
874
+ if (accessedCols.some(isIndex)) {
875
+ result.push({
876
+ operation: 'accessCols',
877
+ operand: operand?.info.id,
878
+ columns: accessedCols.filter(isIndex).map(Math.abs)
879
+ });
880
+ }
881
+ if (filterArg !== undefined && r_argument_1.RArgument.isNotEmpty(filterArg)) {
882
+ result.push({
883
+ operation: 'filterRows',
884
+ operand: operand?.info.id,
885
+ condition: condition
886
+ });
887
+ operand = undefined;
888
+ }
889
+ if (dropArg === undefined || accessedCols.length > 1) {
890
+ if (unselectedCols === undefined || unselectedCols.length > 0) {
891
+ result.push({
892
+ operation: 'removeCols',
893
+ operand: operand?.info.id,
894
+ colnames: unselectedCols?.map(toColName)
895
+ });
896
+ operand = undefined;
897
+ }
898
+ if (selectedCols === undefined || selectedCols.length > 0) {
899
+ result.push({
900
+ operation: 'subsetCols',
901
+ operand: operand?.info.id,
902
+ colnames: selectedCols?.map(toColName),
903
+ ...(duplicateCols || mixedAccess ? { options: { duplicateCols: true } } : {})
904
+ });
905
+ // eslint-disable-next-line no-useless-assignment -- ends the chain
906
+ operand = undefined;
907
+ }
908
+ }
909
+ return result;
910
+ }
911
+ /**
912
+ * Maps a function filtering the rows of a data frame, such as `filter(df, id > 1)`, to abstract data frame operations.
913
+ */
914
+ function mapDataFrameFilter(args, params, ctx, info) {
915
+ args = (0, arguments_1.getEffectiveArgs)(args, params.special);
916
+ const dataFrame = (0, arguments_1.getFunctionArgument)(args, params.dataFrame, info);
917
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, ctx)) {
918
+ return;
919
+ }
920
+ else if (args.length === 1) {
921
+ return [{ operation: 'identity', operand: dataFrame.value.info.id }];
922
+ }
923
+ const result = [];
924
+ const filterArgs = args.filter(arg => arg !== dataFrame);
925
+ const filterValues = filterArgs.map(arg => resolve_helper_1.Resolve.argument.value(arg, info));
926
+ const accessedNames = filterArgs.flatMap(arg => (0, arguments_1.getUnresolvedSymbolsInExpression)(arg, info.graph));
927
+ const condition = filterValues.every(value => typeof value === 'boolean') ? filterValues.every(Boolean) : undefined;
928
+ if (accessedNames.length > 0) {
929
+ result.push({
930
+ operation: 'accessCols',
931
+ operand: dataFrame.value.info.id,
932
+ columns: accessedNames
933
+ });
934
+ }
935
+ result.push({
936
+ operation: 'filterRows',
937
+ operand: dataFrame.value.info.id,
938
+ condition: condition
939
+ });
940
+ return result;
941
+ }
942
+ /**
943
+ * Maps a function selecting the columns of a data frame, such as `select(df, id, name)` or `select(df, -id)`, to abstract data frame operations.
944
+ */
945
+ function mapDataFrameSelect(args, params, ctx, info) {
946
+ args = (0, arguments_1.getEffectiveArgs)(args, params.special);
947
+ const dataFrame = (0, arguments_1.getFunctionArgument)(args, params.dataFrame, info);
948
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, ctx)) {
949
+ return;
950
+ }
951
+ const result = [];
952
+ let operand = dataFrame.value;
953
+ const selectArgs = args.filter(arg => arg !== dataFrame);
954
+ let { selectedCols, unselectedCols } = getSelectedColumns(selectArgs, info);
955
+ const accessedCols = [...selectedCols ?? [], ...unselectedCols ?? []];
956
+ const mixedAccess = accessedCols.some(isColName) && accessedCols.some(isIndex);
957
+ const duplicateAccess = accessedCols.some((col, _, list) => col !== undefined && list.filter(other => other === col).length > 1);
958
+ const renamedCols = selectArgs.some(r_argument_1.RArgument.isNamed);
959
+ // map to top if columns are selected mixed by string and number, or are selected duplicate
960
+ if (mixedAccess || duplicateAccess) {
961
+ selectedCols = undefined;
962
+ unselectedCols = [];
963
+ }
964
+ if (accessedCols.some(isColName)) {
965
+ result.push({
966
+ operation: 'accessCols',
967
+ operand: operand?.info.id,
968
+ columns: accessedCols.filter(isColName)
969
+ });
970
+ }
971
+ if (accessedCols.some(isIndex)) {
972
+ result.push({
973
+ operation: 'accessCols',
974
+ operand: operand?.info.id,
975
+ columns: accessedCols.filter(isIndex).map(Math.abs)
976
+ });
977
+ }
978
+ if (unselectedCols === undefined || unselectedCols.length > 0) {
979
+ result.push({
980
+ operation: 'removeCols',
981
+ operand: operand?.info.id,
982
+ colnames: unselectedCols?.map(toColName)
983
+ });
984
+ operand = undefined;
985
+ }
986
+ if (selectedCols === undefined || selectedCols.length > 0 || unselectedCols?.length === 0) {
987
+ result.push({
988
+ operation: 'subsetCols',
989
+ operand: operand?.info.id,
990
+ colnames: selectedCols?.map(toColName),
991
+ ...(renamedCols ? { options: { renamedCols: true } } : {})
992
+ });
993
+ // eslint-disable-next-line no-useless-assignment -- ends the chain
994
+ operand = undefined;
995
+ }
996
+ return result;
997
+ }
998
+ /**
999
+ * Maps a function creating, modifying, or deleting the columns of a data frame, such as `mutate(df, id = id + 1)` or `transform(df, id = NULL)`, to abstract data frame operations.
1000
+ */
1001
+ function mapDataFrameMutate(args, params, ctx, info) {
1002
+ args = (0, arguments_1.getEffectiveArgs)(args, params.special);
1003
+ const dataFrame = (0, arguments_1.getFunctionArgument)(args, params.dataFrame, info);
1004
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, ctx)) {
1005
+ return;
1006
+ }
1007
+ else if (args.length === 1) {
1008
+ return [{ operation: 'identity', operand: dataFrame.value.info.id }];
1009
+ }
1010
+ const result = [];
1011
+ let operand = dataFrame.value;
1012
+ const mutateArgs = args.filter(arg => arg !== dataFrame);
1013
+ let deletedCols = mutateArgs
1014
+ .filter(arguments_1.isRNull)
1015
+ .map(arg => resolve_helper_1.Resolve.argument.toName(arg, info));
1016
+ let mutatedCols = mutateArgs
1017
+ .filter(arg => !(0, arguments_1.isRNull)(arg))
1018
+ .map(arg => resolve_helper_1.Resolve.argument.toName(arg, info));
1019
+ // only column names that are not created by mutation are preconditions on the operand
1020
+ const mutatedColSet = new Set(mutatedCols);
1021
+ const accessedNames = mutateArgs
1022
+ .flatMap(arg => (0, arguments_1.getUnresolvedSymbolsInExpression)(arg, info.graph))
1023
+ .filter(arg => !mutatedColSet.has(arg));
1024
+ deletedCols = (0, arguments_1.filterValidNames)(deletedCols, params.checkNames, params.noDupNames, undefined, true);
1025
+ mutatedCols = (0, arguments_1.filterValidNames)(mutatedCols, params.checkNames, params.noDupNames, undefined, true);
1026
+ if (accessedNames.length > 0) {
1027
+ result.push({
1028
+ operation: 'accessCols',
1029
+ operand: operand?.info.id,
1030
+ columns: accessedNames
1031
+ });
1032
+ }
1033
+ if (mutatedCols === undefined || mutatedCols.length > 0 || deletedCols?.length === 0) {
1034
+ result.push({
1035
+ operation: 'mutateCols',
1036
+ operand: operand?.info.id,
1037
+ colnames: mutatedCols
1038
+ });
1039
+ operand = undefined;
1040
+ }
1041
+ if (deletedCols === undefined || deletedCols.length > 0) {
1042
+ result.push({
1043
+ operation: 'removeCols',
1044
+ operand: operand?.info.id,
1045
+ colnames: deletedCols,
1046
+ options: { maybe: true }
1047
+ });
1048
+ // eslint-disable-next-line no-useless-assignment -- ends the chain
1049
+ operand = undefined;
1050
+ }
1051
+ return result;
1052
+ }
1053
+ /**
1054
+ * Maps a function grouping the rows of a data frame by columns, such as `group_by(df, id)`, to abstract data frame operations.
1055
+ */
1056
+ function mapDataFrameGroupBy(args, params, ctx, info) {
1057
+ args = (0, arguments_1.getEffectiveArgs)(args, params.special);
1058
+ const dataFrame = (0, arguments_1.getFunctionArgument)(args, params.dataFrame, info);
1059
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, ctx)) {
1060
+ return;
1061
+ }
1062
+ else if (args.length === 1) {
1063
+ return [{ operation: 'identity', operand: dataFrame.value.info.id }];
1064
+ }
1065
+ const result = [];
1066
+ const byArgs = args.filter(arg => arg !== dataFrame);
1067
+ const accessedNames = byArgs.flatMap(arg => (0, arguments_1.getUnresolvedSymbolsInExpression)(arg, info.graph));
1068
+ const byNames = byArgs.map(arg => r_argument_1.RArgument.isNamed(arg) ? resolve_helper_1.Resolve.argument.toName(arg, info) : resolve_helper_1.Resolve.argument.symbolName(arg, info));
1069
+ const mutatedCols = byArgs.some(r_argument_1.RArgument.isNamed) || byNames.some(assert_1.isUndefined);
1070
+ if (accessedNames.length > 0) {
1071
+ result.push({
1072
+ operation: 'accessCols',
1073
+ operand: dataFrame.value.info.id,
1074
+ columns: accessedNames
1075
+ });
1076
+ }
1077
+ result.push({
1078
+ operation: 'groupBy',
1079
+ operand: dataFrame.value.info.id,
1080
+ by: byNames,
1081
+ ...(mutatedCols ? { options: { mutatedCols: true } } : {})
1082
+ });
1083
+ return result;
1084
+ }
1085
+ /**
1086
+ * Maps a function summarizing the columns of a data frame, such as `summarize(df, mean = mean(score))`, to abstract data frame operations.
1087
+ */
1088
+ function mapDataFrameSummarize(args, params, ctx, info) {
1089
+ args = (0, arguments_1.getEffectiveArgs)(args, params.special);
1090
+ const dataFrame = (0, arguments_1.getFunctionArgument)(args, params.dataFrame, info);
1091
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, ctx)) {
1092
+ return;
1093
+ }
1094
+ const result = [];
1095
+ const summarizeArgs = args.filter(arg => arg !== dataFrame);
1096
+ const summarizedCols = summarizeArgs.map(arg => resolve_helper_1.Resolve.argument.toName(arg, info));
1097
+ // only column names that are not created by summarize are preconditions on the operand
1098
+ const accessedNames = summarizeArgs
1099
+ .flatMap(arg => (0, arguments_1.getUnresolvedSymbolsInExpression)(arg, info.graph))
1100
+ .filter(arg => !summarizedCols.includes(arg));
1101
+ if (accessedNames.length > 0) {
1102
+ result.push({
1103
+ operation: 'accessCols',
1104
+ operand: dataFrame.value.info.id,
1105
+ columns: accessedNames
1106
+ });
1107
+ }
1108
+ result.push({
1109
+ operation: 'summarize',
1110
+ operand: dataFrame.value.info.id,
1111
+ colnames: summarizedCols
1112
+ });
1113
+ return result;
1114
+ }
1115
+ /**
1116
+ * Maps a function joining two data frames, such as `left_join(df1, df2, by = "id")` or `merge(df1, df2)`, to abstract data frame operations.
1117
+ */
1118
+ function mapDataFrameJoin(args, params, ctx, info) {
1119
+ const dataFrame = (0, arguments_1.getFunctionArgument)(args, params.dataFrame, info);
1120
+ const joinAll = (0, arguments_1.getArgumentValue)(args, params.joinAll, info);
1121
+ const joinLeft = (0, arguments_1.getArgumentValue)(args, params.joinLeft, info);
1122
+ const joinRight = (0, arguments_1.getArgumentValue)(args, params.joinRight, info);
1123
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, ctx)) {
1124
+ return;
1125
+ }
1126
+ else if (args.length === 1) {
1127
+ return [{ operation: 'identity', operand: dataFrame.value.info.id }];
1128
+ }
1129
+ else if (typeof joinAll !== 'boolean' || typeof joinLeft !== 'boolean' || typeof joinRight !== 'boolean') {
1130
+ return [{ operation: 'unknown', operand: dataFrame.value.info.id }];
1131
+ }
1132
+ const result = [];
1133
+ const otherArg = (0, arguments_1.getFunctionArgument)(args, params.otherDataFrame, info);
1134
+ const byArg = (0, arguments_1.getFunctionArgument)(args, params.by, info);
1135
+ const otherDataFrame = ctx.getAbstractValue(otherArg) ?? dataframe_domain_1.DataFrameDomain.top(info.ctx.config.abstractInterpretation.dataFrame.maxColNames);
1136
+ let byCols;
1137
+ const joinType = getJoinType(joinAll, joinLeft, joinRight);
1138
+ if (byArg !== undefined) {
1139
+ const byValue = resolve_helper_1.Resolve.argument.value(byArg, info);
1140
+ if (isColName(byValue) || isIndex(byValue)) {
1141
+ byCols = [byValue];
1142
+ }
1143
+ else if (Array.isArray(byValue) && (byValue.every(isColName) || byValue.every(isIndex))) {
1144
+ byCols = byValue;
1145
+ }
1146
+ }
1147
+ if (byCols?.some(isColName)) {
1148
+ result.push({
1149
+ operation: 'accessCols',
1150
+ operand: dataFrame.value.info.id,
1151
+ columns: byCols.filter(isColName)
1152
+ });
1153
+ }
1154
+ if (byCols?.some(isIndex)) {
1155
+ result.push({
1156
+ operation: 'accessCols',
1157
+ operand: dataFrame.value.info.id,
1158
+ columns: byCols.filter(isIndex)
1159
+ });
1160
+ }
1161
+ result.push({
1162
+ operation: 'join',
1163
+ operand: dataFrame.value.info.id,
1164
+ other: otherDataFrame,
1165
+ by: byCols?.map(toColName),
1166
+ options: { join: joinType, natural: byArg === undefined }
1167
+ });
1168
+ return result;
1169
+ }
1170
+ /**
1171
+ * Maps a function that does not change the shape of a data frame, such as `relocate(df, id)` or `arrange(df, id)`, to abstract data frame operations.
1172
+ */
1173
+ function mapDataFrameIdentity(args, params, ctx, info) {
1174
+ args = (0, arguments_1.getEffectiveArgs)(args, params.special);
1175
+ const dataFrame = (0, arguments_1.getFunctionArgument)(args, params.dataFrame, info);
1176
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, ctx)) {
1177
+ return;
1178
+ }
1179
+ else if (params.disallowNamedArgs && args.some(r_argument_1.RArgument.isNamed)) {
1180
+ return [{ operation: 'unknown', operand: dataFrame.value.info.id }];
1181
+ }
1182
+ return [{
1183
+ operation: 'identity',
1184
+ operand: dataFrame.value.info.id
1185
+ }];
1186
+ }
1187
+ /**
1188
+ * Maps a function that is not explicitly supported but returns or modifies a data frame, such as `na.omit(df)` or `setNames(df, "id")`, to abstract data frame operations.
1189
+ */
1190
+ function mapDataFrameUnknown(args, params, ctx, info) {
1191
+ let dataFrame;
1192
+ if (params.dataFrame !== undefined) {
1193
+ dataFrame = (0, arguments_1.getFunctionArgument)(args, params.dataFrame, info);
1194
+ }
1195
+ else {
1196
+ dataFrame = args.find(arg => (0, arguments_1.isDataFrameArgument)(arg, ctx));
1197
+ }
1198
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, ctx)) {
1199
+ return;
1200
+ }
1201
+ return [{
1202
+ operation: 'unknown',
1203
+ operand: dataFrame.value.info.id,
1204
+ ...(params.constraintType !== undefined ? { type: params.constraintType } : {})
1205
+ }];
1206
+ }
1207
+ /**
1208
+ * Maps a data frame access operation, such as `df$id`, `df["id"]`, or `df[1, 2]`, to abstract data frame operations.
1209
+ */
1210
+ function mapDataFrameAccess(access, ctx, info) {
1211
+ if (r_access_1.RAccess.isNamed(access)) {
1212
+ return mapDataFrameNamedColumnAccess(access, ctx, info);
1213
+ }
1214
+ else {
1215
+ return mapDataFrameIndexColRowAccess(access, ctx, info);
1216
+ }
1217
+ }
1218
+ /**
1219
+ * Maps a string-based access of a data frame column, such as `df$id`, to abstract data frame operations.
1220
+ */
1221
+ function mapDataFrameNamedColumnAccess(access, ctx, info) {
1222
+ const dataFrame = access.accessed;
1223
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, ctx)) {
1224
+ return;
1225
+ }
1226
+ const colname = resolve_helper_1.Resolve.argument.symbolName(access.access[0], info);
1227
+ return [{
1228
+ operation: 'accessCols',
1229
+ operand: dataFrame.info.id,
1230
+ columns: colname ? [colname] : undefined
1231
+ }];
1232
+ }
1233
+ /** the largest absolute index of a list, which can hold more entries than a spread could pass as arguments */
1234
+ function maxAbs(indices) {
1235
+ let max = -Infinity;
1236
+ for (const index of indices) {
1237
+ max = Math.max(max, Math.abs(index));
1238
+ }
1239
+ return max;
1240
+ }
1241
+ /**
1242
+ * Maps an index-based access of the rows and columns of a data frame, such as `df[1, ]` or `df[["id"]]`, to abstract data frame operations.
1243
+ */
1244
+ function mapDataFrameIndexColRowAccess(access, ctx, info) {
1245
+ const dataFrame = access.accessed;
1246
+ const drop = (0, arguments_1.getArgumentValue)(access.access, 'drop', info);
1247
+ const exact = (0, arguments_1.getArgumentValue)(access.access, 'exact', info);
1248
+ const args = access.access.filter(arg => r_argument_1.RArgument.isEmpty(arg) || r_argument_1.RArgument.isUnnamed(arg));
1249
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, ctx)) {
1250
+ return;
1251
+ }
1252
+ else if (args.every(r_argument_1.RArgument.isEmpty)) {
1253
+ return [{ operation: 'identity', operand: dataFrame.info.id }];
1254
+ }
1255
+ const result = [];
1256
+ const rowArg = args.length < 2 ? undefined : args[0];
1257
+ const colArg = args.length < 2 ? args[0] : args[1];
1258
+ let rows = undefined;
1259
+ let columns = undefined;
1260
+ if (rowArg !== undefined && r_argument_1.RArgument.isNotEmpty(rowArg)) {
1261
+ const rowValue = resolve_helper_1.Resolve.argument.value(rowArg, info);
1262
+ if (isIndex(rowValue)) {
1263
+ rows = [rowValue];
1264
+ }
1265
+ else if (Array.isArray(rowValue) && rowValue.every(isIndex)) {
1266
+ rows = rowValue;
1267
+ }
1268
+ result.push({
1269
+ operation: 'accessRows',
1270
+ operand: dataFrame.info.id,
1271
+ rows: rows?.map(Math.abs)
1272
+ });
1273
+ }
1274
+ if (colArg !== undefined && r_argument_1.RArgument.isNotEmpty(colArg)) {
1275
+ const colValue = resolve_helper_1.Resolve.argument.value(colArg, info);
1276
+ if (isIndex(colValue)) {
1277
+ columns = [colValue];
1278
+ }
1279
+ else if (isColName(colValue) && exact !== false) {
1280
+ columns = [colValue];
1281
+ }
1282
+ else if (Array.isArray(colValue) && colValue.every(isIndex)) {
1283
+ columns = colValue;
1284
+ }
1285
+ else if (Array.isArray(colValue) && colValue.every(isColName) && exact !== false) {
1286
+ columns = colValue;
1287
+ }
1288
+ result.push({
1289
+ operation: 'accessCols',
1290
+ operand: dataFrame.info.id,
1291
+ columns: columns?.every(isIndex) ? columns.map(Math.abs) : columns
1292
+ });
1293
+ }
1294
+ // The data frame extent is dropped if the operator `[[` is used, the argument `drop` is true, or only one column is accessed
1295
+ const dropExtent = access.operator === '[[' ? true :
1296
+ args.length === 2 && typeof drop === 'boolean' ? drop :
1297
+ rowArg !== undefined && columns?.length === 1 && (isColName(columns[0]) || columns[0] > 0);
1298
+ if (!dropExtent) {
1299
+ const rowSubset = rows === undefined || rows.every(row => row >= 0);
1300
+ const colSubset = columns === undefined || columns.every(col => isColName(col) || col >= 0);
1301
+ const rowZero = rows?.length === 1 && rows[0] === 0;
1302
+ const colZero = columns?.length === 1 && columns[0] === 0;
1303
+ const duplicateCols = columns !== undefined && new Set(columns).size !== columns.length;
1304
+ let operand = dataFrame;
1305
+ if (rowArg !== undefined && r_argument_1.RArgument.isNotEmpty(rowArg)) {
1306
+ if (rowSubset) {
1307
+ result.push({
1308
+ operation: 'subsetRows',
1309
+ operand: operand?.info.id,
1310
+ rows: rowZero ? 0 : rows?.filter(index => index !== 0).length
1311
+ });
1312
+ }
1313
+ else {
1314
+ result.push({
1315
+ operation: 'removeRows',
1316
+ operand: operand?.info.id,
1317
+ rows: rowZero ? 0 : rows?.filter(index => index !== 0).length,
1318
+ /* R drops nothing for an index beyond the extent, so the semantics has to know how far they reach */
1319
+ maxIndex: rows !== undefined ? maxAbs(rows) : undefined
1320
+ });
1321
+ }
1322
+ operand = undefined;
1323
+ }
1324
+ if (colArg !== undefined && r_argument_1.RArgument.isNotEmpty(colArg)) {
1325
+ if (colSubset) {
1326
+ result.push({
1327
+ operation: 'subsetCols',
1328
+ operand: operand?.info.id,
1329
+ colnames: colZero ? [] : columns?.map(toColName),
1330
+ ...(duplicateCols ? { options: { duplicateCols: true } } : {})
1331
+ });
1332
+ }
1333
+ else {
1334
+ result.push({
1335
+ operation: 'removeCols',
1336
+ operand: operand?.info.id,
1337
+ colnames: columns?.map(toColName),
1338
+ maxIndex: columns?.every(isIndex) ? maxAbs(columns) : undefined
1339
+ });
1340
+ }
1341
+ // eslint-disable-next-line no-useless-assignment -- ends the chain
1342
+ operand = undefined;
1343
+ }
1344
+ }
1345
+ return result;
1346
+ }
1347
+ /**
1348
+ * Maps an assignment to a data frame access, such as `df$id <- 1:5`, `df[] <- NULL`, or `df[1, 2] <- 0`, to abstract data frame operations.
1349
+ */
1350
+ function mapDataFrameAccessAssignment(node, expression, ctx, info) {
1351
+ if (!r_access_1.RAccess.is(node)) {
1352
+ return;
1353
+ }
1354
+ else if (r_access_1.RAccess.isNamed(node)) {
1355
+ return mapDataFrameNamedColumnAssignment(node, expression, ctx, info);
1356
+ }
1357
+ else if (node.access.every(r_argument_1.RArgument.isEmpty)) {
1358
+ return mapDataFrameContentAssignment(node, expression, ctx);
1359
+ }
1360
+ else {
1361
+ return mapDataFrameIndexColRowAssignment(node, expression, ctx, info);
1362
+ }
1363
+ }
1364
+ /**
1365
+ * Maps an assignment to the content of a data frame, such as `df[] <- NULL`, to abstract data frame operations.
1366
+ */
1367
+ function mapDataFrameContentAssignment(access, expression, ctx) {
1368
+ const dataFrame = access.accessed;
1369
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, ctx)) {
1370
+ return;
1371
+ }
1372
+ if ((0, arguments_1.isRNull)(expression)) {
1373
+ return [{
1374
+ operation: 'subsetCols',
1375
+ operand: dataFrame.info.id,
1376
+ colnames: [],
1377
+ type: semantics_1.ConstraintType.OperandModification
1378
+ }];
1379
+ }
1380
+ else {
1381
+ return [{
1382
+ operation: 'identity',
1383
+ operand: dataFrame.info.id,
1384
+ type: semantics_1.ConstraintType.OperandModification
1385
+ }];
1386
+ }
1387
+ }
1388
+ /**
1389
+ * Maps an assignment to a string-based access of a data frame column, such as `df$id <- 1:5`, to abstract data frame operations.
1390
+ */
1391
+ function mapDataFrameNamedColumnAssignment(access, expression, ctx, info) {
1392
+ const dataFrame = access.accessed;
1393
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, ctx)) {
1394
+ return;
1395
+ }
1396
+ const colname = resolve_helper_1.Resolve.argument.symbolName(access.access[0], info);
1397
+ if ((0, arguments_1.isRNull)(expression)) {
1398
+ return [{
1399
+ operation: 'removeCols',
1400
+ operand: dataFrame.info.id,
1401
+ colnames: colname ? [colname] : undefined,
1402
+ type: semantics_1.ConstraintType.OperandModification,
1403
+ options: { maybe: true }
1404
+ }];
1405
+ }
1406
+ else {
1407
+ return [{
1408
+ operation: 'assignCols',
1409
+ operand: dataFrame.info.id,
1410
+ columns: colname ? [colname] : undefined
1411
+ }];
1412
+ }
1413
+ }
1414
+ /**
1415
+ * Maps an assignment to an index-based access of the rows and columns of a data frame, such as `df[1, 2] <- 0`, to abstract data frame operations.
1416
+ */
1417
+ function mapDataFrameIndexColRowAssignment(access, expression, ctx, info) {
1418
+ const dataFrame = access.accessed;
1419
+ const args = access.access.filter(arg => r_argument_1.RArgument.isEmpty(arg) || r_argument_1.RArgument.isUnnamed(arg));
1420
+ if (!(0, arguments_1.isDataFrameArgument)(dataFrame, ctx) || args.every(r_argument_1.RArgument.isEmpty)) {
1421
+ return;
1422
+ }
1423
+ const result = [];
1424
+ const rowArg = args.length < 2 ? undefined : args[0];
1425
+ const colArg = args.length < 2 ? args[0] : args[1];
1426
+ if (rowArg !== undefined && r_argument_1.RArgument.isNotEmpty(rowArg)) {
1427
+ const rowValue = resolve_helper_1.Resolve.argument.value(rowArg, info);
1428
+ let rows = undefined;
1429
+ if (isIndex(rowValue)) {
1430
+ rows = [rowValue];
1431
+ }
1432
+ else if (Array.isArray(rowValue) && rowValue.every(isIndex)) {
1433
+ rows = rowValue;
1434
+ }
1435
+ result.push({
1436
+ operation: 'assignRows',
1437
+ operand: dataFrame.info.id,
1438
+ rows
1439
+ });
1440
+ }
1441
+ if (colArg !== undefined && r_argument_1.RArgument.isNotEmpty(colArg)) {
1442
+ const colValue = resolve_helper_1.Resolve.argument.value(colArg, info);
1443
+ let columns = undefined;
1444
+ if (isColName(colValue)) {
1445
+ columns = [colValue];
1446
+ }
1447
+ else if (isIndex(colValue)) {
1448
+ columns = [colValue];
1449
+ }
1450
+ else if (Array.isArray(colValue) && (colValue.every(isColName) || colValue.every(isIndex))) {
1451
+ columns = colValue;
1452
+ }
1453
+ if ((0, arguments_1.isRNull)(expression)) {
1454
+ result.push({
1455
+ operation: 'removeCols',
1456
+ operand: dataFrame.info.id,
1457
+ colnames: columns?.map(toColName),
1458
+ type: semantics_1.ConstraintType.OperandModification,
1459
+ options: { maybe: true }
1460
+ });
1461
+ }
1462
+ else {
1463
+ result.push({
1464
+ operation: 'assignCols',
1465
+ operand: dataFrame.info.id,
1466
+ columns
1467
+ });
1468
+ }
1469
+ }
1470
+ return result;
1471
+ }
1472
+ /**
1473
+ * Maps an assignment to the column names of a data frame, such as `colnames(df) <- c("id", "name")`, to abstract data frame operations.
1474
+ */
1475
+ function mapDataFrameColNamesAssignment(node, expression, ctx, info) {
1476
+ const operand = getReplacementOperand(node, ctx);
1477
+ if (operand === undefined) {
1478
+ return;
1479
+ }
1480
+ const argument = info.idMap !== undefined ? (0, make_argument_1.toUnnamedArgument)(expression, info.idMap) : undefined;
1481
+ const assignedNames = resolve_helper_1.Resolve.argument.stringVector(argument, info);
1482
+ // the assignment is only partial if the replacement is nested in another replacement, such as `colnames(df)[1:2] <- ...`
1483
+ const parent = hasParentReplacement(node, ctx) ? ctx.getAstNode(node.info.parent) : undefined;
1484
+ return [{
1485
+ operation: 'setColNames',
1486
+ operand: operand.value.info.id,
1487
+ colnames: assignedNames,
1488
+ ...(parent !== undefined ? { options: { partial: true } } : {})
1489
+ }];
1490
+ }
1491
+ /**
1492
+ * Maps an assignment to the row names of a data frame, such as `rownames(df) <- c("a", "b")`, to abstract data frame operations.
1493
+ */
1494
+ function mapDataFrameRowNamesAssignment(node, _expression, ctx) {
1495
+ const operand = getReplacementOperand(node, ctx);
1496
+ if (operand === undefined) {
1497
+ return;
1498
+ }
1499
+ return [{
1500
+ operation: 'identity',
1501
+ operand: operand.value.info.id,
1502
+ type: semantics_1.ConstraintType.OperandModification
1503
+ }];
1504
+ }
1505
+ /**
1506
+ * Maps an assignment to the dimension names of a data frame, such as `dimnames(df) <- list(NULL, c("id"))`, to abstract data frame operations.
1507
+ */
1508
+ function mapDataFrameDimNamesAssignment(node, _expression, ctx) {
1509
+ const operand = getReplacementOperand(node, ctx);
1510
+ if (operand === undefined) {
1511
+ return;
1512
+ }
1513
+ return [{
1514
+ operation: 'setColNames',
1515
+ operand: operand.value.info.id,
1516
+ colnames: undefined
1517
+ }];
1518
+ }
1519
+ /**
1520
+ * Gets the data frame operand of a replacement function call, such as `df` in `colnames(df) <- "id"`.
1521
+ * @param node - The R node of the replacement function call
1522
+ * @param ctx - The context of the abstract interpretation analysis
1523
+ * @returns The argument of the data frame operand, or `undefined` if the call has no single argument that is a data frame
1524
+ */
1525
+ function getReplacementOperand(node, ctx) {
1526
+ if (!r_function_call_1.RFunctionCall.isNamed(node) || node.arguments.length !== 1) {
1527
+ return;
1528
+ }
1529
+ const operand = node.arguments[0];
1530
+ return (0, arguments_1.isDataFrameArgument)(operand, ctx) ? operand : undefined;
1531
+ }
1532
+ /**
1533
+ * Checks whether a replacement function call is nested in another replacement function call, such as `colnames(df)[1:2] <- ...`.
1534
+ */
1535
+ function hasParentReplacement(node, ctx) {
1536
+ const parentVertex = ctx.getDfgVertex(node.info.parent);
1537
+ return vertex_1.FunctionCallVertex.hasOrigin(parentVertex, built_in_proc_name_1.BuiltInProcName.Replacement);
1538
+ }
1539
+ /**
1540
+ * Gets the source and the parse request of the file or text that is read by a data frame read function (see {@link mapDataFrameRead}).
1541
+ */
1542
+ function getRequestFromRead(fileNameArg, textArg, params, info) {
1543
+ let source;
1544
+ let request;
1545
+ if (fileNameArg !== undefined && r_argument_1.RArgument.isNotEmpty(fileNameArg)) {
1546
+ const fileName = resolve_helper_1.Resolve.argument.value(fileNameArg, info);
1547
+ if (typeof fileName === 'string') {
1548
+ const text = (0, resolve_args_1.unescapeSpecialChars)(fileName);
1549
+ source = fileName;
1550
+ const referenceChain = fileNameArg.info.file ? [fileNameArg.info.file] : [];
1551
+ const sources = (0, built_in_source_1.findSource)(info.ctx.config.solver.resolveSource, fileName, { referenceChain, ctx: info.ctx });
1552
+ if (sources?.length === 1) {
1553
+ source = sources[0];
1554
+ // create request from resolved source file path
1555
+ request = { request: 'file', content: sources[0] };
1556
+ }
1557
+ else if (params.text === undefined && text.includes('\n')) {
1558
+ // create request from string if file name argument contains newline
1559
+ request = (0, retriever_1.requestFromInput)(text);
1560
+ }
1561
+ }
1562
+ }
1563
+ else if (textArg !== undefined && r_argument_1.RArgument.isNotEmpty(textArg)) {
1564
+ const text = resolve_helper_1.Resolve.argument.value(textArg, info);
1565
+ if (typeof text === 'string') {
1566
+ request = (0, retriever_1.requestFromInput)((0, resolve_args_1.unescapeSpecialChars)(text));
1567
+ }
1568
+ }
1569
+ if (request?.request === 'file' && info.ctx.files.hasCached(request.content)) {
1570
+ request = info.ctx.files.resolveRequest(request).r;
1571
+ }
1572
+ return { source, request };
1573
+ }
1574
+ /**
1575
+ * Gets all entries from a line of a CSV file using a custom separator char, quote char, and comment char
1576
+ */
1577
+ function getEntriesFromCsvLine(line, sep = ',', quote = '"', comment = '', trim = true) {
1578
+ sep = sep.length > 0 ? sep : '\\s'; // default to whitespace separator
1579
+ sep = (0, arguments_1.escapeRegExp)(sep, true); // only allow tokens like `\s`, `\t`, or `\n` in separator, quote, and comment chars
1580
+ quote = (0, arguments_1.escapeRegExp)(quote);
1581
+ comment = (0, arguments_1.escapeRegExp)(comment);
1582
+ const quantifier = sep === '\\s' ? '+' : '*'; // do not allow unquoted empty entries in whitespace-separated files
1583
+ const LineCommentRegex = new RegExp(`[${comment}].*`);
1584
+ const CsvEntryRegex = new RegExp(`(?<=^|[${sep}])(?:[${quote}]((?:[^${quote}]|[${quote}]{2})*)[${quote}]|([^${sep}]${quantifier}))`, 'g');
1585
+ const DoubleQuoteRegex = new RegExp(`([${quote}])\\1`, 'g'); // regex for doubled quotes like `""` or `''`
1586
+ return (comment ? line.replace(LineCommentRegex, '') : line)
1587
+ .matchAll(CsvEntryRegex)
1588
+ .map(match => match[1]?.replace(DoubleQuoteRegex, '$1') ?? match[2])
1589
+ .map(entry => trim ? entry.trim() : entry)
1590
+ .toArray();
1591
+ }
1592
+ /**
1593
+ * Resolves all selected columns in a select expression, such as `id`, `"id"`, `1`, `c(id, name)`, `c("id", "name")`, `1:2`, `-id`, `-1`, `-c(id, name)`, `c(-1, -2)`, etc.
1594
+ */
1595
+ function getSelectedColumns(args, info) {
1596
+ let selectedCols = [];
1597
+ let unselectedCols = [];
1598
+ const joinColumns = (columns1, columns2) => columns1 !== undefined && columns2 !== undefined ? [...columns1, ...columns2] : undefined;
1599
+ for (const arg of args) {
1600
+ if (arg !== undefined && r_argument_1.RArgument.isNotEmpty(arg)) {
1601
+ if (r_function_call_1.RFunctionCall.isNamed(arg.value) && identifier_1.Identifier.getName(arg.value.functionName.content) === 'c') {
1602
+ const result = getSelectedColumns(arg.value.arguments, info);
1603
+ selectedCols = joinColumns(selectedCols, result.selectedCols);
1604
+ unselectedCols = joinColumns(unselectedCols, result.unselectedCols);
1605
+ }
1606
+ else if (r_unary_op_1.RUnaryOp.is(arg.value) && arg.value.operator === '+' && info.idMap !== undefined) {
1607
+ const result = getSelectedColumns([(0, make_argument_1.toUnnamedArgument)(arg.value.operand, info.idMap)], info);
1608
+ selectedCols = joinColumns(selectedCols, result.selectedCols);
1609
+ unselectedCols = joinColumns(unselectedCols, result.unselectedCols);
1610
+ }
1611
+ else if (r_unary_op_1.RUnaryOp.is(arg.value) && arg.value.operator === '-' && info.idMap !== undefined) {
1612
+ const result = getSelectedColumns([(0, make_argument_1.toUnnamedArgument)(arg.value.operand, info.idMap)], info);
1613
+ selectedCols = joinColumns(selectedCols, result.unselectedCols);
1614
+ unselectedCols = joinColumns(unselectedCols, result.selectedCols);
1615
+ }
1616
+ else if (r_binary_op_1.RBinaryOp.is(arg.value) && arg.value.operator === ':' && info.idMap !== undefined) {
1617
+ const values = resolve_helper_1.Resolve.argument.value((0, make_argument_1.toUnnamedArgument)(arg.value, info.idMap), { ...info, resolve: config_1.VariableResolve.Disabled });
1618
+ if (Array.isArray(values) && values.every(isIndex)) {
1619
+ selectedCols = joinColumns(selectedCols, values.filter(value => value >= 0));
1620
+ unselectedCols = joinColumns(unselectedCols, values.filter(value => value < 0).map(Math.abs));
1621
+ }
1622
+ else {
1623
+ selectedCols = undefined;
1624
+ }
1625
+ }
1626
+ else if (r_symbol_1.RSymbol.is(arg.value) || r_string_1.RString.is(arg.value)) {
1627
+ selectedCols?.push(resolve_helper_1.Resolve.argument.symbolName(arg, info));
1628
+ }
1629
+ else if (r_number_1.RNumber.is(arg.value)) {
1630
+ selectedCols?.push(arg.value.content.num);
1631
+ }
1632
+ else {
1633
+ selectedCols = undefined;
1634
+ }
1635
+ }
1636
+ }
1637
+ return { selectedCols, unselectedCols };
1638
+ }
1639
+ /**
1640
+ * Gets the type of a join operation based on whether all rows of the left, the right, or both data frames are kept (see {@link mapDataFrameJoin}).
1641
+ */
1642
+ function getJoinType(joinAll, joinLeft, joinRight) {
1643
+ if (joinAll || (joinLeft && joinRight)) {
1644
+ return 'full';
1645
+ }
1646
+ else if (joinLeft) {
1647
+ return 'left';
1648
+ }
1649
+ else if (joinRight) {
1650
+ return 'right';
1651
+ }
1652
+ else {
1653
+ return 'inner';
1654
+ }
1655
+ }
1656
+ function isColName(value) {
1657
+ return typeof value === 'string';
1658
+ }
1659
+ function isIndex(value) {
1660
+ return typeof value === 'number';
1661
+ }
1662
+ function toColName(value) {
1663
+ return isColName(value) ? value : undefined;
1664
+ }
1665
+ //# sourceMappingURL=dataframe-semantics.js.map