-
Notifications
You must be signed in to change notification settings - Fork 14
[Query] Control Flow
This document was generated from 'src/documentation/wiki-query.ts' on 2026-07-20, 13:05:03 UTC presenting an overview of flowR's query API (v2.12.3). Please do not edit this file/wiki page directly.
Control-Flow Query [overview]
Provides the control-flow of the program.
This query is requested with the type control-flow.
This control-flow query provides you access to the control flow graph.
In other words, if you have a script simply reading: if(TRUE) 1 else 2, the following query returns the CFG:
[ { "type": "control-flow" } ](This can be shortened to @control-flow when used with the REPL command :query).
Show Results
Results (prettified and summarized):
Show Detailed Results as Json
The analysis required 3.3 ms (including parsing and normalization and the query) within the generation environment.
In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR. Please consult the Interface wiki page for more information on how to get those.
{
"control-flow": {
".meta": {
"timing": 3
},
"controlFlow": {
"returns": [],
"entryPoints": [
6
],
"exitPoints": [
"6-e"
],
"breaks": [],
"nexts": [],
"graph": {
"roots": [
6,
5,
"5-e",
0,
2,
1,
"2-e",
4,
3,
"4-e",
"6-e"
],
"vtxInfos": [
[
6,
[
2,
6,
null,
[
"6-e"
]
]
],
[
5,
[
1,
5,
[
0
],
[
"5-e"
]
]
],
[
"5-e",
"5-e"
],
[
0,
[
2,
0
]
],
[
2,
[
2,
2,
null,
[
"2-e"
]
]
],
[
1,
[
2,
1
]
],
[
"2-e",
"2-e"
],
[
4,
[
2,
4,
null,
[
"4-e"
]
]
],
[
3,
[
2,
3
]
],
[
"4-e",
"4-e"
],
[
"6-e",
"6-e"
]
],
"bbChildren": [],
"edgeInfos": [
[
5,
[
[
6,
0
]
]
],
[
1,
[
[
2,
0
]
]
],
[
"2-e",
[
[
1,
0
]
]
],
[
3,
[
[
4,
0
]
]
],
[
"4-e",
[
[
3,
0
]
]
],
[
2,
[
[
0,
[
5,
"TRUE"
]
]
]
],
[
4,
[
[
0,
[
5,
"FALSE"
]
]
]
],
[
0,
[
[
5,
0
]
]
],
[
"5-e",
[
[
"2-e",
0
],
[
"4-e",
0
]
]
],
[
"6-e",
[
[
"5-e",
0
]
]
]
],
"_mayBB": false
}
}
},
".meta": {
"timing": 3
}
}You can also overwrite the simplification passes to tune the perspective. for example, if you want to have basic blocks:
[
{
"type": "control-flow",
"config": {
"simplificationPasses": [
"unique-cf-sets",
"to-basic-blocks"
]
}
}
]Show Results
Results (prettified and summarized):
Show Detailed Results as Json
The analysis required 3.6 ms (including parsing and normalization and the query) within the generation environment.
In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR. Please consult the Interface wiki page for more information on how to get those.
{
"control-flow": {
".meta": {
"timing": 3
},
"controlFlow": {
"returns": [],
"entryPoints": [
"bb-0"
],
"exitPoints": [
"bb-6-e"
],
"breaks": [],
"nexts": [],
"graph": {
"roots": [
"bb-0",
"bb-2-e",
"bb-4-e",
"bb-6-e"
],
"vtxInfos": [
[
"bb-0",
[
3,
"bb-0",
[
[
2,
0
],
[
1,
5,
[
0
],
[
"5-e"
]
],
[
2,
6,
null,
[
"6-e"
]
]
]
]
],
[
"bb-2-e",
[
3,
"bb-2-e",
[
"2-e",
[
2,
1
],
[
2,
2,
null,
[
"2-e"
]
]
]
]
],
[
"bb-4-e",
[
3,
"bb-4-e",
[
"4-e",
[
2,
3
],
[
2,
4,
null,
[
"4-e"
]
]
]
]
],
[
"bb-6-e",
[
3,
"bb-6-e",
[
"6-e",
"5-e"
]
]
]
],
"bbChildren": [
[
6,
"bb-0"
],
[
5,
"bb-0"
],
[
"5-e",
"bb-6-e"
],
[
0,
"bb-0"
],
[
2,
"bb-2-e"
],
[
1,
"bb-2-e"
],
[
"2-e",
"bb-2-e"
],
[
4,
"bb-4-e"
],
[
3,
"bb-4-e"
],
[
"4-e",
"bb-4-e"
],
[
"6-e",
"bb-6-e"
]
],
"edgeInfos": [
[
"bb-6-e",
[
[
"bb-2-e",
0
],
[
"bb-4-e",
0
]
]
],
[
"bb-2-e",
[
[
"bb-0",
[
5,
"TRUE"
]
]
]
],
[
"bb-4-e",
[
[
"bb-0",
[
5,
"FALSE"
]
]
]
]
],
"revEdgeInfos": [
[
"bb-0",
[
[
"bb-2-e",
[
5,
"TRUE"
]
],
[
"bb-4-e",
[
5,
"FALSE"
]
]
]
],
[
"bb-2-e",
[
[
"bb-6-e",
0
]
]
],
[
"bb-4-e",
[
[
"bb-6-e",
0
]
]
]
],
"_mayBB": true
}
}
},
".meta": {
"timing": 3
}
}this produces:
flowchart RL
subgraph nbb-0 [Block bb-0]
direction RL
n0["`RLogical (0)
#34;TRUE#34;`"]
n5["`RIfThenElse (5)
#34;if(TRUE) 1 else 2#34;`"]
n0 -.-> n5
n6["`RExpressionList (6)`"]
n5 -.-> n6
end
subgraph nbb-2-e [Block bb-2-e]
direction RL
n2-e[[2-e]]
n1["`RNumber (1)
#34;1#34;`"]
n2-e -.-> n1
n2["`RExpressionList (2)
#34;1#34;`"]
n1 -.-> n2
end
subgraph nbb-4-e [Block bb-4-e]
direction RL
n4-e[[4-e]]
n3["`RNumber (3)
#34;2#34;`"]
n4-e -.-> n3
n4["`RExpressionList (4)
#34;2#34;`"]
n3 -.-> n4
end
subgraph nbb-6-e [Block bb-6-e]
direction RL
n6-e[[6-e]]
n5-e[[5-e]]
n6-e -.-> n5-e
end
nbb-6-e -.->|"FD"| nbb-2-e
nbb-6-e -.->|"FD"| nbb-4-e
nbb-2-e -->|"CD (TRUE)"| nbb-0
nbb-4-e -->|"CD (FALSE)"| nbb-0
style nbb-0 stroke:cyan,stroke-width:6.5px; style nbb-6-e stroke:green,stroke-width:6.5px;
(The analysis required 2.1 ms (including the dataflow analysis, normalization, and parsing with the r-shell engine) within the generation environment.
We used the following simplifications: unique-cf-sets, to-basic-blocks .
)
If, on the other hand, you want to prune dead code edges:
[
{
"type": "control-flow",
"config": {
"simplificationPasses": [
"unique-cf-sets",
"analyze-dead-code"
]
}
}
]Show Results
Results (prettified and summarized):
Show Detailed Results as Json
The analysis required 7.4 ms (including parsing and normalization and the query) within the generation environment.
In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR. Please consult the Interface wiki page for more information on how to get those.
{
"control-flow": {
".meta": {
"timing": 7
},
"controlFlow": {
"returns": [],
"entryPoints": [
6
],
"exitPoints": [
"6-e"
],
"breaks": [],
"nexts": [],
"graph": {
"roots": [
6,
5,
"5-e",
0,
2,
1,
"2-e",
4,
3,
"4-e",
"6-e"
],
"vtxInfos": [
[
6,
[
2,
6,
null,
[
"6-e"
]
]
],
[
5,
[
1,
5,
[
0
],
[
"5-e"
]
]
],
[
"5-e",
"5-e"
],
[
0,
[
2,
0
]
],
[
2,
[
2,
2,
null,
[
"2-e"
]
]
],
[
1,
[
2,
1
]
],
[
"2-e",
"2-e"
],
[
4,
[
2,
4,
null,
[
"4-e"
]
]
],
[
3,
[
2,
3
]
],
[
"4-e",
"4-e"
],
[
"6-e",
"6-e"
]
],
"bbChildren": [],
"edgeInfos": [
[
5,
[
[
6,
0
]
]
],
[
1,
[
[
2,
0
]
]
],
[
"2-e",
[
[
1,
0
]
]
],
[
3,
[
[
4,
0
]
]
],
[
"4-e",
[
[
3,
0
]
]
],
[
2,
[
[
0,
[
5,
"TRUE"
]
]
]
],
[
0,
[
[
5,
0
]
]
],
[
"5-e",
[
[
"2-e",
0
],
[
"4-e",
0
]
]
],
[
"6-e",
[
[
"5-e",
0
]
]
]
],
"_mayBB": false
}
}
},
".meta": {
"timing": 7
}
}this produces:
flowchart RL
n6(["`RExpressionList (6)`"])
n5["`RIfThenElse (5)
#34;if(TRUE) 1 else 2#34;`"]
n5-e[[5-e]]
n0(["`RLogical (0)
#34;TRUE#34;`"])
n2(["`RExpressionList (2)
#34;1#34;`"])
n1(["`RNumber (1)
#34;1#34;`"])
n2-e[[2-e]]
n4(["`RExpressionList (4)
#34;2#34;`"])
n3(["`RNumber (3)
#34;2#34;`"])
n4-e[[4-e]]
n6-e[[6-e]]
n5 -.->|"FD"| n6
n1 -.->|"FD"| n2
n2-e -.->|"FD"| n1
n3 -.->|"FD"| n4
n4-e -.->|"FD"| n3
n2 -->|"CD (TRUE)"| n0
n0 -.->|"FD"| n5
n5-e -.->|"FD"| n2-e
n5-e -.->|"FD"| n4-e
n6-e -.->|"FD"| n5-e
style n6 stroke:cyan,stroke-width:6.5px; style n6-e stroke:green,stroke-width:6.5px;
(The analysis required 2.5 ms (including the dataflow analysis, normalization, and parsing with the r-shell engine) within the generation environment.
We used the following simplifications: unique-cf-sets, analyze-dead-code .
)
Or, completely remove dead code:
[
{
"type": "control-flow",
"config": {
"simplificationPasses": [
"unique-cf-sets",
"analyze-dead-code",
"remove-dead-code"
]
}
}
]Show Results
Results (prettified and summarized):
Query: control-flow (4ms)
╰ CFG: https://mermaid.live/view#base64:eyJjb2RlIjoiZmxvd2NoYXJ0IEJUXG4gICAgbjYoW1wiYFJFeHByZXNzaW9uTGlzdCAoNilgXCJdKVxuICAgIG41W1wiYFJJZlRoZW5FbHNlICg1KVxuIzM0O2lmKFRSVUUpIDEgZWxzZSAyIzM0O2BcIl1cbiAgICBuNS1lW1s1LWVdXVxuICAgIG4wKFtcImBSTG9naWNhbCAoMClcbiMzNDtUUlVFIzM0O2BcIl0pXG4gICAgbjIoW1wiYFJFeHByZXNzaW9uTGlzdCAoMilcbiMzNDsxIzM0O2BcIl0pXG4gICAgbjEoW1wiYFJOdW1iZXIgKDEpXG4jMzQ7MSMzNDtgXCJdKVxuICAgIG4yLWVbWzItZV1dXG4gICAgbjYtZVtbNi1lXV1cbiAgICBuNSAtLi0+fFwiRkRcInwgbjZcbiAgICBuMSAtLi0+fFwiRkRcInwgbjJcbiAgICBuMi1lIC0uLT58XCJGRFwifCBuMVxuICAgIG4yIC0tPnxcIkNEIChUUlVFKVwifCBuMFxuICAgIG4wIC0uLT58XCJGRFwifCBuNVxuICAgIG41LWUgLS4tPnxcIkZEXCJ8IG4yLWVcbiAgICBuNi1lIC0uLT58XCJGRFwifCBuNS1lXG4gICAgc3R5bGUgbjYgc3Ryb2tlOmN5YW4sc3Ryb2tlLXdpZHRoOjYuNXB4OyAgICBzdHlsZSBuNi1lIHN0cm9rZTpncmVlbixzdHJva2Utd2lkdGg6Ni41cHg7IiwibWVybWFpZCI6eyJhdXRvU3luYyI6dHJ1ZX19\
All queries together required ≈4 ms (1ms accuracy, total 4 ms)
Show Detailed Results as Json
The analysis required 4.2 ms (including parsing and normalization and the query) within the generation environment.
In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR. Please consult the Interface wiki page for more information on how to get those.
{
"control-flow": {
".meta": {
"timing": 4
},
"controlFlow": {
"returns": [],
"entryPoints": [
6
],
"exitPoints": [
"6-e"
],
"breaks": [],
"nexts": [],
"graph": {
"roots": [
6,
5,
"5-e",
0,
2,
1,
"2-e",
"6-e"
],
"vtxInfos": [
[
6,
[
2,
6,
null,
[
"6-e"
]
]
],
[
5,
[
1,
5,
[
0
],
[
"5-e"
]
]
],
[
"5-e",
"5-e"
],
[
0,
[
2,
0
]
],
[
2,
[
2,
2,
null,
[
"2-e"
]
]
],
[
1,
[
2,
1
]
],
[
"2-e",
"2-e"
],
[
"6-e",
"6-e"
]
],
"bbChildren": [],
"edgeInfos": [
[
5,
[
[
6,
0
]
]
],
[
1,
[
[
2,
0
]
]
],
[
"2-e",
[
[
1,
0
]
]
],
[
2,
[
[
0,
[
5,
"TRUE"
]
]
]
],
[
0,
[
[
5,
0
]
]
],
[
"5-e",
[
[
"2-e",
0
]
]
],
[
"6-e",
[
[
"5-e",
0
]
]
]
],
"revEdgeInfos": [
[
6,
[
[
5,
0
]
]
],
[
2,
[
[
1,
0
]
]
],
[
1,
[
[
"2-e",
0
]
]
],
[
0,
[
[
2,
[
5,
"TRUE"
]
]
]
],
[
5,
[
[
0,
0
]
]
],
[
"2-e",
[
[
"5-e",
0
]
]
],
[
"5-e",
[
[
"6-e",
0
]
]
]
],
"_mayBB": false
}
}
},
".meta": {
"timing": 4
}
}this produces:
flowchart RL
n6(["`RExpressionList (6)`"])
n5["`RIfThenElse (5)
#34;if(TRUE) 1 else 2#34;`"]
n5-e[[5-e]]
n0(["`RLogical (0)
#34;TRUE#34;`"])
n2(["`RExpressionList (2)
#34;1#34;`"])
n1(["`RNumber (1)
#34;1#34;`"])
n2-e[[2-e]]
n6-e[[6-e]]
n5 -.->|"FD"| n6
n1 -.->|"FD"| n2
n2-e -.->|"FD"| n1
n2 -->|"CD (TRUE)"| n0
n0 -.->|"FD"| n5
n5-e -.->|"FD"| n2-e
n6-e -.->|"FD"| n5-e
style n6 stroke:cyan,stroke-width:6.5px; style n6-e stroke:green,stroke-width:6.5px;
(The analysis required 2.2 ms (including the dataflow analysis, normalization, and parsing with the r-shell engine) within the generation environment.
We used the following simplifications: unique-cf-sets, analyze-dead-code, remove-dead-code .
)
Implementation Details
Responsible for the execution of the Control-Flow Query query is executeControlFlowQuery in ./src/queries/catalog/control-flow-query/control-flow-query-executor.ts.
Currently maintained by Florian Sihler and Oliver Gerstl at Ulm University
Email | GitHub | Penguins | Portfolio
- 🧑💻 Developer Onboarding
- 💻 Setup
- 👓 Overview
- 🪟 Interfacing with flowR
- 🌋 Core
- 🧹 Testing & Linting (Benchmark Page)
⁉️ FAQ- ℹ️ Extra Information