unification of accessable descriptor lookup between functions and properties

This commit is contained in:
Alex Tkachman
2012-09-12 09:20:10 +03:00
parent 5080ca9eb0
commit fb4d6610a8
2 changed files with 25 additions and 25 deletions
@@ -1656,44 +1656,43 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
private PropertyDescriptor accessablePropertyDescriptor(PropertyDescriptor propertyDescriptor) { private PropertyDescriptor accessablePropertyDescriptor(PropertyDescriptor propertyDescriptor) {
PropertySetterDescriptor setter = propertyDescriptor.getSetter(); PropertySetterDescriptor setter = propertyDescriptor.getSetter();
if ((propertyDescriptor.getVisibility() == Visibilities.PRIVATE || PropertyGetterDescriptor getter = propertyDescriptor.getGetter();
(setter != null && setter.getVisibility() == Visibilities.PRIVATE))
&& !DescriptorUtils.isClassObject(propertyDescriptor.getContainingDeclaration()) final int flag = CodegenUtil.getVisibilityAccessFlag(propertyDescriptor) |
&& propertyDescriptor.getContainingDeclaration() instanceof ClassDescriptor) { (getter == null ? 0 : CodegenUtil.getVisibilityAccessFlag(getter)) |
if (context.getClassOrNamespaceDescriptor() != propertyDescriptor.getContainingDeclaration()) { (setter == null ? 0 : CodegenUtil.getVisibilityAccessFlag(setter));
DeclarationDescriptor enclosed = propertyDescriptor.getContainingDeclaration();
if (!context.hasThisDescriptor() || enclosed != context.getThisDescriptor()) { if ((flag & ACC_PRIVATE) == 0) {
CodegenContext c = context; return propertyDescriptor;
while (c != null && c.getContextDescriptor() != enclosed) {
c = c.getParentContext();
}
if (c != null) {
propertyDescriptor = (PropertyDescriptor) c.getAccessor(propertyDescriptor);
}
}
}
} }
return propertyDescriptor;
return (PropertyDescriptor) accessibleDescriptor(context, propertyDescriptor);
} }
private FunctionDescriptor accessableFunctionDescriptor(FunctionDescriptor fd) { private FunctionDescriptor accessableFunctionDescriptor(FunctionDescriptor fd) {
if (fd.getVisibility() != Visibilities.PRIVATE || fd.getContainingDeclaration() instanceof NamespaceDescriptor) { final int flag = CodegenUtil.getVisibilityAccessFlag(fd);
if ((flag & ACC_PRIVATE) == 0) {
return fd; return fd;
} }
if (context.getClassOrNamespaceDescriptor() != fd.getContainingDeclaration()) { return (FunctionDescriptor) accessibleDescriptor(context, fd);
DeclarationDescriptor enclosed = fd.getContainingDeclaration(); }
if (enclosed != context.getThisDescriptor()) {
private static MemberDescriptor accessibleDescriptor(CodegenContext context, DeclarationDescriptor descriptor) {
if (context.getClassOrNamespaceDescriptor() != descriptor.getContainingDeclaration()) {
DeclarationDescriptor enclosed = descriptor.getContainingDeclaration();
if (context.hasThisDescriptor() && enclosed != context.getThisDescriptor()) {
CodegenContext c = context; CodegenContext c = context;
while (c.getContextDescriptor() != enclosed) { while (c.getContextDescriptor() != enclosed) {
c = c.getParentContext(); c = c.getParentContext();
assert c != null; if (c == null) {
return (MemberDescriptor) descriptor;
}
} }
fd = (FunctionDescriptor) c.getAccessor(fd); return (MemberDescriptor) c.getAccessor(descriptor);
} }
} }
return (MemberDescriptor) descriptor;
return fd;
} }
private StackValue invokeFunction( private StackValue invokeFunction(
@@ -381,6 +381,7 @@ public class ClassGenTest extends CodegenTestCase {
public void testKt1018() throws Exception { public void testKt1018() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1018.kt"); blackBoxFile("regressions/kt1018.kt");
System.out.println(generateToText());
} }
public void testKt1120() throws Exception { public void testKt1120() throws Exception {