@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
@@ -0,0 +1,352 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAliases = getAliases;
4
+ exports.resolveIdToValue = resolveIdToValue;
5
+ exports.trackAliasInEnvironments = trackAliasInEnvironments;
6
+ exports.trackAliasesInGraph = trackAliasesInGraph;
7
+ exports.resolveToConstants = resolveToConstants;
8
+ const config_1 = require("../../../config");
9
+ const node_id_1 = require("../../../r-bridge/lang-4.x/ast/model/processing/node-id");
10
+ const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
11
+ const fingerprint_1 = require("../../../slicing/static/fingerprint");
12
+ const visiting_queue_1 = require("../../../slicing/static/visiting-queue");
13
+ const assert_1 = require("../../../util/assert");
14
+ const environment_1 = require("../../environments/environment");
15
+ const identifier_1 = require("../../environments/identifier");
16
+ const resolve_by_name_1 = require("../../environments/resolve-by-name");
17
+ const edge_1 = require("../../graph/edge");
18
+ const unknown_replacement_1 = require("../../graph/unknown-replacement");
19
+ const unknown_side_effect_1 = require("../../graph/unknown-side-effect");
20
+ const vertex_1 = require("../../graph/vertex");
21
+ const general_1 = require("../values/general");
22
+ const r_value_1 = require("../values/r-value");
23
+ const set_constants_1 = require("../values/sets/set-constants");
24
+ const resolve_1 = require("./resolve");
25
+ const AliasHandler = {
26
+ [vertex_1.VertexType.Value]: (sourceId) => [sourceId],
27
+ [vertex_1.VertexType.Use]: getUseAlias,
28
+ [vertex_1.VertexType.FunctionCall]: getFunctionCallAlias,
29
+ [vertex_1.VertexType.FunctionDefinition]: () => undefined,
30
+ [vertex_1.VertexType.VariableDefinition]: () => undefined
31
+ };
32
+ function getFunctionCallAlias(sourceId, dataflow, environment) {
33
+ const identifier = (0, node_id_1.recoverName)(sourceId, dataflow.idMap);
34
+ if (identifier === undefined) {
35
+ return undefined;
36
+ }
37
+ const defs = (0, resolve_by_name_1.resolveByName)(identifier, environment, identifier_1.ReferenceType.Function);
38
+ if (defs === undefined || defs.length !== 1) {
39
+ return undefined;
40
+ }
41
+ return [sourceId];
42
+ }
43
+ function getUseAlias(sourceId, dataflow, environment) {
44
+ const definitions = [];
45
+ // Source is Symbol -> resolve definitions of symbol
46
+ const identifier = (0, node_id_1.recoverName)(sourceId, dataflow.idMap);
47
+ if (identifier === undefined) {
48
+ return undefined;
49
+ }
50
+ const defs = (0, resolve_by_name_1.resolveByName)(identifier, environment);
51
+ if (defs === undefined) {
52
+ return undefined;
53
+ }
54
+ for (const def of defs) {
55
+ // If one definition is not constant (or a variable aliasing a constant)
56
+ // we can't say for sure what value the source has
57
+ if (def.type === identifier_1.ReferenceType.Variable) {
58
+ if (def.value === undefined) {
59
+ return undefined;
60
+ }
61
+ definitions.push(...def.value);
62
+ }
63
+ else if (def.type === identifier_1.ReferenceType.Constant || def.type === identifier_1.ReferenceType.BuiltInConstant) {
64
+ definitions.push(def.nodeId);
65
+ }
66
+ else {
67
+ return undefined;
68
+ }
69
+ }
70
+ return definitions;
71
+ }
72
+ /**
73
+ * Gets the definitions / aliases of a node
74
+ *
75
+ * This function is called by the built-in-assignment processor so that we can
76
+ * track assignments inside the environment. The returned ids are stored in
77
+ * the sourceIds value field of their InGraphIdentifierDefinition. This enables
78
+ * us later, in the {@link trackAliasInEnvironments} function, to get all the
79
+ * aliases of an identifier.
80
+ *
81
+ * @param sourceIds - node ids to get the definitions for
82
+ * @param dataflow - dataflow graph
83
+ * @param environment - environment
84
+ * @returns node id of alias
85
+ */
86
+ function getAliases(sourceIds, dataflow, environment) {
87
+ const definitions = new Set();
88
+ for (const sourceId of sourceIds) {
89
+ const info = dataflow.getVertex(sourceId);
90
+ if (info === undefined) {
91
+ return undefined;
92
+ }
93
+ const defs = AliasHandler[info.tag](sourceId, dataflow, environment);
94
+ for (const def of defs ?? []) {
95
+ definitions.add(def);
96
+ }
97
+ }
98
+ return [...definitions];
99
+ }
100
+ /**
101
+ * Evaluates the value of a node in the set domain.
102
+ *
103
+ * resolveIdToValue tries to resolve the value using the data it has been given.
104
+ * If the environment is provided the approximation is more precise, as we can
105
+ * track aliases in the environment.
106
+ * Otherwise, the graph is used to try and resolve the nodes value.
107
+ * If neither is provided the value cannot be resolved.
108
+ *
109
+ * This function is also used by the Resolve Value Query and the Dependency Query
110
+ * to resolve values. For e.g. in the Dependency Query it is used to resolve calls
111
+ * like `lapply(c("a", "b", "c"), library, character.only = TRUE)`
112
+ *
113
+ * @param id - The node id or node to resolve
114
+ * @param environment - The current environment used for name resolution
115
+ * @param graph - The graph to resolve in
116
+ * @param idMap - The id map to resolve the node if given as an id
117
+ * @param full - Whether to track aliases on resolve
118
+ * @param resolve - Variable resolve mode
119
+ */
120
+ function resolveIdToValue(id, { environment, graph, idMap, full = true, resolve }) {
121
+ if (id === undefined) {
122
+ return r_value_1.Top;
123
+ }
124
+ idMap ??= graph?.idMap;
125
+ const node = typeof id === 'object' ? id : idMap?.get(id);
126
+ if (node === undefined) {
127
+ return r_value_1.Top;
128
+ }
129
+ switch (node.type) {
130
+ case type_1.RType.Argument:
131
+ case type_1.RType.Symbol:
132
+ if (environment) {
133
+ return full ? trackAliasInEnvironments(resolve, node.lexeme, environment, graph, idMap) : r_value_1.Top;
134
+ }
135
+ else if (graph && resolve === config_1.VariableResolve.Alias) {
136
+ return full ? trackAliasesInGraph(node.info.id, graph, idMap) : r_value_1.Top;
137
+ }
138
+ else {
139
+ return r_value_1.Top;
140
+ }
141
+ case type_1.RType.FunctionCall:
142
+ return (0, set_constants_1.setFrom)((0, resolve_1.resolveNode)(resolve, node, environment, graph, idMap));
143
+ case type_1.RType.String:
144
+ case type_1.RType.Number:
145
+ case type_1.RType.Logical:
146
+ return (0, set_constants_1.setFrom)((0, general_1.valueFromRNodeConstant)(node));
147
+ default:
148
+ return r_value_1.Top;
149
+ }
150
+ }
151
+ /**
152
+ * Please use {@link resolveIdToValue}
153
+ *
154
+ * Uses the aliases that were tracked in the environments (by the
155
+ * {@link getAliases} function) to resolve a node to a value.
156
+ *
157
+ *
158
+ * @param resolve - Variable resolve mode
159
+ * @param identifier - Identifier to resolve
160
+ * @param use - Environment to use
161
+ * @param graph - Dataflow graph
162
+ * @param idMap - id map of Dataflow graph
163
+ * @returns Value of Identifier or Top
164
+ */
165
+ function trackAliasInEnvironments(resolve, identifier, use, graph, idMap) {
166
+ if (identifier === undefined) {
167
+ return r_value_1.Top;
168
+ }
169
+ const defs = (0, resolve_by_name_1.resolveByName)(identifier, use);
170
+ if (defs === undefined) {
171
+ return r_value_1.Top;
172
+ }
173
+ const values = new Set();
174
+ for (const def of defs) {
175
+ if (def.type === identifier_1.ReferenceType.BuiltInConstant) {
176
+ values.add((0, general_1.valueFromTsValue)(def.value));
177
+ }
178
+ else if (def.type === identifier_1.ReferenceType.BuiltInFunction) {
179
+ // Tracked in #1207
180
+ }
181
+ else if (def.value !== undefined) {
182
+ /* if there is at least one location for which we have no idea, we have to give up for now! */
183
+ if (def.value.length === 0) {
184
+ return r_value_1.Top;
185
+ }
186
+ for (const alias of def.value) {
187
+ const definitionOfAlias = idMap?.get(alias);
188
+ if (definitionOfAlias !== undefined) {
189
+ const value = (0, resolve_1.resolveNode)(resolve, definitionOfAlias, use, graph, idMap);
190
+ if ((0, r_value_1.isTop)(value)) {
191
+ return r_value_1.Top;
192
+ }
193
+ values.add(value);
194
+ }
195
+ }
196
+ }
197
+ }
198
+ if (values.size == 0) {
199
+ return r_value_1.Top;
200
+ }
201
+ return (0, set_constants_1.setFrom)(...values);
202
+ }
203
+ /** given an unknown alias, we have to clear all values in the environments */
204
+ (0, unknown_side_effect_1.onUnknownSideEffect)((_graph, env, _id, target) => {
205
+ if (target) {
206
+ return;
207
+ }
208
+ let current = env.current;
209
+ while (current) {
210
+ current.memory.forEach(mem => mem.forEach((def) => {
211
+ if (def.type !== identifier_1.ReferenceType.BuiltInConstant
212
+ && def.type !== identifier_1.ReferenceType.BuiltInFunction
213
+ && def.value !== undefined) {
214
+ def.value.length = 0;
215
+ }
216
+ }));
217
+ current = current.parent;
218
+ }
219
+ });
220
+ (0, unknown_replacement_1.onReplacementOperator)((args) => {
221
+ if (!args.target) {
222
+ return;
223
+ }
224
+ let current = args.env.current;
225
+ while (current) {
226
+ const defs = current.memory.get(args.target);
227
+ defs?.forEach(def => {
228
+ if (def.type !== identifier_1.ReferenceType.BuiltInConstant
229
+ && def.type !== identifier_1.ReferenceType.BuiltInFunction
230
+ && def.value !== undefined) {
231
+ def.value.length = 0;
232
+ }
233
+ });
234
+ current = current.parent;
235
+ }
236
+ });
237
+ function isNestedInLoop(node, ast) {
238
+ const parent = node?.info.parent;
239
+ if (node === undefined || !parent) {
240
+ return false;
241
+ }
242
+ const parentNode = ast.get(parent);
243
+ if (parentNode === undefined) {
244
+ return false;
245
+ }
246
+ if (parentNode.type === type_1.RType.WhileLoop || parentNode.type === type_1.RType.RepeatLoop) {
247
+ return true;
248
+ }
249
+ return isNestedInLoop(parentNode, ast);
250
+ }
251
+ /**
252
+ * Please use {@link resolveIdToValue}
253
+ *
254
+ * Tries to resolve the value of a node by traversing the dataflow graph
255
+ *
256
+ * @param id - node to resolve
257
+ * @param graph - dataflow graph
258
+ * @param idMap - idmap of dataflow graph
259
+ * @returns Value of node or Top/Bottom
260
+ */
261
+ function trackAliasesInGraph(id, graph, idMap) {
262
+ idMap ??= graph.idMap;
263
+ (0, assert_1.guard)(idMap !== undefined, 'The ID map is required to get the lineage of a node');
264
+ const start = graph.getVertex(id);
265
+ (0, assert_1.guard)(start !== undefined, 'Unable to find start for alias tracking');
266
+ const queue = new visiting_queue_1.VisitingQueue(25);
267
+ const clean = (0, environment_1.initializeCleanEnvironments)();
268
+ const cleanFingerprint = (0, fingerprint_1.envFingerprint)(clean);
269
+ queue.add(id, clean, cleanFingerprint, false);
270
+ let forceBot = false;
271
+ const resultIds = [];
272
+ while (queue.nonEmpty()) {
273
+ const { id, baseEnvironment } = queue.next();
274
+ const res = graph.get(id);
275
+ if (!res) {
276
+ continue;
277
+ }
278
+ const [vertex, outgoingEdges] = res;
279
+ const cds = vertex.cds;
280
+ for (const cd of cds ?? []) {
281
+ const target = graph.idMap?.get(cd.id);
282
+ if (target === undefined) {
283
+ continue;
284
+ }
285
+ if (target.type === type_1.RType.WhileLoop || target.type === type_1.RType.RepeatLoop) {
286
+ forceBot = true;
287
+ break;
288
+ }
289
+ }
290
+ if (!forceBot && (cds?.length === 0 && isNestedInLoop(idMap.get(id), idMap))) {
291
+ forceBot = true;
292
+ }
293
+ if (forceBot) {
294
+ break;
295
+ }
296
+ if (vertex.tag === vertex_1.VertexType.Value) {
297
+ resultIds.push(id);
298
+ continue;
299
+ }
300
+ else if (vertex.tag === vertex_1.VertexType.FunctionDefinition) {
301
+ resultIds.push(id);
302
+ continue;
303
+ }
304
+ const isFn = vertex.tag === vertex_1.VertexType.FunctionCall;
305
+ // travel all read and defined-by edges
306
+ for (const [targetId, edge] of outgoingEdges) {
307
+ if (isFn) {
308
+ if (edge.types === edge_1.EdgeType.Returns || edge.types === edge_1.EdgeType.DefinedByOnCall || edge.types === edge_1.EdgeType.DefinedBy) {
309
+ queue.add(targetId, baseEnvironment, cleanFingerprint, false);
310
+ }
311
+ continue;
312
+ }
313
+ // currently, they have to be exact!
314
+ if (edge.types === edge_1.EdgeType.Reads || edge.types === edge_1.EdgeType.DefinedBy || edge.types === edge_1.EdgeType.DefinedByOnCall) {
315
+ queue.add(targetId, baseEnvironment, cleanFingerprint, false);
316
+ }
317
+ }
318
+ }
319
+ if (forceBot || resultIds.length === 0) {
320
+ return r_value_1.Bottom;
321
+ }
322
+ const values = new Set();
323
+ for (const id of resultIds) {
324
+ const node = idMap.get(id);
325
+ if (node !== undefined) {
326
+ values.add((0, general_1.valueFromRNodeConstant)(node));
327
+ }
328
+ }
329
+ return (0, set_constants_1.setFrom)(...values);
330
+ }
331
+ /**
332
+ * Please use {@link resolveIdToValue}
333
+ *
334
+ * Resolve an Identifier to a constant, if the identifier is a constant
335
+ *
336
+ * @param name - Identifier to resolve
337
+ * @param environment - Environment to use
338
+ * @returns Value of Constant or Top
339
+ */
340
+ function resolveToConstants(name, environment) {
341
+ if (name === undefined) {
342
+ return r_value_1.Top;
343
+ }
344
+ const definitions = (0, resolve_by_name_1.resolveByName)(name, environment, identifier_1.ReferenceType.Constant);
345
+ if (definitions === undefined) {
346
+ return r_value_1.Top;
347
+ }
348
+ const values = new Set();
349
+ definitions.forEach(def => values.add((0, general_1.valueFromTsValue)(def.value ?? r_value_1.Top)));
350
+ return (0, set_constants_1.setFrom)(...values);
351
+ }
352
+ //# sourceMappingURL=alias-tracking.js.map
@@ -0,0 +1,8 @@
1
+ import type { DataflowGraph } from '../../graph/graph';
2
+ import type { DataflowGraphVertexFunctionCall } from '../../graph/vertex';
3
+ import type { NodeId } from '../../../r-bridge/lang-4.x/ast/model/processing/node-id';
4
+ import type { VariableResolve } from '../../../config';
5
+ /**
6
+ * Get the values of all arguments matching the criteria.
7
+ */
8
+ export declare function getArgumentStringValue(variableResolve: VariableResolve, graph: DataflowGraph, vertex: DataflowGraphVertexFunctionCall, argumentIndex: number | 'unnamed' | undefined, argumentName: string | undefined, resolveValue: boolean | 'library' | undefined): Map<NodeId, Set<string | undefined>> | undefined;
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getArgumentStringValue = getArgumentStringValue;
4
+ const graph_1 = require("../../graph/graph");
5
+ const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
6
+ const assert_1 = require("../../../util/assert");
7
+ const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
8
+ const dependencies_query_format_1 = require("../../../queries/catalog/dependencies-query/dependencies-query-format");
9
+ const general_1 = require("../values/general");
10
+ const alias_tracking_1 = require("./alias-tracking");
11
+ const r_value_1 = require("../values/r-value");
12
+ const convert_values_1 = require("../../../r-bridge/lang-4.x/convert-values");
13
+ const string_constants_1 = require("../values/string/string-constants");
14
+ /**
15
+ * Get the values of all arguments matching the criteria.
16
+ */
17
+ function getArgumentStringValue(variableResolve, graph, vertex, argumentIndex, argumentName, resolveValue) {
18
+ if (argumentName) {
19
+ const arg = vertex?.args.findIndex(arg => arg !== r_function_call_1.EmptyArgument && arg.name === argumentName);
20
+ if (arg >= 0) {
21
+ argumentIndex = arg;
22
+ }
23
+ }
24
+ if (!vertex || argumentIndex === undefined) {
25
+ return undefined;
26
+ }
27
+ if (argumentIndex === 'unnamed') {
28
+ // return all unnamed arguments
29
+ const references = vertex.args.filter(arg => arg !== r_function_call_1.EmptyArgument && !arg.name).map(graph_1.getReferenceOfArgument).filter(assert_1.isNotUndefined);
30
+ const map = new Map();
31
+ for (const ref of references) {
32
+ let valueNode = graph.idMap?.get(ref);
33
+ if (valueNode?.type === type_1.RType.Argument) {
34
+ valueNode = valueNode.value;
35
+ }
36
+ if (valueNode) {
37
+ // this should be evaluated in the callee-context
38
+ const values = resolveBasedOnConfig(variableResolve, graph, vertex, valueNode, vertex.environment, graph.idMap, resolveValue) ?? [dependencies_query_format_1.Unknown];
39
+ map.set(ref, new Set(values));
40
+ }
41
+ }
42
+ return map;
43
+ }
44
+ if (argumentIndex < vertex.args.length) {
45
+ const arg = (0, graph_1.getReferenceOfArgument)(vertex.args[argumentIndex]);
46
+ if (!arg) {
47
+ return undefined;
48
+ }
49
+ let valueNode = graph.idMap?.get(arg);
50
+ if (valueNode?.type === type_1.RType.Argument) {
51
+ valueNode = valueNode.value;
52
+ }
53
+ if (valueNode) {
54
+ const values = resolveBasedOnConfig(variableResolve, graph, vertex, valueNode, vertex.environment, graph.idMap, resolveValue) ?? [dependencies_query_format_1.Unknown];
55
+ return new Map([[arg, new Set(values)]]);
56
+ }
57
+ }
58
+ return undefined;
59
+ }
60
+ function hasCharacterOnly(variableResolve, graph, vertex, idMap) {
61
+ if (!vertex.args || vertex.args.length === 0 || !idMap) {
62
+ return false;
63
+ }
64
+ const treatAsChar = getArgumentStringValue(variableResolve, graph, vertex, 5, 'character.only', true);
65
+ if (!treatAsChar) {
66
+ return false;
67
+ }
68
+ const hasTrue = [...treatAsChar.values()].some(set => set?.has('TRUE'));
69
+ const hasFalse = hasTrue ? [...treatAsChar.values()].some(set => set === undefined || set.has('FALSE')) : false;
70
+ if (hasTrue && hasFalse) {
71
+ return 'maybe';
72
+ }
73
+ else {
74
+ return hasTrue;
75
+ }
76
+ }
77
+ function resolveBasedOnConfig(variableResolve, graph, vertex, argument, environment, idMap, resolveValue) {
78
+ let full = true;
79
+ if (!resolveValue) {
80
+ full = false;
81
+ }
82
+ if (resolveValue === 'library') {
83
+ const hasChar = hasCharacterOnly(variableResolve, graph, vertex, idMap);
84
+ if (hasChar === false) {
85
+ if (argument.type === type_1.RType.Symbol) {
86
+ return [argument.lexeme];
87
+ }
88
+ full = false;
89
+ }
90
+ }
91
+ const resolved = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(argument, { environment, graph, full, resolve: variableResolve }));
92
+ if (resolved) {
93
+ const values = [];
94
+ for (const value of resolved.elements) {
95
+ if (!(0, r_value_1.isValue)(value)) {
96
+ return undefined;
97
+ }
98
+ else if (value.type === 'string' && (0, r_value_1.isValue)(value.value)) {
99
+ values.push(value.value.str);
100
+ }
101
+ else if (value.type === 'logical' && (0, r_value_1.isValue)(value.value)) {
102
+ values.push(value.value.valueOf() ? convert_values_1.RTrue : convert_values_1.RFalse);
103
+ }
104
+ else if (value.type === 'vector' && (0, r_value_1.isValue)(value.elements)) {
105
+ const elements = (0, string_constants_1.collectStrings)(value.elements, !full);
106
+ if (elements === undefined) {
107
+ return undefined;
108
+ }
109
+ values.push(...elements);
110
+ }
111
+ else {
112
+ return undefined;
113
+ }
114
+ }
115
+ return values;
116
+ }
117
+ }
118
+ //# sourceMappingURL=resolve-argument.js.map
@@ -0,0 +1,37 @@
1
+ import type { AstIdMap, RNodeWithParent } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
2
+ import type { REnvironmentInformation } from '../../environments/environment';
3
+ import type { DataflowGraph } from '../../graph/graph';
4
+ import type { Value } from '../values/r-value';
5
+ import type { VariableResolve } from '../../../config';
6
+ /**
7
+ * Helper function used by {@link resolveIdToValue}, please use that instead, if
8
+ * you want to resolve the value of an identifier / node
9
+ *
10
+ * This function converts an RNode to its Value, but also recursively resolves
11
+ * aliases and vectors (in case of a vector).
12
+ *
13
+ * @param a - Ast node to resolve
14
+ * @param resolve - Variable resolve mode
15
+ * @param env - Environment to use
16
+ * @param graph - Dataflow Graph to use
17
+ * @param map - Idmap of Dataflow Graph
18
+ * @returns resolved value or top/bottom
19
+ */
20
+ export declare function resolveNode(resolve: VariableResolve, a: RNodeWithParent, env?: REnvironmentInformation, graph?: DataflowGraph, map?: AstIdMap): Value;
21
+ /**
22
+ * Helper function used by {@link resolveIdToValue}, please use that instead, if
23
+ * you want to resolve the value of an identifier / node
24
+ *
25
+ * This function converts an r-node to a Value Vector {@link vectorFrom}
26
+ * It also recursively resolves any symbols, values, function calls (only c), in
27
+ * order to construct the value of the vector to resolve by calling {@link resolveIdToValue}
28
+ * or {@link resolveNode}
29
+ *
30
+ * @param a - Node of the vector to resolve
31
+ * @param env - Environment to use
32
+ * @param resolve - Variable resolve mode
33
+ * @param graph - Dataflow graph
34
+ * @param map - Idmap of Dataflow Graph
35
+ * @returns ValueVector or Top
36
+ */
37
+ export declare function resolveAsVector(resolve: VariableResolve, a: RNodeWithParent, env: REnvironmentInformation, graph?: DataflowGraph, map?: AstIdMap): Value;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveNode = resolveNode;
4
+ exports.resolveAsVector = resolveAsVector;
5
+ const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
6
+ const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
7
+ const assert_1 = require("../../../util/assert");
8
+ const built_in_1 = require("../../environments/built-in");
9
+ const dfg_get_origin_1 = require("../../origin/dfg-get-origin");
10
+ const interval_constants_1 = require("../values/intervals/interval-constants");
11
+ const logical_constants_1 = require("../values/logical/logical-constants");
12
+ const r_value_1 = require("../values/r-value");
13
+ const string_constants_1 = require("../values/string/string-constants");
14
+ const vector_constants_1 = require("../values/vectors/vector-constants");
15
+ const alias_tracking_1 = require("./alias-tracking");
16
+ /**
17
+ * Helper function used by {@link resolveIdToValue}, please use that instead, if
18
+ * you want to resolve the value of an identifier / node
19
+ *
20
+ * This function converts an RNode to its Value, but also recursively resolves
21
+ * aliases and vectors (in case of a vector).
22
+ *
23
+ * @param a - Ast node to resolve
24
+ * @param resolve - Variable resolve mode
25
+ * @param env - Environment to use
26
+ * @param graph - Dataflow Graph to use
27
+ * @param map - Idmap of Dataflow Graph
28
+ * @returns resolved value or top/bottom
29
+ */
30
+ function resolveNode(resolve, a, env, graph, map) {
31
+ if (a.type === type_1.RType.String) {
32
+ return (0, string_constants_1.stringFrom)(a.content.str);
33
+ }
34
+ else if (a.type === type_1.RType.Number) {
35
+ return (0, interval_constants_1.intervalFrom)(a.content.num, a.content.num);
36
+ }
37
+ else if (a.type === type_1.RType.Logical) {
38
+ return a.content.valueOf() ? logical_constants_1.ValueLogicalTrue : logical_constants_1.ValueLogicalFalse;
39
+ }
40
+ else if (a.type === type_1.RType.FunctionCall && env && graph) {
41
+ const origin = (0, dfg_get_origin_1.getOriginInDfg)(graph, a.info.id)?.[0];
42
+ if (origin === undefined || origin.type !== 3 /* OriginType.BuiltInFunctionOrigin */) {
43
+ return r_value_1.Top;
44
+ }
45
+ if (origin.proc in built_in_1.BuiltInEvalHandlerMapper) {
46
+ const handler = built_in_1.BuiltInEvalHandlerMapper[origin.proc];
47
+ return handler(resolve, a, env, graph, map);
48
+ }
49
+ }
50
+ return r_value_1.Top;
51
+ }
52
+ /**
53
+ * Helper function used by {@link resolveIdToValue}, please use that instead, if
54
+ * you want to resolve the value of an identifier / node
55
+ *
56
+ * This function converts an r-node to a Value Vector {@link vectorFrom}
57
+ * It also recursively resolves any symbols, values, function calls (only c), in
58
+ * order to construct the value of the vector to resolve by calling {@link resolveIdToValue}
59
+ * or {@link resolveNode}
60
+ *
61
+ * @param a - Node of the vector to resolve
62
+ * @param env - Environment to use
63
+ * @param resolve - Variable resolve mode
64
+ * @param graph - Dataflow graph
65
+ * @param map - Idmap of Dataflow Graph
66
+ * @returns ValueVector or Top
67
+ */
68
+ function resolveAsVector(resolve, a, env, graph, map) {
69
+ (0, assert_1.guard)(a.type === type_1.RType.FunctionCall);
70
+ const values = [];
71
+ for (const arg of a.arguments) {
72
+ if (arg === r_function_call_1.EmptyArgument) {
73
+ continue;
74
+ }
75
+ if (arg.value === undefined) {
76
+ return r_value_1.Top;
77
+ }
78
+ if (arg.value.type === type_1.RType.Symbol) {
79
+ const value = (0, alias_tracking_1.resolveIdToValue)(arg.info.id, { environment: env, idMap: map, graph: graph, full: true, resolve });
80
+ if ((0, r_value_1.isTop)(value)) {
81
+ return r_value_1.Top;
82
+ }
83
+ values.push(value);
84
+ }
85
+ else {
86
+ const val = resolveNode(resolve, arg.value, env, graph, map);
87
+ if ((0, r_value_1.isTop)(val)) {
88
+ return r_value_1.Top;
89
+ }
90
+ values.push(val);
91
+ }
92
+ }
93
+ return (0, vector_constants_1.vectorFrom)((0, vector_constants_1.flattenVectorElements)(values));
94
+ }
95
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1,27 @@
1
+ import type { RNodeWithParent } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
2
+ import type { Lift, Value, ValueSet } from './r-value';
3
+ import { Bottom, Top } from './r-value';
4
+ /**
5
+ * Takes n potentially lifted ops and returns `Top` or `Bottom` if any is `Top` or `Bottom`.
6
+ */
7
+ export declare function bottomTopGuard(...a: Lift<unknown>[]): typeof Top | typeof Bottom | undefined;
8
+ /**
9
+ * Returns a value set, if a is not bottom or top, otherwise undefined.
10
+ * Useful when working with values returned by {@link resolveIdToValue}
11
+ *
12
+ * @param a - value set to check
13
+ * @returns value set if a is not top or bottom
14
+ */
15
+ export declare function valueSetGuard(a: Lift<ValueSet<Value[]>>): ValueSet<Value[]> | undefined;
16
+ /**
17
+ * Constructs an Abstract Value from a normal TS value
18
+ * @param a - ts value
19
+ * @returns abstract value
20
+ */
21
+ export declare function valueFromTsValue(a: unknown): Value;
22
+ /**
23
+ * Converts a constant from an RNode into an abstract value
24
+ * @param a - RNode constant
25
+ * @returns abstract value
26
+ */
27
+ export declare function valueFromRNodeConstant(a: RNodeWithParent): Value;