@eagleoutice/flowr 2.2.14 → 2.2.16

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 (245) hide show
  1. package/README.md +210 -6
  2. package/benchmark/slicer.d.ts +3 -1
  3. package/benchmark/slicer.js +8 -5
  4. package/benchmark/summarizer/first-phase/process.d.ts +2 -1
  5. package/benchmark/summarizer/first-phase/process.js +2 -2
  6. package/cli/benchmark-app.d.ts +1 -0
  7. package/cli/benchmark-app.js +4 -1
  8. package/cli/benchmark-helper-app.d.ts +1 -0
  9. package/cli/benchmark-helper-app.js +7 -8
  10. package/cli/common/options.js +2 -0
  11. package/cli/export-quads-app.js +2 -1
  12. package/cli/flowr.js +58 -57
  13. package/cli/repl/commands/repl-cfg.js +13 -13
  14. package/cli/repl/commands/repl-commands.js +3 -3
  15. package/cli/repl/commands/repl-dataflow.js +10 -10
  16. package/cli/repl/commands/repl-execute.d.ts +2 -3
  17. package/cli/repl/commands/repl-execute.js +5 -4
  18. package/cli/repl/commands/repl-lineage.js +4 -4
  19. package/cli/repl/commands/repl-main.d.ts +12 -1
  20. package/cli/repl/commands/repl-normalize.js +6 -6
  21. package/cli/repl/commands/repl-parse.js +2 -2
  22. package/cli/repl/commands/repl-query.js +9 -9
  23. package/cli/repl/commands/repl-version.js +1 -1
  24. package/cli/repl/core.d.ts +5 -2
  25. package/cli/repl/core.js +10 -8
  26. package/cli/repl/server/connection.d.ts +3 -1
  27. package/cli/repl/server/connection.js +7 -5
  28. package/cli/repl/server/server.d.ts +3 -2
  29. package/cli/repl/server/server.js +4 -2
  30. package/cli/script-core/statistics-core.d.ts +2 -1
  31. package/cli/script-core/statistics-core.js +2 -2
  32. package/cli/script-core/statistics-helper-core.d.ts +2 -1
  33. package/cli/script-core/statistics-helper-core.js +5 -4
  34. package/cli/slicer-app.js +4 -2
  35. package/cli/statistics-app.js +2 -1
  36. package/cli/statistics-helper-app.js +2 -1
  37. package/config.d.ts +12 -10
  38. package/config.js +27 -43
  39. package/control-flow/basic-cfg-guided-visitor.d.ts +3 -3
  40. package/control-flow/cfg-dead-code.d.ts +4 -0
  41. package/control-flow/cfg-dead-code.js +124 -0
  42. package/control-flow/cfg-simplification.d.ts +19 -6
  43. package/control-flow/cfg-simplification.js +23 -19
  44. package/control-flow/control-flow-graph.d.ts +3 -1
  45. package/control-flow/control-flow-graph.js +5 -0
  46. package/control-flow/dfg-cfg-guided-visitor.d.ts +9 -7
  47. package/control-flow/dfg-cfg-guided-visitor.js +16 -5
  48. package/control-flow/extract-cfg.d.ts +4 -2
  49. package/control-flow/extract-cfg.js +63 -59
  50. package/control-flow/semantic-cfg-guided-visitor.d.ts +36 -9
  51. package/control-flow/semantic-cfg-guided-visitor.js +73 -20
  52. package/control-flow/simple-visitor.d.ts +4 -0
  53. package/control-flow/simple-visitor.js +14 -0
  54. package/control-flow/syntax-cfg-guided-visitor.d.ts +2 -2
  55. package/core/pipeline-executor.d.ts +4 -1
  56. package/core/pipeline-executor.js +6 -5
  57. package/core/steps/all/core/10-normalize.d.ts +2 -0
  58. package/core/steps/all/core/10-normalize.js +1 -1
  59. package/core/steps/all/core/11-normalize-tree-sitter.d.ts +2 -1
  60. package/core/steps/all/core/11-normalize-tree-sitter.js +2 -2
  61. package/core/steps/all/core/20-dataflow.d.ts +2 -1
  62. package/core/steps/all/core/20-dataflow.js +2 -2
  63. package/core/steps/all/static-slicing/00-slice.d.ts +2 -1
  64. package/core/steps/all/static-slicing/00-slice.js +2 -2
  65. package/core/steps/pipeline/default-pipelines.d.ts +32 -31
  66. package/core/steps/pipeline/default-pipelines.js +8 -8
  67. package/core/steps/pipeline-step.d.ts +2 -1
  68. package/dataflow/environments/built-in-config.d.ts +4 -3
  69. package/dataflow/environments/built-in.d.ts +16 -1
  70. package/dataflow/environments/built-in.js +11 -5
  71. package/dataflow/environments/default-builtin-config.js +5 -3
  72. package/dataflow/environments/define.d.ts +2 -1
  73. package/dataflow/environments/define.js +4 -5
  74. package/dataflow/environments/remove.d.ts +6 -0
  75. package/dataflow/environments/remove.js +29 -0
  76. package/dataflow/environments/resolve-by-name.d.ts +0 -36
  77. package/dataflow/environments/resolve-by-name.js +0 -240
  78. package/dataflow/eval/resolve/alias-tracking.d.ts +92 -0
  79. package/dataflow/eval/resolve/alias-tracking.js +352 -0
  80. package/dataflow/eval/resolve/resolve-argument.d.ts +8 -0
  81. package/dataflow/eval/resolve/resolve-argument.js +118 -0
  82. package/dataflow/eval/resolve/resolve.d.ts +37 -0
  83. package/dataflow/eval/resolve/resolve.js +95 -0
  84. package/dataflow/eval/values/general.d.ts +27 -0
  85. package/dataflow/eval/values/general.js +73 -0
  86. package/dataflow/eval/values/intervals/interval-constants.d.ts +4 -0
  87. package/dataflow/eval/values/intervals/interval-constants.js +27 -0
  88. package/dataflow/eval/values/logical/logical-constants.d.ts +7 -0
  89. package/dataflow/eval/values/logical/logical-constants.js +31 -0
  90. package/dataflow/eval/values/r-value.d.ts +58 -0
  91. package/dataflow/eval/values/r-value.js +90 -0
  92. package/dataflow/eval/values/scalar/scalar-consatnts.d.ts +15 -0
  93. package/dataflow/eval/values/scalar/scalar-consatnts.js +35 -0
  94. package/dataflow/eval/values/sets/set-constants.d.ts +7 -0
  95. package/dataflow/eval/values/sets/set-constants.js +34 -0
  96. package/dataflow/eval/values/string/string-constants.d.ts +8 -0
  97. package/dataflow/eval/values/string/string-constants.js +45 -0
  98. package/dataflow/eval/values/vectors/vector-constants.d.ts +14 -0
  99. package/dataflow/eval/values/vectors/vector-constants.js +35 -0
  100. package/dataflow/extractor.d.ts +2 -1
  101. package/dataflow/extractor.js +2 -1
  102. package/dataflow/graph/unknown-replacement.d.ts +11 -0
  103. package/dataflow/graph/unknown-replacement.js +12 -0
  104. package/dataflow/graph/unknown-side-effect.d.ts +7 -0
  105. package/dataflow/graph/unknown-side-effect.js +13 -0
  106. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +5 -6
  107. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +8 -5
  108. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +4 -2
  109. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +15 -13
  110. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +20 -18
  111. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +7 -2
  112. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +2 -3
  113. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +5 -4
  114. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +2 -2
  115. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +11 -5
  116. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +5 -3
  117. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +26 -29
  118. package/dataflow/internal/process/functions/call/built-in/built-in-vector.js +2 -2
  119. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +23 -0
  120. package/dataflow/internal/process/functions/call/common.js +1 -1
  121. package/dataflow/internal/process/functions/call/known-call-handling.js +2 -1
  122. package/dataflow/internal/process/functions/process-parameter.js +1 -1
  123. package/dataflow/origin/dfg-get-symbol-refs.d.ts +21 -0
  124. package/dataflow/origin/dfg-get-symbol-refs.js +50 -0
  125. package/dataflow/processor.d.ts +5 -0
  126. package/documentation/doc-util/doc-cfg.js +4 -3
  127. package/documentation/doc-util/doc-code.d.ts +1 -1
  128. package/documentation/doc-util/doc-dfg.js +3 -2
  129. package/documentation/doc-util/doc-functions.d.ts +24 -0
  130. package/documentation/doc-util/doc-functions.js +65 -0
  131. package/documentation/doc-util/doc-normalized-ast.js +3 -2
  132. package/documentation/doc-util/doc-print.d.ts +5 -0
  133. package/documentation/doc-util/doc-print.js +36 -0
  134. package/documentation/doc-util/doc-query.d.ts +6 -3
  135. package/documentation/doc-util/doc-query.js +6 -3
  136. package/documentation/doc-util/doc-repl.js +2 -1
  137. package/documentation/doc-util/doc-search.js +3 -2
  138. package/documentation/doc-util/doc-types.d.ts +28 -6
  139. package/documentation/doc-util/doc-types.js +89 -45
  140. package/documentation/print-cfg-wiki.js +10 -11
  141. package/documentation/print-core-wiki.js +5 -5
  142. package/documentation/print-dataflow-graph-wiki.js +14 -13
  143. package/documentation/print-engines-wiki.js +2 -3
  144. package/documentation/print-faq-wiki.js +8 -2
  145. package/documentation/print-interface-wiki.js +1 -2
  146. package/documentation/print-linter-issue.d.ts +1 -0
  147. package/documentation/print-linter-issue.js +71 -0
  148. package/documentation/print-linter-wiki.js +219 -34
  149. package/documentation/print-linting-and-testing-wiki.js +2 -4
  150. package/documentation/print-normalized-ast-wiki.js +3 -3
  151. package/documentation/print-query-wiki.js +81 -2
  152. package/documentation/print-readme.js +24 -1
  153. package/documentation/print-search-wiki.js +1 -2
  154. package/linter/linter-executor.d.ts +3 -1
  155. package/linter/linter-executor.js +3 -2
  156. package/linter/linter-format.d.ts +67 -7
  157. package/linter/linter-format.js +12 -1
  158. package/linter/linter-rules.d.ts +155 -16
  159. package/linter/linter-rules.js +12 -4
  160. package/linter/linter-tags.d.ts +80 -0
  161. package/linter/linter-tags.js +85 -0
  162. package/linter/rules/absolute-path.d.ts +71 -0
  163. package/linter/rules/absolute-path.js +177 -0
  164. package/linter/rules/deprecated-functions.d.ts +43 -0
  165. package/linter/rules/deprecated-functions.js +58 -0
  166. package/linter/rules/{2-file-path-validity.d.ts → file-path-validity.d.ts} +16 -6
  167. package/linter/rules/{2-file-path-validity.js → file-path-validity.js} +21 -13
  168. package/linter/rules/naming-convention.d.ts +71 -0
  169. package/linter/rules/naming-convention.js +164 -0
  170. package/linter/rules/seeded-randomness.d.ts +65 -0
  171. package/linter/rules/seeded-randomness.js +122 -0
  172. package/linter/rules/unused-definition.d.ts +41 -0
  173. package/linter/rules/unused-definition.js +105 -0
  174. package/package.json +4 -1
  175. package/queries/base-query-format.d.ts +2 -0
  176. package/queries/catalog/call-context-query/call-context-query-executor.d.ts +1 -1
  177. package/queries/catalog/call-context-query/call-context-query-executor.js +2 -2
  178. package/queries/catalog/cluster-query/cluster-query-format.d.ts +1 -1
  179. package/queries/catalog/config-query/config-query-executor.d.ts +1 -1
  180. package/queries/catalog/config-query/config-query-executor.js +2 -3
  181. package/queries/catalog/control-flow-query/control-flow-query-executor.d.ts +3 -0
  182. package/queries/catalog/control-flow-query/control-flow-query-executor.js +20 -0
  183. package/queries/catalog/control-flow-query/control-flow-query-format.d.ts +81 -0
  184. package/queries/catalog/control-flow-query/control-flow-query-format.js +34 -0
  185. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.d.ts +1 -1
  186. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +1 -1
  187. package/queries/catalog/dependencies-query/dependencies-query-executor.js +4 -115
  188. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +1 -1
  189. package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +1 -1
  190. package/queries/catalog/id-map-query/id-map-query-format.d.ts +1 -1
  191. package/queries/catalog/lineage-query/lineage-query-format.d.ts +1 -1
  192. package/queries/catalog/linter-query/linter-query-executor.d.ts +1 -1
  193. package/queries/catalog/linter-query/linter-query-executor.js +2 -2
  194. package/queries/catalog/linter-query/linter-query-format.d.ts +1 -1
  195. package/queries/catalog/linter-query/linter-query-format.js +17 -12
  196. package/queries/catalog/normalized-ast-query/normalized-ast-query-format.d.ts +1 -1
  197. package/queries/catalog/origin-query/origin-query-format.d.ts +1 -1
  198. package/queries/catalog/project-query/project-query-format.d.ts +1 -1
  199. package/queries/catalog/resolve-value-query/resolve-value-query-executor.d.ts +1 -1
  200. package/queries/catalog/resolve-value-query/resolve-value-query-executor.js +4 -4
  201. package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +3 -2
  202. package/queries/catalog/resolve-value-query/resolve-value-query-format.js +2 -22
  203. package/queries/catalog/search-query/search-query-executor.d.ts +1 -1
  204. package/queries/catalog/search-query/search-query-executor.js +2 -2
  205. package/queries/catalog/search-query/search-query-format.d.ts +1 -1
  206. package/queries/catalog/static-slice-query/static-slice-query-executor.d.ts +1 -1
  207. package/queries/catalog/static-slice-query/static-slice-query-executor.js +2 -2
  208. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +1 -1
  209. package/queries/query.d.ts +75 -15
  210. package/queries/query.js +2 -0
  211. package/r-bridge/lang-4.x/ast/parser/json/parser.d.ts +2 -1
  212. package/r-bridge/lang-4.x/ast/parser/json/parser.js +4 -2
  213. package/r-bridge/lang-4.x/convert-values.js +2 -1
  214. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +3 -1
  215. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +4 -4
  216. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.d.ts +1 -1
  217. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +18 -9
  218. package/r-bridge/shell.d.ts +3 -2
  219. package/r-bridge/shell.js +4 -5
  220. package/search/flowr-search-builder.d.ts +6 -2
  221. package/search/flowr-search-builder.js +7 -0
  222. package/search/flowr-search-filters.d.ts +32 -8
  223. package/search/flowr-search-filters.js +42 -15
  224. package/search/flowr-search.d.ts +4 -0
  225. package/search/search-executor/search-enrichers.d.ts +7 -3
  226. package/search/search-executor/search-enrichers.js +32 -20
  227. package/search/search-executor/search-generators.js +1 -1
  228. package/search/search-executor/search-transformer.d.ts +2 -0
  229. package/search/search-executor/search-transformer.js +10 -1
  230. package/slicing/criterion/parse.d.ts +8 -0
  231. package/slicing/criterion/parse.js +20 -0
  232. package/slicing/static/static-slicer.d.ts +1 -1
  233. package/slicing/static/static-slicer.js +2 -3
  234. package/statistics/statistics.d.ts +3 -1
  235. package/statistics/statistics.js +5 -4
  236. package/util/containers.d.ts +12 -9
  237. package/util/containers.js +12 -9
  238. package/util/objects.d.ts +5 -4
  239. package/util/range.d.ts +5 -1
  240. package/util/range.js +11 -3
  241. package/util/text/strings.d.ts +6 -0
  242. package/util/text/strings.js +35 -0
  243. package/util/version.js +1 -1
  244. package/linter/rules/1-deprecated-functions.d.ts +0 -34
  245. package/linter/rules/1-deprecated-functions.js +0 -54
