@eagleoutice/flowr 2.17.4 → 2.17.5

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 (544) hide show
  1. package/README.md +13 -52
  2. package/abstract-interpretation/absint-inference.js +1 -2
  3. package/abstract-interpretation/data-frame/arguments.d.ts +14 -3
  4. package/abstract-interpretation/data-frame/arguments.js +34 -0
  5. package/abstract-interpretation/data-frame/dataframe-semantics.js +7 -15
  6. package/abstract-interpretation/data-frame/resolve-args.d.ts +2 -2
  7. package/abstract-interpretation/data-frame/semantics.d.ts +8 -1
  8. package/abstract-interpretation/data-frame/semantics.js +14 -6
  9. package/abstract-interpretation/domains/state-abstract-domain.js +28 -18
  10. package/abstract-interpretation/domains/state-map.d.ts +43 -0
  11. package/abstract-interpretation/domains/state-map.js +147 -0
  12. package/benchmark/slicer.d.ts +1 -1
  13. package/benchmark/slicer.js +8 -7
  14. package/cli/repl/commands/repl-dataflow.js +5 -5
  15. package/cli/repl/commands/repl-execute.js +3 -2
  16. package/cli/repl/commands/repl-parse.js +2 -1
  17. package/cli/repl/print-version.d.ts +1 -1
  18. package/cli/repl/print-version.js +2 -1
  19. package/cli/repl/server/connection.d.ts +1 -1
  20. package/cli/repl/server/connection.js +7 -9
  21. package/cli/slicer-app.js +2 -1
  22. package/clones/algorithms/baxter-ast.d.ts +33 -0
  23. package/clones/algorithms/baxter-ast.js +70 -0
  24. package/clones/algorithms/greedy-string-tiling.d.ts +17 -0
  25. package/clones/algorithms/greedy-string-tiling.js +56 -0
  26. package/clones/algorithms/winnowing.d.ts +27 -0
  27. package/clones/algorithms/winnowing.js +66 -0
  28. package/clones/clone-ast.d.ts +75 -0
  29. package/clones/clone-ast.js +174 -0
  30. package/clones/clone-dataflow.d.ts +11 -0
  31. package/clones/clone-dataflow.js +83 -0
  32. package/clones/clone-detector.d.ts +116 -0
  33. package/clones/clone-detector.js +200 -0
  34. package/clones/clone-index.d.ts +54 -0
  35. package/clones/clone-index.js +56 -0
  36. package/config.d.ts +21 -2
  37. package/config.js +7 -1
  38. package/control-flow/basic-cfg-guided-visitor.js +1 -2
  39. package/control-flow/happens-before.d.ts +2 -0
  40. package/control-flow/happens-before.js +15 -9
  41. package/control-flow/simple-visitor.js +2 -4
  42. package/core/steps/all/core/00-parse.js +2 -1
  43. package/core/steps/all/core/01-parse-tree-sitter.js +2 -1
  44. package/core/steps/all/core/10-normalize.js +2 -1
  45. package/core/steps/all/core/11-normalize-tree-sitter.js +2 -1
  46. package/core/steps/all/static-slicing/00-slice.js +2 -1
  47. package/core/steps/all/static-slicing/10-reconstruct.js +2 -1
  48. package/core/steps/pipeline/create-pipeline.js +1 -2
  49. package/core/steps/pipeline/default-pipelines.d.ts +1 -1
  50. package/core/steps/pipeline/default-pipelines.js +5 -4
  51. package/core/steps/pipeline-step.d.ts +3 -1
  52. package/core/steps/pipeline-step.js +5 -0
  53. package/data/r-base-primitives.generated.d.ts +2 -1
  54. package/dataflow/cluster.js +1 -2
  55. package/dataflow/environments/ambient-state-name.d.ts +14 -22
  56. package/dataflow/environments/ambient-state-name.js +4 -18
  57. package/dataflow/environments/apply-kill.d.ts +9 -20
  58. package/dataflow/environments/apply-kill.js +51 -25
  59. package/dataflow/environments/built-in-config.d.ts +7 -15
  60. package/dataflow/environments/built-in-config.js +15 -16
  61. package/dataflow/environments/built-in-eval-name.d.ts +5 -6
  62. package/dataflow/environments/built-in-eval-name.js +4 -5
  63. package/dataflow/environments/built-in-kinds.d.ts +111 -0
  64. package/dataflow/environments/built-in-kinds.js +35 -0
  65. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  66. package/dataflow/environments/built-in-proc-name.js +11 -0
  67. package/dataflow/environments/built-in-props.d.ts +62 -175
  68. package/dataflow/environments/built-in-props.js +42 -154
  69. package/dataflow/environments/built-in.d.ts +37 -73
  70. package/dataflow/environments/built-in.js +41 -62
  71. package/dataflow/environments/data-masking-functions.d.ts +2 -2
  72. package/dataflow/environments/default-builtin-config/base-functions.d.ts +7 -0
  73. package/dataflow/environments/default-builtin-config/base-functions.js +339 -0
  74. package/dataflow/environments/default-builtin-config/base-language.d.ts +3 -0
  75. package/dataflow/environments/default-builtin-config/base-language.js +66 -0
  76. package/dataflow/environments/default-builtin-config/base-operators.d.ts +58 -0
  77. package/dataflow/environments/default-builtin-config/base-operators.js +169 -0
  78. package/dataflow/environments/default-builtin-config/database-access.d.ts +3 -0
  79. package/dataflow/environments/default-builtin-config/database-access.js +16 -0
  80. package/dataflow/environments/default-builtin-config/define-helpers.d.ts +45 -0
  81. package/dataflow/environments/default-builtin-config/define-helpers.js +50 -0
  82. package/dataflow/environments/default-builtin-config/dev-tooling.d.ts +3 -0
  83. package/dataflow/environments/default-builtin-config/dev-tooling.js +63 -0
  84. package/dataflow/environments/default-builtin-config/file-io.d.ts +3 -0
  85. package/dataflow/environments/default-builtin-config/file-io.js +81 -0
  86. package/dataflow/environments/default-builtin-config/graphics-devices.d.ts +3 -0
  87. package/dataflow/environments/default-builtin-config/graphics-devices.js +57 -0
  88. package/dataflow/environments/default-builtin-config/index.d.ts +18 -0
  89. package/dataflow/environments/default-builtin-config/index.js +114 -0
  90. package/dataflow/environments/default-builtin-config/media-formats.d.ts +3 -0
  91. package/dataflow/environments/default-builtin-config/media-formats.js +41 -0
  92. package/dataflow/environments/default-builtin-config/misc-packages.d.ts +3 -0
  93. package/dataflow/environments/default-builtin-config/misc-packages.js +18 -0
  94. package/dataflow/environments/default-builtin-config/network-access.d.ts +3 -0
  95. package/dataflow/environments/default-builtin-config/network-access.js +47 -0
  96. package/dataflow/environments/default-builtin-config/object-systems.d.ts +3 -0
  97. package/dataflow/environments/default-builtin-config/object-systems.js +39 -0
  98. package/dataflow/environments/default-builtin-config/package-data-table.d.ts +3 -0
  99. package/dataflow/environments/default-builtin-config/package-data-table.js +18 -0
  100. package/dataflow/environments/default-builtin-config/package-spatial.d.ts +3 -0
  101. package/dataflow/environments/default-builtin-config/package-spatial.js +32 -0
  102. package/dataflow/environments/default-builtin-config/package-tidyverse.d.ts +3 -0
  103. package/dataflow/environments/default-builtin-config/package-tidyverse.js +96 -0
  104. package/dataflow/environments/default-builtin-config/package-utils.d.ts +3 -0
  105. package/dataflow/environments/default-builtin-config/package-utils.js +35 -0
  106. package/dataflow/environments/default-builtin-config/package-withr.d.ts +3 -0
  107. package/dataflow/environments/default-builtin-config/package-withr.js +41 -0
  108. package/dataflow/environments/default-builtin-config/parallel-execution.d.ts +3 -0
  109. package/dataflow/environments/default-builtin-config/parallel-execution.js +31 -0
  110. package/dataflow/environments/default-builtin-config/session-interactive.d.ts +3 -0
  111. package/dataflow/environments/default-builtin-config/session-interactive.js +31 -0
  112. package/dataflow/environments/default-builtin-config/shared-configs.d.ts +267 -0
  113. package/dataflow/environments/default-builtin-config/shared-configs.js +483 -0
  114. package/dataflow/environments/default-builtin-config/shared-signatures.d.ts +21 -0
  115. package/dataflow/environments/default-builtin-config/shared-signatures.js +32 -0
  116. package/dataflow/environments/default-builtin-config/statistics.d.ts +3 -0
  117. package/dataflow/environments/default-builtin-config/statistics.js +32 -0
  118. package/dataflow/environments/default-builtin-config/unit-testing.d.ts +3 -0
  119. package/dataflow/environments/default-builtin-config/unit-testing.js +13 -0
  120. package/dataflow/environments/environment.d.ts +28 -52
  121. package/dataflow/environments/environment.js +24 -71
  122. package/dataflow/environments/group-generics.d.ts +12 -19
  123. package/dataflow/environments/group-generics.js +17 -14
  124. package/dataflow/environments/identifier.d.ts +72 -427
  125. package/dataflow/environments/identifier.js +34 -145
  126. package/dataflow/environments/pkg-name.d.ts +197 -0
  127. package/dataflow/environments/pkg-name.js +3 -0
  128. package/dataflow/environments/query-fn-props.d.ts +27 -76
  129. package/dataflow/environments/query-fn-props.js +34 -95
  130. package/dataflow/environments/resolve-by-name.d.ts +6 -16
  131. package/dataflow/environments/resolve-by-name.js +23 -35
  132. package/dataflow/environments/scoping.d.ts +5 -5
  133. package/dataflow/environments/scoping.js +13 -5
  134. package/dataflow/eval/resolve/alias-tracking.d.ts +31 -68
  135. package/dataflow/eval/resolve/alias-tracking.js +611 -126
  136. package/dataflow/eval/resolve/match-arguments.d.ts +5 -3
  137. package/dataflow/eval/resolve/resolve-argument.d.ts +11 -11
  138. package/dataflow/eval/resolve/resolve-argument.js +25 -30
  139. package/dataflow/eval/resolve/resolve-field.d.ts +10 -0
  140. package/dataflow/eval/resolve/resolve-field.js +127 -0
  141. package/dataflow/eval/resolve/resolve-replacement.d.ts +10 -0
  142. package/dataflow/eval/resolve/resolve-replacement.js +80 -0
  143. package/dataflow/eval/resolve/resolve-strings.d.ts +2 -2
  144. package/dataflow/eval/resolve/resolve.d.ts +13 -10
  145. package/dataflow/eval/resolve/resolve.js +81 -32
  146. package/dataflow/eval/values/general.d.ts +6 -24
  147. package/dataflow/eval/values/general.js +12 -29
  148. package/dataflow/eval/values/lists/list-constants.d.ts +11 -0
  149. package/dataflow/eval/values/lists/list-constants.js +65 -0
  150. package/dataflow/eval/values/r-value.d.ts +20 -23
  151. package/dataflow/eval/values/r-value.js +22 -17
  152. package/dataflow/extractor.d.ts +2 -10
  153. package/dataflow/extractor.js +100 -46
  154. package/dataflow/fn/argument-roles.d.ts +2 -4
  155. package/dataflow/fn/argument-roles.js +49 -23
  156. package/dataflow/fn/class-declaration.d.ts +36 -52
  157. package/dataflow/fn/class-declaration.js +22 -56
  158. package/dataflow/fn/condition-handlers.d.ts +2 -1
  159. package/dataflow/fn/dispatch.d.ts +70 -0
  160. package/dataflow/fn/dispatch.js +434 -0
  161. package/dataflow/fn/exceptions-of-function.d.ts +1 -2
  162. package/dataflow/fn/exceptions-of-function.js +36 -106
  163. package/dataflow/fn/frame-reflection.d.ts +1 -3
  164. package/dataflow/fn/frame-reflection.js +8 -16
  165. package/dataflow/fn/function-props.d.ts +2 -5
  166. package/dataflow/fn/function-props.js +27 -36
  167. package/dataflow/fn/function-semantics.d.ts +14 -26
  168. package/dataflow/fn/function-semantics.js +4 -18
  169. package/dataflow/fn/higher-order-function.js +2 -4
  170. package/dataflow/fn/strict-function.d.ts +10 -35
  171. package/dataflow/fn/strict-function.js +126 -138
  172. package/dataflow/graph/ambient-access.d.ts +51 -0
  173. package/dataflow/graph/ambient-access.js +80 -0
  174. package/dataflow/graph/call-graph.d.ts +9 -29
  175. package/dataflow/graph/call-graph.js +17 -41
  176. package/dataflow/graph/closure-frames.d.ts +46 -0
  177. package/dataflow/graph/closure-frames.js +225 -0
  178. package/dataflow/graph/dataflowgraph-builder.d.ts +25 -96
  179. package/dataflow/graph/dataflowgraph-builder.js +29 -97
  180. package/dataflow/graph/df-helper.d.ts +48 -188
  181. package/dataflow/graph/df-helper.js +107 -208
  182. package/dataflow/graph/diff-dataflow-graph.d.ts +5 -15
  183. package/dataflow/graph/diff-dataflow-graph.js +25 -25
  184. package/dataflow/graph/edge.js +1 -1
  185. package/dataflow/graph/graph-helper.d.ts +10 -46
  186. package/dataflow/graph/graph-helper.js +16 -50
  187. package/dataflow/graph/graph.d.ts +44 -97
  188. package/dataflow/graph/graph.js +83 -79
  189. package/dataflow/graph/match-args.d.ts +21 -88
  190. package/dataflow/graph/match-args.js +284 -97
  191. package/dataflow/graph/vertex.d.ts +101 -128
  192. package/dataflow/graph/vertex.js +23 -20
  193. package/dataflow/hooks.d.ts +7 -14
  194. package/dataflow/hooks.js +15 -13
  195. package/dataflow/info.d.ts +2 -17
  196. package/dataflow/internal/dispatch-linking.d.ts +71 -0
  197. package/dataflow/internal/dispatch-linking.js +332 -0
  198. package/dataflow/internal/linker.d.ts +48 -50
  199. package/dataflow/internal/linker.js +457 -155
  200. package/dataflow/internal/process/functions/call/argument/make-argument.js +2 -1
  201. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +2 -14
  202. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +16 -46
  203. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.d.ts +7 -6
  204. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-keys.js +10 -9
  205. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +23 -75
  206. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +263 -97
  207. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +10 -7
  208. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +66 -45
  209. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +15 -19
  210. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +82 -62
  211. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +4 -4
  212. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +2 -2
  213. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +2 -2
  214. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +3 -2
  215. package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.d.ts +15 -0
  216. package/dataflow/internal/process/functions/call/built-in/built-in-deferred-env-ops.js +416 -0
  217. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +37 -54
  218. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +192 -111
  219. package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +4 -3
  220. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +60 -13
  221. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -3
  222. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +80 -76
  223. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.d.ts +1 -7
  224. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +4 -13
  225. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +4 -8
  226. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +436 -140
  227. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +18 -10
  228. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +90 -12
  229. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.d.ts +1 -5
  230. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +5 -14
  231. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +9 -8
  232. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +12 -7
  233. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +2 -2
  234. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +3 -5
  235. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +2 -6
  236. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.d.ts +9 -24
  237. package/dataflow/internal/process/functions/call/built-in/built-in-purrr-formula.js +10 -6
  238. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.d.ts +5 -6
  239. package/dataflow/internal/process/functions/call/built-in/built-in-register-hook.js +3 -4
  240. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +1 -4
  241. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +8 -11
  242. package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +1 -5
  243. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +20 -28
  244. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +17 -4
  245. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +117 -4
  246. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +5 -3
  247. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +3 -3
  248. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +8 -4
  249. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +18 -29
  250. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +7 -25
  251. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +31 -35
  252. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +4 -18
  253. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +13 -19
  254. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +18 -16
  255. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +130 -65
  256. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +2 -1
  257. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +38 -30
  258. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +584 -114
  259. package/dataflow/internal/process/functions/call/common.d.ts +8 -24
  260. package/dataflow/internal/process/functions/call/common.js +24 -24
  261. package/dataflow/internal/process/functions/call/deferred.d.ts +7 -27
  262. package/dataflow/internal/process/functions/call/deferred.js +6 -27
  263. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +6 -26
  264. package/dataflow/internal/process/functions/call/known-call-handling.js +6 -16
  265. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +1 -4
  266. package/dataflow/internal/process/functions/call/named-call-handling.js +14 -35
  267. package/dataflow/internal/process/functions/call/nse.d.ts +2 -9
  268. package/dataflow/internal/process/functions/call/nse.js +6 -13
  269. package/dataflow/internal/process/functions/call/quoted.d.ts +4 -15
  270. package/dataflow/internal/process/functions/call/quoted.js +26 -62
  271. package/dataflow/internal/process/functions/call/unnamed-call-handling.d.ts +3 -6
  272. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +29 -11
  273. package/dataflow/internal/process/functions/process-parameter.js +1 -1
  274. package/dataflow/internal/program-order.d.ts +3 -10
  275. package/dataflow/internal/program-order.js +19 -10
  276. package/dataflow/origin/dfg-get-origin.js +2 -1
  277. package/documentation/data/faq/faqs.js +16 -1
  278. package/documentation/data/interface/doc-writing-code.js +5 -7
  279. package/documentation/doc-capabilities.js +3 -3
  280. package/documentation/doc-readme.js +1 -1
  281. package/documentation/doc-util/doc-code.d.ts +0 -5
  282. package/documentation/doc-util/doc-code.js +2 -22
  283. package/documentation/doc-util/doc-query.d.ts +1 -2
  284. package/documentation/doc-util/doc-query.js +4 -5
  285. package/documentation/doc-util/doc-search.js +1 -1
  286. package/documentation/wiki-analyzer.js +4 -3
  287. package/documentation/wiki-core.js +5 -5
  288. package/documentation/wiki-dataflow-graph.js +6 -0
  289. package/documentation/wiki-interface.js +2 -1
  290. package/documentation/wiki-linter.js +15 -3
  291. package/documentation/wiki-linting-and-testing.js +15 -2
  292. package/documentation/wiki-query.js +111 -29
  293. package/index.d.ts +3 -1
  294. package/index.js +6 -3
  295. package/linter/linter-executor.js +1 -1
  296. package/linter/linter-rules.d.ts +37 -8
  297. package/linter/linter-rules.js +8 -1
  298. package/linter/linter-util.d.ts +3 -3
  299. package/linter/linter-util.js +1 -1
  300. package/linter/rules/cmd-check/bogus-return.d.ts +2 -1
  301. package/linter/rules/cmd-check/call-arguments.d.ts +3 -2
  302. package/linter/rules/cmd-check/call-arguments.js +5 -5
  303. package/linter/rules/cmd-check/cmd-check-util.d.ts +9 -8
  304. package/linter/rules/cmd-check/dependency-declaration.d.ts +2 -1
  305. package/linter/rules/cmd-check/dependency-declaration.js +1 -1
  306. package/linter/rules/cmd-check/documentation-mismatch.d.ts +3 -2
  307. package/linter/rules/cmd-check/documentation-mismatch.js +2 -1
  308. package/linter/rules/cmd-check/file-checks.d.ts +2 -2
  309. package/linter/rules/cmd-check/foreign-function-calls.d.ts +2 -1
  310. package/linter/rules/cmd-check/global-environment-modification.d.ts +6 -5
  311. package/linter/rules/cmd-check/namespace-tampering.d.ts +2 -1
  312. package/linter/rules/cmd-check/non-ascii-code.js +1 -1
  313. package/linter/rules/cmd-check/package-files.d.ts +2 -2
  314. package/linter/rules/cmd-check/package-hooks.d.ts +5 -4
  315. package/linter/rules/cmd-check/package-runtime.js +2 -2
  316. package/linter/rules/cmd-check/rd-files.js +2 -1
  317. package/linter/rules/cmd-check/s-three-method-consistency.d.ts +3 -2
  318. package/linter/rules/cmd-check/s-three-method-consistency.js +2 -1
  319. package/linter/rules/code-clones.d.ts +57 -0
  320. package/linter/rules/code-clones.js +53 -0
  321. package/linter/rules/deprecated-functions.js +3 -6
  322. package/linter/rules/file-path-validity.js +6 -4
  323. package/linter/rules/function-finder-util.d.ts +4 -2
  324. package/linter/rules/naming-convention.d.ts +6 -5
  325. package/linter/rules/naming-convention.js +2 -3
  326. package/linter/rules/no-leaked-credentials.d.ts +2 -1
  327. package/linter/rules/no-leaked-credentials.js +1 -1
  328. package/linter/rules/overwritten-file.d.ts +2 -1
  329. package/linter/rules/problematic-inputs.d.ts +2 -1
  330. package/linter/rules/problematic-inputs.js +3 -3
  331. package/linter/rules/process-state-in-session.d.ts +7 -6
  332. package/linter/rules/process-state-in-session.js +1 -1
  333. package/linter/rules/roxygen-arguments.d.ts +1 -1
  334. package/linter/rules/secret-exfiltration.js +1 -1
  335. package/linter/rules/seeded-randomness.d.ts +3 -3
  336. package/linter/rules/unclosed-connection.js +1 -2
  337. package/linter/rules/undefined-symbol-util.d.ts +3 -2
  338. package/linter/rules/undefined-symbol.d.ts +3 -2
  339. package/linter/rules/unescaped-arguments.d.ts +1 -1
  340. package/linter/rules/unescaped-arguments.js +6 -8
  341. package/linter/rules/unused-definition.d.ts +4 -3
  342. package/linter/rules/unused-definition.js +10 -12
  343. package/linter/rules/unused-import.d.ts +6 -5
  344. package/package.json +1 -1
  345. package/project/attached-packages.d.ts +5 -4
  346. package/project/cache/flowr-analyzer-cache.d.ts +14 -1
  347. package/project/cache/flowr-analyzer-cache.js +40 -3
  348. package/project/context/flowr-analyzer-dependencies-context.d.ts +12 -12
  349. package/project/context/flowr-analyzer-environment-context.d.ts +3 -3
  350. package/project/context/flowr-analyzer-environment-context.js +3 -3
  351. package/project/context/flowr-analyzer-functions-context.d.ts +9 -7
  352. package/project/context/flowr-analyzer-gas-context.d.ts +25 -0
  353. package/project/context/flowr-analyzer-gas-context.js +34 -4
  354. package/project/dependency-version-space.d.ts +30 -29
  355. package/project/dependency-version-space.js +1 -2
  356. package/project/flowr-analyzer-builder.d.ts +2 -3
  357. package/project/flowr-analyzer.d.ts +35 -3
  358. package/project/flowr-analyzer.js +11 -5
  359. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +15 -14
  360. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.d.ts +5 -4
  361. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-on-demand-plugin.js +1 -1
  362. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +2 -1
  363. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +4 -3
  364. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +2 -1
  365. package/project/plugins/package-version-plugins/package.d.ts +6 -5
  366. package/project/sigdb/build.js +1 -1
  367. package/project/sigdb/decode.d.ts +8 -7
  368. package/project/sigdb/decode.js +1 -2
  369. package/project/sigdb/dict.d.ts +2 -1
  370. package/project/sigdb/dict.js +2 -2
  371. package/project/sigdb/index-format.d.ts +2 -1
  372. package/project/sigdb/manifest.d.ts +1 -1
  373. package/project/sigdb/memory-source.d.ts +18 -17
  374. package/project/sigdb/on-demand/package-sources.d.ts +4 -3
  375. package/project/sigdb/on-demand/recoverer.d.ts +2 -1
  376. package/project/sigdb/on-demand/remote-sources.d.ts +2 -1
  377. package/project/sigdb/reader.d.ts +85 -80
  378. package/project/sigdb/reader.js +0 -4
  379. package/project/sigdb/schema.d.ts +9 -8
  380. package/project/sigdb/signature-db.d.ts +6 -6
  381. package/queries/catalog/ambient-access-query/ambient-access-query-executor.d.ts +6 -0
  382. package/queries/catalog/ambient-access-query/ambient-access-query-executor.js +50 -0
  383. package/queries/catalog/ambient-access-query/ambient-access-query-format.d.ts +54 -0
  384. package/queries/catalog/ambient-access-query/ambient-access-query-format.js +45 -0
  385. package/queries/catalog/call-context-query/call-context-query-executor.d.ts +2 -1
  386. package/queries/catalog/call-context-query/call-context-query-executor.js +2 -2
  387. package/queries/catalog/call-graph-query/expand-library-internals.d.ts +3 -2
  388. package/queries/catalog/code-clones-query/code-clones-query-executor.d.ts +6 -0
  389. package/queries/catalog/code-clones-query/code-clones-query-executor.js +38 -0
  390. package/queries/catalog/code-clones-query/code-clones-query-format.d.ts +54 -0
  391. package/queries/catalog/code-clones-query/code-clones-query-format.js +73 -0
  392. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.js +3 -3
  393. package/queries/catalog/dependencies-query/data-flow.d.ts +5 -4
  394. package/queries/catalog/dependencies-query/dependencies-query-executor.d.ts +5 -2
  395. package/queries/catalog/dependencies-query/dependencies-query-executor.js +5 -5
  396. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +3 -2
  397. package/queries/catalog/dependencies-query/dependencies-query-format.js +1 -1
  398. package/queries/catalog/dependencies-query/function-info/function-info.d.ts +6 -4
  399. package/queries/catalog/dependencies-query/implicit-echo.js +2 -1
  400. package/queries/catalog/dice-query/dice-query-format.d.ts +1 -0
  401. package/queries/catalog/dice-query/dice-query-format.js +1 -0
  402. package/queries/catalog/does-call-query/does-call-query-executor.js +1 -2
  403. package/queries/catalog/does-call-query/does-call-query-format.d.ts +1 -0
  404. package/queries/catalog/does-call-query/does-call-query-format.js +1 -0
  405. package/queries/catalog/function-info-query/function-info-query-format.d.ts +2 -1
  406. package/queries/catalog/function-info-query/function-origin.d.ts +3 -2
  407. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +3 -3
  408. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +5 -4
  409. package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +1 -0
  410. package/queries/catalog/happens-before-query/happens-before-query-format.js +1 -0
  411. package/queries/catalog/input-sources-query/input-sources-query-executor.js +7 -3
  412. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +9 -9
  413. package/queries/catalog/input-sources-query/simple-input-classifier.js +1 -1
  414. package/queries/catalog/linter-query/linter-query-executor.js +4 -1
  415. package/queries/catalog/linter-query/linter-query-format.js +3 -2
  416. package/queries/catalog/origin-query/origin-query-format.d.ts +1 -0
  417. package/queries/catalog/origin-query/origin-query-format.js +1 -0
  418. package/queries/catalog/project-query/project-query-format.d.ts +2 -1
  419. package/queries/catalog/provenance-query/provenance-query-format.d.ts +1 -0
  420. package/queries/catalog/provenance-query/provenance-query-format.js +1 -0
  421. package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +1 -0
  422. package/queries/catalog/resolve-value-query/resolve-value-query-format.js +1 -0
  423. package/queries/catalog/signature-query/signature-query-executor.d.ts +9 -6
  424. package/queries/catalog/signature-query/signature-query-executor.js +14 -15
  425. package/queries/catalog/signature-query/signature-query-format.d.ts +21 -20
  426. package/queries/catalog/signature-query/signature-query-render.js +1 -1
  427. package/queries/catalog/static-slice-query/static-slice-query-executor.js +1 -1
  428. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +9 -5
  429. package/queries/catalog/static-slice-query/static-slice-query-format.js +1 -0
  430. package/queries/query-function-filter.d.ts +1 -1
  431. package/queries/query.d.ts +59 -8
  432. package/queries/query.js +59 -37
  433. package/r-bridge/data/data.d.ts +39 -28
  434. package/r-bridge/data/data.js +37 -28
  435. package/r-bridge/lang-4.x/ast/model/model.d.ts +10 -1
  436. package/r-bridge/lang-4.x/ast/model/model.js +30 -0
  437. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +21 -0
  438. package/r-bridge/lang-4.x/ast/model/nodes/r-access.js +25 -2
  439. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +2 -1
  440. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +3 -2
  441. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.js +2 -2
  442. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  443. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  444. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  445. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  446. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +4 -3
  447. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  448. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  449. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  450. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  451. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  452. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  453. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  454. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  455. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  456. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +5 -6
  457. package/r-bridge/lang-4.x/ast/model/nodes/r-string.js +2 -7
  458. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  459. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +3 -2
  460. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.js +2 -2
  461. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  462. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +4 -5
  463. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +7 -2
  464. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +14 -6
  465. package/r-bridge/lang-4.x/ast/model/processing/visitor.d.ts +1 -1
  466. package/r-bridge/lang-4.x/ast/model/processing/visitor.js +2 -2
  467. package/r-bridge/lang-4.x/ast/model/type.d.ts +1 -1
  468. package/r-bridge/lang-4.x/ast/model/type.js +1 -1
  469. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-binary.js +2 -2
  470. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-unary.js +2 -2
  471. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
  472. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +3 -2
  473. package/r-bridge/parser.d.ts +8 -2
  474. package/r-bridge/parser.js +6 -0
  475. package/r-bridge/shell-executor.d.ts +2 -2
  476. package/r-bridge/shell-executor.js +3 -2
  477. package/r-bridge/shell.d.ts +2 -2
  478. package/r-bridge/shell.js +3 -2
  479. package/reconstruct/auto-select/magic-comments.js +1 -1
  480. package/reconstruct/reconstruct.d.ts +0 -5
  481. package/reconstruct/reconstruct.js +6 -5
  482. package/search/flowr-search-builder.d.ts +14 -0
  483. package/search/flowr-search-builder.js +7 -0
  484. package/search/flowr-search-executor.js +2 -2
  485. package/search/flowr-search-filters.js +8 -9
  486. package/search/flowr-search.js +1 -1
  487. package/search/search-executor/search-enrichers.d.ts +2 -0
  488. package/search/search-executor/search-enrichers.js +6 -1
  489. package/search/search-executor/search-generators.d.ts +2 -2
  490. package/search/search-executor/search-generators.js +13 -8
  491. package/search/search-executor/search-mappers.js +1 -1
  492. package/search/search-executor/search-transformer.d.ts +2 -2
  493. package/search/search-executor/search-transformer.js +6 -6
  494. package/slicing/criterion/parse.d.ts +2 -1
  495. package/slicing/criterion/parse.js +2 -1
  496. package/slicing/static/removal-slice.js +2 -1
  497. package/slicing/static/slice-call.d.ts +30 -4
  498. package/slicing/static/slice-call.js +74 -9
  499. package/slicing/static/slicer-types.d.ts +2 -1
  500. package/slicing/static/static-slicer.js +66 -11
  501. package/slicing/static/visiting-queue.d.ts +2 -0
  502. package/slicing/static/visiting-queue.js +4 -0
  503. package/taint-analysis/builder/report-template.d.ts +3 -3
  504. package/util/arg-matching.d.ts +1 -1
  505. package/util/collections/relation.d.ts +23 -0
  506. package/util/collections/relation.js +63 -0
  507. package/util/fixpoint.d.ts +65 -0
  508. package/util/fixpoint.js +216 -0
  509. package/util/flowr-version.d.ts +1 -1
  510. package/util/flowr-version.js +2 -2
  511. package/util/json.d.ts +4 -0
  512. package/util/json.js +12 -3
  513. package/util/mermaid/cfg.js +1 -2
  514. package/util/mermaid/dfg.d.ts +1 -1
  515. package/util/mermaid/dfg.js +1 -1
  516. package/util/mermaid/mermaid.d.ts +2 -1
  517. package/util/monoid.d.ts +26 -0
  518. package/util/monoid.js +31 -0
  519. package/util/prefix.d.ts +1 -1
  520. package/util/r-base-packages.d.ts +10 -7
  521. package/util/r-base-packages.js +11 -6
  522. package/util/r-package-urls.d.ts +10 -9
  523. package/util/r-value.js +2 -1
  524. package/util/r-version-order.d.ts +2 -0
  525. package/util/r-version-order.js +19 -0
  526. package/util/r-version.d.ts +2 -1
  527. package/util/r-version.js +2 -14
  528. package/util/range.d.ts +38 -29
  529. package/util/range.js +10 -5
  530. package/util/simple-df/dfg-ascii.js +2 -2
  531. package/util/text/ansi.d.ts +13 -9
  532. package/util/text/ansi.js +4 -6
  533. package/util/text/strings.d.ts +10 -3
  534. package/util/text/strings.js +10 -1
  535. package/util/version.d.ts +1 -1
  536. package/util/version.js +2 -1
  537. package/dataflow/environments/default-builtin-config.d.ts +0 -8874
  538. package/dataflow/environments/default-builtin-config.js +0 -1737
  539. package/r-bridge/lang-4.x/ast/model/operators.d.ts +0 -33
  540. package/r-bridge/lang-4.x/ast/model/operators.js +0 -54
  541. package/taint-analysis/eval/eval.d.ts +0 -1
  542. package/taint-analysis/eval/eval.js +0 -124
  543. package/taint-analysis/eval/instrumentation.d.ts +0 -59
  544. package/taint-analysis/eval/instrumentation.js +0 -124
