@eagleoutice/flowr 2.9.9 → 2.9.11

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 (198) hide show
  1. package/README.md +57 -54
  2. package/abstract-interpretation/absint-visitor.d.ts +16 -14
  3. package/abstract-interpretation/absint-visitor.js +93 -47
  4. package/abstract-interpretation/data-frame/mappers/arguments.d.ts +1 -1
  5. package/abstract-interpretation/data-frame/mappers/arguments.js +2 -2
  6. package/abstract-interpretation/data-frame/shape-inference.d.ts +2 -5
  7. package/abstract-interpretation/data-frame/shape-inference.js +4 -5
  8. package/abstract-interpretation/domains/abstract-domain.d.ts +4 -4
  9. package/abstract-interpretation/domains/abstract-domain.js +8 -8
  10. package/abstract-interpretation/domains/mapped-abstract-domain.d.ts +12 -5
  11. package/abstract-interpretation/domains/mapped-abstract-domain.js +47 -23
  12. package/abstract-interpretation/domains/set-range-domain.js +1 -1
  13. package/abstract-interpretation/domains/state-abstract-domain.d.ts +30 -1
  14. package/abstract-interpretation/domains/state-abstract-domain.js +130 -4
  15. package/abstract-interpretation/normalized-ast-fold.d.ts +2 -2
  16. package/abstract-interpretation/normalized-ast-fold.js +4 -3
  17. package/benchmark/slicer.js +5 -5
  18. package/benchmark/summarizer/first-phase/process.js +4 -4
  19. package/cli/repl/commands/repl-normalize.js +2 -2
  20. package/cli/repl/core.js +2 -2
  21. package/config.js +1 -1
  22. package/control-flow/cfg-simplification.d.ts +1 -0
  23. package/control-flow/cfg-simplification.js +1 -0
  24. package/control-flow/control-flow-graph.d.ts +1 -1
  25. package/control-flow/control-flow-graph.js +1 -2
  26. package/control-flow/extract-cfg.js +34 -15
  27. package/control-flow/semantic-cfg-guided-visitor.js +1 -0
  28. package/dataflow/cluster.js +1 -1
  29. package/dataflow/environments/built-in.d.ts +6 -15
  30. package/dataflow/environments/built-in.js +25 -33
  31. package/dataflow/environments/default-builtin-config.d.ts +4 -8
  32. package/dataflow/environments/default-builtin-config.js +8 -5
  33. package/dataflow/environments/reference-to-maybe.d.ts +8 -0
  34. package/dataflow/environments/reference-to-maybe.js +46 -3
  35. package/dataflow/eval/resolve/alias-tracking.d.ts +2 -2
  36. package/dataflow/eval/resolve/alias-tracking.js +6 -6
  37. package/dataflow/eval/resolve/resolve.js +12 -10
  38. package/dataflow/fn/exceptions-of-function.d.ts +1 -1
  39. package/dataflow/fn/exceptions-of-function.js +2 -1
  40. package/dataflow/graph/call-graph.d.ts +1 -1
  41. package/dataflow/graph/call-graph.js +4 -3
  42. package/dataflow/graph/dataflowgraph-builder.d.ts +1 -1
  43. package/dataflow/graph/dataflowgraph-builder.js +21 -21
  44. package/dataflow/graph/graph.d.ts +5 -5
  45. package/dataflow/graph/graph.js +36 -32
  46. package/dataflow/graph/unknown-side-effect.js +3 -1
  47. package/dataflow/info.d.ts +4 -0
  48. package/dataflow/info.js +2 -2
  49. package/dataflow/internal/linker.d.ts +4 -4
  50. package/dataflow/internal/linker.js +59 -33
  51. package/dataflow/internal/process/functions/call/argument/make-argument.d.ts +2 -1
  52. package/dataflow/internal/process/functions/call/argument/make-argument.js +3 -1
  53. package/dataflow/internal/process/functions/call/built-in/built-in-access.d.ts +1 -1
  54. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +2 -1
  55. package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +3 -5
  56. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.d.ts +1 -1
  57. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +6 -5
  58. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +15 -6
  59. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +1 -1
  60. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +3 -2
  61. package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +4 -4
  62. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +3 -3
  63. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -2
  64. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.d.ts +1 -1
  65. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +2 -1
  66. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +7 -7
  67. package/dataflow/internal/process/functions/call/built-in/built-in-s-three-dispatch.js +3 -3
  68. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +22 -11
  69. package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +22 -19
  70. package/dataflow/internal/process/functions/call/common.d.ts +1 -1
  71. package/dataflow/internal/process/functions/call/common.js +43 -35
  72. package/dataflow/internal/process/functions/call/known-call-handling.js +0 -2
  73. package/dataflow/internal/process/functions/process-argument.d.ts +1 -1
  74. package/dataflow/internal/process/functions/process-argument.js +3 -3
  75. package/dataflow/internal/process/functions/process-parameter.js +2 -2
  76. package/dataflow/origin/dfg-get-origin.d.ts +1 -1
  77. package/dataflow/origin/dfg-get-origin.js +2 -2
  78. package/documentation/doc-util/doc-types.js +1 -1
  79. package/documentation/wiki-absint.js +7 -8
  80. package/documentation/wiki-cfg.js +3 -3
  81. package/documentation/wiki-mk/doc-context.d.ts +8 -0
  82. package/documentation/wiki-mk/doc-context.js +4 -0
  83. package/documentation/wiki-normalized-ast.d.ts +1 -1
  84. package/documentation/wiki-normalized-ast.js +9 -6
  85. package/linter/linter-format.d.ts +10 -0
  86. package/linter/linter-format.js +15 -0
  87. package/linter/rules/absolute-path.js +3 -3
  88. package/linter/rules/dead-code.js +1 -1
  89. package/linter/rules/file-path-validity.js +1 -1
  90. package/linter/rules/seeded-randomness.js +1 -1
  91. package/linter/rules/unused-definition.js +1 -1
  92. package/package.json +7 -7
  93. package/project/plugins/file-plugins/files/flowr-description-file.d.ts +9 -0
  94. package/project/plugins/file-plugins/files/flowr-description-file.js +12 -0
  95. package/queries/catalog/call-context-query/call-context-query-executor.js +1 -1
  96. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.d.ts +1 -1
  97. package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +4 -5
  98. package/queries/catalog/dependencies-query/dependencies-query-executor.js +2 -1
  99. package/queries/catalog/dependencies-query/dependencies-query-format.js +6 -5
  100. package/queries/catalog/df-shape-query/df-shape-query-format.d.ts +1 -1
  101. package/queries/catalog/df-shape-query/df-shape-query-format.js +3 -3
  102. package/queries/catalog/does-call-query/does-call-query-executor.js +3 -3
  103. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.d.ts +1 -1
  104. package/queries/catalog/inspect-exceptions-query/inspect-exception-query-format.js +2 -2
  105. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.d.ts +1 -1
  106. package/queries/catalog/inspect-higher-order-query/inspect-higher-order-query-format.js +1 -1
  107. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.d.ts +1 -1
  108. package/queries/catalog/inspect-recursion-query/inspect-recursion-query-format.js +1 -1
  109. package/queries/query-print.d.ts +1 -1
  110. package/queries/query-print.js +4 -3
  111. package/r-bridge/lang-4.x/ast/model/model.d.ts +151 -4
  112. package/r-bridge/lang-4.x/ast/model/model.js +249 -0
  113. package/r-bridge/lang-4.x/ast/model/nodes/info/r-delimiter.d.ts +11 -1
  114. package/r-bridge/lang-4.x/ast/model/nodes/info/r-delimiter.js +13 -0
  115. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +19 -1
  116. package/r-bridge/lang-4.x/ast/model/nodes/r-access.js +26 -0
  117. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +36 -3
  118. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.js +48 -13
  119. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +16 -1
  120. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.js +21 -0
  121. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +11 -1
  122. package/r-bridge/lang-4.x/ast/model/nodes/r-break.js +14 -0
  123. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +8 -2
  124. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.js +11 -5
  125. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +23 -1
  126. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.js +32 -0
  127. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +11 -1
  128. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.js +14 -0
  129. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +19 -1
  130. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.js +26 -1
  131. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +11 -1
  132. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.js +14 -0
  133. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +11 -1
  134. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.js +14 -0
  135. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +12 -2
  136. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.js +14 -0
  137. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +20 -2
  138. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.js +26 -0
  139. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +12 -2
  140. package/r-bridge/lang-4.x/ast/model/nodes/r-next.js +14 -0
  141. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +8 -2
  142. package/r-bridge/lang-4.x/ast/model/nodes/r-number.js +11 -5
  143. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +17 -1
  144. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.js +22 -0
  145. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +16 -1
  146. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.js +22 -0
  147. package/r-bridge/lang-4.x/ast/model/nodes/r-project.d.ts +45 -8
  148. package/r-bridge/lang-4.x/ast/model/nodes/r-project.js +57 -16
  149. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +12 -2
  150. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.js +14 -0
  151. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +15 -3
  152. package/r-bridge/lang-4.x/ast/model/nodes/r-string.js +21 -6
  153. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +21 -6
  154. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.js +22 -5
  155. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +16 -1
  156. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.js +21 -0
  157. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +11 -1
  158. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.js +14 -0
  159. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +23 -17
  160. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +39 -2
  161. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +52 -9
  162. package/r-bridge/lang-4.x/ast/model/processing/role.d.ts +18 -17
  163. package/r-bridge/lang-4.x/ast/model/processing/visitor.d.ts +8 -7
  164. package/r-bridge/lang-4.x/ast/model/processing/visitor.js +6 -13
  165. package/r-bridge/lang-4.x/ast/parser/json/parser.d.ts +1 -1
  166. package/r-bridge/lang-4.x/ast/parser/json/parser.js +1 -1
  167. package/r-bridge/lang-4.x/ast/parser/main/internal/expression/normalize-expression.js +4 -2
  168. package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-number.js +1 -1
  169. package/r-bridge/lang-4.x/ast/parser/main/internal/values/normalize-string.js +2 -2
  170. package/r-bridge/lang-4.x/convert-values.d.ts +14 -5
  171. package/r-bridge/lang-4.x/convert-values.js +76 -72
  172. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +33 -15
  173. package/r-bridge/roxygen2/roxygen-parse.js +1 -1
  174. package/r-bridge/shell-executor.js +1 -1
  175. package/reconstruct/auto-select/magic-comments.js +4 -4
  176. package/reconstruct/reconstruct.js +2 -1
  177. package/search/search-executor/search-generators.js +2 -2
  178. package/slicing/criterion/filters/all-variables.js +1 -1
  179. package/slicing/criterion/parse.d.ts +1 -1
  180. package/slicing/criterion/parse.js +5 -3
  181. package/slicing/static/slice-call.d.ts +1 -1
  182. package/slicing/static/slice-call.js +2 -2
  183. package/statistics/features/supported/assignments/assignments.js +2 -2
  184. package/statistics/features/supported/control-flow/control-flow.js +2 -2
  185. package/statistics/features/supported/data-access/data-access.js +6 -5
  186. package/statistics/features/supported/defined-functions/defined-functions.js +9 -8
  187. package/statistics/features/supported/expression-list/statistics-expression-list.js +2 -2
  188. package/statistics/features/supported/loops/loops.js +6 -5
  189. package/statistics/features/supported/used-functions/used-functions.js +2 -2
  190. package/statistics/features/supported/variables/variables.js +8 -8
  191. package/util/mermaid/ast.js +3 -3
  192. package/util/mermaid/cfg.js +3 -4
  193. package/util/mermaid/dfg.d.ts +1 -1
  194. package/util/mermaid/dfg.js +13 -12
  195. package/util/simple-df/dfg-ascii.js +1 -1
  196. package/util/version.js +1 -1
  197. package/r-bridge/lang-4.x/ast/model/collect.d.ts +0 -10
  198. package/r-bridge/lang-4.x/ast/model/collect.js +0 -25
