@eagleoutice/flowr 2.10.4 → 2.10.6

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 (115) hide show
  1. package/README.md +31 -14
  2. package/abstract-interpretation/absint-visitor.d.ts +17 -22
  3. package/abstract-interpretation/absint-visitor.js +47 -48
  4. package/abstract-interpretation/data-frame/dataframe-domain.d.ts +0 -3
  5. package/abstract-interpretation/data-frame/shape-inference.d.ts +2 -1
  6. package/abstract-interpretation/data-frame/shape-inference.js +5 -4
  7. package/abstract-interpretation/domains/abstract-domain.d.ts +17 -16
  8. package/abstract-interpretation/domains/abstract-domain.js +25 -27
  9. package/abstract-interpretation/domains/bounded-set-domain.js +1 -1
  10. package/abstract-interpretation/domains/multi-value-state-domain.d.ts +32 -0
  11. package/abstract-interpretation/domains/multi-value-state-domain.js +60 -0
  12. package/abstract-interpretation/domains/partial-product-domain.d.ts +43 -0
  13. package/abstract-interpretation/domains/partial-product-domain.js +163 -0
  14. package/abstract-interpretation/domains/product-domain.d.ts +2 -29
  15. package/abstract-interpretation/domains/product-domain.js +6 -123
  16. package/abstract-interpretation/domains/set-range-domain.js +3 -3
  17. package/abstract-interpretation/domains/set-upper-bound-domain.js +1 -1
  18. package/abstract-interpretation/domains/singleton-domain.js +1 -1
  19. package/abstract-interpretation/domains/state-abstract-domain.d.ts +13 -28
  20. package/abstract-interpretation/domains/state-abstract-domain.js +16 -38
  21. package/abstract-interpretation/domains/state-domain-like.d.ts +36 -0
  22. package/abstract-interpretation/domains/state-domain-like.js +3 -0
  23. package/cli/flowr.js +11 -1
  24. package/config.d.ts +13 -0
  25. package/config.js +24 -3
  26. package/control-flow/basic-cfg-guided-visitor.d.ts +1 -1
  27. package/control-flow/semantic-cfg-guided-visitor.d.ts +4 -0
  28. package/control-flow/semantic-cfg-guided-visitor.js +23 -32
  29. package/dataflow/environments/built-in-proc-name.d.ts +7 -1
  30. package/dataflow/environments/built-in-proc-name.js +6 -0
  31. package/dataflow/environments/built-in.d.ts +6 -0
  32. package/dataflow/environments/built-in.js +6 -0
  33. package/dataflow/environments/default-builtin-config.d.ts +63 -1
  34. package/dataflow/environments/default-builtin-config.js +15 -4
  35. package/dataflow/environments/identifier.d.ts +14 -0
  36. package/dataflow/graph/vertex.d.ts +6 -0
  37. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +16 -0
  38. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +6 -0
  39. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +99 -2
  40. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +13 -0
  41. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +48 -0
  42. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +75 -0
  43. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +196 -0
  44. package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +2 -0
  45. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +38 -21
  46. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +5 -0
  47. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +27 -13
  48. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +14 -4
  49. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.d.ts +27 -0
  50. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +97 -0
  51. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +23 -0
  52. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +90 -0
  53. package/documentation/doc-readme.js +13 -2
  54. package/documentation/doc-util/doc-types.d.ts +11 -2
  55. package/documentation/doc-util/doc-types.js +31 -9
  56. package/documentation/wiki-absint.d.ts +17 -2
  57. package/documentation/wiki-absint.js +83 -24
  58. package/documentation/wiki-analyzer.js +3 -4
  59. package/documentation/wiki-interface.js +22 -16
  60. package/documentation/wiki-mk/doc-context.d.ts +14 -1
  61. package/documentation/wiki-mk/doc-context.js +6 -0
  62. package/documentation/wiki-normalized-ast.d.ts +0 -9
  63. package/documentation/wiki-normalized-ast.js +9 -60
  64. package/linter/linter-rules.d.ts +4 -3
  65. package/linter/rules/problematic-inputs.d.ts +13 -7
  66. package/linter/rules/problematic-inputs.js +109 -60
  67. package/package.json +3 -3
  68. package/project/flowr-analyzer-builder.d.ts +6 -3
  69. package/project/flowr-analyzer-builder.js +12 -5
  70. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +4 -3
  71. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +17 -4
  72. package/project/plugins/flowr-analyzer-plugin.d.ts +1 -1
  73. package/project/plugins/flowr-analyzer-plugin.js +1 -1
  74. package/queries/catalog/dependencies-query/function-info/read-functions.js +2 -0
  75. package/queries/catalog/dependencies-query/function-info/write-functions.js +1 -0
  76. package/queries/catalog/input-sources-query/input-source-functions.d.ts +7 -0
  77. package/queries/catalog/input-sources-query/input-source-functions.js +56 -0
  78. package/queries/catalog/input-sources-query/input-sources-query-executor.d.ts +1 -1
  79. package/queries/catalog/input-sources-query/input-sources-query-executor.js +19 -53
  80. package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +2 -1
  81. package/queries/catalog/input-sources-query/input-sources-query-format.js +28 -11
  82. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +21 -42
  83. package/queries/catalog/input-sources-query/simple-input-classifier.js +168 -104
  84. package/r-bridge/data/data.d.ts +28 -2
  85. package/r-bridge/data/data.js +34 -2
  86. package/r-bridge/lang-4.x/ast/model/model.d.ts +5 -6
  87. package/r-bridge/lang-4.x/ast/model/model.js +0 -1
  88. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +6 -6
  89. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +6 -6
  90. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +6 -6
  91. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +6 -6
  92. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +6 -6
  93. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +6 -6
  94. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +6 -6
  95. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +6 -6
  96. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +6 -6
  97. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +6 -6
  98. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +6 -6
  99. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +6 -6
  100. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +6 -6
  101. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +6 -6
  102. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +6 -6
  103. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +6 -6
  104. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +6 -6
  105. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +6 -6
  106. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +6 -6
  107. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +6 -6
  108. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +6 -6
  109. package/util/record.d.ts +18 -3
  110. package/util/record.js +22 -1
  111. package/util/version.js +1 -1
  112. package/abstract-interpretation/normalized-ast-fold.d.ts +0 -119
  113. package/abstract-interpretation/normalized-ast-fold.js +0 -181
  114. package/project/plugins/flowr-analyzer-plugin-defaults.d.ts +0 -5
  115. package/project/plugins/flowr-analyzer-plugin-defaults.js +0 -37
