IR: make IrExpression and subtypes classes

This commit is contained in:
Alexander Udalov
2020-07-22 21:46:03 +02:00
parent ba7ff36274
commit 4351f5235b
47 changed files with 164 additions and 255 deletions
@@ -42,7 +42,7 @@ data class LoopBounds(val headState: SuspendState, val exitState: SuspendState)
data class TryState(val tryState: SuspendState, val catchState: SuspendState) data class TryState(val tryState: SuspendState, val catchState: SuspendState)
class IrDispatchPoint(val target: SuspendState) : IrExpressionBase() { class IrDispatchPoint(val target: SuspendState) : IrExpression() {
override val startOffset: Int get() = UNDEFINED_OFFSET override val startOffset: Int get() = UNDEFINED_OFFSET
override val endOffset: Int get() = UNDEFINED_OFFSET override val endOffset: Int get() = UNDEFINED_OFFSET
@@ -16,31 +16,46 @@
package org.jetbrains.kotlin.ir.expressions package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrReturnTarget import org.jetbrains.kotlin.ir.declarations.IrReturnTarget
import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner
import org.jetbrains.kotlin.ir.symbols.IrFileSymbol import org.jetbrains.kotlin.ir.symbols.IrFileSymbol
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
import org.jetbrains.kotlin.ir.util.file import org.jetbrains.kotlin.ir.util.file
import org.jetbrains.kotlin.ir.util.transform
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
interface IrContainerExpression : IrExpression, IrStatementContainer { abstract class IrContainerExpression : IrExpression(), IrStatementContainer {
val origin: IrStatementOrigin? abstract val origin: IrStatementOrigin?
val isTransparentScope: Boolean abstract val isTransparentScope: Boolean
override val statements: MutableList<IrStatement> = ArrayList(2)
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
statements.forEach { it.accept(visitor, data) }
}
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
statements.transform { it.transform(transformer, data) }
}
} }
interface IrBlock : IrContainerExpression { abstract class IrBlock : IrContainerExpression() {
override val isTransparentScope: Boolean override val isTransparentScope: Boolean
get() = false get() = false
} }
interface IrComposite : IrContainerExpression { abstract class IrComposite : IrContainerExpression() {
override val isTransparentScope: Boolean override val isTransparentScope: Boolean
get() = true get() = true
} }
interface IrReturnableBlock : IrBlock, IrSymbolOwner, IrReturnTarget { abstract class IrReturnableBlock : IrBlock(), IrSymbolOwner, IrReturnTarget {
override val symbol: IrReturnableBlockSymbol abstract override val symbol: IrReturnableBlockSymbol
val inlineFunctionSymbol: IrFunctionSymbol?
abstract val inlineFunctionSymbol: IrFunctionSymbol?
} }
val IrReturnableBlock.sourceFileSymbol: IrFileSymbol? val IrReturnableBlock.sourceFileSymbol: IrFileSymbol?
@@ -16,11 +16,12 @@
package org.jetbrains.kotlin.ir.expressions package org.jetbrains.kotlin.ir.expressions
interface IrBreakContinue : IrExpression { abstract class IrBreakContinue : IrExpression() {
var loop: IrLoop abstract var loop: IrLoop
val label: String?
var label: String? = null
} }
interface IrBreak : IrBreakContinue abstract class IrBreak : IrBreakContinue()
interface IrContinue : IrBreakContinue abstract class IrContinue : IrBreakContinue()
@@ -16,11 +16,11 @@
package org.jetbrains.kotlin.ir.expressions package org.jetbrains.kotlin.ir.expressions
interface IrConst<T> : IrExpression, IrExpressionWithCopy { abstract class IrConst<T> : IrExpression(), IrExpressionWithCopy {
val kind: IrConstKind<T> abstract val kind: IrConstKind<T>
val value: T abstract val value: T
override fun copy(): IrConst<T> abstract override fun copy(): IrConst<T>
} }
sealed class IrConstKind<T>(val asString: kotlin.String) { sealed class IrConstKind<T>(val asString: kotlin.String) {
@@ -41,4 +41,3 @@ sealed class IrConstKind<T>(val asString: kotlin.String) {
override fun toString() = asString override fun toString() = asString
} }
@@ -16,13 +16,12 @@
package org.jetbrains.kotlin.ir.expressions package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBase
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.ir.symbols.IrSymbol
abstract class IrDeclarationReference : IrExpressionBase() { abstract class IrDeclarationReference : IrExpression() {
abstract val symbol: IrSymbol abstract val symbol: IrSymbol
} }
@@ -5,14 +5,14 @@
package org.jetbrains.kotlin.ir.expressions package org.jetbrains.kotlin.ir.expressions
interface IrDynamicExpression : IrExpression abstract class IrDynamicExpression : IrExpression()
interface IrDynamicOperatorExpression : IrDynamicExpression { abstract class IrDynamicOperatorExpression : IrDynamicExpression() {
val operator: IrDynamicOperator abstract val operator: IrDynamicOperator
var receiver: IrExpression abstract var receiver: IrExpression
val arguments: MutableList<IrExpression> abstract val arguments: MutableList<IrExpression>
} }
var IrDynamicOperatorExpression.left: IrExpression var IrDynamicOperatorExpression.left: IrExpression
@@ -30,9 +30,10 @@ var IrDynamicOperatorExpression.right: IrExpression
arguments[0] = value arguments[0] = value
} }
interface IrDynamicMemberExpression : IrDynamicExpression { abstract class IrDynamicMemberExpression : IrDynamicExpression() {
val memberName: String abstract val memberName: String
var receiver: IrExpression
abstract var receiver: IrExpression
} }
enum class IrDynamicOperator(val image: String, val isAssignmentOperator: Boolean = false) { enum class IrDynamicOperator(val image: String, val isAssignmentOperator: Boolean = false) {
@@ -69,4 +70,4 @@ enum class IrDynamicOperator(val image: String, val isAssignmentOperator: Boolea
ARRAY_ACCESS("[]"), ARRAY_ACCESS("[]"),
INVOKE("()") INVOKE("()")
} }
@@ -16,12 +16,11 @@
package org.jetbrains.kotlin.ir.expressions package org.jetbrains.kotlin.ir.expressions
interface IrErrorExpression : IrExpression { abstract class IrErrorExpression : IrExpression() {
val description: String abstract val description: String
} }
interface IrErrorCallExpression : IrErrorExpression { abstract class IrErrorCallExpression : IrErrorExpression() {
var explicitReceiver: IrExpression? abstract var explicitReceiver: IrExpression?
val arguments: MutableList<IrExpression> abstract val arguments: MutableList<IrExpression>
} }
@@ -16,16 +16,29 @@
package org.jetbrains.kotlin.ir.expressions package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.IrElementBase
import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrAttributeContainer import org.jetbrains.kotlin.ir.declarations.IrAttributeContainer
import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
interface IrExpression : IrStatement, IrVarargElement, IrAttributeContainer { abstract class IrExpression : IrElementBase(), IrStatement, IrVarargElement, IrAttributeContainer {
val type: IrType @Suppress("LeakingThis")
override var attributeOwnerId: IrAttributeContainer = this
abstract val type: IrType
override fun <D> transform(transformer: IrElementTransformer<D>, data: D): IrExpression = override fun <D> transform(transformer: IrElementTransformer<D>, data: D): IrExpression =
accept(transformer, data) as IrExpression accept(transformer, data) as IrExpression
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
// No children by default
}
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
// No children by default
}
} }
interface IrExpressionWithCopy { interface IrExpressionWithCopy {
@@ -7,7 +7,8 @@ package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
interface IrFunctionExpression : IrExpression { abstract class IrFunctionExpression : IrExpression() {
val origin: IrStatementOrigin abstract val origin: IrStatementOrigin
var function: IrSimpleFunction
} abstract var function: IrSimpleFunction
}
@@ -16,8 +16,6 @@
package org.jetbrains.kotlin.ir.expressions package org.jetbrains.kotlin.ir.expressions
abstract class IrGetClass : IrExpression() {
interface IrGetClass : IrExpression { abstract var argument: IrExpression
var argument: IrExpression
} }
@@ -18,6 +18,6 @@ package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
interface IrInstanceInitializerCall : IrExpression { abstract class IrInstanceInitializerCall : IrExpression() {
val classSymbol: IrClassSymbol abstract val classSymbol: IrClassSymbol
} }
@@ -16,13 +16,14 @@
package org.jetbrains.kotlin.ir.expressions package org.jetbrains.kotlin.ir.expressions
interface IrLoop : IrExpression { abstract class IrLoop : IrExpression() {
val origin: IrStatementOrigin? abstract val origin: IrStatementOrigin?
var body: IrExpression?
var condition: IrExpression var body: IrExpression? = null
var label: String? lateinit var condition: IrExpression
var label: String? = null
} }
interface IrWhileLoop : IrLoop abstract class IrWhileLoop : IrLoop()
interface IrDoWhileLoop : IrLoop abstract class IrDoWhileLoop : IrLoop()
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.symbols.IrReturnTargetSymbol import org.jetbrains.kotlin.ir.symbols.IrReturnTargetSymbol
interface IrReturn : IrExpression { abstract class IrReturn : IrExpression() {
var value: IrExpression abstract var value: IrExpression
val returnTargetSymbol: IrReturnTargetSymbol abstract val returnTargetSymbol: IrReturnTargetSymbol
} }
@@ -16,8 +16,8 @@
package org.jetbrains.kotlin.ir.expressions package org.jetbrains.kotlin.ir.expressions
interface IrStringConcatenation : IrExpression { abstract class IrStringConcatenation : IrExpression() {
val arguments: List<IrExpression> abstract val arguments: List<IrExpression>
fun addArgument(argument: IrExpression)
}
abstract fun addArgument(argument: IrExpression)
}
@@ -7,14 +7,13 @@ package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.declarations.IrVariable import org.jetbrains.kotlin.ir.declarations.IrVariable
abstract class IrSuspensionPoint : IrExpression() {
interface IrSuspensionPoint : IrExpression { abstract var suspensionPointIdParameter: IrVariable
var suspensionPointIdParameter: IrVariable abstract var result: IrExpression
var result: IrExpression abstract var resumeResult: IrExpression
var resumeResult: IrExpression
} }
interface IrSuspendableExpression : IrExpression { abstract class IrSuspendableExpression : IrExpression() {
var suspensionPointId: IrExpression abstract var suspensionPointId: IrExpression
var result: IrExpression abstract var result: IrExpression
} }
@@ -16,8 +16,6 @@
package org.jetbrains.kotlin.ir.expressions package org.jetbrains.kotlin.ir.expressions
abstract class IrThrow : IrExpression() {
interface IrThrow : IrExpression { abstract var value: IrExpression
var value: IrExpression
} }
@@ -20,12 +20,12 @@ import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrVariable import org.jetbrains.kotlin.ir.declarations.IrVariable
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
interface IrTry : IrExpression { abstract class IrTry : IrExpression() {
var tryResult: IrExpression abstract var tryResult: IrExpression
val catches: List<IrCatch> abstract val catches: List<IrCatch>
var finallyExpression: IrExpression? abstract var finallyExpression: IrExpression?
} }
interface IrCatch : IrElement { interface IrCatch : IrElement {
@@ -22,43 +22,53 @@ import org.jetbrains.kotlin.ir.types.IrType
enum class IrTypeOperator { enum class IrTypeOperator {
/** Explicit cast: `e as Type` */ /** Explicit cast: `e as Type` */
CAST, CAST,
/** Implicit cast: value of type `A` is used where a value of type `B` is expected */ /** Implicit cast: value of type `A` is used where a value of type `B` is expected */
IMPLICIT_CAST, IMPLICIT_CAST,
/** Implicit cast from a value of nullability flexible type `A!` to non-null type `B`, `B :> A` */ /** Implicit cast from a value of nullability flexible type `A!` to non-null type `B`, `B :> A` */
IMPLICIT_NOTNULL, IMPLICIT_NOTNULL,
/** Implicit coercion to Unit: expression of type `A, !(A <: kotlin.Unit)` is used where `kotlin.Unit` is expected */ /** Implicit coercion to Unit: expression of type `A, !(A <: kotlin.Unit)` is used where `kotlin.Unit` is expected */
IMPLICIT_COERCION_TO_UNIT, IMPLICIT_COERCION_TO_UNIT,
/** /**
* Implicit integer coercion: expression of integer type `A` (`kotlin.Int`, `kotlin.Byte`, ...) * Implicit integer coercion: expression of integer type `A` (`kotlin.Int`, `kotlin.Byte`, ...)
* is used where another integer type `B` (`kotlin.Int`, `kotlin.Byte`, ...) is expected. * is used where another integer type `B` (`kotlin.Int`, `kotlin.Byte`, ...) is expected.
* This mostly happens for constant expressions. * This mostly happens for constant expressions.
*/ */
IMPLICIT_INTEGER_COERCION, IMPLICIT_INTEGER_COERCION,
/** Safe cast: `e as? Type` */ /** Safe cast: `e as? Type` */
SAFE_CAST, SAFE_CAST,
/** Instance-of check: `a is Type` */ /** Instance-of check: `a is Type` */
INSTANCEOF, INSTANCEOF,
/** Instance-of check: `a !is Type` */ /** Instance-of check: `a !is Type` */
NOT_INSTANCEOF, // TODO drop and replace with `INSTANCEOF<T>(x).not()`? NOT_INSTANCEOF, // TODO drop and replace with `INSTANCEOF<T>(x).not()`?
/** /**
* SAM conversion: value of functional type F is used where Single Abstract Method interface value is expected. * SAM conversion: value of functional type F is used where Single Abstract Method interface value is expected.
* Currently this is possible in Kotlin/JVM only, however, there's a big demand for SAM conversion for Kotlin interfaces. * Currently this is possible in Kotlin/JVM only, however, there's a big demand for SAM conversion for Kotlin interfaces.
*/ */
SAM_CONVERSION, SAM_CONVERSION,
/** /**
* Implicit dynamic cast: implicit cast from `dynamic` to `T`. * Implicit dynamic cast: implicit cast from `dynamic` to `T`.
* This currently can happen in Kotlin/JS only. * This currently can happen in Kotlin/JS only.
*/ */
IMPLICIT_DYNAMIC_CAST, IMPLICIT_DYNAMIC_CAST,
/** /**
* C-like reinterpret_cast<T> using as primitive type operation in JS * C-like reinterpret_cast<T> using as primitive type operation in JS
*/ */
REINTERPRET_CAST; REINTERPRET_CAST;
} }
interface IrTypeOperatorCall : IrExpression { abstract class IrTypeOperatorCall : IrExpression() {
val operator: IrTypeOperator abstract val operator: IrTypeOperator
var argument: IrExpression abstract var argument: IrExpression
val typeOperand: IrType abstract val typeOperand: IrType
val typeOperandClassifier: IrClassifierSymbol abstract val typeOperandClassifier: IrClassifierSymbol
} }
@@ -22,12 +22,12 @@ import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
interface IrVarargElement : IrElement interface IrVarargElement : IrElement
interface IrVararg : IrExpression { abstract class IrVararg : IrExpression() {
val varargElementType: IrType abstract val varargElementType: IrType
val elements: List<IrVarargElement> abstract val elements: List<IrVarargElement>
fun putElement(i: Int, element: IrVarargElement) abstract fun putElement(i: Int, element: IrVarargElement)
} }
interface IrSpreadElement : IrVarargElement { interface IrSpreadElement : IrVarargElement {
@@ -36,4 +36,3 @@ interface IrSpreadElement : IrVarargElement {
override fun <D> transform(transformer: IrElementTransformer<D>, data: D): IrElement = override fun <D> transform(transformer: IrElementTransformer<D>, data: D): IrElement =
accept(transformer, data) as IrSpreadElement accept(transformer, data) as IrSpreadElement
} }
@@ -18,11 +18,25 @@ package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
interface IrWhen : IrExpression { abstract class IrWhen : IrExpression() {
val origin: IrStatementOrigin? abstract val origin: IrStatementOrigin?
val branches: MutableList<IrBranch> abstract val branches: MutableList<IrBranch>
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitWhen(this, data)
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
branches.forEach { it.accept(visitor, data) }
}
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
branches.forEachIndexed { i, irBranch ->
branches[i] = irBranch.transform(transformer, data)
}
}
} }
interface IrBranch : IrElement { interface IrBranch : IrElement {
@@ -33,7 +33,7 @@ class IrBlockImpl(
override val endOffset: Int, override val endOffset: Int,
override val type: IrType, override val type: IrType,
override val origin: IrStatementOrigin? = null, override val origin: IrStatementOrigin? = null,
) : IrContainerExpressionBase(), IrBlock { ) : IrBlock() {
constructor( constructor(
startOffset: Int, startOffset: Int,
endOffset: Int, endOffset: Int,
@@ -67,7 +67,7 @@ class IrReturnableBlockImpl(
override val symbol: IrReturnableBlockSymbol, override val symbol: IrReturnableBlockSymbol,
override val origin: IrStatementOrigin? = null, override val origin: IrStatementOrigin? = null,
override val inlineFunctionSymbol: IrFunctionSymbol? = null override val inlineFunctionSymbol: IrFunctionSymbol? = null
) : IrContainerExpressionBase(), IrReturnableBlock { ) : IrReturnableBlock() {
@ObsoleteDescriptorBasedAPI @ObsoleteDescriptorBasedAPI
override val descriptor: FunctionDescriptor override val descriptor: FunctionDescriptor
get() = symbol.descriptor get() = symbol.descriptor
@@ -1,23 +0,0 @@
/*
* Copyright 2010-2016 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.expressions.impl
import org.jetbrains.kotlin.ir.expressions.IrBreakContinue
abstract class IrBreakContinueBase : IrExpressionBase(), IrBreakContinue {
override var label: String? = null
}
@@ -26,7 +26,7 @@ class IrBreakImpl(
override val endOffset: Int, override val endOffset: Int,
override val type: IrType, override val type: IrType,
override var loop: IrLoop, override var loop: IrLoop,
) : IrBreakContinueBase(), IrBreak { ) : IrBreak() {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R = override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitBreak(this, data) visitor.visitBreak(this, data)
} }
@@ -27,7 +27,7 @@ class IrCompositeImpl(
override val endOffset: Int, override val endOffset: Int,
override val type: IrType, override val type: IrType,
override val origin: IrStatementOrigin? = null, override val origin: IrStatementOrigin? = null,
) : IrContainerExpressionBase(), IrComposite { ) : IrComposite() {
constructor( constructor(
startOffset: Int, startOffset: Int,
endOffset: Int, endOffset: Int,
@@ -27,7 +27,7 @@ class IrConstImpl<T>(
override val type: IrType, override val type: IrType,
override val kind: IrConstKind<T>, override val kind: IrConstKind<T>,
override val value: T override val value: T
) : IrExpressionBase(), IrConst<T> { ) : IrConst<T>() {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R = override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitConst(this, data) visitor.visitConst(this, data)
@@ -1,36 +0,0 @@
/*
* Copyright 2010-2016 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.expressions.impl
import org.jetbrains.kotlin.ir.IrStatement
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.IrElementVisitor
import java.util.*
abstract class IrContainerExpressionBase : IrExpressionBase(), IrContainerExpression {
override val statements: MutableList<IrStatement> = ArrayList(2)
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
statements.forEach { it.accept(visitor, data) }
}
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
statements.transform { it.transform(transformer, data) }
}
}
@@ -26,7 +26,7 @@ class IrContinueImpl(
override val endOffset: Int, override val endOffset: Int,
override val type: IrType, override val type: IrType,
override var loop: IrLoop, override var loop: IrLoop,
) : IrBreakContinueBase(), IrContinue { ) : IrContinue() {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R = override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitContinue(this, data) visitor.visitContinue(this, data)
} }
@@ -27,7 +27,7 @@ class IrDoWhileLoopImpl(
override val endOffset: Int, override val endOffset: Int,
override val type: IrType, override val type: IrType,
override val origin: IrStatementOrigin?, override val origin: IrStatementOrigin?,
) : IrLoopBase(), IrDoWhileLoop { ) : IrDoWhileLoop() {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R { override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitDoWhileLoop(this, data) return visitor.visitDoWhileLoop(this, data)
} }
@@ -17,7 +17,7 @@ class IrDynamicMemberExpressionImpl(
override val type: IrType, override val type: IrType,
override val memberName: String, override val memberName: String,
override var receiver: IrExpression override var receiver: IrExpression
) : IrExpressionBase(), IrDynamicMemberExpression { ) : IrDynamicMemberExpression() {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R = override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitDynamicMemberExpression(this, data) visitor.visitDynamicMemberExpression(this, data)
@@ -18,7 +18,7 @@ class IrDynamicOperatorExpressionImpl(
override val endOffset: Int, override val endOffset: Int,
override val type: IrType, override val type: IrType,
override val operator: IrDynamicOperator override val operator: IrDynamicOperator
) : IrExpressionBase(), IrDynamicOperatorExpression { ) : IrDynamicOperatorExpression() {
override lateinit var receiver: IrExpression override lateinit var receiver: IrExpression
override val arguments: MutableList<IrExpression> = SmartList() override val arguments: MutableList<IrExpression> = SmartList()
@@ -28,7 +28,7 @@ class IrErrorCallExpressionImpl(
override val endOffset: Int, override val endOffset: Int,
override val type: IrType, override val type: IrType,
override val description: String override val description: String
) : IrExpressionBase(), IrErrorCallExpression { ) : IrErrorCallExpression() {
override var explicitReceiver: IrExpression? = null override var explicitReceiver: IrExpression? = null
override val arguments: MutableList<IrExpression> = SmartList() override val arguments: MutableList<IrExpression> = SmartList()
@@ -26,7 +26,7 @@ class IrErrorExpressionImpl(
override val endOffset: Int, override val endOffset: Int,
override val type: IrType, override val type: IrType,
override val description: String override val description: String
) : IrExpressionBase(), IrExpressionWithCopy, IrErrorExpression { ) : IrErrorExpression(), IrExpressionWithCopy {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R = override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitErrorExpression(this, data) visitor.visitErrorExpression(this, data)
@@ -1,36 +0,0 @@
/*
* Copyright 2010-2016 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.expressions.impl
import org.jetbrains.kotlin.ir.IrElementBase
import org.jetbrains.kotlin.ir.declarations.IrAttributeContainer
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
abstract class IrExpressionBase : IrElementBase(), IrExpression {
@Suppress("LeakingThis")
override var attributeOwnerId: IrAttributeContainer = this
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
// No children by default
}
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
// No children by default
}
}
@@ -18,7 +18,7 @@ class IrFunctionExpressionImpl(
override val type: IrType, override val type: IrType,
override var function: IrSimpleFunction, override var function: IrSimpleFunction,
override val origin: IrStatementOrigin override val origin: IrStatementOrigin
) : IrExpressionBase(), IrFunctionExpression { ) : IrFunctionExpression() {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R { override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitFunctionExpression(this, data) return visitor.visitFunctionExpression(this, data)
} }
@@ -27,7 +27,7 @@ class IrGetClassImpl(
override val endOffset: Int, override val endOffset: Int,
override val type: IrType, override val type: IrType,
override var argument: IrExpression, override var argument: IrExpression,
) : IrExpressionBase(), IrGetClass { ) : IrGetClass() {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R { override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitGetClass(this, data) return visitor.visitGetClass(this, data)
} }
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.ir.expressions.IrBranch import org.jetbrains.kotlin.ir.expressions.IrBranch
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
import org.jetbrains.kotlin.ir.expressions.IrWhen
import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.kotlin.utils.SmartList
@@ -26,6 +27,6 @@ class IrIfThenElseImpl(
override val endOffset: Int, override val endOffset: Int,
override val type: IrType, override val type: IrType,
override val origin: IrStatementOrigin? = null override val origin: IrStatementOrigin? = null
) : IrWhenBase() { ) : IrWhen() {
override val branches: MutableList<IrBranch> = SmartList() override val branches: MutableList<IrBranch> = SmartList()
} }
@@ -26,7 +26,7 @@ class IrInstanceInitializerCallImpl(
override val endOffset: Int, override val endOffset: Int,
override val classSymbol: IrClassSymbol, override val classSymbol: IrClassSymbol,
override val type: IrType, override val type: IrType,
) : IrExpressionBase(), IrInstanceInitializerCall { ) : IrInstanceInitializerCall() {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R { override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitInstanceInitializerCall(this, data) return visitor.visitInstanceInitializerCall(this, data)
} }
@@ -1,28 +0,0 @@
/*
* Copyright 2010-2016 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.expressions.impl
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrLoop
abstract class IrLoopBase : IrExpressionBase(), IrLoop {
override var label: String? = null
override lateinit var condition: IrExpression
override var body: IrExpression? = null
}
@@ -29,7 +29,7 @@ class IrReturnImpl(
override val type: IrType, override val type: IrType,
override val returnTargetSymbol: IrReturnTargetSymbol, override val returnTargetSymbol: IrReturnTargetSymbol,
override var value: IrExpression override var value: IrExpression
) : IrExpressionBase(), IrReturn { ) : IrReturn() {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R = override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitReturn(this, data) visitor.visitReturn(this, data)
@@ -27,7 +27,7 @@ class IrStringConcatenationImpl(
override val startOffset: Int, override val startOffset: Int,
override val endOffset: Int, override val endOffset: Int,
override val type: IrType override val type: IrType
) : IrExpressionBase(), IrStringConcatenation { ) : IrStringConcatenation() {
constructor( constructor(
startOffset: Int, startOffset: Int,
endOffset: Int, endOffset: Int,
@@ -20,7 +20,7 @@ class IrSuspensionPointImpl(
override var suspensionPointIdParameter: IrVariable, override var suspensionPointIdParameter: IrVariable,
override var result: IrExpression, override var result: IrExpression,
override var resumeResult: IrExpression override var resumeResult: IrExpression
) : IrExpressionBase(), IrSuspensionPoint { ) : IrSuspensionPoint() {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R = override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitSuspensionPoint(this, data) visitor.visitSuspensionPoint(this, data)
@@ -43,8 +43,7 @@ class IrSuspendableExpressionImpl(
override val type: IrType, override val type: IrType,
override var suspensionPointId: IrExpression, override var suspensionPointId: IrExpression,
override var result: IrExpression override var result: IrExpression
) : IrExpressionBase(), IrSuspendableExpression { ) : IrSuspendableExpression() {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R = override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitSuspendableExpression(this, data) visitor.visitSuspendableExpression(this, data)
@@ -27,7 +27,7 @@ class IrThrowImpl(
override val endOffset: Int, override val endOffset: Int,
override val type: IrType, override val type: IrType,
override var value: IrExpression, override var value: IrExpression,
) : IrExpressionBase(), IrThrow { ) : IrThrow() {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R = override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitThrow(this, data) visitor.visitThrow(this, data)
@@ -30,7 +30,7 @@ class IrTryImpl(
override val startOffset: Int, override val startOffset: Int,
override val endOffset: Int, override val endOffset: Int,
override val type: IrType, override val type: IrType,
) : IrExpressionBase(), IrTry { ) : IrTry() {
constructor( constructor(
startOffset: Int, startOffset: Int,
endOffset: Int, endOffset: Int,
@@ -32,7 +32,7 @@ class IrTypeOperatorCallImpl(
override val operator: IrTypeOperator, override val operator: IrTypeOperator,
override val typeOperand: IrType, override val typeOperand: IrType,
override var argument: IrExpression, override var argument: IrExpression,
) : IrExpressionBase(), IrTypeOperatorCall { ) : IrTypeOperatorCall() {
override val typeOperandClassifier: IrClassifierSymbol override val typeOperandClassifier: IrClassifierSymbol
get() = typeOperand.classifierOrFail get() = typeOperand.classifierOrFail
@@ -28,7 +28,7 @@ class IrVarargImpl(
override val endOffset: Int, override val endOffset: Int,
override val type: IrType, override val type: IrType,
override val varargElementType: IrType override val varargElementType: IrType
) : IrExpressionBase(), IrVararg { ) : IrVararg() {
constructor( constructor(
startOffset: Int, startOffset: Int,
endOffset: Int, endOffset: Int,
@@ -23,27 +23,12 @@ 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 java.util.*
abstract class IrWhenBase : IrExpressionBase(), IrWhen {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitWhen(this, data)
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
branches.forEach { it.accept(visitor, data) }
}
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
branches.forEachIndexed { i, irBranch ->
branches[i] = irBranch.transform(transformer, data)
}
}
}
class IrWhenImpl( class IrWhenImpl(
override val startOffset: Int, override val startOffset: Int,
override val endOffset: Int, override val endOffset: Int,
override val type: IrType, override val type: IrType,
override val origin: IrStatementOrigin? = null override val origin: IrStatementOrigin? = null
) : IrWhenBase() { ) : IrWhen() {
constructor( constructor(
startOffset: Int, startOffset: Int,
endOffset: Int, endOffset: Int,
@@ -27,7 +27,7 @@ class IrWhileLoopImpl(
override val endOffset: Int, override val endOffset: Int,
override val type: IrType, override val type: IrType,
override val origin: IrStatementOrigin?, override val origin: IrStatementOrigin?,
) : IrLoopBase(), IrWhileLoop { ) : IrWhileLoop() {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R { override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitWhileLoop(this, data) return visitor.visitWhileLoop(this, data)
} }