Minor, remove code duplication in ImplementationBodyCodegen

This commit is contained in:
Alexander Udalov
2014-07-10 21:05:43 +04:00
parent 2a763598e7
commit 295283dc40
@@ -975,16 +975,18 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
final PropertyDescriptor bridge = (PropertyDescriptor) entry.getValue(); final PropertyDescriptor bridge = (PropertyDescriptor) entry.getValue();
final PropertyDescriptor original = (PropertyDescriptor) entry.getKey(); final PropertyDescriptor original = (PropertyDescriptor) entry.getKey();
PropertyGetterDescriptor getter = bridge.getGetter(); class PropertyAccessorStrategy extends FunctionGenerationStrategy.CodegenBased<PropertyAccessorDescriptor> {
assert getter != null; public PropertyAccessorStrategy(@NotNull PropertyAccessorDescriptor callableDescriptor) {
functionCodegen.generateMethod(OtherOrigin(original.getGetter()), typeMapper.mapSignature(getter), getter, super(ImplementationBodyCodegen.this.state, callableDescriptor);
new FunctionGenerationStrategy.CodegenBased<PropertyGetterDescriptor>(state, getter) { }
@Override @Override
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) { public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
InstructionAdapter iv = codegen.v; boolean forceField = AsmUtil.isPropertyWithBackingFieldInOuterClass(original) &&
boolean forceField = AsmUtil.isPropertyWithBackingFieldInOuterClass(original) && !isClassObject(bridge.getContainingDeclaration()); !isClassObject(bridge.getContainingDeclaration());
StackValue property = codegen.intermediateValueForProperty(original, forceField, null, MethodKind.SYNTHETIC_ACCESSOR); StackValue property = codegen.intermediateValueForProperty(original, forceField, null, MethodKind.SYNTHETIC_ACCESSOR);
InstructionAdapter iv = codegen.v;
Type[] argTypes = signature.getAsmMethod().getArgumentTypes(); Type[] argTypes = signature.getAsmMethod().getArgumentTypes();
for (int i = 0, reg = 0; i < argTypes.length; i++) { for (int i = 0, reg = 0; i < argTypes.length; i++) {
Type argType = argTypes[i]; Type argType = argTypes[i];
@@ -993,10 +995,21 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
reg += argType.getSize(); reg += argType.getSize();
} }
property.put(property.type, iv); if (callableDescriptor instanceof PropertyGetterDescriptor) {
property.put(property.type, iv);
}
else {
property.store(property.type, iv);
}
iv.areturn(signature.getReturnType()); iv.areturn(signature.getReturnType());
} }
}); }
PropertyGetterDescriptor getter = bridge.getGetter();
assert getter != null;
functionCodegen.generateMethod(OtherOrigin(original.getGetter()), typeMapper.mapSignature(getter), getter,
new PropertyAccessorStrategy(getter));
if (bridge.isVar()) { if (bridge.isVar()) {
@@ -1004,25 +1017,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
assert setter != null; assert setter != null;
functionCodegen.generateMethod(OtherOrigin(original.getSetter()), typeMapper.mapSignature(setter), setter, functionCodegen.generateMethod(OtherOrigin(original.getSetter()), typeMapper.mapSignature(setter), setter,
new FunctionGenerationStrategy.CodegenBased<PropertySetterDescriptor>(state, setter) { new PropertyAccessorStrategy(setter));
@Override
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
boolean forceField = AsmUtil.isPropertyWithBackingFieldInOuterClass(original) && !isClassObject(bridge.getContainingDeclaration());
StackValue property = codegen.intermediateValueForProperty(original, forceField, null, MethodKind.SYNTHETIC_ACCESSOR);
InstructionAdapter iv = codegen.v;
Type[] argTypes = signature.getAsmMethod().getArgumentTypes();
for (int i = 0, reg = 0; i < argTypes.length; i++) {
Type argType = argTypes[i];
iv.load(reg, argType);
//noinspection AssignmentToForLoopParameter
reg += argType.getSize();
}
property.store(property.type, iv);
iv.areturn(signature.getReturnType());
}
});
} }
} }
else { else {