@eagleoutice/flowr 2.2.11 → 2.2.13

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 (301) hide show
  1. package/README.md +82 -20
  2. package/benchmark/slicer.d.ts +49 -22
  3. package/benchmark/slicer.js +89 -29
  4. package/benchmark/stats/print.js +16 -10
  5. package/benchmark/stats/size-of.js +18 -1
  6. package/benchmark/stats/stats.d.ts +3 -0
  7. package/benchmark/summarizer/first-phase/input.js +1 -1
  8. package/benchmark/summarizer/first-phase/process.js +3 -3
  9. package/benchmark/summarizer/second-phase/process.js +9 -3
  10. package/benchmark/summarizer/summarizer.js +1 -1
  11. package/cli/benchmark-app.d.ts +5 -0
  12. package/cli/benchmark-app.js +49 -6
  13. package/cli/benchmark-helper-app.d.ts +4 -0
  14. package/cli/benchmark-helper-app.js +20 -4
  15. package/cli/common/options.js +15 -6
  16. package/cli/common/script.js +1 -1
  17. package/cli/flowr.js +1 -1
  18. package/cli/repl/commands/repl-cfg.d.ts +2 -0
  19. package/cli/repl/commands/repl-cfg.js +38 -24
  20. package/cli/repl/commands/repl-commands.js +6 -2
  21. package/cli/repl/commands/repl-dataflow.d.ts +2 -0
  22. package/cli/repl/commands/repl-dataflow.js +37 -3
  23. package/cli/repl/commands/repl-execute.js +1 -1
  24. package/cli/repl/commands/repl-main.d.ts +1 -1
  25. package/cli/repl/commands/repl-main.js +1 -1
  26. package/cli/repl/commands/repl-normalize.js +1 -1
  27. package/cli/repl/commands/repl-query.js +2 -2
  28. package/cli/repl/core.js +1 -1
  29. package/cli/repl/prompt.js +1 -1
  30. package/cli/repl/server/connection.js +4 -4
  31. package/cli/repl/server/messages/message-analysis.d.ts +1 -1
  32. package/cli/script-core/statistics-core.js +1 -1
  33. package/cli/script-core/statistics-helper-core.js +4 -4
  34. package/config.d.ts +60 -21
  35. package/config.js +24 -4
  36. package/control-flow/basic-cfg-guided-visitor.d.ts +39 -0
  37. package/control-flow/basic-cfg-guided-visitor.js +114 -0
  38. package/control-flow/cfg-properties.d.ts +26 -0
  39. package/control-flow/cfg-properties.js +100 -0
  40. package/control-flow/cfg-simplification.d.ts +18 -0
  41. package/control-flow/cfg-simplification.js +55 -0
  42. package/control-flow/cfg-to-basic-blocks.d.ts +5 -0
  43. package/control-flow/cfg-to-basic-blocks.js +81 -0
  44. package/control-flow/control-flow-graph.d.ts +247 -0
  45. package/control-flow/control-flow-graph.js +290 -0
  46. package/control-flow/dfg-cfg-guided-visitor.d.ts +32 -0
  47. package/control-flow/dfg-cfg-guided-visitor.js +71 -0
  48. package/control-flow/diff-cfg.d.ts +11 -0
  49. package/control-flow/diff-cfg.js +161 -0
  50. package/control-flow/extract-cfg.d.ts +30 -0
  51. package/control-flow/extract-cfg.js +475 -0
  52. package/control-flow/happens-before.d.ts +7 -0
  53. package/{util/cfg → control-flow}/happens-before.js +3 -3
  54. package/control-flow/semantic-cfg-guided-visitor.d.ts +452 -0
  55. package/control-flow/semantic-cfg-guided-visitor.js +492 -0
  56. package/control-flow/simple-visitor.d.ts +25 -0
  57. package/control-flow/simple-visitor.js +80 -0
  58. package/control-flow/syntax-cfg-guided-visitor.d.ts +128 -0
  59. package/control-flow/syntax-cfg-guided-visitor.js +166 -0
  60. package/core/print/print.d.ts +1 -1
  61. package/core/print/slice-diff-ansi.js +1 -1
  62. package/core/steps/pipeline/create-pipeline.js +1 -1
  63. package/dataflow/environments/built-in-config.d.ts +5 -2
  64. package/dataflow/environments/built-in-config.js +17 -8
  65. package/dataflow/environments/built-in.d.ts +16 -5
  66. package/dataflow/environments/built-in.js +55 -6
  67. package/dataflow/environments/clone.d.ts +5 -0
  68. package/dataflow/environments/clone.js +5 -0
  69. package/dataflow/environments/default-builtin-config.d.ts +2 -0
  70. package/dataflow/environments/default-builtin-config.js +164 -13
  71. package/dataflow/environments/define.d.ts +5 -1
  72. package/dataflow/environments/define.js +36 -10
  73. package/dataflow/environments/overwrite.js +4 -0
  74. package/dataflow/environments/remove.d.ts +6 -0
  75. package/dataflow/environments/remove.js +24 -0
  76. package/dataflow/environments/resolve-by-name.js +16 -5
  77. package/dataflow/extractor.js +2 -2
  78. package/dataflow/graph/dataflowgraph-builder.d.ts +79 -7
  79. package/dataflow/graph/dataflowgraph-builder.js +106 -8
  80. package/dataflow/graph/diff-dataflow-graph.d.ts +16 -0
  81. package/dataflow/graph/{diff.js → diff-dataflow-graph.js} +30 -56
  82. package/dataflow/graph/graph.d.ts +17 -4
  83. package/dataflow/graph/graph.js +51 -12
  84. package/dataflow/graph/vertex.d.ts +59 -4
  85. package/dataflow/graph/vertex.js +32 -0
  86. package/dataflow/internal/linker.d.ts +3 -2
  87. package/dataflow/internal/linker.js +36 -25
  88. package/dataflow/internal/process/functions/call/argument/unpack-argument.d.ts +1 -1
  89. package/dataflow/internal/process/functions/call/argument/unpack-argument.js +1 -1
  90. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +1 -0
  91. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +67 -54
  92. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +6 -4
  93. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +108 -21
  94. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +54 -17
  95. package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +10 -0
  96. package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +140 -0
  97. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +9 -4
  98. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +3 -2
  99. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +15 -4
  100. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +4 -3
  101. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +4 -3
  102. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +4 -3
  103. package/dataflow/internal/process/functions/call/built-in/built-in-list.js +51 -17
  104. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +1 -1
  105. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +9 -7
  106. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +3 -2
  107. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +4 -0
  108. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +100 -31
  109. package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +7 -0
  110. package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +41 -0
  111. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +35 -8
  112. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +4 -3
  113. package/dataflow/internal/process/functions/call/built-in/built-in-vector.d.ts +15 -0
  114. package/dataflow/internal/process/functions/call/built-in/built-in-vector.js +75 -0
  115. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +3 -3
  116. package/dataflow/internal/process/functions/call/common.d.ts +5 -2
  117. package/dataflow/internal/process/functions/call/common.js +9 -5
  118. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +3 -2
  119. package/dataflow/internal/process/functions/call/known-call-handling.js +2 -1
  120. package/dataflow/internal/process/functions/call/named-call-handling.d.ts +2 -0
  121. package/dataflow/internal/process/functions/call/named-call-handling.js +10 -6
  122. package/dataflow/internal/process/functions/call/unnamed-call-handling.d.ts +1 -0
  123. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +6 -4
  124. package/dataflow/internal/process/process-named-call.d.ts +4 -1
  125. package/dataflow/internal/process/process-named-call.js +8 -5
  126. package/dataflow/origin/dfg-get-origin.d.ts +82 -0
  127. package/dataflow/origin/dfg-get-origin.js +116 -0
  128. package/documentation/doc-util/doc-cfg.d.ts +20 -4
  129. package/documentation/doc-util/doc-cfg.js +41 -7
  130. package/documentation/doc-util/doc-cli-option.js +4 -2
  131. package/documentation/doc-util/doc-code.js +10 -2
  132. package/documentation/doc-util/doc-dfg.js +3 -3
  133. package/documentation/doc-util/doc-escape.d.ts +7 -0
  134. package/documentation/doc-util/doc-escape.js +19 -0
  135. package/documentation/doc-util/doc-files.d.ts +1 -0
  136. package/documentation/doc-util/doc-files.js +2 -1
  137. package/documentation/doc-util/doc-normalized-ast.js +3 -3
  138. package/documentation/doc-util/doc-query.js +2 -2
  139. package/documentation/doc-util/doc-repl.js +1 -1
  140. package/documentation/doc-util/doc-search.js +1 -1
  141. package/documentation/doc-util/doc-server-message.js +2 -2
  142. package/documentation/doc-util/doc-structure.d.ts +1 -0
  143. package/documentation/doc-util/doc-structure.js +5 -0
  144. package/documentation/doc-util/doc-types.d.ts +7 -1
  145. package/documentation/doc-util/doc-types.js +13 -2
  146. package/documentation/print-capabilities-markdown.js +28 -2
  147. package/documentation/print-cfg-wiki.d.ts +1 -0
  148. package/documentation/print-cfg-wiki.js +572 -0
  149. package/documentation/print-core-wiki.js +2 -2
  150. package/documentation/print-dataflow-graph-wiki.js +180 -25
  151. package/documentation/print-engines-wiki.js +1 -1
  152. package/documentation/print-faq-wiki.d.ts +1 -0
  153. package/documentation/print-faq-wiki.js +75 -0
  154. package/documentation/print-interface-wiki.js +2 -1
  155. package/documentation/print-linting-and-testing-wiki.js +52 -36
  156. package/documentation/print-normalized-ast-wiki.js +1 -1
  157. package/documentation/print-onboarding-wiki.d.ts +1 -0
  158. package/documentation/print-onboarding-wiki.js +42 -0
  159. package/documentation/print-query-wiki.js +23 -3
  160. package/documentation/print-readme.js +10 -3
  161. package/package.json +10 -6
  162. package/queries/catalog/call-context-query/call-context-query-executor.js +5 -5
  163. package/queries/catalog/call-context-query/call-context-query-format.d.ts +1 -1
  164. package/queries/catalog/call-context-query/call-context-query-format.js +2 -2
  165. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.d.ts +2 -2
  166. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +24 -21
  167. package/queries/catalog/cluster-query/cluster-query-format.d.ts +1 -1
  168. package/queries/catalog/cluster-query/cluster-query-format.js +1 -1
  169. package/queries/catalog/config-query/config-query-format.d.ts +1 -1
  170. package/queries/catalog/config-query/config-query-format.js +2 -2
  171. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.d.ts +1 -1
  172. package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.js +2 -2
  173. package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +1 -1
  174. package/queries/catalog/dataflow-query/dataflow-query-format.js +2 -2
  175. package/queries/catalog/dependencies-query/dependencies-query-executor.js +17 -7
  176. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +2 -26
  177. package/queries/catalog/dependencies-query/dependencies-query-format.js +4 -147
  178. package/queries/catalog/dependencies-query/function-info/function-info.d.ts +24 -0
  179. package/queries/catalog/dependencies-query/function-info/function-info.js +10 -0
  180. package/queries/catalog/dependencies-query/function-info/library-functions.d.ts +2 -0
  181. package/queries/catalog/dependencies-query/function-info/library-functions.js +18 -0
  182. package/queries/catalog/dependencies-query/function-info/read-functions.d.ts +2 -0
  183. package/queries/catalog/dependencies-query/function-info/read-functions.js +101 -0
  184. package/queries/catalog/dependencies-query/function-info/source-functions.d.ts +2 -0
  185. package/queries/catalog/dependencies-query/function-info/source-functions.js +11 -0
  186. package/queries/catalog/dependencies-query/function-info/write-functions.d.ts +2 -0
  187. package/queries/catalog/dependencies-query/function-info/write-functions.js +87 -0
  188. package/queries/catalog/happens-before-query/happens-before-query-executor.d.ts +1 -1
  189. package/queries/catalog/happens-before-query/happens-before-query-executor.js +4 -4
  190. package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +1 -1
  191. package/queries/catalog/happens-before-query/happens-before-query-format.js +2 -2
  192. package/queries/catalog/id-map-query/id-map-query-format.d.ts +1 -1
  193. package/queries/catalog/id-map-query/id-map-query-format.js +2 -2
  194. package/queries/catalog/lineage-query/lineage-query-format.d.ts +1 -1
  195. package/queries/catalog/lineage-query/lineage-query-format.js +2 -2
  196. package/queries/catalog/location-map-query/location-map-query-format.d.ts +1 -1
  197. package/queries/catalog/location-map-query/location-map-query-format.js +2 -2
  198. package/queries/catalog/normalized-ast-query/normalized-ast-query-format.d.ts +1 -1
  199. package/queries/catalog/normalized-ast-query/normalized-ast-query-format.js +2 -2
  200. package/queries/catalog/origin-query/origin-query-executor.d.ts +5 -0
  201. package/queries/catalog/origin-query/origin-query-executor.js +33 -0
  202. package/queries/catalog/origin-query/origin-query-format.d.ts +71 -0
  203. package/queries/catalog/origin-query/origin-query-format.js +27 -0
  204. package/queries/catalog/project-query/project-query-format.d.ts +1 -1
  205. package/queries/catalog/project-query/project-query-format.js +2 -2
  206. package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +1 -1
  207. package/queries/catalog/resolve-value-query/resolve-value-query-format.js +2 -2
  208. package/queries/catalog/search-query/search-query-format.d.ts +1 -1
  209. package/queries/catalog/search-query/search-query-format.js +2 -2
  210. package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +1 -1
  211. package/queries/catalog/static-slice-query/static-slice-query-format.js +2 -2
  212. package/queries/query-print.d.ts +1 -1
  213. package/queries/query-print.js +4 -4
  214. package/queries/query.d.ts +61 -2
  215. package/queries/query.js +3 -1
  216. package/r-bridge/data/data.d.ts +2 -2
  217. package/r-bridge/data/data.js +2 -2
  218. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +3 -2
  219. package/r-bridge/lang-4.x/ast/model/nodes/r-number.js +5 -0
  220. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +3 -2
  221. package/r-bridge/lang-4.x/ast/model/nodes/r-string.js +5 -0
  222. package/r-bridge/lang-4.x/ast/model/processing/decorate.d.ts +1 -1
  223. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +1 -1
  224. package/r-bridge/lang-4.x/ast/model/processing/fold.js +3 -1
  225. package/r-bridge/lang-4.x/ast/model/processing/stateful-fold.d.ts +1 -1
  226. package/r-bridge/lang-4.x/ast/parser/main/internal/expression/normalize-expression.js +1 -1
  227. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-argument.js +1 -1
  228. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-call.js +1 -1
  229. package/r-bridge/lang-4.x/ast/parser/main/internal/functions/normalize-definition.js +1 -1
  230. package/r-bridge/lang-4.x/ast/parser/main/internal/normalize-access.js +1 -1
  231. package/r-bridge/lang-4.x/ast/parser/main/internal/operators/normalize-binary.js +1 -1
  232. package/r-bridge/lang-4.x/ast/parser/main/internal/structure/normalize-root.js +1 -1
  233. package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-symbol.js +1 -1
  234. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.d.ts +2 -2
  235. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +4 -4
  236. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +26 -8
  237. package/r-bridge/retriever.js +1 -1
  238. package/search/search-executor/search-generators.d.ts +1 -1
  239. package/search/search-executor/search-transformer.d.ts +1 -1
  240. package/slicing/criterion/collect-all.js +1 -1
  241. package/slicing/static/slice-call.js +13 -3
  242. package/statistics/features/supported/assignments/post-process.js +1 -1
  243. package/statistics/features/supported/defined-functions/post-process.js +2 -2
  244. package/statistics/features/supported/used-functions/post-process.js +1 -1
  245. package/statistics/features/supported/used-packages/post-process.js +2 -2
  246. package/statistics/features/supported/values/post-process.js +2 -2
  247. package/statistics/output/print-stats.js +2 -2
  248. package/statistics/summarizer/post-process/clusterer.d.ts +1 -1
  249. package/statistics/summarizer/post-process/clusterer.js +1 -1
  250. package/statistics/summarizer/post-process/histogram.js +3 -3
  251. package/statistics/summarizer/post-process/post-process-output.js +3 -3
  252. package/statistics/summarizer/second-phase/process.js +2 -2
  253. package/statistics/summarizer/summarizer.js +2 -2
  254. package/util/assert.js +36 -1
  255. package/util/cfg/cfg.d.ts +0 -80
  256. package/util/cfg/cfg.js +0 -549
  257. package/util/{arrays.d.ts → collections/arrays.d.ts} +24 -1
  258. package/util/{arrays.js → collections/arrays.js} +44 -3
  259. package/util/collections/set.js +17 -0
  260. package/util/{list-access.d.ts → containers.d.ts} +24 -4
  261. package/util/{list-access.js → containers.js} +42 -12
  262. package/util/diff-graph.d.ts +47 -0
  263. package/util/diff-graph.js +61 -0
  264. package/util/diff.d.ts +6 -6
  265. package/util/diff.js +1 -1
  266. package/util/mermaid/ast.js +12 -1
  267. package/util/mermaid/cfg.d.ts +9 -2
  268. package/util/mermaid/cfg.js +65 -13
  269. package/util/mermaid/dfg.d.ts +2 -1
  270. package/util/mermaid/dfg.js +26 -10
  271. package/util/mermaid/mermaid.d.ts +2 -0
  272. package/util/mermaid/mermaid.js +6 -0
  273. package/util/parallel.d.ts +2 -1
  274. package/util/parallel.js +11 -2
  275. package/util/prefix.d.ts +13 -0
  276. package/util/prefix.js +34 -0
  277. package/util/quads.js +1 -1
  278. package/util/schema.d.ts +1 -1
  279. package/util/schema.js +1 -1
  280. package/util/summarizer.js +1 -1
  281. package/util/{text.js → text/text.js} +1 -1
  282. package/util/{time.js → text/time.js} +1 -1
  283. package/util/version.js +1 -1
  284. package/dataflow/graph/diff.d.ts +0 -36
  285. package/util/cfg/happens-before.d.ts +0 -7
  286. package/util/cfg/visitor.d.ts +0 -9
  287. package/util/cfg/visitor.js +0 -30
  288. package/util/set.js +0 -31
  289. /package/util/{bimap.d.ts → collections/bimap.d.ts} +0 -0
  290. /package/util/{bimap.js → collections/bimap.js} +0 -0
  291. /package/util/{defaultmap.d.ts → collections/defaultmap.d.ts} +0 -0
  292. /package/util/{defaultmap.js → collections/defaultmap.js} +0 -0
  293. /package/util/{set.d.ts → collections/set.d.ts} +0 -0
  294. /package/util/{ansi.d.ts → text/ansi.d.ts} +0 -0
  295. /package/util/{ansi.js → text/ansi.js} +0 -0
  296. /package/util/{args.d.ts → text/args.d.ts} +0 -0
  297. /package/util/{args.js → text/args.js} +0 -0
  298. /package/util/{strings.d.ts → text/strings.d.ts} +0 -0
  299. /package/util/{strings.js → text/strings.js} +0 -0
  300. /package/util/{text.d.ts → text/text.d.ts} +0 -0
  301. /package/util/{time.d.ts → text/time.d.ts} +0 -0
