Utilize existing mapType methods
Fix warnings related to nullable CallableDescriptor.getReturnType()
This commit is contained in:
@@ -36,7 +36,7 @@ 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.binding.MutableClosure;
|
import org.jetbrains.jet.codegen.binding.MutableClosure;
|
||||||
import org.jetbrains.jet.codegen.context.*;
|
import org.jetbrains.jet.codegen.context.*;
|
||||||
import org.jetbrains.jet.codegen.intrinsics.*;
|
import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethod;
|
||||||
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||||
@@ -1639,7 +1639,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
IntrinsicMethod intrinsic = state.getIntrinsics().getIntrinsic(memberDescriptor);
|
IntrinsicMethod intrinsic = state.getIntrinsics().getIntrinsic(memberDescriptor);
|
||||||
if (intrinsic != null) {
|
if (intrinsic != null) {
|
||||||
Type returnType = typeMapper.mapType(memberDescriptor.getReturnType());
|
Type returnType = typeMapper.mapType(memberDescriptor);
|
||||||
return intrinsic.generate(this, v, returnType, expression, Collections.<JetExpression>emptyList(), receiver, state);
|
return intrinsic.generate(this, v, returnType, expression, Collections.<JetExpression>emptyList(), receiver, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2021,7 +2021,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
args.add(argument.getArgumentExpression());
|
args.add(argument.getArgumentExpression());
|
||||||
}
|
}
|
||||||
|
|
||||||
Type returnType = typeMapper.mapType(resolvedCall.getResultingDescriptor().getReturnType());
|
Type returnType = typeMapper.mapType(resolvedCall.getResultingDescriptor());
|
||||||
|
|
||||||
StackValue stackValue = intrinsic.generate(this, v, returnType, call.getCallElement(), args, receiver, state);
|
StackValue stackValue = intrinsic.generate(this, v, returnType, call.getCallElement(), args, receiver, state);
|
||||||
stackValue.put(returnType, v);
|
stackValue.put(returnType, v);
|
||||||
@@ -2667,10 +2667,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
assert op instanceof FunctionDescriptor : String.valueOf(op);
|
assert op instanceof FunctionDescriptor : String.valueOf(op);
|
||||||
Callable callable = resolveToCallable((FunctionDescriptor) op, false);
|
Callable callable = resolveToCallable((FunctionDescriptor) op, false);
|
||||||
if (callable instanceof IntrinsicMethod) {
|
if (callable instanceof IntrinsicMethod) {
|
||||||
IntrinsicMethod intrinsic = (IntrinsicMethod) callable;
|
//noinspection ConstantConditions
|
||||||
Type returnType = typeMapper.mapType(resolvedCall.getResultingDescriptor().getReturnType());
|
Type returnType = typeMapper.mapType(resolvedCall.getResultingDescriptor());
|
||||||
return intrinsic.generate(this, v, returnType, expression,
|
return ((IntrinsicMethod) callable).generate(this, v, returnType, expression,
|
||||||
Arrays.asList(expression.getLeft(), expression.getRight()), receiver, state);
|
Arrays.asList(expression.getLeft(), expression.getRight()), receiver, state);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return invokeFunction(call, receiver, resolvedCall);
|
return invokeFunction(call, receiver, resolvedCall);
|
||||||
@@ -2913,13 +2913,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
value.dupReceiver(v); // receiver receiver
|
value.dupReceiver(v); // receiver receiver
|
||||||
value.put(lhsType, v); // receiver lhs
|
value.put(lhsType, v); // receiver lhs
|
||||||
IntrinsicMethod intrinsic = (IntrinsicMethod) callable;
|
IntrinsicMethod intrinsic = (IntrinsicMethod) callable;
|
||||||
//noinspection NullableProblems
|
|
||||||
JetExpression right = expression.getRight();
|
JetExpression right = expression.getRight();
|
||||||
assert right != null;
|
assert right != null;
|
||||||
Type returnType = typeMapper.mapType(((FunctionDescriptor) op).getReturnType());
|
Type returnType = typeMapper.mapType((FunctionDescriptor) op);
|
||||||
StackValue stackValue = intrinsic.generate(this, v, returnType, expression,
|
intrinsic.generate(this, v, returnType, expression, Collections.singletonList(right), StackValue.onStack(lhsType), state);
|
||||||
Arrays.asList(right),
|
|
||||||
StackValue.onStack(lhsType), state);
|
|
||||||
value.store(lhsType, v);
|
value.store(lhsType, v);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -3004,11 +3001,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
assert op instanceof FunctionDescriptor : String.valueOf(op);
|
assert op instanceof FunctionDescriptor : String.valueOf(op);
|
||||||
Callable callable = resolveToCallable((FunctionDescriptor) op, false);
|
Callable callable = resolveToCallable((FunctionDescriptor) op, false);
|
||||||
if (callable instanceof IntrinsicMethod) {
|
if (callable instanceof IntrinsicMethod) {
|
||||||
IntrinsicMethod intrinsic = (IntrinsicMethod) callable;
|
Type returnType = typeMapper.mapType((FunctionDescriptor) op);
|
||||||
//noinspection ConstantConditions
|
return ((IntrinsicMethod) callable).generate(this, v, returnType, expression,
|
||||||
Type returnType = typeMapper.mapType(((FunctionDescriptor) op).getReturnType());
|
Collections.singletonList(expression.getBaseExpression()), receiver, state);
|
||||||
return intrinsic.generate(this, v, returnType, expression,
|
|
||||||
Arrays.asList(expression.getBaseExpression()), receiver, state);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DeclarationDescriptor cls = op.getContainingDeclaration();
|
DeclarationDescriptor cls = op.getContainingDeclaration();
|
||||||
|
|||||||
@@ -33,12 +33,12 @@ public class FieldInfo {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
Type fieldType = typeMapper.mapType(fieldClassDescriptor.getDefaultType());
|
Type fieldType = typeMapper.mapType(fieldClassDescriptor);
|
||||||
|
|
||||||
ClassDescriptor ownerDescriptor = kind == ClassKind.OBJECT
|
ClassDescriptor ownerDescriptor = kind == ClassKind.OBJECT
|
||||||
? fieldClassDescriptor: DescriptorUtils.getParentOfType(fieldClassDescriptor, ClassDescriptor.class);
|
? fieldClassDescriptor: DescriptorUtils.getParentOfType(fieldClassDescriptor, ClassDescriptor.class);
|
||||||
assert ownerDescriptor != null;
|
assert ownerDescriptor != null;
|
||||||
Type ownerType = typeMapper.mapType(ownerDescriptor.getDefaultType());
|
Type ownerType = typeMapper.mapType(ownerDescriptor);
|
||||||
|
|
||||||
String fieldName = kind == ClassKind.ENUM_ENTRY
|
String fieldName = kind == ClassKind.ENUM_ENTRY
|
||||||
? fieldClassDescriptor.getName().asString()
|
? fieldClassDescriptor.getName().asString()
|
||||||
@@ -52,14 +52,11 @@ public class FieldInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final Type fieldType;
|
private final Type fieldType;
|
||||||
|
|
||||||
private final Type ownerType;
|
private final Type ownerType;
|
||||||
|
|
||||||
private final String fieldName;
|
private final String fieldName;
|
||||||
|
|
||||||
private final boolean isStatic;
|
private final boolean isStatic;
|
||||||
|
|
||||||
private FieldInfo(@NotNull Type ownerType, @NotNull Type fieldType, @NotNull String fieldName, @NotNull boolean isStatic) {
|
private FieldInfo(@NotNull Type ownerType, @NotNull Type fieldType, @NotNull String fieldName, boolean isStatic) {
|
||||||
this.ownerType = ownerType;
|
this.ownerType = ownerType;
|
||||||
this.fieldType = fieldType;
|
this.fieldType = fieldType;
|
||||||
this.fieldName = fieldName;
|
this.fieldName = fieldName;
|
||||||
@@ -86,7 +83,6 @@ public class FieldInfo {
|
|||||||
return fieldName;
|
return fieldName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public boolean isStatic() {
|
public boolean isStatic() {
|
||||||
return isStatic;
|
return isStatic;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
|||||||
private Type getThisTypeForFunction(@NotNull FunctionDescriptor functionDescriptor, @NotNull MethodContext context) {
|
private Type getThisTypeForFunction(@NotNull FunctionDescriptor functionDescriptor, @NotNull MethodContext context) {
|
||||||
ReceiverParameterDescriptor expectedThisObject = functionDescriptor.getExpectedThisObject();
|
ReceiverParameterDescriptor expectedThisObject = functionDescriptor.getExpectedThisObject();
|
||||||
if (functionDescriptor instanceof ConstructorDescriptor) {
|
if (functionDescriptor instanceof ConstructorDescriptor) {
|
||||||
return typeMapper.mapType(functionDescriptor.getReturnType());
|
return typeMapper.mapType(functionDescriptor);
|
||||||
}
|
}
|
||||||
else if (expectedThisObject != null) {
|
else if (expectedThisObject != null) {
|
||||||
return typeMapper.mapType(expectedThisObject.getType());
|
return typeMapper.mapType(expectedThisObject.getType());
|
||||||
|
|||||||
@@ -654,7 +654,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
iv.store(2, AsmTypeConstants.OBJECT_TYPE);
|
iv.store(2, AsmTypeConstants.OBJECT_TYPE);
|
||||||
|
|
||||||
for (PropertyDescriptor propertyDescriptor : properties) {
|
for (PropertyDescriptor propertyDescriptor : properties) {
|
||||||
Type asmType = typeMapper.mapType(propertyDescriptor.getType());
|
Type asmType = typeMapper.mapType(propertyDescriptor);
|
||||||
|
|
||||||
genPropertyOnStack(iv, propertyDescriptor, 0);
|
genPropertyOnStack(iv, propertyDescriptor, 0);
|
||||||
genPropertyOnStack(iv, propertyDescriptor, 2);
|
genPropertyOnStack(iv, propertyDescriptor, 2);
|
||||||
@@ -702,7 +702,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
genPropertyOnStack(iv, propertyDescriptor, 0);
|
genPropertyOnStack(iv, propertyDescriptor, 0);
|
||||||
|
|
||||||
Label ifNull = null;
|
Label ifNull = null;
|
||||||
Type asmType = typeMapper.mapType(propertyDescriptor.getType());
|
Type asmType = typeMapper.mapType(propertyDescriptor);
|
||||||
if (!isPrimitive(asmType)) {
|
if (!isPrimitive(asmType)) {
|
||||||
ifNull = new Label();
|
ifNull = new Label();
|
||||||
iv.dup();
|
iv.dup();
|
||||||
@@ -829,7 +829,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
private void generateCopyFunction(@NotNull final FunctionDescriptor function) {
|
private void generateCopyFunction(@NotNull final FunctionDescriptor function) {
|
||||||
JvmMethodSignature methodSignature = typeMapper.mapSignature(function);
|
JvmMethodSignature methodSignature = typeMapper.mapSignature(function);
|
||||||
|
|
||||||
final Type thisDescriptorType = typeMapper.mapType(descriptor.getDefaultType());
|
final Type thisDescriptorType = typeMapper.mapType(descriptor);
|
||||||
|
|
||||||
functionCodegen.generateMethod(myClass, methodSignature, function, new FunctionGenerationStrategy() {
|
functionCodegen.generateMethod(myClass, methodSignature, function, new FunctionGenerationStrategy() {
|
||||||
@Override
|
@Override
|
||||||
@@ -888,7 +888,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
assert propertyDescriptor != null
|
assert propertyDescriptor != null
|
||||||
: "Trying to generate default value for parameter of copy function that doesn't correspond to any property";
|
: "Trying to generate default value for parameter of copy function that doesn't correspond to any property";
|
||||||
codegen.v.load(0, thisDescriptorType);
|
codegen.v.load(0, thisDescriptorType);
|
||||||
Type propertyType = codegen.typeMapper.mapType(propertyDescriptor.getType());
|
Type propertyType = codegen.typeMapper.mapType(propertyDescriptor);
|
||||||
codegen.intermediateValueForProperty(propertyDescriptor, false, null)
|
codegen.intermediateValueForProperty(propertyDescriptor, false, null)
|
||||||
.put(propertyType, codegen.v);
|
.put(propertyType, codegen.v);
|
||||||
}
|
}
|
||||||
@@ -1300,8 +1300,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
!propertyDescriptor.isVar() &&
|
!propertyDescriptor.isVar() &&
|
||||||
Boolean.TRUE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor))) {
|
Boolean.TRUE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor))) {
|
||||||
// final property with backing field
|
// final property with backing field
|
||||||
field = StackValue.field(typeMapper.mapType(propertyDescriptor.getType()), classAsmType,
|
field = StackValue.field(typeMapper.mapType(propertyDescriptor), classAsmType, propertyDescriptor.getName().asString(), false);
|
||||||
propertyDescriptor.getName().asString(), false);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
iv.load(0, classAsmType);
|
iv.load(0, classAsmType);
|
||||||
@@ -1712,7 +1711,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
public static boolean shouldWriteFieldInitializer(PropertyDescriptor descriptor, JetTypeMapper mapper) {
|
public static boolean shouldWriteFieldInitializer(PropertyDescriptor descriptor, JetTypeMapper mapper) {
|
||||||
//final field of primitive or String type
|
//final field of primitive or String type
|
||||||
if (!descriptor.isVar()) {
|
if (!descriptor.isVar()) {
|
||||||
Type type = mapper.mapType(descriptor.getType());
|
Type type = mapper.mapType(descriptor);
|
||||||
return AsmUtil.isPrimitive(type) || "java.lang.String".equals(type.getClassName());
|
return AsmUtil.isPrimitive(type) || "java.lang.String".equals(type.getClassName());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -221,13 +221,14 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Type mapType(@NotNull VariableDescriptor variableDescriptor) {
|
public Type mapType(@NotNull CallableDescriptor descriptor) {
|
||||||
return mapType(variableDescriptor.getType(), null, JetTypeMapperMode.VALUE);
|
//noinspection ConstantConditions
|
||||||
|
return mapType(descriptor.getReturnType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Type mapType(@NotNull ClassifierDescriptor classifierDescriptor) {
|
public Type mapType(@NotNull ClassifierDescriptor descriptor) {
|
||||||
return mapType(classifierDescriptor.getDefaultType(), null, JetTypeMapperMode.VALUE);
|
return mapType(descriptor.getDefaultType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user