@eagleoutice/flowr 2.10.5 → 2.10.7

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 (113) hide show
  1. package/README.md +21 -21
  2. package/abstract-interpretation/absint-visitor.d.ts +1 -2
  3. package/abstract-interpretation/domains/state-domain-like.d.ts +2 -2
  4. package/config.d.ts +6 -0
  5. package/config.js +2 -0
  6. package/control-flow/basic-cfg-guided-visitor.d.ts +1 -1
  7. package/control-flow/semantic-cfg-guided-visitor.js +4 -0
  8. package/dataflow/environments/built-in-proc-name.d.ts +27 -19
  9. package/dataflow/environments/built-in-proc-name.js +27 -19
  10. package/dataflow/environments/built-in.d.ts +24 -18
  11. package/dataflow/environments/built-in.js +6 -0
  12. package/dataflow/environments/default-builtin-config.d.ts +53 -1
  13. package/dataflow/environments/default-builtin-config.js +13 -3
  14. package/dataflow/environments/identifier.d.ts +19 -0
  15. package/dataflow/environments/reference-to-maybe.js +32 -6
  16. package/dataflow/eval/resolve/alias-tracking.js +5 -0
  17. package/dataflow/graph/graph.js +51 -30
  18. package/dataflow/graph/vertex.d.ts +18 -11
  19. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +16 -0
  20. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +6 -0
  21. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +145 -11
  22. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +15 -0
  23. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +54 -0
  24. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +75 -0
  25. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +196 -0
  26. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +22 -8
  27. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +57 -1
  28. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +5 -0
  29. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +27 -13
  30. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +14 -4
  31. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.d.ts +27 -0
  32. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +97 -0
  33. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +7 -7
  34. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +23 -0
  35. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +90 -0
  36. package/documentation/doc-util/doc-types.d.ts +11 -2
  37. package/documentation/doc-util/doc-types.js +31 -9
  38. package/documentation/wiki-absint.d.ts +16 -0
  39. package/documentation/wiki-absint.js +50 -15
  40. package/documentation/wiki-interface.js +1 -0
  41. package/documentation/wiki-mk/doc-context.d.ts +14 -1
  42. package/documentation/wiki-mk/doc-context.js +6 -0
  43. package/documentation/wiki-normalized-ast.d.ts +0 -9
  44. package/documentation/wiki-normalized-ast.js +9 -60
  45. package/linter/linter-format.d.ts +4 -0
  46. package/linter/linter-rules.d.ts +7 -6
  47. package/linter/rules/absolute-path.d.ts +0 -2
  48. package/linter/rules/dataframe-access-validation.d.ts +4 -7
  49. package/linter/rules/dataframe-access-validation.js +3 -3
  50. package/linter/rules/dead-code.d.ts +4 -7
  51. package/linter/rules/file-path-validity.d.ts +0 -2
  52. package/linter/rules/function-finder-util.d.ts +1 -3
  53. package/linter/rules/function-finder-util.js +2 -2
  54. package/linter/rules/naming-convention.d.ts +0 -2
  55. package/linter/rules/network-functions.js +4 -1
  56. package/linter/rules/problematic-inputs.d.ts +9 -6
  57. package/linter/rules/problematic-inputs.js +108 -58
  58. package/linter/rules/roxygen-arguments.d.ts +0 -2
  59. package/linter/rules/seeded-randomness.d.ts +0 -2
  60. package/linter/rules/stop-with-call-arg.d.ts +3 -6
  61. package/linter/rules/unused-definition.d.ts +0 -2
  62. package/linter/rules/useless-loop.d.ts +0 -2
  63. package/package.json +4 -4
  64. package/queries/catalog/dependencies-query/dependencies-query-executor.js +6 -2
  65. package/queries/catalog/dependencies-query/function-info/function-info.d.ts +2 -0
  66. package/queries/catalog/dependencies-query/function-info/read-functions.js +2 -0
  67. package/queries/catalog/dependencies-query/function-info/source-functions.js +1 -1
  68. package/queries/catalog/dependencies-query/function-info/write-functions.js +1 -0
  69. package/queries/catalog/input-sources-query/input-source-functions.d.ts +1 -0
  70. package/queries/catalog/input-sources-query/input-source-functions.js +7 -1
  71. package/queries/catalog/input-sources-query/input-sources-query-format.js +3 -1
  72. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +3 -1
  73. package/queries/catalog/input-sources-query/simple-input-classifier.js +3 -1
  74. package/r-bridge/data/data.d.ts +28 -2
  75. package/r-bridge/data/data.js +34 -2
  76. package/r-bridge/lang-4.x/ast/model/model.d.ts +1 -2
  77. package/r-bridge/lang-4.x/ast/model/model.js +0 -1
  78. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +3 -3
  79. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -3
  80. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +3 -3
  81. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +3 -3
  82. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +3 -3
  83. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +3 -3
  84. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +3 -3
  85. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +3 -3
  86. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +3 -3
  87. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +3 -3
  88. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +3 -3
  89. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +3 -3
  90. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +3 -3
  91. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +3 -3
  92. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +3 -3
  93. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +3 -3
  94. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +3 -3
  95. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +3 -3
  96. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +3 -3
  97. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +3 -3
  98. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +3 -3
  99. package/r-bridge/lang-4.x/ast/model/processing/decorate.d.ts +1 -1
  100. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +16 -16
  101. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +6 -0
  102. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +8 -0
  103. package/search/flowr-search-builder.d.ts +16 -2
  104. package/search/flowr-search-builder.js +10 -1
  105. package/search/flowr-search.d.ts +9 -0
  106. package/search/search-executor/search-generators.d.ts +1 -1
  107. package/search/search-executor/search-generators.js +28 -2
  108. package/slicing/static/static-slicer.js +2 -2
  109. package/util/range.d.ts +13 -1
  110. package/util/range.js +32 -2
  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