@@ -1,10 +1,30 @@
1
1
  import type { REnvironmentInformation } from '../dataflow/environments/environment';
2
- import type { ContainerIndices, ContainerIndicesCollection } from '../dataflow/graph/vertex';
2
+ import type { Identifier } from '../dataflow/environments/identifier';
3
+ import type { ContainerIndices, ContainerIndicesCollection, IndexIdentifier } from '../dataflow/graph/vertex';
3
4
  import type { RAccess } from '../r-bridge/lang-4.x/ast/model/nodes/r-access';
5
+ import type { RArgument } from '../r-bridge/lang-4.x/ast/model/nodes/r-argument';
6
+ import type { RFunctionArgument } from '../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
4
7
  import type { ParentInformation } from '../r-bridge/lang-4.x/ast/model/processing/decorate';
8
+ /**
9
+ * Returns the accessed and access argument of an access operation by filtering the operation arguments.
10
+ */
11
+ export declare function getAccessOperands<OtherInfo>(args: readonly RFunctionArgument<OtherInfo & ParentInformation>[]): {
12
+ accessedArg: RArgument<OtherInfo & ParentInformation> | undefined;
13
+ accessArg: RArgument<OtherInfo & ParentInformation> | undefined;
14
+ };
15
+ /**
16
+ * Resolves the passed name in the passed environment and returns the indicesCollection of the resolved definitions.
17
+ *
18
+ * @param name - Name to resolve
19
+ * @param environment - Environment in which name is resolved
20
+ * @returns The indicesCollection of the resolved definitions
21
+ */
22
+ export declare function resolveIndicesByName(name: Identifier, environment: REnvironmentInformation): ContainerIndices[] | undefined;
5
23
  /**
6
24
  * Resolves {@link accessedArg} in the {@link environment} and filters its indices according to {@link accessArg}.
7
25
  *
26
+ * If no indices could be found that match the `accessArg`, the original indices are returned as overapproximation.
27
+ *
8
28
  * @param accessedArg - The argument to resolve
9
29
  * @param accessArg - The argument which is used to filter the indices
10
30
  * @param environment - The environment in which {@link accessedArg} is resolved
@@ -14,7 +34,7 @@ export declare function resolveSingleIndex(accessedArg: {
14
34
  lexeme: string;
15
35
  }, accessArg: {
16
36
  lexeme: string;
17
- }, environment: REnvironmentInformation): ContainerIndicesCollection;
37
+ }, environment: REnvironmentInformation, isIndexBasedAccess: boolean): ContainerIndicesCollection;
18
38
  /**
19
39
  * Filters the single indices of the {@link indicesCollection} according to the lexeme of the {@link accessArg}.
20
40
  *
@@ -24,7 +44,7 @@ export declare function resolveSingleIndex(accessedArg: {
24
44
  */
