@eagleoutice/flowr 2.13.8 → 2.13.10

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 (152) hide show
  1. package/config.d.ts +50 -2
  2. package/config.js +37 -6
  3. package/dataflow/cluster.js +48 -24
  4. package/dataflow/environments/apply-kill.js +4 -4
  5. package/dataflow/environments/built-in-props.d.ts +28 -4
  6. package/dataflow/environments/built-in-props.js +31 -8
  7. package/dataflow/environments/built-in.d.ts +7 -2
  8. package/dataflow/environments/built-in.js +10 -12
  9. package/dataflow/environments/default-builtin-config.d.ts +76 -6
  10. package/dataflow/environments/default-builtin-config.js +39 -16
  11. package/dataflow/environments/environment.d.ts +16 -0
  12. package/dataflow/environments/environment.js +70 -18
  13. package/dataflow/environments/identifier.d.ts +6 -0
  14. package/dataflow/environments/identifier.js +18 -5
  15. package/dataflow/environments/query-fn-props.js +34 -2
  16. package/dataflow/environments/reference-to-maybe.js +1 -1
  17. package/dataflow/eval/resolve/alias-tracking.js +45 -1
  18. package/dataflow/eval/resolve/resolve-argument.js +25 -17
  19. package/dataflow/eval/resolve/resolve-strings.d.ts +17 -0
  20. package/dataflow/eval/resolve/resolve-strings.js +16 -9
  21. package/dataflow/eval/resolve/resolve.js +3 -1
  22. package/dataflow/graph/call-graph.d.ts +7 -0
  23. package/dataflow/graph/call-graph.js +103 -0
  24. package/dataflow/graph/df-helper.d.ts +2 -0
  25. package/dataflow/graph/graph.d.ts +6 -8
  26. package/dataflow/graph/graph.js +21 -6
  27. package/dataflow/internal/linker.d.ts +5 -5
  28. package/dataflow/internal/linker.js +31 -92
  29. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +2 -2
  30. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +3 -9
  31. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +4 -30
  32. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +2 -1
  33. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +1 -1
  34. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +7 -1
  35. package/dataflow/internal/process/functions/call/built-in/built-in-load.js +3 -3
  36. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.d.ts +1 -1
  37. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +5 -1
  38. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +2 -2
  39. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +5 -6
  40. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +32 -14
  41. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +16 -4
  42. package/dataflow/internal/process/functions/call/known-call-handling.js +29 -8
  43. package/documentation/doc-util/doc-sigdb.d.ts +9 -0
  44. package/documentation/doc-util/doc-sigdb.js +32 -0
  45. package/documentation/wiki-interface.js +13 -2
  46. package/documentation/wiki-query.js +3 -0
  47. package/documentation/wiki-signature-database.js +2 -5
  48. package/gas.d.ts +6 -0
  49. package/gas.js +7 -1
  50. package/package.json +2 -2
  51. package/project/attached-packages.d.ts +13 -0
  52. package/project/attached-packages.js +30 -0
  53. package/project/context/flowr-analyzer-context.d.ts +15 -0
  54. package/project/context/flowr-analyzer-context.js +14 -3
  55. package/project/context/flowr-analyzer-files-context.d.ts +11 -0
  56. package/project/context/flowr-analyzer-files-context.js +3 -0
  57. package/project/context/flowr-analyzer-incremental-analysis-context.d.ts +4 -0
  58. package/project/context/flowr-analyzer-incremental-analysis-context.js +69 -0
  59. package/project/dependency-version-space.d.ts +45 -8
  60. package/project/dependency-version-space.js +86 -26
  61. package/project/plugins/file-plugins/files/flowr-namespace-file.js +52 -24
  62. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-library-plugin.d.ts +22 -0
  63. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-library-plugin.js +101 -0
  64. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +30 -11
  65. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +79 -37
  66. package/project/plugins/package-version-plugins/package.d.ts +2 -0
  67. package/project/plugins/package-version-plugins/package.js +4 -0
  68. package/project/plugins/plugin-registry.d.ts +2 -1
  69. package/project/plugins/plugin-registry.js +2 -0
  70. package/project/sigdb/manifest.js +9 -5
  71. package/project/sigdb/signature-match.d.ts +5 -18
  72. package/project/sigdb/signature-match.js +5 -18
  73. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.d.ts +4 -2
  74. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +25 -0
  75. package/queries/catalog/call-graph-query/call-graph-query-executor.js +3 -1
  76. package/queries/catalog/call-graph-query/call-graph-query-format.d.ts +4 -0
  77. package/queries/catalog/call-graph-query/call-graph-query-format.js +4 -0
  78. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.js +11 -1
  79. package/queries/catalog/dependencies-query/dependencies-query-executor.js +13 -5
  80. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +27 -1
  81. package/queries/catalog/dependencies-query/dependencies-query-format.js +69 -7
  82. package/queries/catalog/dependencies-query/function-info/library-functions.js +9 -2
  83. package/queries/catalog/dependencies-query/function-info/read-functions.js +31 -5
  84. package/queries/catalog/dependencies-query/function-info/remote-functions.d.ts +18 -0
  85. package/queries/catalog/dependencies-query/function-info/remote-functions.js +46 -0
  86. package/queries/catalog/dependencies-query/function-info/test-functions.d.ts +2 -0
  87. package/queries/catalog/dependencies-query/function-info/test-functions.js +33 -31
  88. package/queries/catalog/dependencies-query/function-info/visualize-functions.js +52 -2
  89. package/queries/catalog/dependencies-query/function-info/write-functions.js +28 -5
  90. package/queries/catalog/dependencies-query/link-devices.d.ts +12 -0
  91. package/queries/catalog/dependencies-query/link-devices.js +58 -0
  92. package/queries/catalog/dice-query/dice-query-format.d.ts +2 -0
  93. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +25 -6
  94. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +38 -7
  95. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +18 -5
  96. package/queries/catalog/happens-before-query/happens-before-query-format.js +3 -2
  97. package/queries/catalog/input-sources-query/input-sources-query-format.js +4 -0
  98. package/queries/catalog/input-sources-query/input-types.d.ts +10 -0
  99. package/queries/catalog/input-sources-query/input-types.js +10 -0
  100. package/queries/catalog/location-map-query/location-map-query-executor.js +16 -6
  101. package/queries/catalog/location-map-query/location-map-query-format.d.ts +15 -1
  102. package/queries/catalog/location-map-query/location-map-query-format.js +22 -5
  103. package/queries/catalog/signature-query/signature-query-executor.js +3 -0
  104. package/queries/catalog/signature-query/signature-query-format.d.ts +5 -0
  105. package/queries/catalog/static-slice-query/static-slice-query-format.js +1 -0
  106. package/queries/query.d.ts +1 -1
  107. package/r-bridge/data/data.d.ts +1 -1
  108. package/r-bridge/data/data.js +1 -1
  109. package/r-bridge/lang-4.x/ast/model/model.d.ts +14 -2
  110. package/r-bridge/lang-4.x/ast/model/model.js +32 -0
  111. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +2 -0
  112. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +2 -0
  113. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +2 -0
  114. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +2 -0
  115. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +2 -0
  116. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +2 -0
  117. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +2 -0
  118. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +7 -8
  119. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +9 -46
  120. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +2 -0
  121. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +2 -0
  122. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +2 -0
  123. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +2 -0
  124. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +2 -0
  125. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +2 -0
  126. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +2 -0
  127. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +2 -0
  128. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +2 -0
  129. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +2 -0
  130. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +2 -0
  131. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +2 -0
  132. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +2 -0
  133. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +0 -5
  134. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +6 -3
  135. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +1 -1
  136. package/search/flowr-search-filters.d.ts +17 -1
  137. package/search/flowr-search-filters.js +23 -0
  138. package/slicing/criterion/parse.d.ts +6 -25
  139. package/slicing/criterion/parse.js +50 -19
  140. package/slicing/static/fingerprint.d.ts +1 -1
  141. package/slicing/static/fingerprint.js +52 -8
  142. package/slicing/static/slicer-types.d.ts +10 -0
  143. package/slicing/static/static-slicer.d.ts +1 -1
  144. package/slicing/static/static-slicer.js +29 -6
  145. package/slicing/static/visiting-queue.d.ts +15 -3
  146. package/slicing/static/visiting-queue.js +37 -3
  147. package/util/arg-matching.d.ts +18 -0
  148. package/util/arg-matching.js +70 -0
  149. package/util/r-regex.js +19 -1
  150. package/util/range.d.ts +7 -8
  151. package/util/range.js +10 -11
  152. package/util/version.js +1 -1
