Move some callable method impl to trait
This commit is contained in:
@@ -46,8 +46,15 @@ public trait Callable {
|
|||||||
|
|
||||||
public fun isStaticCall(): Boolean
|
public fun isStaticCall(): Boolean
|
||||||
|
|
||||||
public fun beforeParameterGeneration(v: InstructionAdapter, value: StackValue?)
|
public fun beforeParameterGeneration(v: InstructionAdapter, value: StackValue?) {
|
||||||
|
|
||||||
public fun invokeMethodWithArguments(resolvedCall: ResolvedCall<*>, receiver: StackValue, returnType: Type, codegen: ExpressionCodegen): StackValue
|
}
|
||||||
|
|
||||||
|
public fun invokeMethodWithArguments(resolvedCall: ResolvedCall<*>, receiver: StackValue, returnType: Type, codegen: ExpressionCodegen): StackValue {
|
||||||
|
return StackValue.functionCall(returnType) {
|
||||||
|
codegen.invokeMethodWithArguments(this, resolvedCall, receiver)
|
||||||
|
StackValue.coerce(this.returnType, returnType, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,33 +40,19 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class CallableMethod(override val owner: Type, private val defaultImplOwner: Type?, private val defaultImplParam: Type?, private val signature: JvmMethodSignature, private val invokeOpcode: Int, override val thisType: Type?, override val receiverType: Type?, override val generateCalleeType: Type?) : Callable {
|
public class CallableMethod(override val owner: Type, private val defaultImplOwner: Type?, private val defaultImplParam: Type?, private val signature: JvmMethodSignature, private val invokeOpcode: Int, override val thisType: Type?, override val receiverType: Type?, override val generateCalleeType: Type?) : Callable {
|
||||||
|
|
||||||
|
|
||||||
public fun getValueParameters(): List<JvmMethodParameterSignature> {
|
public fun getValueParameters(): List<JvmMethodParameterSignature> {
|
||||||
return signature.getValueParameters()
|
return signature.getValueParameters()
|
||||||
}
|
}
|
||||||
|
|
||||||
override val valueParameterTypes: List<Type>
|
override val valueParameterTypes: List<Type>
|
||||||
get() {
|
get() = signature.getValueParameters().filter { it.getKind() == JvmMethodParameterKind.VALUE }.map { it.getAsmType() }
|
||||||
val valueParameters = signature.getValueParameters()
|
|
||||||
val result = ArrayList<Type>(valueParameters.size())
|
|
||||||
for (parameter in valueParameters) {
|
|
||||||
if (parameter.getKind() == JvmMethodParameterKind.VALUE) {
|
|
||||||
result.add(parameter.getAsmType())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun getAsmMethod(): Method {
|
public fun getAsmMethod(): Method {
|
||||||
return signature.getAsmMethod()
|
return signature.getAsmMethod()
|
||||||
}
|
}
|
||||||
|
|
||||||
override val argumentTypes: Array<Type>
|
override val argumentTypes: Array<Type>
|
||||||
get() =signature.getAsmMethod().getArgumentTypes()
|
get() = getAsmMethod().getArgumentTypes()
|
||||||
|
|
||||||
private fun invoke(v: InstructionAdapter) {
|
|
||||||
v.visitMethodInsn(invokeOpcode, owner.getInternalName(), getAsmMethod().getName(), getAsmMethod().getDescriptor())
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public override fun invokeWithNotNullAssertion(v: InstructionAdapter, state: GenerationState, resolvedCall: ResolvedCall<*>) {
|
public override fun invokeWithNotNullAssertion(v: InstructionAdapter, state: GenerationState, resolvedCall: ResolvedCall<*>) {
|
||||||
@@ -75,7 +61,7 @@ public class CallableMethod(override val owner: Type, private val defaultImplOwn
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override fun invokeWithoutAssertions(v: InstructionAdapter) {
|
public override fun invokeWithoutAssertions(v: InstructionAdapter) {
|
||||||
invoke(v)
|
v.visitMethodInsn(invokeOpcode, owner.getInternalName(), getAsmMethod().getName(), getAsmMethod().getDescriptor())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun invokeDefault(v: InstructionAdapter) {
|
private fun invokeDefault(v: InstructionAdapter) {
|
||||||
@@ -104,25 +90,13 @@ public class CallableMethod(override val owner: Type, private val defaultImplOwn
|
|||||||
}
|
}
|
||||||
|
|
||||||
override val returnType: Type
|
override val returnType: Type
|
||||||
get() {
|
get() = signature.getReturnType()
|
||||||
return signature.getReturnType()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
|
||||||
return Printer.OPCODES[invokeOpcode] + " " + owner.getInternalName() + "." + signature
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isStaticCall(): Boolean {
|
override fun isStaticCall(): Boolean {
|
||||||
return invokeOpcode == INVOKESTATIC
|
return invokeOpcode == INVOKESTATIC
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun beforeParameterGeneration(v: InstructionAdapter, value: StackValue?) {
|
override fun toString(): String {
|
||||||
|
return "${Printer.OPCODES[invokeOpcode]} ${owner.getInternalName()}.$signature"
|
||||||
}
|
|
||||||
|
|
||||||
override fun invokeMethodWithArguments(resolvedCall: ResolvedCall<*>, receiver: StackValue, returnType: Type, codegen: ExpressionCodegen): StackValue {
|
|
||||||
return StackValue.functionCall(returnType) {
|
|
||||||
codegen.invokeMethodWithArguments(this@CallableMethod, resolvedCall, receiver, returnType)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2255,17 +2255,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
Callable callable = resolveToCallable(accessibleFunctionDescriptor, superCall, resolvedCall);
|
Callable callable = resolveToCallable(accessibleFunctionDescriptor, superCall, resolvedCall);
|
||||||
Type returnType = typeMapper.mapReturnType(accessibleFunctionDescriptor);
|
Type returnType = typeMapper.mapReturnType(accessibleFunctionDescriptor);
|
||||||
|
|
||||||
return ((Callable) callable).invokeMethodWithArguments(resolvedCall, receiver, returnType, this);
|
return callable.invokeMethodWithArguments(resolvedCall, receiver, returnType, this);
|
||||||
}
|
|
||||||
|
|
||||||
public void invokeMethodWithArguments(
|
|
||||||
@NotNull Callable callable,
|
|
||||||
@NotNull ResolvedCall resolvedCall,
|
|
||||||
@NotNull StackValue receiver,
|
|
||||||
@NotNull Type returnType
|
|
||||||
) {
|
|
||||||
invokeMethodWithArguments(callable, resolvedCall, receiver);
|
|
||||||
StackValue.coerce(callable.getReturnType(), returnType, v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
@@ -97,26 +97,17 @@ public abstract class IntrinsicCallable(override val returnType: Type,
|
|||||||
return receiverType ?: thisType
|
return receiverType ?: thisType
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun beforeParameterGeneration(v: InstructionAdapter, value: StackValue?) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun invokeMethodWithArguments(resolvedCall: ResolvedCall<*>, receiver: StackValue, returnType: Type, codegen: ExpressionCodegen): StackValue {
|
|
||||||
return StackValue.functionCall(returnType) {
|
|
||||||
codegen.invokeMethodWithArguments(this, resolvedCall, receiver, returnType)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class UnaryIntrinsic(val callable: CallableMethod, val newReturnType: Type? = null, needPrimitiveCheck: Boolean = false, val newThisType: Type? = null, val invoke: UnaryIntrinsic.(v: InstructionAdapter) -> Unit) :
|
public class UnaryIntrinsic(val callable: CallableMethod, val newReturnType: Type? = null, needPrimitiveCheck: Boolean = false, val newThisType: Type? = null, val invoke: UnaryIntrinsic.(v: InstructionAdapter) -> Unit) :
|
||||||
IntrinsicCallable(newReturnType ?: callable.returnType, callable.valueParameterTypes, newThisType ?: callable.thisType, callable.receiverType) {
|
IntrinsicCallable(newReturnType ?: callable.returnType, callable.valueParameterTypes, newThisType ?: callable.thisType, callable.receiverType) {
|
||||||
|
|
||||||
{
|
init {
|
||||||
if (needPrimitiveCheck) {
|
if (needPrimitiveCheck) {
|
||||||
assert(AsmUtil.isPrimitive(returnType)) { "Return type of UnaryPlus intrinsic should be of primitive type : " + returnType }
|
assert(AsmUtil.isPrimitive(returnType)) { "Return type of UnaryPlus intrinsic should be of primitive type : " + returnType }
|
||||||
}
|
}
|
||||||
assert(valueParameterTypes.size == 0, "Unary operation should not have any parameters")
|
assert(valueParameterTypes.isEmpty(), "Unary operation should not have any parameters")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun invokeIntrinsic(v: InstructionAdapter) {
|
override fun invokeIntrinsic(v: InstructionAdapter) {
|
||||||
|
|||||||
Reference in New Issue
Block a user