Skip to content

Commit 2ced47f

Browse files
committed
Java: Accept revised CFG.
1 parent 3dd748c commit 2ced47f

File tree

39 files changed

+525
-461
lines changed

39 files changed

+525
-461
lines changed

java/ql/lib/utils/test/AstCfg.qll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Provides utilities for getting an AST-based control flow graph in tests.
3+
*/
4+
overlay[local?]
5+
module;
6+
7+
import java
8+
9+
private predicate isAstNode(ControlFlowNode n) {
10+
n.injects(_) or
11+
n instanceof ControlFlow::EntryNode or
12+
n instanceof ControlFlow::AnnotatedExitNode or
13+
n instanceof ControlFlow::ExitNode
14+
}
15+
16+
private predicate succToAst(ControlFlowNode n1, ControlFlowNode n2) {
17+
n2 = n1.getASuccessor() and
18+
isAstNode(n2)
19+
or
20+
exists(ControlFlowNode mid |
21+
mid = n1.getASuccessor() and
22+
not isAstNode(mid) and
23+
succToAst(mid, n2)
24+
)
25+
}
26+
27+
/** Gets a control flow successor of `n` that skips over non-AST nodes. */
28+
ControlFlowNode getAnAstSuccessor(ControlFlowNode n) { isAstNode(n) and succToAst(n, result) }