@@ -4,8 +4,45 @@ import type { DataflowGraph } from '../../../../../dataflow/graph/graph';
4
4
  export type NodeId<T extends string | number = string | number> = T & {
5
5
  __brand?: 'node-id';
6
6
  };
7
- /** used so that we do not have to store strings for the default numeric ids */
8
- export declare function normalizeIdToNumberIfPossible(id: NodeId): NodeId;
7
+ /**
8
+ * A variant of {@link NodeId} that represents built-in functions or operators. The string is prefixed with `built-in:` to avoid confusion with other node ids.
9
+ */
10
+ export type BuiltIn<T extends string = string> = `built-in:${T}`;
11
+ /**
12
+ * The type of the id assigned to each node. Branded to avoid problematic usages with other string or numeric types.
13
+ * The default ids are numeric, but we use a branded type to avoid confusion with other numeric types.
14
+ * Custom ids or scoped ids can be strings, but they will be normalized to numbers if they are numeric strings.
15
+ */
16
+ export declare const NodeId: {
17
+ readonly name: "NodeId";
18
+ /**
19
+ * Normalizes a node id by converting numeric strings to numbers.
20
+ * This allows us to use numeric ids without storing them as strings, while still allowing custom string ids if needed.
21
+ */
22
+ readonly normalize: (this: void, id: NodeId) => NodeId;
23
+ /**
24
+ * The prefix used for built-in function or operator ids.
25
+ */
26
+ readonly builtInPrefix: "built-in:";
27
+ /**
28
+ * Checks if a given node id is a built-in function or operator id by checking if it is a string that starts with the built-in prefix.
29
+ * @see {@link toBuiltIn} - to convert a built-in function or operator name to a built-in id
30
+ * @see {@link fromBuiltIn} - to recover the built-in function or operator name from a built-in id
31
+ */
32
+ readonly isBuiltIn: (this: void, id: BuiltIn | NodeId | undefined) => id is BuiltIn;
33
+ /**
34
+ * Converts a built-in function or operator name to a built-in id by prefixing it with the built-in prefix.
35
+ * @see {@link isBuiltIn} - to check if a given node id is a built-in function or operator id
36
+ * @see {@link fromBuiltIn} - to recover the built-in function or operator name from a built-in id
37
+ */
38
+ readonly toBuiltIn: <T extends string>(this: void, name: T) => BuiltIn<T>;
39
+ /**
40
+ * Recovers the built-in function or operator name from a built-in id by removing the built-in prefix.
41
+ * @see {@link isBuiltIn} - to check if a given node id is a built-in function or operator id
42
+ * @see {@link toBuiltIn} - to convert a built-in function or operator name to a built-in id
43
+ */
44
+ readonly fromBuiltIn: <T extends string>(this: void, id: BuiltIn<T>) => T;
45
+ };
9
46
  /**
10
47
  * Recovers the lexeme of a {@link RNode|node} from its id in the {@link AstIdMap|id map}.
11
48
  * @see {@link recoverContent} - to recover the content of a node
@@ -1,20 +1,63 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeIdToNumberIfPossible = normalizeIdToNumberIfPossible;
3
+ exports.NodeId = void 0;
4
4
  exports.recoverName = recoverName;
5
5
  exports.recoverContent = recoverContent;
6
6
  const vertex_1 = require("../../../../../dataflow/graph/vertex");
7
7
  const retriever_1 = require("../../../../retriever");
8
8
  const identifier_1 = require("../../../../../dataflow/environments/identifier");
9
- const numIdRegex = /^\d+$/;
10
- /** used so that we do not have to store strings for the default numeric ids */
11
- function normalizeIdToNumberIfPossible(id) {
12
- // check if string is number
13
- if (typeof id === 'string' && numIdRegex.test(id)) {
14
- return Number(id);
9
+ /**
10
+ * The type of the id assigned to each node. Branded to avoid problematic usages with other string or numeric types.
11
+ * The default ids are numeric, but we use a branded type to avoid confusion with other numeric types.
12
+ * Custom ids or scoped ids can be strings, but they will be normalized to numbers if they are numeric strings.
13
+ */
14
+ exports.NodeId = {
15
+ name: 'NodeId',
16
+ /**
17
+ * Normalizes a node id by converting numeric strings to numbers.
18
+ * This allows us to use numeric ids without storing them as strings, while still allowing custom string ids if needed.
19
+ */
20
+ normalize(id) {
21
+ // check if string is number
22
+ if (typeof id === 'string') {
23
+ /* typescript is a beautiful converter */
24
+ const num = +id;
25
+ if (!Number.isNaN(num)) {
26
+ return num;
27
+ }
28
+ }
29
+ return id;
30
+ },
31
+ /**
32
+ * The prefix used for built-in function or operator ids.
33
+ */
34
+ builtInPrefix: 'built-in:',
35
+ /**
36
+ * Checks if a given node id is a built-in function or operator id by checking if it is a string that starts with the built-in prefix.
37
+ * @see {@link toBuiltIn} - to convert a built-in function or operator name to a built-in id
38
+ * @see {@link fromBuiltIn} - to recover the built-in function or operator name from a built-in id
39
+ */
40
+ isBuiltIn(id) {
41
+ return typeof id === 'string' && id.startsWith(exports.NodeId.builtInPrefix);
42
+ },
43
+ /**
44
+ * Converts a built-in function or operator name to a built-in id by prefixing it with the built-in prefix.
45
+ * @see {@link isBuiltIn} - to check if a given node id is a built-in function or operator id
46
+ * @see {@link fromBuiltIn} - to recover the built-in function or operator name from a built-in id
47
+ */
48
+ toBuiltIn(name) {
49
+ return `built-in:${name}`;
50
+ },
51
+ /**
52
+ * Recovers the built-in function or operator name from a built-in id by removing the built-in prefix.
53
+ * @see {@link isBuiltIn} - to check if a given node id is a built-in function or operator id
54
+ * @see {@link toBuiltIn} - to convert a built-in function or operator name to a built-in id
55
+ */
56
+ fromBuiltIn(id) {
57
+ return id.slice(builtInPrefixLength);
15
58
  }
16
- return id;
17
- }
59
+ };
60
+ const builtInPrefixLength = exports.NodeId.builtInPrefix.length;
18
61
  /**
19
62
  * Recovers the lexeme of a {@link RNode|node} from its id in the {@link AstIdMap|id map}.
20
63
  * @see {@link recoverContent} - to recover the content of a node
@@ -8,31 +8,32 @@ import type { AstIdMap, RNodeWithParent } from './decorate';
8
8
  export declare const enum RoleInParent {
9
9
  /** has no parent */
10
10
  Root = "root",
11
- IfCondition = "if-cond",
11
+ IfCondition = "if-c",
12
12
  IfThen = "if-then",
13
13
  IfOtherwise = "if-other",
14
- WhileCondition = "while-cond",
15
- WhileBody = "while-body",
16
- RepeatBody = "repeat-body",
14
+ WhileCondition = "while-c",
15
+ WhileBody = "while-b",
16
+ RepeatBody = "repeat-b",
17
17
  ForVariable = "for-var",
18
18
  ForVector = "for-vec",
19
- ForBody = "for-body",
19
+ ForBody = "for-b",
20
20
  FunctionCallName = "call-name",
21
21
  FunctionCallArgument = "call-arg",
22
- FunctionDefinitionBody = "fun-body",
22
+ FunctionDefinitionBody = "fun-b",
23
23
  FunctionDefinitionParameter = "param",
24
- ExpressionListChild = "expr-list-child",
25
- BinaryOperationLhs = "binop-lhs",
26
- BinaryOperationRhs = "binop-rhs",
27
- PipeLhs = "pipe-lhs",
28
- PipeRhs = "pipe-rhs",
24
+ ExpressionListChild = "el-c",
25
+ ExpressionListGrouping = "el-g",
26
+ BinaryOperationLhs = "bin-l",
27
+ BinaryOperationRhs = "bin-r",
28
+ PipeLhs = "pipe-l",
29
+ PipeRhs = "pipe-r",
29
30
  UnaryOperand = "unary-op",
30
- ParameterName = "param-name",
31
- ParameterDefaultValue = "param-value",
32
- ArgumentName = "arg-name",
33
- ArgumentValue = "arg-value",
34
- Accessed = "accessed",
35
- IndexAccess = "index-acc"
31
+ ParameterName = "param-n",
32
+ ParameterDefaultValue = "param-v",
33
+ ArgumentName = "arg-n",
34
+ ArgumentValue = "arg-v",
35
+ Accessed = "acc",
36
+ IndexAccess = "idx-acc"
36
37
  }
