@eagleoutice/flowr 2.13.3 → 2.13.5

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 (176) hide show
  1. package/README.md +32 -32
  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/cli/repl/core.js +10 -2
  7. package/config.d.ts +4 -1
  8. package/config.js +10 -1
  9. package/control-flow/cfg-dead-code.js +91 -15
  10. package/control-flow/extract-cfg.js +93 -8
  11. package/control-flow/semantic-cfg-guided-visitor.js +2 -0
  12. package/dataflow/environments/built-in-config.d.ts +6 -3
  13. package/dataflow/environments/built-in-eval-name.d.ts +20 -0
  14. package/dataflow/environments/built-in-eval-name.js +25 -0
  15. package/dataflow/environments/built-in-proc-name.d.ts +4 -0
  16. package/dataflow/environments/built-in-proc-name.js +4 -0
  17. package/dataflow/environments/built-in-props.d.ts +175 -0
  18. package/dataflow/environments/built-in-props.js +207 -0
  19. package/dataflow/environments/built-in.d.ts +28 -20
  20. package/dataflow/environments/built-in.js +39 -8
  21. package/dataflow/environments/default-builtin-config.d.ts +1094 -86
  22. package/dataflow/environments/default-builtin-config.js +496 -212
  23. package/dataflow/environments/identifier.d.ts +25 -1
  24. package/dataflow/environments/identifier.js +24 -2
  25. package/dataflow/environments/query-fn-props.d.ts +102 -0
  26. package/dataflow/environments/query-fn-props.js +188 -0
  27. package/dataflow/eval/resolve/alias-tracking.d.ts +2 -0
  28. package/dataflow/eval/resolve/alias-tracking.js +12 -2
  29. package/dataflow/eval/resolve/match-arguments.d.ts +15 -0
  30. package/dataflow/eval/resolve/match-arguments.js +77 -0
  31. package/dataflow/eval/resolve/resolve-numbers.d.ts +202 -0
  32. package/dataflow/eval/resolve/resolve-numbers.js +163 -0
  33. package/dataflow/eval/resolve/resolve-operators.d.ts +60 -0
  34. package/dataflow/eval/resolve/resolve-operators.js +115 -0
  35. package/dataflow/eval/resolve/resolve-strings.d.ts +98 -0
  36. package/dataflow/eval/resolve/resolve-strings.js +116 -0
  37. package/dataflow/eval/resolve/resolve.d.ts +5 -23
  38. package/dataflow/eval/resolve/resolve.js +56 -87
  39. package/dataflow/fn/higher-order-function.js +3 -3
  40. package/dataflow/fn/recursive-function.js +1 -1
  41. package/dataflow/graph/df-helper.js +1 -1
  42. package/dataflow/graph/vertex.d.ts +32 -25
  43. package/dataflow/graph/vertex.js +40 -36
  44. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +1 -0
  45. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +7 -4
  46. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +14 -0
  47. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +28 -29
  48. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +41 -48
  49. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.d.ts +14 -0
  50. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +45 -0
  51. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +7 -1
  52. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +30 -0
  53. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +62 -2
  54. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +63 -16
  55. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +29 -9
  56. package/dataflow/internal/process/functions/call/built-in/built-in-list.d.ts +5 -1
  57. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +35 -0
  58. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +2 -2
  59. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +1 -1
  60. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +2 -0
  61. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +46 -0
  62. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +1 -1
  63. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +3 -1
  64. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +2 -1
  65. package/dataflow/internal/process/functions/call/known-call-handling.js +2 -1
  66. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +24 -0
  67. package/dataflow/internal/process/functions/process-parameter.js +2 -1
  68. package/documentation/data/faq/faqs.js +11 -0
  69. package/documentation/doc-util/doc-types.js +1 -1
  70. package/documentation/wiki-analyzer.js +75 -0
  71. package/documentation/wiki-core.js +65 -16
  72. package/documentation/wiki-interface.js +3 -0
  73. package/linter/linter-rules.d.ts +10 -11
  74. package/linter/rules/absolute-path.js +1 -1
  75. package/linter/rules/deprecated-functions.js +5 -3
  76. package/linter/rules/function-finder-util.d.ts +2 -2
  77. package/linter/rules/function-finder-util.js +11 -4
  78. package/linter/rules/network-functions.d.ts +25 -5
  79. package/linter/rules/network-functions.js +51 -11
  80. package/linter/rules/no-leaked-credentials.js +1 -1
  81. package/linter/rules/problematic-inputs.d.ts +1 -1
  82. package/linter/rules/problematic-inputs.js +7 -1
  83. package/linter/rules/seeded-randomness.d.ts +5 -8
  84. package/linter/rules/seeded-randomness.js +17 -9
  85. package/linter/rules/undefined-symbol.js +1 -1
  86. package/linter/rules/unused-definition.js +15 -10
  87. package/linter/rules/useless-loop.js +1 -1
  88. package/package.json +3 -2
  89. package/project/cache/flowr-analyzer-cache.d.ts +4 -3
  90. package/project/cache/flowr-analyzer-cache.js +32 -13
  91. package/project/cache/flowr-cache.d.ts +39 -12
  92. package/project/cache/flowr-cache.js +5 -3
  93. package/project/context/flowr-analyzer-context.d.ts +8 -1
  94. package/project/context/flowr-analyzer-context.js +11 -1
  95. package/project/context/flowr-analyzer-dependencies-context.d.ts +4 -2
  96. package/project/context/flowr-analyzer-dependencies-context.js +15 -1
  97. package/project/context/flowr-analyzer-files-context.d.ts +8 -4
  98. package/project/context/flowr-analyzer-files-context.js +20 -1
  99. package/project/context/flowr-analyzer-incremental-analysis-context.d.ts +33 -0
  100. package/project/context/flowr-analyzer-incremental-analysis-context.js +63 -0
  101. package/project/context/flowr-analyzer-meta-context.d.ts +3 -1
  102. package/project/context/flowr-analyzer-meta-context.js +14 -0
  103. package/project/context/flowr-file.d.ts +25 -3
  104. package/project/context/flowr-file.js +24 -2
  105. package/project/dependency-version-space.d.ts +37 -0
  106. package/project/dependency-version-space.js +118 -26
  107. package/project/flowr-analyzer.d.ts +6 -0
  108. package/project/flowr-analyzer.js +6 -2
  109. package/project/incremental/incremental-parse/edit-computation.d.ts +7 -0
  110. package/project/incremental/incremental-parse/edit-computation.js +61 -0
  111. package/project/incremental/incremental-parse/incremental-parse.d.ts +12 -0
  112. package/project/incremental/incremental-parse/incremental-parse.js +37 -0
  113. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +1 -1
  114. package/project/plugins/file-plugins/files/flowr-manifest-files.d.ts +57 -0
  115. package/project/plugins/file-plugins/files/flowr-manifest-files.js +121 -0
  116. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +2 -2
  117. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +2 -2
  118. package/project/plugins/file-plugins/files/flowr-sweave-file.d.ts +1 -1
  119. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.d.ts +33 -0
  120. package/project/plugins/file-plugins/flowr-analyzer-manifest-file-plugin.js +53 -0
  121. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +1 -1
  122. package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +3 -3
  123. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.d.ts +27 -0
  124. package/project/plugins/package-version-plugins/flowr-analyzer-meta-manifest-file-plugin.js +47 -0
  125. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +7 -0
  126. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +31 -3
  127. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +10 -4
  128. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +17 -4
  129. package/project/plugins/plugin-registry.d.ts +4 -4
  130. package/project/plugins/plugin-registry.js +7 -4
  131. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +4 -4
  132. package/project/sigdb/reader.d.ts +7 -0
  133. package/project/sigdb/reader.js +12 -0
  134. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +1 -1
  135. package/queries/catalog/call-context-query/identify-link-to-nested-call-relation.js +1 -1
  136. package/queries/catalog/dependencies-query/function-info/derived-functions.d.ts +10 -0
  137. package/queries/catalog/dependencies-query/function-info/derived-functions.js +41 -0
  138. package/queries/catalog/dependencies-query/function-info/read-functions.js +14 -13
  139. package/queries/catalog/dependencies-query/function-info/write-functions.js +28 -36
  140. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-executor.js +33 -3
  141. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.d.ts +31 -0
  142. package/queries/catalog/guess-dep-versions-query/guess-dep-versions-query-format.js +9 -2
  143. package/queries/catalog/input-sources-query/input-source-functions.d.ts +9 -10
  144. package/queries/catalog/input-sources-query/input-source-functions.js +23 -394
  145. package/queries/catalog/input-sources-query/input-sources-query-executor.js +11 -6
  146. package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +7 -0
  147. package/queries/catalog/input-sources-query/input-sources-query-format.js +28 -10
  148. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +14 -1
  149. package/queries/catalog/input-sources-query/simple-input-classifier.js +24 -0
  150. package/queries/catalog/signature-query/signature-query-executor.d.ts +2 -1
  151. package/queries/catalog/signature-query/signature-query-executor.js +79 -3
  152. package/queries/catalog/signature-query/signature-query-format.d.ts +27 -0
  153. package/queries/catalog/signature-query/signature-query-render.js +21 -3
  154. package/r-bridge/data/data.d.ts +2 -2
  155. package/r-bridge/data/data.js +2 -2
  156. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +6 -2
  157. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +21 -2
  158. package/r-bridge/parser.d.ts +11 -1
  159. package/r-bridge/parser.js +7 -4
  160. package/r-bridge/shell-executor.d.ts +1 -0
  161. package/r-bridge/shell-executor.js +1 -0
  162. package/r-bridge/shell.d.ts +1 -0
  163. package/r-bridge/shell.js +1 -0
  164. package/reconstruct/inline/source-inline-map.js +1 -1
  165. package/search/flowr-search-filters.d.ts +1 -6
  166. package/search/flowr-search-filters.js +1 -8
  167. package/search/search-executor/search-enrichers.d.ts +2 -0
  168. package/search/search-executor/search-enrichers.js +29 -12
  169. package/util/mermaid/dfg.js +1 -1
  170. package/util/version.js +1 -1
  171. package/project/plugins/file-plugins/files/flowr-rproject-file.d.ts +0 -31
  172. package/project/plugins/file-plugins/files/flowr-rproject-file.js +0 -66
  173. package/project/plugins/file-plugins/flowr-analyzer-rproject-file-plugin.d.ts +0 -22
  174. package/project/plugins/file-plugins/flowr-analyzer-rproject-file-plugin.js +0 -36
  175. package/project/plugins/package-version-plugins/flowr-analyzer-meta-rproject-file-plugin.d.ts +0 -13
  176. package/project/plugins/package-version-plugins/flowr-analyzer-meta-rproject-file-plugin.js +0 -32
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PasteLikeCalls = exports.StringFns = void 0;
4
+ exports.foldStringCall = foldStringCall;
5
+ exports.resolveAsStringFn = resolveAsStringFn;
6
+ const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
7
+ const identifier_1 = require("../../environments/identifier");
8
+ const r_value_1 = require("../values/r-value");
9
+ const string_constants_1 = require("../values/string/string-constants");
10
+ const interval_constants_1 = require("../values/intervals/interval-constants");
11
+ const alias_tracking_1 = require("./alias-tracking");
12
+ const match_arguments_1 = require("./match-arguments");
13
+ /** everything after the last separator, with trailing separators dropped first (`a/b/` is `b`, `/` is the empty string) */
14
+ function basename(path) {
15
+ const trimmed = path.replace(/\/+$/, '');
16
+ return trimmed.slice(trimmed.lastIndexOf('/') + 1);
17
+ }
18
+ /** everything before the last separator, `.` if there is none and `/` if only the root remains */
19
+ function dirname(path) {
20
+ if (path === '') {
21
+ return '';
22
+ }
23
+ const trimmed = path.length > 1 ? path.replace(/(?<=.)\/+$/, '') : path;
24
+ const cut = trimmed.lastIndexOf('/');
25
+ if (cut < 0) {
26
+ return '.';
27
+ }
28
+ const head = trimmed.slice(0, cut).replace(/\/+$/, '');
29
+ return head === '' ? '/' : head;
30
+ }
31
+ /**
32
+ * Every string built-in the value solver folds, the joining ones included: `paste` is an entry like `toupper`
33
+ * is, and both are reached through {@link resolveAsStringFn}. Teaching flowR one more is a line here plus the
34
+ * matching `evalHandler` in the built-in configuration -- a test checks that the two agree.
35
+ *
36
+ * An entry with a `...` parameter joins what it collected, which is why its separator is just another
37
+ * parameter with a default. The rest take a fixed number of arguments under the names R documents.
38
+ */
39
+ exports.StringFns = {
40
+ /* the joining calls, which differ only in their separator and what the argument overriding it is called */
41
+ paste: { params: ['...', 'sep'], defaults: { sep: ' ' }, ignored: ['collapse'], fold: (parts, sep) => parts.join(sep) },
42
+ paste0: { params: ['...', 'sep'], defaults: { sep: '' }, ignored: ['collapse'], fold: (parts, sep) => parts.join(sep) },
43
+ 'file.path': { params: ['...', 'fsep'], defaults: { fsep: '/' }, fold: (parts, fsep) => parts.join(fsep) },
44
+ /* the path splits, which only ever treat `/` as a separator, so a Windows path keeps its non-`\` parts */
45
+ basename: { params: ['path'], fold: basename },
46
+ dirname: { params: ['path'], fold: dirname },
47
+ /* whole-string transformations */
48
+ toupper: { params: ['x'], fold: (s) => s.toUpperCase() },
49
+ tolower: { params: ['x'], fold: (s) => s.toLowerCase() },
50
+ trimws: { params: ['x'], fold: (s) => s.trim() },
51
+ /** R counts characters, so we count code points rather than UTF-16 units */
52
+ nchar: { params: ['x'], fold: (s) => [...s].length }
53
+ };
54
+ /** the entries that join what they are handed, the ones a name at construction time may be built from */
55
+ exports.PasteLikeCalls = new Set(Object.entries(exports.StringFns).filter(([, fn]) => fn.params.includes('...')).map(([name]) => name));
56
+ /**
57
+ * Folds a named {@link StringFns} call to its result, resolving each argument with `resolveArg`. `undefined`
58
+ * when the name is not one of them, an argument does not resolve, or the call does not match what the entry
59
+ * declares. Shared by the value solver ({@link resolveAsStringFn}) and construction-time name resolution.
60
+ */
61
+ function foldStringCall(node, resolveArg) {
62
+ const known = exports.StringFns[identifier_1.Identifier.getName(node.functionName.content)];
63
+ if (known === undefined) {
64
+ return undefined;
65
+ }
66
+ const matched = (0, match_arguments_1.matchCallArguments)(node, known.params, known.ignored);
67
+ if (matched === undefined) {
68
+ return undefined;
69
+ }
70
+ /* a fold that reads the characters cannot run on source text with an escape still in it (`\t` is two chars
71
+ * there); joining does not read them, so the entries collecting a `...` are exempt */
72
+ const literal = !known.params.includes('...');
73
+ const args = [];
74
+ for (const [at, slot] of matched.entries()) {
75
+ if (Array.isArray(slot)) {
76
+ const parts = slot.map(resolveArg);
77
+ if (parts.some(p => p === undefined)) {
78
+ return undefined;
79
+ }
80
+ args.push(parts);
81
+ continue;
82
+ }
83
+ if (slot === undefined) {
84
+ const fallback = known.defaults?.[known.params[at]];
85
+ if (fallback === undefined) {
86
+ break; // the parameters R gives a default are the trailing ones, so the fold sees a shorter prefix
87
+ }
88
+ args.push(fallback);
89
+ continue;
90
+ }
91
+ // the argument *was* given, so failing to resolve it means we do not know the result, defaults do not apply
92
+ const value = resolveArg(slot);
93
+ if (value === undefined || (literal && value.includes('\\'))) {
94
+ return undefined;
95
+ }
96
+ args.push(value);
97
+ }
98
+ return args.length > 0 ? known.fold(...args) : undefined;
99
+ }
100
+ /**
101
+ * Resolves any call of a {@link StringFns} entry to a {@link Value}, with its arguments in any order R accepts:
102
+ * a join like `paste0("cfg_", k)` when every part resolves to a single string constant, and a transformation
103
+ * like `basename(p)` when its argument does. Anything that does not resolve stays `Top`.
104
+ */
105
+ function resolveAsStringFn(args) {
106
+ const node = args.node;
107
+ if (node.type !== type_1.RType.FunctionCall || !node.named) {
108
+ return r_value_1.Top;
109
+ }
110
+ const folded = foldStringCall(node, arg => (0, alias_tracking_1.resolveIdToSingleString)(arg.info.id, args));
111
+ if (folded === undefined) {
112
+ return r_value_1.Top;
113
+ }
114
+ return typeof folded === 'number' ? (0, interval_constants_1.intervalFrom)(folded, folded) : (0, string_constants_1.stringFrom)(folded);
115
+ }
116
+ //# sourceMappingURL=resolve-strings.js.map
@@ -4,11 +4,11 @@ import { type Lift, Top, type Value, type ValueNumber, type ValueVector } from '
4
4
  * Helper function used by {@link resolveIdToValue}, please use that instead, if
