@eagleoutice/flowr 2.16.3 → 2.16.5
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.
- package/README.md +14 -14
- package/cli/repl/core.js +13 -2
- package/cli/repl/parser/slice-query-parser.d.ts +21 -5
- package/cli/repl/parser/slice-query-parser.js +33 -13
- package/core/steps/all/static-slicing/10-reconstruct.d.ts +2 -2
- package/dataflow/environments/built-in.d.ts +2 -0
- package/dataflow/environments/built-in.js +10 -2
- package/dataflow/environments/data-masking-functions.js +2 -1
- package/dataflow/environments/default-builtin-config.d.ts +31 -5
- package/dataflow/environments/default-builtin-config.js +12 -15
- package/dataflow/environments/query-fn-props.js +2 -1
- package/dataflow/eval/resolve/alias-tracking.js +5 -2
- package/dataflow/eval/resolve/node-value.js +1 -1
- package/dataflow/eval/resolve/resolve-argument.js +2 -0
- package/dataflow/eval/resolve/resolve-strings.d.ts +10 -0
- package/dataflow/eval/resolve/resolve-strings.js +79 -12
- package/dataflow/eval/resolve/resolve.js +2 -6
- package/dataflow/extractor.js +11 -4
- package/dataflow/graph/applied-arguments.d.ts +5 -0
- package/dataflow/graph/applied-arguments.js +17 -0
- package/dataflow/graph/df-helper.js +2 -2
- package/dataflow/graph/graph.d.ts +5 -0
- package/dataflow/graph/graph.js +5 -0
- package/dataflow/info.js +8 -1
- package/dataflow/internal/linker.js +35 -13
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.d.ts +9 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-ambient-state.js +32 -12
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +8 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +7 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +11 -1
- package/dataflow/internal/process/functions/call/named-call-handling.js +4 -2
- package/dataflow/internal/process/functions/call/quoted.js +3 -3
- package/dataflow/internal/program-order.js +7 -1
- package/dataflow/processor.d.ts +2 -0
- package/documentation/doc-util/doc-query.d.ts +1 -1
- package/documentation/doc-util/doc-query.js +3 -1
- package/documentation/doc-util/doc-timings.js +3 -2
- package/documentation/doc-util/doc-types.js +4 -0
- package/documentation/wiki-create-linting-rules.js +1 -1
- package/documentation/wiki-linter.d.ts +14 -0
- package/documentation/wiki-linter.js +341 -126
- package/linter/linter-executor.js +7 -0
- package/linter/linter-rules.d.ts +47 -47
- package/linter/rules/absolute-path.d.ts +1 -1
- package/linter/rules/absolute-path.js +6 -4
- package/linter/rules/cmd-check/call-arguments.d.ts +1 -1
- package/linter/rules/cmd-check/call-arguments.js +10 -5
- package/linter/rules/cmd-check/compiled-code.d.ts +1 -1
- package/linter/rules/cmd-check/compiled-code.js +1 -1
- package/linter/rules/cmd-check/conformance.d.ts +5 -1
- package/linter/rules/cmd-check/conformance.js +64 -64
- package/linter/rules/cmd-check/description-metadata.d.ts +1 -1
- package/linter/rules/cmd-check/description-metadata.js +1 -1
- package/linter/rules/cmd-check/documentation-mismatch.d.ts +6 -0
- package/linter/rules/cmd-check/foreign-function-calls.d.ts +1 -1
- package/linter/rules/cmd-check/foreign-function-calls.js +1 -1
- package/linter/rules/cmd-check/namespace-tampering.d.ts +1 -1
- package/linter/rules/cmd-check/namespace-tampering.js +1 -1
- package/linter/rules/cmd-check/non-ascii-code.d.ts +1 -1
- package/linter/rules/cmd-check/non-ascii-code.js +1 -1
- package/linter/rules/cmd-check/package-data.d.ts +3 -1
- package/linter/rules/cmd-check/package-data.js +1 -1
- package/linter/rules/cmd-check/package-hooks.d.ts +2 -2
- package/linter/rules/cmd-check/package-hooks.js +13 -5
- package/linter/rules/cmd-check/package-metafiles.d.ts +1 -1
- package/linter/rules/cmd-check/package-metafiles.js +1 -1
- package/linter/rules/cmd-check/package-structure.d.ts +1 -1
- package/linter/rules/cmd-check/package-structure.js +1 -1
- package/linter/rules/cmd-check/rd-files.d.ts +17 -1
- package/linter/rules/cmd-check/rd-files.js +1 -1
- package/linter/rules/cmd-check/true-false-abbreviation.d.ts +1 -1
- package/linter/rules/cmd-check/true-false-abbreviation.js +1 -1
- package/linter/rules/dataframe-access-validation.d.ts +1 -1
- package/linter/rules/dataframe-access-validation.js +1 -1
- package/linter/rules/dead-code.d.ts +4 -4
- package/linter/rules/dead-code.js +19 -4
- package/linter/rules/deprecated-functions.d.ts +1 -1
- package/linter/rules/deprecated-functions.js +1 -1
- package/linter/rules/file-path-validity.d.ts +6 -2
- package/linter/rules/file-path-validity.js +7 -3
- package/linter/rules/namespace-access.d.ts +3 -3
- package/linter/rules/namespace-access.js +12 -3
- package/linter/rules/naming-convention.d.ts +1 -1
- package/linter/rules/naming-convention.js +1 -1
- package/linter/rules/network-functions.d.ts +1 -1
- package/linter/rules/network-functions.js +1 -1
- package/linter/rules/no-leaked-credentials.d.ts +1 -1
- package/linter/rules/no-leaked-credentials.js +1 -1
- package/linter/rules/problematic-inputs.d.ts +2 -2
- package/linter/rules/problematic-inputs.js +4 -4
- package/linter/rules/roxygen-arguments.d.ts +2 -2
- package/linter/rules/roxygen-arguments.js +2 -2
- package/linter/rules/seeded-randomness.d.ts +2 -2
- package/linter/rules/seeded-randomness.js +2 -2
- package/linter/rules/software-has-license.d.ts +2 -2
- package/linter/rules/software-has-license.js +2 -2
- package/linter/rules/software-has-tests.d.ts +2 -2
- package/linter/rules/software-has-tests.js +2 -2
- package/linter/rules/stop-with-call-arg.d.ts +3 -3
- package/linter/rules/stop-with-call-arg.js +22 -5
- package/linter/rules/syntactically-valid.d.ts +1 -1
- package/linter/rules/syntactically-valid.js +1 -1
- package/linter/rules/unclosed-connection.d.ts +2 -2
- package/linter/rules/unclosed-connection.js +2 -2
- package/linter/rules/undefined-symbol.d.ts +1 -1
- package/linter/rules/undefined-symbol.js +27 -4
- package/linter/rules/unescaped-arguments.d.ts +1 -1
- package/linter/rules/unescaped-arguments.js +1 -1
- package/linter/rules/unused-definition.d.ts +1 -1
- package/linter/rules/unused-definition.js +21 -2
- package/linter/rules/unused-import.d.ts +1 -1
- package/linter/rules/unused-import.js +1 -1
- package/linter/rules/useless-loop.d.ts +1 -1
- package/linter/rules/useless-loop.js +1 -1
- package/package.json +1 -1
- package/project/context/flowr-analyzer-environment-context.d.ts +1 -1
- package/project/context/flowr-analyzer-environment-context.js +2 -1
- package/project/context/flowr-analyzer-files-context.js +12 -11
- package/project/dependency-version-space.js +4 -6
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +2 -0
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +9 -8
- package/project/plugins/file-plugins/flowr-analyzer-test-file-plugin.js +1 -1
- package/project/plugins/file-plugins/flowr-analyzer-vignette-file-plugin.js +1 -1
- package/queries/catalog/dependencies-query/data-flow.d.ts +2 -0
- package/queries/catalog/dependencies-query/data-flow.js +6 -0
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +31 -0
- package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +5 -0
- package/queries/catalog/dependencies-query/implicit-echo.js +29 -30
- package/queries/catalog/dependencies-query/plot-objects.js +6 -2
- package/queries/catalog/dice-query/dice-query-format.d.ts +1 -1
- package/queries/catalog/dice-query/dice-query-format.js +1 -1
- package/queries/catalog/slice-query-options.d.ts +3 -3
- package/queries/catalog/slice-query-options.js +1 -1
- package/queries/catalog/static-slice-query/static-slice-query-executor.js +12 -1
- package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +7 -1
- package/queries/catalog/static-slice-query/static-slice-query-format.js +4 -2
- package/queries/query.d.ts +2 -2
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +19 -56
- package/reconstruct/inline/source-inline-map.d.ts +1 -1
- package/reconstruct/inline/source-inline-map.js +5 -3
- package/reconstruct/reconstruct.d.ts +8 -1
- package/reconstruct/reconstruct.js +12 -3
- package/slicing/static/removal-slice.d.ts +19 -0
- package/slicing/static/removal-slice.js +165 -0
- package/slicing/static/static-slicer.js +10 -5
- package/util/text/playground-link.d.ts +24 -1
- package/util/text/playground-link.js +16 -1
- package/util/version.js +2 -2
|
@@ -40,6 +40,28 @@ function declaredGlobalVariables(graph, ctx) {
|
|
|
40
40
|
}
|
|
41
41
|
return names;
|
|
42
42
|
}
|
|
43
|
+
/** the calls binding the name they are handed as a string, which flowR does not link to the reads of that name */
|
|
44
|
+
const NameBindingFunctions = new Set(['assign', 'delayedAssign']);
|
|
45
|
+
/**
|
|
46
|
+
* The names bound by the `assign(name, value)` calls of the code, as far as flowR resolves `name`:
|
|
47
|
+
* `assign(paste0("year", i), ...)` in a loop over `2000:2025` binds `year2000` to `year2025`.
|
|
48
|
+
*/
|
|
49
|
+
function assignedNames(graph, ctx) {
|
|
50
|
+
const names = new Set();
|
|
51
|
+
for (const [, vertex] of graph.verticesOfType(vertex_1.VertexType.FunctionCall)) {
|
|
52
|
+
const [name, ns] = identifier_1.Identifier.toArray(vertex.name);
|
|
53
|
+
if (!NameBindingFunctions.has(name) || (ns !== undefined && ns !== 'base')) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const values = (0, resolve_argument_1.getArgumentStringValue)(ctx.config.solver.variables, graph, vertex, 0, 'x', true, ctx);
|
|
57
|
+
for (const str of values?.values().flatMap(v => [...v]) ?? []) {
|
|
58
|
+
if (str !== undefined) {
|
|
59
|
+
names.add(str);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return names;
|
|
64
|
+
}
|
|
43
65
|
/** calls that load a package; an unresolved one means we cannot enumerate all exports in scope */
|
|
44
66
|
const LibraryLoadFunctions = new Set(['library', 'require', 'requireNamespace', 'loadNamespace', 'attachNamespace', 'load_all', 'use', 'p_load']);
|
|
45
67
|
/** test frameworks whose namespace a test file runs under implicitly (e.g. `tests/testthat/test-*.R` sees testthat's exports without a `library()`) */
|
|
@@ -90,6 +112,7 @@ exports.UNDEFINED_SYMBOL = {
|
|
|
90
112
|
.some(([id, v]) => unknownIds.has(id) && LibraryLoadFunctions.has(identifier_1.Identifier.getName(v.name)));
|
|
91
113
|
// names a package declares global (`utils::globalVariables`) are no undefined symbols to R CMD check either
|
|
92
114
|
const declaredGlobals = declaredGlobalVariables(graph, ctx);
|
|
115
|
+
const boundByAssign = assignedNames(graph, ctx);
|
|
93
116
|
// scope-defined names, a fallback for closure variables flowR's dataflow did not statically link
|
|
94
117
|
const scopeDefined = (0, undefined_symbol_util_1.collectScopeDefinedNames)(graph);
|
|
95
118
|
// packages whose exports are in scope: DESCRIPTION/library() deps plus the default-attached base
|
|
@@ -141,7 +164,7 @@ exports.UNDEFINED_SYMBOL = {
|
|
|
141
164
|
return suppress('declaredGlobal');
|
|
142
165
|
}
|
|
143
166
|
// forward-referenced closure binding flowR's dataflow did not link (unconditional bindings only)
|
|
144
|
-
if ((0, undefined_symbol_util_1.isDefinedInEnclosingScope)(graph, scopeDefined, id, name)) {
|
|
167
|
+
if ((0, undefined_symbol_util_1.isDefinedInEnclosingScope)(graph, scopeDefined, id, name) || (kind === 'variable' && namespace === undefined && boundByAssign.has(name))) {
|
|
145
168
|
return suppress('enclosingScope');
|
|
146
169
|
}
|
|
147
170
|
// consumed by non-standard evaluation (quoting), hence not an ordinary read
|
|
@@ -198,8 +221,8 @@ exports.UNDEFINED_SYMBOL = {
|
|
|
198
221
|
const where = range_1.SourceLocation.format(result.loc);
|
|
199
222
|
if (result.availableInPackages && result.availableInPackages.length > 0) {
|
|
200
223
|
const pkgs = result.availableInPackages.map(p => `\`${p}\``).join(', ');
|
|
201
|
-
const hint = result.availableInPackages.length === 1 ?
|
|
202
|
-
return `\`${result.name}\` at ${where} is used but not defined
|
|
224
|
+
const hint = result.availableInPackages.length === 1 ? `with \`library(${result.availableInPackages[0]})\`` : 'from one of them';
|
|
225
|
+
return `\`${result.name}\` at ${where} is used but not defined. It is exported by ${pkgs}, so it may only need loading, for example ${hint}.`;
|
|
203
226
|
}
|
|
204
227
|
return result.kind === 'function'
|
|
205
228
|
? `\`${result.name}\` at ${where} is called but is neither defined locally, a base R builtin, nor exported by a loaded package`
|
|
@@ -209,7 +232,7 @@ exports.UNDEFINED_SYMBOL = {
|
|
|
209
232
|
info: {
|
|
210
233
|
name: 'Undefined Symbol',
|
|
211
234
|
certainty: linter_format_1.LintingRuleCertainty.OverApproximative,
|
|
212
|
-
description: '
|
|
235
|
+
description: 'Finds functions and variables that are neither defined locally, a base R builtin, nor exported by a loaded package.',
|
|
213
236
|
tags: [linter_tags_1.LintingRuleTag.Bug, linter_tags_1.LintingRuleTag.Experimental],
|
|
214
237
|
defaultConfig: () => ({
|
|
215
238
|
checkFunctions: true,
|
|
@@ -115,7 +115,7 @@ export declare const UNESCAPED_ARGUMENTS: {
|
|
|
115
115
|
readonly name: "Unescaped Arguments";
|
|
116
116
|
readonly tags: readonly [LintingRuleTag.Security, LintingRuleTag.Smell, LintingRuleTag.Shiny, LintingRuleTag.QuickFix];
|
|
117
117
|
readonly certainty: LintingRuleCertainty.BestEffort;
|
|
118
|
-
readonly description: "
|
|
118
|
+
readonly description: "Finds arguments of critical system, evaluation, database, and HTML/JavaScript calls that are not properly escaped.";
|
|
119
119
|
readonly defaultConfig: () => {
|
|
120
120
|
categories: {
|
|
121
121
|
system: {
|
|
@@ -329,7 +329,7 @@ exports.UNESCAPED_ARGUMENTS = {
|
|
|
329
329
|
name: 'Unescaped Arguments',
|
|
330
330
|
tags: [linter_tags_1.LintingRuleTag.Security, linter_tags_1.LintingRuleTag.Smell, linter_tags_1.LintingRuleTag.Shiny, linter_tags_1.LintingRuleTag.QuickFix],
|
|
331
331
|
certainty: linter_format_1.LintingRuleCertainty.BestEffort,
|
|
332
|
-
description: '
|
|
332
|
+
description: 'Finds arguments of critical system, evaluation, database, and HTML/JavaScript calls that are not properly escaped.',
|
|
333
333
|
defaultConfig: () => ({
|
|
334
334
|
categories: {
|
|
335
335
|
[UnescapedArgumentCategory.System]: {
|
|
@@ -38,7 +38,7 @@ export declare const UNUSED_DEFINITION: {
|
|
|
38
38
|
};
|
|
39
39
|
readonly info: {
|
|
40
40
|
readonly name: "Unused Definitions";
|
|
41
|
-
readonly description: "
|
|
41
|
+
readonly description: "Finds definitions that are never used.";
|
|
42
42
|
readonly tags: readonly [LintingRuleTag.Readability, LintingRuleTag.Smell, LintingRuleTag.QuickFix];
|
|
43
43
|
readonly certainty: LintingRuleCertainty.BestEffort;
|
|
44
44
|
readonly defaultConfig: () => {
|
|
@@ -27,6 +27,8 @@ const r_parameter_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-paramet
|
|
|
27
27
|
const r_expression_list_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
|
|
28
28
|
const r_argument_1 = require("../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
29
29
|
const df_helper_1 = require("../../dataflow/graph/df-helper");
|
|
30
|
+
const resolve_helper_1 = require("../../dataflow/environments/resolve-helper");
|
|
31
|
+
const r_value_1 = require("../../dataflow/eval/values/r-value");
|
|
30
32
|
/**
|
|
31
33
|
* The dots parameter is a special parameter and must never be reported as an unused definition.
|
|
32
34
|
*/
|
|
@@ -242,6 +244,23 @@ function isWithinPromise(node, idMap) {
|
|
|
242
244
|
}
|
|
243
245
|
return false;
|
|
244
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Whether `node` writes into a parameter (`output$plot <- ...` in a Shiny server) that may hold an environment, so the
|
|
249
|
+
* caller sees the write. It may unless every call in the code passes a value flowR resolves, which is never an environment.
|
|
250
|
+
*/
|
|
251
|
+
function mayWriteIntoCallerObject(node, graph, idMap, ctx) {
|
|
252
|
+
if (node.info.role !== "acc" /* RoleInParent.Accessed */) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
const environment = ctx.env.makeCleanEnv();
|
|
256
|
+
return df_helper_1.Dataflow.targetsOf(graph, node.info.id, edge_1.EdgeType.Reads).some(param => {
|
|
257
|
+
if (idMap.get(param)?.info.role !== "param-n" /* RoleInParent.ParameterName */) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
const handed = df_helper_1.Dataflow.targetsOf(graph, param, edge_1.EdgeType.DefinedByOnCall);
|
|
261
|
+
return handed.length === 0 || handed.some(arg => (0, r_value_1.isTop)(resolve_helper_1.Resolve.toValue(arg, { graph, idMap, environment, ctx })));
|
|
262
|
+
});
|
|
263
|
+
}
|
|
245
264
|
exports.UNUSED_DEFINITION = {
|
|
246
265
|
createSearch: config => flowr_search_builder_1.Q.all().filter(config.includeFunctionDefinitions ? flowr_search_filters_1.F.or(vertex_1.VertexType.VariableDefinition, vertex_1.VertexType.FunctionDefinition) : vertex_1.VertexType.VariableDefinition),
|
|
247
266
|
processSearchResult: async (elements, config, data) => {
|
|
@@ -263,7 +282,7 @@ exports.UNUSED_DEFINITION = {
|
|
|
263
282
|
if (!vertex || (!vertex_1.DfgVertex.isVariableDefinition(vertex) && vertex_1.DfgVertex.isFunctionDefinition(vertex) && !config.includeFunctionDefinitions)) {
|
|
264
283
|
return false;
|
|
265
284
|
}
|
|
266
|
-
if (s3GenericParams.has(node.info.id)) {
|
|
285
|
+
if (s3GenericParams.has(node.info.id) || mayWriteIntoCallerObject(node, graph, normalize.idMap, ctx)) {
|
|
267
286
|
return false;
|
|
268
287
|
}
|
|
269
288
|
// an anonymous dispatcher passed to setGeneric()/new_generic() runs on every dispatch, so it is used
|
|
@@ -304,7 +323,7 @@ exports.UNUSED_DEFINITION = {
|
|
|
304
323
|
},
|
|
305
324
|
info: {
|
|
306
325
|
name: 'Unused Definitions',
|
|
307
|
-
description: '
|
|
326
|
+
description: 'Finds definitions that are never used.',
|
|
308
327
|
tags: [linter_tags_1.LintingRuleTag.Readability, linter_tags_1.LintingRuleTag.Smell, linter_tags_1.LintingRuleTag.QuickFix],
|
|
309
328
|
// our limited analysis causes unused definitions involving complex reflection etc. not to be included in our result, but unused definitions are correctly validated
|
|
310
329
|
certainty: linter_format_1.LintingRuleCertainty.BestEffort,
|
|
@@ -55,7 +55,7 @@ export declare const UNUSED_IMPORT: {
|
|
|
55
55
|
readonly name: "Unused Import";
|
|
56
56
|
readonly tags: readonly [LintingRuleTag.Smell, LintingRuleTag.Readability, LintingRuleTag.QuickFix];
|
|
57
57
|
readonly certainty: LintingRuleCertainty.BestEffort;
|
|
58
|
-
readonly description: "
|
|
58
|
+
readonly description: "Finds packages that are attached but never used, so the code runs just the same without them. Requires a signature database, and packages that only do their work on load should be whitelisted in the configuration.";
|
|
59
59
|
readonly defaultConfig: () => {
|
|
60
60
|
whitelist: never[];
|
|
61
61
|
};
|
|
@@ -161,7 +161,7 @@ exports.UNUSED_IMPORT = {
|
|
|
161
161
|
name: 'Unused Import',
|
|
162
162
|
tags: [linter_tags_1.LintingRuleTag.Smell, linter_tags_1.LintingRuleTag.Readability, linter_tags_1.LintingRuleTag.QuickFix],
|
|
163
163
|
certainty: linter_format_1.LintingRuleCertainty.BestEffort,
|
|
164
|
-
description: '
|
|
164
|
+
description: 'Finds packages that are attached but never used, so the code runs just the same without them. Requires a signature database, and packages that only do their work on load should be whitelisted in the configuration.',
|
|
165
165
|
defaultConfig: () => ({
|
|
166
166
|
whitelist: []
|
|
167
167
|
})
|
|
@@ -31,7 +31,7 @@ export declare const USELESS_LOOP: {
|
|
|
31
31
|
};
|
|
32
32
|
readonly info: {
|
|
33
33
|
readonly name: "Useless Loops";
|
|
34
|
-
readonly description: "
|
|
34
|
+
readonly description: "Finds loops that iterate only once.";
|
|
35
35
|
readonly certainty: LintingRuleCertainty.BestEffort;
|
|
36
36
|
readonly tags: readonly [LintingRuleTag.Smell, LintingRuleTag.Readability];
|
|
37
37
|
readonly defaultConfig: () => {
|
|
@@ -38,7 +38,7 @@ exports.USELESS_LOOP = {
|
|
|
38
38
|
},
|
|
39
39
|
info: {
|
|
40
40
|
name: 'Useless Loops',
|
|
41
|
-
description: '
|
|
41
|
+
description: 'Finds loops that iterate only once.',
|
|
42
42
|
certainty: linter_format_1.LintingRuleCertainty.BestEffort,
|
|
43
43
|
tags: [linter_tags_1.LintingRuleTag.Smell, linter_tags_1.LintingRuleTag.Readability],
|
|
44
44
|
defaultConfig: () => ({
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@ export interface ReadOnlyFlowrAnalyzerEnvironmentContext {
|
|
|
16
16
|
*/
|
|
17
17
|
get builtInEnvironment(): DeepReadonly<IEnvironment>;
|
|
18
18
|
/**
|
|
19
|
-
* Every built-in definition flowR carries for `name
|
|
19
|
+
* Every built-in definition flowR carries for `name`: what its namespace states when it names one, else matched by its plain name.
|
|
20
20
|
*/
|
|
21
21
|
builtInDefinitionsOf(name: Identifier): readonly IdentifierDefinition[];
|
|
22
22
|
/**
|
|
@@ -85,7 +85,8 @@ class FlowrAnalyzerEnvironmentContext {
|
|
|
85
85
|
return this.emptyBuiltInEnv;
|
|
86
86
|
}
|
|
87
87
|
builtInDefinitionsOf(name) {
|
|
88
|
-
|
|
88
|
+
const namespaced = identifier_1.Identifier.getNamespace(name) === undefined ? undefined : this.statedDefinitionsOf(name);
|
|
89
|
+
return namespaced ?? this.builtInEnv.memory.get(identifier_1.Identifier.getName(name)) ?? this.statedDefinitionsOf(name) ?? [];
|
|
89
90
|
}
|
|
90
91
|
knowsPackage(pkg) {
|
|
91
92
|
if (this.knownPackages === undefined) {
|
|
@@ -251,9 +251,9 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
|
|
|
251
251
|
this.inlineFiles.push(f);
|
|
252
252
|
}
|
|
253
253
|
else {
|
|
254
|
-
const exist = this.files.get(f.path());
|
|
254
|
+
const exist = this.files.get(files_1.RPath.of(f.path()));
|
|
255
255
|
(0, assert_1.guard)(exist === undefined || exist === f, `File ${f.path()} already added to the context.`);
|
|
256
|
-
this.files.set(f.path(), f);
|
|
256
|
+
this.files.set(files_1.RPath.of(f.path()), f);
|
|
257
257
|
this.caseIndex = undefined;
|
|
258
258
|
}
|
|
259
259
|
if (f.roles) {
|
|
@@ -265,7 +265,7 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
|
|
|
265
265
|
return f;
|
|
266
266
|
}
|
|
267
267
|
hasCached(path) {
|
|
268
|
-
return this.files.has(path);
|
|
268
|
+
return this.files.has(files_1.RPath.of(path));
|
|
269
269
|
}
|
|
270
270
|
hasFile(path) {
|
|
271
271
|
return this.hasCached(path) || (this.ctx.config.project.resolveUnknownPathsOnDisk && onDisk(path));
|
|
@@ -273,14 +273,15 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
|
|
|
273
273
|
fileIndex() {
|
|
274
274
|
if (this.caseIndex === undefined) {
|
|
275
275
|
const index = new Map();
|
|
276
|
-
for (const
|
|
277
|
-
const
|
|
276
|
+
for (const file of this.files.values()) {
|
|
277
|
+
const f = file.path();
|
|
278
|
+
const dir = files_1.RPath.dirname(f).toLowerCase();
|
|
278
279
|
let entries = index.get(dir);
|
|
279
280
|
if (entries === undefined) {
|
|
280
281
|
entries = new Map();
|
|
281
282
|
index.set(dir, entries);
|
|
282
283
|
}
|
|
283
|
-
const base =
|
|
284
|
+
const base = files_1.RPath.basename(f).toLowerCase();
|
|
284
285
|
if (!entries.has(base)) {
|
|
285
286
|
entries.set(base, f);
|
|
286
287
|
}
|
|
@@ -314,14 +315,14 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
|
|
|
314
315
|
if (this.hasFile(p)) {
|
|
315
316
|
return p;
|
|
316
317
|
}
|
|
317
|
-
const
|
|
318
|
-
const file = path_1.default.basename(p).toLowerCase();
|
|
318
|
+
const file = files_1.RPath.basename(p).toLowerCase();
|
|
319
319
|
// try to find in local known files first
|
|
320
|
-
const known = this.fileIndex().get(
|
|
320
|
+
const known = this.fileIndex().get(files_1.RPath.dirname(p).toLowerCase())?.get(file);
|
|
321
321
|
if (known !== undefined) {
|
|
322
322
|
return known;
|
|
323
323
|
}
|
|
324
324
|
if (this.ctx.config.project.resolveUnknownPathsOnDisk) {
|
|
325
|
+
const dir = path_1.default.dirname(p);
|
|
325
326
|
let realDir = dir;
|
|
326
327
|
let files = this.readdir(dir);
|
|
327
328
|
if (files === undefined) {
|
|
@@ -366,7 +367,7 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
|
|
|
366
367
|
}
|
|
367
368
|
/** Resolve the file at `path`, loading it from disk through the {@link FlowrAnalyzerFilePlugin}s if unknown. */
|
|
368
369
|
resolveFile(path) {
|
|
369
|
-
const file = this.files.get(path);
|
|
370
|
+
const file = this.files.get(files_1.RPath.of(path));
|
|
370
371
|
if (file !== undefined && file !== null) {
|
|
371
372
|
return file;
|
|
372
373
|
}
|
|
@@ -430,7 +431,7 @@ class FlowrAnalyzerFilesContext extends abstract_flowr_analyzer_context_1.Abstra
|
|
|
430
431
|
return [...this.files.values(), ...this.inlineFiles];
|
|
431
432
|
}
|
|
432
433
|
getFileByPath(path) {
|
|
433
|
-
return this.files.get(path) ?? this.inlineFiles.find(f => f.path() === path);
|
|
434
|
+
return this.files.get(files_1.RPath.of(path)) ?? this.inlineFiles.find(f => f.path() === path);
|
|
434
435
|
}
|
|
435
436
|
getFileCount() {
|
|
436
437
|
return this.files.size + this.inlineFiles.length;
|
|
@@ -269,11 +269,6 @@ function collectOrphanUsage(graph, deps, usage, isKnown, options = {}) {
|
|
|
269
269
|
continue;
|
|
270
270
|
}
|
|
271
271
|
const name = identifier_1.Identifier.getName(vertex.name);
|
|
272
|
-
// a call bound to a real definition (local, parameter, closure, or import) *is* that definition, not a package
|
|
273
|
-
// export; only an unresolved or builtin-modeled call can be an orphan (flowR models e.g. `ggplot` as a builtin)
|
|
274
|
-
if (df_helper_1.Dataflow.origin(graph, id)?.some(o => o.type === 2 /* OriginType.FunctionCallOrigin */) === true) {
|
|
275
|
-
continue;
|
|
276
|
-
}
|
|
277
272
|
// a bare name from a default-attached base package (or a base primitive) is defined without a library() call
|
|
278
273
|
const baseOwner = (0, r_base_packages_1.baseRExportOwner)(name);
|
|
279
274
|
if (baseOwner !== undefined && r_base_packages_1.AttachedBasePackages.includes(baseOwner)) {
|
|
@@ -295,7 +290,10 @@ function collectOrphanUsage(graph, deps, usage, isKnown, options = {}) {
|
|
|
295
290
|
const pkg = builtin ? mapped
|
|
296
291
|
: known.length === 1 ? known[0]
|
|
297
292
|
: known.length === 0 && providers.length > 0 && providers.length <= MaxOrphanProviders ? providers[0] : undefined;
|
|
298
|
-
|
|
293
|
+
// a call bound to a real definition (local, parameter, closure, or import) *is* that definition, not a package
|
|
294
|
+
// export; only an unresolved or builtin-modeled call can be an orphan (flowR models e.g. `ggplot` as a builtin).
|
|
295
|
+
// Resolving the call is what costs, so the cheaper checks above go first
|
|
296
|
+
if (pkg === undefined || df_helper_1.Dataflow.origin(graph, id)?.some(o => o.type === 2 /* OriginType.FunctionCallOrigin */) === true) {
|
|
299
297
|
continue;
|
|
300
298
|
}
|
|
301
299
|
recordCallUsage(atKey(usage, pkg, () => new Map()), name, vertex.args, id);
|
|
@@ -93,3 +93,5 @@ export declare function restoreBlocksWithoutMd(blocks: readonly CodeBlock[], tot
|
|
|
93
93
|
* Parses the options of an R code block from its header and content
|
|
94
94
|
*/
|
|
95
95
|
export declare function parseCodeBlockOptions(header: string, content: string): CodeBlockOptions;
|
|
96
|
+
/** The `#|` lines that open a code block, which state its options rather than code */
|
|
97
|
+
export declare function cellOptionLines(content: string): string[];
|
|
@@ -8,6 +8,7 @@ exports.parseRMarkdownFile = parseRMarkdownFile;
|
|
|
8
8
|
exports.isRCodeBlock = isRCodeBlock;
|
|
9
9
|
exports.restoreBlocksWithoutMd = restoreBlocksWithoutMd;
|
|
10
10
|
exports.parseCodeBlockOptions = parseCodeBlockOptions;
|
|
11
|
+
exports.cellOptionLines = cellOptionLines;
|
|
11
12
|
const flowr_file_1 = require("../../../context/flowr-file");
|
|
12
13
|
const assert_1 = require("../../../../util/assert");
|
|
13
14
|
const commonmark_1 = require("commonmark");
|
|
@@ -273,16 +274,16 @@ function parseCodeBlockOptions(header, content) {
|
|
|
273
274
|
const headerOpts = header.length === 3 // '{r}' => header.length=3 (no options in header)
|
|
274
275
|
? ''
|
|
275
276
|
: header.slice(3, -1).trim();
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if (!line.trim().startsWith('#|')) {
|
|
279
|
-
break;
|
|
280
|
-
}
|
|
281
|
-
// keep the indentation, yaml block scalars rely on it
|
|
282
|
-
cellLines.push(line.trim().slice(2).replace(/^ /, ''));
|
|
283
|
-
}
|
|
277
|
+
// keep the indentation, yaml block scalars rely on it
|
|
278
|
+
const cellLines = cellOptionLines(content).map(line => line.trim().slice(2).replace(/^ /, ''));
|
|
284
279
|
return new Map([...parseOptionString(headerOpts), ...parseCellOptions(cellLines)]);
|
|
285
280
|
}
|
|
281
|
+
/** The `#|` lines that open a code block, which state its options rather than code */
|
|
282
|
+
function cellOptionLines(content) {
|
|
283
|
+
const lines = content.split('\n');
|
|
284
|
+
const code = lines.findIndex(line => !line.trim().startsWith('#|'));
|
|
285
|
+
return lines.slice(0, code < 0 ? lines.length : code);
|
|
286
|
+
}
|
|
286
287
|
/** Parses knitr's `key=value` option syntax as used in the chunk header */
|
|
287
288
|
function parseOptionString(opts) {
|
|
288
289
|
const parsedOptions = new Map();
|
|
@@ -4,7 +4,7 @@ exports.FlowrAnalyzerMetaTestFilesPlugin = void 0;
|
|
|
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 TestPathPattern = /tests
|
|
7
|
+
const TestPathPattern = /(^|\/)tests?(\/|$)/i;
|
|
8
8
|
/**
|
|
9
9
|
* This plugin provides supports for the identification of test files.
|
|
10
10
|
* If you use multiple plugins, this should be included *before* other plugins.
|
|
@@ -4,7 +4,7 @@ exports.FlowrAnalyzerMetaVignetteFilesPlugin = void 0;
|
|
|
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 VignettePathPattern = /vignettes
|
|
7
|
+
const VignettePathPattern = /(^|\/)vignettes?(\/|$)/i;
|
|
8
8
|
/**
|
|
9
9
|
* This plugin provides supports for the loading of Vignette files.
|
|
10
10
|
* If you use multiple plugins, this should be included *before* other plugins.
|
|
@@ -31,6 +31,8 @@ export declare function argumentRoles(dataflow: DataflowInformation, call: Dataf
|
|
|
31
31
|
* `filter(df, x > 1)`), or a use that only names a function.
|
|
32
32
|
*/
|
|
33
33
|
export declare function inputVariablesOf(dataflow: DataflowInformation, ast: NormalizedAst, call: DataflowGraphVertexFunctionCall, memo?: FlowMemo): string[];
|
|
34
|
+
/** The variables the value `id` is computed from: those of {@link inputVariablesOf} for a call, the variable itself for a use. */
|
|
35
|
+
export declare function inputVariablesAt(dataflow: DataflowInformation, ast: NormalizedAst, id: NodeId, memo?: FlowMemo): string[];
|
|
34
36
|
/**
|
|
35
37
|
* The arguments the call hands on as its own result: the {@link ArgProp.Alias} one of its signature (`(x)`, a pipe
|
|
36
38
|
* into a call), or both operands of a `+` that adds to a plot, as ggplot's method for it returns the plot.
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.makeFlowMemo = makeFlowMemo;
|
|
4
4
|
exports.argumentRoles = argumentRoles;
|
|
5
5
|
exports.inputVariablesOf = inputVariablesOf;
|
|
6
|
+
exports.inputVariablesAt = inputVariablesAt;
|
|
6
7
|
exports.handedOn = handedOn;
|
|
7
8
|
exports.assignmentOf = assignmentOf;
|
|
8
9
|
const vertex_1 = require("../../../dataflow/graph/vertex");
|
|
@@ -121,6 +122,11 @@ function inputVariablesOf(dataflow, ast, call, memo) {
|
|
|
121
122
|
}
|
|
122
123
|
return [...into];
|
|
123
124
|
}
|
|
125
|
+
/** The variables the value `id` is computed from: those of {@link inputVariablesOf} for a call, the variable itself for a use. */
|
|
126
|
+
function inputVariablesAt(dataflow, ast, id, memo) {
|
|
127
|
+
const vertex = dataflow.graph.getVertex(id);
|
|
128
|
+
return vertex_1.DfgVertex.isFunctionCall(vertex) ? inputVariablesOf(dataflow, ast, vertex, memo) : [...variablesOf(dataflow, ast, id, new Set(), memo)];
|
|
129
|
+
}
|
|
124
130
|
function targetOf(dataflow, assignment, value) {
|
|
125
131
|
return dataflow.graph.edgesFrom(assignment.id).entries()
|
|
126
132
|
.find(([to, edge]) => to !== value && edge_1.DfEdge.includesType(edge, edge_1.EdgeType.Returns) && vertex_1.DfgVertex.isVariableDefinition(dataflow.graph.getVertex(to)))?.[0];
|
|
@@ -24,6 +24,7 @@ const data_flow_1 = require("./data-flow");
|
|
|
24
24
|
const match_args_1 = require("../../../dataflow/graph/match-args");
|
|
25
25
|
const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
26
26
|
const r_argument_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
27
|
+
const r_function_definition_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-definition");
|
|
27
28
|
const r_base_packages_1 = require("../../../util/r-base-packages");
|
|
28
29
|
/**
|
|
29
30
|
* Executes a dependencies query.
|
|
@@ -81,6 +82,11 @@ async function executeDependenciesQuery({ analyzer, }, queries) {
|
|
|
81
82
|
(0, plot_description_1.describePlots)(results.write ?? [], results.visualize, run, ctx);
|
|
82
83
|
inheritPlotInputs(results.visualize);
|
|
83
84
|
}
|
|
85
|
+
for (const [category, found] of Object.entries(results)) {
|
|
86
|
+
if (found !== undefined && !NotPassedOnByCalls.has(category)) {
|
|
87
|
+
results[category] = [...found, ...callSitesOf(found, dataflow.graph, normalize)];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
84
90
|
if (query.assumedPackages && (enabled === undefined || enabled.includes('library'))) {
|
|
85
91
|
const explicit = new Set((results.library ?? []).map(r => r.value).filter((v) => v !== undefined && v !== dependencies_query_format_1.Unknown && v !== dependencies_query_format_1.Constant));
|
|
86
92
|
const assumed = assumedBasePackageEntries(dataflow.graph, ctx.resolvedRVersion, explicit);
|
|
@@ -95,6 +101,31 @@ async function executeDependenciesQuery({ analyzer, }, queries) {
|
|
|
95
101
|
...results,
|
|
96
102
|
};
|
|
97
103
|
}
|
|
104
|
+
/** what a call of a function does not do itself: loading a package or a script there is still what the function does */
|
|
105
|
+
const NotPassedOnByCalls = new Set(['library', 'source', 'remote']);
|
|
106
|
+
/**
|
|
107
|
+
* The calls of the program's functions that do what the entries within their bodies do, transitively: a call of `report()`
|
|
108
|
+
* writes what the `cat()` in its body writes, and so does every call of a function that calls `report()`.
|
|
109
|
+
*/
|
|
110
|
+
function callSitesOf(found, graph, ast) {
|
|
111
|
+
const added = [];
|
|
112
|
+
const known = new Set(found.map(f => f.nodeId));
|
|
113
|
+
const queue = [...found];
|
|
114
|
+
for (let entry = queue.shift(); entry !== undefined; entry = queue.shift()) {
|
|
115
|
+
const definition = entry.nodeId === undefined ? undefined : model_1.RNode.findEnclosing(entry.nodeId, ast.idMap, r_function_definition_1.RFunctionDefinition.is);
|
|
116
|
+
for (const call of definition === undefined ? [] : df_helper_1.Dataflow.sourcesOf(graph, definition, edge_1.EdgeType.Calls)) {
|
|
117
|
+
const vertex = graph.getVertex(call);
|
|
118
|
+
if (!vertex_1.DfgVertex.isFunctionCall(vertex) || known.has(call)) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
known.add(call);
|
|
122
|
+
const site = { functionName: vertex.name ?? entry.functionName, nodeId: call, via: entry.nodeId, ...entry.value === undefined ? {} : { value: entry.value } };
|
|
123
|
+
added.push(site);
|
|
124
|
+
queue.push(site);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return added;
|
|
128
|
+
}
|
|
98
129
|
/** whether the call may reach a function definition of the code, whose formals differ from call to call */
|
|
99
130
|
function callsDefinition(dfg, id) {
|
|
100
131
|
for (const [target, edge] of dfg.edgesFrom(id)) {
|
|
@@ -67,6 +67,11 @@ export interface DependencyInfo extends Record<string, unknown> {
|
|
|
67
67
|
/** the called name; an {@link Identifier}, so a namespaced call like `maps::map` keeps its package */
|
|
68
68
|
functionName: Identifier;
|
|
69
69
|
linkedIds?: readonly NodeId[];
|
|
70
|
+
/**
|
|
71
|
+
* Set on a call of a function of the program that does what this entry reports, transitively: the call of
|
|
72
|
+
* `report()` writes what the `cat()` in its body writes. It names the entry within the called function.
|
|
73
|
+
*/
|
|
74
|
+
via?: NodeId;
|
|
70
75
|
/**
|
|
71
76
|
* The other statements that build this output: for a plot, the addons drawn onto it and, when it lands in a
|
|
72
77
|
* file, the device opener and closer around it. Answers *which statements produce this output* without
|
|
@@ -5,6 +5,7 @@ const function_semantics_1 = require("../../../dataflow/fn/function-semantics");
|
|
|
5
5
|
const identifier_1 = require("../../../dataflow/environments/identifier");
|
|
6
6
|
const model_1 = require("../../../r-bridge/lang-4.x/ast/model/model");
|
|
7
7
|
const type_1 = require("../../../r-bridge/lang-4.x/ast/model/type");
|
|
8
|
+
const r_expression_list_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
|
|
8
9
|
const r_binary_op_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-binary-op");
|
|
9
10
|
const r_function_call_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
10
11
|
const r_argument_1 = require("../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
@@ -15,9 +16,10 @@ const query_fn_props_1 = require("../../../dataflow/environments/query-fn-props"
|
|
|
15
16
|
const built_in_props_1 = require("../../../dataflow/environments/built-in-props");
|
|
16
17
|
const built_in_ambient_state_1 = require("../../../dataflow/internal/process/functions/call/built-in/built-in-ambient-state");
|
|
17
18
|
const plot_objects_1 = require("./plot-objects");
|
|
19
|
+
const data_flow_1 = require("./data-flow");
|
|
18
20
|
const test_functions_1 = require("./function-info/test-functions");
|
|
19
21
|
/** the node whose value R echoes for a statement, `undefined` if the statement yields nothing visible */
|
|
20
|
-
function echoedValue(node, dataflow, invisible) {
|
|
22
|
+
function echoedValue(node, dataflow, invisible, seen = new Set()) {
|
|
21
23
|
switch (node?.type) {
|
|
22
24
|
/* the loops hand back an invisible NULL, and the jumps never hand back anything at all */
|
|
23
25
|
case undefined:
|
|
@@ -30,22 +32,22 @@ function echoedValue(node, dataflow, invisible) {
|
|
|
30
32
|
case type_1.RType.LineDirective:
|
|
31
33
|
return undefined;
|
|
32
34
|
case type_1.RType.FunctionCall: {
|
|
33
|
-
if (callName(node, dataflow, invisible) === undefined) {
|
|
35
|
+
if (callName(node, dataflow, invisible, seen) === undefined) {
|
|
34
36
|
return undefined;
|
|
35
37
|
}
|
|
36
38
|
const handedOn = aliased(node, dataflow, invisible);
|
|
37
|
-
return handedOn === undefined ? node : echoedValue(handedOn, dataflow, invisible);
|
|
39
|
+
return handedOn === undefined ? node : echoedValue(handedOn, dataflow, invisible, seen);
|
|
38
40
|
}
|
|
39
41
|
/* a block hands on the value of its last statement, a `( )` group that of what it holds, visibly:
|
|
40
42
|
which is what makes `(x <- 1)` print what it assigned */
|
|
41
43
|
case type_1.RType.ExpressionList:
|
|
42
44
|
return grouped(node) ? lastStatement(node) ?? node
|
|
43
|
-
: echoedValue(lastStatement(node), dataflow, invisible) ?? (node.children.length === 0 ? node : undefined);
|
|
45
|
+
: echoedValue(lastStatement(node), dataflow, invisible, seen) ?? (node.children.length === 0 ? node : undefined);
|
|
44
46
|
case type_1.RType.Pipe:
|
|
45
|
-
return echoedValue(node.rhs, dataflow, invisible);
|
|
47
|
+
return echoedValue(node.rhs, dataflow, invisible, seen);
|
|
46
48
|
/* whichever branch runs decides; without an `else` a false condition yields an invisible NULL */
|
|
47
49
|
case type_1.RType.IfThenElse:
|
|
48
|
-
return echoedValue(node.then, dataflow, invisible) ?? echoedValue(node.otherwise, dataflow, invisible);
|
|
50
|
+
return echoedValue(node.then, dataflow, invisible, seen) ?? echoedValue(node.otherwise, dataflow, invisible, seen);
|
|
49
51
|
case type_1.RType.BinaryOp:
|
|
50
52
|
return r_binary_op_1.RBinaryOp.getOperatorInfo(node)?.usedAs === 'assignment' ? undefined : node;
|
|
51
53
|
/* a symbol, a constant, an access, a unary operator, or a function definition is printed as it stands */
|
|
@@ -67,8 +69,8 @@ function aliased(node, dataflow, invisible) {
|
|
|
67
69
|
?.findIndex(([, p]) => (p & built_in_props_1.ArgProp.Alias) !== 0) ?? -1;
|
|
68
70
|
const arg = at < 0 ? undefined : node.arguments[at];
|
|
69
71
|
const value = typeof arg === 'object' && r_argument_1.RArgument.is(arg) ? arg.value : undefined;
|
|
70
|
-
/* only a call
|
|
71
|
-
return r_function_call_1.RFunctionCall.is(value) ? value : undefined;
|
|
72
|
+
/* only a call or a block (`local({ ... })`) can be invisible where the one around it is not, a symbol says nothing new */
|
|
73
|
+
return r_function_call_1.RFunctionCall.is(value) || r_expression_list_1.RExpressionList.is(value) ? value : undefined;
|
|
72
74
|
}
|
|
73
75
|
/** the last statement of a block, which is what its value comes from */
|
|
74
76
|
function lastStatement(node) {
|
|
@@ -80,16 +82,30 @@ function lastStatement(node) {
|
|
|
80
82
|
}
|
|
81
83
|
return undefined;
|
|
82
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* The name of the call if its result is visible, `undefined` if it hands it back invisibly. A call that reaches
|
|
87
|
+
* functions of the program is visible exactly when one of their exits yields a visible value, by the same rules as a
|
|
88
|
+
* statement of the top level, whatever a built-in of that name would do; only otherwise its built-in props decide.
|
|
89
|
+
*/
|
|
83
90
|
function callName(node, dataflow, invisible, seen = new Set()) {
|
|
84
91
|
const name = (0, plot_objects_1.callIdentifierOf)(node, dataflow);
|
|
85
|
-
if (name === undefined) {
|
|
92
|
+
if (name === undefined || test_functions_1.ExpectFunctionNames.test(identifier_1.Identifier.getName(name)) || isInvisible(name, invisible)) {
|
|
86
93
|
return undefined;
|
|
87
94
|
}
|
|
95
|
+
const idMap = dataflow.graph.idMap;
|
|
96
|
+
const callees = [...df_helper_1.Dataflow.calleesOf(dataflow.graph, node.info.id)];
|
|
97
|
+
if (callees.length > 0 && idMap !== undefined) {
|
|
98
|
+
/* a recursive call is as visible as the call that started it, which the others decide */
|
|
99
|
+
if (seen.has(node.info.id)) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
seen.add(node.info.id);
|
|
103
|
+
return callees.some(definition => definition.exitPoints.some(exit => echoedValue(idMap.get(exit.nodeId), dataflow, invisible, seen) !== undefined)) ? name : undefined;
|
|
104
|
+
}
|
|
88
105
|
const props = (0, query_fn_props_1.queryFnProps)(name, { environment: dataflow.environment });
|
|
89
106
|
/* a setter hands back the previous state invisibly, but queried, the state is what it returns */
|
|
90
107
|
const hidden = function_semantics_1.FunctionSemantics.call.props.hasAny(props, [built_in_props_1.CallProp.Invisible]) && !(0, built_in_ambient_state_1.callOnlyQueries)(name, node.arguments, dataflow.environment);
|
|
91
|
-
return hidden
|
|
92
|
-
|| (props === undefined && calleesReturnInvisibly(node.info.id, dataflow, invisible, seen)) ? undefined : name;
|
|
108
|
+
return hidden ? undefined : name;
|
|
93
109
|
}
|
|
94
110
|
/** whether the call is to one of the functions stated to return invisibly, unless its package says it is another one */
|
|
95
111
|
function isInvisible(name, invisible) {
|
|
@@ -97,24 +113,6 @@ function isInvisible(name, invisible) {
|
|
|
97
113
|
const ns = identifier_1.Identifier.getNamespace(name);
|
|
98
114
|
return invisible.some(f => f.name === fn && (f.package === undefined || ns === undefined || f.package === ns));
|
|
99
115
|
}
|
|
100
|
-
function calleesReturnInvisibly(id, dataflow, invisible, seen) {
|
|
101
|
-
const idMap = dataflow.graph.idMap;
|
|
102
|
-
if (idMap === undefined || seen.has(id)) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
seen.add(id);
|
|
106
|
-
let callee = false;
|
|
107
|
-
for (const definition of df_helper_1.Dataflow.calleesOf(dataflow.graph, id)) {
|
|
108
|
-
callee = true;
|
|
109
|
-
for (const exit of definition.exitPoints) {
|
|
110
|
-
const last = idMap.get(exit.nodeId);
|
|
111
|
-
if (!r_function_call_1.RFunctionCall.is(last) || callName(last, dataflow, invisible, seen) !== undefined) {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return callee;
|
|
117
|
-
}
|
|
118
116
|
/** what to report the echo under: the called name, or the operator or lexeme producing the value */
|
|
119
117
|
function echoName(node, dataflow) {
|
|
120
118
|
switch (node.type) {
|
|
@@ -148,7 +146,8 @@ function collectImplicitEchoes(ast, dataflow, accountedFor, invisible, result) {
|
|
|
148
146
|
if (echoed === undefined || accountedFor.has(echoed.info.id) || (0, plot_objects_1.isPlot)(echoed, dataflow)) {
|
|
149
147
|
continue;
|
|
150
148
|
}
|
|
151
|
-
|
|
149
|
+
const inputs = (0, data_flow_1.inputVariablesAt)(dataflow, ast, echoed.info.id);
|
|
150
|
+
result.push({ nodeId: echoed.info.id, functionName: echoName(echoed, dataflow), value: 'stdout', implicit: true, inputVariables: inputs.length > 0 ? inputs : undefined });
|
|
152
151
|
}
|
|
153
152
|
}
|
|
154
153
|
}
|
|
@@ -55,7 +55,11 @@ function isPlotNode(node, dataflow, seen, memo) {
|
|
|
55
55
|
/** whether the node calls one of the given graphics functions */
|
|
56
56
|
function isPlotCall(node, dataflow, among) {
|
|
57
57
|
const name = r_function_call_1.RFunctionCall.is(node) ? callIdentifierOf(node, dataflow) : undefined;
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
if (name === undefined || !among.has(identifier_1.Identifier.getName(name))) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
/* without its package loaded, flowR knows nothing of `ggplot`, which still draws as its name says, unless the code defines its own */
|
|
62
|
+
const props = (0, query_fn_props_1.queryFnProps)(name, { environment: dataflow.environment });
|
|
63
|
+
return props === undefined ? [...df_helper_1.Dataflow.calleesOf(dataflow.graph, node.info.id)].length === 0 : function_semantics_1.FunctionSemantics.call.props.hasAny(props, [built_in_props_1.SemanticCallTag.Graphics]);
|
|
60
64
|
}
|
|
61
65
|
//# sourceMappingURL=plot-objects.js.map
|