Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3af8273

Browse files
tamasvajkigfoo
authored andcommitted
Modify extraction of &&/|| to resugar it from when expression
1 parent d33224a commit 3af8273

10 files changed

Lines changed: 78 additions & 156 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,6 +2635,44 @@ open class KotlinFileExtractor(
26352635
}
26362636
}
26372637
is IrWhen -> {
2638+
if (e.origin == IrStatementOrigin.ANDAND ||
2639+
e.origin == IrStatementOrigin.OROR) {
2640+
2641+
// resugar binary logical operators:
2642+
2643+
val exprParent = parent.expr(e, callable)
2644+
val type = useType(e.type)
2645+
2646+
val id = if (e.origin == IrStatementOrigin.ANDAND){
2647+
val id = tw.getFreshIdLabel<DbAndlogicalexpr>()
2648+
tw.writeExprs_andlogicalexpr(id, type.javaResult.id, exprParent.parent, exprParent.idx)
2649+
id
2650+
}
2651+
else {
2652+
val id = tw.getFreshIdLabel<DbOrlogicalexpr>()
2653+
tw.writeExprs_orlogicalexpr(id, type.javaResult.id, exprParent.parent, exprParent.idx)
2654+
id
2655+
}
2656+
val locId = tw.getLocation(e)
2657+
2658+
tw.writeExprsKotlinType(id, type.kotlinResult.id)
2659+
tw.writeHasLocation(id, locId)
2660+
tw.writeCallableEnclosingExpr(id, callable)
2661+
tw.writeStatementEnclosingExpr(id, exprParent.enclosingStmt)
2662+
2663+
if (e.branches.size != 2) {
2664+
logger.errorElement("Expected to find 2 when branches for ${e.origin}, found ${e.branches.size}", e)
2665+
return
2666+
}
2667+
2668+
extractExpressionExpr(e.branches[0].condition, callable, id, 0, exprParent.enclosingStmt)
2669+
2670+
var rhsIdx = if (e.origin == IrStatementOrigin.ANDAND) 0 else 1
2671+
extractExpressionExpr(e.branches[rhsIdx].result, callable, id, 1, exprParent.enclosingStmt)
2672+
2673+
return
2674+
}
2675+
26382676
val exprParent = parent.expr(e, callable)
26392677
val id = tw.getFreshIdLabel<DbWhenexpr>()
26402678
val type = useType(e.type)

java/ql/test/kotlin/library-tests/controlflow/basic/bbStmts.expected

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,13 @@
137137
| Test.kt:100:25:110:1 | { ... } | 1 | Test.kt:101:5:103:5 | <Expr>; |
138138
| Test.kt:100:25:110:1 | { ... } | 2 | Test.kt:101:5:103:5 | when ... |
139139
| Test.kt:100:25:110:1 | { ... } | 3 | Test.kt:101:5:103:5 | ... -> ... |
140-
| Test.kt:100:25:110:1 | { ... } | 4 | Test.kt:101:9:101:30 | when ... |
141-
| Test.kt:100:25:110:1 | { ... } | 5 | Test.kt:101:9:101:30 | ... -> ... |
142-
| Test.kt:100:25:110:1 | { ... } | 6 | Test.kt:101:9:101:9 | x |
143-
| Test.kt:100:25:110:1 | { ... } | 7 | Test.kt:101:14:101:17 | null |
144-
| Test.kt:100:25:110:1 | { ... } | 8 | Test.kt:101:9:101:17 | ... (value equals) ... |
145-
| Test.kt:101:22:101:30 | ... -> ... | 0 | Test.kt:101:22:101:30 | ... -> ... |
146-
| Test.kt:101:22:101:30 | ... -> ... | 1 | Test.kt:101:22:101:30 | true |
147-
| Test.kt:101:22:101:30 | ... -> ... | 2 | Test.kt:101:22:101:30 | <Expr>; |
148-
| Test.kt:101:22:101:30 | ... -> ... | 3 | Test.kt:101:22:101:30 | false |
149-
| Test.kt:101:22:101:30 | <Expr>; | 0 | Test.kt:101:22:101:30 | <Expr>; |
150-
| Test.kt:101:22:101:30 | <Expr>; | 1 | Test.kt:101:22:101:22 | y |
151-
| Test.kt:101:22:101:30 | <Expr>; | 2 | Test.kt:101:27:101:30 | null |
152-
| Test.kt:101:22:101:30 | <Expr>; | 3 | Test.kt:101:22:101:30 | ... (value equals) ... |
140+
| Test.kt:100:25:110:1 | { ... } | 4 | Test.kt:101:9:101:30 | ... && ... |
141+
| Test.kt:100:25:110:1 | { ... } | 5 | Test.kt:101:9:101:9 | x |
142+
| Test.kt:100:25:110:1 | { ... } | 6 | Test.kt:101:14:101:17 | null |
143+
| Test.kt:100:25:110:1 | { ... } | 7 | Test.kt:101:9:101:17 | ... (value equals) ... |
144+
| Test.kt:101:22:101:22 | y | 0 | Test.kt:101:22:101:22 | y |
145+
| Test.kt:101:22:101:22 | y | 1 | Test.kt:101:27:101:30 | null |
146+
| Test.kt:101:22:101:22 | y | 2 | Test.kt:101:22:101:30 | ... (value equals) ... |
153147
| Test.kt:101:33:103:5 | { ... } | 0 | Test.kt:101:33:103:5 | { ... } |
154148
| Test.kt:101:33:103:5 | { ... } | 1 | Test.kt:102:15:102:25 | new Exception(...) |
155149
| Test.kt:101:33:103:5 | { ... } | 2 | Test.kt:102:9:102:25 | throw ... |
@@ -176,15 +170,9 @@
176170
| Test.kt:112:32:116:1 | { ... } | 1 | Test.kt:113:5:115:5 | <Expr>; |
177171
| Test.kt:112:32:116:1 | { ... } | 2 | Test.kt:113:5:115:5 | when ... |
178172
| Test.kt:112:32:116:1 | { ... } | 3 | Test.kt:113:5:115:5 | ... -> ... |
179-
| Test.kt:112:32:116:1 | { ... } | 4 | Test.kt:113:9:113:14 | when ... |
180-
| Test.kt:112:32:116:1 | { ... } | 5 | Test.kt:113:9:113:14 | ... -> ... |
181-
| Test.kt:112:32:116:1 | { ... } | 6 | Test.kt:113:9:113:9 | x |
182-
| Test.kt:113:14:113:14 | ... -> ... | 0 | Test.kt:113:14:113:14 | ... -> ... |
183-
| Test.kt:113:14:113:14 | ... -> ... | 1 | Test.kt:113:14:113:14 | true |
184-
| Test.kt:113:14:113:14 | ... -> ... | 2 | Test.kt:113:14:113:14 | <Expr>; |
185-
| Test.kt:113:14:113:14 | ... -> ... | 3 | Test.kt:113:14:113:14 | false |
186-
| Test.kt:113:14:113:14 | <Expr>; | 0 | Test.kt:113:14:113:14 | <Expr>; |
187-
| Test.kt:113:14:113:14 | <Expr>; | 1 | Test.kt:113:14:113:14 | y |
173+
| Test.kt:112:32:116:1 | { ... } | 4 | Test.kt:113:9:113:14 | ... && ... |
174+
| Test.kt:112:32:116:1 | { ... } | 5 | Test.kt:113:9:113:9 | x |
175+
| Test.kt:113:14:113:14 | y | 0 | Test.kt:113:14:113:14 | y |
188176
| Test.kt:113:17:115:5 | { ... } | 0 | Test.kt:113:17:115:5 | { ... } |
189177
| Test.kt:118:1:124:1 | fn_when | 0 | Test.kt:118:1:124:1 | fn_when |
190178
| Test.kt:118:37:124:1 | { ... } | 0 | Test.kt:118:37:124:1 | { ... } |

java/ql/test/kotlin/library-tests/controlflow/basic/bbStrictDominance.expected

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,21 @@
3434
| Test.kt:91:22:98:1 | { ... } | Test.kt:93:3:93:13 | x |
3535
| Test.kt:91:22:98:1 | { ... } | Test.kt:95:4:97:2 | catch (...) |
3636
| Test.kt:100:25:110:1 | { ... } | Test.kt:100:1:110:1 | fn |
37-
| Test.kt:100:25:110:1 | { ... } | Test.kt:101:22:101:30 | ... -> ... |
38-
| Test.kt:100:25:110:1 | { ... } | Test.kt:101:22:101:30 | <Expr>; |
37+
| Test.kt:100:25:110:1 | { ... } | Test.kt:101:22:101:22 | y |
3938
| Test.kt:100:25:110:1 | { ... } | Test.kt:101:33:103:5 | { ... } |
4039
| Test.kt:100:25:110:1 | { ... } | Test.kt:105:5:109:5 | <Expr>; |
4140
| Test.kt:100:25:110:1 | { ... } | Test.kt:105:20:107:5 | { ... } |
4241
| Test.kt:100:25:110:1 | { ... } | Test.kt:107:16:109:5 | ... -> ... |
4342
| Test.kt:100:25:110:1 | { ... } | Test.kt:107:27:109:5 | { ... } |
44-
| Test.kt:101:22:101:30 | <Expr>; | Test.kt:100:1:110:1 | fn |
45-
| Test.kt:101:22:101:30 | <Expr>; | Test.kt:101:33:103:5 | { ... } |
46-
| Test.kt:101:22:101:30 | <Expr>; | Test.kt:105:5:109:5 | <Expr>; |
47-
| Test.kt:101:22:101:30 | <Expr>; | Test.kt:105:20:107:5 | { ... } |
48-
| Test.kt:101:22:101:30 | <Expr>; | Test.kt:107:16:109:5 | ... -> ... |
49-
| Test.kt:101:22:101:30 | <Expr>; | Test.kt:107:27:109:5 | { ... } |
43+
| Test.kt:101:22:101:22 | y | Test.kt:101:33:103:5 | { ... } |
5044
| Test.kt:105:5:109:5 | <Expr>; | Test.kt:105:20:107:5 | { ... } |
5145
| Test.kt:105:5:109:5 | <Expr>; | Test.kt:107:16:109:5 | ... -> ... |
5246
| Test.kt:105:5:109:5 | <Expr>; | Test.kt:107:27:109:5 | { ... } |
5347
| Test.kt:107:16:109:5 | ... -> ... | Test.kt:107:27:109:5 | { ... } |
5448
| Test.kt:112:32:116:1 | { ... } | Test.kt:112:1:116:1 | fn |
55-
| Test.kt:112:32:116:1 | { ... } | Test.kt:113:14:113:14 | ... -> ... |
56-
| Test.kt:112:32:116:1 | { ... } | Test.kt:113:14:113:14 | <Expr>; |
49+
| Test.kt:112:32:116:1 | { ... } | Test.kt:113:14:113:14 | y |
5750
| Test.kt:112:32:116:1 | { ... } | Test.kt:113:17:115:5 | { ... } |
58-
| Test.kt:113:14:113:14 | <Expr>; | Test.kt:112:1:116:1 | fn |
59-
| Test.kt:113:14:113:14 | <Expr>; | Test.kt:113:17:115:5 | { ... } |
51+
| Test.kt:113:14:113:14 | y | Test.kt:113:17:115:5 | { ... } |
6052
| Test.kt:118:37:124:1 | { ... } | Test.kt:118:1:124:1 | fn_when |
6153
| Test.kt:118:37:124:1 | { ... } | Test.kt:121:9:121:9 | <Expr>; |
6254
| Test.kt:118:37:124:1 | { ... } | Test.kt:122:12:122:16 | ... -> ... |

java/ql/test/kotlin/library-tests/controlflow/basic/bbSuccessor.expected

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@
2121
| Test.kt:91:22:98:1 | { ... } | Test.kt:95:4:97:2 | catch (...) |
2222
| Test.kt:93:3:93:13 | x | Test.kt:91:1:98:1 | t2 |
2323
| Test.kt:95:4:97:2 | catch (...) | Test.kt:91:1:98:1 | t2 |
24-
| Test.kt:100:25:110:1 | { ... } | Test.kt:101:22:101:30 | ... -> ... |
25-
| Test.kt:100:25:110:1 | { ... } | Test.kt:101:22:101:30 | <Expr>; |
26-
| Test.kt:101:22:101:30 | <Expr>; | Test.kt:101:33:103:5 | { ... } |
27-
| Test.kt:101:22:101:30 | <Expr>; | Test.kt:105:5:109:5 | <Expr>; |
24+
| Test.kt:100:25:110:1 | { ... } | Test.kt:101:22:101:22 | y |
25+
| Test.kt:100:25:110:1 | { ... } | Test.kt:105:5:109:5 | <Expr>; |
26+
| Test.kt:101:22:101:22 | y | Test.kt:101:33:103:5 | { ... } |
27+
| Test.kt:101:22:101:22 | y | Test.kt:105:5:109:5 | <Expr>; |
2828
| Test.kt:101:33:103:5 | { ... } | Test.kt:100:1:110:1 | fn |
2929
| Test.kt:105:5:109:5 | <Expr>; | Test.kt:105:20:107:5 | { ... } |
3030
| Test.kt:105:5:109:5 | <Expr>; | Test.kt:107:16:109:5 | ... -> ... |
3131
| Test.kt:105:20:107:5 | { ... } | Test.kt:100:1:110:1 | fn |
3232
| Test.kt:107:16:109:5 | ... -> ... | Test.kt:100:1:110:1 | fn |
3333
| Test.kt:107:16:109:5 | ... -> ... | Test.kt:107:27:109:5 | { ... } |
3434
| Test.kt:107:27:109:5 | { ... } | Test.kt:100:1:110:1 | fn |
35-
| Test.kt:112:32:116:1 | { ... } | Test.kt:113:14:113:14 | ... -> ... |
36-
| Test.kt:112:32:116:1 | { ... } | Test.kt:113:14:113:14 | <Expr>; |
37-
| Test.kt:113:14:113:14 | <Expr>; | Test.kt:112:1:116:1 | fn |
38-
| Test.kt:113:14:113:14 | <Expr>; | Test.kt:113:17:115:5 | { ... } |
35+
| Test.kt:112:32:116:1 | { ... } | Test.kt:112:1:116:1 | fn |
36+
| Test.kt:112:32:116:1 | { ... } | Test.kt:113:14:113:14 | y |
37+
| Test.kt:113:14:113:14 | y | Test.kt:112:1:116:1 | fn |
38+
| Test.kt:113:14:113:14 | y | Test.kt:113:17:115:5 | { ... } |
3939
| Test.kt:113:17:115:5 | { ... } | Test.kt:112:1:116:1 | fn |
4040
| Test.kt:118:37:124:1 | { ... } | Test.kt:121:9:121:9 | <Expr>; |
4141
| Test.kt:118:37:124:1 | { ... } | Test.kt:122:12:122:16 | ... -> ... |

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

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
missingSuccessor
2-
| Test.kt:101:22:101:30 | false |
3-
| Test.kt:113:14:113:14 | false |
42
| Test.kt:122:12:122:16 | false |
53
#select
64
| Test.kt:0:0:0:0 | TestKt | Class | file://:0:0:0:0 | <none> | <none> |
@@ -186,23 +184,17 @@ missingSuccessor
186184
| Test.kt:100:16:100:22 | Object | TypeAccess | file://:0:0:0:0 | <none> | <none> |
187185
| Test.kt:100:16:100:22 | y | Parameter | file://:0:0:0:0 | <none> | <none> |
188186
| Test.kt:100:25:110:1 | { ... } | BlockStmt | Test.kt:101:5:103:5 | <Expr>; | ExprStmt |
189-
| Test.kt:101:5:103:5 | ... -> ... | WhenBranch | Test.kt:101:9:101:30 | when ... | WhenExpr |
187+
| Test.kt:101:5:103:5 | ... -> ... | WhenBranch | Test.kt:101:9:101:30 | ... && ... | AndLogicalExpr |
190188
| Test.kt:101:5:103:5 | <Expr>; | ExprStmt | Test.kt:101:5:103:5 | when ... | WhenExpr |
191189
| Test.kt:101:5:103:5 | when ... | WhenExpr | Test.kt:101:5:103:5 | ... -> ... | WhenBranch |
192190
| Test.kt:101:9:101:9 | x | VarAccess | Test.kt:101:14:101:17 | null | NullLiteral |
193-
| Test.kt:101:9:101:17 | ... (value equals) ... | ValueEQExpr | Test.kt:101:22:101:30 | ... -> ... | WhenBranch |
194-
| Test.kt:101:9:101:17 | ... (value equals) ... | ValueEQExpr | Test.kt:101:22:101:30 | <Expr>; | ExprStmt |
195-
| Test.kt:101:9:101:30 | ... -> ... | WhenBranch | Test.kt:101:9:101:9 | x | VarAccess |
196-
| Test.kt:101:9:101:30 | when ... | WhenExpr | Test.kt:101:9:101:30 | ... -> ... | WhenBranch |
191+
| Test.kt:101:9:101:17 | ... (value equals) ... | ValueEQExpr | Test.kt:101:22:101:22 | y | VarAccess |
192+
| Test.kt:101:9:101:17 | ... (value equals) ... | ValueEQExpr | Test.kt:105:5:109:5 | <Expr>; | ExprStmt |
193+
| Test.kt:101:9:101:30 | ... && ... | AndLogicalExpr | Test.kt:101:9:101:9 | x | VarAccess |
197194
| Test.kt:101:14:101:17 | null | NullLiteral | Test.kt:101:9:101:17 | ... (value equals) ... | ValueEQExpr |
198195
| Test.kt:101:22:101:22 | y | VarAccess | Test.kt:101:27:101:30 | null | NullLiteral |
199196
| Test.kt:101:22:101:30 | ... (value equals) ... | ValueEQExpr | Test.kt:101:33:103:5 | { ... } | BlockStmt |
200197
| Test.kt:101:22:101:30 | ... (value equals) ... | ValueEQExpr | Test.kt:105:5:109:5 | <Expr>; | ExprStmt |
201-
| Test.kt:101:22:101:30 | ... -> ... | WhenBranch | Test.kt:101:22:101:30 | true | BooleanLiteral |
202-
| Test.kt:101:22:101:30 | <Expr>; | ExprStmt | Test.kt:101:22:101:22 | y | VarAccess |
203-
| Test.kt:101:22:101:30 | <Expr>; | ExprStmt | Test.kt:101:22:101:30 | false | BooleanLiteral |
204-
| Test.kt:101:22:101:30 | false | BooleanLiteral | file://:0:0:0:0 | <none> | <none> |
205-
| Test.kt:101:22:101:30 | true | BooleanLiteral | Test.kt:101:22:101:30 | <Expr>; | ExprStmt |
206198
| Test.kt:101:27:101:30 | null | NullLiteral | Test.kt:101:22:101:30 | ... (value equals) ... | ValueEQExpr |
207199
| Test.kt:101:33:103:5 | { ... } | BlockStmt | Test.kt:102:15:102:25 | new Exception(...) | ClassInstanceExpr |
208200
| Test.kt:102:9:102:25 | throw ... | ThrowStmt | Test.kt:100:1:110:1 | fn | Method |
@@ -237,18 +229,12 @@ missingSuccessor
237229
| Test.kt:112:20:112:29 | boolean | TypeAccess | file://:0:0:0:0 | <none> | <none> |
238230
| Test.kt:112:20:112:29 | y | Parameter | file://:0:0:0:0 | <none> | <none> |
239231
| Test.kt:112:32:116:1 | { ... } | BlockStmt | Test.kt:113:5:115:5 | <Expr>; | ExprStmt |
240-
| Test.kt:113:5:115:5 | ... -> ... | WhenBranch | Test.kt:113:9:113:14 | when ... | WhenExpr |
232+
| Test.kt:113:5:115:5 | ... -> ... | WhenBranch | Test.kt:113:9:113:14 | ... && ... | AndLogicalExpr |
241233
| Test.kt:113:5:115:5 | <Expr>; | ExprStmt | Test.kt:113:5:115:5 | when ... | WhenExpr |
242234
| Test.kt:113:5:115:5 | when ... | WhenExpr | Test.kt:113:5:115:5 | ... -> ... | WhenBranch |
243-
| Test.kt:113:9:113:9 | x | VarAccess | Test.kt:113:14:113:14 | ... -> ... | WhenBranch |
244-
| Test.kt:113:9:113:9 | x | VarAccess | Test.kt:113:14:113:14 | <Expr>; | ExprStmt |
245-
| Test.kt:113:9:113:14 | ... -> ... | WhenBranch | Test.kt:113:9:113:9 | x | VarAccess |
246-
| Test.kt:113:9:113:14 | when ... | WhenExpr | Test.kt:113:9:113:14 | ... -> ... | WhenBranch |
247-
| Test.kt:113:14:113:14 | ... -> ... | WhenBranch | Test.kt:113:14:113:14 | true | BooleanLiteral |
248-
| Test.kt:113:14:113:14 | <Expr>; | ExprStmt | Test.kt:113:14:113:14 | false | BooleanLiteral |
249-
| Test.kt:113:14:113:14 | <Expr>; | ExprStmt | Test.kt:113:14:113:14 | y | VarAccess |
250-
| Test.kt:113:14:113:14 | false | BooleanLiteral | file://:0:0:0:0 | <none> | <none> |
251-
| Test.kt:113:14:113:14 | true | BooleanLiteral | Test.kt:113:14:113:14 | <Expr>; | ExprStmt |
235+
| Test.kt:113:9:113:9 | x | VarAccess | Test.kt:112:1:116:1 | fn | Method |
236+
| Test.kt:113:9:113:9 | x | VarAccess | Test.kt:113:14:113:14 | y | VarAccess |
237+
| Test.kt:113:9:113:14 | ... && ... | AndLogicalExpr | Test.kt:113:9:113:9 | x | VarAccess |
252238
| Test.kt:113:14:113:14 | y | VarAccess | Test.kt:112:1:116:1 | fn | Method |
253239
| Test.kt:113:14:113:14 | y | VarAccess | Test.kt:113:17:115:5 | { ... } | BlockStmt |
254240
| Test.kt:113:17:115:5 | { ... } | BlockStmt | Test.kt:112:1:116:1 | fn | Method |

0 commit comments

Comments
 (0)