NO_RECEIVER_PARAMETER is now simply null

This commit is contained in:
Andrey Breslav
2012-11-01 16:34:44 +04:00
parent a325d86e20
commit ec255e8342
62 changed files with 194 additions and 264 deletions
@@ -159,7 +159,7 @@ public final class TipsManager {
Collections2.filter(JetScopeUtils.getAllExtensions(scope), new Predicate<CallableDescriptor>() {
@Override
public boolean apply(CallableDescriptor callableDescriptor) {
if (!callableDescriptor.getReceiverParameter().exists()) {
if (callableDescriptor.getReceiverParameter() == null) {
return false;
}
for (ReceiverParameterDescriptor receiverDescriptor : result) {
@@ -18,6 +18,7 @@ package org.jetbrains.jet.codegen;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Collections;
@@ -35,13 +36,13 @@ public class AccessorForFunctionDescriptor extends SimpleFunctionDescriptorImpl
FunctionDescriptor fd = (FunctionDescriptor) descriptor;
initialize(fd.getReceiverParameter().exists() ? fd.getReceiverParameter().getType() : null,
descriptor instanceof ConstructorDescriptor ? NO_RECEIVER_PARAMETER : fd.getExpectedThisObject(),
Collections.<TypeParameterDescriptor>emptyList(),
fd.getValueParameters(),
fd.getReturnType(),
Modality.FINAL,
Visibilities.INTERNAL,
initialize(DescriptorUtils.getReceiverParameterType(fd.getReceiverParameter()),
descriptor instanceof ConstructorDescriptor ? NO_RECEIVER_PARAMETER : fd.getExpectedThisObject(),
Collections.<TypeParameterDescriptor>emptyList(),
fd.getValueParameters(),
fd.getReturnType(),
Modality.FINAL,
Visibilities.INTERNAL,
/*isInline = */ false);
}
}
@@ -18,6 +18,7 @@ package org.jetbrains.jet.codegen;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.JetType;
@@ -32,7 +33,7 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptor {
pd.isVar(), Name.identifier(pd.getName() + "$b$" + index),
Kind.DECLARATION);
JetType receiverType = pd.getReceiverParameter().exists() ? pd.getReceiverParameter().getType() : null;
JetType receiverType = DescriptorUtils.getReceiverParameterType(pd.getReceiverParameter());
setType(pd.getType(), Collections.<TypeParameterDescriptorImpl>emptyList(), pd.getExpectedThisObject(), receiverType);
initialize(new Getter(this), new Setter(this));
}
@@ -175,7 +175,7 @@ public class ClosureCodegen extends GenerationStateAware {
final ReceiverParameterDescriptor receiver = funDescriptor.getReceiverParameter();
int count = 1;
if (receiver.exists()) {
if (receiver != null) {
StackValue.local(count, OBJECT_TYPE).put(OBJECT_TYPE, iv);
StackValue.onStack(OBJECT_TYPE)
.upcast(typeMapper.mapType(receiver.getType()), iv);
@@ -69,12 +69,13 @@ public class CodegenUtil {
public static SimpleFunctionDescriptor createInvoke(FunctionDescriptor fd) {
int arity = fd.getValueParameters().size();
SimpleFunctionDescriptorImpl invokeDescriptor = new SimpleFunctionDescriptorImpl(
fd.getExpectedThisObject().exists() ? KotlinBuiltIns.getInstance().getExtensionFunction(arity) : KotlinBuiltIns.getInstance().getFunction(arity),
fd.getExpectedThisObject() != null
? KotlinBuiltIns.getInstance().getExtensionFunction(arity) : KotlinBuiltIns.getInstance().getFunction(arity),
Collections.<AnnotationDescriptor>emptyList(),
Name.identifier("invoke"),
CallableMemberDescriptor.Kind.DECLARATION);
invokeDescriptor.initialize(fd.getReceiverParameter().exists() ? fd.getReceiverParameter().getType() : null,
invokeDescriptor.initialize(DescriptorUtils.getReceiverParameterType(fd.getReceiverParameter()),
fd.getExpectedThisObject(),
Collections.<TypeParameterDescriptorImpl>emptyList(),
fd.getValueParameters(),
@@ -121,7 +122,7 @@ public class CodegenUtil {
@NotNull
public static JvmClassName getInternalClassName(FunctionDescriptor descriptor) {
final int paramCount = descriptor.getValueParameters().size();
if (descriptor.getReceiverParameter().exists()) {
if (descriptor.getReceiverParameter() != null) {
return JvmClassName.byInternalName("jet/ExtensionFunction" + paramCount);
}
else {
@@ -136,7 +137,7 @@ public class CodegenUtil {
signatureWriter.writeFormalTypeParametersStart();
signatureWriter.writeFormalTypeParametersEnd();
boolean isExtensionFunction = fd.getReceiverParameter().exists();
boolean isExtensionFunction = fd.getReceiverParameter() != null;
int paramCount = fd.getValueParameters().size();
if (isExtensionFunction) {
paramCount++;
@@ -1379,7 +1379,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
final StackValue.Property iValue =
intermediateValueForProperty(propertyDescriptor, directToField, isSuper ? (JetSuperExpression) r : null);
if (!directToField && resolvedCall != null && !isSuper) {
receiver.put(propertyDescriptor.getReceiverParameter().exists() || isStatic
receiver.put(propertyDescriptor.getReceiverParameter() != null || isStatic
? receiver.type
: iValue.methodOwner.getAsmType(), v);
}
@@ -1566,7 +1566,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
getter = null;
}
if (getter == null && propertyDescriptor.getReceiverParameter().exists()) {
if (getter == null && propertyDescriptor.getReceiverParameter() != null) {
throw new IllegalStateException();
}
}
@@ -1586,7 +1586,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
setter = null;
}
if (setter == null && propertyDescriptor.isVar() && propertyDescriptor.getReceiverParameter().exists()) {
if (setter == null && propertyDescriptor.isVar() && propertyDescriptor.getReceiverParameter() != null) {
throw new IllegalStateException();
}
}
@@ -3018,7 +3018,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
gen(array, asmType(((ClassDescriptor) getterDescriptor.getContainingDeclaration()).getDefaultType()));
}
if (getterDescriptor.getReceiverParameter().exists()) {
if (getterDescriptor.getReceiverParameter() != null) {
index++;
}
asmType = accessor.getSignature().getAsmMethod().getReturnType();
@@ -3033,7 +3033,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
gen(array, arrayType);
}
if (setterDescriptor.getReceiverParameter().exists()) {
if (setterDescriptor.getReceiverParameter() != null) {
index++;
}
asmType = argumentTypes[argumentTypes.length - 1];
@@ -147,7 +147,7 @@ public class FunctionCodegen extends GenerationStateAware {
Type thisType;
ReceiverParameterDescriptor expectedThisObject = functionDescriptor.getExpectedThisObject();
if (expectedThisObject.exists()) {
if (expectedThisObject != null) {
thisType = typeMapper.mapType(expectedThisObject.getType());
}
else if (fun instanceof JetFunctionLiteralExpression || isLocalFun(bindingContext, functionDescriptor)) {
@@ -188,7 +188,7 @@ public class FunctionCodegen extends GenerationStateAware {
add++;
}
if (functionDescriptor.getReceiverParameter().exists()) {
if (functionDescriptor.getReceiverParameter() != null) {
add++;
}
@@ -258,8 +258,9 @@ public class FunctionCodegen extends GenerationStateAware {
mv.visitLocalVariable("this", thisType.getDescriptor(), null, methodBegin, methodEnd, k++);
}
if (functionDescriptor.getReceiverParameter().exists()) {
Type type = typeMapper.mapType(functionDescriptor.getReceiverParameter().getType());
ReceiverParameterDescriptor receiverParameter = functionDescriptor.getReceiverParameter();
if (receiverParameter != null) {
Type type = typeMapper.mapType(receiverParameter.getType());
mv.visitLocalVariable(JvmAbi.RECEIVER_PARAMETER, type.getDescriptor(), null, methodBegin, methodEnd, k);
k += type.getSize();
}
@@ -430,7 +431,7 @@ public class FunctionCodegen extends GenerationStateAware {
final List<JvmMethodParameterSignature> kotlinParameterTypes = jvmSignature.getKotlinParameterTypes();
assert kotlinParameterTypes != null;
if (receiverParameter.exists()) {
if (receiverParameter != null) {
JetValueParameterAnnotationWriter av = JetValueParameterAnnotationWriter.visitParameterAnnotation(mv, start++);
av.writeName(JvmAbi.RECEIVER_PARAMETER);
av.writeReceiver();
@@ -546,7 +547,7 @@ public class FunctionCodegen extends GenerationStateAware {
}
ReceiverParameterDescriptor receiverParameter = functionDescriptor.getReceiverParameter();
boolean hasReceiver = receiverParameter.exists();
boolean hasReceiver = receiverParameter != null;
boolean isStatic = isStatic(kind);
if (kind == OwnerKind.TRAIT_IMPL) {
@@ -64,7 +64,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
((ClassDescriptorImpl)classDescriptor).initialize(
false,
Collections.<TypeParameterDescriptor>emptyList(),
Collections.singleton((funDescriptor.getReceiverParameter().exists()
Collections.singleton((funDescriptor.getReceiverParameter() != null
? KotlinBuiltIns.getInstance().getExtensionFunction(arity)
: KotlinBuiltIns.getInstance().getFunction(arity)).getDefaultType()), JetScope.EMPTY,
Collections.<ConstructorDescriptor>emptySet(), null);
@@ -183,7 +183,7 @@ public class CodegenBinding {
? ((PropertyAccessorDescriptor) enclosingReceiver).getCorrespondingProperty()
: enclosingReceiver;
if (!enclosingReceiver.getReceiverParameter().exists()) {
if (enclosingReceiver.getReceiverParameter() == null) {
enclosingReceiver = null;
}
}
@@ -110,7 +110,7 @@ public abstract class CodegenContext {
public final CallableDescriptor getCallableDescriptorWithReceiver() {
if (contextDescriptor instanceof CallableDescriptor) {
final CallableDescriptor callableDescriptor = (CallableDescriptor) getContextDescriptor();
return callableDescriptor.getReceiverParameter().exists() ? callableDescriptor : null;
return callableDescriptor.getReceiverParameter() != null ? callableDescriptor : null;
}
return null;
}
@@ -131,7 +131,7 @@ public interface LocalLookup {
@Override
public StackValue outerValue(EnclosedValueDescriptor d, ExpressionCodegen expressionCodegen) {
CallableDescriptor descriptor = (FunctionDescriptor) d.getDescriptor();
return StackValue.local(descriptor.getExpectedThisObject().exists() ? 1 : 0, d.getType());
return StackValue.local(descriptor.getExpectedThisObject() != null ? 1 : 0, d.getType());
}
};
@@ -219,7 +219,7 @@ public class IntrinsicMethods {
if (descriptor instanceof SimpleFunctionDescriptor) {
SimpleFunctionDescriptor functionDescriptor = (SimpleFunctionDescriptor) descriptor;
if (!functionDescriptor.getReceiverParameter().exists()) {
if (functionDescriptor.getReceiverParameter() == null) {
FqNameUnsafe ownerFqName = DescriptorUtils.getFQName(descriptor.getContainingDeclaration());
if (ownerFqName.equalsTo("jet.String")) {
return new PsiMethodCall(functionDescriptor);
@@ -460,8 +460,9 @@ public class JetTypeMapper extends BindingTraceAware {
Type receiverParameterType;
if (functionDescriptor.getReceiverParameter().exists()) {
receiverParameterType = mapType(functionDescriptor.getOriginal().getReceiverParameter().getType());
ReceiverParameterDescriptor receiverParameter = functionDescriptor.getOriginal().getReceiverParameter();
if (receiverParameter != null) {
receiverParameterType = mapType(receiverParameter.getType());
}
else {
receiverParameterType = null;
@@ -499,8 +500,7 @@ public class JetTypeMapper extends BindingTraceAware {
writeFormalTypeParameters(f.getTypeParameters(), signatureVisitor);
final ReceiverParameterDescriptor receiverTypeRef = f.getReceiverParameter();
final JetType receiverType = !receiverTypeRef.exists() ? null : receiverTypeRef.getType();
final JetType receiverType = DescriptorUtils.getReceiverParameterType(f.getReceiverParameter());
final List<ValueParameterDescriptor> parameters = f.getValueParameters();
signatureVisitor.writeParametersStart();
@@ -547,7 +547,7 @@ public class JetTypeMapper extends BindingTraceAware {
}
private void writeThisForAccessorIfNeeded(FunctionDescriptor f, BothSignatureWriter signatureVisitor) {
if (isAccessor(f) && f.getExpectedThisObject().exists()) {
if (isAccessor(f) && f.getExpectedThisObject() != null) {
signatureVisitor.writeParameterType(JvmMethodParameterKind.THIS);
mapType(((ClassifierDescriptor) f.getContainingDeclaration()).getDefaultType(), signatureVisitor, JetTypeMapperMode.VALUE);
signatureVisitor.writeParameterTypeEnd();
@@ -637,8 +637,8 @@ public class JetTypeMapper extends BindingTraceAware {
return signatureWriter.makeJvmMethodSignature(name.getName());
}
private void writeReceiverIfNeeded(ReceiverParameterDescriptor receiver, BothSignatureWriter signatureWriter) {
if (receiver.exists()) {
private void writeReceiverIfNeeded(@Nullable ReceiverParameterDescriptor receiver, BothSignatureWriter signatureWriter) {
if (receiver != null) {
signatureWriter.writeParameterType(JvmMethodParameterKind.RECEIVER);
mapType(receiver.getType(), signatureWriter, JetTypeMapperMode.VALUE);
signatureWriter.writeParameterTypeEnd();
@@ -895,8 +895,9 @@ public class JetTypeMapper extends BindingTraceAware {
JvmMethodSignature descriptor = erasedInvokeSignature(fd);
JvmClassName owner = getInternalClassName(fd);
Type receiverParameterType;
if (fd.getReceiverParameter().exists()) {
receiverParameterType = mapType(fd.getOriginal().getReceiverParameter().getType());
ReceiverParameterDescriptor receiverParameter = fd.getOriginal().getReceiverParameter();
if (receiverParameter != null) {
receiverParameterType = mapType(receiverParameter.getType());
}
else {
receiverParameterType = null;