@@ -2,9 +2,6 @@ import type { REnvironmentInformation } from './environment';
2
2
  import { Ternary } from '../../util/logic';
3
3
  import type { Identifier, IdentifierDefinition } from './identifier';
4
4
  import { ReferenceType } from './identifier';
5
- import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
6
- import type { DataflowGraph } from '../graph/graph';
7
- import type { AstIdMap, RNodeWithParent } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
8
5
  /**
9
6
  * Resolves a given identifier name to a list of its possible definition location using R scoping and resolving rules.
10
7
  *
@@ -17,36 +14,3 @@ import type { AstIdMap, RNodeWithParent } from '../../r-bridge/lang-4.x/ast/mode
17
14
  */
18
15
  export declare function resolveByName(name: Identifier, environment: REnvironmentInformation, target?: ReferenceType): IdentifierDefinition[] | undefined;
19
16
  export declare function resolvesToBuiltInConstant(name: Identifier | undefined, environment: REnvironmentInformation, wantedValue: unknown): Ternary;
20
- /** Please use {@link resolveValueOfVariable} */
21
- export declare function resolveToConstants(name: Identifier | undefined, environment: REnvironmentInformation): unknown[] | undefined;
22
- export declare function getAliases(sourceIds: readonly NodeId[], dataflow: DataflowGraph, environment: REnvironmentInformation): NodeId[] | undefined;
23
- /** Please use {@link resolveValueOfVariable} */
24
- export declare function trackAliasInEnvironments(identifier: Identifier | undefined, use: REnvironmentInformation, idMap?: AstIdMap): unknown[] | undefined;
25
- export declare function trackAliasesInGraph(id: NodeId, graph: DataflowGraph, idMap?: AstIdMap): unknown[] | undefined;
26
- /**
27
- * Convenience function using the variable resolver as specified within the configuration file
28
- * In the future we may want to have this set once at the start of the analysis
29
- *
30
- * @see {@link resolveIdToValue} - for a more general approach which "evaluates" a node based on value resolve
31
- */
32
- export declare function resolveValueOfVariable(identifier: Identifier | undefined, environment: REnvironmentInformation, idMap?: AstIdMap): unknown[] | undefined;
33
- export interface ResolveInfo {
34
- /** The current environment used for name resolution */
35
- environment?: REnvironmentInformation;
36
- /** The id map to resolve the node if given as an id */
37
- idMap?: AstIdMap;
38
- /** The graph to resolve in */
39
- graph?: DataflowGraph;
40
- /** Whether to track variables */
41
- full?: boolean;
42
- }
43
- /**
44
- * Generalized {@link resolveValueOfVariable} function which evaluates a node based on the value resolve
45
- *
46
- * @param id - The node id or node to resolve
47
- * @param environment - The current environment used for name resolution
48
- * @param graph - The graph to resolve in
49
- * @param idMap - The id map to resolve the node if given as an id
50
- * @param full - Whether to track variables
51
- */
52
- export declare function resolveIdToValue(id: NodeId | RNodeWithParent, { environment, graph, idMap, full }: ResolveInfo): unknown[] | undefined;
@@ -2,24 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveByName = resolveByName;
4
4
  exports.resolvesToBuiltInConstant = resolvesToBuiltInConstant;
