@eagleoutice/flowr 2.15.10 → 2.16.1

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 (213) hide show
  1. package/README.md +23 -26
  2. package/abstract-interpretation/data-frame/arguments.js +11 -7
  3. package/cli/flowr-main-options.d.ts +15 -0
  4. package/cli/flowr-main-options.js +18 -0
  5. package/cli/flowr.d.ts +18 -0
  6. package/cli/flowr.js +13 -2
  7. package/cli/repl/commands/repl-clipboard.js +2 -1
  8. package/cli/repl/commands/repl-commands.js +2 -0
  9. package/cli/repl/commands/repl-main.d.ts +5 -0
  10. package/cli/repl/commands/repl-signature.js +2 -0
  11. package/cli/repl/core.d.ts +7 -1
  12. package/cli/repl/core.js +17 -8
  13. package/cli/repl/execute.js +2 -0
  14. package/cli/repl/server/connection.js +2 -1
  15. package/cli/repl/server/net.d.ts +10 -0
  16. package/cli/repl/server/net.js +34 -1
  17. package/cli/slicer-app.js +2 -1
  18. package/config.d.ts +12 -2
  19. package/config.js +91 -14
  20. package/control-flow/happens-before.d.ts +5 -0
  21. package/control-flow/happens-before.js +48 -34
  22. package/control-flow/useless-loop.d.ts +1 -1
  23. package/control-flow/useless-loop.js +29 -42
  24. package/dataflow/environments/built-in-props.d.ts +9 -0
  25. package/dataflow/environments/built-in-props.js +25 -19
  26. package/dataflow/environments/built-in.d.ts +2 -2
  27. package/dataflow/environments/built-in.js +41 -77
  28. package/dataflow/environments/default-builtin-config.d.ts +181 -29
  29. package/dataflow/environments/default-builtin-config.js +38 -24
  30. package/dataflow/environments/environment.d.ts +6 -4
  31. package/dataflow/environments/environment.js +54 -121
  32. package/dataflow/environments/identifier.d.ts +4 -2
  33. package/dataflow/environments/identifier.js +23 -69
  34. package/dataflow/environments/reference-to-maybe.d.ts +9 -0
  35. package/dataflow/environments/reference-to-maybe.js +23 -51
  36. package/dataflow/environments/resolve-by-name.js +37 -76
  37. package/dataflow/eval/resolve/resolve-argument.d.ts +3 -1
  38. package/dataflow/eval/resolve/resolve-argument.js +61 -64
  39. package/dataflow/eval/resolve/resolve-working-directory.d.ts +8 -2
  40. package/dataflow/eval/resolve/resolve-working-directory.js +12 -20
  41. package/dataflow/eval/resolve/resolve.d.ts +4 -0
  42. package/dataflow/eval/resolve/resolve.js +23 -14
  43. package/dataflow/extractor.js +185 -59
  44. package/dataflow/fn/class-declaration.d.ts +8 -2
  45. package/dataflow/fn/class-declaration.js +96 -97
  46. package/dataflow/fn/exceptions-of-function.js +68 -37
  47. package/dataflow/fn/frame-reflection.d.ts +12 -4
  48. package/dataflow/fn/frame-reflection.js +64 -42
  49. package/dataflow/fn/function-props.js +15 -33
  50. package/dataflow/fn/function-semantics.d.ts +11 -3
  51. package/dataflow/fn/function-semantics.js +6 -0
  52. package/dataflow/fn/higher-order-function.js +13 -17
  53. package/dataflow/fn/strict-function.d.ts +13 -0
  54. package/dataflow/fn/strict-function.js +285 -122
  55. package/dataflow/graph/call-graph.d.ts +7 -6
  56. package/dataflow/graph/call-graph.js +35 -46
  57. package/dataflow/graph/graph.d.ts +6 -1
  58. package/dataflow/graph/graph.js +57 -66
  59. package/dataflow/info.d.ts +8 -1
  60. package/dataflow/info.js +24 -30
  61. package/dataflow/internal/control-flow.d.ts +42 -4
  62. package/dataflow/internal/control-flow.js +76 -39
  63. package/dataflow/internal/linker.d.ts +15 -9
  64. package/dataflow/internal/linker.js +253 -241
  65. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +80 -14
  66. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +441 -79
  67. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +3 -1
  68. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +51 -48
  69. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +2 -2
  70. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +119 -185
  71. package/dataflow/internal/process/functions/call/built-in/built-in-class-generator.js +7 -9
  72. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
  73. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +122 -147
  74. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +55 -25
  75. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +290 -252
  76. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +1 -1
  77. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +30 -32
  78. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +68 -67
  79. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +72 -126
  80. package/dataflow/internal/process/functions/call/built-in/built-in-local.d.ts +1 -3
  81. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +10 -10
  82. package/dataflow/internal/process/functions/call/built-in/built-in-quote.d.ts +4 -4
  83. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -35
  84. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +8 -3
  85. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.d.ts +1 -1
  86. package/dataflow/internal/process/functions/call/built-in/built-in-s-four.js +12 -28
  87. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.d.ts +1 -1
  88. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +40 -118
  89. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.d.ts +1 -3
  90. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +16 -24
  91. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +2 -0
  92. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +93 -102
  93. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.d.ts +7 -3
  94. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +173 -114
  95. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.d.ts +1 -3
  96. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +22 -27
  97. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +1 -1
  98. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +34 -9
  99. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +1 -1
  100. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +120 -93
  101. package/dataflow/internal/process/functions/call/common.d.ts +1 -3
  102. package/dataflow/internal/process/functions/call/common.js +36 -76
  103. package/dataflow/internal/process/functions/call/deferred.d.ts +6 -2
  104. package/dataflow/internal/process/functions/call/deferred.js +60 -58
  105. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +4 -2
  106. package/dataflow/internal/process/functions/call/known-call-handling.js +65 -68
  107. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +3 -5
  108. package/dataflow/internal/process/functions/call/named-call-handling.js +44 -21
  109. package/dataflow/internal/process/functions/call/quoted.d.ts +2 -0
  110. package/dataflow/internal/process/functions/call/quoted.js +162 -172
  111. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +17 -38
  112. package/dataflow/internal/process/functions/process-parameter.js +25 -32
  113. package/dataflow/internal/process/process-symbol.js +3 -6
  114. package/dataflow/internal/program-order.d.ts +26 -0
  115. package/dataflow/internal/program-order.js +49 -0
  116. package/documentation/doc-capabilities.js +4 -1
  117. package/documentation/wiki-interface.js +4 -0
  118. package/documentation/wiki-setup.js +23 -0
  119. package/engines.js +11 -3
  120. package/linter/linter-executor.js +19 -1
  121. package/linter/linter-rules.d.ts +17 -8
  122. package/linter/rules/absolute-path.js +63 -87
  123. package/linter/rules/file-path-validity.d.ts +4 -2
  124. package/linter/rules/file-path-validity.js +117 -80
  125. package/linter/rules/namespace-access.js +21 -33
  126. package/linter/rules/naming-convention.d.ts +1 -1
  127. package/linter/rules/naming-convention.js +60 -48
  128. package/linter/rules/network-functions.js +11 -7
  129. package/linter/rules/no-leaked-credentials.js +15 -18
  130. package/linter/rules/problematic-inputs.d.ts +2 -1
  131. package/linter/rules/problematic-inputs.js +39 -59
  132. package/linter/rules/roxygen-arguments.d.ts +9 -4
  133. package/linter/rules/roxygen-arguments.js +29 -48
  134. package/linter/rules/seeded-randomness.d.ts +7 -4
  135. package/linter/rules/seeded-randomness.js +130 -89
  136. package/linter/rules/stop-with-call-arg.d.ts +4 -2
  137. package/linter/rules/stop-with-call-arg.js +25 -22
  138. package/linter/rules/unclosed-connection.js +31 -24
  139. package/linter/rules/undefined-symbol.d.ts +4 -6
  140. package/linter/rules/undefined-symbol.js +58 -75
  141. package/linter/rules/unescaped-arguments.js +18 -44
  142. package/linter/rules/unused-definition.d.ts +6 -0
  143. package/linter/rules/unused-definition.js +105 -145
  144. package/linter/rules/unused-import.d.ts +3 -0
  145. package/linter/rules/unused-import.js +25 -43
  146. package/package.json +5 -2
  147. package/project/flowr-analyzer.js +6 -2
  148. package/project/plugins/file-plugins/files/flowr-jupyter-file.d.ts +2 -2
  149. package/project/plugins/file-plugins/files/flowr-jupyter-file.js +8 -12
  150. package/project/plugins/file-plugins/files/flowr-rda-file.d.ts +14 -5
  151. package/project/plugins/file-plugins/files/flowr-rda-file.js +35 -24
  152. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +7 -5
  153. package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +34 -56
  154. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +18 -42
  155. package/project/sigdb/decompress.js +3 -1
  156. package/project/sigdb/sigdb-download.js +9 -6
  157. package/queries/base-query-format.js +1 -2
  158. package/queries/catalog/absint-query/absint-query-format.js +1 -1
  159. package/queries/catalog/config-query/config-query-executor.js +9 -2
  160. package/queries/catalog/dataflow-query/dataflow-query-executor.js +2 -2
  161. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
  162. package/queries/catalog/dataflow-query/dataflow-query-format.js +4 -7
  163. package/queries/catalog/dependencies-query/dependencies-query-executor.js +50 -114
  164. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +5 -9
  165. package/queries/catalog/dependencies-query/function-info/library-functions.js +6 -0
  166. package/queries/catalog/dependencies-query/function-info/read-functions.js +1 -1
  167. package/queries/catalog/dependencies-query/function-info/write-functions.js +7 -3
  168. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +4 -4
  169. package/queries/catalog/input-sources-query/simple-input-classifier.js +192 -301
  170. package/r-bridge/lang-4.x/ast/model/model.d.ts +3 -1
  171. package/r-bridge/lang-4.x/ast/model/model.js +19 -43
  172. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +1 -0
  173. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -0
  174. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +5 -12
  175. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +1 -0
  176. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +1 -0
  177. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +1 -0
  178. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +1 -0
  179. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -0
  180. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +1 -0
  181. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +1 -0
  182. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +1 -0
  183. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +1 -0
  184. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +1 -0
  185. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +1 -0
  186. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +1 -0
  187. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +1 -0
  188. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +1 -0
  189. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -0
  190. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +1 -0
  191. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +1 -0
  192. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +1 -0
  193. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +1 -0
  194. package/r-bridge/roxygen2/roxygen-parse.js +28 -42
  195. package/r-bridge/shell-executor.js +2 -0
  196. package/r-bridge/shell.js +8 -0
  197. package/search/search-executor/search-enrichers.js +25 -37
  198. package/slicing/static/slice-call.d.ts +4 -3
  199. package/slicing/static/slice-call.js +56 -88
  200. package/slicing/static/static-slicer.js +120 -79
  201. package/slicing/static/visiting-queue.d.ts +4 -6
  202. package/slicing/static/visiting-queue.js +9 -13
  203. package/util/files.d.ts +6 -0
  204. package/util/files.js +12 -0
  205. package/util/parallel.js +2 -0
  206. package/util/proc.js +2 -1
  207. package/util/r-base-packages.d.ts +2 -0
  208. package/util/r-base-packages.js +23 -13
  209. package/util/secure-mode.d.ts +42 -0
  210. package/util/secure-mode.js +70 -0
  211. package/util/text/playground-link.d.ts +12 -3
  212. package/util/text/playground-link.js +18 -27
  213. package/util/version.js +4 -10