5
5
  * you want to resolve the value of an identifier / node
6
6
  *
7
- * This function converts an RNode to its Value, but also recursively resolves
8
- * aliases and vectors (in case of node vector).
7
+ * This function converts an RNode to its Value, either directly for a constant or by handing the node
8
+ * to the {@link BuiltInEvalHandler} its built-in declares, which may resolve further nodes recursively.
9
9
  * @returns resolved value or top/bottom
10
10
  */
11
- export declare function resolveNode({ resolve, node, ctx, blocked, environment, graph, idMap }: BuiltInEvalHandlerArgs): Value;
11
+ export declare function resolveNode(args: BuiltInEvalHandlerArgs): Value;
12
12
  /**
13
13
  * Helper function used by {@link resolveIdToValue}, please use that instead, if
14
14
  * you want to resolve the value of an identifier / node
@@ -17,7 +17,7 @@ export declare function resolveNode({ resolve, node, ctx, blocked, environment,
17
17
  * by recursively resolving the values of the arguments by calling {@link resolveIdToValue}
18
18
  * @returns ValueVector or Top
19
19
  */
20
- export declare function resolveAsVector({ resolve, environment, node, graph, idMap, ctx, blocked }: BuiltInEvalHandlerArgs): ValueVector | typeof Top;
20
+ export declare function resolveAsVector(args: BuiltInEvalHandlerArgs): ValueVector | typeof Top;
21
21
  /**
22
22
  * Helper function used by {@link resolveIdToValue}, please use that instead, if
23
23
  * you want to resolve the value of an identifier / node
@@ -26,22 +26,4 @@ export declare function resolveAsVector({ resolve, environment, node, graph, idM
26
26
  * by recursively resolving the values of the arguments by calling {@link resolveIdToValue}
27
27
  * @returns ValueVector of ValueNumbers or Top
28
28
  */
