@eagleoutice/flowr 2.10.4 → 2.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/README.md +31 -14
  2. package/abstract-interpretation/absint-visitor.d.ts +17 -22
  3. package/abstract-interpretation/absint-visitor.js +47 -48
  4. package/abstract-interpretation/data-frame/dataframe-domain.d.ts +0 -3
  5. package/abstract-interpretation/data-frame/shape-inference.d.ts +2 -1
  6. package/abstract-interpretation/data-frame/shape-inference.js +5 -4
  7. package/abstract-interpretation/domains/abstract-domain.d.ts +17 -16
  8. package/abstract-interpretation/domains/abstract-domain.js +25 -27
  9. package/abstract-interpretation/domains/bounded-set-domain.js +1 -1
  10. package/abstract-interpretation/domains/multi-value-state-domain.d.ts +32 -0
  11. package/abstract-interpretation/domains/multi-value-state-domain.js +60 -0
  12. package/abstract-interpretation/domains/partial-product-domain.d.ts +43 -0
  13. package/abstract-interpretation/domains/partial-product-domain.js +163 -0
  14. package/abstract-interpretation/domains/product-domain.d.ts +2 -29
  15. package/abstract-interpretation/domains/product-domain.js +6 -123
  16. package/abstract-interpretation/domains/set-range-domain.js +3 -3
  17. package/abstract-interpretation/domains/set-upper-bound-domain.js +1 -1
  18. package/abstract-interpretation/domains/singleton-domain.js +1 -1
  19. package/abstract-interpretation/domains/state-abstract-domain.d.ts +13 -28
  20. package/abstract-interpretation/domains/state-abstract-domain.js +16 -38
  21. package/abstract-interpretation/domains/state-domain-like.d.ts +36 -0
  22. package/abstract-interpretation/domains/state-domain-like.js +3 -0
  23. package/cli/flowr.js +11 -1
  24. package/config.d.ts +13 -0
  25. package/config.js +24 -3
  26. package/control-flow/basic-cfg-guided-visitor.d.ts +1 -1
  27. package/control-flow/semantic-cfg-guided-visitor.d.ts +4 -0
  28. package/control-flow/semantic-cfg-guided-visitor.js +23 -32
  29. package/dataflow/environments/built-in-proc-name.d.ts +7 -1
  30. package/dataflow/environments/built-in-proc-name.js +6 -0
  31. package/dataflow/environments/built-in.d.ts +6 -0
  32. package/dataflow/environments/built-in.js +6 -0
  33. package/dataflow/environments/default-builtin-config.d.ts +63 -1
  34. package/dataflow/environments/default-builtin-config.js +15 -4
  35. package/dataflow/environments/identifier.d.ts +14 -0
  36. package/dataflow/graph/vertex.d.ts +6 -0
  37. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +16 -0
  38. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +6 -0
  39. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +99 -2
  40. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +13 -0
  41. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +48 -0
  42. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +75 -0
  43. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +196 -0
  44. package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +2 -0
  45. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +38 -21
  46. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +5 -0
  47. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +27 -13
  48. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +14 -4
  49. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.d.ts +27 -0
  50. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +97 -0
  51. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +23 -0
  52. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +90 -0
  53. package/documentation/doc-readme.js +13 -2
  54. package/documentation/doc-util/doc-types.d.ts +11 -2
  55. package/documentation/doc-util/doc-types.js +31 -9
  56. package/documentation/wiki-absint.d.ts +17 -2
  57. package/documentation/wiki-absint.js +83 -24
  58. package/documentation/wiki-analyzer.js +3 -4
  59. package/documentation/wiki-interface.js +22 -16
  60. package/documentation/wiki-mk/doc-context.d.ts +14 -1
  61. package/documentation/wiki-mk/doc-context.js +6 -0
  62. package/documentation/wiki-normalized-ast.d.ts +0 -9
  63. package/documentation/wiki-normalized-ast.js +9 -60
  64. package/linter/linter-rules.d.ts +4 -3
  65. package/linter/rules/problematic-inputs.d.ts +13 -7
  66. package/linter/rules/problematic-inputs.js +109 -60
  67. package/package.json +3 -3
  68. package/project/flowr-analyzer-builder.d.ts +6 -3
  69. package/project/flowr-analyzer-builder.js +12 -5
  70. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +4 -3
  71. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +17 -4
  72. package/project/plugins/flowr-analyzer-plugin.d.ts +1 -1
  73. package/project/plugins/flowr-analyzer-plugin.js +1 -1
  74. package/queries/catalog/dependencies-query/function-info/read-functions.js +2 -0
  75. package/queries/catalog/dependencies-query/function-info/write-functions.js +1 -0
  76. package/queries/catalog/input-sources-query/input-source-functions.d.ts +7 -0
  77. package/queries/catalog/input-sources-query/input-source-functions.js +56 -0
  78. package/queries/catalog/input-sources-query/input-sources-query-executor.d.ts +1 -1
  79. package/queries/catalog/input-sources-query/input-sources-query-executor.js +19 -53
  80. package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +2 -1
  81. package/queries/catalog/input-sources-query/input-sources-query-format.js +28 -11
  82. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +21 -42
  83. package/queries/catalog/input-sources-query/simple-input-classifier.js +168 -104
  84. package/r-bridge/data/data.d.ts +28 -2
  85. package/r-bridge/data/data.js +34 -2
  86. package/r-bridge/lang-4.x/ast/model/model.d.ts +5 -6
  87. package/r-bridge/lang-4.x/ast/model/model.js +0 -1
  88. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +6 -6
  89. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +6 -6
  90. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +6 -6
  91. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +6 -6
  92. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +6 -6
  93. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +6 -6
  94. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +6 -6
  95. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +6 -6
  96. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +6 -6
  97. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +6 -6
  98. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +6 -6
  99. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +6 -6
  100. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +6 -6
  101. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +6 -6
  102. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +6 -6
  103. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +6 -6
  104. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +6 -6
  105. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +6 -6
  106. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +6 -6
  107. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +6 -6
  108. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +6 -6
  109. package/util/record.d.ts +18 -3
  110. package/util/record.js +22 -1
  111. package/util/version.js +1 -1
  112. package/abstract-interpretation/normalized-ast-fold.d.ts +0 -119
  113. package/abstract-interpretation/normalized-ast-fold.js +0 -181
  114. package/project/plugins/flowr-analyzer-plugin-defaults.d.ts +0 -5
  115. package/project/plugins/flowr-analyzer-plugin-defaults.js +0 -37