@@ -0,0 +1,75 @@
1
+ import { RNode } from '../r-bridge/lang-4.x/ast/model/model';
2
+ import type { ParentInformation } from '../r-bridge/lang-4.x/ast/model/processing/decorate';
3
+ import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
4
+ import { EmptyArgument } from '../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
5
+ type Node = RNode<ParentInformation>;
6
+ /** A node as the detectors see it, including the empty argument of `f(, x)`. */
7
+ export type CloneNode = Node | typeof EmptyArgument;
8
+ /**
9
+ * How the code is presented to the detectors:
10
+ * - `syntax`: as written
11
+ * - `canonical`: sugar rewritten to one core form (pipes become calls, `\(x)` is `function(x)`, `->` and `=` are `<-`,
12
+ * `(e)` and `{e}` are `e`, `x[["a"]]` is `x$a`, `T` is `TRUE`, a tail `return(e)` is `e`), keeping the ids of the source nodes
13
+ * - `dataflow`: `canonical` with single-use temporaries inlined along the dataflow graph (`t <- f(x); g(t)` is `g(f(x))`)
14
+ */
15
+ export declare enum ClonePerspective {
16
+ Syntax = "syntax",
17
+ Canonical = "canonical",
18
+ Dataflow = "dataflow"
19
+ }
20
+ /**
21
+ * How {@link tokenize} presents the nodes: `normalized` abstracts identifiers and constants (type-2 clones),
22
+ * `exact` keeps them (type-1 clones).
23
+ */
24
+ export declare enum CloneTokenization {
25
+ Normalized = "normalized",
26
+ Exact = "exact"
27
+ }
28
+ /** Which symbol reads to replace by which value, and which assignment statements to drop. */
29
+ export interface InlinePlan {
30
+ readonly replace: ReadonlyMap<NodeId, Node>;
31
+ readonly drop: ReadonlySet<NodeId>;
32
+ }
33
+ /** The normalized AST of one file and, for the `dataflow` perspective, the temporaries to inline in it. */
34
+ export interface CloneAst {
35
+ readonly file: string;
36
+ readonly root: Node;
37
+ readonly inline?: InlinePlan;
38
+ }
39
+ /**
40
+ * One file as presented to the detectors, in preorder: the subtree of `nodes[i]` is `[i, i + size[i])`.
41
+ * Rewritten nodes carry the info (and id) of the node they stem from.
42
+ */
43
+ export interface CloneTree {
44
+ readonly file: string;
45
+ readonly nodes: readonly CloneNode[];
46
+ /** type, operator, and number of children of each node, which the detectors compare */
47
+ readonly shape: readonly string[];
48
+ readonly size: readonly number[];
49
+ /** the names function definitions (by preorder index) are bound to */
50
+ readonly names: ReadonlyMap<number, string>;
51
+ }
52
+ /** The target and value of an assignment as the operator database describes it, `undefined` for other nodes. */
53
+ export declare function assignment(n: Node): {
54
+ readonly target: Node;
55
+ readonly value: Node;
56
+ readonly super: boolean;
57
+ } | undefined;
58
+ /** The identifier or constant of a leaf, empty for other nodes. */
59
+ export declare function leafText(n: CloneNode): string;
60
+ /** The direct children of `n` as the perspective presents them, without comments (and the field of `x$f`). */
61
+ export declare function cloneChildren(n: CloneNode, canonical: boolean, inline?: InlinePlan): CloneNode[];
62
+ /**
63
+ * Presents the AST of one file in preorder, see {@link CloneTree}.
64
+ * @example
65
+ * ```ts
66
+ * const tree = cloneTree(index.files[0], index.perspective);
67
+ * ```
68
+ */
69
+ export declare function cloneTree({ file, root, inline }: CloneAst, perspective: ClonePerspective): CloneTree;
70
+ /**
71
+ * The token string of the subtree at `from` (the whole file for `from = 0`), one token per node.
72
+ * The token of a node includes its number of children, so the string determines the shape of the subtree.
73
+ */
74
+ export declare function tokenize(tree: CloneTree, mode: CloneTokenization, from?: number): string[];
75
+ export {};
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CloneTokenization = exports.ClonePerspective = void 0;
4
+ exports.assignment = assignment;
5
+ exports.leafText = leafText;
6
+ exports.cloneChildren = cloneChildren;
7
+ exports.cloneTree = cloneTree;
8
+ exports.tokenize = tokenize;
9
+ const r_symbol_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
10
+ const r_string_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-string");
11
+ const r_expression_list_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
12
+ const r_comment_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-comment");
13
+ const r_line_directive_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-line-directive");
14
+ const r_argument_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-argument");
15
+ const model_1 = require("../r-bridge/lang-4.x/ast/model/model");
16
+ const type_1 = require("../r-bridge/lang-4.x/ast/model/type");
17
+ const r_access_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-access");
18
+ const r_binary_op_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
19
+ const r_function_definition_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
20
+ const r_function_call_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
21
+ const identifier_1 = require("../dataflow/environments/identifier");
22
+ const base_operators_1 = require("../dataflow/environments/default-builtin-config/base-operators");
23
+ /**
24
+ * How the code is presented to the detectors:
25
+ * - `syntax`: as written
26
+ * - `canonical`: sugar rewritten to one core form (pipes become calls, `\(x)` is `function(x)`, `->` and `=` are `<-`,
27
+ * `(e)` and `{e}` are `e`, `x[["a"]]` is `x$a`, `T` is `TRUE`, a tail `return(e)` is `e`), keeping the ids of the source nodes
28
+ * - `dataflow`: `canonical` with single-use temporaries inlined along the dataflow graph (`t <- f(x); g(t)` is `g(f(x))`)
29
+ */
30
+ var ClonePerspective;
31
+ (function (ClonePerspective) {
32
+ ClonePerspective["Syntax"] = "syntax";
33
+ ClonePerspective["Canonical"] = "canonical";
34
+ ClonePerspective["Dataflow"] = "dataflow";
35
+ })(ClonePerspective || (exports.ClonePerspective = ClonePerspective = {}));
36
+ /**
37
+ * How {@link tokenize} presents the nodes: `normalized` abstracts identifiers and constants (type-2 clones),
38
+ * `exact` keeps them (type-1 clones).
39
+ */
40
+ var CloneTokenization;
41
+ (function (CloneTokenization) {
42
+ CloneTokenization["Normalized"] = "normalized";
43
+ CloneTokenization["Exact"] = "exact";
44
+ })(CloneTokenization || (exports.CloneTokenization = CloneTokenization = {}));
45
+ /** The target and value of an assignment as the operator database describes it, `undefined` for other nodes. */
46
+ function assignment(n) {
47
+ const facts = r_binary_op_1.RBinaryOp.is(n) ? r_binary_op_1.RBinaryOp.getOperatorInfo(n) : undefined;
48
+ if (!r_binary_op_1.RBinaryOp.is(n) || facts?.usedAs !== base_operators_1.OperatorUsedAs.Assignment) {
49
+ return undefined;
50
+ }
51
+ const right = facts.stringUsedInRAst === type_1.RawRType.RightAssign;
52
+ return { target: right ? n.rhs : n.lhs, value: right ? n.lhs : n.rhs, super: facts.capabilities.some(c => c.startsWith('super-')) };
53
+ }
54
+ /** The identifier or constant of a leaf, empty for other nodes. */
55
+ function leafText(n) {
56
+ if (n === r_function_call_1.EmptyArgument) {
57
+ return '';
58
+ }
59
+ switch (n.type) {
60
+ case type_1.RType.Symbol: return identifier_1.Identifier.toString(n.content);
61
+ case type_1.RType.Number:
62
+ case type_1.RType.String:
63
+ case type_1.RType.Logical: return n.lexeme;
64
+ default: return '';
65
+ }
66
+ }
67
+ function withoutTailReturn(body) {
68
+ const last = r_expression_list_1.RExpressionList.is(body) ? body.children.at(-1) : undefined;
69
+ const arg = r_function_call_1.RFunctionCall.isNamed(last, 'return') && last.arguments.length === 1 ? last.arguments[0] : r_function_call_1.EmptyArgument;
70
+ return r_expression_list_1.RExpressionList.is(body) && arg !== r_function_call_1.EmptyArgument && arg.name === undefined && arg.value ? { ...body, children: [...body.children.slice(0, -1), arg.value] } : body;
71
+ }
72
+ /**
73
+ * Rewrites `x |> f(y)` and `x %>% f(y)` to `f(x, y)` and `x %>% f` to `f(x)`; a direct `placeholder` argument
74
+ * receives `x` instead. Returns `undefined` if the rhs is no call (or symbol for magrittr).
75
+ */
76
+ function pipe(n, lhs, rhs, placeholder) {
77
+ const x = r_argument_1.RArgument.is(lhs) && lhs.value ? lhs.value : lhs;
78
+ const arg = { type: type_1.RType.Argument, name: undefined, value: x, lexeme: '', location: n.location, info: x.info };
79
+ if (r_symbol_1.RSymbol.is(rhs) && placeholder === '.') {
80
+ return { type: type_1.RType.FunctionCall, named: true, functionName: rhs, arguments: [arg], lexeme: n.lexeme, location: n.location, info: n.info };
81
+ }
82
+ else if (!r_function_call_1.RFunctionCall.is(rhs)) {
83
+ return undefined;
84
+ }
85
+ const args = rhs.arguments.map(a => a !== r_function_call_1.EmptyArgument && r_symbol_1.RSymbol.is(a.value) && a.value.content === placeholder ? { ...a, value: x } : a);
86
+ return { ...rhs, arguments: args.some((a, i) => a !== rhs.arguments[i]) ? args : [arg, ...args] };
87
+ }
88
+ /** The node `n` as the perspective presents it, see {@link ClonePerspective}; its children are presented by {@link cloneChildren}. */
89
+ function present(n, canonical, inline) {
90
+ const value = inline?.replace.get(n.info.id);
91
+ if (value !== undefined) {
92
+ return present(value, canonical, inline);
93
+ }
94
+ else if (!canonical) {
95
+ return n;
96
+ }
97
+ switch (n.type) {
98
+ case type_1.RType.ExpressionList: {
99
+ const children = cloneChildren(n, canonical, inline);
100
+ return children.length === 1 ? children[0] : n;
101
+ }
102
+ case type_1.RType.FunctionDefinition:
103
+ return { ...n, body: withoutTailReturn(n.body) };
104
+ case type_1.RType.FunctionCall: {
105
+ const [lhs, rhs] = n.arguments;
106
+ return r_function_call_1.RFunctionCall.isNamed(n, '%>%') && n.arguments.length === 2 && lhs !== r_function_call_1.EmptyArgument && rhs !== r_function_call_1.EmptyArgument && rhs.value ? pipe(n, lhs, rhs.value, '.') ?? n : n;
107
+ }
108
+ case type_1.RType.Pipe:
109
+ return pipe(n, n.lhs, n.rhs, '_') ?? n;
110
+ case type_1.RType.Access: {
111
+ const a = n.access[0];
112
+ const field = a !== r_function_call_1.EmptyArgument && a.name === undefined && (r_access_1.RAccess.isNamed(n) || n.operator === '[[' && n.access.length === 1) ? a.value : undefined;
113
+ if (a === r_function_call_1.EmptyArgument || !r_string_1.RString.is(field)) {
114
+ return n;
115
+ }
116
+ const symbol = { type: type_1.RType.Symbol, content: field.content.str, lexeme: field.content.str, location: field.location, info: field.info };
117
+ return { ...n, operator: n.operator === '@' ? '@' : '$', access: [{ ...a, name: undefined, value: symbol }] };
118
+ }
119
+ case type_1.RType.BinaryOp: {
120
+ const a = assignment(n);
121
+ return a ? { ...n, operator: a.super ? '<<-' : '<-', lhs: a.target, rhs: a.value } : n;
122
+ }
123
+ case type_1.RType.Symbol: {
124
+ const text = leafText(n);
125
+ return text === 'T' || text === 'F' ? { type: type_1.RType.Logical, content: text === 'T', lexeme: text === 'T' ? 'TRUE' : 'FALSE', location: n.location, info: n.info } : n;
126
+ }
127
+ }
128
+ return n;
129
+ }
130
+ /** The direct children of `n` as the perspective presents them, without comments (and the field of `x$f`). */
131
+ function cloneChildren(n, canonical, inline) {
132
+ if (n === r_function_call_1.EmptyArgument) {
133
+ return [];
134
+ }
135
+ const children = r_expression_list_1.RExpressionList.is(n) ? n.children.filter(c => !inline?.drop.has(c.info.id)) : r_access_1.RAccess.is(n) ? [n.accessed, ...n.access] : model_1.RNode.directChildren(n);
136
+ return children.filter(c => c === r_function_call_1.EmptyArgument || !r_comment_1.RComment.is(c) && !r_line_directive_1.RLineDirective.is(c)).map(c => c === r_function_call_1.EmptyArgument ? c : present(c, canonical, inline));
137
+ }
138
+ /**
139
+ * Presents the AST of one file in preorder, see {@link CloneTree}.
140
+ * @example
141
+ * ```ts
142
+ * const tree = cloneTree(index.files[0], index.perspective);
143
+ * ```
144
+ */
145
+ function cloneTree({ file, root, inline }, perspective) {
146
+ const canonical = perspective !== ClonePerspective.Syntax;
147
+ const nodes = [], shape = [], size = [], names = new Map();
148
+ const visit = (n, name) => {
149
+ const i = nodes.length;
150
+ const children = cloneChildren(n, canonical, inline);
151
+ const kind = n === r_function_call_1.EmptyArgument ? n : `${n.type}${'operator' in n ? String(n.operator) : ''}${r_expression_list_1.RExpressionList.is(n) ? n.grouping?.[0].lexeme ?? '' : ''}`;
152
+ nodes.push(n);
153
+ shape.push(`${kind}/${children.length}`);
154
+ size.push(1);
155
+ if (name !== undefined && n !== r_function_call_1.EmptyArgument && r_function_definition_1.RFunctionDefinition.is(n)) {
156
+ names.set(i, name);
157
+ }
158
+ const a = n === r_function_call_1.EmptyArgument ? undefined : assignment(n);
159
+ const bound = a && r_symbol_1.RSymbol.is(a.target) && r_function_definition_1.RFunctionDefinition.is(a.value) ? leafText(a.target) : undefined;
160
+ children.forEach(c => visit(c, bound));
161
+ size[i] = nodes.length - i;
162
+ };
163
+ visit(root, undefined);
164
+ return { file, nodes, shape, size, names };
165
+ }
166
+ /**
167
+ * The token string of the subtree at `from` (the whole file for `from = 0`), one token per node.
168
+ * The token of a node includes its number of children, so the string determines the shape of the subtree.
169
+ */
170
+ function tokenize(tree, mode, from = 0) {
171
+ const tokens = tree.shape.slice(from, from + tree.size[from]);
172
+ return mode === CloneTokenization.Exact ? tokens.map((t, k) => `${t} ${leafText(tree.nodes[from + k])}`) : tokens;
173
+ }
174
+ //# sourceMappingURL=clone-ast.js.map
@@ -0,0 +1,11 @@
1
+ import type { DataflowGraph } from '../dataflow/graph/graph';
2
+ import type { REnvironmentInformation } from '../dataflow/environments/environment';
3
+ import type { AstIdMap, RNodeWithParent } from '../r-bridge/lang-4.x/ast/model/processing/decorate';
4
+ import { type InlinePlan } from './clone-ast';
5
+ /**
6
+ * Plans the `dataflow` perspective: a local assignment `x <- e` (no function) whose definition is read exactly once,
7
+ * by a read seeing no other definition, evaluated exactly once in a later statement of the same block, is dropped and
8
+ * `e` takes the place of the read, if nothing in between can change `e` (an impure `e` must be next to its use, a
9
+ * pure one must not have its variables reassigned in between).
10
+ */
11
+ export declare function planInlining(root: RNodeWithParent, graph: DataflowGraph, idMap: AstIdMap, environment?: REnvironmentInformation): InlinePlan;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.planInlining = planInlining;
4
+ const type_1 = require("../r-bridge/lang-4.x/ast/model/type");
5
+ const r_for_loop_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-for-loop");
6
+ const r_if_then_else_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-if-then-else");
7
+ const model_1 = require("../r-bridge/lang-4.x/ast/model/model");
8
+ const identifier_1 = require("../dataflow/environments/identifier");
9
+ const function_semantics_1 = require("../dataflow/fn/function-semantics");
10
+ const query_fn_props_1 = require("../dataflow/environments/query-fn-props");
11
+ const built_in_props_1 = require("../dataflow/environments/built-in-props");
12
+ const r_symbol_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-symbol");
13
+ const r_function_definition_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
14
+ const r_expression_list_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
15
+ const edge_1 = require("../dataflow/graph/edge");
16
+ const clone_ast_1 = require("./clone-ast");
17
+ const vertex_1 = require("../dataflow/graph/vertex");
18
+ const built_in_proc_name_1 = require("../dataflow/environments/built-in-proc-name");
19
+ const CallTypes = new Set([type_1.RType.FunctionCall, type_1.RType.BinaryOp, type_1.RType.UnaryOp, type_1.RType.Access]);
20
+ /** the single read of the definition `def`, if there is exactly one and it reads nothing else */
21
+ function singleUse(graph, def) {
22
+ const reads = (edges) => [...edges].filter(([, e]) => edge_1.DfEdge.includesType(e, edge_1.EdgeType.Reads)).map(([id]) => id);
23
+ const [use, ...more] = reads(graph.edgesTo(def));
24
+ return use !== undefined && more.length === 0 && reads(graph.edgesFrom(use)).every(t => t === def) ? use : undefined;
25
+ }
26
+ /** the statement of `list` containing `node` if it evaluates `node` exactly once: not within a closure, loop, or branch */
27
+ function statementWithin(node, list, idMap) {
28
+ let current = node;
29
+ while (current.info.parent !== list) {
30
+ const parent = model_1.RNode.directParent(current, idMap);
31
+ if (parent === undefined || r_function_definition_1.RFunctionDefinition.is(parent) || (model_1.RLoopConstructs.is(parent) && !(r_for_loop_1.RForLoop.is(parent) && current === parent.vector))
32
+ || (r_if_then_else_1.RIfThenElse.is(parent) && current !== parent.condition)) {
33
+ return undefined;
34
+ }
35
+ current = parent;
36
+ }
37
+ return current;
38
+ }
39
+ /** the names assigned (or read, with `assigned = false`) in `nodes`, and whether all calls in them are pure */
40
+ function namesOf(nodes, assigned, graph, environment) {
41
+ const names = new Set();
42
+ let pure = true;
43
+ model_1.RNode.visitAst(nodes, n => {
44
+ const symbol = assigned ? (0, clone_ast_1.assignment)(n)?.target : n;
45
+ if (r_symbol_1.RSymbol.is(symbol)) {
46
+ names.add(identifier_1.Identifier.getName(symbol.content));
47
+ }
48
+ if (!assigned && CallTypes.has(n.type)) {
49
+ pure &&= function_semantics_1.FunctionSemantics.call.props.hasAny((0, query_fn_props_1.callFnProps)(n.info.id, graph, environment), built_in_props_1.CallProp.Pure);
50
+ }
51
+ });
52
+ return { names, pure };
53
+ }
54
+ /**
55
+ * Plans the `dataflow` perspective: a local assignment `x <- e` (no function) whose definition is read exactly once,
56
+ * by a read seeing no other definition, evaluated exactly once in a later statement of the same block, is dropped and
57
+ * `e` takes the place of the read, if nothing in between can change `e` (an impure `e` must be next to its use, a
58
+ * pure one must not have its variables reassigned in between).
59
+ */
60
+ function planInlining(root, graph, idMap, environment) {
61
+ const replace = new Map();
62
+ const drop = new Set();
63
+ model_1.RNode.visitAst(root, node => {
64
+ const assign = (0, clone_ast_1.assignment)(node);
65
+ const list = model_1.RNode.directParent(node, idMap);
66
+ if (!assign || assign.super || !r_expression_list_1.RExpressionList.is(list) || !vertex_1.DfgVertex.hasOrigin(graph.getVertex(node.info.id), built_in_proc_name_1.BuiltInProcName.Assignment)) {
67
+ return;
68
+ }
69
+ const { target, value } = assign;
70
+ const useId = r_symbol_1.RSymbol.is(target) && !r_function_definition_1.RFunctionDefinition.is(value) ? singleUse(graph, target.info.id) : undefined;
71
+ const use = useId === undefined ? undefined : idMap.get(useId);
72
+ const statement = r_symbol_1.RSymbol.is(use) ? statementWithin(use, list.info.id, idMap) : undefined;
73
+ const from = list.children.indexOf(node), to = statement ? list.children.indexOf(statement) : -1;
74
+ const between = list.children.slice(from + 1, to);
75
+ const reads = between.length > 0 ? namesOf(value, false, graph, environment) : undefined;
76
+ if (use && to > from && (!reads || reads.pure && ![...namesOf(between, true, graph, environment).names].some(n => reads.names.has(n)))) {
77
+ replace.set(use.info.id, value);
78
+ drop.add(node.info.id);
79
+ }
80
+ });
81
+ return { replace, drop };
82
+ }
83
+ //# sourceMappingURL=clone-dataflow.js.map
@@ -0,0 +1,116 @@
1
+ import type { MergeableRecord } from '../util/objects';
2
+ import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
3
+ import { SourceRange, type SourceLocation } from '../util/range';
4
+ import { CloneTokenization } from './clone-ast';
5
+ import type { CloneIndex } from './clone-index';
6
+ /**
7
+ * The supported detectors:
8
+ * - `baxter`: AST subtree hashing and comparison (Baxter et al., ICSM 1998)
9
+ * - `gst`: Greedy String Tiling over token strings, as in JPlag (Prechelt et al., 2002)
10
+ * - `winnowing`: k-gram fingerprinting as in MOSS (Schleimer et al., SIGMOD 2003)
11
+ */
12
+ export declare enum CloneAlgorithm {
13
+ Baxter = "baxter",
14
+ Gst = "gst",
15
+ Winnowing = "winnowing"
16
+ }
17
+ /** Compare functions with each other, or whole files. */
18
+ export declare enum CloneUnit {
19
+ Function = "function",
20
+ File = "file"
21
+ }
22
+ /** Which pairs may be reported: any two fragments, or only fragments in different files. */
23
+ export declare enum CloneScope {
24
+ All = "all",
25
+ CrossFile = "cross-file"
26
+ }
27
+ interface TokenConfig extends MergeableRecord {
28
+ readonly tokens: CloneTokenization;
29
+ /** the similarity a pair needs */
30
+ readonly threshold: number;
31
+ readonly unit: CloneUnit;
32
+ }
33
+ export interface GstConfig extends TokenConfig {
34
+ /** JPlag's `minimumTokenMatch` */
35
+ readonly minimumMatchLength: number;
36
+ }
37
+ export interface WinnowingConfig extends TokenConfig {
38
+ /** the noise threshold: the k-gram length */
39
+ readonly k: number;
40
+ /** the guarantee threshold: every shared run of at least `t` tokens is found */
41
+ readonly t: number;
42
+ /** fingerprints found in more units than this are ignored (MOSS's `-m`) */
43
+ readonly maxDocumentFrequency: number;
44
+ }
45
+ export interface BaxterDetectionConfig extends MergeableRecord {
46
+ readonly massThreshold: number;
47
+ readonly similarityThreshold: number;
48
+ }
49
+ export interface CloneDetectionConfig extends MergeableRecord {
50
+ readonly algorithms: readonly CloneAlgorithm[];
51
+ readonly scope: CloneScope;
52
+ /** report at most this many pairs per algorithm (the most similar ones), `0` for no limit */
53
+ readonly maxPairs: number;
54
+ readonly gst: GstConfig;
55
+ readonly winnowing: WinnowingConfig;
56
+ readonly baxter: BaxterDetectionConfig;
57
+ }
58
+ /**
59
+ * The configuration {@link detectClones} falls back to: `gst` on functions. The thresholds of the algorithms are not comparable.
60
+ * @example
61
+ * ```ts
62
+ * const config = { ...DefaultCloneDetectionConfig, gst: { ...DefaultCloneDetectionConfig.gst, threshold: 0.9 } };
63
+ * ```
64
+ */
65
+ export declare const DefaultCloneDetectionConfig: CloneDetectionConfig;
66
+ /** One side of a clone. */
67
+ export interface CloneFragment {
68
+ readonly file: string;
69
+ readonly id: NodeId;
70
+ readonly loc: SourceLocation;
71
+ /** the function name, if the fragment is a named function */
72
+ readonly name?: string;
73
+ /** set for fragments of the `against` index, whose ids belong to another analysis */
74
+ readonly external?: true;
75
+ }
76
+ /** Two fragments an algorithm found to be clones. */
77
+ export interface ClonePair {
78
+ readonly algorithm: CloneAlgorithm;
79
+ /** the symmetric similarity in [0, 1] */
80
+ readonly similarity: number;
81
+ /** how much of `a` is found in `b` and vice versa */
82
+ readonly containment?: readonly [aInB: number, bInA: number];
83
+ readonly a: CloneFragment;
84
+ readonly b: CloneFragment;
85
+ /** the matched regions of the token-based algorithms */
86
+ readonly matches?: readonly {
87
+ readonly a: SourceRange;
88
+ readonly b: SourceRange;
89
+ }[];
90
+ }
91
+ export interface CloneDetectionStats extends MergeableRecord {
92
+ readonly files: number;
93
+ /** compared units (subtrees for `baxter`) per algorithm */
94
+ readonly units: Partial<Record<CloneAlgorithm, number>>;
95
+ /** pairs that passed the lossless filters and were compared in full */
96
+ readonly comparisons: Partial<Record<CloneAlgorithm, number>>;
97
+ readonly timing: Partial<Record<CloneAlgorithm, number>>;
98
+ }
99
+ export interface CloneDetectionResult {
100
+ readonly pairs: readonly ClonePair[];
101
+ readonly stats: CloneDetectionStats;
102
+ }
103
+ /**
104
+ * Runs the configured algorithms on the presented trees ({@link cloneTree}) of the index. With `against`, only pairs
105
+ * of a fragment of `index` and one of `against` (whose fragments are marked `external`) are reported.
106
+ * Each algorithm reports at most `maxPairs` pairs.
107
+ * @param index - the code to check, built with {@link CloneIndex.build}
108
+ * @param config - see {@link DefaultCloneDetectionConfig}
109
+ * @param against - an index of the same perspective to search `index` in, e.g., from {@link CloneIndex.deserialize}
110
+ * @example
111
+ * ```ts
112
+ * const { pairs } = detectClones(await CloneIndex.build(analyzer, { perspective: ClonePerspective.Canonical }), DefaultCloneDetectionConfig);
113
+ * ```
114
+ */
115
+ export declare function detectClones(index: CloneIndex, config: CloneDetectionConfig, against?: CloneIndex): CloneDetectionResult;
116
+ export {};
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultCloneDetectionConfig = exports.CloneScope = exports.CloneUnit = exports.CloneAlgorithm = void 0;
4
+ exports.detectClones = detectClones;
5
+ const arrays_1 = require("../util/collections/arrays");
6
+ const defaultmap_1 = require("../util/collections/defaultmap");
7
+ const range_1 = require("../util/range");
8
+ const clone_ast_1 = require("./clone-ast");
9
+ const model_1 = require("../r-bridge/lang-4.x/ast/model/model");
10
+ const r_function_call_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
11
+ const r_function_definition_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
12
+ const greedy_string_tiling_1 = require("./algorithms/greedy-string-tiling");
13
+ const winnowing_1 = require("./algorithms/winnowing");
14
+ const baxter_ast_1 = require("./algorithms/baxter-ast");
15
+ /**
16
+ * The supported detectors:
17
+ * - `baxter`: AST subtree hashing and comparison (Baxter et al., ICSM 1998)
18
+ * - `gst`: Greedy String Tiling over token strings, as in JPlag (Prechelt et al., 2002)
19
+ * - `winnowing`: k-gram fingerprinting as in MOSS (Schleimer et al., SIGMOD 2003)
20
+ */
21
+ var CloneAlgorithm;
22
+ (function (CloneAlgorithm) {
23
+ CloneAlgorithm["Baxter"] = "baxter";
24
+ CloneAlgorithm["Gst"] = "gst";
25
+ CloneAlgorithm["Winnowing"] = "winnowing";
26
+ })(CloneAlgorithm || (exports.CloneAlgorithm = CloneAlgorithm = {}));
27
+ /** Compare functions with each other, or whole files. */
28
+ var CloneUnit;
29
+ (function (CloneUnit) {
30
+ CloneUnit["Function"] = "function";
31
+ CloneUnit["File"] = "file";
32
+ })(CloneUnit || (exports.CloneUnit = CloneUnit = {}));
33
+ /** Which pairs may be reported: any two fragments, or only fragments in different files. */
34
+ var CloneScope;
35
+ (function (CloneScope) {
36
+ CloneScope["All"] = "all";
37
+ CloneScope["CrossFile"] = "cross-file";
38
+ })(CloneScope || (exports.CloneScope = CloneScope = {}));
39
+ /**
40
+ * The configuration {@link detectClones} falls back to: `gst` on functions. The thresholds of the algorithms are not comparable.
41
+ * @example
42
+ * ```ts
43
+ * const config = { ...DefaultCloneDetectionConfig, gst: { ...DefaultCloneDetectionConfig.gst, threshold: 0.9 } };
44
+ * ```
45
+ */
46
+ exports.DefaultCloneDetectionConfig = {
47
+ algorithms: [CloneAlgorithm.Gst],
48
+ scope: CloneScope.All,
49
+ maxPairs: 1000,
50
+ gst: { tokens: clone_ast_1.CloneTokenization.Normalized, minimumMatchLength: 8, threshold: 0.8, unit: CloneUnit.Function },
51
+ winnowing: { tokens: clone_ast_1.CloneTokenization.Normalized, k: 5, t: 8, threshold: 0.6, maxDocumentFrequency: 50, unit: CloneUnit.Function },
52
+ baxter: { massThreshold: 30, similarityThreshold: 0.9 }
53
+ };
54
+ function units(c, unit) {
55
+ return c.trees.flatMap((tree, file) => unit === CloneUnit.File ? [{ file, node: 0 }] : tree.nodes.flatMap((n, node) => n !== r_function_call_1.EmptyArgument && r_function_definition_1.RFunctionDefinition.is(n) ? [{ file, node }] : []));
56
+ }
57
+ /** whether the pair may be reported: scope, sides, and neither fragment within the other */
58
+ function admissible(c, a, b) {
59
+ const size = c.trees[a.file].size;
60
+ return c.own < c.trees.length ? (a.file < c.own) !== (b.file < c.own)
61
+ : a.file !== b.file || c.config.scope !== CloneScope.CrossFile && (a.node + size[a.node] <= b.node || b.node + size[b.node] <= a.node);
62
+ }
63
+ function fragment(c, { file, node }) {
64
+ const tree = c.trees[file], n = tree.nodes[node], name = tree.names.get(node);
65
+ const [sl, sc, el, ec] = model_1.RNode.span(n) ?? range_1.SourceRange.invalid();
66
+ return { file: tree.file, id: n.info.id, loc: [sl, sc, el, ec, tree.file], ...(name ? { name } : {}), ...(file >= c.own ? { external: true } : {}) };
67
+ }
68
+ /** the source covered by the tokens of the nodes `[from, to)` */
69
+ function range(tree, from, to) {
70
+ const rs = tree.nodes.slice(from, to).map(n => n === r_function_call_1.EmptyArgument ? undefined : n.location);
71
+ return rs.some(r => r !== undefined) ? range_1.SourceRange.merge(rs) : range_1.SourceRange.invalid();
72
+ }
73
+ function pair(c, algorithm, a, b, similarity, containment, runs) {
74
+ const matches = runs.map(([i, j, la, lb]) => ({ a: range(c.trees[a.file], a.node + i, a.node + i + la), b: range(c.trees[b.file], b.node + j, b.node + j + lb) }));
75
+ return { algorithm, similarity, containment, a: fragment(c, a), b: fragment(c, b), matches };
76
+ }
77
+ /**
78
+ * The units with their token strings, tokens numbered across all trees, and a function calling `visit(i, j)`, `i < j`,
79
+ * once per admissible pair of units sharing a key, unless the lengths alone rule out the threshold
80
+ * (the similarity is at most `2 min(li, lj) / (li + lj)`).
81
+ */
82
+ function tokenUnits(c, { unit, tokens: mode }) {
83
+ const us = units(c, unit);
84
+ const tokens = us.map(u => (0, clone_ast_1.tokenize)(c.trees[u.file], mode, u.node).map(t => c.tokens.get(t)));
85
+ c.stats.units = us.length;
86
+ const candidates = (keys, lengths, threshold, visit) => {
87
+ const postings = new defaultmap_1.DefaultMap(() => new Set());
88
+ keys.forEach((ks, u) => {
89
+ for (const k of ks) {
90
+ postings.get(k).add(u);
91
+ }
92
+ });
93
+ keys.forEach((ks, i) => {
94
+ const js = new Set();
95
+ for (const k of ks) {
96
+ postings.get(k).forEach(j => j > i && js.add(j));
97
+ }
98
+ for (const j of js) {
99
+ if (2 * Math.min(lengths[i], lengths[j]) / (lengths[i] + lengths[j]) >= threshold && admissible(c, us[i], us[j])) {
100
+ c.stats.comparisons++;
101
+ visit(i, j);
102
+ }
103
+ }
104
+ });
105
+ };
106
+ return { us, tokens, candidates };
107
+ }
108
+ function detectGst(c) {
109
+ const cfg = c.config.gst;
110
+ const { us, tokens, candidates } = tokenUnits(c, cfg);
111
+ const pairs = [];
112
+ // a tile of at least `minimumMatchLength` tokens shares a k-gram
113
+ candidates(tokens.map(t => (0, winnowing_1.kgramHashes)(t, cfg.minimumMatchLength)), tokens.map(t => t.length), cfg.threshold, (i, j) => {
114
+ const [l, r] = tokens[j].length < tokens[i].length ? [j, i] : [i, j];
115
+ const tiles = (0, greedy_string_tiling_1.greedyStringTiling)(tokens[l], tokens[r], cfg.minimumMatchLength);
116
+ const matched = tiles.reduce((n, t) => n + t.length, 0);
117
+ const similarity = 2 * matched / (tokens[l].length + tokens[r].length);
118
+ if (similarity >= cfg.threshold) {
119
+ pairs.push(pair(c, CloneAlgorithm.Gst, us[l], us[r], similarity, [matched / tokens[l].length, matched / tokens[r].length], tiles.map(t => [t.left, t.right, t.length, t.length])));
120
+ }
121
+ });
122
+ return pairs;
123
+ }
124
+ function detectWinnowing(c) {
125
+ const cfg = c.config.winnowing;
126
+ const { us, tokens, candidates } = tokenUnits(c, cfg);
127
+ const all = tokens.map(t => (0, winnowing_1.fingerprints)(t, cfg.k, cfg.t));
128
+ const frequency = new Map();
129
+ all.forEach(ps => new Set(ps.map(p => p.hash)).forEach(h => frequency.set(h, (frequency.get(h) ?? 0) + 1)));
130
+ const prints = all.map(ps => ps.filter(p => (frequency.get(p.hash) ?? 0) <= cfg.maxDocumentFrequency));
131
+ const keys = prints.map(ps => (0, arrays_1.uniqueArray)(ps.map(p => p.hash)));
132
+ const pairs = [];
133
+ candidates(keys, keys.map(k => k.length), cfg.threshold, (i, j) => {
134
+ const inJ = new Map();
135
+ prints[j].forEach(p => inJ.has(p.hash) || inJ.set(p.hash, p.position));
136
+ const shared = keys[i].filter(h => inJ.has(h)).length;
137
+ const similarity = 2 * shared / (keys[i].length + keys[j].length);
138
+ if (similarity < cfg.threshold) {
139
+ return;
140
+ }
141
+ // MOSS-style passages: the k-grams of shared fingerprints, merged where they touch on both sides
142
+ const runs = [];
143
+ for (const p of prints[i]) {
144
+ const q = inJ.get(p.hash), last = runs.at(-1);
145
+ if (q !== undefined && last && p.position <= last[0] + last[2] && q >= last[1] && q <= last[1] + last[3]) {
146
+ last[2] = Math.max(last[2], p.position + cfg.k - last[0]);
147
+ last[3] = Math.max(last[3], q + cfg.k - last[1]);
148
+ }
149
+ else if (q !== undefined) {
150
+ runs.push([p.position, q, cfg.k, cfg.k]);
151
+ }
152
+ }
153
+ pairs.push(pair(c, CloneAlgorithm.Winnowing, us[i], us[j], similarity, [shared / keys[i].length, shared / keys[j].length], runs));
154
+ });
155
+ return pairs;
156
+ }
157
+ function detectBaxter(c) {
158
+ const found = (0, baxter_ast_1.baxterClones)(c.trees, c.config.baxter);
159
+ c.stats.units = found.subtrees;
160
+ c.stats.comparisons = found.comparisons;
161
+ return found.pairs.filter(p => admissible(c, p.a, p.b)).map(p => ({ algorithm: CloneAlgorithm.Baxter, similarity: p.similarity, a: fragment(c, p.a), b: fragment(c, p.b) }));
162
+ }
163
+ const Detectors = {
164
+ [CloneAlgorithm.Baxter]: detectBaxter,
165
+ [CloneAlgorithm.Gst]: detectGst,
166
+ [CloneAlgorithm.Winnowing]: detectWinnowing
167
+ };
168
+ /**
169
+ * Runs the configured algorithms on the presented trees ({@link cloneTree}) of the index. With `against`, only pairs
170
+ * of a fragment of `index` and one of `against` (whose fragments are marked `external`) are reported.
171
+ * Each algorithm reports at most `maxPairs` pairs.
172
+ * @param index - the code to check, built with {@link CloneIndex.build}
173
+ * @param config - see {@link DefaultCloneDetectionConfig}
174
+ * @param against - an index of the same perspective to search `index` in, e.g., from {@link CloneIndex.deserialize}
175
+ * @example
176
+ * ```ts
177
+ * const { pairs } = detectClones(await CloneIndex.build(analyzer, { perspective: ClonePerspective.Canonical }), DefaultCloneDetectionConfig);
178
+ * ```
179
+ */
180
+ function detectClones(index, config, against) {
181
+ const trees = [index, ...against ? [against] : []].flatMap(i => i.files.map(f => (0, clone_ast_1.cloneTree)(f, i.perspective)));
182
+ const tokens = new defaultmap_1.DefaultMap(() => tokens.size());
183
+ const pairs = [];
184
+ const stats = { files: trees.length, units: {}, comparisons: {}, timing: {} };
185
+ for (const algorithm of new Set(config.algorithms)) {
186
+ const detector = Detectors[algorithm];
187
+ if (detector === undefined) {
188
+ throw new Error(`unknown clone detection algorithm ${String(algorithm)}, use one of ${Object.values(CloneAlgorithm).join(', ')}`);
189
+ }
190
+ const start = performance.now();
191
+ const c = { trees, own: against ? index.files.length : trees.length, config, stats: { units: 0, comparisons: 0 }, tokens };
192
+ const found = detector(c);
193
+ pairs.push(...config.maxPairs > 0 && found.length > config.maxPairs ? found.sort((x, y) => y.similarity - x.similarity).slice(0, config.maxPairs) : found);
194
+ stats.units[algorithm] = c.stats.units;
195
+ stats.comparisons[algorithm] = c.stats.comparisons;
196
+ stats.timing[algorithm] = performance.now() - start;
197
+ }
198
+ return { pairs, stats };
199
+ }
200
+ //# sourceMappingURL=clone-detector.js.map