Skip to content

Commit 54b210f

Browse files
committed
Extract logical not expression
1 parent a2d0b38 commit 54b210f

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,13 +1887,33 @@ open class KotlinFileExtractor(
18871887
}
18881888
}
18891889

1890+
fun unaryopReceiver(id: Label<out DbExpr>, receiver: IrExpression?, receiverDescription: String) {
1891+
val locId = tw.getLocation(c)
1892+
tw.writeHasLocation(id, locId)
1893+
tw.writeCallableEnclosingExpr(id, callable)
1894+
tw.writeStatementEnclosingExpr(id, enclosingStmt)
1895+
1896+
if(receiver == null) {
1897+
logger.errorElement("$receiverDescription not found", c)
1898+
} else {
1899+
extractExpressionExpr(receiver, callable, id, 0, enclosingStmt)
1900+
}
1901+
if(c.valueArgumentsCount > 0) {
1902+
logger.errorElement("Extra arguments found", c)
1903+
}
1904+
}
1905+
18901906
/**
18911907
* Populate the lhs of a binary op from this call's dispatch receiver, and the rhs from its sole argument.
18921908
*/
18931909
fun binopDisp(id: Label<out DbExpr>) {
18941910
binopReceiver(id, c.dispatchReceiver, "Dispatch receiver")
18951911
}
18961912

1913+
fun unaryopDisp(id: Label<out DbExpr>) {
1914+
unaryopReceiver(id, c.dispatchReceiver, "Dispatch receiver")
1915+
}
1916+
18971917
/**
18981918
* Populate the lhs of a binary op from this call's extension receiver, and the rhs from its sole argument.
18991919
*/
@@ -2003,6 +2023,13 @@ open class KotlinFileExtractor(
20032023
tw.writeExprsKotlinType(id, type.kotlinResult.id)
20042024
binOp(id, dr, callable, enclosingStmt)
20052025
}
2026+
isFunction(target, "kotlin", "Boolean", "not") -> {
2027+
val id = tw.getFreshIdLabel<DbLognotexpr>()
2028+
val type = useType(c.type)
2029+
tw.writeExprs_lognotexpr(id, type.javaResult.id, parent, idx)
2030+
tw.writeExprsKotlinType(id, type.kotlinResult.id)
2031+
unaryopDisp(id)
2032+
}
20062033
// We need to handle all the builtin operators defines in BuiltInOperatorNames in
20072034
// compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/IrBuiltIns.kt
20082035
// as they can't be extracted as external dependencies.

java/ql/test/kotlin/library-tests/exprs/CONSISTENCY/javaEquivalent.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Boolean.not in java.lang.Boolean |
2-
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Boolean.not in java.lang.Boolean |
31
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Byte.toInt in java.lang.Byte |
42
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Byte.toInt in java.lang.Byte |
53
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.Byte.toInt in java.lang.Byte |

java/ql/test/kotlin/library-tests/exprs/PrintAst.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,8 +2025,8 @@ exprs.kt:
20252025
# 31| 0: [VarAccess] x
20262026
# 32| 21: [LocalVariableDeclStmt] var ...;
20272027
# 32| 1: [LocalVariableDeclExpr] i22
2028-
# 32| 0: [MethodAccess] not(...)
2029-
# 32| -1: [MethodAccess] contains(...)
2028+
# 32| 0: [LogNotExpr] !...
2029+
# 32| 0: [MethodAccess] contains(...)
20302030
# 32| -1: [MethodAccess] rangeTo(...)
20312031
# 32| -1: [VarAccess] x
20322032
# 32| 0: [VarAccess] y
@@ -2422,8 +2422,8 @@ exprs.kt:
24222422
# 114| 1: [VarAccess] b2
24232423
# 115| 98: [LocalVariableDeclStmt] var ...;
24242424
# 115| 1: [LocalVariableDeclExpr] b5
2425-
# 115| 0: [MethodAccess] not(...)
2426-
# 115| -1: [VarAccess] b1
2425+
# 115| 0: [LogNotExpr] !...
2426+
# 115| 0: [VarAccess] b1
24272427
# 117| 99: [LocalVariableDeclStmt] var ...;
24282428
# 117| 1: [LocalVariableDeclExpr] c
24292429
# 117| 0: [CharacterLiteral] x

java/ql/test/kotlin/library-tests/exprs/exprs.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,8 @@
989989
| exprs.kt:31:25:31:25 | y | exprs.kt:4:1:136:1 | topLevelMethod | VarAccess |
990990
| exprs.kt:32:5:32:26 | i22 | exprs.kt:4:1:136:1 | topLevelMethod | LocalVariableDeclExpr |
991991
| exprs.kt:32:15:32:15 | x | exprs.kt:4:1:136:1 | topLevelMethod | VarAccess |
992+
| exprs.kt:32:15:32:26 | !... | exprs.kt:4:1:136:1 | topLevelMethod | LogNotExpr |
992993
| exprs.kt:32:15:32:26 | contains(...) | exprs.kt:4:1:136:1 | topLevelMethod | MethodAccess |
993-
| exprs.kt:32:15:32:26 | not(...) | exprs.kt:4:1:136:1 | topLevelMethod | MethodAccess |
994994
| exprs.kt:32:21:32:21 | x | exprs.kt:4:1:136:1 | topLevelMethod | VarAccess |
995995
| exprs.kt:32:21:32:26 | rangeTo(...) | exprs.kt:4:1:136:1 | topLevelMethod | MethodAccess |
996996
| exprs.kt:32:26:32:26 | y | exprs.kt:4:1:136:1 | topLevelMethod | VarAccess |
@@ -1308,7 +1308,7 @@
13081308
| exprs.kt:114:14:114:21 | ... \|\| ... | exprs.kt:4:1:136:1 | topLevelMethod | OrLogicalExpr |
13091309
| exprs.kt:114:20:114:21 | b2 | exprs.kt:4:1:136:1 | topLevelMethod | VarAccess |
13101310
| exprs.kt:115:5:115:16 | b5 | exprs.kt:4:1:136:1 | topLevelMethod | LocalVariableDeclExpr |
1311-
| exprs.kt:115:14:115:16 | not(...) | exprs.kt:4:1:136:1 | topLevelMethod | MethodAccess |
1311+
| exprs.kt:115:14:115:16 | !... | exprs.kt:4:1:136:1 | topLevelMethod | LogNotExpr |
13121312
| exprs.kt:115:15:115:16 | b1 | exprs.kt:4:1:136:1 | topLevelMethod | VarAccess |
13131313
| exprs.kt:117:5:117:15 | c | exprs.kt:4:1:136:1 | topLevelMethod | LocalVariableDeclExpr |
13141314
| exprs.kt:117:13:117:15 | x | exprs.kt:4:1:136:1 | topLevelMethod | CharacterLiteral |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
| exprs.kt:32:15:32:26 | !... | exprs.kt:32:15:32:26 | contains(...) |
2+
| exprs.kt:115:14:115:16 | !... | exprs.kt:115:15:115:16 | b1 |
13
| exprs.kt:196:19:196:20 | ...!! | exprs.kt:196:18:196:18 | x |
24
| exprs.kt:205:20:205:21 | ...!! | exprs.kt:205:19:205:19 | s |
35
| exprs.kt:206:20:206:21 | ...!! | exprs.kt:206:19:206:19 | s |

0 commit comments

Comments
 (0)