@eagleoutice/flowr 2.17.2 → 2.17.4

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 (106) hide show
  1. package/README.md +9 -9
  2. package/cli/repl/commands/repl-signature.d.ts +1 -1
  3. package/cli/repl/completion.d.ts +23 -0
  4. package/cli/repl/completion.js +9 -0
  5. package/cli/repl/core.d.ts +0 -23
  6. package/cli/repl/core.js +0 -5
  7. package/cli/repl/parser/slice-query-parser.d.ts +1 -1
  8. package/cli/repl/parser/slice-query-parser.js +3 -3
  9. package/data/r-reexports.generated.d.ts +4 -0
  10. package/data/r-reexports.generated.js +43 -0
  11. package/dataflow/environments/built-in-props.d.ts +8 -1
  12. package/dataflow/environments/built-in-props.js +9 -1
  13. package/dataflow/environments/built-in.d.ts +5 -3
  14. package/dataflow/environments/built-in.js +5 -4
  15. package/dataflow/environments/default-builtin-config.d.ts +21 -3
  16. package/dataflow/environments/default-builtin-config.js +49 -47
  17. package/dataflow/eval/resolve/resolve-argument.js +11 -6
  18. package/dataflow/eval/resolve/resolve-numbers.d.ts +1 -178
  19. package/dataflow/eval/resolve/resolve-numbers.js +2 -13
  20. package/dataflow/eval/resolve/resolve-strings.d.ts +1 -93
  21. package/dataflow/eval/resolve/resolve-strings.js +2 -17
  22. package/dataflow/eval/resolve/resolve-working-directory.js +3 -4
  23. package/dataflow/extractor.js +44 -26
  24. package/dataflow/graph/df-helper.d.ts +10 -1
  25. package/dataflow/graph/df-helper.js +27 -3
  26. package/dataflow/internal/linker.js +2 -1
  27. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +8 -0
  28. package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +44 -7
  29. package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +3 -2
  30. package/dataflow/internal/process/functions/call/built-in/built-in-library.js +9 -6
  31. package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +2 -1
  32. package/dataflow/internal/process/functions/call/built-in/built-in-source.d.ts +0 -9
  33. package/dataflow/internal/process/functions/call/built-in/built-in-source.js +11 -21
  34. package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +3 -3
  35. package/dataflow/internal/process/functions/call/built-in/built-in-with.js +2 -1
  36. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +13 -3
  37. package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +15 -5
  38. package/dataflow/internal/process/functions/call/known-call-handling.d.ts +1 -24
  39. package/dataflow/internal/process/functions/call/known-call-handling.js +8 -34
  40. package/dataflow/internal/process/functions/call/nse-kind.d.ts +24 -0
  41. package/dataflow/internal/process/functions/call/nse-kind.js +30 -0
  42. package/documentation/wiki-dataflow-graph.js +7 -2
  43. package/documentation/wiki-query.js +3 -2
  44. package/linter/rules/absolute-path.js +5 -5
  45. package/linter/rules/cmd-check/dependency-declaration.js +2 -2
  46. package/linter/rules/cmd-check/package-runtime.js +2 -2
  47. package/linter/rules/deprecated-functions.js +2 -2
  48. package/linter/rules/file-path-validity.js +5 -5
  49. package/linter/rules/function-finder-util.js +2 -2
  50. package/linter/rules/overwritten-file.js +2 -4
  51. package/linter/rules/secret-exfiltration.d.ts +3 -2
  52. package/linter/rules/secret-exfiltration.js +8 -3
  53. package/linter/rules/unused-import.js +20 -6
  54. package/package.json +1 -1
  55. package/project/cache/flowr-analyzer-controlflow-cache.d.ts +0 -6
  56. package/project/cache/flowr-analyzer-controlflow-cache.js +7 -27
  57. package/project/context/flowr-analyzer-context.d.ts +2 -2
  58. package/project/context/flowr-analyzer-context.js +2 -2
  59. package/project/context/flowr-analyzer-files-context.d.ts +8 -0
  60. package/project/context/flowr-analyzer-files-context.js +51 -6
  61. package/project/flowr-analyzer.d.ts +0 -9
  62. package/project/flowr-analyzer.js +7 -28
  63. package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +5 -3
  64. package/project/plugins/file-plugins/files/flowr-namespace-file.js +70 -163
  65. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.d.ts +2 -3
  66. package/project/plugins/file-plugins/flowr-analyzer-file-plugin.js +2 -3
  67. package/project/plugins/file-plugins/flowr-analyzer-rprofile-file-plugin.js +3 -3
  68. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +2 -2
  69. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin.js +1 -2
  70. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.d.ts +1 -1
  71. package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-sigdb-plugin.js +25 -3
  72. package/project/plugins/package-version-plugins/package.js +1 -1
  73. package/project/plugins/project-discovery/flowr-analyzer-project-discovery-plugin.js +2 -3
  74. package/project/sigdb/build.js +7 -6
  75. package/project/sigdb/decode.d.ts +2 -0
  76. package/project/sigdb/decode.js +9 -3
  77. package/project/sigdb/schema.d.ts +8 -3
  78. package/queries/catalog/absint-query/absint-query-format.d.ts +1 -1
  79. package/queries/catalog/config-query/config-query-format.d.ts +1 -1
  80. package/queries/catalog/config-query/config-query-format.js +4 -4
  81. package/queries/catalog/dependencies-query/dependencies-query-executor.js +6 -5
  82. package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +1 -4
  83. package/queries/catalog/dependencies-query/dependencies-query-format.js +11 -11
  84. package/queries/catalog/dependencies-query/dependency-values.d.ts +9 -0
  85. package/queries/catalog/dependencies-query/dependency-values.js +13 -0
  86. package/queries/catalog/dependencies-query/function-info/remote-functions.js +2 -2
  87. package/queries/catalog/dependencies-query/function-info/write-functions.js +8 -7
  88. package/queries/catalog/dependencies-query/implicit-echo.js +2 -1
  89. package/queries/catalog/dependencies-query/plot-description.d.ts +1 -1
  90. package/queries/catalog/dependencies-query/plot-description.js +2 -2
  91. package/queries/catalog/dice-query/dice-query-format.d.ts +1 -1
  92. package/queries/catalog/files-query/files-query-format.d.ts +1 -1
  93. package/queries/catalog/linter-query/linter-query-format.d.ts +2 -2
  94. package/queries/catalog/linter-query/linter-query-format.js +13 -9
  95. package/queries/catalog/signature-query/signature-query-executor.d.ts +1 -1
  96. package/queries/catalog/taint-query/taint-query-format.d.ts +1 -1
  97. package/queries/query-function-filter.d.ts +1 -1
  98. package/queries/query.d.ts +2 -2
  99. package/r-bridge/init.js +1 -1
  100. package/search/flowr-search-filters.js +2 -2
  101. package/search/search-executor/search-generators.d.ts +0 -1
  102. package/search/search-executor/search-generators.js +5 -6
  103. package/search/search-logger.d.ts +1 -0
  104. package/search/search-logger.js +6 -0
  105. package/util/flowr-version.d.ts +1 -1
  106. package/util/flowr-version.js +2 -2
