Optimize Utils.kt by removing unused functions
This commit is contained in:
committed by
TeamCityServer
parent
877832ef8c
commit
b3fa7b25cf
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
|||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
|
||||||
import org.jetbrains.kotlin.ir.interpreter.builtins.evaluateIntrinsicAnnotation
|
|
||||||
import org.jetbrains.kotlin.ir.interpreter.builtins.interpretBinaryFunction
|
import org.jetbrains.kotlin.ir.interpreter.builtins.interpretBinaryFunction
|
||||||
import org.jetbrains.kotlin.ir.interpreter.builtins.interpretTernaryFunction
|
import org.jetbrains.kotlin.ir.interpreter.builtins.interpretTernaryFunction
|
||||||
import org.jetbrains.kotlin.ir.interpreter.builtins.interpretUnaryFunction
|
import org.jetbrains.kotlin.ir.interpreter.builtins.interpretUnaryFunction
|
||||||
|
|||||||
@@ -8,16 +8,14 @@ package org.jetbrains.kotlin.ir.interpreter
|
|||||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||||
import org.jetbrains.kotlin.builtins.StandardNames
|
import org.jetbrains.kotlin.builtins.StandardNames
|
||||||
import org.jetbrains.kotlin.builtins.UnsignedType
|
import org.jetbrains.kotlin.builtins.UnsignedType
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
|
||||||
import org.jetbrains.kotlin.ir.interpreter.builtins.evaluateIntrinsicAnnotation
|
|
||||||
import org.jetbrains.kotlin.ir.interpreter.state.*
|
|
||||||
import org.jetbrains.kotlin.ir.interpreter.proxy.Proxy
|
import org.jetbrains.kotlin.ir.interpreter.proxy.Proxy
|
||||||
import org.jetbrains.kotlin.ir.interpreter.proxy.wrap
|
import org.jetbrains.kotlin.ir.interpreter.proxy.wrap
|
||||||
|
import org.jetbrains.kotlin.ir.interpreter.state.*
|
||||||
import org.jetbrains.kotlin.ir.interpreter.state.reflection.KTypeState
|
import org.jetbrains.kotlin.ir.interpreter.state.reflection.KTypeState
|
||||||
import org.jetbrains.kotlin.ir.symbols.*
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
@@ -29,7 +27,10 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly
|
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly
|
||||||
import java.lang.invoke.MethodType
|
import java.lang.invoke.MethodType
|
||||||
import kotlin.math.min
|
|
||||||
|
val compileTimeAnnotation = FqName("kotlin.CompileTimeCalculation")
|
||||||
|
val evaluateIntrinsicAnnotation = FqName("kotlin.EvaluateIntrinsic")
|
||||||
|
val contractsDslAnnotation = FqName("kotlin.internal.ContractsDsl")
|
||||||
|
|
||||||
internal fun IrFunction.getDispatchReceiver(): IrValueParameterSymbol? = this.dispatchReceiverParameter?.symbol
|
internal fun IrFunction.getDispatchReceiver(): IrValueParameterSymbol? = this.dispatchReceiverParameter?.symbol
|
||||||
|
|
||||||
@@ -37,8 +38,6 @@ internal fun IrFunction.getExtensionReceiver(): IrValueParameterSymbol? = this.e
|
|||||||
|
|
||||||
internal fun IrFunction.getReceiver(): IrSymbol? = this.getDispatchReceiver() ?: this.getExtensionReceiver()
|
internal fun IrFunction.getReceiver(): IrSymbol? = this.getDispatchReceiver() ?: this.getExtensionReceiver()
|
||||||
|
|
||||||
internal fun IrFunctionAccessExpression.getBody(): IrBody? = this.symbol.owner.body
|
|
||||||
|
|
||||||
internal fun IrFunctionAccessExpression.getThisReceiver(): IrValueSymbol = this.symbol.owner.parentAsClass.thisReceiver!!.symbol
|
internal fun IrFunctionAccessExpression.getThisReceiver(): IrValueSymbol = this.symbol.owner.parentAsClass.thisReceiver!!.symbol
|
||||||
|
|
||||||
internal fun State.toIrExpression(expression: IrExpression): IrExpression {
|
internal fun State.toIrExpression(expression: IrExpression): IrExpression {
|
||||||
@@ -180,7 +179,12 @@ fun IrFunctionAccessExpression.getVarargType(index: Int): IrType? {
|
|||||||
|
|
||||||
internal fun IrFunction.getCapitalizedFileName() = this.file.name.replace(".kt", "Kt").capitalizeAsciiOnly()
|
internal fun IrFunction.getCapitalizedFileName() = this.file.name.replace(".kt", "Kt").capitalizeAsciiOnly()
|
||||||
|
|
||||||
internal fun IrType.isUnsigned() = this.isUByte() || this.isUShort() || this.isUInt() || this.isULong()
|
internal fun IrType.isUnsigned() = this.getUnsignedType() != null
|
||||||
|
internal fun IrType.isFunction() = this.getClass()?.fqNameWhenAvailable?.asString()?.startsWith("kotlin.Function") ?: false
|
||||||
|
internal fun IrType.isKFunction() = this.getClass()?.fqNameWhenAvailable?.asString()?.startsWith("kotlin.reflect.KFunction") ?: false
|
||||||
|
internal fun IrType.isTypeParameter() = classifierOrNull is IrTypeParameterSymbol
|
||||||
|
internal fun IrType.isThrowable() = this.getClass()?.fqNameWhenAvailable?.asString() == "kotlin.Throwable"
|
||||||
|
|
||||||
internal fun IrType.isUnsignedArray(): Boolean {
|
internal fun IrType.isUnsignedArray(): Boolean {
|
||||||
if (this !is IrSimpleType || classifier !is IrClassSymbol) return false
|
if (this !is IrSimpleType || classifier !is IrClassSymbol) return false
|
||||||
val fqName = (classifier.owner as IrDeclarationWithName).fqNameWhenAvailable?.asString()
|
val fqName = (classifier.owner as IrDeclarationWithName).fqNameWhenAvailable?.asString()
|
||||||
@@ -191,34 +195,7 @@ internal fun IrType.isPrimitiveArray(): Boolean {
|
|||||||
return this.getClass()?.fqNameWhenAvailable?.toUnsafe()?.let { StandardNames.isPrimitiveArray(it) } ?: false
|
return this.getClass()?.fqNameWhenAvailable?.toUnsafe()?.let { StandardNames.isPrimitiveArray(it) } ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun IrType.isFunction() = this.getClass()?.fqNameWhenAvailable?.asString()?.startsWith("kotlin.Function") ?: false
|
internal fun IrClass.internalName(): String {
|
||||||
internal fun IrType.isKFunction() = this.getClass()?.fqNameWhenAvailable?.asString()?.startsWith("kotlin.reflect.KFunction") ?: false
|
|
||||||
|
|
||||||
internal fun IrType.isTypeParameter() = classifierOrNull is IrTypeParameterSymbol
|
|
||||||
|
|
||||||
internal fun IrType.isInterface() = classOrNull?.owner?.kind == ClassKind.INTERFACE
|
|
||||||
|
|
||||||
internal fun IrType.isThrowable() = this.getClass()?.fqNameWhenAvailable?.asString() == "kotlin.Throwable"
|
|
||||||
|
|
||||||
internal fun IrType.renderType(): String {
|
|
||||||
var renderedType = this.render()
|
|
||||||
do {
|
|
||||||
val index = renderedType.indexOf(" of ")
|
|
||||||
if (index == -1) break
|
|
||||||
val replaceUntilComma = renderedType.indexOf(',', index)
|
|
||||||
val replaceUntilTriangle = renderedType.indexOf('>', index)
|
|
||||||
val replaceUntil = when {
|
|
||||||
replaceUntilComma == -1 && replaceUntilTriangle == -1 -> renderedType.length
|
|
||||||
replaceUntilComma == -1 -> replaceUntilTriangle
|
|
||||||
replaceUntilTriangle == -1 -> replaceUntilComma
|
|
||||||
else -> min(replaceUntilComma, replaceUntilTriangle)
|
|
||||||
}
|
|
||||||
renderedType = renderedType.replaceRange(index, replaceUntil, "")
|
|
||||||
} while (true)
|
|
||||||
return renderedType
|
|
||||||
}
|
|
||||||
|
|
||||||
fun IrClass.internalName(): String {
|
|
||||||
val internalName = StringBuilder(this.name.asString())
|
val internalName = StringBuilder(this.name.asString())
|
||||||
generateSequence(this as? IrDeclarationParent) { (it as? IrDeclaration)?.parent }
|
generateSequence(this as? IrDeclarationParent) { (it as? IrDeclaration)?.parent }
|
||||||
.drop(1)
|
.drop(1)
|
||||||
|
|||||||
-12
@@ -1,12 +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.interpreter.builtins
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
|
|
||||||
val compileTimeAnnotation = FqName("kotlin.CompileTimeCalculation")
|
|
||||||
val evaluateIntrinsicAnnotation = FqName("kotlin.EvaluateIntrinsic")
|
|
||||||
val contractsDslAnnotation = FqName("kotlin.internal.ContractsDsl")
|
|
||||||
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.ir.declarations.IrFunction
|
|||||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||||
import org.jetbrains.kotlin.ir.interpreter.*
|
import org.jetbrains.kotlin.ir.interpreter.*
|
||||||
import org.jetbrains.kotlin.ir.interpreter.builtins.evaluateIntrinsicAnnotation
|
import org.jetbrains.kotlin.ir.interpreter.evaluateIntrinsicAnnotation
|
||||||
import org.jetbrains.kotlin.ir.interpreter.stack.Variable
|
import org.jetbrains.kotlin.ir.interpreter.stack.Variable
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
|
|||||||
-1
@@ -11,7 +11,6 @@ import org.jetbrains.kotlin.ir.interpreter.CallInterceptor
|
|||||||
import org.jetbrains.kotlin.ir.interpreter.proxy.reflection.KClassProxy
|
import org.jetbrains.kotlin.ir.interpreter.proxy.reflection.KClassProxy
|
||||||
import org.jetbrains.kotlin.ir.interpreter.proxy.reflection.KTypeParameterProxy
|
import org.jetbrains.kotlin.ir.interpreter.proxy.reflection.KTypeParameterProxy
|
||||||
import org.jetbrains.kotlin.ir.interpreter.proxy.reflection.KTypeProxy
|
import org.jetbrains.kotlin.ir.interpreter.proxy.reflection.KTypeProxy
|
||||||
import org.jetbrains.kotlin.ir.interpreter.renderType
|
|
||||||
import org.jetbrains.kotlin.ir.interpreter.state.Wrapper
|
import org.jetbrains.kotlin.ir.interpreter.state.Wrapper
|
||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
|||||||
+20
-1
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
|||||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||||
import org.jetbrains.kotlin.ir.interpreter.renderType
|
|
||||||
import org.jetbrains.kotlin.ir.interpreter.stack.Variable
|
import org.jetbrains.kotlin.ir.interpreter.stack.Variable
|
||||||
import org.jetbrains.kotlin.ir.interpreter.state.State
|
import org.jetbrains.kotlin.ir.interpreter.state.State
|
||||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||||
@@ -20,6 +19,8 @@ import org.jetbrains.kotlin.ir.types.typeOrNull
|
|||||||
import org.jetbrains.kotlin.ir.util.defaultType
|
import org.jetbrains.kotlin.ir.util.defaultType
|
||||||
import org.jetbrains.kotlin.ir.util.nameForIrSerialization
|
import org.jetbrains.kotlin.ir.util.nameForIrSerialization
|
||||||
import org.jetbrains.kotlin.ir.util.parentClassOrNull
|
import org.jetbrains.kotlin.ir.util.parentClassOrNull
|
||||||
|
import org.jetbrains.kotlin.ir.util.render
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
internal abstract class ReflectionState : State {
|
internal abstract class ReflectionState : State {
|
||||||
override val fields: MutableList<Variable> = mutableListOf()
|
override val fields: MutableList<Variable> = mutableListOf()
|
||||||
@@ -76,4 +77,22 @@ internal abstract class ReflectionState : State {
|
|||||||
val returnType = property.getter!!.returnType.renderType()
|
val returnType = property.getter!!.returnType.renderType()
|
||||||
return "$prefix $receivers${property.name}: $returnType"
|
return "$prefix $receivers${property.name}: $returnType"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected fun IrType.renderType(): String {
|
||||||
|
var renderedType = this.render()
|
||||||
|
do {
|
||||||
|
val index = renderedType.indexOf(" of ")
|
||||||
|
if (index == -1) break
|
||||||
|
val replaceUntilComma = renderedType.indexOf(',', index)
|
||||||
|
val replaceUntilTriangle = renderedType.indexOf('>', index)
|
||||||
|
val replaceUntil = when {
|
||||||
|
replaceUntilComma == -1 && replaceUntilTriangle == -1 -> renderedType.length
|
||||||
|
replaceUntilComma == -1 -> replaceUntilTriangle
|
||||||
|
replaceUntilTriangle == -1 -> replaceUntilComma
|
||||||
|
else -> min(replaceUntilComma, replaceUntilTriangle)
|
||||||
|
}
|
||||||
|
renderedType = renderedType.replaceRange(index, replaceUntil, "")
|
||||||
|
} while (true)
|
||||||
|
return renderedType
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user