Extract SAM lambda conversion

This commit is contained in:
Tamas Vajk
2022-02-14 13:27:18 +01:00
committed by Ian Lynagh
parent 377a0f91f0
commit 34ae00fa62
6 changed files with 208 additions and 11 deletions

View File

@@ -2204,3 +2204,80 @@ localFunctionCalls.kt:
# 13| 0: [SuperConstructorInvocationStmt] super(...)
# 13| 1: [ExprStmt] <Expr>;
# 13| 0: [MethodAccess] <obinit>(...)
samConversion.kt:
# 0| [CompilationUnit] samConversion
# 0| 1: [Class] SamConversionKt
# 1| 1: [Method] main
# 1| 5: [BlockStmt] { ... }
# 2| 0: [LocalVariableDeclStmt] var ...;
# 2| 1: [LocalVariableDeclExpr] isEven
# 2| 0: [CastExpr] (...)...
# 2| 0: [TypeAccess] IntPredicate
# 2| 1: [ClassInstanceExpr] new (...)
# 2| -4: [AnonymousClass] new Object(...) { ... }
# 2| 1: [Constructor]
# 2| 5: [BlockStmt] { ... }
# 2| 0: [SuperConstructorInvocationStmt] super(...)
# 2| 1: [Method] accept
#-----| 4: (Parameters)
# 2| 0: [Parameter] it
# 2| 5: [BlockStmt] { ... }
# 2| 0: [ReturnStmt] return ...
# 2| 0: [ValueEQExpr] ... (value equals) ...
# 2| 0: [RemExpr] ... % ...
# 2| 0: [VarAccess] it
# 2| 1: [IntegerLiteral] 2
# 2| 1: [IntegerLiteral] 0
# 2| -3: [TypeAccess] Object
# 4| 1: [ExprStmt] <Expr>;
# 4| 0: [MethodAccess] fn1(...)
# 4| -1: [CastExpr] (...)...
# 4| 0: [TypeAccess] InterfaceFn1
# 4| 1: [ClassInstanceExpr] new (...)
# 4| -4: [AnonymousClass] new Object(...) { ... }
# 4| 1: [Constructor]
# 4| 5: [BlockStmt] { ... }
# 4| 0: [SuperConstructorInvocationStmt] super(...)
# 4| 1: [Method] fn1
#-----| 4: (Parameters)
# 4| 0: [Parameter] a
# 4| 1: [Parameter] b
# 4| 5: [BlockStmt] { ... }
# 4| 0: [ExprStmt] <Expr>;
# 4| 0: [VarAccess] INSTANCE
# 4| -3: [TypeAccess] Object
# 4| 0: [IntegerLiteral] 1
# 4| 1: [IntegerLiteral] 2
# 6| 2: [LocalVariableDeclStmt] var ...;
# 6| 1: [LocalVariableDeclExpr] i
# 6| 0: [CastExpr] (...)...
# 6| 0: [TypeAccess] InterfaceFnExt1
# 6| 1: [ClassInstanceExpr] new (...)
# 6| -4: [AnonymousClass] new Object(...) { ... }
# 6| 1: [Constructor]
# 6| 5: [BlockStmt] { ... }
# 6| 0: [SuperConstructorInvocationStmt] super(...)
# 6| 1: [ExtensionMethod] ext
#-----| 4: (Parameters)
# 6| 0: [Parameter] $this$InterfaceFnExt1
# 6| 1: [Parameter] i
# 6| 5: [BlockStmt] { ... }
# 6| 0: [ReturnStmt] return ...
# 6| 0: [ValueEQExpr] ... (value equals) ...
# 6| 0: [ThisAccess] this
# 6| 1: [StringLiteral]
# 6| -3: [TypeAccess] Object
# 9| 2: [Interface] IntPredicate
# 10| 2: [Method] accept
#-----| 4: (Parameters)
# 10| 0: [Parameter] i
# 13| 3: [Interface] InterfaceFn1
# 14| 2: [Method] fn1
#-----| 4: (Parameters)
# 14| 0: [Parameter] i
# 14| 1: [Parameter] j
# 17| 4: [Interface] InterfaceFnExt1
# 18| 2: [ExtensionMethod] ext
#-----| 4: (Parameters)
# 18| 0: [Parameter] <this>
# 18| 1: [Parameter] i

View File

@@ -106,3 +106,6 @@
| exprs.kt:257:11:257:17 | ... * ... | exprs.kt:257:11:257:12 | fx | exprs.kt:257:16:257:17 | fy |
| funcExprs.kt:26:35:26:42 | ... + ... | funcExprs.kt:26:35:26:38 | this | funcExprs.kt:26:42:26:42 | a |
| localFunctionCalls.kt:5:25:5:29 | ... + ... | localFunctionCalls.kt:5:25:5:25 | i | localFunctionCalls.kt:5:29:5:29 | x |
| samConversion.kt:2:33:2:38 | ... % ... | samConversion.kt:2:33:2:34 | it | samConversion.kt:2:38:2:38 | 2 |
| samConversion.kt:2:33:2:43 | ... (value equals) ... | samConversion.kt:2:33:2:38 | ... % ... | samConversion.kt:2:43:2:43 | 0 |
| samConversion.kt:6:36:6:45 | ... (value equals) ... | samConversion.kt:6:36:6:39 | this | samConversion.kt:6:44:6:45 | |

