@eagleoutice/flowr 2.10.5 → 2.10.7

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 (113) hide show
  1. package/README.md +21 -21
  2. package/abstract-interpretation/absint-visitor.d.ts +1 -2
  3. package/abstract-interpretation/domains/state-domain-like.d.ts +2 -2
  4. package/config.d.ts +6 -0
  5. package/config.js +2 -0
  6. package/control-flow/basic-cfg-guided-visitor.d.ts +1 -1
  7. package/control-flow/semantic-cfg-guided-visitor.js +4 -0
  8. package/dataflow/environments/built-in-proc-name.d.ts +27 -19
  9. package/dataflow/environments/built-in-proc-name.js +27 -19
  10. package/dataflow/environments/built-in.d.ts +24 -18
  11. package/dataflow/environments/built-in.js +6 -0
  12. package/dataflow/environments/default-builtin-config.d.ts +53 -1
  13. package/dataflow/environments/default-builtin-config.js +13 -3
  14. package/dataflow/environments/identifier.d.ts +19 -0
  15. package/dataflow/environments/reference-to-maybe.js +32 -6
  16. package/dataflow/eval/resolve/alias-tracking.js +5 -0
  17. package/dataflow/graph/graph.js +51 -30
  18. package/dataflow/graph/vertex.d.ts +18 -11
  19. package/dataflow/internal/process/functions/call/built-in/built-in-access.js +16 -0
  20. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +6 -0
  21. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +145 -11
  22. package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +15 -0
  23. package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +54 -0
  24. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +75 -0
  25. package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +196 -0
  26. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +22 -8
  27. package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +57 -1
  28. package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +5 -0
  29. package/dataflow/internal/process/functions/call/built-in/built-in-get.js +27 -13
  30. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +14 -4
  31. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.d.ts +27 -0
  32. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +97 -0
  33. package/dataflow/internal/process/functions/call/built-in/built-in-s-seven-new-generic.js +7 -7
  34. package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +23 -0
  35. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +90 -0
  36. package/documentation/doc-util/doc-types.d.ts +11 -2
  37. package/documentation/doc-util/doc-types.js +31 -9
  38. package/documentation/wiki-absint.d.ts +16 -0
  39. package/documentation/wiki-absint.js +50 -15
  40. package/documentation/wiki-interface.js +1 -0
  41. package/documentation/wiki-mk/doc-context.d.ts +14 -1
  42. package/documentation/wiki-mk/doc-context.js +6 -0
  43. package/documentation/wiki-normalized-ast.d.ts +0 -9
  44. package/documentation/wiki-normalized-ast.js +9 -60
  45. package/linter/linter-format.d.ts +4 -0
  46. package/linter/linter-rules.d.ts +7 -6
  47. package/linter/rules/absolute-path.d.ts +0 -2
  48. package/linter/rules/dataframe-access-validation.d.ts +4 -7
  49. package/linter/rules/dataframe-access-validation.js +3 -3
  50. package/linter/rules/dead-code.d.ts +4 -7
  51. package/linter/rules/file-path-validity.d.ts +0 -2
  52. package/linter/rules/function-finder-util.d.ts +1 -3
  53. package/linter/rules/function-finder-util.js +2 -2
  54. package/linter/rules/naming-convention.d.ts +0 -2
  55. package/linter/rules/network-functions.js +4 -1
  56. package/linter/rules/problematic-inputs.d.ts +9 -6
  57. package/linter/rules/problematic-inputs.js +108 -58
  58. package/linter/rules/roxygen-arguments.d.ts +0 -2
  59. package/linter/rules/seeded-randomness.d.ts +0 -2
  60. package/linter/rules/stop-with-call-arg.d.ts +3 -6
  61. package/linter/rules/unused-definition.d.ts +0 -2
  62. package/linter/rules/useless-loop.d.ts +0 -2
  63. package/package.json +4 -4
  64. package/queries/catalog/dependencies-query/dependencies-query-executor.js +6 -2
  65. package/queries/catalog/dependencies-query/function-info/function-info.d.ts +2 -0
  66. package/queries/catalog/dependencies-query/function-info/read-functions.js +2 -0
  67. package/queries/catalog/dependencies-query/function-info/source-functions.js +1 -1
  68. package/queries/catalog/dependencies-query/function-info/write-functions.js +1 -0
  69. package/queries/catalog/input-sources-query/input-source-functions.d.ts +1 -0
  70. package/queries/catalog/input-sources-query/input-source-functions.js +7 -1
  71. package/queries/catalog/input-sources-query/input-sources-query-format.js +3 -1
  72. package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +3 -1
  73. package/queries/catalog/input-sources-query/simple-input-classifier.js +3 -1
  74. package/r-bridge/data/data.d.ts +28 -2
  75. package/r-bridge/data/data.js +34 -2
  76. package/r-bridge/lang-4.x/ast/model/model.d.ts +1 -2
  77. package/r-bridge/lang-4.x/ast/model/model.js +0 -1
  78. package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +3 -3
  79. package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +3 -3
  80. package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +3 -3
  81. package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +3 -3
  82. package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +3 -3
  83. package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +3 -3
  84. package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +3 -3
  85. package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +3 -3
  86. package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +3 -3
  87. package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +3 -3
  88. package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +3 -3
  89. package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +3 -3
  90. package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +3 -3
  91. package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +3 -3
  92. package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +3 -3
  93. package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +3 -3
  94. package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +3 -3
  95. package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +3 -3
  96. package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +3 -3
  97. package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +3 -3
  98. package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +3 -3
  99. package/r-bridge/lang-4.x/ast/model/processing/decorate.d.ts +1 -1
  100. package/r-bridge/lang-4.x/ast/model/processing/decorate.js +16 -16
  101. package/r-bridge/lang-4.x/ast/model/processing/node-id.d.ts +6 -0
  102. package/r-bridge/lang-4.x/ast/model/processing/node-id.js +8 -0
  103. package/search/flowr-search-builder.d.ts +16 -2
  104. package/search/flowr-search-builder.js +10 -1
  105. package/search/flowr-search.d.ts +9 -0
  106. package/search/search-executor/search-generators.d.ts +1 -1
  107. package/search/search-executor/search-generators.js +28 -2
  108. package/slicing/static/static-slicer.js +2 -2
  109. package/util/range.d.ts +13 -1
  110. package/util/range.js +32 -2
  111. package/util/version.js +1 -1
  112. package/abstract-interpretation/normalized-ast-fold.d.ts +0 -119
  113. package/abstract-interpretation/normalized-ast-fold.js +0 -181