@@ -9,6 +9,8 @@ exports.classDeclarationOfImpl = classDeclarationOfImpl;
9
9
  exports.declaredClassesImpl = declaredClassesImpl;
10
10
  exports.superClassesOfImpl = superClassesOfImpl;
11
11
  exports.toSigClassesImpl = toSigClassesImpl;
12
+ exports.s3DispatchClassesOf = s3DispatchClassesOf;
13
+ const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
12
14
  const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
13
15
  const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
14
16
  const r_string_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-string");
@@ -18,6 +20,11 @@ const edge_1 = require("../graph/edge");
18
20
  const assert_1 = require("../../util/assert");
19
21
  const objects_1 = require("../../util/objects");
20
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");
21
28
  /** the class name R uses to mark a class as non-instantiable */
22
29
  const VirtualClass = 'VIRTUAL';
23
30
  /** The argument `ref` names, by name when the call gives one and by position among the unnamed ones otherwise. */
@@ -25,37 +32,24 @@ function argForImpl(args, ref) {
25
32
  if (ref === undefined) {
26
33
  return undefined;
27
34
  }
28
- if (ref.name !== undefined) {
29
- const named = args.find(a => !r_argument_1.RArgument.isEmpty(a) && a.name?.content === ref.name);
30
- if (named !== undefined && !r_argument_1.RArgument.isEmpty(named)) {
31
- return named.value;
32
- }
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);
33
38
  }
