@eagleoutice/flowr 2.8.15 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/README.md +25 -26
  2. package/abstract-interpretation/data-frame/mappers/access-mapper.d.ts +4 -3
  3. package/abstract-interpretation/data-frame/mappers/access-mapper.js +4 -3
  4. package/abstract-interpretation/data-frame/mappers/arguments.d.ts +2 -1
  5. package/abstract-interpretation/data-frame/mappers/arguments.js +2 -1
  6. package/abstract-interpretation/data-frame/mappers/function-mapper.d.ts +4 -3
  7. package/abstract-interpretation/data-frame/mappers/function-mapper.js +13 -10
  8. package/abstract-interpretation/data-frame/mappers/replacement-mapper.js +7 -6
  9. package/abstract-interpretation/data-frame/resolve-args.js +2 -1
  10. package/benchmark/slicer.d.ts +0 -16
  11. package/benchmark/slicer.js +0 -47
  12. package/benchmark/stats/print.js +0 -6
  13. package/benchmark/stats/stats.d.ts +0 -3
  14. package/benchmark/summarizer/second-phase/process.js +0 -6
  15. package/cli/benchmark-app.d.ts +0 -1
  16. package/cli/benchmark-app.js +0 -1
  17. package/cli/benchmark-helper-app.d.ts +0 -1
  18. package/cli/benchmark-helper-app.js +1 -5
  19. package/cli/common/options.d.ts +0 -10
  20. package/cli/common/options.js +0 -2
  21. package/cli/common/scripts-info.d.ts +0 -10
  22. package/cli/repl/server/connection.js +1 -1
  23. package/config.d.ts +0 -15
  24. package/config.js +0 -21
  25. package/control-flow/cfg-dead-code.js +0 -3
  26. package/control-flow/extract-cfg.js +4 -0
  27. package/control-flow/semantic-cfg-guided-visitor.d.ts +7 -0
  28. package/control-flow/semantic-cfg-guided-visitor.js +11 -4
  29. package/dataflow/cluster.js +2 -2
  30. package/dataflow/environments/built-in-config.d.ts +1 -0
  31. package/dataflow/environments/built-in.d.ts +9 -3
  32. package/dataflow/environments/built-in.js +15 -7
  33. package/dataflow/environments/default-builtin-config.d.ts +10 -1
  34. package/dataflow/environments/default-builtin-config.js +6 -4
  35. package/dataflow/environments/define.d.ts +4 -11
  36. package/dataflow/environments/define.js +16 -96
  37. package/dataflow/environments/diff.js +3 -2
  38. package/dataflow/environments/environment.d.ts +17 -6
  39. package/dataflow/environments/environment.js +69 -18
  40. package/dataflow/environments/identifier.d.ts +92 -6
  41. package/dataflow/environments/identifier.js +159 -1
  42. package/dataflow/environments/resolve-by-name.d.ts +4 -4
  43. package/dataflow/environments/resolve-by-name.js +24 -8
  44. package/dataflow/eval/resolve/resolve.d.ts +10 -6
  45. package/dataflow/eval/resolve/resolve.js +12 -7
  46. package/dataflow/extractor.js +6 -3
  47. package/dataflow/fn/higher-order-function.js +4 -4
  48. package/dataflow/graph/call-graph.d.ts +1 -1
  49. package/dataflow/graph/call-graph.js +10 -8
  50. package/dataflow/graph/diff-dataflow-graph.js +6 -4
  51. package/dataflow/graph/edge.d.ts +48 -31
  52. package/dataflow/graph/edge.js +66 -60
  53. package/dataflow/graph/graph.d.ts +7 -7
  54. package/dataflow/graph/quads.js +1 -1
  55. package/dataflow/graph/resolve-graph.js +1 -1
  56. package/dataflow/graph/unknown-replacement.d.ts +2 -1
  57. package/dataflow/graph/vertex.d.ts +2 -103
  58. package/dataflow/graph/vertex.js +0 -44
  59. package/dataflow/internal/linker.d.ts +2 -2
  60. package/dataflow/internal/linker.js +26 -18
  61. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +3 -65
  62. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +4 -6
  63. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +12 -46
  64. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +2 -1
  65. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +4 -4
  66. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +2 -2
  67. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +8 -5
  68. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +4 -4
  69. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +2 -2
  70. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +6 -2
  71. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +1 -69
  72. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +1 -1
  73. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +1 -1
  74. package/dataflow/internal/process/functions/call/built-in/built-in-recall.d.ts +11 -0
  75. package/dataflow/internal/process/functions/call/built-in/built-in-recall.js +46 -0
  76. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +3 -2
  77. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +0 -2
  78. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +11 -72
  79. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +1 -2
  80. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +2 -1
  81. package/dataflow/internal/process/functions/call/built-in/built-in-stop-if-not.js +4 -3
  82. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +3 -2
  83. package/dataflow/internal/process/functions/call/built-in/built-in-vector.js +1 -60
  84. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +3 -3
  85. package/dataflow/internal/process/functions/call/common.d.ts +3 -1
  86. package/dataflow/internal/process/functions/call/common.js +4 -16
  87. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +6 -2
  88. package/dataflow/internal/process/functions/call/known-call-handling.js +2 -3
  89. package/dataflow/internal/process/functions/call/unnamed-call-handling.d.ts +1 -1
  90. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +1 -1
  91. package/dataflow/internal/process/functions/process-parameter.js +1 -1
  92. package/dataflow/internal/process/process-named-call.d.ts +2 -1
  93. package/dataflow/internal/process/process-named-call.js +0 -1
  94. package/dataflow/internal/process/process-symbol.d.ts +3 -1
  95. package/dataflow/internal/process/process-symbol.js +8 -5
  96. package/dataflow/origin/dfg-get-origin.d.ts +2 -2
  97. package/dataflow/origin/dfg-get-origin.js +4 -4
  98. package/dataflow/origin/dfg-get-symbol-refs.js +2 -2
  99. package/documentation/data/interface/doc-writing-code.d.ts +6 -0
  100. package/documentation/data/interface/doc-writing-code.js +176 -0
  101. package/documentation/doc-util/doc-types.d.ts +3 -1
  102. package/documentation/doc-util/doc-types.js +4 -2
  103. package/documentation/wiki-absint.js +2 -1
  104. package/documentation/wiki-analyzer.js +17 -2
  105. package/documentation/wiki-cfg.js +2 -2
  106. package/documentation/wiki-dataflow-graph.js +9 -8
  107. package/documentation/wiki-interface.js +8 -164
  108. package/documentation/wiki-mk/doc-context.d.ts +12 -1
  109. package/documentation/wiki-mk/doc-context.js +21 -4
  110. package/documentation/wiki-normalized-ast.js +5 -0
  111. package/linter/linter-rules.d.ts +3 -3
  112. package/linter/rules/absolute-path.js +23 -23
  113. package/linter/rules/dataframe-access-validation.js +2 -1
  114. package/linter/rules/deprecated-functions.d.ts +1 -1
  115. package/linter/rules/deprecated-functions.js +1 -1
  116. package/linter/rules/function-finder-util.d.ts +2 -2
  117. package/linter/rules/network-functions.d.ts +1 -1
  118. package/linter/rules/seeded-randomness.d.ts +2 -2
  119. package/linter/rules/seeded-randomness.js +5 -4
  120. package/linter/rules/unused-definition.js +4 -4
  121. package/package.json +5 -5
  122. package/project/context/flowr-analyzer-context.d.ts +17 -1
  123. package/project/context/flowr-analyzer-context.js +17 -1
  124. package/project/context/flowr-analyzer-meta-context.d.ts +51 -0
  125. package/project/context/flowr-analyzer-meta-context.js +47 -0
  126. package/project/flowr-analyzer.d.ts +17 -1
  127. package/project/flowr-analyzer.js +18 -0
  128. package/project/plugins/file-plugins/files/flowr-description-file.d.ts +15 -0
  129. package/project/plugins/file-plugins/files/flowr-description-file.js +26 -0
  130. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +17 -3
  131. package/project/plugins/file-plugins/files/flowr-namespace-file.js +292 -10
  132. package/project/plugins/file-plugins/flowr-analyzer-namespace-files-plugin.d.ts +1 -1
  133. package/project/plugins/file-plugins/flowr-analyzer-namespace-files-plugin.js +2 -2
  134. package/project/plugins/flowr-analyzer-plugin-defaults.js +2 -0
  135. package/project/plugins/loading-order-plugins/flowr-analyzer-loading-order-description-file-plugin.js +1 -1
  136. package/project/plugins/package-version-plugins/flowr-analyzer-meta-description-file-plugin.d.ts +12 -0
  137. package/project/plugins/package-version-plugins/flowr-analyzer-meta-description-file-plugin.js +42 -0
  138. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.d.ts +1 -1
  139. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-description-file-plugin.js +2 -2
  140. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.d.ts +1 -1
  141. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.js +2 -2
  142. package/project/plugins/plugin-registry.d.ts +2 -1
  143. package/project/plugins/plugin-registry.js +2 -0
  144. package/queries/catalog/call-context-query/call-context-query-executor.js +6 -4
  145. package/queries/catalog/call-context-query/call-context-query-format.d.ts +2 -1
  146. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +3 -3
  147. package/queries/catalog/dependencies-query/dependencies-query-format.js +5 -3
  148. package/queries/catalog/does-call-query/does-call-query-executor.js +2 -1
  149. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-executor.js +2 -2
  150. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +1 -1
  151. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-executor.js +1 -1
  152. package/r-bridge/data/data.d.ts +8 -3
  153. package/r-bridge/data/data.js +9 -3
  154. package/r-bridge/lang-4.x/ast/model/model.d.ts +0 -11
  155. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +2 -1
  156. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +2 -1
  157. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +7 -3
  158. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +2 -1
  159. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-argument.js +0 -1
  160. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-call.js +0 -1
  161. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-binary.js +0 -1
  162. package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-number.js +0 -1
  163. package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-symbol.d.ts +1 -2
  164. package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-symbol.js +12 -13
  165. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +4 -11
  166. package/reconstruct/reconstruct.js +6 -5
  167. package/search/flowr-search-filters.js +2 -1
  168. package/search/search-executor/search-enrichers.d.ts +1 -2
  169. package/search/search-executor/search-enrichers.js +2 -1
  170. package/slicing/static/slice-call.js +5 -5
  171. package/slicing/static/static-slicer.js +2 -2
  172. package/statistics/features/common-syntax-probability.js +3 -2
  173. package/statistics/features/supported/defined-functions/defined-functions.js +3 -3
  174. package/statistics/features/supported/used-functions/used-functions.js +3 -2
  175. package/util/mermaid/dfg.js +3 -3
  176. package/util/simple-df/dfg-ascii.js +5 -5
  177. package/util/version.js +1 -1
  178. package/util/containers.d.ts +0 -66
  179. package/util/containers.js +0 -143
