Refactor JetTypeMapper.mapToCallableMethod parameters
Pass CodegenContext instead of two parameters that are always calculated by it and instead of the other one which is always OwnerKind.IMPLEMENTATION (except a single case where it was context.kind, but that case doesn't seem to matter)
This commit is contained in:
@@ -1774,7 +1774,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
boolean isStatic = containingDeclaration instanceof PackageFragmentDescriptor;
|
boolean isStatic = containingDeclaration instanceof PackageFragmentDescriptor;
|
||||||
boolean isSuper = superExpression != null;
|
boolean isSuper = superExpression != null;
|
||||||
boolean isInsideClass = isCallInsideSameClassAsDeclared(propertyDescriptor, context);
|
boolean isInsideClass = isCallInsideSameClassAsDeclared(propertyDescriptor, context);
|
||||||
boolean isInsideModule = isCallInsideSameModuleAsDeclared(propertyDescriptor, context);
|
|
||||||
|
|
||||||
JetType delegateType = getPropertyDelegateType(propertyDescriptor, state.getBindingContext());
|
JetType delegateType = getPropertyDelegateType(propertyDescriptor, state.getBindingContext());
|
||||||
boolean isDelegatedProperty = delegateType != null;
|
boolean isDelegatedProperty = delegateType != null;
|
||||||
@@ -1817,9 +1816,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
PropertyGetterDescriptor getter = propertyDescriptor.getGetter();
|
PropertyGetterDescriptor getter = propertyDescriptor.getGetter();
|
||||||
if (getter != null) {
|
if (getter != null) {
|
||||||
callableGetter = typeMapper.mapToCallableMethod(
|
callableGetter = typeMapper.mapToCallableMethod(getter, isSuper || MethodKind.SYNTHETIC_ACCESSOR == methodKind, context);
|
||||||
getter, isSuper || MethodKind.SYNTHETIC_ACCESSOR == methodKind, isInsideClass, isInsideModule,
|
|
||||||
OwnerKind.IMPLEMENTATION);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1830,9 +1827,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
callableSetter = null;
|
callableSetter = null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
callableSetter = typeMapper.mapToCallableMethod(
|
callableSetter = typeMapper.mapToCallableMethod(setter, isSuper || MethodKind.SYNTHETIC_ACCESSOR == methodKind, context);
|
||||||
setter, isSuper || MethodKind.SYNTHETIC_ACCESSOR == methodKind, isInsideClass, isInsideModule,
|
|
||||||
OwnerKind.IMPLEMENTATION);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1844,7 +1839,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
propertyDescriptor = unwrapFakeOverride(propertyDescriptor);
|
propertyDescriptor = unwrapFakeOverride(propertyDescriptor);
|
||||||
if (callableMethod == null) {
|
if (callableMethod == null) {
|
||||||
owner = typeMapper.getOwner(isBackingFieldInAnotherClass ? propertyDescriptor.getContainingDeclaration() : propertyDescriptor,
|
owner = typeMapper.getOwner(isBackingFieldInAnotherClass ? propertyDescriptor.getContainingDeclaration() : propertyDescriptor,
|
||||||
context.getContextKind(), isInsideModule);
|
context.getContextKind(), isCallInsideSameModuleAsDeclared(propertyDescriptor, context));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
owner = callableMethod.getOwner();
|
owner = callableMethod.getOwner();
|
||||||
@@ -2073,10 +2068,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SimpleFunctionDescriptor originalOfSamAdapter = (SimpleFunctionDescriptor) SamCodegenUtil.getOriginalIfSamAdapter(fd);
|
SimpleFunctionDescriptor originalOfSamAdapter = (SimpleFunctionDescriptor) SamCodegenUtil.getOriginalIfSamAdapter(fd);
|
||||||
return typeMapper.mapToCallableMethod(originalOfSamAdapter != null ? originalOfSamAdapter : fd, superCall,
|
return typeMapper.mapToCallableMethod(originalOfSamAdapter != null ? originalOfSamAdapter : fd, superCall, context);
|
||||||
isCallInsideSameClassAsDeclared(fd, context),
|
|
||||||
isCallInsideSameModuleAsDeclared(fd, context),
|
|
||||||
OwnerKind.IMPLEMENTATION);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,8 +49,6 @@ import java.util.*;
|
|||||||
|
|
||||||
import static org.jetbrains.asm4.Opcodes.*;
|
import static org.jetbrains.asm4.Opcodes.*;
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.*;
|
import static org.jetbrains.jet.codegen.AsmUtil.*;
|
||||||
import static org.jetbrains.jet.codegen.CodegenUtil.isCallInsideSameClassAsDeclared;
|
|
||||||
import static org.jetbrains.jet.codegen.CodegenUtil.isCallInsideSameModuleAsDeclared;
|
|
||||||
import static org.jetbrains.jet.codegen.JvmSerializationBindings.*;
|
import static org.jetbrains.jet.codegen.JvmSerializationBindings.*;
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.asmTypeForAnonymousClass;
|
import static org.jetbrains.jet.codegen.binding.CodegenBinding.asmTypeForAnonymousClass;
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun;
|
import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun;
|
||||||
@@ -610,11 +608,9 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
|||||||
|
|
||||||
CallableMethod method;
|
CallableMethod method;
|
||||||
if (functionDescriptor instanceof ConstructorDescriptor) {
|
if (functionDescriptor instanceof ConstructorDescriptor) {
|
||||||
method = state.getTypeMapper().mapToCallableMethod((ConstructorDescriptor) functionDescriptor);
|
method = typeMapper.mapToCallableMethod((ConstructorDescriptor) functionDescriptor);
|
||||||
} else {
|
} else {
|
||||||
method = state.getTypeMapper()
|
method = typeMapper.mapToCallableMethod(functionDescriptor, false, methodContext);
|
||||||
.mapToCallableMethod(functionDescriptor, false, isCallInsideSameClassAsDeclared(functionDescriptor, methodContext),
|
|
||||||
isCallInsideSameModuleAsDeclared(functionDescriptor, methodContext), OwnerKind.IMPLEMENTATION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
iv.visitMethodInsn(method.getInvokeOpcode(), method.getOwner().getInternalName(), method.getSignature().getAsmMethod().getName(),
|
iv.visitMethodInsn(method.getInvokeOpcode(), method.getOwner().getInternalName(), method.getSignature().getAsmMethod().getName(),
|
||||||
|
|||||||
@@ -999,10 +999,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
boolean callFromAccessor = !JetTypeMapper.isAccessor(functionDescriptor);
|
boolean callFromAccessor = !JetTypeMapper.isAccessor(functionDescriptor);
|
||||||
CallableMethod callableMethod = isConstructor ?
|
CallableMethod callableMethod = isConstructor ?
|
||||||
typeMapper.mapToCallableMethod((ConstructorDescriptor) functionDescriptor) :
|
typeMapper.mapToCallableMethod((ConstructorDescriptor) functionDescriptor) :
|
||||||
typeMapper.mapToCallableMethod(functionDescriptor, callFromAccessor,
|
typeMapper.mapToCallableMethod(functionDescriptor, callFromAccessor, context);
|
||||||
isCallInsideSameClassAsDeclared(functionDescriptor, context),
|
|
||||||
isCallInsideSameModuleAsDeclared(functionDescriptor, context),
|
|
||||||
context.getContextKind());
|
|
||||||
|
|
||||||
Method method = callableMethod.getSignature().getAsmMethod();
|
Method method = callableMethod.getSignature().getAsmMethod();
|
||||||
Type[] argTypes = method.getArgumentTypes();
|
Type[] argTypes = method.getArgumentTypes();
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import org.jetbrains.jet.codegen.*;
|
|||||||
import org.jetbrains.jet.codegen.binding.BindingTraceAware;
|
import org.jetbrains.jet.codegen.binding.BindingTraceAware;
|
||||||
import org.jetbrains.jet.codegen.binding.CalculatedClosure;
|
import org.jetbrains.jet.codegen.binding.CalculatedClosure;
|
||||||
import org.jetbrains.jet.codegen.binding.CodegenBinding;
|
import org.jetbrains.jet.codegen.binding.CodegenBinding;
|
||||||
|
import org.jetbrains.jet.codegen.context.CodegenContext;
|
||||||
import org.jetbrains.jet.codegen.signature.BothSignatureWriter;
|
import org.jetbrains.jet.codegen.signature.BothSignatureWriter;
|
||||||
import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind;
|
import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind;
|
||||||
import org.jetbrains.jet.codegen.signature.JvmMethodParameterSignature;
|
import org.jetbrains.jet.codegen.signature.JvmMethodParameterSignature;
|
||||||
@@ -399,15 +400,13 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
public CallableMethod mapToCallableMethod(
|
public CallableMethod mapToCallableMethod(
|
||||||
@NotNull FunctionDescriptor functionDescriptor,
|
@NotNull FunctionDescriptor functionDescriptor,
|
||||||
boolean superCall,
|
boolean superCall,
|
||||||
boolean isInsideClass,
|
@NotNull CodegenContext<?> context
|
||||||
boolean isInsideModule,
|
|
||||||
OwnerKind kind
|
|
||||||
) {
|
) {
|
||||||
DeclarationDescriptor functionParent = functionDescriptor.getOriginal().getContainingDeclaration();
|
DeclarationDescriptor functionParent = functionDescriptor.getOriginal().getContainingDeclaration();
|
||||||
|
|
||||||
functionDescriptor = unwrapFakeOverride(functionDescriptor.getOriginal());
|
functionDescriptor = unwrapFakeOverride(functionDescriptor.getOriginal());
|
||||||
|
|
||||||
JvmMethodSignature descriptor = mapSignature(functionDescriptor.getOriginal(), kind);
|
JvmMethodSignature descriptor = mapSignature(functionDescriptor.getOriginal());
|
||||||
Type owner;
|
Type owner;
|
||||||
Type ownerForDefaultImpl;
|
Type ownerForDefaultImpl;
|
||||||
Type ownerForDefaultParam;
|
Type ownerForDefaultParam;
|
||||||
@@ -428,12 +427,13 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
owner = asmTypeForAnonymousClass(bindingContext, functionDescriptor);
|
owner = asmTypeForAnonymousClass(bindingContext, functionDescriptor);
|
||||||
ownerForDefaultImpl = ownerForDefaultParam = thisClass = owner;
|
ownerForDefaultImpl = ownerForDefaultParam = thisClass = owner;
|
||||||
invokeOpcode = INVOKEVIRTUAL;
|
invokeOpcode = INVOKEVIRTUAL;
|
||||||
descriptor = mapSignature(functionDescriptor, kind);
|
descriptor = mapSignature(functionDescriptor);
|
||||||
calleeType = owner;
|
calleeType = owner;
|
||||||
}
|
}
|
||||||
else if (functionParent instanceof PackageFragmentDescriptor) {
|
else if (functionParent instanceof PackageFragmentDescriptor) {
|
||||||
assert !superCall;
|
assert !superCall;
|
||||||
owner = asmTypeForPackage((PackageFragmentDescriptor) functionParent, functionDescriptor, isInsideModule);
|
owner = asmTypeForPackage((PackageFragmentDescriptor) functionParent, functionDescriptor,
|
||||||
|
isCallInsideSameModuleAsDeclared(functionDescriptor, context));
|
||||||
ownerForDefaultImpl = ownerForDefaultParam = owner;
|
ownerForDefaultImpl = ownerForDefaultParam = owner;
|
||||||
invokeOpcode = INVOKESTATIC;
|
invokeOpcode = INVOKESTATIC;
|
||||||
thisClass = null;
|
thisClass = null;
|
||||||
@@ -460,8 +460,6 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
boolean originalIsInterface = isInterface(declarationOwner);
|
boolean originalIsInterface = isInterface(declarationOwner);
|
||||||
boolean currentIsInterface = isInterface(currentOwner);
|
boolean currentIsInterface = isInterface(currentOwner);
|
||||||
|
|
||||||
boolean isAccessor = isAccessor(functionDescriptor);
|
|
||||||
|
|
||||||
ClassDescriptor receiver;
|
ClassDescriptor receiver;
|
||||||
if (currentIsInterface && !originalIsInterface) {
|
if (currentIsInterface && !originalIsInterface) {
|
||||||
receiver = declarationOwner;
|
receiver = declarationOwner;
|
||||||
@@ -483,11 +481,12 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
invokeOpcode = superCall ? INVOKESTATIC : INVOKEINTERFACE;
|
invokeOpcode = superCall ? INVOKESTATIC : INVOKEINTERFACE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (isAccessor) {
|
if (isAccessor(functionDescriptor)) {
|
||||||
invokeOpcode = INVOKESTATIC;
|
invokeOpcode = INVOKESTATIC;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
boolean isPrivateFunInvocation = isInsideClass && functionDescriptor.getVisibility() == Visibilities.PRIVATE;
|
boolean isPrivateFunInvocation = isCallInsideSameClassAsDeclared(functionDescriptor, context) &&
|
||||||
|
functionDescriptor.getVisibility() == Visibilities.PRIVATE;
|
||||||
invokeOpcode = superCall || isPrivateFunInvocation ? INVOKESPECIAL : INVOKEVIRTUAL;
|
invokeOpcode = superCall || isPrivateFunInvocation ? INVOKESPECIAL : INVOKEVIRTUAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user