@@ -3,7 +3,7 @@ import type { Fingerprint } from './fingerprint';
3
3
  import { VisitingQueue } from './visiting-queue';
4
4
  import type { NormalizedAst } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
5
5
  import type { REnvironmentInformation } from '../../dataflow/environments/environment';
6
- import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
6
+ import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
7
  import type { DataflowInformation } from '../../dataflow/info';
8
8
  import type { DataflowGraph } from '../../dataflow/graph/graph';
9
9
  import type { ReadOnlyFlowrAnalyzerContext } from '../../project/context/flowr-analyzer-context';
@@ -8,6 +8,7 @@ const assert_1 = require("../../util/assert");
8
8
  const log_1 = require("../../util/log");
9
9
  const visiting_queue_1 = require("./visiting-queue");
10
10
  const slice_call_1 = require("./slice-call");
11
+ const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
11
12
  const vertex_1 = require("../../dataflow/graph/vertex");
12
13
  const edge_1 = require("../../dataflow/graph/edge");
13
14
  const df_helper_1 = require("../../dataflow/graph/df-helper");
@@ -39,7 +40,7 @@ function staticSlice(options) {
39
40
  graph = df_helper_1.Dataflow.invertGraph(graph, ctx.env.makeCleanEnv());
40
41
  }
41
42
  }