5
- exports.resolveToConstants = resolveToConstants;
6
- exports.getAliases = getAliases;
7
- exports.trackAliasInEnvironments = trackAliasInEnvironments;
8
- exports.trackAliasesInGraph = trackAliasesInGraph;
9
- exports.resolveValueOfVariable = resolveValueOfVariable;
10
- exports.resolveIdToValue = resolveIdToValue;
11
5
  const environment_1 = require("./environment");
12
6
  const logic_1 = require("../../util/logic");
13
7
  const identifier_1 = require("./identifier");
14
8
  const info_1 = require("../info");
15
- const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
16
- const vertex_1 = require("../graph/vertex");
17
- const config_1 = require("../../config");
18
- const assert_1 = require("../../util/assert");
19
- const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
20
- const visiting_queue_1 = require("../../slicing/static/visiting-queue");
21
- const fingerprint_1 = require("../../slicing/static/fingerprint");
22
- const edge_1 = require("../graph/edge");
23
9
  const FunctionTargetTypes = identifier_1.ReferenceType.Function | identifier_1.ReferenceType.BuiltInFunction | identifier_1.ReferenceType.Unknown | identifier_1.ReferenceType.Argument | identifier_1.ReferenceType.Parameter;
24
10
  const VariableTargetTypes = identifier_1.ReferenceType.Variable | identifier_1.ReferenceType.Parameter | identifier_1.ReferenceType.Argument | identifier_1.ReferenceType.Unknown;