@@ -21,6 +21,12 @@ export interface AssignmentConfiguration extends ForceArguments {
21
21
  readonly targetVariable?: boolean;
22
22
  readonly mayHaveMoreArgs?: boolean;
23
23
  readonly modesForFn?: DataflowGraphVertexFunctionDefinition['mode'];
24
+ /**
25
+ * The name of the argument that selects the target environment (e.g. `'envir'` for `assign`).
26
+ * When present and the argument resolves to a variable with a tracked {@link InGraphIdentifierDefinition#envState},
27
+ * the assignment is routed into that environment instead of the current scope.
28
+ */
29
+ readonly environmentArg?: string;
24
30
  }
25
31
  export interface ExtendedAssignmentConfiguration extends AssignmentConfiguration {
26
32
  readonly source: {
@@ -18,12 +18,14 @@ const vertex_1 = require("../../../../../graph/vertex");
18
18
  const define_1 = require("../../../../../environments/define");
19
19
  const edge_1 = require("../../../../../graph/edge");
20
20
  const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
21
+ const built_in_envir_utils_1 = require("./built-in-envir-utils");
21
22
  const named_call_handling_1 = require("../named-call-handling");
22
23
  const built_in_1 = require("../../../../../environments/built-in");
23
24
  const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
24
25
  const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
25
26
  const r_value_1 = require("../../../../../eval/values/r-value");
26
27
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
28
+ const built_in_new_env_1 = require("./built-in-new-env");
27
29
  function toReplacementSymbol(target, prefix, superAssignment) {
28
30
  return {
29
31
  type: type_1.RType.Symbol,
@@ -104,6 +106,13 @@ args, rootId, data, config) {
104
106
  logger_1.dataflowLogger.warn(`Assignment ${identifier_1.Identifier.toString(name.content)} has something else than 2 arguments, skipping`);
105
107
  return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, forceArgs: config.forceArgs, origin: 'default' }).information;
106
108
  }
109
+ /* route into a custom environment when envir resolves to a tracked env variable */
110
+ if (config.environmentArg) {
111
+ const routed = tryRouteToCustomEnv(name, args, rootId, data, config);
112
+ if (routed !== undefined) {
113
+ return routed;
114
+ }
115
+ }
107
116
  const effectiveArgs = getEffectiveOrder(config, args);
108
117
  const { target, source } = extractSourceAndTarget(effectiveArgs);
109
118
  if (target === undefined || source === undefined) {
@@ -172,6 +181,10 @@ args, rootId, data, config) {
172
181
  else if (config.canBeReplacement && type === type_1.RType.Access) {
173
182
  logger_1.dataflowLogger.debug(`Assignment ${identifier_1.Identifier.toString(name.content)} has an access-type node as target ==> replacement function ${target.lexeme}`);
174
183
  const replacement = toReplacementSymbol(target, target.operator, config.superAssignment ?? false);
184
+ const envRouted = tryRouteDollarEnvAssign(rootId, data, config, target, source, replacement);
185
+ if (envRouted !== undefined) {
186
+ return envRouted;
187
+ }
175
188
  return tryReplacement(rootId, replacement, data, replacement.content, [(0, make_argument_1.toUnnamedArgument)(target.accessed, data.completeAst.idMap), ...target.access, source]);
176
189
  }
177
190
  else if (type === type_1.RType.Access) {
@@ -241,11 +254,12 @@ function processAssignmentToString(target, args, name, rootId, data, config, sou
241
254
  lexeme: target.lexeme,
242
255
  location: target.location,
243
256
  };
244
- // treat first argument to Symbol
257
+ // treat first argument to Symbol; include extra args (e.g. envir=) so they get graph vertices
258
+ const extraArgs = config.mayHaveMoreArgs ? Array.from(args).slice(2) : [];
245
259
  const mappedArgs = config.swapSourceAndTarget ? [args[0], {
246
260
  ...args[1],
247
261
  value: symbol
248
- }] : [{ ...args[0], value: symbol }, args[1]];
262
+ }, ...extraArgs] : [{ ...args[0], value: symbol }, args[1], ...extraArgs];
249
263
  const res = (0, known_call_handling_1.processKnownFunctionCall)({
250
264
  name,
251
265
  args: mappedArgs,
@@ -286,6 +300,74 @@ function checkTargetReferenceType(sourceInfo, fnModes) {
286
300
  return identifier_1.ReferenceType.Variable;
287
301
  }
288
302
  }
303
+ /**
304
+ * Returns `true` when the entry-point of `sourceInfo` is a call to a `new.env`-family function.
305
+ * Used by {@link processAssignmentToSymbol} to attach an initial {@link InGraphIdentifierDefinition#envState}.
306
+ */
307
+ function isEnvCreatorSource(sourceInfo) {
308
+ const vert = sourceInfo.graph.getVertex(sourceInfo.entryPoint);
309
+ return (0, vertex_1.isFunctionCallVertex)(vert) && vert.origin.includes(built_in_proc_name_1.BuiltInProcName.NewEnv);
310
+ }
311
+ /**
312
+ * When `e$x <- val` and `e` holds a tracked {@link InGraphIdentifierDefinition#envState},
313
+ * adds the field `x` into that envState instead of redefining the whole `e` object.
314
+ * Returns `undefined` when routing is not applicable.
315
+ */
316
+ function tryRouteDollarEnvAssign(rootId, data, config, target, source, replacement) {
317
+ if (target.operator !== '$' || target.accessed.type !== type_1.RType.Symbol) {
318
+ return undefined;
319
+ }
320
+ const envirResolution = (0, built_in_envir_utils_1.resolveSymbolToEnvir)(target.accessed.content, target.accessed.info.id, data);
321
+ if (!envirResolution) {
322
+ return undefined;
323
+ }
324
+ const fieldNode = (0, unpack_argument_1.unpackArg)(target.access[0]);
325
+ if (!fieldNode) {
326
+ return undefined;
327
+ }
328
+ const fieldName = (fieldNode.type === type_1.RType.String ? fieldNode.content.str : fieldNode.lexeme);
329
+ /* run normal $<- replacement to get correct graph structure (reads of e, x, source) */
330
+ const normalResult = tryReplacement(rootId, replacement, data, replacement.content, [(0, make_argument_1.toUnnamedArgument)(target.accessed, data.completeAst.idMap), ...target.access, source]);
331
+ const fieldDef = {
332
+ type: identifier_1.ReferenceType.Variable,
333
+ name: fieldName,
334
+ nodeId: fieldNode.info.id,
335
+ definedAt: rootId,
336
+ cds: data.cds
337
+ };
338
+ const newEnvState = (0, define_1.define)(fieldDef, false, envirResolution.envDef.envState);
339
+ const updatedEnvDef = {
340
+ ...envirResolution.envDef,
341
+ definedAt: rootId,
342
+ envState: newEnvState
343
+ };
344
+ const strippedEnv = {
345
+ current: normalResult.environment.current.removeAll([{ name: envirResolution.envDef.name }]),
346
+ level: normalResult.environment.level
347
+ };
348
+ return { ...normalResult, environment: (0, define_1.define)(updatedEnvDef, false, strippedEnv) };
349
+ }
350
+ /**
351
+ * When `config.environmentArg` identifies an `envir`-like parameter (e.g. `'envir'` for `assign`)
352
+ * and that argument resolves to a variable with a tracked {@link InGraphIdentifierDefinition#envState},
353
+ * this function routes the written definitions into that custom environment instead of the current
354
+ * global scope.
355
+ * @returns `undefined` if routing is not possible
356
+ */
357
+ function tryRouteToCustomEnv(name, args, rootId, data, config) {
358
+ const resolution = (0, built_in_envir_utils_1.resolveEnvirArg)(args, data, config.environmentArg);
359
+ if (!resolution) {
360
+ return undefined;
361
+ }
362
+ /* run the normal assignment path to get the correct graph structure */
363
+ const normalResult = processAssignment(name, args, rootId, data, {
364
+ ...config,
365
+ environmentArg: undefined // prevent re-entry
366
+ });
367
+ normalResult.graph.addEdge(rootId, resolution.envirNodeId, edge_1.EdgeType.Reads);
368
+ /* pass rootId as definedAt so only defs made at this call site are routed */
369
+ return (0, built_in_envir_utils_1.routeWrittenToCustomEnv)(normalResult, resolution.envDef, rootId, rootId);
370
+ }
289
371
  /**
290
372
  * Consider a call like `x <- v`
291
373
  * @param information - the information to define the assignment within
@@ -331,6 +413,21 @@ function processAssignmentToSymbol(config) {
331
413
  value: aliases
332
414
  }]
333
415
  : produceWrittenNodes(rootId, targetArg, referenceType, data, makeMaybe ?? false, aliases);
416
+ if (data.ctx.config.solver.trackEnvironments) {
417
+ let envState;
418
+ if (isEnvCreatorSource(sourceArg)) {
419
+ envState = (0, built_in_new_env_1.createFreshEnvState)(data, sourceArg);
420
+ }
421
+ else if (source.type === type_1.RType.Symbol) {
422
+ const defs = (0, resolve_by_name_1.resolveByName)(source.content, data.environment, identifier_1.ReferenceType.Variable);
423
+ envState = defs?.find(d => d.envState !== undefined)?.envState;
424
+ }
425
+ if (envState) {
426
+ for (let i = 0; i < writeNodes.length; i++) {
427
+ writeNodes[i] = { ...writeNodes[i], envState };
428
+ }
429
+ }
430
+ }
334
431
  if (writeNodes.length !== 1 && log_1.log.settings.minLevel >= 4 /* LogLevel.Warn */) {
335
432
  log_1.log.warn(`Unexpected write number in assignment: ${JSON.stringify(writeNodes)}`);
336
433
  }
@@ -0,0 +1,13 @@
1
+ import type { DataflowProcessorInformation } from '../../../../../processor';
2
+ import type { DataflowInformation } from '../../../../../info';
3
+ import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
4
+ import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
5
+ import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
6
+ import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
+ /**
8
+ * Processes `attach(what, ...)` - when `what` is a variable that holds a tracked
9
+ * {@link InGraphIdentifierDefinition#envState}, all statically-known definitions from
10
+ * that environment are injected into the current scope so that subsequent reads of
11
+ * those names resolve correctly.
12
+ */
13
+ export declare function processAttach<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processAttach = processAttach;
4
+ const known_call_handling_1 = require("../known-call-handling");
5
+ const unpack_argument_1 = require("../argument/unpack-argument");
6
+ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
7
+ const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
8
+ const identifier_1 = require("../../../../../environments/identifier");
9
+ const define_1 = require("../../../../../environments/define");
10
+ const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
11
+ const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
12
+ const edge_1 = require("../../../../../graph/edge");
13
+ const built_in_envir_utils_1 = require("./built-in-envir-utils");
14
+ /**
15
+ * Processes `attach(what, ...)` - when `what` is a variable that holds a tracked
16
+ * {@link InGraphIdentifierDefinition#envState}, all statically-known definitions from
17
+ * that environment are injected into the current scope so that subsequent reads of
18
+ * those names resolve correctly.
19
+ */
20
+ function processAttach(name, args, rootId, data) {
21
+ const result = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.Attach }).information;
22
+ const whatArg = args.length >= 1 ? args[0] : undefined;
23
+ const whatNode = whatArg && whatArg !== r_function_call_1.EmptyArgument ? (0, unpack_argument_1.unpackArg)(whatArg) : undefined;
24
+ if (whatNode?.type !== type_1.RType.Symbol) {
25
+ (0, unknown_side_effect_1.handleUnknownSideEffect)(result.graph, result.environment, rootId);
26
+ return result;
27
+ }
28
+ const envirResolution = (0, built_in_envir_utils_1.resolveSymbolToEnvir)(whatNode.content, whatNode.info.id, data);
29
+ if (!envirResolution) {
30
+ (0, unknown_side_effect_1.handleUnknownSideEffect)(result.graph, result.environment, rootId);
31
+ return result;
32
+ }
33
+ let newEnvironment = result.environment;
34
+ for (const [varName, varDefs] of envirResolution.envDef.envState.current.memory) {
35
+ for (const varDef of varDefs) {
36
+ const inDef = varDef;
37
+ const injected = {
38
+ ...inDef,
39
+ name: varName,
40
+ type: identifier_1.ReferenceType.Variable,
41
+ };
42
+ newEnvironment = (0, define_1.define)(injected, false, newEnvironment);
43
+ result.graph.addEdge(inDef.nodeId, rootId, edge_1.EdgeType.Reads);
44
+ }
45
+ }
46
+ return { ...result, environment: newEnvironment };
47
+ }
48
+ //# sourceMappingURL=built-in-attach.js.map
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Shared utilities for built-in functions that interact with tracked R environments.
3
+ *
4
+ * - {@link bindArgs} - bind call arguments to formal parameter names using R's matching rules.
5
+ * - {@link resolveArgToEnvir} - resolve a single already-found argument to an {@link EnvirResolution}.
6
+ * - {@link resolveEnvirArg} / {@link resolveSymbolToEnvir} - resolve a named argument or
7
+ * symbol to an {@link EnvirResolution} when it holds a tracked {@link InGraphIdentifierDefinition#envState}.
8
+ * - {@link routeWrittenToCustomEnv} - move written definitions from the caller's scope into
9
+ * the holder variable's `envState` after processing an expression that writes into a custom env.
10
+ */
11
+ import type { DataflowProcessorInformation } from '../../../../../processor';
12
+ import type { DataflowInformation } from '../../../../../info';
13
+ import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
14
+ import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
15
+ import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
16
+ import type { Identifier, NamedInGraphIdentifierDefinition } from '../../../../../environments/identifier';
17
+ import type { REnvironmentInformation } from '../../../../../environments/environment';
18
+ /** Result type for a successful envir-argument resolution. */
19
+ export interface EnvirResolution<OtherInfo> {
20
+ /** `data` with its `environment` replaced by the resolved `envState` for in-env lookups. */
21
+ readonly envirData: DataflowProcessorInformation<OtherInfo & ParentInformation>;
22
+ /** The definition of the variable that holds the environment */
23
+ readonly envDef: NamedInGraphIdentifierDefinition & {
24
+ envState: REnvironmentInformation;
25
+ };
26
+ /** Node ID of the USE of the envir variable (e.g. the `e` in `envir=e`). */
27
+ readonly envirNodeId: NodeId;
28
+ }
29
+ /**
30
+ * Binds call arguments to formal parameter names following R's standard matching rules:
31
+ * 1. Exact name matches (named args bound to exact-matching formal params).
32
+ * 2. Partial (pmatch) name matches via {@link findByPrefixIfUnique}.
33
+ * 3. Remaining unnamed args fill remaining unbound formal params left-to-right.
34
+ *
35
+ * Pass `paramNames` as the full formal parameter list (excluding `...`) so ambiguous
36
+ * prefixes are rejected correctly. Use this when multiple formals must be found
37
+ * simultaneously so that named-arg binding is consistent across all formals.
38
+ */
39
+ export declare function bindArgs<OtherInfo>(args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], paramNames: readonly string[]): ReadonlyMap<string, PotentiallyEmptyRArgument<OtherInfo & ParentInformation>>;
40
+ /**
41
+ * Resolves a single already-found argument (e.g. from {@link bindArgs}) to an
42
+ * {@link EnvirResolution} when the argument is a symbol that holds a tracked envState.
43
+ * Returns `undefined` when the arg is empty, non-symbolic, or unresolved.
44
+ */
45
+ export declare function resolveArgToEnvir<OtherInfo>(arg: PotentiallyEmptyRArgument<OtherInfo & ParentInformation>, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): EnvirResolution<OtherInfo> | undefined;
46
+ /**
47
+ * Scans `args` for an argument named `argName` (default `'envir'`), or - when
48
+ * `positionalFallbackIndex` is given - for the arg at that positional index when
49
+ * no named match is found. When the resolved argument is a symbol that resolves
50
+ * to a variable with a tracked {@link InGraphIdentifierDefinition#envState},
51
+ * returns the resolved context; otherwise returns `undefined`.
52
+ *
53
+ * Named matching uses pmatch semantics: pass `allParamNames` (the full formal parameter
54
+ * list) so ambiguous prefixes are rejected. Defaults to `[argName]`, which allows
55
+ * prefix matches for `argName` only.
56
+ *
57
+ * When multiple formals must be matched simultaneously (e.g. `data` and `expr` in `with`),
58
+ * use {@link bindArgs} + {@link resolveArgToEnvir} instead so named binding is consistent.
59
+ */
60
+ export declare function resolveEnvirArg<OtherInfo>(args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], data: DataflowProcessorInformation<OtherInfo & ParentInformation>, argName?: string, positionalFallbackIndex?: number, allParamNames?: readonly string[]): EnvirResolution<OtherInfo> | undefined;
61
+ /**
62
+ * Resolves a symbol by name to an {@link EnvirResolution} when the symbol holds a tracked
63
+ * environment. Handles multiple reaching definitions (e.g. from if/else branches) by
64
+ * merging their envStates - see {@link resolveDefsToEnvirResolution}.
65
+ * Returns `undefined` when the name cannot be resolved or none of its definitions carry an envState.
66
+ */
67
+ export declare function resolveSymbolToEnvir<OtherInfo>(symbolName: Identifier, nodeId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): EnvirResolution<OtherInfo> | undefined;
68
+ /**
69
+ * After processing an expression that writes into a custom environment, moves the
70
+ * written definitions from the caller's scope into `envDef`'s tracked `envState`
71
+ * and re-defines the holder variable in the returned environment.
72
+ */
73
+ export declare function routeWrittenToCustomEnv(result: DataflowInformation, envDef: NamedInGraphIdentifierDefinition & {
74
+ envState: REnvironmentInformation;
75
+ }, newDefAt: NodeId, definedAt?: NodeId): DataflowInformation;
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bindArgs = bindArgs;
4
+ exports.resolveArgToEnvir = resolveArgToEnvir;
5
+ exports.resolveEnvirArg = resolveEnvirArg;
6
+ exports.resolveSymbolToEnvir = resolveSymbolToEnvir;
7
+ exports.routeWrittenToCustomEnv = routeWrittenToCustomEnv;
8
+ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
9
+ const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
10
+ const unpack_argument_1 = require("../argument/unpack-argument");
11
+ const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
12
+ const identifier_1 = require("../../../../../environments/identifier");
13
+ const define_1 = require("../../../../../environments/define");
14
+ const prefix_1 = require("../../../../../../util/prefix");
15
+ /**
16
+ * Core resolver: maps a list of identifier definitions (from {@link resolveByName}) to an
17
+ * {@link EnvirResolution}. Accepts `undefined` so callers can pass `resolveByName` results
18
+ * directly without an intermediate null check.
19
+ *
20
+ * Multiple reaching definitions (e.g. from if/else branches) are accepted only when every
21
+ * definition carries an envState; their envStates are merged into a single combined snapshot.
22
+ */
23
+ function resolveDefsToEnvirResolution(defs, nodeId, data) {
24
+ if (!defs || defs.length === 0) {
25
+ return undefined;
26
+ }
27
+ const inDefs = defs;
28
+ if (inDefs.length === 1) {
29
+ const envState = inDefs[0].envState;
30
+ if (!envState) {
31
+ return undefined;
32
+ }
33
+ const envDef = inDefs[0];
34
+ return { envirData: { ...data, environment: envState }, envDef, envirNodeId: nodeId };
35
+ }
36
+ if (!inDefs.every(d => d.envState !== undefined)) {
37
+ return undefined;
38
+ }
39
+ let mergedEnvState = inDefs[0].envState;
40
+ for (let i = 1; i < inDefs.length; i++) {
41
+ for (const [, varDefs] of inDefs[i].envState.current.memory) {
42
+ for (const varDef of varDefs) {
43
+ const named = varDef;
44
+ if (named.name !== undefined) {
45
+ mergedEnvState = (0, define_1.define)(named, false, mergedEnvState);
46
+ }
47
+ }
48
+ }
49
+ }
50
+ const envDef = {
51
+ ...inDefs[0],
52
+ envState: mergedEnvState
53
+ };
54
+ return { envirData: { ...data, environment: mergedEnvState }, envDef, envirNodeId: nodeId };
55
+ }
56
+ /**
57
+ * Binds call arguments to formal parameter names following R's standard matching rules:
58
+ * 1. Exact name matches (named args bound to exact-matching formal params).
59
+ * 2. Partial (pmatch) name matches via {@link findByPrefixIfUnique}.
60
+ * 3. Remaining unnamed args fill remaining unbound formal params left-to-right.
61
+ *
62
+ * Pass `paramNames` as the full formal parameter list (excluding `...`) so ambiguous
63
+ * prefixes are rejected correctly. Use this when multiple formals must be found
64
+ * simultaneously so that named-arg binding is consistent across all formals.
65
+ */
66
+ function bindArgs(args, paramNames) {
67
+ const bound = new Map();
68
+ const used = new Set();
69
+ /* pass 1: exact name matches */
70
+ for (let i = 0; i < args.length; i++) {
71
+ const arg = args[i];
72
+ if (arg === r_function_call_1.EmptyArgument || arg.name === undefined) {
73
+ continue;
74
+ }
75
+ const n = arg.name.content;
76
+ if (paramNames.includes(n) && !bound.has(n)) {
77
+ bound.set(n, arg);
78
+ used.add(i);
79
+ }
80
+ }
81
+ /* pass 2: partial (pmatch) name matches */
82
+ for (let i = 0; i < args.length; i++) {
83
+ if (used.has(i)) {
84
+ continue;
85
+ }
86
+ const arg = args[i];
87
+ if (arg === r_function_call_1.EmptyArgument || arg.name === undefined) {
88
+ continue;
89
+ }
90
+ const matched = (0, prefix_1.findByPrefixIfUnique)(arg.name.content, paramNames);
91
+ if (matched !== undefined && !bound.has(matched)) {
92
+ bound.set(matched, arg);
93
+ used.add(i);
94
+ }
95
+ }
96
+ /* pass 3: remaining unnamed args fill remaining formal params left-to-right */
97
+ let formalIdx = 0;
98
+ for (let i = 0; i < args.length; i++) {
99
+ if (used.has(i)) {
100
+ continue;
101
+ }
102
+ const arg = args[i];
103
+ if (arg === r_function_call_1.EmptyArgument || arg.name !== undefined) {
104
+ continue;
105
+ }
106
+ while (formalIdx < paramNames.length && bound.has(paramNames[formalIdx])) {
107
+ formalIdx++;
108
+ }
109
+ if (formalIdx < paramNames.length) {
110
+ bound.set(paramNames[formalIdx], arg);
111
+ used.add(i);
112
+ formalIdx++;
113
+ }
114
+ }
115
+ return bound;
116
+ }
117
+ /**
118
+ * Resolves a single already-found argument (e.g. from {@link bindArgs}) to an
119
+ * {@link EnvirResolution} when the argument is a symbol that holds a tracked envState.
120
+ * Returns `undefined` when the arg is empty, non-symbolic, or unresolved.
121
+ */
122
+ function resolveArgToEnvir(arg, data) {
123
+ if (arg === r_function_call_1.EmptyArgument) {
124
+ return undefined;
125
+ }
126
+ const node = (0, unpack_argument_1.unpackArg)(arg);
127
+ if (node?.type !== type_1.RType.Symbol) {
128
+ return undefined;
129
+ }
130
+ return resolveDefsToEnvirResolution((0, resolve_by_name_1.resolveByName)(node.content, data.environment, identifier_1.ReferenceType.Variable), node.info.id, data);
131
+ }
132
+ /**
133
+ * Scans `args` for an argument named `argName` (default `'envir'`), or - when
134
+ * `positionalFallbackIndex` is given - for the arg at that positional index when
135
+ * no named match is found. When the resolved argument is a symbol that resolves
136
+ * to a variable with a tracked {@link InGraphIdentifierDefinition#envState},
137
+ * returns the resolved context; otherwise returns `undefined`.
138
+ *
139
+ * Named matching uses pmatch semantics: pass `allParamNames` (the full formal parameter
140
+ * list) so ambiguous prefixes are rejected. Defaults to `[argName]`, which allows
141
+ * prefix matches for `argName` only.
142
+ *
143
+ * When multiple formals must be matched simultaneously (e.g. `data` and `expr` in `with`),
144
+ * use {@link bindArgs} + {@link resolveArgToEnvir} instead so named binding is consistent.
145
+ */
146
+ function resolveEnvirArg(args, data, argName = 'envir', positionalFallbackIndex, allParamNames = [argName]) {
147
+ /* named pass: pmatch against the full parameter list */
148
+ for (const arg of args) {
149
+ if (arg === r_function_call_1.EmptyArgument || arg.name === undefined) {
150
+ continue;
151
+ }
152
+ if ((0, prefix_1.findByPrefixIfUnique)(arg.name.content, allParamNames) === argName) {
153
+ return resolveArgToEnvir(arg, data);
154
+ }
155
+ }
156
+ /* positional fallback (only when no named match existed) */
157
+ if (positionalFallbackIndex !== undefined) {
158
+ let pos = 0;
159
+ for (const arg of args) {
160
+ if (arg === r_function_call_1.EmptyArgument || arg.name !== undefined) {
161
+ continue;
162
+ }
163
+ if (pos === positionalFallbackIndex) {
164
+ return resolveArgToEnvir(arg, data);
165
+ }
166
+ pos++;
167
+ }
168
+ }
169
+ return undefined;
170
+ }
171
+ /**
172
+ * Resolves a symbol by name to an {@link EnvirResolution} when the symbol holds a tracked
173
+ * environment. Handles multiple reaching definitions (e.g. from if/else branches) by
174
+ * merging their envStates - see {@link resolveDefsToEnvirResolution}.
175
+ * Returns `undefined` when the name cannot be resolved or none of its definitions carry an envState.
176
+ */
177
+ function resolveSymbolToEnvir(symbolName, nodeId, data) {
178
+ return resolveDefsToEnvirResolution((0, resolve_by_name_1.resolveByName)(symbolName, data.environment, identifier_1.ReferenceType.Variable), nodeId, data);
179
+ }
180
+ /**
181
+ * After processing an expression that writes into a custom environment, moves the
182
+ * written definitions from the caller's scope into `envDef`'s tracked `envState`
183
+ * and re-defines the holder variable in the returned environment.
184
+ */
185
+ function routeWrittenToCustomEnv(result, envDef, newDefAt, definedAt) {
186
+ const written = result.out.filter((d) => d.name !== undefined && 'definedAt' in d &&
187
+ (definedAt === undefined || d.definedAt === definedAt));
188
+ let newEnvState = envDef.envState;
189
+ const namesToRemove = written.map(w => ({ name: w.name }));
190
+ for (const w of written) {
191
+ newEnvState = (0, define_1.define)(w, false, newEnvState);
192
+ }
193
+ const newEnvironment = (0, define_1.define)({ ...envDef, definedAt: newDefAt, envState: newEnvState }, false, { current: result.environment.current.removeAll(namesToRemove), level: result.environment.level });
194
+ return { ...result, environment: newEnvironment };
195
+ }
196
+ //# sourceMappingURL=built-in-envir-utils.js.map
@@ -10,4 +10,6 @@ import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/proce
10
10
  export declare function processEvalCall<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, config: {
11
11
  /** should this produce an explicit source function call in the graph? */
12
12
  includeFunctionCall?: boolean;
13
+ /** if selected processes evalText function call, else processes eval*/
14
+ supportFunctionCall?: boolean;
13
15
  }): DataflowInformation;
