@eagleoutice/flowr 2.6.3 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/README.md +13 -13
  2. package/abstract-interpretation/data-frame/absint-visitor.d.ts +1 -1
  3. package/abstract-interpretation/data-frame/absint-visitor.js +3 -3
  4. package/abstract-interpretation/data-frame/dataframe-domain.d.ts +4 -7
  5. package/abstract-interpretation/data-frame/dataframe-domain.js +5 -11
  6. package/abstract-interpretation/data-frame/mappers/access-mapper.d.ts +3 -1
  7. package/abstract-interpretation/data-frame/mappers/access-mapper.js +3 -2
  8. package/abstract-interpretation/data-frame/mappers/arguments.js +2 -2
  9. package/abstract-interpretation/data-frame/mappers/assignment-mapper.d.ts +3 -1
  10. package/abstract-interpretation/data-frame/mappers/assignment-mapper.js +3 -2
  11. package/abstract-interpretation/data-frame/mappers/function-mapper.d.ts +1 -1
  12. package/abstract-interpretation/data-frame/mappers/function-mapper.js +8 -8
  13. package/abstract-interpretation/data-frame/mappers/replacement-mapper.d.ts +3 -1
  14. package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +3 -2
  15. package/abstract-interpretation/data-frame/semantics.js +47 -42
  16. package/abstract-interpretation/data-frame/shape-inference.d.ts +1 -1
  17. package/abstract-interpretation/domains/abstract-domain.d.ts +1 -0
  18. package/abstract-interpretation/domains/abstract-domain.js +3 -2
  19. package/abstract-interpretation/domains/bounded-set-domain.js +1 -1
  20. package/abstract-interpretation/domains/interval-domain.d.ts +2 -2
  21. package/abstract-interpretation/domains/interval-domain.js +3 -6
  22. package/abstract-interpretation/domains/lattice.d.ts +2 -0
  23. package/abstract-interpretation/domains/lattice.js +3 -1
  24. package/abstract-interpretation/domains/positive-interval-domain.d.ts +1 -1
  25. package/abstract-interpretation/domains/positive-interval-domain.js +1 -1
  26. package/abstract-interpretation/domains/satisfiable-domain.d.ts +2 -2
  27. package/abstract-interpretation/domains/satisfiable-domain.js +2 -2
  28. package/abstract-interpretation/domains/set-range-domain.d.ts +98 -0
  29. package/abstract-interpretation/domains/set-range-domain.js +400 -0
  30. package/abstract-interpretation/domains/set-upper-bound-domain.js +2 -2
  31. package/abstract-interpretation/domains/singleton-domain.js +2 -2
  32. package/benchmark/slicer.d.ts +2 -1
  33. package/benchmark/slicer.js +37 -15
  34. package/benchmark/stats/print.js +8 -5
  35. package/benchmark/stats/stats.d.ts +3 -2
  36. package/benchmark/summarizer/data.d.ts +11 -8
  37. package/benchmark/summarizer/first-phase/process.js +11 -8
  38. package/benchmark/summarizer/second-phase/process.js +24 -18
  39. package/control-flow/cfg-dead-code.js +3 -2
  40. package/control-flow/useless-loop.js +4 -2
  41. package/core/steps/all/static-slicing/00-slice.d.ts +3 -0
  42. package/core/steps/all/static-slicing/00-slice.js +2 -1
  43. package/core/steps/pipeline/default-pipelines.d.ts +42 -42
  44. package/dataflow/cluster.js +2 -2
  45. package/dataflow/environments/append.d.ts +5 -0
  46. package/dataflow/environments/append.js +6 -20
  47. package/dataflow/environments/built-in.d.ts +2 -1
  48. package/dataflow/environments/clone.d.ts +1 -1
  49. package/dataflow/environments/clone.js +3 -27
  50. package/dataflow/environments/define.d.ts +7 -3
  51. package/dataflow/environments/define.js +9 -56
  52. package/dataflow/environments/diff.js +1 -1
  53. package/dataflow/environments/environment.d.ts +48 -28
  54. package/dataflow/environments/environment.js +187 -62
  55. package/dataflow/environments/overwrite.js +2 -45
  56. package/dataflow/environments/reference-to-maybe.d.ts +13 -0
  57. package/dataflow/environments/reference-to-maybe.js +54 -0
  58. package/dataflow/environments/resolve-by-name.d.ts +6 -1
  59. package/dataflow/environments/resolve-by-name.js +56 -4
  60. package/dataflow/environments/scoping.d.ts +2 -2
  61. package/dataflow/environments/scoping.js +7 -7
  62. package/dataflow/eval/resolve/alias-tracking.d.ts +10 -4
  63. package/dataflow/eval/resolve/alias-tracking.js +15 -13
  64. package/dataflow/eval/resolve/resolve-argument.d.ts +2 -1
  65. package/dataflow/eval/resolve/resolve-argument.js +8 -8
  66. package/dataflow/eval/resolve/resolve.d.ts +13 -11
  67. package/dataflow/eval/resolve/resolve.js +16 -15
  68. package/dataflow/extractor.js +1 -7
  69. package/dataflow/fn/higher-order-function.d.ts +2 -1
  70. package/dataflow/fn/higher-order-function.js +4 -4
  71. package/dataflow/graph/dataflowgraph-builder.d.ts +9 -5
  72. package/dataflow/graph/dataflowgraph-builder.js +21 -11
  73. package/dataflow/graph/diff-dataflow-graph.js +2 -2
  74. package/dataflow/graph/graph.d.ts +10 -2
  75. package/dataflow/graph/graph.js +41 -12
  76. package/dataflow/graph/invert-dfg.d.ts +3 -2
  77. package/dataflow/graph/invert-dfg.js +3 -3
  78. package/dataflow/graph/resolve-graph.d.ts +2 -1
  79. package/dataflow/graph/resolve-graph.js +2 -2
  80. package/dataflow/graph/vertex.d.ts +3 -3
  81. package/dataflow/graph/vertex.js +3 -3
  82. package/dataflow/info.d.ts +1 -1
  83. package/dataflow/internal/linker.js +3 -7
  84. package/dataflow/internal/process/functions/call/argument/unpack-argument.d.ts +7 -1
  85. package/dataflow/internal/process/functions/call/argument/unpack-argument.js +12 -3
  86. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +3 -3
  87. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +2 -2
  88. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +3 -1
  89. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +3 -3
  90. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +9 -9
  91. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +9 -7
  92. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +3 -3
  93. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +2 -1
  94. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +9 -13
  95. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +1 -1
  96. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.d.ts +3 -1
  97. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +8 -6
  98. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +1 -1
  99. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +1 -1
  100. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +1 -1
  101. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +3 -3
  102. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +6 -4
  103. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +1 -1
  104. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +5 -5
  105. package/dataflow/internal/process/functions/call/common.js +2 -3
  106. package/dataflow/internal/process/functions/call/known-call-handling.js +1 -1
  107. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +1 -1
  108. package/dataflow/internal/process/functions/process-argument.js +1 -1
  109. package/dataflow/internal/process/process-symbol.js +1 -1
  110. package/dataflow/internal/process/process-value.d.ts +1 -1
  111. package/dataflow/internal/process/process-value.js +7 -7
  112. package/dataflow/processor.d.ts +1 -5
  113. package/documentation/doc-util/doc-dfg.js +3 -2
  114. package/documentation/doc-util/doc-normalized-ast.js +3 -2
  115. package/documentation/doc-util/doc-types.d.ts +1 -1
  116. package/documentation/doc-util/doc-types.js +2 -2
  117. package/documentation/wiki-analyzer.js +14 -1
  118. package/documentation/wiki-dataflow-graph.js +4 -5
  119. package/documentation/wiki-faq.js +0 -1
  120. package/documentation/wiki-linter.js +1 -1
  121. package/documentation/wiki-mk/doc-maker.js +2 -1
  122. package/linter/linter-rules.d.ts +2 -2
  123. package/linter/rules/absolute-path.js +4 -4
  124. package/linter/rules/dataframe-access-validation.d.ts +1 -1
  125. package/linter/rules/dataframe-access-validation.js +1 -1
  126. package/linter/rules/function-finder-util.d.ts +2 -2
  127. package/linter/rules/function-finder-util.js +1 -1
  128. package/linter/rules/network-functions.js +1 -1
  129. package/linter/rules/seeded-randomness.d.ts +1 -1
  130. package/linter/rules/seeded-randomness.js +5 -5
  131. package/package.json +1 -2
  132. package/project/context/flowr-analyzer-context.d.ts +7 -0
  133. package/project/context/flowr-analyzer-context.js +3 -0
  134. package/project/context/flowr-analyzer-environment-context.d.ts +47 -0
  135. package/project/context/flowr-analyzer-environment-context.js +50 -0
  136. package/queries/catalog/call-context-query/call-context-query-executor.js +1 -4
  137. package/queries/catalog/control-flow-query/control-flow-query-format.js +3 -2
  138. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-executor.js +1 -1
  139. package/queries/catalog/dependencies-query/dependencies-query-executor.js +4 -4
  140. package/queries/catalog/df-shape-query/df-shape-query-executor.d.ts +1 -1
  141. package/queries/catalog/df-shape-query/df-shape-query-executor.js +1 -1
  142. package/queries/catalog/df-shape-query/df-shape-query-format.d.ts +4 -4
  143. package/queries/catalog/df-shape-query/df-shape-query-format.js +2 -2
  144. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +3 -3
  145. package/queries/catalog/resolve-value-query/resolve-value-query-executor.js +1 -1
  146. package/queries/catalog/static-slice-query/static-slice-query-executor.js +1 -1
  147. package/slicing/static/slice-call.d.ts +3 -2
  148. package/slicing/static/slice-call.js +4 -4
  149. package/slicing/static/static-slicer.d.ts +3 -1
  150. package/slicing/static/static-slicer.js +6 -7
  151. package/statistics/features/supported/control-flow/control-flow.js +1 -1
  152. package/statistics/features/supported/used-functions/used-functions.js +1 -1
  153. package/statistics/features/supported/variables/variables.js +2 -1
  154. package/util/containers.js +1 -1
  155. package/util/mermaid/dfg.d.ts +1 -0
  156. package/util/mermaid/dfg.js +3 -3
  157. package/util/simple-df/dfg-view.d.ts +2 -1
  158. package/util/simple-df/dfg-view.js +2 -2
  159. package/util/version.js +1 -1
  160. package/dataflow/environments/remove.d.ts +0 -12
  161. package/dataflow/environments/remove.js +0 -52