25
11
  const ConstantTargetTypes = identifier_1.ReferenceType.Constant | identifier_1.ReferenceType.BuiltInConstant | identifier_1.ReferenceType.Unknown;
@@ -96,230 +82,4 @@ function resolvesToBuiltInConstant(name, environment, wantedValue) {
96
82
  return some ? logic_1.Ternary.Maybe : logic_1.Ternary.Never;
97
83
  }
98
84
  }
99
- /** Please use {@link resolveValueOfVariable} */
100
- function resolveToConstants(name, environment) {
101
- if (name === undefined) {
102
- return undefined;
103
- }
104
- const definitions = resolveByName(name, environment, identifier_1.ReferenceType.Constant);
105
- return definitions?.map(def => def.value);
106
- }
107
- const AliasHandler = {
108
- [vertex_1.VertexType.Value]: (sourceId) => [sourceId],
109
- [vertex_1.VertexType.Use]: getUseAlias,
110
- [vertex_1.VertexType.FunctionCall]: () => undefined,
111
- [vertex_1.VertexType.FunctionDefinition]: () => undefined,
112
- [vertex_1.VertexType.VariableDefinition]: () => undefined
113
- };
114
- function getUseAlias(sourceId, dataflow, environment) {
115
- let definitions = [];
116
- // Source is Symbol -> resolve definitions of symbol
117
- const identifier = (0, node_id_1.recoverName)(sourceId, dataflow.idMap);
118
- if (identifier === undefined) {
119
- return undefined;
120
- }
121
- const defs = resolveByName(identifier, environment);
122
- if (defs === undefined) {
123
- return undefined;
124
- }
125
- for (const def of defs) {
126
- // If one definition is not constant (or a variable aliasing a constant)
127
- // we can't say for sure what value the source has
128
- if (def.type === identifier_1.ReferenceType.Variable) {
129
- if (def.value === undefined) {
130
- return undefined;
131
- }
132
- definitions = definitions.concat(def.value);
133
- }
134
- else if (def.type === identifier_1.ReferenceType.Constant || def.type === identifier_1.ReferenceType.BuiltInConstant) {
135
- definitions.push(def.nodeId);
136
- }
137
- else {
138
- return undefined;
139
- }
140
- }
141
- return definitions;
142
- }
143
- function getAliases(sourceIds, dataflow, environment) {
144
- const definitions = new Set();
145
- for (const sourceId of sourceIds) {
146
- const info = dataflow.getVertex(sourceId);
147
- if (info === undefined) {
148
- return undefined;
149
- }
150
- const defs = AliasHandler[info.tag](sourceId, dataflow, environment);
151
- for (const def of defs ?? []) {
152
- definitions.add(def);
153
- }
154
- }
155
- return [...definitions];
156
- }
157
- /** Please use {@link resolveValueOfVariable} */
158
- function trackAliasInEnvironments(identifier, use, idMap) {
159
- if (identifier === undefined) {
160
- return undefined;
161
- }
162
- const defs = resolveByName(identifier, use);
163
- if (defs === undefined) {
164
- return undefined;
165
- }
166
- const values = [];
167
- for (const def of defs) {
168
- if (def.type === identifier_1.ReferenceType.BuiltInConstant) {
169
- values.push(def.value);
170
- }
171
- else if (def.type === identifier_1.ReferenceType.BuiltInFunction) {
172
- // Tracked in #1207
173
- }
174
- else if (def.value !== undefined) {
175
- /* if there is at least one location for which we have no idea, we have to give up for now! */
176
- if (def.value.length === 0) {
177
- return undefined;
178
- }
179
- for (const id of def.value) {
180
- const value = idMap?.get(id)?.content;
181
- if (value !== undefined) {
182
- values.push(value);
183
- }
184
- }
185
- }
186
- }
187
- if (values.length == 0) {
188
- return undefined;
189
- }
190
- return values;
191
- }
192
- function isNestedInLoop(node, ast) {
193
- const parent = node?.info.parent;
194
- if (node === undefined || !parent) {
195
- return false;
196
- }
197
- const parentNode = ast.get(parent);
198
- if (parentNode === undefined) {
199
- return false;
200
- }
201
- if (parentNode.type === type_1.RType.WhileLoop || parentNode.type === type_1.RType.RepeatLoop) {
202
- return true;
203
- }
204
- return isNestedInLoop(parentNode, ast);
205
- }
206
- function trackAliasesInGraph(id, graph, idMap) {
207
- idMap ??= graph.idMap;
208
- (0, assert_1.guard)(idMap !== undefined, 'The ID map is required to get the lineage of a node');
209
- const start = graph.getVertex(id);
210
- (0, assert_1.guard)(start !== undefined, 'Unable to find start for alias tracking');
211
- const queue = new visiting_queue_1.VisitingQueue(25);
212
- const clean = (0, environment_1.initializeCleanEnvironments)();
213
- const cleanFingerprint = (0, fingerprint_1.envFingerprint)(clean);
214
- queue.add(id, clean, cleanFingerprint, false);
215
- let forceBot = false;
216
- const resultIds = [];
217
- while (queue.nonEmpty()) {
218
- const { id, baseEnvironment } = queue.next();
219
- const res = graph.get(id);
220
- if (!res) {
221
- continue;
222
- }
223
- const [vertex, outgoingEdges] = res;
224
- const cds = vertex.cds;
225
- for (const cd of cds ?? []) {
226
- const target = graph.idMap?.get(cd.id);
227
- if (target === undefined) {
228
- continue;
229
- }
230
- if (target.type === type_1.RType.WhileLoop || target.type === type_1.RType.RepeatLoop) {
231
- forceBot = true;
232
- break;
233
- }
234
- }
235
- if (!forceBot && (cds?.length === 0 && isNestedInLoop(idMap.get(id), idMap))) {
236
- forceBot = true;
237
- }
238
- if (forceBot) {
239
- break;
240
- }
241
- if (vertex.tag === vertex_1.VertexType.Value) {
242
- resultIds.push(id);
243
- continue;
244
- }
245
- else if (vertex.tag === vertex_1.VertexType.FunctionDefinition) {
246
- resultIds.push(id);
247
- continue;
248
- }
249
- const isFn = vertex.tag === vertex_1.VertexType.FunctionCall;
250
- // travel all read and defined-by edges
251
- for (const [targetId, edge] of outgoingEdges) {
252
- if (isFn) {
253
- if (edge.types === edge_1.EdgeType.Returns || edge.types === edge_1.EdgeType.DefinedByOnCall || edge.types === edge_1.EdgeType.DefinedBy) {
254
- queue.add(targetId, baseEnvironment, cleanFingerprint, false);
255
- }
256
- continue;
257
- }
258
- // currently, they have to be exact!
259
- if (edge.types === edge_1.EdgeType.Reads || edge.types === edge_1.EdgeType.DefinedBy || edge.types === edge_1.EdgeType.DefinedByOnCall) {
260
- queue.add(targetId, baseEnvironment, cleanFingerprint, false);
261
- }
262
- }
263
- }
264
- if (forceBot || resultIds.length === 0) {
265
- return undefined;
266
- }
267
- const values = [];
268
- for (const id of resultIds) {
269
- const node = idMap.get(id);
270
- if (node !== undefined) {
271
- values.push(node.content);
272
- }
273
- }
274
- return values;
275
- }
276
- /**
277
- * Convenience function using the variable resolver as specified within the configuration file
278
- * In the future we may want to have this set once at the start of the analysis
279
- *
280
- * @see {@link resolveIdToValue} - for a more general approach which "evaluates" a node based on value resolve
281
- */
282
- function resolveValueOfVariable(identifier, environment, idMap) {
283
- const resolve = (0, config_1.getConfig)().solver.variables;
284
- switch (resolve) {
285
- case config_1.VariableResolve.Alias: return trackAliasInEnvironments(identifier, environment, idMap);
286
- case config_1.VariableResolve.Builtin: return resolveToConstants(identifier, environment);
287
- case config_1.VariableResolve.Disabled: return [];
288
- default: (0, assert_1.assertUnreachable)(resolve);
289
- }
290
- }
291
- /**
292
- * Generalized {@link resolveValueOfVariable} function which evaluates a node based on the value resolve
293
- *
294
- * @param id - The node id or node to resolve
295
- * @param environment - The current environment used for name resolution
296
- * @param graph - The graph to resolve in
297
- * @param idMap - The id map to resolve the node if given as an id
298
- * @param full - Whether to track variables
299
- */
300
- function resolveIdToValue(id, { environment, graph, idMap, full }) {
301
- idMap ??= graph?.idMap;
302
- const node = typeof id === 'object' ? id : idMap?.get(id);
303
- if (node === undefined) {
304
- return undefined;
305
- }
306
- switch (node.type) {
307
- case type_1.RType.Symbol:
308
- if (environment) {
309
- return full ? resolveValueOfVariable(node.lexeme, environment, idMap) : undefined;
310
- }
311
- else if (graph && (0, config_1.getConfig)().solver.variables === config_1.VariableResolve.Alias) {
312
- return full ? trackAliasesInGraph(node.info.id, graph, idMap) : undefined;
313
- }
314
- else {
315
- return undefined;
316
- }
317
- case type_1.RType.String:
318
- case type_1.RType.Number:
319
- case type_1.RType.Logical:
320
- return [node.content];
321
- default:
322
- return undefined;
323
- }
324
- }
325
85
  //# sourceMappingURL=resolve-by-name.js.map
