@eagleoutice/flowr 2.0.25 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (381) hide show
  1. package/benchmark/slicer.js +2 -1
  2. package/benchmark/stats/print.js +3 -4
  3. package/benchmark/stats/size-of.js +9 -7
  4. package/benchmark/summarizer/first-phase/input.d.ts +0 -1
  5. package/benchmark/summarizer/first-phase/input.js +2 -3
  6. package/benchmark/summarizer/first-phase/process.js +7 -7
  7. package/benchmark/summarizer/second-phase/graph.js +1 -2
  8. package/benchmark/summarizer/second-phase/process.d.ts +0 -1
  9. package/benchmark/summarizer/second-phase/process.js +4 -5
  10. package/benchmark/summarizer/summarizer.js +7 -1
  11. package/cli/benchmark-app.js +6 -1
  12. package/cli/common/features.js +2 -3
  13. package/cli/common/script.js +2 -3
  14. package/cli/common/scripts-info.d.ts +69 -1
  15. package/cli/common/scripts-info.js +6 -6
  16. package/cli/flowr-main-options.d.ts +4 -0
  17. package/cli/flowr-main-options.js +88 -0
  18. package/cli/flowr.d.ts +3 -3
  19. package/cli/flowr.js +22 -31
  20. package/cli/repl/commands/{cfg.d.ts → repl-cfg.d.ts} +1 -1
  21. package/cli/repl/commands/{cfg.js → repl-cfg.js} +3 -3
  22. package/cli/repl/commands/{commands.d.ts → repl-commands.d.ts} +3 -1
  23. package/cli/repl/commands/{commands.js → repl-commands.js} +56 -35
  24. package/cli/repl/commands/{dataflow.d.ts → repl-dataflow.d.ts} +1 -1
  25. package/cli/repl/commands/{dataflow.js → repl-dataflow.js} +2 -2
  26. package/cli/repl/commands/{execute.d.ts → repl-execute.d.ts} +1 -1
  27. package/cli/repl/commands/{execute.js → repl-execute.js} +3 -3
  28. package/cli/repl/commands/repl-lineage.d.ts +15 -0
  29. package/cli/repl/commands/{lineage.js → repl-lineage.js} +14 -12
  30. package/cli/repl/commands/{main.js → repl-main.js} +1 -1
  31. package/cli/repl/commands/{normalize.d.ts → repl-normalize.d.ts} +1 -1
  32. package/cli/repl/commands/{normalize.js → repl-normalize.js} +3 -3
  33. package/cli/repl/commands/{parse.d.ts → repl-parse.d.ts} +1 -1
  34. package/cli/repl/commands/{parse.js → repl-parse.js} +3 -2
  35. package/cli/repl/commands/repl-query.d.ts +8 -0
  36. package/cli/repl/commands/repl-query.js +155 -0
  37. package/cli/repl/commands/repl-quit.d.ts +2 -0
  38. package/cli/repl/commands/{quit.js → repl-quit.js} +1 -1
  39. package/cli/repl/commands/{version.d.ts → repl-version.d.ts} +1 -1
  40. package/cli/repl/commands/{version.js → repl-version.js} +4 -4
  41. package/cli/repl/core.d.ts +1 -2
  42. package/cli/repl/core.js +13 -13
  43. package/cli/repl/execute.d.ts +1 -2
  44. package/cli/repl/execute.js +2 -3
  45. package/cli/repl/print-version.js +3 -4
  46. package/cli/repl/server/connection.d.ts +1 -0
  47. package/cli/repl/server/connection.js +45 -12
  48. package/cli/repl/server/messages/{messages.d.ts → all-messages.d.ts} +8 -7
  49. package/cli/repl/server/messages/{messages.js → all-messages.js} +1 -1
  50. package/cli/repl/server/messages/{analysis.d.ts → message-analysis.d.ts} +2 -1
  51. package/cli/repl/server/messages/message-analysis.js +39 -0
  52. package/cli/repl/server/messages/{error.d.ts → message-error.d.ts} +1 -1
  53. package/cli/repl/server/messages/{error.js → message-error.js} +1 -1
  54. package/cli/repl/server/messages/{hello.d.ts → message-hello.d.ts} +4 -3
  55. package/cli/repl/server/messages/message-hello.js +20 -0
  56. package/cli/repl/server/messages/{lineage.d.ts → message-lineage.d.ts} +2 -1
  57. package/cli/repl/server/messages/message-lineage.js +25 -0
  58. package/cli/repl/server/messages/message-query.d.ts +16 -0
  59. package/cli/repl/server/messages/message-query.js +26 -0
  60. package/cli/repl/server/messages/{repl.d.ts → message-repl.d.ts} +3 -1
  61. package/cli/repl/server/messages/message-repl.js +53 -0
  62. package/cli/repl/server/messages/{slice.d.ts → message-slice.d.ts} +2 -1
  63. package/cli/repl/server/messages/{slice.js → message-slice.js} +14 -6
  64. package/cli/repl/server/net.d.ts +0 -1
  65. package/cli/repl/server/send.d.ts +1 -1
  66. package/cli/repl/server/send.js +2 -3
  67. package/cli/repl/server/server.js +2 -2
  68. package/cli/repl/server/validate.d.ts +1 -1
  69. package/cli/repl/server/validate.js +5 -6
  70. package/cli/run-script.d.ts +8 -0
  71. package/cli/run-script.js +18 -0
  72. package/cli/script-core/statistics-core.d.ts +2 -0
  73. package/cli/script-core/statistics-core.js +100 -0
  74. package/cli/script-core/statistics-helper-core.d.ts +2 -0
  75. package/cli/script-core/statistics-helper-core.js +81 -0
  76. package/cli/script-core/summarizer-core.d.ts +2 -0
  77. package/cli/script-core/summarizer-core.js +51 -0
  78. package/cli/statistics-app.js +3 -87
  79. package/cli/statistics-helper-app.js +3 -77
  80. package/cli/summarizer-app.js +2 -48
  81. package/config.d.ts +20 -4
  82. package/config.js +62 -36
  83. package/core/pipeline-executor.js +11 -1
  84. package/core/print/dataflow-printer.js +4 -5
  85. package/core/print/normalize-printer.js +4 -5
  86. package/core/print/parse-printer.js +1 -2
  87. package/core/print/print.js +2 -3
  88. package/core/print/slice-diff-ansi.js +1 -2
  89. package/core/steps/pipeline/create-pipeline.js +1 -2
  90. package/core/steps/pipeline/default-pipelines.d.ts +18 -18
  91. package/core/steps/pipeline/pipeline.js +1 -2
  92. package/dataflow/environments/append.js +1 -2
  93. package/dataflow/environments/built-in-config.d.ts +47 -0
  94. package/dataflow/environments/built-in-config.js +83 -0
  95. package/dataflow/environments/built-in.d.ts +49 -6
  96. package/dataflow/environments/built-in.js +29 -97
  97. package/dataflow/environments/clone.js +2 -2
  98. package/dataflow/environments/default-builtin-config.d.ts +5 -0
  99. package/dataflow/environments/default-builtin-config.js +83 -0
  100. package/dataflow/environments/define.js +1 -2
  101. package/dataflow/environments/diff.js +5 -6
  102. package/dataflow/environments/environment.js +8 -7
  103. package/dataflow/environments/identifier.d.ts +39 -8
  104. package/dataflow/environments/identifier.js +33 -0
  105. package/dataflow/environments/overwrite.d.ts +6 -5
  106. package/dataflow/environments/overwrite.js +16 -9
  107. package/dataflow/environments/resolve-by-name.d.ts +3 -1
  108. package/dataflow/environments/resolve-by-name.js +40 -8
  109. package/dataflow/environments/scoping.js +2 -3
  110. package/dataflow/extractor.js +25 -24
  111. package/dataflow/graph/dataflowgraph-builder.d.ts +139 -0
  112. package/dataflow/graph/dataflowgraph-builder.js +247 -0
  113. package/dataflow/graph/diff.js +12 -11
  114. package/dataflow/graph/edge.d.ts +2 -2
  115. package/dataflow/graph/edge.js +46 -20
  116. package/dataflow/graph/graph.d.ts +14 -6
  117. package/dataflow/graph/graph.js +25 -21
  118. package/dataflow/graph/quads.js +1 -2
  119. package/dataflow/graph/resolve-graph.d.ts +7 -0
  120. package/dataflow/graph/resolve-graph.js +51 -0
  121. package/dataflow/graph/vertex.d.ts +12 -4
  122. package/dataflow/graph/vertex.js +19 -11
  123. package/dataflow/info.d.ts +3 -7
  124. package/dataflow/info.js +7 -8
  125. package/dataflow/internal/linker.d.ts +3 -1
  126. package/dataflow/internal/linker.js +77 -32
  127. package/dataflow/internal/process/functions/call/argument/make-argument.js +5 -5
  128. package/dataflow/internal/process/functions/call/argument/unpack-argument.js +1 -2
  129. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +10 -8
  130. package/dataflow/internal/process/functions/call/built-in/built-in-apply.d.ts +5 -1
  131. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +27 -10
  132. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +40 -26
  133. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +30 -20
  134. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +10 -9
  135. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +12 -11
  136. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +6 -5
  137. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +7 -6
  138. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +4 -4
  139. package/dataflow/internal/process/functions/call/built-in/built-in-pipe.js +10 -6
  140. package/dataflow/internal/process/functions/call/built-in/built-in-quote.js +7 -3
  141. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -3
  142. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +5 -4
  143. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +6 -6
  144. package/dataflow/internal/process/functions/call/built-in/built-in-special-bin-op.js +3 -3
  145. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +6 -5
  146. package/dataflow/internal/process/functions/call/common.js +30 -19
  147. package/dataflow/internal/process/functions/call/default-call-handling.js +1 -2
  148. package/dataflow/internal/process/functions/call/known-call-handling.js +8 -6
  149. package/dataflow/internal/process/functions/call/named-call-handling.js +7 -6
  150. package/dataflow/internal/process/functions/call/unnamed-call-handling.js +11 -7
  151. package/dataflow/internal/process/functions/process-argument.js +10 -8
  152. package/dataflow/internal/process/functions/process-parameter.js +8 -6
  153. package/dataflow/internal/process/process-named-call.js +3 -3
  154. package/dataflow/internal/process/process-symbol.js +5 -4
  155. package/dataflow/internal/process/process-uninteresting-leaf.js +1 -2
  156. package/dataflow/internal/process/process-value.js +5 -4
  157. package/dataflow/processor.js +1 -2
  158. package/documentation/data/dfg/doc-data-dfg-util.d.ts +20 -0
  159. package/documentation/data/dfg/doc-data-dfg-util.js +13 -0
  160. package/documentation/data/query/example-query-code.d.ts +1 -0
  161. package/documentation/data/query/example-query-code.js +25 -0
  162. package/documentation/data/server/doc-data-server-messages.d.ts +1 -0
  163. package/documentation/data/server/doc-data-server-messages.js +508 -0
  164. package/documentation/doc-util/doc-auto-gen.d.ts +7 -0
  165. package/documentation/doc-util/doc-auto-gen.js +9 -0
  166. package/documentation/doc-util/doc-cfg.d.ts +7 -0
  167. package/documentation/doc-util/doc-cfg.js +18 -0
  168. package/documentation/doc-util/doc-cli-option.d.ts +8 -0
  169. package/documentation/doc-util/doc-cli-option.js +36 -0
  170. package/documentation/doc-util/doc-code.d.ts +1 -0
  171. package/documentation/doc-util/doc-code.js +7 -0
  172. package/documentation/doc-util/doc-dfg.d.ts +21 -0
  173. package/documentation/doc-util/doc-dfg.js +93 -0
  174. package/documentation/doc-util/doc-docker.d.ts +1 -0
  175. package/documentation/doc-util/doc-docker.js +5 -0
  176. package/documentation/doc-util/doc-env.d.ts +2 -0
  177. package/documentation/doc-util/doc-env.js +20 -0
  178. package/documentation/doc-util/doc-files.d.ts +6 -0
  179. package/documentation/doc-util/doc-files.js +25 -0
  180. package/documentation/doc-util/doc-general.d.ts +2 -0
  181. package/documentation/doc-util/doc-general.js +16 -0
  182. package/documentation/doc-util/doc-hover-over.d.ts +1 -0
  183. package/documentation/doc-util/doc-hover-over.js +7 -0
  184. package/documentation/doc-util/doc-issue.d.ts +1 -0
  185. package/documentation/doc-util/doc-issue.js +6 -0
  186. package/documentation/doc-util/doc-ms.d.ts +1 -0
  187. package/documentation/doc-util/doc-ms.js +8 -0
  188. package/documentation/doc-util/doc-normalized-ast.d.ts +11 -0
  189. package/documentation/doc-util/doc-normalized-ast.js +71 -0
  190. package/documentation/doc-util/doc-query.d.ts +24 -0
  191. package/documentation/doc-util/doc-query.js +113 -0
  192. package/documentation/doc-util/doc-repl.d.ts +13 -0
  193. package/documentation/doc-util/doc-repl.js +79 -0
  194. package/documentation/doc-util/doc-server-message.d.ts +37 -0
  195. package/documentation/doc-util/doc-server-message.js +153 -0
  196. package/documentation/doc-util/doc-structure.d.ts +12 -0
  197. package/documentation/doc-util/doc-structure.js +21 -0
  198. package/documentation/doc-util/doc-types.d.ts +38 -0
  199. package/documentation/doc-util/doc-types.js +276 -0
  200. package/{r-bridge/data/print.js → documentation/print-capabilities-markdown.js} +8 -4
  201. package/documentation/print-dataflow-graph-wiki.d.ts +1 -0
  202. package/documentation/print-dataflow-graph-wiki.js +849 -0
  203. package/documentation/print-interface-wiki.d.ts +1 -0
  204. package/documentation/print-interface-wiki.js +401 -0
  205. package/documentation/print-normalized-ast-wiki.d.ts +1 -0
  206. package/documentation/print-normalized-ast-wiki.js +98 -0
  207. package/documentation/print-query-wiki.d.ts +1 -0
  208. package/documentation/print-query-wiki.js +215 -0
  209. package/package.json +29 -33
  210. package/queries/base-query-format.d.ts +11 -0
  211. package/{cli/repl/server/messages/hello.js → queries/base-query-format.js} +1 -1
  212. package/queries/call-context-query/call-context-query-executor.d.ts +11 -0
  213. package/queries/call-context-query/call-context-query-executor.js +255 -0
  214. package/queries/call-context-query/call-context-query-format.d.ts +72 -0
  215. package/queries/call-context-query/call-context-query-format.js +17 -0
  216. package/queries/query-schema.d.ts +7 -0
  217. package/queries/query-schema.js +31 -0
  218. package/queries/query.d.ts +35 -0
  219. package/queries/query.js +57 -0
  220. package/queries/two-layer-collector.d.ts +8 -0
  221. package/queries/two-layer-collector.js +31 -0
  222. package/queries/virtual-query/compound-query.d.ts +24 -0
  223. package/queries/virtual-query/compound-query.js +18 -0
  224. package/queries/virtual-query/virtual-queries.d.ts +15 -0
  225. package/queries/virtual-query/virtual-queries.js +8 -0
  226. package/r-bridge/data/data.d.ts +5 -0
  227. package/r-bridge/data/data.js +6 -0
  228. package/r-bridge/data/get.js +2 -3
  229. package/r-bridge/init.js +2 -2
  230. package/r-bridge/lang-4.x/ast/model/collect.js +1 -2
  231. package/r-bridge/lang-4.x/ast/model/model.d.ts +1 -2
  232. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +3 -0
  233. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +3 -0
  234. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +3 -0
  235. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +5 -0
  236. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +4 -0
  237. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +1 -1
  238. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +10 -1
  239. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +5 -0
  240. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +3 -0
  241. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +3 -0
  242. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +3 -0
  243. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +3 -0
  244. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +1 -1
  245. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +3 -0
  246. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +3 -0
  247. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.js +1 -2
  248. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +3 -0
  249. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +2 -2
  250. package/r-bridge/lang-4.x/ast/model/operators.js +27 -26
  251. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +9 -9
  252. package/r-bridge/lang-4.x/ast/model/processing/fold.js +1 -2
  253. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +5 -0
  254. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +26 -3
  255. package/r-bridge/lang-4.x/ast/model/processing/role.js +1 -2
  256. package/r-bridge/lang-4.x/ast/model/processing/stateful-fold.js +23 -23
  257. package/r-bridge/lang-4.x/ast/model/processing/visitor.js +23 -23
  258. package/r-bridge/lang-4.x/ast/model/type.d.ts +2 -2
  259. package/r-bridge/lang-4.x/ast/model/type.js +221 -12
  260. package/r-bridge/lang-4.x/ast/parser/json/format.js +2 -2
  261. package/r-bridge/lang-4.x/ast/parser/json/parser.js +6 -5
  262. package/r-bridge/lang-4.x/ast/parser/xml/input-format.js +3 -3
  263. package/r-bridge/lang-4.x/ast/parser/xml/internal/control/normalize-if-then-else.js +4 -4
  264. package/r-bridge/lang-4.x/ast/parser/xml/internal/control/normalize-if-then.js +7 -7
  265. package/r-bridge/lang-4.x/ast/parser/xml/internal/expression/normalize-expression.js +4 -4
  266. package/r-bridge/lang-4.x/ast/parser/xml/internal/functions/normalize-argument.js +10 -10
  267. package/r-bridge/lang-4.x/ast/parser/xml/internal/functions/normalize-call.js +18 -18
  268. package/r-bridge/lang-4.x/ast/parser/xml/internal/functions/normalize-definition.js +8 -8
  269. package/r-bridge/lang-4.x/ast/parser/xml/internal/functions/normalize-parameter.js +9 -9
  270. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/normalize-break.js +3 -3
  271. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/normalize-for.js +10 -10
  272. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/normalize-next.js +3 -3
  273. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/normalize-repeat.js +5 -5
  274. package/r-bridge/lang-4.x/ast/parser/xml/internal/loops/normalize-while.js +7 -7
  275. package/r-bridge/lang-4.x/ast/parser/xml/internal/normalize-access.js +12 -12
  276. package/r-bridge/lang-4.x/ast/parser/xml/internal/operators/normalize-binary.js +14 -14
  277. package/r-bridge/lang-4.x/ast/parser/xml/internal/operators/normalize-unary.js +4 -4
  278. package/r-bridge/lang-4.x/ast/parser/xml/internal/other/normalize-comment.js +3 -3
  279. package/r-bridge/lang-4.x/ast/parser/xml/internal/other/normalize-line-directive.js +4 -4
  280. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/normalize-delimiter.js +3 -3
  281. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/normalize-expressions.js +13 -13
  282. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/normalize-root.js +6 -6
  283. package/r-bridge/lang-4.x/ast/parser/xml/internal/structure/normalize-single-node.js +19 -19
  284. package/r-bridge/lang-4.x/ast/parser/xml/internal/values/normalize-number.js +5 -5
  285. package/r-bridge/lang-4.x/ast/parser/xml/internal/values/normalize-string.js +3 -3
  286. package/r-bridge/lang-4.x/ast/parser/xml/internal/values/normalize-symbol.js +2 -3
  287. package/r-bridge/lang-4.x/ast/parser/xml/normalize-meta.js +12 -12
  288. package/r-bridge/lang-4.x/convert-values.js +7 -7
  289. package/r-bridge/retriever.js +12 -11
  290. package/r-bridge/shell.d.ts +0 -1
  291. package/r-bridge/shell.js +6 -1
  292. package/reconstruct/auto-select/auto-select-defaults.js +1 -2
  293. package/reconstruct/auto-select/magic-comments.js +3 -3
  294. package/reconstruct/reconstruct.js +4 -3
  295. package/slicing/criterion/collect-all.js +1 -2
  296. package/slicing/criterion/parse.d.ts +1 -1
  297. package/slicing/criterion/parse.js +6 -5
  298. package/slicing/static/fingerprint.js +2 -3
  299. package/slicing/static/slice-call.js +9 -9
  300. package/slicing/static/static-slicer.js +5 -4
  301. package/statistics/features/common-syntax-probability.js +13 -13
  302. package/statistics/features/feature.d.ts +5 -9
  303. package/statistics/features/feature.js +2 -2
  304. package/statistics/features/post-processing.js +2 -3
  305. package/statistics/features/supported/assignments/assignments.js +3 -2
  306. package/statistics/features/supported/assignments/post-process.js +1 -2
  307. package/statistics/features/supported/comments/post-process.js +1 -2
  308. package/statistics/features/supported/control-flow/control-flow.js +4 -3
  309. package/statistics/features/supported/control-flow/post-process.js +1 -2
  310. package/statistics/features/supported/data-access/data-access.d.ts +2 -2
  311. package/statistics/features/supported/data-access/data-access.js +3 -2
  312. package/statistics/features/supported/data-access/post-process.js +1 -2
  313. package/statistics/features/supported/defined-functions/defined-functions.js +9 -7
  314. package/statistics/features/supported/defined-functions/post-process.d.ts +1 -1
  315. package/statistics/features/supported/defined-functions/post-process.js +2 -3
  316. package/statistics/features/supported/expression-list/post-process.js +1 -2
  317. package/statistics/features/supported/expression-list/{expression-list.js → statistics-expression-list.js} +4 -3
  318. package/statistics/features/supported/loops/loops.js +8 -7
  319. package/statistics/features/supported/loops/post-process.js +1 -2
  320. package/statistics/features/supported/used-functions/post-process.js +2 -3
  321. package/statistics/features/supported/used-functions/used-functions.d.ts +1 -1
  322. package/statistics/features/supported/used-functions/used-functions.js +4 -3
  323. package/statistics/features/supported/used-packages/post-process.js +1 -2
  324. package/statistics/features/supported/values/post-process.js +1 -2
  325. package/statistics/features/supported/variables/post-process.js +2 -3
  326. package/statistics/features/supported/variables/variables.js +2 -1
  327. package/statistics/meta-statistics.js +1 -2
  328. package/statistics/output/print-stats.js +4 -5
  329. package/statistics/output/statistics-file.js +5 -5
  330. package/statistics/statistics.js +2 -3
  331. package/statistics/summarizer/auto-detect.js +1 -2
  332. package/statistics/summarizer/post-process/clusterer.js +1 -2
  333. package/statistics/summarizer/post-process/file-based-count.js +2 -3
  334. package/statistics/summarizer/post-process/histogram.js +3 -4
  335. package/statistics/summarizer/post-process/post-process-output.js +2 -3
  336. package/statistics/summarizer/second-phase/process.d.ts +2 -0
  337. package/statistics/summarizer/second-phase/process.js +2 -2
  338. package/statistics/summarizer/summarizer.js +8 -1
  339. package/util/ansi.d.ts +1 -0
  340. package/util/ansi.js +27 -4
  341. package/util/args.js +2 -3
  342. package/util/arrays.js +8 -9
  343. package/util/assert.js +5 -6
  344. package/util/bimap.d.ts +4 -4
  345. package/util/cfg/cfg.d.ts +1 -0
  346. package/util/cfg/cfg.js +8 -5
  347. package/util/cfg/visitor.d.ts +8 -13
  348. package/util/cfg/visitor.js +22 -56
  349. package/util/diff.js +1 -2
  350. package/util/files.d.ts +0 -1
  351. package/util/files.js +11 -8
  352. package/util/json.js +2 -3
  353. package/util/mermaid/ast.js +7 -7
  354. package/util/mermaid/cfg.js +2 -3
  355. package/util/mermaid/dfg.d.ts +12 -4
  356. package/util/mermaid/dfg.js +28 -16
  357. package/util/mermaid/mermaid.js +5 -4
  358. package/util/numbers.js +1 -2
  359. package/util/objects.d.ts +7 -0
  360. package/util/objects.js +13 -3
  361. package/util/os.js +1 -2
  362. package/util/quads.js +5 -5
  363. package/util/random.js +2 -2
  364. package/util/range.js +8 -9
  365. package/util/schema.d.ts +11 -0
  366. package/util/schema.js +75 -0
  367. package/util/set.js +2 -3
  368. package/util/strings.js +3 -4
  369. package/util/summarizer.js +4 -4
  370. package/util/text.d.ts +1 -0
  371. package/util/text.js +20 -0
  372. package/util/time.js +1 -2
  373. package/util/version.js +2 -3
  374. package/cli/repl/commands/lineage.d.ts +0 -15
  375. package/cli/repl/commands/quit.d.ts +0 -2
  376. package/cli/repl/server/messages/analysis.js +0 -21
  377. package/cli/repl/server/messages/lineage.js +0 -17
  378. package/cli/repl/server/messages/repl.js +0 -37
  379. /package/cli/repl/commands/{main.d.ts → repl-main.d.ts} +0 -0
  380. /package/{r-bridge/data/print.d.ts → documentation/print-capabilities-markdown.d.ts} +0 -0
  381. /package/statistics/features/supported/expression-list/{expression-list.d.ts → statistics-expression-list.d.ts} +0 -0
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const shell_1 = require("../r-bridge/shell");
4
+ const doc_dfg_1 = require("./doc-util/doc-dfg");
5
+ const log_1 = require("../../test/functionality/_helper/log");
6
+ const query_1 = require("../queries/query");
7
+ const doc_files_1 = require("./doc-util/doc-files");
8
+ const doc_query_1 = require("./doc-util/doc-query");
9
+ const call_context_query_format_1 = require("../queries/call-context-query/call-context-query-format");
10
+ const schema_1 = require("../util/schema");
11
+ const query_schema_1 = require("../queries/query-schema");
12
+ const ansi_1 = require("../util/ansi");
13
+ const call_context_query_executor_1 = require("../queries/call-context-query/call-context-query-executor");
14
+ const compound_query_1 = require("../queries/virtual-query/compound-query");
15
+ const doc_auto_gen_1 = require("./doc-util/doc-auto-gen");
16
+ const example_query_code_1 = require("./data/query/example-query-code");
17
+ const doc_structure_1 = require("./doc-util/doc-structure");
18
+ const doc_code_1 = require("./doc-util/doc-code");
19
+ (0, doc_query_1.registerQueryDocumentation)('call-context', {
20
+ name: 'Call-Context Query',
21
+ type: 'active',
22
+ shortDescription: 'Finds all calls in a set of files that matches specified criteria.',
23
+ functionName: call_context_query_executor_1.executeCallContextQueries.name,
24
+ functionFile: '../queries/call-context-query/call-context-query-executor.ts',
25
+ buildExplanation: async (shell) => {
26
+ return `
27
+ Call context queries may be used to identify calls to specific functions that match criteria of your interest.
28
+ For now, we support two criteria:
29
+
30
+ 1. **Function Name** (\`callName\`): The function name is specified by a regular expression. This allows you to find all calls to functions that match a specific pattern.
31
+ 2. **Call Targets** (\`callTargets\`): This specifies to what the function call targets. For example, you may want to find all calls to a function that is not defined locally.
32
+
33
+ Besides this we provide the following ways to automatically categorize and link identified invocations:
34
+
35
+ 1. **Kind** (\`kind\`): This is a general category that can be used to group calls together. For example, you may want to link all calls to \`plot\` to \`visualize\`.
36
+ 2. **Subkind** (\`subkind\`): This is used to uniquely identify the respective call type when grouping the output. For example, you may want to link all calls to \`ggplot\` to \`plot\`.
37
+ 3. **Linked Calls** (\`linkTo\`): This links the current call to the last call of the given kind. This way, you can link a call like \`points\` to the latest graphics plot etc.
38
+ For now, we _only_offer support for linking to the last call_ as the current flow dependency over-approximation is not stable.
39
+ 4. **Aliases** (\`includeAliases\`): Consider a case like \`f <- function_of_interest\`, do you want calls to \`f\` to be included in the results? There is probably no need to combine this with a global call target!
40
+
41
+ Re-using the example code from above, the following query attaches all calls to \`mean\` to the kind \`visualize\` and the subkind \`text\`,
42
+ all calls that start with \`read_\` to the kind \`input\` but only if they are not locally overwritten, and the subkind \`csv-file\`, and links all calls to \`points\` to the last call to \`plot\`:
43
+
44
+ ${await (0, doc_query_1.showQuery)(shell, example_query_code_1.exampleQueryCode, [
45
+ { type: 'call-context', callName: '^mean$', kind: 'visualize', subkind: 'text' },
46
+ {
47
+ type: 'call-context',
48
+ callName: '^read_',
49
+ kind: 'input',
50
+ subkind: 'csv-file',
51
+ callTargets: call_context_query_format_1.CallTargets.OnlyGlobal
52
+ },
53
+ {
54
+ type: 'call-context',
55
+ callName: '^points$',
56
+ kind: 'visualize',
57
+ subkind: 'plot',
58
+ linkTo: { type: 'link-to-last-call', callName: '^plot$' }
59
+ }
60
+ ], { showCode: false })}
61
+
62
+ As you can see, all kinds and subkinds with the same name are grouped together.
63
+ Yet, re-stating common arguments and kinds may be cumbersome (although you can already use clever regex patterns).
64
+ See the [Compound Query](#compound-query) for a way to structure your queries more compactly if you think it gets too verbose.
65
+
66
+ ${await (async () => {
67
+ const code = `
68
+ foo <- my_test_function
69
+ foo()
70
+ if(u) bar <- foo
71
+ bar()
72
+ my_test_function()
73
+ `.trim();
74
+ return (0, doc_structure_1.details)('Alias Example', `Consider the following code: ${(0, doc_code_1.codeBlock)('r', code)}\nNow let's say we want to query _all_ uses of the \`my_test_function\`:` + await (0, doc_query_1.showQuery)(shell, code, [
75
+ { type: 'call-context', callName: '^my_test_function', includeAliases: true }
76
+ ], { showCode: false }));
77
+ })()}
78
+ `;
79
+ }
80
+ });
81
+ (0, doc_query_1.registerQueryDocumentation)('compound', {
82
+ name: 'Compound Query',
83
+ type: 'virtual',
84
+ shortDescription: 'Combines multiple queries of the same type into one, specifying common arguments.',
85
+ functionName: compound_query_1.executeCompoundQueries.name,
86
+ functionFile: '../queries/virtual-query/compound-query.ts',
87
+ buildExplanation: async (shell) => {
88
+ return `
89
+ A compound query comes in use, whenever we want to state multiple queries of the same type with a set of common arguments.
90
+ It offers the following properties of interest:
91
+
92
+ 1. **Query** (\`query\`): the type of the query that is to be combined.
93
+ 2. **Common Arguments** (\`commonArguments\`): The arguments that are to be used as defaults for all queries (i.e., any argument the query may have).
94
+ 3. **Arguments** (\`arguments\`): The other arguments for the individual queries that are to be combined.
95
+
96
+ For example, consider the following compound query that combines two call-context queries for \`mean\` and \`print\`, both of which are to be
97
+ assigned to the kind \`visualize\` and the subkind \`text\` (using the example code from above):
98
+
99
+ ${await (0, doc_query_1.showQuery)(shell, example_query_code_1.exampleQueryCode, [{
100
+ type: 'compound',
101
+ query: 'call-context',
102
+ commonArguments: { kind: 'visualize', subkind: 'text' },
103
+ arguments: [
104
+ { callName: '^mean$' },
105
+ { callName: '^print$' }
106
+ ]
107
+ }], { showCode: false })}
108
+
109
+ Of course, in this specific scenario, the following query would be equivalent:
110
+
111
+ ${await (0, doc_query_1.showQuery)(shell, example_query_code_1.exampleQueryCode, [
112
+ { type: 'call-context', callName: '^(mean|print)$', kind: 'visualize', subkind: 'text' }
113
+ ], { showCode: false, collapseResult: true })}
114
+
115
+ However, compound queries become more useful whenever common arguments can not be expressed as a union in one of their properties.
116
+ Additionally, you can still overwrite default arguments.
117
+ In the following, we (by default) want all calls to not resolve to a local definition, except for those to \`print\` for which we explicitly
118
+ want to resolve to a local definition:
119
+
120
+ ${await (0, doc_query_1.showQuery)(shell, example_query_code_1.exampleQueryCode, [{
121
+ type: 'compound',
122
+ query: 'call-context',
123
+ commonArguments: { kind: 'visualize', subkind: 'text', callTargets: call_context_query_format_1.CallTargets.OnlyGlobal },
124
+ arguments: [
125
+ { callName: '^mean$' },
126
+ { callName: '^print$', callTargets: call_context_query_format_1.CallTargets.OnlyLocal }
127
+ ]
128
+ }], { showCode: false })}
129
+
130
+ Now, the results no longer contain calls to \`plot\` that are not defined locally.
131
+
132
+ `;
133
+ }
134
+ });
135
+ async function getText(shell) {
136
+ const rversion = (await shell.usedRVersion())?.format() ?? 'unknown';
137
+ return `${(0, doc_auto_gen_1.autoGenHeader)({ filename: module.filename, purpose: 'query API', rVersion: rversion })}
138
+
139
+ This page briefly summarizes flowR's query API, represented by the ${query_1.executeQueries.name} function in ${(0, doc_files_1.getFilePathMd)('../queries/query.ts')}.
140
+ Please see the [Interface](${doc_files_1.FlowrWikiBaseRef}/Interface) wiki page for more information on how to access this API.
141
+
142
+ First, consider that you have a file like the following (of course, this is just a simple and artificial example):
143
+
144
+ \`\`\`r
145
+ ${example_query_code_1.exampleQueryCode}
146
+ \`\`\`
147
+
148
+ <details> <summary>Dataflow Graph of the Example</summary>
149
+
150
+ ${await (0, doc_dfg_1.printDfGraphForCode)(shell, example_query_code_1.exampleQueryCode, { showCode: false })}
151
+
152
+ </details>
153
+
154
+ &nbsp;
155
+
156
+ Additionally, consider that you are interested in all function calls which loads data with \`read_csv\`.
157
+ A simple \`regex\`-based query could look like this: \`^read_csv$\`.
158
+ However, this fails to incorporate
159
+
160
+ 1. Syntax-based information (comments, strings, used as a variable, called as a higher-order function, ...)
161
+ 2. Semantic information (e.g., \`read_csv\` is overwritten by a function with the same name)
162
+ 3. Context information (e.g., calls like \`points\` may link to the current plot)
163
+
164
+ To solve this, flowR provides a query API which allows you to specify queries on the dataflow graph.
165
+ For the specific use-case stated, you could use the [Call-Context Query](#call-context-query) to find all calls to \`read_csv\` which refer functions that are not overwritten.
166
+
167
+ Just as an example, the following [Call-Context Query](#call-context-query) finds all calls to \`read_csv\` that are not overwritten:
168
+
169
+ ${await (0, doc_query_1.showQuery)(shell, example_query_code_1.exampleQueryCode, [{ type: 'call-context', callName: '^read_csv$', callTargets: call_context_query_format_1.CallTargets.OnlyGlobal, kind: 'input', subkind: 'csv-file' }], { showCode: false })}
170
+
171
+ ## The Query Format
172
+
173
+ Queries are JSON arrays of query objects, each of which uses a \`type\` property to specify the query type.
174
+ In general, we separate two types of queries:
175
+
176
+ 1. **Active Queries**: Are exactly what you would expect from a query (e.g., the [Call-Context Query](#call-context-query)). They fetch information from the dataflow graph.
177
+ 2. **Virtual Queries**: Are used to structure your queries (e.g., the [Compound Query](#compound-query)).
178
+
179
+ We separate these from a concept perspective.
180
+ For now, we support the following **active** queries (which we will refer to simply as a \`query\`):
181
+
182
+ ${(0, doc_query_1.tocForQueryType)('active')}
183
+
184
+ Similarly, we support the following **virtual** queries:
185
+
186
+ ${(0, doc_query_1.tocForQueryType)('virtual')}
187
+
188
+ <details>
189
+
190
+
191
+ <summary>Detailed Query Format (Automatically Generated)</summary>
192
+
193
+ Although it is probably better to consult the detailed explanations below, if you want to have a look at the scehma, here is its description:
194
+
195
+ ${(0, schema_1.describeSchema)(query_schema_1.QueriesSchema, ansi_1.markdownFormatter)}
196
+
197
+ </details>
198
+
199
+ ${await (0, doc_query_1.explainQueries)(shell, 'active')}
200
+
201
+ ${await (0, doc_query_1.explainQueries)(shell, 'virtual')}
202
+
203
+ `;
204
+ }
205
+ /** if we run this script, we want a Markdown representation of the capabilities */
206
+ if (require.main === module) {
207
+ (0, log_1.setMinLevelOfAllLogs)(6 /* LogLevel.Fatal */);
208
+ const shell = new shell_1.RShell();
209
+ void getText(shell).then(str => {
210
+ console.log(str);
211
+ }).finally(() => {
212
+ shell.close();
213
+ });
214
+ }
215
+ //# sourceMappingURL=print-query-wiki.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eagleoutice/flowr",
3
- "version": "2.0.25",
3
+ "version": "2.1.0",
4
4
  "description": "Static Dataflow Analyzer and Program Slicer for the R Programming Language",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "repository": {
@@ -24,7 +24,11 @@
24
24
  "benchmark": "npm run build && node dist/src/cli/benchmark-app.js",
25
25
  "summarizer": "ts-node src/cli/summarizer-app.ts",
26
26
  "export-quads": "ts-node src/cli/export-quads-app.ts",
27
- "capabilities-markdown": "ts-node src/r-bridge/data/print.ts",
27
+ "capabilities-markdown": "ts-node src/documentation/print-capabilities-markdown.ts",
28
+ "wiki:df-graph": "ts-node src/documentation/print-dataflow-graph-wiki.ts",
29
+ "wiki:normalized-ast": "ts-node src/documentation/print-normalized-ast-wiki.ts",
30
+ "wiki:query-api": "ts-node src/documentation/print-query-wiki.ts",
31
+ "wiki:interface": "ts-node src/documentation/print-interface-wiki.ts",
28
32
  "build": "tsc --project .",
29
33
  "build:bundle-flowr": "npm run build && esbuild --bundle dist/src/cli/flowr.js --platform=node --bundle --minify --target=node18 --outfile=dist/src/cli/flowr.min.js",
30
34
  "lint-local": "npx eslint --version && npx eslint src/ test/ --rule \"no-warning-comments: off\"",
@@ -185,11 +189,8 @@
185
189
  "devDependencies": {
186
190
  "@commitlint/cli": "^19.3.0",
187
191
  "@commitlint/config-angular": "^19.3.0",
188
- "@eagleoutice/eslint-config-flowr": "^1.0.11",
192
+ "@eagleoutice/eslint-config-flowr": "^1.0.14",
189
193
  "@j-ulrich/release-it-regex-bumper": "^5.1.0",
190
- "@stylistic/eslint-plugin": "^2.1.0",
191
- "@stylistic/eslint-plugin-plus": "^2.1.0",
192
- "@stylistic/eslint-plugin-ts": "^2.1.0",
193
194
  "@types/chai": "^4.3.16",
194
195
  "@types/chai-as-promised": "^7.1.8",
195
196
  "@types/command-line-args": "^5.2.3",
@@ -204,41 +205,36 @@
204
205
  "@typescript-eslint/eslint-plugin": "^7.8.0",
205
206
  "chai": "^4.3.16",
206
207
  "chai-as-promised": "^7.1.1",
207
- "esbuild": "0.21.3",
208
- "eslint": "^8.57.0",
209
- "eslint-plugin-check-file": "^2.8.0",
210
- "eslint-plugin-import": "^2.29.1",
211
- "eslint-plugin-n": "^17.6.0",
212
- "eslint-plugin-promise": "^6.1.1",
213
- "eslint-plugin-tsdoc": "^0.2.17",
208
+ "esbuild": "^0.23.1",
209
+ "eslint": "^8.57.1",
214
210
  "license-checker": "^25.0.1",
215
- "mocha": "^10.2.0",
211
+ "mocha": "^10.7.3",
216
212
  "mocha-multi-reporters": "^1.5.1",
217
- "nyc": "^15.1.0",
218
- "release-it": "^17.0.1",
213
+ "nyc": "^17.0.0",
214
+ "release-it": "^17.6.0",
219
215
  "ts-node": "^10.9.2",
220
- "typedoc": "^0.25.13",
221
- "typedoc-plugin-missing-exports": "^2.2.0",
222
- "typedoc-theme-hierarchy": "^4.1.2",
223
- "typedoc-umlclass": "^0.9.0",
224
- "typescript": "^5.3.3"
216
+ "typedoc": "^0.26.7",
217
+ "typedoc-plugin-missing-exports": "^3.0.0",
218
+ "typedoc-theme-hierarchy": "^5.0.3",
219
+ "typedoc-umlclass": "^0.10.0",
220
+ "typescript": "^5.6.2"
225
221
  },
226
222
  "dependencies": {
227
- "@xmldom/xmldom": "^0.8.10",
228
- "command-line-args": "^5.2.1",
229
- "command-line-usage": "^7.0.1",
230
- "joi": "^17.13.1",
223
+ "@xmldom/xmldom": "^0.9.2",
224
+ "command-line-args": "^6.0.0",
225
+ "command-line-usage": "^7.0.3",
226
+ "joi": "^17.13.3",
231
227
  "n-readlines": "^1.0.1",
232
- "n3": "^1.17.2",
228
+ "n3": "^1.21.3",
233
229
  "object-hash": "^3.0.0",
234
- "object-sizeof": "^2.6.4",
235
- "rotating-file-stream": "^3.1.1",
236
- "semver": "^7.5.4",
237
- "tar": "^7.1.0",
230
+ "object-sizeof": "^2.6.5",
231
+ "rotating-file-stream": "^3.2.5",
232
+ "semver": "^7.6.3",
233
+ "tar": "^7.4.3",
238
234
  "tmp": "^0.2.3",
239
- "ts-essentials": "^9.4.1",
240
- "tslog": "^4.9.2",
241
- "ws": "^8.17.0",
235
+ "ts-essentials": "^10.0.2",
236
+ "tslog": "^4.9.3",
237
+ "ws": "^8.18.0",
242
238
  "xpath-ts2": "^1.4.2"
243
239
  }
244
240
  }