34
39
  if (ref.idx === undefined) {
35
40
  return undefined;
36
41
  }
37
- let pos = 0;
38
- for (const a of args) {
39
- if (r_argument_1.RArgument.isEmpty(a) || a.name !== undefined) {
40
- continue;
41
- }
42
- if (pos++ === ref.idx) {
43
- return a.value;
44
- }
45
- }
46
- return undefined;
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]);
47
44
  }
48
45
  /** The string a node states literally, `undefined` for anything that is not a literal (a variable, a call, ...). */
49
46
  function literal(node) {
50
- 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;
51
48
  }
52
49
  /** The character vector a node states: a literal, or the literals of a `c(...)`/`list(...)` around them. */
53
50
  function literalVector(node) {
54
51
  const values = [];
55
52
  const byVariable = [];
56
- if (node === undefined) {
57
- return { values, byVariable };
58
- }
59
53
  const collect = (n) => {
60
54
  const str = literal(n);
61
55
  if (str !== undefined) {
@@ -66,11 +60,7 @@ function literalVector(node) {
66
60
  byVariable.push(n.lexeme);
67
61
  }
68
62
  else if (r_function_call_1.RFunctionCall.isNamed(n)) {
69
- for (const arg of n.arguments) {
70
- if (!r_argument_1.RArgument.isEmpty(arg) && arg.value !== undefined) {
71
- collect(arg.value);
72
- }
73
- }
63
+ n.arguments.forEach(a => collect(r_argument_1.RArgument.valueOf(a)));
74
64
  }
75
65
  };
76
66
  collect(node);
@@ -81,14 +71,11 @@ function literalVector(node) {
81
71
  * element, plus the bare strings such a call may carry (an RC `fields = c("x", "y")`, or a `"VIRTUAL"` marker).
82
72
  */
83
73
  function membersOf(node, ref) {
84
- const members = [];
85
- let virtual = false;
86
- if (node === undefined) {
87
- return { members, virtual };
88
- }
89
74
  if (!r_function_call_1.RFunctionCall.isNamed(node)) {
90
- return { members, virtual: literal(node) === VirtualClass };
75
+ return { members: [], virtual: literal(node) === VirtualClass };
91
76
  }
77
+ const members = [];
78
+ let virtual = false;
92
79
  for (const arg of node.arguments) {
93
80
  if (r_argument_1.RArgument.isEmpty(arg) || arg.value === undefined) {
94
81
  continue;
@@ -121,15 +108,10 @@ function isTrue(node) {
121
108
  * An argument that resolves to no literal contributes a {@link ClassDeclaration.byVariable|by-variable} name, or nothing.
122
109
  */
123
110
  function classDeclarationOfImpl(config, args) {
124
- const byVariable = [];
125
111
  const nameNode = argForImpl(args, config.nameArg);
126
112
  const name = literal(nameNode);
127
- if (name === undefined && nameNode !== undefined && r_symbol_1.RSymbol.is(nameNode)) {
128
- byVariable.push(nameNode.lexeme);
129
- }
130
113
  const parents = literalVector(argForImpl(args, config.containsArg));
131
- byVariable.push(...parents.byVariable);
132
- 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;
133
115
  let virtual = parents.values.includes(VirtualClass) || isTrue(argForImpl(args, config.virtualArg));
134
116
  const members = [];
135
117
  for (const ref of config.memberArgs ?? []) {
@@ -137,15 +119,14 @@ function classDeclarationOfImpl(config, args) {
137
119
  members.push(...found.members);
138
120
  virtual ||= found.virtual;
139
121
  }
140
- const union = config.unionArg === undefined ? undefined : literalVector(argForImpl(args, config.unionArg)).values;
141
- const prototype = config.prototypeArg === undefined ? []
142
- : 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);
143
124
  /* a class union is virtual by construction: it exists to be extended, never to be instantiated */
144
- const isUnion = union !== undefined && union.length > 0;
125
+ const isUnion = union.length > 0;
145
126
  return (0, objects_1.compactRecord)({
146
127
  system: config.system,
147
128
  name,
148
- contains,
129
+ contains: parents.values.filter(c => c !== VirtualClass),
149
130
  members,
150
131
  virtual: virtual || isUnion ? true : undefined,
151
132
  union: isUnion ? union : undefined,
@@ -157,61 +138,54 @@ function classDeclarationOfImpl(config, args) {
157
138
  /** Every class the graph declares, keyed by name. A later declaration of the same name wins, as it would in R. */
158
139
  function declaredClassesImpl(graph) {
159
140
  const classes = new Map();
160
- for (const [id, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
161
- const decl = vertex.classDecl;
162
- if (decl?.name === undefined || decl.relation !== undefined) {
163
- 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 });
164
144
  }
165
- classes.set(decl.name, { ...decl, id, name: decl.name });
166
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
+ };
167
152
  /* R6 and S7 name their parent by the generator *variable*, so `Employee <- R6Class(inherit = Person)`
168
153
  only says "Person"; the assignment that bound the generator says which class that is */
169
154
  const byGenerator = generatorVariables(graph, classes);
170
155
  for (const [name, declared] of classes) {
171
- const resolved = declared.byVariable.map(v => byGenerator.get(v)).filter(assert_1.isNotUndefined)
172
- .filter(c => c !== name && !declared.contains.includes(c));
173
- if (resolved.length > 0) {
174
- 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
+ }
175
160
  }
176
161
  }
177
- /* a `setClassUnion` states its members as subclasses, which is the same fact written the other way round */
178
- for (const [, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
179
- const decl = vertex.classDecl;
180
- if (decl?.name === undefined) {
162
+ for (const [, { classDecl }] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
163
+ if (classDecl?.name === undefined) {
181
164
  continue;
182
165
  }
183
- for (const member of decl.union ?? []) {
184
- const existing = classes.get(member);
185
- if (existing !== undefined && !existing.contains.includes(decl.name)) {
186
- classes.set(member, { ...existing, contains: [...existing.contains, decl.name] });
187
- }
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);
188
169
  }
189
170
  /* `setIs(class1, class2)` states the same is-a relation `contains` does */
190
- if (decl.relation === 'is') {
191
- const [sub, sup] = [decl.name, decl.contains[0]];
192
- const existing = classes.get(sub);
193
- if (existing !== undefined && sup !== undefined && !existing.contains.includes(sup)) {
194
- classes.set(sub, { ...existing, contains: [...existing.contains, sup] });
195
- }
171
+ if (classDecl.relation === 'is') {
172
+ addSuper(classDecl.name, classDecl.contains[0]);
196
173
  }
197
174
  }
198
175
  return classes;
199
176
  }
200
177
  /** Variable name to the class its generator declares, for the `Cls <- R6Class(...)`/`Cls <- new_class(...)` bindings. */
201
178
  function generatorVariables(graph, classes) {
202
- const byName = new Map();
203
- for (const declared of classes.values()) {
204
- byName.set(declared.id, declared.name);
205
- }
179
+ const classOfId = new Map(classes.values().map(d => [d.id, d.name]));
206
180
  const generators = new Map();
207
181
  for (const [id] of graph.verticesOfType(vertex_1.VertexType.VariableDefinition)) {
208
182
  const lexeme = graph.idMap?.get(id)?.lexeme;
209
183
  if (lexeme === undefined) {
210
184
  continue;
211
185
  }
212
- for (const [target, edge] of graph.edgesFrom(id)) {
213
- const cls = byName.get(target);
214
- 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) {
215
189
  generators.set(lexeme, cls);
216
190
  }
217
191
  }
@@ -223,50 +197,75 @@ function generatorVariables(graph, classes) {
223
197
  * analysis never saw declared ends the chain, so what another package contributes is simply not in the answer.
224
198
  */
225
199
  function superClassesOfImpl(name, classes) {
226
- const chain = [];
227
200
  const seen = new Set([name]);
228
- const queue = [...(classes.get(name)?.contains ?? [])];
229
- while (queue.length > 0) {
230
- const next = queue.shift();
231
- if (seen.has(next)) {
232
- 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);
233
205
  }
234
- seen.add(next);
235
- chain.push(next);
236
- queue.push(...(classes.get(next)?.contains ?? []));
237
206
  }
238
- return chain;
207
+ seen.delete(name);
208
+ return [...seen];
239
209
  }
240
210
  /**
241
211
  * The {@link SigClassInfo} records the signature database stores for the classes an analysis found. A class
242
212
  * the analysis declared carries no `package`; a referenced class `ownerOf` can place becomes a `foreign` record.
243
213
  */
244
214
  function toSigClassesImpl(classes, ownerOf) {
245
- const records = [];
246
- for (const declared of classes.values()) {
247
- records.push((0, objects_1.compactRecord)({
248
- name: declared.name,
249
- system: declared.system,
250
- supers: declared.union ?? declared.contains,
251
- slots: declared.members.filter(m => !m.method).map(m => (0, objects_1.compactRecord)({ name: m.name, type: m.type })),
252
- virtual: declared.virtual ? true : undefined,
253
- union: declared.union !== undefined ? true : undefined
254
- }));
255
- }
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();
256
223
  if (ownerOf === undefined) {
257
224
  return records;
258
225
  }
259
226
  /* a superclass the analysis never declared belongs to whoever does define it, which is what makes an
260
227
  inherited class distinguishable from one the package owns */
261
228
  for (const referenced of new Set(records.flatMap(r => r.supers))) {
262
- if (classes.has(referenced)) {
263
- continue;
264
- }
265
- const owner = ownerOf(referenced);
229
+ const owner = classes.has(referenced) ? undefined : ownerOf(referenced);
266
230
  if (owner !== undefined) {
267
231
  records.push({ name: referenced, system: 's4', supers: [], slots: [], package: owner });
268
232
  }
269
233
  }
270
234
  return records;
271
235
  }
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;
270
+ }
272
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}. */