29
- export declare function resolveAsSeq({ node: operator, environment, resolve, ctx, graph, idMap, blocked }: BuiltInEvalHandlerArgs): ValueVector<Lift<ValueNumber[]>> | typeof Top;
30
- /**
31
- * Helper function used by {@link resolveIdToValue}, please use that instead, if
32
- * you want to resolve the value of an identifier / node
33
- *
34
- * This function resolves a unary plus operator `+` to a {@link ValueNumber} or {@link ValueVector} of ValueNumbers
35
- * by recursively resolving the values of the arguments by calling {@link resolveIdToValue}
36
- * @returns ValueNumber, ValueVector of ValueNumbers, or Top
37
- */
38
- export declare function resolveAsPlus({ node: operator, environment, resolve, ctx, graph, idMap, blocked }: BuiltInEvalHandlerArgs): ValueNumber | ValueVector<Lift<ValueNumber[]>> | typeof Top;
39
- /**
40
- * Helper function used by {@link resolveIdToValue}, please use that instead, if
41
- * you want to resolve the value of an identifier / node
42
- *
43
- * This function resolves a unary minus operator `-` to a {@link ValueNumber} or {@link ValueVector} of ValueNumbers
44
- * by recursively resolving the values of the arguments by calling {@link resolveIdToValue}
45
- * @returns ValueNumber, ValueVector of ValueNumbers, or Top
46
- */
47
- export declare function resolveAsMinus({ node: operator, environment, resolve, ctx, graph, idMap, blocked }: BuiltInEvalHandlerArgs): ValueNumber | ValueVector<Lift<ValueNumber[]>> | typeof Top;
29
+ export declare function resolveAsSeq(args: BuiltInEvalHandlerArgs): ValueVector<Lift<ValueNumber[]>> | typeof Top;
@@ -3,12 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveNode = resolveNode;
4
4
  exports.resolveAsVector = resolveAsVector;
