many bug fixes
This commit is contained in:
@@ -21,9 +21,10 @@ public class ClassCodegen {
|
||||
public void generate(ClassContext parentContext, JetClassOrObject aClass) {
|
||||
GenerationState.prepareAnonymousClasses((JetElement) aClass, state.getTypeMapper());
|
||||
|
||||
ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass);
|
||||
|
||||
generateImplementation(parentContext, aClass, OwnerKind.IMPLEMENTATION);
|
||||
|
||||
ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass);
|
||||
final ClassContext contextForInners = parentContext.intoClass(descriptor, OwnerKind.IMPLEMENTATION);
|
||||
for (JetDeclaration declaration : aClass.getDeclarations()) {
|
||||
if (declaration instanceof JetClass && !(declaration instanceof JetEnumEntry)) {
|
||||
|
||||
@@ -24,4 +24,34 @@ public class CodegenUtil {
|
||||
public static boolean isInterface(JetType type) {
|
||||
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;
|
||||
if (descriptor != null) {
|
||||
classDescriptor = descriptor.getContainingDeclaration();
|
||||
if (classDescriptor.getContainingDeclaration() instanceof ClassDescriptor) {
|
||||
if (CodegenUtil.hasThis0(classDescriptor)) {
|
||||
myOuterThisIndex = enterTemp(); // outer class instance
|
||||
}
|
||||
}
|
||||
|
||||
@@ -550,7 +550,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
Type type = Type.getObjectType(descriptor.getClassname());
|
||||
v.anew(type);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -905,6 +907,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
if (declarationPsiElement instanceof PsiMethod || declarationPsiElement instanceof JetNamedFunction) {
|
||||
callableMethod = typeMapper.mapToCallableMethod((PsiNamedElement) declarationPsiElement, null);
|
||||
}
|
||||
else if (fd instanceof VariableAsFunctionDescriptor) {
|
||||
callableMethod = ClosureCodegen.asCallableMethod((FunctionDescriptor) fd);
|
||||
}
|
||||
else if (fd instanceof FunctionDescriptor) {
|
||||
callableMethod = ClosureCodegen.asCallableMethod((FunctionDescriptor) fd);
|
||||
}
|
||||
@@ -940,7 +945,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
if (callableMethod.needsReceiverOnStack()) {
|
||||
if (receiver == StackValue.none()) {
|
||||
receiver = thisExpression();
|
||||
ClassDescriptor receiverClass = callableMethod.getReceiverClass();
|
||||
receiver = receiverClass == null ? thisExpression() : generateThisOrOuter(receiverClass);
|
||||
}
|
||||
receiver.put(JetTypeMapper.TYPE_OBJECT, v);
|
||||
}
|
||||
|
||||
@@ -374,8 +374,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
if (myClass.getParent() instanceof JetClassObject) {
|
||||
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,
|
||||
|
||||
@@ -568,9 +568,8 @@ public class JetTypeMapper {
|
||||
List<ValueParameterDescriptor> parameters = descriptor.getOriginal().getValueParameters();
|
||||
List<Type> parameterTypes = new ArrayList<Type>();
|
||||
ClassDescriptor classDescriptor = descriptor.getContainingDeclaration();
|
||||
final DeclarationDescriptor outerDescriptor = classDescriptor.getContainingDeclaration();
|
||||
if (outerDescriptor instanceof ClassDescriptor && classDescriptor.getKind() != ClassKind.OBJECT) {
|
||||
parameterTypes.add(jvmType((ClassDescriptor) outerDescriptor, OwnerKind.IMPLEMENTATION));
|
||||
if (CodegenUtil.hasThis0(classDescriptor)) {
|
||||
parameterTypes.add(jvmType(CodegenUtil.getOuterClassDescriptor(classDescriptor), OwnerKind.IMPLEMENTATION));
|
||||
}
|
||||
for (ValueParameterDescriptor parameter : parameters) {
|
||||
final Type type = mapType(parameter.getOutType());
|
||||
|
||||
Reference in New Issue
Block a user