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

Skip to content

Commit 5c38b4e

Browse files
tamasvajkigfoo
authored andcommitted
Extract expression body
1 parent 4d40815 commit 5c38b4e

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -716,13 +716,10 @@ open class KotlinFileExtractor(
716716

717717
fun extractBody(b: IrBody, callable: Label<out DbCallable>) {
718718
with("body", b) {
719-
when(b) {
719+
when (b) {
720720
is IrBlockBody -> extractBlockBody(b, callable)
721721
is IrSyntheticBody -> extractSyntheticBody(b, callable)
722-
is IrExpressionBody -> {
723-
// TODO
724-
logger.warnElement(Severity.ErrorSevere, "Unhandled IrExpressionBody", b)
725-
}
722+
is IrExpressionBody -> extractExpressionBody(b, callable)
726723
else -> {
727724
logger.warnElement(Severity.ErrorSevere, "Unrecognised IrBody: " + b.javaClass, b)
728725
}
@@ -736,7 +733,7 @@ open class KotlinFileExtractor(
736733
val locId = tw.getLocation(b)
737734
tw.writeStmts_block(id, callable, 0, callable)
738735
tw.writeHasLocation(id, locId)
739-
for((sIdx, stmt) in b.statements.withIndex()) {
736+
for ((sIdx, stmt) in b.statements.withIndex()) {
740737
extractStatement(stmt, callable, id, sIdx)
741738
}
742739
}
@@ -751,6 +748,20 @@ open class KotlinFileExtractor(
751748
}
752749
}
753750

751+
fun extractExpressionBody(b: IrExpressionBody, callable: Label<out DbCallable>) {
752+
with("expression body", b) {
753+
val blockId = tw.getFreshIdLabel<DbBlock>()
754+
val locId = tw.getLocation(b)
755+
tw.writeStmts_block(blockId, callable, 0, callable)
756+
tw.writeHasLocation(blockId, locId)
757+
758+
val returnId = tw.getFreshIdLabel<DbReturnstmt>()
759+
tw.writeStmts_returnstmt(returnId, blockId, 0, callable)
760+
tw.writeHasLocation(returnId, locId)
761+
extractExpressionExpr(b.expression, callable, returnId, 0, returnId)
762+
}
763+
}
764+
754765
private fun getVariableLocationProvider(v: IrVariable): IrElement {
755766
val init = v.initializer
756767
if (v.startOffset < 0 && init != null) {

0 commit comments

Comments
 (0)