@@ -8,23 +8,23 @@ const assert_1 = require("../../util/assert");
8
8
  * Add a new local environment scope to the stack, returns the modified variant - sharing the original environments in the stack (no deep-clone)
9
9
  * @see {@link popLocalEnvironment} - to remove the local scope again
10
10
  */
11
- function pushLocalEnvironment(base) {
11
+ function pushLocalEnvironment({ level, current }) {
12
12
  return {
13
- current: new environment_1.Environment(base.current),
14
- level: base.level + 1
13
+ current: new environment_1.Environment(current),
14
+ level: level + 1
15
15
  };
16
16
  }
17
17
  /**
18
18
  * Remove the top local environment scope from the stack, returns the modified variant - sharing the original environments in the stack (no deep-clone)
19
19
  * @see {@link pushLocalEnvironment} - to add a local scope
20
20
  */
21
- function popLocalEnvironment(base) {
22
- (0, assert_1.guard)(base.level > 0, 'cannot remove the global/root environment');
23
- const parent = base.current.parent;
21
+ function popLocalEnvironment({ current, level }) {
22
+ (0, assert_1.guard)(level > 0, 'cannot remove the global/root environment');
23
+ const parent = current.parent;
24
24
  (0, assert_1.guard)(parent !== undefined, 'level is wrong, parent is undefined even though level suggested depth > 0 (starts with 0)');
25
25
  return {
26
26
  current: parent,
27
- level: base.level - 1
27
+ level: level - 1
28
28
  };
29
29
  }
30
30
  //# sourceMappingURL=scoping.js.map
@@ -5,6 +5,7 @@ import { type REnvironmentInformation } from '../../environments/environment';
5
5
  import { type Identifier } from '../../environments/identifier';
6
6
  import type { DataflowGraph } from '../../graph/graph';
7
7
  import { type Lift, type Value, type ValueSet } from '../values/r-value';
8
+ import type { ReadOnlyFlowrAnalyzerContext } from '../../../project/context/flowr-analyzer-context';
8
9
  export type ResolveResult = Lift<ValueSet<Value[]>>;
9
10
  export interface ResolveInfo {
10
11
  /** The current environment used for name resolution */
@@ -16,7 +17,9 @@ export interface ResolveInfo {
16
17
  /** Whether to track variables */
17
18
  full?: boolean;
18
19
  /** Variable resolve mode */
19
- resolve: VariableResolve;
20
+ resolve?: VariableResolve;
21
+ /** Context used for resolving */
22
+ ctx: ReadOnlyFlowrAnalyzerContext;
20
23
  }
21
24
  /**
22
25
  * Gets the definitions / aliases of a node
@@ -50,8 +53,9 @@ export declare function getAliases(sourceIds: readonly NodeId[], dataflow: Dataf
50
53
  * @param idMap - The id map to resolve the node if given as an id
51
54
  * @param full - Whether to track aliases on resolve
52
55
  * @param resolve - Variable resolve mode
56
+ * @param ctx - Context used for clean environment
53
57
  */
54
- export declare function resolveIdToValue(id: NodeId | RNodeWithParent | undefined, { environment, graph, idMap, full, resolve }: ResolveInfo): ResolveResult;
58
+ export declare function resolveIdToValue(id: NodeId | RNodeWithParent | undefined, { environment, graph, idMap, full, resolve, ctx }: ResolveInfo): ResolveResult;
55
59
  /**
56
60
  * Please use {@link resolveIdToValue}
57
61
  *
@@ -60,21 +64,23 @@ export declare function resolveIdToValue(id: NodeId | RNodeWithParent | undefine
60
64
  * @param resolve - Variable resolve mode
61
65
  * @param identifier - Identifier to resolve
62
66
  * @param use - Environment to use
67
+ * @param ctx - analysis context
63
68
  * @param graph - dataflow graph
64
69
  * @param idMap - id map of Dataflow graph
65
70
  * @returns Value of Identifier or Top
66
71
  */
67
- export declare function trackAliasInEnvironments(resolve: VariableResolve, identifier: Identifier | undefined, use: REnvironmentInformation, graph?: DataflowGraph, idMap?: AstIdMap): ResolveResult;
72
+ export declare function trackAliasInEnvironments(resolve: VariableResolve, identifier: Identifier | undefined, use: REnvironmentInformation, ctx: ReadOnlyFlowrAnalyzerContext, graph?: DataflowGraph, idMap?: AstIdMap): ResolveResult;
68
73
  /**
69
74
  * Please use {@link resolveIdToValue}
70
75
  *
71
76
  * Tries to resolve the value of a node by traversing the dataflow graph
72
77
  * @param id - node to resolve
78
+ * @param ctx - analysis context
73
79
  * @param graph - dataflow graph
74
80
  * @param idMap - idmap of dataflow graph
75
81
  * @returns Value of node or Top/Bottom
76
82
  */
77
- export declare function trackAliasesInGraph(id: NodeId, graph: DataflowGraph, idMap?: AstIdMap): ResolveResult;
83
+ export declare function trackAliasesInGraph(id: NodeId, graph: DataflowGraph, ctx: ReadOnlyFlowrAnalyzerContext, idMap?: AstIdMap): ResolveResult;
78
84
  /**
79
85
  * Please use {@link resolveIdToValue}
80
86
  *
@@ -8,10 +8,8 @@ exports.resolveToConstants = resolveToConstants;
8
8
  const config_1 = require("../../../config");
9
9
  const node_id_1 = require("../../../r-bridge/lang-4.x/ast/model/processing/node-id");
10
10
  const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
11
- const fingerprint_1 = require("../../../slicing/static/fingerprint");
12
11
  const visiting_queue_1 = require("../../../slicing/static/visiting-queue");
13
12
  const assert_1 = require("../../../util/assert");
14
- const environment_1 = require("../../environments/environment");
15
13
  const identifier_1 = require("../../environments/identifier");
16
14
  const resolve_by_name_1 = require("../../environments/resolve-by-name");
17
15
  const edge_1 = require("../../graph/edge");
@@ -47,7 +45,7 @@ function getUseAlias(sourceId, dataflow, environment) {
47
45
  if (identifier === undefined) {
48
46
  return undefined;
49
47
  }
50
- const defs = (0, resolve_by_name_1.resolveByName)(identifier, environment);
48
+ const defs = (0, resolve_by_name_1.resolveByNameAnyType)(identifier, environment);
51
49
  if (defs === undefined) {
52
50
  return undefined;
53
51
  }
@@ -114,8 +112,10 @@ function getAliases(sourceIds, dataflow, environment) {
114
112
  * @param idMap - The id map to resolve the node if given as an id
115
113
  * @param full - Whether to track aliases on resolve
116
114
  * @param resolve - Variable resolve mode
115
+ * @param ctx - Context used for clean environment
117
116
  */
118
- function resolveIdToValue(id, { environment, graph, idMap, full = true, resolve }) {
117
+ function resolveIdToValue(id, { environment, graph, idMap, full = true, resolve, ctx }) {
118
+ const variableResolve = resolve ?? ctx.config.solver.variables;
119
119
  if (id === undefined) {
120
120
  return r_value_1.Top;
121
121
  }
@@ -128,10 +128,10 @@ function resolveIdToValue(id, { environment, graph, idMap, full = true, resolve
128
128
  case type_1.RType.Argument:
129
129
  case type_1.RType.Symbol:
130
130
  if (environment) {
131
- return full ? trackAliasInEnvironments(resolve, node.lexeme, environment, graph, idMap) : r_value_1.Top;
131
+ return full ? trackAliasInEnvironments(variableResolve, node.lexeme, environment, ctx, graph, idMap) : r_value_1.Top;
132
132
  }
133
133
  else if (graph && resolve === config_1.VariableResolve.Alias) {
134
- return full ? trackAliasesInGraph(node.info.id, graph, idMap) : r_value_1.Top;
134
+ return full ? trackAliasesInGraph(node.info.id, graph, ctx, idMap) : r_value_1.Top;
135
135
  }
136
136
  else {
137
137
  return r_value_1.Top;
@@ -141,7 +141,7 @@ function resolveIdToValue(id, { environment, graph, idMap, full = true, resolve
141
141
  case type_1.RType.FunctionCall:
142
142
  case type_1.RType.BinaryOp:
143
143
  case type_1.RType.UnaryOp:
144
- return (0, set_constants_1.setFrom)((0, resolve_1.resolveNode)(resolve, node, environment, graph, idMap));
144
+ return (0, set_constants_1.setFrom)((0, resolve_1.resolveNode)(variableResolve, node, ctx, environment, graph, idMap));
145
145
  case type_1.RType.String:
146
146
  case type_1.RType.Number:
147
147
  case type_1.RType.Logical:
@@ -158,15 +158,16 @@ function resolveIdToValue(id, { environment, graph, idMap, full = true, resolve
158
158
  * @param resolve - Variable resolve mode
159
159
  * @param identifier - Identifier to resolve
160
160
  * @param use - Environment to use
161
+ * @param ctx - analysis context
161
162
  * @param graph - dataflow graph
162
163
  * @param idMap - id map of Dataflow graph
163
164
  * @returns Value of Identifier or Top
164
165
  */
165
- function trackAliasInEnvironments(resolve, identifier, use, graph, idMap) {
166
+ function trackAliasInEnvironments(resolve, identifier, use, ctx, graph, idMap) {
166
167
  if (identifier === undefined) {
167
168
  return r_value_1.Top;
168
169
  }
169
- const defs = (0, resolve_by_name_1.resolveByName)(identifier, use);
170
+ const defs = (0, resolve_by_name_1.resolveByNameAnyType)(identifier, use);
170
171
  if (defs === undefined) {
171
172
  return r_value_1.Top;
172
173
  }
@@ -186,7 +187,7 @@ function trackAliasInEnvironments(resolve, identifier, use, graph, idMap) {
186
187
  for (const alias of def.value) {
187
188
  const definitionOfAlias = idMap?.get(alias);
188
189
  if (definitionOfAlias !== undefined) {
189
- const value = (0, resolve_1.resolveNode)(resolve, definitionOfAlias, use, graph, idMap);
190
+ const value = (0, resolve_1.resolveNode)(resolve, definitionOfAlias, ctx, use, graph, idMap);
190
191
  if ((0, r_value_1.isTop)(value)) {
191
192
  return r_value_1.Top;
192
193
  }
@@ -253,19 +254,20 @@ function isNestedInLoop(node, ast) {
253
254
  *
254
255
  * Tries to resolve the value of a node by traversing the dataflow graph
255
256
  * @param id - node to resolve
257
+ * @param ctx - analysis context
256
258
  * @param graph - dataflow graph
257
259
  * @param idMap - idmap of dataflow graph
258
260
  * @returns Value of node or Top/Bottom
259
261
  */
260
- function trackAliasesInGraph(id, graph, idMap) {
262
+ function trackAliasesInGraph(id, graph, ctx, idMap) {
261
263
  if (!graph.get(id)) {
262
264
  return r_value_1.Bottom;
263
265
  }
264
266
  idMap ??= graph.idMap;
265
267
  (0, assert_1.guard)(idMap !== undefined, 'The ID map is required to get the lineage of a node');
266
268
  const queue = new visiting_queue_1.VisitingQueue(25);
267
- const clean = (0, environment_1.initializeCleanEnvironments)();
268
- const cleanFingerprint = (0, fingerprint_1.envFingerprint)(clean);
269
+ const clean = ctx.env.makeCleanEnv();
270
+ const cleanFingerprint = ctx.env.getCleanEnvFingerprint();
269
271
  queue.add(id, clean, cleanFingerprint, false);
270
272
  let forceTop = false;
271
273
  const resultIds = [];
@@ -2,7 +2,8 @@ import { type DataflowGraph } from '../../graph/graph';
2
2
  import type { DataflowGraphVertexFunctionCall } from '../../graph/vertex';
3
3
  import type { NodeId } from '../../../r-bridge/lang-4.x/ast/model/processing/node-id';
4
4
  import type { VariableResolve } from '../../../config';
5
+ import type { ReadOnlyFlowrAnalyzerContext } from '../../../project/context/flowr-analyzer-context';
5
6
  /**
6
7
  * Get the values of all arguments matching the criteria.
7
8
  */
8
- export declare function getArgumentStringValue(variableResolve: VariableResolve, graph: DataflowGraph, vertex: DataflowGraphVertexFunctionCall, argumentIndex: number | 'unnamed' | undefined, argumentName: string | undefined, resolveValue: boolean | 'library' | undefined): Map<NodeId, Set<string | undefined>> | undefined;
9
+ export declare function getArgumentStringValue(variableResolve: VariableResolve, graph: DataflowGraph, vertex: DataflowGraphVertexFunctionCall, argumentIndex: number | 'unnamed' | undefined, argumentName: string | undefined, resolveValue: boolean | 'library' | undefined, ctx: ReadOnlyFlowrAnalyzerContext): Map<NodeId, Set<string | undefined>> | undefined;
@@ -14,7 +14,7 @@ const string_constants_1 = require("../values/string/string-constants");
14
14
  /**
15
15
  * Get the values of all arguments matching the criteria.
16
16
  */
17
- function getArgumentStringValue(variableResolve, graph, vertex, argumentIndex, argumentName, resolveValue) {
17
+ function getArgumentStringValue(variableResolve, graph, vertex, argumentIndex, argumentName, resolveValue, ctx) {
18
18
  if (argumentName) {
19
19
  const arg = vertex?.args.findIndex(arg => arg !== r_function_call_1.EmptyArgument && arg.name === argumentName);
20
20
  if (arg >= 0) {
@@ -35,7 +35,7 @@ function getArgumentStringValue(variableResolve, graph, vertex, argumentIndex, a
35
35
  }
36
36
  if (valueNode) {
37
37
  // this should be evaluated in the callee-context
38
- const values = resolveBasedOnConfig(variableResolve, graph, vertex, valueNode, vertex.environment, graph.idMap, resolveValue) ?? [dependencies_query_format_1.Unknown];
38
+ const values = resolveBasedOnConfig(variableResolve, graph, vertex, valueNode, vertex.environment, graph.idMap, resolveValue, ctx) ?? [dependencies_query_format_1.Unknown];
39
39
  map.set(ref, new Set(values));
40
40
  }
41
41
  }
@@ -51,17 +51,17 @@ function getArgumentStringValue(variableResolve, graph, vertex, argumentIndex, a
51
51
  valueNode = valueNode.value;
52
52
  }
53
53
  if (valueNode) {
54
- const values = resolveBasedOnConfig(variableResolve, graph, vertex, valueNode, vertex.environment, graph.idMap, resolveValue) ?? [dependencies_query_format_1.Unknown];
54
+ const values = resolveBasedOnConfig(variableResolve, graph, vertex, valueNode, vertex.environment, graph.idMap, resolveValue, ctx) ?? [dependencies_query_format_1.Unknown];
55
55
  return new Map([[arg, new Set(values)]]);
56
56
  }
57
57
  }
58
58
  return undefined;
59
59
  }
60
- function hasCharacterOnly(variableResolve, graph, vertex, idMap) {
60
+ function hasCharacterOnly(variableResolve, graph, vertex, idMap, ctx) {
61
61
  if (!vertex.args || vertex.args.length === 0 || !idMap) {
62
62
  return false;
63
63
  }
64
- const treatAsChar = getArgumentStringValue(variableResolve, graph, vertex, 5, 'character.only', true);
64
+ const treatAsChar = getArgumentStringValue(variableResolve, graph, vertex, 5, 'character.only', true, ctx);
65
65
  if (!treatAsChar) {
66
66
  return false;
67
67
  }
@@ -74,13 +74,13 @@ function hasCharacterOnly(variableResolve, graph, vertex, idMap) {
74
74
  return hasTrue;
75
75
  }
76
76
  }
77
- function resolveBasedOnConfig(variableResolve, graph, vertex, argument, environment, idMap, resolveValue) {
77
+ function resolveBasedOnConfig(variableResolve, graph, vertex, argument, environment, idMap, resolveValue, ctx) {
78
78
  let full = true;
79
79
  if (!resolveValue) {
80
80
  full = false;
81
81
  }
82
82
  if (resolveValue === 'library') {
83
- const hasChar = hasCharacterOnly(variableResolve, graph, vertex, idMap);
83
+ const hasChar = hasCharacterOnly(variableResolve, graph, vertex, idMap, ctx);
84
84
  if (hasChar === false) {
85
85
  if (argument.type === type_1.RType.Symbol) {
86
86
  return [argument.lexeme];
@@ -88,7 +88,7 @@ function resolveBasedOnConfig(variableResolve, graph, vertex, argument, environm
88
88
  full = false;
89
89
  }
90
90
  }
91
- const resolved = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(argument, { environment, graph, full, resolve: variableResolve }));
91
+ const resolved = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(argument, { environment, graph, full, resolve: variableResolve, ctx }));
92
92
  if (resolved) {
93
93
  const values = [];
94
94
  for (const value of resolved.elements) {
@@ -1,8 +1,9 @@
1
1
  import type { AstIdMap, RNodeWithParent } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
2
2
  import type { REnvironmentInformation } from '../../environments/environment';
3
3
  import type { DataflowGraph } from '../../graph/graph';
4
- import { type Lift, type Value, type ValueNumber, type ValueVector, Top } from '../values/r-value';
4
+ import { type Lift, Top, type Value, type ValueNumber, type ValueVector } from '../values/r-value';
5
5
  import type { VariableResolve } from '../../../config';
6
+ import type { ReadOnlyFlowrAnalyzerContext } from '../../../project/context/flowr-analyzer-context';
6
7
  /**
7
8
  * Helper function used by {@link resolveIdToValue}, please use that instead, if
8
9
  * you want to resolve the value of an identifier / node
@@ -16,21 +17,22 @@ import type { VariableResolve } from '../../../config';
16
17
  * @param map - Idmap of Dataflow Graph
17
18
  * @returns resolved value or top/bottom
18
19
  */
19
- export declare function resolveNode(resolve: VariableResolve, a: RNodeWithParent, env?: REnvironmentInformation, graph?: DataflowGraph, map?: AstIdMap): Value;
20
+ export declare function resolveNode(resolve: VariableResolve, a: RNodeWithParent, ctx: ReadOnlyFlowrAnalyzerContext, env?: REnvironmentInformation, graph?: DataflowGraph, map?: AstIdMap): Value;
20
21
  /**
21
22
  * Helper function used by {@link resolveIdToValue}, please use that instead, if
22
23
  * you want to resolve the value of an identifier / node
23
24
  *
24
25
  * This function resolves a vector function call `c` to a {@link ValueVector}
25
26
  * by recursively resolving the values of the arguments by calling {@link resolveIdToValue}
26
- * @param resolve - Variable resolve mode
27
- * @param node - Node of the vector function to resolve
28
- * @param env - Environment to use
29
- * @param graph - Dataflow graph
30
- * @param map - Id map of the dataflow graph
27
+ * @param resolve - Variable resolve mode
28
+ * @param node - Node of the vector function to resolve
29
+ * @param environment - Environment to use
30
+ * @param ctx - Analyzer context
31
+ * @param graph - Dataflow graph
32
+ * @param idMap - ID map of the dataflow graph
31
33
  * @returns ValueVector or Top
32
34
  */
33
- export declare function resolveAsVector(resolve: VariableResolve, node: RNodeWithParent, environment?: REnvironmentInformation, graph?: DataflowGraph, idMap?: AstIdMap): ValueVector<Lift<Value[]>> | typeof Top;
35
+ export declare function resolveAsVector(resolve: VariableResolve, node: RNodeWithParent, ctx: ReadOnlyFlowrAnalyzerContext, environment?: REnvironmentInformation, graph?: DataflowGraph, idMap?: AstIdMap): ValueVector<Lift<Value[]>> | typeof Top;
34
36
  /**
35
37
  * Helper function used by {@link resolveIdToValue}, please use that instead, if
36
38
  * you want to resolve the value of an identifier / node
@@ -44,7 +46,7 @@ export declare function resolveAsVector(resolve: VariableResolve, node: RNodeWit
44
46
  * @param map - Id map of the dataflow graph
45
47
  * @returns ValueVector of ValueNumbers or Top
46
48
  */
47
- export declare function resolveAsSeq(resolve: VariableResolve, operator: RNodeWithParent, environment?: REnvironmentInformation, graph?: DataflowGraph, idMap?: AstIdMap): ValueVector<Lift<ValueNumber[]>> | typeof Top;
49
+ export declare function resolveAsSeq(resolve: VariableResolve, operator: RNodeWithParent, ctx: ReadOnlyFlowrAnalyzerContext, environment?: REnvironmentInformation, graph?: DataflowGraph, idMap?: AstIdMap): ValueVector<Lift<ValueNumber[]>> | typeof Top;
48
50
  /**
49
51
  * Helper function used by {@link resolveIdToValue}, please use that instead, if
50
52
  * you want to resolve the value of an identifier / node
@@ -58,7 +60,7 @@ export declare function resolveAsSeq(resolve: VariableResolve, operator: RNodeWi
58
60
  * @param map - Id map of the dataflow graph
59
61
  * @returns ValueNumber, ValueVector of ValueNumbers, or Top
60
62
  */
61
- export declare function resolveAsPlus(resolve: VariableResolve, operator: RNodeWithParent, environment?: REnvironmentInformation, graph?: DataflowGraph, idMap?: AstIdMap): ValueNumber | ValueVector<Lift<ValueNumber[]>> | typeof Top;
63
+ export declare function resolveAsPlus(resolve: VariableResolve, operator: RNodeWithParent, ctx: ReadOnlyFlowrAnalyzerContext, environment?: REnvironmentInformation, graph?: DataflowGraph, idMap?: AstIdMap): ValueNumber | ValueVector<Lift<ValueNumber[]>> | typeof Top;
62
64
  /**
63
65
  * Helper function used by {@link resolveIdToValue}, please use that instead, if
64
66
  * you want to resolve the value of an identifier / node
@@ -72,4 +74,4 @@ export declare function resolveAsPlus(resolve: VariableResolve, operator: RNodeW
72
74
  * @param map - Id map of the dataflow graph
73
75
  * @returns ValueNumber, ValueVector of ValueNumbers, or Top
74
76
  */
75
- export declare function resolveAsMinus(resolve: VariableResolve, operator: RNodeWithParent, environment?: REnvironmentInformation, graph?: DataflowGraph, idMap?: AstIdMap): ValueNumber | ValueVector<Lift<ValueNumber[]>> | typeof Top;
77
+ export declare function resolveAsMinus(resolve: VariableResolve, operator: RNodeWithParent, ctx: ReadOnlyFlowrAnalyzerContext, environment?: REnvironmentInformation, graph?: DataflowGraph, idMap?: AstIdMap): ValueNumber | ValueVector<Lift<ValueNumber[]>> | typeof Top;
@@ -30,7 +30,7 @@ const scalar_consatnts_1 = require("../values/scalar/scalar-consatnts");
30
30
  * @param map - Idmap of Dataflow Graph
31
31
  * @returns resolved value or top/bottom
32
32
  */
33
- function resolveNode(resolve, a, env, graph, map) {
33
+ function resolveNode(resolve, a, ctx, env, graph, map) {
34
34
  if (a.type === type_1.RType.String) {
35
35
  return (0, string_constants_1.stringFrom)(a.content.str);
36
36
  }
@@ -63,7 +63,7 @@ function resolveNode(resolve, a, env, graph, map) {
63
63
  }
64
64
  if (Object.hasOwn(built_in_1.BuiltInEvalHandlerMapper, builtInName)) {
65
65
  const handler = built_in_1.BuiltInEvalHandlerMapper[builtInName];
66
- return handler(resolve, a, env, graph, map);
66
+ return handler(resolve, a, ctx, env, graph, map);
67
67
  }
68
68
  }
69
69
  return r_value_2.Top;
@@ -74,18 +74,19 @@ function resolveNode(resolve, a, env, graph, map) {
74
74
  *
75
75
  * This function resolves a vector function call `c` to a {@link ValueVector}
76
76
  * by recursively resolving the values of the arguments by calling {@link resolveIdToValue}
77
- * @param resolve - Variable resolve mode
78
- * @param node - Node of the vector function to resolve
79
- * @param env - Environment to use
80
- * @param graph - Dataflow graph
81
- * @param map - Id map of the dataflow graph
77
+ * @param resolve - Variable resolve mode
78
+ * @param node - Node of the vector function to resolve
79
+ * @param environment - Environment to use
80
+ * @param ctx - Analyzer context
81
+ * @param graph - Dataflow graph
82
+ * @param idMap - ID map of the dataflow graph
82
83
  * @returns ValueVector or Top
83
84
  */
84
- function resolveAsVector(resolve, node, environment, graph, idMap) {
85
+ function resolveAsVector(resolve, node, ctx, environment, graph, idMap) {
85
86
  if (node.type !== type_1.RType.FunctionCall) {
86
87
  return r_value_2.Top;
87
88
  }
88
- const resolveInfo = { environment, graph, idMap, full: true, resolve };
89
+ const resolveInfo = { environment, graph, idMap, full: true, resolve, ctx };
89
90
  const values = node.arguments.map(arg => arg !== r_function_call_1.EmptyArgument ? (0, alias_tracking_1.resolveIdToValue)(arg.value, resolveInfo) : r_value_2.Top);
90
91
  return (0, vector_constants_1.vectorFrom)((0, vector_constants_1.flattenVectorElements)(values));
91
92
  }
@@ -102,11 +103,11 @@ function resolveAsVector(resolve, node, environment, graph, idMap) {
102
103
  * @param map - Id map of the dataflow graph
103
104
  * @returns ValueVector of ValueNumbers or Top
104
105
  */
105
- function resolveAsSeq(resolve, operator, environment, graph, idMap) {
106
+ function resolveAsSeq(resolve, operator, ctx, environment, graph, idMap) {
106
107
  if (operator.type !== type_1.RType.BinaryOp) {
107
108
  return r_value_2.Top;
108
109
  }
109
- const resolveInfo = { environment, graph, idMap, full: true, resolve };
110
+ const resolveInfo = { environment, graph, idMap, full: true, resolve, ctx };
110
111
  const leftArg = (0, alias_tracking_1.resolveIdToValue)(operator.lhs, resolveInfo);
111
112
  const rightArg = (0, alias_tracking_1.resolveIdToValue)(operator.rhs, resolveInfo);
112
113
  const leftValue = (0, r_value_1.unliftRValue)(leftArg);
@@ -129,11 +130,11 @@ function resolveAsSeq(resolve, operator, environment, graph, idMap) {
129
130
  * @param map - Id map of the dataflow graph
130
131
  * @returns ValueNumber, ValueVector of ValueNumbers, or Top
131
132
  */
132
- function resolveAsPlus(resolve, operator, environment, graph, idMap) {
133
+ function resolveAsPlus(resolve, operator, ctx, environment, graph, idMap) {
133
134
  if (operator.type !== type_1.RType.UnaryOp) {
134
135
  return r_value_2.Top;
135
136
  }
136
- const resolveInfo = { environment, graph, idMap, full: true, resolve };
137
+ const resolveInfo = { environment, graph, idMap, full: true, resolve, ctx };
137
138
  const arg = (0, alias_tracking_1.resolveIdToValue)(operator.operand, resolveInfo);
138
139
  const argValue = (0, r_value_1.unliftRValue)(arg);
139
140
  if ((0, r_value_1.isRNumberValue)(argValue)) {
@@ -157,11 +158,11 @@ function resolveAsPlus(resolve, operator, environment, graph, idMap) {
157
158
  * @param map - Id map of the dataflow graph
158
159
  * @returns ValueNumber, ValueVector of ValueNumbers, or Top
159
160
  */
160
- function resolveAsMinus(resolve, operator, environment, graph, idMap) {
161
+ function resolveAsMinus(resolve, operator, ctx, environment, graph, idMap) {
161
162
  if (operator.type !== type_1.RType.UnaryOp) {
162
163
  return r_value_2.Top;
163
164
  }
164
- const resolveInfo = { environment, graph, idMap, full: true, resolve };
165
+ const resolveInfo = { environment, graph, idMap, full: true, resolve, ctx };
165
166
  const arg = (0, alias_tracking_1.resolveIdToValue)(operator.operand, resolveInfo);
166
167
  const argValue = (0, r_value_1.unliftRValue)(arg);
167
168
  if ((0, r_value_1.isRNumberValue)(argValue)) {
@@ -14,13 +14,11 @@ const named_call_handling_1 = require("./internal/process/functions/call/named-c
14
14
  const make_argument_1 = require("./internal/process/functions/call/argument/make-argument");
15
15
  const range_1 = require("../util/range");
16
16
  const type_1 = require("../r-bridge/lang-4.x/ast/model/type");
17
- const environment_1 = require("./environments/environment");
18
17
  const built_in_source_1 = require("./internal/process/functions/call/built-in/built-in-source");
19
18
  const extract_cfg_1 = require("../control-flow/extract-cfg");
20
19
  const edge_1 = require("./graph/edge");
21
20
  const identify_link_to_last_call_relation_1 = require("../queries/catalog/call-context-query/identify-link-to-last-call-relation");
22
21
  const built_in_function_definition_1 = require("./internal/process/functions/call/built-in/built-in-function-definition");
23
- const built_in_config_1 = require("./environments/built-in-config");
24
22
  const flowr_file_1 = require("../project/context/flowr-file");
25
23
  /**
26
24
  * The best friend of {@link produceDataFlowGraph} and {@link processDataflowFor}.
@@ -95,17 +93,13 @@ function resolveLinkToSideEffects(ast, graph) {
95
93
  * For the actual, canonical fold entry point, see {@link processDataflowFor}.
96
94
  */
97
95
  function produceDataFlowGraph(parser, completeAst, ctx) {
98
- const builtInsConfig = ctx.config.semantics.environment.overwriteBuiltIns;
99
- const builtIns = (0, built_in_config_1.getBuiltInDefinitions)(builtInsConfig.definitions, builtInsConfig.loadDefaults);
100
- const env = (0, environment_1.initializeCleanEnvironments)(builtIns.builtInMemory);
101
96
  // we freeze the files here to avoid endless modifications during processing
102
97
  const files = completeAst.ast.files.slice();
103
98
  ctx.files.addConsideredFile(files[0].filePath ? files[0].filePath : flowr_file_1.FlowrFile.INLINE_PATH);
104
99
  const dfData = {
105
100
  parser,
106
101
  completeAst,
107
- environment: env,
108
- builtInEnvironment: env.current.parent,
102
+ environment: ctx.env.makeCleanEnv(),
109
103
  processors: exports.processors,
110
104
  controlDependencies: undefined,
111
105
  referenceChain: [files[0].filePath],
@@ -1,9 +1,10 @@
1
1
  import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
2
2
  import type { DataflowGraph } from '../graph/graph';
3
+ import type { ReadOnlyFlowrAnalyzerContext } from '../../project/context/flowr-analyzer-context';
3
4
  /**
4
5
  * Determines whether the function with the given id is a higher-order function, i.e.,
5
6
  * either takes a function as an argument or (may) returns a function.
6
7
  * If the return is an identity, e.g., `function(x) x`, this is not considered higher-order,
7
8
  * if no function is passed as an argument.
8
9
  */
9
- export declare function isHigherOrder(id: NodeId, graph: DataflowGraph): boolean;
10
+ export declare function isHigherOrder(id: NodeId, graph: DataflowGraph, ctx: ReadOnlyFlowrAnalyzerContext): boolean;
@@ -32,7 +32,7 @@ function isAnyReturnAFunction(def, graph) {
32
32
  }
33
33
  return false;
34
34
  }
35
- function inspectCallSitesArgumentsFns(def, graph) {
35
+ function inspectCallSitesArgumentsFns(def, graph, ctx) {
36
36
  const callSites = graph.ingoingEdges(def.id);
37
37
  for (const [callerId, { types }] of callSites ?? []) {
38
38
  if (!(0, edge_1.edgeIncludesType)(types, edge_1.EdgeType.Calls)) {
@@ -46,7 +46,7 @@ function inspectCallSitesArgumentsFns(def, graph) {
46
46
  if (arg === r_function_call_1.EmptyArgument) {
47
47
  continue;
48
48
  }
49
- const value = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(arg.nodeId, { graph, idMap: graph.idMap, resolve: config_1.VariableResolve.Alias, full: true }));
49
+ const value = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(arg.nodeId, { graph, idMap: graph.idMap, resolve: config_1.VariableResolve.Alias, full: true, ctx }));
50
50
  if (value?.elements.some(e => e.type === 'function-definition')) {
51
51
  return true;
52
52
  }
@@ -60,7 +60,7 @@ function inspectCallSitesArgumentsFns(def, graph) {
60
60
  * If the return is an identity, e.g., `function(x) x`, this is not considered higher-order,
61
61
  * if no function is passed as an argument.
62
62
  */
63
- function isHigherOrder(id, graph) {
63
+ function isHigherOrder(id, graph, ctx) {
64
64
  const vert = graph.getVertex(id);
65
65
  if (!vert || !(0, vertex_1.isFunctionDefinitionVertex)(vert)) {
66
66
  return false;
@@ -70,6 +70,6 @@ function isHigherOrder(id, graph) {
70
70
  return true;
71
71
  }
72
72
  // 2. check whether any of the callsites passes a function
73
- return inspectCallSitesArgumentsFns(vert, graph);
73
+ return inspectCallSitesArgumentsFns(vert, graph, ctx);
74
74
  }
75
75
  //# sourceMappingURL=higher-order-function.js.map
@@ -1,23 +1,27 @@
1
1
  import { type NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
2
2
  import type { AstIdMap } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
3
- import { type DataflowFunctionFlowInformation, type FunctionArgument, DataflowGraph } from './graph';
3
+ import { type DataflowFunctionFlowInformation, DataflowGraph, type FunctionArgument } from './graph';
4
4
  import { type IEnvironment, type REnvironmentInformation } from '../environments/environment';
5
- import { type DataflowGraphVertexAstLink, type DataflowGraphVertexUse, type FunctionOriginInformation } from './vertex';
5
+ import { type DataflowGraphVertexArgument, type DataflowGraphVertexAstLink, type DataflowGraphVertexInfo, type DataflowGraphVertexUse, type FunctionOriginInformation } from './vertex';
6
6
  import type { ControlDependency } from '../info';
7
7
  import type { LinkTo } from '../../queries/catalog/call-context-query/call-context-query-format';
8
8
  import type { FlowrSearchLike } from '../../search/flowr-search-builder';
9
9
  import type { ReadonlyFlowrAnalysisProvider } from '../../project/flowr-analyzer';
10
10
  /**
11
- *
11
+ * Creates an empty dataflow graph.
12
+ * Should only be used in tests and documentation.
12
13
  */
13
- export declare function emptyGraph(idMap?: AstIdMap): DataflowGraphBuilder;
14
+ export declare function emptyGraph(cleanEnv?: REnvironmentInformation, idMap?: AstIdMap): DataflowGraphBuilder<DataflowGraphVertexInfo>;
14
15
  export type DataflowGraphEdgeTarget = NodeId | (readonly NodeId[]);
15
16
  /**
16
17
  * This DataflowGraphBuilder extends {@link DataflowGraph} with builder methods to
17
18
  * easily and compactly add vertices and edges to a dataflow graph. Its usage thus
18
19
  * simplifies writing tests for dataflow graphs.
19
20
  */
20
- export declare class DataflowGraphBuilder extends DataflowGraph {
21
+ export declare class DataflowGraphBuilder<Vertex extends DataflowGraphVertexInfo = DataflowGraphVertexInfo> extends DataflowGraph {
22
+ private readonly defaultEnvironment;
23
+ constructor(cleanEnv?: REnvironmentInformation, idMap?: AstIdMap);
24
+ addVertexWithDefaultEnv(vertex: DataflowGraphVertexArgument & Omit<Vertex, keyof DataflowGraphVertexArgument>, asRoot?: boolean, overwrite?: boolean): this;
21
25
  /**
22
26
  * Adds a **vertex** for a **function definition** (V1).
23
27
  * @param id - AST node ID
@@ -6,7 +6,6 @@ exports.getBuiltInSideEffect = getBuiltInSideEffect;
6
6
  const objects_1 = require("../../util/objects");
7
7
  const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
8
8
  const graph_1 = require("./graph");
9
- const environment_1 = require("../environments/environment");
10
9
  const vertex_1 = require("./vertex");
11
10
  const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
12
11
  const built_in_1 = require("../environments/built-in");
@@ -14,11 +13,13 @@ const edge_1 = require("./edge");
14
13
  const default_builtin_config_1 = require("../environments/default-builtin-config");
15
14
  const flowr_search_executor_1 = require("../../search/flowr-search-executor");
16
15
  const assert_1 = require("../../util/assert");
16
+ const flowr_analyzer_context_1 = require("../../project/context/flowr-analyzer-context");
17
17
  /**
18
- *
18
+ * Creates an empty dataflow graph.
19
+ * Should only be used in tests and documentation.
19
20
  */
20
- function emptyGraph(idMap) {
21
- return new DataflowGraphBuilder(idMap);
21
+ function emptyGraph(cleanEnv, idMap) {
22
+ return new DataflowGraphBuilder(cleanEnv, idMap);
22
23
  }
23
24
  /**
24
25
  * This DataflowGraphBuilder extends {@link DataflowGraph} with builder methods to
@@ -26,6 +27,15 @@ function emptyGraph(idMap) {
26
27
  * simplifies writing tests for dataflow graphs.
27
28
  */
28
29
  class DataflowGraphBuilder extends graph_1.DataflowGraph {
30
+ defaultEnvironment;
31
+ constructor(cleanEnv, idMap) {
32
+ super(idMap);
33
+ this.defaultEnvironment = cleanEnv ?? (0, flowr_analyzer_context_1.contextFromInput)('').env.makeCleanEnv();
34
+ }
35
+ addVertexWithDefaultEnv(vertex, asRoot = true, overwrite = false) {
36
+ super.addVertex(vertex, this.defaultEnvironment, asRoot, overwrite);
37
+ return this;
38
+ }
29
39
  /**
30
40
  * Adds a **vertex** for a **function definition** (V1).
31
41
  * @param id - AST node ID
@@ -36,7 +46,7 @@ class DataflowGraphBuilder extends graph_1.DataflowGraph {
36
46
  * (i.e., be a valid entry point), or is it nested (e.g., as part of a function definition)
37
47
  */
38
48
  defineFunction(id, exitPoints, subflow, info, asRoot = true) {
39
- return this.addVertex({
49
+ return this.addVertexWithDefaultEnv({
40
50
  tag: vertex_1.VertexType.FunctionDefinition,
41
51
  id: (0, node_id_1.normalizeIdToNumberIfPossible)(id),
42
52
  subflow: {
@@ -49,7 +59,7 @@ class DataflowGraphBuilder extends graph_1.DataflowGraph {
49
59
  },
50
60
  exitPoints: exitPoints.map(node_id_1.normalizeIdToNumberIfPossible),
51
61
  cds: info?.controlDependencies?.map(c => ({ ...c, id: (0, node_id_1.normalizeIdToNumberIfPossible)(c.id) })),
52
- environment: info?.environment
62
+ environment: info?.environment,
53
63
  }, asRoot);
54
64
  }
55
65
  /**
@@ -63,12 +73,12 @@ class DataflowGraphBuilder extends graph_1.DataflowGraph {
63
73
  */
64
74
  call(id, name, args, info, asRoot = true) {
65
75
  const onlyBuiltInAuto = info?.reads?.length === 1 && (0, built_in_1.isBuiltIn)(info?.reads[0]);
66
- this.addVertex({
76
+ this.addVertexWithDefaultEnv({
67
77
  tag: vertex_1.VertexType.FunctionCall,
68
78
  id: (0, node_id_1.normalizeIdToNumberIfPossible)(id),
69
79
  name,
70
80
  args: args.map(a => a === r_function_call_1.EmptyArgument ? r_function_call_1.EmptyArgument : { ...a, nodeId: (0, node_id_1.normalizeIdToNumberIfPossible)(a.nodeId), controlDependencies: undefined }),
71
- environment: (info?.onlyBuiltIn || onlyBuiltInAuto) ? undefined : info?.environment ?? (0, environment_1.initializeCleanEnvironments)(),
81
+ environment: (info?.onlyBuiltIn || onlyBuiltInAuto) ? undefined : info?.environment ?? this.defaultEnvironment,
72
82
  cds: info?.controlDependencies?.map(c => ({ ...c, id: (0, node_id_1.normalizeIdToNumberIfPossible)(c.id) })),
73
83
  onlyBuiltin: info?.onlyBuiltIn ?? onlyBuiltInAuto ?? false,
74
84
  origin: info?.origin ?? [(0, default_builtin_config_1.getDefaultProcessor)(name) ?? 'function'],
@@ -115,7 +125,7 @@ class DataflowGraphBuilder extends graph_1.DataflowGraph {
115
125
  * (i.e., be a valid entry point), or is it nested (e.g., as part of a function definition)
116
126
  */
117
127
  defineVariable(id, name, info, asRoot = true) {
118
- this.addVertex({
128
+ this.addVertexWithDefaultEnv({
119
129
  tag: vertex_1.VertexType.VariableDefinition,
120
130
  id: (0, node_id_1.normalizeIdToNumberIfPossible)(id),
121
131
  name,
@@ -137,7 +147,7 @@ class DataflowGraphBuilder extends graph_1.DataflowGraph {
137
147
  * (i.e., be a valid entry point) or is it nested (e.g., as part of a function definition)
138
148
  */
139
149
  use(id, name, info, asRoot = true) {
140
- return this.addVertex((0, objects_1.deepMergeObject)({
150
+ return this.addVertexWithDefaultEnv((0, objects_1.deepMergeObject)({
141
151
  tag: vertex_1.VertexType.Use,
142
152
  id: (0, node_id_1.normalizeIdToNumberIfPossible)(id),
143
153
  name,
@@ -156,7 +166,7 @@ class DataflowGraphBuilder extends graph_1.DataflowGraph {
156
166
  * (i.e., be a valid entry point), or is it nested (e.g., as part of a function definition)
157
167
  */
158
168
  constant(id, options, asRoot = true) {
159
- return this.addVertex({
169
+ return this.addVertexWithDefaultEnv({
160
170
  tag: vertex_1.VertexType.Value,
161
171
  id: (0, node_id_1.normalizeIdToNumberIfPossible)(id),
162
172
  cds: options?.controlDependencies?.map(c => ({ ...c, id: (0, node_id_1.normalizeIdToNumberIfPossible)(c.id) })),