42
- const queue = new visiting_queue_1.VisitingQueue(threshold, cache);
43
+ const queue = new visiting_queue_1.VisitingQueue(threshold, cache, id => graph.hasVertex(id), ctx.gas);
43
44
  let minNesting = Number.MAX_SAFE_INTEGER;
44
45
  const sliceSeedIds = new Set();
45
46
  // every node ships the call environment which registers the calling environment
@@ -139,12 +140,33 @@ function staticSlice(options) {
139
140
  }
140
141
  }
141
142
  const status = queue.status();
142
- if (ctx.config.solver.slicer?.autoExtend) {
143
- return { ...status, slicedFor: ids, result: extendSlices(status.result, idMap) };
144
- }
145
- else {
146
- return { ...status, slicedFor: ids };
143
+ const result = ctx.config.solver.slicer?.autoExtend ? extendSlices(status.result, idMap) : status.result;
144
+ return { ...status, slicedFor: ids, result, freeNames: freeNamesOf(result, info.graph) };
145
+ }
146
+ /**
147
+ * The names the slice reads without defining them: a use whose definitions all stayed outside meets that name
148
+ * undefined, and so does one that reads nothing at all (a name the program never defines). Reading a built-in
149
+ * is no such case, as those are there whatever the slice contains.
150
+ */
151
+ function freeNamesOf(slice, graph) {
152
+ const free = new Set();
153
+ for (const id of slice) {
154
+ if (graph.getVertex(id)?.tag !== vertex_1.VertexType.Use) {
155
+ continue;
156
+ }
157
+ let defined = false;
158
+ for (const [target, edge] of graph.outgoingEdges(id) ?? []) {
159
+ if (edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Reads) && (slice.has(target) || node_id_1.NodeId.isBuiltIn(target))) {
160
+ defined = true;
161
+ break;
162
+ }
163
+ }
164
+ const name = defined ? undefined : (0, node_id_1.recoverName)(id, graph.idMap);
165
+ if (name !== undefined) {
166
+ free.add(name);
167
+ }
147
168
  }
