Print callable reference as value parameter
This commit is contained in:
committed by
KonstantinAnisimov
parent
531540c8d3
commit
f70835fc29
@@ -133,9 +133,10 @@ class PackageFragmentPrinter(val packageFragment: KonanLinkData.PackageFragment,
|
|||||||
val annotations = protoFunction.getExtension(KonanSerializerProtocol.functionAnnotation)
|
val annotations = protoFunction.getExtension(KonanSerializerProtocol.functionAnnotation)
|
||||||
val typeParameters = typeParametersToString(protoFunction.typeParameterList)
|
val typeParameters = typeParametersToString(protoFunction.typeParameterList)
|
||||||
val valueParameters = valueParametersToString(protoFunction.valueParameterList)
|
val valueParameters = valueParametersToString(protoFunction.valueParameterList)
|
||||||
|
val returnType = typeToString(protoFunction.returnTypeId)
|
||||||
|
|
||||||
printAnnotations(annotations)
|
printAnnotations(annotations)
|
||||||
printer.println("$visibility${isInline}fun $typeParameters$receiverType$name$valueParameters")
|
printer.println("$visibility${isInline}fun $typeParameters$receiverType$name$valueParameters: $returnType")
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
@@ -434,8 +435,9 @@ class PackageFragmentPrinter(val packageFragment: KonanLinkData.PackageFragment,
|
|||||||
|
|
||||||
fun typeToString(typeId: Int): String {
|
fun typeToString(typeId: Int): String {
|
||||||
val type = typeTable!!.getType(typeId)
|
val type = typeTable!!.getType(typeId)
|
||||||
val buff = StringBuilder(typeName(type))
|
if (isCallableType(type)) return callableTypeToString(type)
|
||||||
|
|
||||||
|
val buff = StringBuilder(typeName(type))
|
||||||
val argumentList = type.argumentList
|
val argumentList = type.argumentList
|
||||||
if (argumentList.isNotEmpty()) {
|
if (argumentList.isNotEmpty()) {
|
||||||
buff.append("<")
|
buff.append("<")
|
||||||
@@ -452,6 +454,24 @@ class PackageFragmentPrinter(val packageFragment: KonanLinkData.PackageFragment,
|
|||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
fun isCallableType(type: ProtoBuf.Type) = typeName(type).contains("Function")
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
fun callableTypeToString(callableType: ProtoBuf.Type): String {
|
||||||
|
val buff = StringBuilder("(")
|
||||||
|
val argumentTypes = callableType.argumentList.dropLast(1)
|
||||||
|
val returnType = callableType.argumentList.lastOrNull()
|
||||||
|
|
||||||
|
argumentTypes.dropLast(1).forEach { buff.append("${typeToString(it.typeId)}, ") }
|
||||||
|
argumentTypes.lastOrNull()?.let { buff.append(typeToString(it.typeId)) }
|
||||||
|
buff.append(") -> ")
|
||||||
|
if (returnType != null) buff.append(typeToString(returnType.typeId))
|
||||||
|
return buff.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
fun typeName(type: ProtoBuf.Type): String {
|
fun typeName(type: ProtoBuf.Type): String {
|
||||||
var typeName = "undefined"
|
var typeName = "undefined"
|
||||||
if (type.hasClassName()) {
|
if (type.hasClassName()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user