@@ -131,7 +131,7 @@ function mermaidNodeBrackets(tag) {
131
131
  * Prints an identifier definition in a human-readable format.
132
132
  */
133
133
  function printIdentifier(id) {
134
- return `**${id.name}** (id: ${id.nodeId}, type: ${identifier_1.ReferenceTypeReverseMapping.get(id.type)},${id.cds ? ' cds: {' + id.cds.map(c => c.id + (c.when ? '+' : '-')).join(',') + '},' : ''} def. @${id.definedAt})`;
134
+ return `**${id.name ? identifier_1.Identifier.toString(id.name) : 'undefined'}** (id: ${id.nodeId}, type: ${identifier_1.ReferenceTypeReverseMapping.get(id.type)},${id.cds ? ' cds: {' + id.cds.map(c => c.id + (c.when ? '+' : '-')).join(',') + '},' : ''} def. @${id.definedAt})`;
135
135
  }
136
136
  function printEnvironmentToLines(env) {
137
137
  if (env === undefined) {
@@ -190,12 +190,12 @@ function vertexToMermaid(info, mermaid, id, idPrefix, mark, includeOnlyIds) {
190
190
  }
191
191
  const originalTarget = target;
192
192
  target = (0, mermaid_1.escapeId)(target);
193
- const edgeTypes = typeof edge.types == 'number' ? new Set((0, edge_1.splitEdgeTypes)(edge.types)) : edge.types;
193
+ const edgeTypes = typeof edge.types == 'number' ? new Set(edge_1.DfEdge.splitTypes(edge)) : edge.types;
194
194
  const edgeId = encodeEdge(idPrefix + id, idPrefix + target, edgeTypes);
195
195
  if (!mermaid.presentEdges.has(edgeId)) {
196
196
  mermaid.presentEdges.add(edgeId);
197
197
  const style = (0, built_in_1.isBuiltIn)(target) ? '-.->' : '-->';
198
- mermaid.edgeLines.push(` ${idPrefix}${id} ${style}|"${[...edgeTypes].map(e => typeof e === 'number' ? (0, edge_1.edgeTypeToName)(e) : e).join(', ')}"| ${idPrefix}${target}`);
198
+ mermaid.edgeLines.push(` ${idPrefix}${id} ${style}|"${[...edgeTypes].map(e => typeof e === 'number' ? edge_1.DfEdge.typeToName(e) : e).join(', ')}"| ${idPrefix}${target}`);
199
199
  if (mermaid.mark?.has(id + '->' + target)) {
200
200
  // who invented this syntax?!
201
201
  mermaid.edgeLines.push(` linkStyle ${mermaid.presentEdges.size - 1} ${mermaid.markStyle.edge}`);
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dfgToAscii = dfgToAscii;
4
4
  const dagre_1 = require("dagre");
5
- const edge_1 = require("../../dataflow/graph/edge");
6
5
  const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
7
6
  const vertex_1 = require("../../dataflow/graph/vertex");
7
+ const edge_1 = require("../../dataflow/graph/edge");
8
8
  function combineAscii(has, add) {
9
9
  if (has === ' ' || has === add) {
10
10
  return add;
@@ -97,12 +97,12 @@ function dfgToAscii(dfg) {
97
97
  let longestId = 0;
98
98
  for (const [from, edges] of dfg.edges()) {
99
99
  longestId = Math.max(longestId, String(from).length);
100
- for (const [to, { types }] of edges) {
100
+ for (const [to, e] of edges) {
101
101
  if (!g.hasNode(String(from)) || !g.hasNode(String(to)) || edgesDone.has(`${to}-${from}`)) {
102
102
  continue;
103
103
  }
104
104
  longestId = Math.max(longestId, String(to).length);
105
- g.setEdge(String(from), String(to), (0, edge_1.edgeTypesToNames)(types));
105
+ g.setEdge(String(from), String(to), edge_1.DfEdge.typesToNames(e));
106
106
  edgesDone.add(`${from}-${to}`);
107
107
  }
108
108
  }
@@ -116,11 +116,11 @@ function dfgToAscii(dfg) {
116
116
  const edgeLines = [];
117
117
  // add all edges
118
118
  for (const [from, edges] of dfg.edges()) {
119
- for (const [to, { types }] of edges) {
119
+ for (const [to, e] of edges) {
120
120
  if (!g.hasNode(String(from)) || !g.hasNode(String(to))) {
121
121
  continue;
122
122
  }
123
- edgeLines.push(`${from.toString().padStart(longestId, ' ')} -> ${to.toString().padStart(longestId, ' ')}: ${Array.from((0, edge_1.edgeTypesToNames)(types)).join(', ')}`);
123
+ edgeLines.push(`${from.toString().padStart(longestId, ' ')} -> ${to.toString().padStart(longestId, ' ')}: ${Array.from(edge_1.DfEdge.typesToNames(e)).join(', ')}`);
124
124
  }
125
125
  }
126
126
  // always merge two edgelines with padding
package/util/version.js CHANGED
@@ -6,7 +6,7 @@ exports.printVersionInformation = printVersionInformation;
6
6
  const semver_1 = require("semver");
7
7
  const assert_1 = require("./assert");
8
8
  // this is automatically replaced with the current version by release-it
9
- const version = '2.8.15';
9
+ const version = '2.9.0';
10
10
  /**
11
11
  * Retrieves the current flowR version as a new {@link SemVer} object.
12
12
  */
@@ -1,66 +0,0 @@
1
- import type { REnvironmentInformation } from '../dataflow/environments/environment';
2
- import type { Identifier } from '../dataflow/environments/identifier';
3
- import { type ContainerIndices, type ContainerIndicesCollection, type IndexIdentifier } from '../dataflow/graph/vertex';
4
- import type { RAccess } from '../r-bridge/lang-4.x/ast/model/nodes/r-access';
5
- import type { RArgument } from '../r-bridge/lang-4.x/ast/model/nodes/r-argument';
6
- import { type RFunctionArgument } from '../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
7
- import type { ParentInformation } from '../r-bridge/lang-4.x/ast/model/processing/decorate';
8
- /**
9
- * Returns the accessed and access argument of an access operation by filtering the operation arguments.
10
- */
11
- export declare function getAccessOperands<OtherInfo>(args: readonly RFunctionArgument<OtherInfo & ParentInformation>[]): {
12
- accessedArg: RArgument<OtherInfo & ParentInformation> | undefined;
13
- accessArg: RArgument<OtherInfo & ParentInformation> | undefined;
14
- };
15
- /**
16
- * Resolves the passed name within the passed environment and returns the indicesCollection of the resolved definitions.
17
- * @param name - Name to resolve
18
- * @param environment - Environment in which name is resolved
19
- * @returns The indicesCollection of the resolved definitions
20
- */
21
- export declare function resolveIndicesByName(name: Identifier, environment: REnvironmentInformation): ContainerIndices[] | undefined;
22
- /**
23
- * Resolves {@link accessedArg} in the {@link environment} and filters its indices according to {@link accessArg}.
24
- *
25
- * If no indices could be found that match the `accessArg`, the original indices are returned as overapproximation.
26
- * @param accessedArg - The argument to resolve
27
- * @param accessArg - The argument which is used to filter the indices
28
- * @param environment - The environment in which {@link accessedArg} is resolved
29
- * @param isIndexBasedAccess - Whether the access is index-based (e.g. `x[1]`) or name-based (e.g. `x$name`)
30
- * @returns The filtered {@link ContainerIndicesCollection} of the resolved {@link accessedArg}
31
- */
32
- export declare function resolveSingleIndex(accessedArg: {
33
- lexeme: string;
34
- }, accessArg: {
35
- lexeme: string;
36
- }, environment: REnvironmentInformation, isIndexBasedAccess: boolean): ContainerIndicesCollection;
37
- /**
38
- * Filters the single indices of the {@link indicesCollection} according to the lexeme of the {@link accessArg}.
39
- * @param indicesCollection - The {@link ContainerIndicesCollection} to filter
40
- * @param accessArg - The argument which is used to filter {@link indicesCollection}
41
- * @param isIndexBasedAccess - Whether the access is index-based (e.g. `x[1]`) or name-based (e.g. `x$name`)
42
- * @returns The filtered copy of {@link indicesCollection}
43
- */
44
- export declare function filterIndices(indicesCollection: ContainerIndicesCollection, accessArg: {
45
- lexeme: string;
46
- }, isIndexBasedAccess: boolean): ContainerIndicesCollection;
47
- /**
48
- * Constructs the definition of a nested access.
49
- *
50
- * Example:
51
- * ```r
52
- * person$credentials$username
53
- * ```
54
- * would result in a list with the index `credentials`, which has the subIndex `username`.
55
- * @param accessedArg - The top level argument that is accessed
56
- * @param leafIndices - The index at the end of the nested access i.e. `c` in `a$b$c`.
57
- * @param constructIdentifier - A function that constructs the identifier for the index from the argument
58
- * @returns The constructed nested access
59
- */
60
- export declare function constructNestedAccess<OtherInfo>(accessedArg: RAccess<OtherInfo & ParentInformation>, leafIndices: ContainerIndices, constructIdentifier: (arg: RArgument<OtherInfo & ParentInformation>) => IndexIdentifier): ContainerIndices[];
61
- /**
62
- * Adds the passed list of {@link leafSubIndices} to the leaf (sub-)indices of {@link indicesCollection}.
63
- * @param indicesCollection - Indices where to add the sub indices.
64
- * @param leafSubIndices - Indices that are added to the leaf indices.
65
- */
66
- export declare function addSubIndicesToLeafIndices(indicesCollection: ContainerIndices[], leafSubIndices: ContainerIndices[]): ContainerIndices[];
@@ -1,143 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAccessOperands = getAccessOperands;
4
- exports.resolveIndicesByName = resolveIndicesByName;
5
- exports.resolveSingleIndex = resolveSingleIndex;
6
- exports.filterIndices = filterIndices;
7
- exports.constructNestedAccess = constructNestedAccess;
8
- exports.addSubIndicesToLeafIndices = addSubIndicesToLeafIndices;
9
- const resolve_by_name_1 = require("../dataflow/environments/resolve-by-name");
10
- const vertex_1 = require("../dataflow/graph/vertex");
11
- const r_function_call_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
12
- const type_1 = require("../r-bridge/lang-4.x/ast/model/type");
13
- /**
14
- * Returns the accessed and access argument of an access operation by filtering the operation arguments.
15
- */
16
- function getAccessOperands(args) {
17
- const nonEmptyArgs = args.filter(arg => arg !== r_function_call_1.EmptyArgument);
18
- const accessedArg = nonEmptyArgs.find(arg => arg.info.role === "accessed" /* RoleInParent.Accessed */);
19
- const accessArg = nonEmptyArgs.find(arg => arg.info.role === "index-acc" /* RoleInParent.IndexAccess */);
20
- return { accessedArg, accessArg };
21
- }
22
- /**
23
- * Resolves the passed name within the passed environment and returns the indicesCollection of the resolved definitions.
24
- * @param name - Name to resolve
25
- * @param environment - Environment in which name is resolved
26
- * @returns The indicesCollection of the resolved definitions
27
- */
28
- function resolveIndicesByName(name, environment) {
29
- const definitions = (0, resolve_by_name_1.resolveByNameAnyType)(name, environment);
30
- return definitions?.flatMap(def => def?.indicesCollection ?? []);
31
- }
32
- /**
33
- * Resolves {@link accessedArg} in the {@link environment} and filters its indices according to {@link accessArg}.
34
- *
35
- * If no indices could be found that match the `accessArg`, the original indices are returned as overapproximation.
36
- * @param accessedArg - The argument to resolve
37
- * @param accessArg - The argument which is used to filter the indices
38
- * @param environment - The environment in which {@link accessedArg} is resolved
39
- * @param isIndexBasedAccess - Whether the access is index-based (e.g. `x[1]`) or name-based (e.g. `x$name`)
40
- * @returns The filtered {@link ContainerIndicesCollection} of the resolved {@link accessedArg}
41
- */
42
- function resolveSingleIndex(accessedArg, accessArg, environment, isIndexBasedAccess) {
43
- const indicesCollection = resolveIndicesByName(accessedArg.lexeme, environment);
44
- const accessedIndicesCollection = filterIndices(indicesCollection, accessArg, isIndexBasedAccess);
45
- // If the accessed indices couldn't be resolved, overapproximate by returning the original indices.
46
- // This could also be the case, when nothing is acccessed, but we better be safe.
47
- if (accessedIndicesCollection === undefined) {
48
- return indicesCollection;
49
- }
50
- else {
51
- return accessedIndicesCollection;
52
- }
53
- }
54
- /**
55
- * Filters the single indices of the {@link indicesCollection} according to the lexeme of the {@link accessArg}.
56
- * @param indicesCollection - The {@link ContainerIndicesCollection} to filter
57
- * @param accessArg - The argument which is used to filter {@link indicesCollection}
58
- * @param isIndexBasedAccess - Whether the access is index-based (e.g. `x[1]`) or name-based (e.g. `x$name`)
59
- * @returns The filtered copy of {@link indicesCollection}
60
- */
61
- function filterIndices(indicesCollection, accessArg, isIndexBasedAccess) {
62
- let accessedIndicesCollection = undefined;
63
- for (const indices of indicesCollection ?? []) {
64
- const filteredIndices = indices.indices.filter(index => (0, vertex_1.isAccessed)(index, accessArg.lexeme, isIndexBasedAccess));
65
- if (filteredIndices.length === 0) {
66
- continue;
67
- }
68
- accessedIndicesCollection ??= [];
69
- accessedIndicesCollection.push({
70
- indices: filteredIndices,
71
- isContainer: indices.isContainer
72
- });
73
- }
74
- return accessedIndicesCollection;
75
- }
76
- /**
77
- * Constructs the definition of a nested access.
78
- *
79
- * Example:
80
- * ```r
81
- * person$credentials$username
82
- * ```
83
- * would result in a list with the index `credentials`, which has the subIndex `username`.
84
- * @param accessedArg - The top level argument that is accessed
85
- * @param leafIndices - The index at the end of the nested access i.e. `c` in `a$b$c`.
86
- * @param constructIdentifier - A function that constructs the identifier for the index from the argument
87
- * @returns The constructed nested access
88
- */
89
- function constructNestedAccess(accessedArg, leafIndices, constructIdentifier) {
90
- const accessed = accessedArg.accessed;
91
- const accesses = accessedArg.access.filter(arg => arg !== r_function_call_1.EmptyArgument).map(arg => arg);
92
- const indices = [];
93
- for (const access of accesses) {
94
- const newIndices = {
95
- indices: [
96
- {
97
- identifier: constructIdentifier(access),
98
- nodeId: access.info.id,
99
- subIndices: [leafIndices],
100
- }
101
- ],
102
- isContainer: false,
103
- };
104
- if (accessed.type === type_1.RType.Access) {
105
- const nestedIndices = constructNestedAccess(accessed, newIndices, constructIdentifier);
106
- indices.push(...nestedIndices);
107
- }
108
- else {
109
- indices.push(newIndices);
110
- }
111
- }
112
- return indices;
113
- }
114
- /**
115
- * Adds the passed list of {@link leafSubIndices} to the leaf (sub-)indices of {@link indicesCollection}.
116
- * @param indicesCollection - Indices where to add the sub indices.
117
- * @param leafSubIndices - Indices that are added to the leaf indices.
118
- */
119
- function addSubIndicesToLeafIndices(indicesCollection, leafSubIndices) {
120
- const result = [];
121
- for (const indices of indicesCollection) {
122
- const newIndices = [];
123
- for (const index of indices.indices) {
124
- let newSubIndices = [];
125
- if ((0, vertex_1.isParentContainerIndex)(index)) {
126
- newSubIndices = addSubIndicesToLeafIndices(index.subIndices, leafSubIndices);
127
- }
128
- else {
129
- newSubIndices = leafSubIndices;
130
- }
131
- newIndices.push({
132
- ...index,
133
- subIndices: newSubIndices,
134
- });
135
- }
136
- result.push({
137
- ...indices,
138
- indices: newIndices,
139
- });
140
- }
141
- return result;
142
- }
143
- //# sourceMappingURL=containers.js.map