@@ -19,6 +19,7 @@ const logger_1 = require("../../../../../logger");
19
19
  const log_1 = require("../../../../../../util/log");
20
20
  const reference_to_maybe_1 = require("../../../../../environments/reference-to-maybe");
21
21
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
22
+ const general_1 = require("../../../../../eval/values/general");
22
23
  function linkReadNameToWriteIfPossible(read, environments, listEnvironments, remainingRead, nextGraph) {
23
24
  const readName = read.name && identifier_1.Identifier.isDotDotDotAccess(read.name) ? identifier_1.Identifier.dotdotdot() : read.name;
24
25
  const probableTarget = readName ? (0, resolve_by_name_1.resolveByName)(readName, environments, read.type) : undefined;
@@ -41,14 +42,23 @@ function linkReadNameToWriteIfPossible(read, environments, listEnvironments, rem
41
42
  return;
42
43
  }
43
44
  const rid = read.nodeId;
45
+ const isFunc = read.type === identifier_1.ReferenceType.Function || read.type === identifier_1.ReferenceType.BuiltInFunction;
44
46
  for (const target of probableTarget) {
45
47
  const tid = target.nodeId;
46
- if (node_id_1.NodeId.isBuiltIn(target.definedAt) && (read.type === identifier_1.ReferenceType.Function || read.type === identifier_1.ReferenceType.BuiltInFunction)) {
48
+ if (node_id_1.NodeId.isBuiltIn(target.definedAt) && isFunc) {
47
49
  nextGraph.addEdge(rid, tid, edge_1.EdgeType.Reads | edge_1.EdgeType.Calls);
48
50
  }
49
51
  else {
50
52
  nextGraph.addEdge(rid, tid, edge_1.EdgeType.Reads);
51
53
  }
54
+ if (target.type === identifier_1.ReferenceType.BuiltInConstant) {
55
+ nextGraph.addVertex({
56
+ tag: vertex_1.VertexType.Value,
57
+ id: tid,
58
+ cds: undefined,
59
+ value: (0, general_1.valueFromTsValue)(target.value)
60
+ }, environments, false);
61
+ }
52
62
  }
53
63
  }
54
64
  function updateSideEffectsForCalledFunctions(calledEnvs, inputEnvironment, nextGraph, localDefs) {
@@ -104,7 +114,7 @@ function processExpressionList(name, args, rootId, data) {
104
114
  const listEnvironments = new Set();
105
115
  const remainingRead = new Map();
106
116
  const nextGraph = new graph_1.DataflowGraph(data.completeAst.idMap);
107
- let out = [];
117
+ const out = [];
108
118
  const exitPoints = [];
109
119
  const activeCdsAtStart = data.cds;
110
120
  const invertExitCds = [];
@@ -128,12 +138,13 @@ function processExpressionList(name, args, rootId, data) {
128
138
  processed.in = (0, reference_to_maybe_1.makeAllMaybe)(processed.in, nextGraph, processed.environment, false, invertExitCds);
129
139
  processed.unknownReferences = (0, reference_to_maybe_1.makeAllMaybe)(processed.unknownReferences, nextGraph, processed.environment, false);
130
140
  }
131
- out = out.concat(processed.out);
141
+ out.push(...processed.out);
132
142
  // all inputs that have not been written until now are read!
133
- for (const ls of [processed.in, processed.unknownReferences]) {
134
- for (const read of ls) {
135
- linkReadNameToWriteIfPossible(read, environment, listEnvironments, remainingRead, nextGraph);
136
- }
143
+ for (const read of processed.in) {
144
+ linkReadNameToWriteIfPossible(read, environment, listEnvironments, remainingRead, nextGraph);
145
+ }
146
+ for (const read of processed.unknownReferences) {
147
+ linkReadNameToWriteIfPossible(read, environment, listEnvironments, remainingRead, nextGraph);
137
148
  }
138
149
  const calledEnvs = (0, linker_1.linkFunctionCalls)(nextGraph, data.completeAst.idMap, processed.graph);
139
150
  for (const c of calledEnvs) {
@@ -167,7 +178,10 @@ function processExpressionList(name, args, rootId, data) {
167
178
  nodeId: defaultReturnExpr.entryPoint
168
179
  });
169
180
  }
170
- const ingoing = remainingRead.values().toArray().flat();
181
+ const ingoing = [];
182
+ for (const refs of remainingRead.values()) {
183
+ ingoing.push(...refs);
184
+ }
171
185
  const rootNode = data.completeAst.idMap.get(rootId);
172
186
  const withGroup = rootNode?.grouping;
173
187
  if (withGroup) {
@@ -16,6 +16,7 @@ const graph_1 = require("../../../../../graph/graph");
16
16
  const identifier_1 = require("../../../../../environments/identifier");
17
17
  const overwrite_1 = require("../../../../../environments/overwrite");
18
18
  const vertex_1 = require("../../../../../graph/vertex");
19
+ const built_in_new_env_1 = require("./built-in-new-env");
19
20
  const scoping_1 = require("../../../../../environments/scoping");
20
21
  const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
21
22
  const edge_1 = require("../../../../../graph/edge");
@@ -128,6 +129,25 @@ function processFunctionDefinition(name, args, rootId, data) {
128
129
  afterHookExitPoints = (0, info_1.overwriteExitPoints)(afterHookExitPoints, hookExitPoints);
129
130
  }
130
131
  }
132
+ let returnEnvState;
133
+ if (data.ctx.config.solver.trackEnvironments) {
134
+ for (const ep of afterHookExitPoints) {
135
+ const epVertex = subgraph.getVertex(ep.nodeId);
136
+ if ((0, vertex_1.isFunctionCallVertex)(epVertex) && epVertex.origin.includes(built_in_proc_name_1.BuiltInProcName.NewEnv)) {
137
+ returnEnvState = (0, built_in_new_env_1.createFreshEnvState)(data, { graph: subgraph, entryPoint: ep.nodeId });
138
+ break;
139
+ }
140
+ const epNode = subgraph.idMap?.get(ep.nodeId);
141
+ if (epNode?.type === type_1.RType.Symbol) {
142
+ const defs = (0, resolve_by_name_1.resolveByName)(epNode.content, outEnvironment, identifier_1.ReferenceType.Variable);
143
+ const def = defs?.find((d) => d.envState !== undefined);
144
+ if (def?.envState) {
145
+ returnEnvState = def.envState;
146
+ break;
147
+ }
148
+ }
149
+ }
150
+ }
131
151
  const graph = new graph_1.DataflowGraph(data.completeAst.idMap).mergeWith(subgraph, false);
132
152
  graph.addVertex({
133
153
  tag: vertex_1.VertexType.FunctionDefinition,
@@ -136,7 +156,8 @@ function processFunctionDefinition(name, args, rootId, data) {
136
156
  cds: data.cds,
137
157
  params: readParams,
138
158
  subflow: flow,
139
- exitPoints: afterHookExitPoints
159
+ exitPoints: afterHookExitPoints,
160
+ returnEnvState
140
161
  }, data.ctx.env.makeCleanEnv());
141
162
  return {
142
163
  /* nothing escapes a function definition, but the function itself, will be forced in assignment: { nodeId: functionDefinition.info.id, scope: data.activeScope, used: 'always', name: functionDefinition.info.id as string } */
@@ -220,6 +241,41 @@ function updateNestedFunctionClosures(graph, outEnvironment, fnId) {
220
241
  }
221
242
  (0, log_1.expensiveTrace)(logger_1.dataflowLogger, () => `Keeping ${remainingIn.length} references to open ref ${id} in closure of function definition ${fnId}`);
222
243
  subflow.in = remainingIn;
244
+ linkSuperAssignmentsToOuterDefinitions(graph, subflow.graph, outEnvironment);
245
+ }
246
+ }
247
+ function linkSuperAssignmentsToOuterDefinitions(parentGraph, nestedGraphNodeIds, parentEnvironment) {
248
+ for (const nodeId of nestedGraphNodeIds) {
249
+ const vertex = parentGraph.getVertex(nodeId);
250
+ if (vertex?.tag !== vertex_1.VertexType.FunctionCall || !vertex.origin.includes(built_in_proc_name_1.BuiltInProcName.SuperAssignment)) {
251
+ continue;
252
+ }
253
+ const outgoingReturns = parentGraph.outgoingEdges(nodeId);
254
+ if (!outgoingReturns) {
255
+ continue;
256
+ }
257
+ for (const [targetId, edge] of outgoingReturns) {
258
+ if (!edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Returns)) {
259
+ continue;
260
+ }
261
+ const targetVertex = parentGraph.getVertex(targetId);
262
+ if (targetVertex?.tag !== vertex_1.VertexType.VariableDefinition) {
263
+ continue;
264
+ }
265
+ const targetNode = parentGraph.idMap?.get(targetId);
266
+ if (targetNode?.type !== type_1.RType.Symbol) {
267
+ continue;
268
+ }
269
+ const varName = targetNode.content;
270
+ const resolved = (0, resolve_by_name_1.resolveByName)(varName, parentEnvironment, identifier_1.ReferenceType.Variable);
271
+ if (resolved) {
272
+ for (const ref of resolved) {
273
+ if (ref.nodeId !== targetId && !node_id_1.NodeId.isBuiltIn(ref.nodeId)) {
274
+ parentGraph.addEdge(targetId, ref.nodeId, edge_1.EdgeType.Reads);
275
+ }
276
+ }
277
+ }
278
+ }
223
279
  }
224
280
  }
225
281
  /**
@@ -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;
@@ -4,23 +4,32 @@ exports.processGet = processGet;
4
4
  const known_call_handling_1 = require("../known-call-handling");
5
5
  const unpack_argument_1 = require("../argument/unpack-argument");
6
6
  const make_argument_1 = require("../argument/make-argument");
7
+ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
7
8
  const logger_1 = require("../../../../../logger");
8
9
  const retriever_1 = require("../../../../../../r-bridge/retriever");
9
10
  const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
10
11
  const edge_1 = require("../../../../../graph/edge");
11
12
  const identifier_1 = require("../../../../../environments/identifier");
12
13
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
14
+ const built_in_envir_utils_1 = require("./built-in-envir-utils");
13
15
  /**
14
16
  * Processes a built-in 'get' function call.
17
+ *
18
+ * When an `envir` argument is present and resolves to a variable with a tracked environment
19
+ * state (set up by `new.env()` + `assign(..., envir=...)`), the lookup is performed inside
20
+ * that environment so that the correct definition is found and the returned {@link DataflowInformation}
21
+ * contains the right read edges.
15
22
  */
16
23
  function processGet(name, args, rootId, data) {
17
- if (args.length !== 1) {
18
- logger_1.dataflowLogger.warn(`symbol access with ${identifier_1.Identifier.toString(name.content)} has not 1 argument, skipping`);
19
- return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
20
- }
21
- const retrieve = (0, unpack_argument_1.unpackNonameArg)(args[0]);
24
+ /* use the custom environment for resolution when envir points to a tracked env */
25
+ const resolution = (0, built_in_envir_utils_1.resolveEnvirArg)(args, data);
26
+ /* the first arg must be a string naming the variable to retrieve */
27
+ const firstArg = args.length >= 1 ? args[0] : undefined;
28
+ const retrieve = firstArg !== undefined && firstArg !== r_function_call_1.EmptyArgument
29
+ ? (0, unpack_argument_1.unpackNonameArg)(firstArg)
30
+ : undefined;
22
31
  if (retrieve === undefined || retrieve.type !== type_1.RType.String) {
23
- logger_1.dataflowLogger.warn(`symbol access with ${identifier_1.Identifier.toString(name.content)} has not 1 argument, skipping`);
32
+ logger_1.dataflowLogger.warn(`symbol access with ${identifier_1.Identifier.toString(name.content)} has not 1 string argument, skipping`);
24
33
  return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
25
34
  }
26
35
  const treatTargetAsSymbol = {
@@ -30,18 +39,23 @@ function processGet(name, args, rootId, data) {
30
39
  lexeme: retrieve.lexeme,
31
40
  location: retrieve.location
32
41
  };
42
+ /* resolve in the custom environment if one was found, else the global one.
43
+ * Pass remaining original args (e.g. envir=e) so they appear as Use vertices in the graph. */
33
44
  const { information, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({
34
45
  name,
35
- args: (0, make_argument_1.wrapArgumentsUnnamed)([treatTargetAsSymbol], data.completeAst.idMap),
46
+ args: [...(0, make_argument_1.wrapArgumentsUnnamed)([treatTargetAsSymbol], data.completeAst.idMap), ...args.slice(1)],
36
47
  rootId,
37
- data,
48
+ data: resolution ? resolution.envirData : data,
38
49
  origin: built_in_proc_name_1.BuiltInProcName.Get
39
50
  });
40
- const firstArg = processedArguments[0];
41
- if (firstArg) {
42
- // get 'reads' its first argument
43
- information.graph.addEdge(rootId, firstArg.entryPoint, edge_1.EdgeType.Returns | edge_1.EdgeType.Reads);
51
+ const firstProcessed = processedArguments[0];
52
+ if (firstProcessed) {
53
+ information.graph.addEdge(rootId, firstProcessed.entryPoint, edge_1.EdgeType.Returns | edge_1.EdgeType.Reads);
54
+ }
55
+ if (resolution) {
56
+ information.graph.addEdge(rootId, resolution.envirNodeId, edge_1.EdgeType.Reads);
44
57
  }
45
- return information;
58
+ /* restore the caller's (global) environment so we don't leak envState upward */
59
+ return { ...information, environment: data.environment };
46
60
  }
47
61
  //# sourceMappingURL=built-in-get.js.map
@@ -11,6 +11,7 @@ const scoping_1 = require("../../../../../environments/scoping");
11
11
  const identifier_1 = require("../../../../../environments/identifier");
12
12
  const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
13
13
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
14
+ const built_in_envir_utils_1 = require("./built-in-envir-utils");
14
15
  /**
15
16
  * Processes a built-in 'local' function call.
16
17
  */
@@ -29,6 +30,8 @@ function processLocal(name, args, rootId, data, config) {
29
30
  if (!expr) {
30
31
  return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
31
32
  }
33
+ /* when envir resolves to a tracked environment, evaluate expr inside it */
34
+ const envirResolution = env ? (0, built_in_envir_utils_1.resolveEnvirArg)(args, data, config.args.env) : undefined;
32
35
  const dfEnv = env ? (0, processor_1.processDataflowFor)(env, data) : info_1.DataflowInformation.initialize(rootId, data);
33
36
  if ((0, info_1.alwaysExits)(dfEnv)) {
34
37
  (0, common_1.patchFunctionCall)({
@@ -41,8 +44,10 @@ function processLocal(name, args, rootId, data, config) {
41
44
  });
42
45
  return dfEnv;
43
46
  }
44
- const bodyData = { ...data, environment: (0, scoping_1.pushLocalEnvironment)(data.environment) };
45
- const dfExpr = (0, processor_1.processDataflowFor)(expr, bodyData);
47
+ const baseEnvironment = envirResolution
48
+ ? envirResolution.envirData.environment // evaluate in the tracked custom env
49
+ : (0, scoping_1.pushLocalEnvironment)(data.environment); // normal new local scope
50
+ const dfExpr = (0, processor_1.processDataflowFor)(expr, { ...data, environment: baseEnvironment });
46
51
  (0, common_1.patchFunctionCall)({
47
52
  nextGraph: dfEnv.graph,
48
53
  rootId,
@@ -53,9 +58,9 @@ function processLocal(name, args, rootId, data, config) {
53
58
  });
54
59
  const ingoing = dfEnv.in.concat(dfExpr.in, dfEnv.unknownReferences, dfExpr.unknownReferences);
55
60
  ingoing.push({ nodeId: rootId, name: name.content, cds: data.cds, type: identifier_1.ReferenceType.Function });
56
- return {
61
+ const baseResult = {
57
62
  hooks: dfExpr.hooks.concat(dfEnv.hooks),
58
- environment: (0, scoping_1.popLocalEnvironment)(dfExpr.environment),
63
+ environment: envirResolution ? data.environment : (0, scoping_1.popLocalEnvironment)(dfExpr.environment),
59
64
  exitPoints: dfEnv.exitPoints.concat(dfExpr.exitPoints),
60
65
  graph: dfEnv.graph.mergeWith(dfExpr.graph),
61
66
  entryPoint: rootId,
@@ -63,5 +68,10 @@ function processLocal(name, args, rootId, data, config) {
63
68
  out: dfExpr.out.concat(dfEnv.out),
64
69
  unknownReferences: []
65
70
  };
71
+ /* move all definitions made inside the body into the custom env's tracked state */
72
+ if (envirResolution) {
73
+ return (0, built_in_envir_utils_1.routeWrittenToCustomEnv)(baseResult, envirResolution.envDef, rootId);
74
+ }
75
+ return baseResult;
66
76
  }
67
77
  //# sourceMappingURL=built-in-local.js.map
@@ -0,0 +1,27 @@
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
+ import { type REnvironmentInformation } from '../../../../../environments/environment';
8
+ /**
9
+ * Processes `new.env()` and `rlang::new_environment()`.
10
+ *
11
+ * The resulting function-call vertex carries the {@link BuiltInProcName.NewEnv} origin so that
12
+ * `processAssignment` can detect it and attach an `envState` to the assigned variable.
13
+ *
14
+ * When the `parent` argument can be statically resolved (a tracked env variable or an
15
+ * `emptyenv()`-family call), the resolved parent is stored in the vertex's `newEnvParent`
16
+ * field so that {@link createFreshEnvState} can use it.
17
+ */
18
+ export declare function processNewEnv<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
19
+ /**
20
+ * Creates the initial (empty) environment state for a freshly created `new.env()`.
21
+ *
22
+ * When called from `processAssignmentToSymbol`, pass `sourceInfo` so that a
23
+ * statically-resolved `parent` argument (stored in the vertex's `newEnvParent` field)
24
+ * is honoured. Without `sourceInfo` (or when no `newEnvParent` is present), falls back
25
+ * to the current execution environment as parent.
26
+ */
27
+ export declare function createFreshEnvState(data: Pick<DataflowProcessorInformation<never>, 'environment'>, sourceInfo?: Pick<DataflowInformation, 'graph' | 'entryPoint'>): REnvironmentInformation;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processNewEnv = processNewEnv;
4
+ exports.createFreshEnvState = createFreshEnvState;
5
+ const known_call_handling_1 = require("../known-call-handling");
6
+ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
7
+ const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
8
+ const scoping_1 = require("../../../../../environments/scoping");
9
+ const environment_1 = require("../../../../../environments/environment");
10
+ const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
11
+ const unpack_argument_1 = require("../argument/unpack-argument");
12
+ const vertex_1 = require("../../../../../graph/vertex");
13
+ const convert_values_1 = require("../../../../../../r-bridge/lang-4.x/convert-values");
14
+ const built_in_envir_utils_1 = require("./built-in-envir-utils");
15
+ const EmptyParentEnvFunctions = new Set(['emptyenv', 'baseenv']);
16
+ /**
17
+ * Processes `new.env()` and `rlang::new_environment()`.
18
+ *
19
+ * The resulting function-call vertex carries the {@link BuiltInProcName.NewEnv} origin so that
20
+ * `processAssignment` can detect it and attach an `envState` to the assigned variable.
21
+ *
22
+ * When the `parent` argument can be statically resolved (a tracked env variable or an
23
+ * `emptyenv()`-family call), the resolved parent is stored in the vertex's `newEnvParent`
24
+ * field so that {@link createFreshEnvState} can use it.
25
+ */
26
+ function processNewEnv(name, args, rootId, data) {
27
+ const result = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.NewEnv }).information;
28
+ if (data.ctx.config.solver.trackEnvironments) {
29
+ const parentState = resolveNewEnvParentArg(args, data);
30
+ const vertex = result.graph.getVertex(rootId);
31
+ if (parentState !== undefined && (0, vertex_1.isFunctionCallVertex)(vertex)) {
32
+ vertex.newEnvParent = parentState;
33
+ }
34
+ }
35
+ return result;
36
+ }
37
+ /**
38
+ * Scans `args` for the `parent` argument and returns the {@link REnvironmentInformation}
39
+ * to use as the parent of the newly-created environment, or `undefined` to fall through
40
+ * to the default (current execution environment).
41
+ *
42
+ * Recognised patterns:
43
+ * - `parent = <tracked-env-var>` - returns that variable's `envState`
44
+ * - `parent = emptyenv()` / `parent = baseenv()` - returns an isolated env (no user scope)
45
+ * - everything else - `undefined` (fall through)
46
+ */
47
+ function resolveNewEnvParentArg(args, data) {
48
+ for (const arg of args) {
49
+ if (arg === r_function_call_1.EmptyArgument || arg.name?.content !== 'parent') {
50
+ continue;
51
+ }
52
+ const node = (0, unpack_argument_1.unpackArg)(arg);
53
+ if (!node) {
54
+ return undefined;
55
+ }
56
+ if (node.type === type_1.RType.Symbol) {
57
+ if (node.content === convert_values_1.RNull) {
58
+ return undefined;
59
+ }
60
+ return (0, built_in_envir_utils_1.resolveSymbolToEnvir)(node.content, node.info.id, data)?.envDef.envState;
61
+ }
62
+ if (r_function_call_1.RFunctionCall.isNamed(node) && node.functionName.type === type_1.RType.Symbol
63
+ && EmptyParentEnvFunctions.has(node.functionName.content)) {
64
+ return createIsolatedEnvState(data);
65
+ }
66
+ return undefined;
67
+ }
68
+ return undefined;
69
+ }
70
+ function createIsolatedEnvState(data) {
71
+ let root = data.environment.current;
72
+ while (!root.builtInEnv) {
73
+ root = root.parent;
74
+ }
75
+ return { current: new environment_1.Environment(root), level: 0 };
76
+ }
77
+ /**
78
+ * Creates the initial (empty) environment state for a freshly created `new.env()`.
79
+ *
80
+ * When called from `processAssignmentToSymbol`, pass `sourceInfo` so that a
81
+ * statically-resolved `parent` argument (stored in the vertex's `newEnvParent` field)
82
+ * is honoured. Without `sourceInfo` (or when no `newEnvParent` is present), falls back
83
+ * to the current execution environment as parent.
84
+ */
85
+ function createFreshEnvState(data, sourceInfo) {
86
+ if (sourceInfo !== undefined) {
87
+ const vertex = sourceInfo.graph.getVertex(sourceInfo.entryPoint);
88
+ if ((0, vertex_1.isFunctionCallVertex)(vertex) && vertex.newEnvParent !== undefined) {
89
+ return {
90
+ current: new environment_1.Environment(vertex.newEnvParent.current),
91
+ level: vertex.newEnvParent.level + 1
92
+ };
93
+ }
94
+ }
95
+ return (0, scoping_1.pushLocalEnvironment)(data.environment);
96
+ }
97
+ //# sourceMappingURL=built-in-new-env.js.map
@@ -79,7 +79,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
79
79
  content: 'fun',
80
80
  info: {
81
81
  id: argNameId,
82
- nesting: name.info.nesting,
82
+ nest: name.info.nest,
83
83
  role: "arg-n" /* RoleInParent.ArgumentName */,
84
84
  fullRange: r,
85
85
  adToks: undefined,
@@ -96,7 +96,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
96
96
  lexeme: 'S7_dispatch',
97
97
  info: {
98
98
  id: funcNameId,
99
- nesting: name.info.nesting,
99
+ nest: name.info.nest,
100
100
  role: "call-name" /* RoleInParent.FunctionCallName */,
101
101
  fullRange: r,
102
102
  adToks: undefined,
@@ -116,7 +116,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
116
116
  arguments: [],
117
117
  info: {
118
118
  id: rootId + '-s7-new-generic-fun-body',
119
- nesting: name.info.nesting,
119
+ nest: name.info.nest,
120
120
  role: "fun-b" /* RoleInParent.FunctionDefinitionBody */,
121
121
  fullRange: r,
122
122
  adToks: undefined,
@@ -131,7 +131,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
131
131
  info: {
132
132
  file: name.info.file,
133
133
  id: fdefId,
134
- nesting: name.info.nesting,
134
+ nest: name.info.nest,
135
135
  role: "arg-v" /* RoleInParent.ArgumentValue */,
136
136
  parent: rootId,
137
137
  index: args + 1,
@@ -149,7 +149,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
149
149
  content: n,
150
150
  info: {
151
151
  id: paramNameId,
152
- nesting: name.info.nesting,
152
+ nest: name.info.nest,
153
153
  role: "param-n" /* RoleInParent.ParameterName */,
154
154
  fullRange: r,
155
155
  adToks: undefined,
@@ -168,7 +168,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
168
168
  special: n === '...',
169
169
  info: {
170
170
  id: paramId,
171
- nesting: name.info.nesting,
171
+ nest: name.info.nest,
172
172
  role: "param" /* RoleInParent.FunctionDefinitionParameter */,
173
173
  parent: fdefId,
174
174
  index: i,
@@ -193,7 +193,7 @@ function makeS7DispatchFDef(name, names, rootId, args, idMap) {
193
193
  location: r,
194
194
  info: {
195
195
  id: argId,
196
- nesting: name.info.nesting,
196
+ nest: name.info.nest,
197
197
  role: "call-arg" /* RoleInParent.FunctionCallArgument */,
198
198
  fullRange: r,
199
199
  adToks: undefined,
@@ -0,0 +1,23 @@
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 `with(data, expr)` and `within(data, expr)`.
9
+ *
10
+ * When `data` is a variable that holds a tracked {@link InGraphIdentifierDefinition#envState},
11
+ * the expression `expr` is evaluated in that environment's scope so that reads of names
12
+ * defined there resolve correctly.
13
+ *
14
+ * - `with`: writes in `expr` are ephemeral (R's `with` uses a temporary scope and discards them).
15
+ * - `within`: writes in `expr` are persisted back into the tracked envState of `data`.
16
+ *
17
+ * Arguments are resolved using R's standard matching rules ({@link bindArgs}: pmatch for named
18
+ * args, positional fallback), so `with(expr=x, data=e)` and `with(dat=e, x)` are handled correctly.
19
+ *
20
+ * Falls back to a normal function-call analysis when the data argument cannot be resolved
21
+ * to a tracked environment.
22
+ */
23
+ export declare function processWithEnv<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processWithEnv = processWithEnv;
4
+ const processor_1 = require("../../../../../processor");
5
+ const known_call_handling_1 = require("../known-call-handling");
6
+ const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
7
+ const identifier_1 = require("../../../../../environments/identifier");
8
+ const built_in_envir_utils_1 = require("./built-in-envir-utils");
9
+ const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
10
+ const common_1 = require("../common");
11
+ const edge_1 = require("../../../../../graph/edge");
12
+ const linker_1 = require("../../../../linker");
13
+ /** Formal parameter names for `with(data, expr, ...)` and `within(data, expr, ...)`. */
14
+ const withParams = ['data', 'expr'];
15
+ /**
16
+ * Processes `with(data, expr)` and `within(data, expr)`.
17
+ *
18
+ * When `data` is a variable that holds a tracked {@link InGraphIdentifierDefinition#envState},
19
+ * the expression `expr` is evaluated in that environment's scope so that reads of names
20
+ * defined there resolve correctly.
21
+ *
22
+ * - `with`: writes in `expr` are ephemeral (R's `with` uses a temporary scope and discards them).
23
+ * - `within`: writes in `expr` are persisted back into the tracked envState of `data`.
24
+ *
25
+ * Arguments are resolved using R's standard matching rules ({@link bindArgs}: pmatch for named
26
+ * args, positional fallback), so `with(expr=x, data=e)` and `with(dat=e, x)` are handled correctly.
27
+ *
28
+ * Falls back to a normal function-call analysis when the data argument cannot be resolved
29
+ * to a tracked environment.
30
+ */
31
+ function processWithEnv(name, args, rootId, data) {
32
+ if (args.length < 2) {
33
+ return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.With }).information;
34
+ }
35
+ const bound = (0, built_in_envir_utils_1.bindArgs)(args, withParams);
36
+ const dataArg = bound.get('data');
37
+ const exprArg = bound.get('expr');
38
+ if (dataArg === undefined || dataArg === r_function_call_1.EmptyArgument || dataArg.value === undefined ||
39
+ exprArg === undefined || exprArg === r_function_call_1.EmptyArgument || exprArg.value === undefined) {
40
+ return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.With }).information;
41
+ }
42
+ const envirResolution = (0, built_in_envir_utils_1.resolveArgToEnvir)(dataArg, data);
43
+ if (!envirResolution) {
44
+ return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.With }).information;
45
+ }
46
+ /* evaluate data arg in the caller's scope (it is just read) */
47
+ const dfDataArg = (0, processor_1.processDataflowFor)(dataArg.value, data);
48
+ /* evaluate expr in the resolved env's scope so variable lookup uses envState */
49
+ const dfExpr = (0, processor_1.processDataflowFor)(exprArg.value, {
50
+ ...data,
51
+ environment: envirResolution.envirData.environment
52
+ });
53
+ /*
54
+ * processSymbol puts symbol uses in unknownReferences without creating reads edges.
55
+ * Explicitly link expr's unknown references against the envState so reads edges are
56
+ * created for names that resolve there (e.g. `x` in `with(e, x)` -> assign).
57
+ * References that cannot be resolved in envState are kept for the outer scope.
58
+ */
59
+ const remainingFromExpr = [];
60
+ (0, linker_1.linkInputs)(dfExpr.unknownReferences, envirResolution.envirData.environment, remainingFromExpr, dfExpr.graph, false);
61
+ (0, common_1.patchFunctionCall)({
62
+ nextGraph: dfDataArg.graph,
63
+ rootId,
64
+ name,
65
+ data,
66
+ argumentProcessResult: [dfDataArg, dfExpr],
67
+ origin: built_in_proc_name_1.BuiltInProcName.With
68
+ });
69
+ const merged = dfDataArg.graph.mergeWith(dfExpr.graph);
70
+ merged.addEdge(rootId, envirResolution.envirNodeId, edge_1.EdgeType.Reads);
71
+ const ingoing = dfDataArg.in.concat(dfExpr.in, dfDataArg.unknownReferences, remainingFromExpr, /* unresolved expr refs propagate to outer scope */ [{ nodeId: rootId, name: name.content, cds: data.cds, type: identifier_1.ReferenceType.Function }]);
72
+ /* within routes body writes back into the data environment; with discards them */
73
+ const isWithin = identifier_1.Identifier.getName(name.content) === 'within';
74
+ let resultEnv = data.environment;
75
+ if (isWithin && dfExpr.out.length > 0) {
76
+ const tempResult = { ...dfExpr, environment: data.environment };
77
+ resultEnv = (0, built_in_envir_utils_1.routeWrittenToCustomEnv)(tempResult, envirResolution.envDef, rootId).environment;
78
+ }
79
+ return {
80
+ hooks: dfDataArg.hooks.concat(dfExpr.hooks),
81
+ environment: resultEnv,
82
+ exitPoints: dfDataArg.exitPoints.concat(dfExpr.exitPoints),
83
+ graph: merged,
84
+ entryPoint: rootId,
85
+ in: ingoing,
86
+ out: [], /* writes are inside envState, not directly in outer scope */
87
+ unknownReferences: []
88
+ };
89
+ }
90
+ //# sourceMappingURL=built-in-with.js.map
@@ -59,7 +59,7 @@ export declare function getStartLineOfTypeScriptNode(node: ts.Node, sourceFile:
59
59
  * Return the link to the type in the source code.
60
60
  * If you create a wiki, please refer to the functions provided by the {@link GeneralWikiContext}.
61
61
  */
62
- export declare function getTypePathLink(elem: Pick<TypeElementInSource, 'filePath' | 'lineNumber'>, prefix?: string): string;
62
+ export declare function getTypePathLink(elem: Pick<TypeElementInSource, 'filePath' | 'lineNumber'>, relative?: boolean): string;
63
63
  export interface MermaidClassDiagramArguments {
64
64
  readonly inlineTypes?: readonly string[];
65
65
  readonly simplify?: boolean;
@@ -130,6 +130,8 @@ export interface FnElementInfo {
130
130
  doNotAutoGobble?: boolean;
131
131
  /** Whether to hide the "Defined at ..." line */
132
132
  hideDefinedAt?: boolean;
133
+ /** Whether lines with import statements in the code should be skipped */
134
+ skipImports?: boolean;
133
135
  }
134
136
  /**
135
137
  * Print an element from the info as code block.
@@ -137,7 +139,14 @@ export interface FnElementInfo {
137
139
  *
138
140
  * This is great to show examples that are directly taken from the source code.
139
141
  */
140
- export declare function printCodeOfElement({ program, info, dropLinesEnd, dropLinesStart, doNotAutoGobble, hideDefinedAt }: FnElementInfo, name: string): string;
142
+ export declare function printCodeOfElement(info: FnElementInfo, name: string): string;
143
+ /**
144
+ * Print a source file as code block.
145
+ * If you create a wiki, please refer to the functions provided by the {@link GeneralWikiContext}.
146
+ *
147
+ * This is great to show examples that are directly taken from the source code.
148
+ */
149
+ export declare function printCodeOfFile(info: FnElementInfo, relativePath: string): string;
141
150
  /**
142
151
  * Create a short link to a type in the documentation.
143
152
  * If you create a wiki, please refer to the functions provided by the {@link GeneralDocContext}.