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

Skip to content

Commit d48739c

Browse files
committed
Kotlin: Check a call actually is an addition
1 parent 9a75ca7 commit d48739c

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

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

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import org.jetbrains.kotlin.ir.declarations.IrFile
1717
import org.jetbrains.kotlin.ir.declarations.IrFunction
1818
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
1919
import org.jetbrains.kotlin.ir.util.dump
20+
import org.jetbrains.kotlin.ir.util.IdSignature
2021
import org.jetbrains.kotlin.ir.util.packageFqName
22+
import org.jetbrains.kotlin.ir.util.render
2123
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
2224
import org.jetbrains.kotlin.ir.IrFileEntry
2325
import org.jetbrains.kotlin.ir.types.isInt
@@ -255,23 +257,32 @@ class KotlinFileExtractor(val tw: TrapWriter) {
255257
fun extractExpression(e: IrExpression, parent: Label<out DbExprparent>, idx: Int) {
256258
when(e) {
257259
is IrCall -> {
258-
// TODO: This shouldn't assume all IrCalls's are addexpr's
259-
if(e.valueArgumentsCount == 1) {
260-
val left = e.dispatchReceiver
261-
val right = e.getValueArgument(0)
262-
if(left != null && right != null) {
263-
val id = tw.getFreshIdLabel<DbAddexpr>()
264-
val typeId = useType(e.type)
265-
val locId = tw.getLocation(e.startOffset, e.endOffset)
266-
tw.writeExprs_addexpr(id, typeId, parent, idx)
267-
tw.writeHasLocation(id, locId)
268-
extractExpression(left, id, 0)
269-
extractExpression(right, id, 1)
270-
} else {
271-
extractorBug("Unrecognised IrCall: left or right is null")
272-
}
260+
val sig: IdSignature.PublicSignature? = e.symbol.signature?.asPublic()
261+
if(sig == null) {
262+
extractorBug("IrCall without public signature")
273263
} else {
274-
extractorBug("Unrecognised IrCall: Not binary")
264+
when {
265+
sig.packageFqName == "kotlin" && sig.declarationFqName == "Int.plus" -> {
266+
if(e.valueArgumentsCount == 1) {
267+
val left = e.dispatchReceiver
268+
val right = e.getValueArgument(0)
269+
if(left != null && right != null) {
270+
val id = tw.getFreshIdLabel<DbAddexpr>()
271+
val typeId = useType(e.type)
272+
val locId = tw.getLocation(e.startOffset, e.endOffset)
273+
tw.writeExprs_addexpr(id, typeId, parent, idx)
274+
tw.writeHasLocation(id, locId)
275+
extractExpression(left, id, 0)
276+
extractExpression(right, id, 1)
277+
} else {
278+
extractorBug("Unrecognised IrCall: left or right is null")
279+
}
280+
} else {
281+
extractorBug("Unrecognised IrCall: Not binary")
282+
}
283+
}
284+
else -> extractorBug("Unrecognised IrCall: " + e.render())
285+
}
275286
}
276287
}
277288
is IrConst<*> -> {

0 commit comments

Comments
 (0)