Introduce IrTypeParameter and IrValueParameter declarations
This commit is contained in:
@@ -23,6 +23,8 @@ interface IrClass : IrDeclaration, IrDeclarationContainer {
|
|||||||
get() = IrDeclarationKind.CLASS
|
get() = IrDeclarationKind.CLASS
|
||||||
|
|
||||||
override val descriptor: ClassDescriptor
|
override val descriptor: ClassDescriptor
|
||||||
|
|
||||||
|
val typeParameters: MutableList<IrTypeParameter>
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IrClass.getInstanceInitializerMembers() =
|
fun IrClass.getInstanceInitializerMembers() =
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ enum class IrDeclarationKind {
|
|||||||
LOCAL_PROPERTY_ACCESSOR,
|
LOCAL_PROPERTY_ACCESSOR,
|
||||||
TYPEALIAS,
|
TYPEALIAS,
|
||||||
ANONYMOUS_INITIALIZER,
|
ANONYMOUS_INITIALIZER,
|
||||||
|
TYPE_PARAMETER,
|
||||||
|
VALUE_PARAMETER,
|
||||||
ERROR;
|
ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,11 @@ import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
|||||||
|
|
||||||
interface IrFunction : IrDeclaration {
|
interface IrFunction : IrDeclaration {
|
||||||
override val descriptor: FunctionDescriptor
|
override val descriptor: FunctionDescriptor
|
||||||
|
|
||||||
|
val typeParameters: MutableList<IrTypeParameter>
|
||||||
|
|
||||||
|
val valueParameters: MutableList<IrValueParameter>
|
||||||
|
|
||||||
var body: IrBody?
|
var body: IrBody?
|
||||||
|
|
||||||
override val declarationKind: IrDeclarationKind
|
override val declarationKind: IrDeclarationKind
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
|||||||
|
|
||||||
interface IrProperty : IrDeclaration {
|
interface IrProperty : IrDeclaration {
|
||||||
override val descriptor: PropertyDescriptor
|
override val descriptor: PropertyDescriptor
|
||||||
|
val typeParameters: MutableList<IrTypeParameter>
|
||||||
val isDelegated: Boolean
|
val isDelegated: Boolean
|
||||||
var backingField: IrField?
|
var backingField: IrField?
|
||||||
var getter: IrFunction?
|
var getter: IrFunction?
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.ir.declarations
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
|
|
||||||
|
interface IrTypeParameter : IrDeclaration {
|
||||||
|
override val declarationKind: IrDeclarationKind
|
||||||
|
get() = IrDeclarationKind.TYPE_PARAMETER
|
||||||
|
|
||||||
|
override val descriptor: TypeParameterDescriptor
|
||||||
|
|
||||||
|
override fun <D> transform(transformer: IrElementTransformer<D>, data: D): IrTypeParameter
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.ir.declarations
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
|
|
||||||
|
interface IrValueParameter : IrDeclaration {
|
||||||
|
override val declarationKind: IrDeclarationKind
|
||||||
|
get() = IrDeclarationKind.VALUE_PARAMETER
|
||||||
|
|
||||||
|
override val descriptor: ParameterDescriptor
|
||||||
|
|
||||||
|
override fun <D> transform(transformer: IrElementTransformer<D>, data: D): IrValueParameter
|
||||||
|
|
||||||
|
var defaultValue: IrExpressionBody?
|
||||||
|
}
|
||||||
@@ -17,12 +17,11 @@
|
|||||||
package org.jetbrains.kotlin.ir.declarations.impl
|
package org.jetbrains.kotlin.ir.declarations.impl
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
import org.jetbrains.kotlin.ir.util.transform
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationContainer
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
|
import org.jetbrains.kotlin.utils.SmartList
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class IrClassImpl(
|
class IrClassImpl(
|
||||||
@@ -40,6 +39,8 @@ class IrClassImpl(
|
|||||||
|
|
||||||
override val declarations: MutableList<IrDeclaration> = ArrayList()
|
override val declarations: MutableList<IrDeclaration> = ArrayList()
|
||||||
|
|
||||||
|
override val typeParameters: MutableList<IrTypeParameter> = SmartList()
|
||||||
|
|
||||||
fun addMember(member: IrDeclaration) {
|
fun addMember(member: IrDeclaration) {
|
||||||
declarations.add(member)
|
declarations.add(member)
|
||||||
}
|
}
|
||||||
@@ -52,12 +53,12 @@ class IrClassImpl(
|
|||||||
visitor.visitClass(this, data)
|
visitor.visitClass(this, data)
|
||||||
|
|
||||||
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||||
|
typeParameters.forEach { it.accept(visitor, data) }
|
||||||
declarations.forEach { it.accept(visitor, data) }
|
declarations.forEach { it.accept(visitor, data) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||||
declarations.forEachIndexed { i, irDeclaration ->
|
typeParameters.transform { it.transform(transformer, data) }
|
||||||
declarations[i] = irDeclaration.transform(transformer, data) as IrDeclaration
|
declarations.transform { it.transform(transformer, data) as IrDeclaration }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-8
@@ -19,37 +19,48 @@ package org.jetbrains.kotlin.ir.declarations.impl
|
|||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrBody
|
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||||
|
import org.jetbrains.kotlin.ir.util.transform
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import java.util.*
|
import org.jetbrains.kotlin.utils.SmartList
|
||||||
|
|
||||||
abstract class IrFunctionBase(
|
abstract class IrFunctionBase(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
origin: IrDeclarationOrigin
|
origin: IrDeclarationOrigin
|
||||||
) : IrDeclarationBase(startOffset, endOffset, origin), IrFunction {
|
) : IrDeclarationBase(startOffset, endOffset, origin), IrFunction {
|
||||||
private val defaults = LinkedHashMap<ValueParameterDescriptor, IrExpressionBody>()
|
override val typeParameters: MutableList<IrTypeParameter> = SmartList()
|
||||||
|
|
||||||
|
override val valueParameters: MutableList<IrValueParameter> = ArrayList()
|
||||||
|
|
||||||
final override var body: IrBody? = null
|
final override var body: IrBody? = null
|
||||||
|
|
||||||
|
private fun getIrValueParameter(parameter: ValueParameterDescriptor): IrValueParameter =
|
||||||
|
valueParameters.getOrElse(parameter.index) {
|
||||||
|
throw AssertionError("No IrValueParameter for $parameter")
|
||||||
|
}
|
||||||
|
|
||||||
override fun getDefault(parameter: ValueParameterDescriptor): IrExpressionBody? =
|
override fun getDefault(parameter: ValueParameterDescriptor): IrExpressionBody? =
|
||||||
defaults[parameter]
|
getIrValueParameter(parameter).defaultValue
|
||||||
|
|
||||||
override fun putDefault(parameter: ValueParameterDescriptor, expressionBody: IrExpressionBody) {
|
override fun putDefault(parameter: ValueParameterDescriptor, expressionBody: IrExpressionBody) {
|
||||||
defaults[parameter] = expressionBody
|
getIrValueParameter(parameter).defaultValue = expressionBody
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||||
defaults.values.forEach { it.accept(visitor, data) }
|
typeParameters.forEach { it.accept(visitor, data) }
|
||||||
|
valueParameters.forEach { it.accept(visitor, data) }
|
||||||
body?.accept(visitor, data)
|
body?.accept(visitor, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||||
for ((valueParameter, defaultValue) in defaults) {
|
typeParameters.transform { it.transform(transformer, data) }
|
||||||
putDefault(valueParameter, defaultValue.transform(transformer, data))
|
valueParameters.transform { it.transform(transformer, data) }
|
||||||
}
|
|
||||||
body = body?.transform(transformer, data)
|
body = body?.transform(transformer, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,12 +18,11 @@ package org.jetbrains.kotlin.ir.declarations.impl
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
import org.jetbrains.kotlin.ir.*
|
import org.jetbrains.kotlin.ir.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrField
|
import org.jetbrains.kotlin.ir.util.transform
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
|
import org.jetbrains.kotlin.utils.SmartList
|
||||||
|
|
||||||
class IrPropertyImpl(
|
class IrPropertyImpl(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
@@ -47,6 +46,7 @@ class IrPropertyImpl(
|
|||||||
this.setter = setter
|
this.setter = setter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val typeParameters: MutableList<IrTypeParameter> = SmartList()
|
||||||
override var backingField: IrField? = null
|
override var backingField: IrField? = null
|
||||||
override var getter: IrFunction? = null
|
override var getter: IrFunction? = null
|
||||||
override var setter: IrFunction? = null
|
override var setter: IrFunction? = null
|
||||||
@@ -56,12 +56,14 @@ class IrPropertyImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||||
|
typeParameters.forEach { it.accept(visitor, data) }
|
||||||
backingField?.accept(visitor, data)
|
backingField?.accept(visitor, data)
|
||||||
getter?.accept(visitor, data)
|
getter?.accept(visitor, data)
|
||||||
setter?.accept(visitor, data)
|
setter?.accept(visitor, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||||
|
typeParameters.transform { it.transform(transformer, data) }
|
||||||
backingField = backingField?.transform(transformer, data) as? IrField
|
backingField = backingField?.transform(transformer, data) as? IrField
|
||||||
getter = getter?.transform(transformer, data) as? IrFunction
|
getter = getter?.transform(transformer, data) as? IrFunction
|
||||||
setter = setter?.transform(transformer, data) as? IrFunction
|
setter = setter?.transform(transformer, data) as? IrFunction
|
||||||
|
|||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.ir.declarations.impl
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
|
|
||||||
|
class IrTypeParameterImpl(
|
||||||
|
startOffset: Int,
|
||||||
|
endOffset: Int,
|
||||||
|
origin: IrDeclarationOrigin,
|
||||||
|
override val descriptor: TypeParameterDescriptor
|
||||||
|
) : IrDeclarationBase(startOffset, endOffset, origin), IrTypeParameter {
|
||||||
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||||
|
visitor.visitTypeParameter(this, data)
|
||||||
|
|
||||||
|
override fun <D> transform(transformer: IrElementTransformer<D>, data: D): IrTypeParameter =
|
||||||
|
transformer.visitTypeParameter(this, data) as IrTypeParameter
|
||||||
|
|
||||||
|
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||||
|
// no children
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||||
|
// no children
|
||||||
|
}
|
||||||
|
}
|
||||||
+67
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.ir.declarations.impl
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
|
|
||||||
|
class IrValueParameterImpl(
|
||||||
|
startOffset: Int,
|
||||||
|
endOffset: Int,
|
||||||
|
origin: IrDeclarationOrigin,
|
||||||
|
override val descriptor: ParameterDescriptor
|
||||||
|
) : IrDeclarationBase(startOffset, endOffset, origin), IrValueParameter {
|
||||||
|
constructor(
|
||||||
|
startOffset: Int,
|
||||||
|
endOffset: Int,
|
||||||
|
origin: IrDeclarationOrigin,
|
||||||
|
descriptor: ParameterDescriptor,
|
||||||
|
defaultValue: IrExpressionBody
|
||||||
|
) : this(startOffset, endOffset, origin, descriptor) {
|
||||||
|
this.defaultValue = defaultValue
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
startOffset: Int,
|
||||||
|
endOffset: Int,
|
||||||
|
origin: IrDeclarationOrigin,
|
||||||
|
descriptor: ParameterDescriptor,
|
||||||
|
defaultValue: IrExpression
|
||||||
|
) : this(startOffset, endOffset, origin, descriptor, IrExpressionBodyImpl(defaultValue))
|
||||||
|
|
||||||
|
override var defaultValue: IrExpressionBody? = null
|
||||||
|
|
||||||
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||||
|
visitor.visitValueParameter(this, data)
|
||||||
|
|
||||||
|
override fun <D> transform(transformer: IrElementTransformer<D>, data: D): IrValueParameter =
|
||||||
|
transformer.visitValueParameter(this, data) as IrValueParameter
|
||||||
|
|
||||||
|
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||||
|
defaultValue?.accept(visitor, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||||
|
defaultValue = defaultValue?.transform(transformer, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-3
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.ir.expressions.impl
|
|||||||
import org.jetbrains.kotlin.ir.*
|
import org.jetbrains.kotlin.ir.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrContainerExpression
|
import org.jetbrains.kotlin.ir.expressions.IrContainerExpression
|
||||||
|
import org.jetbrains.kotlin.ir.util.transform
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
@@ -33,8 +34,6 @@ abstract class IrContainerExpressionBase(startOffset: Int, endOffset: Int, type:
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||||
statements.forEachIndexed { i, irStatement ->
|
statements.transform { it.transform(transformer, data) }
|
||||||
statements[i] = irStatement.transform(transformer, data)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,31 +64,35 @@ class DumpIrTreeVisitor(out: Appendable): IrElementVisitor<Unit, String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declaration.declarations.forEach { it.accept(this, "") }
|
declaration.declarations.dumpElements()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitFunction(declaration: IrFunction, data: String) {
|
override fun visitFunction(declaration: IrFunction, data: String) {
|
||||||
visitFunctionWithParameters(declaration, data)
|
declaration.dumpLabeledElementWith(data) {
|
||||||
|
declaration.typeParameters.dumpElements()
|
||||||
|
declaration.valueParameters.dumpElements()
|
||||||
|
declaration.body?.accept(this, "")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitConstructor(declaration: IrConstructor, data: String) {
|
override fun visitProperty(declaration: IrProperty, data: String) {
|
||||||
visitFunctionWithParameters(declaration, data)
|
declaration.dumpLabeledElementWith(data) {
|
||||||
|
declaration.typeParameters.dumpElements()
|
||||||
|
declaration.backingField?.accept(this, "")
|
||||||
|
declaration.getter?.accept(this, "")
|
||||||
|
declaration.setter?.accept(this, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun List<IrElement>.dumpElements() {
|
||||||
|
forEach { it.accept(this@DumpIrTreeVisitor, "") }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitErrorCallExpression(expression: IrErrorCallExpression, data: String) {
|
override fun visitErrorCallExpression(expression: IrErrorCallExpression, data: String) {
|
||||||
expression.dumpLabeledElementWith(data) {
|
expression.dumpLabeledElementWith(data) {
|
||||||
expression.explicitReceiver?.accept(this, "receiver")
|
expression.explicitReceiver?.accept(this, "receiver")
|
||||||
expression.arguments.forEach { it.accept(this, "") }
|
expression.arguments.dumpElements()
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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, "")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,9 +139,7 @@ class DumpIrTreeVisitor(out: Appendable): IrElementVisitor<Unit, String> {
|
|||||||
|
|
||||||
override fun visitWhen(expression: IrWhen, data: String) {
|
override fun visitWhen(expression: IrWhen, data: String) {
|
||||||
expression.dumpLabeledElementWith(data) {
|
expression.dumpLabeledElementWith(data) {
|
||||||
expression.branches.forEach {
|
expression.branches.dumpElements()
|
||||||
it.accept(this, "")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,9 +167,7 @@ class DumpIrTreeVisitor(out: Appendable): IrElementVisitor<Unit, String> {
|
|||||||
override fun visitTry(aTry: IrTry, data: String) {
|
override fun visitTry(aTry: IrTry, data: String) {
|
||||||
aTry.dumpLabeledElementWith(data) {
|
aTry.dumpLabeledElementWith(data) {
|
||||||
aTry.tryResult.accept(this, "try")
|
aTry.tryResult.accept(this, "try")
|
||||||
for (aCatch in aTry.catches) {
|
aTry.catches.dumpElements()
|
||||||
aCatch.accept(this, "")
|
|
||||||
}
|
|
||||||
aTry.finallyExpression?.accept(this, "finally")
|
aTry.finallyExpression?.accept(this, "finally")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,12 @@ class RenderIrElementVisitor : IrElementVisitor<String, Nothing?> {
|
|||||||
override fun visitAnonymousInitializer(declaration: IrAnonymousInitializer, data: Nothing?): String =
|
override fun visitAnonymousInitializer(declaration: IrAnonymousInitializer, data: Nothing?): String =
|
||||||
"ANONYMOUS_INITIALIZER ${declaration.descriptor.ref()}"
|
"ANONYMOUS_INITIALIZER ${declaration.descriptor.ref()}"
|
||||||
|
|
||||||
|
override fun visitTypeParameter(declaration: IrTypeParameter, data: Nothing?): String =
|
||||||
|
"TYPE_PARAMETER ${declaration.renderDeclared()}"
|
||||||
|
|
||||||
|
override fun visitValueParameter(declaration: IrValueParameter, data: Nothing?): String =
|
||||||
|
"VALUE_PARAMETER ${declaration.renderDeclared()}"
|
||||||
|
|
||||||
override fun visitLocalDelegatedProperty(declaration: IrLocalDelegatedProperty, data: Nothing?): String =
|
override fun visitLocalDelegatedProperty(declaration: IrLocalDelegatedProperty, data: Nothing?): String =
|
||||||
"LOCAL_DELEGATED_PROPERTY ${declaration.renderOrigin()}${declaration.renderDeclared()}"
|
"LOCAL_DELEGATED_PROPERTY ${declaration.renderOrigin()}${declaration.renderDeclared()}"
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ interface IrElementTransformer<in D> : IrElementVisitor<IrElement, D> {
|
|||||||
override fun visitEnumEntry(declaration: IrEnumEntry, data: D) = visitDeclaration(declaration, data)
|
override fun visitEnumEntry(declaration: IrEnumEntry, data: D) = visitDeclaration(declaration, data)
|
||||||
override fun visitAnonymousInitializer(declaration: IrAnonymousInitializer, data: D) = visitDeclaration(declaration, data)
|
override fun visitAnonymousInitializer(declaration: IrAnonymousInitializer, data: D) = visitDeclaration(declaration, data)
|
||||||
override fun visitVariable(declaration: IrVariable, data: D) = visitDeclaration(declaration, data)
|
override fun visitVariable(declaration: IrVariable, data: D) = visitDeclaration(declaration, data)
|
||||||
|
override fun visitTypeParameter(declaration: IrTypeParameter, data: D) = visitDeclaration(declaration, data)
|
||||||
|
override fun visitValueParameter(declaration: IrValueParameter, data: D) = visitDeclaration(declaration, data)
|
||||||
|
|
||||||
override fun visitBody(body: IrBody, data: D): IrBody =
|
override fun visitBody(body: IrBody, data: D): IrBody =
|
||||||
body.apply { transformChildren(this@IrElementTransformer, data) }
|
body.apply { transformChildren(this@IrElementTransformer, data) }
|
||||||
|
|||||||
@@ -61,6 +61,12 @@ abstract class IrElementTransformerVoid : IrElementTransformer<Nothing?> {
|
|||||||
open fun visitAnonymousInitializer(declaration: IrAnonymousInitializer) = visitDeclaration(declaration)
|
open fun visitAnonymousInitializer(declaration: IrAnonymousInitializer) = visitDeclaration(declaration)
|
||||||
override final fun visitAnonymousInitializer(declaration: IrAnonymousInitializer, data: Nothing?) = visitAnonymousInitializer(declaration)
|
override final fun visitAnonymousInitializer(declaration: IrAnonymousInitializer, data: Nothing?) = visitAnonymousInitializer(declaration)
|
||||||
|
|
||||||
|
open fun visitTypeParameter(declaration: IrTypeParameter) = visitDeclaration(declaration)
|
||||||
|
override final fun visitTypeParameter(declaration: IrTypeParameter, data: Nothing?): IrStatement = visitTypeParameter(declaration)
|
||||||
|
|
||||||
|
open fun visitValueParameter(declaration: IrValueParameter) = visitDeclaration(declaration)
|
||||||
|
override final fun visitValueParameter(declaration: IrValueParameter, data: Nothing?): IrStatement = visitValueParameter(declaration)
|
||||||
|
|
||||||
open fun visitVariable(declaration: IrVariable) = visitDeclaration(declaration)
|
open fun visitVariable(declaration: IrVariable) = visitDeclaration(declaration)
|
||||||
override final fun visitVariable(declaration: IrVariable, data: Nothing?) = visitVariable(declaration)
|
override final fun visitVariable(declaration: IrVariable, data: Nothing?) = visitVariable(declaration)
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ interface IrElementVisitor<out R, in D> {
|
|||||||
fun visitVariable(declaration: IrVariable, data: D) = visitDeclaration(declaration, data)
|
fun visitVariable(declaration: IrVariable, data: D) = visitDeclaration(declaration, data)
|
||||||
fun visitEnumEntry(declaration: IrEnumEntry, data: D) = visitDeclaration(declaration, data)
|
fun visitEnumEntry(declaration: IrEnumEntry, data: D) = visitDeclaration(declaration, data)
|
||||||
fun visitAnonymousInitializer(declaration: IrAnonymousInitializer, data: D) = visitDeclaration(declaration, data)
|
fun visitAnonymousInitializer(declaration: IrAnonymousInitializer, data: D) = visitDeclaration(declaration, data)
|
||||||
|
fun visitTypeParameter(declaration: IrTypeParameter, data: D) = visitDeclaration(declaration, data)
|
||||||
|
fun visitValueParameter(declaration: IrValueParameter, data: D) = visitDeclaration(declaration, data)
|
||||||
|
|
||||||
fun visitBody(body: IrBody, data: D) = visitElement(body, data)
|
fun visitBody(body: IrBody, data: D) = visitElement(body, data)
|
||||||
fun visitExpressionBody(body: IrExpressionBody, data: D) = visitBody(body, data)
|
fun visitExpressionBody(body: IrExpressionBody, data: D) = visitBody(body, data)
|
||||||
|
|||||||
@@ -63,6 +63,12 @@ interface IrElementVisitorVoid : IrElementVisitor<Unit, Nothing?> {
|
|||||||
fun visitAnonymousInitializer(declaration: IrAnonymousInitializer) = visitDeclaration(declaration)
|
fun visitAnonymousInitializer(declaration: IrAnonymousInitializer) = visitDeclaration(declaration)
|
||||||
override fun visitAnonymousInitializer(declaration: IrAnonymousInitializer, data: Nothing?) = visitAnonymousInitializer(declaration)
|
override fun visitAnonymousInitializer(declaration: IrAnonymousInitializer, data: Nothing?) = visitAnonymousInitializer(declaration)
|
||||||
|
|
||||||
|
fun visitTypeParameter(declaration: IrTypeParameter) = visitDeclaration(declaration)
|
||||||
|
override fun visitTypeParameter(declaration: IrTypeParameter, data: Nothing?) = visitTypeParameter(declaration)
|
||||||
|
|
||||||
|
fun visitValueParameter(declaration: IrValueParameter) = visitDeclaration(declaration)
|
||||||
|
override fun visitValueParameter(declaration: IrValueParameter, data: Nothing?) = visitValueParameter(declaration)
|
||||||
|
|
||||||
fun visitBody(body: IrBody) = visitElement(body)
|
fun visitBody(body: IrBody) = visitElement(body)
|
||||||
override fun visitBody(body: IrBody, data: Nothing?) = visitBody(body)
|
override fun visitBody(body: IrBody, data: Nothing?) = visitBody(body)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user