@eagleoutice/flowr 2.15.9 → 2.16.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 (244) hide show
  1. package/README.md +47 -41
  2. package/abstract-interpretation/absint-inference.d.ts +2 -2
  3. package/abstract-interpretation/absint-inference.js +32 -79
  4. package/abstract-interpretation/data-frame/arguments.js +11 -7
  5. package/benchmark/slicer.d.ts +0 -1
  6. package/benchmark/slicer.js +1 -2
  7. package/cli/repl/commands/repl-signature.js +12 -3
  8. package/config.d.ts +5 -1
  9. package/control-flow/cfg-properties.js +0 -22
  10. package/control-flow/happens-before.d.ts +7 -2
  11. package/control-flow/happens-before.js +55 -31
  12. package/control-flow/useless-loop.d.ts +1 -1
  13. package/control-flow/useless-loop.js +29 -42
  14. package/dataflow/environments/apply-kill.js +6 -2
  15. package/dataflow/environments/built-in-config.d.ts +2 -0
  16. package/dataflow/environments/built-in-props.d.ts +16 -1
  17. package/dataflow/environments/built-in-props.js +33 -20
  18. package/dataflow/environments/built-in.d.ts +8 -3
  19. package/dataflow/environments/built-in.js +52 -82
  20. package/dataflow/environments/default-builtin-config.d.ts +551 -21
  21. package/dataflow/environments/default-builtin-config.js +121 -45
  22. package/dataflow/environments/define.d.ts +3 -2
  23. package/dataflow/environments/define.js +4 -3
  24. package/dataflow/environments/deprecation-info.d.ts +45 -0
  25. package/dataflow/environments/deprecation-info.js +13 -0
  26. package/dataflow/environments/environment.d.ts +7 -5
  27. package/dataflow/environments/environment.js +55 -121
  28. package/dataflow/environments/identifier.d.ts +6 -2
  29. package/dataflow/environments/identifier.js +23 -69
  30. package/dataflow/environments/reference-to-maybe.d.ts +9 -0
  31. package/dataflow/environments/reference-to-maybe.js +23 -51
  32. package/dataflow/environments/resolve-by-name.js +37 -76
  33. package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
  34. package/dataflow/eval/resolve/resolve-argument.js +61 -64
  35. package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
  36. package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
  37. package/dataflow/eval/resolve/resolve.d.ts +4 -0
  38. package/dataflow/eval/resolve/resolve.js +23 -14
  39. package/dataflow/extractor.js +180 -58
  40. package/dataflow/fn/class-declaration.d.ts +8 -13
  41. package/dataflow/fn/class-declaration.js +95 -116
  42. package/dataflow/fn/exceptions-of-function.js +68 -37
  43. package/dataflow/fn/frame-reflection.d.ts +12 -4
  44. package/dataflow/fn/frame-reflection.js +51 -41
  45. package/dataflow/fn/function-props.js +15 -33
  46. package/dataflow/fn/function-semantics.d.ts +11 -3
  47. package/dataflow/fn/function-semantics.js +6 -0
  48. package/dataflow/fn/higher-order-function.d.ts +9 -1
  49. package/dataflow/fn/higher-order-function.js +27 -24
  50. package/dataflow/fn/strict-function.d.ts +13 -0
  51. package/dataflow/fn/strict-function.js +291 -123
  52. package/dataflow/graph/call-graph.d.ts +7 -6
  53. package/dataflow/graph/call-graph.js +35 -46
  54. package/dataflow/graph/graph.d.ts +13 -1
  55. package/dataflow/graph/graph.js +74 -66
  56. package/dataflow/graph/vertex.d.ts +1 -1
  57. package/dataflow/info.d.ts +8 -1
  58. package/dataflow/info.js +24 -30
  59. package/dataflow/internal/control-flow.d.ts +31 -4
  60. package/dataflow/internal/control-flow.js +61 -39
  61. package/dataflow/internal/linker.d.ts +17 -8
  62. package/dataflow/internal/linker.js +286 -213
  63. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +179 -0
  64. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +874 -0
  65. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
  66. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +60 -48
  67. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +4 -2
  68. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +135 -198
  69. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
  70. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +5 -1
  71. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +21 -14
  72. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +14 -4
  73. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
  74. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +141 -146
  75. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +56 -24
  76. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +292 -253
  77. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
  78. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
  79. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
  80. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +91 -129
  81. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
  82. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +16 -12
  83. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
  84. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
  85. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -0
  86. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
  87. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +5 -3
  88. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +13 -31
  89. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
  90. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +42 -119
  91. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
  92. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +21 -21
  93. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
  94. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
  95. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
  96. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
  97. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
  98. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +23 -26
  99. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
  100. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
  101. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
  102. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +119 -93
  103. package/dataflow/internal/process/functions/call/common.d.ts +4 -4
  104. package/dataflow/internal/process/functions/call/common.js +49 -71
  105. package/dataflow/internal/process/functions/call/deferred.d.ts +12 -2
  106. package/dataflow/internal/process/functions/call/deferred.js +81 -63
  107. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
  108. package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
  109. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
  110. package/dataflow/internal/process/functions/call/named-call-handling.js +48 -19
  111. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
  112. package/dataflow/internal/process/functions/call/quoted.js +257 -154
  113. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
  114. package/dataflow/internal/process/functions/process-parameter.js +25 -32
  115. package/dataflow/internal/process/process-symbol.js +4 -3
  116. package/dataflow/internal/program-order.d.ts +26 -0
  117. package/dataflow/internal/program-order.js +49 -0
  118. package/documentation/data/faq/faqs.js +3 -3
  119. package/documentation/data/interface/doc-writing-code.js +1 -2
  120. package/documentation/data/server/doc-data-server-messages.js +7 -7
  121. package/documentation/doc-capabilities.js +80 -34
  122. package/documentation/doc-util/doc-query.d.ts +0 -3
  123. package/documentation/doc-util/doc-query.js +4 -3
  124. package/documentation/wiki-analyzer.js +1 -1
  125. package/documentation/wiki-cfg.js +5 -6
  126. package/documentation/wiki-core.js +8 -8
  127. package/documentation/wiki-dataflow-graph.js +10 -11
  128. package/documentation/wiki-interface.js +2 -2
  129. package/documentation/wiki-linting-and-testing.js +3 -3
  130. package/documentation/wiki-overview.js +6 -6
  131. package/documentation/wiki-query.js +9 -101
  132. package/documentation/wiki-setup.js +23 -0
  133. package/documentation/wiki-signature-database.js +1 -1
  134. package/linter/linter-rules.d.ts +18 -9
  135. package/linter/rules/absolute-path.js +63 -87
  136. package/linter/rules/deprecated-functions.d.ts +1 -45
  137. package/linter/rules/deprecated-functions.js +24 -33
  138. package/linter/rules/file-path-validity.d.ts +4 -2
  139. package/linter/rules/file-path-validity.js +114 -80
  140. package/linter/rules/namespace-access.js +21 -33
  141. package/linter/rules/naming-convention.d.ts +1 -1
  142. package/linter/rules/naming-convention.js +60 -48
  143. package/linter/rules/network-functions.js +11 -7
  144. package/linter/rules/no-leaked-credentials.js +15 -18
  145. package/linter/rules/problematic-inputs.d.ts +2 -1
  146. package/linter/rules/problematic-inputs.js +39 -59
  147. package/linter/rules/roxygen-arguments.d.ts +9 -4
  148. package/linter/rules/roxygen-arguments.js +29 -48
  149. package/linter/rules/seeded-randomness.d.ts +7 -4
  150. package/linter/rules/seeded-randomness.js +128 -89
  151. package/linter/rules/stop-with-call-arg.d.ts +4 -2
  152. package/linter/rules/stop-with-call-arg.js +25 -22
  153. package/linter/rules/unclosed-connection.js +31 -24
  154. package/linter/rules/undefined-symbol.d.ts +4 -6
  155. package/linter/rules/undefined-symbol.js +58 -75
  156. package/linter/rules/unescaped-arguments.js +18 -44
  157. package/linter/rules/unused-definition.d.ts +6 -0
  158. package/linter/rules/unused-definition.js +105 -145
  159. package/linter/rules/unused-import.d.ts +3 -0
  160. package/linter/rules/unused-import.js +25 -43
  161. package/package.json +5 -2
  162. package/project/flowr-analyzer.d.ts +2 -0
  163. package/project/flowr-analyzer.js +28 -1
  164. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
  165. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
  166. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +0 -2
  167. package/project/plugins/file-plugins/files/flowr-rda-file.js +10 -55
  168. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
  169. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
  170. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -1
  171. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +22 -45
  172. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -2
  173. package/project/sigdb/build.js +4 -0
  174. package/project/sigdb/manifest.d.ts +2 -0
  175. package/project/sigdb/manifest.js +10 -1
  176. package/project/sigdb/reader.js +23 -61
  177. package/project/sigdb/sigdb-download.d.ts +29 -6
  178. package/project/sigdb/sigdb-download.js +212 -64
  179. package/queries/base-query-format.js +1 -2
  180. package/queries/catalog/absint-query/absint-query-format.js +1 -1
  181. package/queries/catalog/call-context-query/cascade-action.d.ts +3 -1
  182. package/queries/catalog/call-context-query/cascade-action.js +2 -0
  183. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +3 -0
  184. package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
  185. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
  186. package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
  187. package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
  188. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
  189. package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
  190. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  191. package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
  192. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
  193. package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
  194. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-executor.js +2 -1
  195. package/queries/catalog/origin-query/origin-query-executor.d.ts +1 -1
  196. package/queries/catalog/origin-query/origin-query-executor.js +2 -2
  197. package/queries/catalog/origin-query/origin-query-format.d.ts +2 -2
  198. package/queries/catalog/origin-query/origin-query-format.js +1 -1
  199. package/queries/query.d.ts +1 -1
  200. package/r-bridge/data/data.d.ts +21 -14
  201. package/r-bridge/data/data.js +28 -20
  202. package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
  203. package/r-bridge/lang-4.x/ast/model/model.js +19 -43
  204. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  205. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
  206. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
  207. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  208. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  209. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  210. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  211. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  212. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  213. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  214. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  215. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  216. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  217. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  218. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  219. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  220. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  221. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  222. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  223. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  224. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  225. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  226. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
  227. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +11 -2
  228. package/r-bridge/roxygen2/roxygen-parse.js +28 -42
  229. package/r-bridge/shell.js +6 -0
  230. package/search/search-executor/search-enrichers.js +25 -37
  231. package/slicing/static/slice-call.d.ts +4 -3
  232. package/slicing/static/slice-call.js +56 -88
  233. package/slicing/static/static-slicer.js +115 -79
  234. package/slicing/static/visiting-queue.d.ts +4 -6
  235. package/slicing/static/visiting-queue.js +9 -13
  236. package/util/files.d.ts +2 -0
  237. package/util/files.js +3 -1
  238. package/util/mermaid/mermaid.js +6 -2
  239. package/util/proc.js +2 -1
  240. package/util/r-base-packages.d.ts +2 -0
  241. package/util/r-base-packages.js +23 -13
  242. package/util/text/playground-link.d.ts +12 -3
  243. package/util/text/playground-link.js +18 -27
  244. package/util/version.js +4 -10
