From 27bea0a607d565b05aa5e3427221a4675f8f78ad Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 2 Oct 2012 22:16:47 +0400 Subject: [PATCH] Pass state and property descriptor to StackValue.Property --- .../jet/codegen/ExpressionCodegen.java | 5 ++-- .../codegen/ImplementationBodyCodegen.java | 9 +++--- .../jetbrains/jet/codegen/ScriptCodegen.java | 2 +- .../org/jetbrains/jet/codegen/StackValue.java | 28 +++++++++++-------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index f99c05d6573..981edadf48f 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -1613,9 +1613,8 @@ public class ExpressionCodegen extends JetVisitor implem ownerParam = callableMethod.getDefaultImplParam(); } - return StackValue - .property(propertyDescriptor.getName().getName(), owner, ownerParam, asmType(propertyDescriptor.getType()), isStatic, - isInterface, isSuper, getter, setter, invokeOpcode); + return StackValue.property(propertyDescriptor, owner, ownerParam, asmType(propertyDescriptor.getType()), + isStatic, isInterface, isSuper, getter, setter, invokeOpcode, state); } private static boolean isOverrideForTrait(CallableMemberDescriptor propertyDescriptor) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 1a604e86434..fd7f00db6d1 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -962,7 +962,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { curParam++; } - generateInitializers(codegen, iv, myClass.getDeclarations(), bindingContext, typeMapper); + generateInitializers(codegen, iv, myClass.getDeclarations(), bindingContext, state); mv.visitInsn(RETURN); FunctionCodegen.endVisit(mv, "constructor", myClass); @@ -1451,8 +1451,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { public static void generateInitializers( @NotNull ExpressionCodegen codegen, @NotNull InstructionAdapter iv, @NotNull List declarations, - @NotNull BindingContext bindingContext, @NotNull JetTypeMapper typeMapper + @NotNull BindingContext bindingContext, @NotNull GenerationState state ) { + JetTypeMapper typeMapper = state.getTypeMapper(); for (JetDeclaration declaration : declarations) { if (declaration instanceof JetProperty) { final PropertyDescriptor propertyDescriptor = (PropertyDescriptor) bindingContext.get(BindingContext.VARIABLE, declaration); @@ -1476,8 +1477,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { // @todo write directly to the field. Fix test excloset.jet::test6 JvmClassName owner = typeMapper.getOwner(propertyDescriptor, OwnerKind.IMPLEMENTATION); Type propType = typeMapper.mapType(jetType); - StackValue.property(propertyDescriptor.getName().getName(), owner, owner, - propType, false, false, false, null, null, 0).store(propType, iv); + StackValue.property(propertyDescriptor, owner, owner, + propType, false, false, false, null, null, 0, state).store(propType, iv); } } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java index 11155696bbd..79b3fc27230 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java @@ -150,7 +150,7 @@ public class ScriptCodegen extends MemberCodegen { instructionAdapter, scriptDeclaration.getDeclarations(), bindingContext, - typeMapper); + state); int offset = 1; diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java index 22bd220363b..96866387fcc 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java @@ -152,7 +152,7 @@ public abstract class StackValue { } public static Property property( - String name, + PropertyDescriptor descriptor, JvmClassName methodOwner, JvmClassName methodOwnerParam, Type type, @@ -161,9 +161,11 @@ public abstract class StackValue { boolean isSuper, @Nullable Method getter, @Nullable Method setter, - int invokeOpcode + int invokeOpcode, + GenerationState state ) { - return new Property(name, methodOwner, methodOwnerParam, getter, setter, isStatic, isInterface, isSuper, type, invokeOpcode); + return new Property(descriptor, methodOwner, methodOwnerParam, getter, setter, isStatic, isInterface, isSuper, type, invokeOpcode, + state); } public static StackValue expression(Type type, JetExpression expression, ExpressionCodegen generator) { @@ -929,8 +931,6 @@ public abstract class StackValue { } static class Property extends StackValue { - @NotNull - private final String name; @Nullable private final Method getter; @Nullable @@ -943,21 +943,27 @@ public abstract class StackValue { private final boolean isInterface; private final boolean isSuper; private final int invokeOpcode; + @NotNull + private final PropertyDescriptor descriptor; + @NotNull + private final GenerationState state; public Property( - @NotNull String name, @NotNull JvmClassName methodOwner, @NotNull JvmClassName methodOwnerParam, - Method getter, Method setter, boolean aStatic, boolean isInterface, boolean isSuper, Type type, int invokeOpcode + @NotNull PropertyDescriptor descriptor, @NotNull JvmClassName methodOwner, @NotNull JvmClassName methodOwnerParam, + @Nullable Method getter, @Nullable Method setter, boolean isStatic, boolean isInterface, boolean isSuper, + @NotNull Type type, int invokeOpcode, @NotNull GenerationState state ) { super(type); - this.name = name; this.methodOwner = methodOwner; this.methodOwnerParam = methodOwnerParam; this.getter = getter; this.setter = setter; - isStatic = aStatic; + this.isStatic = isStatic; this.isInterface = isInterface; this.isSuper = isSuper; this.invokeOpcode = invokeOpcode; + this.descriptor = descriptor; + this.state = state; if (invokeOpcode == 0) { if (setter != null || getter != null) { throw new IllegalArgumentException(); @@ -974,7 +980,7 @@ public abstract class StackValue { } else { if (getter == null) { - v.visitFieldInsn(isStatic ? GETSTATIC : GETFIELD, methodOwner.getInternalName(), name, + v.visitFieldInsn(isStatic ? GETSTATIC : GETFIELD, methodOwner.getInternalName(), descriptor.getName().getName(), this.type.getDescriptor()); } else { @@ -993,7 +999,7 @@ public abstract class StackValue { setter.getDescriptor().replace("(", "(" + methodOwnerParam.getDescriptor())); } else if (setter == null) { - v.visitFieldInsn(isStatic ? PUTSTATIC : PUTFIELD, methodOwner.getInternalName(), name, + v.visitFieldInsn(isStatic ? PUTSTATIC : PUTFIELD, methodOwner.getInternalName(), descriptor.getName().getName(), this.type.getDescriptor()); } else {