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

Skip to content

Commit 0319909

Browse files
committed
Kotlin: Add SAFE_CAST support
1 parent 1c5f6d7 commit 0319909

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,18 @@ open class KotlinFileExtractor(
16561656
extractTypeAccess(e.typeOperand, callable, id, 0, e, enclosingStmt)
16571657
extractExpressionExpr(e.argument, callable, id, 1, enclosingStmt)
16581658
}
1659+
IrTypeOperator.SAFE_CAST -> {
1660+
// TODO: Distinguish this (e as? T) from CAST
1661+
val id = tw.getFreshIdLabel<DbCastexpr>()
1662+
val locId = tw.getLocation(e)
1663+
val type = useType(e.type)
1664+
tw.writeExprs_castexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
1665+
tw.writeHasLocation(id, locId)
1666+
tw.writeCallableEnclosingExpr(id, callable)
1667+
tw.writeStatementEnclosingExpr(id, enclosingStmt)
1668+
extractTypeAccess(e.typeOperand, callable, id, 0, e, enclosingStmt)
1669+
extractExpressionExpr(e.argument, callable, id, 1, enclosingStmt)
1670+
}
16591671
IrTypeOperator.INSTANCEOF -> {
16601672
val id = tw.getFreshIdLabel<DbInstanceofexpr>()
16611673
val locId = tw.getLocation(e)
@@ -1679,7 +1691,7 @@ open class KotlinFileExtractor(
16791691
extractTypeAccess(e.typeOperand, callable, id, 1, e, enclosingStmt)
16801692
}
16811693
else -> {
1682-
logger.warnElement(Severity.ErrorSevere, "Unrecognised IrTypeOperatorCall: " + e.render(), e)
1694+
logger.warnElement(Severity.ErrorSevere, "Unrecognised IrTypeOperatorCall for ${e.operator}: " + e.render(), e)
16831695
}
16841696
}
16851697
}

0 commit comments

Comments
 (0)