[IR] Convert methods in IrConstantValue classes to extension functions
to get rid of custom logic inside generated classes. #KT-65773 In Progress
This commit is contained in:
committed by
Space Team
parent
42668e2bf6
commit
baaaf4567e
@@ -11,8 +11,4 @@ package org.jetbrains.kotlin.ir.expressions
|
||||
/**
|
||||
* Generated from: [org.jetbrains.kotlin.ir.generator.IrTree.constantValue]
|
||||
*/
|
||||
abstract class IrConstantValue : IrExpression() {
|
||||
abstract fun contentEquals(other: IrConstantValue): Boolean
|
||||
|
||||
abstract fun contentHashCode(): Int
|
||||
}
|
||||
sealed class IrConstantValue : IrExpression()
|
||||
|
||||
-14
@@ -21,18 +21,4 @@ class IrConstantArrayImpl(
|
||||
|
||||
override var attributeOwnerId: IrAttributeContainer = this
|
||||
override var originalBeforeInline: IrAttributeContainer? = null
|
||||
|
||||
override fun contentEquals(other: IrConstantValue): Boolean =
|
||||
other is IrConstantArray &&
|
||||
other.type == type &&
|
||||
elements.size == other.elements.size &&
|
||||
elements.indices.all { elements[it].contentEquals(other.elements[it]) }
|
||||
|
||||
override fun contentHashCode(): Int {
|
||||
var res = type.hashCode()
|
||||
for (value in elements) {
|
||||
res = res * 31 + value.contentHashCode()
|
||||
}
|
||||
return res
|
||||
}
|
||||
}
|
||||
+4
-24
@@ -1,18 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2024 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.expressions.impl
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrAttributeContainer
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstantObject
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstantValue
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.constructedClassType
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
|
||||
class IrConstantObjectImpl constructor(
|
||||
class IrConstantObjectImpl(
|
||||
override val startOffset: Int,
|
||||
override val endOffset: Int,
|
||||
override var constructor: IrConstructorSymbol,
|
||||
@@ -25,25 +26,4 @@ class IrConstantObjectImpl constructor(
|
||||
|
||||
override var attributeOwnerId: IrAttributeContainer = this
|
||||
override var originalBeforeInline: IrAttributeContainer? = null
|
||||
|
||||
override fun contentEquals(other: IrConstantValue): Boolean =
|
||||
other is IrConstantObject &&
|
||||
other.type == type &&
|
||||
other.constructor == constructor &&
|
||||
valueArguments.size == other.valueArguments.size &&
|
||||
typeArguments.size == other.typeArguments.size &&
|
||||
valueArguments.indices.all { index -> valueArguments[index].contentEquals(other.valueArguments[index]) } &&
|
||||
typeArguments.indices.all { index -> typeArguments[index] == other.typeArguments[index] }
|
||||
|
||||
|
||||
override fun contentHashCode(): Int {
|
||||
var res = type.hashCode() * 31 + constructor.hashCode()
|
||||
for (value in valueArguments) {
|
||||
res = res * 31 + value.contentHashCode()
|
||||
}
|
||||
for (value in typeArguments) {
|
||||
res = res * 31 + value.hashCode()
|
||||
}
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
-17
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.ir.expressions.impl
|
||||
import org.jetbrains.kotlin.ir.declarations.IrAttributeContainer
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConst
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstantPrimitive
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstantValue
|
||||
|
||||
class IrConstantPrimitiveImpl(
|
||||
override val startOffset: Int,
|
||||
@@ -17,21 +16,5 @@ class IrConstantPrimitiveImpl(
|
||||
) : IrConstantPrimitive() {
|
||||
override var attributeOwnerId: IrAttributeContainer = this
|
||||
override var originalBeforeInline: IrAttributeContainer? = null
|
||||
|
||||
override fun contentEquals(other: IrConstantValue) =
|
||||
other is IrConstantPrimitive &&
|
||||
type == other.type &&
|
||||
value.type == other.value.type &&
|
||||
value.kind == other.value.kind &&
|
||||
value.value == other.value.value
|
||||
|
||||
override fun contentHashCode(): Int {
|
||||
var result = type.hashCode()
|
||||
result = result * 31 + value.type.hashCode()
|
||||
result = result * 31 + value.kind.hashCode()
|
||||
result = result * 31 + value.value.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
override var type = value.type
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2010-2024 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.expressions.IrConstantArray
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstantObject
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstantPrimitive
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstantValue
|
||||
|
||||
fun IrConstantValue.contentEquals(other: IrConstantValue): Boolean = when (this) {
|
||||
is IrConstantPrimitive -> contentEquals(other)
|
||||
is IrConstantObject -> contentEquals(other)
|
||||
is IrConstantArray -> contentEquals(other)
|
||||
}
|
||||
|
||||
fun IrConstantValue.contentHashCode(): Int = when (this) {
|
||||
is IrConstantPrimitive -> contentHashCode()
|
||||
is IrConstantObject -> contentHashCode()
|
||||
is IrConstantArray -> contentHashCode()
|
||||
}
|
||||
|
||||
|
||||
fun IrConstantPrimitive.contentEquals(other: IrConstantValue): Boolean =
|
||||
other is IrConstantPrimitive &&
|
||||
type == other.type &&
|
||||
value.type == other.value.type &&
|
||||
value.kind == other.value.kind &&
|
||||
value.value == other.value.value
|
||||
|
||||
fun IrConstantPrimitive.contentHashCode(): Int {
|
||||
var result = type.hashCode()
|
||||
result = result * 31 + value.type.hashCode()
|
||||
result = result * 31 + value.kind.hashCode()
|
||||
result = result * 31 + value.value.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
fun IrConstantObject.contentEquals(other: IrConstantValue): Boolean =
|
||||
other is IrConstantObject &&
|
||||
other.type == type &&
|
||||
other.constructor == constructor &&
|
||||
valueArguments.size == other.valueArguments.size &&
|
||||
typeArguments.size == other.typeArguments.size &&
|
||||
valueArguments.indices.all { index -> valueArguments[index].contentEquals(other.valueArguments[index]) } &&
|
||||
typeArguments.indices.all { index -> typeArguments[index] == other.typeArguments[index] }
|
||||
|
||||
fun IrConstantObject.contentHashCode(): Int {
|
||||
var res = type.hashCode() * 31 + constructor.hashCode()
|
||||
for (value in valueArguments) {
|
||||
res = res * 31 + value.contentHashCode()
|
||||
}
|
||||
for (value in typeArguments) {
|
||||
res = res * 31 + value.hashCode()
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
fun IrConstantArray.contentEquals(other: IrConstantValue): Boolean =
|
||||
other is IrConstantArray &&
|
||||
other.type == type &&
|
||||
elements.size == other.elements.size &&
|
||||
elements.indices.all { elements[it].contentEquals(other.elements[it]) }
|
||||
|
||||
fun IrConstantArray.contentHashCode(): Int {
|
||||
var res = type.hashCode()
|
||||
for (value in elements) {
|
||||
res = res * 31 + value.contentHashCode()
|
||||
}
|
||||
return res
|
||||
}
|
||||
@@ -951,27 +951,9 @@ object IrTree : AbstractTreeBuilder() {
|
||||
}
|
||||
val constantValue: Element by element(Expression) {
|
||||
transformByChildren = true
|
||||
kind = ImplementationKind.SealedClass
|
||||
|
||||
parent(expression)
|
||||
|
||||
generationCallback = {
|
||||
println()
|
||||
printFunctionDeclaration(
|
||||
name = "contentEquals",
|
||||
parameters = listOf(FunctionParameter("other", constantValue)),
|
||||
returnType = StandardTypes.boolean,
|
||||
modality = Modality.ABSTRACT,
|
||||
)
|
||||
println()
|
||||
println()
|
||||
printFunctionDeclaration(
|
||||
name = "contentHashCode",
|
||||
parameters = emptyList(),
|
||||
returnType = StandardTypes.int,
|
||||
modality = Modality.ABSTRACT,
|
||||
)
|
||||
println()
|
||||
}
|
||||
}
|
||||
val constantPrimitive: Element by element(Expression) {
|
||||
parent(constantValue)
|
||||
|
||||
Reference in New Issue
Block a user