@@ -0,0 +1,92 @@
1
+ import { VariableResolve } from '../../../config';
2
+ import type { AstIdMap, RNodeWithParent } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
3
+ import type { NodeId } from '../../../r-bridge/lang-4.x/ast/model/processing/node-id';
4
+ import type { REnvironmentInformation } from '../../environments/environment';
5
+ import type { Identifier } from '../../environments/identifier';
6
+ import type { DataflowGraph } from '../../graph/graph';
7
+ import type { Lift, Value, ValueSet } from '../values/r-value';
8
+ export type ResolveResult = Lift<ValueSet<Value[]>>;
9
+ export interface ResolveInfo {
10
+ /** The current environment used for name resolution */
11
+ environment?: REnvironmentInformation;
12
+ /** The id map to resolve the node if given as an id */
13
+ idMap?: AstIdMap;
14
+ /** The graph to resolve in */
15
+ graph?: DataflowGraph;
16
+ /** Whether to track variables */
17
+ full?: boolean;
18
+ /** Variable resolve mode */
19
+ resolve: VariableResolve;
20
+ }
21
+ /**
22
+ * Gets the definitions / aliases of a node
23
+ *
24
+ * This function is called by the built-in-assignment processor so that we can
25
+ * track assignments inside the environment. The returned ids are stored in
26
+ * the sourceIds value field of their InGraphIdentifierDefinition. This enables
27
+ * us later, in the {@link trackAliasInEnvironments} function, to get all the
28
+ * aliases of an identifier.
29
+ *
30
+ * @param sourceIds - node ids to get the definitions for
31
+ * @param dataflow - dataflow graph
32
+ * @param environment - environment
33
+ * @returns node id of alias
34
+ */
35
+ export declare function getAliases(sourceIds: readonly NodeId[], dataflow: DataflowGraph, environment: REnvironmentInformation): NodeId[] | undefined;
36
+ /**
37
+ * Evaluates the value of a node in the set domain.
38
+ *
39
+ * resolveIdToValue tries to resolve the value using the data it has been given.
40
+ * If the environment is provided the approximation is more precise, as we can
41
+ * track aliases in the environment.
42
+ * Otherwise, the graph is used to try and resolve the nodes value.
43
+ * If neither is provided the value cannot be resolved.
44
+ *
45
+ * This function is also used by the Resolve Value Query and the Dependency Query
46
+ * to resolve values. For e.g. in the Dependency Query it is used to resolve calls
47
+ * like `lapply(c("a", "b", "c"), library, character.only = TRUE)`
48
+ *
49
+ * @param id - The node id or node to resolve
50
+ * @param environment - The current environment used for name resolution
51
+ * @param graph - The graph to resolve in
52
+ * @param idMap - The id map to resolve the node if given as an id
53
+ * @param full - Whether to track aliases on resolve
54
+ * @param resolve - Variable resolve mode
55
+ */
56
+ export declare function resolveIdToValue(id: NodeId | RNodeWithParent | undefined, { environment, graph, idMap, full, resolve }: ResolveInfo): ResolveResult;
57
+ /**
58
+ * Please use {@link resolveIdToValue}
59
+ *
60
+ * Uses the aliases that were tracked in the environments (by the
61
+ * {@link getAliases} function) to resolve a node to a value.
62
+ *
63
+ *
64
+ * @param resolve - Variable resolve mode
65
+ * @param identifier - Identifier to resolve
66
+ * @param use - Environment to use
67
+ * @param graph - Dataflow graph
68
+ * @param idMap - id map of Dataflow graph
69
+ * @returns Value of Identifier or Top
70
+ */
71
+ export declare function trackAliasInEnvironments(resolve: VariableResolve, identifier: Identifier | undefined, use: REnvironmentInformation, graph?: DataflowGraph, idMap?: AstIdMap): ResolveResult;
72
+ /**
73
+ * Please use {@link resolveIdToValue}
74
+ *
75
+ * Tries to resolve the value of a node by traversing the dataflow graph
76
+ *
77
+ * @param id - node to resolve
78
+ * @param graph - dataflow graph
79
+ * @param idMap - idmap of dataflow graph
80
+ * @returns Value of node or Top/Bottom
81
+ */
82
+ export declare function trackAliasesInGraph(id: NodeId, graph: DataflowGraph, idMap?: AstIdMap): ResolveResult;
83
+ /**
84
+ * Please use {@link resolveIdToValue}
85
+ *
86
+ * Resolve an Identifier to a constant, if the identifier is a constant
87
+ *
88
+ * @param name - Identifier to resolve
89
+ * @param environment - Environment to use
90
+ * @returns Value of Constant or Top
91
+ */
92
+ export declare function resolveToConstants(name: Identifier | undefined, environment: REnvironmentInformation): ResolveResult;