@@ -24,13 +24,13 @@ export declare const RWhileLoop: {
24
24
  readonly getLocation: (this: void, node: RNode) => import("../../../../../util/range").SourceLocation | undefined;
25
25
  readonly getId: (this: void, node: RNode<import("../processing/decorate").ParentInformation>) => import("../processing/node-id").NodeId;
26
26
  readonly getType: (this: void, node: RNode) => RType;
27
- readonly visitAst: <OtherInfo = object>(this: void, nodes: import("../../../../../abstract-interpretation/normalized-ast-fold").SingleOrArrayOrNothing<RNode<OtherInfo>>, onVisit?: import("../processing/visitor").OnEnter<OtherInfo>, onExit?: import("../processing/visitor").OnExit<OtherInfo>) => void;
28
- readonly collectAllIds: <OtherInfo>(this: void, nodes: import("../../../../../abstract-interpretation/normalized-ast-fold").SingleOrArrayOrNothing<RNode<OtherInfo & import("../processing/decorate").ParentInformation>>) => Set<import("../processing/node-id").NodeId>;
27
+ readonly visitAst: <OtherInfo = object>(this: void, nodes: import("../model").SingleOrArrayOrNothing<RNode<OtherInfo>>, onVisit?: import("../processing/visitor").OnEnter<OtherInfo>, onExit?: import("../processing/visitor").OnExit<OtherInfo>) => void;
28
+ readonly collectAllIds: <OtherInfo>(this: void, nodes: import("../model").SingleOrArrayOrNothing<RNode<OtherInfo & import("../processing/decorate").ParentInformation>>) => Set<import("../processing/node-id").NodeId>;
29
29
  readonly directChildren: <OtherInfo>(this: void, node: RNode<OtherInfo>) => readonly (RNode<OtherInfo> | typeof import("./r-function-call").EmptyArgument)[];
30
30
  readonly directParent: <OtherInfo>(this: void, node: RNode<OtherInfo & import("../processing/decorate").ParentInformation>, idMap: import("../processing/decorate").AstIdMap<OtherInfo & import("../processing/decorate").ParentInformation>) => RNode<OtherInfo & import("../processing/decorate").ParentInformation> | undefined;
31
31
  readonly iterateParents: <OtherInfo>(this: void, node: RNode<OtherInfo & import("../processing/decorate").ParentInformation> | undefined, idMap: import("../processing/decorate").AstIdMap<OtherInfo & import("../processing/decorate").ParentInformation>) => Generator<RNode<OtherInfo & import("../processing/decorate").ParentInformation>>;
32
32
  readonly depth: (this: void, node: RNode<import("../processing/decorate").ParentInformation>, idMap: import("../processing/decorate").AstIdMap<import("../processing/decorate").ParentInformation>) => number;
33
- readonly collectAllIdsWithStop: <OtherInfo>(this: void, nodes: import("../../../../../abstract-interpretation/normalized-ast-fold").SingleOrArrayOrNothing<RNode<OtherInfo & import("../processing/decorate").ParentInformation>>, stop: (node: RNode<OtherInfo & import("../processing/decorate").ParentInformation>) => boolean) => Set<import("../processing/node-id").NodeId>;
33
+ readonly collectAllIdsWithStop: <OtherInfo>(this: void, nodes: import("../model").SingleOrArrayOrNothing<RNode<OtherInfo & import("../processing/decorate").ParentInformation>>, stop: (node: RNode<OtherInfo & import("../processing/decorate").ParentInformation>) => boolean) => Set<import("../processing/node-id").NodeId>;
34
34
  readonly lexeme: <R extends RNode<import("../processing/decorate").ParentInformation>>(this: void, node: R | undefined) => R extends {
35
35
  lexeme: string;
36
36
  } ? string : string | undefined;
@@ -52,7 +52,7 @@ export interface ParentContextInfo extends MergeableRecord {
52
52
  *
53
53
  * The root node has a nesting of 0, contexts listed in ${@link nestForElement} will increase the nesting
54
54
  */
55
- nesting: number;
55
+ nest: number;
56
56
  /**
57
57
  * 0-based index of the child in the parent (code semantics, e.g., for an if-then-else, the condition will be 0, the then-case will be 1, ...)
58
58
  *
@@ -154,7 +154,7 @@ function createFoldForLeaf(info) {
154
154
  id,
155
155
  parent: undefined,
156
156
  ...defaultParentContext,
157
- nesting
157
+ nest: nesting
158
158
  }
159
159
  };
160
160
  decorated.info.file = info.file;
@@ -163,9 +163,9 @@ function createFoldForLeaf(info) {
163
163
  };
164
164
  }
165
165
  function createFoldForBinaryOp(info) {
166
- return (data, lhs, rhs, nesting) => {
166
+ return (data, lhs, rhs, nest) => {
167
167
  const id = info.getId(data);
168
- const decorated = { ...data, info: { ...data.info, id, parent: undefined, nesting }, lhs, rhs };
168
+ const decorated = { ...data, info: { ...data.info, id, parent: undefined, nest }, lhs, rhs };
169
169
  info.idMap.set(id, decorated);
170
170
  const lhsInfo = lhs.info;
171
171
  lhsInfo.parent = id;
@@ -185,9 +185,9 @@ function createFoldForBinaryOp(info) {
185
185
  };
186
186
  }
187
187
  function createFoldForUnaryOp(info) {
188
- return (data, operand, nesting) => {
188
+ return (data, operand, nest) => {
189
189
  const id = info.getId(data);
190
- const decorated = { ...data, info: { ...data.info, id, parent: undefined, nesting }, operand };
190
+ const decorated = { ...data, info: { ...data.info, id, parent: undefined, nest }, operand };
191
191
  info.idMap.set(id, decorated);
192
192
  const opInfo = operand.info;
193
193
  opInfo.parent = id;
@@ -199,7 +199,7 @@ function createFoldForUnaryOp(info) {
199
199
  function createFoldForAccess(info) {
200
200
  return (data, accessed, access, nesting) => {
201
201
  const id = info.getId(data);
202
- const decorated = { ...data, info: { ...data.info, id, parent: undefined, nesting }, accessed, access };
202
+ const decorated = { ...data, info: { ...data.info, id, parent: undefined, nest: nesting }, accessed, access };
203
203
  info.idMap.set(id, decorated);
204
204
  const accessedInfo = accessed.info;
205
205
  accessedInfo.parent = id;
@@ -223,7 +223,7 @@ function createFoldForAccess(info) {
223
223
  function createFoldForForLoop(info) {
224
224
  return (data, variable, vector, body, nesting) => {
225
225
  const id = info.getId(data);
226
- const decorated = { ...data, info: { ...data.info, id, parent: undefined, nesting }, variable, vector, body };
226
+ const decorated = { ...data, info: { ...data.info, id, parent: undefined, nest: nesting }, variable, vector, body };
227
227
  info.idMap.set(id, decorated);
228
228
  const varInfo = variable.info;
229
229
  varInfo.parent = id;
@@ -243,7 +243,7 @@ function createFoldForForLoop(info) {
243
243
  function createFoldForRepeatLoop(info) {
244
244
  return (data, body, nesting) => {
245
245
  const id = info.getId(data);
246
- const decorated = { ...data, info: { ...data.info, id, parent: undefined, nesting }, body };
246
+ const decorated = { ...data, info: { ...data.info, id, parent: undefined, nest: nesting }, body };
247
247
  info.idMap.set(id, decorated);
248
248
  const bodyInfo = body.info;
249
249
  bodyInfo.parent = id;
@@ -255,7 +255,7 @@ function createFoldForRepeatLoop(info) {
255
255
  function createFoldForWhileLoop(info) {
256
256
  return (data, condition, body, nesting) => {
257
257
  const id = info.getId(data);
258
- const decorated = { ...data, info: { ...data.info, id, parent: undefined, nesting }, condition, body };
258
+ const decorated = { ...data, info: { ...data.info, id, parent: undefined, nest: nesting }, condition, body };
259
259
  info.idMap.set(id, decorated);
260
260
  const condInfo = condition.info;
261
261
  condInfo.parent = id;
@@ -271,7 +271,7 @@ function createFoldForWhileLoop(info) {
271
271
  function createFoldForIfThenElse(info) {
272
272
  return (data, condition, then, otherwise, nesting) => {
273
273
  const id = info.getId(data);
274
- const decorated = { ...data, info: { ...data.info, id, parent: undefined, nesting }, condition, then, otherwise };
274
+ const decorated = { ...data, info: { ...data.info, id, parent: undefined, nest: nesting }, condition, then, otherwise };
275
275
  info.idMap.set(id, decorated);
276
276
  const condInfo = condition.info;
277
277
  condInfo.parent = id;
@@ -293,7 +293,7 @@ function createFoldForIfThenElse(info) {
293
293
  function createFoldForExprList(info) {
294
294
  return (data, grouping, children, nesting) => {
295
295
  const id = info.getId(data);
296
- const decorated = { ...data, info: { ...data.info, id, parent: undefined, nesting }, grouping, children };
296
+ const decorated = { ...data, info: { ...data.info, id, parent: undefined, nest: nesting }, grouping, children };
297
297
  info.idMap.set(id, decorated);
298
298
  let i = 0;
299
299
  for (const child of children) {
@@ -317,10 +317,10 @@ function createFoldForFunctionCall(info) {
317
317
  const id = info.getId(data);
318
318
  let decorated;
319
319
  if (data.named) {
320
- decorated = { ...data, info: { ...data.info, id, parent: undefined, nesting }, functionName, arguments: args };
320
+ decorated = { ...data, info: { ...data.info, id, parent: undefined, nest: nesting }, functionName, arguments: args };
321
321
  }
322
322
  else {
323
- decorated = { ...data, info: { ...data.info, id, parent: undefined, nesting }, calledFunction: functionName, arguments: args };
323
+ decorated = { ...data, info: { ...data.info, id, parent: undefined, nest: nesting }, calledFunction: functionName, arguments: args };
324
324
  }
325
325
  info.idMap.set(id, decorated);
326
326
  const funcInfo = functionName.info;
@@ -343,7 +343,7 @@ function createFoldForFunctionCall(info) {
343
343
  function createFoldForFunctionDefinition(info) {
344
344
  return (data, params, body, nesting) => {
345
345
  const id = info.getId(data);
346
- const decorated = { ...data, info: { ...data.info, id, parent: undefined, nesting }, parameters: params, body };
346
+ const decorated = { ...data, info: { ...data.info, id, parent: undefined, nest: nesting }, parameters: params, body };
347
347
  info.idMap.set(id, decorated);
348
348
  let idx = 0;
349
349
  for (const param of params) {
@@ -363,7 +363,7 @@ function createFoldForFunctionDefinition(info) {
363
363
  function createFoldForFunctionParameter(info) {
364
364
  return (data, name, defaultValue, nesting) => {
365
365
  const id = info.getId(data);
366
- const decorated = { ...data, info: { ...data.info, id, parent: undefined, nesting }, name, defaultValue };
366
+ const decorated = { ...data, info: { ...data.info, id, parent: undefined, nest: nesting }, name, defaultValue };
367
367
  info.idMap.set(id, decorated);
368
368
  const nameInfo = name.info;
369
369
  nameInfo.parent = id;
@@ -381,7 +381,7 @@ function createFoldForFunctionParameter(info) {
381
381
  function createFoldForFunctionArgument(info) {
382
382
  return (data, name, value, nesting) => {
383
383
  const id = info.getId(data);
384
- const decorated = { ...data, info: { ...data.info, id, parent: undefined, nesting }, name, value };
384
+ const decorated = { ...data, info: { ...data.info, id, parent: undefined, nest: nesting }, name, value };
385
385
  info.idMap.set(id, decorated);
386
386
  let idx = 0;
387
387
  if (name) {
@@ -1,5 +1,6 @@
1
1
  import type { AstIdMap } from './decorate';
2
2
  import type { DataflowGraph } from '../../../../../dataflow/graph/graph';
3
+ import type { BuiltInProcName } from '../../../../../dataflow/environments/built-in-proc-name';
3
4
  /** The type of the id assigned to each node. Branded to avoid problematic usages with other string or numeric types. */
4
5
  export type NodeId<T extends string | number = string | number> = T & {
5
6
  __brand?: 'node-id';
@@ -36,6 +37,11 @@ export declare const NodeId: {
36
37
  * @see {@link fromBuiltIn} - to recover the built-in function or operator name from a built-in id
37
38
  */
38
39
  readonly toBuiltIn: <T extends string>(this: void, name: T) => BuiltIn<T>;
40
+ /**
41
+ * Converts a built-in function or operator name or id to a built-in id by prefixing it with the built-in prefix if it is not already a built-in id.
42
+ * This allows us to accept both built-in names and ids in contexts where we want to work with built-in ids.
43
+ */
44
+ readonly mapBuiltInProc: <T extends BuiltInProcName>(this: void, proc: T) => T extends `builtin:${infer S}` ? BuiltIn<S> : BuiltIn<T>;
39
45
  /**
40
46
  * Recovers the built-in function or operator name from a built-in id by removing the built-in prefix.
41
47
  * @see {@link isBuiltIn} - to check if a given node id is a built-in function or operator id
@@ -48,6 +48,14 @@ exports.NodeId = {
48
48
  toBuiltIn(name) {
49
49
  return `built-in:${name}`;
50
50
  },
51
+ /**
52
+ * Converts a built-in function or operator name or id to a built-in id by prefixing it with the built-in prefix if it is not already a built-in id.
53
+ * This allows us to accept both built-in names and ids in contexts where we want to work with built-in ids.
54
+ */
55
+ mapBuiltInProc(proc) {
56
+ const bi = 'builtin:';
57
+ return exports.NodeId.toBuiltIn(proc.startsWith(bi) ? proc.substring(bi.length) : proc);
58
+ },
51
59
  /**
52
60
  * Recovers the built-in function or operator name from a built-in id by removing the built-in prefix.
53
61
  * @see {@link isBuiltIn} - to check if a given node id is a built-in function or operator id
@@ -54,9 +54,16 @@ export declare const FlowrSearchGenerator: {
54
54
  /**
55
55
  * Short form of {@link get} with only the
56
56
  * {@link FlowrSearchGetFilters#line|line} and {@link FlowrSearchGetFilters#column|column} filters:
57
- * `get({line, column})`.
57
+ * `get({line, column})`. Please use {@link FlowrSearchGenerator#locFuzzy|locFuzzy} for a fuzzy location search.
58
58
  */
59
59
  readonly loc: (line?: number, column?: number) => FlowrSearchBuilder<"get">;
60
+ /**
61
+ * Fuzzy variant of {@link loc} that matches any node whose source range contains the given position.
62
+ * @param line - the line number to search in (required for fuzzy matching)
63
+ * @param column - the column number to search in
64
+ * @param innermostOnly - if true, return only the deepest (innermost) matching nodes in the AST
65
+ */
66
+ readonly locFuzzy: (line: number, column: number, innermostOnly?: boolean) => FlowrSearchBuilder<"get">;
60
67
  /**
61
68
  * Short form of {@link get} with only the {@link FlowrSearchGetFilters#name|name} and {@link FlowrSearchGetFilters#line|line} filters:
62
69
  * `get({name, line})`.
@@ -117,9 +124,16 @@ export declare const Q: {
117
124
  /**
118
125
  * Short form of {@link get} with only the
119
126
  * {@link FlowrSearchGetFilters#line|line} and {@link FlowrSearchGetFilters#column|column} filters:
120
- * `get({line, column})`.
127
+ * `get({line, column})`. Please use {@link FlowrSearchGenerator#locFuzzy|locFuzzy} for a fuzzy location search.
121
128
  */
122
129
  readonly loc: (line?: number, column?: number) => FlowrSearchBuilder<"get">;
130
+ /**
131
+ * Fuzzy variant of {@link loc} that matches any node whose source range contains the given position.
132
+ * @param line - the line number to search in (required for fuzzy matching)
133
+ * @param column - the column number to search in
134
+ * @param innermostOnly - if true, return only the deepest (innermost) matching nodes in the AST
135
+ */
136
+ readonly locFuzzy: (line: number, column: number, innermostOnly?: boolean) => FlowrSearchBuilder<"get">;
123
137
  /**
124
138
  * Short form of {@link get} with only the {@link FlowrSearchGetFilters#name|name} and {@link FlowrSearchGetFilters#line|line} filters:
125
139
  * `get({name, line})`.
@@ -64,11 +64,20 @@ exports.FlowrSearchGenerator = {
64
64
  /**
65
65
  * Short form of {@link get} with only the
66
66
  * {@link FlowrSearchGetFilters#line|line} and {@link FlowrSearchGetFilters#column|column} filters:
67
- * `get({line, column})`.
67
+ * `get({line, column})`. Please use {@link FlowrSearchGenerator#locFuzzy|locFuzzy} for a fuzzy location search.
68
68
  */
69
69
  loc(line, column) {
70
70
  return exports.FlowrSearchGenerator.get({ line, column });
71
71
  },
72
+ /**
73
+ * Fuzzy variant of {@link loc} that matches any node whose source range contains the given position.
74
+ * @param line - the line number to search in (required for fuzzy matching)
75
+ * @param column - the column number to search in
76
+ * @param innermostOnly - if true, return only the deepest (innermost) matching nodes in the AST
77
+ */
78
+ locFuzzy(line, column, innermostOnly = false) {
79
+ return exports.FlowrSearchGenerator.get({ line, column, fuzzy: true, innermostOnly });
80
+ },
72
81
  /**
73
82
  * Short form of {@link get} with only the {@link FlowrSearchGetFilters#name|name} and {@link FlowrSearchGetFilters#line|line} filters:
74
83
  * `get({name, line})`.
@@ -53,6 +53,15 @@ export interface FlowrSearchGetFilter extends Record<string, unknown> {
53
53
  * ```
54
54
  */
55
55
  readonly filePathRegex?: string;
56
+ /**
57
+ * If true, match any node whose source range contains the given line/column (fuzzy position match).
58
+ * Requires `line` to be provided.
59
+ */
60
+ readonly fuzzy?: boolean;
61
+ /**
62
+ * If true (and `fuzzy` is true), return only the innermost (deepest in the AST) matching node(s).
63
+ */
64
+ readonly innermostOnly?: boolean;
56
65
  }
57
66
  /** Intentionally, we abstract away from an array to avoid the use of conventional typescript operations */
58
67
  export declare class FlowrSearchElements<Info = NoInfo, Elements extends FlowrSearchElement<Info>[] = FlowrSearchElement<Info>[]> {
@@ -28,7 +28,7 @@ export declare const generators: {
28
28
  readonly syntax: typeof generateSyntax;
29
29
  };
30
30
  declare function generateAll(data: ReadonlyFlowrAnalysisProvider): Promise<FlowrSearchElements<ParentInformation>>;
31
- declare function generateGet(input: ReadonlyFlowrAnalysisProvider, { filter: { line, column, id, name, nameIsRegex, filePathRegex } }: {
31
+ declare function generateGet(input: ReadonlyFlowrAnalysisProvider, { filter: { line, column, id, name, nameIsRegex, filePathRegex, fuzzy, innermostOnly } }: {
32
32
  filter: FlowrSearchGetFilter;
33
33
  }): Promise<FlowrSearchElements<ParentInformation>>;
34
34
  declare function generateFrom(_input: ReadonlyFlowrAnalysisProvider, args: {
@@ -5,6 +5,7 @@ exports.getGenerator = getGenerator;
5
5
  const flowr_search_1 = require("../flowr-search");
6
6
  const parse_1 = require("../../slicing/criterion/parse");
7
7
  const assert_1 = require("../../util/assert");
8
+ const range_1 = require("../../util/range");
8
9
  const query_1 = require("../../queries/query");
9
10
  const search_enrichers_1 = require("./search-enrichers");
10
11
  const log_1 = require("../../util/log");
@@ -30,7 +31,7 @@ async function getAllNodes(data) {
30
31
  return [...new Map([...normalize.idMap.values()].map(n => [n.info.id, n]))
31
32
  .values()];
32
33
  }
33
- async function generateGet(input, { filter: { line, column, id, name, nameIsRegex, filePathRegex } }) {
34
+ async function generateGet(input, { filter: { line, column, id, name, nameIsRegex, filePathRegex, fuzzy, innermostOnly } }) {
34
35
  const normalize = await input.normalize();
35
36
  let potentials = (id ?
36
37
  [normalize.idMap.get(id)].filter(assert_1.isNotUndefined) :
@@ -45,7 +46,32 @@ async function generateGet(input, { filter: { line, column, id, name, nameIsRege
45
46
  (id ? (await getAllNodes(input)) : potentials).reduce((maxLine, { location }) => location && location[2] > maxLine ? location[2] : maxLine, 0);
46
47
  line = maxLines + line + 1;
47
48
  }
48
- if (line && column) {
49
+ if (fuzzy) {
50
+ (0, assert_1.guard)(line, 'Fuzzy location matching requires line to be provided');
51
+ potentials = potentials.filter(node => {
52
+ const range = range_1.SourceRange.fromNode(node);
53
+ if (!range) {
54
+ return false;
55
+ }
56
+ return column === undefined ? (range[0] <= line && line <= range[2]) : range_1.SourceRange.containsPosition(range, line, column);
57
+ });
58
+ if (innermostOnly && potentials.length > 1) {
59
+ potentials = potentials.filter(node => {
60
+ const range = range_1.SourceRange.fromNode(node);
61
+ return range && !potentials.some(other => {
62
+ if (other === node) {
63
+ return false;
64
+ }
65
+ else if (other.info.parent === node.info.id) {
66
+ return true;
67
+ }
68
+ const otherRange = range_1.SourceRange.fromNode(other);
69
+ return otherRange && range_1.SourceRange.isStrictSubsetOf(otherRange, range);
70
+ });
71
+ });
72
+ }
73
+ }
74
+ else if (line && column) {
49
75
  potentials = potentials.filter(({ location }) => location?.[0] === line && location?.[1] === column);
50
76
  }
51
77
  else if (line) {
@@ -41,7 +41,7 @@ function staticSlice(ctx, info, { idMap }, ids, direction, threshold = 75, cache
41
41
  for (const startId of ids) {
42
42
  queue.add(startId, emptyEnv, basePrint, false);
43
43
  // retrieve the minimum nesting of all nodes to only add control dependencies if they are "part" of the current execution
44
- minNesting = Math.min(minNesting, idMap.get(startId)?.info.nesting ?? minNesting);
44
+ minNesting = Math.min(minNesting, idMap.get(startId)?.info.nest ?? minNesting);
45
45
  sliceSeedIds.add(startId);
46
46
  }
47
47
  /* additionally,
@@ -67,7 +67,7 @@ function staticSlice(ctx, info, { idMap }, ids, direction, threshold = 75, cache
67
67
  if (currentVertex.cds && currentVertex.cds.length > 0) {
68
68
  const topLevel = graph.isRoot(id) || sliceSeedIds.has(id);
69
69
  for (const cd of currentVertex.cds.filter(({ id }) => !queue.hasId(id))) {
70
- if (!topLevel || (idMap.get(cd.id)?.info.nesting ?? 0) >= minNesting) {
70
+ if (!topLevel || (idMap.get(cd.id)?.info.nest ?? 0) >= minNesting) {
71
71
  queue.add(cd.id, baseEnvironment, baseEnvFingerprint, false);
72
72
  }
73
73
  }
package/util/range.d.ts CHANGED
@@ -113,10 +113,22 @@ export declare const SourceRange: {
113
113
  * @returns a positive number if `r1` comes after `r2`, a negative number if `r1` comes before `r2`, and `0` if they are equal
114
114
  */
115
115
  readonly compare: (this: void, [r1sl, r1sc, ,]: SourceRange, [r2sl, r2sc, ,]: SourceRange) => number;
116
+ /**
117
+ * Checks if two ranges are equal (i.e., they start and end at the same position).
118
+ */
119
+ readonly equals: (this: void, [r1sl, r1sc, r1el, r1ec]: SourceRange, [r2sl, r2sc, r2el, r2ec]: SourceRange) => boolean;
120
+ /**
121
+ * Checks if a given position (line, column) is contained within the range.
122
+ */
123
+ readonly containsPosition: (this: void, [sl, sc, el, ec]: SourceRange, line: number, column: number) => boolean;
116
124
  /**
117
125
  * Checks if the first range is a subset of the second range.
118
126
  */
119
127
  readonly isSubsetOf: (this: void, [r1sl, r1sc, r1el, r1ec]: SourceRange, [r2sl, r2sc, r2el, r2ec]: SourceRange) => boolean;
128
+ /**
129
+ * Checks if the first range is a strict subset of the second range (i.e., it is a subset but not equal).
130
+ */
131
+ readonly isStrictSubsetOf: (this: void, r1: SourceRange, r2: SourceRange) => boolean;
120
132
  /**
121
133
  * Combines overlapping or subset ranges into a minimal set of ranges.
122
134
  * @see {@link SourceRange.merge} for merging multiple ranges into a single range.
@@ -152,7 +164,7 @@ export declare const SourceLocation: {
152
164
  * @returns undefined if the given range is undefined
153
165
  * @see {@link SourceRange.fromNode} for getting the range from an AST node
154
166
  */
155
- readonly fromNode: <OtherInfo>(this: void, node: RNode<OtherInfo>) => SourceLocation | undefined;
167
+ readonly fromNode: <OtherInfo>(this: void, node: RNode<OtherInfo> | undefined) => SourceLocation | undefined;
156
168
  /**
157
169
  * Maps the file part of a {@link SourceLocation|source location} using the given mapper function.
158
170
  */
package/util/range.js CHANGED
@@ -150,11 +150,41 @@ exports.SourceRange = {
150
150
  return r1sl - r2sl;
151
151
  }
152
152
  },
153
+ /**
154
+ * Checks if two ranges are equal (i.e., they start and end at the same position).
155
+ */
156
+ equals([r1sl, r1sc, r1el, r1ec], [r2sl, r2sc, r2el, r2ec]) {
157
+ return r1sl === r2sl && r1sc === r2sc && r1el === r2el && r1ec === r2ec;
158
+ },
159
+ /**
160
+ * Checks if a given position (line, column) is contained within the range.
161
+ */
162
+ containsPosition([sl, sc, el, ec], line, column) {
163
+ if (line < sl || line > el) {
164
+ return false;
165
+ }
166
+ else if (sl === el) {
167
+ return sc <= column && column <= ec;
168
+ }
169
+ else if (line === sl) {
170
+ return column >= sc;
171
+ }
172
+ else if (line === el) {
173
+ return column <= ec;
174
+ }
175
+ return true;
176
+ },
153
177
  /**
154
178
  * Checks if the first range is a subset of the second range.
155
179
  */
156
180
  isSubsetOf([r1sl, r1sc, r1el, r1ec], [r2sl, r2sc, r2el, r2ec]) {
157
- return (r1sl > r2sl || r1sl === r2sl && r1sc >= r2sc) && (r1el < r2el || r1sl === r2sl && r1ec <= r2ec);
181
+ return (r1sl > r2sl || r1sl === r2sl && r1sc >= r2sc) && (r1el < r2el || r1el === r2el && r1ec <= r2ec);
182
+ },
183
+ /**
184
+ * Checks if the first range is a strict subset of the second range (i.e., it is a subset but not equal).
185
+ */
186
+ isStrictSubsetOf(r1, r2) {
187
+ return exports.SourceRange.isSubsetOf(r1, r2) && !exports.SourceRange.equals(r1, r2);
158
188
  },
159
189
  /**
160
190
  * Combines overlapping or subset ranges into a minimal set of ranges.
@@ -208,7 +238,7 @@ exports.SourceLocation = {
208
238
  */
209
239
  fromNode(node) {
210
240
  const range = exports.SourceRange.fromNode(node);
211
- return range !== undefined ? exports.SourceLocation.from(range, node.info.file) : undefined;
241
+ return node !== undefined && range !== undefined ? exports.SourceLocation.from(range, node.info.file) : undefined;
212
242
  },
213
243
  /**
214
244
  * Maps the file part of a {@link SourceLocation|source location} using the given mapper function.
package/util/version.js CHANGED
@@ -6,7 +6,7 @@ exports.printVersionInformation = printVersionInformation;
6
6
  const semver_1 = require("semver");
7
7
  const assert_1 = require("./assert");
8
8
  // this is automatically replaced with the current version by release-it
9
- const version = '2.10.5';
9
+ const version = '2.10.7';
10
10
  /**
11
11
  * Retrieves the current flowR version as a new {@link SemVer} object.
12
12
  */
@@ -1,119 +0,0 @@
1
- import type { NoInfo, RNode } from '../r-bridge/lang-4.x/ast/model/model';
2
- import type { RExpressionList } from '../r-bridge/lang-4.x/ast/model/nodes/r-expression-list';
3
- import { type RFunctionCall, EmptyArgument } from '../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
4
- import type { RFunctionDefinition } from '../r-bridge/lang-4.x/ast/model/nodes/r-function-definition';
5
- import { RType } from '../r-bridge/lang-4.x/ast/model/type';
6
- import type { RForLoop } from '../r-bridge/lang-4.x/ast/model/nodes/r-for-loop';
7
- import type { RWhileLoop } from '../r-bridge/lang-4.x/ast/model/nodes/r-while-loop';
8
- import type { RRepeatLoop } from '../r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop';
9
- import type { RIfThenElse } from '../r-bridge/lang-4.x/ast/model/nodes/r-if-then-else';
10
- import type { RBinaryOp } from '../r-bridge/lang-4.x/ast/model/nodes/r-binary-op';
11
- import type { RPipe } from '../r-bridge/lang-4.x/ast/model/nodes/r-pipe';
12
- import type { RUnaryOp } from '../r-bridge/lang-4.x/ast/model/nodes/r-unary-op';
13
- import type { RParameter } from '../r-bridge/lang-4.x/ast/model/nodes/r-parameter';
14
- import type { RArgument } from '../r-bridge/lang-4.x/ast/model/nodes/r-argument';
15
- import { RAccess } from '../r-bridge/lang-4.x/ast/model/nodes/r-access';
16
- import type { RLogical } from '../r-bridge/lang-4.x/ast/model/nodes/r-logical';
17
- import type { RBreak } from '../r-bridge/lang-4.x/ast/model/nodes/r-break';
18
- import type { RComment } from '../r-bridge/lang-4.x/ast/model/nodes/r-comment';
19
- import type { RNext } from '../r-bridge/lang-4.x/ast/model/nodes/r-next';
20
- import type { RNumber } from '../r-bridge/lang-4.x/ast/model/nodes/r-number';
21
- import type { RLineDirective } from '../r-bridge/lang-4.x/ast/model/nodes/r-line-directive';
22
- import type { RString } from '../r-bridge/lang-4.x/ast/model/nodes/r-string';
23
- import type { RSymbol } from '../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
24
- import { RProject } from '../r-bridge/lang-4.x/ast/model/nodes/r-project';
25
- type FoldOfType<T extends RType, Returns = void, Info = NoInfo> = (node: Extract<RNode<Info>, {
26
- type: T;
27
- }>) => Returns;
28
- /** explicitly excludes types that are not visitable */
29
- export type FoldableRType = Exclude<RType, RType.Delimiter | RType.Project>;
30
- /**
31
- * Describes the fold functions for each node type.
32
- */
33
- export type NormalizedAstFold<Returns = void, Info = NoInfo> = {
34
- [K in FoldableRType as `fold${Capitalize<K>}`]: FoldOfType<K, Returns, Info>;
35
- };
36
- /**
37
- * Describes the type of a mapping object,
38
- * which maps the type of the normalized AST node to the corresponding fold function.
39
- */
40
- export type FittingNormalizedAstFold<Returns = void, Info = NoInfo> = Readonly<{
41
- [K in FoldableRType]: FoldOfType<K, Returns, Info>;
42
- }>;
43
- export type SingleOrArrayOrNothing<T> = T | readonly (T | null | undefined)[] | null | undefined;
44
- export type EntryExitVisitor<Info> = ((node: RNode<Info>) => void) | undefined;
45
- /**
46
- * Default implementation of a fold over the normalized AST (using the classic fold traversal).
47
- * To modify the behavior, please extend this class and overwrite the methods of interest.
48
- * You can control the value passing (`Returns` generic)
49
- * by providing sensible Monoid behavior overwriting the {@link DefaultNormalizedAstFold#concat|concat} method
50
- * and supplying the empty value in the constructor.
51
- * @note By providing `entry` and `exit` you can use this as an extension to the simpler {@link visitAst} function but without
52
- * the early termination within the visitors (for this, you can overwrite the respective `fold*` methods).
53
- * @example First you want to create your own fold:
54
- *
55
- * ```ts
56
- * let marker = false;
57
- * class MyNumberFold<Info> extends DefaultNormalizedAstFold<void, Info> {
58
- * override foldRNumber(node: RNumber<Info>) {
59
- * super.foldRNumber(node);
60
- * marker = true;
61
- * }
62
- * }
63
- * ```
64
- * This one does explicitly not use the return functionality (and hence acts more as a conventional visitor).
65
- * Now let us suppose we have a normalized AST as an {@link RNode} in the variable `ast`
66
- * and want to check if the AST contains a number:
67
- *
68
- * ```ts
69
- * const result = new MyNumberFold().fold(ast);
70
- * ```
71
- *
72
- * Please take a look at the corresponding tests or the wiki pages for more information on how to use this fold.
73
- */
74
- export declare class DefaultNormalizedAstFold<Returns = void, Info = NoInfo> implements NormalizedAstFold<Returns, Info> {
75
- protected readonly enter: EntryExitVisitor<Info>;
76
- protected readonly exit: EntryExitVisitor<Info>;
77
- protected readonly empty: Returns;
78
- /**
79
- * Empty must provide a sensible default whenever you want to have `Returns` as non-`void`
80
- * (e.g., whenever you want your visitors to be able to return a value).
81
- */
82
- constructor(empty: Returns, enter?: EntryExitVisitor<Info>, exit?: EntryExitVisitor<Info>);
83
- /**
84
- * Monoid::concat
85
- * @see {@link https://en.wikipedia.org/wiki/Monoid}
86
- * @see {@link DefaultNormalizedAstFold#concatAll|concatAll}
87
- */
88
- protected concat(_a: Returns, _b: Returns): Returns;
89
- /**
90
- * overwrite this method, if you have a faster way to concat multiple nodes
91
- * @see {@link DefaultNormalizedAstFold#concatAll|concatAll}
92
- */
93
- protected concatAll(nodes: readonly Returns[]): Returns;
94
- fold(nodes: SingleOrArrayOrNothing<RNode<Info> | typeof EmptyArgument | RProject<Info>>): Returns;
95
- protected foldSingle(node: RNode<Info>): Returns;
96
- foldRAccess(access: RAccess<Info>): Returns;
97
- foldRArgument(argument: RArgument<Info>): Returns;
98
- foldRBinaryOp(binaryOp: RBinaryOp<Info>): Returns;
99
- foldRExpressionList(exprList: RExpressionList<Info>): Returns;
100
- foldRForLoop(loop: RForLoop<Info>): Returns;
101
- foldRFunctionCall(call: RFunctionCall<Info>): Returns;
102
- foldRFunctionDefinition(definition: RFunctionDefinition<Info>): Returns;
103
- foldRIfThenElse(ite: RIfThenElse<Info>): Returns;
104
- foldRParameter(parameter: RParameter<Info>): Returns;
105
- foldRPipe(pipe: RPipe<Info>): Returns;
106
- foldRRepeatLoop(loop: RRepeatLoop<Info>): Returns;
107
- foldRUnaryOp(unaryOp: RUnaryOp<Info>): Returns;
108
- foldRWhileLoop(loop: RWhileLoop<Info>): Returns;
109
- foldRBreak(_node: RBreak<Info>): Returns;
110
- foldRComment(_node: RComment<Info>): Returns;
111
- foldRLineDirective(_node: RLineDirective<Info>): Returns;
112
- foldRLogical(_node: RLogical<Info>): Returns;
113
- foldRNext(_node: RNext<Info>): Returns;
114
- foldRNumber(_node: RNumber<Info>): Returns;
115
- foldRString(_node: RString<Info>): Returns;
116
- foldRSymbol(_node: RSymbol<Info>): Returns;
117
- protected readonly folds: FittingNormalizedAstFold<Returns, Info>;
118
- }
119
- export {};