[Interop][StubIr] Add origin to PropertyStub
This commit is contained in:
committed by
Sergey Bogolepov
parent
cd07dec326
commit
a4486de7fa
+2
-1
@@ -574,7 +574,8 @@ private class ObjCPropertyStubBuilder(
|
|||||||
is ObjCClassOrProtocol -> null
|
is ObjCClassOrProtocol -> null
|
||||||
is ObjCCategory -> ClassifierStubType(context.getKotlinClassFor(container.clazz, isMeta = property.getter.isClass))
|
is ObjCCategory -> ClassifierStubType(context.getKotlinClassFor(container.clazz, isMeta = property.getter.isClass))
|
||||||
}
|
}
|
||||||
return listOf(PropertyStub(property.name, kotlinType.toStubIrType(), kind, modality, receiver))
|
val origin = StubOrigin.ObjCProperty(property, container)
|
||||||
|
return listOf(PropertyStub(property.name, kotlinType.toStubIrType(), kind, modality, receiver, origin = origin))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-1
@@ -88,6 +88,11 @@ sealed class StubOrigin {
|
|||||||
val container: ObjCContainer
|
val container: ObjCContainer
|
||||||
) : StubOrigin()
|
) : StubOrigin()
|
||||||
|
|
||||||
|
class ObjCProperty(
|
||||||
|
val property: org.jetbrains.kotlin.native.interop.indexer.ObjCProperty,
|
||||||
|
val container: ObjCContainer
|
||||||
|
) : StubOrigin()
|
||||||
|
|
||||||
class ObjCClass(
|
class ObjCClass(
|
||||||
val clazz: org.jetbrains.kotlin.native.interop.indexer.ObjCClass
|
val clazz: org.jetbrains.kotlin.native.interop.indexer.ObjCClass
|
||||||
) : StubOrigin()
|
) : StubOrigin()
|
||||||
@@ -103,6 +108,10 @@ sealed class StubOrigin {
|
|||||||
class FunctionParameter(val parameter: Parameter) : StubOrigin()
|
class FunctionParameter(val parameter: Parameter) : StubOrigin()
|
||||||
|
|
||||||
class Struct(val struct: StructDecl) : StubOrigin()
|
class Struct(val struct: StructDecl) : StubOrigin()
|
||||||
|
|
||||||
|
class Constant(val constantDef: ConstantDef): StubOrigin()
|
||||||
|
|
||||||
|
class Global(val global: GlobalDecl) : StubOrigin()
|
||||||
}
|
}
|
||||||
|
|
||||||
interface StubElementWithOrigin : StubIrElement {
|
interface StubElementWithOrigin : StubIrElement {
|
||||||
@@ -178,7 +187,8 @@ class PropertyStub(
|
|||||||
val kind: Kind,
|
val kind: Kind,
|
||||||
val modality: MemberStubModality = MemberStubModality.FINAL,
|
val modality: MemberStubModality = MemberStubModality.FINAL,
|
||||||
val receiverType: StubType? = null,
|
val receiverType: StubType? = null,
|
||||||
override val annotations: List<AnnotationStub> = emptyList()
|
override val annotations: List<AnnotationStub> = emptyList(),
|
||||||
|
val origin: StubOrigin
|
||||||
) : StubIrElement, AnnotationHolder {
|
) : StubIrElement, AnnotationHolder {
|
||||||
sealed class Kind {
|
sealed class Kind {
|
||||||
class Val(
|
class Val(
|
||||||
|
|||||||
+14
-10
@@ -13,16 +13,17 @@ internal class MacroConstantStubBuilder(
|
|||||||
) : StubElementBuilder {
|
) : StubElementBuilder {
|
||||||
override fun build(): List<StubIrElement> {
|
override fun build(): List<StubIrElement> {
|
||||||
val kotlinName = constant.name
|
val kotlinName = constant.name
|
||||||
|
val origin = StubOrigin.Constant(constant)
|
||||||
val declaration = when (constant) {
|
val declaration = when (constant) {
|
||||||
is IntegerConstantDef -> {
|
is IntegerConstantDef -> {
|
||||||
val literal = context.tryCreateIntegralStub(constant.type, constant.value) ?: return emptyList()
|
val literal = context.tryCreateIntegralStub(constant.type, constant.value) ?: return emptyList()
|
||||||
val kotlinType = context.mirror(constant.type).argType.toStubIrType()
|
val kotlinType = context.mirror(constant.type).argType.toStubIrType()
|
||||||
when (context.platform) {
|
when (context.platform) {
|
||||||
KotlinPlatform.NATIVE -> PropertyStub(kotlinName, kotlinType, PropertyStub.Kind.Constant(literal))
|
KotlinPlatform.NATIVE -> PropertyStub(kotlinName, kotlinType, PropertyStub.Kind.Constant(literal), origin = origin)
|
||||||
// No reason to make it const val with backing field on Kotlin/JVM yet:
|
// No reason to make it const val with backing field on Kotlin/JVM yet:
|
||||||
KotlinPlatform.JVM -> {
|
KotlinPlatform.JVM -> {
|
||||||
val getter = PropertyAccessor.Getter.SimpleGetter(constant = literal)
|
val getter = PropertyAccessor.Getter.SimpleGetter(constant = literal)
|
||||||
PropertyStub(kotlinName, kotlinType, PropertyStub.Kind.Val(getter))
|
PropertyStub(kotlinName, kotlinType, PropertyStub.Kind.Val(getter), origin = origin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,13 +31,13 @@ internal class MacroConstantStubBuilder(
|
|||||||
val literal = context.tryCreateDoubleStub(constant.type, constant.value) ?: return emptyList()
|
val literal = context.tryCreateDoubleStub(constant.type, constant.value) ?: return emptyList()
|
||||||
val kotlinType = context.mirror(constant.type).argType.toStubIrType()
|
val kotlinType = context.mirror(constant.type).argType.toStubIrType()
|
||||||
val getter = PropertyAccessor.Getter.SimpleGetter(constant = literal)
|
val getter = PropertyAccessor.Getter.SimpleGetter(constant = literal)
|
||||||
PropertyStub(kotlinName, kotlinType, PropertyStub.Kind.Val(getter))
|
PropertyStub(kotlinName, kotlinType, PropertyStub.Kind.Val(getter), origin = origin)
|
||||||
}
|
}
|
||||||
is StringConstantDef -> {
|
is StringConstantDef -> {
|
||||||
val literal = StringConstantStub(constant.value.quoteAsKotlinLiteral())
|
val literal = StringConstantStub(constant.value.quoteAsKotlinLiteral())
|
||||||
val kotlinType = KotlinTypes.string.toStubIrType()
|
val kotlinType = KotlinTypes.string.toStubIrType()
|
||||||
val getter = PropertyAccessor.Getter.SimpleGetter(constant = literal)
|
val getter = PropertyAccessor.Getter.SimpleGetter(constant = literal)
|
||||||
PropertyStub(kotlinName, kotlinType, PropertyStub.Kind.Val(getter))
|
PropertyStub(kotlinName, kotlinType, PropertyStub.Kind.Val(getter), origin = origin)
|
||||||
}
|
}
|
||||||
else -> return emptyList()
|
else -> return emptyList()
|
||||||
}
|
}
|
||||||
@@ -72,6 +73,7 @@ internal class StructStubBuilder(
|
|||||||
val offset = field.offset / 8
|
val offset = field.offset / 8
|
||||||
val fieldRefType = context.mirror(field.type)
|
val fieldRefType = context.mirror(field.type)
|
||||||
val unwrappedFieldType = field.type.unwrapTypedefs()
|
val unwrappedFieldType = field.type.unwrapTypedefs()
|
||||||
|
val origin = StubOrigin.None
|
||||||
if (unwrappedFieldType is ArrayType) {
|
if (unwrappedFieldType is ArrayType) {
|
||||||
val type = (fieldRefType as TypeMirror.ByValue).valueType
|
val type = (fieldRefType as TypeMirror.ByValue).valueType
|
||||||
val annotations = if (platform == KotlinPlatform.JVM) {
|
val annotations = if (platform == KotlinPlatform.JVM) {
|
||||||
@@ -83,7 +85,7 @@ internal class StructStubBuilder(
|
|||||||
}
|
}
|
||||||
val kind = PropertyStub.Kind.Val(PropertyAccessor.Getter.ArrayMemberAt(offset))
|
val kind = PropertyStub.Kind.Val(PropertyAccessor.Getter.ArrayMemberAt(offset))
|
||||||
// TODO: Should receiver be added?
|
// TODO: Should receiver be added?
|
||||||
PropertyStub(field.name, type.toStubIrType(), kind, annotations = annotations)
|
PropertyStub(field.name, type.toStubIrType(), kind, annotations = annotations, origin = origin)
|
||||||
} else {
|
} else {
|
||||||
val pointedType = fieldRefType.pointedType.toStubIrType()
|
val pointedType = fieldRefType.pointedType.toStubIrType()
|
||||||
val pointedTypeArgument = TypeArgumentStub(pointedType)
|
val pointedTypeArgument = TypeArgumentStub(pointedType)
|
||||||
@@ -92,10 +94,10 @@ internal class StructStubBuilder(
|
|||||||
PropertyAccessor.Getter.MemberAt(offset, typeArguments = listOf(pointedTypeArgument), hasValueAccessor = true),
|
PropertyAccessor.Getter.MemberAt(offset, typeArguments = listOf(pointedTypeArgument), hasValueAccessor = true),
|
||||||
PropertyAccessor.Setter.MemberAt(offset, typeArguments = listOf(pointedTypeArgument))
|
PropertyAccessor.Setter.MemberAt(offset, typeArguments = listOf(pointedTypeArgument))
|
||||||
)
|
)
|
||||||
PropertyStub(field.name, fieldRefType.argType.toStubIrType(), kind)
|
PropertyStub(field.name, fieldRefType.argType.toStubIrType(), kind, origin = origin)
|
||||||
} else {
|
} else {
|
||||||
val kind = PropertyStub.Kind.Val(PropertyAccessor.Getter.MemberAt(offset, hasValueAccessor = false))
|
val kind = PropertyStub.Kind.Val(PropertyAccessor.Getter.MemberAt(offset, hasValueAccessor = false))
|
||||||
PropertyStub(field.name, pointedType, kind)
|
PropertyStub(field.name, pointedType, kind, origin = origin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
@@ -113,7 +115,7 @@ internal class StructStubBuilder(
|
|||||||
context.bridgeComponentsBuilder.getterToBridgeInfo[readBits] = BridgeGenerationInfo("", typeInfo)
|
context.bridgeComponentsBuilder.getterToBridgeInfo[readBits] = BridgeGenerationInfo("", typeInfo)
|
||||||
context.bridgeComponentsBuilder.setterToBridgeInfo[writeBits] = BridgeGenerationInfo("", typeInfo)
|
context.bridgeComponentsBuilder.setterToBridgeInfo[writeBits] = BridgeGenerationInfo("", typeInfo)
|
||||||
val kind = PropertyStub.Kind.Var(readBits, writeBits)
|
val kind = PropertyStub.Kind.Var(readBits, writeBits)
|
||||||
PropertyStub(field.name, kotlinType.toStubIrType(), kind)
|
PropertyStub(field.name, kotlinType.toStubIrType(), kind, origin = StubOrigin.None)
|
||||||
}
|
}
|
||||||
|
|
||||||
val superClass = context.platform.getRuntimeType("CStructVar")
|
val superClass = context.platform.getRuntimeType("CStructVar")
|
||||||
@@ -276,7 +278,8 @@ internal class EnumStubBuilder(
|
|||||||
kotlinType.toStubIrType(),
|
kotlinType.toStubIrType(),
|
||||||
kind,
|
kind,
|
||||||
MemberStubModality.FINAL,
|
MemberStubModality.FINAL,
|
||||||
null
|
null,
|
||||||
|
origin = StubOrigin.None
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val container = SimpleStubContainer(
|
val container = SimpleStubContainer(
|
||||||
@@ -436,6 +439,7 @@ internal class GlobalStubBuilder(
|
|||||||
override fun build(): List<StubIrElement> {
|
override fun build(): List<StubIrElement> {
|
||||||
val mirror = context.mirror(global.type)
|
val mirror = context.mirror(global.type)
|
||||||
val unwrappedType = global.type.unwrapTypedefs()
|
val unwrappedType = global.type.unwrapTypedefs()
|
||||||
|
val origin = StubOrigin.Global(global)
|
||||||
|
|
||||||
val kotlinType: KotlinType
|
val kotlinType: KotlinType
|
||||||
val kind: PropertyStub.Kind
|
val kind: PropertyStub.Kind
|
||||||
@@ -490,7 +494,7 @@ internal class GlobalStubBuilder(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return listOf(PropertyStub(global.name, kotlinType.toStubIrType(), kind))
|
return listOf(PropertyStub(global.name, kotlinType.toStubIrType(), kind, origin = origin))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user