java/ql/test-kotlin1/library-tests/controlflow/basic/getASuccessor.expected

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#select
22
| Test.kt:3:1:80:1 | super(...) | SuperConstructorInvocationStmt | Test.kt:3:8:80:1 | { ... } | BlockStmt |
3-
| Test.kt:3:8:80:1 | Exceptional Exit | Constructor | Test.kt:3:8:80:1 | Exit | Constructor |
4-
| Test.kt:3:8:80:1 | Exit | Constructor | file://:0:0:0:0 | <none> | <none> |
3+
| Test.kt:3:8:80:1 | Entry | Constructor | Test.kt:3:8:80:1 | { ... } | BlockStmt |
54
| Test.kt:3:8:80:1 | Normal Exit | Constructor | Test.kt:3:8:80:1 | Exit | Constructor |
65
| Test.kt:3:8:80:1 | { ... } | BlockStmt | Test.kt:3:1:80:1 | super(...) | SuperConstructorInvocationStmt |
76
| Test.kt:3:8:80:1 | { ... } | BlockStmt | Test.kt:3:8:80:1 | Normal Exit | Constructor |
8-
| Test.kt:4:2:79:2 | Exceptional Exit | Method | Test.kt:4:2:79:2 | Exit | Method |
9-
| Test.kt:4:2:79:2 | Exit | Method | file://:0:0:0:0 | <none> | <none> |
7+
| Test.kt:4:2:79:2 | Entry | Method | Test.kt:4:13:79:2 | { ... } | BlockStmt |
108
| Test.kt:4:2:79:2 | Normal Exit | Method | Test.kt:4:2:79:2 | Exit | Method |
119
| Test.kt:4:13:79:2 | { ... } | BlockStmt | Test.kt:5:7:5:7 | var ...; | LocalVariableDeclStmt |
1210
| Test.kt:5:7:5:7 | var ...; | LocalVariableDeclStmt | Test.kt:5:16:5:16 | 0 | IntegerLiteral |
@@ -31,17 +29,21 @@
3129
| Test.kt:11:7:11:11 | ... > ... | GTExpr | Test.kt:11:14:14:3 | { ... } | BlockStmt |
3230
| Test.kt:11:11:11:11 | 0 | IntegerLiteral | Test.kt:11:7:11:11 | ... > ... | GTExpr |
3331
| Test.kt:11:14:14:3 | { ... } | BlockStmt | Test.kt:12:4:12:4 | <Expr>; | ExprStmt |
34-
| Test.kt:12:4:12:4 | <Expr>; | ExprStmt | Test.kt:12:8:12:9 | 20 | LongLiteral |
32+
| Test.kt:12:4:12:4 | <Expr>; | ExprStmt | Test.kt:12:4:12:4 | y | VarAccess |
33+
| Test.kt:12:4:12:4 | y | VarAccess | Test.kt:12:8:12:9 | 20 | LongLiteral |
3534
| Test.kt:12:4:12:9 | ...=... | AssignExpr | Test.kt:13:4:13:4 | <Expr>; | ExprStmt |
3635
| Test.kt:12:8:12:9 | 20 | LongLiteral | Test.kt:12:4:12:9 | ...=... | AssignExpr |
37-
| Test.kt:13:4:13:4 | <Expr>; | ExprStmt | Test.kt:13:8:13:9 | 10 | IntegerLiteral |
36+
| Test.kt:13:4:13:4 | <Expr>; | ExprStmt | Test.kt:13:4:13:4 | z | VarAccess |
37+
| Test.kt:13:4:13:4 | z | VarAccess | Test.kt:13:8:13:9 | 10 | IntegerLiteral |
3838
| Test.kt:13:4:13:9 | ...=... | AssignExpr | Test.kt:18:3:18:3 | <Expr>; | ExprStmt |
3939
| Test.kt:13:8:13:9 | 10 | IntegerLiteral | Test.kt:13:4:13:9 | ...=... | AssignExpr |
4040
| Test.kt:14:10:16:3 | { ... } | BlockStmt | Test.kt:15:4:15:4 | <Expr>; | ExprStmt |
41-
| Test.kt:15:4:15:4 | <Expr>; | ExprStmt | Test.kt:15:8:15:9 | 30 | LongLiteral |
41+
| Test.kt:15:4:15:4 | <Expr>; | ExprStmt | Test.kt:15:4:15:4 | y | VarAccess |
42+
| Test.kt:15:4:15:4 | y | VarAccess | Test.kt:15:8:15:9 | 30 | LongLiteral |
4243
| Test.kt:15:4:15:9 | ...=... | AssignExpr | Test.kt:18:3:18:3 | <Expr>; | ExprStmt |
4344
| Test.kt:15:8:15:9 | 30 | LongLiteral | Test.kt:15:4:15:9 | ...=... | AssignExpr |
44-
| Test.kt:18:3:18:3 | <Expr>; | ExprStmt | Test.kt:18:7:18:7 | 0 | IntegerLiteral |
45+
| Test.kt:18:3:18:3 | <Expr>; | ExprStmt | Test.kt:18:3:18:3 | z | VarAccess |
46+
| Test.kt:18:3:18:3 | z | VarAccess | Test.kt:18:7:18:7 | 0 | IntegerLiteral |
4547
| Test.kt:18:3:18:7 | ...=... | AssignExpr | Test.kt:21:3:24:9 | <Expr>; | ExprStmt |
4648
| Test.kt:18:7:18:7 | 0 | IntegerLiteral | Test.kt:18:3:18:7 | ...=... | AssignExpr |
4749
| Test.kt:21:3:24:9 | ... -> ... | WhenBranch | Test.kt:21:3:24:9 | true | BooleanLiteral |
@@ -53,12 +55,14 @@
5355
| Test.kt:21:6:21:10 | ... < ... | LTExpr | Test.kt:21:3:24:9 | ... -> ... | WhenBranch |
5456
| Test.kt:21:6:21:10 | ... < ... | LTExpr | Test.kt:22:4:22:4 | <Expr>; | ExprStmt |
5557
| Test.kt:21:10:21:10 | 0 | IntegerLiteral | Test.kt:21:6:21:10 | ... < ... | LTExpr |
56-
| Test.kt:22:4:22:4 | <Expr>; | ExprStmt | Test.kt:22:8:22:9 | 40 | LongLiteral |
58+
| Test.kt:22:4:22:4 | <Expr>; | ExprStmt | Test.kt:22:4:22:4 | y | VarAccess |
59+
| Test.kt:22:4:22:4 | y | VarAccess | Test.kt:22:8:22:9 | 40 | LongLiteral |
5760
| Test.kt:22:4:22:9 | ...=... | AssignExpr | Test.kt:27:3:27:3 | <Expr>; | ExprStmt |
5861
| Test.kt:22:8:22:9 | 40 | LongLiteral | Test.kt:22:4:22:9 | ...=... | AssignExpr |
5962
| Test.kt:24:4:24:9 | INSTANCE | VarAccess | Test.kt:24:4:24:9 | return ... | ReturnStmt |
6063
| Test.kt:24:4:24:9 | return ... | ReturnStmt | Test.kt:4:2:79:2 | Normal Exit | Method |
61-
| Test.kt:27:3:27:3 | <Expr>; | ExprStmt | Test.kt:27:7:27:8 | 10 | IntegerLiteral |
64+
| Test.kt:27:3:27:3 | <Expr>; | ExprStmt | Test.kt:27:3:27:3 | z | VarAccess |
65+
| Test.kt:27:3:27:3 | z | VarAccess | Test.kt:27:7:27:8 | 10 | IntegerLiteral |
6266
| Test.kt:27:3:27:8 | ...=... | AssignExpr | Test.kt:30:3:33:3 | <Expr>; | ExprStmt |
6367
| Test.kt:27:7:27:8 | 10 | IntegerLiteral | Test.kt:27:3:27:8 | ...=... | AssignExpr |
6468
| Test.kt:30:3:33:3 | ... -> ... | WhenBranch | Test.kt:30:7:30:7 | x | VarAccess |
@@ -69,13 +73,16 @@
6973
| Test.kt:30:7:30:12 | ... (value equals) ... | ValueEQExpr | Test.kt:35:3:35:3 | <Expr>; | ExprStmt |
7074
| Test.kt:30:12:30:12 | 0 | IntegerLiteral | Test.kt:30:7:30:12 | ... (value equals) ... | ValueEQExpr |
7175
| Test.kt:30:15:33:3 | { ... } | BlockStmt | Test.kt:31:4:31:4 | <Expr>; | ExprStmt |
72-
| Test.kt:31:4:31:4 | <Expr>; | ExprStmt | Test.kt:31:8:31:9 | 60 | LongLiteral |
76+
| Test.kt:31:4:31:4 | <Expr>; | ExprStmt | Test.kt:31:4:31:4 | y | VarAccess |
77+
| Test.kt:31:4:31:4 | y | VarAccess | Test.kt:31:8:31:9 | 60 | LongLiteral |
7378
| Test.kt:31:4:31:9 | ...=... | AssignExpr | Test.kt:32:4:32:4 | <Expr>; | ExprStmt |
7479
| Test.kt:31:8:31:9 | 60 | LongLiteral | Test.kt:31:4:31:9 | ...=... | AssignExpr |
75-
| Test.kt:32:4:32:4 | <Expr>; | ExprStmt | Test.kt:32:8:32:9 | 10 | IntegerLiteral |
80+
| Test.kt:32:4:32:4 | <Expr>; | ExprStmt | Test.kt:32:4:32:4 | z | VarAccess |
81+
| Test.kt:32:4:32:4 | z | VarAccess | Test.kt:32:8:32:9 | 10 | IntegerLiteral |
7682
| Test.kt:32:4:32:9 | ...=... | AssignExpr | Test.kt:35:3:35:3 | <Expr>; | ExprStmt |
7783
| Test.kt:32:8:32:9 | 10 | IntegerLiteral | Test.kt:32:4:32:9 | ...=... | AssignExpr |
78-
| Test.kt:35:3:35:3 | <Expr>; | ExprStmt | Test.kt:35:7:35:8 | 20 | IntegerLiteral |
84+
| Test.kt:35:3:35:3 | <Expr>; | ExprStmt | Test.kt:35:3:35:3 | z | VarAccess |
85+
| Test.kt:35:3:35:3 | z | VarAccess | Test.kt:35:7:35:8 | 20 | IntegerLiteral |
7986
| Test.kt:35:3:35:8 | ...=... | AssignExpr | Test.kt:38:3:41:3 | while (...) | WhileStmt |
8087
| Test.kt:35:7:35:8 | 20 | IntegerLiteral | Test.kt:35:3:35:8 | ...=... | AssignExpr |
8188
| Test.kt:38:3:41:3 | while (...) | WhileStmt | Test.kt:38:9:38:9 | x | VarAccess |
@@ -84,35 +91,40 @@
8491
| Test.kt:38:9:38:13 | ... > ... | GTExpr | Test.kt:43:3:43:3 | <Expr>; | ExprStmt |
8592
| Test.kt:38:13:38:13 | 0 | IntegerLiteral | Test.kt:38:9:38:13 | ... > ... | GTExpr |
8693
| Test.kt:38:16:41:3 | { ... } | BlockStmt | Test.kt:39:4:39:4 | <Expr>; | ExprStmt |
87-
| Test.kt:39:4:39:4 | <Expr>; | ExprStmt | Test.kt:39:8:39:9 | 10 | LongLiteral |
94+
| Test.kt:39:4:39:4 | <Expr>; | ExprStmt | Test.kt:39:4:39:4 | y | VarAccess |
95+
| Test.kt:39:4:39:4 | y | VarAccess | Test.kt:39:8:39:9 | 10 | LongLiteral |
8896
| Test.kt:39:4:39:9 | ...=... | AssignExpr | Test.kt:40:4:40:6 | <Expr>; | ExprStmt |
8997
| Test.kt:39:8:39:9 | 10 | LongLiteral | Test.kt:39:4:39:9 | ...=... | AssignExpr |
90-
| Test.kt:40:4:40:4 | <Expr>; | ExprStmt | Test.kt:40:4:40:6 | tmp0 | VarAccess |
98+
| Test.kt:40:4:40:4 | <Expr>; | ExprStmt | Test.kt:40:4:40:4 | x | VarAccess |
9199
| Test.kt:40:4:40:4 | x | VarAccess | Test.kt:40:4:40:6 | tmp0 | LocalVariableDeclExpr |
100+
| Test.kt:40:4:40:4 | x | VarAccess | Test.kt:40:4:40:6 | tmp0 | VarAccess |
92101
| Test.kt:40:4:40:6 | ...=... | AssignExpr | Test.kt:40:4:40:6 | <Expr>; | ExprStmt |
93-
| Test.kt:40:4:40:6 | <Expr>; | ExprStmt | Test.kt:40:4:40:6 | <Stmt> | StmtExpr |
94102
| Test.kt:40:4:40:6 | <Expr>; | ExprStmt | Test.kt:40:4:40:6 | tmp0 | VarAccess |
95-
| Test.kt:40:4:40:6 | <Stmt> | StmtExpr | Test.kt:40:4:40:6 | { ... } | BlockStmt |
103+
| Test.kt:40:4:40:6 | <Expr>; | ExprStmt | Test.kt:40:4:40:6 | { ... } | BlockStmt |
104+
| Test.kt:40:4:40:6 | <Stmt> | StmtExpr | Test.kt:40:4:40:6 | <implicit coercion to unit> | ImplicitCoercionToUnitExpr |
96105
| Test.kt:40:4:40:6 | <implicit coercion to unit> | ImplicitCoercionToUnitExpr | Test.kt:38:9:38:9 | x | VarAccess |
97106
| Test.kt:40:4:40:6 | dec(...) | MethodCall | Test.kt:40:4:40:6 | ...=... | AssignExpr |
98107
| Test.kt:40:4:40:6 | tmp0 | LocalVariableDeclExpr | Test.kt:40:4:40:4 | <Expr>; | ExprStmt |
99-
| Test.kt:40:4:40:6 | tmp0 | VarAccess | Test.kt:40:4:40:6 | <implicit coercion to unit> | ImplicitCoercionToUnitExpr |
108+
| Test.kt:40:4:40:6 | tmp0 | VarAccess | Test.kt:40:4:40:6 | <Stmt> | StmtExpr |
100109
| Test.kt:40:4:40:6 | tmp0 | VarAccess | Test.kt:40:4:40:6 | dec(...) | MethodCall |
101110
| Test.kt:40:4:40:6 | var ...; | LocalVariableDeclStmt | Test.kt:40:4:40:4 | x | VarAccess |
102111
| Test.kt:40:4:40:6 | { ... } | BlockStmt | Test.kt:40:4:40:6 | var ...; | LocalVariableDeclStmt |
103-
| Test.kt:43:3:43:3 | <Expr>; | ExprStmt | Test.kt:43:7:43:8 | 30 | IntegerLiteral |
112+
| Test.kt:43:3:43:3 | <Expr>; | ExprStmt | Test.kt:43:3:43:3 | z | VarAccess |
113+
| Test.kt:43:3:43:3 | z | VarAccess | Test.kt:43:7:43:8 | 30 | IntegerLiteral |
104114
| Test.kt:43:3:43:8 | ...=... | AssignExpr | Test.kt:73:3:73:3 | <Expr>; | ExprStmt |
105115
| Test.kt:43:7:43:8 | 30 | IntegerLiteral | Test.kt:43:3:43:8 | ...=... | AssignExpr |
106-
| Test.kt:73:3:73:3 | <Expr>; | ExprStmt | Test.kt:73:7:73:8 | 50 | IntegerLiteral |
116+
| Test.kt:73:3:73:3 | <Expr>; | ExprStmt | Test.kt:73:3:73:3 | z | VarAccess |
117+
| Test.kt:73:3:73:3 | z | VarAccess | Test.kt:73:7:73:8 | 50 | IntegerLiteral |
107118
| Test.kt:73:3:73:8 | ...=... | AssignExpr | Test.kt:77:3:77:3 | <Expr>; | ExprStmt |
108119
| Test.kt:73:7:73:8 | 50 | IntegerLiteral | Test.kt:73:3:73:8 | ...=... | AssignExpr |
109-
| Test.kt:77:3:77:3 | <Expr>; | ExprStmt | Test.kt:77:7:77:8 | 40 | IntegerLiteral |
120+
| Test.kt:77:3:77:3 | <Expr>; | ExprStmt | Test.kt:77:3:77:3 | w | VarAccess |
121+
| Test.kt:77:3:77:3 | w | VarAccess | Test.kt:77:7:77:8 | 40 | IntegerLiteral |
110122
| Test.kt:77:3:77:8 | ...=... | AssignExpr | Test.kt:78:3:78:8 | INSTANCE | VarAccess |
111123
| Test.kt:77:7:77:8 | 40 | IntegerLiteral | Test.kt:77:3:77:8 | ...=... | AssignExpr |
112124
| Test.kt:78:3:78:8 | INSTANCE | VarAccess | Test.kt:78:3:78:8 | return ... | ReturnStmt |
113125
| Test.kt:78:3:78:8 | return ... | ReturnStmt | Test.kt:4:2:79:2 | Normal Exit | Method |
126+
| Test.kt:82:1:89:1 | Entry | Method | Test.kt:82:21:89:1 | { ... } | BlockStmt |
114127
| Test.kt:82:1:89:1 | Exceptional Exit | Method | Test.kt:82:1:89:1 | Exit | Method |
115-
| Test.kt:82:1:89:1 | Exit | Method | file://:0:0:0:0 | <none> | <none> |
116128
| Test.kt:82:1:89:1 | Normal Exit | Method | Test.kt:82:1:89:1 | Exit | Method |
117129
| Test.kt:82:21:89:1 | { ... } | BlockStmt | Test.kt:83:2:88:2 | try ... | TryStmt |
118130
| Test.kt:83:2:88:2 | try ... | TryStmt | Test.kt:83:6:86:2 | { ... } | BlockStmt |
@@ -124,13 +136,14 @@
124136
| Test.kt:84:11:84:18 | (...)... | CastExpr | Test.kt:86:4:88:2 | catch (...) | CatchClause |
125137
| Test.kt:85:3:85:10 | return ... | ReturnStmt | Test.kt:82:1:89:1 | Normal Exit | Method |
126138
| Test.kt:85:10:85:10 | 1 | IntegerLiteral | Test.kt:85:3:85:10 | return ... | ReturnStmt |
139+
| Test.kt:86:4:88:2 | catch (...) | CatchClause | Test.kt:82:1:89:1 | Exceptional Exit | Method |
127140
| Test.kt:86:4:88:2 | catch (...) | CatchClause | Test.kt:86:11:86:31 | e | LocalVariableDeclExpr |
128141
| Test.kt:86:11:86:31 | e | LocalVariableDeclExpr | Test.kt:86:34:88:2 | { ... } | BlockStmt |
129142
| Test.kt:86:34:88:2 | { ... } | BlockStmt | Test.kt:87:10:87:10 | 2 | IntegerLiteral |
130143
| Test.kt:87:3:87:10 | return ... | ReturnStmt | Test.kt:82:1:89:1 | Normal Exit | Method |
131144
| Test.kt:87:10:87:10 | 2 | IntegerLiteral | Test.kt:87:3:87:10 | return ... | ReturnStmt |
145+
| Test.kt:91:1:98:1 | Entry | Method | Test.kt:91:22:98:1 | { ... } | BlockStmt |
132146
| Test.kt:91:1:98:1 | Exceptional Exit | Method | Test.kt:91:1:98:1 | Exit | Method |
133-
| Test.kt:91:1:98:1 | Exit | Method | file://:0:0:0:0 | <none> | <none> |
134147
| Test.kt:91:1:98:1 | Normal Exit | Method | Test.kt:91:1:98:1 | Exit | Method |
135148
| Test.kt:91:22:98:1 | { ... } | BlockStmt | Test.kt:92:2:97:2 | try ... | TryStmt |
136149
| Test.kt:92:2:97:2 | try ... | TryStmt | Test.kt:92:6:95:2 | { ... } | BlockStmt |
@@ -142,13 +155,14 @@
142155
| Test.kt:93:12:93:13 | ...!! | NotNullExpr | Test.kt:95:4:97:2 | catch (...) | CatchClause |
143156
| Test.kt:94:3:94:10 | return ... | ReturnStmt | Test.kt:91:1:98:1 | Normal Exit | Method |
144157
| Test.kt:94:10:94:10 | 1 | IntegerLiteral | Test.kt:94:3:94:10 | return ... | ReturnStmt |
158+
| Test.kt:95:4:97:2 | catch (...) | CatchClause | Test.kt:91:1:98:1 | Exceptional Exit | Method |
145159
| Test.kt:95:4:97:2 | catch (...) | CatchClause | Test.kt:95:11:95:33 | e | LocalVariableDeclExpr |
146160
| Test.kt:95:11:95:33 | e | LocalVariableDeclExpr | Test.kt:95:36:97:2 | { ... } | BlockStmt |
147161
| Test.kt:95:36:97:2 | { ... } | BlockStmt | Test.kt:96:10:96:10 | 2 | IntegerLiteral |
148162
| Test.kt:96:3:96:10 | return ... | ReturnStmt | Test.kt:91:1:98:1 | Normal Exit | Method |
149163
| Test.kt:96:10:96:10 | 2 | IntegerLiteral | Test.kt:96:3:96:10 | return ... | ReturnStmt |
164+
| Test.kt:100:1:110:1 | Entry | Method | Test.kt:100:25:110:1 | { ... } | BlockStmt |
150165
| Test.kt:100:1:110:1 | Exceptional Exit | Method | Test.kt:100:1:110:1 | Exit | Method |
151-
| Test.kt:100:1:110:1 | Exit | Method | file://:0:0:0:0 | <none> | <none> |
152166
| Test.kt:100:1:110:1 | Normal Exit | Method | Test.kt:100:1:110:1 | Exit | Method |
153167
| Test.kt:100:25:110:1 | { ... } | BlockStmt | Test.kt:101:5:103:5 | <Expr>; | ExprStmt |
154168
| Test.kt:101:5:103:5 | ... -> ... | WhenBranch | Test.kt:101:9:101:30 | ... && ... | AndLogicalExpr |
@@ -186,8 +200,7 @@
186200
| Test.kt:108:9:108:29 | <Expr>; | ExprStmt | Test.kt:108:17:108:28 | "y not null" | StringLiteral |
187201
| Test.kt:108:9:108:29 | println(...) | MethodCall | Test.kt:100:1:110:1 | Normal Exit | Method |
188202
| Test.kt:108:17:108:28 | "y not null" | StringLiteral | Test.kt:108:9:108:29 | println(...) | MethodCall |
189-
| Test.kt:112:1:116:1 | Exceptional Exit | Method | Test.kt:112:1:116:1 | Exit | Method |
190-
| Test.kt:112:1:116:1 | Exit | Method | file://:0:0:0:0 | <none> | <none> |
203+
| Test.kt:112:1:116:1 | Entry | Method | Test.kt:112:32:116:1 | { ... } | BlockStmt |
191204
| Test.kt:112:1:116:1 | Normal Exit | Method | Test.kt:112:1:116:1 | Exit | Method |
192205
| Test.kt:112:32:116:1 | { ... } | BlockStmt | Test.kt:113:5:115:5 | <Expr>; | ExprStmt |
193206
| Test.kt:113:5:115:5 | ... -> ... | WhenBranch | Test.kt:113:9:113:14 | ... && ... | AndLogicalExpr |
@@ -199,8 +212,7 @@
199212
| Test.kt:113:14:113:14 | y | VarAccess | Test.kt:112:1:116:1 | Normal Exit | Method |
200213
| Test.kt:113:14:113:14 | y | VarAccess | Test.kt:113:17:115:5 | { ... } | BlockStmt |
201214
| Test.kt:113:17:115:5 | { ... } | BlockStmt | Test.kt:112:1:116:1 | Normal Exit | Method |
202-
| Test.kt:118:1:124:1 | Exceptional Exit | Method | Test.kt:118:1:124:1 | Exit | Method |
203-
| Test.kt:118:1:124:1 | Exit | Method | file://:0:0:0:0 | <none> | <none> |
215+
| Test.kt:118:1:124:1 | Entry | Method | Test.kt:118:37:124:1 | { ... } | BlockStmt |
204216
| Test.kt:118:1:124:1 | Normal Exit | Method | Test.kt:118:1:124:1 | Exit | Method |
205217
| Test.kt:118:37:124:1 | { ... } | BlockStmt | Test.kt:119:2:123:12 | <Expr>; | ExprStmt |
206218
| Test.kt:119:2:123:12 | <Expr>; | ExprStmt | Test.kt:119:2:123:12 | when ... | WhenExpr |
@@ -216,6 +228,7 @@
216228
| Test.kt:122:12:122:16 | ... -> ... | WhenBranch | Test.kt:122:12:122:16 | true | BooleanLiteral |
217229
| Test.kt:122:12:122:16 | <Expr>; | ExprStmt | Test.kt:122:12:122:16 | false | BooleanLiteral |
218230
| Test.kt:122:12:122:16 | false | BooleanLiteral | Test.kt:118:1:124:1 | Normal Exit | Method |
231+
| Test.kt:122:12:122:16 | false | BooleanLiteral | Test.kt:123:8:123:10 | { ... } | BlockStmt |
219232
| Test.kt:122:12:122:16 | true | BooleanLiteral | Test.kt:122:12:122:16 | <Expr>; | ExprStmt |
220233
| Test.kt:123:8:123:10 | { ... } | BlockStmt | Test.kt:118:1:124:1 | Normal Exit | Method |
221234
missingSuccessor

