@eagleoutice/flowr 2.11.0 → 2.12.0

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 (256) hide show
  1. package/README.md +190 -260
  2. package/abstract-interpretation/data-frame/mappers/arguments.js +7 -1
  3. package/abstract-interpretation/domains/set-range-domain.js +1 -1
  4. package/abstract-interpretation/domains/set-upper-bound-domain.js +6 -2
  5. package/benchmark/slicer.d.ts +1 -1
  6. package/benchmark/slicer.js +3 -1
  7. package/benchmark/summarizer/second-phase/graph.js +5 -0
  8. package/cli/common/options.d.ts +8 -0
  9. package/cli/common/options.js +2 -0
  10. package/cli/common/scripts-info.d.ts +8 -0
  11. package/cli/flowr.js +1 -1
  12. package/cli/repl/commands/repl-commands.d.ts +1 -0
  13. package/cli/repl/commands/repl-commands.js +69 -17
  14. package/cli/repl/commands/repl-dataflow.js +48 -4
  15. package/cli/repl/commands/repl-main.d.ts +2 -0
  16. package/cli/repl/commands/repl-main.js +5 -0
  17. package/cli/repl/commands/repl-query.d.ts +4 -1
  18. package/cli/repl/commands/repl-query.js +72 -22
  19. package/cli/repl/commands/repl-signature.d.ts +7 -0
  20. package/cli/repl/commands/repl-signature.js +119 -0
  21. package/cli/repl/core.d.ts +8 -1
  22. package/cli/repl/core.js +46 -6
  23. package/cli/repl/ghost-hint.d.ts +37 -0
  24. package/cli/repl/ghost-hint.js +72 -0
  25. package/cli/repl/parser/slice-query-parser.d.ts +11 -1
  26. package/cli/repl/parser/slice-query-parser.js +45 -16
  27. package/cli/repl/print-version.d.ts +2 -4
  28. package/cli/repl/print-version.js +41 -23
  29. package/cli/repl/server/connection.js +19 -17
  30. package/cli/slicer-app.d.ts +2 -0
  31. package/cli/slicer-app.js +3 -3
  32. package/cli/wiki.d.ts +2 -2
  33. package/cli/wiki.js +2 -2
  34. package/config.d.ts +70 -13
  35. package/config.js +65 -7
  36. package/control-flow/cfg-dead-code.js +0 -1
  37. package/control-flow/control-flow-graph.js +6 -6
  38. package/control-flow/diff-cfg.js +2 -2
  39. package/control-flow/semantic-cfg-guided-visitor.js +2 -0
  40. package/core/print/slice-diff-ansi.js +8 -8
  41. package/core/steps/all/core/20-dataflow.d.ts +2 -2
  42. package/core/steps/all/static-slicing/00-slice.d.ts +5 -0
  43. package/core/steps/all/static-slicing/00-slice.js +1 -1
  44. package/core/steps/all/static-slicing/10-reconstruct.d.ts +7 -0
  45. package/core/steps/all/static-slicing/10-reconstruct.js +6 -2
  46. package/core/steps/pipeline/default-pipelines.d.ts +20 -16
  47. package/data/r-base-packages.generated.d.ts +44 -0
  48. package/data/r-base-packages.generated.js +32 -0
  49. package/data/r-base-primitives.generated.d.ts +1 -0
  50. package/data/r-base-primitives.generated.js +15 -0
  51. package/data/sigdb/sigdb.remote.json +112 -0
  52. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  53. package/dataflow/environments/built-in-proc-name.js +4 -0
  54. package/dataflow/environments/built-in.d.ts +14 -4
  55. package/dataflow/environments/built-in.js +13 -2
  56. package/dataflow/environments/data-masking-functions.d.ts +12 -0
  57. package/dataflow/environments/data-masking-functions.js +46 -0
  58. package/dataflow/environments/default-builtin-config.d.ts +72 -19
  59. package/dataflow/environments/default-builtin-config.js +48 -14
  60. package/dataflow/environments/diff.js +1 -1
  61. package/dataflow/environments/environment.js +1 -2
  62. package/dataflow/environments/identifier.d.ts +11 -4
  63. package/dataflow/environments/identifier.js +28 -10
  64. package/dataflow/environments/resolve-by-name.js +16 -2
  65. package/dataflow/extractor.js +6 -3
  66. package/dataflow/graph/call-graph.d.ts +2 -2
  67. package/dataflow/graph/df-helper.d.ts +4 -4
  68. package/dataflow/graph/diff-dataflow-graph.js +2 -2
  69. package/dataflow/graph/edge.d.ts +3 -3
  70. package/dataflow/graph/edge.js +3 -3
  71. package/dataflow/graph/graph-helper.d.ts +2 -2
  72. package/dataflow/internal/linker.js +1 -1
  73. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +7 -0
  74. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +20 -0
  75. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +1 -0
  76. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +2 -49
  77. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +6 -1
  78. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +7 -1
  79. package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +19 -0
  80. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +111 -6
  81. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +13 -0
  82. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +2 -3
  83. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +9 -0
  84. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +19 -0
  85. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +12 -4
  86. package/dataflow/internal/process/functions/call/common.js +8 -1
  87. package/dataflow/internal/process/functions/call/default-call-handling.js +6 -0
  88. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +17 -0
  89. package/dataflow/internal/process/functions/call/known-call-handling.js +32 -0
  90. package/dataflow/internal/process/functions/call/named-call-handling.js +29 -7
  91. package/dataflow/internal/process/functions/process-argument.js +12 -1
  92. package/dataflow/internal/process/process-named-call.d.ts +18 -1
  93. package/dataflow/internal/process/process-named-call.js +94 -0
  94. package/dataflow/processor.d.ts +18 -0
  95. package/documentation/data/faq/faqs.js +5 -1
  96. package/documentation/doc-capabilities.js +1 -1
  97. package/documentation/doc-util/doc-cli-option.d.ts +10 -0
  98. package/documentation/doc-util/doc-cli-option.js +23 -0
  99. package/documentation/doc-util/doc-dfg.js +2 -1
  100. package/documentation/doc-util/doc-query.d.ts +9 -3
  101. package/documentation/doc-util/doc-query.js +9 -4
  102. package/documentation/wiki-dataflow-graph.js +8 -5
  103. package/documentation/wiki-interface.js +3 -2
  104. package/documentation/wiki-linter.js +1 -1
  105. package/documentation/wiki-linting-and-testing.js +4 -1
  106. package/documentation/wiki-mk/doc-context.d.ts +14 -0
  107. package/documentation/wiki-mk/doc-context.js +3 -0
  108. package/documentation/wiki-mk/doc-maker.js +3 -1
  109. package/documentation/wiki-query.js +19 -1
  110. package/documentation/wiki-setup.js +10 -7
  111. package/documentation/wiki-signature-database.d.ts +16 -0
  112. package/documentation/wiki-signature-database.js +293 -0
  113. package/linter/linter-format.d.ts +7 -0
  114. package/linter/linter-rules.d.ts +10 -9
  115. package/linter/rules/naming-convention.d.ts +1 -0
  116. package/linter/rules/naming-convention.js +2 -0
  117. package/linter/rules/no-leaked-credentials.js +1 -2
  118. package/linter/rules/roxygen-arguments.js +18 -5
  119. package/linter/rules/stop-with-call-arg.js +2 -2
  120. package/linter/rules/undefined-symbol-util.d.ts +36 -0
  121. package/linter/rules/undefined-symbol-util.js +149 -0
  122. package/linter/rules/undefined-symbol.d.ts +58 -17
  123. package/linter/rules/undefined-symbol.js +143 -33
  124. package/linter/rules/unused-definition.d.ts +8 -1
  125. package/linter/rules/unused-definition.js +126 -1
  126. package/package.json +23 -10
  127. package/project/context/abstract-flowr-analyzer-context.js +7 -1
  128. package/project/context/flowr-analyzer-context.d.ts +8 -0
  129. package/project/context/flowr-analyzer-context.js +10 -0
  130. package/project/context/flowr-analyzer-dependencies-context.d.ts +28 -4
  131. package/project/context/flowr-analyzer-dependencies-context.js +53 -1
  132. package/project/context/flowr-analyzer-files-context.d.ts +1 -0
  133. package/project/context/flowr-analyzer-files-context.js +2 -1
  134. package/project/context/flowr-analyzer-functions-context.js +1 -1
  135. package/project/context/flowr-file.d.ts +5 -0
  136. package/project/context/flowr-file.js +5 -0
  137. package/project/flowr-analyzer-builder.js +12 -2
  138. package/project/plugins/file-plugins/files/flowr-description-file.js +6 -3
  139. package/project/plugins/file-plugins/files/flowr-namespace-file.js +9 -3
  140. package/project/plugins/file-plugins/files/flowr-news-file.js +1 -3
  141. package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.d.ts +26 -0
  142. package/project/plugins/file-plugins/flowr-analyzer-inst-file-plugin.js +39 -0
  143. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +1 -1
  144. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +2 -2
  145. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.js +1 -0
  146. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +18 -2
  147. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +19 -0
  148. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +120 -0
  149. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +518 -0
  150. package/project/plugins/package-version-plugins/package.d.ts +5 -3
  151. package/project/plugins/package-version-plugins/package.js +27 -25
  152. package/project/plugins/plugin-registry.d.ts +3 -2
  153. package/project/plugins/plugin-registry.js +4 -2
  154. package/project/plugins/project-discovery/flowr-analyzer-gitignore-project-discovery-plugin.js +7 -2
  155. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +3 -1
  156. package/project/sigdb/build.d.ts +131 -0
  157. package/project/sigdb/build.js +628 -0
  158. package/project/sigdb/codec.d.ts +51 -0
  159. package/project/sigdb/codec.js +122 -0
  160. package/project/sigdb/decode.d.ts +58 -0
  161. package/project/sigdb/decode.js +129 -0
  162. package/project/sigdb/decompress.d.ts +44 -0
  163. package/project/sigdb/decompress.js +176 -0
  164. package/project/sigdb/hash.d.ts +9 -0
  165. package/project/sigdb/hash.js +54 -0
  166. package/project/sigdb/index-format.d.ts +40 -0
  167. package/project/sigdb/index-format.js +28 -0
  168. package/project/sigdb/manifest.d.ts +68 -0
  169. package/project/sigdb/manifest.js +146 -0
  170. package/project/sigdb/reader.d.ts +250 -0
  171. package/project/sigdb/reader.js +692 -0
  172. package/project/sigdb/schema.d.ts +196 -0
  173. package/project/sigdb/schema.js +33 -0
  174. package/project/sigdb/sigdb-download.d.ts +65 -0
  175. package/project/sigdb/sigdb-download.js +237 -0
  176. package/project/sigdb/signature-match.d.ts +26 -0
  177. package/project/sigdb/signature-match.js +40 -0
  178. package/project/sigdb/version.d.ts +20 -0
  179. package/project/sigdb/version.js +55 -0
  180. package/queries/catalog/call-context-query/call-context-query-executor.js +1 -3
  181. package/queries/catalog/config-query/config-query-format.d.ts +3 -1
  182. package/queries/catalog/config-query/config-query-format.js +68 -9
  183. package/queries/catalog/dataflow-query/dataflow-query-format.js +11 -1
  184. package/queries/catalog/dependencies-query/dependencies-query-executor.js +1 -1
  185. package/queries/catalog/linter-query/linter-query-executor.d.ts +2 -0
  186. package/queries/catalog/linter-query/linter-query-executor.js +6 -1
  187. package/queries/catalog/linter-query/linter-query-format.d.ts +2 -1
  188. package/queries/catalog/linter-query/linter-query-format.js +40 -8
  189. package/queries/catalog/project-query/project-query-executor.d.ts +15 -0
  190. package/queries/catalog/project-query/project-query-executor.js +96 -4
  191. package/queries/catalog/project-query/project-query-format.d.ts +44 -0
  192. package/queries/catalog/project-query/project-query-format.js +33 -2
  193. package/queries/catalog/signature-query/signature-query-executor.d.ts +29 -0
  194. package/queries/catalog/signature-query/signature-query-executor.js +461 -0
  195. package/queries/catalog/signature-query/signature-query-format.d.ts +138 -0
  196. package/queries/catalog/signature-query/signature-query-format.js +76 -0
  197. package/queries/catalog/signature-query/signature-query-render.d.ts +15 -0
  198. package/queries/catalog/signature-query/signature-query-render.js +155 -0
  199. package/queries/catalog/static-slice-query/static-slice-query-executor.js +9 -3
  200. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +10 -0
  201. package/queries/catalog/static-slice-query/static-slice-query-format.js +19 -1
  202. package/queries/query-print.js +5 -0
  203. package/queries/query.d.ts +10 -1
  204. package/queries/query.js +5 -2
  205. package/r-bridge/init.js +5 -1
  206. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +10 -0
  207. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +55 -0
  208. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +16 -0
  209. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +27 -0
  210. package/r-bridge/lang-4.x/ast/parser/json/format.js +89 -2
  211. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-expressions.js +2 -4
  212. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +2 -1
  213. package/r-bridge/parser.d.ts +2 -0
  214. package/r-bridge/retriever.js +4 -1
  215. package/r-bridge/roxygen2/documentation-provider.js +2 -1
  216. package/r-bridge/shell.d.ts +5 -0
  217. package/r-bridge/shell.js +17 -1
  218. package/reconstruct/inline/source-inline-map.d.ts +48 -0
  219. package/reconstruct/inline/source-inline-map.js +94 -0
  220. package/reconstruct/reconstruct.d.ts +19 -2
  221. package/reconstruct/reconstruct.js +79 -16
  222. package/search/search-executor/search-generators.js +5 -22
  223. package/search/search-executor/search-transformer.js +10 -6
  224. package/slicing/criterion/parse.d.ts +22 -4
  225. package/slicing/criterion/parse.js +125 -18
  226. package/slicing/static/slice-call.d.ts +24 -1
  227. package/slicing/static/slice-call.js +90 -0
  228. package/slicing/static/static-slicer.d.ts +7 -0
  229. package/slicing/static/static-slicer.js +38 -3
  230. package/util/collections/arrays.d.ts +4 -5
  231. package/util/collections/arrays.js +7 -18
  232. package/util/hash.d.ts +14 -0
  233. package/util/hash.js +31 -0
  234. package/util/mermaid/dfg.d.ts +7 -2
  235. package/util/mermaid/dfg.js +53 -13
  236. package/util/r-base-packages.d.ts +19 -0
  237. package/util/r-base-packages.js +72 -0
  238. package/util/r-license.js +2 -10
  239. package/util/r-version.d.ts +45 -15
  240. package/util/r-version.js +97 -36
  241. package/util/range.d.ts +15 -0
  242. package/util/range.js +39 -0
  243. package/util/schema.d.ts +10 -0
  244. package/util/schema.js +22 -0
  245. package/util/text/ansi.d.ts +13 -1
  246. package/util/text/ansi.js +27 -4
  247. package/util/text/args.js +1 -2
  248. package/util/version.js +28 -8
  249. package/data/pkgdb/pkgdb-latest.json.br +0 -0
  250. package/data/pkgdb/pkgdb-tiny.json.br +0 -0
  251. package/documentation/wiki-package-database.d.ts +0 -9
  252. package/documentation/wiki-package-database.js +0 -63
  253. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.d.ts +0 -63
  254. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.js +0 -174
  255. package/project/plugins/package-version-plugins/pkgdb.d.ts +0 -133
  256. package/project/plugins/package-version-plugins/pkgdb.js +0 -370
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RFunctionCall = exports.EmptyArgument = void 0;
4
4
  const model_1 = require("../model");
