Minor inlines and renames in PropertyCodegen

This commit is contained in:
Alexander Udalov
2014-01-13 20:32:22 +04:00
parent 64b982d821
commit b92e121458
@@ -26,13 +26,11 @@ import org.jetbrains.asm4.Opcodes;
import org.jetbrains.asm4.Type; import org.jetbrains.asm4.Type;
import org.jetbrains.asm4.commons.InstructionAdapter; import org.jetbrains.asm4.commons.InstructionAdapter;
import org.jetbrains.asm4.commons.Method; import org.jetbrains.asm4.commons.Method;
import org.jetbrains.jet.codegen.context.CodegenContext;
import org.jetbrains.jet.codegen.context.FieldOwnerContext; import org.jetbrains.jet.codegen.context.FieldOwnerContext;
import org.jetbrains.jet.codegen.context.PackageFacadeContext; import org.jetbrains.jet.codegen.context.PackageFacadeContext;
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.GenerationStateAware; import org.jetbrains.jet.codegen.state.GenerationStateAware;
import org.jetbrains.jet.codegen.state.JetTypeMapper;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -64,7 +62,7 @@ public class PropertyCodegen extends GenerationStateAware {
private final FieldOwnerContext context; private final FieldOwnerContext context;
@Nullable @Nullable
private MemberCodegen classBodyCodegen; private final MemberCodegen classBodyCodegen;
@NotNull @NotNull
private final OwnerKind kind; private final OwnerKind kind;
@@ -316,45 +314,34 @@ public class PropertyCodegen extends GenerationStateAware {
@Override @Override
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) { public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
generateDefaultAccessor(callableDescriptor, codegen.v, codegen); InstructionAdapter v = codegen.v;
} PropertyDescriptor propertyDescriptor = callableDescriptor.getCorrespondingProperty();
} Type type = codegen.typeMapper.mapType(propertyDescriptor);
private static void generateDefaultAccessor( int paramCode = 0;
@NotNull PropertyAccessorDescriptor accessorDescriptor, if (codegen.context.getContextKind() != OwnerKind.NAMESPACE) {
@NotNull InstructionAdapter iv, v.load(0, OBJECT_TYPE);
@NotNull ExpressionCodegen codegen paramCode = 1;
) {
JetTypeMapper typeMapper = codegen.typeMapper;
CodegenContext context = codegen.context;
OwnerKind kind = context.getContextKind();
PropertyDescriptor propertyDescriptor = accessorDescriptor.getCorrespondingProperty();
Type type = typeMapper.mapType(propertyDescriptor);
int paramCode = 0;
if (kind != OwnerKind.NAMESPACE) {
iv.load(0, OBJECT_TYPE);
paramCode = 1;
}
StackValue property = codegen.intermediateValueForProperty(accessorDescriptor.getCorrespondingProperty(), true, null);
if (accessorDescriptor instanceof PropertyGetterDescriptor) {
property.put(type, iv);
iv.areturn(type);
}
else if (accessorDescriptor instanceof PropertySetterDescriptor) {
ReceiverParameterDescriptor receiverParameter = propertyDescriptor.getReceiverParameter();
if (receiverParameter != null) {
paramCode += typeMapper.mapType(receiverParameter.getType()).getSize();
} }
iv.load(paramCode, type);
property.store(type, iv); StackValue property = codegen.intermediateValueForProperty(propertyDescriptor, true, null);
iv.visitInsn(RETURN);
} else { if (callableDescriptor instanceof PropertyGetterDescriptor) {
assert false : "Unreachable state"; property.put(type, v);
v.areturn(type);
}
else if (callableDescriptor instanceof PropertySetterDescriptor) {
ReceiverParameterDescriptor receiverParameter = propertyDescriptor.getReceiverParameter();
if (receiverParameter != null) {
paramCode += codegen.typeMapper.mapType(receiverParameter.getType()).getSize();
}
v.load(paramCode, type);
property.store(type, v);
v.visitInsn(RETURN);
} else {
throw new IllegalStateException("Unknown property accessor: " + callableDescriptor);
}
} }
} }
@@ -365,33 +352,31 @@ public class PropertyCodegen extends GenerationStateAware {
@Override @Override
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) { public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
JetTypeMapper typeMapper = codegen.typeMapper; InstructionAdapter v = codegen.v;
OwnerKind kind = codegen.context.getContextKind();
InstructionAdapter iv = codegen.v;
BindingContext bindingContext = state.getBindingContext();
BindingContext bindingContext = state.getBindingContext();
ResolvedCall<FunctionDescriptor> resolvedCall = ResolvedCall<FunctionDescriptor> resolvedCall =
bindingContext.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, callableDescriptor); bindingContext.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, callableDescriptor);
Call call = bindingContext.get(BindingContext.DELEGATED_PROPERTY_CALL, callableDescriptor); Call call = bindingContext.get(BindingContext.DELEGATED_PROPERTY_CALL, callableDescriptor);
assert call != null : "Call should be recorded for delegate call " + signature.toString(); assert call != null : "Call should be recorded for delegate call " + signature.toString();
PropertyDescriptor property = callableDescriptor.getCorrespondingProperty(); if (codegen.context.getContextKind() != OwnerKind.NAMESPACE) {
Type asmType = typeMapper.mapType(property); v.load(0, OBJECT_TYPE);
if (kind != OwnerKind.NAMESPACE) {
iv.load(0, OBJECT_TYPE);
} }
StackValue delegatedProperty = codegen.intermediateValueForProperty(property, true, null); PropertyDescriptor propertyDescriptor = callableDescriptor.getCorrespondingProperty();
StackValue delegatedProperty = codegen.intermediateValueForProperty(propertyDescriptor, true, null);
StackValue lastValue = codegen.invokeFunction(call, delegatedProperty, resolvedCall); StackValue lastValue = codegen.invokeFunction(call, delegatedProperty, resolvedCall);
if (lastValue.type != Type.VOID_TYPE) { if (lastValue.type != Type.VOID_TYPE) {
lastValue.put(asmType, iv); Type asmType = codegen.typeMapper.mapType(propertyDescriptor);
iv.areturn(asmType); lastValue.put(asmType, v);
v.areturn(asmType);
} }
else { else {
iv.areturn(Type.VOID_TYPE); v.areturn(Type.VOID_TYPE);
} }
} }
} }