[Psi2Ir, Fir2Ir] Generate toString, hashCode, equals methods for MF VC
This commit is contained in:
committed by
Space
parent
c7edc353d3
commit
e97ca2ada4
+2
-2
@@ -17,7 +17,7 @@ class IrClassBuilder : IrDeclarationBuilder() {
|
||||
var isInner: Boolean = false
|
||||
var isData: Boolean = false
|
||||
var isExternal: Boolean = false
|
||||
var isInline: Boolean = false
|
||||
var isValue: Boolean = false
|
||||
var isExpect: Boolean = false
|
||||
var isFun: Boolean = false
|
||||
|
||||
@@ -30,7 +30,7 @@ class IrClassBuilder : IrDeclarationBuilder() {
|
||||
isInner = from.isInner
|
||||
isData = from.isData
|
||||
isExternal = from.isExternal
|
||||
isInline = from.isInline
|
||||
isValue = from.isValue
|
||||
isExpect = from.isExpect
|
||||
isFun = from.isFun
|
||||
}
|
||||
|
||||
@@ -21,8 +21,9 @@ import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.transformInPlace
|
||||
import org.jetbrains.kotlin.ir.util.primaryConstructor
|
||||
import org.jetbrains.kotlin.ir.util.transformIfNeeded
|
||||
import org.jetbrains.kotlin.ir.util.transformInPlace
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
|
||||
@@ -39,7 +40,7 @@ abstract class IrClass :
|
||||
abstract val isCompanion: Boolean
|
||||
abstract val isInner: Boolean
|
||||
abstract val isData: Boolean
|
||||
abstract val isInline: Boolean
|
||||
abstract val isValue: Boolean
|
||||
abstract val isExpect: Boolean
|
||||
abstract val isFun: Boolean
|
||||
|
||||
@@ -69,6 +70,12 @@ abstract class IrClass :
|
||||
}
|
||||
}
|
||||
|
||||
val IrClass.isSingleFieldValueClass
|
||||
get() = this.isValue && (this.inlineClassRepresentation != null || this.primaryConstructor?.valueParameters?.size == 1)
|
||||
|
||||
val IrClass.isMultiFieldValueClass
|
||||
get() = this.isValue && !isSingleFieldValueClass
|
||||
|
||||
fun IrClass.addMember(member: IrDeclaration) {
|
||||
declarations.add(member)
|
||||
}
|
||||
|
||||
@@ -49,7 +49,8 @@ interface IrDeclarationOrigin {
|
||||
object SCRIPT_PROVIDED_PROPERTY : IrDeclarationOriginImpl("SCRIPT_PROVIDED_PROPERTY")
|
||||
object SCRIPT_RESULT_PROPERTY : IrDeclarationOriginImpl("SCRIPT_RESULT_PROPERTY")
|
||||
object GENERATED_DATA_CLASS_MEMBER : IrDeclarationOriginImpl("GENERATED_DATA_CLASS_MEMBER")
|
||||
object GENERATED_INLINE_CLASS_MEMBER : IrDeclarationOriginImpl("GENERATED_INLINE_CLASS_MEMBER")
|
||||
object GENERATED_SINGLE_FIELD_VALUE_CLASS_MEMBER : IrDeclarationOriginImpl("GENERATED_SINGLE_FIELD_VALUE_CLASS_MEMBER")
|
||||
object GENERATED_MULTI_FIELD_VALUE_CLASS_MEMBER : IrDeclarationOriginImpl("GENERATED_MULTI_FIELD_VALUE_CLASS_MEMBER")
|
||||
object LOCAL_FUNCTION : IrDeclarationOriginImpl("LOCAL_FUNCTION")
|
||||
object LOCAL_FUNCTION_FOR_LAMBDA : IrDeclarationOriginImpl("LOCAL_FUNCTION_FOR_LAMBDA")
|
||||
object CATCH_PARAMETER : IrDeclarationOriginImpl("CATCH_PARAMETER")
|
||||
|
||||
@@ -40,7 +40,7 @@ interface IrFactory {
|
||||
isInner: Boolean = false,
|
||||
isData: Boolean = false,
|
||||
isExternal: Boolean = false,
|
||||
isInline: Boolean = false,
|
||||
isValue: Boolean = false,
|
||||
isExpect: Boolean = false,
|
||||
isFun: Boolean = false,
|
||||
source: SourceElement = SourceElement.NO_SOURCE,
|
||||
|
||||
@@ -33,7 +33,7 @@ class IrLazyClass(
|
||||
override val isInner: Boolean,
|
||||
override val isData: Boolean,
|
||||
override val isExternal: Boolean,
|
||||
override val isInline: Boolean,
|
||||
override val isValue: Boolean,
|
||||
override val isExpect: Boolean,
|
||||
override val isFun: Boolean,
|
||||
override val stubGenerator: DeclarationStubGenerator,
|
||||
|
||||
@@ -33,7 +33,7 @@ class LazyIrFactory(
|
||||
isInner: Boolean,
|
||||
isData: Boolean,
|
||||
isExternal: Boolean,
|
||||
isInline: Boolean,
|
||||
isValue: Boolean,
|
||||
isExpect: Boolean,
|
||||
isFun: Boolean,
|
||||
source: SourceElement
|
||||
@@ -42,7 +42,7 @@ class LazyIrFactory(
|
||||
else
|
||||
delegate.createClass(
|
||||
startOffset, endOffset, origin, symbol, name, kind, visibility, modality,
|
||||
isCompanion, isInner, isData, isExternal, isInline, isExpect, isFun, source
|
||||
isCompanion, isInner, isData, isExternal, isValue, isExpect, isFun, source
|
||||
)
|
||||
|
||||
override fun createConstructor(
|
||||
|
||||
@@ -604,12 +604,11 @@ open class IrBasedClassDescriptor(owner: IrClass) : ClassDescriptor, IrBasedDecl
|
||||
|
||||
override fun isData() = owner.isData
|
||||
|
||||
override fun isInline() = owner.isInline
|
||||
override fun isInline() = owner.isSingleFieldValueClass
|
||||
|
||||
override fun isFun() = owner.isFun
|
||||
|
||||
// In IR, inline and value are synonyms
|
||||
override fun isValue() = owner.isInline
|
||||
override fun isValue() = owner.isValue
|
||||
|
||||
override fun getThisAsReceiverParameter() = owner.thisReceiver?.toIrBasedDescriptor() as ReceiverParameterDescriptor
|
||||
|
||||
|
||||
@@ -457,7 +457,7 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
|
||||
this as? IrTypeParameterSymbol
|
||||
|
||||
override fun TypeConstructorMarker.isInlineClass(): Boolean =
|
||||
(this as? IrClassSymbol)?.owner?.isInline == true
|
||||
(this as? IrClassSymbol)?.owner?.isSingleFieldValueClass == true
|
||||
|
||||
override fun TypeConstructorMarker.isInnerClass(): Boolean =
|
||||
(this as? IrClassSymbol)?.owner?.isInner == true
|
||||
|
||||
@@ -128,7 +128,7 @@ abstract class DataClassMembersGenerator(
|
||||
fun generateEqualsMethodBody(properties: List<IrProperty>) {
|
||||
val irType = irClass.defaultType
|
||||
|
||||
if (!irClass.isInline) {
|
||||
if (!irClass.isSingleFieldValueClass) {
|
||||
+irIfThenReturnTrue(irEqeqeq(irThis(), irOther()))
|
||||
}
|
||||
+irIfThenReturnFalse(irNotIs(irOther(), irType))
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.resolve.isInlineClass
|
||||
import org.jetbrains.kotlin.resolve.isInlineOrValueClass
|
||||
import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
@@ -269,7 +269,7 @@ abstract class DeclarationStubGenerator(
|
||||
isInner = descriptor.isInner,
|
||||
isData = descriptor.isData,
|
||||
isExternal = descriptor.isEffectivelyExternal(),
|
||||
isInline = descriptor.isInlineClass(),
|
||||
isValue = descriptor.isInlineOrValueClass(),
|
||||
isExpect = descriptor.isExpect,
|
||||
isFun = descriptor.isFun,
|
||||
stubGenerator = this,
|
||||
|
||||
@@ -147,7 +147,7 @@ open class DeepCopyIrTreeWithSymbols(
|
||||
isInner = declaration.isInner,
|
||||
isData = declaration.isData,
|
||||
isExternal = declaration.isExternal,
|
||||
isInline = declaration.isInline,
|
||||
isValue = declaration.isValue,
|
||||
isExpect = declaration.isExpect,
|
||||
isFun = declaration.isFun
|
||||
).apply {
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.jetbrains.kotlin.ir.declarations.IrFactory
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.resolve.isInlineClass
|
||||
import org.jetbrains.kotlin.resolve.isInlineOrValueClass
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
val ParameterDescriptor.indexOrMinusOne: Int
|
||||
@@ -39,5 +39,5 @@ fun IrFactory.createIrClassFromDescriptor(
|
||||
): IrClass = createClass(
|
||||
startOffset, endOffset, origin, symbol, name, descriptor.kind, visibility, modality,
|
||||
descriptor.isCompanionObject, descriptor.isInner, descriptor.isData, descriptor.isEffectivelyExternal(),
|
||||
descriptor.isInlineClass(), descriptor.isExpect, descriptor.isFun, descriptor.source
|
||||
descriptor.isInlineOrValueClass(), descriptor.isExpect, descriptor.isFun, descriptor.source
|
||||
)
|
||||
|
||||
@@ -475,7 +475,7 @@ class RenderIrElementVisitor(private val normalizeNames: Boolean = false, privat
|
||||
"inner".takeIf { isInner },
|
||||
"data".takeIf { isData },
|
||||
"external".takeIf { isExternal },
|
||||
"inline".takeIf { isInline },
|
||||
"value".takeIf { isValue },
|
||||
"expect".takeIf { isExpect },
|
||||
"fun".takeIf { isFun }
|
||||
)
|
||||
|
||||
@@ -194,7 +194,8 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
||||
isVararg = INAPPLICABLE,
|
||||
isSuspend = INAPPLICABLE,
|
||||
isInner,
|
||||
isInline,
|
||||
isInline = false,
|
||||
isValue,
|
||||
isData,
|
||||
isCompanion,
|
||||
isFun,
|
||||
@@ -254,6 +255,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
||||
enum / annotation / fun // as a modifier in `fun interface`
|
||||
companion
|
||||
inline
|
||||
value
|
||||
infix
|
||||
operator
|
||||
data
|
||||
@@ -271,6 +273,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
||||
isSuspend: Boolean,
|
||||
isInner: Boolean,
|
||||
isInline: Boolean,
|
||||
isValue: Boolean,
|
||||
isData: Boolean,
|
||||
isCompanion: Boolean,
|
||||
isFunInterface: Boolean,
|
||||
@@ -305,6 +308,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
||||
p(isSuspend, "suspend")
|
||||
p(isInner, "inner")
|
||||
p(isInline, "inline")
|
||||
p(isValue, "value")
|
||||
p(isData, "data")
|
||||
p(isCompanion, "companion")
|
||||
p(isFunInterface, "fun")
|
||||
@@ -542,6 +546,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
||||
isSuspend = INAPPLICABLE,
|
||||
isInner = INAPPLICABLE,
|
||||
isInline,
|
||||
isValue = INAPPLICABLE,
|
||||
isData = INAPPLICABLE,
|
||||
isCompanion = INAPPLICABLE,
|
||||
isFunInterface = INAPPLICABLE,
|
||||
@@ -597,6 +602,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
||||
isSuspend,
|
||||
isInner = INAPPLICABLE,
|
||||
isInline,
|
||||
isValue = INAPPLICABLE,
|
||||
isData = INAPPLICABLE,
|
||||
isCompanion = INAPPLICABLE,
|
||||
isFunInterface = INAPPLICABLE,
|
||||
@@ -707,8 +713,9 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
||||
isVararg = INAPPLICABLE,
|
||||
isSuspend = getter?.isSuspend == true,
|
||||
isInner = INAPPLICABLE,
|
||||
// could be used on property if all all accessors have same state, otherwise must be defined on each accessor
|
||||
// could be used on property if all accessors have same state, otherwise must be defined on each accessor
|
||||
isInline = false,
|
||||
isValue = INAPPLICABLE,
|
||||
isData = INAPPLICABLE,
|
||||
isCompanion = INAPPLICABLE,
|
||||
isFunInterface = INAPPLICABLE,
|
||||
@@ -797,6 +804,7 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
||||
isSuspend = INAPPLICABLE,
|
||||
isInner = INAPPLICABLE,
|
||||
isInline = INAPPLICABLE,
|
||||
isValue = INAPPLICABLE,
|
||||
isData = INAPPLICABLE,
|
||||
isCompanion = INAPPLICABLE,
|
||||
isFunInterface = INAPPLICABLE,
|
||||
|
||||
Reference in New Issue
Block a user