@eagleoutice/flowr 2.13.3 → 2.13.4

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 (67) hide show
  1. package/README.md +11 -11
  2. package/abstract-interpretation/absint-visitor.js +2 -2
  3. package/abstract-interpretation/data-frame/mappers/arguments.js +2 -2
  4. package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +1 -1
  5. package/abstract-interpretation/unsupported-functions.js +1 -1
  6. package/control-flow/cfg-dead-code.js +72 -11
  7. package/control-flow/extract-cfg.js +85 -8
  8. package/control-flow/semantic-cfg-guided-visitor.js +2 -0
  9. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  10. package/dataflow/environments/built-in-proc-name.js +4 -0
  11. package/dataflow/environments/built-in.d.ts +5 -1
  12. package/dataflow/environments/built-in.js +5 -1
  13. package/dataflow/environments/default-builtin-config.d.ts +59 -4
  14. package/dataflow/environments/default-builtin-config.js +23 -11
  15. package/dataflow/environments/identifier.d.ts +1 -0
  16. package/dataflow/eval/resolve/alias-tracking.d.ts +2 -0
  17. package/dataflow/eval/resolve/alias-tracking.js +8 -1
  18. package/dataflow/eval/resolve/resolve.d.ts +14 -0
  19. package/dataflow/eval/resolve/resolve.js +47 -0
  20. package/dataflow/fn/higher-order-function.js +3 -3
  21. package/dataflow/fn/recursive-function.js +1 -1
  22. package/dataflow/graph/df-helper.js +1 -1
  23. package/dataflow/graph/vertex.d.ts +32 -25
  24. package/dataflow/graph/vertex.js +40 -36
  25. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +1 -0
  26. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +7 -4
  27. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +14 -0
  28. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +28 -29
  29. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +41 -48
  30. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +14 -0
  31. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +45 -0
  32. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +7 -1
  33. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +29 -0
  34. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +62 -2
  35. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +63 -16
  36. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +29 -9
  37. package/dataflow/internal/process/functions/call/built-in/built-in-list.d.ts +5 -1
  38. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +35 -0
  39. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +2 -2
  40. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +1 -1
  41. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +2 -0
  42. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +46 -0
  43. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +3 -1
  44. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +24 -0
  45. package/dataflow/internal/process/functions/process-parameter.js +2 -1
  46. package/linter/rules/absolute-path.js +1 -1
  47. package/linter/rules/function-finder-util.js +1 -1
  48. package/linter/rules/no-leaked-credentials.js +1 -1
  49. package/linter/rules/undefined-symbol.js +1 -1
  50. package/linter/rules/unused-definition.js +15 -10
  51. package/linter/rules/useless-loop.js +1 -1
  52. package/package.json +1 -1
  53. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +1 -1
  54. package/queries/catalog/call-context-query/identify-link-to-nested-call-relation.js +1 -1
  55. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  56. package/queries/catalog/dependencies-query/function-info/write-functions.js +23 -24
  57. package/queries/catalog/input-sources-query/input-source-functions.d.ts +2 -1
  58. package/queries/catalog/input-sources-query/input-source-functions.js +14 -20
  59. package/queries/catalog/input-sources-query/input-sources-query-executor.js +11 -6
  60. package/queries/catalog/input-sources-query/input-sources-query-format.js +2 -1
  61. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +14 -1
  62. package/queries/catalog/input-sources-query/simple-input-classifier.js +24 -0
  63. package/r-bridge/data/data.d.ts +2 -2
  64. package/r-bridge/data/data.js +2 -2
  65. package/reconstruct/inline/source-inline-map.js +1 -1
  66. package/util/mermaid/dfg.js +1 -1
  67. package/util/version.js +1 -1
package/README.md CHANGED
@@ -43,7 +43,7 @@ It offers a wide variety of features, for example:
43
43
 
44
44
  ```shell
45
45
  $ docker run -it --rm eagleoutice/flowr # or npm run flowr
46
- flowR repl v2.13.2, R grammar v14 (tree-sitter engine)
46
+ flowR repl v2.13.3, R grammar v14 (tree-sitter engine)
47
47
  R> :query @linter "read.csv(\"/root/x.txt\")"
48
48
  ```
49
49
 
@@ -52,7 +52,7 @@ It offers a wide variety of features, for example:
52
52
 
53
53
 