5
5
  exports.resolveAsSeq = resolveAsSeq;
6
- exports.resolveAsPlus = resolveAsPlus;
7
- exports.resolveAsMinus = resolveAsMinus;
8
6
  const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
9
7
  const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
10
8
  const r_value_1 = require("../../../util/r-value");
11
- const built_in_1 = require("../../environments/built-in");
12
9
  const interval_constants_1 = require("../values/intervals/interval-constants");
13
10
  const logical_constants_1 = require("../values/logical/logical-constants");
14
11
  const r_value_2 = require("../values/r-value");
@@ -17,17 +14,59 @@ const vector_constants_1 = require("../values/vectors/vector-constants");
17
14
  const alias_tracking_1 = require("./alias-tracking");
18
15
  const scalar_constants_1 = require("../values/scalar/scalar-constants");
19
16
  const identifier_1 = require("../../environments/identifier");
20
- const node_id_1 = require("../../../r-bridge/lang-4.x/ast/model/processing/node-id");
17
+ const resolve_by_name_1 = require("../../environments/resolve-by-name");
21
18
  const df_helper_1 = require("../../graph/df-helper");
19
+ const node_id_1 = require("../../../r-bridge/lang-4.x/ast/model/processing/node-id");
20
+ /**
21
+ * The {@link BuiltInEvalHandler} the given name resolves to in the current environment, just like the
22
+ * {@link BuiltInIdentifierDefinition#processor} a call resolves to; `undefined` if the name is shadowed
23
+ * by a user definition or its built-in declares no handler.
24
+ */
25
+ function evalHandlerOf(name, environment, ctx) {
26
+ const defs = environment ?
27
+ (0, resolve_by_name_1.resolveByName)(name, environment, identifier_1.ReferenceType.BuiltInFunction)
28
+ : ctx.env.builtInEnvironment.memory.get(identifier_1.Identifier.getName(name));
29
+ const def = defs?.length === 1 ? defs[0] : undefined;
30
+ return def?.type === identifier_1.ReferenceType.BuiltInFunction ? def.evalHandler : undefined;
31
+ }
32
+ /** the node types that may fold through a built-in: calls, operators, and the `(`/`{` groupings */
33
+ const EvalNodeTypes = [type_1.RType.FunctionCall, type_1.RType.BinaryOp, type_1.RType.UnaryOp, type_1.RType.ExpressionList];
34
+ /**
35
+ * The name of the built-in the given node folds through, `undefined` if it is no call to one or if it may just
36
+ * as well resolve to something else (a user redefinition, a conditional one, ...), which must not be folded.
37
+ */
38
+ function evalNameOf({ node, graph }) {
39
+ if (graph === undefined || !EvalNodeTypes.includes(node.type)) {
40
+ return undefined;
41
+ }
42
+ let name;
43
+ for (const origin of df_helper_1.Dataflow.origin(graph, node.info.id) ?? []) {
44
+ if (origin.type === 2 /* OriginType.FunctionCallOrigin */ || origin.type === 1 /* OriginType.WriteVariableOrigin */) {
45
+ /* the call may go to a definition of the program instead, so we know too little to fold it */
46
+ return undefined;
47
+ }
48
+ else if (origin.type !== 3 /* OriginType.BuiltInFunctionOrigin */) {
49
+ continue;
50
+ }
51
+ /* an alias like `f <- c` keeps the built-in it stands for in `proc`, a direct call names itself */
52
+ const named = node_id_1.NodeId.isBuiltIn(origin.proc) ? node_id_1.NodeId.fromBuiltIn(origin.proc) : origin.fn.name;
53
+ if (name !== undefined && identifier_1.Identifier.getName(name) !== identifier_1.Identifier.getName(named)) {
54
+ return undefined;
55
+ }
56
+ name = named;
57
+ }
58
+ return name;
59
+ }
22
60
  /**
23
61
  * Helper function used by {@link resolveIdToValue}, please use that instead, if
24
62
  * you want to resolve the value of an identifier / node
25
63
  *
26
- * This function converts an RNode to its Value, but also recursively resolves
27
- * aliases and vectors (in case of node vector).
64
+ * This function converts an RNode to its Value, either directly for a constant or by handing the node
65
+ * to the {@link BuiltInEvalHandler} its built-in declares, which may resolve further nodes recursively.
28
66
  * @returns resolved value or top/bottom
29
67
  */
