[cinterop] Fix mapping of typedefs to pointers to typedefs
Mapping type aliases from stub ir to metadata is kinda tricky. We need to preserve references to type alias declarations when translating expanded types. The problem is that we translate C declarations and types independently. In the most cases these processes are coherent. But not for type aliases to pointers to type aliases. This commit fixes it.
This commit is contained in:
committed by
Sergey Bogolepov
parent
e714f1e067
commit
a194ec18e7
+14
-6
@@ -469,12 +469,20 @@ fun mirror(declarationMapper: DeclarationMapper, type: Type): TypeMirror = when
|
||||
|
||||
val name = type.def.name
|
||||
when (baseType) {
|
||||
is TypeMirror.ByValue -> TypeMirror.ByValue(
|
||||
Classifier.topLevel(pkg, "${name}Var").typeAbbreviation(baseType.pointedType),
|
||||
baseType.info,
|
||||
Classifier.topLevel(pkg, name).typeAbbreviation(baseType.valueType),
|
||||
nullable = baseType.nullable
|
||||
)
|
||||
is TypeMirror.ByValue -> {
|
||||
val valueType = Classifier.topLevel(pkg, name).typeAbbreviation(baseType.valueType)
|
||||
val underlyingPointedType = if (baseType.info is TypeInfo.Pointer) {
|
||||
KotlinTypes.cPointerVarOf.typeWith(valueType)
|
||||
} else {
|
||||
baseType.pointedType
|
||||
}
|
||||
val pointedType = Classifier.topLevel(pkg, "${name}Var").typeAbbreviation(underlyingPointedType)
|
||||
TypeMirror.ByValue(
|
||||
pointedType,
|
||||
baseType.info,
|
||||
valueType,
|
||||
nullable = baseType.nullable)
|
||||
}
|
||||
|
||||
is TypeMirror.ByRef -> TypeMirror.ByRef(
|
||||
Classifier.topLevel(pkg, name).typeAbbreviation(baseType.pointedType),
|
||||
|
||||
Reference in New Issue
Block a user