@@ -88,6 +88,10 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
88
88
  this.caseIndex = undefined;
89
89
  this.readdirCache.clear();
90
90
  }
91
+ addRoot(root) {
92
+ this.requestedRoots.push(root);
93
+ this.rootResolved = false;
94
+ }
91
95
  /** The directory the analysis was asked about: a `project`'s folder, or the one holding the requested file(s). */
92
96
  root() {
93
97
  if (!this.rootResolved) {
@@ -165,6 +169,12 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
165
169
  * Add multiple requests to the context. This is just a convenience method that calls {@link addRequest} for each request.
166
170
  */
167
171
  addRequests(requests) {
172
+ /* every folder first, so that the files of one request are seen from the same root as those of the others */
173
+ for (const request of requests) {
174
+ if (request.request !== 'text') {
175
+ this.addRoot(request.request === 'file' ? path_1.default.dirname(request.content) : request.content);
176
+ }
177
+ }
168
178
  for (const request of requests) {
169
179
  this.addRequest(request);
170
180
  }
@@ -176,14 +186,14 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
176
186
  addRequest(request) {
177
187
  if (request.request !== 'project') {
178
188
  if (request.request === 'file') {
179
- this.requestedRoots.push(path_1.default.dirname(request.content));
180
189
  this.discoverImplicitSources(request.content);
190
+ /* registers the file with its roles now, so they do not depend on whether it was parsed yet */
191
+ this.resolveFile(request.content);
181
192
  }
182
193
  this.loadingOrder.addRequest(request);
183
194
  this.projectKindCache = undefined;
184
195
  return;
185
196
  }
186
- this.requestedRoots.push(request.content);
187
197
  for (const req of this.activeDiscoveryPlugins().flatMap(p => p.processor(this.ctx, request))) {
188
198
  this.addDiscovered(req);
189
199
  }
@@ -239,12 +249,24 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
239
249
  /**
240
250
  * Add a file to the context. If the file has a special role, it will be added to the corresponding list of special files.
241
251
  * This method also applies any registered {@link FlowrAnalyzerFilePlugin}s to the file before adding it to the context.
252
+ * A file already known under the same path (e.g., reached by both a request and implicit-source discovery) is kept, it only gains the new roles.
242
253
  */
243
254
  addFile(file, roles) {
244
255
  if (file === undefined) {
245
256
  return;
246
257
  }
247
- const f = this.fileLoadPlugins(wrapFile(file, roles));
258
+ const wrapped = wrapFile(file, roles);
259
+ const known = wrapped.path() === flowr_file_1.FlowrFile.INLINE_PATH ? undefined : this.files.get(files_1.RPath.of(wrapped.path()));
260
+ if (known !== undefined) {
261
+ /* the same file on disk again only adds its roles, a provider of its own replaces the known one */
262
+ if (known === file || wrapped instanceof flowr_file_1.FlowrTextFile) {
263
+ this.addRoles(known, [...wrapped.roles ?? [], ...roles ?? []]);
264
+ return known;
265
+ }
266
+ this.forget(known);
267
+ known.roles?.forEach(r => wrapped.assignRole(r));
268
+ }
269
+ const f = this.fileLoadPlugins(wrapped);
248
270
  f.addOnInvalidate(c => {
249
271
  this.context.analyzer?.receive(c);
250
272
  });
@@ -252,8 +274,6 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
252
274
  this.inlineFiles.push(f);
253
275
  }
254
276
  else {
255
- const exist = this.files.get(files_1.RPath.of(f.path()));
256
- (0, assert_1.guard)(exist === undefined || exist === f, `File ${f.path()} already added to the context.`);
257
277
  this.files.set(files_1.RPath.of(f.path()), f);
258
278
  this.caseIndex = undefined;
259
279
  }
@@ -265,6 +285,24 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
265
285
  this.projectKindCache = undefined;
266
286
  return f;
267
287
  }
288
+ forget(file) {
289
+ for (const r of file.roles ?? []) {
290
+ const files = this.byRole[r];
291
+ const at = files.indexOf(file);
292
+ if (at >= 0) {
293
+ files.splice(at, 1);
294
+ }
295
+ }
296
+ }
297
+ addRoles(file, roles) {
298
+ for (const r of roles) {
299
+ if (!file.roles?.includes(r)) {
300
+ file.assignRole(r);
301
+ this.byRole[r].push(file);
302
+ this.projectKindCache = undefined;
303
+ }
304
+ }
305
+ }
268
306
  hasCached(path) {
269
307
  return this.files.has(files_1.RPath.of(path));
270
308
  }
@@ -346,10 +384,17 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
346
384
  return undefined;
347
385
  }
348
386
  }
387
+ /**
388
+ * Runs the file loaders on `f`. They match the path below the folder `f` shares with the {@link root}, so the folders
389
+ * holding the project (say, a package checked out below a `test` folder) assign no role.
390
+ */
349
391
  fileLoadPlugins(f) {
350
392
  let fFinal = f;
393
+ const root = this.root();
394
+ const shared = root === undefined || f.path() === flowr_file_1.FlowrFile.INLINE_PATH ? undefined : (0, files_1.commonDirectory)([root, path_1.default.dirname(f.path())]);
395
+ const relative = shared === undefined ? f.path() : (0, files_1.relativeTo)(shared, f.path());
351
396
  for (const loader of this.fileLoaders) {
352
- if (loader.applies(f.path())) {
397
+ if (loader.applies(relative)) {
353
398
  fileLog.debug(`Applying file loader ${loader.name} to file ${f.path()}`);
354
399
  const res = loader.processor(this.ctx, fFinal);
355
400
  if (Array.isArray(res)) {
@@ -223,15 +223,6 @@ export declare class FlowrAnalyzer<Parser extends KnownParser = KnownParser> imp
223
223
  normalizeStandalone(data: `${typeof fileProtocol}${string}` | string | RParseRequest): NormalizedAst;
224
224
  addRequest(...request: (RAnalysisRequest | readonly RAnalysisRequest[] | `${typeof fileProtocol}${string}` | string)[]): this;
225
225
  addFile(...f: (string | FlowrFileProvider | RParseRequestFromFile)[]): this;
226
- /**
227
- * Add a request created from the given input.
228
- * This is a convenience method that uses {@link requestFromInput} internally.
229
- */
230
- private addRequestFromInput;
231
- /**
232
- * Add one or multiple requests to analyze the builder.
233
- */
234
- private addAnalysisRequest;
235
226
  parse(force?: boolean): Promise<NonNullable<AnalyzerCacheType<Parser>['parse']>>;
236
227
  peekParse(): NonNullable<AnalyzerCacheType<Parser>['parse']> | undefined;
237
228
  normalize(force?: boolean): Promise<NonNullable<AnalyzerCacheType<Parser>['normalize']>>;
@@ -90,41 +90,20 @@ class FlowrAnalyzer {
90
90
  return (0, decorate_1.decorateAst)((0, tree_sitter_normalize_1.normalizeTreeSitterTreeToAst)([{ parsed: parse, filePath: undefined }], true), {});
91
91
  }
92
92
  addRequest(...request) {
93
- for (const r of request) {
94
- if (typeof r === 'string') {
95
- const trimmed = r.slice(retriever_1.fileProtocol.length);
96
- if (r.startsWith(retriever_1.fileProtocol) && !(0, files_1.isFilePath)(trimmed)) {
97
- this.addAnalysisRequest({ request: 'project', content: trimmed });
98
- }
99
- else {
100
- this.addRequestFromInput(r);
101
- }
93
+ /* added at once, so that every request knows the folders of the others when its files are added */
94
+ this.ctx.addRequests(request.flatMap((r) => {
95
+ if (typeof r !== 'string') {
96
+ return r;
102
97
  }
103
- else {
104
- this.addAnalysisRequest(r);
105
- }
106
- }
98
+ const trimmed = r.slice(retriever_1.fileProtocol.length);
99
+ return r.startsWith(retriever_1.fileProtocol) && !(0, files_1.isFilePath)(trimmed) ? { request: 'project', content: trimmed } : (0, retriever_1.requestFromInput)(r);
100
+ }));
107
101
  return this;
108
102
  }
109
103
  addFile(...f) {
110
104
  this.ctx.addFiles(f);
111
105
  return this;
112
106
  }
113
- /**
114
- * Add a request created from the given input.
115
- * This is a convenience method that uses {@link requestFromInput} internally.
116
- */
117
- addRequestFromInput(input) {
118
- this.addAnalysisRequest((0, retriever_1.requestFromInput)(input));
119
- return this;
120
- }
121
- /**
122
- * Add one or multiple requests to analyze the builder.
123
- */
124
- addAnalysisRequest(request) {
125
- this.ctx.addRequests((Array.isArray(request) ? request : [request]));
126
- return this;
127
- }
128
107
  async parse(force) {
129
108
  return this.cache.parse(force);
130
109
  }
@@ -5,14 +5,11 @@ import type { FlowrAnalyzerContext } from '../../../context/flowr-analyzer-conte
5
5
  import type { ParentInformation } from '../../../../r-bridge/lang-4.x/ast/model/processing/decorate';
6
6
  export interface NamespaceInfo {
7
7
  exportedSymbols: string[];
8
- exportedFunctions: string[];
9
8
  /**
10
9
  * Names listed by `exportMethods()`: S4 methods the package registered for one of its classes, which is a
11
10
  * different claim than an ordinary export (the package answers a generic, it does not define the function).
12
11
  * As R's `loadNamespace`, this keeps only the non-primitive generics: a method on a primitive such as `+` or `[`
13
12
  * binds nothing in the namespace, so `pkg::"+"` does not exist and the call stays with base.
14
- * Only the context-parsed path ({@link parseNamespaceComplex}) tells these apart; the regex fallback folds
15
- * them into {@link exportedFunctions}.
16
13
  */
17
14
  exportedS4Methods: string[];
18
15
  /** Classes listed by `exportClasses()`: the S4 classes the package owns. Separated like {@link exportedS4Methods}. */
@@ -67,6 +64,11 @@ export declare class FlowrNamespaceFile extends FlowrFile<NamespaceFormat> {
67
64
  * @param pkg - The package to check in
68
65
  */
69
66
  export declare function isExportedInNamespaceFormat(this: void, fmt: NamespaceFormat, name: string, pkg?: string): boolean | RNode<ParentInformation>[];
67
+ /**
68
+ * The package an explicit `importFrom(pkg, name)` takes `name` from. A package exporting such a name defines nothing
69
+ * of it but re-exports that package's function (`dplyr::%>%` is `magrittr::%>%`), which stays its own export all the same.
70
+ */
71
+ export declare function importOrigin(this: void, name: string, nsInfo: NamespaceInfo): string | undefined;
70
72
  /** As {@link isExportedInNamespaceFormat}, but for one already picked {@link NamespaceInfo}. */
71
73
  export declare function isExportedInInfo(this: void, name: string, nsInfo: NamespaceInfo): boolean | RNode<ParentInformation>[];
72
74
  /** All exported names of a namespace that can be referenced (functions, symbols, patterns, and S3 methods as `generic.class`). */
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FlowrNamespaceFile = void 0;
4
4
  exports.isExportedInNamespaceFormat = isExportedInNamespaceFormat;
5
+ exports.importOrigin = importOrigin;
5
6
  exports.isExportedInInfo = isExportedInInfo;
6
7
  exports.getExportedNames = getExportedNames;
7
8
  exports.getCallables = getCallables;
@@ -12,7 +13,6 @@ const flowr_file_1 = require("../../../context/flowr-file");
12
13
  const resolve_args_1 = require("../../../../abstract-interpretation/data-frame/resolve-args");
13
14
  const fold_1 = require("../../../../r-bridge/lang-4.x/ast/model/processing/fold");
14
15
  const identifier_1 = require("../../../../dataflow/environments/identifier");
15
- const assert_1 = require("../../../../util/assert");
16
16
  const type_1 = require("../../../../r-bridge/lang-4.x/ast/model/type");
17
17
  const r_primitives_generated_1 = require("../../../../data/r-primitives.generated");
18
18
  const make_argument_1 = require("../../../../dataflow/internal/process/functions/call/argument/make-argument");
@@ -20,7 +20,6 @@ const range_1 = require("../../../../util/range");
20
20
  const r_regex_1 = require("../../../../util/r-regex");
21
21
  const r_argument_1 = require("../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
22
22
  const arrays_1 = require("../../../../util/collections/arrays");
23
- const r_function_call_1 = require("../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
24
23
  /**
25
24
  * Decorates a text file to expose its content as a {@link NamespaceFormat}.
26
25
  * Simple parsing is quicker but does not support `if`/other R constructs.
@@ -81,10 +80,21 @@ function isExportedInNamespaceFormat(fmt, name, pkg = 'current') {
81
80
  const nsInfo = pkg === 'current' ? fmt.current : fmt[pkg];
82
81
  return nsInfo ? isExportedInInfo(name, nsInfo) : false;
83
82
  }
83
+ /**
84
+ * The package an explicit `importFrom(pkg, name)` takes `name` from. A package exporting such a name defines nothing
85
+ * of it but re-exports that package's function (`dplyr::%>%` is `magrittr::%>%`), which stays its own export all the same.
86
+ */
87
+ function importOrigin(name, nsInfo) {
88
+ for (const [pkg, names] of nsInfo.importedPackages) {
89
+ if (names !== 'all' && names.includes(name)) {
90
+ return pkg;
91
+ }
92
+ }
93
+ return undefined;
94
+ }
84
95
  /** As {@link isExportedInNamespaceFormat}, but for one already picked {@link NamespaceInfo}. */
85
96
  function isExportedInInfo(name, nsInfo) {
86
- if (nsInfo.exportedSymbols.includes(name) || nsInfo.exportedFunctions.includes(name)
87
- || nsInfo.exportedS4Methods.includes(name) || nsInfo.exportedS4Classes.includes(name)) {
97
+ if (nsInfo.exportedSymbols.includes(name) || nsInfo.exportedS4Methods.includes(name) || nsInfo.exportedS4Classes.includes(name)) {
88
98
  return true;
89
99
  }
90
100
  if (name.includes('.')) {
@@ -167,27 +177,10 @@ function parseNamespaceComplex(file, ctx) {
167
177
  }
168
178
  const name = identifier_1.Identifier.getName(call.functionName.content);
169
179
  const g = expr ?? getEmptyNamespaceFormat();
170
- switch (name) {
171
- case 'export':
172
- return handleExportCall(g, call.arguments);
173
- case 'exportPattern':
174
- return handleExportPatternCall(g, call.arguments);
175
- case 'S3method':
176
- return handleS3MethodCall(g, call.arguments);
177
- case 'import':
178
- return handleImportCall(g, call.arguments);
179
- case 'importFrom':
180
- case 'importClassesFrom':
181
- case 'importMethodsFrom':
182
- return handleImportFromCall(g, call.arguments);
183
- case 'useDynLib':
184
- return handleUseDynLibCall(g, call.arguments);
185
- case 'exportClasses':
186
- return handleS4ExportCall(g, call.arguments, 'exportedS4Classes');
187
- case 'exportMethods':
188
- return handleS4ExportCall(g, call.arguments, 'exportedS4Methods');
189
- }
190
- return g;
180
+ return applyDirective(g, name, call.arguments.flatMap(a => {
181
+ const value = r_argument_1.RArgument.isEmpty(a) ? undefined : a.name === undefined ? a.lexeme : a.value?.lexeme;
182
+ return value === undefined || r_argument_1.RArgument.isEmpty(a) ? [] : [{ name: a.name === undefined ? undefined : identifier_1.Identifier.getName(a.name.content), value }];
183
+ }));
191
184
  }
192
185
  }
193
186
  });
@@ -200,7 +193,7 @@ function getExportedNames(info) {
200
193
  s3.push(`${g}.${m}`);
201
194
  }
202
195
  }
203
- return (0, arrays_1.uniqueArray)([...info.exportedSymbols, ...info.exportedFunctions, ...info.exportedS4Methods,
196
+ return (0, arrays_1.uniqueArray)([...info.exportedSymbols, ...info.exportedS4Methods,
204
197
  ...info.exportedS4Classes, ...info.exportedPatterns, ...s3]);
205
198
  }
206
199
  /** The names a package makes callable: the explicitly configured {@link NamespaceInfo#callable} subset, or all exports (see {@link getExportedNames}) by default. */
@@ -244,10 +237,6 @@ function wrapRNodeInNotCall(node, idMap) {
244
237
  arguments: [(0, make_argument_1.toUnnamedArgument)(node, idMap)]
245
238
  };
246
239
  }
247
- /** Unquotes every lexeme of `args` (dropping empty/nameless arguments) and pushes the result onto `target`. */
248
- function pushUnquotedLexemes(target, args, unquote) {
249
- target.push(...args.filter(a => a !== r_function_call_1.EmptyArgument).map(a => a.lexeme ? unquote(a.lexeme) : undefined).filter(assert_1.isNotUndefined));
250
- }
251
240
  /** The array stored for `key` in a `string[]`-valued map, creating and registering an empty one if there is none yet. */
252
241
  function arrayAt(map, key) {
253
242
  const arr = map.get(key) ?? [];
@@ -268,88 +257,59 @@ function importArrayAt(map, key) {
268
257
  function markSideEffectLoader(fmt, pkg) {
269
258
  (fmt[pkg] ??= emptyNamespaceInfo()).loadsWithSideEffects = true;
270
259
  }
271
- function handleExportCall(g, args) {
272
- pushUnquotedLexemes(g.current.exportedSymbols, args, r_string_1.RString.unquote);
273
- return g;
274
- }
275
- function handleExportPatternCall(g, args) {
276
- pushUnquotedLexemes(g.current.exportedPatterns, args, resolve_args_1.unquoteArgument);
277
- return g;
278
- }
279
- function handleS3MethodCall(g, args) {
280
- /* `S3method(generic, class)` and `S3method(generic, class, method)` both register the class */
281
- if (args.length !== 2 && args.length !== 3) {
282
- return g;
283
- }
284
- const pkgArg = args[0];
285
- const funcArg = args[1];
286
- if (r_argument_1.RArgument.isEmpty(pkgArg) || r_argument_1.RArgument.isEmpty(funcArg) || !pkgArg.lexeme || !funcArg.lexeme) {
287
- return g;
260
+ function importFrom(g, [pkg, ...symbols]) {
261
+ if (pkg !== undefined && symbols.length > 0) {
262
+ importArrayAt(g.current.importedPackages, r_string_1.RString.unquote(pkg)).push(...symbols.map(r_string_1.RString.unquote));
288
263
  }
289
- const generic = r_string_1.RString.unquote(pkgArg.lexeme);
290
- const cls = r_string_1.RString.unquote(funcArg.lexeme);
291
- arrayAt(g.current.exportS3Generics, generic).push(cls);
292
- const fun = args[2];
293
- if (fun !== undefined && !r_argument_1.RArgument.isEmpty(fun) && fun.lexeme) {
294
- (g.current.s3MethodFunctions ??= new Map()).set(`${generic}.${cls}`, r_string_1.RString.unquote(fun.lexeme));
295
- }
296
- return g;
297
264
  }
298
- function handleImportCall(g, args) {
299
- /* `import(a, b)` imports both; a named argument like `except =` names no package */
300
- for (const arg of args) {
301
- if (arg !== r_function_call_1.EmptyArgument && arg.name === undefined && arg.lexeme) {
302
- g.current.importedPackages?.set(r_string_1.RString.unquote(arg.lexeme), 'all');
265
+ /** What each NAMESPACE directive adds, shared by the AST-based and the plain-text parser so that both read a NAMESPACE alike. */
266
+ const NamespaceDirectives = new Map(Object.entries({
267
+ export: (g, args) => g.current.exportedSymbols.push(...args.map(r_string_1.RString.unquote)),
268
+ exportPattern: (g, args) => g.current.exportedPatterns.push(...args.map(a => (0, resolve_args_1.unquoteArgument)(a))),
269
+ exportClasses: (g, args) => g.current.exportedS4Classes.push(...args.map(r_string_1.RString.unquote)),
270
+ /* as for R, a method on a primitive generic binds nothing in the namespace */
271
+ exportMethods: (g, args) => g.current.exportedS4Methods.push(...args.map(r_string_1.RString.unquote).filter(n => !r_primitives_generated_1.RPrimitives.has(n))),
272
+ /* `S3method(generic, class)` and `S3method(generic, class, method)` both register the class */
273
+ S3method: (g, args) => {
274
+ if (args.length !== 2 && args.length !== 3) {
275
+ return;
303
276
  }
304
- }
305
- return g;
306
- }
307
- function handleImportFromCall(g, args) {
308
- if (args.length < 2) {
309
- return g;
310
- }
311
- const pkgArg = args[0];
312
- if (r_argument_1.RArgument.isEmpty(pkgArg) || !pkgArg.lexeme) {
313
- return g;
314
- }
315
- const arr = importArrayAt(g.current.importedPackages, r_string_1.RString.unquote(pkgArg.lexeme));
316
- for (let i = 1; i < args.length; i++) {
317
- const symArg = args[i];
318
- if (r_argument_1.RArgument.isEmpty(symArg) || !symArg.lexeme) {
319
- continue;
277
+ const [generic, cls, fun] = args.map(r_string_1.RString.unquote);
278
+ arrayAt(g.current.exportS3Generics, generic).push(cls);
279
+ if (fun !== undefined) {
280
+ (g.current.s3MethodFunctions ??= new Map()).set(`${generic}.${cls}`, fun);
281
+ }
282
+ },
283
+ import: (g, args) => {
284
+ for (const pkg of args) {
285
+ g.current.importedPackages.set(r_string_1.RString.unquote(pkg), 'all');
286
+ }
287
+ },
288
+ importFrom,
289
+ importClassesFrom: importFrom,
290
+ importMethodsFrom: importFrom,
291
+ useDynLib: (g, [pkg]) => {
292
+ if (pkg !== undefined) {
293
+ markSideEffectLoader(g, r_string_1.RString.unquote(pkg));
320
294
  }
321
- arr.push(r_string_1.RString.unquote(symArg.lexeme));
322
- }
323
- return g;
324
- }
325
- function handleUseDynLibCall(g, args) {
326
- if (args.length < 1) {
327
- return g;
328
- }
329
- const pkgArg = args[0];
330
- if (r_argument_1.RArgument.isEmpty(pkgArg) || !pkgArg.lexeme) {
331
- return g;
332
295
  }
333
- markSideEffectLoader(g, r_string_1.RString.unquote(pkgArg.lexeme));
334
- return g;
335
- }
336
- /** `exportClasses(A, B)` / `exportMethods(show, summary)`: a directive may list several names, and each goes to `into`. */
337
- function handleS4ExportCall(g, args, into) {
338
- const names = [];
339
- pushUnquotedLexemes(names, args, r_string_1.RString.unquote);
340
- g.current[into].push(...(into === 'exportedS4Methods' ? exportedGenerics(names) : names));
296
+ }));
297
+ /** As R's `parseNamespaceFile`, these options are read by name, every other argument by its position. */
298
+ const DirectiveOptions = new Map([
299
+ ['import', new Set(['except'])],
300
+ ['useDynLib', new Set(['.registration', '.fixes'])]
301
+ ]);
302
+ /** Applies the directive `name` (if it is one) with its `args` to `g`. */
303
+ function applyDirective(g, name, args) {
304
+ const options = DirectiveOptions.get(name);
305
+ NamespaceDirectives.get(name)?.(g, args.filter(a => a.name === undefined || !options?.has(a.name)).map(a => a.value));
341
306
  return g;
342
307
  }
343
- /** The `exportMethods()` names R exports: methods on a primitive generic bind nothing in the namespace. */
344
- function exportedGenerics(names) {
345
- return names.filter(n => !r_primitives_generated_1.RPrimitives.has(n));
346
- }
347
308
  const cleanLineCommentRegex = /^#.*$/gm;
348
309
  /** A namespace that neither exports nor imports anything yet. */
349
310
  function emptyNamespaceInfo() {
350
311
  return {
351
312
  exportedSymbols: [],
352
- exportedFunctions: [],
353
313
  exportedS4Methods: [],
354
314
  exportedS4Classes: [],
355
315
  exportS3Generics: new Map(),
@@ -424,23 +384,22 @@ function mergeNamespaceInfo(target, source) {
424
384
  ? new Map([...target.s3MethodFunctions ?? [], ...source.s3MethodFunctions ?? []]) : undefined;
425
385
  return {
426
386
  ...(s3MethodFunctions ? { s3MethodFunctions } : {}),
387
+ ...(mergedConditional.size > 0 ? { conditional: mergedConditional } : {}),
427
388
  callable: [...target.callable, ...source.callable],
428
389
  exportedSymbols: [...target.exportedSymbols, ...source.exportedSymbols],
429
- exportedFunctions: [...target.exportedFunctions, ...source.exportedFunctions],
430
390
  exportedS4Methods: [...target.exportedS4Methods, ...source.exportedS4Methods],
431
391
  exportedS4Classes: [...target.exportedS4Classes, ...source.exportedS4Classes],
432
392
  exportS3Generics: mergedS3Generics,
433
393
  exportedPatterns: [...target.exportedPatterns, ...source.exportedPatterns],
434
394
  importedPackages: mergedImportedPackages,
435
- loadsWithSideEffects: target.loadsWithSideEffects || source.loadsWithSideEffects,
436
- conditional: mergedConditional.size > 0 ? mergedConditional : undefined,
395
+ loadsWithSideEffects: target.loadsWithSideEffects || source.loadsWithSideEffects
437
396
  };
438
397
  }
439
- /** an argument given by name (`except = c(x)`), which names no symbol of its own */
440
- const namedArgument = /^[\w.]+\s*=[^=]/;
398
+ /** an argument given by name (`except = c(x)`) */
399
+ const namedArgument = /^([\w.]+)\s*=(?!=)\s*(.*)$/s;
441
400
  /**
442
- * Split a NAMESPACE directive's argument list (`a, "b", except = c(x)`) into its positional, quote-stripped
443
- * names. Only top-level commas separate, so an argument that is itself a call stays in one piece.
401
+ * Split a NAMESPACE directive's argument list (`a, "b", except = c(x)`) into its
402
+ * arguments as written. Only top-level commas separate, so an argument that is itself a call stays in one piece.
444
403
  */
445
404
  function splitNamespaceArgs(args) {
446
405
  const names = [];
@@ -469,8 +428,9 @@ function splitNamespaceArgs(args) {
469
428
  else if (i === args.length || (c === ',' && depth === 0)) {
470
429
  const part = args.slice(start, i).trim();
471
430
  start = i + 1;
472
- if (part.length > 0 && !namedArgument.test(part)) {
473
- names.push(r_string_1.RString.unquote(part));
431
+ const named = namedArgument.exec(part);
432
+ if (part.length > 0) {
433
+ names.push(named === null ? { value: part } : { name: named[1], value: named[2] });
474
434
  }
475
435
  }
476
436
  }
@@ -489,60 +449,7 @@ function parseNamespaceSimple(file) {
489
449
  continue;
490
450
  }
491
451
  const [, type, args] = match;
492
- switch (type) {
493
- case 'exportClasses':
494
- case 'exportMethods':
495
- // a single directive may list several symbols, e.g. `exportMethods(show, summary)`
496
- result.current.exportedFunctions.push(...exportedGenerics(splitNamespaceArgs(args)));
497
- break;
498
- case 'S3method':
499
- {
500
- const parts = splitNamespaceArgs(args);
501
- if (parts.length !== 2 && parts.length !== 3) {
502
- continue;
503
- }
504
- const [pkg, func, fun] = parts;
505
- arrayAt(result.current.exportS3Generics, pkg).push(func);
506
- if (fun !== undefined) {
507
- (result.current.s3MethodFunctions ??= new Map()).set(`${pkg}.${func}`, fun);
508
- }
509
- break;
510
- }
511
- case 'export':
512
- // `export(a, b)` exports both `a` and `b`, so split rather than storing the literal `"a, b"`
513
- result.current.exportedSymbols.push(...splitNamespaceArgs(args));
514
- break;
515
- case 'useDynLib':
516
- {
517
- const parts = args.split(',').map(s => s.trim());
518
- if (parts.length !== 2) {
519
- continue;
520
- }
521
- markSideEffectLoader(result, parts[0]);
522
- break;
523
- }
524
- case 'import': {
525
- for (const pkg of splitNamespaceArgs(args)) {
526
- result.current.importedPackages?.set(pkg, 'all');
527
- }
528
- break;
529
- }
530
- case 'importFrom':
531
- case 'importClassesFrom':
532
- case 'importMethodsFrom': {
533
- const parts = splitNamespaceArgs(args);
534
- if (parts.length < 2) {
535
- continue;
536
- }
537
- const [pkg, ...symbols] = parts;
538
- importArrayAt(result.current.importedPackages, pkg).push(...symbols);
539
- break;
540
- }
541
- case 'exportPattern': {
542
- result.current.exportedPatterns?.push((0, resolve_args_1.unquoteArgument)(args.trim()));
543
- break;
544
- }
545
- }
452
+ applyDirective(result, type, splitNamespaceArgs(args));
546
453
  }
547
454
  return result;
548
455
  }
@@ -3,7 +3,6 @@ import type { PathLike } from 'fs';
3
3
  import type { FlowrFileProvider } from '../../context/flowr-file';
4
4
  import { FileRole } from '../../context/flowr-file';
5
5
  import type { FlowrAnalyzerContext } from '../../context/flowr-analyzer-context';
6
- import { platformBasename, platformDirname } from '../../../dataflow/internal/process/functions/call/built-in/built-in-source';
7
6
  /**
8
7
  * This is the base class for all plugins that load and possibly transform files when they are loaded.
9
8
  * Different from other plugins, these plugins trigger for each file that is loaded (if they {@link applies} to the file).
@@ -28,9 +27,9 @@ export declare abstract class FlowrAnalyzerFilePlugin extends FlowrAnalyzerPlugi
28
27
  /** Which part of a path a {@link FlowrAnalyzerPatternFilePlugin} matches its pattern against. */
29
28
  export declare const PathPart: {
30
29
  /** The file name including its extension. */
31
- readonly Basename: typeof platformBasename;
30
+ readonly Basename: (this: void, p: string) => string;
32
31
  /** The directory portion of the path. */
33
- readonly Dirname: typeof platformDirname;
32
+ readonly Dirname: (this: void, p: string) => string;
34
33
  /** The whole path, for patterns that need both the folder and the file name. */
35
34
  readonly Full: (p: string) => string;
36
35
  };
@@ -5,7 +5,6 @@ const flowr_analyzer_plugin_1 = require("../flowr-analyzer-plugin");
5
5
  const flowr_file_1 = require("../../context/flowr-file");
6
6
  const semver_1 = require("semver");
7
7
  const files_1 = require("../../../util/files");
8
- const built_in_source_1 = require("../../../dataflow/internal/process/functions/call/built-in/built-in-source");
9
8
  /**
10
9
  * This is the base class for all plugins that load and possibly transform files when they are loaded.
11
10
  * Different from other plugins, these plugins trigger for each file that is loaded (if they {@link applies} to the file).
@@ -45,9 +44,9 @@ class DefaultFlowrAnalyzerFilePlugin extends FlowrAnalyzerFilePlugin {
45
44
  /** Which part of a path a {@link FlowrAnalyzerPatternFilePlugin} matches its pattern against. */
46
45
  exports.PathPart = {
47
46
  /** The file name including its extension. */
48
- Basename: built_in_source_1.platformBasename,
47
+ Basename: files_1.RPath.basename,
49
48
  /** The directory portion of the path. */
50
- Dirname: built_in_source_1.platformDirname,
49
+ Dirname: files_1.RPath.dirname,
51
50
  /** The whole path, for patterns that need both the folder and the file name. */
52
51
  Full: (p) => p
53
52
  };
@@ -4,7 +4,7 @@ exports.FlowrAnalyzerRprofileFilePlugin = exports.RenvironFilePattern = exports.
4
4
  const flowr_analyzer_file_plugin_1 = require("./flowr-analyzer-file-plugin");
5
5
  const semver_1 = require("semver");
6
6
  const flowr_file_1 = require("../../context/flowr-file");
7
- const built_in_source_1 = require("../../../dataflow/internal/process/functions/call/built-in/built-in-source");
7
+ const files_1 = require("../../../util/files");
8
8
  /** `Rprofile.site` is the site-wide, `.Rprofile` the user/project profile. */
9
9
  exports.RprofileFilePattern = /^(\.Rprofile|Rprofile\.site)$/i;
10
10
  /** `.Renviron` is the user/project environment file, `Renviron.site` the site-wide one. */
@@ -25,10 +25,10 @@ class FlowrAnalyzerRprofileFilePlugin extends flowr_analyzer_file_plugin_1.Flowr
25
25
  this.environPattern = environPattern;
26
26
  }
27
27
  applies(file) {
28
- return super.applies(file) || this.environPattern.test((0, built_in_source_1.platformBasename)(file.toString()));
28
+ return super.applies(file) || this.environPattern.test(files_1.RPath.basename(file.toString()));
29
29
  }
30
30
  process(_ctx, file) {
31
- if (this.environPattern.test((0, built_in_source_1.platformBasename)(file.path()))) {
31
+ if (this.environPattern.test(files_1.RPath.basename(file.path()))) {
32
32
  file.assignRole(flowr_file_1.FileRole.Environment);
33
33
  }
34
34
  else {
@@ -6,7 +6,7 @@ const flowr_analyzer_package_versions_plugin_1 = require("./flowr-analyzer-packa
6
6
  const semver_1 = require("semver");
7
7
  const package_1 = require("./package");
8
8
  const flowr_file_1 = require("../../context/flowr-file");
9
- const built_in_source_1 = require("../../../dataflow/internal/process/functions/call/built-in/built-in-source");
9
+ const files_1 = require("../../../util/files");
10
10
  const log_1 = require("../../../util/log");
11
11
  const smol_toml_1 = require("smol-toml");
12
12
  const flowr_analyzer_meta_context_1 = require("../../context/flowr-analyzer-meta-context");
@@ -15,7 +15,7 @@ exports.lockfileLog = log_1.log.getSubLogger({ name: 'flowr-analyzer-package-ver
15
15
  /** The {@link FileRole.VirtualEnv} lockfiles named `name` (e.g. `renv.lock`), matched case-insensitively like the role is assigned. */
16
16
  function virtualEnvFiles(ctx, name) {
17
17
  return ctx.files.getFilesByRole(flowr_file_1.FileRole.VirtualEnv).filter(f => {
18
- const base = (0, built_in_source_1.platformBasename)(f.path());
18
+ const base = files_1.RPath.basename(f.path());
19
19
  return typeof name === 'string' ? base.toLowerCase() === name : name.test(base);
20
20
  });
21
21
  }
@@ -28,10 +28,9 @@ class FlowrAnalyzerPackageVersionsNamespaceFilePlugin extends flowr_analyzer_pac
28
28
  name: pkg,
29
29
  namespaceInfo: info
30
30
  }));
31
- /* the S4 lists are exports as much as the other two, they just say *why* the name is exported */
31
+ /* the S4 lists are exports as much as the plain one, they just say *why* the name is exported */
32
32
  const exportKinds = [
33
33
  [info.exportedSymbols, {}],
34
- [info.exportedFunctions, {}],
35
34
  [info.exportedS4Methods, { isS4Method: true }],
36
35
  [info.exportedS4Classes, { isS4Class: true }]
37
36
  ];
@@ -116,4 +116,4 @@ export declare class FlowrAnalyzerPackageVersionsSigDbPlugin extends FlowrAnalyz
116
116
  * The resolved {@link Package} (namespace and version) of a source's export view. What the configuration states
117
117
  * for the package (`stated`) is part of its interface, even where the source misses it.
118
118
  */
119
- export declare function packageFromExports(name: string, info: Pick<LibraryExports, 'exported' | 's4Classes' | 'version'>, stated?: Iterable<unknown>): Package;
119
+ export declare function packageFromExports(name: string, info: Pick<LibraryExports, 'exported' | 's4Classes' | 'version' | 'reexports'>, stated?: Iterable<unknown>): Package;