@eagleoutice/flowr 2.13.3 → 2.13.4

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 (67) hide show
  1. package/README.md +11 -11
  2. package/abstract-interpretation/absint-visitor.js +2 -2
  3. package/abstract-interpretation/data-frame/mappers/arguments.js +2 -2
  4. package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +1 -1
  5. package/abstract-interpretation/unsupported-functions.js +1 -1
  6. package/control-flow/cfg-dead-code.js +72 -11
  7. package/control-flow/extract-cfg.js +85 -8
  8. package/control-flow/semantic-cfg-guided-visitor.js +2 -0
  9. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  10. package/dataflow/environments/built-in-proc-name.js +4 -0
  11. package/dataflow/environments/built-in.d.ts +5 -1
  12. package/dataflow/environments/built-in.js +5 -1
  13. package/dataflow/environments/default-builtin-config.d.ts +59 -4
  14. package/dataflow/environments/default-builtin-config.js +23 -11
  15. package/dataflow/environments/identifier.d.ts +1 -0
  16. package/dataflow/eval/resolve/alias-tracking.d.ts +2 -0
  17. package/dataflow/eval/resolve/alias-tracking.js +8 -1
  18. package/dataflow/eval/resolve/resolve.d.ts +14 -0
  19. package/dataflow/eval/resolve/resolve.js +47 -0
  20. package/dataflow/fn/higher-order-function.js +3 -3
  21. package/dataflow/fn/recursive-function.js +1 -1
  22. package/dataflow/graph/df-helper.js +1 -1
  23. package/dataflow/graph/vertex.d.ts +32 -25
  24. package/dataflow/graph/vertex.js +40 -36
  25. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +1 -0
  26. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +7 -4
  27. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +14 -0
  28. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +28 -29
  29. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +41 -48
  30. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +14 -0
  31. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +45 -0
  32. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +7 -1
  33. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +29 -0
  34. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +62 -2
  35. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +63 -16
  36. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +29 -9
  37. package/dataflow/internal/process/functions/call/built-in/built-in-list.d.ts +5 -1
  38. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +35 -0
  39. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +2 -2
  40. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +1 -1
  41. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +2 -0
  42. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +46 -0
  43. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +3 -1
  44. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +24 -0
  45. package/dataflow/internal/process/functions/process-parameter.js +2 -1
  46. package/linter/rules/absolute-path.js +1 -1
  47. package/linter/rules/function-finder-util.js +1 -1
  48. package/linter/rules/no-leaked-credentials.js +1 -1
  49. package/linter/rules/undefined-symbol.js +1 -1
  50. package/linter/rules/unused-definition.js +15 -10
  51. package/linter/rules/useless-loop.js +1 -1
  52. package/package.json +1 -1
  53. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +1 -1
  54. package/queries/catalog/call-context-query/identify-link-to-nested-call-relation.js +1 -1
  55. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  56. package/queries/catalog/dependencies-query/function-info/write-functions.js +23 -24
  57. package/queries/catalog/input-sources-query/input-source-functions.d.ts +2 -1
  58. package/queries/catalog/input-sources-query/input-source-functions.js +14 -20
  59. package/queries/catalog/input-sources-query/input-sources-query-executor.js +11 -6
  60. package/queries/catalog/input-sources-query/input-sources-query-format.js +2 -1
  61. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +14 -1
  62. package/queries/catalog/input-sources-query/simple-input-classifier.js +24 -0
  63. package/r-bridge/data/data.d.ts +2 -2
  64. package/r-bridge/data/data.js +2 -2
  65. package/reconstruct/inline/source-inline-map.js +1 -1
  66. package/util/mermaid/dfg.js +1 -1
  67. package/util/version.js +1 -1
@@ -14,7 +14,9 @@ export declare enum StackEnvKind {
14
14
  Empty = 2,
15
15
  Current = 3,
16
16
  Parent = 4,
17
- Named = 5
17
+ /** `parent.frame()`: the dynamic caller's frame, over-approximated to the global env (exact at a top-level call). */
18
+ CallerFrame = 5,
19
+ Named = 6
18
20
  }
19
21
  /** Maps the env-returning/-transforming base builtins and constants to the stack environment each denotes. */