25
45
  export declare function filterIndices(indicesCollection: ContainerIndicesCollection, accessArg: {
26
46
  lexeme: string;
27
- }): ContainerIndicesCollection;
47
+ }, isIndexBasedAccess: boolean): ContainerIndicesCollection;
28
48
  /**
29
49
  * Constructs the definition of a nested access.
30
50
  *
@@ -38,7 +58,7 @@ export declare function filterIndices(indicesCollection: ContainerIndicesCollect
38
58
  * @param leafIndices - The index at the end of the nested access i.e. `c` in `a$b$c`.
39
59
  * @returns The constructed nested access
40
60
  */
41
- export declare function constructNestedAccess<OtherInfo>(accessedArg: RAccess<OtherInfo & ParentInformation>, leafIndices: ContainerIndices): ContainerIndices[];
61
+ export declare function constructNestedAccess<OtherInfo>(accessedArg: RAccess<OtherInfo & ParentInformation>, leafIndices: ContainerIndices, constructIdentifier: (arg: RArgument<OtherInfo & ParentInformation>) => IndexIdentifier): ContainerIndices[];
42
62
  /**
43
63
  * Adds the passed list of {@link leafSubIndices} to the leaf (sub-)indices of {@link indicesCollection}.
44
64
  *
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAccessOperands = getAccessOperands;
4
+ exports.resolveIndicesByName = resolveIndicesByName;
3
5
  exports.resolveSingleIndex = resolveSingleIndex;
4
6
  exports.filterIndices = filterIndices;
5
7
  exports.constructNestedAccess = constructNestedAccess;
@@ -8,19 +10,47 @@ const resolve_by_name_1 = require("../dataflow/environments/resolve-by-name");
8
10
  const vertex_1 = require("../dataflow/graph/vertex");
9
11
  const r_function_call_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
10
12
  const type_1 = require("../r-bridge/lang-4.x/ast/model/type");
13
+ /**
14
+ * Returns the accessed and access argument of an access operation by filtering the operation arguments.
15
+ */
16
+ function getAccessOperands(args) {
17
+ const nonEmptyArgs = args.filter(arg => arg !== r_function_call_1.EmptyArgument);
18
+ const accessedArg = nonEmptyArgs.find(arg => arg.info.role === "accessed" /* RoleInParent.Accessed */);
19
+ const accessArg = nonEmptyArgs.find(arg => arg.info.role === "index-access" /* RoleInParent.IndexAccess */);
20
+ return { accessedArg, accessArg };
21
+ }
22
+ /**
23
+ * Resolves the passed name in the passed environment and returns the indicesCollection of the resolved definitions.
24
+ *
25
+ * @param name - Name to resolve
26
+ * @param environment - Environment in which name is resolved
27
+ * @returns The indicesCollection of the resolved definitions
28
+ */
29
+ function resolveIndicesByName(name, environment) {
30
+ const definitions = (0, resolve_by_name_1.resolveByName)(name, environment);
31
+ return definitions?.flatMap(def => def?.indicesCollection ?? []);
32
+ }
11
33
  /**
12
34
  * Resolves {@link accessedArg} in the {@link environment} and filters its indices according to {@link accessArg}.
13
35
  *
36
+ * If no indices could be found that match the `accessArg`, the original indices are returned as overapproximation.
37
+ *
14
38
  * @param accessedArg - The argument to resolve
15
39
  * @param accessArg - The argument which is used to filter the indices
16
40
  * @param environment - The environment in which {@link accessedArg} is resolved
17
41
  * @returns The filtered {@link ContainerIndicesCollection} of the resolved {@link accessedArg}
18
42
  */