View File

@@ -1317,3 +1317,29 @@
| localFunctionCalls.kt:10:15:10:20 | new (...) | localFunctionCalls.kt:3:1:11:1 | x | ClassInstanceExpr |
| localFunctionCalls.kt:10:18:10:19 | 42 | localFunctionCalls.kt:3:1:11:1 | x | IntegerLiteral |
| localFunctionCalls.kt:13:1:13:14 | <obinit>(...) | localFunctionCalls.kt:13:1:13:14 | C1 | MethodAccess |
| samConversion.kt:2:5:2:45 | isEven | samConversion.kt:1:1:7:1 | main | LocalVariableDeclExpr |
| samConversion.kt:2:18:2:45 | (...)... | samConversion.kt:1:1:7:1 | main | CastExpr |
| samConversion.kt:2:18:2:45 | IntPredicate | samConversion.kt:1:1:7:1 | main | TypeAccess |
| samConversion.kt:2:18:2:45 | Object | samConversion.kt:1:1:7:1 | main | TypeAccess |
| samConversion.kt:2:18:2:45 | new (...) | samConversion.kt:1:1:7:1 | main | ClassInstanceExpr |
| samConversion.kt:2:33:2:34 | it | samConversion.kt:2:31:2:45 | accept | VarAccess |
| samConversion.kt:2:33:2:38 | ... % ... | samConversion.kt:2:31:2:45 | accept | RemExpr |
| samConversion.kt:2:33:2:43 | ... (value equals) ... | samConversion.kt:2:31:2:45 | accept | ValueEQExpr |
| samConversion.kt:2:38:2:38 | 2 | samConversion.kt:2:31:2:45 | accept | IntegerLiteral |
| samConversion.kt:2:43:2:43 | 0 | samConversion.kt:2:31:2:45 | accept | IntegerLiteral |
| samConversion.kt:4:5:4:33 | (...)... | samConversion.kt:1:1:7:1 | main | CastExpr |
| samConversion.kt:4:5:4:33 | InterfaceFn1 | samConversion.kt:1:1:7:1 | main | TypeAccess |
| samConversion.kt:4:5:4:33 | Object | samConversion.kt:1:1:7:1 | main | TypeAccess |
| samConversion.kt:4:5:4:33 | new (...) | samConversion.kt:1:1:7:1 | main | ClassInstanceExpr |
| samConversion.kt:4:28:4:31 | INSTANCE | samConversion.kt:4:18:4:33 | fn1 | VarAccess |
| samConversion.kt:4:35:4:42 | fn1(...) | samConversion.kt:1:1:7:1 | main | MethodAccess |
| samConversion.kt:4:39:4:39 | 1 | samConversion.kt:1:1:7:1 | main | IntegerLiteral |
| samConversion.kt:4:41:4:41 | 2 | samConversion.kt:1:1:7:1 | main | IntegerLiteral |
| samConversion.kt:6:5:6:46 | i | samConversion.kt:1:1:7:1 | main | LocalVariableDeclExpr |
| samConversion.kt:6:13:6:46 | (...)... | samConversion.kt:1:1:7:1 | main | CastExpr |
| samConversion.kt:6:13:6:46 | InterfaceFnExt1 | samConversion.kt:1:1:7:1 | main | TypeAccess |
| samConversion.kt:6:13:6:46 | Object | samConversion.kt:1:1:7:1 | main | TypeAccess |
| samConversion.kt:6:13:6:46 | new (...) | samConversion.kt:1:1:7:1 | main | ClassInstanceExpr |
| samConversion.kt:6:36:6:39 | this | samConversion.kt:6:29:6:46 | ext | ThisAccess |
| samConversion.kt:6:36:6:45 | ... (value equals) ... | samConversion.kt:6:29:6:46 | ext | ValueEQExpr |
| samConversion.kt:6:44:6:45 | | samConversion.kt:6:29:6:46 | ext | StringLiteral |

View File

@@ -0,0 +1,19 @@
fun main() {
val isEven = IntPredicate { it % 2 == 0 }
InterfaceFn1 { a, b -> Unit }.fn1(1,2)
val i = InterfaceFnExt1 { i -> this == ""}
}
fun interface IntPredicate {
fun accept(i: Int): Boolean
}
fun interface InterfaceFn1 {
fun fn1(i: Int, j: Int)
}
fun interface InterfaceFnExt1 {
fun String.ext(i: Int): Boolean
}