@@ -40,7 +40,7 @@ function processEvalCall(name, args, rootId, data, config) {
40
40
  (0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
41
41
  return information;
42
42
  }
43
- const code = resolveEvalToCode(evalArgument.value, data.environment, data.completeAst.idMap, data.ctx);
43
+ const code = resolveEvalToCode(evalArgument.value, config, data);
44
44
  if (code) {
45
45
  const idGenerator = (0, decorate_1.sourcedDeterministicCountingIdGenerator)(name.lexeme + '::' + rootId, name.location);
46
46
  data = {
@@ -73,35 +73,52 @@ function processEvalCall(name, args, rootId, data, config) {
73
73
  (0, unknown_side_effect_1.handleUnknownSideEffect)(information.graph, information.environment, rootId);
74
74
  return information;
75
75
  }
76
- function resolveEvalToCode(evalArgument, env, idMap, ctx) {
76
+ function resolveEvalToCode(evalArgument, config, data) {
77
+ const ctx = data.ctx;
78
+ const env = data.environment;
79
+ const idMap = data.completeAst.idMap;
77
80
  const val = evalArgument;
78
- if (val.type === type_1.RType.FunctionCall && val.named && val.functionName.content === 'parse') {
79
- const arg = val.arguments.find(v => v !== r_function_call_1.EmptyArgument && v.name?.content === 'text');
80
- const nArg = val.arguments.find(v => v !== r_function_call_1.EmptyArgument && v.name?.content === 'n');
81
- if (nArg !== undefined || arg === undefined || arg === r_function_call_1.EmptyArgument) {
82
- return undefined;
83
- }
84
- if (arg.value?.type === type_1.RType.String) {
85
- return [arg.value.content.str];
81
+ if (config.supportFunctionCall) {
82
+ if (val.type === type_1.RType.String) {
83
+ return [val.content.str];
86
84
  }
87
- else if (arg.value?.type === type_1.RType.Symbol) {
88
- const resolved = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(arg.value.info.id, { environment: env, idMap: idMap, resolve: ctx.config.solver.variables, ctx }));
85
+ else if (val.type === type_1.RType.Symbol) {
86
+ const resolved = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(val.info.id, { environment: env, idMap: idMap, resolve: ctx.config.solver.variables, ctx }));
89
87
  if (resolved) {
90
88
  return (0, string_constants_1.collectStrings)(resolved.elements);
91
89
  }
92
90
  }
93
- else if (arg.value?.type === type_1.RType.FunctionCall && arg.value.named && ['paste', 'paste0'].includes(identifier_1.Identifier.getName(arg.value.functionName.content))) {
94
- return handlePaste(ctx.config, arg.value.arguments, env, idMap, arg.value.functionName.content === 'paste' ? [' '] : [''], ctx);
95
- }
96
- return undefined;
97
- }
98
- else if (val.type === type_1.RType.Symbol) {
99
- // const resolved = resolveValueOfVariable(val.content, env);
100
- // see https://github.com/flowr-analysis/flowr/pull/1467
101
91
  return undefined;
102
92
  }
103
93
  else {
104
- return undefined;
94
+ if (val.type === type_1.RType.FunctionCall && val.named && val.functionName.content === 'parse') {
95
+ const arg = val.arguments.find(v => v !== r_function_call_1.EmptyArgument && v.name?.content === 'text');
96
+ const nArg = val.arguments.find(v => v !== r_function_call_1.EmptyArgument && v.name?.content === 'n');
97
+ if (nArg !== undefined || arg === undefined || arg === r_function_call_1.EmptyArgument) {
98
+ return undefined;
99
+ }
100
+ if (arg.value?.type === type_1.RType.String) {
101
+ return [arg.value.content.str];
102
+ }
103
+ else if (arg.value?.type === type_1.RType.Symbol) {
104
+ const resolved = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(arg.value.info.id, { environment: env, idMap: idMap, resolve: ctx.config.solver.variables, ctx }));
105
+ if (resolved) {
106
+ return (0, string_constants_1.collectStrings)(resolved.elements);
107
+ }
108
+ }
109
+ else if (arg.value?.type === type_1.RType.FunctionCall && arg.value.named && ['paste', 'paste0'].includes(identifier_1.Identifier.getName(arg.value.functionName.content))) {
110
+ return handlePaste(ctx.config, arg.value.arguments, env, idMap, arg.value.functionName.content === 'paste' ? [' '] : [''], ctx);
111
+ }
112
+ return undefined;
113
+ }
114
+ else if (val.type === type_1.RType.Symbol) {
115
+ // const resolved = resolveValueOfVariable(val.content, env);
116
+ // see https://github.com/flowr-analysis/flowr/pull/1467
117
+ return undefined;
118
+ }
119
+ else {
120
+ return undefined;
121
+ }
105
122
  }
106
123
  }
107
124
  function getAsString(config, val, env, idMap, ctx) {
@@ -6,5 +6,10 @@ import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/node
6
6
  import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
7
  /**
8
8
  * Processes a built-in 'get' function call.
9
+ *
10
+ * When an `envir` argument is present and resolves to a variable with a tracked environment
11
+ * state (set up by `new.env()` + `assign(..., envir=...)`), the lookup is performed inside
12
+ * that environment so that the correct definition is found and the returned {@link DataflowInformation}
13
+ * contains the right read edges.
9
14
  */
10
15
  export declare function processGet<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;