@@ -0,0 +1,36 @@
1
+ import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
2
+ import { type AnyAbstractDomain } from './abstract-domain';
3
+ /**
4
+ * An interface for state-like domains that store abstract values for AST nodes.
5
+ */
6
+ export interface StateDomainLike<Domain extends AnyAbstractDomain> {
7
+ /**
8
+ * The underlying value domain of the state domain.
9
+ */
10
+ get domain(): Domain;
11
+ /**
12
+ * Gets the inferred abstract value for an AST node ID.
13
+ */
14
+ get(node: NodeId): Domain | undefined;
15
+ /**
16
+ * Checks whether the state domain has an inferred value for an AST node ID.
17
+ */
18
+ has(node: NodeId): boolean;
19
+ /**
20
+ * Removes the inferred value for an AST node ID from the state domain.
21
+ */
22
+ remove(node: NodeId): void;
23
+ /**
24
+ * Sets the inferred value for an AST node ID from the state domain.
25
+ */
26
+ set(node: NodeId, value: Domain): void;
27
+ }
28
+ /**
29
+ * A type representing any state abstract domain that stores abstract values for AST nodes.
30
+ */
31
+ export type AnyStateDomain<Domain extends AnyAbstractDomain = AnyAbstractDomain> = AnyAbstractDomain & StateDomainLike<Domain>;
32
+ /**
33
+ * The type of the value abstract domain of a state abstract domain.
34
+ * @template StateDomain - The state abstract domain to get the value abstract domain type for
35
+ */
36
+ export type ValueDomain<StateDomain extends AnyStateDomain> = StateDomain extends AnyStateDomain<infer Domain> ? Domain : never;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=state-domain-like.js.map
package/cli/flowr.js CHANGED
@@ -102,6 +102,15 @@ function hookSignalHandlers(engines) {
102
102
  process.on('SIGINT', end);
103
103
  process.on('SIGTERM', end);
104
104
  }
