@eagleoutice/flowr 2.2.13 → 2.2.15
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 +4 -4
- package/cli/repl/commands/repl-cfg.d.ts +2 -2
- package/cli/repl/commands/repl-cfg.js +4 -4
- package/cli/repl/commands/repl-commands.js +3 -3
- package/cli/repl/commands/repl-execute.js +2 -1
- package/cli/repl/server/connection.js +1 -1
- package/cli/script-core/statistics-helper-core.js +1 -1
- package/config.js +1 -1
- package/control-flow/basic-cfg-guided-visitor.d.ts +3 -3
- package/control-flow/cfg-dead-code.d.ts +4 -0
- package/control-flow/cfg-dead-code.js +81 -0
- package/control-flow/cfg-simplification.d.ts +17 -6
- package/control-flow/cfg-simplification.js +23 -19
- package/control-flow/control-flow-graph.d.ts +2 -1
- package/control-flow/control-flow-graph.js +1 -0
- package/control-flow/dfg-cfg-guided-visitor.d.ts +4 -4
- package/control-flow/dfg-cfg-guided-visitor.js +1 -1
- package/control-flow/extract-cfg.d.ts +2 -2
- package/control-flow/extract-cfg.js +70 -67
- package/control-flow/semantic-cfg-guided-visitor.d.ts +17 -8
- package/control-flow/semantic-cfg-guided-visitor.js +50 -17
- package/control-flow/simple-visitor.d.ts +4 -0
- package/control-flow/simple-visitor.js +14 -0
- package/control-flow/syntax-cfg-guided-visitor.d.ts +2 -2
- package/dataflow/environments/built-in-config.d.ts +1 -0
- package/dataflow/environments/built-in.d.ts +10 -1
- package/dataflow/environments/built-in.js +9 -3
- package/dataflow/environments/default-builtin-config.js +1 -1
- package/dataflow/environments/resolve-by-name.d.ts +0 -36
- package/dataflow/environments/resolve-by-name.js +0 -240
- package/dataflow/eval/resolve/alias-tracking.d.ts +87 -0
- package/dataflow/eval/resolve/alias-tracking.js +349 -0
- package/dataflow/eval/resolve/resolve.d.ts +34 -0
- package/dataflow/eval/resolve/resolve.js +93 -0
- package/dataflow/eval/values/general.d.ts +27 -0
- package/dataflow/eval/values/general.js +73 -0
- package/dataflow/eval/values/intervals/interval-constants.d.ts +4 -0
- package/dataflow/eval/values/intervals/interval-constants.js +27 -0
- package/dataflow/eval/values/logical/logical-constants.d.ts +7 -0
- package/dataflow/eval/values/logical/logical-constants.js +31 -0
- package/dataflow/eval/values/r-value.d.ts +58 -0
- package/dataflow/eval/values/r-value.js +90 -0
- package/dataflow/eval/values/scalar/scalar-consatnts.d.ts +15 -0
- package/dataflow/eval/values/scalar/scalar-consatnts.js +35 -0
- package/dataflow/eval/values/sets/set-constants.d.ts +7 -0
- package/dataflow/eval/values/sets/set-constants.js +34 -0
- package/dataflow/eval/values/string/string-constants.d.ts +8 -0
- package/dataflow/eval/values/string/string-constants.js +40 -0
- package/dataflow/eval/values/vectors/vector-constants.d.ts +14 -0
- package/dataflow/eval/values/vectors/vector-constants.js +35 -0
- package/dataflow/graph/unknown-replacement.d.ts +11 -0
- package/dataflow/graph/unknown-replacement.js +12 -0
- package/dataflow/graph/unknown-side-effect.d.ts +7 -0
- package/dataflow/graph/unknown-side-effect.js +13 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-apply.js +8 -5
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +4 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +12 -9
- package/dataflow/internal/process/functions/call/built-in/built-in-if-then-else.js +5 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +9 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-source.js +12 -15
- package/dataflow/internal/process/functions/call/built-in/built-in-while-loop.js +23 -0
- package/dataflow/internal/process/functions/call/known-call-handling.js +2 -1
- package/documentation/doc-util/doc-cfg.d.ts +1 -1
- package/documentation/doc-util/doc-cfg.js +3 -3
- package/documentation/doc-util/doc-query.d.ts +6 -3
- package/documentation/doc-util/doc-query.js +3 -1
- package/documentation/print-cfg-wiki.js +31 -31
- package/documentation/print-dataflow-graph-wiki.js +4 -3
- package/documentation/print-engines-wiki.js +1 -1
- package/documentation/print-linter-wiki.d.ts +1 -0
- package/documentation/print-linter-wiki.js +76 -0
- package/documentation/print-query-wiki.js +80 -0
- package/linter/linter-executor.d.ts +9 -0
- package/linter/linter-executor.js +26 -0
- package/linter/linter-format.d.ts +65 -0
- package/linter/linter-format.js +9 -0
- package/linter/linter-rules.d.ts +42 -0
- package/linter/linter-rules.js +14 -0
- package/linter/rules/1-deprecated-functions.d.ts +34 -0
- package/linter/rules/1-deprecated-functions.js +54 -0
- package/linter/rules/2-file-path-validity.d.ts +48 -0
- package/linter/rules/2-file-path-validity.js +93 -0
- package/package.json +2 -1
- package/queries/catalog/call-context-query/call-context-query-executor.js +1 -1
- package/queries/catalog/call-context-query/call-context-query-format.d.ts +2 -2
- package/queries/catalog/call-context-query/call-context-query-format.js +5 -1
- package/queries/catalog/cluster-query/cluster-query-format.d.ts +2 -0
- package/queries/catalog/cluster-query/cluster-query-format.js +5 -1
- package/queries/catalog/config-query/config-query-format.d.ts +1 -0
- package/queries/catalog/config-query/config-query-format.js +2 -1
- package/queries/catalog/control-flow-query/control-flow-query-executor.d.ts +3 -0
- package/queries/catalog/control-flow-query/control-flow-query-executor.js +20 -0
- package/queries/catalog/control-flow-query/control-flow-query-format.d.ts +81 -0
- package/queries/catalog/control-flow-query/control-flow-query-format.js +34 -0
- package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.d.ts +1 -0
- package/queries/catalog/dataflow-lens-query/dataflow-lens-query-format.js +2 -1
- package/queries/catalog/dataflow-query/dataflow-query-format.d.ts +2 -0
- package/queries/catalog/dataflow-query/dataflow-query-format.js +9 -1
- package/queries/catalog/dependencies-query/dependencies-query-executor.js +33 -32
- package/queries/catalog/dependencies-query/dependencies-query-format.d.ts +1 -0
- package/queries/catalog/dependencies-query/dependencies-query-format.js +10 -1
- package/queries/catalog/happens-before-query/happens-before-query-format.d.ts +1 -0
- package/queries/catalog/happens-before-query/happens-before-query-format.js +2 -1
- package/queries/catalog/id-map-query/id-map-query-format.d.ts +1 -0
- package/queries/catalog/id-map-query/id-map-query-format.js +2 -1
- package/queries/catalog/lineage-query/lineage-query-format.d.ts +1 -0
- package/queries/catalog/lineage-query/lineage-query-format.js +5 -1
- package/queries/catalog/linter-query/linter-query-executor.d.ts +3 -0
- package/queries/catalog/linter-query/linter-query-executor.js +28 -0
- package/queries/catalog/linter-query/linter-query-format.d.ts +80 -0
- package/queries/catalog/linter-query/linter-query-format.js +44 -0
- package/queries/catalog/location-map-query/location-map-query-format.d.ts +1 -0
- package/queries/catalog/location-map-query/location-map-query-format.js +2 -1
- package/queries/catalog/normalized-ast-query/normalized-ast-query-format.d.ts +1 -0
- package/queries/catalog/normalized-ast-query/normalized-ast-query-format.js +2 -1
- package/queries/catalog/origin-query/origin-query-format.d.ts +2 -0
- package/queries/catalog/origin-query/origin-query-format.js +5 -1
- package/queries/catalog/project-query/project-query-executor.js +1 -1
- package/queries/catalog/project-query/project-query-format.d.ts +1 -0
- package/queries/catalog/project-query/project-query-format.js +2 -1
- package/queries/catalog/resolve-value-query/resolve-value-query-executor.js +3 -3
- package/queries/catalog/resolve-value-query/resolve-value-query-format.d.ts +3 -1
- package/queries/catalog/resolve-value-query/resolve-value-query-format.js +4 -23
- package/queries/catalog/search-query/search-query-format.d.ts +1 -0
- package/queries/catalog/search-query/search-query-format.js +5 -1
- package/queries/catalog/static-slice-query/static-slice-query-format.d.ts +2 -0
- package/queries/catalog/static-slice-query/static-slice-query-format.js +9 -1
- package/queries/query.d.ts +143 -1
- package/queries/query.js +4 -0
- package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +11 -4
- package/r-bridge/retriever.js +1 -1
- package/search/flowr-search-builder.d.ts +31 -2
- package/search/flowr-search-builder.js +30 -0
- package/search/flowr-search.d.ts +7 -1
- package/search/search-executor/search-enrichers.d.ts +73 -0
- package/search/search-executor/search-enrichers.js +101 -0
- package/search/search-executor/search-generators.d.ts +6 -1
- package/search/search-executor/search-generators.js +21 -1
- package/search/search-executor/search-mappers.d.ts +19 -0
- package/search/search-executor/search-mappers.js +21 -0
- package/search/search-executor/search-transformer.d.ts +12 -0
- package/search/search-executor/search-transformer.js +11 -1
- package/slicing/criterion/parse.d.ts +8 -0
- package/slicing/criterion/parse.js +20 -0
- package/util/version.js +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EmptyBuiltInMemory = exports.BuiltInMemory = exports.BuiltInProcessorMapper = void 0;
|
|
3
|
+
exports.EmptyBuiltInMemory = exports.BuiltInMemory = exports.BuiltInEvalHandlerMapper = exports.BuiltInProcessorMapper = void 0;
|
|
4
4
|
exports.builtInId = builtInId;
|
|
5
5
|
exports.isBuiltIn = isBuiltIn;
|
|
6
6
|
exports.registerBuiltInFunctions = registerBuiltInFunctions;
|
|
@@ -33,6 +33,8 @@ const built_in_rm_1 = require("../internal/process/functions/call/built-in/built
|
|
|
33
33
|
const built_in_eval_1 = require("../internal/process/functions/call/built-in/built-in-eval");
|
|
34
34
|
const vertex_1 = require("../graph/vertex");
|
|
35
35
|
const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
|
|
36
|
+
const unknown_side_effect_1 = require("../graph/unknown-side-effect");
|
|
37
|
+
const resolve_1 = require("../eval/resolve/resolve");
|
|
36
38
|
function builtInId(name) {
|
|
37
39
|
return `built-in:${name}`;
|
|
38
40
|
}
|
|
@@ -56,10 +58,10 @@ function defaultBuiltInProcessor(name, args, rootId, data, config) {
|
|
|
56
58
|
}
|
|
57
59
|
if (config.hasUnknownSideEffects) {
|
|
58
60
|
if (typeof config.hasUnknownSideEffects !== 'boolean') {
|
|
59
|
-
res.graph.
|
|
61
|
+
(0, unknown_side_effect_1.handleUnknownSideEffect)(res.graph, res.environment, rootId, config.hasUnknownSideEffects);
|
|
60
62
|
}
|
|
61
63
|
else {
|
|
62
|
-
res.graph.
|
|
64
|
+
(0, unknown_side_effect_1.handleUnknownSideEffect)(res.graph, res.environment, rootId);
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
const fnCallNames = config.treatAsFnCall?.[name.content];
|
|
@@ -140,6 +142,10 @@ exports.BuiltInProcessorMapper = {
|
|
|
140
142
|
'builtin:list': built_in_list_1.processList,
|
|
141
143
|
'builtin:vector': built_in_vector_1.processVector,
|
|
142
144
|
};
|
|
145
|
+
exports.BuiltInEvalHandlerMapper = {
|
|
146
|
+
'built-in:c': resolve_1.resolveAsVector,
|
|
147
|
+
'builtin:vector': resolve_1.resolveAsVector
|
|
148
|
+
};
|
|
143
149
|
exports.BuiltInMemory = new Map();
|
|
144
150
|
exports.EmptyBuiltInMemory = new Map();
|
|
145
151
|
(0, built_in_config_1.registerBuiltInDefinitions)(default_builtin_config_1.DefaultBuiltinConfig);
|
|
@@ -245,7 +245,7 @@ exports.DefaultBuiltinConfig = [
|
|
|
245
245
|
{ type: 'function', names: ['interference'], processor: 'builtin:apply', config: { unquoteFunction: true, nameOfFunctionArgument: 'propensity_integrand' }, assumePrimitive: false },
|
|
246
246
|
{ type: 'function', names: ['ddply'], processor: 'builtin:apply', config: { unquoteFunction: true, indexOfFunction: 2, nameOfFunctionArgument: '.fun' }, assumePrimitive: false },
|
|
247
247
|
{ type: 'function', names: ['list'], processor: 'builtin:list', config: {}, assumePrimitive: true },
|
|
248
|
-
{ type: 'function', names: ['c'], processor: 'builtin:vector', config: {}, assumePrimitive: true },
|
|
248
|
+
{ type: 'function', names: ['c'], processor: 'builtin:vector', config: {}, assumePrimitive: true, evalHandler: 'builtin:c' },
|
|
249
249
|
{
|
|
250
250
|
type: 'function',
|
|
251
251
|
names: ['setnames', 'setNames', 'setkey', 'setkeyv', 'setindex', 'setindexv', 'setattr'],
|
|
@@ -2,9 +2,6 @@ import type { REnvironmentInformation } from './environment';
|
|
|
2
2
|
import { Ternary } from '../../util/logic';
|
|
3
3
|
import type { Identifier, IdentifierDefinition } from './identifier';
|
|
4
4
|
import { ReferenceType } from './identifier';
|
|
5
|
-
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
6
|
-
import type { DataflowGraph } from '../graph/graph';
|
|
7
|
-
import type { AstIdMap, RNodeWithParent } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
8
5
|
/**
|
|
9
6
|
* Resolves a given identifier name to a list of its possible definition location using R scoping and resolving rules.
|
|
10
7
|
*
|
|
@@ -17,36 +14,3 @@ import type { AstIdMap, RNodeWithParent } from '../../r-bridge/lang-4.x/ast/mode
|
|
|
17
14
|
*/
|
|
18
15
|
export declare function resolveByName(name: Identifier, environment: REnvironmentInformation, target?: ReferenceType): IdentifierDefinition[] | undefined;
|
|
19
16
|
export declare function resolvesToBuiltInConstant(name: Identifier | undefined, environment: REnvironmentInformation, wantedValue: unknown): Ternary;
|
|
20
|
-
/** Please use {@link resolveValueOfVariable} */
|
|
21
|
-
export declare function resolveToConstants(name: Identifier | undefined, environment: REnvironmentInformation): unknown[] | undefined;
|
|
22
|
-
export declare function getAliases(sourceIds: readonly NodeId[], dataflow: DataflowGraph, environment: REnvironmentInformation): NodeId[] | undefined;
|
|
23
|
-
/** Please use {@link resolveValueOfVariable} */
|
|
24
|
-
export declare function trackAliasInEnvironments(identifier: Identifier | undefined, use: REnvironmentInformation, idMap?: AstIdMap): unknown[] | undefined;
|
|
25
|
-
export declare function trackAliasesInGraph(id: NodeId, graph: DataflowGraph, idMap?: AstIdMap): unknown[] | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* Convenience function using the variable resolver as specified within the configuration file
|
|
28
|
-
* In the future we may want to have this set once at the start of the analysis
|
|
29
|
-
*
|
|
30
|
-
* @see {@link resolveIdToValue} - for a more general approach which "evaluates" a node based on value resolve
|
|
31
|
-
*/
|
|
32
|
-
export declare function resolveValueOfVariable(identifier: Identifier | undefined, environment: REnvironmentInformation, idMap?: AstIdMap): unknown[] | undefined;
|
|
33
|
-
export interface ResolveInfo {
|
|
34
|
-
/** The current environment used for name resolution */
|
|
35
|
-
environment?: REnvironmentInformation;
|
|
36
|
-
/** The id map to resolve the node if given as an id */
|
|
37
|
-
idMap?: AstIdMap;
|
|
38
|
-
/** The graph to resolve in */
|
|
39
|
-
graph?: DataflowGraph;
|
|
40
|
-
/** Whether to track variables */
|
|
41
|
-
full?: boolean;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Generalized {@link resolveValueOfVariable} function which evaluates a node based on the value resolve
|
|
45
|
-
*
|
|
46
|
-
* @param id - The node id or node to resolve
|
|
47
|
-
* @param environment - The current environment used for name resolution
|
|
48
|
-
* @param graph - The graph to resolve in
|
|
49
|
-
* @param idMap - The id map to resolve the node if given as an id
|
|
50
|
-
* @param full - Whether to track variables
|
|
51
|
-
*/
|
|
52
|
-
export declare function resolveIdToValue(id: NodeId | RNodeWithParent, { environment, graph, idMap, full }: ResolveInfo): unknown[] | undefined;
|
|
@@ -2,24 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveByName = resolveByName;
|
|
4
4
|
exports.resolvesToBuiltInConstant = resolvesToBuiltInConstant;
|
|
5
|
-
exports.resolveToConstants = resolveToConstants;
|
|
6
|
-
exports.getAliases = getAliases;
|
|
7
|
-
exports.trackAliasInEnvironments = trackAliasInEnvironments;
|
|
8
|
-
exports.trackAliasesInGraph = trackAliasesInGraph;
|
|
9
|
-
exports.resolveValueOfVariable = resolveValueOfVariable;
|
|
10
|
-
exports.resolveIdToValue = resolveIdToValue;
|
|
11
5
|
const environment_1 = require("./environment");
|
|
12
6
|
const logic_1 = require("../../util/logic");
|
|
13
7
|
const identifier_1 = require("./identifier");
|
|
14
8
|
const info_1 = require("../info");
|
|
15
|
-
const node_id_1 = require("../../r-bridge/lang-4.x/ast/model/processing/node-id");
|
|
16
|
-
const vertex_1 = require("../graph/vertex");
|
|
17
|
-
const config_1 = require("../../config");
|
|
18
|
-
const assert_1 = require("../../util/assert");
|
|
19
|
-
const type_1 = require("../../r-bridge/lang-4.x/ast/model/type");
|
|
20
|
-
const visiting_queue_1 = require("../../slicing/static/visiting-queue");
|
|
21
|
-
const fingerprint_1 = require("../../slicing/static/fingerprint");
|
|
22
|
-
const edge_1 = require("../graph/edge");
|
|
23
9
|
const FunctionTargetTypes = identifier_1.ReferenceType.Function | identifier_1.ReferenceType.BuiltInFunction | identifier_1.ReferenceType.Unknown | identifier_1.ReferenceType.Argument | identifier_1.ReferenceType.Parameter;
|
|
24
10
|
const VariableTargetTypes = identifier_1.ReferenceType.Variable | identifier_1.ReferenceType.Parameter | identifier_1.ReferenceType.Argument | identifier_1.ReferenceType.Unknown;
|
|
25
11
|
const ConstantTargetTypes = identifier_1.ReferenceType.Constant | identifier_1.ReferenceType.BuiltInConstant | identifier_1.ReferenceType.Unknown;
|
|
@@ -96,230 +82,4 @@ function resolvesToBuiltInConstant(name, environment, wantedValue) {
|
|
|
96
82
|
return some ? logic_1.Ternary.Maybe : logic_1.Ternary.Never;
|
|
97
83
|
}
|
|
98
84
|
}
|
|
99
|
-
/** Please use {@link resolveValueOfVariable} */
|
|
100
|
-
function resolveToConstants(name, environment) {
|
|
101
|
-
if (name === undefined) {
|
|
102
|
-
return undefined;
|
|
103
|
-
}
|
|
104
|
-
const definitions = resolveByName(name, environment, identifier_1.ReferenceType.Constant);
|
|
105
|
-
return definitions?.map(def => def.value);
|
|
106
|
-
}
|
|
107
|
-
const AliasHandler = {
|
|
108
|
-
[vertex_1.VertexType.Value]: (sourceId) => [sourceId],
|
|
109
|
-
[vertex_1.VertexType.Use]: getUseAlias,
|
|
110
|
-
[vertex_1.VertexType.FunctionCall]: () => undefined,
|
|
111
|
-
[vertex_1.VertexType.FunctionDefinition]: () => undefined,
|
|
112
|
-
[vertex_1.VertexType.VariableDefinition]: () => undefined
|
|
113
|
-
};
|
|
114
|
-
function getUseAlias(sourceId, dataflow, environment) {
|
|
115
|
-
let definitions = [];
|
|
116
|
-
// Source is Symbol -> resolve definitions of symbol
|
|
117
|
-
const identifier = (0, node_id_1.recoverName)(sourceId, dataflow.idMap);
|
|
118
|
-
if (identifier === undefined) {
|
|
119
|
-
return undefined;
|
|
120
|
-
}
|
|
121
|
-
const defs = resolveByName(identifier, environment);
|
|
122
|
-
if (defs === undefined) {
|
|
123
|
-
return undefined;
|
|
124
|
-
}
|
|
125
|
-
for (const def of defs) {
|
|
126
|
-
// If one definition is not constant (or a variable aliasing a constant)
|
|
127
|
-
// we can't say for sure what value the source has
|
|
128
|
-
if (def.type === identifier_1.ReferenceType.Variable) {
|
|
129
|
-
if (def.value === undefined) {
|
|
130
|
-
return undefined;
|
|
131
|
-
}
|
|
132
|
-
definitions = definitions.concat(def.value);
|
|
133
|
-
}
|
|
134
|
-
else if (def.type === identifier_1.ReferenceType.Constant || def.type === identifier_1.ReferenceType.BuiltInConstant) {
|
|
135
|
-
definitions.push(def.nodeId);
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
return undefined;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return definitions;
|
|
142
|
-
}
|
|
143
|
-
function getAliases(sourceIds, dataflow, environment) {
|
|
144
|
-
const definitions = new Set();
|
|
145
|
-
for (const sourceId of sourceIds) {
|
|
146
|
-
const info = dataflow.getVertex(sourceId);
|
|
147
|
-
if (info === undefined) {
|
|
148
|
-
return undefined;
|
|
149
|
-
}
|
|
150
|
-
const defs = AliasHandler[info.tag](sourceId, dataflow, environment);
|
|
151
|
-
for (const def of defs ?? []) {
|
|
152
|
-
definitions.add(def);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return [...definitions];
|
|
156
|
-
}
|
|
157
|
-
/** Please use {@link resolveValueOfVariable} */
|
|
158
|
-
function trackAliasInEnvironments(identifier, use, idMap) {
|
|
159
|
-
if (identifier === undefined) {
|
|
160
|
-
return undefined;
|
|
161
|
-
}
|
|
162
|
-
const defs = resolveByName(identifier, use);
|
|
163
|
-
if (defs === undefined) {
|
|
164
|
-
return undefined;
|
|
165
|
-
}
|
|
166
|
-
const values = [];
|
|
167
|
-
for (const def of defs) {
|
|
168
|
-
if (def.type === identifier_1.ReferenceType.BuiltInConstant) {
|
|
169
|
-
values.push(def.value);
|
|
170
|
-
}
|
|
171
|
-
else if (def.type === identifier_1.ReferenceType.BuiltInFunction) {
|
|
172
|
-
// Tracked in #1207
|
|
173
|
-
}
|
|
174
|
-
else if (def.value !== undefined) {
|
|
175
|
-
/* if there is at least one location for which we have no idea, we have to give up for now! */
|
|
176
|
-
if (def.value.length === 0) {
|
|
177
|
-
return undefined;
|
|
178
|
-
}
|
|
179
|
-
for (const id of def.value) {
|
|
180
|
-
const value = idMap?.get(id)?.content;
|
|
181
|
-
if (value !== undefined) {
|
|
182
|
-
values.push(value);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
if (values.length == 0) {
|
|
188
|
-
return undefined;
|
|
189
|
-
}
|
|
190
|
-
return values;
|
|
191
|
-
}
|
|
192
|
-
function isNestedInLoop(node, ast) {
|
|
193
|
-
const parent = node?.info.parent;
|
|
194
|
-
if (node === undefined || !parent) {
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
const parentNode = ast.get(parent);
|
|
198
|
-
if (parentNode === undefined) {
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
if (parentNode.type === type_1.RType.WhileLoop || parentNode.type === type_1.RType.RepeatLoop) {
|
|
202
|
-
return true;
|
|
203
|
-
}
|
|
204
|
-
return isNestedInLoop(parentNode, ast);
|
|
205
|
-
}
|
|
206
|
-
function trackAliasesInGraph(id, graph, idMap) {
|
|
207
|
-
idMap ??= graph.idMap;
|
|
208
|
-
(0, assert_1.guard)(idMap !== undefined, 'The ID map is required to get the lineage of a node');
|
|
209
|
-
const start = graph.getVertex(id);
|
|
210
|
-
(0, assert_1.guard)(start !== undefined, 'Unable to find start for alias tracking');
|
|
211
|
-
const queue = new visiting_queue_1.VisitingQueue(25);
|
|
212
|
-
const clean = (0, environment_1.initializeCleanEnvironments)();
|
|
213
|
-
const cleanFingerprint = (0, fingerprint_1.envFingerprint)(clean);
|
|
214
|
-
queue.add(id, clean, cleanFingerprint, false);
|
|
215
|
-
let forceBot = false;
|
|
216
|
-
const resultIds = [];
|
|
217
|
-
while (queue.nonEmpty()) {
|
|
218
|
-
const { id, baseEnvironment } = queue.next();
|
|
219
|
-
const res = graph.get(id);
|
|
220
|
-
if (!res) {
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
const [vertex, outgoingEdges] = res;
|
|
224
|
-
const cds = vertex.cds;
|
|
225
|
-
for (const cd of cds ?? []) {
|
|
226
|
-
const target = graph.idMap?.get(cd.id);
|
|
227
|
-
if (target === undefined) {
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
if (target.type === type_1.RType.WhileLoop || target.type === type_1.RType.RepeatLoop) {
|
|
231
|
-
forceBot = true;
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
if (!forceBot && (cds?.length === 0 && isNestedInLoop(idMap.get(id), idMap))) {
|
|
236
|
-
forceBot = true;
|
|
237
|
-
}
|
|
238
|
-
if (forceBot) {
|
|
239
|
-
break;
|
|
240
|
-
}
|
|
241
|
-
if (vertex.tag === vertex_1.VertexType.Value) {
|
|
242
|
-
resultIds.push(id);
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
else if (vertex.tag === vertex_1.VertexType.FunctionDefinition) {
|
|
246
|
-
resultIds.push(id);
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
const isFn = vertex.tag === vertex_1.VertexType.FunctionCall;
|
|
250
|
-
// travel all read and defined-by edges
|
|
251
|
-
for (const [targetId, edge] of outgoingEdges) {
|
|
252
|
-
if (isFn) {
|
|
253
|
-
if (edge.types === edge_1.EdgeType.Returns || edge.types === edge_1.EdgeType.DefinedByOnCall || edge.types === edge_1.EdgeType.DefinedBy) {
|
|
254
|
-
queue.add(targetId, baseEnvironment, cleanFingerprint, false);
|
|
255
|
-
}
|
|
256
|
-
continue;
|
|
257
|
-
}
|
|
258
|
-
// currently, they have to be exact!
|
|
259
|
-
if (edge.types === edge_1.EdgeType.Reads || edge.types === edge_1.EdgeType.DefinedBy || edge.types === edge_1.EdgeType.DefinedByOnCall) {
|
|
260
|
-
queue.add(targetId, baseEnvironment, cleanFingerprint, false);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
if (forceBot || resultIds.length === 0) {
|
|
265
|
-
return undefined;
|
|
266
|
-
}
|
|
267
|
-
const values = [];
|
|
268
|
-
for (const id of resultIds) {
|
|
269
|
-
const node = idMap.get(id);
|
|
270
|
-
if (node !== undefined) {
|
|
271
|
-
values.push(node.content);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
return values;
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Convenience function using the variable resolver as specified within the configuration file
|
|
278
|
-
* In the future we may want to have this set once at the start of the analysis
|
|
279
|
-
*
|
|
280
|
-
* @see {@link resolveIdToValue} - for a more general approach which "evaluates" a node based on value resolve
|
|
281
|
-
*/
|
|
282
|
-
function resolveValueOfVariable(identifier, environment, idMap) {
|
|
283
|
-
const resolve = (0, config_1.getConfig)().solver.variables;
|
|
284
|
-
switch (resolve) {
|
|
285
|
-
case config_1.VariableResolve.Alias: return trackAliasInEnvironments(identifier, environment, idMap);
|
|
286
|
-
case config_1.VariableResolve.Builtin: return resolveToConstants(identifier, environment);
|
|
287
|
-
case config_1.VariableResolve.Disabled: return [];
|
|
288
|
-
default: (0, assert_1.assertUnreachable)(resolve);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Generalized {@link resolveValueOfVariable} function which evaluates a node based on the value resolve
|
|
293
|
-
*
|
|
294
|
-
* @param id - The node id or node to resolve
|
|
295
|
-
* @param environment - The current environment used for name resolution
|
|
296
|
-
* @param graph - The graph to resolve in
|
|
297
|
-
* @param idMap - The id map to resolve the node if given as an id
|
|
298
|
-
* @param full - Whether to track variables
|
|
299
|
-
*/
|
|
300
|
-
function resolveIdToValue(id, { environment, graph, idMap, full }) {
|
|
301
|
-
idMap ??= graph?.idMap;
|
|
302
|
-
const node = typeof id === 'object' ? id : idMap?.get(id);
|
|
303
|
-
if (node === undefined) {
|
|
304
|
-
return undefined;
|
|
305
|
-
}
|
|
306
|
-
switch (node.type) {
|
|
307
|
-
case type_1.RType.Symbol:
|
|
308
|
-
if (environment) {
|
|
309
|
-
return full ? resolveValueOfVariable(node.lexeme, environment, idMap) : undefined;
|
|
310
|
-
}
|
|
311
|
-
else if (graph && (0, config_1.getConfig)().solver.variables === config_1.VariableResolve.Alias) {
|
|
312
|
-
return full ? trackAliasesInGraph(node.info.id, graph, idMap) : undefined;
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
return undefined;
|
|
316
|
-
}
|
|
317
|
-
case type_1.RType.String:
|
|
318
|
-
case type_1.RType.Number:
|
|
319
|
-
case type_1.RType.Logical:
|
|
320
|
-
return [node.content];
|
|
321
|
-
default:
|
|
322
|
-
return undefined;
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
85
|
//# sourceMappingURL=resolve-by-name.js.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { AstIdMap, RNodeWithParent } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate';
|
|
2
|
+
import type { NodeId } from '../../../r-bridge/lang-4.x/ast/model/processing/node-id';
|
|
3
|
+
import type { REnvironmentInformation } from '../../environments/environment';
|
|
4
|
+
import type { Identifier } from '../../environments/identifier';
|
|
5
|
+
import type { DataflowGraph } from '../../graph/graph';
|
|
6
|
+
import type { Lift, Value, ValueSet } from '../values/r-value';
|
|
7
|
+
export type ResolveResult = Lift<ValueSet<Value[]>>;
|
|
8
|
+
export interface ResolveInfo {
|
|
9
|
+
/** The current environment used for name resolution */
|
|
10
|
+
environment?: REnvironmentInformation;
|
|
11
|
+
/** The id map to resolve the node if given as an id */
|
|
12
|
+
idMap?: AstIdMap;
|
|
13
|
+
/** The graph to resolve in */
|
|
14
|
+
graph?: DataflowGraph;
|
|
15
|
+
/** Whether to track variables */
|
|
16
|
+
full?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Gets the definitions / aliases of a node
|
|
20
|
+
*
|
|
21
|
+
* This function is called by the built-in-assignment processor so that we can
|
|
22
|
+
* track assignments inside the environment. The returned ids are stored in
|
|
23
|
+
* the sourceIds value field of their InGraphIdentifierDefinition. This enables
|
|
24
|
+
* us later, in the {@link trackAliasInEnvironments} function, to get all the
|
|
25
|
+
* aliases of an identifier.
|
|
26
|
+
*
|
|
27
|
+
* @param sourceIds - node ids to get the definitions for
|
|
28
|
+
* @param dataflow - dataflow graph
|
|
29
|
+
* @param environment - environment
|
|
30
|
+
* @returns node id of alias
|
|
31
|
+
*/
|
|
32
|
+
export declare function getAliases(sourceIds: readonly NodeId[], dataflow: DataflowGraph, environment: REnvironmentInformation): NodeId[] | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Evaluates the value of a node in the set domain.
|
|
35
|
+
*
|
|
36
|
+
* resolveIdToValue tries to resolve the value using the data it has been given.
|
|
37
|
+
* If the environment is provided the approximation is more precise, as we can
|
|
38
|
+
* track aliases in the environment.
|
|
39
|
+
* Otherwise, the graph is used to try and resolve the nodes value.
|
|
40
|
+
* If neither is provided the value cannot be resolved.
|
|
41
|
+
*
|
|
42
|
+
* This function is also used by the Resolve Value Query and the Dependency Query
|
|
43
|
+
* to resolve values. For e.g. in the Dependency Query it is used to resolve calls
|
|
44
|
+
* like `lapply(c("a", "b", "c"), library, character.only = TRUE)`
|
|
45
|
+
*
|
|
46
|
+
* @param id - The node id or node to resolve
|
|
47
|
+
* @param environment - The current environment used for name resolution
|
|
48
|
+
* @param graph - The graph to resolve in
|
|
49
|
+
* @param idMap - The id map to resolve the node if given as an id
|
|
50
|
+
* @param full - Whether to track aliases on resolve
|
|
51
|
+
*/
|
|
52
|
+
export declare function resolveIdToValue(id: NodeId | RNodeWithParent | undefined, { environment, graph, idMap, full }: ResolveInfo): ResolveResult;
|
|
53
|
+
/**
|
|
54
|
+
* Please use {@link resolveIdToValue}
|
|
55
|
+
*
|
|
56
|
+
* Uses the aliases that were tracked in the environments (by the
|
|
57
|
+
* {@link getAliases} function) to resolve a node to a value.
|
|
58
|
+
*
|
|
59
|
+
*
|
|
60
|
+
* @param identifier - Identifier to resolve
|
|
61
|
+
* @param use - Environment to use
|
|
62
|
+
* @param graph - Dataflow graph
|
|
63
|
+
* @param idMap - id map of Dataflow graph
|
|
64
|
+
* @returns Value of Identifier or Top
|
|
65
|
+
*/
|
|
66
|
+
export declare function trackAliasInEnvironments(identifier: Identifier | undefined, use: REnvironmentInformation, graph?: DataflowGraph, idMap?: AstIdMap): ResolveResult;
|
|
67
|
+
/**
|
|
68
|
+
* Please use {@link resolveIdToValue}
|
|
69
|
+
*
|
|
70
|
+
* Tries to resolve the value of a node by traversing the dataflow graph
|
|
71
|
+
*
|
|
72
|
+
* @param id - node to resolve
|
|
73
|
+
* @param graph - dataflow graph
|
|
74
|
+
* @param idMap - idmap of dataflow graph
|
|
75
|
+
* @returns Value of node or Top/Bottom
|
|
76
|
+
*/
|
|
77
|
+
export declare function trackAliasesInGraph(id: NodeId, graph: DataflowGraph, idMap?: AstIdMap): ResolveResult;
|
|
78
|
+
/**
|
|
79
|
+
* Please use {@link resolveIdToValue}
|
|
80
|
+
*
|
|
81
|
+
* Resolve an Identifier to a constant, if the identifier is a constant
|
|
82
|
+
*
|
|
83
|
+
* @param name - Identifier to resolve
|
|
84
|
+
* @param environment - Environment to use
|
|
85
|
+
* @returns Value of Constant or Top
|
|
86
|
+
*/
|
|
87
|
+
export declare function resolveToConstants(name: Identifier | undefined, environment: REnvironmentInformation): ResolveResult;
|