@eagleoutice/flowr 2.10.10 → 2.11.1
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 +35 -27
- package/cli/common/options.d.ts +2 -108
- package/cli/common/options.js +3 -27
- package/cli/common/scripts-info.d.ts +2 -123
- package/cli/common/scripts-info.js +0 -17
- package/cli/flowr-main-options.d.ts +5 -0
- package/cli/flowr-main-options.js +10 -0
- package/cli/flowr.js +2 -2
- package/cli/repl/commands/repl-commands.js +7 -6
- package/cli/repl/print-version.d.ts +3 -1
- package/cli/repl/print-version.js +21 -2
- package/cli/repl/server/connection.d.ts +2 -0
- package/cli/repl/server/connection.js +40 -31
- package/cli/script-core/summarizer-core.js +13 -32
- package/cli/wiki.d.ts +2 -1
- package/cli/wiki.js +2 -0
- package/config.d.ts +9 -0
- package/config.js +10 -0
- package/control-flow/semantic-cfg-guided-visitor.js +1 -0
- package/core/steps/pipeline/default-pipelines.d.ts +146 -146
- package/data/pkgdb/pkgdb-latest.json.br +0 -0
- package/data/pkgdb/pkgdb-tiny.json.br +0 -0
- package/dataflow/environments/append.d.ts +1 -2
- package/dataflow/environments/append.js +3 -10
- package/dataflow/environments/apply-kill.d.ts +21 -0
- package/dataflow/environments/apply-kill.js +155 -0
- package/dataflow/environments/built-in-proc-name.d.ts +2 -0
- package/dataflow/environments/built-in-proc-name.js +2 -0
- package/dataflow/environments/built-in.d.ts +2 -0
- package/dataflow/environments/built-in.js +2 -0
- package/dataflow/environments/default-builtin-config.d.ts +63 -3
- package/dataflow/environments/default-builtin-config.js +40 -8
- package/dataflow/environments/environment.d.ts +49 -32
- package/dataflow/environments/environment.js +133 -18
- package/dataflow/environments/identifier.d.ts +10 -0
- package/dataflow/environments/identifier.js +23 -0
- package/dataflow/environments/overwrite.js +2 -10
- package/dataflow/environments/resolve-by-name.d.ts +1 -1
- package/dataflow/environments/resolve-by-name.js +10 -2
- package/dataflow/environments/scoping.d.ts +9 -2
- package/dataflow/environments/scoping.js +15 -2
- package/dataflow/extractor.js +23 -2
- package/dataflow/graph/df-helper.d.ts +8 -0
- package/dataflow/graph/df-helper.js +8 -0
- package/dataflow/graph/graph.d.ts +4 -1
- package/dataflow/graph/graph.js +5 -1
- package/dataflow/info.d.ts +26 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-access.js +7 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +19 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +1 -8
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +7 -13
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +9 -48
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +30 -47
- package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +17 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +6 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.d.ts +2 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-function-definition.js +8 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +9 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-library.d.ts +37 -3
- package/dataflow/internal/process/functions/call/built-in/built-in-library.js +391 -21
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.d.ts +2 -1
- package/dataflow/internal/process/functions/call/built-in/built-in-rm.js +131 -48
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.d.ts +25 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-stack-env.js +94 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +10 -3
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.d.ts +30 -0
- package/dataflow/internal/process/functions/call/built-in/transitive-side-effects.js +279 -0
- package/dataflow/internal/process/functions/call/named-call-handling.d.ts +1 -1
- package/dataflow/internal/process/functions/call/named-call-handling.js +17 -0
- package/documentation/data/faq/faqs.js +3 -0
- package/documentation/data/interface/doc-writing-code.js +4 -80
- package/documentation/doc-util/doc-structure.js +1 -2
- package/documentation/wiki-core.js +2 -1
- package/documentation/wiki-dataflow-graph.js +35 -1
- package/documentation/wiki-interface.js +2 -2
- package/documentation/wiki-linter.js +2 -0
- package/documentation/wiki-overview.js +1 -14
- package/documentation/wiki-package-database.d.ts +9 -0
- package/documentation/wiki-package-database.js +63 -0
- package/documentation/wiki-query.js +1 -0
- package/linter/linter-rules.d.ts +23 -0
- package/linter/linter-rules.js +3 -1
- package/linter/rules/absolute-path.js +2 -1
- package/linter/rules/undefined-symbol.d.ts +39 -0
- package/linter/rules/undefined-symbol.js +80 -0
- package/package.json +4 -4
- package/project/cache/flowr-analyzer-cache.d.ts +2 -0
- package/project/cache/flowr-analyzer-cache.js +9 -1
- package/project/context/flowr-analyzer-dependencies-context.d.ts +16 -8
- package/project/context/flowr-analyzer-dependencies-context.js +39 -4
- package/project/context/flowr-analyzer-environment-context.d.ts +2 -4
- package/project/context/flowr-analyzer-environment-context.js +3 -4
- package/project/context/flowr-analyzer-files-context.d.ts +1 -0
- package/project/context/flowr-file.d.ts +2 -0
- package/project/context/flowr-file.js +2 -0
- package/project/flowr-analyzer-builder.js +3 -0
- package/project/flowr-analyzer.d.ts +2 -1
- package/project/flowr-analyzer.js +3 -1
- package/project/plugins/file-plugins/files/flowr-namespace-file.d.ts +13 -15
- package/project/plugins/file-plugins/files/flowr-namespace-file.js +36 -13
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.d.ts +27 -0
- package/project/plugins/file-plugins/flowr-analyzer-virtualenv-file-plugin.js +41 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.d.ts +18 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-lockfile-plugin.js +62 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.d.ts +63 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-pkgdb-plugin.js +176 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.d.ts +10 -0
- package/project/plugins/package-version-plugins/flowr-analyzer-package-versions-plugin.js +6 -0
- package/project/plugins/package-version-plugins/package.d.ts +3 -0
- package/project/plugins/package-version-plugins/package.js +12 -0
- package/project/plugins/package-version-plugins/pkgdb.d.ts +133 -0
- package/project/plugins/package-version-plugins/pkgdb.js +370 -0
- package/project/plugins/plugin-registry.d.ts +4 -1
- package/project/plugins/plugin-registry.js +7 -0
- package/queries/catalog/call-context-query/call-context-query-executor.js +8 -0
- package/queries/catalog/call-context-query/call-context-query-format.d.ts +2 -0
- package/queries/catalog/call-context-query/call-context-query-format.js +1 -0
- package/queries/catalog/call-context-query/identify-link-to-last-call-relation.js +8 -0
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +31 -3
- package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +3 -1
- package/queries/catalog/dependencies-query/dependencies-query-format.js +3 -2
- package/queries/catalog/dependencies-query/function-info/function-info.d.ts +1 -1
- package/queries/catalog/dependencies-query/function-info/other-path-functions.d.ts +2 -0
- package/queries/catalog/dependencies-query/function-info/other-path-functions.js +27 -0
- package/queries/catalog/dependencies-query/function-info/read-functions.js +5 -4
- package/queries/catalog/dependencies-query/function-info/visualize-functions.js +3 -1
- package/queries/catalog/linter-query/linter-query-executor.js +1 -0
- package/r-bridge/data/data.d.ts +2 -2
- package/r-bridge/data/data.js +2 -2
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-executor.js +13 -4
- package/search/search-executor/search-enrichers.d.ts +1 -1
- package/search/search-executor/search-enrichers.js +7 -4
- package/util/mermaid/mermaid.d.ts +4 -0
- package/util/mermaid/mermaid.js +8 -1
- package/util/text/ansi.d.ts +10 -1
- package/util/text/ansi.js +17 -4
- package/util/version.js +10 -2
- package/cli/common/features.d.ts +0 -9
- package/cli/common/features.js +0 -35
- package/cli/script-core/statistics-core.d.ts +0 -6
- package/cli/script-core/statistics-core.js +0 -104
- package/cli/script-core/statistics-helper-core.d.ts +0 -6
- package/cli/script-core/statistics-helper-core.js +0 -86
- package/cli/statistics-app.d.ts +0 -11
- package/cli/statistics-app.js +0 -16
- package/cli/statistics-helper-app.d.ts +0 -11
- package/cli/statistics-helper-app.js +0 -14
- package/statistics/features/common-syntax-probability.d.ts +0 -38
- package/statistics/features/common-syntax-probability.js +0 -169
- package/statistics/features/feature.d.ts +0 -179
- package/statistics/features/feature.js +0 -38
- package/statistics/features/post-processing.d.ts +0 -18
- package/statistics/features/post-processing.js +0 -26
- package/statistics/features/supported/assignments/assignments.d.ts +0 -12
- package/statistics/features/supported/assignments/assignments.js +0 -56
- package/statistics/features/supported/assignments/post-process.d.ts +0 -6
- package/statistics/features/supported/assignments/post-process.js +0 -126
- package/statistics/features/supported/comments/comments.d.ts +0 -18
- package/statistics/features/supported/comments/comments.js +0 -143
- package/statistics/features/supported/comments/post-process.d.ts +0 -6
- package/statistics/features/supported/comments/post-process.js +0 -51
- package/statistics/features/supported/control-flow/control-flow.d.ts +0 -17
- package/statistics/features/supported/control-flow/control-flow.js +0 -69
- package/statistics/features/supported/control-flow/post-process.d.ts +0 -6
- package/statistics/features/supported/control-flow/post-process.js +0 -66
- package/statistics/features/supported/data-access/data-access.d.ts +0 -15
- package/statistics/features/supported/data-access/data-access.js +0 -122
- package/statistics/features/supported/data-access/post-process.d.ts +0 -6
- package/statistics/features/supported/data-access/post-process.js +0 -108
- package/statistics/features/supported/defined-functions/defined-functions.d.ts +0 -34
- package/statistics/features/supported/defined-functions/defined-functions.js +0 -145
- package/statistics/features/supported/defined-functions/post-process.d.ts +0 -6
- package/statistics/features/supported/defined-functions/post-process.js +0 -168
- package/statistics/features/supported/expression-list/post-process.d.ts +0 -6
- package/statistics/features/supported/expression-list/post-process.js +0 -45
- package/statistics/features/supported/expression-list/statistics-expression-list.d.ts +0 -9
- package/statistics/features/supported/expression-list/statistics-expression-list.js +0 -37
- package/statistics/features/supported/loops/loops.d.ts +0 -20
- package/statistics/features/supported/loops/loops.js +0 -81
- package/statistics/features/supported/loops/post-process.d.ts +0 -6
- package/statistics/features/supported/loops/post-process.js +0 -73
- package/statistics/features/supported/used-functions/post-process.d.ts +0 -6
- package/statistics/features/supported/used-functions/post-process.js +0 -176
- package/statistics/features/supported/used-functions/used-functions.d.ts +0 -24
- package/statistics/features/supported/used-functions/used-functions.js +0 -99
- package/statistics/features/supported/used-packages/post-process.d.ts +0 -6
- package/statistics/features/supported/used-packages/post-process.js +0 -122
- package/statistics/features/supported/used-packages/used-packages.d.ts +0 -16
- package/statistics/features/supported/used-packages/used-packages.js +0 -140
- package/statistics/features/supported/values/post-process.d.ts +0 -6
- package/statistics/features/supported/values/post-process.js +0 -73
- package/statistics/features/supported/values/values.d.ts +0 -14
- package/statistics/features/supported/values/values.js +0 -111
- package/statistics/features/supported/variables/post-process.d.ts +0 -15
- package/statistics/features/supported/variables/post-process.js +0 -126
- package/statistics/features/supported/variables/variables.d.ts +0 -15
- package/statistics/features/supported/variables/variables.js +0 -62
- package/statistics/meta-statistics.d.ts +0 -32
- package/statistics/meta-statistics.js +0 -16
- package/statistics/output/file-provider.d.ts +0 -36
- package/statistics/output/file-provider.js +0 -96
- package/statistics/output/print-stats.d.ts +0 -29
- package/statistics/output/print-stats.js +0 -81
- package/statistics/output/statistics-file.d.ts +0 -36
- package/statistics/output/statistics-file.js +0 -68
- package/statistics/statistics.d.ts +0 -29
- package/statistics/statistics.js +0 -108
- package/statistics/summarizer/auto-detect.d.ts +0 -5
- package/statistics/summarizer/auto-detect.js +0 -34
- package/statistics/summarizer/first-phase/process.d.ts +0 -6
- package/statistics/summarizer/first-phase/process.js +0 -81
- package/statistics/summarizer/post-process/clusterer.d.ts +0 -25
- package/statistics/summarizer/post-process/clusterer.js +0 -40
- package/statistics/summarizer/post-process/file-based-count.d.ts +0 -16
- package/statistics/summarizer/post-process/file-based-count.js +0 -47
- package/statistics/summarizer/post-process/histogram.d.ts +0 -57
- package/statistics/summarizer/post-process/histogram.js +0 -126
- package/statistics/summarizer/post-process/post-process-output.d.ts +0 -14
- package/statistics/summarizer/post-process/post-process-output.js +0 -102
- package/statistics/summarizer/second-phase/process.d.ts +0 -15
- package/statistics/summarizer/second-phase/process.js +0 -118
- package/statistics/summarizer/summarizer.d.ts +0 -34
- package/statistics/summarizer/summarizer.js +0 -141
|
@@ -1,45 +1,415 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.processLibrary = processLibrary;
|
|
4
|
+
exports.attachExportVertex = attachExportVertex;
|
|
5
|
+
exports.attachDependencyToEnvironment = attachDependencyToEnvironment;
|
|
4
6
|
const known_call_handling_1 = require("../known-call-handling");
|
|
7
|
+
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
8
|
+
const r_access_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-access");
|
|
9
|
+
const r_logical_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-logical");
|
|
10
|
+
const node_id_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
5
11
|
const logger_1 = require("../../../../../logger");
|
|
6
|
-
const unpack_argument_1 = require("../argument/unpack-argument");
|
|
7
12
|
const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
|
|
8
13
|
const make_argument_1 = require("../argument/make-argument");
|
|
9
14
|
const identifier_1 = require("../../../../../environments/identifier");
|
|
10
15
|
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
|
|
16
|
+
const environment_1 = require("../../../../../environments/environment");
|
|
17
|
+
const edge_1 = require("../../../../../graph/edge");
|
|
18
|
+
const assert_1 = require("../../../../../../util/assert");
|
|
19
|
+
const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
20
|
+
const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
|
|
21
|
+
const general_1 = require("../../../../../eval/values/general");
|
|
22
|
+
const package_1 = require("../../../../../../project/plugins/package-version-plugins/package");
|
|
23
|
+
const flowr_namespace_file_1 = require("../../../../../../project/plugins/file-plugins/files/flowr-namespace-file");
|
|
24
|
+
const common_1 = require("../common");
|
|
25
|
+
const linker_1 = require("../../../../linker");
|
|
26
|
+
const vertex_1 = require("../../../../../graph/vertex");
|
|
11
27
|
/**
|
|
12
28
|
* Process a library call like `library` or `require`
|
|
13
29
|
*/
|
|
14
|
-
function processLibrary(name, args, rootId, data) {
|
|
30
|
+
function processLibrary(name, args, rootId, data, config = {}) {
|
|
15
31
|
/* we do not really know what loading the library does and what side effects it causes, hence we mark it as an unknown side effect */
|
|
16
|
-
if (args.length
|
|
17
|
-
logger_1.dataflowLogger.warn(`Currently only one-arg library-likes are allows (for ${identifier_1.Identifier.toString(name.content)}), skipping`);
|
|
32
|
+
if (args.length === 0) {
|
|
18
33
|
return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, hasUnknownSideEffect: true, origin: 'default' }).information;
|
|
19
34
|
}
|
|
20
|
-
|
|
21
|
-
|
|
35
|
+
if (config.boxUse) {
|
|
36
|
+
return processUse(name, args, rootId, data);
|
|
37
|
+
}
|
|
38
|
+
/* parse the import selection before the library flow rewrites `args` below */
|
|
39
|
+
const spec = config.fromImports ? parseFromSpec(args) : { namespaceOnly: config.namespaceOnly };
|
|
40
|
+
const params = {
|
|
41
|
+
'package': 'pkg',
|
|
42
|
+
'character.only': 'char'
|
|
43
|
+
};
|
|
44
|
+
const resolveArgs = { environment: data.environment, idMap: data.completeAst.idMap, resolve: data.ctx.config.solver.variables, ctx: data.ctx };
|
|
45
|
+
const argMaps = (0, linker_1.pMatch)((0, common_1.convertFnArguments)(args), params);
|
|
46
|
+
const packageId = Array.from(new Set(argMaps.get('pkg')));
|
|
47
|
+
const charId = Array.from(new Set(argMaps.get('char')));
|
|
48
|
+
let namesToLoad = packageId.map(v => r_argument_1.RArgument.getValue(args, v));
|
|
49
|
+
//check if library name provided
|
|
50
|
+
namesToLoad = namesToLoad.filter(v => v !== undefined && (v.type === type_1.RType.Symbol || v.type === type_1.RType.String));
|
|
51
|
+
if (namesToLoad.length === 0) {
|
|
22
52
|
logger_1.dataflowLogger.warn('No library name provided, skipping');
|
|
23
53
|
return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, hasUnknownSideEffect: true, origin: 'default' }).information;
|
|
24
54
|
}
|
|
25
|
-
|
|
26
|
-
|
|
55
|
+
for (const nameToLoad of namesToLoad) {
|
|
56
|
+
if (nameToLoad !== undefined && (nameToLoad.type === type_1.RType.Symbol || nameToLoad.type === type_1.RType.String) && identifier_1.Identifier.getNamespace(nameToLoad.type === type_1.RType.String ? nameToLoad.content.str : nameToLoad.content) !== undefined) {
|
|
57
|
+
logger_1.dataflowLogger.warn('Namespaced library names are not supported, ignoring namespace of library: ', nameToLoad);
|
|
58
|
+
}
|
|
27
59
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
60
|
+
let isCharacterOnly = config.characterOnly === true;
|
|
61
|
+
if (!config.characterOnly && charId.length >= 1) {
|
|
62
|
+
const values = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(charId[0], resolveArgs));
|
|
63
|
+
if (values?.type === 'set' && values?.elements.length > 0) {
|
|
64
|
+
let hasTrue = 0;
|
|
65
|
+
let hasFalse = 0;
|
|
66
|
+
let hasMaybe = 0;
|
|
67
|
+
for (const elem of values.elements) {
|
|
68
|
+
if (elem.type === 'logical') {
|
|
69
|
+
switch (elem.value) {
|
|
70
|
+
case true:
|
|
71
|
+
hasTrue++;
|
|
72
|
+
break;
|
|
73
|
+
case false:
|
|
74
|
+
hasFalse++;
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
hasMaybe++;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (hasMaybe > 0) {
|
|
83
|
+
isCharacterOnly = 'maybe';
|
|
84
|
+
}
|
|
85
|
+
else if (hasTrue === 0 && hasFalse > 0) {
|
|
86
|
+
isCharacterOnly = false;
|
|
87
|
+
}
|
|
88
|
+
else if (hasTrue > 0 && hasFalse === 0) {
|
|
89
|
+
isCharacterOnly = true;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
isCharacterOnly = 'maybe';
|
|
93
|
+
}
|
|
37
94
|
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
95
|
+
}
|
|
96
|
+
const packetName = [];
|
|
97
|
+
//case: true or maybe
|
|
98
|
+
if (isCharacterOnly) {
|
|
99
|
+
for (const nameToLoad of namesToLoad) {
|
|
100
|
+
const values = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(nameToLoad.info.id, resolveArgs));
|
|
101
|
+
if (values?.type === 'set' && values.elements.length !== 0) {
|
|
102
|
+
for (const elem of values.elements) {
|
|
103
|
+
if (elem.type === 'string' && 'str' in elem.value) {
|
|
104
|
+
packetName.push(elem.value.str);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (!isCharacterOnly || isCharacterOnly === 'maybe') {
|
|
111
|
+
for (const nameToLoad of namesToLoad) {
|
|
112
|
+
// a quoted literal (`requireNamespace("pkg")`) carries its name in `content.str`, not the quoted `lexeme`
|
|
113
|
+
const packageName = nameToLoad.type === type_1.RType.String ? nameToLoad.content.str : nameToLoad.lexeme;
|
|
114
|
+
if ((0, assert_1.isNotUndefined)(packageName)) {
|
|
115
|
+
packetName.push(packageName);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (!isCharacterOnly || isCharacterOnly === 'maybe') {
|
|
120
|
+
// treat as a function call but convert the first argument to a string
|
|
121
|
+
const newArgs = [];
|
|
122
|
+
for (const nameToLoad of namesToLoad) {
|
|
123
|
+
if (!(nameToLoad.type === type_1.RType.Symbol || nameToLoad.type === type_1.RType.String)) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const newArg = nameToLoad.type === type_1.RType.String ? nameToLoad : {
|
|
127
|
+
type: type_1.RType.String,
|
|
128
|
+
info: nameToLoad.info,
|
|
129
|
+
lexeme: nameToLoad.lexeme,
|
|
130
|
+
location: nameToLoad.location,
|
|
131
|
+
content: {
|
|
132
|
+
quotes: 'none',
|
|
133
|
+
str: identifier_1.Identifier.getName(nameToLoad.content)
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
newArgs.push(newArg);
|
|
137
|
+
}
|
|
138
|
+
args = (0, make_argument_1.wrapArgumentsUnnamed)([...newArgs, ...args.slice(1)], data.completeAst.idMap);
|
|
139
|
+
}
|
|
140
|
+
const info = (0, known_call_handling_1.processKnownFunctionCall)({
|
|
141
|
+
name,
|
|
142
|
+
args, rootId, data,
|
|
143
|
+
hasUnknownSideEffect: false,
|
|
42
144
|
origin: built_in_proc_name_1.BuiltInProcName.Library
|
|
43
145
|
}).information;
|
|
146
|
+
for (const p of packetName) {
|
|
147
|
+
const dependency = data.ctx.deps.getDependency(p);
|
|
148
|
+
if (dependency) {
|
|
149
|
+
linkLibrary(dependency, info, rootId, data, spec);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
info.graph.markIdForUnknownSideEffects(rootId);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (packetName.length === 0) {
|
|
156
|
+
info.graph.markIdForUnknownSideEffects(rootId);
|
|
157
|
+
}
|
|
158
|
+
return info;
|
|
159
|
+
}
|
|
160
|
+
/** The name of a symbol or string literal node, or `undefined` for anything else. */
|
|
161
|
+
function symbolOrStringName(node) {
|
|
162
|
+
if (node?.type === type_1.RType.Symbol) {
|
|
163
|
+
return identifier_1.Identifier.getName(node.content);
|
|
164
|
+
}
|
|
165
|
+
if (node?.type === type_1.RType.String) {
|
|
166
|
+
return node.content.str;
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
/** The string literals of a `"x"` or `c("x", "y")` node (used for `import::from`'s `.except`). */
|
|
171
|
+
function stringLiterals(node) {
|
|
172
|
+
if (node.type === type_1.RType.String) {
|
|
173
|
+
return [node.content.str];
|
|
174
|
+
}
|
|
175
|
+
if (r_function_call_1.RFunctionCall.isNamed(node) && identifier_1.Identifier.getName(node.functionName.content) === 'c') {
|
|
176
|
+
return node.arguments.flatMap(a => a !== r_function_call_1.EmptyArgument && a.value?.type === type_1.RType.String ? [a.value.content.str] : []);
|
|
177
|
+
}
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
/** Parse `import::from(pkg, a, keep = filter, .all = TRUE, .except = c(...))` into which exports to attach. */
|
|
181
|
+
function parseFromSpec(args) {
|
|
182
|
+
const include = new Map();
|
|
183
|
+
const exclude = new Set();
|
|
184
|
+
let all = false;
|
|
185
|
+
for (let i = 1; i < args.length; i++) {
|
|
186
|
+
const arg = args[i];
|
|
187
|
+
if (arg === r_function_call_1.EmptyArgument || arg.value === undefined) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
const argName = arg.name?.lexeme;
|
|
191
|
+
if (argName === '.all') {
|
|
192
|
+
all ||= r_logical_1.RLogical.isTrue(arg.value);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
if (argName === '.except') {
|
|
196
|
+
for (const s of stringLiterals(arg.value)) {
|
|
197
|
+
exclude.add(s);
|
|
198
|
+
}
|
|
199
|
+
all = true;
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (argName?.startsWith('.')) {
|
|
203
|
+
continue; // other control args (.into, .library, ...) do not affect which exports resolve
|
|
204
|
+
}
|
|
205
|
+
const exported = symbolOrStringName(arg.value);
|
|
206
|
+
if (exported !== undefined) {
|
|
207
|
+
include.set(argName ?? exported, exported);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
include: include.size > 0 ? include : undefined,
|
|
212
|
+
exclude: exclude.size > 0 ? exclude : undefined,
|
|
213
|
+
all: all || exclude.size > 0
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/** Parse a `box::use` bracket argument (`pkg[a, b]` or `pkg[...]`) into a package and its attach spec; `undefined` if not a bracket. */
|
|
217
|
+
function parseBoxSpec(first) {
|
|
218
|
+
if (first === undefined || !r_access_1.RAccess.isIndex(first)) {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
const pack = symbolOrStringName(first.accessed);
|
|
222
|
+
if (pack === undefined) {
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
const include = new Map();
|
|
226
|
+
let all = false;
|
|
227
|
+
for (const el of first.access) {
|
|
228
|
+
if (el === r_function_call_1.EmptyArgument || el.value === undefined) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (el.value.type === type_1.RType.Symbol && identifier_1.Identifier.getName(el.value.content) === '...') {
|
|
232
|
+
all = true; // use(pkg[...]) attaches every export
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
const exported = symbolOrStringName(el.value);
|
|
236
|
+
if (exported !== undefined) {
|
|
237
|
+
include.set(el.name?.lexeme ?? exported, exported);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return { pack, spec: { include: include.size > 0 ? include : undefined, all } };
|
|
241
|
+
}
|
|
242
|
+
/** Whether `use` should be read as `box::use` here: a `box::`-qualified call, or `box` is a loaded dependency. */
|
|
243
|
+
function usesBoxSemantics(name, data) {
|
|
244
|
+
if (identifier_1.Identifier.getNamespace(name.content) === "box" /* PkgName.Box */) {
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
return data.ctx.deps.getDependency("box" /* PkgName.Box */) !== undefined;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Process a `use` call, library-sensitively: `pkg[...]` uses box's bracket selection; a bare `pkg` is box's
|
|
251
|
+
* namespace-only member access when box is loaded, otherwise `import::from`-style extra-argument selection.
|
|
252
|
+
*/
|
|
253
|
+
function processUse(name, args, rootId, data) {
|
|
254
|
+
const info = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, hasUnknownSideEffect: false, origin: built_in_proc_name_1.BuiltInProcName.Library }).information;
|
|
255
|
+
const first = args[0] === r_function_call_1.EmptyArgument ? undefined : args[0]?.value;
|
|
256
|
+
const parsed = parseUseSpec(name, first, args, data);
|
|
257
|
+
const dependency = parsed && data.ctx.deps.getDependency(parsed.pack);
|
|
258
|
+
if (parsed && dependency) {
|
|
259
|
+
linkLibrary(dependency, info, rootId, data, parsed.spec);
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
info.graph.markIdForUnknownSideEffects(rootId);
|
|
263
|
+
}
|
|
264
|
+
return info;
|
|
265
|
+
}
|
|
266
|
+
/** The package and attach spec for a `use` call (see {@link processUse}). */
|
|
267
|
+
function parseUseSpec(name, first, args, data) {
|
|
268
|
+
const bracket = parseBoxSpec(first);
|
|
269
|
+
if (bracket !== undefined) {
|
|
270
|
+
return bracket;
|
|
271
|
+
}
|
|
272
|
+
const pack = symbolOrStringName(first);
|
|
273
|
+
if (pack === undefined) {
|
|
274
|
+
return undefined;
|
|
275
|
+
}
|
|
276
|
+
if (usesBoxSemantics(name, data)) {
|
|
277
|
+
return { pack, spec: { namespaceOnly: true } }; // box: use(pkg) is member access via pkg$fn
|
|
278
|
+
}
|
|
279
|
+
return { pack, spec: parseFromSpec(args) }; // extra-argument selection: use(pkg, a, b) / use(pkg)
|
|
280
|
+
}
|
|
281
|
+
/** Materialize the empty built-in function-definition vertex for a package export (idempotent). */
|
|
282
|
+
function attachExportVertex(graph, builtInId, environment, ctx, cds) {
|
|
283
|
+
if (graph.hasVertex(builtInId)) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
graph.addVertex({
|
|
287
|
+
tag: vertex_1.VertexType.FunctionDefinition,
|
|
288
|
+
id: builtInId,
|
|
289
|
+
environment, cds, params: {},
|
|
290
|
+
subflow: { graph: new Set(), unknownReferences: [], in: [], out: [], environment, entryPoint: builtInId, hooks: [] },
|
|
291
|
+
exitPoints: [],
|
|
292
|
+
}, ctx.env.makeCleanEnv());
|
|
293
|
+
}
|
|
294
|
+
function linkLibrary(dependency, info, rootId, data, spec = {}) {
|
|
295
|
+
if (info.environment.level < 0 || (0, assert_1.isUndefined)(dependency.namespaceInfo)) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const pack = dependency.name;
|
|
299
|
+
// re-loading an already attached package is a no-op, cf. R's `search()`
|
|
300
|
+
if (isAttached(info.environment.current, pack, spec.namespaceOnly)) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
// by default only the environment carries the exports; their built-in vertices are materialized on
|
|
304
|
+
// demand when a call resolves to one (see attachExportVertex). Eager mode registers them all upfront.
|
|
305
|
+
if (data.ctx.config.solver.pkgdb.eagerlyLoadExports) {
|
|
306
|
+
for (const { exported: func } of selectExports((0, flowr_namespace_file_1.getCallables)(dependency.namespaceInfo), spec)) {
|
|
307
|
+
const builtInId = node_id_1.NodeId.toBuiltIn(package_1.Package.funcIdentif(pack, func));
|
|
308
|
+
attachExportVertex(info.graph, builtInId, info.environment, data.ctx, data.cds);
|
|
309
|
+
info.graph.addEdge(builtInId, rootId, edge_1.EdgeType.Reads | edge_1.EdgeType.Calls);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
info.environment = attachDependencyToEnvironment(dependency, info.environment, data.ctx, spec, rootId);
|
|
313
|
+
}
|
|
314
|
+
/** The exports of `callables` to attach under `spec` (see {@link AttachSpec}), resolving selection and aliasing. */
|
|
315
|
+
function selectExports(callables, spec) {
|
|
316
|
+
if (spec.include !== undefined && !spec.all) {
|
|
317
|
+
const available = new Set(callables);
|
|
318
|
+
return Array.from(spec.include, ([as, exported]) => ({ exported, as })).filter(e => available.has(e.exported));
|
|
319
|
+
}
|
|
320
|
+
return callables.filter(c => !spec.exclude?.has(c)).map(c => ({ exported: c, as: c }));
|
|
321
|
+
}
|
|
322
|
+
/** The identifier definition binding a package export (or its alias) to its built-in function-definition. */
|
|
323
|
+
function exportDefinition(pack, exp, definedAt = node_id_1.NodeId.toBuiltIn(pack)) {
|
|
324
|
+
return {
|
|
325
|
+
name: identifier_1.Identifier.make(exp.as, pack),
|
|
326
|
+
type: identifier_1.ReferenceType.Function,
|
|
327
|
+
nodeId: node_id_1.NodeId.toBuiltIn(package_1.Package.funcIdentif(pack, exp.exported)),
|
|
328
|
+
definedAt,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
/** Whether a subset import restricts the attached exports, so no imports layer is materialized. */
|
|
332
|
+
function isSubsetAttach(spec) {
|
|
333
|
+
return spec.include !== undefined && !spec.all;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Attaches `dependency`'s exports below the global environment (see {@link attachPackageBelowGlobal}) and returns the
|
|
337
|
+
* enriched environment (the graph is untouched). Used by `library()`, `import::from`, `box::use`, `requireNamespace`,
|
|
338
|
+
* and the transitive side-effect propagation.
|
|
339
|
+
*/
|
|
340
|
+
function attachDependencyToEnvironment(dependency, envInfo, ctx, spec = {}, definedAt) {
|
|
341
|
+
const pack = dependency.name;
|
|
342
|
+
if ((0, assert_1.isUndefined)(dependency.namespaceInfo) || isAttached(envInfo.current, pack, spec.namespaceOnly)) {
|
|
343
|
+
return envInfo;
|
|
344
|
+
}
|
|
345
|
+
const exports = selectExports((0, flowr_namespace_file_1.getCallables)(dependency.namespaceInfo), spec);
|
|
346
|
+
if (spec.namespaceOnly || isSubsetAttach(spec)) {
|
|
347
|
+
const layerType = spec.namespaceOnly ? environment_1.EnvType.LoadedNamespace : environment_1.EnvType.Namespace;
|
|
348
|
+
let layer = new environment_1.Environment(envInfo.current).asLibrary(pack, layerType);
|
|
349
|
+
for (const exp of exports) {
|
|
350
|
+
layer = layer.define(exportDefinition(pack, exp, definedAt));
|
|
351
|
+
}
|
|
352
|
+
return { level: envInfo.level, current: environment_1.REnvironment.attachBelowGlobal(envInfo.current, layer, layer) };
|
|
353
|
+
}
|
|
354
|
+
// full attach: imports layer at the bottom, namespace (exports) layer on top
|
|
355
|
+
let importsEnv = new environment_1.Environment(envInfo.current).asLibrary(pack, environment_1.EnvType.Imports);
|
|
356
|
+
importsEnv = recImports(importsEnv, dependency.namespaceInfo, ctx, new Set());
|
|
357
|
+
let namespaceEnv = new environment_1.Environment(importsEnv).asLibrary(pack, environment_1.EnvType.Namespace);
|
|
358
|
+
for (const exp of exports) {
|
|
359
|
+
namespaceEnv = namespaceEnv.define(exportDefinition(pack, exp, definedAt));
|
|
360
|
+
}
|
|
361
|
+
return { level: envInfo.level, current: environment_1.REnvironment.attachBelowGlobal(envInfo.current, namespaceEnv, importsEnv) };
|
|
362
|
+
}
|
|
363
|
+
/** A namespace-only load is subsumed by any layer for `pack`; a full attach ignores a mere {@link EnvType.LoadedNamespace}. */
|
|
364
|
+
function blocksAttach(layer, namespaceOnly) {
|
|
365
|
+
if (namespaceOnly) {
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
return layer.t !== environment_1.EnvType.LoadedNamespace;
|
|
369
|
+
}
|
|
370
|
+
/** Whether package `pack` is already attached below the global env in a way that makes this (re-)attach a no-op. */
|
|
371
|
+
function isAttached(env, pack, namespaceOnly) {
|
|
372
|
+
for (let e = environment_1.REnvironment.findGlobal(env).parent; e.t !== undefined && !e.builtInEnv; e = e.parent) {
|
|
373
|
+
if (e.n === pack && blocksAttach(e, namespaceOnly)) {
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
function recImports(importsEnv, namespaceInfo, ctx, alreadyImportedAll) {
|
|
380
|
+
for (const imp of namespaceInfo.importedPackages) {
|
|
381
|
+
const importedDependency = ctx.deps.getDependency(imp[0]);
|
|
382
|
+
if ((0, assert_1.isUndefined)(importedDependency)) {
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
const importedNs = importedDependency.namespaceInfo;
|
|
386
|
+
const funcToImport = importedNs === undefined ? undefined
|
|
387
|
+
: imp[1] === 'all' ? (0, flowr_namespace_file_1.getCallables)(importedNs) : (0, flowr_namespace_file_1.getCallables)(importedNs).filter(v => imp[1].includes(v));
|
|
388
|
+
if ((0, assert_1.isUndefined)(funcToImport)) {
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
if (alreadyImportedAll.has(importedDependency.name)) {
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
for (const func of funcToImport) {
|
|
395
|
+
if (importsEnv.memory.has(package_1.Package.funcIdentif(importedDependency.name, func))) {
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
importsEnv = importsEnv.define({
|
|
399
|
+
name: identifier_1.Identifier.make(package_1.Package.funcIdentif(importedDependency.name, func), importsEnv.n),
|
|
400
|
+
type: identifier_1.ReferenceType.Function,
|
|
401
|
+
nodeId: node_id_1.NodeId.toBuiltIn(package_1.Package.funcIdentif(importedDependency.name, func)),
|
|
402
|
+
definedAt: node_id_1.NodeId.toBuiltIn(importedDependency.name)
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
if (imp[1] === 'all') {
|
|
406
|
+
alreadyImportedAll.add(importedDependency.name);
|
|
407
|
+
}
|
|
408
|
+
//if only importFrom() we don't have to recursively import
|
|
409
|
+
if (imp[1] === 'all' && importedDependency?.namespaceInfo) {
|
|
410
|
+
importsEnv = recImports(importsEnv, importedDependency.namespaceInfo, ctx, alreadyImportedAll);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return importsEnv;
|
|
44
414
|
}
|
|
45
415
|
//# sourceMappingURL=built-in-library.js.map
|
|
@@ -5,6 +5,7 @@ import type { PotentiallyEmptyRArgument } from '../../../../../../r-bridge/lang-
|
|
|
5
5
|
import type { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
|
|
6
6
|
import type { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
7
7
|
/**
|
|
8
|
-
* Process an `rm` call
|
|
8
|
+
* Process an `rm` call, marking the removed variables as {@link KillReference|killed} so the removal is
|
|
9
|
+
* carried to the enclosing scope even when it happens nested within a branch or block.
|
|
9
10
|
*/
|
|
10
11
|
export declare function processRm<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>): DataflowInformation;
|
|
@@ -2,70 +2,153 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.processRm = processRm;
|
|
4
4
|
const known_call_handling_1 = require("../known-call-handling");
|
|
5
|
+
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
5
6
|
const logger_1 = require("../../../../../logger");
|
|
6
7
|
const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
|
|
8
|
+
const identifier_1 = require("../../../../../environments/identifier");
|
|
7
9
|
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
|
|
8
|
-
const
|
|
9
|
-
const r_argument_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-argument");
|
|
10
|
-
const common_1 = require("../common");
|
|
10
|
+
const prefix_1 = require("../../../../../../util/prefix");
|
|
11
11
|
const alias_tracking_1 = require("../../../../../eval/resolve/alias-tracking");
|
|
12
12
|
const general_1 = require("../../../../../eval/values/general");
|
|
13
13
|
const r_value_1 = require("../../../../../eval/values/r-value");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
const resolve_by_name_1 = require("../../../../../environments/resolve-by-name");
|
|
15
|
+
const apply_kill_1 = require("../../../../../environments/apply-kill");
|
|
16
|
+
const define_1 = require("../../../../../environments/define");
|
|
17
|
+
const built_in_envir_utils_1 = require("./built-in-envir-utils");
|
|
18
|
+
/** whether `value` is a call to the *built-in* `ls`/`objects` that lists (and thus clears) the whole scope */
|
|
19
|
+
function isBuiltInLsCall(value, data) {
|
|
20
|
+
if (value.type !== type_1.RType.FunctionCall || !value.named) {
|
|
21
|
+
return false;
|
|
21
22
|
}
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
for (const dotId of argMaps.get('...') ?? []) {
|
|
26
|
-
const value = r_argument_1.RArgument.getWithId(args, dotId)?.value;
|
|
27
|
-
if (value?.type === type_1.RType.Symbol) {
|
|
28
|
-
names.push(value.content);
|
|
29
|
-
}
|
|
30
|
-
else if (value?.type === type_1.RType.String) {
|
|
31
|
-
names.push(value.content.str);
|
|
32
|
-
}
|
|
33
|
-
else if (value !== undefined) {
|
|
34
|
-
logger_1.dataflowLogger.warn(`argument is not a symbol or string in rm, skipping ${JSON.stringify(value)}`);
|
|
35
|
-
}
|
|
23
|
+
const [fn, ns] = identifier_1.Identifier.toArray(value.functionName.content);
|
|
24
|
+
if ((fn !== 'ls' && fn !== 'objects') || (ns !== undefined && ns !== 'base')) {
|
|
25
|
+
return false;
|
|
36
26
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
// a `pattern`/`envir` argument restricts the listing, so only a plain listing clears everything
|
|
28
|
+
const listsEverything = value.arguments.every(a => a !== r_function_call_1.EmptyArgument && a.name !== undefined && (a.name.content === 'all.names' || a.name.content === 'sorted'));
|
|
29
|
+
if (!listsEverything) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
// an explicit `base::` is always the built-in; otherwise only when `ls` is not shadowed
|
|
33
|
+
if (ns === 'base') {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
const resolved = (0, resolve_by_name_1.resolveByName)(fn, data.environment, identifier_1.ReferenceType.Function);
|
|
37
|
+
return resolved === undefined || resolved.every(d => (0, identifier_1.isReferenceType)(d.type, identifier_1.ReferenceType.BuiltInFunction));
|
|
38
|
+
}
|
|
39
|
+
/** formal parameters of `rm` that may be given by name; every other positional argument belongs to `...` */
|
|
40
|
+
const RmNamedFormals = ['list', 'pos', 'envir', 'inherits'];
|
|
41
|
+
/** Adds the name a single `...` argument (an unquoted symbol or quoted string) refers to. */
|
|
42
|
+
function collectDotArg(targets, value) {
|
|
43
|
+
if (value?.type === type_1.RType.Symbol) {
|
|
44
|
+
targets.names.push({ name: value.content, nodeId: value.info.id });
|
|
45
|
+
}
|
|
46
|
+
else if (value?.type === type_1.RType.String) {
|
|
47
|
+
targets.names.push({ name: value.content.str, nodeId: value.info.id });
|
|
48
|
+
}
|
|
49
|
+
else if (value !== undefined) {
|
|
50
|
+
logger_1.dataflowLogger.warn(`argument is not a symbol or string in rm, skipping ${JSON.stringify(value)}`);
|
|
51
|
+
targets.unknown = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Resolves the `list=` argument, recognizing a whole-scope clear via built-in `ls()` and concrete string vectors. */
|
|
55
|
+
function collectListArg(targets, value, data) {
|
|
56
|
+
if (!value) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (value.type === type_1.RType.String) {
|
|
60
|
+
targets.names.push({ name: value.content.str, nodeId: value.info.id });
|
|
61
|
+
}
|
|
62
|
+
else if (isBuiltInLsCall(value, data)) {
|
|
63
|
+
targets.all = true;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const elements = (0, general_1.valueSetGuard)((0, alias_tracking_1.resolveIdToValue)(value.info.id, {
|
|
67
|
+
environment: data.environment,
|
|
68
|
+
idMap: data.completeAst.idMap,
|
|
69
|
+
resolve: data.ctx.config.solver.variables,
|
|
70
|
+
ctx: data.ctx
|
|
71
|
+
}))?.elements;
|
|
72
|
+
if (!elements || elements.length === 0) {
|
|
73
|
+
targets.unknown = true;
|
|
44
74
|
}
|
|
45
75
|
else {
|
|
46
|
-
const
|
|
47
|
-
environment: data.environment,
|
|
48
|
-
idMap: data.completeAst.idMap,
|
|
49
|
-
resolve: data.ctx.config.solver.variables,
|
|
50
|
-
ctx: data.ctx
|
|
51
|
-
}));
|
|
52
|
-
for (const r of resolved?.elements ?? []) {
|
|
76
|
+
for (const r of elements) {
|
|
53
77
|
if (r.type === 'string' && (0, r_value_1.isValue)(r.value)) {
|
|
54
|
-
names.push(r.value.str);
|
|
78
|
+
targets.names.push({ name: r.value.str, nodeId: value.info.id });
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
targets.unknown = true;
|
|
55
82
|
}
|
|
56
83
|
}
|
|
57
84
|
}
|
|
58
85
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Collects the removal targets of an `rm` call: every unnamed argument names a variable (`rm`'s `...` swallows
|
|
89
|
+
* all positionals), `list=` is resolved separately, and `pos`/`envir`/`inherits` contribute no names.
|
|
90
|
+
*/
|
|
91
|
+
function collectRmTargets(args, data) {
|
|
92
|
+
const targets = { names: [], all: false, unknown: false };
|
|
93
|
+
for (const arg of args) {
|
|
94
|
+
if (arg === r_function_call_1.EmptyArgument) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (arg.name === undefined) {
|
|
98
|
+
collectDotArg(targets, arg.value);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const formal = (0, prefix_1.findByPrefixIfUnique)(arg.name.content, RmNamedFormals);
|
|
102
|
+
if (formal === 'list') {
|
|
103
|
+
collectListArg(targets, arg.value, data);
|
|
104
|
+
}
|
|
105
|
+
else if (formal === undefined) {
|
|
106
|
+
// an unknown named argument falls into `...` in R, but we cannot tell which name it removes
|
|
107
|
+
targets.unknown = true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return targets;
|
|
111
|
+
}
|
|
112
|
+
/** Builds the {@link KillReference|kills} produced by an `rm` call from its resolved {@link RmTargets}. */
|
|
113
|
+
function buildKills(targets, cds) {
|
|
114
|
+
const kills = [];
|
|
115
|
+
if (targets.all) {
|
|
116
|
+
kills.push({ kind: 'all', cds });
|
|
117
|
+
}
|
|
118
|
+
if (targets.unknown) {
|
|
119
|
+
kills.push({ kind: 'unknown', cds });
|
|
120
|
+
}
|
|
121
|
+
for (const { name, nodeId } of targets.names) {
|
|
122
|
+
kills.push({ kind: 'named', reference: { nodeId, name, cds, type: identifier_1.ReferenceType.Variable } });
|
|
62
123
|
}
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
124
|
+
return kills;
|
|
125
|
+
}
|
|
126
|
+
/** Removes the targets from a tracked custom environment (`rm(..., envir=e)`) instead of the lexical scope. */
|
|
127
|
+
function removeFromCustomEnv(res, envir, targets, rootId, cds) {
|
|
128
|
+
const newEnvState = (0, apply_kill_1.applyKills)(envir.envDef.envState, buildKills(targets, cds));
|
|
129
|
+
const environment = (0, define_1.define)({ ...envir.envDef, definedAt: rootId, envState: newEnvState }, false, res.environment);
|
|
130
|
+
return { ...res, environment };
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Process an `rm` call, marking the removed variables as {@link KillReference|killed} so the removal is
|
|
134
|
+
* carried to the enclosing scope even when it happens nested within a branch or block.
|
|
135
|
+
*/
|
|
136
|
+
function processRm(name, args, rootId, data) {
|
|
137
|
+
if (args.length === 0) {
|
|
138
|
+
logger_1.dataflowLogger.warn('empty rm, skipping');
|
|
139
|
+
return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
|
|
140
|
+
}
|
|
141
|
+
const res = (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.Rm }).information;
|
|
142
|
+
const targets = collectRmTargets(args, data);
|
|
143
|
+
// `rm(x, envir=e)` removes from a tracked custom environment instead of the lexical scope
|
|
144
|
+
if (data.ctx.config.solver.trackEnvironments) {
|
|
145
|
+
const envir = (0, built_in_envir_utils_1.resolveEnvirArg)(args, data, 'envir');
|
|
146
|
+
if (envir) {
|
|
147
|
+
return removeFromCustomEnv(res, envir, targets, rootId, data.cds);
|
|
68
148
|
}
|
|
69
|
-
}
|
|
149
|
+
}
|
|
150
|
+
// apply to our own environment so threading reflects it, and emit the kills so a merging parent can re-apply
|
|
151
|
+
const kills = buildKills(targets, data.cds);
|
|
152
|
+
return kills.length > 0 ? { ...res, environment: (0, apply_kill_1.applyKills)(res.environment, kills), kill: kills } : res;
|
|
70
153
|
}
|
|
71
154
|
//# sourceMappingURL=built-in-rm.js.map
|