From 2815bb88c279e65770574c0b4d451e80026f6677 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 23 Apr 2020 18:58:38 +0200 Subject: [PATCH] Remove unnecessary dependency of 'fir2ir' on 'ir.backend.common' Move some lookup utilities which are used in `OperatorExpressionGenerator`, to 'ir.tree'. --- compiler/fir/fir2ir/build.gradle.kts | 8 +-- .../kotlin/ir/util/IrBackendUtils.kt | 49 ------------------- .../kotlin/ir/util/AdditionalIrUtils.kt | 28 +++++++++++ 3 files changed, 29 insertions(+), 56 deletions(-) delete mode 100644 compiler/ir/backend.common/src/org/jetbrains/kotlin/ir/util/IrBackendUtils.kt diff --git a/compiler/fir/fir2ir/build.gradle.kts b/compiler/fir/fir2ir/build.gradle.kts index 3c2024efc8c..4605fa6403c 100644 --- a/compiler/fir/fir2ir/build.gradle.kts +++ b/compiler/fir/fir2ir/build.gradle.kts @@ -1,8 +1,3 @@ -/* - * Copyright 2000-2018 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. - */ - plugins { kotlin("jvm") id("jps-compatible") @@ -15,7 +10,6 @@ dependencies { compileOnly(project(":compiler:fir:tree")) compileOnly(project(":compiler:ir.tree")) compileOnly(project(":compiler:ir.psi2ir")) - compileOnly(project(":compiler:ir.backend.common")) compileOnly(intellijCoreDep()) { includeJars("intellij-core") } @@ -48,4 +42,4 @@ projectTest(parallel = true) { workingDir = rootDir } -testsJar() \ No newline at end of file +testsJar() diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/ir/util/IrBackendUtils.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/ir/util/IrBackendUtils.kt deleted file mode 100644 index f92588906ae..00000000000 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/ir/util/IrBackendUtils.kt +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.util - -import org.jetbrains.kotlin.ir.declarations.IrClass -import org.jetbrains.kotlin.ir.declarations.IrProperty -import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction -import org.jetbrains.kotlin.ir.symbols.IrClassSymbol -import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol - -private fun IrClass.getPropertyDeclaration(name: String): IrProperty? { - val properties = declarations.filterIsInstance().filter { it.name.asString() == name } - if (properties.size > 1) { - error( - "More than one property with name $name in class $fqNameWhenAvailable:\n" + - properties.joinToString("\n", transform = IrProperty::render) - ) - } - return properties.firstOrNull() -} - -private fun IrClass.getSimpleFunction(name: String): IrSimpleFunctionSymbol? = - findDeclaration { it.name.asString() == name }?.symbol - -fun IrClass.getPropertyGetter(name: String): IrSimpleFunctionSymbol? = - getPropertyDeclaration(name)?.getter?.symbol - ?: getSimpleFunction("").also { assert(it?.owner?.correspondingPropertySymbol?.owner?.name?.asString() == name) } - -fun IrClass.getPropertySetter(name: String): IrSimpleFunctionSymbol? = - getPropertyDeclaration(name)?.setter?.symbol - ?: getSimpleFunction("").also { assert(it?.owner?.correspondingPropertySymbol?.owner?.name?.asString() == name) } - -fun IrClassSymbol.getSimpleFunction(name: String): IrSimpleFunctionSymbol? = owner.getSimpleFunction(name) -fun IrClassSymbol.getPropertyGetter(name: String): IrSimpleFunctionSymbol? = owner.getPropertyGetter(name) -fun IrClassSymbol.getPropertySetter(name: String): IrSimpleFunctionSymbol? = owner.getPropertySetter(name) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/AdditionalIrUtils.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/AdditionalIrUtils.kt index 394f7330e5b..f173c213054 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/AdditionalIrUtils.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/AdditionalIrUtils.kt @@ -12,6 +12,8 @@ import org.jetbrains.kotlin.ir.SourceRangeInfo import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.IrConstructorCall +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name @@ -217,3 +219,29 @@ class NaiveSourceBasedFileEntryImpl(override val name: String, val lineStartOffs } } + +private fun IrClass.getPropertyDeclaration(name: String): IrProperty? { + val properties = declarations.filterIsInstance().filter { it.name.asString() == name } + if (properties.size > 1) { + error( + "More than one property with name $name in class $fqNameWhenAvailable:\n" + + properties.joinToString("\n", transform = IrProperty::render) + ) + } + return properties.firstOrNull() +} + +private fun IrClass.getSimpleFunction(name: String): IrSimpleFunctionSymbol? = + findDeclaration { it.name.asString() == name }?.symbol + +fun IrClass.getPropertyGetter(name: String): IrSimpleFunctionSymbol? = + getPropertyDeclaration(name)?.getter?.symbol + ?: getSimpleFunction("").also { assert(it?.owner?.correspondingPropertySymbol?.owner?.name?.asString() == name) } + +fun IrClass.getPropertySetter(name: String): IrSimpleFunctionSymbol? = + getPropertyDeclaration(name)?.setter?.symbol + ?: getSimpleFunction("").also { assert(it?.owner?.correspondingPropertySymbol?.owner?.name?.asString() == name) } + +fun IrClassSymbol.getSimpleFunction(name: String): IrSimpleFunctionSymbol? = owner.getSimpleFunction(name) +fun IrClassSymbol.getPropertyGetter(name: String): IrSimpleFunctionSymbol? = owner.getPropertyGetter(name) +fun IrClassSymbol.getPropertySetter(name: String): IrSimpleFunctionSymbol? = owner.getPropertySetter(name)