Rename fields on name clashing
#KT-3663 Fixed #KT-3664 Fixed
This commit is contained in:
@@ -51,6 +51,7 @@ import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
|||||||
import org.jetbrains.jet.lang.resolve.calls.util.ExpressionAsFunctionDescriptor;
|
import org.jetbrains.jet.lang.resolve.calls.util.ExpressionAsFunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||||
import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils;
|
import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils;
|
||||||
@@ -1569,7 +1570,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
JetExpression r = getReceiverForSelector(expression);
|
JetExpression r = getReceiverForSelector(expression);
|
||||||
boolean isSuper = r instanceof JetSuperExpression;
|
boolean isSuper = r instanceof JetSuperExpression;
|
||||||
propertyDescriptor = accessablePropertyDescriptor(propertyDescriptor);
|
propertyDescriptor = accessablePropertyDescriptor(propertyDescriptor);
|
||||||
StackValue.Property iValue =
|
StackValue iValue =
|
||||||
intermediateValueForProperty(propertyDescriptor, directToField, isSuper ? (JetSuperExpression) r : null);
|
intermediateValueForProperty(propertyDescriptor, directToField, isSuper ? (JetSuperExpression) r : null);
|
||||||
if (directToField) {
|
if (directToField) {
|
||||||
receiver = StackValue.receiverWithoutReceiverArgument(receiver);
|
receiver = StackValue.receiverWithoutReceiverArgument(receiver);
|
||||||
@@ -1678,7 +1679,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public StackValue.Property intermediateValueForProperty(
|
public StackValue intermediateValueForProperty(
|
||||||
@NotNull PropertyDescriptor propertyDescriptor,
|
@NotNull PropertyDescriptor propertyDescriptor,
|
||||||
boolean forceField,
|
boolean forceField,
|
||||||
@Nullable JetSuperExpression superExpression
|
@Nullable JetSuperExpression superExpression
|
||||||
@@ -1686,7 +1687,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
return intermediateValueForProperty(propertyDescriptor, forceField, superExpression, MethodKind.GENERAL);
|
return intermediateValueForProperty(propertyDescriptor, forceField, superExpression, MethodKind.GENERAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StackValue.Property intermediateValueForProperty(
|
public StackValue.StackValueWithSimpleReceiver intermediateValueForProperty(
|
||||||
@NotNull PropertyDescriptor propertyDescriptor,
|
@NotNull PropertyDescriptor propertyDescriptor,
|
||||||
boolean forceField,
|
boolean forceField,
|
||||||
@Nullable JetSuperExpression superExpression,
|
@Nullable JetSuperExpression superExpression,
|
||||||
@@ -1754,7 +1755,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
callableSetter = null;
|
callableSetter = null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
callableSetter = typeMapper.mapToCallableMethod(propertyDescriptor.getSetter(), isSuper || MethodKind.SYNTHETIC_ACCESSOR == methodKind, isInsideClass, isInsideModule, OwnerKind.IMPLEMENTATION);
|
callableSetter = typeMapper
|
||||||
|
.mapToCallableMethod(propertyDescriptor.getSetter(), isSuper || MethodKind.SYNTHETIC_ACCESSOR == methodKind,
|
||||||
|
isInsideClass, isInsideModule, OwnerKind.IMPLEMENTATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1765,20 +1768,25 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
propertyDescriptor = unwrapFakeOverride(propertyDescriptor);
|
propertyDescriptor = unwrapFakeOverride(propertyDescriptor);
|
||||||
if (callableMethod == null) {
|
if (callableMethod == null) {
|
||||||
owner = typeMapper.getOwner(isBackingFieldInAnotherClass ? propertyDescriptor.getContainingDeclaration() : propertyDescriptor, context.getContextKind(), isInsideModule);
|
owner = typeMapper.getOwner(isBackingFieldInAnotherClass ? propertyDescriptor.getContainingDeclaration() : propertyDescriptor,
|
||||||
|
context.getContextKind(), isInsideModule);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
owner = callableMethod.getOwner();
|
owner = callableMethod.getOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDelegatedProperty && forceField) {
|
String name;
|
||||||
return StackValue.property(propertyDescriptor, owner, typeMapper.mapType(delegateType),
|
if (propertyDescriptor.getContainingDeclaration() == backingFieldContext.getContextDescriptor()) {
|
||||||
isStatic, true, callableGetter, callableSetter, state);
|
assert backingFieldContext instanceof FieldOwnerContext : "Actual context is " + backingFieldContext + " but should be instance of FieldOwnerContext" ;
|
||||||
}
|
name = ((FieldOwnerContext) backingFieldContext).getFieldName(propertyDescriptor, isDelegatedProperty);
|
||||||
else {
|
} else {
|
||||||
return StackValue.property(propertyDescriptor, owner, typeMapper.mapType(propertyDescriptor.getOriginal().getType()),
|
name = JvmAbi.getDefaultPropertyName(propertyDescriptor.getName(), isDelegatedProperty, propertyDescriptor.getReceiverParameter() != null);
|
||||||
isStatic, false, callableGetter, callableSetter, state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return StackValue.property(propertyDescriptor, owner,
|
||||||
|
typeMapper.mapType(isDelegatedProperty && forceField ? delegateType : propertyDescriptor.getOriginal().getType()),
|
||||||
|
isStatic, name, callableGetter, callableSetter, state);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -471,8 +471,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
for (JetParameter parameter : getPrimaryConstructorParameters()) {
|
for (JetParameter parameter : getPrimaryConstructorParameters()) {
|
||||||
if (parameter.getValOrVarNode() == null) continue;
|
if (parameter.getValOrVarNode() == null) continue;
|
||||||
|
|
||||||
PropertyDescriptor propertyDescriptor = state.getBindingContext().get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter);
|
PropertyDescriptor propertyDescriptor = DescriptorUtils.getPropertyDescriptor(parameter, bindingContext);
|
||||||
assert propertyDescriptor != null;
|
|
||||||
|
|
||||||
result.add(propertyDescriptor);
|
result.add(propertyDescriptor);
|
||||||
}
|
}
|
||||||
@@ -860,7 +859,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
public void doGenerateBody(ExpressionCodegen codegen, JvmMethodSignature signature) {
|
public void doGenerateBody(ExpressionCodegen codegen, JvmMethodSignature signature) {
|
||||||
InstructionAdapter iv = codegen.v;
|
InstructionAdapter iv = codegen.v;
|
||||||
boolean forceField = AsmUtil.isPropertyWithBackingFieldInOuterClass(original) && !isClassObject(bridge.getContainingDeclaration());
|
boolean forceField = AsmUtil.isPropertyWithBackingFieldInOuterClass(original) && !isClassObject(bridge.getContainingDeclaration());
|
||||||
StackValue.Property property = codegen.intermediateValueForProperty(original, forceField, null, MethodKind.SYNTHETIC_ACCESSOR);
|
StackValue property = codegen.intermediateValueForProperty(original, forceField, null, MethodKind.SYNTHETIC_ACCESSOR);
|
||||||
if (!forceField) {
|
if (!forceField) {
|
||||||
iv.load(0, OBJECT_TYPE);
|
iv.load(0, OBJECT_TYPE);
|
||||||
}
|
}
|
||||||
@@ -879,7 +878,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
@Override
|
@Override
|
||||||
public void doGenerateBody(ExpressionCodegen codegen, JvmMethodSignature signature) {
|
public void doGenerateBody(ExpressionCodegen codegen, JvmMethodSignature signature) {
|
||||||
boolean forceField = AsmUtil.isPropertyWithBackingFieldInOuterClass(original) && !isClassObject(bridge.getContainingDeclaration());
|
boolean forceField = AsmUtil.isPropertyWithBackingFieldInOuterClass(original) && !isClassObject(bridge.getContainingDeclaration());
|
||||||
StackValue.Property property = codegen.intermediateValueForProperty(original, forceField, null, MethodKind.SYNTHETIC_ACCESSOR);
|
StackValue property = codegen.intermediateValueForProperty(original, forceField, null, MethodKind.SYNTHETIC_ACCESSOR);
|
||||||
InstructionAdapter iv = codegen.v;
|
InstructionAdapter iv = codegen.v;
|
||||||
|
|
||||||
Type[] argTypes = signature.getAsmMethod().getArgumentTypes();
|
Type[] argTypes = signature.getAsmMethod().getArgumentTypes();
|
||||||
@@ -955,7 +954,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
if (classObjectPropertiesToCopy != null) {
|
if (classObjectPropertiesToCopy != null) {
|
||||||
for (PropertyDescriptor propertyDescriptor : classObjectPropertiesToCopy) {
|
for (PropertyDescriptor propertyDescriptor : classObjectPropertiesToCopy) {
|
||||||
|
|
||||||
v.newField(null, ACC_STATIC | ACC_FINAL | ACC_PUBLIC, propertyDescriptor.getName().asString(), typeMapper.mapType(propertyDescriptor).getDescriptor(), null, null);
|
v.newField(null, ACC_STATIC | ACC_FINAL | ACC_PUBLIC, context.getFieldName(propertyDescriptor), typeMapper.mapType(propertyDescriptor).getDescriptor(), null, null);
|
||||||
|
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
||||||
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
||||||
@@ -1048,7 +1047,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
private void generatePrimaryConstructorImpl(
|
private void generatePrimaryConstructorImpl(
|
||||||
@Nullable ConstructorDescriptor constructorDescriptor,
|
@Nullable ConstructorDescriptor constructorDescriptor,
|
||||||
@NotNull final ExpressionCodegen codegen,
|
@NotNull ExpressionCodegen codegen,
|
||||||
@Nullable MutableClosure closure
|
@Nullable MutableClosure closure
|
||||||
) {
|
) {
|
||||||
List<ValueParameterDescriptor> paramDescrs = constructorDescriptor != null
|
List<ValueParameterDescriptor> paramDescrs = constructorDescriptor != null
|
||||||
@@ -1096,7 +1095,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
Type type = typeMapper.mapType(descriptor);
|
Type type = typeMapper.mapType(descriptor);
|
||||||
iv.load(0, classAsmType);
|
iv.load(0, classAsmType);
|
||||||
iv.load(codegen.myFrameMap.getIndex(descriptor), type);
|
iv.load(codegen.myFrameMap.getIndex(descriptor), type);
|
||||||
iv.putfield(classAsmType.getInternalName(), descriptor.getName().asString(), type.getDescriptor());
|
iv.putfield(classAsmType.getInternalName(),
|
||||||
|
context.getFieldName(DescriptorUtils.getPropertyDescriptor(parameter, bindingContext)),
|
||||||
|
type.getDescriptor());
|
||||||
}
|
}
|
||||||
curParam++;
|
curParam++;
|
||||||
}
|
}
|
||||||
@@ -1609,7 +1610,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
JetType jetType = getPropertyOrDelegateType(bindingContext, property, propertyDescriptor);
|
JetType jetType = getPropertyOrDelegateType(bindingContext, property, propertyDescriptor);
|
||||||
|
|
||||||
StackValue.Property propValue = codegen.intermediateValueForProperty(propertyDescriptor, true, null, MethodKind.INITIALIZER);
|
StackValue.StackValueWithSimpleReceiver propValue = codegen.intermediateValueForProperty(propertyDescriptor, true, null, MethodKind.INITIALIZER);
|
||||||
|
|
||||||
if (!propValue.isStatic) {
|
if (!propValue.isStatic) {
|
||||||
codegen.v.load(0, OBJECT_TYPE);
|
codegen.v.load(0, OBJECT_TYPE);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.codegen.context.ClassContext;
|
import org.jetbrains.jet.codegen.context.ClassContext;
|
||||||
import org.jetbrains.jet.codegen.context.CodegenContext;
|
import org.jetbrains.jet.codegen.context.CodegenContext;
|
||||||
|
import org.jetbrains.jet.codegen.context.FieldOwnerContext;
|
||||||
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.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
@@ -27,8 +28,6 @@ import org.jetbrains.jet.lang.psi.*;
|
|||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
public class MemberCodegen extends GenerationStateAware {
|
public class MemberCodegen extends GenerationStateAware {
|
||||||
|
|
||||||
@@ -46,7 +45,7 @@ public class MemberCodegen extends GenerationStateAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void genFunctionOrProperty(
|
public void genFunctionOrProperty(
|
||||||
CodegenContext context,
|
@NotNull FieldOwnerContext context,
|
||||||
@NotNull JetTypeParameterListOwner functionOrProperty,
|
@NotNull JetTypeParameterListOwner functionOrProperty,
|
||||||
@NotNull ClassBuilder classBuilder
|
@NotNull ClassBuilder classBuilder
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.jetbrains.asm4.AnnotationVisitor;
|
|||||||
import org.jetbrains.asm4.MethodVisitor;
|
import org.jetbrains.asm4.MethodVisitor;
|
||||||
import org.jetbrains.asm4.Type;
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.jet.codegen.context.CodegenContext;
|
import org.jetbrains.jet.codegen.context.CodegenContext;
|
||||||
|
import org.jetbrains.jet.codegen.context.FieldOwnerContext;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
@@ -147,22 +148,20 @@ public class NamespaceCodegen extends MemberCodegen {
|
|||||||
);
|
);
|
||||||
builder.visitSource(file.getName(), null);
|
builder.visitSource(file.getName(), null);
|
||||||
|
|
||||||
|
FieldOwnerContext nameSpaceContext =
|
||||||
|
CodegenContext.STATIC.intoNamespace(descriptor);
|
||||||
|
|
||||||
|
FieldOwnerContext nameSpacePart =
|
||||||
|
CodegenContext.STATIC.intoNamespacePart(className, descriptor);
|
||||||
|
|
||||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||||
if (declaration instanceof JetNamedFunction || declaration instanceof JetProperty) {
|
if (declaration instanceof JetNamedFunction || declaration instanceof JetProperty) {
|
||||||
{
|
genFunctionOrProperty(nameSpaceContext, (JetTypeParameterListOwner) declaration, builder);
|
||||||
CodegenContext context =
|
genFunctionOrProperty(nameSpacePart, (JetTypeParameterListOwner) declaration, v.getClassBuilder());
|
||||||
CodegenContext.STATIC.intoNamespace(descriptor);
|
|
||||||
genFunctionOrProperty(context, (JetTypeParameterListOwner) declaration, builder);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
CodegenContext context =
|
|
||||||
CodegenContext.STATIC.intoNamespacePart(className, descriptor);
|
|
||||||
genFunctionOrProperty(context, (JetTypeParameterListOwner) declaration, v.getClassBuilder());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generateStaticInitializers(descriptor, builder, file);
|
generateStaticInitializers(descriptor, builder, file, nameSpaceContext);
|
||||||
|
|
||||||
builder.done();
|
builder.done();
|
||||||
}
|
}
|
||||||
@@ -206,7 +205,12 @@ public class NamespaceCodegen extends MemberCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateStaticInitializers(NamespaceDescriptor descriptor, @NotNull ClassBuilder builder, @NotNull JetFile file) {
|
private void generateStaticInitializers(
|
||||||
|
NamespaceDescriptor descriptor,
|
||||||
|
@NotNull ClassBuilder builder,
|
||||||
|
@NotNull JetFile file,
|
||||||
|
@NotNull FieldOwnerContext context
|
||||||
|
) {
|
||||||
List<JetProperty> properties = collectPropertiesToInitialize(file);
|
List<JetProperty> properties = collectPropertiesToInitialize(file);
|
||||||
if (properties.isEmpty()) return;
|
if (properties.isEmpty()) return;
|
||||||
|
|
||||||
@@ -223,7 +227,7 @@ public class NamespaceCodegen extends MemberCodegen {
|
|||||||
clInit.initialize(null, null, Collections.<TypeParameterDescriptor>emptyList(),
|
clInit.initialize(null, null, Collections.<TypeParameterDescriptor>emptyList(),
|
||||||
Collections.<ValueParameterDescriptor>emptyList(), null, null, Visibilities.PRIVATE, false);
|
Collections.<ValueParameterDescriptor>emptyList(), null, null, Visibilities.PRIVATE, false);
|
||||||
|
|
||||||
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, CodegenContext.STATIC.intoFunction(clInit), state);
|
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, context.intoFunction(clInit), state);
|
||||||
|
|
||||||
for (JetDeclaration declaration : properties) {
|
for (JetDeclaration declaration : properties) {
|
||||||
ImplementationBodyCodegen.
|
ImplementationBodyCodegen.
|
||||||
|
|||||||
@@ -17,15 +17,14 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.asm4.FieldVisitor;
|
import org.jetbrains.asm4.FieldVisitor;
|
||||||
import org.jetbrains.asm4.MethodVisitor;
|
import org.jetbrains.asm4.MethodVisitor;
|
||||||
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.jet.codegen.context.ClassContext;
|
|
||||||
import org.jetbrains.jet.codegen.context.CodegenContext;
|
import org.jetbrains.jet.codegen.context.CodegenContext;
|
||||||
|
import org.jetbrains.jet.codegen.context.FieldOwnerContext;
|
||||||
import org.jetbrains.jet.codegen.context.MethodContext;
|
import org.jetbrains.jet.codegen.context.MethodContext;
|
||||||
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
||||||
import org.jetbrains.jet.codegen.signature.JvmPropertyAccessorSignature;
|
import org.jetbrains.jet.codegen.signature.JvmPropertyAccessorSignature;
|
||||||
@@ -41,7 +40,6 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
|||||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
|
||||||
import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils;
|
import org.jetbrains.jet.lang.resolve.java.kt.DescriptorKindUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
@@ -63,7 +61,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
private final ClassBuilder v;
|
private final ClassBuilder v;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final CodegenContext context;
|
private final FieldOwnerContext context;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private MemberCodegen classBodyCodegen;
|
private MemberCodegen classBodyCodegen;
|
||||||
@@ -72,7 +70,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
private final OwnerKind kind;
|
private final OwnerKind kind;
|
||||||
|
|
||||||
public PropertyCodegen(
|
public PropertyCodegen(
|
||||||
@NotNull CodegenContext context,
|
@NotNull FieldOwnerContext context,
|
||||||
@NotNull ClassBuilder v,
|
@NotNull ClassBuilder v,
|
||||||
@NotNull FunctionCodegen functionCodegen,
|
@NotNull FunctionCodegen functionCodegen,
|
||||||
@Nullable MemberCodegen classBodyCodegen
|
@Nullable MemberCodegen classBodyCodegen
|
||||||
@@ -145,9 +143,12 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
|
|
||||||
ClassBuilder builder = v;
|
ClassBuilder builder = v;
|
||||||
|
|
||||||
|
FieldOwnerContext backingFieldContext = context;
|
||||||
if (AsmUtil.isPropertyWithBackingFieldInOuterClass(propertyDescriptor)) {
|
if (AsmUtil.isPropertyWithBackingFieldInOuterClass(propertyDescriptor)) {
|
||||||
modifiers |= ACC_STATIC | getVisibilityForSpecialPropertyBackingField(propertyDescriptor, isDelegate);
|
modifiers |= ACC_STATIC | getVisibilityForSpecialPropertyBackingField(propertyDescriptor, isDelegate);
|
||||||
builder = getParentBodyCodegen(classBodyCodegen).v;
|
ImplementationBodyCodegen codegen = getParentBodyCodegen(classBodyCodegen);
|
||||||
|
builder = codegen.v;
|
||||||
|
backingFieldContext = codegen.context;
|
||||||
} else {
|
} else {
|
||||||
if (kind != OwnerKind.NAMESPACE || isDelegate) {
|
if (kind != OwnerKind.NAMESPACE || isDelegate) {
|
||||||
modifiers |= ACC_PRIVATE;
|
modifiers |= ACC_PRIVATE;
|
||||||
@@ -159,7 +160,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
parentBodyCodegen.addClassObjectPropertyToCopy(propertyDescriptor);
|
parentBodyCodegen.addClassObjectPropertyToCopy(propertyDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = isDelegate ? JvmAbi.getPropertyDelegateName(propertyDescriptor.getName()) : propertyDescriptor.getName().asString();
|
String name = backingFieldContext.getFieldName(propertyDescriptor, isDelegate);
|
||||||
|
|
||||||
return builder.newField(element, modifiers, name, type.getDescriptor(),
|
return builder.newField(element, modifiers, name, type.getDescriptor(),
|
||||||
null, defaultValue);
|
null, defaultValue);
|
||||||
@@ -333,7 +334,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
iv.load(0, OBJECT_TYPE);
|
iv.load(0, OBJECT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
StackValue.Property delegatedProperty = codegen.intermediateValueForProperty(property, true, null);
|
StackValue delegatedProperty = codegen.intermediateValueForProperty(property, 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) {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ 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.CodegenContext;
|
||||||
|
import org.jetbrains.jet.codegen.context.FieldOwnerContext;
|
||||||
import org.jetbrains.jet.codegen.context.MethodContext;
|
import org.jetbrains.jet.codegen.context.MethodContext;
|
||||||
import org.jetbrains.jet.codegen.context.ScriptContext;
|
import org.jetbrains.jet.codegen.context.ScriptContext;
|
||||||
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
||||||
@@ -196,7 +197,7 @@ public class ScriptCodegen extends MemberCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void genMembers(@NotNull JetScript scriptDeclaration, @NotNull CodegenContext context, @NotNull ClassBuilder classBuilder) {
|
private void genMembers(@NotNull JetScript scriptDeclaration, @NotNull FieldOwnerContext context, @NotNull ClassBuilder classBuilder) {
|
||||||
for (JetDeclaration decl : scriptDeclaration.getDeclarations()) {
|
for (JetDeclaration decl : scriptDeclaration.getDeclarations()) {
|
||||||
genFunctionOrProperty(context, (JetTypeParameterListOwner) decl, classBuilder);
|
genFunctionOrProperty(context, (JetTypeParameterListOwner) decl, classBuilder);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,10 +116,12 @@ public abstract class StackValue {
|
|||||||
return new Invert(stackValue);
|
return new Invert(stackValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static StackValue arrayElement(Type type, boolean unbox) {
|
public static StackValue arrayElement(Type type, boolean unbox) {
|
||||||
return new ArrayElement(type, unbox);
|
return new ArrayElement(type, unbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static StackValue collectionElement(
|
public static StackValue collectionElement(
|
||||||
Type type,
|
Type type,
|
||||||
ResolvedCall<FunctionDescriptor> getter,
|
ResolvedCall<FunctionDescriptor> getter,
|
||||||
@@ -135,19 +137,21 @@ public abstract class StackValue {
|
|||||||
return new Field(type, owner, name, isStatic);
|
return new Field(type, owner, name, isStatic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static Property property(
|
public static Property property(
|
||||||
PropertyDescriptor descriptor,
|
@NotNull PropertyDescriptor descriptor,
|
||||||
JvmClassName methodOwner,
|
@NotNull JvmClassName methodOwner,
|
||||||
Type type,
|
@NotNull Type type,
|
||||||
boolean isStatic,
|
boolean isStatic,
|
||||||
boolean isDelegated,
|
@NotNull String name,
|
||||||
@Nullable CallableMethod getter,
|
@Nullable CallableMethod getter,
|
||||||
@Nullable CallableMethod setter,
|
@Nullable CallableMethod setter,
|
||||||
GenerationState state
|
GenerationState state
|
||||||
) {
|
) {
|
||||||
return new Property(descriptor, methodOwner, getter, setter, isStatic, isDelegated, type, state);
|
return new Property(descriptor, methodOwner, getter, setter, isStatic, name, type, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static StackValue expression(Type type, JetExpression expression, ExpressionCodegen generator) {
|
public static StackValue expression(Type type, JetExpression expression, ExpressionCodegen generator) {
|
||||||
return new Expression(type, expression, generator);
|
return new Expression(type, expression, generator);
|
||||||
}
|
}
|
||||||
@@ -870,12 +874,13 @@ public abstract class StackValue {
|
|||||||
private final PropertyDescriptor descriptor;
|
private final PropertyDescriptor descriptor;
|
||||||
@NotNull
|
@NotNull
|
||||||
private final GenerationState state;
|
private final GenerationState state;
|
||||||
private final boolean isDelegated;
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
public Property(
|
public Property(
|
||||||
@NotNull PropertyDescriptor descriptor, @NotNull JvmClassName methodOwner,
|
@NotNull PropertyDescriptor descriptor, @NotNull JvmClassName methodOwner,
|
||||||
@Nullable CallableMethod getter, @Nullable CallableMethod setter, boolean isStatic,
|
@Nullable CallableMethod getter, @Nullable CallableMethod setter, boolean isStatic,
|
||||||
boolean isDelegated, @NotNull Type type, @NotNull GenerationState state
|
@NotNull String name, @NotNull Type type, @NotNull GenerationState state
|
||||||
) {
|
) {
|
||||||
super(type, isStatic);
|
super(type, isStatic);
|
||||||
this.methodOwner = methodOwner;
|
this.methodOwner = methodOwner;
|
||||||
@@ -883,7 +888,7 @@ public abstract class StackValue {
|
|||||||
this.setter = setter;
|
this.setter = setter;
|
||||||
this.descriptor = descriptor;
|
this.descriptor = descriptor;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.isDelegated = isDelegated;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -913,7 +918,7 @@ public abstract class StackValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getPropertyName() {
|
private String getPropertyName() {
|
||||||
return isDelegated ? JvmAbi.getPropertyDelegateName(descriptor.getName()) : descriptor.getName().asString();
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1244,7 +1249,7 @@ public abstract class StackValue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private abstract static class StackValueWithSimpleReceiver extends StackValue {
|
public abstract static class StackValueWithSimpleReceiver extends StackValue {
|
||||||
|
|
||||||
protected final boolean isStatic;
|
protected final boolean isStatic;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
|||||||
|
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.CLOSURE;
|
import static org.jetbrains.jet.codegen.binding.CodegenBinding.CLOSURE;
|
||||||
|
|
||||||
public class ClassContext extends CodegenContext<ClassDescriptor> {
|
public class ClassContext extends FieldOwnerContext<ClassDescriptor> {
|
||||||
|
|
||||||
public ClassContext(
|
public ClassContext(
|
||||||
@NotNull JetTypeMapper typeMapper,
|
@NotNull JetTypeMapper typeMapper,
|
||||||
|
|||||||
@@ -147,12 +147,12 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CodegenContext intoNamespace(@NotNull NamespaceDescriptor descriptor) {
|
public FieldOwnerContext intoNamespace(@NotNull NamespaceDescriptor descriptor) {
|
||||||
return new NamespaceContext(descriptor, this, OwnerKind.NAMESPACE);
|
return new NamespaceContext(descriptor, this, OwnerKind.NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CodegenContext intoNamespacePart(String delegateTo, NamespaceDescriptor descriptor) {
|
public FieldOwnerContext intoNamespacePart(String delegateTo, NamespaceDescriptor descriptor) {
|
||||||
return new NamespaceContext(descriptor, this, new OwnerKind.StaticDelegateKind(delegateTo));
|
return new NamespaceContext(descriptor, this, new OwnerKind.StaticDelegateKind(delegateTo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.codegen.context;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.codegen.OwnerKind;
|
||||||
|
import org.jetbrains.jet.codegen.binding.MutableClosure;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public abstract class FieldOwnerContext<T extends DeclarationDescriptor> extends CodegenContext<T> {
|
||||||
|
|
||||||
|
//default property name -> map<property descriptor -> bytecode name>
|
||||||
|
private Map<String, Map<PropertyDescriptor, String>> fieldNames = new HashMap<String, Map<PropertyDescriptor, String>>();
|
||||||
|
|
||||||
|
public FieldOwnerContext(
|
||||||
|
@NotNull T contextDescriptor,
|
||||||
|
@NotNull OwnerKind contextKind,
|
||||||
|
@Nullable CodegenContext parentContext,
|
||||||
|
@Nullable MutableClosure closure,
|
||||||
|
@Nullable ClassDescriptor thisDescriptor,
|
||||||
|
@Nullable LocalLookup expressionCodegen
|
||||||
|
) {
|
||||||
|
super(contextDescriptor, contextKind, parentContext, closure, thisDescriptor, expressionCodegen);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFieldName(PropertyDescriptor descriptor) {
|
||||||
|
return getFieldName(descriptor, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFieldName(PropertyDescriptor descriptor, boolean isDelegated) {
|
||||||
|
assert descriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE;
|
||||||
|
boolean isExtension = descriptor.getReceiverParameter() != null;
|
||||||
|
|
||||||
|
return getFieldName(descriptor, isDelegated, isExtension);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getFieldName(PropertyDescriptor descriptor, boolean isDelegated, boolean isExtension) {
|
||||||
|
descriptor = descriptor.getOriginal();
|
||||||
|
String defaultPropertyName = JvmAbi.getDefaultPropertyName(descriptor.getName(), isDelegated, isExtension);
|
||||||
|
|
||||||
|
Map<PropertyDescriptor, String> descriptor2Name = fieldNames.get(defaultPropertyName);
|
||||||
|
if (descriptor2Name == null) {
|
||||||
|
descriptor2Name = new HashMap<PropertyDescriptor, String>();
|
||||||
|
fieldNames.put(defaultPropertyName, descriptor2Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
String actualName = descriptor2Name.get(descriptor);
|
||||||
|
if (actualName == null) {
|
||||||
|
actualName = descriptor2Name.isEmpty() ? defaultPropertyName : defaultPropertyName + "$" + descriptor2Name.size();
|
||||||
|
descriptor2Name.put(descriptor, actualName);
|
||||||
|
}
|
||||||
|
return actualName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.jet.codegen.OwnerKind;
|
import org.jetbrains.jet.codegen.OwnerKind;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
|
|
||||||
public class NamespaceContext extends CodegenContext {
|
public class NamespaceContext extends FieldOwnerContext<NamespaceDescriptor> {
|
||||||
public NamespaceContext(@NotNull NamespaceDescriptor contextDescriptor, @Nullable CodegenContext parent, @NotNull OwnerKind kind) {
|
public NamespaceContext(@NotNull NamespaceDescriptor contextDescriptor, @Nullable CodegenContext parent, @NotNull OwnerKind kind) {
|
||||||
super(contextDescriptor, kind, parent, null, null, null);
|
super(contextDescriptor, kind, parent, null, null, null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import org.jetbrains.jet.codegen.binding.MutableClosure;
|
|||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
|
||||||
|
|
||||||
public class ScriptContext extends CodegenContext {
|
public class ScriptContext extends FieldOwnerContext<ClassDescriptor> {
|
||||||
@NotNull
|
@NotNull
|
||||||
private final ScriptDescriptor scriptDescriptor;
|
private final ScriptDescriptor scriptDescriptor;
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.lang.resolve.java;
|
package org.jetbrains.jet.lang.resolve.java;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
@@ -59,6 +60,20 @@ public class JvmAbi {
|
|||||||
return name.asString() + DELEGATED_PROPERTY_NAME_POSTFIX;
|
return name.asString() + DELEGATED_PROPERTY_NAME_POSTFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getDefaultPropertyName(Name propertyName, boolean isDelegated, boolean isExtensionProperty) {
|
||||||
|
if (isDelegated) {
|
||||||
|
return getPropertyDelegateName(propertyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = propertyName.asString();
|
||||||
|
if (isExtensionProperty) {
|
||||||
|
name += "$ext";
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private JvmAbi() {
|
private JvmAbi() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor;
|
|||||||
import org.jetbrains.jet.lang.descriptors.impl.NamespaceDescriptorParent;
|
import org.jetbrains.jet.lang.descriptors.impl.NamespaceDescriptorParent;
|
||||||
import org.jetbrains.jet.lang.psi.JetElement;
|
import org.jetbrains.jet.lang.psi.JetElement;
|
||||||
import org.jetbrains.jet.lang.psi.JetFunction;
|
import org.jetbrains.jet.lang.psi.JetFunction;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
@@ -586,4 +587,13 @@ public class DescriptorUtils {
|
|||||||
}
|
}
|
||||||
return (PropertyDescriptor) descriptor;
|
return (PropertyDescriptor) descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static PropertyDescriptor getPropertyDescriptor(@NotNull JetParameter constructorParameter, @NotNull BindingContext bindingContext) {
|
||||||
|
assert constructorParameter.getValOrVarNode() != null;
|
||||||
|
PropertyDescriptor descriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, constructorParameter);
|
||||||
|
assert descriptor != null;
|
||||||
|
return descriptor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user