@@ -0,0 +1,11 @@
1
+ export interface BaseQueryFormat {
2
+ /** used to select the query type :) */
3
+ readonly type: string;
4
+ }
5
+ export interface BaseQueryMeta {
6
+ /** Duration in milliseconds */
7
+ readonly timing: number;
8
+ }
9
+ export interface BaseQueryResult {
10
+ readonly '.meta': BaseQueryMeta;
11
+ }
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=hello.js.map
3
+ //# sourceMappingURL=base-query-format.js.map
@@ -0,0 +1,11 @@
1
+ import type { CallContextQuery, CallContextQueryResult } from './call-context-query-format';
2
+ import type { BasicQueryData } from '../query';
3
+ /**
4
+ * Multi-stage call context query resolve.
5
+ *
6
+ * 1. Resolve all calls in the DF graph that match the respective {@link DefaultCallContextQueryFormat#callName} regex.
7
+ * 2. Identify their respective call targets, if {@link DefaultCallContextQueryFormat#callTargets} is set to be non-any.
8
+ * This happens during the main resolution!
9
+ * 3. Attach `linkTo` calls to the respective calls.
10
+ */
11
+ export declare function executeCallContextQueries({ graph, ast }: BasicQueryData, queries: readonly CallContextQuery[]): CallContextQueryResult;
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeCallContextQueries = executeCallContextQueries;
4
+ const call_context_query_format_1 = require("./call-context-query-format");
5
+ const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
6
+ const vertex_1 = require("../../dataflow/graph/vertex");
7
+ const assert_1 = require("../../util/assert");
8
+ const edge_1 = require("../../dataflow/graph/edge");
9
+ const resolve_by_name_1 = require("../../dataflow/environments/resolve-by-name");
10
+ const built_in_1 = require("../../dataflow/environments/built-in");
11
+ const cfg_1 = require("../../util/cfg/cfg");
12
+ const two_layer_collector_1 = require("../two-layer-collector");
13
+ const objects_1 = require("../../util/objects");
14
+ const visitor_1 = require("../../util/cfg/visitor");
15
+ const identifier_1 = require("../../dataflow/environments/identifier");
16
+ function satisfiesCallTargets(id, graph, callTarget) {
17
+ const callVertex = graph.get(id);
18
+ if (callVertex === undefined || callVertex[0].tag !== vertex_1.VertexType.FunctionCall) {
19
+ return 'no';
20
+ }
21
+ const [info, outgoing] = callVertex;
22
+ const callTargets = [...outgoing]
23
+ .filter(([, e]) => (0, edge_1.edgeIncludesType)(e.types, edge_1.EdgeType.Calls))
24
+ .map(([t]) => t);
25
+ let builtIn = false;
26
+ if (info.environment === undefined) {
27
+ /* if we have a call with an unbound environment,
28
+ * this only happens if we are sure of built-in relations and want to save references
29
+ */
30
+ builtIn = true;
31
+ }
32
+ else {
33
+ /*
34
+ * for performance and scoping reasons, flowR will not identify the global linkage,
35
+ * including any potential built-in mapping.
36
+ */
37
+ const reResolved = (0, resolve_by_name_1.resolveByName)(info.name, info.environment, identifier_1.ReferenceType.Unknown);
38
+ if (reResolved && reResolved.some(t => t.definedAt === built_in_1.BuiltIn)) {
39
+ builtIn = true;
40
+ }
41
+ }
42
+ switch (callTarget) {
43
+ case call_context_query_format_1.CallTargets.Any:
44
+ return callTargets;
45
+ case call_context_query_format_1.CallTargets.OnlyGlobal:
46
+ if (callTargets.length === 0) {
47
+ return builtIn ? [built_in_1.BuiltIn] : [];
48
+ }
49
+ else {
50
+ return 'no';
51
+ }
52
+ case call_context_query_format_1.CallTargets.MustIncludeGlobal:
53
+ return builtIn || callTargets.length === 0 ? [...callTargets, built_in_1.BuiltIn] : 'no';
54
+ case call_context_query_format_1.CallTargets.OnlyLocal:
55
+ return !builtIn && callTargets.length > 0 ? callTargets : 'no';
56
+ case call_context_query_format_1.CallTargets.MustIncludeLocal:
57
+ if (callTargets.length > 0) {
58
+ return builtIn ? [...callTargets, built_in_1.BuiltIn] : callTargets;
59
+ }
60
+ else {
61
+ return 'no';
62
+ }
63
+ default:
64
+ (0, assert_1.assertUnreachable)(callTarget);
65
+ }
66
+ }
67
+ /* if the node is effected by nse, we have an ingoing nse edge */
68
+ function isQuoted(node, graph) {
69
+ const vertex = graph.ingoingEdges(node);
70
+ if (vertex === undefined) {
71
+ return false;
72
+ }
73
+ return [...vertex.values()].some(({ types }) => (0, edge_1.edgeIncludesType)(types, edge_1.EdgeType.NonStandardEvaluation));
74
+ }
75
+ function makeReport(collector) {
76
+ const result = {};
77
+ for (const [kind, collected] of collector.store) {
78
+ const subkinds = {};
79
+ for (const [subkind, values] of collected) {
80
+ subkinds[subkind] ??= [];
81
+ const collectIn = subkinds[subkind];
82
+ for (const value of values) {
83
+ collectIn.push(value);
84
+ }
85
+ }
86
+ result[kind] = {
87
+ subkinds
88
+ };
89
+ }
90
+ return result;
91
+ }
92
+ function isSubCallQuery(query) {
93
+ return 'linkTo' in query;
94
+ }
95
+ function promoteQueryCallNames(queries) {
96
+ let requiresCfg = false;
97
+ const promotedQueries = queries.map(q => {
98
+ if (isSubCallQuery(q)) {
99
+ requiresCfg = true;
100
+ return {
101
+ ...q,
102
+ callName: new RegExp(q.callName),
103
+ linkTo: {
104
+ ...q.linkTo,
105
+ /* we have to add another promotion layer whenever we add something without this call name */
106
+ callName: new RegExp(q.linkTo.callName)
107
+ }
108
+ };
109
+ }
110
+ else {
111
+ return {
112
+ ...q,
113
+ callName: new RegExp(q.callName)
114
+ };
115
+ }
116
+ });
117
+ return { promotedQueries, requiresCfg };
118
+ }
119
+ function identifyLinkToLastCallRelation(from, cfg, graph, linkTo) {
120
+ const found = [];
121
+ (0, visitor_1.visitInReverseOrder)(cfg, from, node => {
122
+ /* we ignore the start id as it cannot be the last call */
123
+ if (node === from) {
124
+ return;
125
+ }
126
+ const vertex = graph.getVertex(node);
127
+ if (vertex === undefined || vertex.tag !== vertex_1.VertexType.FunctionCall) {
128
+ return;
129
+ }
130
+ if (linkTo.test(vertex.name)) {
131
+ found.push(node);
132
+ return true;
133
+ }
134
+ });
135
+ return found;
136
+ }
137
+ /* maybe we want to add caches to this */
138
+ function retrieveAllCallAliases(nodeId, graph) {
139
+ /* we want the names of all functions called at the source id, including synonyms and returns */
140
+ const aliases = new Map();
141
+ const visited = new Set();
142
+ /* we store the current call name */
143
+ const queue = [[(0, node_id_1.recoverContent)(nodeId, graph) ?? '', nodeId]];
144
+ while (queue.length > 0) {
145
+ const [str, id] = queue.shift();
146
+ if (visited.has(id)) {
147
+ continue;
148
+ }
149
+ visited.add(id);
150
+ if (id !== nodeId) {
151
+ const present = aliases.get(str);
152
+ if (present) {
153
+ present.push(id);
154
+ }
155
+ else {
156
+ aliases.set(str, [id]);
157
+ }
158
+ }
159
+ const vertex = graph.get(id);
160
+ if (vertex === undefined) {
161
+ continue;
162
+ }
163
+ const [info, outgoing] = vertex;
164
+ if (info.tag !== vertex_1.VertexType.FunctionCall) {
165
+ const x = [...outgoing]
166
+ .filter(([, { types }]) => (0, edge_1.edgeIncludesType)(types, edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.DefinedByOnCall))
167
+ .map(([t]) => [(0, node_id_1.recoverContent)(t, graph) ?? '', t]);
168
+ /** only follow defined-by and reads */
169
+ queue.push(...x);
170
+ continue;
171
+ }
172
+ let track = edge_1.EdgeType.Calls | edge_1.EdgeType.Reads | edge_1.EdgeType.DefinedBy | edge_1.EdgeType.DefinedByOnCall;
173
+ if (id !== nodeId) {
174
+ track |= edge_1.EdgeType.Returns;
175
+ }
176
+ const out = [...outgoing]
177
+ .filter(([, e]) => (0, edge_1.edgeIncludesType)(e.types, track) && (nodeId !== id || !(0, edge_1.edgeIncludesType)(e.types, edge_1.EdgeType.Argument)))
178
+ .map(([t]) => t);
179
+ for (const call of out) {
180
+ queue.push([(0, node_id_1.recoverContent)(call, graph) ?? (0, node_id_1.recoverContent)(id, graph) ?? '', call]);
181
+ }
182
+ }
183
+ return aliases;
184
+ }
185
+ /**
186
+ * Multi-stage call context query resolve.
187
+ *
188
+ * 1. Resolve all calls in the DF graph that match the respective {@link DefaultCallContextQueryFormat#callName} regex.
189
+ * 2. Identify their respective call targets, if {@link DefaultCallContextQueryFormat#callTargets} is set to be non-any.
190
+ * This happens during the main resolution!
191
+ * 3. Attach `linkTo` calls to the respective calls.
192
+ */
193
+ function executeCallContextQueries({ graph, ast }, queries) {
194
+ /* omit performance page load */
195
+ const now = Date.now();
196
+ /* the node id and call targets if present */
197
+ const initialIdCollector = new two_layer_collector_1.TwoLayerCollector();
198
+ /* promote all strings to regex patterns */
199
+ const { promotedQueries, requiresCfg } = promoteQueryCallNames(queries);
200
+ let cfg = undefined;
201
+ if (requiresCfg) {
202
+ cfg = (0, cfg_1.extractCFG)(ast);
203
+ }
204
+ const queriesWhichWantAliases = promotedQueries.filter(q => q.includeAliases);
205
+ for (const [nodeId, info] of graph.vertices(true)) {
206
+ if (info.tag !== vertex_1.VertexType.FunctionCall) {
207
+ continue;
208
+ }
209
+ /* if we have a vertex, and we check for aliased calls, we want to know if we define this as desired! */
210
+ if (queriesWhichWantAliases.length > 0) {
211
+ /*
212
+ * yes, we make an expensive call target check, we can probably do a lot of optimization here, e.g.,
213
+ * by checking all of these queries would be satisfied otherwise,
214
+ * in general, we first want a call to happen, i.e., trace the called targets of this!
215
+ */
216
+ const targets = retrieveAllCallAliases(nodeId, graph);
217
+ for (const [l, ids] of targets.entries()) {
218
+ for (const query of queriesWhichWantAliases) {
219
+ if (query.callName.test(l)) {
220
+ initialIdCollector.add(query.kind ?? '.', query.subkind ?? '.', (0, objects_1.compactRecord)({ id: nodeId, aliasRoots: ids }));
221
+ }
222
+ }
223
+ }
224
+ }
225
+ for (const query of promotedQueries.filter(q => q.callName.test(info.name))) {
226
+ let targets = undefined;
227
+ if (query.callTargets) {
228
+ targets = satisfiesCallTargets(nodeId, graph, query.callTargets);
229
+ if (targets === 'no') {
230
+ continue;
231
+ }
232
+ }
233
+ if (isQuoted(nodeId, graph)) {
234
+ /* if the call is quoted, we do not want to link to it */
235
+ continue;
236
+ }
237
+ let linkedIds = undefined;
238
+ if (cfg && isSubCallQuery(query)) {
239
+ /* if we have a linkTo query, we have to find the last call */
240
+ const lastCall = identifyLinkToLastCallRelation(nodeId, cfg.graph, graph, query.linkTo.callName);
241
+ if (lastCall) {
242
+ linkedIds = lastCall;
243
+ }
244
+ }
245
+ initialIdCollector.add(query.kind ?? '.', query.subkind ?? '.', (0, objects_1.compactRecord)({ id: nodeId, calls: targets, linkedIds }));
246
+ }
247
+ }
248
+ return {
249
+ '.meta': {
250
+ timing: Date.now() - now,
251
+ },
252
+ kinds: makeReport(initialIdCollector)
253
+ };
254
+ }
255
+ //# sourceMappingURL=call-context-query-executor.js.map