mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Kotlin: extract operator expression when operator is in method call form
This commit is contained in:
@@ -1901,9 +1901,8 @@ open class KotlinFileExtractor(
|
||||
|
||||
val dr = c.dispatchReceiver
|
||||
when {
|
||||
c.origin == IrStatementOrigin.PLUS &&
|
||||
(isNumericFunction(target, "plus")
|
||||
|| isFunction(target, "kotlin", "String", "plus", null)) -> {
|
||||
isNumericFunction(target, "plus")
|
||||
|| isFunction(target, "kotlin", "String", "plus", false) -> {
|
||||
val id = tw.getFreshIdLabel<DbAddexpr>()
|
||||
val type = useType(c.type)
|
||||
tw.writeExprs_addexpr(id, type.javaResult.id, parent, idx)
|
||||
@@ -1918,28 +1917,28 @@ open class KotlinFileExtractor(
|
||||
extractRawMethodAccess(stringPlusFn, c, callable, parent, idx, enclosingStmt, listOf(c.extensionReceiver, c.getValueArgument(0)), null, null)
|
||||
}
|
||||
}
|
||||
c.origin == IrStatementOrigin.MINUS && isNumericFunction(target, "minus") -> {
|
||||
isNumericFunction(target, "minus") -> {
|
||||
val id = tw.getFreshIdLabel<DbSubexpr>()
|
||||
val type = useType(c.type)
|
||||
tw.writeExprs_subexpr(id, type.javaResult.id, parent, idx)
|
||||
tw.writeExprsKotlinType(id, type.kotlinResult.id)
|
||||
binopDisp(id)
|
||||
}
|
||||
c.origin == IrStatementOrigin.MUL && isNumericFunction(target, "times") -> {
|
||||
isNumericFunction(target, "times") -> {
|
||||
val id = tw.getFreshIdLabel<DbMulexpr>()
|
||||
val type = useType(c.type)
|
||||
tw.writeExprs_mulexpr(id, type.javaResult.id, parent, idx)
|
||||
tw.writeExprsKotlinType(id, type.kotlinResult.id)
|
||||
binopDisp(id)
|
||||
}
|
||||
c.origin == IrStatementOrigin.DIV && isNumericFunction(target, "div") -> {
|
||||
isNumericFunction(target, "div") -> {
|
||||
val id = tw.getFreshIdLabel<DbDivexpr>()
|
||||
val type = useType(c.type)
|
||||
tw.writeExprs_divexpr(id, type.javaResult.id, parent, idx)
|
||||
tw.writeExprsKotlinType(id, type.kotlinResult.id)
|
||||
binopDisp(id)
|
||||
}
|
||||
c.origin == IrStatementOrigin.PERC && isNumericFunction(target, "rem") -> {
|
||||
isNumericFunction(target, "rem") -> {
|
||||
val id = tw.getFreshIdLabel<DbRemexpr>()
|
||||
val type = useType(c.type)
|
||||
tw.writeExprs_remexpr(id, type.javaResult.id, parent, idx)
|
||||
|
||||
@@ -125,11 +125,11 @@ app/src/main/kotlin/testProject/App.kt:
|
||||
# 0| 1: [ExprStmt] <Expr>;
|
||||
# 0| 0: [AssignExpr] ...=...
|
||||
# 0| 0: [VarAccess] result
|
||||
# 0| 1: [MethodAccess] plus(...)
|
||||
# 0| -1: [MethodAccess] times(...)
|
||||
# 0| -1: [VarAccess] result
|
||||
# 0| 0: [IntegerLiteral] 31
|
||||
# 0| 0: [MethodAccess] hashCode(...)
|
||||
# 0| 1: [AddExpr] ... + ...
|
||||
# 0| 0: [MulExpr] ... * ...
|
||||
# 0| 0: [VarAccess] result
|
||||
# 0| 1: [IntegerLiteral] 31
|
||||
# 0| 1: [MethodAccess] hashCode(...)
|
||||
# 0| -1: [VarAccess] this.language
|
||||
# 0| -1: [ThisAccess] this
|
||||
# 0| 2: [ReturnStmt] return ...
|
||||
|
||||
@@ -89,11 +89,11 @@ dc.kt:
|
||||
# 0| 1: [ExprStmt] <Expr>;
|
||||
# 0| 0: [AssignExpr] ...=...
|
||||
# 0| 0: [VarAccess] result
|
||||
# 0| 1: [MethodAccess] plus(...)
|
||||
# 0| -1: [MethodAccess] times(...)
|
||||
# 0| -1: [VarAccess] result
|
||||
# 0| 0: [IntegerLiteral] 31
|
||||
# 0| 0: [MethodAccess] hashCode(...)
|
||||
# 0| 1: [AddExpr] ... + ...
|
||||
# 0| 0: [MulExpr] ... * ...
|
||||
# 0| 0: [VarAccess] result
|
||||
# 0| 1: [IntegerLiteral] 31
|
||||
# 0| 1: [MethodAccess] hashCode(...)
|
||||
# 0| -1: [TypeAccess] Arrays
|
||||
# 0| 0: [VarAccess] this.strs
|
||||
# 0| -1: [ThisAccess] this
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
| dc.kt:0:0:0:0 | hashCode(...) | java.util.Arrays.hashCode |
|
||||
| dc.kt:0:0:0:0 | hashCode(...) | java.util.Arrays.hashCode |
|
||||
| dc.kt:0:0:0:0 | new ProtoMapValue(...) | ProtoMapValue.ProtoMapValue |
|
||||
| dc.kt:0:0:0:0 | plus(...) | kotlin.Int.plus |
|
||||
| dc.kt:0:0:0:0 | times(...) | kotlin.Int.times |
|
||||
| dc.kt:0:0:0:0 | toString(...) | java.util.Arrays.toString |
|
||||
| dc.kt:0:0:0:0 | toString(...) | java.util.Arrays.toString |
|
||||
| dc.kt:1:1:1:71 | super(...) | java.lang.Object.Object |
|
||||
|
||||
@@ -2473,7 +2473,8 @@ exprs.kt:
|
||||
# 127| 0: [VarAccess] str1
|
||||
# 127| 1: [VarAccess] str2
|
||||
# 127| 2: [StringLiteral] bar
|
||||
# 127| 3: [AddExpr] ... + ...
|
||||
# 127| 3: [MethodAccess] stringPlus(...)
|
||||
# 127| -1: [TypeAccess] Intrinsics
|
||||
# 127| 0: [VarAccess] str2
|
||||
# 127| 1: [VarAccess] str1
|
||||
# 127| 4: [StringLiteral] baz
|
||||
@@ -3052,15 +3053,16 @@ exprs.kt:
|
||||
# 203| 1: [IntegerLiteral] 5
|
||||
# 204| 2: [LocalVariableDeclStmt] var ...;
|
||||
# 204| 1: [LocalVariableDeclExpr] b1
|
||||
# 204| 0: [AddExpr] ... + ...
|
||||
# 204| 0: [MethodAccess] stringPlus(...)
|
||||
# 204| -1: [TypeAccess] Intrinsics
|
||||
# 204| 0: [VarAccess] s
|
||||
# 204| 1: [IntegerLiteral] 5
|
||||
# 205| 3: [LocalVariableDeclStmt] var ...;
|
||||
# 205| 1: [LocalVariableDeclExpr] b2
|
||||
# 205| 0: [MethodAccess] plus(...)
|
||||
# 205| -1: [NotNullExpr] ...!!
|
||||
# 205| 0: [AddExpr] ... + ...
|
||||
# 205| 0: [NotNullExpr] ...!!
|
||||
# 205| 0: [VarAccess] s
|
||||
# 205| 0: [IntegerLiteral] 5
|
||||
# 205| 1: [IntegerLiteral] 5
|
||||
# 206| 4: [LocalVariableDeclStmt] var ...;
|
||||
# 206| 1: [LocalVariableDeclExpr] b3
|
||||
# 206| 0: [AddExpr] ... + ...
|
||||
|
||||
@@ -73,13 +73,12 @@
|
||||
| exprs.kt:113:14:113:21 | ... && ... | exprs.kt:113:14:113:15 | b1 | exprs.kt:113:20:113:21 | b2 |
|
||||
| exprs.kt:114:14:114:21 | ... \|\| ... | exprs.kt:114:14:114:15 | b1 | exprs.kt:114:20:114:21 | b2 |
|
||||
| exprs.kt:127:31:127:41 | ... + ... | exprs.kt:127:31:127:34 | str1 | exprs.kt:127:38:127:41 | str2 |
|
||||
| exprs.kt:127:50:127:60 | ... + ... | exprs.kt:127:50:127:53 | str2 | exprs.kt:127:57:127:60 | str1 |
|
||||
| exprs.kt:128:16:128:26 | ... + ... | exprs.kt:128:16:128:19 | str1 | exprs.kt:128:23:128:26 | str2 |
|
||||
| exprs.kt:131:12:131:23 | ... > ... | exprs.kt:131:12:131:19 | variable | exprs.kt:131:23:131:23 | 0 |
|
||||
| exprs.kt:135:12:135:20 | ... + ... | exprs.kt:135:12:135:14 | 123 | exprs.kt:135:18:135:20 | 456 |
|
||||
| exprs.kt:161:8:161:16 | ... (value not-equals) ... | exprs.kt:161:8:161:8 | r | exprs.kt:161:13:161:16 | null |
|
||||
| exprs.kt:190:31:190:37 | ... + ... | exprs.kt:190:31:190:32 | getA1(...) | exprs.kt:190:36:190:37 | a2 |
|
||||
| exprs.kt:204:19:204:23 | ... + ... | exprs.kt:204:19:204:19 | s | exprs.kt:204:23:204:23 | 5 |
|
||||
| exprs.kt:205:23:205:29 | ... + ... | exprs.kt:205:20:205:21 | ...!! | exprs.kt:205:28:205:28 | 5 |
|
||||
| exprs.kt:206:19:206:25 | ... + ... | exprs.kt:206:20:206:21 | ...!! | exprs.kt:206:25:206:25 | 5 |
|
||||
| exprs.kt:224:12:224:47 | ... (value equals) ... | exprs.kt:224:12:224:27 | notNullPrimitive | exprs.kt:224:32:224:47 | notNullPrimitive |
|
||||
| exprs.kt:225:12:225:48 | ... (value equals) ... | exprs.kt:225:12:225:27 | notNullPrimitive | exprs.kt:225:32:225:48 | nullablePrimitive |
|
||||
|
||||
@@ -1349,7 +1349,8 @@
|
||||
| exprs.kt:127:38:127:41 | str2 | exprs.kt:4:1:136:1 | topLevelMethod | VarAccess |
|
||||
| exprs.kt:127:43:127:47 | bar | exprs.kt:4:1:136:1 | topLevelMethod | StringLiteral |
|
||||
| exprs.kt:127:50:127:53 | str2 | exprs.kt:4:1:136:1 | topLevelMethod | VarAccess |
|
||||
| exprs.kt:127:50:127:60 | ... + ... | exprs.kt:4:1:136:1 | topLevelMethod | AddExpr |
|
||||
| exprs.kt:127:50:127:60 | Intrinsics | exprs.kt:4:1:136:1 | topLevelMethod | TypeAccess |
|
||||
| exprs.kt:127:50:127:60 | stringPlus(...) | exprs.kt:4:1:136:1 | topLevelMethod | MethodAccess |
|
||||
| exprs.kt:127:57:127:60 | str1 | exprs.kt:4:1:136:1 | topLevelMethod | VarAccess |
|
||||
| exprs.kt:127:62:127:65 | baz | exprs.kt:4:1:136:1 | topLevelMethod | StringLiteral |
|
||||
| exprs.kt:128:5:128:26 | str6 | exprs.kt:4:1:136:1 | topLevelMethod | LocalVariableDeclExpr |
|
||||
@@ -1554,12 +1555,13 @@
|
||||
| exprs.kt:203:26:203:26 | 5 | exprs.kt:200:5:211:5 | x | IntegerLiteral |
|
||||
| exprs.kt:204:9:204:23 | b1 | exprs.kt:200:5:211:5 | x | LocalVariableDeclExpr |
|
||||
| exprs.kt:204:19:204:19 | s | exprs.kt:200:5:211:5 | x | VarAccess |
|
||||
| exprs.kt:204:19:204:23 | ... + ... | exprs.kt:200:5:211:5 | x | AddExpr |
|
||||
| exprs.kt:204:19:204:23 | Intrinsics | exprs.kt:200:5:211:5 | x | TypeAccess |
|
||||
| exprs.kt:204:19:204:23 | stringPlus(...) | exprs.kt:200:5:211:5 | x | MethodAccess |
|
||||
| exprs.kt:204:23:204:23 | 5 | exprs.kt:200:5:211:5 | x | IntegerLiteral |
|
||||
| exprs.kt:205:9:205:29 | b2 | exprs.kt:200:5:211:5 | x | LocalVariableDeclExpr |
|
||||
| exprs.kt:205:19:205:19 | s | exprs.kt:200:5:211:5 | x | VarAccess |
|
||||
| exprs.kt:205:20:205:21 | ...!! | exprs.kt:200:5:211:5 | x | NotNullExpr |
|
||||
| exprs.kt:205:23:205:29 | plus(...) | exprs.kt:200:5:211:5 | x | MethodAccess |
|
||||
| exprs.kt:205:23:205:29 | ... + ... | exprs.kt:200:5:211:5 | x | AddExpr |
|
||||
| exprs.kt:205:28:205:28 | 5 | exprs.kt:200:5:211:5 | x | IntegerLiteral |
|
||||
| exprs.kt:206:9:206:25 | b3 | exprs.kt:200:5:211:5 | x | LocalVariableDeclExpr |
|
||||
| exprs.kt:206:19:206:19 | s | exprs.kt:200:5:211:5 | x | VarAccess |
|
||||
|
||||
@@ -43,9 +43,9 @@ test.kt:
|
||||
# 9| 0: [TypeAccess] String
|
||||
# 9| 5: [BlockStmt] { ... }
|
||||
# 9| 0: [ReturnStmt] return ...
|
||||
# 9| 0: [MethodAccess] plus(...)
|
||||
# 9| -1: [VarAccess] s
|
||||
# 9| 0: [StringLiteral]
|
||||
# 9| 0: [AddExpr] ... + ...
|
||||
# 9| 0: [VarAccess] s
|
||||
# 9| 1: [StringLiteral]
|
||||
# 10| 5: [Method] fn2
|
||||
# 10| 3: [TypeAccess] String
|
||||
#-----| 4: (Parameters)
|
||||
@@ -63,9 +63,9 @@ test.kt:
|
||||
# 12| 0: [TypeAccess] int
|
||||
# 12| 5: [BlockStmt] { ... }
|
||||
# 12| 0: [ReturnStmt] return ...
|
||||
# 12| 0: [MethodAccess] minus(...)
|
||||
# 12| -1: [VarAccess] i
|
||||
# 12| 0: [IntegerLiteral] 10
|
||||
# 12| 0: [SubExpr] ... - ...
|
||||
# 12| 0: [VarAccess] i
|
||||
# 12| 1: [IntegerLiteral] 10
|
||||
# 13| 7: [Method] fn2
|
||||
# 13| 3: [TypeAccess] int
|
||||
#-----| 4: (Parameters)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
diagnostics
|
||||
| file://:0:0:0:0 | Couldn't find a Java equivalent function to kotlin.String.plus in java.lang.String |
|
||||
#select
|
||||
| Integer |
|
||||
| Object |
|
||||
| int |
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
| dataClass.kt:0:0:0:0 | ... !is ... | NotInstanceOfExpr |
|
||||
| dataClass.kt:0:0:0:0 | ... (value not-equals) ... | ValueNEExpr |
|
||||
| dataClass.kt:0:0:0:0 | ... (value not-equals) ... | ValueNEExpr |
|
||||
| dataClass.kt:0:0:0:0 | ... * ... | MulExpr |
|
||||
| dataClass.kt:0:0:0:0 | ... + ... | AddExpr |
|
||||
| dataClass.kt:0:0:0:0 | ... == ... | EQExpr |
|
||||
| dataClass.kt:0:0:0:0 | ...=... | AssignExpr |
|
||||
| dataClass.kt:0:0:0:0 | DataClass | TypeAccess |
|
||||
@@ -42,7 +44,6 @@
|
||||
| dataClass.kt:0:0:0:0 | other | VarAccess |
|
||||
| dataClass.kt:0:0:0:0 | other | VarAccess |
|
||||
| dataClass.kt:0:0:0:0 | other | VarAccess |
|
||||
| dataClass.kt:0:0:0:0 | plus(...) | MethodAccess |
|
||||
| dataClass.kt:0:0:0:0 | result | LocalVariableDeclExpr |
|
||||
| dataClass.kt:0:0:0:0 | result | VarAccess |
|
||||
| dataClass.kt:0:0:0:0 | result | VarAccess |
|
||||
@@ -64,7 +65,6 @@
|
||||
| dataClass.kt:0:0:0:0 | this.y | VarAccess |
|
||||
| dataClass.kt:0:0:0:0 | this.y | VarAccess |
|
||||
| dataClass.kt:0:0:0:0 | this.y | VarAccess |
|
||||
| dataClass.kt:0:0:0:0 | times(...) | MethodAccess |
|
||||
| dataClass.kt:0:0:0:0 | tmp0_other_with_cast | LocalVariableDeclExpr |
|
||||
| dataClass.kt:0:0:0:0 | tmp0_other_with_cast | VarAccess |
|
||||
| dataClass.kt:0:0:0:0 | tmp0_other_with_cast | VarAccess |
|
||||
|
||||
Reference in New Issue
Block a user