20
22
  export declare const StackEnvBuiltins: {
@@ -23,6 +25,7 @@ export declare const StackEnvBuiltins: {
23
25
  readonly emptyenv: StackEnvKind.Empty;
24
26
  readonly environment: StackEnvKind.Current;
25
27
  readonly 'parent.env': StackEnvKind.Parent;
28
+ readonly 'parent.frame': StackEnvKind.CallerFrame;
26
29
  readonly 'as.environment': StackEnvKind.Named;
27
30
  readonly '.GlobalEnv': StackEnvKind.Global;
28
31
  readonly '.BaseEnv': StackEnvKind.Base;
@@ -158,6 +161,7 @@ export declare const DefaultBuiltinConfig: [{
158
161
  readonly config: {
159
162
  readonly indexOfFunction: 0;
160
163
  readonly nameOfFunctionArgument: "FUN";
164
+ readonly unquoteFunction: true;
161
165
  };
162
166
  readonly assumePrimitive: false;
163
167
  }, {
@@ -167,6 +171,7 @@ export declare const DefaultBuiltinConfig: [{
167
171
  readonly config: {
168
172
  readonly indexOfFunction: 1;
169
173
  readonly nameOfFunctionArgument: "FUN";
174
+ readonly unquoteFunction: true;
170
175
  };
171
176
  readonly assumePrimitive: false;
172
177
  }, {
@@ -176,6 +181,7 @@ export declare const DefaultBuiltinConfig: [{
176
181
  readonly config: {
177
182
  readonly indexOfFunction: 1;
178
183
  readonly nameOfFunctionArgument: "FUN";
184
+ readonly unquoteFunction: true;
179
185
  };
180
186
  readonly assumePrimitive: false;
181
187
  }, {
@@ -185,6 +191,27 @@ export declare const DefaultBuiltinConfig: [{
185
191
  readonly config: {
186
192
  readonly indexOfFunction: 2;
187
193
  readonly nameOfFunctionArgument: "FUN";
194
+ readonly unquoteFunction: true;
195
+ };
196
+ readonly assumePrimitive: false;
197
+ }, {
198
+ readonly type: "function";
199
+ readonly names: [Identifier, Identifier];
200
+ readonly processor: BuiltInProcName.Apply;
201
+ readonly config: {
202
+ readonly indexOfFunction: 0;
203
+ readonly nameOfFunctionArgument: "f";
204
+ readonly unquoteFunction: true;
205
+ };
206
+ readonly assumePrimitive: false;
207
+ }, {
208
+ readonly type: "function";
209
+ readonly names: [Identifier];
210
+ readonly processor: BuiltInProcName.Apply;
211
+ readonly config: {
212
+ readonly indexOfFunction: 0;
213
+ readonly nameOfFunctionArgument: "f";
214
+ readonly unquoteFunction: true;
188
215
  };
189
216
  readonly assumePrimitive: false;
190
217
  }, {
@@ -369,6 +396,7 @@ export declare const DefaultBuiltinConfig: [{
369
396
  readonly processor: BuiltInProcName.Default;
370
397
  readonly config: {
371
398
  readonly forceArgs: readonly [true];
399
+ readonly useAsProcessor: BuiltInProcName.Switch;
372
400
  };
373
401
  readonly assumePrimitive: false;
374
402
  }, {
@@ -453,10 +481,19 @@ export declare const DefaultBuiltinConfig: [{
453
481
  readonly assumePrimitive: false;
454
482
  }, {
455
483
  readonly type: "function";
456
- readonly names: ["[", "[["];
484
+ readonly names: ["["];
485
+ readonly processor: BuiltInProcName.Access;
486
+ readonly config: {
487
+ readonly treatIndicesAsString: false;
488
+ };
489
+ readonly assumePrimitive: true;
490
+ }, {
491
+ readonly type: "function";
492
+ readonly names: ["[["];
457
493
  readonly processor: BuiltInProcName.Access;
458
494
  readonly config: {
459
495
  readonly treatIndicesAsString: false;
496
+ readonly resolveField: true;
460
497
  };
461
498
  readonly assumePrimitive: true;
462
499
  }, {
@@ -465,6 +502,7 @@ export declare const DefaultBuiltinConfig: [{
465
502
  readonly processor: BuiltInProcName.Access;
466
503
  readonly config: {
467
504
  readonly treatIndicesAsString: true;
505
+ readonly resolveField: true;
468
506
  };
469
507
  readonly assumePrimitive: true;
470
508
  }, {
@@ -1107,6 +1145,12 @@ export declare const DefaultBuiltinConfig: [{
1107
1145
  readonly processor: BuiltInProcName.NewEnv;
1108
1146
  readonly config: {};
1109
1147
  readonly assumePrimitive: true;
1148
+ }, {
1149
+ readonly type: "function";
1150
+ readonly names: [Identifier, Identifier];
1151
+ readonly processor: BuiltInProcName.ClassGenerator;
1152
+ readonly config: {};
1153
+ readonly assumePrimitive: false;
1110
1154
  }, {
1111
1155
  readonly type: "function";
1112
1156
  readonly names: Identifier[];
@@ -1231,9 +1275,20 @@ export declare const DefaultBuiltinConfig: [{
1231
1275
  readonly assumePrimitive: true;
1232
1276
  }, {
1233
1277
  readonly type: "function";
1234
- readonly names: [Identifier, Identifier, Identifier];
1278
+ readonly names: [Identifier, Identifier];
1235
1279
  readonly processor: BuiltInProcName.S7MakeConstructor;
1236
- readonly config: {};
1280
+ readonly config: {
1281
+ readonly wrapIndex: 0;
1282
+ };
1283
+ readonly assumePrimitive: true;
1284
+ }, {
1285
+ readonly type: "function";
1286
+ readonly names: [Identifier];
1287
+ readonly processor: BuiltInProcName.S7MakeConstructor;
1288
+ readonly config: {
1289
+ readonly wrapIndex: 0;
1290
+ readonly wrapName: ".f";
1291
+ };
1237
1292
  readonly assumePrimitive: true;
1238
1293
  }, {
1239
1294
  readonly type: "function";
@@ -19,7 +19,9 @@ var StackEnvKind;
19
19
  StackEnvKind[StackEnvKind["Empty"] = 2] = "Empty";
20
20
  StackEnvKind[StackEnvKind["Current"] = 3] = "Current";
21
21
  StackEnvKind[StackEnvKind["Parent"] = 4] = "Parent";
22
- StackEnvKind[StackEnvKind["Named"] = 5] = "Named";
22
+ /** `parent.frame()`: the dynamic caller's frame, over-approximated to the global env (exact at a top-level call). */
23
+ StackEnvKind[StackEnvKind["CallerFrame"] = 5] = "CallerFrame";
24
+ StackEnvKind[StackEnvKind["Named"] = 6] = "Named";
23
25
  })(StackEnvKind || (exports.StackEnvKind = StackEnvKind = {}));
24
26
  /** Maps the env-returning/-transforming base builtins and constants to the stack environment each denotes. */
25
27
  exports.StackEnvBuiltins = {
@@ -28,6 +30,7 @@ exports.StackEnvBuiltins = {
28
30
  emptyenv: StackEnvKind.Empty,
29
31
  environment: StackEnvKind.Current,
30
32
  'parent.env': StackEnvKind.Parent,
33
+ 'parent.frame': StackEnvKind.CallerFrame,
31
34
  'as.environment': StackEnvKind.Named,
32
35
  '.GlobalEnv': StackEnvKind.Global,
33
36
  '.BaseEnv': StackEnvKind.Base,
@@ -247,13 +250,17 @@ exports.DefaultBuiltinConfig = [
247
250
  { type: 'function', names: [identifier_1.Identifier.from(['options', "base" /* PkgName.Base */])],
248
251
  processor: built_in_proc_name_1.BuiltInProcName.Default, config: { hasUnknownSideEffects: true, forceArgs: 'all' }, assumePrimitive: false },
249
252
  { type: 'function', names: [identifier_1.Identifier.from(['mapply', "base" /* PkgName.Base */]), identifier_1.Identifier.from(['Mapply', "functools" /* PkgName.Functools */])],
250
- processor: built_in_proc_name_1.BuiltInProcName.Apply, config: { indexOfFunction: 0, nameOfFunctionArgument: 'FUN' }, assumePrimitive: false },
253
+ processor: built_in_proc_name_1.BuiltInProcName.Apply, config: { indexOfFunction: 0, nameOfFunctionArgument: 'FUN', unquoteFunction: true }, assumePrimitive: false },
251
254
  { type: 'function', names: [identifier_1.Identifier.from(['lapply', "base" /* PkgName.Base */]), identifier_1.Identifier.from(['sapply', "base" /* PkgName.Base */]), identifier_1.Identifier.from(['vapply', "base" /* PkgName.Base */])],
252
- processor: built_in_proc_name_1.BuiltInProcName.Apply, config: { indexOfFunction: 1, nameOfFunctionArgument: 'FUN' }, assumePrimitive: false },
255
+ processor: built_in_proc_name_1.BuiltInProcName.Apply, config: { indexOfFunction: 1, nameOfFunctionArgument: 'FUN', unquoteFunction: true }, assumePrimitive: false },
253
256
  { type: 'function', names: [identifier_1.Identifier.from(['Lapply', "functools" /* PkgName.Functools */]), identifier_1.Identifier.from(['Sapply', "functools" /* PkgName.Functools */]), identifier_1.Identifier.from(['Vapply', "functools" /* PkgName.Functools */])],
254
- processor: built_in_proc_name_1.BuiltInProcName.Apply, config: { indexOfFunction: 1, nameOfFunctionArgument: 'FUN' }, assumePrimitive: false },
257
+ processor: built_in_proc_name_1.BuiltInProcName.Apply, config: { indexOfFunction: 1, nameOfFunctionArgument: 'FUN', unquoteFunction: true }, assumePrimitive: false },
255
258
  { type: 'function', names: [identifier_1.Identifier.from(['apply', "base" /* PkgName.Base */]), identifier_1.Identifier.from(['tapply', "base" /* PkgName.Base */]), identifier_1.Identifier.from(['Tapply', "functools" /* PkgName.Functools */])],
256
- processor: built_in_proc_name_1.BuiltInProcName.Apply, config: { indexOfFunction: 2, nameOfFunctionArgument: 'FUN' }, assumePrimitive: false },
259
+ processor: built_in_proc_name_1.BuiltInProcName.Apply, config: { indexOfFunction: 2, nameOfFunctionArgument: 'FUN', unquoteFunction: true }, assumePrimitive: false },
260
+ { type: 'function', names: [identifier_1.Identifier.from(['Map', "base" /* PkgName.Base */]), identifier_1.Identifier.from(['Filter', "base" /* PkgName.Base */])],
261
+ processor: built_in_proc_name_1.BuiltInProcName.Apply, config: { indexOfFunction: 0, nameOfFunctionArgument: 'f', unquoteFunction: true }, assumePrimitive: false },
262
+ { type: 'function', names: [identifier_1.Identifier.from(['Reduce', "base" /* PkgName.Base */])],
263
+ processor: built_in_proc_name_1.BuiltInProcName.Apply, config: { indexOfFunction: 0, nameOfFunctionArgument: 'f', unquoteFunction: true }, assumePrimitive: false },
257
264
  { type: 'function', names: [identifier_1.Identifier.from(['print', "base" /* PkgName.Base */]), identifier_1.Identifier.from(['message', "base" /* PkgName.Base */]), identifier_1.Identifier.from(['warning', "base" /* PkgName.Base */]), identifier_1.Identifier.from(['warn', "rlang" /* PkgName.Rlang */]), identifier_1.Identifier.from(['warn', "R.utils" /* PkgName.Rutils */]), identifier_1.Identifier.from(['info', "msgr" /* PkgName.Msgr */])],
258
265
  processor: built_in_proc_name_1.BuiltInProcName.Default, config: { returnsNthArgument: 0, forceArgs: 'all', keepArgumentOut: true, hasUnknownSideEffects: { type: 'link-to-last-call', callName: /^sink$/ } }, assumePrimitive: false },
259
266
  { type: 'function', names: [identifier_1.Identifier.from(['invisible', "base" /* PkgName.Base */])],
@@ -378,7 +385,7 @@ exports.DefaultBuiltinConfig = [
378
385
  { type: 'function', names: [identifier_1.Identifier.from(['cat', "base" /* PkgName.Base */])],
379
386
  processor: built_in_proc_name_1.BuiltInProcName.Default, config: { forceArgs: 'all', hasUnknownSideEffects: { type: 'link-to-last-call', callName: /^sink$/ } }, assumePrimitive: false },
380
387
  { type: 'function', names: [identifier_1.Identifier.from(['switch', "base" /* PkgName.Base */])],
381
- processor: built_in_proc_name_1.BuiltInProcName.Default, config: { forceArgs: [true] }, assumePrimitive: false },
388
+ processor: built_in_proc_name_1.BuiltInProcName.Default, config: { forceArgs: [true], useAsProcessor: built_in_proc_name_1.BuiltInProcName.Switch }, assumePrimitive: false },
382
389
  { type: 'function', names: ['return'],
383
390
  processor: built_in_proc_name_1.BuiltInProcName.Default, config: { returnsNthArgument: 0, cfg: 1 /* ExitPointType.Return */, keepArgumentOut: true, useAsProcessor: built_in_proc_name_1.BuiltInProcName.Return }, assumePrimitive: true },
384
391
  {
@@ -407,10 +414,12 @@ exports.DefaultBuiltinConfig = [
407
414
  processor: built_in_proc_name_1.BuiltInProcName.ExpressionList, config: {}, assumePrimitive: true },
408
415
  { type: 'function', names: [identifier_1.Identifier.from(['source', "base" /* PkgName.Base */])],
409
416
  processor: built_in_proc_name_1.BuiltInProcName.Source, config: { includeFunctionCall: true, forceFollow: false }, assumePrimitive: false },
410
- { type: 'function', names: ['[', '[['],
417
+ { type: 'function', names: ['['],
411
418
  processor: built_in_proc_name_1.BuiltInProcName.Access, config: { treatIndicesAsString: false }, assumePrimitive: true },
419
+ { type: 'function', names: ['[['],
420
+ processor: built_in_proc_name_1.BuiltInProcName.Access, config: { treatIndicesAsString: false, resolveField: true }, assumePrimitive: true },
412
421
  { type: 'function', names: ['$', '@'],
413
- processor: built_in_proc_name_1.BuiltInProcName.Access, config: { treatIndicesAsString: true }, assumePrimitive: true },
422
+ processor: built_in_proc_name_1.BuiltInProcName.Access, config: { treatIndicesAsString: true, resolveField: true }, assumePrimitive: true },
414
423
  { type: 'function', names: ['::'],
415
424
  processor: built_in_proc_name_1.BuiltInProcName.NamespaceAccess, config: { internal: false }, assumePrimitive: true },
416
425
  { type: 'function', names: [':::'],
@@ -614,6 +623,8 @@ exports.DefaultBuiltinConfig = [
614
623
  processor: built_in_proc_name_1.BuiltInProcName.With, config: {}, assumePrimitive: false },
615
624
  { type: 'function', names: [identifier_1.Identifier.from(['new.env', "base" /* PkgName.Base */]), identifier_1.Identifier.from(['new_environment', "rlang" /* PkgName.Rlang */])],
616
625
  processor: built_in_proc_name_1.BuiltInProcName.NewEnv, config: {}, assumePrimitive: true },
626
+ { type: 'function', names: [identifier_1.Identifier.from(['R6Class', "R6" /* PkgName.R6 */]), identifier_1.Identifier.from(['setRefClass', "methods" /* PkgName.Methods */])],
627
+ processor: built_in_proc_name_1.BuiltInProcName.ClassGenerator, config: {}, assumePrimitive: false },
617
628
  /* env-returning builtins pointing into the current search-path stack (`e <- globalenv(); e$x`) */
618
629
  { type: 'function', names: Object.entries(exports.StackEnvBuiltins)
619
630
  .filter(([n, kind]) => !n.startsWith('.') && (kind === StackEnvKind.Global || kind === StackEnvKind.Base || kind === StackEnvKind.Empty))
@@ -653,9 +664,10 @@ exports.DefaultBuiltinConfig = [
653
664
  { type: 'function', names: [identifier_1.Identifier.from(['setClass', "methods" /* PkgName.Methods */])],
654
665
  processor: built_in_proc_name_1.BuiltInProcName.S7MakeConstructor, config: { mode: ['s4'] }, assumePrimitive: true },
655
666
  { type: 'function', names: [
656
- identifier_1.Identifier.from(['Negate', "base" /* PkgName.Base */]), identifier_1.Identifier.from(['Vectorize', "base" /* PkgName.Base */]),
657
- identifier_1.Identifier.from(['partial', "purrr" /* PkgName.Purrr */])
658
- ], processor: built_in_proc_name_1.BuiltInProcName.S7MakeConstructor, config: {}, assumePrimitive: true },
667
+ identifier_1.Identifier.from(['Negate', "base" /* PkgName.Base */]), identifier_1.Identifier.from(['Vectorize', "base" /* PkgName.Base */])
668
+ ], processor: built_in_proc_name_1.BuiltInProcName.S7MakeConstructor, config: { wrapIndex: 0 }, assumePrimitive: true },
669
+ { type: 'function', names: [identifier_1.Identifier.from(['partial', "purrr" /* PkgName.Purrr */])],
670
+ processor: built_in_proc_name_1.BuiltInProcName.S7MakeConstructor, config: { wrapIndex: 0, wrapName: '.f' }, assumePrimitive: true },
659
671
  { type: 'function', names: [identifier_1.Identifier.from(['.Primitive', "base" /* PkgName.Base */]), identifier_1.Identifier.from(['.Internal', "base" /* PkgName.Base */])],
660
672
  processor: built_in_proc_name_1.BuiltInProcName.Apply, config: { indexOfFunction: 0, unquoteFunction: true, resolveInEnvironment: 'global' }, assumePrimitive: true },
661
673
  { type: 'function', names: [identifier_1.Identifier.from(['interference', "inferference" /* PkgName.Inferference */])],
@@ -158,6 +158,7 @@ export declare const enum PkgName {
158
158
  Plyr = "plyr",
159
159
  Purrr = "purrr",
160
160
  Ragg = "ragg",
161
+ R6 = "R6",
161
162
  RasterPdf = "rasterpdf",
162
163
  Remotes = "remotes",
163
164
  Rlang = "rlang",
@@ -59,6 +59,8 @@ export declare function getAliases(sourceIds: readonly NodeId[], dataflow: Dataf
59
59
  * @param blocked - If set, the ids that should not be considered during resolution (=&gt;top)
60
60
  */
61
61
  export declare function resolveIdToValue(id: NodeId | RNodeWithParent | undefined, { environment, graph, idMap, full, ctx, resolve, blocked }: ResolveInfo): ResolveResult;
62
+ /** Resolves an id to a single constant string value, or `undefined` if it is not a unique string constant. */
63
+ export declare function resolveIdToSingleString(id: NodeId | RNodeWithParent | undefined, info: ResolveInfo): string | undefined;
62
64
  /**
63
65
  * Please use {@link resolveIdToValue}
64
66
  *
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAliases = getAliases;
4
4
  exports.resolveIdToValue = resolveIdToValue;
5
+ exports.resolveIdToSingleString = resolveIdToSingleString;
5
6
  exports.trackAliasInEnvironments = trackAliasInEnvironments;
6
7
  exports.trackAliasesInGraph = trackAliasesInGraph;
7
8
  exports.resolveToConstants = resolveToConstants;
@@ -163,6 +164,12 @@ function resolveIdToValue(id, { environment, graph, idMap, full = true, ctx, res
163
164
  return r_value_1.Top;
164
165
  }
165
166
  }
167
+ /** Resolves an id to a single constant string value, or `undefined` if it is not a unique string constant. */
168
+ function resolveIdToSingleString(id, info) {
169
+ const resolved = (0, general_1.valueSetGuard)(resolveIdToValue(id, info));
170
+ const element = resolved?.elements.length === 1 ? resolved.elements[0] : undefined;
171
+ return element?.type === 'string' && (0, r_value_1.isValue)(element.value) ? element.value.str : undefined;
172
+ }
166
173
  /**
167
174
  * Please use {@link resolveIdToValue}
168
175
  *
@@ -325,7 +332,7 @@ function trackAliasesInGraph(id, graph, ctx, idMap) {
325
332
  const values = new Set();
326
333
  for (const id of resultIds) {
327
334
  const vertex = graph.getVertex(id);
328
- if ((0, vertex_1.isValueVertex)(vertex) && vertex.value !== undefined) {
335
+ if (vertex_1.ValueVertex.is(vertex) && vertex.value !== undefined) {
329
336
  values.add(vertex.value);
330
337
  continue;
331
338
  }
@@ -1,3 +1,5 @@
1
+ import type { RNamedFunctionCall } from '../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
2
+ import type { RNode } from '../../../r-bridge/lang-4.x/ast/model/model';
1
3
  import type { BuiltInEvalHandlerArgs } from '../../environments/built-in';
2
4
  import { type Lift, Top, type Value, type ValueNumber, type ValueVector } from '../values/r-value';
3
5
  /**
@@ -45,3 +47,15 @@ export declare function resolveAsPlus({ node: operator, environment, resolve, ct
45
47
  * @returns ValueNumber, ValueVector of ValueNumbers, or Top
46
48
  */
47
49
  export declare function resolveAsMinus({ node: operator, environment, resolve, ctx, graph, idMap, blocked }: BuiltInEvalHandlerArgs): ValueNumber | ValueVector<Lift<ValueNumber[]>> | typeof Top;
50
+ /**
51
+ * Resolves a `paste`/`paste0` call to a {@link Value} string when every non-`sep`/`collapse` argument
52
+ * resolves to a single string constant (e.g. `paste0("cfg_", k)` with `k` a known string). `sep` defaults to
53
+ * `""` for `paste0` and `" "` for `paste`, or the constant `sep=` argument when given; any unresolved part yields Top.
54
+ */
55
+ export declare function resolveAsPaste({ resolve, node, ctx, blocked, environment, graph, idMap }: BuiltInEvalHandlerArgs): Value;
56
+ /**
57
+ * Folds a named `paste`/`paste0` call to its concatenated string, resolving each non-`sep`/`collapse` argument via
58
+ * `resolveArg`; `sep` defaults to `""` (paste0) or `" "` (paste), overridden by a resolvable `sep=`. `undefined` if any
59
+ * part (or `sep`) does not resolve. Shared by the value solver ({@link resolveAsPaste}) and construction-time name resolution.
60
+ */
61
+ export declare function foldPasteCall<Info>(node: RNamedFunctionCall<Info>, resolveArg: (arg: RNode<Info>) => string | undefined): string | undefined;
@@ -5,6 +5,8 @@ exports.resolveAsVector = resolveAsVector;
5
5
  exports.resolveAsSeq = resolveAsSeq;
6
6
  exports.resolveAsPlus = resolveAsPlus;
7
7
  exports.resolveAsMinus = resolveAsMinus;
8
+ exports.resolveAsPaste = resolveAsPaste;
9
+ exports.foldPasteCall = foldPasteCall;
8
10
  const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
9
11
  const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
10
12
  const r_value_1 = require("../../../util/r-value");
@@ -150,6 +152,51 @@ function resolveAsMinus({ node: operator, environment, resolve, ctx, graph, idMa
150
152
  }
151
153
  return r_value_2.Top;
152
154
  }
155
+ /**
156
+ * Resolves a `paste`/`paste0` call to a {@link Value} string when every non-`sep`/`collapse` argument
157
+ * resolves to a single string constant (e.g. `paste0("cfg_", k)` with `k` a known string). `sep` defaults to
158
+ * `""` for `paste0` and `" "` for `paste`, or the constant `sep=` argument when given; any unresolved part yields Top.
159
+ */
160
+ function resolveAsPaste({ resolve, node, ctx, blocked, environment, graph, idMap }) {
161
+ if (node.type !== type_1.RType.FunctionCall || !node.named) {
162
+ return r_value_2.Top;
163
+ }
164
+ const resolveInfo = { environment, graph, idMap, full: true, resolve, ctx, blocked };
165
+ const folded = foldPasteCall(node, arg => (0, alias_tracking_1.resolveIdToSingleString)(arg.info.id, resolveInfo));
166
+ return folded === undefined ? r_value_2.Top : (0, string_constants_1.stringFrom)(folded);
167
+ }
168
+ /**
169
+ * Folds a named `paste`/`paste0` call to its concatenated string, resolving each non-`sep`/`collapse` argument via
170
+ * `resolveArg`; `sep` defaults to `""` (paste0) or `" "` (paste), overridden by a resolvable `sep=`. `undefined` if any
171
+ * part (or `sep`) does not resolve. Shared by the value solver ({@link resolveAsPaste}) and construction-time name resolution.
172
+ */
173
+ function foldPasteCall(node, resolveArg) {
174
+ let sep = identifier_1.Identifier.getName(node.functionName.content) === 'paste0' ? '' : ' ';
175
+ const parts = [];
176
+ for (const arg of node.arguments) {
177
+ if (arg === r_function_call_1.EmptyArgument || arg.value === undefined) {
178
+ continue;
179
+ }
180
+ const argName = arg.name?.content;
181
+ if (argName === 'collapse') {
182
+ continue;
183
+ }
184
+ else if (argName === 'sep') {
185
+ const s = resolveArg(arg.value);
186
+ if (s === undefined) {
187
+ return undefined;
188
+ }
189
+ sep = s;
190
+ continue;
191
+ }
192
+ const part = resolveArg(arg.value);
193
+ if (part === undefined) {
194
+ return undefined;
195
+ }
196
+ parts.push(part);
197
+ }
198
+ return parts.join(sep);
199
+ }
153
200
  function createNumberSequence(start, end) {
154
201
  const sequence = [];
155
202
  const min = Math.min(start.num, end.num);
@@ -17,7 +17,7 @@ function isAnyReturnAFunction(def, graph) {
17
17
  continue;
18
18
  }
19
19
  seen.add(current.id);
20
- if ((0, vertex_1.isFunctionDefinitionVertex)(current)) {
20
+ if (vertex_1.FunctionDefinitionVertex.is(current)) {
21
21
  return true;
22
22
  }
23
23
  const next = graph.outgoingEdges(current.id) ?? [];
@@ -39,7 +39,7 @@ function inspectCallSitesArgumentsFns(def, graph, ctx, invertedGraph) {
39
39
  continue;
40
40
  }
41
41
  const caller = graph.getVertex(callerId);
42
- if (!caller || !(0, vertex_1.isFunctionCallVertex)(caller)) {
42
+ if (!caller || !vertex_1.FunctionCallVertex.is(caller)) {
43
43
  continue;
44
44
  }
45
45
  for (const arg of caller.args) {
@@ -63,7 +63,7 @@ function inspectCallSitesArgumentsFns(def, graph, ctx, invertedGraph) {
63
63
  */
64
64
  function isFunctionHigherOrder(id, graph, ctx, invertedGraph) {
65
65
  const vert = graph.getVertex(id);
66
- if (!vert || !(0, vertex_1.isFunctionDefinitionVertex)(vert)) {
66
+ if (!vert || !vertex_1.FunctionDefinitionVertex.is(vert)) {
67
67
  return false;
68
68
  }
69
69
  // 1. check whether any of the exit types is a function
@@ -7,7 +7,7 @@ const vertex_1 = require("../graph/vertex");
7
7
  */
8
8
  function isFunctionRecursive(id, graph) {
9
9
  const vert = graph.getVertex(id);
10
- if (!(0, vertex_1.isFunctionDefinitionVertex)(vert)) {
10
+ if (!vertex_1.FunctionDefinitionVertex.is(vert)) {
11
11
  return false;
12
12
  }
13
13
  const seen = new Set();
@@ -69,7 +69,7 @@ exports.Dataflow = {
69
69
  */
70
70
  qualify(id, graph, qualifyBaseR = true) {
71
71
  const vertex = graph.getVertex(id);
72
- return identifier_1.Identifier.toQualified((0, dfg_get_origin_1.getOriginInDfg)(graph, id), (0, vertex_1.isFunctionCallVertex)(vertex) ? vertex.name : undefined, qualifyBaseR);
72
+ return identifier_1.Identifier.toQualified((0, dfg_get_origin_1.getOriginInDfg)(graph, id), vertex_1.FunctionCallVertex.is(vertex) ? vertex.name : undefined, qualifyBaseR);
73
73
  },
74
74
  /**
75
75
  * Interprocedural propagation of escaped side effects (attached packages, `<<-` definitions) to their callers.
@@ -62,7 +62,7 @@ export interface DataflowGraphVertexAstLink {
62
62
  *
63
63
  * For built-in constants whose id is not in the {@link AstIdMap} (e.g. `T` resolving to `built-in:T`),
64
64
  * the abstract {@link Value} is stored directly in the {@link DataflowGraphVertexValue#value|value} field.
65
- * @see {@link isValueVertex} - to check if a vertex is a value vertex
65
+ * @see {@link ValueVertex.is} - to check if a vertex is a value vertex
66
66
  */
67
67
  export interface DataflowGraphVertexValue extends DataflowGraphVertexBase {
68
68
  readonly tag: VertexType.Value;
@@ -72,7 +72,7 @@ export interface DataflowGraphVertexValue extends DataflowGraphVertexBase {
72
72
  }
73
73
  /**
74
74
  * Arguments required to construct a vertex which represents the usage of a variable in the {@link DataflowGraph|dataflow graph}.
75
- * @see {@link isUseVertex} - to check if a vertex is a use vertex
75
+ * @see {@link UseVertex.is} - to check if a vertex is a use vertex
76
76
  */
77
77
  export interface DataflowGraphVertexUse extends DataflowGraphVertexBase {
78
78
  readonly tag: VertexType.Use;
@@ -83,7 +83,7 @@ export interface DataflowGraphVertexUse extends DataflowGraphVertexBase {
83
83
  * Arguments required to construct a vertex which represents the call to a function in the {@link DataflowGraph|dataflow graph}.
84
84
  * This describes all kinds of function calls, including calls to built-ins and control-flow structures such as `if` or `for` (they are
85
85
  * treated as function calls in R).
86
- * @see {@link isFunctionCallVertex} - to check if a vertex is a function call vertex
86
+ * @see {@link FunctionCallVertex.is} - to check if a vertex is a function call vertex
87
87
  */
88
88
  export interface DataflowGraphVertexFunctionCall extends DataflowGraphVertexBase {
89
89
  readonly tag: VertexType.FunctionCall;
@@ -117,7 +117,7 @@ export interface DataflowGraphVertexFunctionCall extends DataflowGraphVertexBase
117
117
  export type FunctionOriginInformation = BuiltInProcName;
118
118
  /**
119
119
  * Arguments required to construct a vertex which represents the definition of a variable in the {@link DataflowGraph|dataflow graph}.
120
- * @see {@link isVariableDefinitionVertex} - to check if a vertex is a variable definition vertex
120
+ * @see {@link VariableDefinitionVertex.is} - to check if a vertex is a variable definition vertex
121
121
  */
122
122
  export interface DataflowGraphVertexVariableDefinition extends DataflowGraphVertexBase {
123
123
  readonly tag: VertexType.VariableDefinition;
@@ -130,7 +130,7 @@ export interface DataflowGraphVertexVariableDefinition extends DataflowGraphVert
130
130
  }
131
131
  /**
132
132
  * Arguments required to construct a vertex which represents the definition of a function in the {@link DataflowGraph|dataflow graph}.
133
- * @see {@link isFunctionDefinitionVertex} - to check if a vertex is a function definition vertex
133
+ * @see {@link FunctionDefinitionVertex.is} - to check if a vertex is a function definition vertex
134
134
  */
135
135
  export interface DataflowGraphVertexFunctionDefinition extends DataflowGraphVertexBase {
136
136
  readonly tag: VertexType.FunctionDefinition;
@@ -176,24 +176,31 @@ export type DataflowGraphVertexInfo = Required<DataflowGraphVertexArgument>;
176
176
  * A mapping of {@link NodeId}s to {@link DataflowGraphVertexInfo|vertices}.
177
177
  */
178
178
  export type DataflowGraphVertices<Vertex extends DataflowGraphVertexInfo = DataflowGraphVertexInfo> = Map<NodeId, Vertex>;
179
- /**
180
- * Check if the given vertex is a {@link DataflowGraphVertexValue|value vertex}.
181
- */
182
- export declare function isValueVertex(vertex?: DataflowGraphVertexBase): vertex is DataflowGraphVertexValue;
183
- /**
184
- * Check if the given vertex is a {@link DataflowGraphVertexUse|use vertex}.
185
- */
186
- export declare function isUseVertex(vertex?: DataflowGraphVertexBase): vertex is DataflowGraphVertexUse;
187
- /**
188
- * Check if the given vertex is a {@link DataflowGraphVertexFunctionCall|function call vertex}.
189
- */
190
- export declare function isFunctionCallVertex(vertex?: DataflowGraphVertexBase): vertex is DataflowGraphVertexFunctionCall;
191
- /**
192
- * Check if the given vertex is a {@link DataflowGraphVertexVariableDefinition|variable definition vertex}.
193
- */
194
- export declare function isVariableDefinitionVertex(vertex?: DataflowGraphVertexBase): vertex is DataflowGraphVertexVariableDefinition;
195
- /**
196
- * Check if the given vertex is a {@link DataflowGraphVertexFunctionDefinition|function definition vertex}.
197
- */
198
- export declare function isFunctionDefinitionVertex(vertex?: DataflowGraphVertexBase): vertex is DataflowGraphVertexFunctionDefinition;
179
+ /** Helpers for {@link DataflowGraphVertexValue} vertices. */
180
+ export declare const ValueVertex: {
181
+ /** Whether the given vertex is a value vertex. */
182
+ is(this: void, vertex?: DataflowGraphVertexBase): vertex is DataflowGraphVertexValue;
183
+ };
184
+ /** Helpers for {@link DataflowGraphVertexUse} vertices. */
185
+ export declare const UseVertex: {
186
+ /** Whether the given vertex is a use vertex. */
187
+ is(this: void, vertex?: DataflowGraphVertexBase): vertex is DataflowGraphVertexUse;
188
+ };
189
+ /** Helpers for {@link DataflowGraphVertexFunctionCall} vertices. */
190
+ export declare const FunctionCallVertex: {
191
+ /** Whether the given vertex is a function call vertex. */
192
+ is(this: void, vertex?: DataflowGraphVertexBase): vertex is DataflowGraphVertexFunctionCall;
193
+ /** Whether the given vertex is a function call carrying the given origin. */
194
+ hasOrigin(this: void, vertex: DataflowGraphVertexBase | undefined, origin: BuiltInProcName): boolean;
195
+ };
196
+ /** Helpers for {@link DataflowGraphVertexVariableDefinition} vertices. */
197
+ export declare const VariableDefinitionVertex: {
198
+ /** Whether the given vertex is a variable definition vertex. */
199
+ is(this: void, vertex?: DataflowGraphVertexBase): vertex is DataflowGraphVertexVariableDefinition;
200
+ };
201
+ /** Helpers for {@link DataflowGraphVertexFunctionDefinition} vertices. */
202
+ export declare const FunctionDefinitionVertex: {
203
+ /** Whether the given vertex is a function definition vertex. */
204
+ is(this: void, vertex?: DataflowGraphVertexBase): vertex is DataflowGraphVertexFunctionDefinition;
205
+ };
199
206
  export {};
@@ -1,11 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidVertexTypeReverse = exports.ValidVertexTypes = exports.VertexType = void 0;
4
- exports.isValueVertex = isValueVertex;
5
- exports.isUseVertex = isUseVertex;
6
- exports.isFunctionCallVertex = isFunctionCallVertex;
7
- exports.isVariableDefinitionVertex = isVariableDefinitionVertex;
8
- exports.isFunctionDefinitionVertex = isFunctionDefinitionVertex;
3
+ exports.FunctionDefinitionVertex = exports.VariableDefinitionVertex = exports.FunctionCallVertex = exports.UseVertex = exports.ValueVertex = exports.ValidVertexTypeReverse = exports.ValidVertexTypes = exports.VertexType = void 0;
9
4
  var VertexType;
10
5
  (function (VertexType) {
11
6
  VertexType["Value"] = "value";
@@ -16,34 +11,43 @@ var VertexType;
16
11
  })(VertexType || (exports.VertexType = VertexType = {}));
17
12
  exports.ValidVertexTypes = new Set(Object.values(VertexType));
18
13
  exports.ValidVertexTypeReverse = Object.fromEntries(Object.entries(VertexType).map(([k, v]) => [v, k]));
19
- /**
20
- * Check if the given vertex is a {@link DataflowGraphVertexValue|value vertex}.
21
- */
22
- function isValueVertex(vertex) {
23
- return vertex?.tag === VertexType.Value;
24
- }
25
- /**
26
- * Check if the given vertex is a {@link DataflowGraphVertexUse|use vertex}.
27
- */
28
- function isUseVertex(vertex) {
29
- return vertex?.tag === VertexType.Use;
30
- }
31
- /**
32
- * Check if the given vertex is a {@link DataflowGraphVertexFunctionCall|function call vertex}.
33
- */
34
- function isFunctionCallVertex(vertex) {
35
- return vertex?.tag === VertexType.FunctionCall;
36
- }
37
- /**
38
- * Check if the given vertex is a {@link DataflowGraphVertexVariableDefinition|variable definition vertex}.
39
- */
40
- function isVariableDefinitionVertex(vertex) {
41
- return vertex?.tag === VertexType.VariableDefinition;
42
- }
43
- /**
44
- * Check if the given vertex is a {@link DataflowGraphVertexFunctionDefinition|function definition vertex}.
45
- */
46
- function isFunctionDefinitionVertex(vertex) {
47
- return vertex?.tag === VertexType.FunctionDefinition;
48
- }
14
+ /** Helpers for {@link DataflowGraphVertexValue} vertices. */
15
+ exports.ValueVertex = {
16
+ /** Whether the given vertex is a value vertex. */
17
+ is(vertex) {
18
+ return vertex?.tag === VertexType.Value;
19
+ }
20
+ };
21
+ /** Helpers for {@link DataflowGraphVertexUse} vertices. */
22
+ exports.UseVertex = {
23
+ /** Whether the given vertex is a use vertex. */
24
+ is(vertex) {
25
+ return vertex?.tag === VertexType.Use;
26
+ }
27
+ };
28
+ /** Helpers for {@link DataflowGraphVertexFunctionCall} vertices. */
29
+ exports.FunctionCallVertex = {
30
+ /** Whether the given vertex is a function call vertex. */
31
+ is(vertex) {
32
+ return vertex?.tag === VertexType.FunctionCall;
33
+ },
34
+ /** Whether the given vertex is a function call carrying the given origin. */
35
+ hasOrigin(vertex, origin) {
36
+ return exports.FunctionCallVertex.is(vertex) && vertex.origin.includes(origin);
37
+ }
38
+ };
39
+ /** Helpers for {@link DataflowGraphVertexVariableDefinition} vertices. */
40
+ exports.VariableDefinitionVertex = {
41
+ /** Whether the given vertex is a variable definition vertex. */
42
+ is(vertex) {
43
+ return vertex?.tag === VertexType.VariableDefinition;
44
+ }
45
+ };
46
+ /** Helpers for {@link DataflowGraphVertexFunctionDefinition} vertices. */
47
+ exports.FunctionDefinitionVertex = {
48
+ /** Whether the given vertex is a function definition vertex. */
49
+ is(vertex) {
50
+ return vertex?.tag === VertexType.FunctionDefinition;
51
+ }
52
+ };
49
53
  //# sourceMappingURL=vertex.js.map
@@ -18,6 +18,7 @@ import type { ForceArguments } from '../common';
18
18
  */
19
19
  export declare function processAccess<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, config: {
20
20
  treatIndicesAsString: boolean;
21
+ resolveField?: boolean;
21
22
  } & ForceArguments): DataflowInformation;
22
23
  /**
23
24
  * Converts symbol arguments to string arguments within the specified range.
@@ -60,18 +60,21 @@ function processAccess(name, args, rootId, data, config) {
60
60
  }
61
61
  /* we include the read edges to the constant arguments as well so that they are included if necessary */
62
62
  }
63
- /* for $ access on a tracked env variable or a stack env (globalenv()/.GlobalEnv), add Reads edges to the field definition */
64
- if (config.treatIndicesAsString && identifier_1.Identifier.getName(name.content) === '$'
63
+ if (config.resolveField
65
64
  && head !== r_function_call_1.EmptyArgument && head.value !== undefined
66
65
  && args.length >= 2 && args[1] !== r_function_call_1.EmptyArgument) {
67
- const envState = (0, built_in_stack_env_1.resolveNodeToStackEnv)(head.value, data)
66
+ const stackEnvState = (0, built_in_stack_env_1.resolveNodeToStackEnv)(head.value, data);
67
+ const envState = stackEnvState
68
68
  ?? (head.value.type === type_1.RType.Symbol ? (0, built_in_envir_utils_1.resolveSymbolToEnvir)(head.value.content, head.value.info.id, data)?.envDef.envState : undefined);
69
69
  if (envState) {
70
70
  const fieldNode = (0, unpack_argument_1.unpackArg)(args[1]);
71
- const fieldName = fieldNode?.type === type_1.RType.String ? fieldNode.content.str : fieldNode?.lexeme;
71
+ const fieldName = fieldNode?.type === type_1.RType.String ? fieldNode.content.str : (config.treatIndicesAsString ? fieldNode?.lexeme : undefined);
72
72
  const fieldDefs = fieldName ? envState.current.memory.get(fieldName) : undefined;
73
73
  for (const fd of fieldDefs ?? []) {
74
74
  info.graph.addEdge(name.info.id, fd.nodeId, edge_1.EdgeType.Reads);
75
+ if (stackEnvState === undefined && fd.type === identifier_1.ReferenceType.Function) {
76
+ info.graph.addEdge(name.info.id, fd.nodeId, edge_1.EdgeType.Returns);
77
+ }
75
78
  }
76
79
  }
77
80
  }