Rework Objective-C constructors and support 'initBy' intrinsic

This commit is contained in:
Svyatoslav Scherbina
2017-08-29 13:33:01 +03:00
committed by SvyatoslavScherbina
parent 5a7e3e20b4
commit 07f26dc1df
6 changed files with 65 additions and 7 deletions
@@ -51,8 +51,17 @@ class ObjCPointerHolder(inline val rawPtr: NativePtr) {
@konan.internal.ExportForCompiler
private external fun ObjCObject.initFromPtr(ptr: NativePtr)
@konan.internal.Intrinsic
external fun <T : ObjCObjectBase> T.initBy(constructorCall: T): T
@konan.internal.ExportForCompiler
private fun ObjCObject.initFrom(other: ObjCObject?) = this.initFromPtr(other!!.rawPtr)
private fun ObjCObjectBase.superInitCheck(superInitCallResult: ObjCObject?) {
if (superInitCallResult == null)
throw RuntimeException("Super initialization failed")
if (superInitCallResult.rawPtr != this.rawPtr)
throw UnsupportedOperationException("Super initializer has replaced object")
}
fun <T : Any?> Any?.uncheckedCast(): T = @Suppress("UNCHECKED_CAST") (this as T) // TODO: make private
@@ -421,7 +421,7 @@ val ObjCClassOrProtocol.kotlinName: String get() = when (this) {
}
private val ObjCClass.baseClassName: String
get() = baseClass?.name ?: "ObjCObject"
get() = baseClass?.name ?: "ObjCObjectBase"
private fun Parameter.getTypeStringRepresentation() =
(if (this.nsConsumed) "__attribute__((ns_consumed)) " else "") + type.getStringRepresentation()