IR: minor, extract declarations from IrElement.kt
This commit is contained in:
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.ScriptDescriptor
|
import org.jetbrains.kotlin.descriptors.ScriptDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
import org.jetbrains.kotlin.ir.assertCast
|
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.IrFunctionBuilder
|
import org.jetbrains.kotlin.ir.builders.declarations.IrFunctionBuilder
|
||||||
import org.jetbrains.kotlin.ir.declarations.DescriptorMetadataSource
|
import org.jetbrains.kotlin.ir.declarations.DescriptorMetadataSource
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||||
@@ -197,7 +196,7 @@ class ScriptGenerator(declarationGenerator: DeclarationGenerator) : DeclarationG
|
|||||||
context.irBuiltIns.unitType, IrStatementOrigin.DESTRUCTURING_DECLARATION
|
context.irBuiltIns.unitType, IrStatementOrigin.DESTRUCTURING_DECLARATION
|
||||||
)
|
)
|
||||||
val ktInitializer = d.initializer!!
|
val ktInitializer = d.initializer!!
|
||||||
val initializerExpr = ktInitializer.deparenthesize().accept(statementGenerator, null).assertCast<IrExpression>()
|
val initializerExpr = ktInitializer.deparenthesize().accept(statementGenerator, null) as IrExpression
|
||||||
val containerValue =
|
val containerValue =
|
||||||
statementGenerator.scope.createTemporaryVariableInBlock(context, initializerExpr, irBlock, "container")
|
statementGenerator.scope.createTemporaryVariableInBlock(context, initializerExpr, irBlock, "container")
|
||||||
|
|
||||||
|
|||||||
@@ -1,43 +1,24 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* 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
|
package org.jetbrains.kotlin.ir
|
||||||
|
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
|
|
||||||
interface IrElement {
|
interface IrElement {
|
||||||
val startOffset: Int
|
val startOffset: Int
|
||||||
|
|
||||||
val endOffset: Int
|
val endOffset: Int
|
||||||
|
|
||||||
fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R
|
fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R
|
||||||
|
|
||||||
fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D): Unit
|
|
||||||
|
|
||||||
fun <D> transform(transformer: IrElementTransformer<D>, data: D): IrElement =
|
fun <D> transform(transformer: IrElementTransformer<D>, data: D): IrElement =
|
||||||
accept(transformer, data)
|
accept(transformer, data)
|
||||||
|
|
||||||
fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D): Unit
|
fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D)
|
||||||
|
|
||||||
|
fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IrStatement : IrElement
|
|
||||||
|
|
||||||
fun IrStatement.transformStatement(transformer: IrElementTransformerVoid): IrStatement =
|
|
||||||
transform(transformer, null) as IrStatement
|
|
||||||
|
|
||||||
inline fun <reified T : IrElement> IrElement.assertCast(): T =
|
|
||||||
if (this is T) this else throw AssertionError("Expected ${T::class.simpleName}: $this")
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.ir
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||||
|
|
||||||
|
fun IrStatement.transformStatement(transformer: IrElementTransformerVoid): IrStatement =
|
||||||
|
transform(transformer, null) as IrStatement
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.ir
|
||||||
|
|
||||||
|
interface IrStatement : IrElement
|
||||||
Reference in New Issue
Block a user