@@ -5,13 +5,12 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.argForImpl = argForImpl;
8
- exports.argFor = argFor;
9
8
  exports.classDeclarationOfImpl = classDeclarationOfImpl;
10
9
  exports.declaredClassesImpl = declaredClassesImpl;
11
- exports.declaredClasses = declaredClasses;
12
10
  exports.superClassesOfImpl = superClassesOfImpl;
13
11
  exports.toSigClassesImpl = toSigClassesImpl;
14
- exports.toSigClasses = toSigClasses;
12
+ exports.s3DispatchClassesOf = s3DispatchClassesOf;
13
+ const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
15
14
  const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
16
15
  const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
17
16
  const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
@@ -21,6 +20,11 @@ const edge_1 = require("../graph/edge");
21
20
  const assert_1 = require("../../util/assert");
22
21
  const objects_1 = require("../../util/objects");
23
22
  const vertex_1 = require("../graph/vertex");
23
+ const built_in_proc_name_1 = require("../environments/built-in-proc-name");
24
+ const node_value_1 = require("../eval/resolve/node-value");
25
+ const string_constants_1 = require("../eval/values/string/string-constants");
26
+ const r_value_1 = require("../eval/values/r-value");
27
+ const frame_reflection_1 = require("./frame-reflection");
24
28
  /** the class name R uses to mark a class as non-instantiable */