37
38
  /**
38
39
  * Returns the roles of the parents of the given node, starting with the parent-role of the node itself.
@@ -1,12 +1,13 @@
1
1
  import type { NoInfo, RNode } from '../model';
2
+ import type { EmptyArgument } from '../nodes/r-function-call';
2
3
  /** Return `true` to stop visiting from this node (i.e., do not continue to visit this node *and* the children) */
3
4
  export type OnEnter<OtherInfo> = (node: RNode<OtherInfo>) => (boolean | void);
4
5
  /** Similar to {@link OnEnter} but called when leaving a node. Can't stop exploration as the subtree is already visited! */
5
6
  export type OnExit<OtherInfo> = (node: RNode<OtherInfo>) => void;
6
- /**
7
- * Visits all node ids within a tree given by a respective root node using a depth-first search with prefix order.
8
- * @param nodes - The root id nodes to start collecting from
9
- * @param onVisit - Called before visiting the subtree of each node. Can be used to stop visiting the subtree starting with this node (return `true` stop)
10
- * @param onExit - Called after the subtree of a node has been visited, called for leafs too (even though their subtree is empty)
11
- */
12
- export declare function visitAst<OtherInfo = NoInfo>(nodes: RNode<OtherInfo> | (RNode<OtherInfo> | null | undefined)[] | undefined, onVisit?: OnEnter<OtherInfo>, onExit?: OnExit<OtherInfo>): void;
7
+ export declare class NodeVisitor<OtherInfo = NoInfo> {
8
+ private readonly onEnter?;
9
+ private readonly onExit?;
10
+ constructor(onEnter?: OnEnter<OtherInfo>, onExit?: OnExit<OtherInfo>);
11
+ private visitSingle;
12
+ visit(nodes: RNode<OtherInfo> | readonly (RNode<OtherInfo> | null | undefined | typeof EmptyArgument)[] | undefined | null): void;
13
+ }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.visitAst = visitAst;
3
+ exports.NodeVisitor = void 0;
4
4
  const type_1 = require("../type");
