@eagleoutice/flowr 2.10.4 → 2.10.6
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 +31 -14
- package/abstract-interpretation/absint-visitor.d.ts +17 -22
- package/abstract-interpretation/absint-visitor.js +47 -48
- package/abstract-interpretation/data-frame/dataframe-domain.d.ts +0 -3
- package/abstract-interpretation/data-frame/shape-inference.d.ts +2 -1
- package/abstract-interpretation/data-frame/shape-inference.js +5 -4
- package/abstract-interpretation/domains/abstract-domain.d.ts +17 -16
- package/abstract-interpretation/domains/abstract-domain.js +25 -27
- package/abstract-interpretation/domains/bounded-set-domain.js +1 -1
- package/abstract-interpretation/domains/multi-value-state-domain.d.ts +32 -0
- package/abstract-interpretation/domains/multi-value-state-domain.js +60 -0
- package/abstract-interpretation/domains/partial-product-domain.d.ts +43 -0
- package/abstract-interpretation/domains/partial-product-domain.js +163 -0
- package/abstract-interpretation/domains/product-domain.d.ts +2 -29
- package/abstract-interpretation/domains/product-domain.js +6 -123
- package/abstract-interpretation/domains/set-range-domain.js +3 -3
- package/abstract-interpretation/domains/set-upper-bound-domain.js +1 -1
- package/abstract-interpretation/domains/singleton-domain.js +1 -1
- package/abstract-interpretation/domains/state-abstract-domain.d.ts +13 -28
- package/abstract-interpretation/domains/state-abstract-domain.js +16 -38
- package/abstract-interpretation/domains/state-domain-like.d.ts +36 -0
- package/abstract-interpretation/domains/state-domain-like.js +3 -0
- package/cli/flowr.js +11 -1
- package/config.d.ts +13 -0
- package/config.js +24 -3
- package/control-flow/basic-cfg-guided-visitor.d.ts +1 -1
- package/control-flow/semantic-cfg-guided-visitor.d.ts +4 -0
- package/control-flow/semantic-cfg-guided-visitor.js +23 -32
- package/dataflow/environments/built-in-proc-name.d.ts +7 -1
- package/dataflow/environments/built-in-proc-name.js +6 -0
- package/dataflow/environments/built-in.d.ts +6 -0
- package/dataflow/environments/built-in.js +6 -0
- package/dataflow/environments/default-builtin-config.d.ts +63 -1
- package/dataflow/environments/default-builtin-config.js +15 -4
- package/dataflow/environments/identifier.d.ts +14 -0
- package/dataflow/graph/vertex.d.ts +6 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-access.js +16 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.d.ts +6 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-assignment.js +99 -2
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.d.ts +13 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-attach.js +48 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.d.ts +75 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-envir-utils.js +196 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.d.ts +2 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-eval.js +38 -21
- package/dataflow/internal/process/functions/call/built-in/built-in-get.d.ts +5 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-get.js +27 -13
- package/dataflow/internal/process/functions/call/built-in/built-in-local.js +14 -4
- package/dataflow/internal/process/functions/call/built-in/built-in-new-env.d.ts +27 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-new-env.js +97 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-with.d.ts +23 -0
- package/dataflow/internal/process/functions/call/built-in/built-in-with.js +90 -0
- package/documentation/doc-readme.js +13 -2
- package/documentation/doc-util/doc-types.d.ts +11 -2
- package/documentation/doc-util/doc-types.js +31 -9
- package/documentation/wiki-absint.d.ts +17 -2
- package/documentation/wiki-absint.js +83 -24
- package/documentation/wiki-analyzer.js +3 -4
- package/documentation/wiki-interface.js +22 -16
- package/documentation/wiki-mk/doc-context.d.ts +14 -1
- package/documentation/wiki-mk/doc-context.js +6 -0
- package/documentation/wiki-normalized-ast.d.ts +0 -9
- package/documentation/wiki-normalized-ast.js +9 -60
- package/linter/linter-rules.d.ts +4 -3
- package/linter/rules/problematic-inputs.d.ts +13 -7
- package/linter/rules/problematic-inputs.js +109 -60
- package/package.json +3 -3
- package/project/flowr-analyzer-builder.d.ts +6 -3
- package/project/flowr-analyzer-builder.js +12 -5
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.d.ts +4 -3
- package/project/plugins/file-plugins/files/flowr-rmarkdown-file.js +17 -4
- package/project/plugins/flowr-analyzer-plugin.d.ts +1 -1
- package/project/plugins/flowr-analyzer-plugin.js +1 -1
- package/queries/catalog/dependencies-query/function-info/read-functions.js +2 -0
- package/queries/catalog/dependencies-query/function-info/write-functions.js +1 -0
- package/queries/catalog/input-sources-query/input-source-functions.d.ts +7 -0
- package/queries/catalog/input-sources-query/input-source-functions.js +56 -0
- package/queries/catalog/input-sources-query/input-sources-query-executor.d.ts +1 -1
- package/queries/catalog/input-sources-query/input-sources-query-executor.js +19 -53
- package/queries/catalog/input-sources-query/input-sources-query-format.d.ts +2 -1
- package/queries/catalog/input-sources-query/input-sources-query-format.js +28 -11
- package/queries/catalog/input-sources-query/simple-input-classifier.d.ts +21 -42
- package/queries/catalog/input-sources-query/simple-input-classifier.js +168 -104
- package/r-bridge/data/data.d.ts +28 -2
- package/r-bridge/data/data.js +34 -2
- package/r-bridge/lang-4.x/ast/model/model.d.ts +5 -6
- package/r-bridge/lang-4.x/ast/model/model.js +0 -1
- package/r-bridge/lang-4.x/ast/model/nodes/r-access.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-argument.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-binary-op.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-break.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-comment.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-expression-list.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-for-loop.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-call.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-function-definition.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-if-then-else.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-line-directive.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-logical.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-next.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-number.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-parameter.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-pipe.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-repeat-loop.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-string.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-symbol.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-unary-op.d.ts +6 -6
- package/r-bridge/lang-4.x/ast/model/nodes/r-while-loop.d.ts +6 -6
- package/util/record.d.ts +18 -3
- package/util/record.js +22 -1
- package/util/version.js +1 -1
- package/abstract-interpretation/normalized-ast-fold.d.ts +0 -119
- package/abstract-interpretation/normalized-ast-fold.js +0 -181
- package/project/plugins/flowr-analyzer-plugin-defaults.d.ts +0 -5
- package/project/plugins/flowr-analyzer-plugin-defaults.js +0 -37
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WikiAbsint = void 0;
|
|
3
|
+
exports.WikiAbsint = exports.IntervalInferenceVisitor = void 0;
|
|
4
4
|
const absint_visitor_1 = require("../abstract-interpretation/absint-visitor");
|
|
5
5
|
const abstract_domain_1 = require("../abstract-interpretation/domains/abstract-domain");
|
|
6
|
+
const bounded_set_domain_1 = require("../abstract-interpretation/domains/bounded-set-domain");
|
|
6
7
|
const interval_domain_1 = require("../abstract-interpretation/domains/interval-domain");
|
|
7
8
|
const lattice_1 = require("../abstract-interpretation/domains/lattice");
|
|
9
|
+
const multi_value_state_domain_1 = require("../abstract-interpretation/domains/multi-value-state-domain");
|
|
8
10
|
const state_abstract_domain_1 = require("../abstract-interpretation/domains/state-abstract-domain");
|
|
9
11
|
const semantic_cfg_guided_visitor_1 = require("../control-flow/semantic-cfg-guided-visitor");
|
|
10
12
|
const identifier_1 = require("../dataflow/environments/identifier");
|
|
13
|
+
const graph_1 = require("../dataflow/graph/graph");
|
|
11
14
|
const cfg_kind_1 = require("../project/cfg-kind");
|
|
12
15
|
const flowr_analyzer_builder_1 = require("../project/flowr-analyzer-builder");
|
|
13
|
-
const r_function_call_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
|
|
14
16
|
const doc_code_1 = require("./doc-util/doc-code");
|
|
17
|
+
const doc_files_1 = require("./doc-util/doc-files");
|
|
15
18
|
const doc_structure_1 = require("./doc-util/doc-structure");
|
|
16
19
|
const doc_maker_1 = require("./wiki-mk/doc-maker");
|
|
17
20
|
class IntervalInferenceVisitor extends absint_visitor_1.AbstractInterpretationVisitor {
|
|
21
|
+
constructor(config) {
|
|
22
|
+
super(config, state_abstract_domain_1.StateAbstractDomain.top(interval_domain_1.IntervalDomain.top()));
|
|
23
|
+
}
|
|
18
24
|
onNumberConstant({ vertex, node }) {
|
|
19
25
|
super.onNumberConstant({ vertex, node });
|
|
20
26
|
const interval = new interval_domain_1.IntervalDomain([node.content.num, node.content.num]);
|
|
21
|
-
this.
|
|
27
|
+
this.currentState.set(node.info.id, interval);
|
|
22
28
|
}
|
|
23
29
|
onFunctionCall({ call }) {
|
|
24
30
|
super.onFunctionCall({ call });
|
|
25
|
-
if (call.args.length === 2 && call.args.every(
|
|
31
|
+
if (call.args.length === 2 && call.args.every(graph_1.FunctionArgument.isNotEmpty)) {
|
|
26
32
|
const left = this.getAbstractValue(call.args[0].nodeId, this.currentState);
|
|
27
33
|
const right = this.getAbstractValue(call.args[1].nodeId, this.currentState);
|
|
28
34
|
if (left === undefined || right === undefined) {
|
|
@@ -32,27 +38,28 @@ class IntervalInferenceVisitor extends absint_visitor_1.AbstractInterpretationVi
|
|
|
32
38
|
// We map the numerical operation to the resulting interval after applying the abstract semantics of the operation
|
|
33
39
|
switch (identifier_1.Identifier.getName(call.name)) {
|
|
34
40
|
case '+':
|
|
35
|
-
return this.
|
|
41
|
+
return this.currentState.set(call.id, left.add(right));
|
|
36
42
|
case '-':
|
|
37
|
-
return this.
|
|
43
|
+
return this.currentState.set(call.id, left.subtract(right));
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
}
|
|
41
47
|
}
|
|
48
|
+
exports.IntervalInferenceVisitor = IntervalInferenceVisitor;
|
|
42
49
|
async function inferIntervals() {
|
|
43
50
|
const analyzer = await new flowr_analyzer_builder_1.FlowrAnalyzerBuilder()
|
|
44
51
|
.setEngine('tree-sitter')
|
|
45
52
|
.build();
|
|
46
53
|
analyzer.addRequest(`
|
|
47
54
|
x <- 42
|
|
48
|
-
y <- if (runif() < 0.5) 6 else 12
|
|
55
|
+
y <- if (runif(1) < 0.5) 6 else 12
|
|
49
56
|
z <- x + y
|
|
50
57
|
`.trim());
|
|
51
58
|
const ast = await analyzer.normalize();
|
|
52
59
|
const dfg = (await analyzer.dataflow()).graph;
|
|
53
60
|
const cfg = await analyzer.controlflow(undefined, cfg_kind_1.CfgKind.NoFunctionDefs);
|
|
54
61
|
const ctx = analyzer.inspectContext();
|
|
55
|
-
const inference = new IntervalInferenceVisitor({ controlFlow: cfg, dfg: dfg, normalizedAst: ast, ctx: ctx }
|
|
62
|
+
const inference = new IntervalInferenceVisitor({ controlFlow: cfg, dfg: dfg, normalizedAst: ast, ctx: ctx });
|
|
56
63
|
inference.start();
|
|
57
64
|
const result = inference.getEndState();
|
|
58
65
|
return result.isValue() ? result.value.entries().toArray()
|
|
@@ -63,6 +70,21 @@ function nodeIdToSlicingCriterion(id, idMap) {
|
|
|
63
70
|
const node = idMap.get(id);
|
|
64
71
|
return `${node?.location?.[0]}@${node?.lexeme}`;
|
|
65
72
|
}
|
|
73
|
+
function multiValueExample() {
|
|
74
|
+
const domain = {
|
|
75
|
+
number: new interval_domain_1.IntervalDomain(interval_domain_1.IntervalTop),
|
|
76
|
+
string: new bounded_set_domain_1.BoundedSetDomain(lattice_1.Top)
|
|
77
|
+
};
|
|
78
|
+
const reduction = ({ number, string }) => {
|
|
79
|
+
if (number?.isBottom() || string?.isBottom()) {
|
|
80
|
+
return { number: domain.number.bottom(), string: domain.string.bottom() };
|
|
81
|
+
}
|
|
82
|
+
return { number, string };
|
|
83
|
+
};
|
|
84
|
+
const state = new multi_value_state_domain_1.MultiValueStateDomain(new Map(), domain, [reduction]);
|
|
85
|
+
state.setValue(0, 'number', new interval_domain_1.IntervalDomain([42, 42]));
|
|
86
|
+
state.setValue(1, 'string', new bounded_set_domain_1.BoundedSetDomain(new Set(['Hello world!'])));
|
|
87
|
+
}
|
|
66
88
|
class WikiAbsint extends doc_maker_1.DocMaker {
|
|
67
89
|
constructor() {
|
|
68
90
|
super('wiki/Abstract Interpretation.md', module.filename, 'abstract interpretation framework');
|
|
@@ -83,19 +105,19 @@ In _flowR_, an abstract domain is represented by the class ${ctx.link(abstract_d
|
|
|
83
105
|
* ${ctx.linkM(abstract_domain_1.AbstractDomain, 'value')} the current abstract value of the abstract domain
|
|
84
106
|
* ${ctx.linkM(abstract_domain_1.AbstractDomain, 'top')} to get the top element (greatest element) of the abstract domain
|
|
85
107
|
* ${ctx.linkM(abstract_domain_1.AbstractDomain, 'bottom')} to get the bottom element (least element) of the abstract domain
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
108
|
+
|
|
109
|
+
- ${ctx.linkM(abstract_domain_1.AbstractDomain, 'isTop')} to check whether the current abstract value is top
|
|
110
|
+
- ${ctx.linkM(abstract_domain_1.AbstractDomain, 'isBottom')} to check whether the current abstract value is bottom
|
|
111
|
+
- ${ctx.linkM(abstract_domain_1.AbstractDomain, 'isValue')} to check whether the current abstract value is a value (can still be top or bottom)
|
|
112
|
+
|
|
91
113
|
* ${ctx.linkM(abstract_domain_1.AbstractDomain, 'leq')} to check whether two abstract values are ordered with respect to the partial order of the lattice
|
|
92
114
|
* ${ctx.linkM(abstract_domain_1.AbstractDomain, 'join')} to join two abstract values to get the least upper bound (LUB)
|
|
93
115
|
* ${ctx.linkM(abstract_domain_1.AbstractDomain, 'meet')} to meet two abstract values to get the greates lower bound (GLB)
|
|
94
116
|
* ${ctx.linkM(abstract_domain_1.AbstractDomain, 'widen')} to perform widening with another abstract value to ensure termination of the fixpoint iteration
|
|
95
117
|
* ${ctx.linkM(abstract_domain_1.AbstractDomain, 'narrow')} to perform narrowing with another abstract value to refine the abstract value after widening
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
118
|
+
|
|
119
|
+
- ${ctx.linkM(abstract_domain_1.AbstractDomain, 'concretize')} representing the concretization function of the abstract domain
|
|
120
|
+
- ${ctx.linkM(abstract_domain_1.AbstractDomain, 'abstract')} representing the abstraction function of the abstract domain
|
|
99
121
|
|
|
100
122
|
${(0, doc_structure_1.details)('Class Diagram', `
|
|
101
123
|
All boxes link to their respective implementation in the source code.
|
|
@@ -104,7 +126,7 @@ ${(0, doc_code_1.codeBlock)('mermaid', ctx.mermaid(abstract_domain_1.AbstractDom
|
|
|
104
126
|
|
|
105
127
|
The ${ctx.link('Top')} and ${ctx.link('Bottom')} symbols can be used to explicitly represent the top or bottom elment of an abstract domain. Additionally, for value abstract domains, there is the ${ctx.link('SatisfiableDomain')} interface that provides the function ${ctx.link('SatisfiableDomain:::satisfies')} to check whether the current abstract value of the abstract domain satisfies a concrete value (see also ${ctx.link('NumericalComparator')} and ${ctx.link('SetComparator')}).
|
|
106
128
|
|
|
107
|
-
_flowR_ already provides different abstract domains for abstract interpretation in
|
|
129
|
+
_flowR_ already provides different abstract domains for abstract interpretation in ${(0, doc_files_1.linkFlowRSourceFile)('src/abstract-interpretation/domains')}. Many of the abstract domains are generic and can be used for differend kinds of analyses. The existing abstract domains are presented in the following. Some of the listed abstract domains can be expanded to show the inherited abstract domains.
|
|
108
130
|
|
|
109
131
|
${ctx.hierarchy(abstract_domain_1.AbstractDomain, { collapseFromNesting: 2, skipNesting: 1, reverse: true })}
|
|
110
132
|
|
|
@@ -113,30 +135,34 @@ All boxes link to their respective implementation in the source code.
|
|
|
113
135
|
${(0, doc_code_1.codeBlock)('mermaid', ctx.mermaid(abstract_domain_1.AbstractDomain, { simplify: true, reverse: true }))}
|
|
114
136
|
`.trim())}
|
|
115
137
|
|
|
138
|
+
Multiple abstract domains can be combined using a ${ctx.link(multi_value_state_domain_1.MultiValueDomain)} (for example, to use an interval domain for numbers and bounded set domain for strings at the same time). A multi-value state domain (${ctx.link(multi_value_state_domain_1.MultiValueStateDomain)}) as state domain of a multi-value domain can be used to track the state of multiple value domains in a program. Additionally, is enables to define reductions on the multi-value domain to refine the inferred value for a value domain based on the other value domains in the multi-value domain. For example, the following example shows how a multi-value state domain can be defined to track numbers and strings at the same time with a simple reduction that sets both domains to bottom if one domain is bottom.
|
|
139
|
+
|
|
140
|
+
${ctx.code(multiValueExample, { dropLinesStart: 1, dropLinesEnd: 1 })}
|
|
141
|
+
|
|
116
142
|
${(0, doc_structure_1.section)('Abstract Interpretation', 2, 'abstract-interpretation')}
|
|
117
143
|
|
|
118
144
|
We perform abstract interpretation by forward-traversing the ${ctx.linkPage('wiki/Control Flow Graph', 'control flow graph')} of _flowR_ using an ${ctx.link(absint_visitor_1.AbstractInterpretationVisitor)}. For each visited control flow vertex, the visitor retrieves the current abstract state by joining the abstract states of the predecessors, applies the abstract semantics of the visited control flow vertex to the current state, and updates the abstract state of the currently visited vertex to the current state. The visitor already handles assignments and (delayed) widening at widening points. However, the visitor does not yet support interprocedural abstract interpretation.
|
|
119
145
|
|
|
120
|
-
To implement a custom abstract interpretation analysis, we can just create a new class and extend the ${ctx.link(absint_visitor_1.AbstractInterpretationVisitor)}. The abstract interpretation visitor uses a ${ctx.link(state_abstract_domain_1.StateAbstractDomain)} to capture the current abstract state at each vertex in the control flow graph.
|
|
146
|
+
To implement a custom abstract interpretation analysis, we can just create a new class and extend the ${ctx.link(absint_visitor_1.AbstractInterpretationVisitor)}. The abstract interpretation visitor uses a \`StateDomain\` (e.g., a ${ctx.link(state_abstract_domain_1.StateAbstractDomain)}) to capture the current abstract state at each vertex in the control flow graph. We can then extend the callback functions of the ${ctx.link(absint_visitor_1.AbstractInterpretationVisitor)} to implement the abstract semantics of expressions, such as ${ctx.link(`${semantic_cfg_guided_visitor_1.SemanticCfgGuidedVisitor.name}:::onNumberConstant`)}, ${ctx.link(`${absint_visitor_1.AbstractInterpretationVisitor.name}:::onFunctionCall`)} and ${ctx.link(`${semantic_cfg_guided_visitor_1.SemanticCfgGuidedVisitor.name}:::onReplacementCall`)} (make sure to still call the respective super function). The abstract interpretation visitor provides the following functions to retrieve the currently inferred values:
|
|
121
147
|
|
|
122
148
|
* ${ctx.linkM(absint_visitor_1.AbstractInterpretationVisitor, 'getAbstractValue')} to resolve the inferred abstract value for an AST node (this includes resolving symbols, pipes, and if expressions)
|
|
123
149
|
* ${ctx.linkM(absint_visitor_1.AbstractInterpretationVisitor, 'getAbstractState')} to get the inferred abstract state at an AST node mapping AST nodes to abstract values
|
|
124
150
|
* ${ctx.linkM(absint_visitor_1.AbstractInterpretationVisitor, 'getAbstractTrace')} to get the complete abstract trace mapping AST nodes to abstract states at the respective node
|
|
125
151
|
* ${ctx.linkM(absint_visitor_1.AbstractInterpretationVisitor, 'getEndState')} to get the inferred abstract state at the end of the program (at the exit points of the control flow graph)
|
|
126
152
|
|
|
127
|
-
For example, if we want to perform a (very basic) interval analysis using abstract interpretation in _flowR_, we can implement the following ${ctx.link(IntervalInferenceVisitor)} that extends ${ctx.link(absint_visitor_1.AbstractInterpretationVisitor)} using the ${ctx.link(interval_domain_1.IntervalDomain)}:
|
|
153
|
+
For example, if we want to perform a (very basic) interval analysis using abstract interpretation in _flowR_, we can implement the following ${ctx.link(IntervalInferenceVisitor)} that extends ${ctx.link(absint_visitor_1.AbstractInterpretationVisitor)} using a ${ctx.link(state_abstract_domain_1.StateAbstractDomain)} for the ${ctx.link(interval_domain_1.IntervalDomain)}:
|
|
128
154
|
|
|
129
|
-
${ctx.code(IntervalInferenceVisitor)}
|
|
155
|
+
${ctx.code(IntervalInferenceVisitor, { hideDefinedAt: true })}
|
|
130
156
|
|
|
131
|
-
The interval inference visitor first overrides the ${ctx.link(`${semantic_cfg_guided_visitor_1.SemanticCfgGuidedVisitor.name}:::onNumberConstant`)} function to infer intervals for visited control flow vertices that represent numeric constants. For numeric constants, the resulting interval consists just of the number value of the constant. We then update the current abstract state of the visitor
|
|
157
|
+
The interval inference visitor first overrides the ${ctx.link(`${semantic_cfg_guided_visitor_1.SemanticCfgGuidedVisitor.name}:::onNumberConstant`)} function to infer intervals for visited control flow vertices that represent numeric constants. For numeric constants, the resulting interval consists just of the number value of the constant. We then update the current abstract state of the visitor by setting the inferred abstract value of the currently visited control flow vertex to the new interval.
|
|
132
158
|
|
|
133
|
-
In this simple example, we only want to support the addition and subtraction of numeric values. Therefore, we override the ${ctx.link(`${absint_visitor_1.AbstractInterpretationVisitor.name}:::onFunctionCall`)} function to apply the abstract semantics of additions and subtraction with resprect to the interval domain. For the addition and subtraction, we are only interested in function calls with exactly two non-empty arguments. We first resolve the currently inferred abstract value for the left and right operand of the function call. If we have
|
|
159
|
+
In this simple example, we only want to support the addition and subtraction of numeric values. Therefore, we override the ${ctx.link(`${absint_visitor_1.AbstractInterpretationVisitor.name}:::onFunctionCall`)} function to apply the abstract semantics of additions and subtraction with resprect to the interval domain. For the addition and subtraction, we are only interested in function calls with exactly two non-empty arguments. We first resolve the currently inferred abstract value for the left and right operand of the function call. If we have not inferred a value for one of the operands, this function call might not be a numeric function call and we ignore it. Otherwise, we check whether the function call represents an addition or subtraction and apply the abstract semantics of the operation to the left and right operand. We then again update the current abstract state of the visitor by setting the inferred abstract value of the currently visited function call vertex to the abstract value resulting from applying the abstract semantics of the operation to the operands.
|
|
134
160
|
|
|
135
161
|
If we now want to run the interval inference, we can write the following code:
|
|
136
162
|
|
|
137
|
-
${ctx.code(inferIntervals, { dropLinesStart: 1, dropLinesEnd: 5 })}
|
|
163
|
+
${ctx.code(inferIntervals, { dropLinesStart: 1, dropLinesEnd: 5, hideDefinedAt: true })}
|
|
138
164
|
|
|
139
|
-
We first need a ${ctx.linkPage('wiki/Analyzer', 'flowR analyzer')} (in this case, using the ${ctx.linkPage('wiki/Engines', 'tree-sitter engine')}). In this example, we want to analyze a small example code that assigns \`42\` to the variable \`x\`, randomly assigns \`6\` or \`12\` to the variable \`y\`, and assignes the sum of \`x\` and \`y\` to the variable \`z\`. For the abstract interpretation visitor, we need to retrieve the ${ctx.linkPage('wiki/Normalized AST', 'normalized AST')}, ${ctx.linkPage('wiki/Dataflow Graph', 'dataflow graph')}, ${ctx.linkPage('wiki/Control Flow Graph', 'control flow graph')}, context of the flowR anaylzer
|
|
165
|
+
We first need a ${ctx.linkPage('wiki/Analyzer', 'flowR analyzer')} (in this case, using the ${ctx.linkPage('wiki/Engines', 'tree-sitter engine')}). In this example, we want to analyze a small example code that assigns \`42\` to the variable \`x\`, randomly assigns \`6\` or \`12\` to the variable \`y\`, and assignes the sum of \`x\` and \`y\` to the variable \`z\`. For the abstract interpretation visitor, we need to retrieve the ${ctx.linkPage('wiki/Normalized AST', 'normalized AST')}, ${ctx.linkPage('wiki/Dataflow Graph', 'dataflow graph')}, ${ctx.linkPage('wiki/Control Flow Graph', 'control flow graph')}, and context of the flowR anaylzer. For performance reasons, we construct the control flow graph without simplification passes, data flow information, and function definitions. We then create a new ${ctx.link(IntervalInferenceVisitor)} using the control flow graph, dataflow graph, normalized AST, and analyzer context, and start the visitor using ${ctx.linkM(absint_visitor_1.AbstractInterpretationVisitor, 'start', { hideClass: true })}. After the visitor is finished, we retrieve the inferred abstract state at the end of the program using ${ctx.linkM(absint_visitor_1.AbstractInterpretationVisitor, 'getEndState', { hideClass: true })}.
|
|
140
166
|
|
|
141
167
|
If we now print the inferred abstract state at the end of the program, we get the following output:
|
|
142
168
|
|
|
@@ -144,6 +170,39 @@ ${(0, doc_code_1.codeBlock)('ts', await inferIntervals())}
|
|
|
144
170
|
<i>The output has been prettified for better readability.</i>
|
|
145
171
|
|
|
146
172
|
The AST nodes are represented as slicing criteria for better readability in the format \`<line>@<lexeme>\`. Here, the constants \`42\`, \`0.5\`, \`6\`, and \`12\` of line 1 and 2 are mapped to the intervals \`[42, 42]\`, \`[0.5, 0.5]\`, \`[6, 6]\`, and \`[12, 12]\`, respectively. The variable \`x\` of line 1 is mapped to the interval \`[42, 42]\` of the assigned value and the variable \`y\` of line 2 is assigned to the interval \`[6, 12]\` representing a sound over-approximation of the actual value, as the assigned value can be \`6\` or \`12\`. After applying the abstract semantics of the addition of \`x\` and \`y\`, the addition operation \`+\` and the variable \`z\` of line 3 are mapped to the interval \`[48, 54]\`, resulting from the addition of the interval \`[42, 42]\` of \`x\` and \`[6, 12]\` of \`y\`.
|
|
173
|
+
|
|
174
|
+
${(0, doc_structure_1.section)('Testing', 2, 'testing')}
|
|
175
|
+
|
|
176
|
+
_flowR_ provides a generic testing framework for abstract interpretation in ${(0, doc_files_1.linkFlowRSourceFile)('test/functionality/abstract-interpretation/inference.ts')}. The framework supports two kinds of tests for testing inferred abstract domain values at given source code locations (as ${ctx.link('SlicingCriteria')}):
|
|
177
|
+
|
|
178
|
+
1. **Assertion tests** — compare the inferred values against manually specified expected values (${ctx.link('assertInferredValues')}).
|
|
179
|
+
2. **Validation tests** — run the code to output the actual value at each location and compare the inferred values against the actual values (${ctx.link('validateInferredValues')}).
|
|
180
|
+
|
|
181
|
+
The test function ${ctx.link('testInferredValues')} combines both tests: it performs an assertion test when an ${ctx.link('InferenceTestCase')} record of expected values is provided, and a validation test (unless the option \`skipRun\` is set). When only a list of slicing criteria is provided instead of a ${ctx.link('InferenceTestCase')}, only the validation test is performed. For the validation test, it is required that all slicing criteria represent symbols, as the instrumentation of the code adds print statements for each symbol location after the code line of the symbol. The function takes the following arguments:
|
|
182
|
+
|
|
183
|
+
* \`name\` — the name or label of the test
|
|
184
|
+
* \`shell\` — the R shell to use for the validation test
|
|
185
|
+
* \`code\` — the R code to analyse and (for validation) to execute
|
|
186
|
+
* \`expected\` — an ${ctx.link('InferenceTestCase')} mapping slicing criteria to expected abstract values, or a list of slicing criteria for validation-only tests
|
|
187
|
+
* \`inference\` — a function that takes an ${ctx.link('AbsintVisitorConfiguration')} and returns an ${ctx.link(absint_visitor_1.AbstractInterpretationVisitor)} to perform the inference
|
|
188
|
+
* \`createOutputCode\` — a function \`(marker, symbol) => string\` that returns R code printing the analyzed properties of \`symbol\` in a line prefixed with \`marker\`
|
|
189
|
+
* \`parseOutput\` — a function \`(line) => Domain | undefined\` that parses the output line produced by \`createOutputCode\` into an abstract domain value
|
|
190
|
+
* \`options\` — optional inference test settings (_flowR_ configuration, additional project files, domain matching type, \`skipRun\`, etc.)
|
|
191
|
+
|
|
192
|
+
Additionally, ${ctx.link('assertInferredValues')} and ${ctx.link('validateInferredValues')} are available to only perform the assertions for assertion tests or validation tests without wrapping them into a test case.
|
|
193
|
+
|
|
194
|
+
When comparing inferred values with expected values, the framework supports two matching types via ${ctx.link('DomainMatchingType')}:
|
|
195
|
+
|
|
196
|
+
* ${ctx.link('DomainMatchingType::Equal')} — the inferred value must equal the expected value (default for assertion tests)
|
|
197
|
+
* ${ctx.link('DomainMatchingType::Overapproximation')} — the inferred value must be an over-approximation of the actual value via ${ctx.linkM(abstract_domain_1.AbstractDomain, 'leq')} (default for validation tests)
|
|
198
|
+
|
|
199
|
+
For example, to use the test framework for the ${ctx.link(IntervalInferenceVisitor)} defined above, we first define how to print the properties of an actual numeric scalar value in R using \`createOutputCode\` and how to parse it into an abstract domain value using \`parseOutput\`. Then, we can use ${ctx.link('testInferredValues')} to create a test for our code example by providing a test name, an R shell, the code to test, the test locations as slicing criteria with expected values, the inference visitor, and our \`createOutputCode\` and \`parseOutput\` function:
|
|
200
|
+
|
|
201
|
+
${ctx.codeFile('test/functionality/abstract-interpretation/wiki-absint.ts', { skipImports: true, hideDefinedAt: true })}
|
|
202
|
+
|
|
203
|
+
The assertion test verifies that the inferred intervals match the specified expected values exactly (using ${ctx.link('DomainMatchingType::Equal')}). The validation test instruments the code by inserting print statements after each tested location, executes the instrumented code with the R shell, and checks that each inferred interval at these locations is an over-approximation of the actual runtime value (using ${ctx.link('DomainMatchingType::Overapproximation')}). For example, the inferred interval \`[6, 12]\` for \`y\` is a sound over-approximation of the actual value \`6\` or \`12\`, depending on the random branch taken at runtime.
|
|
204
|
+
|
|
205
|
+
For an existing example of the test framework used in practice, see the data frame shape inference tests in ${(0, doc_files_1.linkFlowRSourceFile)('test/functionality/abstract-interpretation/data-frame/inference.test.ts')}, which use a domain-specific wrapper ${ctx.link('testInferredDataFrameShape')} built on top of ${ctx.link('testInferredValues')}.
|
|
147
206
|
`;
|
|
148
207
|
}
|
|
149
208
|
}
|
|
@@ -22,7 +22,6 @@ const flowr_analyzer_loading_order_context_1 = require("../project/context/flowr
|
|
|
22
22
|
const flowr_analyzer_dependencies_context_1 = require("../project/context/flowr-analyzer-dependencies-context");
|
|
23
23
|
const flowr_analyzer_cache_1 = require("../project/cache/flowr-analyzer-cache");
|
|
24
24
|
const pipeline_executor_1 = require("../core/pipeline-executor");
|
|
25
|
-
const flowr_analyzer_plugin_defaults_1 = require("../project/plugins/flowr-analyzer-plugin-defaults");
|
|
26
25
|
const doc_maker_1 = require("./wiki-mk/doc-maker");
|
|
27
26
|
const flowr_analyzer_rmd_file_plugin_1 = require("../project/plugins/file-plugins/notebooks/flowr-analyzer-rmd-file-plugin");
|
|
28
27
|
const flowr_analyzer_plugin_1 = require("../project/plugins/flowr-analyzer-plugin");
|
|
@@ -219,7 +218,7 @@ This indicates three ways to add a new plugin:
|
|
|
219
218
|
3. By providing a tuple of the plugin name and its constructor arguments (e.g., \`['file:rmd', [/.*.rmd/i]]\` for the ${ctx.link(flowr_analyzer_rmd_file_plugin_1.FlowrAnalyzerRmdFilePlugin)}).\\
|
|
220
219
|
This will also use the ${ctx.link(plugin_registry_1.makePlugin)} function under the hood to create the plugin instance.
|
|
221
220
|
|
|
222
|
-
Please note, that by passing \`false\` to the builder constructor, no default plugins (see ${ctx.link(
|
|
221
|
+
Please note, that by passing \`false\` to the builder constructor, no default plugins (see ${ctx.link('FlowrDefaultPlugins')}) are registered (otherwise, all of the plugins in the example above would be registered by default).
|
|
223
222
|
If you want to unregister specific plugins, you can use the ${ctx.linkM(flowr_analyzer_builder_1.FlowrAnalyzerBuilder, 'unregisterPlugins')} method.
|
|
224
223
|
|
|
225
224
|
${(0, doc_structure_1.block)({
|
|
@@ -251,7 +250,7 @@ Plugins allow you to extend the capabilities of the analyzer in many different w
|
|
|
251
250
|
For example, they can be used to support other file formats, or to provide new algorithms to determine the loading order of files in a project.
|
|
252
251
|
All plugins have to extend the ${ctx.link(flowr_analyzer_plugin_1.FlowrAnalyzerPlugin)} base class and specify their ${ctx.link('PluginType')}.
|
|
253
252
|
During the analysis, the analyzer will apply all registered plugins of the different types at the appropriate stages of the analysis.
|
|
254
|
-
If you just want to _use_ these plugins, you can usually ignore their [type](#plugin-types) and just register them with the builder as described
|
|
253
|
+
If you just want to _use_ these plugins, you can usually ignore their [type](#plugin-types) and just register them with the builder as described
|
|
255
254
|
in the [Builder Configuration](#builder-configuration) section above.
|
|
256
255
|
However, if you want to _create_ new plugins, you should be aware of the different plugin types and when they are applied during the analysis.
|
|
257
256
|
|
|
@@ -285,7 +284,7 @@ ${(0, doc_structure_1.section)('Project Discovery', 4)}
|
|
|
285
284
|
|
|
286
285
|
These plugins trigger when confronted with a project analysis request (see, ${ctx.link('RProjectAnalysisRequest')}).
|
|
287
286
|
Their job is to identify the files that belong to the project and add them to the analysis.
|
|
288
|
-
flowR provides the ${ctx.link(flowr_analyzer_project_discovery_plugin_1.FlowrAnalyzerProjectDiscoveryPlugin)} with a
|
|
287
|
+
flowR provides the ${ctx.link(flowr_analyzer_project_discovery_plugin_1.FlowrAnalyzerProjectDiscoveryPlugin)} with a
|
|
289
288
|
${ctx.link(flowr_analyzer_project_discovery_plugin_1.FlowrAnalyzerProjectDiscoveryPlugin.defaultPlugin.name)} as the default implementation that simply collects all R source files in the given folder.
|
|
290
289
|
|
|
291
290
|
Please note that all project discovery plugins should conform to the ${ctx.link(flowr_analyzer_project_discovery_plugin_1.FlowrAnalyzerProjectDiscoveryPlugin)} base class.
|
|
@@ -20,6 +20,7 @@ const doc_structure_1 = require("./doc-util/doc-structure");
|
|
|
20
20
|
const doc_maker_1 = require("./wiki-mk/doc-maker");
|
|
21
21
|
const doc_writing_code_1 = require("./data/interface/doc-writing-code");
|
|
22
22
|
const built_in_proc_name_1 = require("../dataflow/environments/built-in-proc-name");
|
|
23
|
+
const flowr_analyzer_1 = require("../project/flowr-analyzer");
|
|
23
24
|
async function explainServer(parser) {
|
|
24
25
|
(0, doc_data_server_messages_1.documentAllServerMessages)();
|
|
25
26
|
return `
|
|
@@ -42,7 +43,7 @@ ${await (0, doc_server_message_1.printServerMessages)(parser)}
|
|
|
42
43
|
### 📡 Ways of Connecting
|
|
43
44
|
|
|
44
45
|
If you are interested in clients that communicate with _flowR_, please check out the [R adapter](${doc_files_1.FlowrGithubBaseRef}/flowr-r-adapter)
|
|
45
|
-
as well as the [Visual Studio Code extension](${doc_files_1.FlowrGithubBaseRef}/vscode-flowr).
|
|
46
|
+
as well as the [Visual Studio Code extension](${doc_files_1.FlowrGithubBaseRef}/vscode-flowr).
|
|
46
47
|
|
|
47
48
|
<ol>
|
|
48
49
|
|
|
@@ -99,9 +100,9 @@ async function explainRepl(parser, ctx) {
|
|
|
99
100
|
> To execute arbitrary R commands with a repl request, _flowR_ has to be started explicitly with ${ctx.cliOption('flowr', 'r-session-access')}.
|
|
100
101
|
> Please be aware that this introduces a security risk and note that this relies on the ${ctx.linkPage('wiki/Engines', '`r-shell` engine')} .
|
|
101
102
|
|
|
102
|
-
Although primarily meant for users to explore,
|
|
103
|
-
there is nothing which forbids simply calling _flowR_ as a subprocess to use standard-in, -output, and -error
|
|
104
|
-
for communication (although you can access the REPL using the server as well,
|
|
103
|
+
Although primarily meant for users to explore,
|
|
104
|
+
there is nothing which forbids simply calling _flowR_ as a subprocess to use standard-in, -output, and -error
|
|
105
|
+
for communication (although you can access the REPL using the server as well,
|
|
105
106
|
with the [REPL Request](#message-request-repl-execution) message).
|
|
106
107
|
|
|
107
108
|
The read-eval-print loop (REPL) works relatively simple.
|
|
@@ -111,7 +112,7 @@ The best command to get started with the REPL is ${ctx.replCmd('help')}.
|
|
|
111
112
|
Besides, you can leave the REPL either with the command ${ctx.replCmd('quit')} or by pressing <kbd>Ctrl</kbd>+<kbd>C</kbd> twice.
|
|
112
113
|
When writing a *command*, you may press <kbd>Tab</kbd> to get a list of completions, if available.
|
|
113
114
|
Multiple commands can be entered in a single line by separating them with a semicolon (\`;\`), e.g. \`:parse "x<-2"; :df*\`.
|
|
114
|
-
If a command is given without R code, the REPL will re-use R code given in a previous command.
|
|
115
|
+
If a command is given without R code, the REPL will re-use R code given in a previous command.
|
|
115
116
|
The prior example will hence return first the parsed AST of the program and then the dataflow graph for \`"x <- 2"\`.
|
|
116
117
|
|
|
117
118
|
> [!NOTE]
|
|
@@ -144,7 +145,7 @@ can be used to also modify the currently active configuration of _flowR_ within
|
|
|
144
145
|
|
|
145
146
|
### Example: Retrieving the Dataflow Graph
|
|
146
147
|
|
|
147
|
-
To retrieve a URL to the [mermaid](https://mermaid.js.org/) diagram of the dataflow of a given expression,
|
|
148
|
+
To retrieve a URL to the [mermaid](https://mermaid.js.org/) diagram of the dataflow of a given expression,
|
|
148
149
|
use ${ctx.replCmd('dataflow*')} (or ${ctx.replCmd('dataflow')} to get the mermaid code in the cli):
|
|
149
150
|
|
|
150
151
|
${await (0, doc_repl_1.documentReplSession)(parser, [{
|
|
@@ -163,8 +164,8 @@ For the slicing with ${ctx.replCmd('slicer')}, you have access to the same [magi
|
|
|
163
164
|
|
|
164
165
|
### Example: Interfacing with the File System
|
|
165
166
|
|
|
166
|
-
Many commands that allow for an R-expression (like ${ctx.replCmd('dataflow*')}) allow for a file as well
|
|
167
|
-
if the argument starts with \`${retriever_1.fileProtocol}\`.
|
|
167
|
+
Many commands that allow for an R-expression (like ${ctx.replCmd('dataflow*')}) allow for a file as well
|
|
168
|
+
if the argument starts with \`${retriever_1.fileProtocol}\`.
|
|
168
169
|
If you are working from the root directory of the _flowR_ repository, the following gives you the parsed AST of the example file using the ${ctx.replCmd('parse')} command:
|
|
169
170
|
|
|
170
171
|
${await (0, doc_repl_1.documentReplSession)(parser, [{
|
|
@@ -179,7 +180,7 @@ ${(0, doc_code_1.codeBlock)('r', (0, doc_files_1.getFileContentFromRoot)('test/t
|
|
|
179
180
|
|
|
180
181
|
</details>
|
|
181
182
|
|
|
182
|
-
As _flowR_ directly transforms this AST the output focuses on being human-readable instead of being machine-readable.
|
|
183
|
+
As _flowR_ directly transforms this AST the output focuses on being human-readable instead of being machine-readable.
|
|
183
184
|
`
|
|
184
185
|
}])}
|
|
185
186
|
|
|
@@ -203,8 +204,8 @@ For more information on the available queries, please check out the ${ctx.linkPa
|
|
|
203
204
|
function explainConfigFile(ctx) {
|
|
204
205
|
return `
|
|
205
206
|
|
|
206
|
-
When running _flowR_, you may want to specify some behaviors with a dedicated configuration file.
|
|
207
|
-
By default, flowR looks for a file named \`${flowr_main_options_1.defaultConfigFile}\` in the current working directory (or any higher directory).
|
|
207
|
+
When running _flowR_, you may want to specify some behaviors with a dedicated configuration file.
|
|
208
|
+
By default, flowR looks for a file named \`${flowr_main_options_1.defaultConfigFile}\` in the current working directory (or any higher directory).
|
|
208
209
|
You can also specify a different file with ${(0, doc_cli_option_1.getCliLongOptionOf)('flowr', 'config-file')} or pass the configuration inline using ${(0, doc_cli_option_1.getCliLongOptionOf)('flowr', 'config-json')}.
|
|
209
210
|
To inspect the current configuration, you can run flowr with the ${(0, doc_cli_option_1.getCliLongOptionOf)('flowr', 'verbose')} flag, or use the \`config\` [Query](${doc_files_1.FlowrWikiBaseRef}/Query%20API).
|
|
210
211
|
Within the REPL this works by running the following:
|
|
@@ -216,13 +217,15 @@ ${ctx.linkO(config_1.FlowrConfig, 'amend')}.
|
|
|
216
217
|
The following summarizes the configuration options:
|
|
217
218
|
|
|
218
219
|
- \`ignoreSourceCalls\`: If set to \`true\`, _flowR_ will ignore source calls when analyzing the code, i.e., ignoring the inclusion of other files.
|
|
219
|
-
- \`semantics\`: allows to configure the way _flowR_ handles R, although we currently only support \`semantics/environment/overwriteBuiltIns\`.
|
|
220
|
-
You may use this to overwrite _flowR_'s handling of built-in function and even completely clear the preset definitions shipped with flowR.
|
|
220
|
+
- \`semantics\`: allows to configure the way _flowR_ handles R, although we currently only support \`semantics/environment/overwriteBuiltIns\`.
|
|
221
|
+
You may use this to overwrite _flowR_'s handling of built-in function and even completely clear the preset definitions shipped with flowR.
|
|
221
222
|
See [Configure BuiltIn Semantics](#configure-builtin-semantics) for more information.
|
|
222
223
|
- \`solver\`: allows to configure how _flowR_ resolves variables and their values (currently we support: ${Object.values(config_1.VariableResolve).map(v => `\`${v}\``).join(', ')}), as well as if pointer analysis should be active.
|
|
223
224
|
- \`engines\`: allows to configure the engines used by _flowR_ to interact with R code. See the [Engines wiki page](${doc_files_1.FlowrWikiBaseRef}/Engines) for more information.
|
|
224
225
|
- \`defaultEngine\`: allows to specify the default engine to use for interacting with R code. If not set, an arbitrary engine from the specified list will be used.
|
|
225
226
|
- \`abstractInterpretation\`: allows to configure how _flowR_ performs abstract interpretation, although we currently only support data frame shape inference through abstract interpretation.
|
|
227
|
+
- \`defaultPlugins\`: allows to configure which plugins to load by default when creating a new ${ctx.link(flowr_analyzer_1.FlowrAnalyzer)} instance.
|
|
228
|
+
- \`repl.plugins\`: allows to configure which plugins to load in the _flowR_ REPL. Use \`flowr:default\` to reference the plugins specified by \`defaultPlugins\`.
|
|
226
229
|
|
|
227
230
|
So you can configure _flowR_ by adding a file like the following:
|
|
228
231
|
|
|
@@ -241,9 +244,11 @@ ${(0, doc_code_1.codeBlock)('json', JSON.stringify({
|
|
|
241
244
|
}
|
|
242
245
|
}
|
|
243
246
|
},
|
|
247
|
+
defaultPlugins: ['file:description', 'versions:description'],
|
|
244
248
|
repl: {
|
|
245
249
|
quickStats: false,
|
|
246
|
-
dfProcessorHeat: false
|
|
250
|
+
dfProcessorHeat: false,
|
|
251
|
+
plugins: ['flowr:default']
|
|
247
252
|
},
|
|
248
253
|
project: {
|
|
249
254
|
resolveUnknownPathsOnDisk: true
|
|
@@ -252,6 +257,7 @@ ${(0, doc_code_1.codeBlock)('json', JSON.stringify({
|
|
|
252
257
|
solver: {
|
|
253
258
|
variables: config_1.VariableResolve.Alias,
|
|
254
259
|
evalStrings: true,
|
|
260
|
+
trackEnvironments: true,
|
|
255
261
|
resolveSource: {
|
|
256
262
|
dropPaths: config_1.DropPathsOption.No,
|
|
257
263
|
ignoreCapitalization: true,
|
|
@@ -277,9 +283,9 @@ ${(0, doc_code_1.codeBlock)('json', JSON.stringify({
|
|
|
277
283
|
|
|
278
284
|
</details>
|
|
279
285
|
|
|
280
|
-
<details>
|
|
286
|
+
<details>
|
|
281
287
|
<a id='configure-builtin-semantics'></a>
|
|
282
|
-
<summary>Configure Built-In Semantics</summary>
|
|
288
|
+
<summary>Configure Built-In Semantics</summary>
|
|
283
289
|
|
|
284
290
|
|
|
285
291
|
\`semantics/environment/overwriteBuiltins\` accepts two keys:
|
|
@@ -179,7 +179,7 @@ export interface GeneralDocContext {
|
|
|
179
179
|
* @param filter - An optional filter to further specify the element to get the code for, in case multiple elements with the same name exist.
|
|
180
180
|
* @example
|
|
181
181
|
* ```ts
|
|
182
|
-
* code(exampleFn.name, { dropLinesStart: 1, dropLinesEnd: 2
|
|
182
|
+
* code(exampleFn.name, { dropLinesStart: 1, dropLinesEnd: 2 })
|
|
183
183
|
* ```
|
|
184
184
|
*
|
|
185
185
|
* Creates a code snippet for the `exampleFn` function in the code base,
|
|
@@ -203,6 +203,19 @@ export interface GeneralDocContext {
|
|
|
203
203
|
* @see {@link printCodeOfElement} - for the underlying impl.
|
|
204
204
|
*/
|
|
205
205
|
code(element: ElementIdOrRef, fmt?: Omit<FnElementInfo, 'info' | 'program'>, filter?: ElementFilter): string;
|
|
206
|
+
/**
|
|
207
|
+
* Returns the code snippet for a code file as markdown string.
|
|
208
|
+
* @param path - The path to the file to create a code snippet for.
|
|
209
|
+
* @param fmt - Formatting options for the code snippet (see {@link FnElementInfo})
|
|
210
|
+
* @example
|
|
211
|
+
* ```ts
|
|
212
|
+
* code('src/path/to/file.ts', { skipImports: true })
|
|
213
|
+
* ```
|
|
214
|
+
*
|
|
215
|
+
* Creates a code snippet for the source file `src/path/to/file.ts`,
|
|
216
|
+
* dropping the lines with import statements of the source code.
|
|
217
|
+
*/
|
|
218
|
+
codeFile(path: string, fmt?: Omit<FnElementInfo, 'info' | 'program'>): string;
|
|
206
219
|
/**
|
|
207
220
|
* Returns the hierarchy (e.g., class inheritance) for a code element as markdown string,
|
|
208
221
|
* including their documentation and snippets.
|
|
@@ -88,6 +88,12 @@ function makeDocContextForTypes(shell, ...rootFolders) {
|
|
|
88
88
|
...fmt,
|
|
89
89
|
}, getNameFromElementIdOrRef(element));
|
|
90
90
|
},
|
|
91
|
+
codeFile(path, fmt) {
|
|
92
|
+
return (0, doc_types_1.printCodeOfFile)({
|
|
93
|
+
program, info,
|
|
94
|
+
...fmt,
|
|
95
|
+
}, path);
|
|
96
|
+
},
|
|
91
97
|
async header(filename, purpose) {
|
|
92
98
|
const rVersion = (await shell?.usedRVersion())?.format();
|
|
93
99
|
return (0, doc_auto_gen_1.autoGenHeader)({ filename, purpose, rVersion });
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import { DefaultNormalizedAstFold } from '../abstract-interpretation/normalized-ast-fold';
|
|
2
1
|
import type { DocMakerArgs } from './wiki-mk/doc-maker';
|
|
3
2
|
import { DocMaker } from './wiki-mk/doc-maker';
|
|
4
|
-
import type { RNumber } from '../r-bridge/lang-4.x/ast/model/nodes/r-number';
|
|
5
|
-
import { RBinaryOp } from '../r-bridge/lang-4.x/ast/model/nodes/r-binary-op';
|
|
6
|
-
export declare class MyMathFold<Info> extends DefaultNormalizedAstFold<number, Info> {
|
|
7
|
-
constructor();
|
|
8
|
-
protected concat(a: number, b: number): number;
|
|
9
|
-
foldRNumber(node: RNumber<Info>): number;
|
|
10
|
-
foldRBinaryOp(node: RBinaryOp<Info>): number;
|
|
11
|
-
}
|
|
12
3
|
/**
|
|
13
4
|
* https://github.com/flowr-analysis/flowr/wiki/Normalized-AST
|
|
14
5
|
*/
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WikiNormalizedAst =
|
|
3
|
+
exports.WikiNormalizedAst = void 0;
|
|
4
4
|
const doc_code_1 = require("./doc-util/doc-code");
|
|
5
5
|
const doc_normalized_ast_1 = require("./doc-util/doc-normalized-ast");
|
|
6
6
|
const doc_files_1 = require("./doc-util/doc-files");
|
|
7
7
|
const doc_cli_option_1 = require("./doc-util/doc-cli-option");
|
|
8
8
|
const doc_structure_1 = require("./doc-util/doc-structure");
|
|
9
|
-
const normalized_ast_fold_1 = require("../abstract-interpretation/normalized-ast-fold");
|
|
10
9
|
const flowr_analyzer_1 = require("../project/flowr-analyzer");
|
|
11
10
|
const flowr_analyzer_builder_1 = require("../project/flowr-analyzer-builder");
|
|
12
11
|
const flowr_file_1 = require("../project/context/flowr-file");
|
|
@@ -16,6 +15,7 @@ const r_binary_op_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-binary-op"
|
|
|
16
15
|
const model_1 = require("../r-bridge/lang-4.x/ast/model/model");
|
|
17
16
|
const r_project_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-project");
|
|
18
17
|
const r_expression_list_1 = require("../r-bridge/lang-4.x/ast/model/nodes/r-expression-list");
|
|
18
|
+
const stateful_fold_1 = require("../r-bridge/lang-4.x/ast/model/processing/stateful-fold");
|
|
19
19
|
async function simpleNormalizedAst(code) {
|
|
20
20
|
const analyzer = await new flowr_analyzer_builder_1.FlowrAnalyzerBuilder().build();
|
|
21
21
|
analyzer.addRequest(code);
|
|
@@ -33,40 +33,6 @@ async function quickNormalizedAstMultipleFiles() {
|
|
|
33
33
|
const n = await analyzer.normalize();
|
|
34
34
|
return n;
|
|
35
35
|
}
|
|
36
|
-
class MyMathFold extends normalized_ast_fold_1.DefaultNormalizedAstFold {
|
|
37
|
-
constructor() {
|
|
38
|
-
/* use \`0\` as a placeholder empty for the monoid */
|
|
39
|
-
super(0);
|
|
40
|
-
}
|
|
41
|
-
concat(a, b) {
|
|
42
|
-
/* for this example, we ignore cases that we cannot handle */
|
|
43
|
-
return b;
|
|
44
|
-
}
|
|
45
|
-
foldRNumber(node) {
|
|
46
|
-
/* return the value of the number */
|
|
47
|
-
return node.content.num;
|
|
48
|
-
}
|
|
49
|
-
foldRBinaryOp(node) {
|
|
50
|
-
if (node.operator === '+') {
|
|
51
|
-
return this.fold(node.lhs) + this.fold(node.rhs);
|
|
52
|
-
}
|
|
53
|
-
else if (node.operator === '*') {
|
|
54
|
-
return this.fold(node.lhs) * this.fold(node.rhs);
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
/* in case we cannot handle the operator we could throw an error, or just use the default behavior: */
|
|
58
|
-
return super.foldRBinaryOp(node);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
exports.MyMathFold = MyMathFold;
|
|
63
|
-
async function useMyMathFoldExample() {
|
|
64
|
-
const analyzer = await new flowr_analyzer_builder_1.FlowrAnalyzerBuilder().build();
|
|
65
|
-
analyzer.addRequest('1 + 3 * 2');
|
|
66
|
-
const normalize = await analyzer.normalize();
|
|
67
|
-
const result = new MyMathFold().fold(normalize.ast);
|
|
68
|
-
return result;
|
|
69
|
-
}
|
|
70
36
|
/**
|
|
71
37
|
* https://github.com/flowr-analysis/flowr/wiki/Normalized-AST
|
|
72
38
|
*/
|
|
@@ -134,7 +100,7 @@ ${(0, doc_structure_1.details)('Normalized AST Node Types', ctx.hierarchy(model_
|
|
|
134
100
|
The following segments intend to give you an overview of how to work with the normalized AST:
|
|
135
101
|
|
|
136
102
|
* [How to get a Normalized AST](#how-to-get-a-normalized-ast)
|
|
137
|
-
* [
|
|
103
|
+
* [Traversing the Normalized AST](#traversing-the-normalized-ast)
|
|
138
104
|
|
|
139
105
|
> [!TIP]
|
|
140
106
|
> If you want to get more information on roxygen comments attached to AST nodes,
|
|
@@ -169,8 +135,8 @@ ${(0, doc_normalized_ast_1.printNormalizedAst)((await quickNormalizedAstMultiple
|
|
|
169
135
|
|
|
170
136
|
## Traversing the Normalized AST
|
|
171
137
|
|
|
172
|
-
We provide
|
|
173
|
-
Please note, that
|
|
138
|
+
We provide a visitor to traverse the normalized AST.
|
|
139
|
+
Please note, that it usually operates on the ${ctx.link('RExpressionList')} level, and it is up to
|
|
174
140
|
you to decide how you want to traverse multiple files with a ${ctx.link('RProject')} in the AST (you can, for example, simplify flat-map over the files).
|
|
175
141
|
The ${ctx.link('RProject')} node cannot appear nested within other nodes, so you can safely assume that any child of a node is not an ${ctx.link('RProject')}.
|
|
176
142
|
|
|
@@ -193,29 +159,12 @@ visitAst(nodes, node => {
|
|
|
193
159
|
ids.add(node.info.id);
|
|
194
160
|
});
|
|
195
161
|
return ids;
|
|
196
|
-
`)}
|
|
197
|
-
|
|
198
|
-
### Folds
|
|
199
|
-
|
|
200
|
-
We formulate a fold with the base class ${ctx.link(normalized_ast_fold_1.DefaultNormalizedAstFold)} in ${(0, doc_files_1.getFilePathMd)('../abstract-interpretation/normalized-ast-fold.ts')}.
|
|
201
|
-
Using this class, you can create your own fold behavior by overwriting the default methods.
|
|
202
|
-
By default, the class provides a monoid abstraction using the _empty_ from the constructor and the _concat_ method.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
${ctx.hierarchy(normalized_ast_fold_1.DefaultNormalizedAstFold)}
|
|
206
|
-
|
|
207
|
-
Now, of course, we could provide hundreds of examples here, but we use tests to verify that the fold behaves as expected
|
|
208
|
-
and happily point to them at ${(0, doc_files_1.getFilePathMd)('../../test/functionality/r-bridge/normalize-ast-fold.test.ts')}.
|
|
209
|
-
|
|
210
|
-
As a simple showcase, we want to use the fold to evaluate numeric expressions containing numbers, \`+\`, and \`*\` operators.
|
|
211
|
-
|
|
212
|
-
${ctx.code(MyMathFold, { dropLinesStart: 1 })}
|
|
162
|
+
`)}
|
|
213
163
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
${ctx.code(useMyMathFoldExample, { dropLinesStart: 1, dropLinesEnd: 2, hideDefinedAt: true })}
|
|
164
|
+
### Stateful Fold
|
|
217
165
|
|
|
218
|
-
|
|
166
|
+
A stateful fold over the normalized AST can be performed with the ${ctx.link(stateful_fold_1.foldAstStateful)} function.
|
|
167
|
+
It allows you to specify a down function which is called during the down-pass and can pass information to child nodes, and fold functions which are called after the down-pass in conventional fold-fashion.
|
|
219
168
|
`;
|
|
220
169
|
}
|
|
221
170
|
}
|
package/linter/linter-rules.d.ts
CHANGED
|
@@ -283,14 +283,14 @@ export declare const LintingRules: {
|
|
|
283
283
|
};
|
|
284
284
|
readonly 'problematic-inputs': {
|
|
285
285
|
readonly createSearch: (config: import("./rules/problematic-inputs").ProblematicInputsConfig) => import("../search/flowr-search-builder").FlowrSearchBuilder<"from-query", [], import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../search/flowr-search").FlowrSearchElements<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../search/flowr-search").FlowrSearchElement<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>>;
|
|
286
|
-
readonly processSearchResult: (elements: import("../search/flowr-search").FlowrSearchElements<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../search/flowr-search").FlowrSearchElement<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>,
|
|
286
|
+
readonly processSearchResult: (elements: import("../search/flowr-search").FlowrSearchElements<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation, import("../search/flowr-search").FlowrSearchElement<import("../r-bridge/lang-4.x/ast/model/processing/decorate").ParentInformation>[]>, config: import("./rules/problematic-inputs").ProblematicInputsConfig, data: {
|
|
287
287
|
normalize: import("../r-bridge/lang-4.x/ast/model/processing/decorate").NormalizedAst;
|
|
288
288
|
dataflow: import("../dataflow/info").DataflowInformation;
|
|
289
289
|
cfg: import("../control-flow/control-flow-graph").ControlFlowInformation;
|
|
290
290
|
analyzer: import("../project/flowr-analyzer").ReadonlyFlowrAnalysisProvider;
|
|
291
291
|
}) => Promise<{
|
|
292
292
|
results: import("./rules/problematic-inputs").ProblematicInputsResult[];
|
|
293
|
-
|
|
293
|
+
'.meta': {};
|
|
294
294
|
}>;
|
|
295
295
|
readonly prettyPrint: {
|
|
296
296
|
readonly query: (result: import("./rules/problematic-inputs").ProblematicInputsResult) => string;
|
|
@@ -298,11 +298,12 @@ export declare const LintingRules: {
|
|
|
298
298
|
};
|
|
299
299
|
readonly info: {
|
|
300
300
|
readonly name: "Problematic inputs";
|
|
301
|
-
readonly description: "Detects uses of
|
|
301
|
+
readonly description: "Detects uses of dynamic calls (e.g. eval, system) with non-constant inputs, and graphics-device calls (pdf, postscript) where a filename starts with '|' indicating a pipe command injection.";
|
|
302
302
|
readonly tags: readonly [import("./linter-tags").LintingRuleTag.Security, import("./linter-tags").LintingRuleTag.Smell, import("./linter-tags").LintingRuleTag.Readability, import("./linter-tags").LintingRuleTag.Performance];
|
|
303
303
|
readonly certainty: import("./linter-format").LintingRuleCertainty.BestEffort;
|
|
304
304
|
readonly defaultConfig: {
|
|
305
305
|
readonly consider: readonly ["^eval$", "^system$", "^system2$", "^shell$"];
|
|
306
|
+
readonly pipeCommandFunctions: readonly import("./rules/problematic-inputs").PipeCommandFunctionSpec[];
|
|
306
307
|
};
|
|
307
308
|
};
|
|
308
309
|
};
|