Refactor AnnotationImplementationLowering
- Replaced UNDEFINED_OFFSET with SYNTHETIC_OFFSET, it's required by Native backend codegen - Fixed missing overridden symbols - Enforce adding fakeoverrides for members not overridden by backend - Support more points for platform customisation
This commit is contained in:
+15
-19
@@ -11,9 +11,11 @@ import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||
import org.jetbrains.kotlin.ir.builders.IrBlockBodyBuilder
|
||||
import org.jetbrains.kotlin.ir.builders.irCall
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.isArray
|
||||
@@ -38,9 +40,8 @@ class JsAnnotationImplementationTransformer(val jsContext: JsIrBackendContext) :
|
||||
|
||||
override fun visitClassNew(declaration: IrClass): IrClass {
|
||||
if (!declaration.isAnnotationClass) return declaration
|
||||
val properties = declaration.getAnnotationProperties()
|
||||
context.irFactory.stageController.unrestrictDeclarationListsAccess {
|
||||
implementEqualsAndHashCode(declaration, declaration, properties, properties)
|
||||
implementGeneratedFunctions(declaration, declaration)
|
||||
}
|
||||
return declaration
|
||||
}
|
||||
@@ -48,22 +49,17 @@ class JsAnnotationImplementationTransformer(val jsContext: JsIrBackendContext) :
|
||||
private val arraysContentEquals: Map<IrType, IrSimpleFunctionSymbol> =
|
||||
requireNotNull(jsContext.ir.symbols.arraysContentEquals) { "contentEquals symbols should be defined in JS IR context" }
|
||||
|
||||
override fun generatedEquals(irBuilder: IrBlockBodyBuilder, type: IrType, arg1: IrExpression, arg2: IrExpression): IrExpression {
|
||||
return if (type.isArray() || type.isPrimitiveArray()) {
|
||||
val requiredSymbol =
|
||||
if (type.isPrimitiveArray())
|
||||
arraysContentEquals[type]
|
||||
else
|
||||
arraysContentEquals.entries.singleOrNull { (k, _) -> k.isArray() }?.value
|
||||
if (requiredSymbol == null) {
|
||||
error("Can't find an Arrays.contentEquals method for array type ${type.render()}")
|
||||
}
|
||||
irBuilder.irCall(
|
||||
requiredSymbol
|
||||
).apply {
|
||||
extensionReceiver = arg1
|
||||
putValueArgument(0, arg2)
|
||||
}
|
||||
} else super.generatedEquals(irBuilder, type, arg1, arg2)
|
||||
override fun getArrayContentEqualsSymbol(type: IrType) =
|
||||
when {
|
||||
type.isPrimitiveArray() -> arraysContentEquals[type]
|
||||
else -> arraysContentEquals.entries.singleOrNull { (k, _) -> k.isArray() }?.value
|
||||
} ?: error("Can't find an Arrays.contentEquals method for array type ${type.render()}")
|
||||
|
||||
override fun implementAnnotationPropertiesAndConstructor(
|
||||
implClass: IrClass,
|
||||
annotationClass: IrClass,
|
||||
generatedConstructor: IrConstructor
|
||||
) {
|
||||
throw IllegalStateException("Should not be called")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user