5
5
  const type_1 = require("../type");
6
+ const prefix_1 = require("../../../../../util/prefix");
6
7
  exports.EmptyArgument = '<>';
7
8
  /**
8
9
  * Helper for working with {@link RFunctionCall} AST nodes.
@@ -27,6 +28,60 @@ exports.RFunctionCall = {
27
28
  */
28
29
  isUnnamed(node) {
29
30
  return exports.RFunctionCall.is(node) && !node.named;
31
+ },
32
+ /**
33
+ * Bind a call's `arguments` to the formal `paramNames` using R's argument matching rules
34
+ * (see https://cran.r-project.org/doc/manuals/R-lang.html#Argument-matching): exact name, then partial
35
+ * (`pmatch`, unique-prefix) name, then the remaining unnamed arguments filling the remaining formals
36
+ * left-to-right. Returns a map from parameter name to the argument bound to it, so
37
+ * `matchArgumentsToParameters(call.arguments, names).get('X')` answers "which argument is mapped to
38
+ * parameter `X`". Pass `paramNames` as the full formal list **excluding `...`** so ambiguous prefixes are
39
+ * rejected; this makes it exact when the signature is known (e.g. from the signature database).
40
+ */
41
+ matchArgsToParams(args, paramNames) {
42
+ const bound = new Map();
43
+ const used = new Set();
44
+ // pass 1: exact name matches
45
+ for (let i = 0; i < args.length; i++) {
46
+ const arg = args[i];
47
+ if (arg === exports.EmptyArgument || arg.name === undefined) {
48
+ continue;
49
+ }
50
+ const n = arg.name.content;
51
+ if (paramNames.includes(n) && !bound.has(n)) {
52
+ bound.set(n, arg);
53
+ used.add(i);
54
+ }
55
+ }
56
+ // pass 2: partial (pmatch) name matches on the still-unbound named arguments
57
+ for (let i = 0; i < args.length; i++) {
58
+ const arg = args[i];
59
+ if (used.has(i) || arg === exports.EmptyArgument || arg.name === undefined) {
60
+ continue;
61
+ }
62
+ const matched = (0, prefix_1.findByPrefixIfUnique)(arg.name.content, paramNames);
63
+ if (matched !== undefined && !bound.has(matched)) {
64
+ bound.set(matched, arg);
65
+ used.add(i);
66
+ }
67
+ }
68
+ // pass 3: remaining unnamed args fill the remaining formals left-to-right
69
+ let formalIdx = 0;
70
+ for (let i = 0; i < args.length; i++) {
71
+ const arg = args[i];
72
+ if (used.has(i) || arg === exports.EmptyArgument || arg.name !== undefined) {
73
+ continue;
74
+ }
75
+ while (formalIdx < paramNames.length && bound.has(paramNames[formalIdx])) {
76
+ formalIdx++;
77
+ }
78
+ if (formalIdx < paramNames.length) {
79
+ bound.set(paramNames[formalIdx], arg);
80
+ used.add(i);
81
+ formalIdx++;
82
+ }
83
+ }
84
+ return bound;
30
85
  }