19
- function resolveSingleIndex(accessedArg, accessArg, environment) {
20
- const definitions = (0, resolve_by_name_1.resolveByName)(accessedArg.lexeme, environment);
21
- const indicesCollection = definitions?.flatMap(def => def?.indicesCollection ?? []);
22
- const accessedIndicesCollection = filterIndices(indicesCollection, accessArg);
23
- return accessedIndicesCollection;
43
+ function resolveSingleIndex(accessedArg, accessArg, environment, isIndexBasedAccess) {
44
+ const indicesCollection = resolveIndicesByName(accessedArg.lexeme, environment);
45
+ const accessedIndicesCollection = filterIndices(indicesCollection, accessArg, isIndexBasedAccess);
46
+ // If the accessed indices couldn't be resolved, overapproximate by returning the original indices.
47
+ // This could also be the case, when nothing is acccessed, but we better be safe.
48
+ if (accessedIndicesCollection === undefined) {
49
+ return indicesCollection;
50
+ }
51
+ else {
52
+ return accessedIndicesCollection;
53
+ }
24
54
  }
25
55
  /**
26
56
  * Filters the single indices of the {@link indicesCollection} according to the lexeme of the {@link accessArg}.
@@ -29,11 +59,11 @@ function resolveSingleIndex(accessedArg, accessArg, environment) {
29
59
  * @param accessArg - The argument which is used to filter {@link indicesCollection}
30
60
  * @returns The filtered copy of {@link indicesCollection}
31
61
  */
32
- function filterIndices(indicesCollection, accessArg) {
62
+ function filterIndices(indicesCollection, accessArg, isIndexBasedAccess) {
33
63
  let accessedIndicesCollection = undefined;
34
64
  for (const indices of indicesCollection ?? []) {
35
- const filteredIndices = indices.indices.filter(index => accessArg.lexeme === index.lexeme);
36
- if (filteredIndices.length == 0) {
65
+ const filteredIndices = indices.indices.filter(index => (0, vertex_1.isAccessed)(index, accessArg.lexeme, isIndexBasedAccess));
66
+ if (filteredIndices.length === 0) {
37
67
  continue;
38
68
  }
39
69
  accessedIndicesCollection ??= [];
@@ -57,7 +87,7 @@ function filterIndices(indicesCollection, accessArg) {
57
87
  * @param leafIndices - The index at the end of the nested access i.e. `c` in `a$b$c`.
58
88
  * @returns The constructed nested access
59
89
  */
60
- function constructNestedAccess(accessedArg, leafIndices) {
90
+ function constructNestedAccess(accessedArg, leafIndices, constructIdentifier) {
61
91
  const accessed = accessedArg.accessed;
62
92
  const accesses = accessedArg.access.filter(arg => arg !== r_function_call_1.EmptyArgument).map(arg => arg);
63
93
  const indices = [];
@@ -65,7 +95,7 @@ function constructNestedAccess(accessedArg, leafIndices) {
65
95
  const newIndices = {
66
96
  indices: [
67
97
  {
68
- lexeme: access.lexeme,
98
+ identifier: constructIdentifier(access),
69
99
  nodeId: access.info.id,
70
100
  subIndices: [leafIndices],
71
101
  }
@@ -73,7 +103,7 @@ function constructNestedAccess(accessedArg, leafIndices) {
73
103
  isContainer: false,
74
104
  };
75
105
  if (accessed.type === type_1.RType.Access) {
76
- const nestedIndices = constructNestedAccess(accessed, newIndices);
106
+ const nestedIndices = constructNestedAccess(accessed, newIndices, constructIdentifier);
77
107
  indices.push(...nestedIndices);
78
108
  }
79
109
  else {
@@ -112,4 +142,4 @@ function addSubIndicesToLeafIndices(indicesCollection, leafSubIndices) {
112
142
  }
113
143
  return result;
114
144
  }
115
- //# sourceMappingURL=list-access.js.map
145
+ //# sourceMappingURL=containers.js.map
@@ -0,0 +1,47 @@
1
+ import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
2
+ import type { GenericDiffConfiguration, GenericDifferenceInformation, WriteableDifferenceReport } from './diff';
3
+ import type { DataflowGraph } from '../dataflow/graph/graph';
4
+ export interface NamedGraph<Graph = DataflowGraph> {
5
+ name: string;
6
+ graph: Graph;
7
+ }
8
+ interface ProblematicVertex {
9
+ tag: 'vertex';
10
+ id: NodeId;
11
+ }
12
+ interface ProblematicEdge {
13
+ tag: 'edge';
14
+ from: NodeId;
15
+ to: NodeId;
16
+ }
17
+ export type ProblematicDiffInfo = ProblematicVertex | ProblematicEdge;
18
+ /**
19
+ * To be produced by a function differencing two graphs (e.g., {@link DataflowGraph|DFGs} or {@link ControlFlowGraph|CFGs}).
20
+ *
21
+ * @see {@link GraphDifferenceReport#isEqual|isEqual} - to check whether the graphs are equal
22
+ * @see {@link GraphDifferenceReport#addComment|addComment} - to add comments to the report
23
+ * @see {@link GraphDifferenceReport#comments|comments} - to get the attached comments
24
+ * @see {@link GraphDifferenceReport#problematic|problematic} - to get the problematic vertices/edges
25
+ */
26
+ export declare class GraphDifferenceReport implements WriteableDifferenceReport {
27
+ _comments: string[] | undefined;
28
+ _problematic: ProblematicDiffInfo[] | undefined;
29
+ addComment(comment: string, ...related: readonly ProblematicDiffInfo[]): void;
30
+ comments(): readonly string[] | undefined;
31
+ problematic(): readonly ProblematicDiffInfo[] | undefined;
32
+ isEqual(): boolean;
33
+ }
34
+ /**
35
+ * A context that can be used by differencing functions to compare two graphs
36
+ * See {@link initDiffContext} for a function that creates such a context.
37
+ */
38
+ export interface GraphDiffContext<Graph = DataflowGraph> extends GenericDifferenceInformation<GraphDifferenceReport> {
39
+ left: Graph;
40
+ right: Graph;
41
+ config: GenericDiffConfiguration;
42
+ }
43
+ /**
44
+ * Create the context for differencing two graphs
45
+ */
46
+ export declare function initDiffContext<Graph>(left: NamedGraph<Graph>, right: NamedGraph<Graph>, config?: Partial<GenericDiffConfiguration>): GraphDiffContext<Graph>;
47
+ export {};
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphDifferenceReport = void 0;
4
+ exports.initDiffContext = initDiffContext;
5
+ /**
6
+ * To be produced by a function differencing two graphs (e.g., {@link DataflowGraph|DFGs} or {@link ControlFlowGraph|CFGs}).
7
+ *
8
+ * @see {@link GraphDifferenceReport#isEqual|isEqual} - to check whether the graphs are equal
9
+ * @see {@link GraphDifferenceReport#addComment|addComment} - to add comments to the report
10
+ * @see {@link GraphDifferenceReport#comments|comments} - to get the attached comments
11
+ * @see {@link GraphDifferenceReport#problematic|problematic} - to get the problematic vertices/edges
12
+ */
13
+ class GraphDifferenceReport {
14
+ _comments = undefined;
15
+ _problematic = undefined;
16
+ addComment(comment, ...related) {
17
+ if (this._comments === undefined) {
18
+ this._comments = [comment];
19
+ }
20
+ else {
21
+ this._comments.push(comment);
22
+ }
23
+ if (related.length > 0) {
24
+ if (this._problematic === undefined) {
25
+ this._problematic = [...related];
26
+ }
27
+ else {
28
+ this._problematic.push(...related);
29
+ }
30
+ }
31
+ }
32
+ comments() {
33
+ return this._comments;
34
+ }
35
+ problematic() {
36
+ return this._problematic;
37
+ }
38
+ isEqual() {
39
+ return this._comments === undefined;
40
+ }
41
+ }
42
+ exports.GraphDifferenceReport = GraphDifferenceReport;
43
+ /**
44
+ * Create the context for differencing two graphs
45
+ */
46
+ function initDiffContext(left, right, config) {
47
+ return {
48
+ left: left.graph,
49
+ leftname: left.name,
50
+ right: right.graph,
51
+ rightname: right.name,
52
+ report: new GraphDifferenceReport(),
53
+ position: '',
54
+ config: {
55
+ rightIsSubgraph: false,
56
+ leftIsSubgraph: false,
57
+ ...config
58
+ }
59
+ };
60
+ }
61
+ //# sourceMappingURL=diff-graph.js.map
package/util/diff.d.ts CHANGED
@@ -12,14 +12,14 @@ import type { MergeableRecord } from './objects';
12
12
  */
13
13
  export interface DifferenceReport {
14
14
  /**
15
- * A human-readable description of differences during the comparison
16
- * In combination with {@link isEqual} this can be used to provide detailed
17
- * explanation on equal structures as well (e.g., if structures _could_ be equal).
18
- */
15
+ * A human-readable description of differences during the comparison
16
+ * In combination with {@link isEqual} this can be used to provide detailed
17
+ * explanation on equal structures as well (e.g., if structures _could_ be equal).
18
+ */
19
19
  comments(): readonly string[] | undefined;
20
20
  /**
21
- * @returns true iff the compared structures are equal (i.e., the diff is empty)
22
- */
21
+ * @returns true iff the compared structures are equal (i.e., the diff is empty)
22
+ */
23
23
  isEqual(): boolean;
24
24
  }
25
25
  export interface WriteableDifferenceReport extends DifferenceReport {
package/util/diff.js CHANGED
@@ -7,7 +7,7 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.setDifference = setDifference;
10
- const set_1 = require("./set");
10
+ const set_1 = require("./collections/set");
11
11
  function setDifference(left, right, info) {
12
12
  const lWithoutR = (0, set_1.setMinus)(left, right);
13
13
  const rWithoutL = (0, set_1.setMinus)(right, left);
@@ -5,9 +5,10 @@ exports.normalizedAstToMermaidUrl = normalizedAstToMermaidUrl;
5
5
  const mermaid_1 = require("./mermaid");
6
6
  const visitor_1 = require("../../r-bridge/lang-4.x/ast/model/processing/visitor");
7
7
  const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
8
+ const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
8
9
  function normalizedAstToMermaid(ast, prefix = 'flowchart TD\n') {
9
10
  let output = prefix;
10
- (0, visitor_1.visitAst)(ast, n => {
11
+ function showNode(n) {
11
12
  const name = `${n.type} (${n.info.id})\\n${n.lexeme ?? ' '}`;
12
13
  output += ` n${n.info.id}(["${(0, mermaid_1.escapeMarkdown)(name)}"])\n`;
13
14
  if (n.info.parent !== undefined) {
@@ -19,6 +20,16 @@ function normalizedAstToMermaid(ast, prefix = 'flowchart TD\n') {
19
20
  output += ` n${n.info.id} -.-|"group-open"| n${n.grouping[0].info.id}\n`;
20
21
  output += ` n${n.info.id} -.-|"group-close"| n${n.grouping[1].info.id}\n`;
21
22
  }
23
+ }
24
+ (0, visitor_1.visitAst)(ast, n => {
25
+ showNode(n);
26
+ if (n.type === 'RAccess' && (n.operator !== '[' && n.operator !== '[[')) {
27
+ for (const k of n.access) {
28
+ if (k !== r_function_call_1.EmptyArgument) {
29
+ showNode(k);
30
+ }
31
+ }
32
+ }
22
33
  return false;
23
34
  });
24
35
  return output;
@@ -1,6 +1,13 @@
1
- import type { ControlFlowInformation } from '../cfg/cfg';
2
1
  import type { NormalizedAst } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
3
- export declare function cfgToMermaid(cfg: ControlFlowInformation, normalizedAst: NormalizedAst, prefix?: string): string;
2
+ import type { ControlFlowInformation } from '../../control-flow/control-flow-graph';
3
+ /**
4
+ * Convert the control flow graph to a mermaid string.
5
+ * @param cfg - The control flow graph to convert.
6
+ * @param normalizedAst - The normalized AST to use for the vertex content.
7
+ * @param prefix - The prefix to use for the mermaid string.
8
+ * @param simplify - Whether to simplify the control flow graph (especially in the context of basic blocks).
9
+ */
10
+ export declare function cfgToMermaid(cfg: ControlFlowInformation, normalizedAst: NormalizedAst, prefix?: string, simplify?: boolean): string;
4
11
  /**
5
12
  * Use mermaid to visualize the normalized AST.
6
13
  */
@@ -3,27 +3,79 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.cfgToMermaid = cfgToMermaid;
4
4
  exports.cfgToMermaidUrl = cfgToMermaidUrl;
5
5
  const mermaid_1 = require("./mermaid");
6
+ const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
7
+ const control_flow_graph_1 = require("../../control-flow/control-flow-graph");
8
+ const reconstruct_1 = require("../../reconstruct/reconstruct");
9
+ const auto_select_defaults_1 = require("../../reconstruct/auto-select/auto-select-defaults");
6
10
  function getLexeme(n) {
7
- return n ? n.info.fullLexeme ?? n.lexeme ?? '<unknown>' : '';
11
+ return n ? n.info.fullLexeme ?? n.lexeme ?? '' : undefined;
8
12
  }
9
- function cfgToMermaid(cfg, normalizedAst, prefix = '') {
10
- let output = prefix + 'flowchart BT\n';
11
- for (const [id, vertex] of cfg.graph.vertices()) {
12
- const normalizedVertex = normalizedAst.idMap.get(id);
13
+ function cfgOfNode(vert, normalizedVertex, id, content, output) {
14
+ if (normalizedVertex && content !== undefined) {
15
+ const start = vert.type === control_flow_graph_1.CfgVertexType.Expression ? '([' : '[';
16
+ const end = vert.type === control_flow_graph_1.CfgVertexType.Expression ? '])' : ']';
17
+ const name = `"\`${(0, mermaid_1.escapeMarkdown)(normalizedVertex.type)} (${id})${content ? '\n' + (0, mermaid_1.escapeMarkdown)(JSON.stringify(content)) : ''}${vert.callTargets ? '\n calls:' + (0, mermaid_1.escapeMarkdown)(JSON.stringify([...vert.callTargets])) : ''}\`"`;
18
+ output += ` n${id}${start}${name}${end}\n`;
19
+ }
20
+ else {
21
+ output += String(id).endsWith('-exit') ? ` n${id}((${id}))\n` : ` n${id}[[${id}]]\n`;
22
+ }
23
+ return output;
24
+ }
25
+ const getDirRegex = /flowchart\s+([A-Za-z]+)/;
26
+ /**
27
+ * Convert the control flow graph to a mermaid string.
28
+ * @param cfg - The control flow graph to convert.
29
+ * @param normalizedAst - The normalized AST to use for the vertex content.
30
+ * @param prefix - The prefix to use for the mermaid string.
31
+ * @param simplify - Whether to simplify the control flow graph (especially in the context of basic blocks).
32
+ */
33
+ function cfgToMermaid(cfg, normalizedAst, prefix = 'flowchart BT\n', simplify = false) {
34
+ let output = prefix;
35
+ const dirIs = getDirRegex.exec(prefix)?.at(1) ?? 'LR';
36
+ for (const [id, vertex] of cfg.graph.vertices(false)) {
37
+ const normalizedVertex = normalizedAst?.idMap.get(id);
13
38
  const content = getLexeme(normalizedVertex);
14
- if (content.length > 0) {
15
- const name = `"\`${(0, mermaid_1.escapeMarkdown)(vertex.name)} (${id})\n${(0, mermaid_1.escapeMarkdown)(JSON.stringify(content))}\`"`;
16
- output += ` n${id}[${name}]\n`;
39
+ if (vertex.name === type_1.RType.ExpressionList && vertex.type === control_flow_graph_1.CfgVertexType.Expression && cfg.graph.hasVertex(id + '-exit')) {
40
+ output += ` subgraph ${type_1.RType.ExpressionList} ${normalizedVertex?.info.fullLexeme ?? id}\n`;
41
+ output += ` direction ${dirIs}\n`;
42
+ }
43
+ if (vertex.type === control_flow_graph_1.CfgVertexType.Block) {
44
+ if (simplify) {
45
+ const ids = vertex.elems?.map(e => e.id) ?? [];
46
+ const reconstruct = (0, reconstruct_1.reconstructToCode)(normalizedAst, new Set(ids), auto_select_defaults_1.doNotAutoSelect).code;
47
+ const name = `"\`Basic Block (${id})\n${(0, mermaid_1.escapeMarkdown)(reconstruct)}\`"`;
48
+ output += ` n${id}[[${name}]]\n`;
49
+ }
50
+ else {
51
+ output += ` subgraph n${vertex.id} [Block ${normalizedVertex?.info.fullLexeme ?? id}]\n`;
52
+ output += ` direction ${dirIs}\n`;
53
+ let last = undefined;
54
+ for (const element of vertex.elems ?? []) {
55
+ const childNormalizedVertex = normalizedAst?.idMap.get(element.id);
56
+ const childContent = getLexeme(childNormalizedVertex);
57
+ output = cfgOfNode(vertex, childNormalizedVertex, element.id, childContent, output);
58
+ // just to keep the order
59
+ if (last) {
60
+ output += ` ${last} -.-> n${element.id}\n`;
61
+ }
62
+ last = `n${element.id}`;
63
+ }
64
+ output += ' end\n';
65
+ }
17
66
  }
18
67
  else {
19
- output += String(id).endsWith('-exit') ? ` n${id}((${id}))\n` : ` n${id}[[${id}]]\n`;
68
+ output = cfgOfNode(vertex, normalizedVertex, id, content, output);
69
+ }
70
+ if (vertex.name === type_1.RType.ExpressionList && vertex.type === control_flow_graph_1.CfgVertexType.EndMarker) {
71
+ output += ' end\n';
20
72
  }
21
73
  }
22
74
  for (const [from, targets] of cfg.graph.edges()) {
23
75
  for (const [to, edge] of targets) {
24
- const edgeType = edge.label === 'CD' ? '-->' : '-.->';
25
- const edgeSuffix = edge.label === 'CD' ? ` (${edge.when})` : '';
26
- output += ` n${from} ${edgeType}|"${(0, mermaid_1.escapeMarkdown)(edge.label)}${edgeSuffix}"| n${to}\n`;
76
+ const edgeType = edge.label === 1 /* CfgEdgeType.Cd */ ? '-->' : '-.->';
77
+ const edgeSuffix = edge.label === 1 /* CfgEdgeType.Cd */ ? ` (${edge.when})` : '';
78
+ output += ` n${from} ${edgeType}|"${(0, mermaid_1.escapeMarkdown)((0, control_flow_graph_1.edgeTypeToString)(edge.label))}${edgeSuffix}"| n${to}\n`;
27
79
  }
28
80
  }
29
81
  for (const entryPoint of cfg.entryPoints) {
@@ -37,7 +89,7 @@ function cfgToMermaid(cfg, normalizedAst, prefix = '') {
37
89
  /**
38
90
  * Use mermaid to visualize the normalized AST.
39
91
  */
40
- function cfgToMermaidUrl(cfg, normalizedAst, prefix = '') {
92
+ function cfgToMermaidUrl(cfg, normalizedAst, prefix = 'flowchart BT\n') {
41
93
  return (0, mermaid_1.mermaidCodeToUrl)(cfgToMermaid(cfg, normalizedAst, prefix));
42
94
  }
43
95
  //# sourceMappingURL=cfg.js.map
@@ -17,12 +17,13 @@ interface MermaidGraph {
17
17
  markStyle: MermaidMarkStyle;
18
18
  /** in the form of from-\>to because I am lazy, see {@link encodeEdge} */
19
19
  presentEdges: Set<string>;
20
+ presentVertices: Set<string>;
20
21
  rootGraph: DataflowGraph;
21
22
  /** if given, the dataflow graph will only focus on the "important" parts */
22
23
  simplified?: boolean;
23
24
  }
24
25
  /**
25
- * Prints a {@link SourceRange|range} as a human readable string.
26
+ * Prints a {@link SourceRange|range} as a human-readable string.
26
27
  */
27
28
  export declare function formatRange(range: SourceRange | undefined): string;
28
29
  export declare function printIdentifier(id: IdentifierDefinition): string;
@@ -9,14 +9,16 @@ exports.diffGraphsToMermaidUrl = diffGraphsToMermaidUrl;
9
9
  const assert_1 = require("../assert");
10
10
  const mermaid_1 = require("./mermaid");
11
11
  const graph_1 = require("../../dataflow/graph/graph");
12
+ const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
12
13
  const identifier_1 = require("../../dataflow/environments/identifier");
13
14
  const r_function_call_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
14
15
  const edge_1 = require("../../dataflow/graph/edge");
15
16
  const vertex_1 = require("../../dataflow/graph/vertex");
16
17
  const environment_1 = require("../../dataflow/environments/environment");
17
18
  const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
19
+ const built_in_1 = require("../../dataflow/environments/built-in");
18
20
  /**
19
- * Prints a {@link SourceRange|range} as a human readable string.
21
+ * Prints a {@link SourceRange|range} as a human-readable string.
20
22
  */
21
23
  function formatRange(range) {
22
24
  if (range === undefined) {
@@ -36,14 +38,14 @@ function subflowToMermaid(nodeId, exitPoints, subflow, mermaid, idPrefix = '') {
36
38
  if (subflow === undefined) {
37
39
  return;
38
40
  }
39
- const subflowId = `${idPrefix}flow-${nodeId}`;
41
+ const subflowId = (0, mermaid_1.escapeId)(`${idPrefix}flow-${nodeId}`);
40
42
  if (mermaid.simplified) {
41
43
  // get parent
42
44
  const idMap = mermaid.rootGraph.idMap;
43
45
  const node = idMap?.get(nodeId);
44
- const nodeLexeme = node?.info.fullLexeme ?? node?.lexeme ?? '??';
46
+ const nodeLexeme = node?.info.fullLexeme ?? node?.lexeme ?? 'function';
45
47
  const location = node?.location?.[0] ? ` (L. ${node?.location?.[0]})` : '';
46
- mermaid.nodeLines.push(`\nsubgraph "${subflowId}" ["${(0, mermaid_1.escapeMarkdown)(nodeLexeme ?? 'function')}${location}"]`);
48
+ mermaid.nodeLines.push(`\nsubgraph "${subflowId}" ["${(0, mermaid_1.escapeMarkdown)(nodeLexeme)}${location}"]`);
47
49
  }
48
50
  else {
49
51
  mermaid.nodeLines.push(`\nsubgraph "${subflowId}" [function ${nodeId}]`);
@@ -147,6 +149,7 @@ function printEnvironmentToLines(env) {
147
149
  function vertexToMermaid(info, mermaid, id, idPrefix, mark) {
148
150
  const fCall = info.tag === vertex_1.VertexType.FunctionCall;
149
151
  const { open, close } = mermaidNodeBrackets(info.tag);
152
+ id = (0, mermaid_1.escapeId)(id);
150
153
  if (info.environment && mermaid.includeEnvironments) {
151
154
  if (info.environment.level > 0 || info.environment.current.memory.size !== 0) {
152
155
  mermaid.nodeLines.push(` %% Environment of ${id} [level: ${info.environment.level}]:`, printEnvironmentToLines(info.environment.current).map(x => ` %% ${x}`).join('\n'));
@@ -162,24 +165,29 @@ function vertexToMermaid(info, mermaid, id, idPrefix, mark) {
162
165
  else {
163
166
  const escapedName = (0, mermaid_1.escapeMarkdown)(node ? `[${node.type}] ${lexeme}` : '??');
164
167
  const deps = info.cds ? ', :may:' + info.cds.map(c => c.id + (c.when ? '+' : '-')).join(',') : '';
168
+ const lnks = info.link?.origin ? ', :links:' + info.link.origin.join(',') : '';
165
169
  const n = node?.info.fullRange ?? node?.location ?? (node?.type === type_1.RType.ExpressionList ? node?.grouping?.[0].location : undefined);
166
- mermaid.nodeLines.push(` ${idPrefix}${id}${open}"\`${escapedName}${escapedName.length > 10 ? '\n ' : ' '}(${id}${deps})\n *${formatRange(n)}*${fCall ? displayFunctionArgMapping(info.args) : ''}\`"${close}`);
170
+ mermaid.nodeLines.push(` ${idPrefix}${id}${open}"\`${escapedName}${escapedName.length > 10 ? '\n ' : ' '}(${id}${deps}${lnks})\n *${formatRange(n)}*${fCall ? displayFunctionArgMapping(info.args) : ''}\`"${close}`);
167
171
  }
168
172
  if (mark?.has(id)) {
169
173
  mermaid.nodeLines.push(` style ${idPrefix}${id} ${mermaid.markStyle.vertex} `);
170
174
  }
171
- if (mermaid.rootGraph.unknownSideEffects.has(id)) {
175
+ if ([...mermaid.rootGraph.unknownSideEffects].some(l => (0, node_id_1.normalizeIdToNumberIfPossible)(l) === (0, node_id_1.normalizeIdToNumberIfPossible)(id))) {
172
176
  mermaid.nodeLines.push(` style ${idPrefix}${id} stroke:red,stroke-width:5px; `);
173
177
  }
174
- const edges = mermaid.rootGraph.get(id, true);
178
+ const edges = mermaid.rootGraph.get((0, node_id_1.normalizeIdToNumberIfPossible)(id), true);
175
179
  (0, assert_1.guard)(edges !== undefined, `node ${id} must be found`);
176
180
  const artificialCdEdges = (info.cds ?? []).map(x => [x.id, { types: new Set([x.when ? 'CD-True' : 'CD-False']) }]);
177
- for (const [target, edge] of [...edges[1], ...artificialCdEdges]) {
181
+ // eslint-disable-next-line prefer-const
182
+ for (let [target, edge] of [...edges[1], ...artificialCdEdges]) {
183
+ const originalTarget = target;
184
+ target = (0, mermaid_1.escapeId)(target);
178
185
  const edgeTypes = typeof edge.types == 'number' ? new Set((0, edge_1.splitEdgeTypes)(edge.types)) : edge.types;
179
186
  const edgeId = encodeEdge(idPrefix + id, idPrefix + target, edgeTypes);
180
187
  if (!mermaid.presentEdges.has(edgeId)) {
181
188
  mermaid.presentEdges.add(edgeId);
182
- mermaid.edgeLines.push(` ${idPrefix}${id} -->|"${[...edgeTypes].map(e => typeof e === 'number' ? (0, edge_1.edgeTypeToName)(e) : e).join(', ')}"| ${idPrefix}${target}`);
189
+ const style = (0, built_in_1.isBuiltIn)(target) ? '-.->' : '-->';
190
+ mermaid.edgeLines.push(` ${idPrefix}${id} ${style}|"${[...edgeTypes].map(e => typeof e === 'number' ? (0, edge_1.edgeTypeToName)(e) : e).join(', ')}"| ${idPrefix}${target}`);
183
191
  if (mermaid.mark?.has(id + '->' + target)) {
184
192
  // who invented this syntax?!
185
193
  mermaid.edgeLines.push(` linkStyle ${mermaid.presentEdges.size - 1} ${mermaid.markStyle.edge}`);
@@ -187,6 +195,14 @@ function vertexToMermaid(info, mermaid, id, idPrefix, mark) {
187
195
  if (edgeTypes.has('CD-True') || edgeTypes.has('CD-False')) {
188
196
  mermaid.edgeLines.push(` linkStyle ${mermaid.presentEdges.size - 1} stroke:gray,color:gray;`);
189
197
  }
198
+ if ((0, built_in_1.isBuiltIn)(target)) {
199
+ mermaid.edgeLines.push(` linkStyle ${mermaid.presentEdges.size - 1} stroke:gray;`);
200
+ if (!mermaid.presentVertices.has(target)) {
201
+ mermaid.nodeLines.push(` ${idPrefix}${target}["\`Built-In:\n${(0, mermaid_1.escapeMarkdown)(String(originalTarget).replace('built-in:', ''))}\`"]`);
202
+ mermaid.nodeLines.push(` style ${idPrefix}${target} stroke:gray,fill:lightgray,stroke-width:2px,opacity:.8;`);
203
+ mermaid.presentVertices.add(target);
204
+ }
205
+ }
190
206
  }
191
207
  }
192
208
  if (info.tag === 'function-definition') {
@@ -195,7 +211,7 @@ function vertexToMermaid(info, mermaid, id, idPrefix, mark) {
195
211
  }
196
212
  // make the passing of root ids more performant again
197
213
  function graphToMermaidGraph(rootIds, { simplified, graph, prefix = 'flowchart BT', idPrefix = '', includeEnvironments = !simplified, mark, rootGraph, presentEdges = new Set(), markStyle = { vertex: 'stroke:teal,stroke-width:7px,stroke-opacity:.8;', edge: 'stroke:teal,stroke-width:4.2px,stroke-opacity:.8' } }) {
198
- const mermaid = { nodeLines: prefix === null ? [] : [prefix], edgeLines: [], presentEdges, mark, rootGraph: rootGraph ?? graph, includeEnvironments, markStyle, simplified };
214
+ const mermaid = { nodeLines: prefix === null ? [] : [prefix], edgeLines: [], presentEdges, presentVertices: new Set(), mark, rootGraph: rootGraph ?? graph, includeEnvironments, markStyle, simplified };
199
215
  for (const [id, info] of graph.vertices(true)) {
200
216
  if (rootIds.has(id)) {
201
217
  vertexToMermaid(info, mermaid, id, idPrefix, mark);
@@ -1,7 +1,9 @@
1
1
  export declare function escapeMarkdown(text: string): string;
2
+ export declare function escapeId(text: string | number): string;
2
3
  /**
3
4
  * Converts mermaid code (potentially produced by {@link graphToMermaid}) to an url that presents the graph in the mermaid editor.
4
5
  *
5
6
  * @param code - code to convert
7
+ * @param edit - if true, the url will point to the editor, otherwise it will point to the viewer
6
8
  */
7
9
  export declare function mermaidCodeToUrl(code: string, edit?: boolean): string;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.escapeMarkdown = escapeMarkdown;
4
+ exports.escapeId = escapeId;
4
5
  exports.mermaidCodeToUrl = mermaidCodeToUrl;
5
6
  const replacements = {
6
7
  // keep newlines
@@ -45,10 +46,15 @@ function escapeMarkdown(text) {
45
46
  }
46
47
  return text;
47
48
  }
49
+ function escapeId(text) {
50
+ text = String(text).replace(/[^a-zA-Z0-9:-]/g, '_');
51
+ return text;
52
+ }
48
53
  /**
49
54
  * Converts mermaid code (potentially produced by {@link graphToMermaid}) to an url that presents the graph in the mermaid editor.
50
55
  *
51
56
  * @param code - code to convert
57
+ * @param edit - if true, the url will point to the editor, otherwise it will point to the viewer
52
58
  */
53
59
  function mermaidCodeToUrl(code, edit = false) {
54
60
  const obj = {
@@ -13,12 +13,13 @@ export declare class LimitedThreadPool {
13
13
  private skipped;
14
14
  private currentlyRunning;
15
15
  private reportingInterval;
16
+ private readonly timeLimitInMs;
16
17
  /**
17
18
  * Create a new parallel helper that runs the given `module` once for each list of {@link Arguments} in the `queue`.
18
19
  * The `limit` stops the execution if `<limit>` number of runs exited successfully.
19
20
  * The `parallel` parameter limits the number of parallel executions.
20
21
  */
21
- constructor(module: string, queue: WorkingQueue, limit: number, parallel: number);
22
+ constructor(module: string, queue: WorkingQueue, limit: number, parallel: number, timeLimitInMs?: number);
22
23
  run(): Promise<void>;
23
24
  getStats(): {
24
25
  counter: number;