Extracted logic of obtaining delegated local variable metadata

This commit is contained in:
Mikhael Bogdanov
2016-05-11 14:49:18 +03:00
parent c06b51c1d1
commit 48c8678281
4 changed files with 21 additions and 12 deletions
@@ -1664,8 +1664,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
int index = myFrameMap.enter(variableDescriptor, type);
if (isDelegatedLocalVariable(variableDescriptor)) {
VariableDescriptor metadataVariableDescriptor = bindingContext.get(LOCAL_VARIABLE_PROPERTY_METADATA, variableDescriptor);
myFrameMap.enter(metadataVariableDescriptor, AsmTypes.K_PROPERTY0_TYPE);
myFrameMap.enter(getDelegatedLocalVariableMetadata(variableDescriptor, bindingContext), AsmTypes.K_PROPERTY0_TYPE);
}
if (isSharedVarType(type)) {
@@ -1715,8 +1714,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
@Override
public Void fun(StackValue answer) {
if (isDelegatedLocalVariable(variableDescriptor)) {
VariableDescriptor metadataVariableDescriptor = bindingContext.get(LOCAL_VARIABLE_PROPERTY_METADATA, variableDescriptor);
myFrameMap.leave(metadataVariableDescriptor);
myFrameMap.leave(getDelegatedLocalVariableMetadata(variableDescriptor, bindingContext));
}
int index = myFrameMap.leave(variableDescriptor);
@@ -3439,10 +3437,11 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
return StackValue.none();
}
@Nullable
@NotNull
private StackValue getVariableMetadataValue(VariableDescriptor variableDescriptor) {
VariableDescriptor metadataVariableDescriptor = bindingContext.get(LOCAL_VARIABLE_PROPERTY_METADATA, variableDescriptor);
return metadataVariableDescriptor != null ? findLocalOrCapturedValue(metadataVariableDescriptor) : null;
StackValue value = findLocalOrCapturedValue(getDelegatedLocalVariableMetadata(variableDescriptor, bindingContext));
assert value != null : "Can't find stack value for local delegated variable metadata: " + variableDescriptor;
return value;
}
@NotNull
@@ -3451,7 +3450,6 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
VariableDescriptorWithAccessors variableDescriptor = (VariableDescriptorWithAccessors) descriptor;
StackValue metadataValue = getVariableMetadataValue(variableDescriptor);
assert metadataValue != null : variableDescriptor;
return JvmCodegenUtil.delegatedVariableValue(varValue, metadataValue, variableDescriptor, bindingContext, typeMapper);
}
@@ -3484,8 +3482,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
storeTo.storeSelector(initializer.type, v);
StackValue metadataValue = getVariableMetadataValue(variableDescriptor);
if (metadataValue != null) {
if (isDelegatedLocalVariable(variableDescriptor)) {
StackValue metadataValue = getVariableMetadataValue(variableDescriptor);
initializePropertyMetadata((KtProperty) variableDeclaration, variableDescriptor, metadataValue);
invokePropertyDelegatedOnLocalVar(variableDescriptor, storeTo, metadataValue);
}
@@ -48,10 +48,11 @@ import org.jetbrains.kotlin.types.KotlinType;
import java.io.File;
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.LOCAL_VARIABLE_DELEGATE;
import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.LOCAL_VARIABLE_PROPERTY_METADATA;
import static org.jetbrains.kotlin.descriptors.Modality.ABSTRACT;
import static org.jetbrains.kotlin.descriptors.Modality.FINAL;
import static org.jetbrains.kotlin.resolve.jvm.annotations.AnnotationUtilKt.hasJvmFieldAnnotation;
import static org.jetbrains.kotlin.resolve.BindingContext.DELEGATED_PROPERTY_CALL;
import static org.jetbrains.kotlin.resolve.jvm.annotations.AnnotationUtilKt.hasJvmFieldAnnotation;
public class JvmCodegenUtil {
@@ -250,4 +250,14 @@ public class CodegenBinding {
return allInnerClasses;
}
@NotNull
public static VariableDescriptor getDelegatedLocalVariableMetadata(
@NotNull VariableDescriptor variableDescriptor,
@NotNull BindingContext bindingContext
) {
VariableDescriptor metadataVariableDescriptor = bindingContext.get(LOCAL_VARIABLE_PROPERTY_METADATA, variableDescriptor);
assert metadataVariableDescriptor != null : "Metadata for local delegated property should be not null: " + variableDescriptor;
return metadataVariableDescriptor;
}
}
@@ -58,7 +58,6 @@ public interface LocalLookup {
boolean delegatedVar = false;
VariableDescriptor delegateVariableDescriptor = state.getBindingContext().get(LOCAL_VARIABLE_DELEGATE, vd);
VariableDescriptor metadataVariableDescriptor = state.getBindingContext().get(LOCAL_VARIABLE_PROPERTY_METADATA, vd);
if (delegateVariableDescriptor != null) {
vd = delegateVariableDescriptor;
delegatedVar = true;
@@ -81,6 +80,7 @@ public interface LocalLookup {
else {
innerValue = StackValue.field(type, classType, fieldName, false, thiz, vd);
if (delegatedVar) {
VariableDescriptor metadataVariableDescriptor = getDelegatedLocalVariableMetadata(originalVariableDescriptor, state.getBindingContext());
StackValue metadataValue = innerValue(metadataVariableDescriptor, localLookup, state, closure, classType);
assert metadataValue != null : originalVariableDescriptor;