5
5
  const assert_1 = require("../../../../../util/assert");
6
- const r_function_call_1 = require("../nodes/r-function-call");
6
+ const r_access_1 = require("../nodes/r-access");
7
+ const graph_1 = require("../../../../../dataflow/graph/graph");
7
8
  // capsuled as a class to avoid passing onExit and onEnter on *each* visit call
8
9
  class NodeVisitor {
9
10
  onEnter;
@@ -66,7 +67,7 @@ class NodeVisitor {
66
67
  break;
67
68
  case type_1.RType.Access:
68
69
  this.visitSingle(node.accessed);
69
- if (node.operator === '[' || node.operator === '[[') {
70
+ if (r_access_1.RAccess.isIndex(node)) {
70
71
  this.visit(node.access);
71
72
  }
72
73
  break;
@@ -89,7 +90,7 @@ class NodeVisitor {
89
90
  if (Array.isArray(nodes)) {
90
91
  const n = nodes;
91
92
  for (const node of n) {
92
- if (node && node !== r_function_call_1.EmptyArgument) {
93
+ if (node && graph_1.FunctionArgument.isNotEmpty(node)) {
93
94
  this.visitSingle(node);
94
95
  }
95
96
  }
@@ -99,13 +100,5 @@ class NodeVisitor {
99
100
  }
100
101
  }
101
102
  }
102
- /**
103
- * Visits all node ids within a tree given by a respective root node using a depth-first search with prefix order.
104
- * @param nodes - The root id nodes to start collecting from
105
- * @param onVisit - Called before visiting the subtree of each node. Can be used to stop visiting the subtree starting with this node (return `true` stop)
106
- * @param onExit - Called after the subtree of a node has been visited, called for leafs too (even though their subtree is empty)
107
- */
108
- function visitAst(nodes, onVisit, onExit) {
109
- return new NodeVisitor(onVisit, onExit).visit(nodes);
110
- }
103
+ exports.NodeVisitor = NodeVisitor;
111
104
  //# sourceMappingURL=visitor.js.map
@@ -3,7 +3,7 @@ import type { NoInfo } from '../../model/model';
3
3
  import type { ParseStepOutput, ParseStepOutputSingleFile } from '../../../../parser';
4
4
  import { type FlowrConfigOptions } from '../../../../../config';
5
5
  import type { Tree } from 'web-tree-sitter';
6
- import type { RProject } from '../../model/nodes/r-project';
6
+ import { RProject } from '../../model/nodes/r-project';
7
7
  export declare const parseLog: import("tslog").Logger<import("tslog").ILogObj>;
8
8
  /**
9
9
  * Take the output as produced by the parse step and normalize the AST from the R parser.
@@ -18,7 +18,7 @@ exports.parseLog = log_1.log.getSubLogger({ name: 'ast-parser' });
18
18
  * @see {@link normalizeTreeSitter} - for a version that normalizes the AST from the TreeSitter parser
19
19
  */
20
20
  function normalize(parsed, getId = (0, decorate_1.deterministicCountingIdGenerator)(0)) {
21
- return (0, decorate_1.decorateAst)((0, r_project_1.mergeProjects)(parsed.files.map(normalizeButNotDecorated)), { getId });
21
+ return (0, decorate_1.decorateAst)(r_project_1.RProject.merge(parsed.files.map(normalizeButNotDecorated)), { getId });
22
22
  }
23
23
  /**
24
24
  * Take the output as produced by the parse step and normalize the AST from the R parser.
@@ -9,6 +9,8 @@ const normalize_call_1 = require("../functions/normalize-call");
9
9
  const normalize_definition_1 = require("../functions/normalize-definition");
10
10
  const type_1 = require("../../../../model/type");
11
11
  const normalize_comment_1 = require("../other/normalize-comment");
12
+ const r_delimiter_1 = require("../../../../model/nodes/info/r-delimiter");
13
+ const r_comment_1 = require("../../../../model/nodes/r-comment");
12
14
  /**
13
15
  * Returns an expression list if there are multiple children, otherwise returns the single child directly with no expr wrapper
14
16
  * @param data - The data used by the parser (see {@link NormalizerData})
@@ -36,10 +38,10 @@ function normalizeExpression(data, entry) {
36
38
  return maybeFunctionDefinition;
37
39
  }
38
40
  const children = (0, normalize_expressions_1.normalizeExpressions)(childData, childrenSource);
39
- const [delimiters, nodes] = (0, arrays_1.partition)(children, x => x.type === type_1.RType.Delimiter || x.type === type_1.RType.Comment);
41
+ const [delimiters, nodes] = (0, arrays_1.partition)(children, x => r_delimiter_1.RDelimiter.is(x) || r_comment_1.RComment.is(x));
40
42
  if (nodes.length === 1) {
41
43
  const result = nodes[0];
42
- result.info.adToks = [...result.info.adToks ?? [], ...delimiters];
44
+ result.info.adToks = result.info.adToks ? result.info.adToks.concat(delimiters) : delimiters.slice();
43
45
  return result;
44
46
  }
45
47
  else {
@@ -41,7 +41,7 @@ function normalizeNumber(data, obj) {
41
41
  return {
42
42
  ...common,
43
43
  type: type_1.RType.Number,
44
- content: (0, convert_values_1.number2ts)(content)
44
+ content: convert_values_1.RNumberValue.fromRLexeme(content)
45
45
  };
46
46
  }
47
47
  }
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeString = normalizeString;
4
4
  const normalize_meta_1 = require("../../normalize-meta");
5
5
  const assert_1 = require("../../../../../../../util/assert");
6
- const convert_values_1 = require("../../../../../convert-values");
7
6
  const type_1 = require("../../../../model/type");
7
+ const convert_values_1 = require("../../../../../convert-values");
8
8
  /**
9
9
  * Normalize the given object as a R string (see {@link string2ts}).
10
10
  * This requires you to check the corresponding name beforehand.
@@ -23,7 +23,7 @@ function normalizeString(data, obj) {
23
23
  return {
24
24
  type: type_1.RType.String,
25
25
  location,
26
- content: (0, convert_values_1.string2ts)(stringContent),
26
+ content: convert_values_1.RStringValue.fromRLexeme(stringContent),
27
27
  lexeme: stringContent,
28
28
  info: {
29
29
  fullRange: data.currentRange,
@@ -30,10 +30,13 @@ export interface RNumberValue {
30
30
  /** see {@link RImaginaryMarker}, compound imaginary numbers are expressions in R */
31
31
  complexNumber: boolean;
32
32
  }
33
+ export declare const RNumberValue: {
34
+ readonly name: "RNumberValue";
35
+ readonly fromRLexeme: (this: void, value: string) => RNumberValue;
36
+ };
33
37
  /**
34
- * Convert a valid R number into a {@link RNumberValue}.
38
+ * Represents a string value in R, including the type of quotes used and whether it is a raw string.
35
39
  */
36
- export declare function number2ts(value: string): RNumberValue;
37
40
  export interface RStringValue {
38
41
  str: string;
39
42
  /** from the R-language definition a string is either delimited by a pair of single or double quotes, 'none' strings are syntactically unquoted but treated as strings */
@@ -42,10 +45,16 @@ export interface RStringValue {
42
45
  flag?: 'raw';
43
46
  }
44
47
  /**
45
- * Convert a valid R string into a {@link RStringValue}.
46
- * @throws {@link ValueConversionError} if the string has an unknown starting quote
48
+ * Checks whether the given string is an R string literal (including raw strings).
47
49
  */
48
- export declare function string2ts(value: string): RStringValue;
50
+ export declare const RStringValue: {
51
+ readonly name: "RStringValue";
52
+ /**
53
+ * Convert a valid R string into a {@link RStringValue}.
54
+ * @throws {@link ValueConversionError} if the string has an unknown starting quote
55
+ */
56
+ readonly fromRLexeme: (this: void, value: string) => RStringValue;
57
+ };
49
58
  export declare const RNa = "NA";
50
59
  export declare const RNull = "NULL";
51
60
  /**
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RNull = exports.RNa = exports.RInf = exports.RIntegerMarker = exports.RImaginaryMarker = exports.RNumHexFloatRegex = exports.RFalse = exports.RTrue = void 0;
3
+ exports.RNull = exports.RNa = exports.RStringValue = exports.RNumberValue = exports.RInf = exports.RIntegerMarker = exports.RImaginaryMarker = exports.RNumHexFloatRegex = exports.RFalse = exports.RTrue = void 0;
4
4
  exports.ts2r = ts2r;
5
5
  exports.isBoolean = isBoolean;
6
6
  exports.boolean2ts = boolean2ts;
7
- exports.number2ts = number2ts;
8
- exports.string2ts = string2ts;
9
7
  exports.isNA = isNA;
10
8
  const strings_1 = require("../../util/text/strings");
11
9
  class ValueConversionError extends Error {
@@ -79,85 +77,91 @@ function getDecimalPlacesWithRadix(floatPart, radix) {
79
77
  exports.RImaginaryMarker = 'i';
80
78
  exports.RIntegerMarker = 'L';
81
79
  exports.RInf = 'Inf';
82
- /**
83
- * Convert a valid R number into a {@link RNumberValue}.
84
- */
85
- function number2ts(value) {
86
- // check for hexadecimal number with floating point addon which is supported by R but not by JS :/
87
- let lcValue = value.toLowerCase();
88
- /* both checks are case-sensitive! */
89
- const last = value.at(-1);
90
- const markedAsInt = last === exports.RIntegerMarker;
91
- const complexNumber = last === exports.RImaginaryMarker;
92
- if (markedAsInt || complexNumber) {
93
- lcValue = lcValue.slice(0, -1);
94
- }
95
- if (value === exports.RInf) {
96
- return {
97
- num: Infinity,
98
- complexNumber,
99
- markedAsInt
100
- };
101
- }
102
- if (value === exports.RNa) {
103
- return {
104
- num: NaN,
105
- complexNumber,
106
- markedAsInt
107
- };
108
- }
109
- const floatHex = lcValue.match(exports.RNumHexFloatRegex);
110
- if (floatHex == null) {
111
- return {
112
- num: Number(lcValue),
113
- complexNumber,
114
- markedAsInt
115
- };
116
- }
117
- else {
118
- const { intPart, floatPart, exp } = floatHex.groups;
119
- const base = intPart === undefined ? 0 : parseInt(`${intPart}`, 16);
120
- const floatSuffix = floatPart === undefined ? 0 : getDecimalPlacesWithRadix(floatPart, 16);
121
- const exponent = parseInt(exp, 10);
122
- return {
123
- num: (base + floatSuffix) * Math.pow(2, exponent),
124
- complexNumber,
125
- markedAsInt
126
- };
80
+ exports.RNumberValue = {
81
+ name: 'RNumberValue',
82
+ fromRLexeme(value) {
83
+ // check for hexadecimal number with floating point addon which is supported by R but not by JS :/
84
+ let lcValue = value.toLowerCase();
85
+ /* both checks are case-sensitive! */
86
+ const last = value.at(-1);
87
+ const markedAsInt = last === exports.RIntegerMarker;
88
+ const complexNumber = last === exports.RImaginaryMarker;
89
+ if (markedAsInt || complexNumber) {
90
+ lcValue = lcValue.slice(0, -1);
91
+ }
92
+ if (value === exports.RInf) {
93
+ return {
94
+ num: Infinity,
95
+ complexNumber,
96
+ markedAsInt
97
+ };
98
+ }
99
+ if (value === exports.RNa) {
100
+ return {
101
+ num: NaN,
102
+ complexNumber,
103
+ markedAsInt
104
+ };
105
+ }
106
+ const floatHex = lcValue.match(exports.RNumHexFloatRegex);
107
+ if (floatHex == null) {
108
+ return {
109
+ num: Number(lcValue),
110
+ complexNumber,
111
+ markedAsInt
112
+ };
113
+ }
114
+ else {
115
+ const { intPart, floatPart, exp } = floatHex.groups;
116
+ const base = intPart === undefined ? 0 : parseInt(`${intPart}`, 16);
117
+ const floatSuffix = floatPart === undefined ? 0 : getDecimalPlacesWithRadix(floatPart, 16);
118
+ const exponent = parseInt(exp, 10);
119
+ return {
120
+ num: (base + floatSuffix) * Math.pow(2, exponent),
121
+ complexNumber,
122
+ markedAsInt
123
+ };
124
+ }
127
125
  }
128
- }
126
+ };
129
127
  /**
130
- * Convert a valid R string into a {@link RStringValue}.
131
- * @throws {@link ValueConversionError} if the string has an unknown starting quote
128
+ * Checks whether the given string is an R string literal (including raw strings).
132
129
  */
133
- function string2ts(value) {
134
- if (value.length < 2) {
135
- throw new ValueConversionError(`cannot parse string '${value}' as it is too short`);
136
- }
137
- const init = value[0];
138
- if (init === '"' || init === '\'') {
139
- return {
140
- str: value.slice(1, -1),
141
- quotes: init
142
- };
143
- }
144
- else if (init === 'r' || init === 'R' && value.length >= 3) {
145
- const flags = value[1];
146
- if (flags === '"' || flags === '\'') {
130
+ exports.RStringValue = {
131
+ name: 'RStringValue',
132
+ /**
133
+ * Convert a valid R string into a {@link RStringValue}.
134
+ * @throws {@link ValueConversionError} if the string has an unknown starting quote
135
+ */
136
+ fromRLexeme(value) {
137
+ if (value.length < 2) {
138
+ throw new ValueConversionError(`cannot parse string '${value}' as it is too short`);
139
+ }
140
+ const init = value[0];
141
+ if (init === '"' || init === '\'') {
147
142
  return {
148
- str: (0, strings_1.dropRawStringSurround)(value.slice(2, -1)),
149
- quotes: flags,
150
- flag: 'raw'
143
+ str: value.slice(1, -1),
144
+ quotes: init
151
145
  };
152
146
  }
147
+ else if ((init === 'r' || init === 'R') && value.length >= 3) {
148
+ const flags = value[1];
149
+ if (flags === '"' || flags === '\'') {
150
+ return {
151
+ str: (0, strings_1.dropRawStringSurround)(value.slice(2, -1)),
152
+ quotes: flags,
153
+ flag: 'raw'
154
+ };
155
+ }
156
+ else {
157
+ throw new ValueConversionError(`expected string to start with a known quote (' or "), or raw, yet received ${value}`);
158
+ }
159
+ }
153
160
  else {
154
161
  throw new ValueConversionError(`expected string to start with a known quote (' or "), or raw, yet received ${value}`);
155
162
  }
156
163
  }
157
- else {
158
- throw new ValueConversionError(`expected string to start with a known quote (' or "), or raw, yet received ${value}`);
159
- }
160
- }
164
+ };
161
165
  exports.RNa = 'NA';
162
166
  exports.RNull = 'NULL';
163
167
  /**