54
54
  ```text
55
- Query: linter (3 ms)
55
+ Query: linter (4 ms)
56
56
  ╰ Deprecated Functions (deprecated-functions): no findings
57
57
  ╰ File Path Validity (file-path-validity):
58
58
  ╰ certain:
@@ -62,7 +62,7 @@ It offers a wide variety of features, for example:
62
62
  ╰ Absolute Paths (absolute-file-paths):
63
63
  ╰ certain:
64
64
  ╰ Path `/root/x.txt` at 1.1-23
65
- ╰ Metadata: totalConsidered: 1, totalUnknown: 0, searchTimeMs: 0, processTimeMs: 0
65
+ ╰ Metadata: totalConsidered: 1, totalUnknown: 0, searchTimeMs: 1, processTimeMs: 0
66
66
  ╰ Unused Definitions (unused-definitions): no findings
67
67
  ╰ Network Functions (network-functions): no findings
68
68
  ╰ Dataframe Access Validation (dataframe-access-validation): no findings
@@ -73,7 +73,7 @@ It offers a wide variety of features, for example:
73
73
  ╰ Roxygen Arguments (roxygen-arguments): no findings
74
74
  ╰ No Leaked Credentials (no-leaked-credentials): no findings
75
75
  ╰ Undefined Symbol (undefined-symbol): no findings
76
- All queries together required ≈4 ms (1ms accuracy, total 4 ms)
76
+ All queries together required ≈4 ms (1ms accuracy, total 5 ms)
77
77
  ```
78
78
 
79
79
 
@@ -120,7 +120,7 @@ It offers a wide variety of features, for example:
120
120
 
121
121
  <details> <summary style="color:gray">Show Detailed Results as Json</summary>
122
122
 
123
- The analysis required _4.8 ms_ (including parsing and normalization and the query) within the generation environment.
123
+ The analysis required _4.9 ms_ (including parsing and normalization and the query) within the generation environment.
124
124
 
125
125
  In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR.
126
126
  Please consult the [Interface](https://github.com/flowr-analysis/flowr/wiki/Interface) wiki page for more information on how to get those.
@@ -235,14 +235,14 @@ It offers a wide variety of features, for example:
235
235
  ".meta": {
236
236
  "numOfUselessLoops": 0,
237
237
  "searchTimeMs": 0,
238
- "processTimeMs": 0
238
+ "processTimeMs": 1
239
239
  }
240
240
  },
241
241
  "problematic-inputs": {
242
242
  "results": [],
243
243
  ".meta": {
244
244
  "searchTimeMs": 0,
245
- "processTimeMs": 1
245
+ "processTimeMs": 0
246
246
  }
247
247
  },
