Interop/StubGenerator: fix some bugs related to typedef
This commit is contained in:
committed by
SvyatoslavScherbina
parent
54b8b5f3a3
commit
498c33a4e0
+9
-8
@@ -345,7 +345,7 @@ class StubGenerator(
|
|||||||
|
|
||||||
is PointerType -> {
|
is PointerType -> {
|
||||||
val pointeeType = type.pointeeType
|
val pointeeType = type.pointeeType
|
||||||
if (pointeeType is VoidType) {
|
if (pointeeType.unwrapTypedefs() is VoidType) {
|
||||||
val info = TypeInfo.Pointer("COpaque")
|
val info = TypeInfo.Pointer("COpaque")
|
||||||
TypeMirror.ByValue("COpaquePointerVar", info, "COpaquePointer")
|
TypeMirror.ByValue("COpaquePointerVar", info, "COpaquePointer")
|
||||||
} else if (pointeeType is FunctionType) {
|
} else if (pointeeType is FunctionType) {
|
||||||
@@ -438,7 +438,7 @@ class StubGenerator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getCallbackRetValBinding(type: Type): OutValueBinding {
|
fun getCallbackRetValBinding(type: Type): OutValueBinding {
|
||||||
if (type is VoidType) {
|
if (type.unwrapTypedefs() is VoidType) {
|
||||||
return OutValueBinding(
|
return OutValueBinding(
|
||||||
kotlinType = "Unit",
|
kotlinType = "Unit",
|
||||||
kotlinConv = { throw UnsupportedOperationException() },
|
kotlinConv = { throw UnsupportedOperationException() },
|
||||||
@@ -468,7 +468,7 @@ class StubGenerator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getCFunctionRetValBinding(type: Type): InValueBinding {
|
fun getCFunctionRetValBinding(type: Type): InValueBinding {
|
||||||
when (type) {
|
when (type.unwrapTypedefs()) {
|
||||||
is VoidType -> return InValueBinding("Unit")
|
is VoidType -> return InValueBinding("Unit")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -610,7 +610,7 @@ class StubGenerator(
|
|||||||
}.toMutableList()
|
}.toMutableList()
|
||||||
|
|
||||||
val retValType = func.returnType
|
val retValType = func.returnType
|
||||||
if (retValType is RecordType) {
|
if (retValType.unwrapTypedefs() is RecordType) {
|
||||||
val retValMirror = mirror(retValType)
|
val retValMirror = mirror(retValType)
|
||||||
|
|
||||||
paramBindings.add(OutValueBinding(
|
paramBindings.add(OutValueBinding(
|
||||||
@@ -636,7 +636,7 @@ class StubGenerator(
|
|||||||
}
|
}
|
||||||
}.toMutableList()
|
}.toMutableList()
|
||||||
|
|
||||||
if (func.returnType is RecordType) {
|
if (func.returnType.unwrapTypedefs() is RecordType) {
|
||||||
paramNames.add("retValPlacement")
|
paramNames.add("retValPlacement")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -730,11 +730,12 @@ class StubGenerator(
|
|||||||
}
|
}
|
||||||
getFfiStructType(def.fields.map { it.type })
|
getFfiStructType(def.fields.map { it.type })
|
||||||
}
|
}
|
||||||
|
is Typedef -> getFfiType(type.def.aliased)
|
||||||
else -> throw NotImplementedError(type.toString())
|
else -> throw NotImplementedError(type.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getArgFfiType(type: Type) = when (type) {
|
private fun getArgFfiType(type: Type) = when (type.unwrapTypedefs()) {
|
||||||
is ArrayType -> "Pointer"
|
is ArrayType -> "Pointer"
|
||||||
else -> getFfiType(type)
|
else -> getFfiType(type)
|
||||||
}
|
}
|
||||||
@@ -773,7 +774,7 @@ class StubGenerator(
|
|||||||
val args = type.parameterTypes.mapIndexed { i, paramType ->
|
val args = type.parameterTypes.mapIndexed { i, paramType ->
|
||||||
val pointedTypeName = mirror(paramType).pointedTypeName
|
val pointedTypeName = mirror(paramType).pointedTypeName
|
||||||
val ref = "args[$i].value!!.reinterpret<$pointedTypeName>().pointed"
|
val ref = "args[$i].value!!.reinterpret<$pointedTypeName>().pointed"
|
||||||
when (paramType) {
|
when (paramType.unwrapTypedefs()) {
|
||||||
is RecordType -> ref
|
is RecordType -> ref
|
||||||
else -> "$ref.value"
|
else -> "$ref.value"
|
||||||
}
|
}
|
||||||
@@ -781,7 +782,7 @@ class StubGenerator(
|
|||||||
|
|
||||||
out("val res = function($args)")
|
out("val res = function($args)")
|
||||||
|
|
||||||
when (type.returnType) {
|
when (type.returnType.unwrapTypedefs()) {
|
||||||
is RecordType -> throw NotImplementedError()
|
is RecordType -> throw NotImplementedError()
|
||||||
is VoidType -> {} // nothing to do
|
is VoidType -> {} // nothing to do
|
||||||
else -> {
|
else -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user