Generate delegating constructor calls as IrDelegatingConstructorCall expressions

(they have different platform-level representation in JVM and JS).
This commit is contained in:
Dmitry Petrov
2016-08-30 11:02:54 +03:00
committed by Dmitry Petrov
parent 6fbac2ed40
commit a6bee7a22b
22 changed files with 224 additions and 142 deletions
@@ -0,0 +1,8 @@
open class Base(val x: Int, val y: Int)
class Test1(xx: Int, yy: Int) : Base(y = yy, x = xx)
class Test2 : Base {
constructor(xx: Int, yy: Int) : super(y = yy, x = xx)
constructor(xxx: Int, yyy: Int, a: Any) : this(yy = yyy, xx = xxx)
}
@@ -0,0 +1,50 @@
FILE /argumentReorderingInDelegatingConstructorCall.kt
CLASS CLASS Base
FUN public constructor Base(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
BLOCK_BODY
SET_BACKING_FIELD x type=kotlin.Unit operator=null
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
SET_BACKING_FIELD y type=kotlin.Unit operator=null
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
PROPERTY public final val x: kotlin.Int getter=null setter=null
EXPRESSION_BODY
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
PROPERTY public final val y: kotlin.Int getter=null setter=null
EXPRESSION_BODY
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
CLASS CLASS Test1
FUN public constructor Test1(/*0*/ xx: kotlin.Int, /*1*/ yy: kotlin.Int)
BLOCK_BODY
BLOCK type=Base operator=ARGUMENTS_REORDERING_FOR_CALL
VAR val tmp0_y: kotlin.Int
GET_VAR yy type=kotlin.Int operator=null
VAR val tmp1_x: kotlin.Int
GET_VAR xx type=kotlin.Int operator=null
CALL .<init> type=Base operator=SUPER_CONSTRUCTOR_CALL
x: GET_VAR tmp1_x type=kotlin.Int operator=null
y: GET_VAR tmp0_y type=kotlin.Int operator=null
CLASS CLASS Test2
nestedInitializers: BLOCK_BODY
FUN public constructor Test2(/*0*/ xx: kotlin.Int, /*1*/ yy: kotlin.Int)
BLOCK_BODY
BLOCK type=Base operator=ARGUMENTS_REORDERING_FOR_CALL
VAR val tmp0_y: kotlin.Int
GET_VAR yy type=kotlin.Int operator=null
VAR val tmp1_x: kotlin.Int
GET_VAR xx type=kotlin.Int operator=null
TYPE_OP operator=IMPLICIT_CAST typeOperand=Base
DELEGATING_CONSTRUCTOR_CALL Base
x: GET_VAR tmp1_x type=kotlin.Int operator=null
y: GET_VAR tmp0_y type=kotlin.Int operator=null
NESTED_INITIALIZERS_CALL classDescriptor=Test2
FUN public constructor Test2(/*0*/ xxx: kotlin.Int, /*1*/ yyy: kotlin.Int, /*2*/ a: kotlin.Any)
BLOCK_BODY
BLOCK type=Test2 operator=ARGUMENTS_REORDERING_FOR_CALL
VAR val tmp0_yy: kotlin.Int
GET_VAR yyy type=kotlin.Int operator=null
VAR val tmp1_xx: kotlin.Int
GET_VAR xxx type=kotlin.Int operator=null
TYPE_OP operator=IMPLICIT_CAST typeOperand=Test2
DELEGATING_CONSTRUCTOR_CALL Test2
xx: GET_VAR tmp1_xx type=kotlin.Int operator=null
yy: GET_VAR tmp0_yy type=kotlin.Int operator=null
+1 -1
View File
@@ -16,7 +16,7 @@ FILE /classMembers.kt
GET_VAR z type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN public constructor C()
BLOCK_BODY
CALL .<init> type=C operator=DELEGATING_CONSTRUCTOR_CALL
DELEGATING_CONSTRUCTOR_CALL C
x: CONST Int type=kotlin.Int value='0'
y: CONST Int type=kotlin.Int value='0'
z: CONST Int type=kotlin.Int value='0'
@@ -6,12 +6,12 @@ FILE /delegatingConstructorCallsInSecondaryConstructors.kt
nestedInitializers: BLOCK_BODY
FUN public constructor Test()
BLOCK_BODY
CALL .<init> type=Base operator=DELEGATING_CONSTRUCTOR_CALL
DELEGATING_CONSTRUCTOR_CALL Base
NESTED_INITIALIZERS_CALL classDescriptor=Test
FUN public constructor Test(/*0*/ xx: kotlin.Int)
BLOCK_BODY
CALL .<init> type=Base operator=DELEGATING_CONSTRUCTOR_CALL
DELEGATING_CONSTRUCTOR_CALL Base
NESTED_INITIALIZERS_CALL classDescriptor=Test
FUN public constructor Test(/*0*/ xx: kotlin.Short)
BLOCK_BODY
CALL .<init> type=Test operator=DELEGATING_CONSTRUCTOR_CALL
DELEGATING_CONSTRUCTOR_CALL Test
+2 -2
View File
@@ -48,7 +48,7 @@ FILE /initVar.kt
GET_VAR value type=kotlin.Int operator=null
FUN public constructor TestInitVarWithCustomSetterWithExplicitCtor()
BLOCK_BODY
CALL .<init> type=kotlin.Any operator=DELEGATING_CONSTRUCTOR_CALL
DELEGATING_CONSTRUCTOR_CALL Any
NESTED_INITIALIZERS_CALL classDescriptor=TestInitVarWithCustomSetterWithExplicitCtor
CLASS CLASS TestInitVarWithCustomSetterInCtor
nestedInitializers: BLOCK_BODY
@@ -59,7 +59,7 @@ FILE /initVar.kt
GET_VAR value type=kotlin.Int operator=null
FUN public constructor TestInitVarWithCustomSetterInCtor()
BLOCK_BODY
CALL .<init> type=kotlin.Any operator=DELEGATING_CONSTRUCTOR_CALL
DELEGATING_CONSTRUCTOR_CALL Any
NESTED_INITIALIZERS_CALL classDescriptor=TestInitVarWithCustomSetterInCtor
CALL .<set-x> type=kotlin.Unit operator=EQ
$this: THIS public final class TestInitVarWithCustomSetterInCtor type=TestInitVarWithCustomSetterInCtor
@@ -26,6 +26,6 @@ FILE /primaryConstructorWithSuperConstructorCall.kt
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN public constructor TestWithDelegatingConstructor(/*0*/ x: kotlin.Int)
BLOCK_BODY
CALL .<init> type=TestWithDelegatingConstructor operator=DELEGATING_CONSTRUCTOR_CALL
DELEGATING_CONSTRUCTOR_CALL TestWithDelegatingConstructor
x: GET_VAR x type=kotlin.Int operator=null
y: CONST Int type=kotlin.Int value='0'
@@ -11,7 +11,7 @@ FILE /secondaryConstructorWithInitializersFromClassBody.kt
CONST Int type=kotlin.Int value='0'
FUN public constructor TestProperty()
BLOCK_BODY
CALL .<init> type=Base operator=DELEGATING_CONSTRUCTOR_CALL
DELEGATING_CONSTRUCTOR_CALL Base
NESTED_INITIALIZERS_CALL classDescriptor=TestProperty
CLASS CLASS TestInitBlock
nestedInitializers: BLOCK_BODY
@@ -21,5 +21,5 @@ FILE /secondaryConstructorWithInitializersFromClassBody.kt
PROPERTY public final val x: kotlin.Int getter=null setter=null
FUN public constructor TestInitBlock()
BLOCK_BODY
CALL .<init> type=Base operator=DELEGATING_CONSTRUCTOR_CALL
DELEGATING_CONSTRUCTOR_CALL Base
NESTED_INITIALIZERS_CALL classDescriptor=TestInitBlock
@@ -3,9 +3,9 @@ FILE /secondaryConstructors.kt
nestedInitializers: BLOCK_BODY
FUN public constructor C()
BLOCK_BODY
CALL .<init> type=C operator=DELEGATING_CONSTRUCTOR_CALL
DELEGATING_CONSTRUCTOR_CALL C
x: CONST Int type=kotlin.Int value='0'
FUN public constructor C(/*0*/ x: kotlin.Int)
BLOCK_BODY
CALL .<init> type=kotlin.Any operator=DELEGATING_CONSTRUCTOR_CALL
DELEGATING_CONSTRUCTOR_CALL Any
NESTED_INITIALIZERS_CALL classDescriptor=C