ExpressionCOdegen.visitSimpleNameExpression simplification

This commit is contained in:
Mikhael Bogdanov
2013-04-18 12:55:31 +04:00
parent 1fd76845ad
commit a1d295638a
3 changed files with 64 additions and 29 deletions
@@ -1574,36 +1574,12 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
boolean isSuper = r instanceof JetSuperExpression;
propertyDescriptor = accessablePropertyDescriptor(propertyDescriptor);
StackValue.Property iValue =
intermediateValueForProperty(propertyDescriptor, directToField, isSuper ? (JetSuperExpression) r : null);
if (!directToField && resolvedCall != null && !isSuper) {
receiver.put(propertyDescriptor.getReceiverParameter() != null || isStatic
? receiver.type
: iValue.methodOwner.getAsmType(), v);
}
else {
if (!isStatic) {
if (receiver == StackValue.none()) {
if (resolvedCall != null && resolvedCall.getThisObject() instanceof ExtensionReceiver) {
receiver = generateReceiver(((ExtensionReceiver) resolvedCall.getThisObject()).getDeclarationDescriptor());
}
else {
receiver = generateThisOrOuter((ClassDescriptor) propertyDescriptor.getContainingDeclaration(), false);
}
}
if (directToField) {
receiver = StackValue.receiverWithoutReceiverArgument(receiver);
}
JetType receiverType = bindingContext.get(BindingContext.EXPRESSION_TYPE, r);
receiver.put(receiverType != null && !isSuper ? asmType(receiverType) : OBJECT_TYPE, v);
if (receiverType != null) {
ClassDescriptor propReceiverDescriptor = (ClassDescriptor) propertyDescriptor.getContainingDeclaration();
if (!isInterface(propReceiverDescriptor) &&
isInterface(receiverType.getConstructor().getDeclarationDescriptor())) {
v.checkcast(asmType(propReceiverDescriptor.getDefaultType()));
}
}
}
intermediateValueForProperty(propertyDescriptor, directToField, isSuper ? (JetSuperExpression) r : null);
if (directToField) {
receiver = StackValue.receiverWithoutReceiverArgument(receiver);
}
receiver.put(receiver.type, v);
return iValue;
}
@@ -0,0 +1,54 @@
package As
val staticProperty : String = "1"
val String.staticExt = "1"
open class A(val init: String) {
open val property : String = init
private val privateProperty : String = init
val String.ext = "1"
val Int.myInc : Int
get() = this + 1
open fun getPrivate() : String {
return privateProperty;
}
open fun getExt() : String {
return "0".ext;
}
public var backingField : Int = 0
get() = $backingField.myInc
set(s) = $backingField = s
}
open class B(init: String) : A("1") {
override val property: String = init
fun getOpenProperty(): String {
return super<A>.property
}
fun getWithBackingFieldProperty(): String {
return $property
}
}
fun box() : String {
val a = A("1");
val b = B("0");
a.backingField = 0
val result = a.property + a.getPrivate() + staticProperty + "0".staticExt + a.getExt() +
a.backingField + a.backingField +
b.getOpenProperty() + b.property + b.getWithBackingFieldProperty()
return if (result == "1111111100") "OK" else "fail"
}
@@ -3053,6 +3053,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/box/properties"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("generalAccess.kt")
public void testGeneralAccess() throws Exception {
doTest("compiler/testData/codegen/box/properties/generalAccess.kt");
}
@TestMetadata("kt1159.kt")
public void testKt1159() throws Exception {
doTest("compiler/testData/codegen/box/properties/kt1159.kt");