105
+ function getReplPlugins(config) {
106
+ const plugins = config.repl.plugins.filter(p => p !== 'flowr:default');
107
+ if (plugins.length !== config.repl.plugins.length) {
108
+ return plugins.concat(config.defaultPlugins);
109
+ }
110
+ else {
111
+ return plugins;
112
+ }
113
+ }
105
114
  async function mainRepl() {
106
115
  const config = createConfig();
107
116
  if (options.script) {
@@ -128,9 +137,10 @@ async function mainRepl() {
128
137
  process.exit(0);
129
138
  }
130
139
  hookSignalHandlers(engines);
131
- const analyzer = new flowr_analyzer_builder_1.FlowrAnalyzerBuilder()
140
+ const analyzer = new flowr_analyzer_builder_1.FlowrAnalyzerBuilder(false)
132
141
  .setParser(defaultEngine)
133
142
  .setConfig(config)
143
+ .registerPlugins(...getReplPlugins(config))
134
144
  .buildSync();
135
145
  const allowRSessionAccess = options['r-session-access'] ?? false;
136
146
  if (options.execute) {
package/config.d.ts CHANGED
@@ -6,6 +6,7 @@ import type { DeepWritable, Paths, PathValue } from 'ts-essentials';
6
6
  import type { DataflowProcessors } from './dataflow/processor';
7
7
  import type { ParentInformation } from './r-bridge/lang-4.x/ast/model/processing/decorate';
8
8
  import type { FlowrAnalyzerContext } from './project/context/flowr-analyzer-context';
9
+ import type { BuiltInFlowrPluginArgs, BuiltInFlowrPluginName } from './project/plugins/plugin-registry';
9
10
  export declare enum VariableResolve {
10
11
  /** Don't resolve constants at all */
11
12
  Disabled = "disabled",
@@ -83,6 +84,7 @@ export interface FlowrLaxSourcingOptions extends MergeableRecord {
83
84
  */
84
85
  readonly applyReplacements?: Record<string, string>[];
85
86
  }
87
+ export type ConfigPlugin<T extends BuiltInFlowrPluginName | string> = T | string | (T extends BuiltInFlowrPluginName ? [T, BuiltInFlowrPluginArgs<T>] : [string, unknown[]]);
86
88
  /**
87
89
  * The configuration file format for flowR.
88
90
  * @see {@link FlowrConfig.default} for the default configuration.
@@ -106,12 +108,16 @@ export interface FlowrConfig extends MergeableRecord {
106
108
  };
107
109
  };
108
110
  };
111
+ /** Plugins to load by default when creating a new FlowrAnalyzer */
112
+ readonly defaultPlugins: ConfigPlugin<string>[];
109
113
  /** Configuration options for the REPL */
110
114
  readonly repl: {
111
115
  /** Whether to show quick stats in the REPL after each evaluation */
112
116
  quickStats: boolean;
113
117
  /** This instruments the dataflow processors to count how often each processor is called */
114
118
  dfProcessorHeat: boolean;
119
+ /** Plugins to load in REPL mode */
120
+ plugins: (ConfigPlugin<string> | 'flowr:default')[];
115
121
  };
116
122
  readonly project: {
117
123
  /** Whether to resolve unknown paths loaded by the r project disk when trying to source/analyze files */
@@ -136,6 +142,12 @@ export interface FlowrConfig extends MergeableRecord {
136
142
  * Should we include eval(parse(text="...")) calls in the dataflow graph?
137
143
  */
138
144
  readonly evalStrings: boolean;
145
+ /**
146
+ * Track user-created environments (`new.env()`, `assign(..., envir=e)`, `get(..., envir=e)`,
147
+ * `local({}, envir=e)`, `e$x <- v`, `attach(e)`) with precise per-variable envState.
148
+ * When disabled all envir-style calls fall through to the conservative global treatment.
149
+ */
150
+ readonly trackEnvironments: boolean;
139
151
  /** These keys are only intended for use within code, allowing to instrument the dataflow analyzer! */
140
152
  readonly instrument: {
141
153
  /**
@@ -226,6 +238,7 @@ export type EngineConfig = TreeSitterEngineConfig | RShellEngineConfig;
226
238
  export type KnownEngines = {
227
239
  [T in EngineConfig['type']]?: KnownParser;
228
240
  };
241
+ export declare const FlowrDefaultPlugins: string[];
229
242
  /**
230
243
  * Helper Object to work with {@link FlowrConfig}, provides the default config and the Joi schema for validation.
231
244
  */
package/config.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FlowrConfig = exports.DropPathsOption = exports.InferWorkingDirectory = exports.VariableResolve = void 0;
6
+ exports.FlowrConfig = exports.FlowrDefaultPlugins = exports.DropPathsOption = exports.InferWorkingDirectory = exports.VariableResolve = void 0;
7
7
  const objects_1 = require("./util/objects");
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const fs_1 = __importDefault(require("fs"));
@@ -50,6 +50,21 @@ const defaultEngineConfigs = {
50
50
  'tree-sitter': { type: 'tree-sitter' },
51
51
  'r-shell': { type: 'r-shell' }
52
52
  };
53
+ exports.FlowrDefaultPlugins = [
54
+ 'file:description',
55
+ 'versions:description',
56
+ 'loading-order:description',
57
+ 'meta:description',
58
+ 'files:vignette',
59
+ 'files:test',
60
+ 'file:rmd',
61
+ 'file:qmd',
62
+ 'file:rnw',
63
+ 'file:ipynb',
64
+ 'file:namespace',
65
+ 'file:news',
66
+ 'file:license',
67
+ ];
53
68
  /**
54
69
  * Helper Object to work with {@link FlowrConfig}, provides the default config and the Joi schema for validation.
55
70
  */
@@ -70,9 +85,11 @@ exports.FlowrConfig = {
70
85
  }
71
86
  }
72
87
  },
88
+ defaultPlugins: exports.FlowrDefaultPlugins,
73
89
  repl: {
74
90
  quickStats: false,
75
- dfProcessorHeat: false
91
+ dfProcessorHeat: false,
92
+ plugins: ['flowr:default'],
76
93
  },
77
94
  project: {
78
95
  resolveUnknownPathsOnDisk: true
@@ -82,6 +99,7 @@ exports.FlowrConfig = {
82
99
  solver: {
83
100
  variables: VariableResolve.Alias,
84
101
  evalStrings: true,
102
+ trackEnvironments: true,
85
103
  resolveSource: {
86
104
  dropPaths: DropPathsOption.No,
87
105
  ignoreCapitalization: true,
@@ -122,9 +140,11 @@ exports.FlowrConfig = {
122
140
  }).optional().description('Do you want to overwrite (parts) of the builtin definition?')
123
141
  }).optional().description('Semantics regarding how to handle the R environment.')
124
142
  }).description('Configure language semantics and how flowR handles them.'),
143
+ defaultPlugins: joi_1.default.array().items(joi_1.default.alternatives().try(joi_1.default.string(), joi_1.default.array().ordered(joi_1.default.string(), joi_1.default.array().items(joi_1.default.any())).length(2))).optional().description('The default plugins to load when creating a new instance of FlowrAnalyzer'),
125
144
  repl: joi_1.default.object({
126
145
  quickStats: joi_1.default.boolean().optional().description('Whether to show quick stats in the REPL after each evaluation.'),
127
- dfProcessorHeat: joi_1.default.boolean().optional().description('This instruments the dataflow processors to count how often each processor is called.')
146
+ dfProcessorHeat: joi_1.default.boolean().optional().description('This instruments the dataflow processors to count how often each processor is called.'),
147
+ plugins: joi_1.default.array().items(joi_1.default.alternatives().try(joi_1.default.string(), joi_1.default.array().ordered(joi_1.default.string(), joi_1.default.array().items(joi_1.default.any())).length(2))).optional().description('The plugins to load in REPL mode')
128
148
  }).description('Configuration options for the REPL.'),
129
149
  project: joi_1.default.object({
130
150
  resolveUnknownPathsOnDisk: joi_1.default.boolean().optional().description('Whether to resolve unknown paths loaded by the r project disk when trying to source/analyze files.')
@@ -142,6 +162,7 @@ exports.FlowrConfig = {
142
162
  solver: joi_1.default.object({
143
163
  variables: joi_1.default.string().valid(...Object.values(VariableResolve)).description('How to resolve variables and their values.'),
144
164
  evalStrings: joi_1.default.boolean().description('Should we include eval(parse(text="...")) calls in the dataflow graph?'),
165
+ trackEnvironments: joi_1.default.boolean().optional().description('Track user-created environments (new.env, assign/get/local with envir=, dollar-assign, attach). When false, all envir-style calls fall through conservatively.'),
145
166
  instrument: joi_1.default.object({
146
167
  dataflowExtractors: joi_1.default.any().optional().description('These keys are only intended for use within code, allowing to instrument the dataflow analyzer!')
147
168
  }),
@@ -12,7 +12,7 @@ export interface BasicCfgGuidedVisitorConfiguration<ControlFlow extends ControlF
12
12
  * Use {@link BasicCfgGuidedVisitor#start} to start the traversal.
13
13
  */
14
14
  export declare class BasicCfgGuidedVisitor<ControlFlow extends ControlFlowInformation = ControlFlowInformation, Config extends BasicCfgGuidedVisitorConfiguration<ControlFlow> = BasicCfgGuidedVisitorConfiguration<ControlFlow>> {
15
- protected readonly config: Config;
15
+ readonly config: Config;
16
16
  protected readonly visited: Map<NodeId, number>;
17
17
  constructor(config: Config);
18
18
  /**
@@ -572,4 +572,8 @@ export declare class SemanticCfgGuidedVisitor<OtherInfo = NoInfo, ControlFlow ex
572
572
  protected onPurrFormulaCall(_data: {
573
573
  call: DataflowGraphVertexFunctionCall;
574
574
  }): void;
575
+ protected getSourceAndTarget(call: DataflowGraphVertexFunctionCall): {
576
+ target: NodeId | undefined;
577
+ source: NodeId | undefined;
578
+ };
575
579
  }
@@ -200,22 +200,8 @@ class SemanticCfgGuidedVisitor extends dfg_cfg_guided_visitor_1.DataflowAwareCfg
200
200
  return this.onVectorCall({ call });
201
201
  case built_in_proc_name_1.BuiltInProcName.Assignment:
202
202
  case built_in_proc_name_1.BuiltInProcName.AssignmentLike:
203
- case built_in_proc_name_1.BuiltInProcName.TableAssignment: {
204
- const outgoing = this.config.dfg.outgoingEdges(call.id);
205
- if (outgoing) {
206
- const target = outgoing.entries().filter(([, e]) => edge_1.DfEdge.includesType(e, edge_1.EdgeType.Returns)).toArray();
207
- if (target.length === 1) {
208
- const targetOut = this.config.dfg.outgoingEdges(target[0][0]);
209
- if (targetOut) {
210
- const source = targetOut.entries().filter(([t, e]) => edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedBy) && t !== call.id).toArray();
211
- if (source.length === 1) {
212
- return this.onAssignmentCall({ call, target: target[0][0], source: source[0][0] });
213
- }
214
- }
215
- }
216
- }
217
- return this.onAssignmentCall({ call, target: undefined, source: undefined });
218
- }
203
+ case built_in_proc_name_1.BuiltInProcName.TableAssignment:
204
+ return this.onAssignmentCall({ call, ...this.getSourceAndTarget(call) });
219
205
  case built_in_proc_name_1.BuiltInProcName.SpecialBinOp:
220
206
  if (call.args.length !== 2) {
221
207
  return this.onSpecialBinaryOpCall({ call });
@@ -234,22 +220,8 @@ class SemanticCfgGuidedVisitor extends dfg_cfg_guided_visitor_1.DataflowAwareCfg
234
220
  return this.onRepeatLoopCall({ call, body: call.args[0] });
235
221
  case built_in_proc_name_1.BuiltInProcName.WhileLoop:
236
222
  return this.onWhileLoopCall({ call, condition: call.args[0], body: call.args[1] });
237
- case built_in_proc_name_1.BuiltInProcName.Replacement: {
238
- const outgoing = this.config.dfg.outgoingEdges(call.id);
239
- if (outgoing) {
240
- const target = outgoing.entries().filter(([, e]) => edge_1.DfEdge.includesType(e, edge_1.EdgeType.Returns)).toArray();
241
- if (target.length === 1) {
242
- const targetOut = this.config.dfg.outgoingEdges(target[0][0]);
243
- if (targetOut) {
244
- const source = targetOut.entries().filter(([t, e]) => edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedBy) && t !== call.id).toArray();
245
- if (source.length === 1) {
246
- return this.onReplacementCall({ call, target: target[0][0], source: source[0][0] });
247
- }
248
- }
249
- }
250
- }
251
- return this.onReplacementCall({ call, target: undefined, source: undefined });
252
- }
223
+ case built_in_proc_name_1.BuiltInProcName.Replacement:
224
+ return this.onReplacementCall({ call, ...this.getSourceAndTarget(call) });
253
225
  case built_in_proc_name_1.BuiltInProcName.Library:
254
226
  return this.onLibraryCall({ call });
255
227
  case built_in_proc_name_1.BuiltInProcName.Try:
@@ -280,6 +252,9 @@ class SemanticCfgGuidedVisitor extends dfg_cfg_guided_visitor_1.DataflowAwareCfg
280
252
  return this.onRecallCall({ call });
281
253
  case built_in_proc_name_1.BuiltInProcName.PurrrFormula:
282
254
  return this.onPurrFormulaCall({ call });
255
+ case built_in_proc_name_1.BuiltInProcName.NewEnv:
256
+ case built_in_proc_name_1.BuiltInProcName.With:
257
+ case built_in_proc_name_1.BuiltInProcName.Attach:
283
258
  case built_in_proc_name_1.BuiltInProcName.Default:
284
259
  case built_in_proc_name_1.BuiltInProcName.DefaultReadAllArgs:
285
260
  case built_in_proc_name_1.BuiltInProcName.Function:
@@ -646,6 +621,22 @@ class SemanticCfgGuidedVisitor extends dfg_cfg_guided_visitor_1.DataflowAwareCfg
646
621
  * This event triggers for any purr formula as in `map(df, ~ .x + 1)`
647
622
  */
648
623
  onPurrFormulaCall(_data) { }
624
+ getSourceAndTarget(call) {
625
+ const outgoing = this.config.dfg.outgoingEdges(call.id);
626
+ if (outgoing !== undefined) {
627
+ const target = outgoing.entries().filter(([, e]) => edge_1.DfEdge.includesType(e, edge_1.EdgeType.Returns)).toArray();
628
+ if (target.length === 1) {
629
+ const targetOut = this.config.dfg.outgoingEdges(target[0][0]);
630
+ if (targetOut !== undefined) {
631
+ const source = targetOut.entries().filter(([t, e]) => edge_1.DfEdge.includesType(e, edge_1.EdgeType.DefinedBy) && t !== call.id).toArray();
632
+ if (source.length === 1) {
633
+ return { target: target[0][0], source: source[0][0] };
634
+ }
635
+ }
636
+ }
637
+ }
638
+ return { target: undefined, source: undefined };
639
+ }
649
640
  }
650
641
  exports.SemanticCfgGuidedVisitor = SemanticCfgGuidedVisitor;
651
642
  //# sourceMappingURL=semantic-cfg-guided-visitor.js.map
@@ -80,10 +80,16 @@ export declare enum BuiltInProcName {
80
80
  TableAssignment = "table:assign",
81
81
  /** for `try` calls, see {@link processTryCatch} */
82
82
  Try = "builtin:try",
83
+ /** for `attach` calls that inject environment contents into the search path, see {@link processAttach} */
84
+ Attach = "builtin:attach",
85
+ /** for `new.env` and related environment-creation calls, see {@link processNewEnv} */
86
+ NewEnv = "builtin:new-env",
83
87
  /** for unnamed directly-linked function calls */
84
88
  Unnamed = "unnamed",
85
89
  /** for vector construction calls, see {@link processVector} */
86
90
  Vector = "builtin:vector",
87
91
  /** for `while` loops, see {@link processWhileLoop} */
88
- WhileLoop = "builtin:while-loop"
92
+ WhileLoop = "builtin:while-loop",
93
+ /** for `with` calls that evaluate an expression inside a named environment, see {@link processWithEnv} */
94
+ With = "builtin:with"
89
95
  }
@@ -84,11 +84,17 @@ var BuiltInProcName;
84
84
  BuiltInProcName["TableAssignment"] = "table:assign";
85
85
  /** for `try` calls, see {@link processTryCatch} */
86
86
  BuiltInProcName["Try"] = "builtin:try";
87
+ /** for `attach` calls that inject environment contents into the search path, see {@link processAttach} */
88
+ BuiltInProcName["Attach"] = "builtin:attach";
89
+ /** for `new.env` and related environment-creation calls, see {@link processNewEnv} */
90
+ BuiltInProcName["NewEnv"] = "builtin:new-env";
87
91
  /** for unnamed directly-linked function calls */
88
92
  BuiltInProcName["Unnamed"] = "unnamed";
89
93
  /** for vector construction calls, see {@link processVector} */
90
94
  BuiltInProcName["Vector"] = "builtin:vector";
91
95
  /** for `while` loops, see {@link processWhileLoop} */
92
96
  BuiltInProcName["WhileLoop"] = "builtin:while-loop";
97
+ /** for `with` calls that evaluate an expression inside a named environment, see {@link processWithEnv} */
98
+ BuiltInProcName["With"] = "builtin:with";
93
99
  })(BuiltInProcName || (exports.BuiltInProcName = BuiltInProcName = {}));
94
100
  //# sourceMappingURL=built-in-proc-name.js.map
@@ -44,6 +44,9 @@ import { processS7NewGeneric } from '../internal/process/functions/call/built-in
44
44
  import { processS7Dispatch } from '../internal/process/functions/call/built-in/built-in-s-seven-dispatch';
45
45
  import { BuiltInProcName } from './built-in-proc-name';
46
46
  import { processPurrrFormula } from '../internal/process/functions/call/built-in/built-in-purrr-formula';
47
+ import { processNewEnv } from '../internal/process/functions/call/built-in/built-in-new-env';
48
+ import { processAttach } from '../internal/process/functions/call/built-in/built-in-attach';
49
+ import { processWithEnv } from '../internal/process/functions/call/built-in/built-in-with';
47
50
  export type BuiltInIdentifierProcessor = <OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>) => DataflowInformation;
48
51
  export type BuiltInIdentifierProcessorWithConfig<Config> = <OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, config: Config) => DataflowInformation;
49
52
  export interface BuiltInIdentifierDefinition extends IdentifierReference {
@@ -115,6 +118,9 @@ export declare const BuiltInProcessorMapper: {
115
118
  readonly "builtin:special-bin-op": typeof processSpecialBinOp;
116
119
  readonly "builtin:stopifnot": typeof processStopIfNot;
117
120
  readonly "builtin:try": typeof processTryCatch;
121
+ readonly "builtin:attach": typeof processAttach;
122
+ readonly "builtin:new-env": typeof processNewEnv;
123
+ readonly "builtin:with": typeof processWithEnv;
118
124
  readonly "builtin:vector": typeof processVector;
119
125
  readonly "builtin:while-loop": typeof processWhileLoop;
120
126
  };
@@ -42,6 +42,9 @@ const built_in_s_seven_dispatch_1 = require("../internal/process/functions/call/
42
42
  const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
43
43
  const built_in_proc_name_1 = require("./built-in-proc-name");
44
44
  const built_in_purrr_formula_1 = require("../internal/process/functions/call/built-in/built-in-purrr-formula");
45
+ const built_in_new_env_1 = require("../internal/process/functions/call/built-in/built-in-new-env");
46
+ const built_in_attach_1 = require("../internal/process/functions/call/built-in/built-in-attach");
47
+ const built_in_with_1 = require("../internal/process/functions/call/built-in/built-in-with");
45
48
  function defaultBuiltInProcessor(name, args, rootId, data, { returnsNthArgument, useAsProcessor = built_in_proc_name_1.BuiltInProcName.Default, forceArgs, readAllArguments, cfg, hasUnknownSideEffects, treatAsFnCall }) {
46
49
  const { information: res, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, forceArgs, origin: useAsProcessor });
47
50
  if (returnsNthArgument !== undefined) {
@@ -142,6 +145,9 @@ exports.BuiltInProcessorMapper = {
142
145
  [built_in_proc_name_1.BuiltInProcName.SpecialBinOp]: built_in_special_bin_op_1.processSpecialBinOp,
143
146
  [built_in_proc_name_1.BuiltInProcName.StopIfNot]: built_in_stop_if_not_1.processStopIfNot,
144
147
  [built_in_proc_name_1.BuiltInProcName.Try]: built_in_try_catch_1.processTryCatch,
148
+ [built_in_proc_name_1.BuiltInProcName.Attach]: built_in_attach_1.processAttach,
149
+ [built_in_proc_name_1.BuiltInProcName.NewEnv]: built_in_new_env_1.processNewEnv,
150
+ [built_in_proc_name_1.BuiltInProcName.With]: built_in_with_1.processWithEnv,
145
151
  [built_in_proc_name_1.BuiltInProcName.Vector]: built_in_vector_1.processVector,
146
152
  [built_in_proc_name_1.BuiltInProcName.WhileLoop]: built_in_while_loop_1.processWhileLoop,
147
153
  };
@@ -23,6 +23,11 @@ export declare const DefaultBuiltinConfig: [{
23
23
  readonly names: ["NULL", "NA", "NaN", "NA_integer_", "NA_real_", "NA_complex_", "NA_character_"];
24
24
  readonly value: null;
25
25
  readonly assumePrimitive: true;
26
+ }, {
27
+ readonly type: "constant";
28
+ readonly names: [".GlobalEnv", ".BaseNamespaceEnv", ".BaseEnv"];
29
+ readonly value: null;
30
+ readonly assumePrimitive: true;
26
31
  }, {
27
32
  readonly type: "constant";
28
33
  readonly names: ["TRUE", "T"];
@@ -234,6 +239,16 @@ export declare const DefaultBuiltinConfig: [{
234
239
  readonly processor: BuiltInProcName.Eval;
235
240
  readonly config: {
236
241
  readonly includeFunctionCall: true;
242
+ readonly supportFunctionCall: false;
243
+ };
244
+ readonly assumePrimitive: true;
245
+ }, {
246
+ readonly type: "function";
247
+ readonly names: ["evalText"];
248
+ readonly processor: BuiltInProcName.Eval;
249
+ readonly config: {
250
+ readonly includeFunctionCall: true;
251
+ readonly supportFunctionCall: true;
237
252
  };
238
253
  readonly assumePrimitive: true;
239
254
  }, {
@@ -414,6 +429,7 @@ export declare const DefaultBuiltinConfig: [{
414
429
  readonly config: {
415
430
  readonly targetVariable: true;
416
431
  readonly mayHaveMoreArgs: true;
432
+ readonly environmentArg: "envir";
417
433
  };
418
434
  readonly assumePrimitive: true;
419
435
  }, {
@@ -938,6 +954,38 @@ export declare const DefaultBuiltinConfig: [{
938
954
  };
939
955
  };
940
956
  readonly assumePrimitive: false;
957
+ }, {
958
+ readonly type: "function";
959
+ readonly names: ["with", "within"];
960
+ readonly processor: BuiltInProcName.With;
961
+ readonly config: {};
962
+ readonly assumePrimitive: false;
963
+ }, {
964
+ readonly type: "function";
965
+ readonly names: ["new.env", Identifier];
966
+ readonly processor: BuiltInProcName.NewEnv;
967
+ readonly config: {};
968
+ readonly assumePrimitive: true;
969
+ }, {
970
+ readonly type: "function";
971
+ readonly names: ["globalenv", "baseenv", "emptyenv", "parent.env", "parent.frame", "environmentName", "as.environment", "pos.to.env", "sys.frame", "sys.frames", "topenv"];
972
+ readonly processor: BuiltInProcName.Default;
973
+ readonly config: {};
974
+ readonly assumePrimitive: true;
975
+ }, {
976
+ readonly type: "function";
977
+ readonly names: ["load", "load_image"];
978
+ readonly processor: BuiltInProcName.Default;
979
+ readonly config: {
980
+ readonly hasUnknownSideEffects: true;
981
+ };
982
+ readonly assumePrimitive: false;
983
+ }, {
984
+ readonly type: "function";
985
+ readonly names: ["attach"];
986
+ readonly processor: BuiltInProcName.Attach;
987
+ readonly config: {};
988
+ readonly assumePrimitive: false;
941
989
  }, {
942
990
  readonly type: "function";
943
991
  readonly names: ["for"];
@@ -1081,6 +1129,20 @@ export declare const DefaultBuiltinConfig: [{
1081
1129
  readonly config: {};
1082
1130
  readonly assumePrimitive: true;
1083
1131
  readonly evalHandler: "built-in:c";
1132
+ }, {
1133
+ readonly type: "function";
1134
+ readonly names: [Identifier, Identifier];
1135
+ readonly processor: BuiltInProcName.Default;
1136
+ readonly config: {
1137
+ readonly returnsNthArgument: 0;
1138
+ };
1139
+ }, {
1140
+ readonly type: "function";
1141
+ readonly names: [Identifier];
1142
+ readonly processor: BuiltInProcName.Default;
1143
+ readonly config: {
1144
+ readonly hasUnknownSideEffects: true;
1145
+ };
1084
1146
  }, {
1085
1147
  readonly type: "function";
1086
1148
  readonly names: ["setnames", "setNames", "setkey", "setkeyv", "setindex", "setindexv", "setattr"];
@@ -1093,7 +1155,7 @@ export declare const DefaultBuiltinConfig: [{
1093
1155
  };
1094
1156
  }, {
1095
1157
  readonly type: "function";
1096
- readonly names: ["sys.on.exit", "par", "tpar", "sink", "requireNamespace", "loadNamespace", "attachNamespace", "asNamespace", Identifier, "attach", "unname", "data", "dir.create", "dir_create", "Sys.chmod", "unlink", "file.remove", "file.rename", "file.copy", "file.link", "file.append", "Sys.junction"];
1158
+ readonly names: ["sys.on.exit", "par", "tpar", "sink", "requireNamespace", "loadNamespace", "attachNamespace", "asNamespace", Identifier, "unname", "data", "dir.create", "dir_create", "Sys.chmod", "unlink", "file.remove", "file.rename", "file.copy", "file.link", "file.append", "Sys.junction"];
1097
1159
  readonly processor: BuiltInProcName.Default;
1098
1160
  readonly config: {
1099
1161
  readonly hasUnknownSideEffects: true;
@@ -98,6 +98,7 @@ function toRegex(n) {
98
98
  */
99
99
  exports.DefaultBuiltinConfig = [
100
100
  { type: 'constant', names: ['NULL', 'NA', 'NaN', 'NA_integer_', 'NA_real_', 'NA_complex_', 'NA_character_'], value: null, assumePrimitive: true },
101
+ { type: 'constant', names: ['.GlobalEnv', '.BaseNamespaceEnv', '.BaseEnv'], value: null, assumePrimitive: true },
101
102
  { type: 'constant', names: ['TRUE', 'T'], value: true, assumePrimitive: true },
102
103
  { type: 'constant', names: ['FALSE', 'F'], value: false, assumePrimitive: true },
103
104
  {
@@ -231,7 +232,8 @@ exports.DefaultBuiltinConfig = [
231
232
  '.Fortran': ['.NAME']
232
233
  }
233
234
  }, assumePrimitive: true },
234
- { type: 'function', names: ['eval'], processor: built_in_proc_name_1.BuiltInProcName.Eval, config: { includeFunctionCall: true }, assumePrimitive: true },
235
+ { type: 'function', names: ['eval'], processor: built_in_proc_name_1.BuiltInProcName.Eval, config: { includeFunctionCall: true, supportFunctionCall: false }, assumePrimitive: true },
236
+ { type: 'function', names: ['evalText'], processor: built_in_proc_name_1.BuiltInProcName.Eval, config: { includeFunctionCall: true, supportFunctionCall: true }, assumePrimitive: true },
235
237
  { type: 'function', names: ['cat'], processor: built_in_proc_name_1.BuiltInProcName.Default, config: { forceArgs: 'all', hasUnknownSideEffects: { type: 'link-to-last-call', callName: /^sink$/ } }, assumePrimitive: false },
236
238
  { type: 'function', names: ['switch'], processor: built_in_proc_name_1.BuiltInProcName.Default, config: { forceArgs: [true] }, assumePrimitive: false },
237
239
  { type: 'function', names: ['return'], processor: built_in_proc_name_1.BuiltInProcName.Default, config: { returnsNthArgument: 0, cfg: 1 /* ExitPointType.Return */, useAsProcessor: built_in_proc_name_1.BuiltInProcName.Return }, assumePrimitive: true },
@@ -258,7 +260,7 @@ exports.DefaultBuiltinConfig = [
258
260
  { type: 'function', names: [identifier_1.Identifier.make('from', 'import'), identifier_1.Identifier.make('library', 'base'), identifier_1.Identifier.make('require', 'base')], processor: built_in_proc_name_1.BuiltInProcName.Library, config: {}, assumePrimitive: false },
259
261
  { type: 'function', names: ['<-', '='], processor: built_in_proc_name_1.BuiltInProcName.Assignment, config: { canBeReplacement: true }, assumePrimitive: true },
260
262
  { type: 'function', names: [':='], processor: built_in_proc_name_1.BuiltInProcName.Assignment, config: {}, assumePrimitive: true },
261
- { type: 'function', names: ['assign', 'setValidity'], processor: built_in_proc_name_1.BuiltInProcName.Assignment, config: { targetVariable: true, mayHaveMoreArgs: true }, assumePrimitive: true },
263
+ { type: 'function', names: ['assign', 'setValidity'], processor: built_in_proc_name_1.BuiltInProcName.Assignment, config: { targetVariable: true, mayHaveMoreArgs: true, environmentArg: 'envir' }, assumePrimitive: true },
262
264
  { type: 'function', names: ['setMethod'], processor: built_in_proc_name_1.BuiltInProcName.AssignmentLike, config: { targetVariable: true, canBeReplacement: false, target: { idx: 0, name: 'f' }, source: { idx: 2, name: 'definition' }, modesForFn: ['s4'] }, assumePrimitive: true },
263
265
  { type: 'function', names: ['delayedAssign'], processor: built_in_proc_name_1.BuiltInProcName.Assignment, config: { quoteSource: true, targetVariable: true }, assumePrimitive: true },
264
266
  { type: 'function', names: ['<<-'], processor: built_in_proc_name_1.BuiltInProcName.Assignment, config: { superAssignment: true, canBeReplacement: true }, assumePrimitive: true },
@@ -421,6 +423,13 @@ exports.DefaultBuiltinConfig = [
421
423
  { type: 'function', names: [identifier_1.Identifier.make('enquo', 'rlang'), identifier_1.Identifier.make('enquos', 'rlang'), identifier_1.Identifier.make('quo', 'rlang'), identifier_1.Identifier.make('quos', 'rlang'), identifier_1.Identifier.make('sym', 'rlang'), identifier_1.Identifier.make('syms', 'rlang'), identifier_1.Identifier.make('ensym', 'rlang'), identifier_1.Identifier.make('ensyms', 'rlang'), identifier_1.Identifier.make('expr', 'rlang'), identifier_1.Identifier.make('exprs', 'rlang'), identifier_1.Identifier.make('quo_name', 'rlang'), identifier_1.Identifier.make('as_name', 'rlang'), identifier_1.Identifier.make('as_label', 'rlang'), identifier_1.Identifier.make('as_string', 'rlang')], processor: built_in_proc_name_1.BuiltInProcName.Quote, config: { quoteArgumentsWithIndex: 0, libFn: true }, assumePrimitive: true },
422
424
  { type: 'function', names: [identifier_1.Identifier.make('call2', 'rlang'), identifier_1.Identifier.make('exec', 'rlang'), identifier_1.Identifier.make('invoke', 'purrr'), identifier_1.Identifier.make('invoke_map', 'purrr')], processor: built_in_proc_name_1.BuiltInProcName.Default, config: { libFn: true, hasUnknownSideEffects: true, unquoteFunction: true }, assumePrimitive: false },
423
425
  { type: 'function', names: ['local'], processor: built_in_proc_name_1.BuiltInProcName.Local, config: { args: { env: 'envir', expr: 'expr' } }, assumePrimitive: false },
426
+ { type: 'function', names: ['with', 'within'], processor: built_in_proc_name_1.BuiltInProcName.With, config: {}, assumePrimitive: false },
427
+ { type: 'function', names: ['new.env', identifier_1.Identifier.make('new_environment', 'rlang')], processor: built_in_proc_name_1.BuiltInProcName.NewEnv, config: {}, assumePrimitive: true },
428
+ { type: 'function', names: ['globalenv', 'baseenv', 'emptyenv', 'parent.env', 'parent.frame', 'environmentName', 'as.environment', 'pos.to.env', 'sys.frame', 'sys.frames', 'topenv'],
429
+ processor: built_in_proc_name_1.BuiltInProcName.Default, config: {}, assumePrimitive: true },
430
+ { type: 'function', names: ['load', 'load_image'], processor: built_in_proc_name_1.BuiltInProcName.Default, config: { hasUnknownSideEffects: true }, assumePrimitive: false },
431
+ /* attach injects an environment's contents into the search path; detach reverses it (treated as unknown side effect) */
432
+ { type: 'function', names: ['attach'], processor: built_in_proc_name_1.BuiltInProcName.Attach, config: {}, assumePrimitive: false },
424
433
  { type: 'function', names: ['for'], processor: built_in_proc_name_1.BuiltInProcName.ForLoop, config: {}, assumePrimitive: true },
425
434
  { type: 'function', names: ['repeat'], processor: built_in_proc_name_1.BuiltInProcName.RepeatLoop, config: {}, assumePrimitive: true },
426
435
  { type: 'function', names: ['while'], processor: built_in_proc_name_1.BuiltInProcName.WhileLoop, config: {}, assumePrimitive: true },
@@ -437,6 +446,8 @@ exports.DefaultBuiltinConfig = [
437
446
  { type: 'function', names: ['Recall'], processor: built_in_proc_name_1.BuiltInProcName.Recall, config: { libFn: true }, assumePrimitive: false },
438
447
  { type: 'function', names: ['sys.function'], processor: built_in_proc_name_1.BuiltInProcName.Recall, config: { libFn: true, unknownOnNonZeroArg: true }, assumePrimitive: false },
439
448
  { type: 'function', names: ['c'], processor: built_in_proc_name_1.BuiltInProcName.Vector, config: {}, assumePrimitive: true, evalHandler: 'built-in:c' },
449
+ { type: 'function', names: [identifier_1.Identifier.make('cmpfun', 'compiler'), identifier_1.Identifier.make('compile', 'compiler')], processor: built_in_proc_name_1.BuiltInProcName.Default, config: { returnsNthArgument: 0 } },
450
+ { type: 'function', names: [identifier_1.Identifier.make('loadcmp', 'compiler')], processor: built_in_proc_name_1.BuiltInProcName.Default, config: { hasUnknownSideEffects: true } },
440
451
  {
441
452
  type: 'function',
442
453
  names: ['setnames', 'setNames', 'setkey', 'setkeyv', 'setindex', 'setindexv', 'setattr'],
@@ -456,7 +467,7 @@ exports.DefaultBuiltinConfig = [
456
467
  'requireNamespace', 'loadNamespace', 'attachNamespace', 'asNamespace',
457
468
  identifier_1.Identifier.make('use', 'base'),
458
469
  /* weird env attachments */
459
- 'attach', 'unname', 'data',
470
+ 'unname', 'data',
460
471
  /* file creation/removal */
461
472
  'dir.create', 'dir_create', 'Sys.chmod', 'unlink', 'file.remove', 'file.rename', 'file.copy', 'file.link', 'file.append', 'Sys.junction'
462
473
  ],
@@ -515,7 +526,7 @@ exports.DefaultBuiltinConfig = [
515
526
  config: {
516
527
  readIndices: false
517
528
  }
518
- }
529
+ },
519
530
  ];
520
531
  /**
521
532
  * Expensive and naive lookup of the default processor for a built-in function name
@@ -1,6 +1,7 @@
1
1
  import type { BuiltInIdentifierConstant, BuiltInIdentifierDefinition } from './built-in';
2
2
  import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
3
3
  import type { ControlDependency } from '../info';
4
+ import type { REnvironmentInformation } from './environment';
4
5
  /** this is just a safe-guard type to prevent mixing up branded identifiers with normal strings */
5
6
  export type BrandedIdentifier = string & {
6
7
  __brand?: 'identifier';
@@ -198,7 +199,20 @@ export interface InGraphIdentifierDefinition extends IdentifierReference {
198
199
  * For example, in `x <- 3; y <- x`, the definition of `y` will have the value `3` in its value set
199
200
  */
200
201
  readonly value?: NodeId[];
202
+ /**
203
+ * If this variable holds an R environment (created by `new.env()` etc.),
204
+ * this tracks the current known state of that environment.
205
+ * Use this to resolve variables assigned via `assign(name, val, envir=<this var>)`.
206
+ */
207
+ readonly envState?: REnvironmentInformation;
201
208
  }
209
+ /**
210
+ * A narrowed variant of {@link InGraphIdentifierDefinition} that is guaranteed to have a non-undefined `name`.
211
+ * Prefer this over the inline intersection `InGraphIdentifierDefinition & { name: Identifier }`.
212
+ */
213
+ export type NamedInGraphIdentifierDefinition = InGraphIdentifierDefinition & {
214
+ readonly name: Identifier;
215
+ };
202
216
  /**
203
217
  * Stores the definition of an identifier within an {@link IEnvironment}.
204
218
  *
@@ -110,6 +110,12 @@ export interface DataflowGraphVertexFunctionCall extends DataflowGraphVertexBase
110
110
  environment: REnvironmentInformation | undefined;
111
111
  /** More detailed Information on this function call */
112
112
  origin: FunctionOriginInformation[] | 'unnamed';
113
+ /**
114
+ * For `new.env()`-family calls: the resolved parent {@link REnvironmentInformation} that the
115
+ * freshly-created environment should inherit from. Set by `processNewEnv` when the `parent`
116
+ * argument can be statically resolved (tracked env variable or `emptyenv()`-family call).
117
+ */
118
+ newEnvParent?: REnvironmentInformation;
113
119
  }
114
120
  /** Describes the processor responsible for a function call */
115
121
  export type FunctionOriginInformation = BuiltInProcName;
@@ -12,6 +12,8 @@ const built_in_assignment_1 = require("./built-in-assignment");
12
12
  const identifier_1 = require("../../../../../environments/identifier");
13
13
  const reference_to_maybe_1 = require("../../../../../environments/reference-to-maybe");
14
14
  const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
15
+ const unpack_argument_1 = require("../argument/unpack-argument");
16
+ const built_in_envir_utils_1 = require("./built-in-envir-utils");
15
17
  function tableAssignmentProcessor(name, args, rootId, data, outInfo) {
16
18
  outInfo.definitionRootNodes.push(rootId);
17
19
  return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.TableAssignment }).information;
@@ -57,6 +59,20 @@ function processAccess(name, args, rootId, data, config) {
57
59
  }
58
60
  /* we include the read edges to the constant arguments as well so that they are included if necessary */
59
61
  }
62
+ /* for $ access on a tracked env variable, add Reads edges to the field definition in envState */
63
+ if (config.treatIndicesAsString && identifier_1.Identifier.getName(name.content) === '$'
64
+ && head !== r_function_call_1.EmptyArgument && head.value?.type === type_1.RType.Symbol
65
+ && args.length >= 2 && args[1] !== r_function_call_1.EmptyArgument) {
66
+ const envirResolution = (0, built_in_envir_utils_1.resolveSymbolToEnvir)(head.value.content, head.value.info.id, data);
67
+ if (envirResolution) {
68
+ const fieldNode = (0, unpack_argument_1.unpackArg)(args[1]);
69
+ const fieldName = fieldNode?.type === type_1.RType.String ? fieldNode.content.str : fieldNode?.lexeme;
70
+ const fieldDefs = fieldName ? envirResolution.envDef.envState.current.memory.get(fieldName) : undefined;
71
+ for (const fd of fieldDefs ?? []) {
72
+ info.graph.addEdge(name.info.id, fd.nodeId, edge_1.EdgeType.Reads);
73
+ }
74
+ }
75
+ }
60
76
  return {
61
77
  ...info,
62
78
  /*