Default arguments stored in function declarations.

This commit is contained in:
Dmitry Petrov
2016-08-31 18:28:04 +03:00
committed by Dmitry Petrov
parent 2d2100b1b5
commit 865d2c43c7
41 changed files with 197 additions and 106 deletions
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.psi2ir.generators
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrFunctionBase
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.endOffset
@@ -30,6 +31,20 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context:
override val scope = Scope(scopeOwner)
private val loopTable = HashMap<KtLoopExpression, IrLoop>()
fun generateDefaultParameters(ktFunction: KtFunction, irFunction: IrFunctionBase) {
generateDefaultParameters(ktFunction.valueParameterList ?: return, irFunction)
}
fun generateDefaultParameters(ktParameterList: KtParameterList, irFunction: IrFunctionBase) {
val statementGenerator = createStatementGenerator()
for (ktParameter in ktParameterList.parameters) {
val ktDefaultValue = ktParameter.defaultValue ?: continue
val valueParameter = getOrFail(BindingContext.VALUE_PARAMETER, ktParameter) as? ValueParameterDescriptor ?: continue
val irDefaultValue = statementGenerator.generateExpression(ktDefaultValue)
irFunction.putDefault(valueParameter, IrExpressionBodyImpl(ktDefaultValue.startOffset, ktDefaultValue.endOffset, irDefaultValue))
}
}
fun generateFunctionBody(ktBody: KtExpression): IrBody {
val statementGenerator = createStatementGenerator()
@@ -72,10 +72,14 @@ class ClassGenerator(val declarationGenerator: DeclarationGenerator) : Generator
private fun generatePrimaryConstructor(irClass: IrClassImpl, ktClassOrObject: KtClassOrObject) {
val primaryConstructorDescriptor = irClass.descriptor.unsubstitutedPrimaryConstructor ?: return
val irPrimaryConstructor = IrFunctionImpl(ktClassOrObject.startOffset, ktClassOrObject.endOffset, IrDeclarationOrigin.DEFINED,
primaryConstructorDescriptor)
val irPrimaryConstructor = IrConstructorImpl(ktClassOrObject.startOffset, ktClassOrObject.endOffset, IrDeclarationOrigin.DEFINED,
primaryConstructorDescriptor)
irPrimaryConstructor.body = BodyGenerator(primaryConstructorDescriptor, context).generatePrimaryConstructorBody(ktClassOrObject)
val bodyGenerator = BodyGenerator(primaryConstructorDescriptor, context)
ktClassOrObject.getPrimaryConstructor()?.valueParameterList?.let { ktValueParameterList ->
bodyGenerator.generateDefaultParameters(ktValueParameterList, irPrimaryConstructor)
}
irPrimaryConstructor.body = bodyGenerator.generatePrimaryConstructorBody(ktClassOrObject)
irClass.addMember(irPrimaryConstructor)
}
@@ -57,29 +57,35 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
IrTypeAliasImpl(ktDeclaration.startOffset, ktDeclaration.endOffset, IrDeclarationOrigin.DEFINED,
getOrFail(BindingContext.TYPE_ALIAS, ktDeclaration))
fun generateFunctionDeclaration(ktFunction: KtNamedFunction): IrFunction {
fun generateFunctionDeclaration(ktFunction: KtNamedFunction): IrGeneralFunction {
val functionDescriptor = getOrFail(BindingContext.FUNCTION, ktFunction)
val body = ktFunction.bodyExpression?.let { generateFunctionBody(functionDescriptor, it) }
return IrFunctionImpl(ktFunction.startOffset, ktFunction.endOffset, IrDeclarationOrigin.DEFINED,
functionDescriptor, body)
val irFunction = IrFunctionImpl(ktFunction.startOffset, ktFunction.endOffset, IrDeclarationOrigin.DEFINED, functionDescriptor)
val bodyGenerator = createBodyGenerator(functionDescriptor)
bodyGenerator.generateDefaultParameters(ktFunction, irFunction)
irFunction.body = ktFunction.bodyExpression?.let { bodyGenerator.generateFunctionBody(it) }
return irFunction
}
fun generateSecondaryConstructor(ktConstructor: KtSecondaryConstructor) : IrFunction {
fun generateSecondaryConstructor(ktConstructor: KtSecondaryConstructor) : IrGeneralFunction {
if (ktConstructor.isConstructorDelegatingToSuper(context.bindingContext)) {
return generateSecondaryConstructorWithNestedInitializers(ktConstructor)
}
val constructorDescriptor = getOrFail(BindingContext.CONSTRUCTOR, ktConstructor)
val body = createBodyGenerator(constructorDescriptor).generateSecondaryConstructorBody(ktConstructor)
return IrFunctionImpl(ktConstructor.startOffset, ktConstructor.endOffset, IrDeclarationOrigin.DEFINED,
constructorDescriptor, body)
val irConstructor = IrConstructorImpl(ktConstructor.startOffset, ktConstructor.endOffset, IrDeclarationOrigin.DEFINED, constructorDescriptor)
val bodyGenerator = createBodyGenerator(constructorDescriptor)
bodyGenerator.generateDefaultParameters(ktConstructor, irConstructor)
irConstructor.body = bodyGenerator.generateSecondaryConstructorBody(ktConstructor)
return irConstructor
}
private fun generateSecondaryConstructorWithNestedInitializers(ktConstructor: KtSecondaryConstructor): IrFunction {
private fun generateSecondaryConstructorWithNestedInitializers(ktConstructor: KtSecondaryConstructor): IrGeneralFunction {
val constructorDescriptor = getOrFail(BindingContext.CONSTRUCTOR, ktConstructor)
val body = createBodyGenerator(constructorDescriptor).generateSecondaryConstructorBodyWithNestedInitializers(ktConstructor)
return IrFunctionImpl(ktConstructor.startOffset, ktConstructor.endOffset, IrDeclarationOrigin.DEFINED,
constructorDescriptor, body)
val irConstructor = IrConstructorImpl(ktConstructor.startOffset, ktConstructor.endOffset, IrDeclarationOrigin.DEFINED, constructorDescriptor)
val bodyGenerator = createBodyGenerator(constructorDescriptor)
bodyGenerator.generateDefaultParameters(ktConstructor, irConstructor)
irConstructor.body = createBodyGenerator(constructorDescriptor).generateSecondaryConstructorBodyWithNestedInitializers(ktConstructor)
return irConstructor
}
fun generatePropertyDeclaration(ktProperty: KtProperty): IrProperty {
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.psi2ir.generators
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrGeneralFunction
import org.jetbrains.kotlin.ir.declarations.IrFunctionImpl
import org.jetbrains.kotlin.ir.expressions.IrBlockImpl
import org.jetbrains.kotlin.ir.expressions.IrCallableReferenceImpl
@@ -62,7 +62,7 @@ class LocalFunctionGenerator(statementGenerator: StatementGenerator) : Statement
irBlock
}
private fun generateFunctionDeclaration(ktFun: KtNamedFunction): IrFunction {
private fun generateFunctionDeclaration(ktFun: KtNamedFunction): IrGeneralFunction {
val funDescriptor = getOrFail(BindingContext.FUNCTION, ktFun)
val irFun = IrFunctionImpl(ktFun.startOffset, ktFun.endOffset, IrDeclarationOrigin.DEFINED, funDescriptor)
irFun.body = BodyGenerator(funDescriptor, statementGenerator.context).generateFunctionBody(ktFun.bodyExpression!!)
@@ -22,7 +22,7 @@ const val ARGUMENT0_SLOT = 0
const val ARGUMENT1_SLOT = 1
const val DISPATCH_RECEIVER_SLOT = -1
const val EXTENSION_RECEIVER_SLOT = -2
const val FUNCTION_BODY_SLOT = 0
const val FUNCTION_BODY_SLOT = -1
const val MODULE_SLOT = 0
const val INITIALIZER_SLOT = 0
const val IF_CONDITION_SLOT = 0
@@ -17,11 +17,14 @@
package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.ir.*
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import java.util.*
interface IrFunction : IrDeclaration {
interface IrGeneralFunction : IrDeclaration {
override val descriptor: FunctionDescriptor
val body: IrBody?
@@ -29,11 +32,16 @@ interface IrFunction : IrDeclaration {
get() = IrDeclarationKind.FUNCTION
}
abstract class IrFunctionBase(
interface IrFunction : IrGeneralFunction {
fun putDefault(parameter: ValueParameterDescriptor, expressionBody: IrExpressionBody)
fun getDefault(parameter: ValueParameterDescriptor): IrExpressionBody?
}
abstract class IrGeneralFunctionBase(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin
) : IrDeclarationBase(startOffset, endOffset, origin), IrFunction {
) : IrDeclarationBase(startOffset, endOffset, origin), IrGeneralFunction {
constructor(
startOffset: Int,
endOffset: Int,
@@ -69,6 +77,29 @@ abstract class IrFunctionBase(
}
}
abstract class IrFunctionBase(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin
) : IrGeneralFunctionBase(startOffset, endOffset, origin), IrFunction {
private val defaults = LinkedHashMap<ValueParameterDescriptor, IrExpressionBody>()
override fun getDefault(parameter: ValueParameterDescriptor): IrExpressionBody? =
defaults[parameter]
override fun putDefault(parameter: ValueParameterDescriptor, expressionBody: IrExpressionBody) {
expressionBody.assertDetached()
defaults[parameter]?.detach()
defaults[parameter] = expressionBody
expressionBody.setTreeLocation(this, parameter.index)
}
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
defaults.values.forEach { it.accept(visitor, data) }
body?.accept(visitor, data)
}
}
class IrFunctionImpl(
startOffset: Int,
endOffset: Int,
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
interface IrPropertyAccessor : IrFunction {
interface IrPropertyAccessor : IrGeneralFunction {
override val descriptor: PropertyAccessorDescriptor
}
@@ -45,7 +45,7 @@ abstract class IrPropertyAccessorBase(
endOffset: Int,
origin: IrDeclarationOrigin,
body: IrBody
) : IrFunctionBase(startOffset, endOffset, origin, body), IrPropertyAccessor
) : IrGeneralFunctionBase(startOffset, endOffset, origin, body), IrPropertyAccessor
class IrPropertyGetterImpl(
startOffset: Int,
@@ -18,9 +18,7 @@ package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.SourceLocationManager
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrEnumEntry
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.utils.Printer
@@ -45,6 +43,23 @@ class DumpIrTreeVisitor(out: Appendable): IrElementVisitor<Unit, String> {
element.dumpLabeledSubTree(data)
}
override fun visitFunction(declaration: IrFunction, data: String) {
visitFunctionWithParameters(declaration, data)
}
override fun visitConstructor(declaration: IrConstructor, data: String) {
visitFunctionWithParameters(declaration, data)
}
private fun visitFunctionWithParameters(declaration: IrFunction, data: String) {
declaration.dumpLabeledElementWith(data) {
declaration.descriptor.valueParameters.forEach { valueParameter ->
declaration.getDefault(valueParameter)?.accept(this, valueParameter.name.asString())
}
declaration.body?.accept(this, "")
}
}
override fun visitClass(declaration: IrClass, data: String) {
declaration.dumpLabeledElementWith(data) {
declaration.nestedInitializers?.accept(this, "nestedInitializers")
@@ -42,6 +42,9 @@ class RenderIrElementVisitor : IrElementVisitor<String, Nothing?> {
override fun visitFunction(declaration: IrFunction, data: Nothing?): String =
"FUN ${declaration.descriptor.render()}"
override fun visitConstructor(declaration: IrConstructor, data: Nothing?): String =
"CONSTRUCTOR ${declaration.descriptor.render()}"
override fun visitProperty(declaration: IrProperty, data: Nothing?): String =
"PROPERTY ${declaration.descriptor.render()}"
@@ -28,10 +28,11 @@ interface IrElementVisitor<out R, in D> {
fun visitDeclaration(declaration: IrDeclaration, data: D): R = visitElement(declaration, data)
fun visitClass(declaration: IrClass, data: D): R = visitDeclaration(declaration, data)
fun visitTypeAlias(declaration: IrTypeAlias, data: D): R = visitDeclaration(declaration, data)
fun visitFunction(declaration: IrFunction, data: D): R = visitDeclaration(declaration, data)
fun visitPropertyGetter(declaration: IrPropertyGetter, data: D): R = visitFunction(declaration, data)
fun visitPropertySetter(declaration: IrPropertySetter, data: D): R = visitFunction(declaration, data)
fun visitConstructor(declaration: IrConstructor, data: D): R = visitFunction(declaration, data)
fun visitGeneralFunction(declaration: IrGeneralFunction, data: D) = visitDeclaration(declaration, data)
fun visitFunction(declaration: IrFunction, data: D): R = visitGeneralFunction(declaration, data)
fun visitPropertyGetter(declaration: IrPropertyGetter, data: D): R = visitGeneralFunction(declaration, data)
fun visitPropertySetter(declaration: IrPropertySetter, data: D): R = visitGeneralFunction(declaration, data)
fun visitConstructor(declaration: IrConstructor, data: D): R = visitGeneralFunction(declaration, data)
fun visitProperty(declaration: IrProperty, data: D): R = visitDeclaration(declaration, data)
fun visitSimpleProperty(declaration: IrSimpleProperty, data: D): R = visitProperty(declaration, data)
fun visitDelegatedProperty(declaration: IrDelegatedProperty, data: D): R = visitProperty(declaration, data)
@@ -1,6 +1,6 @@
FILE /argumentReorderingInDelegatingConstructorCall.kt
CLASS CLASS Base
FUN public constructor Base(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
CONSTRUCTOR 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
@@ -13,7 +13,7 @@ FILE /argumentReorderingInDelegatingConstructorCall.kt
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)
CONSTRUCTOR 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
@@ -25,7 +25,7 @@ FILE /argumentReorderingInDelegatingConstructorCall.kt
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)
CONSTRUCTOR 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
@@ -37,7 +37,7 @@ FILE /argumentReorderingInDelegatingConstructorCall.kt
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)
CONSTRUCTOR 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
+6 -4
View File
@@ -1,6 +1,8 @@
FILE /classMembers.kt
CLASS CLASS C
FUN public constructor C(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int, /*2*/ z: kotlin.Int = ...)
CONSTRUCTOR public constructor C(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int, /*2*/ z: kotlin.Int = ...)
z: EXPRESSION_BODY
CONST Int type=kotlin.Int value='1'
BLOCK_BODY
SET_BACKING_FIELD y type=kotlin.Unit operator=null
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
@@ -14,7 +16,7 @@ FILE /classMembers.kt
PROPERTY public final var z: kotlin.Int
EXPRESSION_BODY
GET_VAR z type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN public constructor C()
CONSTRUCTOR public constructor C()
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL C
x: CONST Int type=kotlin.Int value='0'
@@ -48,7 +50,7 @@ FILE /classMembers.kt
CALL .println type=kotlin.Unit operator=null
message: CONST String type=kotlin.String value='2'
CLASS CLASS NestedClass
FUN public constructor NestedClass()
CONSTRUCTOR public constructor NestedClass()
BLOCK_BODY
FUN public final fun function(): kotlin.Unit
BLOCK_BODY
@@ -66,5 +68,5 @@ FILE /classMembers.kt
CALL .foo type=kotlin.Unit operator=null
$this: THIS public interface NestedInterface type=C.NestedInterface
CLASS OBJECT Companion
FUN private constructor Companion()
CONSTRUCTOR private constructor Companion()
BLOCK_BODY
+4 -4
View File
@@ -1,16 +1,16 @@
FILE /classes.kt
CLASS CLASS TestClass
FUN public constructor TestClass()
CONSTRUCTOR public constructor TestClass()
BLOCK_BODY
CLASS INTERFACE TestInterface
CLASS OBJECT TestObject
FUN private constructor TestObject()
CONSTRUCTOR private constructor TestObject()
BLOCK_BODY
CLASS ANNOTATION_CLASS TestAnnotationClass
FUN public constructor TestAnnotationClass()
CONSTRUCTOR public constructor TestAnnotationClass()
BLOCK_BODY
CLASS ENUM_CLASS TestEnumClass
FUN private constructor TestEnumClass()
CONSTRUCTOR private constructor TestEnumClass()
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL Enum super
FUN public final /*synthesized*/ fun values(): kotlin.Array<TestEnumClass>
+4 -4
View File
@@ -1,13 +1,13 @@
FILE /companionObject.kt
CLASS CLASS Test1
FUN public constructor Test1()
CONSTRUCTOR public constructor Test1()
BLOCK_BODY
CLASS OBJECT Companion
FUN private constructor Companion()
CONSTRUCTOR private constructor Companion()
BLOCK_BODY
CLASS CLASS Test2
FUN public constructor Test2()
CONSTRUCTOR public constructor Test2()
BLOCK_BODY
CLASS OBJECT Named
FUN private constructor Named()
CONSTRUCTOR private constructor Named()
BLOCK_BODY
+1 -1
View File
@@ -1,6 +1,6 @@
FILE /dataClasses.kt
CLASS CLASS Test1
FUN public constructor Test1(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.String, /*2*/ z: kotlin.Any)
CONSTRUCTOR public constructor Test1(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.String, /*2*/ z: kotlin.Any)
BLOCK_BODY
SET_BACKING_FIELD x type=kotlin.Unit operator=null
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
@@ -1,17 +1,17 @@
FILE /delegatingConstructorCallsInSecondaryConstructors.kt
CLASS CLASS Base
FUN public constructor Base()
CONSTRUCTOR public constructor Base()
BLOCK_BODY
CLASS CLASS Test
nestedInitializers: BLOCK_BODY
FUN public constructor Test()
CONSTRUCTOR public constructor Test()
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL Base
NESTED_INITIALIZERS_CALL classDescriptor=Test
FUN public constructor Test(/*0*/ xx: kotlin.Int)
CONSTRUCTOR public constructor Test(/*0*/ xx: kotlin.Int)
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL Base
NESTED_INITIALIZERS_CALL classDescriptor=Test
FUN public constructor Test(/*0*/ xx: kotlin.Short)
CONSTRUCTOR public constructor Test(/*0*/ xx: kotlin.Short)
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL Test
+7 -7
View File
@@ -1,6 +1,6 @@
FILE /enum.kt
CLASS ENUM_CLASS TestEnum1
FUN private constructor TestEnum1()
CONSTRUCTOR private constructor TestEnum1()
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL Enum super
ENUM_ENTRY enum entry TEST1
@@ -12,7 +12,7 @@ FILE /enum.kt
FUN public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): TestEnum1
SYNTHETIC_BODY kind=ENUM_VALUEOF
CLASS ENUM_CLASS TestEnum2
FUN private constructor TestEnum2(/*0*/ x: kotlin.Int)
CONSTRUCTOR private constructor TestEnum2(/*0*/ x: kotlin.Int)
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL Enum super
SET_BACKING_FIELD x type=kotlin.Unit operator=null
@@ -34,13 +34,13 @@ FILE /enum.kt
FUN public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): TestEnum2
SYNTHETIC_BODY kind=ENUM_VALUEOF
CLASS ENUM_CLASS TestEnum3
FUN private constructor TestEnum3()
CONSTRUCTOR private constructor TestEnum3()
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL Enum super
ENUM_ENTRY enum entry TEST
init: ENUM_CONSTRUCTOR_CALL TEST TEST
class: CLASS ENUM_ENTRY TEST
FUN private constructor TEST()
CONSTRUCTOR private constructor TEST()
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL TestEnum3 super
FUN public open override /*1*/ fun foo(): kotlin.Unit
@@ -53,7 +53,7 @@ FILE /enum.kt
FUN public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): TestEnum3
SYNTHETIC_BODY kind=ENUM_VALUEOF
CLASS ENUM_CLASS TestEnum4
FUN private constructor TestEnum4(/*0*/ x: kotlin.Int)
CONSTRUCTOR private constructor TestEnum4(/*0*/ x: kotlin.Int)
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL Enum super
SET_BACKING_FIELD x type=kotlin.Unit operator=null
@@ -64,7 +64,7 @@ FILE /enum.kt
ENUM_ENTRY enum entry TEST1
init: ENUM_CONSTRUCTOR_CALL TEST1 TEST1
class: CLASS ENUM_ENTRY TEST1
FUN private constructor TEST1()
CONSTRUCTOR private constructor TEST1()
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL TestEnum4 super
x: CONST Int type=kotlin.Int value='1'
@@ -75,7 +75,7 @@ FILE /enum.kt
ENUM_ENTRY enum entry TEST2
init: ENUM_CONSTRUCTOR_CALL TEST2 TEST2
class: CLASS ENUM_ENTRY TEST2
FUN private constructor TEST2()
CONSTRUCTOR private constructor TEST2()
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL TestEnum4 super
x: CONST Int type=kotlin.Int value='2'
+3 -3
View File
@@ -1,6 +1,6 @@
FILE /initVal.kt
CLASS CLASS TestInitValFromParameter
FUN public constructor TestInitValFromParameter(/*0*/ x: kotlin.Int)
CONSTRUCTOR public constructor TestInitValFromParameter(/*0*/ x: kotlin.Int)
BLOCK_BODY
SET_BACKING_FIELD x type=kotlin.Unit operator=null
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
@@ -8,7 +8,7 @@ FILE /initVal.kt
EXPRESSION_BODY
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
CLASS CLASS TestInitValInClass
FUN public constructor TestInitValInClass()
CONSTRUCTOR public constructor TestInitValInClass()
BLOCK_BODY
SET_BACKING_FIELD x type=kotlin.Unit operator=null
CONST Int type=kotlin.Int value='0'
@@ -16,7 +16,7 @@ FILE /initVal.kt
EXPRESSION_BODY
CONST Int type=kotlin.Int value='0'
CLASS CLASS TestInitValInInitBlock
FUN public constructor TestInitValInInitBlock()
CONSTRUCTOR public constructor TestInitValInInitBlock()
BLOCK_BODY
BLOCK type=kotlin.Unit operator=null
SET_BACKING_FIELD x type=kotlin.Unit operator=null
+6 -6
View File
@@ -1,6 +1,6 @@
FILE /initVar.kt
CLASS CLASS TestInitVarFromParameter
FUN public constructor TestInitVarFromParameter(/*0*/ x: kotlin.Int)
CONSTRUCTOR public constructor TestInitVarFromParameter(/*0*/ x: kotlin.Int)
BLOCK_BODY
SET_BACKING_FIELD x type=kotlin.Unit operator=null
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
@@ -8,7 +8,7 @@ FILE /initVar.kt
EXPRESSION_BODY
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
CLASS CLASS TestInitVarInClass
FUN public constructor TestInitVarInClass()
CONSTRUCTOR public constructor TestInitVarInClass()
BLOCK_BODY
SET_BACKING_FIELD x type=kotlin.Unit operator=null
CONST Int type=kotlin.Int value='0'
@@ -16,7 +16,7 @@ FILE /initVar.kt
EXPRESSION_BODY
CONST Int type=kotlin.Int value='0'
CLASS CLASS TestInitVarInInitBlock
FUN public constructor TestInitVarInInitBlock()
CONSTRUCTOR public constructor TestInitVarInInitBlock()
BLOCK_BODY
BLOCK type=kotlin.Unit operator=null
CALL .<set-x> type=kotlin.Unit operator=EQ
@@ -24,7 +24,7 @@ FILE /initVar.kt
<set-?>: CONST Int type=kotlin.Int value='0'
PROPERTY public final var x: kotlin.Int
CLASS CLASS TestInitVarWithCustomSetter
FUN public constructor TestInitVarWithCustomSetter()
CONSTRUCTOR public constructor TestInitVarWithCustomSetter()
BLOCK_BODY
SET_BACKING_FIELD x type=kotlin.Unit operator=null
CONST Int type=kotlin.Int value='0'
@@ -46,7 +46,7 @@ FILE /initVar.kt
BLOCK_BODY
SET_BACKING_FIELD x type=kotlin.Unit operator=EQ
GET_VAR value type=kotlin.Int operator=null
FUN public constructor TestInitVarWithCustomSetterWithExplicitCtor()
CONSTRUCTOR public constructor TestInitVarWithCustomSetterWithExplicitCtor()
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL Any
NESTED_INITIALIZERS_CALL classDescriptor=TestInitVarWithCustomSetterWithExplicitCtor
@@ -57,7 +57,7 @@ FILE /initVar.kt
BLOCK_BODY
SET_BACKING_FIELD x type=kotlin.Unit operator=EQ
GET_VAR value type=kotlin.Int operator=null
FUN public constructor TestInitVarWithCustomSetterInCtor()
CONSTRUCTOR public constructor TestInitVarWithCustomSetterInCtor()
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL Any
NESTED_INITIALIZERS_CALL classDescriptor=TestInitVarWithCustomSetterInCtor
+1 -1
View File
@@ -2,7 +2,7 @@ FILE /localClasses.kt
FUN public fun outer(): kotlin.Unit
BLOCK_BODY
CLASS CLASS LocalClass
FUN public constructor LocalClass()
CONSTRUCTOR public constructor LocalClass()
BLOCK_BODY
FUN public final fun foo(): kotlin.Unit
BLOCK_BODY
@@ -5,14 +5,14 @@ FILE /objectLiteralExpressions.kt
EXPRESSION_BODY
BLOCK type=test1.<no name provided> operator=OBJECT_LITERAL
CLASS CLASS <no name provided>
FUN public constructor <no name provided>()
CONSTRUCTOR public constructor <no name provided>()
BLOCK_BODY
CALL .<init> type=test1.<no name provided> operator=OBJECT_LITERAL
PROPERTY public val test2: IFoo
EXPRESSION_BODY
BLOCK type=test2.<no name provided> operator=OBJECT_LITERAL
CLASS CLASS <no name provided>
FUN public constructor <no name provided>()
CONSTRUCTOR public constructor <no name provided>()
BLOCK_BODY
FUN public open override /*1*/ fun foo(): kotlin.Unit
BLOCK_BODY
@@ -20,17 +20,17 @@ FILE /objectLiteralExpressions.kt
message: CONST String type=kotlin.String value='foo'
CALL .<init> type=test2.<no name provided> operator=OBJECT_LITERAL
CLASS CLASS Outer
FUN public constructor Outer()
CONSTRUCTOR public constructor Outer()
BLOCK_BODY
CLASS CLASS Inner
FUN public constructor Inner()
CONSTRUCTOR public constructor Inner()
BLOCK_BODY
FUN public final fun test3(): Outer.Inner
BLOCK_BODY
RETURN type=kotlin.Nothing from=test3
BLOCK type=Outer.test3.<no name provided> operator=OBJECT_LITERAL
CLASS CLASS <no name provided>
FUN public constructor <no name provided>()
CONSTRUCTOR public constructor <no name provided>()
BLOCK_BODY
CALL .<init> type=Outer.Inner operator=SUPER_CONSTRUCTOR_CALL
$this: THIS public final class Outer type=Outer
@@ -44,7 +44,7 @@ FILE /objectLiteralExpressions.kt
RETURN type=kotlin.Nothing from=test4
BLOCK type=test4.<no name provided> operator=OBJECT_LITERAL
CLASS CLASS <no name provided>
FUN public constructor <no name provided>()
CONSTRUCTOR public constructor <no name provided>()
BLOCK_BODY
CALL .<init> type=Outer.Inner operator=SUPER_CONSTRUCTOR_CALL
$this: $RECEIVER of: test4 type=Outer
+3 -3
View File
@@ -1,6 +1,6 @@
FILE /primaryConstructor.kt
CLASS CLASS Test1
FUN public constructor Test1(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
CONSTRUCTOR public constructor Test1(/*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
@@ -13,7 +13,7 @@ FILE /primaryConstructor.kt
EXPRESSION_BODY
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
CLASS CLASS Test2
FUN public constructor Test2(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
CONSTRUCTOR public constructor Test2(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
BLOCK_BODY
SET_BACKING_FIELD y type=kotlin.Unit operator=null
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
@@ -26,7 +26,7 @@ FILE /primaryConstructor.kt
EXPRESSION_BODY
GET_VAR x type=kotlin.Int operator=null
CLASS CLASS Test3
FUN public constructor Test3(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
CONSTRUCTOR public constructor Test3(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
BLOCK_BODY
SET_BACKING_FIELD y type=kotlin.Unit operator=null
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
@@ -1,17 +1,17 @@
FILE /primaryConstructorWithSuperConstructorCall.kt
CLASS CLASS Base
FUN public constructor Base()
CONSTRUCTOR public constructor Base()
BLOCK_BODY
CLASS CLASS TestImplicitPrimaryConstructor
FUN public constructor TestImplicitPrimaryConstructor()
CONSTRUCTOR public constructor TestImplicitPrimaryConstructor()
BLOCK_BODY
CALL .<init> type=Base operator=SUPER_CONSTRUCTOR_CALL
CLASS CLASS TestExplicitPrimaryConstructor
FUN public constructor TestExplicitPrimaryConstructor()
CONSTRUCTOR public constructor TestExplicitPrimaryConstructor()
BLOCK_BODY
CALL .<init> type=Base operator=SUPER_CONSTRUCTOR_CALL
CLASS CLASS TestWithDelegatingConstructor
FUN public constructor TestWithDelegatingConstructor(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
CONSTRUCTOR public constructor TestWithDelegatingConstructor(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int)
BLOCK_BODY
CALL .<init> type=Base operator=SUPER_CONSTRUCTOR_CALL
SET_BACKING_FIELD x type=kotlin.Unit operator=null
@@ -24,7 +24,7 @@ FILE /primaryConstructorWithSuperConstructorCall.kt
PROPERTY public final val y: kotlin.Int
EXPRESSION_BODY
GET_VAR y type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN public constructor TestWithDelegatingConstructor(/*0*/ x: kotlin.Int)
CONSTRUCTOR public constructor TestWithDelegatingConstructor(/*0*/ x: kotlin.Int)
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL TestWithDelegatingConstructor
x: GET_VAR x type=kotlin.Int operator=null
@@ -16,7 +16,7 @@ FILE /qualifiedSuperCalls.kt
RETURN type=kotlin.Nothing from=<get-bar>
CONST Int type=kotlin.Int value='2'
CLASS CLASS CBoth
FUN public constructor CBoth()
CONSTRUCTOR public constructor CBoth()
BLOCK_BODY
FUN public open override /*2*/ fun foo(): kotlin.Unit
BLOCK_BODY
@@ -1,6 +1,6 @@
FILE /secondaryConstructorWithInitializersFromClassBody.kt
CLASS CLASS Base
FUN public constructor Base()
CONSTRUCTOR public constructor Base()
BLOCK_BODY
CLASS CLASS TestProperty
nestedInitializers: BLOCK_BODY
@@ -9,7 +9,7 @@ FILE /secondaryConstructorWithInitializersFromClassBody.kt
PROPERTY public final val x: kotlin.Int = 0
EXPRESSION_BODY
CONST Int type=kotlin.Int value='0'
FUN public constructor TestProperty()
CONSTRUCTOR public constructor TestProperty()
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL Base
NESTED_INITIALIZERS_CALL classDescriptor=TestProperty
@@ -19,7 +19,7 @@ FILE /secondaryConstructorWithInitializersFromClassBody.kt
SET_BACKING_FIELD x type=kotlin.Unit operator=null
CONST Int type=kotlin.Int value='0'
PROPERTY public final val x: kotlin.Int
FUN public constructor TestInitBlock()
CONSTRUCTOR public constructor TestInitBlock()
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL Base
NESTED_INITIALIZERS_CALL classDescriptor=TestInitBlock
@@ -1,11 +1,11 @@
FILE /secondaryConstructors.kt
CLASS CLASS C
nestedInitializers: BLOCK_BODY
FUN public constructor C()
CONSTRUCTOR public constructor C()
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL C
x: CONST Int type=kotlin.Int value='0'
FUN public constructor C(/*0*/ x: kotlin.Int)
CONSTRUCTOR public constructor C(/*0*/ x: kotlin.Int)
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL Any
NESTED_INITIALIZERS_CALL classDescriptor=C
+2 -2
View File
@@ -1,6 +1,6 @@
FILE /superCalls.kt
CLASS CLASS Base
FUN public constructor Base()
CONSTRUCTOR public constructor Base()
BLOCK_BODY
SET_BACKING_FIELD bar type=kotlin.Unit operator=null
CONST String type=kotlin.String value=''
@@ -10,7 +10,7 @@ FILE /superCalls.kt
EXPRESSION_BODY
CONST String type=kotlin.String value=''
CLASS CLASS Derived
FUN public constructor Derived()
CONSTRUCTOR public constructor Derived()
BLOCK_BODY
CALL .<init> type=Base operator=SUPER_CONSTRUCTOR_CALL
FUN public open override /*1*/ fun foo(): kotlin.Unit
+1
View File
@@ -0,0 +1 @@
fun test1(x: Int, y: Int = 0, z: String = "abc") {}
+7
View File
@@ -0,0 +1,7 @@
FILE /defaultArguments.kt
FUN public fun test1(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Int = ..., /*2*/ z: kotlin.String = ...): kotlin.Unit
y: EXPRESSION_BODY
CONST Int type=kotlin.Int value='0'
z: EXPRESSION_BODY
CONST String type=kotlin.String value='abc'
BLOCK_BODY
@@ -12,7 +12,7 @@ FILE /arrayAugmentedAssignment1.kt
RETURN type=kotlin.Nothing from=bar
CONST Int type=kotlin.Int value='42'
CLASS CLASS C
FUN public constructor C(/*0*/ x: kotlin.IntArray)
CONSTRUCTOR public constructor C(/*0*/ x: kotlin.IntArray)
BLOCK_BODY
SET_BACKING_FIELD x type=kotlin.Unit operator=null
GET_VAR x type=kotlin.IntArray operator=INITIALIZE_PROPERTY_FROM_PARAMETER
+1 -1
View File
@@ -1,6 +1,6 @@
FILE /assignments.kt
CLASS CLASS Ref
FUN public constructor Ref(/*0*/ x: kotlin.Int)
CONSTRUCTOR public constructor Ref(/*0*/ x: kotlin.Int)
BLOCK_BODY
SET_BACKING_FIELD x type=kotlin.Unit operator=null
GET_VAR x type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
@@ -1,6 +1,6 @@
FILE /augmentedAssignment2.kt
CLASS CLASS A
FUN public constructor A()
CONSTRUCTOR public constructor A()
BLOCK_BODY
FUN public operator fun A.plusAssign(/*0*/ s: kotlin.String): kotlin.Unit
BLOCK_BODY
@@ -1,6 +1,6 @@
FILE /chainOfSafeCalls.kt
CLASS CLASS C
FUN public constructor C()
CONSTRUCTOR public constructor C()
BLOCK_BODY
FUN public final fun foo(): C
BLOCK_BODY
@@ -1,9 +1,9 @@
FILE /forWithImplicitReceivers.kt
CLASS OBJECT FiveTimes
FUN private constructor FiveTimes()
CONSTRUCTOR private constructor FiveTimes()
BLOCK_BODY
CLASS CLASS IntCell
FUN public constructor IntCell(/*0*/ value: kotlin.Int)
CONSTRUCTOR public constructor IntCell(/*0*/ value: kotlin.Int)
BLOCK_BODY
SET_BACKING_FIELD value type=kotlin.Unit operator=null
GET_VAR value type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
@@ -21,7 +21,7 @@ FILE /jvmStaticFieldReference.kt
CALL .<get-out> type=java.io.PrintStream! operator=GET_PROPERTY
p0: CONST String type=kotlin.String value='testProp/set'
CLASS CLASS TestClass
FUN public constructor TestClass()
CONSTRUCTOR public constructor TestClass()
BLOCK_BODY
SET_BACKING_FIELD test type=kotlin.Unit operator=null
WHEN type=kotlin.Int operator=WHEN
@@ -1,6 +1,6 @@
FILE /safeCallWithIncrementDecrement.kt
CLASS CLASS C
FUN public constructor C()
CONSTRUCTOR public constructor C()
BLOCK_BODY
PROPERTY public var test.C?.p: kotlin.Int
PROPERTY_GETTER public fun test.C?.<get-p>(): kotlin.Int
+1 -1
View File
@@ -1,6 +1,6 @@
FILE /safeCalls.kt
CLASS CLASS Ref
FUN public constructor Ref(/*0*/ value: kotlin.Int)
CONSTRUCTOR public constructor Ref(/*0*/ value: kotlin.Int)
BLOCK_BODY
SET_BACKING_FIELD value type=kotlin.Unit operator=null
GET_VAR value type=kotlin.Int operator=INITIALIZE_PROPERTY_FROM_PARAMETER
+4 -4
View File
@@ -1,6 +1,6 @@
FILE /values.kt
CLASS ENUM_CLASS Enum
FUN private constructor Enum()
CONSTRUCTOR private constructor Enum()
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL Enum super
ENUM_ENTRY enum entry A
@@ -10,16 +10,16 @@ FILE /values.kt
FUN public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): Enum
SYNTHETIC_BODY kind=ENUM_VALUEOF
CLASS OBJECT A
FUN private constructor A()
CONSTRUCTOR private constructor A()
BLOCK_BODY
PROPERTY public val a: kotlin.Int = 0
EXPRESSION_BODY
CONST Int type=kotlin.Int value='0'
CLASS CLASS Z
FUN public constructor Z()
CONSTRUCTOR public constructor Z()
BLOCK_BODY
CLASS OBJECT Companion
FUN private constructor Companion()
CONSTRUCTOR private constructor Companion()
BLOCK_BODY
FUN public fun test1(): Enum
BLOCK_BODY
+1 -1
View File
@@ -1,6 +1,6 @@
FILE /when.kt
CLASS OBJECT A
FUN private constructor A()
CONSTRUCTOR private constructor A()
BLOCK_BODY
FUN public fun testWithSubject(/*0*/ x: kotlin.Any?): kotlin.String
BLOCK_BODY
@@ -1,9 +1,9 @@
FILE /multipleImplicitReceivers.kt
CLASS OBJECT A
FUN private constructor A()
CONSTRUCTOR private constructor A()
BLOCK_BODY
CLASS OBJECT B
FUN private constructor B()
CONSTRUCTOR private constructor B()
BLOCK_BODY
CLASS INTERFACE IFoo
PROPERTY public open val A.foo: B
@@ -35,6 +35,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/ir/irText"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("defaultArguments.kt")
public void testDefaultArguments() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/defaultArguments.kt");
doTest(fileName);
}
@TestMetadata("compiler/testData/ir/irText/classes")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)