248
248
  "stop-call": {
@@ -354,7 +354,7 @@ It offers a wide variety of features, for example:
354
354
 
355
355
  ```shell
356
356
  $ docker run -it --rm eagleoutice/flowr # or npm run flowr
357
- flowR repl v2.13.2, R grammar v14 (tree-sitter engine)
357
+ flowR repl v2.13.3, R grammar v14 (tree-sitter engine)
358
358
  R> :query @static-slice (11@sum) file://test/testfiles/example.R
359
359
  ```
360
360
 
@@ -383,7 +383,7 @@ It offers a wide variety of features, for example:
383
383
  </details>
384
384
 
385
385
  * 🚀 **fast call-graph, data-, and control-flow graphs**\
386
- Within just [<i><span title="This measurement is automatically fetched from the latest benchmark!">106.7 ms</span></i> (as of Jul 23, 2026)](https://flowr-analysis.github.io/flowr/wiki/stats/benchmark),
386
+ Within just [<i><span title="This measurement is automatically fetched from the latest benchmark!">101.8 ms</span></i> (as of Jul 25, 2026)](https://flowr-analysis.github.io/flowr/wiki/stats/benchmark),
387
387
  _flowR_ can analyze the data- and control-flow of the average real-world R&nbsp;script. See the [benchmarks](https://flowr-analysis.github.io/flowr/wiki/stats/benchmark) for more information,
388
388
  and consult the [wiki pages](https://github.com/flowr-analysis/flowr/wiki/dataflow-graph) for more details on the [dataflow graphs](https://github.com/flowr-analysis/flowr/wiki/dataflow-graph) as well as [call graphs](https://github.com/flowr-analysis/flowr/wiki/dataflow-graph#perspectives-cg).
389
389
 
@@ -419,7 +419,7 @@ It offers a wide variety of features, for example:
419
419
 
420
420
  ```shell
421
421
  $ docker run -it --rm eagleoutice/flowr # or npm run flowr
422
- flowR repl v2.13.2, R grammar v14 (tree-sitter engine)
422
+ flowR repl v2.13.3, R grammar v14 (tree-sitter engine)
423
423
  R> :dataflow* test/testfiles/example.R
424
424
  ```
425
425
 
@@ -692,7 +692,7 @@ It offers a wide variety of features, for example:
692
692
  ```
693
693
 
694
694
 
695
- (The analysis required _1.9 ms_ (including parse and normalize, using the [tree-sitter](https://github.com/flowr-analysis/flowr/wiki/Engines) engine) within the generation environment. No [signature database](https://github.com/flowr-analysis/flowr/wiki/Signature-Database) is mounted for these generated graphs, so `library()` calls attach no package exports; base-R names are still qualified via the generated base-package store (e.g. `acf` as `stats::acf`).)
695
+ (The analysis required _1.6 ms_ (including parse and normalize, using the [tree-sitter](https://github.com/flowr-analysis/flowr/wiki/Engines) engine) within the generation environment. No [signature database](https://github.com/flowr-analysis/flowr/wiki/Signature-Database) is mounted for these generated graphs, so `library()` calls attach no package exports; base-R names are still qualified via the generated base-package store (e.g. `acf` as `stats::acf`).)
696
696
 
697
697
 
698
698
 
@@ -62,7 +62,7 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
62
62
  return state.get(node.info.id);
63
63
  }
64
64
  const vertex = this.getDataflowGraph(node.info.id);
65
- const call = (0, vertex_1.isFunctionCallVertex)(vertex) ? vertex : undefined;
65
+ const call = vertex_1.FunctionCallVertex.is(vertex) ? vertex : undefined;
66
66
  const origins = Array.isArray(call?.origin) ? call.origin : [];
67
67
  if (node.type === type_1.RType.Symbol) {
68
68
  const values = this.getVariableOrigins(node.info.id)
@@ -189,7 +189,7 @@ class AbstractInterpretationVisitor extends semantic_cfg_guided_visitor_1.Semant
189
189
  this.replacements.delete(nodeId);
190
190
  for (const replacement of replacements) {
191
191
  const call = this.getDataflowGraph(replacement);
192
- if ((0, vertex_1.isFunctionCallVertex)(call)) {
192
+ if (vertex_1.FunctionCallVertex.is(call)) {
193
193
  this.onReplacementCall({ call, ...this.getSourceAndTarget(call) });
194
194
  }
195
195
  }
@@ -121,7 +121,7 @@ function getFunctionArgument(args, argument, info) {
121
121
  */
122
122
  function getFunctionArguments(node, dfg) {
123
123
  const vertex = dfg.getVertex(node.info.id);
124
- if ((0, vertex_1.isFunctionCallVertex)(vertex) && dfg.idMap !== undefined) {
124
+ if (vertex_1.FunctionCallVertex.is(vertex) && dfg.idMap !== undefined) {
125
125
  const idMap = dfg.idMap;
126
126
  return vertex.args
127
127
  .map(arg => graph_1.FunctionArgument.isEmpty(arg) ? arg : idMap.get(arg.nodeId))
@@ -145,7 +145,7 @@ function getUnresolvedSymbolsInExpression(expression, dfg) {
145
145
  const vertex = dfg.get(node.info.id);
146
146
  const symbolName = identifier_1.Identifier.mapName(node.content, resolve_args_1.unquoteArgument);
147
147
  // ignore symbols named ".", as they are used as argument placeholder in magrittr pipe operations
148
- if ((0, vertex_1.isUseVertex)(vertex?.[0]) && vertex[1].size === 0 && symbolName !== '.') {
148
+ if (vertex_1.UseVertex.is(vertex?.[0]) && vertex[1].size === 0 && symbolName !== '.') {
149
149
  unresolvedSymbols.push(symbolName);
150
150
  }
151
151
  }
@@ -60,7 +60,7 @@ function isDataFrameReplacement(functionName) {
60
60
  }
61
61
  function hasParentReplacement(node, dfg) {
62
62
  const parentVertex = node.info.parent ? dfg.getVertex(node.info.parent) : undefined;
63
- return (0, vertex_1.isFunctionCallVertex)(parentVertex) && parentVertex.origin.includes(built_in_proc_name_1.BuiltInProcName.Replacement);
63
+ return vertex_1.FunctionCallVertex.is(parentVertex) && parentVertex.origin.includes(built_in_proc_name_1.BuiltInProcName.Replacement);
64
64
  }
65
65
  function mapDataFrameContentAssignment(access, expression, inference) {
66
66
  const dataFrame = access.accessed;
@@ -45,7 +45,7 @@ exports.UnsupportedFunctions = {
45
45
  * Checks whether a data flow graph vertex represents an unsupported (environment-changing) function call (e.g. `eval`, `load`, `attach`, `rm`, ...)
46
46
  */
47
47
  isUnsupportedCall(vertex, dfg) {
48
- if (!(0, vertex_1.isFunctionCallVertex)(vertex)) {
48
+ if (!vertex_1.FunctionCallVertex.is(vertex)) {
49
49
  return false;
50
50
  }
51
51
  const entry = UnsupportedFunctionsList.find(entry => identifier_1.Identifier.matches(vertex.name, entry.identifier));
@@ -4,7 +4,10 @@ exports.cfgAnalyzeDeadCode = cfgAnalyzeDeadCode;
4
4
  const control_flow_graph_1 = require("./control-flow-graph");
5
5
  const logic_1 = require("../util/logic");
6
6
  const semantic_cfg_guided_visitor_1 = require("./semantic-cfg-guided-visitor");
7
+ const vertex_1 = require("../dataflow/graph/vertex");
8
+ const graph_1 = require("../dataflow/graph/graph");
7
9
  const alias_tracking_1 = require("../dataflow/eval/resolve/alias-tracking");
10
+ const built_in_proc_name_1 = require("../dataflow/environments/built-in-proc-name");
8
11
  const log_1 = require("../util/log");
9
12
  const r_function_call_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
10
13
  const general_1 = require("../dataflow/eval/values/general");
@@ -14,7 +17,8 @@ const convert_values_1 = require("../r-bridge/lang-4.x/convert-values");
14
17
  class CfgConditionalDeadCodeRemoval extends semantic_cfg_guided_visitor_1.SemanticCfgGuidedVisitor {
15
18
  cachedConditions = new Map();
16
19
  cachedStatements = new Map();
17
- inTry = new Set();
20
+ cachedSwitch = new Map();
21
+ jumpIsolated = new Set();
18
22
  getValue(id) {
19
23
  const has = this.cachedConditions.get(id);
20
24
  if (has) {
@@ -24,7 +28,7 @@ class CfgConditionalDeadCodeRemoval extends semantic_cfg_guided_visitor_1.Semant
24
28
  return this.cachedConditions.get(id) ?? logic_1.Ternary.Maybe;
25
29
  }
26
30
  isUnconditionalJump(id) {
27
- if (this.inTry.has(id)) {
31
+ if (this.jumpIsolated.has(id)) {
28
32
  return false;
29
33
  }
30
34
  const has = this.cachedStatements.get(id);
@@ -45,7 +49,12 @@ class CfgConditionalDeadCodeRemoval extends semantic_cfg_guided_visitor_1.Semant
45
49
  for (const [from, targets] of cfg.edges()) {
46
50
  for (const [target, edge] of targets) {
47
51
  if (control_flow_graph_1.CfgEdge.isControlDependency(edge)) {
48
- const og = this.getValue(control_flow_graph_1.CfgEdge.unpackCause(edge));
52
+ const cause = control_flow_graph_1.CfgEdge.unpackCause(edge);
53
+ if (this.switchArmDefinitelyNotTaken(cause, from)) {
54
+ cfg.removeEdge(from, target);
55
+ continue;
56
+ }
57
+ const og = this.getValue(cause);
49
58
  const w = control_flow_graph_1.CfgEdge.unpackWhen(edge);
50
59
  if (og === logic_1.Ternary.Always && w === convert_values_1.RFalse) {
51
60
  cfg.removeEdge(from, target);
@@ -126,21 +135,73 @@ class CfgConditionalDeadCodeRemoval extends semantic_cfg_guided_visitor_1.Semant
126
135
  this.cachedStatements.set(data.call.id, !arg);
127
136
  }
128
137
  }
138
+ protectSubgraph(nodeId) {
139
+ const start = this.getCfgVertex(nodeId);
140
+ if (!start) {
141
+ return;
142
+ }
143
+ (0, simple_visitor_1.visitCfgInOrder)(this.config.controlFlow.graph, [control_flow_graph_1.CfgVertex.getId(start)], n => {
144
+ if (control_flow_graph_1.CfgVertex.getEnd(start)?.includes(n)) {
145
+ return true;
146
+ }
147
+ this.jumpIsolated.add(n);
148
+ return false;
149
+ });
150
+ }
129
151
  onTryCall(data) {
130
152
  if (data.call.args.length < 1 || data.call.args[0] === r_function_call_1.EmptyArgument) {
131
153
  return;
132
154
  }
133
- const body = this.getCfgVertex(data.call.args[0].nodeId);
134
- if (!body) {
135
- return;
155
+ this.protectSubgraph(data.call.args[0].nodeId);
156
+ }
157
+ switchArmDefinitelyNotTaken(cause, from) {
158
+ const v = this.config.dfg.getVertex(cause);
159
+ if (!vertex_1.FunctionCallVertex.is(v) || !v.origin.includes(built_in_proc_name_1.BuiltInProcName.Switch)) {
160
+ return false;
136
161
  }
137
- (0, simple_visitor_1.visitCfgInOrder)(this.config.controlFlow.graph, [control_flow_graph_1.CfgVertex.getId(body)], n => {
138
- if (control_flow_graph_1.CfgVertex.getEnd(body)?.includes(n)) {
139
- return true;
140
- }
141
- this.inTry.add(n);
162
+ const selected = this.selectedSwitchArm(v);
163
+ if (selected === 'unknown') {
142
164
  return false;
165
+ }
166
+ const isArm = v.args.slice(1).some(a => graph_1.FunctionArgument.getReference(a) !== undefined && graph_1.FunctionArgument.getId(a) === from);
167
+ return isArm && from !== selected.id;
168
+ }
169
+ selectedSwitchArm(v) {
170
+ const cached = this.cachedSwitch.get(v.id);
171
+ if (cached !== undefined) {
172
+ return cached;
173
+ }
174
+ const result = this.computeSelectedSwitchArm(v);
175
+ this.cachedSwitch.set(v.id, result);
176
+ return result;
177
+ }
178
+ computeSelectedSwitchArm(v) {
179
+ const target = (0, alias_tracking_1.resolveIdToSingleString)(graph_1.FunctionArgument.getReference(v.args[0]), {
180
+ graph: this.config.dfg, full: true, idMap: this.config.normalizedAst.idMap, resolve: this.config.ctx.config.solver.variables, ctx: this.config.ctx
143
181
  });
182
+ if (target === undefined) {
183
+ return 'unknown';
184
+ }
185
+ const arms = v.args.slice(1);
186
+ for (let i = 0; i < arms.length; i++) {
187
+ if (graph_1.FunctionArgument.getName(arms[i]) === target) {
188
+ for (let j = i; j < arms.length; j++) {
189
+ if (graph_1.FunctionArgument.getReference(arms[j]) !== undefined) {
190
+ return { id: graph_1.FunctionArgument.getId(arms[j]) };
191
+ }
192
+ }
193
+ return { id: undefined };
194
+ }
195
+ }
196
+ let defaultId;
197
+ let defaults = 0;
198
+ for (const arm of arms) {
199
+ if (arm !== r_function_call_1.EmptyArgument && !graph_1.FunctionArgument.isNamed(arm) && graph_1.FunctionArgument.getReference(arm) !== undefined) {
200
+ defaults++;
201
+ defaultId = graph_1.FunctionArgument.getId(arm);
202
+ }
203
+ }
204
+ return defaults > 1 ? 'unknown' : { id: defaultId };
144
205
  }
145
206
  }
146
207
  /** Breaks unsatisfiable control dependencies */
@@ -13,6 +13,7 @@ const vertex_1 = require("../dataflow/graph/vertex");
13
13
  const control_flow_graph_1 = require("./control-flow-graph");
14
14
  const cfg_simplification_1 = require("./cfg-simplification");
15
15
  const assert_1 = require("../util/assert");
16
+ const type_1 = require("../r-bridge/lang-4.x/ast/model/type");
16
17
  const stateful_fold_1 = require("../r-bridge/lang-4.x/ast/model/processing/stateful-fold");
17
18
  const model_1 = require("../r-bridge/lang-4.x/ast/model/model");
18
19
  const built_in_proc_name_1 = require("../dataflow/environments/built-in-proc-name");
@@ -99,7 +100,7 @@ function getCallsInCfg(cfg, graph) {
99
100
  const calls = new Map();
100
101
  for (const vertexId of cfg.graph.vertices().keys()) {
101
102
  const vertex = graph.getVertex(vertexId);
102
- if ((0, vertex_1.isFunctionCallVertex)(vertex)) {
103
+ if (vertex_1.FunctionCallVertex.is(vertex)) {
103
104
  calls.set(vertexId, vertex);
104
105
  }
105
106
  }
@@ -333,10 +334,6 @@ function cfgFunctionDefinition(fn, params, body) {
333
334
  return { graph: graph, breaks: [], nexts: [], returns: [], exitPoints: [fnId], entryPoints: [fnId] };
334
335
  }
335
336
  function cfgFunctionCall(call, name, args, down) {
336
- if (call.named && call.functionName.content === 'ifelse' && args.length > 1) {
337
- // special built-in handling for ifelse as it is an expression that does not short-circuit
338
- return cfgIfThenElse(call, args[0] === r_function_call_1.EmptyArgument ? (0, control_flow_graph_1.emptyControlFlowInformation)() : args[0], args[1] === r_function_call_1.EmptyArgument ? (0, control_flow_graph_1.emptyControlFlowInformation)() : args[1], args[2] === r_function_call_1.EmptyArgument ? (0, control_flow_graph_1.emptyControlFlowInformation)() : args[2]);
339
- }
340
337
  const callId = call.info.id;
341
338
  const graph = name.graph;
342
339
  const info = {
@@ -380,6 +377,72 @@ function cfgFunctionCall(call, name, args, down) {
380
377
  // should not contain any breaks, nexts, or returns, (except for the body if something like 'break()')
381
378
  return info;
382
379
  }
380
+ function cfgSwitch(call, name, args) {
381
+ const callId = call.info.id;
382
+ const exitId = control_flow_graph_1.CfgVertex.toExitId(callId);
383
+ const graph = name.graph;
384
+ const info = {
385
+ graph,
386
+ breaks: Array.from(name.breaks),
387
+ nexts: Array.from(name.nexts),
388
+ returns: Array.from(name.returns),
389
+ exitPoints: [exitId],
390
+ entryPoints: [callId]
391
+ };
392
+ graph.addVertex(control_flow_graph_1.CfgVertex.makeExprOrStm(callId, identifyMayStatementType(call), { mid: name.exitPoints, end: [exitId] }));
393
+ graph.addVertex(control_flow_graph_1.CfgVertex.makeExitMarker(callId));
394
+ for (const entry of name.entryPoints) {
395
+ graph.addEdge(entry, callId, control_flow_graph_1.CfgEdge.makeFd());
396
+ }
397
+ let selectorExits = name.exitPoints;
398
+ const selector = args[0];
399
+ if (selector !== undefined && selector !== r_function_call_1.EmptyArgument) {
400
+ graph.mergeWith(selector.graph);
401
+ info.breaks = info.breaks.concat(selector.breaks);
402
+ info.nexts = info.nexts.concat(selector.nexts);
403
+ info.returns = info.returns.concat(selector.returns);
404
+ for (const entry of selector.entryPoints) {
405
+ for (const exit of name.exitPoints) {
406
+ graph.addEdge(entry, exit, control_flow_graph_1.CfgEdge.makeFd());
407
+ }
408
+ }
409
+ selectorExits = selector.exitPoints;
410
+ }
411
+ const cd = control_flow_graph_1.CfgEdge.makeCdTrue(callId);
412
+ for (const arm of args.slice(1)) {
413
+ if (arm === r_function_call_1.EmptyArgument) {
414
+ continue;
415
+ }
416
+ graph.mergeWith(arm.graph);
417
+ info.breaks = info.breaks.concat(arm.breaks);
418
+ info.nexts = info.nexts.concat(arm.nexts);
419
+ info.returns = info.returns.concat(arm.returns);
420
+ for (const entry of arm.entryPoints) {
421
+ for (const exit of selectorExits) {
422
+ graph.addEdge(entry, exit, cd);
423
+ }
424
+ }
425
+ for (const exit of arm.exitPoints) {
426
+ graph.addEdge(exitId, exit, control_flow_graph_1.CfgEdge.makeFd());
427
+ }
428
+ }
429
+ const hasDefault = call.arguments.slice(1).some(a => a !== r_function_call_1.EmptyArgument && a.name === undefined);
430
+ if (!hasDefault) {
431
+ for (const exit of selectorExits) {
432
+ graph.addEdge(exitId, exit, control_flow_graph_1.CfgEdge.makeCdFalse(callId));
433
+ }
434
+ }
435
+ return info;
436
+ }
437
+ // on.exit defers its expr, so seal a return/break/next inside it from escaping into enclosing control flow
438
+ function cfgRegisterHook(call, name, args, down) {
439
+ const base = cfgFunctionCall(call, name, args, down);
440
+ const exitId = control_flow_graph_1.CfgVertex.toExitId(call.info.id);
441
+ for (const escape of base.returns.concat(base.breaks, base.nexts)) {
442
+ base.graph.addEdge(exitId, escape, control_flow_graph_1.CfgEdge.makeFd());
443
+ }
444
+ return { ...base, returns: [], breaks: [], nexts: [], exitPoints: base.exitPoints.length > 0 ? base.exitPoints : [exitId] };
445
+ }
383
446
  exports.ResolvedCallSuffix = control_flow_graph_1.CfgVertex.toExitId('-resolved-call');
384
447
  const OriginToFoldTypeMap = {
385
448
  [built_in_proc_name_1.BuiltInProcName.IfThenElse]: (folds, call, args, down) => {
@@ -392,10 +455,18 @@ function cfgFunctionCallWithDataflow(graph, folds) {
392
455
  return (call, name, args, down) => {
393
456
  const vtx = graph.getVertex(call.info.id);
394
457
  if (vtx?.tag === vertex_1.VertexType.FunctionCall && vtx.onlyBuiltin && vtx.origin.length === 1) {
395
- const mayMap = OriginToFoldTypeMap[vtx.origin[0]];
396
- if (mayMap) {
458
+ const origin = vtx.origin[0];
459
+ const mayMap = OriginToFoldTypeMap[origin];
460
+ // ifelse/fifelse/if_else share the IfThenElse origin but are eager calls, so only fold a real `if` node
461
+ if (mayMap && call.type === type_1.RType.IfThenElse) {
397
462
  return mayMap(folds, call, args, down, vtx);
398
463
  }
464
+ if (origin === built_in_proc_name_1.BuiltInProcName.Switch) {
465
+ return cfgSwitch(call, name, args);
466
+ }
467
+ if (origin === built_in_proc_name_1.BuiltInProcName.RegisterHook) {
468
+ return cfgRegisterHook(call, name, args, down);
469
+ }
399
470
  }
400
471
  const baseCfg = cfgFunctionCall(call, name, args, down);
401
472
  /* try to resolve the call and link the target definitions */
@@ -405,7 +476,7 @@ function cfgFunctionCallWithDataflow(graph, folds) {
405
476
  (0, assert_1.guard)(callVertex !== undefined, 'cfgFunctionCallWithDataflow: call vertex not found');
406
477
  for (const target of targets) {
407
478
  // we have to filter out non-func-call targets as the call targets contains names and call ids
408
- if ((0, vertex_1.isFunctionDefinitionVertex)(graph.getVertex(target))) {
479
+ if (vertex_1.FunctionDefinitionVertex.is(graph.getVertex(target))) {
409
480
  const ct = control_flow_graph_1.CfgVertex.getCallTargets(callVertex);
410
481
  if (!ct) {
411
482
  control_flow_graph_1.CfgVertex.setCallTargets(callVertex, new Set([target]));
@@ -485,6 +556,12 @@ function cfgBinaryOp(binOp, lhs, rhs) {
485
556
  for (const exitPoint of rhs.exitPoints) {
486
557
  graph.addEdge(binExit, exitPoint, fd);
487
558
  }
559
+ // `&&`/`||` short-circuit: the exit stays reachable via the lhs even when the rhs jumps
560
+ if (binOp.type === type_1.RType.BinaryOp && (binOp.operator === '&&' || binOp.operator === '||')) {
561
+ for (const exitPoint of lhs.exitPoints) {
562
+ graph.addEdge(binExit, exitPoint, fd);
563
+ }
564
+ }
488
565
  return result;
489
566
  }
490
567
  function cfgAccess(access, name, accessors) {
@@ -263,7 +263,9 @@ class SemanticCfgGuidedVisitor extends dfg_cfg_guided_visitor_1.DataflowAwareCfg
263
263
  case built_in_proc_name_1.BuiltInProcName.Function:
264
264
  case built_in_proc_name_1.BuiltInProcName.FunctionDefinition:
265
265
  case built_in_proc_name_1.BuiltInProcName.S7MakeConstructor:
266
+ case built_in_proc_name_1.BuiltInProcName.ClassGenerator:
266
267
  case built_in_proc_name_1.BuiltInProcName.DefineArgument:
268
+ case built_in_proc_name_1.BuiltInProcName.Switch:
267
269
  return this.onDefaultFunctionCall({ call });
268
270
  case built_in_proc_name_1.BuiltInProcName.Load:
269
271
  return this.onLoadCall({ call });
@@ -86,6 +86,8 @@ export declare enum BuiltInProcName {
86
86
  StackEnv = "builtin:stack-env",
87
87
  /** for `stop` calls */
88
88
  Stop = "builtin:stop",
89
+ /** for `switch` calls */
90
+ Switch = "builtin:switch",
89
91
  /** for `stopifnot` calls, see {@link processStopIfNot} */
90
92
  StopIfNot = "builtin:stopifnot",
91
93
  /** support for `:=` in subsetting assignments, see {@link processAccess} */
@@ -96,6 +98,8 @@ export declare enum BuiltInProcName {
96
98
  Attach = "builtin:attach",
97
99
  /** for `new.env` and related environment-creation calls, see {@link processNewEnv} */
98
100
  NewEnv = "builtin:nenv",
101
+ /** for `R6Class`/`setRefClass` class generators whose methods back `$new()`-instance dispatch */
102
+ ClassGenerator = "builtin:class-gen",
99
103
  /** for unnamed directly-linked function calls */
100
104
  Unnamed = "unnamed",
101
105
  /** for vector construction calls, see {@link processVector} */
@@ -90,6 +90,8 @@ var BuiltInProcName;
90
90
  BuiltInProcName["StackEnv"] = "builtin:stack-env";
91
91
  /** for `stop` calls */
92
92
  BuiltInProcName["Stop"] = "builtin:stop";
93
+ /** for `switch` calls */
94
+ BuiltInProcName["Switch"] = "builtin:switch";
93
95
  /** for `stopifnot` calls, see {@link processStopIfNot} */
94
96
  BuiltInProcName["StopIfNot"] = "builtin:stopifnot";
95
97
  /** support for `:=` in subsetting assignments, see {@link processAccess} */
@@ -100,6 +102,8 @@ var BuiltInProcName;
100
102
  BuiltInProcName["Attach"] = "builtin:attach";
101
103
  /** for `new.env` and related environment-creation calls, see {@link processNewEnv} */
102
104
  BuiltInProcName["NewEnv"] = "builtin:nenv";
105
+ /** for `R6Class`/`setRefClass` class generators whose methods back `$new()`-instance dispatch */
106
+ BuiltInProcName["ClassGenerator"] = "builtin:class-gen";
103
107
  /** for unnamed directly-linked function calls */
104
108
  BuiltInProcName["Unnamed"] = "unnamed";
105
109
  /** for vector construction calls, see {@link processVector} */
@@ -30,7 +30,7 @@ import { processRm } from '../internal/process/functions/call/built-in/built-in-
30
30
  import { processEvalCall } from '../internal/process/functions/call/built-in/built-in-eval';
31
31
  import type { REnvironmentInformation } from './environment';
32
32
  import type { Value } from '../eval/values/r-value';
33
- import { resolveAsMinus, resolveAsPlus, resolveAsSeq, resolveAsVector } from '../eval/resolve/resolve';
33
+ import { resolveAsMinus, resolveAsPaste, resolveAsPlus, resolveAsSeq, resolveAsVector } from '../eval/resolve/resolve';
34
34
  import type { DataflowGraph } from '../graph/graph';
35
35
  import type { VariableResolve } from '../../config';
36
36
  import type { BuiltInConstantDefinition, BuiltInDefinition, BuiltInFunctionDefinition, BuiltInReplacementDefinition } from './built-in-config';
@@ -46,6 +46,7 @@ import { processS7Dispatch } from '../internal/process/functions/call/built-in/b
46
46
  import { BuiltInProcName } from './built-in-proc-name';
47
47
  import { processPurrrFormula } from '../internal/process/functions/call/built-in/built-in-purrr-formula';
48
48
  import { processNewEnv } from '../internal/process/functions/call/built-in/built-in-new-env';
49
+ import { processClassGenerator } from '../internal/process/functions/call/built-in/built-in-class-generator';
49
50
  import { processStackEnv } from '../internal/process/functions/call/built-in/built-in-stack-env';
50
51
  import { processAttach } from '../internal/process/functions/call/built-in/built-in-attach';
51
52
  import { processWithEnv } from '../internal/process/functions/call/built-in/built-in-with';
@@ -135,6 +136,7 @@ export declare const BuiltInProcessorMapper: {
135
136
  readonly "builtin:try": typeof processTryCatch;
136
137
  readonly "builtin:attach": typeof processAttach;
137
138
  readonly "builtin:nenv": typeof processNewEnv;
139
+ readonly "builtin:class-gen": typeof processClassGenerator;
138
140
  readonly "builtin:stack-env": typeof processStackEnv;
139
141
  readonly "builtin:with": typeof processWithEnv;
140
142
  readonly "builtin:vector": typeof processVector;
@@ -145,6 +147,8 @@ export declare const BuiltInEvalHandlerMapper: {
145
147
  readonly 'built-in::': typeof resolveAsSeq;
146
148
  readonly 'built-in:+': typeof resolveAsPlus;
147
149
  readonly 'built-in:-': typeof resolveAsMinus;
150
+ readonly 'built-in:paste': typeof resolveAsPaste;
151
+ readonly 'built-in:paste0': typeof resolveAsPaste;
148
152
  };
149
153
  export type ConfigOfBuiltInMappingName<N extends keyof typeof BuiltInProcessorMapper> = Parameters<typeof BuiltInProcessorMapper[N]>[4];
150
154
  export type BuiltInMemory = Map<BrandedIdentifier, IdentifierDefinition[]>;
@@ -43,6 +43,7 @@ const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
43
43
  const built_in_proc_name_1 = require("./built-in-proc-name");
44
44
  const built_in_purrr_formula_1 = require("../internal/process/functions/call/built-in/built-in-purrr-formula");
45
45
  const built_in_new_env_1 = require("../internal/process/functions/call/built-in/built-in-new-env");
46
+ const built_in_class_generator_1 = require("../internal/process/functions/call/built-in/built-in-class-generator");
46
47
  const built_in_stack_env_1 = require("../internal/process/functions/call/built-in/built-in-stack-env");
47
48
  const built_in_attach_1 = require("../internal/process/functions/call/built-in/built-in-attach");
48
49
  const built_in_with_1 = require("../internal/process/functions/call/built-in/built-in-with");
@@ -163,6 +164,7 @@ exports.BuiltInProcessorMapper = {
163
164
  [built_in_proc_name_1.BuiltInProcName.Try]: built_in_try_catch_1.processTryCatch,
164
165
  [built_in_proc_name_1.BuiltInProcName.Attach]: built_in_attach_1.processAttach,
165
166
  [built_in_proc_name_1.BuiltInProcName.NewEnv]: built_in_new_env_1.processNewEnv,
167
+ [built_in_proc_name_1.BuiltInProcName.ClassGenerator]: built_in_class_generator_1.processClassGenerator,
166
168
  [built_in_proc_name_1.BuiltInProcName.StackEnv]: built_in_stack_env_1.processStackEnv,
167
169
  [built_in_proc_name_1.BuiltInProcName.With]: built_in_with_1.processWithEnv,
168
170
  [built_in_proc_name_1.BuiltInProcName.Vector]: built_in_vector_1.processVector,
@@ -172,7 +174,9 @@ exports.BuiltInEvalHandlerMapper = {
172
174
  'built-in:c': resolve_1.resolveAsVector,
173
175
  'built-in::': resolve_1.resolveAsSeq,
174
176
  'built-in:+': resolve_1.resolveAsPlus,
175
- 'built-in:-': resolve_1.resolveAsMinus
177
+ 'built-in:-': resolve_1.resolveAsMinus,
178
+ 'built-in:paste': resolve_1.resolveAsPaste,
179
+ 'built-in:paste0': resolve_1.resolveAsPaste
176
180
  };
177
181
  class BuiltIns {
178
182
  /**