169
+ return [...free].sort();
148
170
  }
149
171
  /**
150
172
  * Computes a program dice: only those nodes reachable forward from `startIds` that are also in the backward slice of `endIds`.
@@ -171,6 +193,7 @@ function staticDice(ctx, info, ast, startIds, endIds, threshold = 75, includeCal
171
193
  timesHitThreshold: forward.timesHitThreshold + backward.timesHitThreshold,
172
194
  result,
173
195
  slicedFor: [...startIds, ...endIds],
196
+ ...(forward.stoppedEarly || backward.stoppedEarly ? { stoppedEarly: true } : {})
174
197
  };
175
198
  }
176
199
  function extendSlices(results, ast) {
@@ -1,8 +1,9 @@
1
1
  import { type Fingerprint } from './fingerprint';
2
2
  import type { NodeToSlice, SliceResult } from './slicer-types';
3
3
  import type { REnvironmentInformation } from '../../dataflow/environments/environment';
4
- import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
4
+ import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
5
5
  import type { DataflowGraphVertexInfo } from '../../dataflow/graph/vertex';
6
+ import type { ReadOnlyFlowrAnalyzerGasContext } from '../../project/context/flowr-analyzer-gas-context';
6
7
  export declare class VisitingQueue {
7
8
  private readonly threshold;
8
9
  private timesHitThreshold;
@@ -13,7 +14,12 @@ export declare class VisitingQueue {
13
14
  private readonly cache?;
14
15
  potentialAdditions: Map<NodeId, [NodeId, NodeToSlice]>;
15
16
  private cachedCallTargets;
16
- constructor(threshold: number, cache?: Map<Fingerprint, Set<NodeId>>);
17
+ /** whether the dataflow graph has a vertex for an id, i.e. whether the traversal could continue from it */
18
+ private readonly isGraphVertex?;
19
+ private readonly gas?;
20
+ private stoppedEarly;
21
+ private untilGasCheck;
22
+ constructor(threshold: number, cache?: Map<Fingerprint, Set<NodeId>>, isGraphVertex?: (id: NodeId) => boolean, gas?: ReadOnlyFlowrAnalyzerGasContext);
17
23
  /**
18
24
  * Adds a node to the queue if it has not been seen before.
19
25
  * @param target - the node to add
@@ -23,8 +29,14 @@ export declare class VisitingQueue {
23
29
  */
24
30
  add(target: NodeId, env: REnvironmentInformation, envFingerprint: string, onlyForSideEffects: boolean): void;
25
31
  next(): NodeToSlice;
32
+ /** Whether there is anything left to visit, which the traversal is out of gas for as soon as it is exhausted. */
26
33
  nonEmpty(): boolean;
34
+ /**
35
+ * The traversal is synchronous, so a caller can only bound it from within. Gas is polled every
36
+ * {@link GasCheckEvery} nodes, which keeps even an enabled check off the per-node path.
37
+ */
38
+ private outOfGas;
27
39
  hasId(id: NodeId): boolean;
28
40
  memoizeCallTargets(id: NodeId, targets: () => Set<DataflowGraphVertexInfo>): Set<DataflowGraphVertexInfo>;
29
- status(): Readonly<Pick<SliceResult, 'timesHitThreshold' | 'result'>>;
41
+ status(): Readonly<Pick<SliceResult, 'timesHitThreshold' | 'result' | 'stoppedEarly'>>;
30
42
  }
@@ -2,6 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VisitingQueue = void 0;
4
4
  const fingerprint_1 = require("./fingerprint");