30
- function resolveNode({ resolve, node, ctx, blocked, environment, graph, idMap }) {
68
+ function resolveNode(args) {
69
+ const { node, environment, ctx } = args;
31
70
  const nt = node.type;
32
71
  if (nt === type_1.RType.String) {
33
72
  return (0, string_constants_1.stringFrom)(node.content.str);
@@ -41,30 +80,9 @@ function resolveNode({ resolve, node, ctx, blocked, environment, graph, idMap })
41
80
  else if (nt === type_1.RType.FunctionDefinition) {
42
81
  return { type: 'function-definition' };
43
82
  }
44
- else if ((nt === type_1.RType.FunctionCall || nt === type_1.RType.BinaryOp || nt === type_1.RType.UnaryOp) && graph) {
45
- const origin = df_helper_1.Dataflow.origin(graph, node.info.id)?.[0];
46
- if (origin === undefined || origin.type !== 3 /* OriginType.BuiltInFunctionOrigin */) {
47
- return r_value_2.Top;
48
- }
49
- let builtInName;
50
- if (node_id_1.NodeId.isBuiltIn(origin.proc)) {
51
- builtInName = origin.proc;
52
- }
53
- else if (nt === type_1.RType.FunctionCall && node.named) {
54
- builtInName = node_id_1.NodeId.toBuiltIn(identifier_1.Identifier.getName(node.functionName.content));
55
- }
56
- else if (nt === type_1.RType.BinaryOp || nt === type_1.RType.UnaryOp) {
57
- builtInName = node_id_1.NodeId.toBuiltIn(node.operator);
58
- }
59
- else {
60
- return r_value_2.Top;
61
- }
62
- if (Object.hasOwn(built_in_1.BuiltInEvalHandlerMapper, builtInName)) {
63
- const handler = built_in_1.BuiltInEvalHandlerMapper[builtInName];
64
- return handler({ resolve, node, ctx, blocked, environment, graph, idMap });
65
- }
66
- }
67
- return r_value_2.Top;
83
+ const name = evalNameOf(args);
84
+ const handler = name === undefined ? undefined : evalHandlerOf(name, environment, ctx);
85
+ return handler?.(args) ?? r_value_2.Top;
68
86
  }
69
87
  /**
70
88
  * Helper function used by {@link resolveIdToValue}, please use that instead, if
@@ -74,13 +92,12 @@ function resolveNode({ resolve, node, ctx, blocked, environment, graph, idMap })
74
92
  * by recursively resolving the values of the arguments by calling {@link resolveIdToValue}
75
93
  * @returns ValueVector or Top
76
94
  */
77
- function resolveAsVector({ resolve, environment, node, graph, idMap, ctx, blocked }) {
95
+ function resolveAsVector(args) {
96
+ const node = args.node;
78
97
  if (node.type !== type_1.RType.FunctionCall) {
79
98
  return r_value_2.Top;
80
99
  }
81
- const resolveInfo = { environment, graph, idMap, full: true, resolve, ctx, blocked };
82
- const values = node.arguments.map(arg => arg !== r_function_call_1.EmptyArgument ? (0, alias_tracking_1.resolveIdToValue)(arg.value, resolveInfo) : r_value_2.Top);
83
- return (0, vector_constants_1.vectorFrom)((0, vector_constants_1.flattenVectorElements)(values));
100
+ return (0, vector_constants_1.vectorFrom)((0, vector_constants_1.flattenVectorElements)(node.arguments.map(arg => arg !== r_function_call_1.EmptyArgument ? (0, alias_tracking_1.resolveIdToValue)(arg.value, args) : r_value_2.Top)));
84
101
  }
85
102
  /**
86
103
  * Helper function used by {@link resolveIdToValue}, please use that instead, if
@@ -90,66 +107,18 @@ function resolveAsVector({ resolve, environment, node, graph, idMap, ctx, blocke
90
107
  * by recursively resolving the values of the arguments by calling {@link resolveIdToValue}
91
108
  * @returns ValueVector of ValueNumbers or Top
92
109
  */
93
- function resolveAsSeq({ node: operator, environment, resolve, ctx, graph, idMap, blocked }) {
110
+ function resolveAsSeq(args) {
111
+ const operator = args.node;
94
112
  if (operator.type !== type_1.RType.BinaryOp) {
95
113
  return r_value_2.Top;
96
114
  }
97
- const resolveInfo = { environment, graph, idMap, full: true, resolve, ctx, blocked };
98
- const leftArg = (0, alias_tracking_1.resolveIdToValue)(operator.lhs, resolveInfo);
99
- const rightArg = (0, alias_tracking_1.resolveIdToValue)(operator.rhs, resolveInfo);
100
- const leftValue = (0, r_value_1.unliftRValue)(leftArg);
101
- const rightValue = (0, r_value_1.unliftRValue)(rightArg);
115
+ const leftValue = (0, r_value_1.unliftRValue)((0, alias_tracking_1.resolveIdToValue)(operator.lhs, args));
116
+ const rightValue = (0, r_value_1.unliftRValue)((0, alias_tracking_1.resolveIdToValue)(operator.rhs, args));
102
117
  if ((0, r_value_1.isRNumberValue)(leftValue) && (0, r_value_1.isRNumberValue)(rightValue)) {
103
118
  return (0, vector_constants_1.vectorFrom)(createNumberSequence(leftValue, rightValue).map(scalar_constants_1.liftScalar));
104
119
  }
105
120
  return r_value_2.Top;
106
121
  }
107
- /**
108
- * Helper function used by {@link resolveIdToValue}, please use that instead, if
109
- * you want to resolve the value of an identifier / node
110
- *
111
- * This function resolves a unary plus operator `+` to a {@link ValueNumber} or {@link ValueVector} of ValueNumbers
112
- * by recursively resolving the values of the arguments by calling {@link resolveIdToValue}
113
- * @returns ValueNumber, ValueVector of ValueNumbers, or Top
114
- */
115
- function resolveAsPlus({ node: operator, environment, resolve, ctx, graph, idMap, blocked }) {
116
- if (operator.type !== type_1.RType.UnaryOp) {
117
- return r_value_2.Top;
118
- }
119
- const resolveInfo = { environment, graph, idMap, full: true, resolve, ctx, blocked };
120
- const arg = (0, alias_tracking_1.resolveIdToValue)(operator.operand, resolveInfo);
121
- const argValue = (0, r_value_1.unliftRValue)(arg);
122
- if ((0, r_value_1.isRNumberValue)(argValue)) {
123
- return (0, scalar_constants_1.liftScalar)(argValue);
124
- }
125
- else if (Array.isArray(argValue) && argValue.every(r_value_1.isRNumberValue)) {
126
- return (0, vector_constants_1.vectorFrom)(argValue.map(scalar_constants_1.liftScalar));
127
- }
128
- return r_value_2.Top;
129
- }
130
- /**
131
- * Helper function used by {@link resolveIdToValue}, please use that instead, if
132
- * you want to resolve the value of an identifier / node
133
- *
134
- * This function resolves a unary minus operator `-` to a {@link ValueNumber} or {@link ValueVector} of ValueNumbers
135
- * by recursively resolving the values of the arguments by calling {@link resolveIdToValue}
136
- * @returns ValueNumber, ValueVector of ValueNumbers, or Top
137
- */
138
- function resolveAsMinus({ node: operator, environment, resolve, ctx, graph, idMap, blocked }) {
139
- if (operator.type !== type_1.RType.UnaryOp) {
140
- return r_value_2.Top;
141
- }
142
- const resolveInfo = { environment, graph, idMap, full: true, resolve, ctx, blocked };
143
- const arg = (0, alias_tracking_1.resolveIdToValue)(operator.operand, resolveInfo);
144
- const argValue = (0, r_value_1.unliftRValue)(arg);
145
- if ((0, r_value_1.isRNumberValue)(argValue)) {
146
- return (0, scalar_constants_1.liftScalar)({ ...argValue, num: -argValue.num });
147
- }
148
- else if (Array.isArray(argValue) && argValue.every(r_value_1.isRNumberValue)) {
149
- return (0, vector_constants_1.vectorFrom)(argValue.map(element => (0, scalar_constants_1.liftScalar)({ ...element, num: -element.num })));
150
- }
151
- return r_value_2.Top;
152
- }
153
122
  function createNumberSequence(start, end) {
154
123
  const sequence = [];
155
124
  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
  }