@eagleoutice/flowr 2.10.5 → 2.10.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -21
- package/abstract-interpretation/absint-visitor.d.ts +1 -2
- package/abstract-interpretation/domains/state-domain-like.d.ts +2 -2
- package/config.d.ts +6 -0
- package/config.js +2 -0
- package/control-flow/basic-cfg-guided-visitor.d.ts +1 -1
- package/control-flow/semantic-cfg-guided-visitor.js +4 -0
- package/dataflow/environments/built-in-proc-name.d.ts +27 -19
- package/dataflow/environments/built-in-proc-name.js +27 -19
- package/dataflow/environments/built-in.d.ts +24 -18
- package/dataflow/environments/built-in.js +6 -0
- package/dataflow/environments/default-builtin-config.d.ts +53 -1
- package/dataflow/environments/default-builtin-config.js +13 -3
- package/dataflow/environments/identifier.d.ts +19 -0
- package/dataflow/environments/reference-to-maybe.js +32 -6
- package/dataflow/eval/resolve/alias-tracking.js +5 -0
- package/dataflow/graph/graph.js +51 -30
- package/dataflow/graph/vertex.d.ts +18 -11
- package/dataflow/internal/process/functions/call/built-in/built-in-access.js +16 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +6 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +145 -11
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +15 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +54 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +75 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +196 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +22 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +57 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +5 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +27 -13
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +14 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-new-env.d.ts +27 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +97 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +7 -7
- package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +23 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +90 -0
- package/documentation/doc-util/doc-types.d.ts +11 -2
- package/documentation/doc-util/doc-types.js +31 -9
- package/documentation/wiki-absint.d.ts +16 -0
- package/documentation/wiki-absint.js +50 -15
- package/documentation/wiki-interface.js +1 -0
- package/documentation/wiki-mk/doc-context.d.ts +14 -1
- package/documentation/wiki-mk/doc-context.js +6 -0
- package/documentation/wiki-normalized-ast.d.ts +0 -9
- package/documentation/wiki-normalized-ast.js +9 -60
- package/linter/linter-format.d.ts +4 -0
- package/linter/linter-rules.d.ts +7 -6
- package/linter/rules/absolute-path.d.ts +0 -2
- package/linter/rules/dataframe-access-validation.d.ts +4 -7
- package/linter/rules/dataframe-access-validation.js +3 -3
- package/linter/rules/dead-code.d.ts +4 -7
- package/linter/rules/file-path-validity.d.ts +0 -2
- package/linter/rules/function-finder-util.d.ts +1 -3
- package/linter/rules/function-finder-util.js +2 -2
- package/linter/rules/naming-convention.d.ts +0 -2
- package/linter/rules/network-functions.js +4 -1
- package/linter/rules/problematic-inputs.d.ts +9 -6
- package/linter/rules/problematic-inputs.js +108 -58
- package/linter/rules/roxygen-arguments.d.ts +0 -2
- package/linter/rules/seeded-randomness.d.ts +0 -2
- package/linter/rules/stop-with-call-arg.d.ts +3 -6
- package/linter/rules/unused-definition.d.ts +0 -2
- package/linter/rules/useless-loop.d.ts +0 -2
- package/package.json +4 -4
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +6 -2
- package/queries/catalog/dependencies-query/function-info/function-info.d.ts +2 -0
- package/queries/catalog/dependencies-query/function-info/read-functions.js +2 -0
- package/queries/catalog/dependencies-query/function-info/source-functions.js +1 -1
- package/queries/catalog/dependencies-query/function-info/write-functions.js +1 -0
- package/queries/catalog/input-sources-query/input-source-functions.d.ts +1 -0
- package/queries/catalog/input-sources-query/input-source-functions.js +7 -1
- package/queries/catalog/input-sources-query/input-sources-query-format.js +3 -1
- package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +3 -1
- package/queries/catalog/input-sources-query/simple-input-classifier.js +3 -1
- package/r-bridge/data/data.d.ts +28 -2
- package/r-bridge/data/data.js +34 -2
- package/r-bridge/lang-4.x/ast/model/model.d.ts +1 -2
- package/r-bridge/lang-4.x/ast/model/model.js +0 -1
- package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +3 -3
- package/r-bridge/lang-4.x/ast/model/processing/decorate.d.ts +1 -1
- package/r-bridge/lang-4.x/ast/model/processing/decorate.js +16 -16
- package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +6 -0
- package/r-bridge/lang-4.x/ast/model/processing/node-id.js +8 -0
- package/search/flowr-search-builder.d.ts +16 -2
- package/search/flowr-search-builder.js +10 -1
- package/search/flowr-search.d.ts +9 -0
- package/search/search-executor/search-generators.d.ts +1 -1
- package/search/search-executor/search-generators.js +28 -2
- package/slicing/static/static-slicer.js +2 -2
- package/util/range.d.ts +13 -1
- package/util/range.js +32 -2
- package/util/version.js +1 -1
- package/abstract-interpretation/normalized-ast-fold.d.ts +0 -119
- package/abstract-interpretation/normalized-ast-fold.js +0 -181
|
@@ -18,12 +18,14 @@ const vertex_1 = require("../../../../../graph/vertex");
|
|
|
18
18
|
const define_1 = require("../../../../../environments/define");
|
|
19
19
|
const edge_1 = require("../../../../../graph/edge");
|
|
20
20
|
const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
|
|
21
|
+
const built_in_envir_utils_1 = require("./built-in-envir-utils");
|
|
21
22
|
const named_call_handling_1 = require("../named-call-handling");
|
|
22
23
|
const built_in_1 = require("../../../../../environments/built-in");
|
|
23
24
|
const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
|
|
24
25
|
const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
|
|
25
26
|
const r_value_1 = require("../../../../../eval/values/r-value");
|
|
26
27
|
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
|
|
28
|
+
const built_in_new_env_1 = require("./built-in-new-env");
|
|
27
29
|
function toReplacementSymbol(target, prefix, superAssignment) {
|
|
28
30
|
return {
|
|
29
31
|
type: type_1.RType.Symbol,
|
|
@@ -45,9 +47,7 @@ function findRootAccess(node) {
|
|
|
45
47
|
if (current.type === type_1.RType.Symbol) {
|
|
46
48
|
return current;
|
|
47
49
|
}
|
|
48
|
-
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
50
|
+
return undefined;
|
|
51
51
|
}
|
|
52
52
|
function tryReplacement(rootId, functionName, data, name, args) {
|
|
53
53
|
const resolved = (0, resolve_by_name_1.resolveByName)(functionName.content, data.environment, identifier_1.ReferenceType.Function) ?? [];
|
|
@@ -104,6 +104,13 @@ args, rootId, data, config) {
|
|
|
104
104
|
logger_1.dataflowLogger.warn(`Assignment ${identifier_1.Identifier.toString(name.content)} has something else than 2 arguments, skipping`);
|
|
105
105
|
return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, forceArgs: config.forceArgs, origin: 'default' }).information;
|
|
106
106
|
}
|
|
107
|
+
/* route into a custom environment when envir resolves to a tracked env variable */
|
|
108
|
+
if (config.environmentArg) {
|
|
109
|
+
const routed = tryRouteToCustomEnv(name, args, rootId, data, config);
|
|
110
|
+
if (routed !== undefined) {
|
|
111
|
+
return routed;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
107
114
|
const effectiveArgs = getEffectiveOrder(config, args);
|
|
108
115
|
const { target, source } = extractSourceAndTarget(effectiveArgs);
|
|
109
116
|
if (target === undefined || source === undefined) {
|
|
@@ -120,7 +127,7 @@ args, rootId, data, config) {
|
|
|
120
127
|
data,
|
|
121
128
|
reverseOrder: !config.swapSourceAndTarget,
|
|
122
129
|
forceArgs: config.forceArgs,
|
|
123
|
-
origin: built_in_proc_name_1.BuiltInProcName.Assignment
|
|
130
|
+
origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
|
|
124
131
|
});
|
|
125
132
|
return processAssignmentToSymbol({
|
|
126
133
|
...config,
|
|
@@ -146,7 +153,7 @@ args, rootId, data, config) {
|
|
|
146
153
|
data,
|
|
147
154
|
reverseOrder: !config.swapSourceAndTarget,
|
|
148
155
|
forceArgs: config.forceArgs,
|
|
149
|
-
origin: built_in_proc_name_1.BuiltInProcName.Assignment
|
|
156
|
+
origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
|
|
150
157
|
});
|
|
151
158
|
return processAssignmentToSymbol({
|
|
152
159
|
...config,
|
|
@@ -172,6 +179,10 @@ args, rootId, data, config) {
|
|
|
172
179
|
else if (config.canBeReplacement && type === type_1.RType.Access) {
|
|
173
180
|
logger_1.dataflowLogger.debug(`Assignment ${identifier_1.Identifier.toString(name.content)} has an access-type node as target ==> replacement function ${target.lexeme}`);
|
|
174
181
|
const replacement = toReplacementSymbol(target, target.operator, config.superAssignment ?? false);
|
|
182
|
+
const envRouted = tryRouteDollarEnvAssign(rootId, data, config, target, source, replacement);
|
|
183
|
+
if (envRouted !== undefined) {
|
|
184
|
+
return envRouted;
|
|
185
|
+
}
|
|
175
186
|
return tryReplacement(rootId, replacement, data, replacement.content, [(0, make_argument_1.toUnnamedArgument)(target.accessed, data.completeAst.idMap), ...target.access, source]);
|
|
176
187
|
}
|
|
177
188
|
else if (type === type_1.RType.Access) {
|
|
@@ -184,7 +195,7 @@ args, rootId, data, config) {
|
|
|
184
195
|
data,
|
|
185
196
|
reverseOrder: !config.swapSourceAndTarget,
|
|
186
197
|
forceArgs: config.forceArgs,
|
|
187
|
-
origin: built_in_proc_name_1.BuiltInProcName.Assignment
|
|
198
|
+
origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
|
|
188
199
|
});
|
|
189
200
|
return processAssignmentToSymbol({
|
|
190
201
|
...config,
|
|
@@ -204,7 +215,7 @@ args, rootId, data, config) {
|
|
|
204
215
|
logger_1.dataflowLogger.warn(`Assignment ${identifier_1.Identifier.toString(name.content)} has an unknown target type ${target.type} => unknown impact`);
|
|
205
216
|
const info = (0, known_call_handling_1.processKnownFunctionCall)({
|
|
206
217
|
name, args: effectiveArgs, rootId, data, forceArgs: config.forceArgs,
|
|
207
|
-
origin: built_in_proc_name_1.BuiltInProcName.Assignment
|
|
218
|
+
origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
|
|
208
219
|
}).information;
|
|
209
220
|
(0, unknown_side_effect_1.handleUnknownSideEffect)(info.graph, info.environment, rootId);
|
|
210
221
|
return info;
|
|
@@ -241,11 +252,12 @@ function processAssignmentToString(target, args, name, rootId, data, config, sou
|
|
|
241
252
|
lexeme: target.lexeme,
|
|
242
253
|
location: target.location,
|
|
243
254
|
};
|
|
244
|
-
// treat first argument to Symbol
|
|
255
|
+
// treat first argument to Symbol; include extra args (e.g. envir=) so they get graph vertices
|
|
256
|
+
const extraArgs = config.mayHaveMoreArgs ? Array.from(args).slice(2) : [];
|
|
245
257
|
const mappedArgs = config.swapSourceAndTarget ? [args[0], {
|
|
246
258
|
...args[1],
|
|
247
259
|
value: symbol
|
|
248
|
-
}] : [{ ...args[0], value: symbol }, args[1]];
|
|
260
|
+
}, ...extraArgs] : [{ ...args[0], value: symbol }, args[1], ...extraArgs];
|
|
249
261
|
const res = (0, known_call_handling_1.processKnownFunctionCall)({
|
|
250
262
|
name,
|
|
251
263
|
args: mappedArgs,
|
|
@@ -253,7 +265,7 @@ function processAssignmentToString(target, args, name, rootId, data, config, sou
|
|
|
253
265
|
data,
|
|
254
266
|
reverseOrder: !config.swapSourceAndTarget,
|
|
255
267
|
forceArgs: config.forceArgs,
|
|
256
|
-
origin: built_in_proc_name_1.BuiltInProcName.Assignment
|
|
268
|
+
origin: config.superAssignment ? built_in_proc_name_1.BuiltInProcName.SuperAssignment : built_in_proc_name_1.BuiltInProcName.Assignment
|
|
257
269
|
});
|
|
258
270
|
return processAssignmentToSymbol({
|
|
259
271
|
...config,
|
|
@@ -286,6 +298,74 @@ function checkTargetReferenceType(sourceInfo, fnModes) {
|
|
|
286
298
|
return identifier_1.ReferenceType.Variable;
|
|
287
299
|
}
|
|
288
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Returns `true` when the entry-point of `sourceInfo` is a call to a `new.env`-family function.
|
|
303
|
+
* Used by {@link processAssignmentToSymbol} to attach an initial {@link InGraphIdentifierDefinition#envState}.
|
|
304
|
+
*/
|
|
305
|
+
function isEnvCreatorSource(sourceInfo) {
|
|
306
|
+
const vert = sourceInfo.graph.getVertex(sourceInfo.entryPoint);
|
|
307
|
+
return (0, vertex_1.isFunctionCallVertex)(vert) && vert.origin.includes(built_in_proc_name_1.BuiltInProcName.NewEnv);
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* When `e$x <- val` and `e` holds a tracked {@link InGraphIdentifierDefinition#envState},
|
|
311
|
+
* adds the field `x` into that envState instead of redefining the whole `e` object.
|
|
312
|
+
* Returns `undefined` when routing is not applicable.
|
|
313
|
+
*/
|
|
314
|
+
function tryRouteDollarEnvAssign(rootId, data, config, target, source, replacement) {
|
|
315
|
+
if (target.operator !== '$' || target.accessed.type !== type_1.RType.Symbol) {
|
|
316
|
+
return undefined;
|
|
317
|
+
}
|
|
318
|
+
const envirResolution = (0, built_in_envir_utils_1.resolveSymbolToEnvir)(target.accessed.content, target.accessed.info.id, data);
|
|
319
|
+
if (!envirResolution) {
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
const fieldNode = (0, unpack_argument_1.unpackArg)(target.access[0]);
|
|
323
|
+
if (!fieldNode) {
|
|
324
|
+
return undefined;
|
|
325
|
+
}
|
|
326
|
+
const fieldName = (fieldNode.type === type_1.RType.String ? fieldNode.content.str : fieldNode.lexeme);
|
|
327
|
+
const normalResult = tryReplacement(rootId, replacement, data, replacement.content, [(0, make_argument_1.toUnnamedArgument)(target.accessed, data.completeAst.idMap), ...target.access, source]);
|
|
328
|
+
const fieldDef = {
|
|
329
|
+
type: identifier_1.ReferenceType.Variable,
|
|
330
|
+
name: fieldName,
|
|
331
|
+
nodeId: fieldNode.info.id,
|
|
332
|
+
definedAt: rootId,
|
|
333
|
+
cds: data.cds ?? (config.makeMaybe ? [] : undefined)
|
|
334
|
+
};
|
|
335
|
+
const newEnvState = (0, define_1.define)(fieldDef, false, envirResolution.envDef.envState);
|
|
336
|
+
const updatedEnvDef = {
|
|
337
|
+
...envirResolution.envDef,
|
|
338
|
+
definedAt: rootId,
|
|
339
|
+
envState: newEnvState
|
|
340
|
+
};
|
|
341
|
+
const strippedEnv = {
|
|
342
|
+
current: normalResult.environment.current.removeAll([{ name: envirResolution.envDef.name }]),
|
|
343
|
+
level: normalResult.environment.level
|
|
344
|
+
};
|
|
345
|
+
normalResult.graph.addEdge(normalResult.entryPoint, target.accessed.info.id, edge_1.EdgeType.Reads);
|
|
346
|
+
return { ...normalResult, environment: (0, define_1.define)(updatedEnvDef, false, strippedEnv) };
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* When `config.environmentArg` identifies an `envir`-like parameter (e.g. `'envir'` for `assign`)
|
|
350
|
+
* and that argument resolves to a variable with a tracked {@link InGraphIdentifierDefinition#envState},
|
|
351
|
+
* this function routes the written definitions into that custom environment instead of the current
|
|
352
|
+
* global scope.
|
|
353
|
+
* @returns `undefined` if routing is not possible
|
|
354
|
+
*/
|
|
355
|
+
function tryRouteToCustomEnv(name, args, rootId, data, config) {
|
|
356
|
+
const resolution = (0, built_in_envir_utils_1.resolveEnvirArg)(args, data, config.environmentArg);
|
|
357
|
+
if (!resolution) {
|
|
358
|
+
return undefined;
|
|
359
|
+
}
|
|
360
|
+
/* run the normal assignment path to get the correct graph structure */
|
|
361
|
+
const normalResult = processAssignment(name, args, rootId, data, {
|
|
362
|
+
...config,
|
|
363
|
+
environmentArg: undefined // prevent re-entry
|
|
364
|
+
});
|
|
365
|
+
normalResult.graph.addEdge(rootId, resolution.envirNodeId, edge_1.EdgeType.Reads);
|
|
366
|
+
/* pass rootId as definedAt so only defs made at this call site are routed */
|
|
367
|
+
return (0, built_in_envir_utils_1.routeWrittenToCustomEnv)(normalResult, resolution.envDef, rootId, rootId);
|
|
368
|
+
}
|
|
289
369
|
/**
|
|
290
370
|
* Consider a call like `x <- v`
|
|
291
371
|
* @param information - the information to define the assignment within
|
|
@@ -331,6 +411,47 @@ function processAssignmentToSymbol(config) {
|
|
|
331
411
|
value: aliases
|
|
332
412
|
}]
|
|
333
413
|
: produceWrittenNodes(rootId, targetArg, referenceType, data, makeMaybe ?? false, aliases);
|
|
414
|
+
if (data.ctx.config.solver.trackEnvironments) {
|
|
415
|
+
let envState;
|
|
416
|
+
let returnsEnvState;
|
|
417
|
+
if (isEnvCreatorSource(sourceArg)) {
|
|
418
|
+
envState = (0, built_in_new_env_1.createFreshEnvState)(data, sourceArg);
|
|
419
|
+
}
|
|
420
|
+
else if (source.type === type_1.RType.Symbol) {
|
|
421
|
+
const defs = (0, resolve_by_name_1.resolveByName)(source.content, data.environment, identifier_1.ReferenceType.Variable);
|
|
422
|
+
const def = defs?.find((d) => d.envState !== undefined);
|
|
423
|
+
envState = def?.envState;
|
|
424
|
+
if (!envState) {
|
|
425
|
+
const fnDef = defs?.find((d) => d.returnsEnvState !== undefined);
|
|
426
|
+
if (fnDef?.returnsEnvState) {
|
|
427
|
+
envState = fnDef.returnsEnvState;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
const entryVertex = sourceArg.graph.getVertex(sourceArg.entryPoint);
|
|
433
|
+
if ((0, vertex_1.isFunctionDefinitionVertex)(entryVertex) && entryVertex.returnEnvState !== undefined) {
|
|
434
|
+
returnsEnvState = entryVertex.returnEnvState;
|
|
435
|
+
}
|
|
436
|
+
else if ((0, vertex_1.isFunctionCallVertex)(entryVertex) && entryVertex.name) {
|
|
437
|
+
const fnDefs = (0, resolve_by_name_1.resolveByName)(entryVertex.name, data.environment, identifier_1.ReferenceType.Function);
|
|
438
|
+
const fnDef = fnDefs?.find((d) => d.returnsEnvState !== undefined);
|
|
439
|
+
if (fnDef?.returnsEnvState) {
|
|
440
|
+
envState = fnDef.returnsEnvState;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (envState) {
|
|
445
|
+
for (let i = 0; i < writeNodes.length; i++) {
|
|
446
|
+
writeNodes[i] = { ...writeNodes[i], envState };
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
else if (returnsEnvState) {
|
|
450
|
+
for (let i = 0; i < writeNodes.length; i++) {
|
|
451
|
+
writeNodes[i] = { ...writeNodes[i], returnsEnvState };
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
334
455
|
if (writeNodes.length !== 1 && log_1.log.settings.minLevel >= 4 /* LogLevel.Warn */) {
|
|
335
456
|
log_1.log.warn(`Unexpected write number in assignment: ${JSON.stringify(writeNodes)}`);
|
|
336
457
|
}
|
|
@@ -338,7 +459,20 @@ function processAssignmentToSymbol(config) {
|
|
|
338
459
|
const readFromSourceWritten = sourceArg.out.slice(1);
|
|
339
460
|
const readTargets = [
|
|
340
461
|
{ nodeId: rootId, name: nameOfAssignmentFunction, cds: data.cds, type: identifier_1.ReferenceType.Function }
|
|
341
|
-
]
|
|
462
|
+
];
|
|
463
|
+
readTargets.push(...sourceArg.unknownReferences);
|
|
464
|
+
readTargets.push(...sourceArg.in);
|
|
465
|
+
if (targetName) {
|
|
466
|
+
readTargets.push(...targetArg.in);
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
for (const i of targetArg.in) {
|
|
470
|
+
if (i.nodeId !== targetId) {
|
|
471
|
+
readTargets.push(i);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
readTargets.push(...readFromSourceWritten);
|
|
342
476
|
information.environment = (0, overwrite_1.overwriteEnvironment)(sourceArg.environment, targetArg.environment);
|
|
343
477
|
// install assigned variables in environment
|
|
344
478
|
for (const write of writeNodes) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DataflowProcessorInformation } from '../../../../../processor';
|
|
2
|
+
import type { DataflowInformation } from '../../../../../info';
|
|
3
|
+
import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
4
|
+
import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
|
|
5
|
+
import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
|
|
6
|
+
import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
7
|
+
/**
|
|
8
|
+
* Processes `attach(what, ...)` - when `what` is a variable that holds a tracked
|
|
9
|
+
* {@link InGraphIdentifierDefinition#envState}, all statically-known definitions from
|
|
10
|
+
* that environment are injected into a new scope layer inserted *between* the current
|
|
11
|
+
* scope and its parent. This mirrors R's behaviour: `attach` adds to the search path
|
|
12
|
+
* below `.GlobalEnv`, so existing global bindings take precedence, but after a
|
|
13
|
+
* `rm(name)` removes a global shadow the attached binding becomes visible again.
|
|
14
|
+
*/
|
|
15
|
+
export declare function processAttach<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processAttach = processAttach;
|
|
4
|
+
const known_call_handling_1 = require("../known-call-handling");
|
|
5
|
+
const unpack_argument_1 = require("../argument/unpack-argument");
|
|
6
|
+
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
7
|
+
const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
|
|
8
|
+
const identifier_1 = require("../../../../../environments/identifier");
|
|
9
|
+
const environment_1 = require("../../../../../environments/environment");
|
|
10
|
+
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
|
|
11
|
+
const unknown_side_effect_1 = require("../../../../../graph/unknown-side-effect");
|
|
12
|
+
const edge_1 = require("../../../../../graph/edge");
|
|
13
|
+
const built_in_envir_utils_1 = require("./built-in-envir-utils");
|
|
14
|
+
/**
|
|
15
|
+
* Processes `attach(what, ...)` - when `what` is a variable that holds a tracked
|
|
16
|
+
* {@link InGraphIdentifierDefinition#envState}, all statically-known definitions from
|
|
17
|
+
* that environment are injected into a new scope layer inserted *between* the current
|
|
18
|
+
* scope and its parent. This mirrors R's behaviour: `attach` adds to the search path
|
|
19
|
+
* below `.GlobalEnv`, so existing global bindings take precedence, but after a
|
|
20
|
+
* `rm(name)` removes a global shadow the attached binding becomes visible again.
|
|
21
|
+
*/
|
|
22
|
+
function processAttach(name, args, rootId, data) {
|
|
23
|
+
const result = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.Attach }).information;
|
|
24
|
+
const whatArg = args.length >= 1 ? args[0] : undefined;
|
|
25
|
+
const whatNode = whatArg && whatArg !== r_function_call_1.EmptyArgument ? (0, unpack_argument_1.unpackArg)(whatArg) : undefined;
|
|
26
|
+
if (whatNode?.type !== type_1.RType.Symbol) {
|
|
27
|
+
(0, unknown_side_effect_1.handleUnknownSideEffect)(result.graph, result.environment, rootId);
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
const envirResolution = (0, built_in_envir_utils_1.resolveSymbolToEnvir)(whatNode.content, whatNode.info.id, data);
|
|
31
|
+
if (!envirResolution) {
|
|
32
|
+
(0, unknown_side_effect_1.handleUnknownSideEffect)(result.graph, result.environment, rootId);
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
/* build the attached layer with the env's known bindings */
|
|
36
|
+
let attachedLayer = new environment_1.Environment(result.environment.current.parent);
|
|
37
|
+
for (const [varName, varDefs] of envirResolution.envDef.envState.current.memory) {
|
|
38
|
+
for (const varDef of varDefs) {
|
|
39
|
+
const inDef = varDef;
|
|
40
|
+
const injected = {
|
|
41
|
+
...inDef,
|
|
42
|
+
name: varName,
|
|
43
|
+
type: identifier_1.ReferenceType.Variable,
|
|
44
|
+
};
|
|
45
|
+
attachedLayer = attachedLayer.define(injected);
|
|
46
|
+
result.graph.addEdge(inDef.nodeId, rootId, edge_1.EdgeType.Reads);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/* splice the attached layer between the current scope and its original parent */
|
|
50
|
+
const newCurrent = result.environment.current.clone(false);
|
|
51
|
+
newCurrent.parent = attachedLayer;
|
|
52
|
+
return { ...result, environment: { current: newCurrent, level: result.environment.level } };
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=built-in-attach.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for built-in functions that interact with tracked R environments.
|
|
3
|
+
*
|
|
4
|
+
* - {@link bindArgs} - bind call arguments to formal parameter names using R's matching rules.
|
|
5
|
+
* - {@link resolveArgToEnvir} - resolve a single already-found argument to an {@link EnvirResolution}.
|
|
6
|
+
* - {@link resolveEnvirArg} / {@link resolveSymbolToEnvir} - resolve a named argument or
|
|
7
|
+
* symbol to an {@link EnvirResolution} when it holds a tracked {@link InGraphIdentifierDefinition#envState}.
|
|
8
|
+
* - {@link routeWrittenToCustomEnv} - move written definitions from the caller's scope into
|
|
9
|
+
* the holder variable's `envState` after processing an expression that writes into a custom env.
|
|
10
|
+
*/
|
|
11
|
+
import type { DataflowProcessorInformation } from '../../../../../processor';
|
|
12
|
+
import type { DataflowInformation } from '../../../../../info';
|
|
13
|
+
import type { ParentInformation } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
14
|
+
import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
|
|
15
|
+
import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
16
|
+
import type { Identifier, NamedInGraphIdentifierDefinition } from '../../../../../environments/identifier';
|
|
17
|
+
import type { REnvironmentInformation } from '../../../../../environments/environment';
|
|
18
|
+
/** Result type for a successful envir-argument resolution. */
|
|
19
|
+
export interface EnvirResolution<OtherInfo> {
|
|
20
|
+
/** `data` with its `environment` replaced by the resolved `envState` for in-env lookups. */
|
|
21
|
+
readonly envirData: DataflowProcessorInformation<OtherInfo & ParentInformation>;
|
|
22
|
+
/** The definition of the variable that holds the environment */
|
|
23
|
+
readonly envDef: NamedInGraphIdentifierDefinition & {
|
|
24
|
+
envState: REnvironmentInformation;
|
|
25
|
+
};
|
|
26
|
+
/** Node ID of the USE of the envir variable (e.g. the `e` in `envir=e`). */
|
|
27
|
+
readonly envirNodeId: NodeId;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Binds call arguments to formal parameter names following R's standard matching rules:
|
|
31
|
+
* 1. Exact name matches (named args bound to exact-matching formal params).
|
|
32
|
+
* 2. Partial (pmatch) name matches via {@link findByPrefixIfUnique}.
|
|
33
|
+
* 3. Remaining unnamed args fill remaining unbound formal params left-to-right.
|
|
34
|
+
*
|
|
35
|
+
* Pass `paramNames` as the full formal parameter list (excluding `...`) so ambiguous
|
|
36
|
+
* prefixes are rejected correctly. Use this when multiple formals must be found
|
|
37
|
+
* simultaneously so that named-arg binding is consistent across all formals.
|
|
38
|
+
*/
|
|
39
|
+
export declare function bindArgs<OtherInfo>(args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], paramNames: readonly string[]): ReadonlyMap<string, PotentiallyEmptyRArgument<OtherInfo & ParentInformation>>;
|
|
40
|
+
/**
|
|
41
|
+
* Resolves a single already-found argument (e.g. from {@link bindArgs}) to an
|
|
42
|
+
* {@link EnvirResolution} when the argument is a symbol that holds a tracked envState.
|
|
43
|
+
* Returns `undefined` when the arg is empty, non-symbolic, or unresolved.
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveArgToEnvir<OtherInfo>(arg: PotentiallyEmptyRArgument<OtherInfo & ParentInformation>, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): EnvirResolution<OtherInfo> | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Scans `args` for an argument named `argName` (default `'envir'`), or - when
|
|
48
|
+
* `positionalFallbackIndex` is given - for the arg at that positional index when
|
|
49
|
+
* no named match is found. When the resolved argument is a symbol that resolves
|
|
50
|
+
* to a variable with a tracked {@link InGraphIdentifierDefinition#envState},
|
|
51
|
+
* returns the resolved context; otherwise returns `undefined`.
|
|
52
|
+
*
|
|
53
|
+
* Named matching uses pmatch semantics: pass `allParamNames` (the full formal parameter
|
|
54
|
+
* list) so ambiguous prefixes are rejected. Defaults to `[argName]`, which allows
|
|
55
|
+
* prefix matches for `argName` only.
|
|
56
|
+
*
|
|
57
|
+
* When multiple formals must be matched simultaneously (e.g. `data` and `expr` in `with`),
|
|
58
|
+
* use {@link bindArgs} + {@link resolveArgToEnvir} instead so named binding is consistent.
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveEnvirArg<OtherInfo>(args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], data: DataflowProcessorInformation<OtherInfo & ParentInformation>, argName?: string, positionalFallbackIndex?: number, allParamNames?: readonly string[]): EnvirResolution<OtherInfo> | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Resolves a symbol by name to an {@link EnvirResolution} when the symbol holds a tracked
|
|
63
|
+
* environment. Handles multiple reaching definitions (e.g. from if/else branches) by
|
|
64
|
+
* merging their envStates - see {@link resolveDefsToEnvirResolution}.
|
|
65
|
+
* Returns `undefined` when the name cannot be resolved or none of its definitions carry an envState.
|
|
66
|
+
*/
|
|
67
|
+
export declare function resolveSymbolToEnvir<OtherInfo>(symbolName: Identifier, nodeId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): EnvirResolution<OtherInfo> | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* After processing an expression that writes into a custom environment, moves the
|
|
70
|
+
* written definitions from the caller's scope into `envDef`'s tracked `envState`
|
|
71
|
+
* and re-defines the holder variable in the returned environment.
|
|
72
|
+
*/
|
|
73
|
+
export declare function routeWrittenToCustomEnv(result: DataflowInformation, envDef: NamedInGraphIdentifierDefinition & {
|
|
74
|
+
envState: REnvironmentInformation;
|
|
75
|
+
}, newDefAt: NodeId, definedAt?: NodeId): DataflowInformation;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bindArgs = bindArgs;
|
|
4
|
+
exports.resolveArgToEnvir = resolveArgToEnvir;
|
|
5
|
+
exports.resolveEnvirArg = resolveEnvirArg;
|
|
6
|
+
exports.resolveSymbolToEnvir = resolveSymbolToEnvir;
|
|
7
|
+
exports.routeWrittenToCustomEnv = routeWrittenToCustomEnv;
|
|
8
|
+
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
9
|
+
const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
|
|
10
|
+
const unpack_argument_1 = require("../argument/unpack-argument");
|
|
11
|
+
const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
|
|
12
|
+
const identifier_1 = require("../../../../../environments/identifier");
|
|
13
|
+
const define_1 = require("../../../../../environments/define");
|
|
14
|
+
const prefix_1 = require("../../../../../../util/prefix");
|
|
15
|
+
/**
|
|
16
|
+
* Core resolver: maps a list of identifier definitions (from {@link resolveByName}) to an
|
|
17
|
+
* {@link EnvirResolution}. Accepts `undefined` so callers can pass `resolveByName` results
|
|
18
|
+
* directly without an intermediate null check.
|
|
19
|
+
*
|
|
20
|
+
* Multiple reaching definitions (e.g. from if/else branches) are accepted only when every
|
|
21
|
+
* definition carries an envState; their envStates are merged into a single combined snapshot.
|
|
22
|
+
*/
|
|
23
|
+
function resolveDefsToEnvirResolution(defs, nodeId, data) {
|
|
24
|
+
if (!defs || defs.length === 0) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const inDefs = defs;
|
|
28
|
+
if (inDefs.length === 1) {
|
|
29
|
+
const envState = inDefs[0].envState;
|
|
30
|
+
if (!envState) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
const envDef = inDefs[0];
|
|
34
|
+
return { envirData: { ...data, environment: envState }, envDef, envirNodeId: nodeId };
|
|
35
|
+
}
|
|
36
|
+
if (!inDefs.every(d => d.envState !== undefined)) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
let mergedEnvState = inDefs[0].envState;
|
|
40
|
+
for (let i = 1; i < inDefs.length; i++) {
|
|
41
|
+
for (const [, varDefs] of inDefs[i].envState.current.memory) {
|
|
42
|
+
for (const varDef of varDefs) {
|
|
43
|
+
const named = varDef;
|
|
44
|
+
if (named.name !== undefined) {
|
|
45
|
+
mergedEnvState = (0, define_1.define)(named, false, mergedEnvState);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const envDef = {
|
|
51
|
+
...inDefs[0],
|
|
52
|
+
envState: mergedEnvState
|
|
53
|
+
};
|
|
54
|
+
return { envirData: { ...data, environment: mergedEnvState }, envDef, envirNodeId: nodeId };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Binds call arguments to formal parameter names following R's standard matching rules:
|
|
58
|
+
* 1. Exact name matches (named args bound to exact-matching formal params).
|
|
59
|
+
* 2. Partial (pmatch) name matches via {@link findByPrefixIfUnique}.
|
|
60
|
+
* 3. Remaining unnamed args fill remaining unbound formal params left-to-right.
|
|
61
|
+
*
|
|
62
|
+
* Pass `paramNames` as the full formal parameter list (excluding `...`) so ambiguous
|
|
63
|
+
* prefixes are rejected correctly. Use this when multiple formals must be found
|
|
64
|
+
* simultaneously so that named-arg binding is consistent across all formals.
|
|
65
|
+
*/
|
|
66
|
+
function bindArgs(args, paramNames) {
|
|
67
|
+
const bound = new Map();
|
|
68
|
+
const used = new Set();
|
|
69
|
+
/* pass 1: exact name matches */
|
|
70
|
+
for (let i = 0; i < args.length; i++) {
|
|
71
|
+
const arg = args[i];
|
|
72
|
+
if (arg === r_function_call_1.EmptyArgument || arg.name === undefined) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const n = arg.name.content;
|
|
76
|
+
if (paramNames.includes(n) && !bound.has(n)) {
|
|
77
|
+
bound.set(n, arg);
|
|
78
|
+
used.add(i);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/* pass 2: partial (pmatch) name matches */
|
|
82
|
+
for (let i = 0; i < args.length; i++) {
|
|
83
|
+
if (used.has(i)) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const arg = args[i];
|
|
87
|
+
if (arg === r_function_call_1.EmptyArgument || arg.name === undefined) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const matched = (0, prefix_1.findByPrefixIfUnique)(arg.name.content, paramNames);
|
|
91
|
+
if (matched !== undefined && !bound.has(matched)) {
|
|
92
|
+
bound.set(matched, arg);
|
|
93
|
+
used.add(i);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/* pass 3: remaining unnamed args fill remaining formal params left-to-right */
|
|
97
|
+
let formalIdx = 0;
|
|
98
|
+
for (let i = 0; i < args.length; i++) {
|
|
99
|
+
if (used.has(i)) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const arg = args[i];
|
|
103
|
+
if (arg === r_function_call_1.EmptyArgument || arg.name !== undefined) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
while (formalIdx < paramNames.length && bound.has(paramNames[formalIdx])) {
|
|
107
|
+
formalIdx++;
|
|
108
|
+
}
|
|
109
|
+
if (formalIdx < paramNames.length) {
|
|
110
|
+
bound.set(paramNames[formalIdx], arg);
|
|
111
|
+
used.add(i);
|
|
112
|
+
formalIdx++;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return bound;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Resolves a single already-found argument (e.g. from {@link bindArgs}) to an
|
|
119
|
+
* {@link EnvirResolution} when the argument is a symbol that holds a tracked envState.
|
|
120
|
+
* Returns `undefined` when the arg is empty, non-symbolic, or unresolved.
|
|
121
|
+
*/
|
|
122
|
+
function resolveArgToEnvir(arg, data) {
|
|
123
|
+
if (arg === r_function_call_1.EmptyArgument) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
const node = (0, unpack_argument_1.unpackArg)(arg);
|
|
127
|
+
if (node?.type !== type_1.RType.Symbol) {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
return resolveDefsToEnvirResolution((0, resolve_by_name_1.resolveByName)(node.content, data.environment, identifier_1.ReferenceType.Variable), node.info.id, data);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Scans `args` for an argument named `argName` (default `'envir'`), or - when
|
|
134
|
+
* `positionalFallbackIndex` is given - for the arg at that positional index when
|
|
135
|
+
* no named match is found. When the resolved argument is a symbol that resolves
|
|
136
|
+
* to a variable with a tracked {@link InGraphIdentifierDefinition#envState},
|
|
137
|
+
* returns the resolved context; otherwise returns `undefined`.
|
|
138
|
+
*
|
|
139
|
+
* Named matching uses pmatch semantics: pass `allParamNames` (the full formal parameter
|
|
140
|
+
* list) so ambiguous prefixes are rejected. Defaults to `[argName]`, which allows
|
|
141
|
+
* prefix matches for `argName` only.
|
|
142
|
+
*
|
|
143
|
+
* When multiple formals must be matched simultaneously (e.g. `data` and `expr` in `with`),
|
|
144
|
+
* use {@link bindArgs} + {@link resolveArgToEnvir} instead so named binding is consistent.
|
|
145
|
+
*/
|
|
146
|
+
function resolveEnvirArg(args, data, argName = 'envir', positionalFallbackIndex, allParamNames = [argName]) {
|
|
147
|
+
/* named pass: pmatch against the full parameter list */
|
|
148
|
+
for (const arg of args) {
|
|
149
|
+
if (arg === r_function_call_1.EmptyArgument || arg.name === undefined) {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if ((0, prefix_1.findByPrefixIfUnique)(arg.name.content, allParamNames) === argName) {
|
|
153
|
+
return resolveArgToEnvir(arg, data);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/* positional fallback (only when no named match existed) */
|
|
157
|
+
if (positionalFallbackIndex !== undefined) {
|
|
158
|
+
let pos = 0;
|
|
159
|
+
for (const arg of args) {
|
|
160
|
+
if (arg === r_function_call_1.EmptyArgument || arg.name !== undefined) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (pos === positionalFallbackIndex) {
|
|
164
|
+
return resolveArgToEnvir(arg, data);
|
|
165
|
+
}
|
|
166
|
+
pos++;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Resolves a symbol by name to an {@link EnvirResolution} when the symbol holds a tracked
|
|
173
|
+
* environment. Handles multiple reaching definitions (e.g. from if/else branches) by
|
|
174
|
+
* merging their envStates - see {@link resolveDefsToEnvirResolution}.
|
|
175
|
+
* Returns `undefined` when the name cannot be resolved or none of its definitions carry an envState.
|
|
176
|
+
*/
|
|
177
|
+
function resolveSymbolToEnvir(symbolName, nodeId, data) {
|
|
178
|
+
return resolveDefsToEnvirResolution((0, resolve_by_name_1.resolveByName)(symbolName, data.environment, identifier_1.ReferenceType.Variable), nodeId, data);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* After processing an expression that writes into a custom environment, moves the
|
|
182
|
+
* written definitions from the caller's scope into `envDef`'s tracked `envState`
|
|
183
|
+
* and re-defines the holder variable in the returned environment.
|
|
184
|
+
*/
|
|
185
|
+
function routeWrittenToCustomEnv(result, envDef, newDefAt, definedAt) {
|
|
186
|
+
const written = result.out.filter((d) => d.name !== undefined && 'definedAt' in d &&
|
|
187
|
+
(definedAt === undefined || d.definedAt === definedAt));
|
|
188
|
+
let newEnvState = envDef.envState;
|
|
189
|
+
const namesToRemove = written.map(w => ({ name: w.name }));
|
|
190
|
+
for (const w of written) {
|
|
191
|
+
newEnvState = (0, define_1.define)(w, false, newEnvState);
|
|
192
|
+
}
|
|
193
|
+
const newEnvironment = (0, define_1.define)({ ...envDef, definedAt: newDefAt, envState: newEnvState }, false, { current: result.environment.current.removeAll(namesToRemove), level: result.environment.level });
|
|
194
|
+
return { ...result, environment: newEnvironment };
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=built-in-envir-utils.js.map
|