5
+ const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
6
+ const gas_1 = require("../../gas");
7
+ const static_slicer_1 = require("./static-slicer");
8
+ /** How many nodes the traversal visits between two {@link GasFeatureKey.Slicer|gas} checks. */
9
+ const GasCheckEvery = 512;
5
10
  class VisitingQueue {
6
11
  threshold;
7
12
  timesHitThreshold = 0;
@@ -14,9 +19,16 @@ class VisitingQueue {
14
19
  // additionally it holds which node id added the addition so we can separate their inclusion on the structure
15
20
  potentialAdditions = new Map();
16
21
  cachedCallTargets = new Map();
17
- constructor(threshold, cache) {
22
+ /** whether the dataflow graph has a vertex for an id, i.e. whether the traversal could continue from it */
23
+ isGraphVertex;
24
+ gas;
25
+ stoppedEarly = false;
26
+ untilGasCheck = 0;
27
+ constructor(threshold, cache, isGraphVertex, gas) {
18
28
  this.threshold = threshold;
19
29
  this.cache = cache;
30
+ this.isGraphVertex = isGraphVertex;
31
+ this.gas = gas;
20
32
  }
21
33
  /**
22
34
  * Adds a node to the queue if it has not been seen before.
@@ -26,6 +38,11 @@ class VisitingQueue {
26
38
  * @param onlyForSideEffects - whether the node is only used for its side effects
27
39
  */
28
40
  add(target, env, envFingerprint, onlyForSideEffects) {
41
+ /* a built-in without a vertex is R's own definition (`x <- 1` reads `built-in:<-`), a dead end the traversal
42
+ * would drop right back out of, so it only ever widened the result */
43
+ if (node_id_1.NodeId.isBuiltIn(target) && this.isGraphVertex?.(target) === false) {
44
+ return;
45
+ }
29
46
  const idCounter = this.idThreshold.get(target) ?? 0;
30
47
  if (idCounter > this.threshold) {
31
48
  this.timesHitThreshold++;
@@ -49,8 +66,24 @@ class VisitingQueue {
49
66
  next() {
50
67
  return this.queue.pop();
51
68
  }
69
+ /** Whether there is anything left to visit, which the traversal is out of gas for as soon as it is exhausted. */
52
70
  nonEmpty() {
53
- return this.queue.length > 0;
71
+ return this.queue.length > 0 && !this.outOfGas();
72
+ }
73
+ /**
74
+ * The traversal is synchronous, so a caller can only bound it from within. Gas is polled every
75
+ * {@link GasCheckEvery} nodes, which keeps even an enabled check off the per-node path.
76
+ */
77
+ outOfGas() {
78
+ if (this.gas === undefined || this.untilGasCheck-- > 0) {
79
+ return this.stoppedEarly;
80
+ }
81
+ this.untilGasCheck = GasCheckEvery - 1;
82
+ if (!this.stoppedEarly && this.gas.checkGas(gas_1.GasFeatureKey.Slicer) >= 2 /* GasLevel.Critical */) {
83
+ this.stoppedEarly = true;
84
+ static_slicer_1.slicerLogger.warn(`slicing ran out of gas, the slice is incomplete (${gas_1.GasWikiRef})`);
85
+ }
86
+ return this.stoppedEarly;
54
87
  }
55
88
  hasId(id) {
56
89
  return this.idThreshold.has(id);
@@ -64,7 +97,8 @@ class VisitingQueue {
64
97
  status() {
65
98
  return {
66
99
  timesHitThreshold: this.timesHitThreshold,
67
- result: new Set([...this.seen.values(), ...this.seenByCache])
100
+ result: new Set([...this.seen.values(), ...this.seenByCache]),
101
+ ...(this.stoppedEarly ? { stoppedEarly: true } : {})
68
102
  };
69
103
  }
70
104
  }
@@ -0,0 +1,18 @@
1
+ /** the name of the special `...` parameter which collects everything that finds no formal of its own */
2
+ export declare const DotsParameterName = "...";
3
+ /**
4
+ * Bind the arguments of a call to the formal parameters of the called function, following R's argument matching
5
+ * rules (see https://cran.r-project.org/doc/manuals/R-lang.html#Argument-matching):
6
+ *
7
+ * 1. every named argument that *exactly* matches a formal takes it,
8
+ * 2. every remaining named argument that is a *unique prefix* of a still-free formal takes it (`pmatch`),
9
+ * 3. the remaining unnamed arguments fill the still-free formals from left to right, stopping at `...`
10
+ * (formals behind `...` can only be matched by name), and
11
+ * 4. everything that is still unmatched goes to `...` if the function has one.
12
+ *
13
+ * Both sides are given by their names alone (`undefined` for an unnamed argument or an anonymous formal), so this
14
+ * works for the normalized AST, the dataflow graph, and a plain signature list alike. An empty argument (`f(1, ,3)`)
15
+ * is an unnamed one: it takes its formal like any other, the caller just has nothing to bind to it.
16
+ * @returns for every argument (by index) the index of the parameter it binds to, `undefined` if it stays unbound
17
+ */
18
+ export declare function matchArgumentsToParameters(argNames: readonly (string | undefined)[], paramNames: readonly (string | undefined)[]): readonly (number | undefined)[];
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DotsParameterName = void 0;
4
+ exports.matchArgumentsToParameters = matchArgumentsToParameters;
5
+ const prefix_1 = require("./prefix");
6
+ /** the name of the special `...` parameter which collects everything that finds no formal of its own */
7
+ exports.DotsParameterName = '...';
8
+ /**
9
+ * Bind the arguments of a call to the formal parameters of the called function, following R's argument matching
10
+ * rules (see https://cran.r-project.org/doc/manuals/R-lang.html#Argument-matching):
11
+ *
12
+ * 1. every named argument that *exactly* matches a formal takes it,
13
+ * 2. every remaining named argument that is a *unique prefix* of a still-free formal takes it (`pmatch`),
14
+ * 3. the remaining unnamed arguments fill the still-free formals from left to right, stopping at `...`
15
+ * (formals behind `...` can only be matched by name), and
16
+ * 4. everything that is still unmatched goes to `...` if the function has one.
17
+ *
18
+ * Both sides are given by their names alone (`undefined` for an unnamed argument or an anonymous formal), so this
19
+ * works for the normalized AST, the dataflow graph, and a plain signature list alike. An empty argument (`f(1, ,3)`)
20
+ * is an unnamed one: it takes its formal like any other, the caller just has nothing to bind to it.
21
+ * @returns for every argument (by index) the index of the parameter it binds to, `undefined` if it stays unbound
22
+ */
23
+ function matchArgumentsToParameters(argNames, paramNames) {
24
+ const bound = Array.from(argNames, () => undefined);
25
+ const names = paramNames.map(p => p ?? '');
26
+ const dots = names.indexOf(exports.DotsParameterName);
27
+ const taken = new Set();
28
+ const take = (arg, param) => {
29
+ bound[arg] = param;
30
+ taken.add(param);
31
+ };
32
+ /** binds each still-free named argument to the formal `pick` names for it, as long as that one is still free too */
33
+ const byName = (pick) => {
34
+ for (let i = 0; i < argNames.length; i++) {
35
+ const name = argNames[i];
36
+ if (name === undefined || bound[i] !== undefined) {
37
+ continue;
38
+ }
39
+ const target = pick(name);
40
+ const param = target === undefined ? -1 : names.indexOf(target);
41
+ if (param >= 0 && !taken.has(param)) {
42
+ take(i, param);
43
+ }
44
+ }
45
+ };
46
+ byName(name => name); // (1) exact
47
+ byName(name => (0, prefix_1.findByPrefixIfUnique)(name, names)); // (2) pmatch
48
+ // (3) positional
49
+ let formal = 0;
50
+ for (let i = 0; i < argNames.length; i++) {
51
+ if (argNames[i] !== undefined || bound[i] !== undefined) {
52
+ continue;
53
+ }
54
+ while (taken.has(formal)) {
55
+ formal++;
56
+ }
57
+ if (formal >= names.length || formal === dots) {
58
+ break;
59
+ }
60
+ take(i, formal);
61
+ }
62
+ // (4) `...`
63
+ if (dots >= 0) {
64
+ for (let i = 0; i < argNames.length; i++) {
65
+ bound[i] ??= dots;
66
+ }
67
+ }
68
+ return bound;
69
+ }
70
+ //# sourceMappingURL=arg-matching.js.map
package/util/r-regex.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RPunctuationChars = exports.RStandardRegexp = void 0;
4
4
  exports.parseRRegexPattern = parseRRegexPattern;
5
+ const log_1 = require("./log");
5
6
  /**
6
7
  * Represents R's `.standard_regexps` definitions.
7
8
  * @see https://github.com/r-devel/r-svn/blob/44474af03ae77fd3b9a340279fa10cb698d106c3/src/library/base/R/utils.R#L52-L53
@@ -40,6 +41,10 @@ const PosixClassMap = {
40
41
  print: '\x20-\x7E'
41
42
  };
42
43
  const posixClassRegex = /\[:([a-z]+):]/g;
44
+ /** the flags R accepts inside the pattern (`(?i)foo`), which JavaScript only takes next to it */
45
+ const inlineFlags = /^\(\?([imsx]+)\)/;
46
+ /** what a pattern JavaScript cannot compile falls back to, so one bad pattern matches nothing rather than throwing */
47
+ const matchesNothing = /(?!)/;
43
48
  /**
44
49
  * Converts an R regex pattern (which may include POSIX character classes) into a JavaScript RegExp.
45
50
  */
@@ -52,6 +57,19 @@ function parseRRegexPattern(pattern) {
52
57
  if (convertedPattern.startsWith('*') || convertedPattern.startsWith('+')) {
53
58
  convertedPattern = '.' + convertedPattern;
54
59
  }
55
- return new RegExp(convertedPattern);
60
+ let flags = '';
61
+ const inline = inlineFlags.exec(convertedPattern);
62
+ if (inline) {
63
+ /* `x` (extended) has no counterpart, the others carry over by name */
64
+ flags = inline[1].replaceAll('x', '');
65
+ convertedPattern = convertedPattern.slice(inline[0].length);
66
+ }
67
+ try {
68
+ return new RegExp(convertedPattern, flags);
69
+ }
70
+ catch (e) {
71
+ log_1.log.warn(`R pattern ${JSON.stringify(pattern)} is no JavaScript regex, treating it as matching nothing: ${e.message}`);
72
+ return matchesNothing;
73
+ }
56
74
  }
57
75
  //# sourceMappingURL=r-regex.js.map
package/util/range.d.ts CHANGED
@@ -101,10 +101,8 @@ export declare const SourceRange: {
101
101
  * @returns true iff `r1` starts and ends before `r2` starts (i.e., if `r1` and `r2` do not overlap and `r1` comes before `r2`
102
102
  */
103
103
  readonly startsCompletelyBefore: (this: void, [, , r1el, r1ec]: SourceRange, [r2sl, r2sc, ,]: SourceRange) => boolean;
104
- /**
105
- * Checks if the two ranges overlap.
106
- */
107
- readonly overlap: (this: void, [r1sl, r1sc, r1el, r1ec]: SourceRange, [r2sl, r2sc, r2el, r2ec]: SourceRange) => boolean;
104
+ /** Checks if the two ranges overlap, i.e. whether neither of them lies completely before the other. */
105
+ readonly overlap: (this: void, r1: SourceRange, r2: SourceRange) => boolean;
108
106
  /**
109
107
  * Calculates the component-wise sum of two ranges.
110
108
  */
@@ -169,17 +167,18 @@ export declare const SourceLocation: {
169
167
  * Formats a {@link SourceLocation|source location} as a human-readable string.
170
168
  */
171
169
  readonly format: (this: void, location: SourceLocation | undefined) => string;
170
+ /** Returns the {@link SourceRange|source range} part of a {@link SourceLocation|source location}, file excluded. */
171
+ readonly getRange: (this: void, [sl, sc, el, ec]: SourceLocation) => SourceRange;
172
172
  /**
173
- * Returns the {@link SourceRange|source range} part of a {@link SourceLocation|source location}.
173
+ * Returns the file part of a {@link SourceLocation|source location}, or `undefined` if no file is set.
174
174
  */
175
- readonly getRange: (this: void, location: SourceLocation) => SourceRange;
176
175
  readonly getFile: (this: void, location: SourceLocation) => string | undefined;
177
176
  /**
178
- * Returns the file part of a {@link SourceLocation|source location}, or `undefined` if no file is set.
177
+ * Creates a {@link SourceLocation|source location} from a {@link SourceRange|source range} and a file name.
179
178
  */
180
179
  readonly from: (this: void, range: SourceRange, file?: string) => SourceLocation;
181
180
  /**
182
- * Creates a {@link SourceLocation|source location} from a {@link SourceRange|source range} and a file name.
181
+ * The {@link SourceLocation|source location} of an AST node, file included.
183
182
  * @returns undefined if the given range is undefined
184
183
  * @see {@link SourceRange.fromNode} for getting the range from an AST node
185
184
  */
package/util/range.js CHANGED
@@ -126,11 +126,9 @@ exports.SourceRange = {
126
126
  startsCompletelyBefore([, , r1el, r1ec], [r2sl, r2sc, ,]) {
127
127
  return r1el < r2sl || (r1el === r2sl && r1ec < r2sc);
128
128
  },
129
- /**
130
- * Checks if the two ranges overlap.
131
- */
132
- overlap([r1sl, r1sc, r1el, r1ec], [r2sl, r2sc, r2el, r2ec]) {
133
- return r1sl <= r2el && r2sl <= r1el && r1sc <= r2ec && r2sc <= r1ec;
129
+ /** Checks if the two ranges overlap, i.e. whether neither of them lies completely before the other. */
130
+ overlap(r1, r2) {
131
+ return !exports.SourceRange.startsCompletelyBefore(r1, r2) && !exports.SourceRange.startsCompletelyBefore(r2, r1);
134
132
  },
135
133
  /**
136
134
  * Calculates the component-wise sum of two ranges.
@@ -273,23 +271,24 @@ exports.SourceLocation = {
273
271
  return exports.SourceRange.format(location);
274
272
  }
275
273
  },
274
+ /** Returns the {@link SourceRange|source range} part of a {@link SourceLocation|source location}, file excluded. */
275
+ getRange([sl, sc, el, ec]) {
276
+ return [sl, sc, el, ec];
277
+ },
276
278
  /**
277
- * Returns the {@link SourceRange|source range} part of a {@link SourceLocation|source location}.
279
+ * Returns the file part of a {@link SourceLocation|source location}, or `undefined` if no file is set.
278
280
  */
279
- getRange(location) {
280
- return location;
281
- },
282
281
  getFile(location) {
283
282
  return location[4];
284
283
  },
285
284
  /**
286
- * Returns the file part of a {@link SourceLocation|source location}, or `undefined` if no file is set.
285
+ * Creates a {@link SourceLocation|source location} from a {@link SourceRange|source range} and a file name.
287
286
  */
288
287
  from(range, file) {
289
288
  return file !== undefined ? [...range, file] : range;
290
289
  },
291
290
  /**
292
- * Creates a {@link SourceLocation|source location} from a {@link SourceRange|source range} and a file name.
291
+ * The {@link SourceLocation|source location} of an AST node, file included.
293
292
  * @returns undefined if the given range is undefined
294
293
  * @see {@link SourceRange.fromNode} for getting the range from an AST node
295
294
  */
package/util/version.js CHANGED
@@ -42,7 +42,7 @@ const assert_1 = require("./assert");
42
42
  const sigdb_download_1 = require("../project/sigdb/sigdb-download");
43
43
  const doc_files_1 = require("../documentation/doc-util/doc-files");
44
44
  // this is automatically replaced with the current version by release-it
45
- const version = '2.13.8';
45
+ const version = '2.13.10';
46
46
  // this is automatically replaced with the release date by release-it (regex-bumper, see package.json)
47
47
  const versionDate = '2026-07-15T07:13:44Z';
48
48
  /**