25
29
  const VirtualClass = 'VIRTUAL';
26
30
  /** The argument `ref` names, by name when the call gives one and by position among the unnamed ones otherwise. */
@@ -28,46 +32,24 @@ function argForImpl(args, ref) {
28
32
  if (ref === undefined) {
29
33
  return undefined;
30
34
  }
31
- if (ref.name !== undefined) {
32
- const named = args.find(a => !r_argument_1.RArgument.isEmpty(a) && a.name?.content === ref.name);
33
- if (named !== undefined && !r_argument_1.RArgument.isEmpty(named)) {
34
- return named.value;
35
- }
35
+ const named = ref.name === undefined ? undefined : args.find(a => !r_argument_1.RArgument.isEmpty(a) && a.name?.content === ref.name);
36
+ if (named !== undefined) {
37
+ return r_argument_1.RArgument.valueOf(named);
36
38
  }
37
39
  if (ref.idx === undefined) {
38
40
  return undefined;
39
41
  }
40
- let pos = 0;
41
- for (const a of args) {
42
- if (r_argument_1.RArgument.isEmpty(a) || a.name !== undefined) {
43
- continue;
44
- }
45
- if (pos++ === ref.idx) {
46
- return a.value;
47
- }
48
- }
49
- return undefined;
50
- }
51
- /**
52
- * The argument `ref` names, by name when the call gives one and by position among the unnamed ones otherwise.
53
- * Exported so `built-in-s-four.ts` can drop its own copy of this instead of hand-rolling it again; that file
54
- * already imports {@link ClassArgRef} from here, so the reverse import would cycle.
55
- * @deprecated use {@link argForImpl} instead
56
- */
57
- function argFor(args, ref) {
58
- return argForImpl(args, ref);
42
+ const unnamed = args.filter(a => !r_argument_1.RArgument.isEmpty(a) && a.name === undefined);
43
+ return r_argument_1.RArgument.valueOf(unnamed[ref.idx]);
59
44
  }
60
45
  /** The string a node states literally, `undefined` for anything that is not a literal (a variable, a call, ...). */
61
46
  function literal(node) {
62
- return node !== undefined && r_string_1.RString.is(node) ? node.content.str : undefined;
47
+ return r_string_1.RString.is(node) ? node.content.str : undefined;
63
48
  }
64
49
  /** The character vector a node states: a literal, or the literals of a `c(...)`/`list(...)` around them. */
65
50
  function literalVector(node) {
66
51
  const values = [];
67
52
  const byVariable = [];
68
- if (node === undefined) {
69
- return { values, byVariable };
70
- }
71
53
  const collect = (n) => {
72
54
  const str = literal(n);
73
55
  if (str !== undefined) {
@@ -78,11 +60,7 @@ function literalVector(node) {
78
60
  byVariable.push(n.lexeme);
79
61
  }
80
62
  else if (r_function_call_1.RFunctionCall.isNamed(n)) {
81
- for (const arg of n.arguments) {
82
- if (!r_argument_1.RArgument.isEmpty(arg) && arg.value !== undefined) {
83
- collect(arg.value);
84
- }
85
- }
63
+ n.arguments.forEach(a => collect(r_argument_1.RArgument.valueOf(a)));
86
64
  }
87
65
  };
88
66
  collect(node);
@@ -93,14 +71,11 @@ function literalVector(node) {
93
71
  * element, plus the bare strings such a call may carry (an RC `fields = c("x", "y")`, or a `"VIRTUAL"` marker).
94
72
  */
95
73
  function membersOf(node, ref) {
96
- const members = [];
97
- let virtual = false;
98
- if (node === undefined) {
99
- return { members, virtual };
100
- }
101
74
  if (!r_function_call_1.RFunctionCall.isNamed(node)) {
102
- return { members, virtual: literal(node) === VirtualClass };
75
+ return { members: [], virtual: literal(node) === VirtualClass };
103
76
  }
77
+ const members = [];
78
+ let virtual = false;
104
79
  for (const arg of node.arguments) {
105
80
  if (r_argument_1.RArgument.isEmpty(arg) || arg.value === undefined) {
106
81
  continue;
@@ -133,15 +108,10 @@ function isTrue(node) {
133
108
  * An argument that resolves to no literal contributes a {@link ClassDeclaration.byVariable|by-variable} name, or nothing.
134
109
  */
135
110
  function classDeclarationOfImpl(config, args) {
136
- const byVariable = [];
137
111
  const nameNode = argForImpl(args, config.nameArg);
138
112
  const name = literal(nameNode);
139
- if (name === undefined && nameNode !== undefined && r_symbol_1.RSymbol.is(nameNode)) {
140
- byVariable.push(nameNode.lexeme);
141
- }
142
113
  const parents = literalVector(argForImpl(args, config.containsArg));
143
- byVariable.push(...parents.byVariable);
144
- const contains = parents.values.filter(c => c !== VirtualClass);
114
+ const byVariable = name === undefined && r_symbol_1.RSymbol.is(nameNode) ? [nameNode.lexeme, ...parents.byVariable] : parents.byVariable;
145
115
  let virtual = parents.values.includes(VirtualClass) || isTrue(argForImpl(args, config.virtualArg));
146
116
  const members = [];
147
117
  for (const ref of config.memberArgs ?? []) {
@@ -149,15 +119,14 @@ function classDeclarationOfImpl(config, args) {
149
119
  members.push(...found.members);
150
120
  virtual ||= found.virtual;
151
121
  }
152
- const union = config.unionArg === undefined ? undefined : literalVector(argForImpl(args, config.unionArg)).values;
153
- const prototype = config.prototypeArg === undefined ? []
154
- : membersOf(argForImpl(args, config.prototypeArg), config.prototypeArg).members.map(m => m.name);
122
+ const union = literalVector(argForImpl(args, config.unionArg)).values;
123
+ const prototype = membersOf(argForImpl(args, config.prototypeArg), config.prototypeArg ?? {}).members.map(m => m.name);
155
124
  /* a class union is virtual by construction: it exists to be extended, never to be instantiated */
156
- const isUnion = union !== undefined && union.length > 0;
125
+ const isUnion = union.length > 0;
157
126
  return (0, objects_1.compactRecord)({
158
127
  system: config.system,
159
128
  name,
160
- contains,
129
+ contains: parents.values.filter(c => c !== VirtualClass),
161
130
  members,
162
131
  virtual: virtual || isUnion ? true : undefined,
163
132
  union: isUnion ? union : undefined,
@@ -169,65 +138,54 @@ function classDeclarationOfImpl(config, args) {
169
138
  /** Every class the graph declares, keyed by name. A later declaration of the same name wins, as it would in R. */
170
139
  function declaredClassesImpl(graph) {
171
140
  const classes = new Map();
172
- for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
173
- const decl = vertex.classDecl;
174
- if (decl?.name === undefined || decl.relation !== undefined) {
175
- continue;
141
+ for (const [id, { classDecl }] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
142
+ if (classDecl?.name !== undefined && classDecl.relation === undefined) {
143
+ classes.set(classDecl.name, { ...classDecl, id, name: classDecl.name });
176
144
  }
177
- classes.set(decl.name, { ...decl, id, name: decl.name });
178
145
  }
146
+ const addSuper = (sub, sup) => {
147
+ const existing = classes.get(sub);
148
+ if (existing !== undefined && sup !== undefined && !existing.contains.includes(sup)) {
149
+ classes.set(sub, { ...existing, contains: [...existing.contains, sup] });
150
+ }
151
+ };
179
152
  /* R6 and S7 name their parent by the generator *variable*, so `Employee <- R6Class(inherit = Person)`
180
153
  only says "Person"; the assignment that bound the generator says which class that is */
181
154
  const byGenerator = generatorVariables(graph, classes);
182
155
  for (const [name, declared] of classes) {
183
- const resolved = declared.byVariable.map(v => byGenerator.get(v)).filter(assert_1.isNotUndefined)
184
- .filter(c => c !== name && !declared.contains.includes(c));
185
- if (resolved.length > 0) {
186
- classes.set(name, { ...declared, contains: [...declared.contains, ...resolved] });
156
+ for (const sup of declared.byVariable.map(v => byGenerator.get(v))) {
157
+ if (sup !== name) {
158
+ addSuper(name, sup);
159
+ }
187
160
  }
188
161
  }
189
- /* a `setClassUnion` states its members as subclasses, which is the same fact written the other way round */
190
- for (const [, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
191
- const decl = vertex.classDecl;
192
- if (decl?.name === undefined) {
162
+ for (const [, { classDecl }] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
163
+ if (classDecl?.name === undefined) {
193
164
  continue;
194
165
  }
195
- for (const member of decl.union ?? []) {
196
- const existing = classes.get(member);
197
- if (existing !== undefined && !existing.contains.includes(decl.name)) {
198
- classes.set(member, { ...existing, contains: [...existing.contains, decl.name] });
199
- }
166
+ /* a `setClassUnion` states its members as subclasses, which is the same fact written the other way round */
167
+ for (const member of classDecl.union ?? []) {
168
+ addSuper(member, classDecl.name);
200
169
  }
201
170
  /* `setIs(class1, class2)` states the same is-a relation `contains` does */
202
- if (decl.relation === 'is') {
203
- const [sub, sup] = [decl.name, decl.contains[0]];
204
- const existing = classes.get(sub);
205
- if (existing !== undefined && sup !== undefined && !existing.contains.includes(sup)) {
206
- classes.set(sub, { ...existing, contains: [...existing.contains, sup] });
207
- }
171
+ if (classDecl.relation === 'is') {
172
+ addSuper(classDecl.name, classDecl.contains[0]);
208
173
  }
209
174
  }
210
175
  return classes;
211
176
  }
212
- /** @deprecated use {@link declaredClassesImpl} instead */
213
- function declaredClasses(graph) {
214
- return declaredClassesImpl(graph);
215
- }
216
177
  /** Variable name to the class its generator declares, for the `Cls <- R6Class(...)`/`Cls <- new_class(...)` bindings. */
217
178
  function generatorVariables(graph, classes) {
218
- const byName = new Map();
219
- for (const declared of classes.values()) {
220
- byName.set(declared.id, declared.name);
221
- }
179
+ const classOfId = new Map(classes.values().map(d => [d.id, d.name]));
222
180
  const generators = new Map();
223
181
  for (const [id] of graph.verticesOfType(vertex_1.VertexType.VariableDefinition)) {
224
182
  const lexeme = graph.idMap?.get(id)?.lexeme;
225
183
  if (lexeme === undefined) {
226
184
  continue;
227
185
  }
228
- for (const [target, edge] of graph.edgesFrom(id)) {
229
- const cls = byName.get(target);
230
- if (cls !== undefined && edge_1.DfEdge.includesType(edge, edge_1.EdgeType.DefinedBy)) {
186
+ for (const target of (0, frame_reflection_1.edgeTargets)(graph, id, edge_1.EdgeType.DefinedBy)) {
187
+ const cls = classOfId.get(target);
188
+ if (cls !== undefined) {
231
189
  generators.set(lexeme, cls);
232
190
  }
233
191
  }
@@ -239,54 +197,75 @@ function generatorVariables(graph, classes) {
239
197
  * analysis never saw declared ends the chain, so what another package contributes is simply not in the answer.
240
198
  */
241
199
  function superClassesOfImpl(name, classes) {
242
- const chain = [];
243
200
  const seen = new Set([name]);
244
- const queue = [...(classes.get(name)?.contains ?? [])];
245
- while (queue.length > 0) {
246
- const next = queue.shift();
247
- if (seen.has(next)) {
248
- continue;
201
+ /* a set iteration also visits what is added during it, so this walks the hierarchy breadth first */
202
+ for (const next of seen) {
203
+ for (const sup of classes.get(next)?.contains ?? []) {
204
+ seen.add(sup);
249
205
  }
250
- seen.add(next);
251
- chain.push(next);
252
- queue.push(...(classes.get(next)?.contains ?? []));
253
206
  }
254
- return chain;
207
+ seen.delete(name);
208
+ return [...seen];
255
209
  }
256
210
  /**
257
211
  * The {@link SigClassInfo} records the signature database stores for the classes an analysis found. A class
258
212
  * the analysis declared carries no `package`; a referenced class `ownerOf` can place becomes a `foreign` record.
259
213
  */
260
214
  function toSigClassesImpl(classes, ownerOf) {
261
- const records = [];
262
- for (const declared of classes.values()) {
263
- records.push((0, objects_1.compactRecord)({
264
- name: declared.name,
265
- system: declared.system,
266
- supers: declared.union ?? declared.contains,
267
- slots: declared.members.filter(m => !m.method).map(m => (0, objects_1.compactRecord)({ name: m.name, type: m.type })),
268
- virtual: declared.virtual ? true : undefined,
269
- union: declared.union !== undefined ? true : undefined
270
- }));
271
- }
215
+ const records = classes.values().map(declared => (0, objects_1.compactRecord)({
216
+ name: declared.name,
217
+ system: declared.system,
218
+ supers: declared.union ?? declared.contains,
219
+ slots: declared.members.filter(m => !m.method).map(m => (0, objects_1.compactRecord)({ name: m.name, type: m.type })),
220
+ virtual: declared.virtual ? true : undefined,
221
+ union: declared.union !== undefined ? true : undefined
222
+ })).toArray();
272
223
  if (ownerOf === undefined) {
273
224
  return records;
274
225
  }
275
226
  /* a superclass the analysis never declared belongs to whoever does define it, which is what makes an
276
227
  inherited class distinguishable from one the package owns */
277
228
  for (const referenced of new Set(records.flatMap(r => r.supers))) {
278
- if (classes.has(referenced)) {
279
- continue;
280
- }
281
- const owner = ownerOf(referenced);
229
+ const owner = classes.has(referenced) ? undefined : ownerOf(referenced);
282
230
  if (owner !== undefined) {
283
231
  records.push({ name: referenced, system: 's4', supers: [], slots: [], package: owner });
284
232
  }
285
233
  }
286
234
  return records;
287
235
  }
288
- /** @deprecated use {@link toSigClassesImpl} instead */
289
- function toSigClasses(classes, ownerOf) {
290
- return toSigClassesImpl(classes, ownerOf);
236
+ /** The class vector S3 dispatch sees for the value at `id`: a `structure(..., class = )` or a constant, `undefined` if not statically known. */
237
+ function s3ClassOfValue(id, info) {
238
+ const node = info.idMap.get(id);
239
+ if (r_function_call_1.RFunctionCall.is(node) && (0, frame_reflection_1.hasEdgeOfType)(info.graph, id, node_id_1.NodeId.toBuiltIn('structure'), edge_1.EdgeType.Calls)) {
240
+ const cls = node_value_1.NodeValue.soleOf(argForImpl(node.arguments, { name: 'class' }), info);
241
+ const strings = cls?.type === 'string' ? (0, string_constants_1.collectStrings)([cls]) : cls?.type === 'vector' && (0, r_value_1.isValue)(cls.elements) ? (0, string_constants_1.collectStrings)(cls.elements) : undefined;
242
+ return strings?.length ? strings : undefined;
243
+ }
244
+ const value = node_value_1.NodeValue.soleOf(id, info);
245
+ if (value?.type === 'string') {
246
+ return ['character'];
247
+ }
248
+ else if (value?.type === 'logical') {
249
+ return ['logical'];
250
+ }
251
+ else if (value?.type === 'number' && (0, r_value_1.isValue)(value.value)) {
252
+ return value.value.complexNumber ? ['complex'] : value.value.markedAsInt ? ['integer', 'numeric'] : ['double', 'numeric'];
253
+ }
254
+ return undefined;
255
+ }
256
+ /** The value a plain assignment binds to the definition `def`, `undefined` for any other kind of definition (`class(x) <- `, `assign`, a parameter, ...). */
257
+ function assignedValueOf(def, graph) {
258
+ const vertex = graph.getVertex(def);
259
+ const byAssignment = (0, frame_reflection_1.edgeTargets)(graph, def, edge_1.EdgeType.DefinedBy).some(t => vertex_1.DfgVertex.hasOrigin(graph.getVertex(t), built_in_proc_name_1.BuiltInProcName.Assignment));
260
+ return vertex_1.DfgVertex.isVariableDefinition(vertex) && byAssignment && vertex.source?.length === 1 ? vertex.source[0] : undefined;
261
+ }
262
+ /** The class vectors S3 dispatch may see for the argument at `id`, one per reaching definition, `undefined` unless all are known. */
263
+ function s3DispatchClassesOf(id, info) {
264
+ const { graph } = info;
265
+ const value = r_argument_1.RArgument.valueOf(info.idMap.get(id))?.info.id;
266
+ const isRead = value !== undefined && vertex_1.DfgVertex.isUse(graph.getVertex(value));
267
+ const values = isRead ? (0, frame_reflection_1.edgeTargets)(graph, value, edge_1.EdgeType.Reads).map(def => assignedValueOf(def, graph)) : [value];
268
+ const classes = values.map(v => v === undefined ? undefined : s3ClassOfValue(v, info));
269
+ return classes.length > 0 && classes.every(assert_1.isNotUndefined) ? classes : undefined;
291
270
  }
292
271
  //# sourceMappingURL=class-declaration.js.map
@@ -11,15 +11,14 @@ const r_function_definition_1 = require("../../r-bridge/lang-4.x/ast/model/nodes
11
11
  const built_in_props_1 = require("../environments/built-in-props");
12
12
  const query_fn_props_1 = require("../environments/query-fn-props");
13
13
  const condition_handlers_1 = require("./condition-handlers");
14
- const function_props_1 = require("./function-props");
15
- const CatchHandlers = new Set([built_in_proc_name_1.BuiltInProcName.Try]);
14
+ const defaultmap_1 = require("../../util/collections/defaultmap");
16
15
  /**
17
16
  * Whether the vertex catches an error raised below it, which ends the walk. A construct declaring no condition
18
17
  * handler of its own (`try`) catches whatever arrives; one that matches handlers by condition class
19
18
  * (`tryCatch`) catches only what the names written for it say.
20
19
  */
21
20
  function catches(vertex, graph, info) {
22
- if (!vertex_1.DfgVertex.isFunctionCall(vertex) || vertex.origin === 'unnamed' || !vertex.origin.some(c => CatchHandlers.has(c))) {
21
+ if (!vertex_1.DfgVertex.isFunctionCall(vertex) || !vertex_1.DfgVertex.hasOrigin(vertex, built_in_proc_name_1.BuiltInProcName.Try)) {
23
22
  return false;
24
23
  }
25
24
  const sig = info(vertex.name)?.sig;
@@ -37,8 +36,8 @@ function catches(vertex, graph, info) {
37
36
  */
38
37
  function guarded(id, graph, info) {
39
38
  const idMap = graph.idMap;
40
- let node = idMap === undefined ? undefined : idMap.get(id);
41
- while (node !== undefined && !r_function_definition_1.RFunctionDefinition.is(node)) {
39
+ let node = idMap?.get(id);
40
+ while (idMap !== undefined && node !== undefined && !r_function_definition_1.RFunctionDefinition.is(node)) {
42
41
  const parent = model_1.RNode.directParent(node, idMap);
43
42
  if (r_argument_1.RArgument.isUnnamed(node) && r_function_call_1.RFunctionCall.is(parent) && catches(graph.getVertex(parent.info.id), graph, info)) {
44
43
  return true;
@@ -49,7 +48,7 @@ function guarded(id, graph, info) {
49
48
  }
50
49
  function reach(id, graph, knownThrower) {
51
50
  const info = (0, query_fn_props_1.builtInLookup)();
52
- const isGuarded = new Map();
51
+ const isGuarded = (0, defaultmap_1.memoize)((n) => guarded(n, graph, info));
53
52
  const calls = new Map();
54
53
  const own = new Map();
55
54
  const defs = new Set();
@@ -75,22 +74,72 @@ function reach(id, graph, knownThrower) {
75
74
  own.set(current, vertex.exitPoints.filter(e => e.type === 4 /* ExitPointType.Error */).map(e => ({ id: e.nodeId, cds: e.cds })));
76
75
  }
77
76
  /* a guarded call is only ever reached through the construct guarding it, which ends the walk of its own */
78
- const next = [...(graph.edgesFrom(current)).keys()].filter(n => {
79
- let known = isGuarded.get(n);
80
- if (known === undefined) {
81
- known = guarded(n, graph, info);
82
- isGuarded.set(n, known);
83
- }
84
- return !known;
85
- });
77
+ const next = [...graph.edgesFrom(current).keys()].filter(n => !isGuarded(n));
86
78
  calls.set(current, next);
87
- for (const n of next) {
88
- if (!calls.has(n)) {
89
- toVisit.push(n);
79
+ toVisit.push(...next);
80
+ }
81
+ return { calls, own, defs };
82
+ }
83
+ /** What each node may raise, its callees included; Tarjan yields the call cycles callees first, so each is settled once. */
84
+ function raisedPerNode(calls, own) {
85
+ const raised = new Map();
86
+ const index = new Map();
87
+ const low = new Map();
88
+ const stack = [];
89
+ const onStack = new Set();
90
+ const lower = (node, to) => low.set(node, Math.min(low.get(node), to));
91
+ for (const root of calls.keys()) {
92
+ if (index.has(root)) {
93
+ continue;
94
+ }
95
+ /* each frame is a node and how many of its callees have been looked at */
96
+ const frames = [[root, 0]];
97
+ while (frames.length > 0) {
98
+ const frame = frames[frames.length - 1];
99
+ const [node, at] = frame;
100
+ if (at === 0) {
101
+ low.set(node, index.size);
102
+ index.set(node, index.size);
103
+ stack.push(node);
104
+ onStack.add(node);
105
+ }
106
+ const callee = calls.get(node)?.[at];
107
+ if (callee !== undefined) {
108
+ frame[1]++;
109
+ if (!index.has(callee)) {
110
+ frames.push([callee, 0]);
111
+ }
112
+ else if (onStack.has(callee)) {
113
+ lower(node, index.get(callee));
114
+ }
115
+ continue;
116
+ }
117
+ frames.pop();
118
+ if (frames.length > 0) {
119
+ lower(frames[frames.length - 1][0], low.get(node));
120
+ }
121
+ if (low.get(node) === index.get(node)) {
122
+ /* the node roots a component: its members are what lies on the stack above it, taken off top first */
123
+ const members = stack.splice(stack.lastIndexOf(node)).reverse();
124
+ const points = new Map();
125
+ for (const m of members) {
126
+ for (const e of own.get(m) ?? []) {
127
+ points.set(e.id, e);
128
+ }
129
+ for (const callee of calls.get(m) ?? []) {
130
+ for (const [at, point] of raised.get(callee) ?? []) {
131
+ points.set(at, point);
132
+ }
133
+ }
134
+ }
135
+ for (const m of members) {
136
+ onStack.delete(m);
137
+ raised.set(m, points);
138
+ }
90
139
  }
91
140
  }
92
141
  }
93
- return { calls, own, defs };
142
+ return raised;
94
143
  }
95
144
  /**
96
145
  * The `NodeId`s of functions that may throw exceptions when called by `id`, restricted to functions known by
@@ -99,30 +148,12 @@ function reach(id, graph, knownThrower) {
99
148
  */
100
149
  function exceptionsOfFunction(id, graph, { knownThrower = {} } = {}) {
101
150
  const { calls, own, defs } = reach(id, graph, knownThrower);
102
- const raised = new Map();
103
- for (const node of calls.keys()) {
104
- raised.set(node, new Map((own.get(node) ?? []).map(e => [e.id, e])));
105
- }
106
- (0, function_props_1.propagateToFixpoint)(calls.keys(), calls, node => {
107
- const into = raised.get(node);
108
- let grew = false;
109
- for (const call of calls.get(node) ?? []) {
110
- for (const [at, point] of raised.get(call) ?? NoPoints) {
111
- if (!into.has(at)) {
112
- into.set(at, point);
113
- grew = true;
114
- }
115
- }
116
- }
117
- return grew;
118
- });
119
151
  const result = {};
120
- for (const [node, points] of raised) {
152
+ for (const [node, points] of raisedPerNode(calls, own)) {
121
153
  if (defs.has(node) || node === id) {
122
154
  result[node] = [...points.values()];
123
155
  }
124
156
  }
125
157
  return result;
126
158
  }
127
- const NoPoints = new Map();
128
159
  //# sourceMappingURL=exceptions-of-function.js.map
@@ -3,19 +3,27 @@ import { EdgeType } from '../graph/edge';
3
3
  import type { DataflowGraphVertexFunctionCall, DataflowGraphVertexFunctionDefinition } from '../graph/vertex';
4
4
  import type { ArgProps, BuiltInFnInfo } from '../environments/built-in-props';
5
5
  import type { Identifier } from '../environments/identifier';
6
- import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
6
+ import { type NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
7
+ import { DefaultMap } from '../../util/collections/defaultmap';
7
8
  /** What flowR states about the built-in a call names, see {@link BuiltInFnInfo}. */
8
9
  export type BuiltInLookup = (name: Identifier) => BuiltInFnInfo | undefined;
9
10
  /** The nodes at the far end of `node`'s outgoing edges of any of `types`, shared by every walk here and in the sibling analyses that follow specific edge kinds. */
10
11
  export declare function edgeTargets(this: void, graph: DataflowGraph, node: NodeId, types: EdgeType): NodeId[];
12
+ /** The function-definition vertices a `call` resolves to (via {@link EdgeType.Calls}). */
13
+ export declare function calledDefinitions(this: void, graph: DataflowGraph, call: NodeId): NodeId[];
14
+ /** The nodes at the near end of `node`'s incoming edges of any of `types`, see {@link edgeTargets}. */
15
+ export declare function edgeSources(this: void, graph: DataflowGraph, node: NodeId, types: EdgeType): NodeId[];
16
+ /** Every variable definition by its unquoted name, in a single pass. */
17
+ export declare function definitionsByName(this: void, graph: DataflowGraph): DefaultMap<string, NodeId[]>;
18
+ /** Whether an edge from `from` to `to` carries any of `types`. */
19
+ export declare function hasEdgeOfType(this: void, graph: DataflowGraph, from: NodeId, to: NodeId, types: EdgeType): boolean;
11
20
  /** The calls a definition's body reaches, id and vertex paired; shared by every walk here and in the sibling analyses that visit them all. */
12
21
  export declare function callsIn(definition: DataflowGraphVertexFunctionDefinition, graph: DataflowGraph): Generator<[NodeId, DataflowGraphVertexFunctionCall]>;
13
22
  /**
14
23
  * Recomputes `recompute(id)` for every node reachable from `seed` along the reverse of `successors`, so a
15
24
  * change at a node is carried on to whatever points at it, until nothing grows anymore. `recompute` updates
16
- * its node's value itself and reports whether it grew; shared by {@link propagateOverCalls} and
17
- * {@link exceptionsOfFunction}, which differ only in what "grew" means for the value they carry, and
18
- * by {@link carriersOf} below, which grows a set rather than a bitfield.
25
+ * its node's value itself and reports whether it grew; shared by {@link propagateOverCalls} and by
26
+ * {@link carriersOf} below, which grows a set rather than a bitfield.
19
27
  */
20
28
  export declare function propagateToFixpoint(seed: Iterable<NodeId>, successors: ReadonlyMap<NodeId, readonly NodeId[]>, recompute: (id: NodeId) => boolean): void;
21
29
  /** What to ask for beyond the definition itself, see {@link reflectiveRolesOf}. */