31
86
  };
32
87
  //# sourceMappingURL=r-function-call.js.map
@@ -37,6 +37,22 @@ export declare const NodeId: {
37
37
  * @see {@link fromBuiltIn} - to recover the built-in function or operator name from a built-in id
38
38
  */
39
39
  readonly toBuiltIn: <T extends string>(this: void, name: T) => BuiltIn<T>;
40
+ /**
41
+ * The canonical `pkg:fn` identifier of a package's exported function (e.g. `ggplot2:ggplot`). The single
42
+ * source of this form: `Package.functionIdentifier` delegates here, and {@link fromPkgFn} wraps it.
43
+ */
44
+ readonly pkgFnName: <P extends string, F extends string>(this: void, pkg: P, fn: F) => `${P}:${F}`;
45
+ /**
46
+ * The built-in id of a package's exported function, e.g. `fromPkgFn('ggplot2', 'ggplot')` yields
47
+ * `built-in:ggplot2:ggplot` -- {@link toBuiltIn} over the {@link pkgFnName} `pkg:fn` form.
48
+ */
49
+ readonly fromPkgFn: <P extends string, F extends string>(this: void, pkg: P, fn: F) => BuiltIn<`${P}:${F}`>;
50
+ /**
51
+ * Inverse of {@link fromPkgFn}: split a package-function built-in id (`built-in:pkg:fn`) into its `[pkg, fn]`
52
+ * parts, or `undefined` when `id` is not one (a non-builtin id, or a bare builtin without a package such as
53
+ * `built-in:print`). A package name never contains a `:`, so the first one separates it from the function.
54
+ */
55
+ readonly toPkgFn: (this: void, id: BuiltIn | NodeId | undefined) => readonly [pkg: string, fn: string] | undefined;
40
56
  /**
41
57
  * Converts a built-in function or operator name or id to a built-in id by prefixing it with the built-in prefix if it is not already a built-in id.
42
58
  * This allows us to accept both built-in names and ids in contexts where we want to work with built-in ids.
@@ -48,6 +48,33 @@ exports.NodeId = {
48
48
  toBuiltIn(name) {
49
49
  return `built-in:${name}`;
50
50
  },
51
+ /**
52
+ * The canonical `pkg:fn` identifier of a package's exported function (e.g. `ggplot2:ggplot`). The single
53
+ * source of this form: `Package.functionIdentifier` delegates here, and {@link fromPkgFn} wraps it.
54
+ */
55
+ pkgFnName(pkg, fn) {
56
+ return `${pkg}:${fn}`;
57
+ },
58
+ /**
59
+ * The built-in id of a package's exported function, e.g. `fromPkgFn('ggplot2', 'ggplot')` yields
60
+ * `built-in:ggplot2:ggplot` -- {@link toBuiltIn} over the {@link pkgFnName} `pkg:fn` form.
61
+ */
62
+ fromPkgFn(pkg, fn) {
63
+ return exports.NodeId.toBuiltIn(exports.NodeId.pkgFnName(pkg, fn));
64
+ },
65
+ /**
66
+ * Inverse of {@link fromPkgFn}: split a package-function built-in id (`built-in:pkg:fn`) into its `[pkg, fn]`
67
+ * parts, or `undefined` when `id` is not one (a non-builtin id, or a bare builtin without a package such as
68
+ * `built-in:print`). A package name never contains a `:`, so the first one separates it from the function.
69
+ */
70
+ toPkgFn(id) {
71
+ if (!exports.NodeId.isBuiltIn(id)) {
72
+ return undefined;
73
+ }
74
+ const rest = exports.NodeId.fromBuiltIn(id);
75
+ const sep = rest.indexOf(':');
76
+ return sep > 0 ? [rest.slice(0, sep), rest.slice(sep + 1)] : undefined;
77
+ },
51
78
  /**
52
79
  * Converts a built-in function or operator name or id to a built-in id by prefixing it with the built-in prefix if it is not already a built-in id.
53
80
  * This allows us to accept both built-in names and ids in contexts where we want to work with built-in ids.
@@ -7,6 +7,87 @@ const retriever_1 = require("../../../../retriever");
7
7
  const assert_1 = require("../../../../../util/assert");
8
8
  const type_1 = require("../../model/type");
9
9
  exports.RootId = 0;
10
+ /**
11
+ * R's `getParseData` escapes the lexeme `text` with `encodeString`, whose escaping is locale-dependent: under a
12
+ * non-UTF-8 locale (a common CI setup) non-ASCII bytes come out as octal (`\303\264`) or hex (`\xc3`) escapes that
13
+ * are not valid JSON. Valid JSON escapes (`\n`, `\"`, `\uXXXX`, ...) are left untouched.
14
+ */
15
+ function jsonSafeRParseData(data) {
16
+ let out = '';
17
+ for (let i = 0; i < data.length;) {
18
+ if (data[i] !== '\\') {
19
+ out += data[i++];
20
+ continue;
21
+ }
22
+ const next = data[i + 1];
23
+ if (next !== undefined && (next === '\\' || next === '"' || next === '/' || next === 'b' || next === 'f' || next === 'n' || next === 'r' || next === 't' || next === 'u')) {
24
+ out += data[i] + next;
25
+ i += 2;
26
+ continue;
27
+ }
28
+ if (next !== undefined && next >= '0' && next <= '7') {
29
+ const run = readByteRun(data, i, collectOctal);
30
+ out += bytesToUtf8Json(run.bytes);
31
+ i = run.next;
32
+ continue;
33
+ }
34
+ if (next === 'x') {
35
+ const run = readByteRun(data, i, collectHex);
36
+ out += bytesToUtf8Json(run.bytes);
37
+ i = run.next;
38
+ continue;
39
+ }
40
+ if (next === undefined) {
41
+ out += data[i];
42
+ i += 1;
43
+ }
44
+ else {
45
+ out += `\\u${next.charCodeAt(0).toString(16).padStart(4, '0')}`;
46
+ i += 2;
47
+ }
48
+ }
49
+ return out;
50
+ }
51
+ /** Reads a run of consecutive `\NNN` octal (or `\xNN` hex) escapes starting at `start` (which points at a `\`). */
52
+ function readByteRun(data, start, collect) {
53
+ const bytes = [];
54
+ let pos = start;
55
+ for (;;) {
56
+ const read = collect(data, pos);
57
+ if (read === undefined) {
58
+ break;
59
+ }
60
+ bytes.push(read.value & 0xff);
61
+ pos = read.next;
62
+ }
63
+ return { bytes, next: pos };
64
+ }
65
+ function collectOctal(data, pos) {
66
+ if (data[pos] !== '\\' || !(data[pos + 1] >= '0' && data[pos + 1] <= '7')) {
67
+ return undefined;
68
+ }
69
+ let oct = '', j = pos + 1;
70
+ while (j < data.length && oct.length < 3 && data[j] >= '0' && data[j] <= '7') {
71
+ oct += data[j++];
72
+ }
73
+ return { value: parseInt(oct, 8), next: j };
74
+ }
75
+ function collectHex(data, pos) {
76
+ if (data[pos] !== '\\' || data[pos + 1] !== 'x' || !/[0-9a-fA-F]/.test(data[pos + 2] ?? '')) {
77
+ return undefined;
78
+ }
79
+ let hex = '', j = pos + 2;
80
+ while (j < data.length && hex.length < 2 && /[0-9a-fA-F]/.test(data[j])) {
81
+ hex += data[j++];
82
+ }
83
+ return { value: parseInt(hex, 16), next: j };
84
+ }
85
+ /** Decodes raw bytes as UTF-8 and re-escapes the result for a JSON string context. */
86
+ function bytesToUtf8Json(bytes) {
87
+ const decoded = Buffer.from(bytes).toString('utf-8');
88
+ // JSON.stringify gives a valid JSON string literal; strip its surrounding quotes to splice back inline
89
+ return JSON.stringify(decoded).slice(1, -1);
90
+ }
10
91
  /**
11
92
  * Takes the raw {@link RShell} output and extracts the csv information contained
12
93
  */
@@ -15,8 +96,14 @@ function prepareParsedData(data) {
15
96
  try {
16
97
  json = JSON.parse(`[${data.trim()}]`);
17
98
  }
18
- catch (e) {
19
- throw new Error(`Failed to parse data [${data}]: ${e?.message}`);
99
+ catch {
100
+ // the fast path failed, most likely because a non-UTF-8 R locale produced octal/hex string escapes
101
+ try {
102
+ json = JSON.parse(`[${jsonSafeRParseData(data.trim())}]`);
103
+ }
104
+ catch (e) {
105
+ throw new Error(`Failed to parse data [${data}]: ${e?.message}`);
106
+ }
20
107
  }
21
108
  (0, assert_1.guard)(Array.isArray(json), () => `Expected ${data} to be an array but was not`);
22
109
  const ret = new Map(json.map(([line1, col1, line2, col2, id, parent, token, terminal, text]) => {
@@ -158,10 +158,8 @@ function normalizeExpressions(data, tokens) {
158
158
  return [processBraces(braces, processed, parsedComments, data)];
159
159
  }
160
160
  else if (processed.length > 0) {
161
- if (parsedComments) {
162
- processed[0].info.adToks ??= [];
163
- processed[0].info.adToks.push(...parsedComments);
164
- }
161
+ processed[0].info.adToks ??= [];
162
+ processed[0].info.adToks.push(...parsedComments);
165
163
  return processed;
166
164
  }
167
165
  else {
@@ -709,6 +709,7 @@ function findFirstNonCommentSibling(snode, knownNexts) {
709
709
  function linkCommentsToNextNodes(nodes, comments) {
710
710
  const remain = [];
711
711
  const cacheMap = new Map();
712
+ const nodeById = new Map(nodes.map(n => [n[0].id, n]));
712
713
  for (const [commentSyntaxNode, commentNode] of comments) {
713
714
  let sibling;
714
715
  const prev = commentSyntaxNode.previousSibling;
@@ -720,7 +721,7 @@ function linkCommentsToNextNodes(nodes, comments) {
720
721
  sibling = findFirstNonCommentSibling(commentSyntaxNode, cacheMap);
721
722
  }
722
723
  // if there is no valid sibling, we just link the comment to the first node (see normalize-expressions.ts)
723
- const [, node] = (sibling ? nodes.find(([s]) => s.id === sibling.id) : undefined) ?? nodes[0] ?? [];
724
+ const [, node] = (sibling ? nodeById.get(sibling.id) : undefined) ?? nodes[0] ?? [];
724
725
  if (node) {
725
726
  node.info.adToks ??= [];
726
727
  node.info.adToks.push(commentNode);
@@ -25,6 +25,8 @@ export interface RShellInformation extends BaseRShellInformation {
25
25
  * @param addonConfig - Additional configuration for the output collector.
26
26
  */
27
27
  sendCommandWithOutput(command: string, addonConfig?: Partial<OutputCollectorConfiguration>): Promise<string[]>;
28
+ /** Map of every package installed on the system to its version (`installed.packages()`); see `solver.sigdb.versionSelection: 'system'`. */
29
+ installedPackageVersions(): Promise<Map<string, string>>;
28
30
  }
29
31
  export interface TreeSitterInformation extends BaseParserInformation {
30
32
  readonly name: 'tree-sitter';
@@ -128,8 +128,11 @@ function retrieveParseDataFromRCode(request, shell) {
128
128
  return Promise.resolve('');
129
129
  }
130
130
  const suffix = request.request === 'file' ? ', encoding="utf-8"' : '';
131
+ /* R's `parse(text=)` (unlike reading a file) rejects a carriage return as an "invalid token", so normalize
132
+ * CRLF/CR line endings to LF for text requests to match R's own file handling and stay robust to Windows sources. */
133
+ const content = request.request === 'text' ? request.content.replace(/\r\n?/g, '\n') : request.content;
131
134
  /* call the function with the request */
132
- const command = `flowr_get_ast(${request.request}=${JSON.stringify(request.content)}${suffix})`;
135
+ const command = `flowr_get_ast(${request.request}=${JSON.stringify(content)}${suffix})`;
133
136
  if (shell instanceof shell_executor_1.RShellExecutor) {
134
137
  return guardRetrievedOutput(shell.run(command), request);
135
138
  }
@@ -29,6 +29,7 @@ const CommentRetriever = {
29
29
  return undefined;
30
30
  }
31
31
  };
32
+ const defaultRetriever = (c, a) => (0, roxygen_parse_1.parseRoxygenCommentsOfNode)(c, a)?.tags;
32
33
  /**
33
34
  * Given a normalized AST and a node ID, returns the Roxygen documentation (if any) associated with that node.
34
35
  * Please note that this does more than {@link parseRoxygenCommentsOfNode}, as it also traverses up the AST to find documentation.
@@ -44,7 +45,7 @@ function getDocumentationOf(nodeId, idMap) {
44
45
  else if ('doc' in node.info) {
45
46
  return node.info.doc;
46
47
  }
47
- const retriever = CommentRetriever[node.type] ?? ((c, a) => (0, roxygen_parse_1.parseRoxygenCommentsOfNode)(c, a)?.tags);
48
+ const retriever = CommentRetriever[node.type] ?? defaultRetriever;
48
49
  const doc = retriever(node, idMap);
49
50
  if (doc) {
50
51
  // to avoid endless recursion, we block the caching here once:
@@ -109,6 +109,11 @@ export declare class RShell implements AsyncParser<string> {
109
109
  usedRVersion(): Promise<SemVer | null>;
110
110
  injectLibPaths(...paths: readonly string[]): void;
111
111
  tryToInjectHomeLibPath(): void;
112
+ /**
113
+ * Map of every package installed on this system to its version (from `installed.packages()`), used by
114
+ * `solver.sigdb.versionSelection: 'system'`. Empty when R reports nothing or fails.
115
+ */
116
+ installedPackageVersions(): Promise<Map<string, string>>;
112
117
  /**
113
118
  * checks if a given package is already installed on the system!
114
119
  */
package/r-bridge/shell.js CHANGED
@@ -129,7 +129,8 @@ class RShell {
129
129
  rVersion: async () => await this.rVersion(),
130
130
  sendCommandWithOutput: (command, addonConfig) => {
131
131
  return this.sendCommandWithOutput(command, addonConfig);
132
- }
132
+ },
133
+ installedPackageVersions: () => this.installedPackageVersions()
133
134
  };
134
135
  }
135
136
  revive() {
@@ -195,6 +196,21 @@ class RShell {
195
196
  this.injectLibPaths(this.options.homeLibPath);
196
197
  }
197
198
  }
199
+ /**
200
+ * Map of every package installed on this system to its version (from `installed.packages()`), used by
201
+ * `solver.sigdb.versionSelection: 'system'`. Empty when R reports nothing or fails.
202
+ */
203
+ async installedPackageVersions() {
204
+ const versions = new Map();
205
+ const result = await this.sendCommandWithOutput(`local({ ip <- installed.packages()[,c("Package","Version"),drop=FALSE]; cat(paste(ip[,1], ip[,2], sep="\t"), sep=${(0, convert_values_1.ts2r)(this.options.eol)}); cat(${(0, convert_values_1.ts2r)(this.options.eol)}) })`);
206
+ for (const line of result) {
207
+ const tab = line.indexOf('\t');
208
+ if (tab > 0) {
209
+ versions.set(line.slice(0, tab).trim(), line.slice(tab + 1).trim());
210
+ }
211
+ }
212
+ return versions;
213
+ }
198
214
  /**
199
215
  * checks if a given package is already installed on the system!
200
216
  */
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Maps each `source()` call node to the index of the file it sources in `ast.ast.files`.
3
+ * {@link reconstructToCode} uses it (via `inlineSources`) to splice a sourced file's reconstruction
4
+ * in place of its `source()` call, yielding one self-contained R text.
5
+ * @module
6
+ */
7
+ import type { NormalizedAst } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
8
+ import type { DataflowGraph } from '../../dataflow/graph/graph';
9
+ import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
10
+ /**
11
+ * A warning raised while inlining `source()` calls during reconstruction.
12
+ * @see {@link reconstructToCode}
13
+ */
14
+ export interface InlineWarning {
15
+ /**
16
+ * - `cycle`: the `source()` would re-inline a file already being inlined on the current path;
17
+ * the literal call is kept at the cycle edge to break the recursion.
18
+ * - `unresolved`: the `source()` survived the slice but could not be linked to a file
19
+ * (dynamic or missing path); the literal call is kept verbatim.
20
+ */
21
+ readonly kind: 'cycle' | 'unresolved';
22
+ /** the id of the `source()` function-call node that triggered the warning */
23
+ readonly callId: NodeId;
24
+ /** the (best-effort) path of the file that was meant to be sourced, if known */
25
+ readonly path?: string;
26
+ }
27
+ /**
28
+ * Helper functions to link `source()` calls to the files they source for reconstruction inlining.
29
+ * @see {@link SourceInlineMap.build}
30
+ */
31
+ export declare const SourceInlineMap: {
32
+ readonly name: "SourceInlineMap";
33
+ /**
34
+ * Connect each `source()` call node to the index of the file it sources in `ast.ast.files` (index 0 is main).
35
+ *
36
+ * A `source()` call lives in its parent file, so we reach its sourced block via the control dependency the
37
+ * dataflow analysis adds (see {@link sourceRequest}): a vertex whose innermost cd (`cds[0]`) is a source call
38
+ * belongs to that call's directly sourced block. Every node carries its resolved file in `info.file`, so the
39
+ * block's `info.file` names the sourced file independent of the call site, and one graph pass resolves all
40
+ * calls via small map lookups. A file sourced from several sites is stored once but each block still tags the
41
+ * same `info.file`, so all sites map to that single index (this also drives cycle detection: a re-sourcing
42
+ * call resolves to an already-visited index).
43
+ * @param ast - the normalized (multi-file) ast
44
+ * @param graph - the dataflow graph for `ast`
45
+ * @returns a map from each `source()` call node id to the index of the sourced file in `ast.ast.files`
46
+ */
47
+ readonly build: (ast: NormalizedAst, graph: DataflowGraph) => Map<NodeId, number>;
48
+ };
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SourceInlineMap = void 0;
4
+ const vertex_1 = require("../../dataflow/graph/vertex");
5
+ const built_in_proc_name_1 = require("../../dataflow/environments/built-in-proc-name");
6
+ const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
7
+ const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
8
+ /** the string-literal path argument of a `source()`-like call node, if it has one (else `undefined`) */
9
+ function sourceArg(ast, callId) {
10
+ const node = ast.idMap.get(callId);
11
+ const arg = node?.type === type_1.RType.FunctionCall ? node.arguments[0] : undefined;
12
+ return arg !== undefined && arg !== r_function_call_1.EmptyArgument && arg.value?.type === type_1.RType.String ? arg.value.content.str : undefined;
13
+ }
14
+ /**
15
+ * Helper functions to link `source()` calls to the files they source for reconstruction inlining.
16
+ * @see {@link SourceInlineMap.build}
17
+ */
18
+ exports.SourceInlineMap = {
19
+ name: 'SourceInlineMap',
20
+ /**
21
+ * Connect each `source()` call node to the index of the file it sources in `ast.ast.files` (index 0 is main).
22
+ *
23
+ * A `source()` call lives in its parent file, so we reach its sourced block via the control dependency the
24
+ * dataflow analysis adds (see {@link sourceRequest}): a vertex whose innermost cd (`cds[0]`) is a source call
25
+ * belongs to that call's directly sourced block. Every node carries its resolved file in `info.file`, so the
26
+ * block's `info.file` names the sourced file independent of the call site, and one graph pass resolves all
27
+ * calls via small map lookups. A file sourced from several sites is stored once but each block still tags the
28
+ * same `info.file`, so all sites map to that single index (this also drives cycle detection: a re-sourcing
29
+ * call resolves to an already-visited index).
30
+ * @param ast - the normalized (multi-file) ast
31
+ * @param graph - the dataflow graph for `ast`
32
+ * @returns a map from each `source()` call node id to the index of the sourced file in `ast.ast.files`
33
+ */
34
+ build(ast, graph) {
35
+ const files = ast.ast.files;
36
+ const map = new Map();
37
+ if (files.length <= 1) {
38
+ return map;
39
+ }
40
+ // resolved file path -> its index (paths are unique per stored file)
41
+ const pathToIndex = new Map();
42
+ for (let i = 1; i < files.length; i++) {
43
+ const path = files[i].root.info.file;
44
+ if (path !== undefined) {
45
+ pathToIndex.set(path, i);
46
+ }
47
+ }
48
+ // single pass: collect every source call (with its literal path arg, computed once) and, per control
49
+ // dependency, the first vertex under it (its directly sourced block).
50
+ const sourceArgs = new Map();
51
+ const firstVertexByCd = new Map();
52
+ for (const [id, vertex] of graph.vertices(true)) {
53
+ if ((0, vertex_1.isFunctionCallVertex)(vertex) && Array.isArray(vertex.origin) && vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.Source)) {
54
+ sourceArgs.set(id, sourceArg(ast, id));
55
+ }
56
+ const cds = vertex.cds;
57
+ if (cds && cds.length > 0 && !firstVertexByCd.has(cds[0].id)) {
58
+ firstVertexByCd.set(cds[0].id, id);
59
+ }
60
+ }
61
+ if (sourceArgs.size === 0) {
62
+ return map;
63
+ }
64
+ // resolve each call via the `info.file` of the block it directly sources (if it has one)
65
+ for (const callId of sourceArgs.keys()) {
66
+ const block = firstVertexByCd.get(callId);
67
+ const path = block !== undefined ? ast.idMap.get(block)?.info.file : undefined;
68
+ const idx = path !== undefined ? pathToIndex.get(path) : undefined;
69
+ if (idx !== undefined) {
70
+ map.set(callId, idx);
71
+ }
72
+ }
73
+ // a re-source of an already-stored file (a diamond's shared leaf, or a cycle edge) is deduplicated and
74
+ // has no block of its own, so the pass above misses it. Map it by its literal path arg, which another
75
+ // (resolved) call to the same file already fixed.
76
+ const argToIndex = new Map();
77
+ for (const [callId, idx] of map) {
78
+ const arg = sourceArgs.get(callId);
79
+ if (arg !== undefined) {
80
+ argToIndex.set(arg, idx);
81
+ }
82
+ }
83
+ for (const [callId, arg] of sourceArgs) {
84
+ if (arg !== undefined && !map.has(callId)) {
85
+ const idx = argToIndex.get(arg);
86
+ if (idx !== undefined) {
87
+ map.set(callId, idx);
88
+ }
89
+ }
90
+ }
91
+ return map;
92
+ }
93
+ };
94
+ //# sourceMappingURL=source-inline-map.js.map
@@ -6,6 +6,7 @@
6
6
  import type { NormalizedAst } from '../r-bridge/lang-4.x/ast/model/processing/decorate';
7
7
  import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
8
8
  import { type AutoSelectPredicate } from './auto-select/auto-select-defaults';
9
+ import type { InlineWarning } from './inline/source-inline-map';
9
10
  interface Selection {
10
11
  /**
11
12
  * The set of node ids to be reconstructed.
@@ -15,6 +16,18 @@ interface Selection {
15
16
  * @see {@link ReconstructRequiredInput#reconstructFiles}
16
17
  */
17
18
  reconstructFiles?: 'all' | number[];
19
+ /**
20
+ * If set, selected `source()` calls are replaced by the (spliced) reconstruction of the sourced file,
21
+ * producing a single self-contained reconstruction (`code` will be a `string` for the main file, index 0).
22
+ * Requires {@link Selection#sourceMap} to be provided. Overrides {@link Selection#reconstructFiles}.
23
+ * @see {@link SourceInlineMap.build}
24
+ */
25
+ inlineSources?: boolean;
26
+ /**
27
+ * Maps a `source()` call node id to the index of the sourced file in `ast.ast.files`.
28
+ * Only used together with {@link Selection#inlineSources}. Build it via {@link SourceInlineMap.build}.
29
+ */
30
+ sourceMap?: ReadonlyMap<NodeId, number>;
18
31
  }
19
32
  export declare const reconstructLogger: import("tslog").Logger<import("tslog").ILogObj>;
20
33
  export interface ReconstructionResult {
@@ -22,10 +35,14 @@ export interface ReconstructionResult {
22
35
  code: string | string[];
23
36
  /** number of lines that contain nodes that triggered the `autoSelectIf` predicate {@link reconstructToCode} */
24
37
  linesWithAutoSelected: number;
38
+ /** warnings raised while inlining `source()` calls (only set when {@link Selection#inlineSources} is active) */
39
+ inlineWarnings?: InlineWarning[];
25
40
  }
26
- export declare function reconstructToCode(ast: NormalizedAst, selection: Selection & {
41
+ export declare function reconstructToCode(ast: NormalizedAst, selection: Selection & ({
42
+ inlineSources: true;
43
+ } | {
27
44
  reconstructFiles?: [number] | undefined;
28
- }, autoSelectIf?: AutoSelectPredicate): ReconstructionResult & {
45
+ }), autoSelectIf?: AutoSelectPredicate): ReconstructionResult & {
29
46
  code: string;
30
47
  };
31
48
  export declare function reconstructToCode(ast: NormalizedAst, selection: Selection, autoSelectIf?: AutoSelectPredicate): ReconstructionResult;