java/ql/test-kotlin1/library-tests/controlflow/basic/getASuccessor.ql

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,14 @@
11
import java
2+
import utils.test.AstCfg
23

3-
newtype TMaybeControlFlowNode =
4-
TControlFlowNode(ControlFlowNode c) or
5-
TNoControlFlowNode()
6-
7-
class MaybeControlFlowNode extends TMaybeControlFlowNode {
8-
abstract string toString();
9-
10-
abstract Location getLocation();
11-
12-
abstract string getPrimaryQlClasses();
13-
}
14-
15-
class YesMaybeControlFlowNode extends MaybeControlFlowNode {
16-
ControlFlowNode c;
17-
18-
YesMaybeControlFlowNode() { this = TControlFlowNode(c) }
19-
20-
override string toString() { result = c.toString() }
21-
22-
override Location getLocation() { result = c.getLocation() }
23-
24-
override string getPrimaryQlClasses() { result = c.getAstNode().getPrimaryQlClasses() }
25-
}
26-
27-
class NoMaybeControlFlowNode extends MaybeControlFlowNode {
28-
NoMaybeControlFlowNode() { this = TNoControlFlowNode() }
29-
30-
override string toString() { result = "<none>" }
31-
32-
override Location getLocation() { result.toString() = "file://:0:0:0:0" }
33-
34-
override string getPrimaryQlClasses() { result = "<none>" }
35-
}
36-
37-
MaybeControlFlowNode maybeSuccessor(ControlFlowNode n) {
38-
if exists(n.getASuccessor())
39-
then result = TControlFlowNode(n.getASuccessor())
40-
else result = TNoControlFlowNode()
41-
}
42-
43-
from ControlFlowNode n, MaybeControlFlowNode m
4+
from ControlFlowNode n, ControlFlowNode m
445
where
45-
m = maybeSuccessor(n) and
6+
m = getAnAstSuccessor(n) and
467
n.getLocation().getFile().(CompilationUnit).fromSource()
47-
select n, n.getAstNode().getPrimaryQlClasses(), m, m.getPrimaryQlClasses()
8+
select n, n.getAstNode().getPrimaryQlClasses(), m, m.getAstNode().getPrimaryQlClasses()
489

4910
query predicate missingSuccessor(Expr e) {
50-
maybeSuccessor(e.getControlFlowNode()) instanceof NoMaybeControlFlowNode and
11+
exists(ControlFlowNode n | n = e.getControlFlowNode() and not exists(n.getASuccessor())) and
5112
e.getFile().(CompilationUnit).fromSource() and
5213
not e instanceof TypeAccess and
5314
not e instanceof VarWrite

0 commit comments

Comments
 (0)