Rename: this object, receiver argument -> dispatch receiver, extension receiver
This commit is contained in:
@@ -44,8 +44,8 @@ public class AccessorForFunctionDescriptor extends SimpleFunctionDescriptorImpl
|
||||
Kind.DECLARATION, SourceElement.NO_SOURCE);
|
||||
this.calleeDescriptor = descriptor;
|
||||
|
||||
initialize(DescriptorUtils.getReceiverParameterType(descriptor.getReceiverParameter()),
|
||||
descriptor instanceof ConstructorDescriptor ? NO_RECEIVER_PARAMETER : descriptor.getExpectedThisObject(),
|
||||
initialize(DescriptorUtils.getReceiverParameterType(descriptor.getExtensionReceiverParameter()),
|
||||
descriptor instanceof ConstructorDescriptor ? NO_RECEIVER_PARAMETER : descriptor.getDispatchReceiverParameter(),
|
||||
copyTypeParameters(descriptor),
|
||||
copyValueParameters(descriptor),
|
||||
descriptor.getReturnType(),
|
||||
|
||||
@@ -34,14 +34,14 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem
|
||||
private final PropertyDescriptor calleeDescriptor;
|
||||
|
||||
public AccessorForPropertyDescriptor(@NotNull PropertyDescriptor pd, @NotNull DeclarationDescriptor containingDeclaration, int index) {
|
||||
this(pd, pd.getType(), DescriptorUtils.getReceiverParameterType(pd.getReceiverParameter()), pd.getExpectedThisObject(), containingDeclaration, index);
|
||||
this(pd, pd.getType(), DescriptorUtils.getReceiverParameterType(pd.getExtensionReceiverParameter()), pd.getDispatchReceiverParameter(), containingDeclaration, index);
|
||||
}
|
||||
|
||||
protected AccessorForPropertyDescriptor(
|
||||
@NotNull PropertyDescriptor original,
|
||||
@NotNull JetType propertyType,
|
||||
@Nullable JetType receiverType,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@Nullable ReceiverParameterDescriptor dispatchReceiverParameter,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
int index
|
||||
) {
|
||||
@@ -50,7 +50,7 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem
|
||||
Kind.DECLARATION, SourceElement.NO_SOURCE);
|
||||
|
||||
this.calleeDescriptor = original;
|
||||
setType(propertyType, Collections.<TypeParameterDescriptorImpl>emptyList(), expectedThisObject, receiverType);
|
||||
setType(propertyType, Collections.<TypeParameterDescriptorImpl>emptyList(), dispatchReceiverParameter, receiverType);
|
||||
initialize(new Getter(this), new Setter(this));
|
||||
}
|
||||
|
||||
|
||||
@@ -667,7 +667,7 @@ public class AsmUtil {
|
||||
}
|
||||
|
||||
public static int getVisibilityForSpecialPropertyBackingField(@NotNull PropertyDescriptor propertyDescriptor, boolean isDelegate) {
|
||||
boolean isExtensionProperty = propertyDescriptor.getReceiverParameter() != null;
|
||||
boolean isExtensionProperty = propertyDescriptor.getExtensionReceiverParameter() != null;
|
||||
if (isDelegate || isExtensionProperty) {
|
||||
return ACC_PRIVATE;
|
||||
}
|
||||
@@ -688,7 +688,7 @@ public class AsmUtil {
|
||||
}
|
||||
|
||||
public static boolean isPropertyWithBackingFieldCopyInOuterClass(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
boolean isExtensionProperty = propertyDescriptor.getReceiverParameter() != null;
|
||||
boolean isExtensionProperty = propertyDescriptor.getExtensionReceiverParameter() != null;
|
||||
DeclarationDescriptor propertyContainer = propertyDescriptor.getContainingDeclaration();
|
||||
return !propertyDescriptor.isVar()
|
||||
&& !isExtensionProperty
|
||||
|
||||
@@ -230,7 +230,7 @@ public class ClosureCodegen extends ParentCodegenAware {
|
||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||
iv.load(0, asmType);
|
||||
|
||||
ReceiverParameterDescriptor receiver = funDescriptor.getReceiverParameter();
|
||||
ReceiverParameterDescriptor receiver = funDescriptor.getExtensionReceiverParameter();
|
||||
int count = 1;
|
||||
if (receiver != null) {
|
||||
StackValue.local(count, bridge.getArgumentTypes()[count - 1]).put(typeMapper.mapType(receiver.getType()), iv);
|
||||
@@ -328,7 +328,7 @@ public class ClosureCodegen extends ParentCodegenAware {
|
||||
@NotNull
|
||||
public static FunctionDescriptor getErasedInvokeFunction(@NotNull FunctionDescriptor funDescriptor) {
|
||||
int arity = funDescriptor.getValueParameters().size();
|
||||
ClassDescriptor funClass = funDescriptor.getReceiverParameter() == null
|
||||
ClassDescriptor funClass = funDescriptor.getExtensionReceiverParameter() == null
|
||||
? KotlinBuiltIns.getInstance().getFunction(arity)
|
||||
: KotlinBuiltIns.getInstance().getExtensionFunction(arity);
|
||||
return funClass.getDefaultType().getMemberScope().getFunctions(Name.identifier("invoke")).iterator().next();
|
||||
|
||||
@@ -1880,7 +1880,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
boolean isBackingFieldInAnotherClass = AsmUtil.isPropertyWithBackingFieldInOuterClass(propertyDescriptor);
|
||||
boolean isStatic = DescriptorUtils.isStaticDeclaration(propertyDescriptor);
|
||||
boolean isSuper = superExpression != null;
|
||||
boolean isExtensionProperty = propertyDescriptor.getReceiverParameter() != null;
|
||||
boolean isExtensionProperty = propertyDescriptor.getExtensionReceiverParameter() != null;
|
||||
|
||||
JetType delegateType = getPropertyDelegateType(propertyDescriptor, bindingContext);
|
||||
boolean isDelegatedProperty = delegateType != null;
|
||||
@@ -2479,7 +2479,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
PackageFragmentDescriptor containingPackage = (PackageFragmentDescriptor) descriptor.getContainingDeclaration();
|
||||
String packageClassInternalName = PackageClassUtils.getPackageClassInternalName(containingPackage.getFqName());
|
||||
|
||||
ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter();
|
||||
ReceiverParameterDescriptor receiverParameter = descriptor.getExtensionReceiverParameter();
|
||||
Method factoryMethod;
|
||||
if (receiverParameter != null) {
|
||||
Type[] parameterTypes = new Type[] {JAVA_STRING_TYPE, K_PACKAGE_IMPL_TYPE, getType(Class.class)};
|
||||
@@ -2556,21 +2556,21 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
JetCallExpression fakeExpression = constructFakeFunctionCall();
|
||||
final List<? extends ValueArgument> fakeArguments = fakeExpression.getValueArguments();
|
||||
|
||||
final ReceiverValue thisObject = computeAndSaveReceiver(signature, codegen, referencedFunction.getExpectedThisObject());
|
||||
final ReceiverValue extensionReceiver = computeAndSaveReceiver(signature, codegen, referencedFunction.getReceiverParameter());
|
||||
final ReceiverValue dispatchReceiver = computeAndSaveReceiver(signature, codegen, referencedFunction.getDispatchReceiverParameter());
|
||||
final ReceiverValue extensionReceiver = computeAndSaveReceiver(signature, codegen, referencedFunction.getExtensionReceiverParameter());
|
||||
computeAndSaveArguments(fakeArguments, codegen);
|
||||
|
||||
ResolvedCall<CallableDescriptor> fakeResolvedCall = new DelegatingResolvedCall<CallableDescriptor>(resolvedCall) {
|
||||
@NotNull
|
||||
@Override
|
||||
public ReceiverValue getReceiverArgument() {
|
||||
public ReceiverValue getExtensionReceiver() {
|
||||
return extensionReceiver;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ReceiverValue getThisObject() {
|
||||
return thisObject;
|
||||
public ReceiverValue getDispatchReceiver() {
|
||||
return dispatchReceiver;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -3316,17 +3316,17 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
ConstructorDescriptor constructor = (ConstructorDescriptor) resolvedCall.getResultingDescriptor();
|
||||
|
||||
ReceiverParameterDescriptor expectedThisObject = constructor.getExpectedThisObject();
|
||||
if (expectedThisObject != null) {
|
||||
Type receiverType = typeMapper.mapType(expectedThisObject.getType());
|
||||
generateReceiverValue(resolvedCall.getThisObject(), receiverType);
|
||||
ReceiverParameterDescriptor dispatchReceiver = constructor.getDispatchReceiverParameter();
|
||||
if (dispatchReceiver != null) {
|
||||
Type receiverType = typeMapper.mapType(dispatchReceiver.getType());
|
||||
generateReceiverValue(resolvedCall.getDispatchReceiver(), receiverType);
|
||||
}
|
||||
|
||||
MutableClosure closure = bindingContext.get(CLOSURE, constructor.getContainingDeclaration());
|
||||
|
||||
// Resolved call to local class constructor doesn't have expectedThisObject, so we need to generate closure on stack
|
||||
// Resolved call to local class constructor doesn't have dispatchReceiver, so we need to generate closure on stack
|
||||
// See StackValue.receiver for more info
|
||||
pushClosureOnStack(closure, expectedThisObject != null, defaultCallGenerator);
|
||||
pushClosureOnStack(closure, dispatchReceiver != null, defaultCallGenerator);
|
||||
|
||||
ConstructorDescriptor originalOfSamAdapter = (ConstructorDescriptor) SamCodegenUtil.getOriginalIfSamAdapter(constructor);
|
||||
CallableMethod method = typeMapper.mapToCallableMethod(originalOfSamAdapter == null ? constructor : originalOfSamAdapter);
|
||||
@@ -3463,7 +3463,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
else {
|
||||
gen(array, arrayType); // intrinsic method
|
||||
|
||||
int index = operationDescriptor.getReceiverParameter() != null ? 1 : 0;
|
||||
int index = operationDescriptor.getExtensionReceiverParameter() != null ? 1 : 0;
|
||||
|
||||
for (JetExpression jetExpression : expression.getIndexExpressions()) {
|
||||
gen(jetExpression, argumentTypes[index]);
|
||||
|
||||
@@ -39,7 +39,6 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.ResolvePackage;
|
||||
import org.jetbrains.jet.lang.resolve.annotations.AnnotationsPackage;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil;
|
||||
import org.jetbrains.jet.lang.resolve.constants.ArrayValue;
|
||||
@@ -236,7 +235,7 @@ public class FunctionCodegen extends ParentCodegenAware {
|
||||
}
|
||||
|
||||
if (kind == JvmMethodParameterKind.RECEIVER) {
|
||||
ReceiverParameterDescriptor receiver = functionDescriptor.getReceiverParameter();
|
||||
ReceiverParameterDescriptor receiver = functionDescriptor.getExtensionReceiverParameter();
|
||||
nullableType = receiver == null || receiver.getType().isNullable();
|
||||
}
|
||||
else {
|
||||
@@ -271,12 +270,12 @@ public class FunctionCodegen extends ParentCodegenAware {
|
||||
|
||||
@Nullable
|
||||
private static Type getThisTypeForFunction(@NotNull FunctionDescriptor functionDescriptor, @NotNull MethodContext context, @NotNull JetTypeMapper typeMapper) {
|
||||
ReceiverParameterDescriptor expectedThisObject = functionDescriptor.getExpectedThisObject();
|
||||
ReceiverParameterDescriptor dispatchReceiver = functionDescriptor.getDispatchReceiverParameter();
|
||||
if (functionDescriptor instanceof ConstructorDescriptor) {
|
||||
return typeMapper.mapType(functionDescriptor);
|
||||
}
|
||||
else if (expectedThisObject != null) {
|
||||
return typeMapper.mapType(expectedThisObject.getType());
|
||||
else if (dispatchReceiver != null) {
|
||||
return typeMapper.mapType(dispatchReceiver.getType());
|
||||
}
|
||||
else if (isFunctionLiteral(functionDescriptor) || isLocalNamedFun(functionDescriptor)) {
|
||||
return typeMapper.mapType(context.getThisDescriptor());
|
||||
|
||||
@@ -172,7 +172,7 @@ public class JvmCodegenUtil {
|
||||
if (!isCallInsideSameClassAsDeclared(property, context) && !isDebuggerContext(context)) return false;
|
||||
|
||||
// Delegated and extension properties have no backing fields
|
||||
if (isDelegated || property.getReceiverParameter() != null) return false;
|
||||
if (isDelegated || property.getExtensionReceiverParameter() != null) return false;
|
||||
|
||||
// Class object properties cannot be accessed directly because their backing fields are stored in the containing class
|
||||
if (DescriptorUtils.isClassObject(property.getContainingDeclaration())) return false;
|
||||
@@ -203,7 +203,7 @@ public class JvmCodegenUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ClassDescriptor getExpectedThisObjectForConstructorCall(
|
||||
public static ClassDescriptor getDispatchReceiverParameterForConstructorCall(
|
||||
@NotNull ConstructorDescriptor descriptor,
|
||||
@Nullable CalculatedClosure closure
|
||||
) {
|
||||
@@ -214,10 +214,10 @@ public class JvmCodegenUtil {
|
||||
|
||||
//for compilation against binaries
|
||||
//TODO: It's best to use this code also for compilation against sources
|
||||
// but sometimes structures that have expectedThisObject (bug?) mapped to static classes
|
||||
ReceiverParameterDescriptor expectedThisObject = descriptor.getExpectedThisObject();
|
||||
if (expectedThisObject != null) {
|
||||
ClassDescriptor expectedThisClass = (ClassDescriptor) expectedThisObject.getContainingDeclaration();
|
||||
// but sometimes structures that have dispatchReceiver (bug?) mapped to static classes
|
||||
ReceiverParameterDescriptor dispatchReceiver = descriptor.getDispatchReceiverParameter();
|
||||
if (dispatchReceiver != null) {
|
||||
ClassDescriptor expectedThisClass = (ClassDescriptor) dispatchReceiver.getContainingDeclaration();
|
||||
if (!expectedThisClass.getKind().isSingleton()) {
|
||||
return expectedThisClass;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class JvmRuntimeTypes {
|
||||
|
||||
@NotNull
|
||||
public Collection<JetType> getSupertypesForClosure(@NotNull FunctionDescriptor descriptor) {
|
||||
ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter();
|
||||
ReceiverParameterDescriptor receiverParameter = descriptor.getExtensionReceiverParameter();
|
||||
|
||||
List<TypeProjection> typeArguments = new ArrayList<TypeProjection>(2);
|
||||
|
||||
@@ -127,21 +127,21 @@ public class JvmRuntimeTypes {
|
||||
|
||||
@NotNull
|
||||
public Collection<JetType> getSupertypesForFunctionReference(@NotNull FunctionDescriptor descriptor) {
|
||||
ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter();
|
||||
ReceiverParameterDescriptor expectedThisObject = descriptor.getExpectedThisObject();
|
||||
ReceiverParameterDescriptor extensionReceiver = descriptor.getExtensionReceiverParameter();
|
||||
ReceiverParameterDescriptor dispatchReceiver = descriptor.getDispatchReceiverParameter();
|
||||
|
||||
List<TypeProjection> typeArguments = new ArrayList<TypeProjection>(2);
|
||||
|
||||
ClassDescriptor classDescriptor;
|
||||
JetType receiverType;
|
||||
if (receiverParameter != null) {
|
||||
if (extensionReceiver != null) {
|
||||
classDescriptor = kExtensionFunctionImpl;
|
||||
receiverType = receiverParameter.getType();
|
||||
receiverType = extensionReceiver.getType();
|
||||
typeArguments.add(new TypeProjectionImpl(receiverType));
|
||||
}
|
||||
else if (expectedThisObject != null) {
|
||||
else if (dispatchReceiver != null) {
|
||||
classDescriptor = kMemberFunctionImpl;
|
||||
receiverType = expectedThisObject.getType();
|
||||
receiverType = dispatchReceiver.getType();
|
||||
typeArguments.add(new TypeProjectionImpl(receiverType));
|
||||
}
|
||||
else {
|
||||
@@ -165,7 +165,7 @@ public class JvmRuntimeTypes {
|
||||
receiverType,
|
||||
ExpressionTypingUtils.getValueParametersTypes(descriptor.getValueParameters()),
|
||||
descriptor.getReturnType(),
|
||||
receiverParameter != null
|
||||
extensionReceiver != null
|
||||
);
|
||||
|
||||
return Arrays.asList(kFunctionImplType, kFunctionType);
|
||||
|
||||
@@ -206,7 +206,7 @@ public class PropertyCodegen {
|
||||
private void generateSyntheticMethodIfNeeded(@NotNull PropertyDescriptor descriptor) {
|
||||
if (descriptor.getAnnotations().isEmpty()) return;
|
||||
|
||||
ReceiverParameterDescriptor receiver = descriptor.getReceiverParameter();
|
||||
ReceiverParameterDescriptor receiver = descriptor.getExtensionReceiverParameter();
|
||||
String name = JvmAbi.getSyntheticMethodNameForAnnotatedProperty(descriptor.getName());
|
||||
String desc = receiver == null ? "()V" : "(" + typeMapper.mapType(receiver.getType()) + ")V";
|
||||
|
||||
@@ -395,7 +395,7 @@ public class PropertyCodegen {
|
||||
v.areturn(type);
|
||||
}
|
||||
else if (callableDescriptor instanceof PropertySetterDescriptor) {
|
||||
ReceiverParameterDescriptor receiverParameter = propertyDescriptor.getReceiverParameter();
|
||||
ReceiverParameterDescriptor receiverParameter = propertyDescriptor.getExtensionReceiverParameter();
|
||||
if (receiverParameter != null) {
|
||||
paramCode += codegen.typeMapper.mapType(receiverParameter.getType()).getSize();
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ public abstract class StackValue {
|
||||
ExpressionCodegen codegen,
|
||||
@Nullable CallableMethod callableMethod
|
||||
) {
|
||||
if (resolvedCall.getThisObject().exists() || resolvedCall.getReceiverArgument().exists() || isLocalFunCall(callableMethod)) {
|
||||
if (resolvedCall.getDispatchReceiver().exists() || resolvedCall.getExtensionReceiver().exists() || isLocalFunCall(callableMethod)) {
|
||||
return new CallReceiver(resolvedCall, receiver, codegen, callableMethod, true);
|
||||
}
|
||||
return receiver;
|
||||
@@ -692,7 +692,7 @@ public abstract class StackValue {
|
||||
v.store(firstParamIndex, type);
|
||||
}
|
||||
|
||||
ReceiverValue receiverParameter = resolvedGetCall.getReceiverArgument();
|
||||
ReceiverValue receiverParameter = resolvedGetCall.getExtensionReceiver();
|
||||
int receiverIndex = -1;
|
||||
if (receiverParameter.exists()) {
|
||||
Type type = codegen.typeMapper.mapType(receiverParameter.getType());
|
||||
@@ -700,9 +700,9 @@ public abstract class StackValue {
|
||||
v.store(receiverIndex, type);
|
||||
}
|
||||
|
||||
ReceiverValue thisObject = resolvedGetCall.getThisObject();
|
||||
ReceiverValue dispatchReceiver = resolvedGetCall.getDispatchReceiver();
|
||||
int thisIndex = -1;
|
||||
if (thisObject.exists()) {
|
||||
if (dispatchReceiver.exists()) {
|
||||
thisIndex = frame.enterTemp(OBJECT_TYPE);
|
||||
v.store(thisIndex, OBJECT_TYPE);
|
||||
}
|
||||
@@ -723,14 +723,14 @@ public abstract class StackValue {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
if (resolvedSetCall.getThisObject().exists()) {
|
||||
if (resolvedSetCall.getReceiverArgument().exists()) {
|
||||
codegen.generateReceiverValue(resolvedSetCall.getThisObject(), OBJECT_TYPE);
|
||||
if (resolvedSetCall.getDispatchReceiver().exists()) {
|
||||
if (resolvedSetCall.getExtensionReceiver().exists()) {
|
||||
codegen.generateReceiverValue(resolvedSetCall.getDispatchReceiver(), OBJECT_TYPE);
|
||||
}
|
||||
v.load(realReceiverIndex, realReceiverType);
|
||||
}
|
||||
else {
|
||||
if (resolvedSetCall.getReceiverArgument().exists()) {
|
||||
if (resolvedSetCall.getExtensionReceiver().exists()) {
|
||||
v.load(realReceiverIndex, realReceiverType);
|
||||
}
|
||||
else {
|
||||
@@ -780,13 +780,13 @@ public abstract class StackValue {
|
||||
}
|
||||
}
|
||||
|
||||
if (call.getThisObject().exists()) {
|
||||
if (call.getReceiverArgument().exists()) {
|
||||
if (call.getDispatchReceiver().exists()) {
|
||||
if (call.getExtensionReceiver().exists()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (codegen.typeMapper.mapType(call.getResultingDescriptor().getReceiverParameter().getType())
|
||||
if (codegen.typeMapper.mapType(call.getResultingDescriptor().getExtensionReceiverParameter().getType())
|
||||
.getSize() != 1) {
|
||||
return false;
|
||||
}
|
||||
@@ -1107,14 +1107,14 @@ public abstract class StackValue {
|
||||
) {
|
||||
CallableDescriptor descriptor = resolvedCall.getResultingDescriptor();
|
||||
|
||||
ReceiverParameterDescriptor expectedThisObject = descriptor.getExpectedThisObject();
|
||||
ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter();
|
||||
ReceiverParameterDescriptor dispatchReceiver = descriptor.getDispatchReceiverParameter();
|
||||
ReceiverParameterDescriptor extensionReceiver = descriptor.getExtensionReceiverParameter();
|
||||
|
||||
if (receiverParameter != null) {
|
||||
return callableMethod != null ? callableMethod.getReceiverClass() : typeMapper.mapType(receiverParameter.getType());
|
||||
if (extensionReceiver != null) {
|
||||
return callableMethod != null ? callableMethod.getReceiverClass() : typeMapper.mapType(extensionReceiver.getType());
|
||||
}
|
||||
else if (expectedThisObject != null) {
|
||||
return callableMethod != null ? callableMethod.getThisType() : typeMapper.mapType(expectedThisObject.getType());
|
||||
else if (dispatchReceiver != null) {
|
||||
return callableMethod != null ? callableMethod.getThisType() : typeMapper.mapType(dispatchReceiver.getType());
|
||||
}
|
||||
else if (isLocalFunCall(callableMethod)) {
|
||||
return callableMethod.getGenerateCalleeType();
|
||||
@@ -1127,28 +1127,28 @@ public abstract class StackValue {
|
||||
public void put(Type type, InstructionAdapter v) {
|
||||
CallableDescriptor descriptor = resolvedCall.getResultingDescriptor();
|
||||
|
||||
ReceiverValue thisObject = resolvedCall.getThisObject();
|
||||
ReceiverValue receiverArgument = resolvedCall.getReceiverArgument();
|
||||
ReceiverValue dispatchReceiver = resolvedCall.getDispatchReceiver();
|
||||
ReceiverValue extensionReceiver = resolvedCall.getExtensionReceiver();
|
||||
int depth = 0;
|
||||
if (thisObject.exists()) {
|
||||
if (dispatchReceiver.exists()) {
|
||||
if (!AnnotationsPackage.isPlatformStaticInObject(descriptor)) {
|
||||
if (receiverArgument.exists()) {
|
||||
if (extensionReceiver.exists()) {
|
||||
//noinspection ConstantConditions
|
||||
Type resultType =
|
||||
callableMethod != null ?
|
||||
callableMethod.getOwner() :
|
||||
codegen.typeMapper.mapType(descriptor.getExpectedThisObject().getType());
|
||||
codegen.typeMapper.mapType(descriptor.getDispatchReceiverParameter().getType());
|
||||
|
||||
codegen.generateReceiverValue(thisObject, resultType);
|
||||
codegen.generateReceiverValue(dispatchReceiver, resultType);
|
||||
}
|
||||
else {
|
||||
genReceiver(v, thisObject, type, null, 0);
|
||||
genReceiver(v, dispatchReceiver, type, null, 0);
|
||||
}
|
||||
depth = 1;
|
||||
}
|
||||
}
|
||||
else if (isLocalFunCall(callableMethod)) {
|
||||
assert receiver == none() || receiverArgument.exists() :
|
||||
assert receiver == none() || extensionReceiver.exists() :
|
||||
"Receiver should be present only for local extension function: " + callableMethod;
|
||||
StackValue value = codegen.findLocalOrCapturedValue(descriptor.getOriginal());
|
||||
assert value != null : "Local fun should be found in locals or in captured params: " + resolvedCall;
|
||||
@@ -1157,8 +1157,8 @@ public abstract class StackValue {
|
||||
depth = 1;
|
||||
}
|
||||
|
||||
if (putReceiverArgumentOnStack && receiverArgument.exists()) {
|
||||
genReceiver(v, receiverArgument, type, descriptor.getReceiverParameter(), depth);
|
||||
if (putReceiverArgumentOnStack && extensionReceiver.exists()) {
|
||||
genReceiver(v, extensionReceiver, type, descriptor.getExtensionReceiverParameter(), depth);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ public class TailRecursionCodegen {
|
||||
}
|
||||
assignParameterValues(fd, callable, arguments);
|
||||
if (callable.getReceiverClass() != null) {
|
||||
if (resolvedCall.getReceiverArgument() != fd.getReceiverParameter().getValue()) {
|
||||
if (resolvedCall.getExtensionReceiver() != fd.getExtensionReceiverParameter().getValue()) {
|
||||
StackValue expression = context.getReceiverExpression(codegen.typeMapper);
|
||||
expression.store(callable.getReceiverClass(), v);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public final class MutableClosure implements CalculatedClosure {
|
||||
DeclarationDescriptor classContainer = classDescriptor.getContainingDeclaration();
|
||||
if (classContainer instanceof CallableMemberDescriptor) {
|
||||
CallableMemberDescriptor member = getDirectMember((CallableMemberDescriptor) classContainer);
|
||||
if (member.getReceiverParameter() != null) {
|
||||
if (member.getExtensionReceiverParameter() != null) {
|
||||
return member;
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public final class MutableClosure implements CalculatedClosure {
|
||||
public JetType getCaptureReceiverType() {
|
||||
if (captureReceiver) {
|
||||
//noinspection ConstantConditions
|
||||
ReceiverParameterDescriptor parameter = enclosingReceiverDescriptor.getReceiverParameter();
|
||||
ReceiverParameterDescriptor parameter = enclosingReceiverDescriptor.getExtensionReceiverParameter();
|
||||
assert parameter != null : "Receiver parameter should exist in " + enclosingReceiverDescriptor;
|
||||
return parameter.getType();
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
public final CallableDescriptor getCallableDescriptorWithReceiver() {
|
||||
if (contextDescriptor instanceof CallableDescriptor) {
|
||||
CallableDescriptor callableDescriptor = (CallableDescriptor) getContextDescriptor();
|
||||
return callableDescriptor.getReceiverParameter() != null ? callableDescriptor : null;
|
||||
return callableDescriptor.getExtensionReceiverParameter() != null ? callableDescriptor : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ public interface LocalLookup {
|
||||
) {
|
||||
if (closure.getEnclosingReceiverDescriptor() != d) return null;
|
||||
|
||||
JetType receiverType = ((CallableDescriptor) d).getReceiverParameter().getType();
|
||||
JetType receiverType = ((CallableDescriptor) d).getExtensionReceiverParameter().getType();
|
||||
Type type = state.getTypeMapper().mapType(receiverType);
|
||||
StackValue innerValue = StackValue.field(type, classType, CAPTURED_RECEIVER_FIELD, false);
|
||||
closure.setCaptureReceiver();
|
||||
@@ -137,7 +137,7 @@ public interface LocalLookup {
|
||||
@Override
|
||||
public StackValue outerValue(@NotNull EnclosedValueDescriptor d, @NotNull ExpressionCodegen codegen) {
|
||||
CallableDescriptor descriptor = (CallableDescriptor) d.getDescriptor();
|
||||
return StackValue.local(descriptor.getExpectedThisObject() != null ? 1 : 0, d.getType());
|
||||
return StackValue.local(descriptor.getDispatchReceiverParameter() != null ? 1 : 0, d.getType());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public class MethodContext extends CodegenContext<CallableMemberDescriptor> {
|
||||
public StackValue getReceiverExpression(JetTypeMapper typeMapper) {
|
||||
assert getCallableDescriptorWithReceiver() != null;
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
Type asmType = typeMapper.mapType(getCallableDescriptorWithReceiver().getReceiverParameter().getType());
|
||||
Type asmType = typeMapper.mapType(getCallableDescriptorWithReceiver().getExtensionReceiverParameter().getType());
|
||||
return StackValue.local(AsmUtil.getReceiverIndex(this, getContextDescriptor()), asmType);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,8 +58,8 @@ public class Clone extends IntrinsicMethod {
|
||||
}
|
||||
|
||||
private static boolean isSuperCall(@NotNull ResolvedCall<?> resolvedCall) {
|
||||
ReceiverValue thisObject = resolvedCall.getThisObject();
|
||||
return thisObject instanceof ExpressionReceiver &&
|
||||
((ExpressionReceiver) thisObject).getExpression() instanceof JetSuperExpression;
|
||||
ReceiverValue dispatchReceiver = resolvedCall.getDispatchReceiver();
|
||||
return dispatchReceiver instanceof ExpressionReceiver &&
|
||||
((ExpressionReceiver) dispatchReceiver).getExpression() instanceof JetSuperExpression;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ class IntrinsicsMap {
|
||||
|
||||
@Nullable
|
||||
private static FqNameUnsafe getReceiverParameterFqName(@NotNull CallableMemberDescriptor descriptor) {
|
||||
ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter();
|
||||
ReceiverParameterDescriptor receiverParameter = descriptor.getExtensionReceiverParameter();
|
||||
if (receiverParameter == null) return null;
|
||||
|
||||
ClassifierDescriptor classifier = receiverParameter.getType().getConstructor().getDeclarationDescriptor();
|
||||
|
||||
@@ -524,7 +524,7 @@ public class JetTypeMapper {
|
||||
Type calleeType = isLocalNamedFun(functionDescriptor) ? owner : null;
|
||||
|
||||
Type receiverParameterType;
|
||||
ReceiverParameterDescriptor receiverParameter = functionDescriptor.getOriginal().getReceiverParameter();
|
||||
ReceiverParameterDescriptor receiverParameter = functionDescriptor.getOriginal().getExtensionReceiverParameter();
|
||||
if (receiverParameter != null) {
|
||||
receiverParameterType = mapType(receiverParameter.getType());
|
||||
}
|
||||
@@ -624,7 +624,7 @@ public class JetTypeMapper {
|
||||
sw.writeParametersStart();
|
||||
writeThisIfNeeded(f, kind, sw);
|
||||
|
||||
ReceiverParameterDescriptor receiverParameter = f.getReceiverParameter();
|
||||
ReceiverParameterDescriptor receiverParameter = f.getExtensionReceiverParameter();
|
||||
if (receiverParameter != null) {
|
||||
writeParameter(sw, JvmMethodParameterKind.RECEIVER, receiverParameter.getType());
|
||||
}
|
||||
@@ -664,7 +664,7 @@ public class JetTypeMapper {
|
||||
public Method mapDefaultMethod(@NotNull FunctionDescriptor functionDescriptor, @NotNull OwnerKind kind, @NotNull CodegenContext<?> context) {
|
||||
Method jvmSignature = mapSignature(functionDescriptor, kind).getAsmMethod();
|
||||
Type ownerType = mapOwner(functionDescriptor, isCallInsideSameModuleAsDeclared(functionDescriptor, context, getOutDirectory()));
|
||||
String descriptor = getDefaultDescriptor(jvmSignature, functionDescriptor.getReceiverParameter() != null);
|
||||
String descriptor = getDefaultDescriptor(jvmSignature, functionDescriptor.getExtensionReceiverParameter() != null);
|
||||
boolean isConstructor = "<init>".equals(jvmSignature.getName());
|
||||
if (!isStaticMethod(kind, functionDescriptor) && !isConstructor) {
|
||||
descriptor = descriptor.replace("(", "(" + ownerType.getDescriptor());
|
||||
@@ -713,7 +713,7 @@ public class JetTypeMapper {
|
||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||
thisType = getTraitImplThisParameterClass((ClassDescriptor) descriptor.getContainingDeclaration());
|
||||
}
|
||||
else if (isAccessor(descriptor) && descriptor.getExpectedThisObject() != null) {
|
||||
else if (isAccessor(descriptor) && descriptor.getDispatchReceiverParameter() != null) {
|
||||
thisType = (ClassDescriptor) descriptor.getContainingDeclaration();
|
||||
}
|
||||
else return;
|
||||
@@ -804,7 +804,7 @@ public class JetTypeMapper {
|
||||
private void writeAdditionalConstructorParameters(@NotNull ConstructorDescriptor descriptor, @NotNull BothSignatureWriter sw) {
|
||||
CalculatedClosure closure = bindingContext.get(CodegenBinding.CLOSURE, descriptor.getContainingDeclaration());
|
||||
|
||||
ClassDescriptor captureThis = getExpectedThisObjectForConstructorCall(descriptor, closure);
|
||||
ClassDescriptor captureThis = getDispatchReceiverParameterForConstructorCall(descriptor, closure);
|
||||
if (captureThis != null) {
|
||||
writeParameter(sw, JvmMethodParameterKind.OUTER, captureThis.getDefaultType());
|
||||
}
|
||||
@@ -930,7 +930,7 @@ public class JetTypeMapper {
|
||||
return asmTypeForAnonymousClass(bindingContext, (FunctionDescriptor) descriptor);
|
||||
}
|
||||
else if (descriptor instanceof PropertyDescriptor || descriptor instanceof FunctionDescriptor) {
|
||||
ReceiverParameterDescriptor receiverParameter = ((CallableDescriptor) descriptor).getReceiverParameter();
|
||||
ReceiverParameterDescriptor receiverParameter = ((CallableDescriptor) descriptor).getExtensionReceiverParameter();
|
||||
assert receiverParameter != null : "Callable should have a receiver parameter: " + descriptor;
|
||||
return StackValue.sharedTypeForType(mapType(receiverParameter.getType()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user