Refine type of CalculatedClosure#superCall
Instead of PSI, store the actual resolved call
This commit is contained in:
@@ -1334,11 +1334,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
pushClosureOnStack(closure, false, defaultCallGenerator);
|
||||
|
||||
JetDelegatorToSuperCall superCall = closure.getSuperCall();
|
||||
ResolvedCall<ConstructorDescriptor> superCall = closure.getSuperCall();
|
||||
if (superCall != null) {
|
||||
ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(superCall, bindingContext);
|
||||
ConstructorDescriptor superConstructor = (ConstructorDescriptor) resolvedCall.getResultingDescriptor();
|
||||
List<ResolvedValueArgument> valueArguments = resolvedCall.getValueArgumentsByIndex();
|
||||
ConstructorDescriptor superConstructor = superCall.getResultingDescriptor();
|
||||
List<ResolvedValueArgument> valueArguments = superCall.getValueArgumentsByIndex();
|
||||
assert valueArguments != null : "Failed to arrange value arguments by index: " + superConstructor;
|
||||
ArgumentGenerator argumentGenerator =
|
||||
new CallBasedArgumentGenerator(this, defaultCallGenerator, superConstructor.getValueParameters(),
|
||||
|
||||
@@ -19,23 +19,23 @@ package org.jetbrains.jet.codegen.binding;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
import org.jetbrains.jet.codegen.context.EnclosedValueDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface CalculatedClosure {
|
||||
|
||||
@Nullable
|
||||
ClassDescriptor getEnclosingClass();
|
||||
|
||||
@Nullable
|
||||
JetDelegatorToSuperCall getSuperCall();
|
||||
ResolvedCall<ConstructorDescriptor> getSuperCall();
|
||||
|
||||
@Nullable
|
||||
ClassDescriptor getCaptureThis();
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.descriptors.impl.ClassDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
@@ -42,6 +43,7 @@ import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.codegen.JvmCodegenUtil.isInterface;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
import static org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage.getResolvedCall;
|
||||
|
||||
public class CodegenBinding {
|
||||
public static final WritableSlice<ClassDescriptor, MutableClosure> CLOSURE = Slices.createSimpleSlice();
|
||||
@@ -170,7 +172,7 @@ public class CodegenBinding {
|
||||
@Nullable ClassDescriptor enclosing,
|
||||
@NotNull Type asmType
|
||||
) {
|
||||
JetDelegatorToSuperCall superCall = findSuperCall(bindingTrace.getBindingContext(), element);
|
||||
ResolvedCall<ConstructorDescriptor> superCall = findSuperCall(bindingTrace.getBindingContext(), element);
|
||||
|
||||
CallableDescriptor enclosingReceiver = null;
|
||||
if (classDescriptor.getContainingDeclaration() instanceof CallableDescriptor) {
|
||||
@@ -324,7 +326,11 @@ public class CodegenBinding {
|
||||
return closure != null && closure.getCaptureThis() != null;
|
||||
}
|
||||
|
||||
private static JetDelegatorToSuperCall findSuperCall(BindingContext bindingContext, JetElement classOrObject) {
|
||||
@Nullable
|
||||
private static ResolvedCall<ConstructorDescriptor> findSuperCall(
|
||||
@NotNull BindingContext bindingContext,
|
||||
@Nullable JetElement classOrObject
|
||||
) {
|
||||
if (!(classOrObject instanceof JetClassOrObject)) {
|
||||
return null;
|
||||
}
|
||||
@@ -335,16 +341,17 @@ public class CodegenBinding {
|
||||
|
||||
for (JetDelegationSpecifier specifier : ((JetClassOrObject) classOrObject).getDelegationSpecifiers()) {
|
||||
if (specifier instanceof JetDelegatorToSuperCall) {
|
||||
JetTypeReference typeReference = specifier.getTypeReference();
|
||||
|
||||
JetType superType = bindingContext.get(TYPE, typeReference);
|
||||
assert superType != null: String.format(
|
||||
JetType supertype = bindingContext.get(TYPE, specifier.getTypeReference());
|
||||
assert supertype != null : String.format(
|
||||
"No type in binding context for \n---\n%s\n---\n", JetPsiUtil.getElementTextWithContext(specifier));
|
||||
|
||||
ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor();
|
||||
assert superClassDescriptor != null;
|
||||
if (!isInterface(superClassDescriptor)) {
|
||||
return (JetDelegatorToSuperCall) specifier;
|
||||
ClassifierDescriptor superClass = supertype.getConstructor().getDeclarationDescriptor();
|
||||
if (superClass != null && !isInterface(superClass)) {
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(specifier, bindingContext);
|
||||
if (resolvedCall != null && resolvedCall.getResultingDescriptor() instanceof ConstructorDescriptor) {
|
||||
//noinspection unchecked
|
||||
return (ResolvedCall<ConstructorDescriptor>) resolvedCall;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,19 +19,16 @@ package org.jetbrains.jet.codegen.binding;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
import org.jetbrains.jet.codegen.context.EnclosedValueDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.org.objectweb.asm.Type;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public final class MutableClosure implements CalculatedClosure {
|
||||
private final JetDelegatorToSuperCall superCall;
|
||||
private final ResolvedCall<ConstructorDescriptor> superCall;
|
||||
|
||||
private final ClassDescriptor enclosingClass;
|
||||
private final CallableDescriptor enclosingReceiverDescriptor;
|
||||
@@ -43,9 +40,9 @@ public final class MutableClosure implements CalculatedClosure {
|
||||
private List<Pair<String, Type>> recordedFields;
|
||||
|
||||
MutableClosure(
|
||||
JetDelegatorToSuperCall superCall,
|
||||
ClassDescriptor enclosingClass,
|
||||
CallableDescriptor enclosingReceiverDescriptor
|
||||
@Nullable ResolvedCall<ConstructorDescriptor> superCall,
|
||||
@Nullable ClassDescriptor enclosingClass,
|
||||
@Nullable CallableDescriptor enclosingReceiverDescriptor
|
||||
) {
|
||||
this.superCall = superCall;
|
||||
this.enclosingClass = enclosingClass;
|
||||
@@ -59,7 +56,7 @@ public final class MutableClosure implements CalculatedClosure {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetDelegatorToSuperCall getSuperCall() {
|
||||
public ResolvedCall<ConstructorDescriptor> getSuperCall() {
|
||||
return superCall;
|
||||
}
|
||||
|
||||
@@ -75,6 +72,7 @@ public final class MutableClosure implements CalculatedClosure {
|
||||
@Override
|
||||
public JetType getCaptureReceiverType() {
|
||||
if (captureReceiver) {
|
||||
//noinspection ConstantConditions
|
||||
ReceiverParameterDescriptor parameter = enclosingReceiverDescriptor.getReceiverParameter();
|
||||
assert parameter != null : "Receiver parameter should exist in " + enclosingReceiverDescriptor;
|
||||
return parameter.getType();
|
||||
|
||||
@@ -29,12 +29,12 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.OverrideResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.constants.StringValue;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
@@ -805,17 +805,12 @@ public class JetTypeMapper {
|
||||
}
|
||||
}
|
||||
|
||||
JetDelegatorToSuperCall superCall = closure.getSuperCall();
|
||||
if (superCall != null) {
|
||||
DeclarationDescriptor superDescriptor = bindingContext
|
||||
.get(BindingContext.REFERENCE_TARGET, superCall.getCalleeExpression().getConstructorReferenceExpression());
|
||||
|
||||
if (superDescriptor instanceof ConstructorDescriptor && isAnonymousObject(descriptor.getContainingDeclaration())) {
|
||||
for (JvmMethodParameterSignature parameter : mapSignature((ConstructorDescriptor) superDescriptor).getValueParameters()) {
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.SUPER_OF_ANONYMOUS_CALL_PARAM);
|
||||
signatureWriter.writeAsmType(parameter.getAsmType());
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
ResolvedCall<ConstructorDescriptor> superCall = closure.getSuperCall();
|
||||
if (superCall != null && isAnonymousObject(descriptor.getContainingDeclaration())) {
|
||||
for (JvmMethodParameterSignature parameter : mapSignature(superCall.getResultingDescriptor()).getValueParameters()) {
|
||||
signatureWriter.writeParameterType(JvmMethodParameterKind.SUPER_OF_ANONYMOUS_CALL_PARAM);
|
||||
signatureWriter.writeAsmType(parameter.getAsmType());
|
||||
signatureWriter.writeParameterTypeEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user