many bug fixes
This commit is contained in:
@@ -21,9 +21,10 @@ public class ClassCodegen {
|
|||||||
public void generate(ClassContext parentContext, JetClassOrObject aClass) {
|
public void generate(ClassContext parentContext, JetClassOrObject aClass) {
|
||||||
GenerationState.prepareAnonymousClasses((JetElement) aClass, state.getTypeMapper());
|
GenerationState.prepareAnonymousClasses((JetElement) aClass, state.getTypeMapper());
|
||||||
|
|
||||||
|
ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass);
|
||||||
|
|
||||||
generateImplementation(parentContext, aClass, OwnerKind.IMPLEMENTATION);
|
generateImplementation(parentContext, aClass, OwnerKind.IMPLEMENTATION);
|
||||||
|
|
||||||
ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass);
|
|
||||||
final ClassContext contextForInners = parentContext.intoClass(descriptor, OwnerKind.IMPLEMENTATION);
|
final ClassContext contextForInners = parentContext.intoClass(descriptor, OwnerKind.IMPLEMENTATION);
|
||||||
for (JetDeclaration declaration : aClass.getDeclarations()) {
|
for (JetDeclaration declaration : aClass.getDeclarations()) {
|
||||||
if (declaration instanceof JetClass && !(declaration instanceof JetEnumEntry)) {
|
if (declaration instanceof JetClass && !(declaration instanceof JetEnumEntry)) {
|
||||||
|
|||||||
@@ -24,4 +24,34 @@ public class CodegenUtil {
|
|||||||
public static boolean isInterface(JetType type) {
|
public static boolean isInterface(JetType type) {
|
||||||
return isInterface(type.getConstructor().getDeclarationDescriptor());
|
return isInterface(type.getConstructor().getDeclarationDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isClassObject(DeclarationDescriptor descriptor) {
|
||||||
|
if(descriptor instanceof ClassDescriptor) {
|
||||||
|
ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
|
||||||
|
if(classDescriptor.getKind() == ClassKind.OBJECT) {
|
||||||
|
if(classDescriptor.getContainingDeclaration() instanceof ClassDescriptor) {
|
||||||
|
ClassDescriptor containingDeclaration = (ClassDescriptor) classDescriptor.getContainingDeclaration();
|
||||||
|
if(classDescriptor.getDefaultType().equals(containingDeclaration.getClassObjectType())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasThis0(ClassDescriptor classDescriptor) {
|
||||||
|
return getOuterClassDescriptor(classDescriptor) != null && !isClassObject(classDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ClassDescriptor getOuterClassDescriptor(ClassDescriptor descriptor) {
|
||||||
|
DeclarationDescriptor outerDescriptor = descriptor.getContainingDeclaration();
|
||||||
|
while(outerDescriptor != null) {
|
||||||
|
if(outerDescriptor instanceof ClassDescriptor)
|
||||||
|
break;
|
||||||
|
|
||||||
|
outerDescriptor = outerDescriptor.getContainingDeclaration();
|
||||||
|
}
|
||||||
|
return (ClassDescriptor) outerDescriptor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class ConstructorFrameMap extends FrameMap {
|
|||||||
ClassDescriptor classDescriptor = null;
|
ClassDescriptor classDescriptor = null;
|
||||||
if (descriptor != null) {
|
if (descriptor != null) {
|
||||||
classDescriptor = descriptor.getContainingDeclaration();
|
classDescriptor = descriptor.getContainingDeclaration();
|
||||||
if (classDescriptor.getContainingDeclaration() instanceof ClassDescriptor) {
|
if (CodegenUtil.hasThis0(classDescriptor)) {
|
||||||
myOuterThisIndex = enterTemp(); // outer class instance
|
myOuterThisIndex = enterTemp(); // outer class instance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -550,7 +550,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
Type type = Type.getObjectType(descriptor.getClassname());
|
Type type = Type.getObjectType(descriptor.getClassname());
|
||||||
v.anew(type);
|
v.anew(type);
|
||||||
v.dup();
|
v.dup();
|
||||||
v.invokespecial(descriptor.getClassname(), "<init>", descriptor.getConstructor().getDescriptor());
|
v.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||||
|
String jvmDescriptor = descriptor.getConstructor().getDescriptor().replace("(","(" + typeMapper.jetImplementationType((ClassDescriptor) contextType()));
|
||||||
|
v.invokespecial(descriptor.getClassname(), "<init>", jvmDescriptor);
|
||||||
return StackValue.onStack(type);
|
return StackValue.onStack(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -905,6 +907,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
if (declarationPsiElement instanceof PsiMethod || declarationPsiElement instanceof JetNamedFunction) {
|
if (declarationPsiElement instanceof PsiMethod || declarationPsiElement instanceof JetNamedFunction) {
|
||||||
callableMethod = typeMapper.mapToCallableMethod((PsiNamedElement) declarationPsiElement, null);
|
callableMethod = typeMapper.mapToCallableMethod((PsiNamedElement) declarationPsiElement, null);
|
||||||
}
|
}
|
||||||
|
else if (fd instanceof VariableAsFunctionDescriptor) {
|
||||||
|
callableMethod = ClosureCodegen.asCallableMethod((FunctionDescriptor) fd);
|
||||||
|
}
|
||||||
else if (fd instanceof FunctionDescriptor) {
|
else if (fd instanceof FunctionDescriptor) {
|
||||||
callableMethod = ClosureCodegen.asCallableMethod((FunctionDescriptor) fd);
|
callableMethod = ClosureCodegen.asCallableMethod((FunctionDescriptor) fd);
|
||||||
}
|
}
|
||||||
@@ -940,7 +945,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
}
|
}
|
||||||
if (callableMethod.needsReceiverOnStack()) {
|
if (callableMethod.needsReceiverOnStack()) {
|
||||||
if (receiver == StackValue.none()) {
|
if (receiver == StackValue.none()) {
|
||||||
receiver = thisExpression();
|
ClassDescriptor receiverClass = callableMethod.getReceiverClass();
|
||||||
|
receiver = receiverClass == null ? thisExpression() : generateThisOrOuter(receiverClass);
|
||||||
}
|
}
|
||||||
receiver.put(JetTypeMapper.TYPE_OBJECT, v);
|
receiver.put(JetTypeMapper.TYPE_OBJECT, v);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -374,8 +374,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
if (myClass.getParent() instanceof JetClassObject) {
|
if (myClass.getParent() instanceof JetClassObject) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final DeclarationDescriptor outerDescriptor = descriptor.getContainingDeclaration();
|
|
||||||
return outerDescriptor instanceof ClassDescriptor ? (ClassDescriptor) outerDescriptor : null;
|
return CodegenUtil.getOuterClassDescriptor(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateDelegatorToConstructorCall(InstructionAdapter iv, ExpressionCodegen codegen, JetCallElement constructorCall,
|
private void generateDelegatorToConstructorCall(InstructionAdapter iv, ExpressionCodegen codegen, JetCallElement constructorCall,
|
||||||
|
|||||||
@@ -568,9 +568,8 @@ public class JetTypeMapper {
|
|||||||
List<ValueParameterDescriptor> parameters = descriptor.getOriginal().getValueParameters();
|
List<ValueParameterDescriptor> parameters = descriptor.getOriginal().getValueParameters();
|
||||||
List<Type> parameterTypes = new ArrayList<Type>();
|
List<Type> parameterTypes = new ArrayList<Type>();
|
||||||
ClassDescriptor classDescriptor = descriptor.getContainingDeclaration();
|
ClassDescriptor classDescriptor = descriptor.getContainingDeclaration();
|
||||||
final DeclarationDescriptor outerDescriptor = classDescriptor.getContainingDeclaration();
|
if (CodegenUtil.hasThis0(classDescriptor)) {
|
||||||
if (outerDescriptor instanceof ClassDescriptor && classDescriptor.getKind() != ClassKind.OBJECT) {
|
parameterTypes.add(jvmType(CodegenUtil.getOuterClassDescriptor(classDescriptor), OwnerKind.IMPLEMENTATION));
|
||||||
parameterTypes.add(jvmType((ClassDescriptor) outerDescriptor, OwnerKind.IMPLEMENTATION));
|
|
||||||
}
|
}
|
||||||
for (ValueParameterDescriptor parameter : parameters) {
|
for (ValueParameterDescriptor parameter : parameters) {
|
||||||
final Type type = mapType(parameter.getOutType());
|
final Type type = mapType(parameter.getOutType());
|
||||||
|
|||||||
@@ -2,17 +2,20 @@ trait ISized {
|
|||||||
val size : Int
|
val size : Int
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ReadOnlyArray<out T> : ISized, Iterable<T> {
|
trait ReadOnlyArray<out T> : ISized, java.lang.Iterable<T> {
|
||||||
fun get(index : Int) : T
|
fun get(index : Int) : T
|
||||||
|
|
||||||
override fun iterator () : Iterator<T> = object : Iterator<T> {
|
class MyIterator() : java.util.Iterator<T> {
|
||||||
private var index = 0
|
private var index = 0
|
||||||
|
|
||||||
override fun hasNext() : Boolean = index < size
|
override fun hasNext() : Boolean = index < size
|
||||||
|
|
||||||
val next : T
|
override fun next() : T = get(index++)
|
||||||
get() = get(index++)
|
|
||||||
|
override fun remove () : Unit {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun iterator() : java.util.Iterator<T> = MyIterator()
|
||||||
}
|
}
|
||||||
|
|
||||||
trait WriteOnlyArray<in T> : ISized {
|
trait WriteOnlyArray<in T> : ISized {
|
||||||
@@ -40,5 +43,11 @@ fun box() : String {
|
|||||||
a [0] = 10
|
a [0] = 10
|
||||||
a.set(1, 2, 13)
|
a.set(1, 2, 13)
|
||||||
a [3] = 40
|
a [3] = 40
|
||||||
|
System.out?.println(a.iterator())
|
||||||
|
System.out?.println(a.iterator().hasNext())
|
||||||
|
// if(a.iterator() !is Iterator<Int>) return "fail";
|
||||||
|
// for(el in a) {
|
||||||
|
// System.out?.println(el)
|
||||||
|
// }
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
@@ -113,6 +113,7 @@ public class TypeInfoTest extends CodegenTestCase {
|
|||||||
|
|
||||||
public void testClassObjectInTypeInfo() throws Exception {
|
public void testClassObjectInTypeInfo() throws Exception {
|
||||||
loadFile();
|
loadFile();
|
||||||
|
System.out.println(generateToText());
|
||||||
Method foo = generateFunction();
|
Method foo = generateFunction();
|
||||||
JetObject jetObject = (JetObject) foo.invoke(null);
|
JetObject jetObject = (JetObject) foo.invoke(null);
|
||||||
TypeInfo<?> typeInfo = jetObject.getTypeInfo();
|
TypeInfo<?> typeInfo = jetObject.getTypeInfo();
|
||||||
|
|||||||
Reference in New Issue
Block a user