IR: remove unused code, cleanup
This commit is contained in:
@@ -28,8 +28,3 @@ fun <E> MutableList<E>.push(element: E) = this.add(element)
|
||||
fun <E> MutableList<E>.pop() = this.removeAt(size - 1)
|
||||
|
||||
fun <E> MutableList<E>.peek(): E? = if (size == 0) null else this[size - 1]
|
||||
|
||||
fun <T: Any> T.onlyIf(condition: T.()->Boolean, then: (T)->Unit): T {
|
||||
if (this.condition()) then(this)
|
||||
return this
|
||||
}
|
||||
|
||||
+4
-30
@@ -16,25 +16,16 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
|
||||
import org.jetbrains.kotlin.builtins.getFunctionalClassKind
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.replace
|
||||
|
||||
val String.synthesizedName: Name get() = Name.identifier(this.synthesizedString)
|
||||
|
||||
val String.synthesizedString: String get() = "\$$this"
|
||||
|
||||
val DeclarationDescriptor.propertyIfAccessor: DeclarationDescriptor
|
||||
get() = if (this is PropertyAccessorDescriptor)
|
||||
this.correspondingProperty
|
||||
else this
|
||||
|
||||
val CallableDescriptor.isSuspend: Boolean
|
||||
get() = this is FunctionDescriptor && isSuspend
|
||||
|
||||
@@ -69,20 +60,3 @@ val CallableDescriptor.explicitParameters: List<ParameterDescriptor>
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Used in Kotlin/Native
|
||||
@Suppress("unused")
|
||||
fun FunctionDescriptor.substitute(vararg types: KotlinType): FunctionDescriptor {
|
||||
val typeSubstitutor = TypeSubstitutor.create(
|
||||
typeParameters
|
||||
.withIndex()
|
||||
.associateBy({ it.value.typeConstructor }, { TypeProjectionImpl(types[it.index]) })
|
||||
)
|
||||
return substitute(typeSubstitutor)!!
|
||||
}
|
||||
|
||||
val KotlinType.isFunctionOrKFunctionType: Boolean
|
||||
get() {
|
||||
val kind = constructor.declarationDescriptor?.getFunctionalClassKind()
|
||||
return kind == FunctionClassDescriptor.Kind.Function || kind == FunctionClassDescriptor.Kind.KFunction
|
||||
}
|
||||
|
||||
+1
-8
@@ -6,15 +6,14 @@
|
||||
package org.jetbrains.kotlin.backend.common.ir
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.lower.VariableRemapper
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnableBlockImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrReturnTargetSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrReturnableBlockSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols
|
||||
import org.jetbrains.kotlin.ir.util.isVararg
|
||||
import org.jetbrains.kotlin.ir.util.statements
|
||||
|
||||
@@ -45,12 +44,6 @@ private fun createParameterMapping(source: IrFunction, target: IrFunction): Map<
|
||||
return sourceParameters.zip(targetParameters).toMap()
|
||||
}
|
||||
|
||||
fun IrFunction.copyBodyTo(target: IrFunction): IrBody? =
|
||||
copyBodyTo(target, createParameterMapping(this, target))
|
||||
|
||||
fun IrFunction.copyBodyTo(target: IrFunction, arguments: Map<IrValueParameter, IrValueDeclaration>): IrBody? =
|
||||
body?.deepCopyWithSymbols(target)?.move(this, target, target.symbol, arguments)
|
||||
|
||||
fun IrFunction.moveBodyTo(target: IrFunction): IrBody? =
|
||||
moveBodyTo(target, createParameterMapping(this, target))
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import java.io.StringWriter
|
||||
|
||||
fun ir2string(ir: IrElement?): String = ir?.render() ?: ""
|
||||
|
||||
// NB: this function is used in native
|
||||
@Suppress("unused") // Used in kotlin-native
|
||||
fun ir2stringWhole(ir: IrElement?): String {
|
||||
val strWriter = StringWriter()
|
||||
ir?.accept(DumpIrTreeVisitor(strWriter), "")
|
||||
@@ -107,15 +107,6 @@ fun IrReturnTarget.returnType(context: CommonBackendContext) =
|
||||
val IrClass.isFinalClass: Boolean
|
||||
get() = modality == Modality.FINAL && kind != ClassKind.ENUM_CLASS
|
||||
|
||||
// For an annotation, get the annotation class.
|
||||
fun IrCall.getAnnotationClass(): IrClass {
|
||||
val callable = symbol.owner
|
||||
assert(callable is IrConstructor) { "Constructor call expected, got ${ir2string(this)}" }
|
||||
val annotationClass = callable.parentAsClass
|
||||
assert(annotationClass.isAnnotationClass) { "Annotation class expected, got ${ir2string(annotationClass)}" }
|
||||
return annotationClass
|
||||
}
|
||||
|
||||
val IrTypeParametersContainer.classIfConstructor get() = if (this is IrConstructor) parentAsClass else this
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
@@ -348,10 +339,6 @@ fun IrDeclarationContainer.addChild(declaration: IrDeclaration) {
|
||||
declaration.setDeclarationsParent(this)
|
||||
}
|
||||
|
||||
fun IrDeclarationContainer.addChildren(declarations: List<IrDeclaration>) {
|
||||
declarations.forEach { this.addChild(it) }
|
||||
}
|
||||
|
||||
fun <T : IrElement> T.setDeclarationsParent(parent: IrDeclarationParent): T {
|
||||
accept(SetDeclarationsParentVisitor, parent)
|
||||
return this
|
||||
|
||||
+1
@@ -15,6 +15,7 @@ val IrDeclaration.isExpect
|
||||
// The original isExpect represents what user has written.
|
||||
// This predicate means "there can possibly exist an 'actual' for the given declaration".
|
||||
// Shouldn't it be incorporated to descriptor -> ir declaration psi2ir translation phase?
|
||||
@Suppress("unused")
|
||||
val IrDeclaration.isProperExpect: Boolean
|
||||
get() = this is IrClass && isExpect ||
|
||||
this is IrFunction && isExpect ||
|
||||
|
||||
+1
-1
@@ -242,7 +242,7 @@ class InlineClassLowering(val context: CommonBackendContext) {
|
||||
val klass = function.parentAsClass
|
||||
return when {
|
||||
!klass.isInline -> expression
|
||||
function.isPrimary -> irConstructorCall(expression, function)
|
||||
function.isPrimary -> irConstructorCall(expression, function.symbol)
|
||||
else -> irCall(expression, getOrCreateStaticMethod(function))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@ package org.jetbrains.kotlin.ir.util
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.FQ_NAMES
|
||||
import org.jetbrains.kotlin.builtins.UnsignedTypes
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationWithName
|
||||
import org.jetbrains.kotlin.ir.declarations.IrPackageFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
@@ -18,7 +21,6 @@ import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.DFS
|
||||
import org.jetbrains.kotlin.ir.types.isNullable as irTreeTypeUtils_isNullable
|
||||
|
||||
val kotlinPackageFqn = FqName.fromSegments(listOf("kotlin"))
|
||||
private val kotlinReflectionPackageFqn = kotlinPackageFqn.child(Name.identifier("reflect"))
|
||||
@@ -31,7 +33,6 @@ fun IrType.isKSuspendFunction(): Boolean = classifierOrNull?.isClassWithNamePref
|
||||
|
||||
fun IrClassifierSymbol.isFunction(): Boolean = this.isClassWithNamePrefix("Function", kotlinPackageFqn)
|
||||
fun IrClassifierSymbol.isKFunction(): Boolean = this.isClassWithNamePrefix("KFunction", kotlinReflectionPackageFqn)
|
||||
fun IrClassifierSymbol.isSuspendFunction(): Boolean = this.isClassWithNamePrefix("SuspendFunction", kotlinCoroutinesPackageFqn)
|
||||
fun IrClassifierSymbol.isKSuspendFunction(): Boolean = this.isClassWithNamePrefix("KSuspendFunction", kotlinReflectionPackageFqn)
|
||||
|
||||
private fun IrClassifierSymbol.isClassWithNamePrefix(prefix: String, packageFqName: FqName): Boolean {
|
||||
@@ -56,19 +57,8 @@ fun IrType.isFunctionOrKFunction() = isFunction() || isKFunction()
|
||||
|
||||
fun IrType.isSuspendFunctionOrKFunction() = isSuspendFunction() || isKSuspendFunction()
|
||||
|
||||
|
||||
@Deprecated(
|
||||
"Use org.jetbrains.kotlin.ir.types.isNullable instead.",
|
||||
ReplaceWith("this.isNullable()", "org.jetbrains.kotlin.ir.types.isNullable")
|
||||
)
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
@kotlin.internal.LowPriorityInOverloadResolution
|
||||
fun IrType.isNullable(): Boolean = this.irTreeTypeUtils_isNullable()
|
||||
|
||||
fun IrType.isThrowable(): Boolean = isTypeFromKotlinPackage { name -> name.asString() == "Throwable" }
|
||||
|
||||
fun IrType.isThrowableTypeOrSubtype(): Boolean = DFS.ifAny(listOf(this), IrType::superTypes, IrType::isThrowable)
|
||||
|
||||
fun IrType.isUnsigned(): Boolean = isTypeFromKotlinPackage { name -> UnsignedTypes.isShortNameOfUnsignedType(name) }
|
||||
|
||||
private inline fun IrType.isTypeFromKotlinPackage(namePredicate: (Name) -> Boolean): Boolean {
|
||||
|
||||
-71
@@ -1,71 +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.psi2ir.generators
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyGetterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertySetterDescriptor
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrSyntheticPropertyAccessorDescriptor.Kind.MEMBER_PROPERTY
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrSyntheticPropertyAccessorDescriptor.Kind.STATIC_PROPERTY
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrSyntheticPropertyGetterDescriptorImpl
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrSyntheticPropertySetterDescriptorImpl
|
||||
import java.lang.AssertionError
|
||||
import java.util.*
|
||||
|
||||
|
||||
class SyntheticDescriptorsFactory {
|
||||
private val propertyGetters = HashMap<PropertyDescriptor, PropertyGetterDescriptor>()
|
||||
|
||||
private fun generateGetter(property: PropertyDescriptor): PropertyGetterDescriptor {
|
||||
return when {
|
||||
isStaticPropertyInClass(property) ->
|
||||
IrSyntheticPropertyGetterDescriptorImpl(property, STATIC_PROPERTY)
|
||||
isPropertyInClass(property) ->
|
||||
IrSyntheticPropertyGetterDescriptorImpl(property, MEMBER_PROPERTY)
|
||||
else ->
|
||||
throw AssertionError("Don't know how to create synthetic getter for $property")
|
||||
}
|
||||
}
|
||||
|
||||
private val propertySetters = HashMap<PropertyDescriptor, PropertySetterDescriptor>()
|
||||
|
||||
private fun generateSetter(property: PropertyDescriptor): PropertySetterDescriptor {
|
||||
return when {
|
||||
isStaticPropertyInClass(property) ->
|
||||
IrSyntheticPropertySetterDescriptorImpl(property, STATIC_PROPERTY)
|
||||
isPropertyInClass(property) ->
|
||||
IrSyntheticPropertySetterDescriptorImpl(property, MEMBER_PROPERTY)
|
||||
else ->
|
||||
throw AssertionError("Don't know how to create synthetic setter for $property")
|
||||
}
|
||||
}
|
||||
|
||||
private fun isStaticPropertyInClass(propertyDescriptor: PropertyDescriptor): Boolean =
|
||||
propertyDescriptor.containingDeclaration is ClassDescriptor &&
|
||||
propertyDescriptor.dispatchReceiverParameter == null &&
|
||||
propertyDescriptor.extensionReceiverParameter == null
|
||||
|
||||
private fun isPropertyInClass(propertyDescriptor: PropertyDescriptor): Boolean =
|
||||
propertyDescriptor.containingDeclaration is ClassDescriptor
|
||||
|
||||
fun getOrCreatePropertyGetter(propertyDescriptor: PropertyDescriptor): PropertyGetterDescriptor =
|
||||
propertyGetters.getOrPut(propertyDescriptor) { generateGetter(propertyDescriptor) }
|
||||
|
||||
fun getOrCreatePropertySetter(propertyDescriptor: PropertyDescriptor): PropertySetterDescriptor =
|
||||
propertySetters.getOrPut(propertyDescriptor) { generateSetter(propertyDescriptor) }
|
||||
}
|
||||
@@ -80,7 +80,7 @@ class IrBuiltIns(
|
||||
val valueParameterSymbol = IrValueParameterSymbolImpl(valueParameterDescriptor)
|
||||
irFactory.createValueParameter(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, BUILTIN_OPERATOR, valueParameterSymbol, Name.identifier("arg$i"), i,
|
||||
valueParameterType, null, false, false
|
||||
valueParameterType, null, isCrossinline = false, isNoinline = false
|
||||
).apply {
|
||||
parent = operator
|
||||
}
|
||||
@@ -120,7 +120,8 @@ class IrBuiltIns(
|
||||
|
||||
valueParameterDescriptor = ValueParameterDescriptorImpl(
|
||||
this, null, 0, Annotations.EMPTY, Name.identifier("arg0"), valueKotlinType,
|
||||
false, false, false, null, SourceElement.NO_SOURCE
|
||||
declaresDefaultValue = false, isCrossinline = false, isNoinline = false, varargElementType = null,
|
||||
source = SourceElement.NO_SOURCE
|
||||
)
|
||||
|
||||
returnKotlinType = typeParameterDescriptor.typeConstructor.makeNonNullType()
|
||||
@@ -184,7 +185,6 @@ class IrBuiltIns(
|
||||
associate { it.classifierOrFail to defineComparisonOperator(name, it) }
|
||||
|
||||
val any = builtIns.anyType
|
||||
val anyN = builtIns.nullableAnyType
|
||||
val anyType = any.toIrType()
|
||||
val anyClass = builtIns.any.toIrSymbol()
|
||||
val anyNType = anyType.withHasQuestionMark(true)
|
||||
@@ -226,7 +226,6 @@ class IrBuiltIns(
|
||||
val doubleClass = builtIns.double.toIrSymbol()
|
||||
|
||||
val nothing = builtIns.nothingType
|
||||
val nothingN = builtIns.nullableNothingType
|
||||
val nothingType = nothing.toIrType()
|
||||
val nothingClass = builtIns.nothing.toIrSymbol()
|
||||
val nothingNType = nothingType.withHasQuestionMark(true)
|
||||
@@ -321,9 +320,6 @@ class IrBuiltIns(
|
||||
fun function(n: Int): IrClassSymbol = functionFactory.functionN(n).symbol
|
||||
fun suspendFunction(n: Int): IrClassSymbol = functionFactory.suspendFunctionN(n).symbol
|
||||
|
||||
fun kFunction(n: Int): IrClassSymbol = functionFactory.kFunctionN(n).symbol
|
||||
fun kSuspendFunction(n: Int): IrClassSymbol = functionFactory.kSuspendFunctionN(n).symbol
|
||||
|
||||
companion object {
|
||||
val KOTLIN_INTERNAL_IR_FQN = FqName("kotlin.internal.ir")
|
||||
val BUILTIN_OPERATOR = object : IrDeclarationOriginImpl("OPERATOR") {}
|
||||
|
||||
-79
@@ -1,79 +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.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertyGetterDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertySetterDescriptorImpl
|
||||
|
||||
|
||||
interface IrSyntheticPropertyAccessorDescriptor : PropertyAccessorDescriptor {
|
||||
enum class Kind {
|
||||
STATIC_PROPERTY,
|
||||
MEMBER_PROPERTY
|
||||
}
|
||||
|
||||
val kind: Kind
|
||||
}
|
||||
|
||||
interface IrSyntheticPropertyGetterDescriptor : IrSyntheticPropertyAccessorDescriptor
|
||||
|
||||
interface IrSyntheticPropertySetterDescriptor : IrSyntheticPropertyAccessorDescriptor
|
||||
|
||||
class IrSyntheticPropertyGetterDescriptorImpl(
|
||||
correspondingProperty: PropertyDescriptor,
|
||||
override val kind: IrSyntheticPropertyAccessorDescriptor.Kind
|
||||
) : PropertyGetterDescriptorImpl(
|
||||
correspondingProperty,
|
||||
Annotations.EMPTY,
|
||||
Modality.FINAL,
|
||||
correspondingProperty.visibility,
|
||||
true, // isDefault
|
||||
false, // isExternal
|
||||
false, // isInline
|
||||
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
||||
null,
|
||||
correspondingProperty.source
|
||||
), IrSyntheticPropertyGetterDescriptor {
|
||||
init {
|
||||
initialize(correspondingProperty.type)
|
||||
}
|
||||
}
|
||||
|
||||
class IrSyntheticPropertySetterDescriptorImpl(
|
||||
correspondingProperty: PropertyDescriptor,
|
||||
override val kind: IrSyntheticPropertyAccessorDescriptor.Kind
|
||||
) : PropertySetterDescriptorImpl(
|
||||
correspondingProperty,
|
||||
Annotations.EMPTY,
|
||||
Modality.FINAL,
|
||||
correspondingProperty.visibility,
|
||||
true, // isDefault
|
||||
false, // isExternal
|
||||
false, // isInline
|
||||
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
||||
null,
|
||||
correspondingProperty.source
|
||||
), IrSyntheticPropertySetterDescriptor {
|
||||
init {
|
||||
initializeDefault()
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,8 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.symbols
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
@@ -54,4 +59,4 @@ fun wrapInDelegatedSymbol(delegate: IrSymbol) = when(delegate) {
|
||||
is IrPropertySymbol -> IrDelegatingPropertySymbolImpl(delegate)
|
||||
is IrTypeAliasSymbol -> IrDelegatingTypeAliasSymbolImpl(delegate)
|
||||
else -> error("Unexpected symbol to delegate to: $delegate")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,8 @@ package org.jetbrains.kotlin.ir.symbols
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrScript
|
||||
import org.jetbrains.kotlin.ir.expressions.IrReturnableBlock
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.ir.util.IrSymbolVisitor
|
||||
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeParameterMarker
|
||||
|
||||
@@ -37,8 +35,6 @@ interface IrSymbol {
|
||||
val signature: IdSignature
|
||||
|
||||
val isPublicApi: Boolean
|
||||
|
||||
fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R
|
||||
}
|
||||
|
||||
interface IrBindableSymbol<out D : DeclarationDescriptor, B : IrSymbolOwner> : IrSymbol {
|
||||
@@ -53,161 +49,59 @@ interface IrBindableSymbol<out D : DeclarationDescriptor, B : IrSymbolOwner> : I
|
||||
interface IrPackageFragmentSymbol : IrSymbol {
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
override val descriptor: PackageFragmentDescriptor
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitPackageFragmentSymbol(this, data)
|
||||
}
|
||||
|
||||
interface IrFileSymbol :
|
||||
IrPackageFragmentSymbol, IrBindableSymbol<PackageFragmentDescriptor, IrFile> {
|
||||
interface IrFileSymbol : IrPackageFragmentSymbol, IrBindableSymbol<PackageFragmentDescriptor, IrFile>
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitFileSymbol(this, data)
|
||||
}
|
||||
interface IrExternalPackageFragmentSymbol : IrPackageFragmentSymbol, IrBindableSymbol<PackageFragmentDescriptor, IrExternalPackageFragment>
|
||||
|
||||
interface IrExternalPackageFragmentSymbol :
|
||||
IrPackageFragmentSymbol, IrBindableSymbol<PackageFragmentDescriptor, IrExternalPackageFragment> {
|
||||
interface IrAnonymousInitializerSymbol : IrBindableSymbol<ClassDescriptor, IrAnonymousInitializer>
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitExternalPackageFragmentSymbol(this, data)
|
||||
}
|
||||
interface IrEnumEntrySymbol : IrBindableSymbol<ClassDescriptor, IrEnumEntry>
|
||||
|
||||
interface IrAnonymousInitializerSymbol :
|
||||
IrBindableSymbol<ClassDescriptor, IrAnonymousInitializer> {
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitAnonymousInitializerSymbol(this, data)
|
||||
}
|
||||
|
||||
interface IrEnumEntrySymbol :
|
||||
IrBindableSymbol<ClassDescriptor, IrEnumEntry> {
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitEnumEntrySymbol(this, data)
|
||||
}
|
||||
|
||||
interface IrFieldSymbol :
|
||||
IrBindableSymbol<PropertyDescriptor, IrField> {
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitFieldSymbol(this, data)
|
||||
}
|
||||
|
||||
interface IrClassifierSymbol :
|
||||
IrSymbol, TypeConstructorMarker {
|
||||
interface IrFieldSymbol : IrBindableSymbol<PropertyDescriptor, IrField>
|
||||
|
||||
interface IrClassifierSymbol : IrSymbol, TypeConstructorMarker {
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
override val descriptor: ClassifierDescriptor
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitClassifierSymbol(this, data)
|
||||
}
|
||||
|
||||
interface IrClassSymbol :
|
||||
IrClassifierSymbol, IrBindableSymbol<ClassDescriptor, IrClass> {
|
||||
interface IrClassSymbol : IrClassifierSymbol, IrBindableSymbol<ClassDescriptor, IrClass>
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitClassSymbol(this, data)
|
||||
}
|
||||
interface IrScriptSymbol : IrSymbol, IrBindableSymbol<ScriptDescriptor, IrScript>
|
||||
|
||||
interface IrScriptSymbol :
|
||||
IrSymbol, IrBindableSymbol<ScriptDescriptor, IrScript> {
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitSymbol(this, data)
|
||||
}
|
||||
|
||||
interface IrTypeParameterSymbol :
|
||||
IrClassifierSymbol, IrBindableSymbol<TypeParameterDescriptor, IrTypeParameter>, TypeParameterMarker {
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitTypeParameterSymbol(this, data)
|
||||
}
|
||||
|
||||
interface IrValueSymbol :
|
||||
IrSymbol {
|
||||
interface IrTypeParameterSymbol : IrClassifierSymbol, IrBindableSymbol<TypeParameterDescriptor, IrTypeParameter>, TypeParameterMarker
|
||||
|
||||
interface IrValueSymbol : IrSymbol {
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
override val descriptor: ValueDescriptor
|
||||
|
||||
override val owner: IrValueDeclaration
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitValueSymbol(this, data)
|
||||
}
|
||||
|
||||
interface IrValueParameterSymbol :
|
||||
IrValueSymbol, IrBindableSymbol<ParameterDescriptor, IrValueParameter> {
|
||||
interface IrValueParameterSymbol : IrValueSymbol, IrBindableSymbol<ParameterDescriptor, IrValueParameter>
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitValueParameterSymbol(this, data)
|
||||
}
|
||||
|
||||
interface IrVariableSymbol :
|
||||
IrValueSymbol, IrBindableSymbol<VariableDescriptor, IrVariable> {
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitVariableSymbol(this, data)
|
||||
}
|
||||
|
||||
interface IrReturnTargetSymbol :
|
||||
IrSymbol {
|
||||
interface IrVariableSymbol : IrValueSymbol, IrBindableSymbol<VariableDescriptor, IrVariable>
|
||||
|
||||
interface IrReturnTargetSymbol : IrSymbol {
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
override val descriptor: FunctionDescriptor
|
||||
|
||||
override val owner: IrReturnTarget
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitReturnTargetSymbol(this, data)
|
||||
}
|
||||
|
||||
interface IrFunctionSymbol :
|
||||
IrReturnTargetSymbol {
|
||||
|
||||
interface IrFunctionSymbol : IrReturnTargetSymbol {
|
||||
override val owner: IrFunction
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitFunctionSymbol(this, data)
|
||||
}
|
||||
|
||||
interface IrConstructorSymbol :
|
||||
IrFunctionSymbol, IrBindableSymbol<ClassConstructorDescriptor, IrConstructor> {
|
||||
interface IrConstructorSymbol : IrFunctionSymbol, IrBindableSymbol<ClassConstructorDescriptor, IrConstructor>
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitConstructorSymbol(this, data)
|
||||
}
|
||||
interface IrSimpleFunctionSymbol :
|
||||
IrFunctionSymbol, IrBindableSymbol<FunctionDescriptor, IrSimpleFunction> {
|
||||
interface IrSimpleFunctionSymbol : IrFunctionSymbol, IrBindableSymbol<FunctionDescriptor, IrSimpleFunction>
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitSimpleFunctionSymbol(this, data)
|
||||
}
|
||||
interface IrReturnableBlockSymbol : IrReturnTargetSymbol, IrBindableSymbol<FunctionDescriptor, IrReturnableBlock>
|
||||
|
||||
interface IrReturnableBlockSymbol :
|
||||
IrReturnTargetSymbol, IrBindableSymbol<FunctionDescriptor, IrReturnableBlock> {
|
||||
interface IrPropertySymbol : IrBindableSymbol<PropertyDescriptor, IrProperty>
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitReturnableBlockSymbol(this, data)
|
||||
}
|
||||
interface IrLocalDelegatedPropertySymbol : IrBindableSymbol<VariableDescriptorWithAccessors, IrLocalDelegatedProperty>
|
||||
|
||||
interface IrPropertySymbol :
|
||||
IrBindableSymbol<PropertyDescriptor, IrProperty> {
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitPropertySymbol(this, data)
|
||||
}
|
||||
|
||||
interface IrLocalDelegatedPropertySymbol :
|
||||
IrBindableSymbol<VariableDescriptorWithAccessors, IrLocalDelegatedProperty> {
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitLocalDelegatedPropertySymbol(this, data)
|
||||
}
|
||||
|
||||
interface IrTypeAliasSymbol :
|
||||
IrBindableSymbol<TypeAliasDescriptor, IrTypeAlias> {
|
||||
|
||||
override fun <D, R> accept(visitor: IrSymbolVisitor<R, D>, data: D): R =
|
||||
visitor.visitTypeAliasSymbol(this, data)
|
||||
}
|
||||
interface IrTypeAliasSymbol : IrBindableSymbol<TypeAliasDescriptor, IrTypeAlias>
|
||||
|
||||
+12
-22
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.ir.symbols.impl
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrReturnableBlock
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
@@ -90,48 +90,40 @@ class IrExternalPackageFragmentSymbolImpl(descriptor: PackageFragmentDescriptor)
|
||||
class IrAnonymousInitializerSymbolImpl(descriptor: ClassDescriptor) :
|
||||
IrBindableSymbolBase<ClassDescriptor, IrAnonymousInitializer>(descriptor),
|
||||
IrAnonymousInitializerSymbol {
|
||||
constructor(irClassSymbol: IrClassSymbol) : this(irClassSymbol.descriptor) {}
|
||||
constructor(irClassSymbol: IrClassSymbol) : this(irClassSymbol.descriptor)
|
||||
}
|
||||
|
||||
class IrClassSymbolImpl(descriptor: ClassDescriptor) :
|
||||
IrBindableSymbolBase<ClassDescriptor, IrClass>(descriptor),
|
||||
IrClassSymbol {
|
||||
}
|
||||
IrClassSymbol
|
||||
|
||||
class IrEnumEntrySymbolImpl(descriptor: ClassDescriptor) :
|
||||
IrBindableSymbolBase<ClassDescriptor, IrEnumEntry>(descriptor),
|
||||
IrEnumEntrySymbol {
|
||||
}
|
||||
IrEnumEntrySymbol
|
||||
|
||||
class IrFieldSymbolImpl(descriptor: PropertyDescriptor) :
|
||||
IrBindableSymbolBase<PropertyDescriptor, IrField>(descriptor),
|
||||
IrFieldSymbol {
|
||||
}
|
||||
IrFieldSymbol
|
||||
|
||||
class IrTypeParameterSymbolImpl(descriptor: TypeParameterDescriptor) :
|
||||
IrBindableSymbolBase<TypeParameterDescriptor, IrTypeParameter>(descriptor),
|
||||
IrTypeParameterSymbol {
|
||||
}
|
||||
IrTypeParameterSymbol
|
||||
|
||||
class IrValueParameterSymbolImpl(descriptor: ParameterDescriptor) :
|
||||
IrBindableSymbolBase<ParameterDescriptor, IrValueParameter>(descriptor),
|
||||
IrValueParameterSymbol {
|
||||
}
|
||||
IrValueParameterSymbol
|
||||
|
||||
class IrVariableSymbolImpl(descriptor: VariableDescriptor) :
|
||||
IrBindableSymbolBase<VariableDescriptor, IrVariable>(descriptor),
|
||||
IrVariableSymbol {
|
||||
}
|
||||
IrVariableSymbol
|
||||
|
||||
class IrSimpleFunctionSymbolImpl(descriptor: FunctionDescriptor) :
|
||||
IrBindableSymbolBase<FunctionDescriptor, IrSimpleFunction>(descriptor),
|
||||
IrSimpleFunctionSymbol {
|
||||
}
|
||||
IrSimpleFunctionSymbol
|
||||
|
||||
class IrConstructorSymbolImpl(descriptor: ClassConstructorDescriptor) :
|
||||
IrBindableSymbolBase<ClassConstructorDescriptor, IrConstructor>(descriptor),
|
||||
IrConstructorSymbol {
|
||||
}
|
||||
IrConstructorSymbol
|
||||
|
||||
class IrReturnableBlockSymbolImpl(descriptor: FunctionDescriptor) :
|
||||
IrBindableSymbolBase<FunctionDescriptor, IrReturnableBlock>(descriptor),
|
||||
@@ -139,8 +131,7 @@ class IrReturnableBlockSymbolImpl(descriptor: FunctionDescriptor) :
|
||||
|
||||
class IrPropertySymbolImpl(descriptor: PropertyDescriptor) :
|
||||
IrBindableSymbolBase<PropertyDescriptor, IrProperty>(descriptor),
|
||||
IrPropertySymbol {
|
||||
}
|
||||
IrPropertySymbol
|
||||
|
||||
class IrLocalDelegatedPropertySymbolImpl(descriptor: VariableDescriptorWithAccessors) :
|
||||
IrBindableSymbolBase<VariableDescriptorWithAccessors, IrLocalDelegatedProperty>(descriptor),
|
||||
@@ -148,8 +139,7 @@ class IrLocalDelegatedPropertySymbolImpl(descriptor: VariableDescriptorWithAcces
|
||||
|
||||
class IrTypeAliasSymbolImpl(descriptor: TypeAliasDescriptor) :
|
||||
IrBindableSymbolBase<TypeAliasDescriptor, IrTypeAlias>(descriptor),
|
||||
IrTypeAliasSymbol {
|
||||
}
|
||||
IrTypeAliasSymbol
|
||||
|
||||
class IrScriptSymbolImpl(descriptor: ScriptDescriptor) :
|
||||
IrScriptSymbol, IrBindableSymbolBase<ScriptDescriptor, IrScript>(descriptor)
|
||||
|
||||
@@ -60,30 +60,24 @@ abstract class IrBindablePublicSymbolBase<out D : DeclarationDescriptor, B : IrS
|
||||
|
||||
class IrClassPublicSymbolImpl(descriptor: ClassDescriptor, sig: IdSignature) :
|
||||
IrBindablePublicSymbolBase<ClassDescriptor, IrClass>(descriptor, sig),
|
||||
IrClassSymbol {
|
||||
}
|
||||
IrClassSymbol
|
||||
|
||||
class IrEnumEntryPublicSymbolImpl(descriptor: ClassDescriptor, sig: IdSignature) :
|
||||
IrBindablePublicSymbolBase<ClassDescriptor, IrEnumEntry>(descriptor, sig),
|
||||
IrEnumEntrySymbol {
|
||||
}
|
||||
IrEnumEntrySymbol
|
||||
|
||||
class IrSimpleFunctionPublicSymbolImpl(descriptor: FunctionDescriptor, sig: IdSignature) :
|
||||
IrBindablePublicSymbolBase<FunctionDescriptor, IrSimpleFunction>(descriptor, sig),
|
||||
IrSimpleFunctionSymbol {
|
||||
}
|
||||
IrSimpleFunctionSymbol
|
||||
|
||||
class IrConstructorPublicSymbolImpl(descriptor: ClassConstructorDescriptor, sig: IdSignature) :
|
||||
IrBindablePublicSymbolBase<ClassConstructorDescriptor, IrConstructor>(descriptor, sig),
|
||||
IrConstructorSymbol {
|
||||
}
|
||||
IrConstructorSymbol
|
||||
|
||||
class IrPropertyPublicSymbolImpl(descriptor: PropertyDescriptor, sig: IdSignature) :
|
||||
IrBindablePublicSymbolBase<PropertyDescriptor, IrProperty>(descriptor, sig),
|
||||
IrPropertySymbol {
|
||||
}
|
||||
IrPropertySymbol
|
||||
|
||||
class IrTypeAliasPublicSymbolImpl(descriptor: TypeAliasDescriptor, sig: IdSignature) :
|
||||
IrBindablePublicSymbolBase<TypeAliasDescriptor, IrTypeAlias>(descriptor, sig),
|
||||
IrTypeAliasSymbol {
|
||||
}
|
||||
IrTypeAliasSymbol
|
||||
|
||||
@@ -12,16 +12,13 @@ import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
import org.jetbrains.kotlin.utils.DFS
|
||||
|
||||
fun IrClassifierSymbol.superTypes() = when (this) {
|
||||
fun IrClassifierSymbol.superTypes(): List<IrType> = when (this) {
|
||||
is IrClassSymbol -> owner.superTypes
|
||||
is IrTypeParameterSymbol -> owner.superTypes
|
||||
else -> emptyList<IrType>()
|
||||
else -> emptyList()
|
||||
}
|
||||
|
||||
fun IrClassifierSymbol.isSubtypeOfClass(superClass: IrClassSymbol): Boolean {
|
||||
@@ -34,50 +31,10 @@ fun IrType.isSubtypeOfClass(superClass: IrClassSymbol): Boolean {
|
||||
return classifier.isSubtypeOfClass(superClass)
|
||||
}
|
||||
|
||||
fun Collection<IrClassifierSymbol>.commonSuperclass(): IrClassifierSymbol {
|
||||
var superClassifiers: MutableSet<IrClassifierSymbol>? = null
|
||||
|
||||
require(isNotEmpty())
|
||||
|
||||
val order = fold(emptyList<IrClassifierSymbol>()) { _, classifierSymbol ->
|
||||
val visited = mutableSetOf<IrClassifierSymbol>()
|
||||
DFS.topologicalOrder(
|
||||
listOf(classifierSymbol), { it.superTypes().map { s -> (s as IrSimpleType).classifier } },
|
||||
DFS.VisitedWithSet(visited)
|
||||
).also {
|
||||
if (superClassifiers == null) {
|
||||
superClassifiers = visited
|
||||
} else {
|
||||
superClassifiers!!.apply {
|
||||
retainAll { c -> visited.any { v -> FqNameEqualityChecker.areEqual(c, v) } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
requireNotNull(superClassifiers)
|
||||
|
||||
return order.firstOrNull { o -> superClassifiers!!.any { s -> FqNameEqualityChecker.areEqual(o, s) } }
|
||||
?: error(
|
||||
"No common superType found for non-empty set of classifiers: ${joinToString(
|
||||
prefix = "[",
|
||||
postfix = "]"
|
||||
) { it.owner.render() }}"
|
||||
)
|
||||
}
|
||||
|
||||
fun IrType.isSubtypeOf(superType: IrType, irBuiltIns: IrBuiltIns): Boolean {
|
||||
return AbstractTypeChecker.isSubtypeOf(IrTypeCheckerContext(irBuiltIns) as AbstractTypeCheckerContext, this, superType)
|
||||
}
|
||||
|
||||
// no searchable usages
|
||||
// delete or FIXME: implement TypeConstructorMarker.isError and TypeConstructorMarker.toErrorType in IrTypeSystemContext
|
||||
fun Collection<IrType>.commonSupertype(irBuiltIns: IrBuiltIns): IrType {
|
||||
return NewCommonSuperTypeCalculator.run {
|
||||
IrTypeCheckerContext(irBuiltIns).commonSuperType(map { it }) as IrType
|
||||
}
|
||||
}
|
||||
|
||||
fun IrType.isNullable(): Boolean =
|
||||
when (this) {
|
||||
is IrSimpleType -> when (val classifier = classifier) {
|
||||
|
||||
@@ -80,9 +80,6 @@ fun IrSimpleTypeBuilder.buildTypeProjection() =
|
||||
inline fun IrSimpleType.buildSimpleType(b: IrSimpleTypeBuilder.() -> Unit): IrSimpleType =
|
||||
toBuilder().apply(b).buildSimpleType()
|
||||
|
||||
inline fun IrSimpleType.buildTypeProjection(b: IrSimpleTypeBuilder.() -> Unit): IrTypeProjection =
|
||||
toBuilder().apply(b).buildTypeProjection()
|
||||
|
||||
class IrTypeProjectionImpl internal constructor(
|
||||
override val type: IrType,
|
||||
override val variance: Variance
|
||||
@@ -108,4 +105,4 @@ fun makeTypeIntersection(types: List<IrType>): IrType =
|
||||
with(types.map { makeTypeProjection(it, Variance.INVARIANT).type }.distinct()) {
|
||||
if (size == 1) return single()
|
||||
else firstOrNull { !(it.isAny() || it.isNullableAny()) } ?: first { it.isAny() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,14 +6,12 @@
|
||||
package org.jetbrains.kotlin.ir.types
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.getFqName
|
||||
|
||||
private fun IrType.isNotNullClassType(fqName: FqNameUnsafe) = isClassType(fqName, hasQuestionMark = false)
|
||||
private fun IrType.isNullableClassType(fqName: FqNameUnsafe) = isClassType(fqName, hasQuestionMark = true)
|
||||
@@ -35,9 +33,6 @@ private fun classFqNameEquals(symbol: IrClassSymbol, fqName: FqNameUnsafe): Bool
|
||||
private fun classFqNameEquals(declaration: IrClass, fqName: FqNameUnsafe): Boolean =
|
||||
declaration.name == fqName.shortName() && fqName == declaration.fqNameWhenAvailable?.toUnsafe()
|
||||
|
||||
private fun classFqNameEquals(descriptor: ClassDescriptor, fqName: FqNameUnsafe): Boolean =
|
||||
descriptor.name == fqName.shortName() && fqName == getFqName(descriptor)
|
||||
|
||||
fun IrType.isAny(): Boolean = isNotNullClassType(KotlinBuiltIns.FQ_NAMES.any)
|
||||
fun IrType.isNullableAny(): Boolean = isNullableClassType(KotlinBuiltIns.FQ_NAMES.any)
|
||||
|
||||
@@ -56,8 +51,6 @@ fun IrType.isNullablePrimitiveType(): Boolean = KotlinBuiltIns.FQ_NAMES.fqNameTo
|
||||
fun IrType.isMarkedNullable() = (this as? IrSimpleType)?.hasQuestionMark ?: false
|
||||
|
||||
fun IrType.isUnit() = isNotNullClassType(KotlinBuiltIns.FQ_NAMES.unit)
|
||||
fun IrType.isNullableUnit() = isNullableClassType(KotlinBuiltIns.FQ_NAMES.unit)
|
||||
fun IrType.isUnitOrNullableUnit() = this.isUnit() || this.isNullableUnit()
|
||||
|
||||
fun IrType.isBoolean(): Boolean = isNotNullClassType(KotlinBuiltIns.FQ_NAMES._boolean)
|
||||
fun IrType.isChar(): Boolean = isNotNullClassType(KotlinBuiltIns.FQ_NAMES._char)
|
||||
@@ -87,10 +80,5 @@ fun IrType.isLongArray(): Boolean = isNotNullClassType(FqNameUnsafe("kotlin.Long
|
||||
fun IrType.isFloatArray(): Boolean = isNotNullClassType(FqNameUnsafe("kotlin.FloatArray"))
|
||||
fun IrType.isDoubleArray(): Boolean = isNotNullClassType(FqNameUnsafe("kotlin.DoubleArray"))
|
||||
|
||||
fun IrType.isNullableBoolean(): Boolean = isNullableClassType(KotlinBuiltIns.FQ_NAMES._boolean)
|
||||
fun IrType.isNullableLong(): Boolean = isNullableClassType(KotlinBuiltIns.FQ_NAMES._long)
|
||||
fun IrType.isNullableChar(): Boolean = isNullableClassType(KotlinBuiltIns.FQ_NAMES._char)
|
||||
|
||||
fun IrType.isKotlinResult(): Boolean = isNotNullClassType(DescriptorUtils.RESULT_FQ_NAME.toUnsafe())
|
||||
fun IrType.isContinuation(): Boolean = isNotNullClassType(DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME_RELEASE.toUnsafe())
|
||||
fun IrType.isNullableContinuation(): Boolean = isNullableClassType(DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME_RELEASE.toUnsafe())
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
@@ -16,12 +18,11 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import java.io.File
|
||||
|
||||
val IrConstructor.constructedClass get() = this.parent as IrClass
|
||||
|
||||
val <T : IrDeclaration> T.original get() = this
|
||||
|
||||
val IrDeclarationParent.fqNameForIrSerialization: FqName
|
||||
get() = when (this) {
|
||||
is IrPackageFragment -> this.fqName
|
||||
@@ -29,14 +30,6 @@ val IrDeclarationParent.fqNameForIrSerialization: FqName
|
||||
else -> error(this)
|
||||
}
|
||||
|
||||
@Deprecated(
|
||||
"Use fqNameForIrSerialization instead.",
|
||||
ReplaceWith("fqNameForIrSerialization", "org.jetbrains.kotlin.ir.util.fqNameForIrSerialization"),
|
||||
DeprecationLevel.ERROR
|
||||
)
|
||||
val IrDeclarationParent.fqNameSafe: FqName
|
||||
get() = fqNameForIrSerialization
|
||||
|
||||
val IrClass.classId: ClassId?
|
||||
get() = when (val parent = this.parent) {
|
||||
is IrClass -> parent.classId?.createNestedClassId(this.name)
|
||||
@@ -50,13 +43,6 @@ val IrDeclaration.nameForIrSerialization: Name
|
||||
is IrConstructor -> SPECIAL_INIT_NAME
|
||||
else -> error(this)
|
||||
}
|
||||
@Deprecated(
|
||||
"Use nameForIrSerialization instead.",
|
||||
ReplaceWith("nameForIrSerialization", "org.jetbrains.kotlin.ir.util.nameForIrSerialization"),
|
||||
DeprecationLevel.ERROR
|
||||
)
|
||||
val IrDeclaration.name: Name
|
||||
get() = nameForIrSerialization
|
||||
|
||||
private val SPECIAL_INIT_NAME = Name.special("<init>")
|
||||
|
||||
@@ -114,17 +100,6 @@ val IrDeclaration.isPropertyField get() =
|
||||
val IrDeclaration.isTopLevelDeclaration get() =
|
||||
parent !is IrDeclaration && !this.isPropertyAccessor && !this.isPropertyField
|
||||
|
||||
fun IrDeclaration.findTopLevelDeclaration(): IrDeclaration = when {
|
||||
this.isTopLevelDeclaration ->
|
||||
this
|
||||
this.isPropertyAccessor ->
|
||||
(this as IrSimpleFunction).correspondingPropertySymbol!!.owner.findTopLevelDeclaration()
|
||||
this.isPropertyField ->
|
||||
(this as IrField).correspondingPropertySymbol!!.owner.findTopLevelDeclaration()
|
||||
else ->
|
||||
(this.parent as IrDeclaration).findTopLevelDeclaration()
|
||||
}
|
||||
|
||||
val IrDeclaration.isAnonymousObject get() = this is IrClass && name == SpecialNames.NO_NAME_PROVIDED
|
||||
|
||||
val IrDeclaration.isLocal: Boolean
|
||||
@@ -173,10 +148,10 @@ val SourceManager.FileEntry.lineStartOffsets
|
||||
if (it.exists() && it.isFile) it.lineStartOffsets else IntArray(0)
|
||||
}
|
||||
|
||||
class NaiveSourceBasedFileEntryImpl(override val name: String, val lineStartOffsets: IntArray = IntArray(0)) : SourceManager.FileEntry {
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
class NaiveSourceBasedFileEntryImpl(
|
||||
override val name: String,
|
||||
private val lineStartOffsets: IntArray = intArrayOf()
|
||||
) : SourceManager.FileEntry {
|
||||
override fun getLineNumber(offset: Int): Int {
|
||||
assert(offset != UNDEFINED_OFFSET)
|
||||
if (offset == SYNTHETIC_OFFSET) return 0
|
||||
@@ -184,8 +159,6 @@ class NaiveSourceBasedFileEntryImpl(override val name: String, val lineStartOffs
|
||||
return if (index >= 0) index else -index - 2
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
override fun getColumnNumber(offset: Int): Int {
|
||||
assert(offset != UNDEFINED_OFFSET)
|
||||
if (offset == SYNTHETIC_OFFSET) return 0
|
||||
@@ -193,16 +166,11 @@ class NaiveSourceBasedFileEntryImpl(override val name: String, val lineStartOffs
|
||||
return offset - lineStartOffsets[lineNumber]
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
override val maxOffset: Int
|
||||
//get() = TODO("not implemented")
|
||||
get() = UNDEFINED_OFFSET
|
||||
|
||||
override fun getSourceRangeInfo(beginOffset: Int, endOffset: Int): SourceRangeInfo {
|
||||
//TODO("not implemented")
|
||||
return SourceRangeInfo(name, beginOffset, -1, -1, endOffset, -1, -1)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,3 +199,6 @@ fun IrClass.getPropertySetter(name: String): IrSimpleFunctionSymbol? =
|
||||
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)
|
||||
|
||||
inline fun MemberScope.findFirstFunction(name: String, predicate: (CallableMemberDescriptor) -> Boolean) =
|
||||
getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND).first(predicate)
|
||||
|
||||
@@ -129,12 +129,14 @@ abstract class DataClassMembersGenerator(
|
||||
private val intType = context.builtIns.intType
|
||||
|
||||
private val intTimesSymbol: IrSimpleFunctionSymbol =
|
||||
intClass.findFirstFunction("times") { KotlinTypeChecker.DEFAULT.equalTypes(it.valueParameters[0].type, intType) }
|
||||
.let { symbolTable.referenceSimpleFunction(it) }
|
||||
intClass.unsubstitutedMemberScope.findFirstFunction("times") {
|
||||
KotlinTypeChecker.DEFAULT.equalTypes(it.valueParameters[0].type, intType)
|
||||
}.let { symbolTable.referenceSimpleFunction(it) }
|
||||
|
||||
private val intPlusSymbol: IrSimpleFunctionSymbol =
|
||||
intClass.findFirstFunction("plus") { KotlinTypeChecker.DEFAULT.equalTypes(it.valueParameters[0].type, intType) }
|
||||
.let { symbolTable.referenceSimpleFunction(it) }
|
||||
intClass.unsubstitutedMemberScope.findFirstFunction("plus") {
|
||||
KotlinTypeChecker.DEFAULT.equalTypes(it.valueParameters[0].type, intType)
|
||||
}.let { symbolTable.referenceSimpleFunction(it) }
|
||||
|
||||
fun generateHashCodeMethodBody(properties: List<PropertyDescriptor>) {
|
||||
val irIntType = context.irBuiltIns.intType
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.util
|
||||
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
|
||||
interface IrSymbolVisitor<out R, in D> {
|
||||
fun visitSymbol(symbol: IrSymbol, data: D): R
|
||||
|
||||
fun visitPackageFragmentSymbol(symbol: IrPackageFragmentSymbol, data: D) =
|
||||
visitSymbol(symbol, data)
|
||||
|
||||
fun visitFileSymbol(symbol: IrFileSymbol, data: D) =
|
||||
visitPackageFragmentSymbol(symbol, data)
|
||||
|
||||
fun visitExternalPackageFragmentSymbol(symbol: IrExternalPackageFragmentSymbol, data: D) =
|
||||
visitPackageFragmentSymbol(symbol, data)
|
||||
|
||||
fun visitClassifierSymbol(symbol: IrClassifierSymbol, data: D) =
|
||||
visitSymbol(symbol, data)
|
||||
|
||||
fun visitClassSymbol(symbol: IrClassSymbol, data: D) =
|
||||
visitClassifierSymbol(symbol, data)
|
||||
|
||||
fun visitTypeParameterSymbol(symbol: IrTypeParameterSymbol, data: D) =
|
||||
visitClassifierSymbol(symbol, data)
|
||||
|
||||
fun visitValueSymbol(symbol: IrValueSymbol, data: D) =
|
||||
visitSymbol(symbol, data)
|
||||
|
||||
fun visitVariableSymbol(symbol: IrVariableSymbol, data: D) =
|
||||
visitValueSymbol(symbol, data)
|
||||
|
||||
fun visitValueParameterSymbol(symbol: IrValueParameterSymbol, data: D) =
|
||||
visitValueSymbol(symbol, data)
|
||||
|
||||
fun visitReturnTargetSymbol(symbol: IrReturnTargetSymbol, data: D) =
|
||||
visitSymbol(symbol, data)
|
||||
|
||||
fun visitFunctionSymbol(symbol: IrFunctionSymbol, data: D) =
|
||||
visitReturnTargetSymbol(symbol, data)
|
||||
|
||||
fun visitSimpleFunctionSymbol(symbol: IrSimpleFunctionSymbol, data: D) =
|
||||
visitFunctionSymbol(symbol, data)
|
||||
|
||||
fun visitConstructorSymbol(symbol: IrConstructorSymbol, data: D) =
|
||||
visitFunctionSymbol(symbol, data)
|
||||
|
||||
fun visitReturnableBlockSymbol(symbol: IrReturnableBlockSymbol, data: D) =
|
||||
visitReturnTargetSymbol(symbol, data)
|
||||
|
||||
fun visitAnonymousInitializerSymbol(symbol: IrAnonymousInitializerSymbol, data: D) =
|
||||
visitSymbol(symbol, data)
|
||||
|
||||
fun visitEnumEntrySymbol(symbol: IrEnumEntrySymbol, data: D) =
|
||||
visitSymbol(symbol, data)
|
||||
|
||||
fun visitFieldSymbol(symbol: IrFieldSymbol, data: D) =
|
||||
visitSymbol(symbol, data)
|
||||
|
||||
fun visitPropertySymbol(symbol: IrPropertySymbol, data: D) =
|
||||
visitSymbol(symbol, data)
|
||||
|
||||
fun visitLocalDelegatedPropertySymbol(symbol: IrLocalDelegatedPropertySymbol, data: D) =
|
||||
visitSymbol(symbol, data)
|
||||
|
||||
fun visitTypeAliasSymbol(symbol: IrTypeAliasSymbol, data: D) =
|
||||
visitSymbol(symbol, data)
|
||||
}
|
||||
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
@@ -20,11 +19,6 @@ import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.utils.DFS
|
||||
@@ -64,6 +58,7 @@ fun IrMemberAccessExpression<*>.getArguments(): List<Pair<ParameterDescriptor, I
|
||||
* The arguments are to be evaluated in the same order as they appear in the resulting list.
|
||||
*/
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
@Suppress("unused") // Used in kotlin-native
|
||||
fun IrFunctionAccessExpression.getArgumentsWithSymbols(): List<Pair<IrValueParameterSymbol, IrExpression>> {
|
||||
val res = mutableListOf<Pair<IrValueParameterSymbol, IrExpression>>()
|
||||
val irFunction = symbol.owner
|
||||
@@ -149,6 +144,7 @@ fun IrMemberAccessExpression<*>.addArguments(args: Map<ParameterDescriptor, IrEx
|
||||
}
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
@Suppress("unused") // Used in kotlin-native
|
||||
fun IrMemberAccessExpression<*>.addArguments(args: List<Pair<ParameterDescriptor, IrExpression>>) =
|
||||
this.addArguments(args.toMap())
|
||||
|
||||
@@ -162,14 +158,9 @@ fun IrExpression.isIntegerConst(value: Int) = this is IrConst<*> && this.kind ==
|
||||
|
||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||
fun IrExpression.coerceToUnit(builtins: IrBuiltIns): IrExpression {
|
||||
val valueType = getKotlinType(this)
|
||||
return coerceToUnitIfNeeded(valueType, builtins)
|
||||
return coerceToUnitIfNeeded(type.toKotlinType(), builtins)
|
||||
}
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
private fun getKotlinType(irExpression: IrExpression) =
|
||||
irExpression.type.toKotlinType()
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
fun IrExpression.coerceToUnitIfNeeded(valueType: KotlinType, irBuiltIns: IrBuiltIns): IrExpression {
|
||||
return if (KotlinTypeChecker.DEFAULT.isSubtypeOf(valueType, irBuiltIns.unitType.toKotlinType()))
|
||||
@@ -201,9 +192,6 @@ fun IrExpression.coerceToUnitIfNeeded(valueType: IrType, irBuiltIns: IrBuiltIns)
|
||||
fun IrMemberAccessExpression<*>.usesDefaultArguments(): Boolean =
|
||||
(symbol.descriptor as CallableDescriptor).valueParameters.any { this.getValueArgument(it) == null }
|
||||
|
||||
val DeclarationDescriptorWithSource.startOffset: Int? get() = (this.source as? PsiSourceElement)?.psi?.startOffset
|
||||
val DeclarationDescriptorWithSource.endOffset: Int? get() = (this.source as? PsiSourceElement)?.psi?.endOffset
|
||||
|
||||
val IrClass.functions: Sequence<IrSimpleFunction>
|
||||
get() = declarations.asSequence().filterIsInstance<IrSimpleFunction>()
|
||||
|
||||
@@ -297,10 +285,9 @@ fun IrClass.isLocalClass(): Boolean {
|
||||
|
||||
tailrec fun IrElement.getPackageFragment(): IrPackageFragment? {
|
||||
if (this is IrPackageFragment) return this
|
||||
val vParent = (this as? IrDeclaration)?.parent
|
||||
return when (vParent) {
|
||||
is IrPackageFragment -> vParent
|
||||
else -> vParent?.getPackageFragment()
|
||||
return when (val parent = (this as? IrDeclaration)?.parent) {
|
||||
is IrPackageFragment -> parent
|
||||
else -> parent?.getPackageFragment()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,22 +353,12 @@ fun IrFunction.isExternalOrInheritedFromExternal(): Boolean {
|
||||
inline fun <reified T : IrDeclaration> IrDeclarationContainer.findDeclaration(predicate: (T) -> Boolean): T? =
|
||||
declarations.find { it is T && predicate(it) } as? T
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
inline fun <reified T : IrDeclaration> IrDeclarationContainer.filterDeclarations(predicate: (T) -> Boolean): List<T> =
|
||||
declarations.filter { it is T && predicate(it) } as List<T>
|
||||
|
||||
fun IrValueParameter.hasDefaultValue(): Boolean = DFS.ifAny(
|
||||
listOf(this),
|
||||
{ current -> (current.parent as? IrSimpleFunction)?.overriddenSymbols?.map { it.owner.valueParameters[current.index] } ?: listOf() },
|
||||
{ current -> current.defaultValue != null }
|
||||
)
|
||||
|
||||
// In presence of `IrBlock`s, return the expression that actually serves as the value (the last one).
|
||||
tailrec fun IrExpression.removeBlocks(): IrExpression? = when (this) {
|
||||
is IrBlock -> (statements.last() as? IrExpression)?.removeBlocks()
|
||||
else -> this
|
||||
}
|
||||
|
||||
fun ReferenceSymbolTable.referenceClassifier(classifier: ClassifierDescriptor): IrClassifierSymbol =
|
||||
when (classifier) {
|
||||
is TypeParameterDescriptor ->
|
||||
@@ -403,19 +380,10 @@ fun ReferenceSymbolTable.referenceFunction(callable: CallableDescriptor): IrFunc
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new call based on given [call] and [newFunction]
|
||||
* Create new call based on given [call] and [newSymbol]
|
||||
* [receiversAsArguments]: optionally convert call with dispatch receiver to static call
|
||||
* [argumentsAsReceivers]: optionally convert static call to call with dispatch receiver
|
||||
* [argumentsAsDispatchers]: optionally convert static call to call with dispatch receiver
|
||||
*/
|
||||
|
||||
fun irConstructorCall(
|
||||
call: IrFunctionAccessExpression,
|
||||
newFunction: IrConstructor,
|
||||
receiversAsArguments: Boolean = false,
|
||||
argumentsAsReceivers: Boolean = false
|
||||
): IrConstructorCall =
|
||||
irConstructorCall(call, newFunction.symbol, receiversAsArguments, argumentsAsReceivers)
|
||||
|
||||
fun irConstructorCall(
|
||||
call: IrFunctionAccessExpression,
|
||||
newSymbol: IrConstructorSymbol,
|
||||
@@ -568,42 +536,6 @@ val IrFunctionReference.typeSubstitutionMap: Map<IrTypeParameterSymbol, IrType>
|
||||
val IrFunctionAccessExpression.typeSubstitutionMap: Map<IrTypeParameterSymbol, IrType>
|
||||
get() = getTypeSubstitutionMap(symbol.owner)
|
||||
|
||||
// Note: there is not enough information in a descriptor to choose between an enum entry and its corresponding class,
|
||||
// so the entry itself is chosen in that case.
|
||||
fun SymbolTable.referenceMember(descriptor: DeclarationDescriptor, correspondingClassForEnum: Boolean = false): IrSymbol =
|
||||
descriptor.accept(
|
||||
object : DeclarationDescriptorVisitorEmptyBodies<IrSymbol, Unit?>() {
|
||||
override fun visitClassDescriptor(descriptor: ClassDescriptor, data: Unit?) =
|
||||
if (DescriptorUtils.isEnumEntry(descriptor) && !correspondingClassForEnum)
|
||||
referenceEnumEntry(descriptor)
|
||||
else
|
||||
referenceClass(descriptor)
|
||||
|
||||
override fun visitConstructorDescriptor(constructorDescriptor: ConstructorDescriptor, data: Unit?) =
|
||||
referenceConstructor(descriptor as ClassConstructorDescriptor)
|
||||
|
||||
override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, data: Unit?) = referenceSimpleFunction(descriptor)
|
||||
|
||||
override fun visitPropertyDescriptor(descriptor: PropertyDescriptor, data: Unit?) = referenceProperty(descriptor)
|
||||
|
||||
override fun visitTypeParameterDescriptor(descriptor: TypeParameterDescriptor, data: Unit?) = referenceTypeParameter(descriptor)
|
||||
|
||||
override fun visitTypeAliasDescriptor(descriptor: TypeAliasDescriptor, data: Unit?) = referenceTypeAlias(descriptor)
|
||||
|
||||
override fun visitDeclarationDescriptor(descriptor: DeclarationDescriptor?, data: Unit?): IrSymbol {
|
||||
throw AssertionError("Unexpected member descriptor: $descriptor")
|
||||
}
|
||||
},
|
||||
null
|
||||
)
|
||||
|
||||
fun SymbolTable.findOrDeclareExternalPackageFragment(descriptor: PackageFragmentDescriptor) =
|
||||
referenceExternalPackageFragment(descriptor).also {
|
||||
if (!it.isBound) {
|
||||
declareExternalPackageFragment(descriptor)
|
||||
}
|
||||
}.owner
|
||||
|
||||
val IrDeclaration.isFileClass: Boolean
|
||||
get() = origin == IrDeclarationOrigin.FILE_CLASS || origin == IrDeclarationOrigin.SYNTHETIC_FILE_CLASS
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 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.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
|
||||
inline fun ClassDescriptor.findFirstFunction(name: String, predicate: (CallableMemberDescriptor) -> Boolean) =
|
||||
unsubstitutedMemberScope.findFirstFunction(name, predicate)
|
||||
|
||||
inline fun MemberScope.findFirstFunction(name: String, predicate: (CallableMemberDescriptor) -> Boolean) =
|
||||
getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND).first(predicate)
|
||||
+1
-8
@@ -5,14 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.serialization
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.propertyIfAccessor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.konan.kotlinLibrary
|
||||
import org.jetbrains.kotlin.library.metadata.DeserializedSourceFile
|
||||
import org.jetbrains.kotlin.library.metadata.KlibMetadataDeserializedPackageFragment
|
||||
import org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||
import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor
|
||||
@@ -29,11 +27,6 @@ tailrec fun DeclarationDescriptor.findPackage(): PackageFragmentDescriptor {
|
||||
else this.containingDeclaration!!.findPackage()
|
||||
}
|
||||
|
||||
fun DeclarationDescriptor.findTopLevelDescriptor(): DeclarationDescriptor {
|
||||
return if (this.containingDeclaration is PackageFragmentDescriptor) this.propertyIfAccessor
|
||||
else this.containingDeclaration!!.findTopLevelDescriptor()
|
||||
}
|
||||
|
||||
// This is Native specific. Try to eliminate.
|
||||
val ModuleDescriptor.isForwardDeclarationModule get() =
|
||||
name == Name.special("<forward declarations>")
|
||||
@@ -57,4 +50,4 @@ fun CallableMemberDescriptor.findSourceFile(): SourceFile {
|
||||
this, proto.getExtension(KlibMetadataProtoBuf.propertyFile))
|
||||
else -> TODO()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.scripting.ide_services.compiler.impl
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.tree.TokenSet
|
||||
import org.jetbrains.kotlin.backend.common.onlyIf
|
||||
import org.jetbrains.kotlin.builtins.isFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||
@@ -236,7 +235,9 @@ private class KJvmReplCompleter(
|
||||
)
|
||||
Triple(it, presentation, (presentation.presentableText + presentation.tailText).toLowerCase())
|
||||
}
|
||||
.onlyIf({ isSortNeeded }) { it.sortedBy { descTriple -> descTriple.third } }
|
||||
.let {
|
||||
if (isSortNeeded) it.sortedBy { descTriple -> descTriple.third } else it
|
||||
}
|
||||
.forEach {
|
||||
val descriptor = it.first
|
||||
val (rawName, presentableText, tailText, completionText) = it.second
|
||||
|
||||
Reference in New Issue
Block a user