className moved out of calculatedClosure/MutableClosure
This commit is contained in:
@@ -1042,7 +1042,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
assert constructorDescriptor != null;
|
assert constructorDescriptor != null;
|
||||||
CallableMethod constructor = typeMapper.mapToCallableMethod(constructorDescriptor, closure);
|
CallableMethod constructor = typeMapper.mapToCallableMethod(constructorDescriptor, closure);
|
||||||
|
|
||||||
final JvmClassName name = closure.getClassName();
|
final JvmClassName name = bindingContext.get(FQN, constructorDescriptor.getContainingDeclaration());
|
||||||
|
assert name != null;
|
||||||
|
|
||||||
Type type = name.getAsmType();
|
Type type = name.getAsmType();
|
||||||
v.anew(type);
|
v.anew(type);
|
||||||
v.dup();
|
v.dup();
|
||||||
|
|||||||
@@ -98,7 +98,8 @@ public class ScriptCodegen {
|
|||||||
(CodegenContext.ScriptContext) CodegenContext.STATIC
|
(CodegenContext.ScriptContext) CodegenContext.STATIC
|
||||||
.intoScript(scriptDescriptor, classDescriptorForScript);
|
.intoScript(scriptDescriptor, classDescriptorForScript);
|
||||||
|
|
||||||
JvmClassName className = classNameForClassDescriptor(bindingContext, classDescriptorForScript);
|
JvmClassName className = bindingContext.get(FQN, classDescriptorForScript);
|
||||||
|
assert className != null;
|
||||||
|
|
||||||
ClassBuilder classBuilder = classFileFactory.newVisitor(className.getInternalName() + ".class");
|
ClassBuilder classBuilder = classFileFactory.newVisitor(className.getInternalName() + ".class");
|
||||||
classBuilder.defineClass(scriptDeclaration,
|
classBuilder.defineClass(scriptDeclaration,
|
||||||
@@ -144,7 +145,8 @@ public class ScriptCodegen {
|
|||||||
|
|
||||||
InstructionAdapter instructionAdapter = new InstructionAdapter(mv);
|
InstructionAdapter instructionAdapter = new InstructionAdapter(mv);
|
||||||
|
|
||||||
JvmClassName className = classNameForClassDescriptor(bindingContext, classDescriptorForScript);
|
JvmClassName className = bindingContext.get(FQN, classDescriptorForScript);
|
||||||
|
assert className != null;
|
||||||
|
|
||||||
instructionAdapter.load(0, className.getAsmType());
|
instructionAdapter.load(0, className.getAsmType());
|
||||||
instructionAdapter.invokespecial("java/lang/Object", "<init>", "()V");
|
instructionAdapter.invokespecial("java/lang/Object", "<init>", "()V");
|
||||||
|
|||||||
@@ -37,9 +37,6 @@ public interface CalculatedClosure {
|
|||||||
@Nullable
|
@Nullable
|
||||||
ClassDescriptor getEnclosingClass();
|
ClassDescriptor getEnclosingClass();
|
||||||
|
|
||||||
@NotNull
|
|
||||||
JvmClassName getClassName();
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
JetDelegatorToSuperCall getSuperCall();
|
JetDelegatorToSuperCall getSuperCall();
|
||||||
|
|
||||||
|
|||||||
+3
-8
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.jet.codegen.context;
|
package org.jetbrains.jet.codegen.context;
|
||||||
|
|
||||||
import com.intellij.util.containers.Stack;
|
import com.intellij.util.containers.Stack;
|
||||||
import org.jetbrains.jet.codegen.CodegenUtil;
|
|
||||||
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;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
@@ -132,15 +131,10 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
|
|||||||
final boolean trivial = enumEntry.getDeclarations().isEmpty();
|
final boolean trivial = enumEntry.getDeclarations().isEmpty();
|
||||||
if (!trivial) {
|
if (!trivial) {
|
||||||
bindingTrace.record(ENUM_ENTRY_CLASS_NEED_SUBCLASS, descriptor);
|
bindingTrace.record(ENUM_ENTRY_CLASS_NEED_SUBCLASS, descriptor);
|
||||||
|
|
||||||
classStack.push(descriptor);
|
|
||||||
nameStack.push(peekFromStack(nameStack) + "$" + descriptor.getName().getName());
|
|
||||||
super.visitEnumEntry(enumEntry);
|
super.visitEnumEntry(enumEntry);
|
||||||
nameStack.pop();
|
|
||||||
classStack.pop();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
super.visitEnumEntry(enumEntry);
|
bindingTrace.record(FQN, descriptor, bindingTrace.get(FQN, peekFromStack(classStack)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,7 +209,8 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
|
|||||||
recordClosure(bindingTrace, expression.getObjectDeclaration(), classDescriptor, peekFromStack(classStack), JvmClassName.byInternalName(name), false);
|
recordClosure(bindingTrace, expression.getObjectDeclaration(), classDescriptor, peekFromStack(classStack), JvmClassName.byInternalName(name), false);
|
||||||
|
|
||||||
classStack.push(classDescriptor);
|
classStack.push(classDescriptor);
|
||||||
nameStack.push(classNameForClassDescriptor(bindingContext, classDescriptor).getInternalName());
|
//noinspection ConstantConditions
|
||||||
|
nameStack.push(bindingContext.get(FQN, classDescriptor).getInternalName());
|
||||||
super.visitObjectLiteralExpression(expression);
|
super.visitObjectLiteralExpression(expression);
|
||||||
nameStack.pop();
|
nameStack.pop();
|
||||||
classStack.pop();
|
classStack.pop();
|
||||||
|
|||||||
@@ -77,9 +77,8 @@ public class CodegenBinding {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static JvmClassName classNameForScriptDescriptor(BindingContext bindingContext, @NotNull ScriptDescriptor scriptDescriptor) {
|
public static JvmClassName classNameForScriptDescriptor(BindingContext bindingContext, @NotNull ScriptDescriptor scriptDescriptor) {
|
||||||
final ClassDescriptor classDescriptor = bindingContext.get(CLASS_FOR_FUNCTION, scriptDescriptor);
|
final ClassDescriptor classDescriptor = bindingContext.get(CLASS_FOR_FUNCTION, scriptDescriptor);
|
||||||
final CalculatedClosure closure = bindingContext.get(CLOSURE, classDescriptor);
|
//noinspection ConstantConditions
|
||||||
assert closure != null;
|
return bindingContext.get(FQN, classDescriptor);
|
||||||
return closure.getClassName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -96,11 +95,6 @@ public class CodegenBinding {
|
|||||||
return closure == null ? null : closure.getEnclosingClass();
|
return closure == null ? null : closure.getEnclosingClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JvmClassName classNameForClassDescriptor(BindingContext bindingContext, ClassDescriptor descriptor) {
|
|
||||||
final CalculatedClosure closure = bindingContext.get(CLOSURE, descriptor);
|
|
||||||
return closure == null ? null : closure.getClassName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JvmClassName classNameForAnonymousClass(BindingContext bindingContext, JetElement expression) {
|
public static JvmClassName classNameForAnonymousClass(BindingContext bindingContext, JetElement expression) {
|
||||||
if (expression instanceof JetObjectLiteralExpression) {
|
if (expression instanceof JetObjectLiteralExpression) {
|
||||||
JetObjectLiteralExpression jetObjectLiteralExpression = (JetObjectLiteralExpression) expression;
|
JetObjectLiteralExpression jetObjectLiteralExpression = (JetObjectLiteralExpression) expression;
|
||||||
@@ -113,7 +107,7 @@ public class CodegenBinding {
|
|||||||
assert functionDescriptor != null;
|
assert functionDescriptor != null;
|
||||||
descriptor = bindingContext.get(CLASS_FOR_FUNCTION, functionDescriptor);
|
descriptor = bindingContext.get(CLASS_FOR_FUNCTION, functionDescriptor);
|
||||||
}
|
}
|
||||||
return classNameForClassDescriptor(bindingContext, descriptor);
|
return bindingContext.get(FQN, descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerClassNameForScript(
|
public static void registerClassNameForScript(
|
||||||
@@ -174,8 +168,9 @@ public class CodegenBinding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final MutableClosure closure = new MutableClosure(superCall, enclosing, name, enclosingReceiver);
|
final MutableClosure closure = new MutableClosure(superCall, enclosing, enclosingReceiver);
|
||||||
|
|
||||||
|
bindingTrace.record(FQN, classDescriptor, name);
|
||||||
bindingTrace.record(CLOSURE, classDescriptor, closure);
|
bindingTrace.record(CLOSURE, classDescriptor, closure);
|
||||||
|
|
||||||
// TODO: this is temporary before we have proper inner classes
|
// TODO: this is temporary before we have proper inner classes
|
||||||
@@ -295,16 +290,8 @@ public class CodegenBinding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (klass.getKind() == ClassKind.ENUM_ENTRY) {
|
|
||||||
if (enumEntryNeedSubclass(bindingTrace.getBindingContext(), klass)) {
|
|
||||||
return getJvmInternalName(bindingTrace, klass.getContainingDeclaration()).getInternalName() + "$" + klass.getName().getName();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return getJvmInternalName(bindingTrace, klass.getContainingDeclaration()).getInternalName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JvmClassName name = classNameForClassDescriptor(bindingTrace.getBindingContext(), (ClassDescriptor) descriptor);
|
JvmClassName name = bindingTrace.getBindingContext().get(FQN, descriptor);
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
return name.getInternalName();
|
return name.getInternalName();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.jet.codegen.*;
|
import org.jetbrains.jet.codegen.*;
|
||||||
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;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import static org.jetbrains.jet.codegen.JetTypeMapper.OBJECT_TYPE;
|
import static org.jetbrains.jet.codegen.JetTypeMapper.OBJECT_TYPE;
|
||||||
import static org.jetbrains.jet.codegen.context.CodegenBinding.CLASS_FOR_FUNCTION;
|
import static org.jetbrains.jet.codegen.context.CodegenBinding.CLASS_FOR_FUNCTION;
|
||||||
|
import static org.jetbrains.jet.codegen.context.CodegenBinding.FQN;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @author max
|
* @author max
|
||||||
@@ -275,7 +277,7 @@ public abstract class CodegenContext {
|
|||||||
|
|
||||||
for (LocalLookup.LocalLookupCase aCase : LocalLookup.LocalLookupCase.values()) {
|
for (LocalLookup.LocalLookupCase aCase : LocalLookup.LocalLookupCase.values()) {
|
||||||
if (aCase.isCase(d, state)) {
|
if (aCase.isCase(d, state)) {
|
||||||
StackValue innerValue = aCase.innerValue(d, enclosingLocalLookup, state, closure);
|
StackValue innerValue = aCase.innerValue(d, enclosingLocalLookup, state, closure, state.getBindingContext().get(FQN, getThisDescriptor()));
|
||||||
if (innerValue == null) {
|
if (innerValue == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,12 @@ public interface LocalLookup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StackValue innerValue(DeclarationDescriptor d, LocalLookup localLookup, GenerationState state, MutableClosure closure) {
|
public StackValue innerValue(
|
||||||
|
DeclarationDescriptor d,
|
||||||
|
LocalLookup localLookup,
|
||||||
|
GenerationState state,
|
||||||
|
MutableClosure closure, JvmClassName className
|
||||||
|
) {
|
||||||
VariableDescriptor vd = (VariableDescriptor) d;
|
VariableDescriptor vd = (VariableDescriptor) d;
|
||||||
|
|
||||||
final boolean idx = localLookup != null && localLookup.lookupLocal(vd);
|
final boolean idx = localLookup != null && localLookup.lookupLocal(vd);
|
||||||
@@ -53,8 +58,8 @@ public interface LocalLookup {
|
|||||||
|
|
||||||
final String fieldName = "$" + vd.getName();
|
final String fieldName = "$" + vd.getName();
|
||||||
StackValue innerValue = sharedVarType != null
|
StackValue innerValue = sharedVarType != null
|
||||||
? StackValue.fieldForSharedVar(localType, closure.getClassName(), fieldName)
|
? StackValue.fieldForSharedVar(localType, className, fieldName)
|
||||||
: StackValue.field(type, closure.getClassName(), fieldName, false);
|
: StackValue.field(type, className, fieldName, false);
|
||||||
|
|
||||||
closure.recordField(fieldName, type);
|
closure.recordField(fieldName, type);
|
||||||
closure.captureVariable(new EnclosedValueDescriptor(d, innerValue, type));
|
closure.captureVariable(new EnclosedValueDescriptor(d, innerValue, type));
|
||||||
@@ -70,7 +75,13 @@ public interface LocalLookup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StackValue innerValue(DeclarationDescriptor d, LocalLookup localLookup, GenerationState state, MutableClosure closure) {
|
public StackValue innerValue(
|
||||||
|
DeclarationDescriptor d,
|
||||||
|
LocalLookup localLookup,
|
||||||
|
GenerationState state,
|
||||||
|
MutableClosure closure,
|
||||||
|
JvmClassName className
|
||||||
|
) {
|
||||||
FunctionDescriptor vd = (FunctionDescriptor) d;
|
FunctionDescriptor vd = (FunctionDescriptor) d;
|
||||||
|
|
||||||
final boolean idx = localLookup.lookupLocal(vd);
|
final boolean idx = localLookup.lookupLocal(vd);
|
||||||
@@ -81,7 +92,7 @@ public interface LocalLookup {
|
|||||||
Type localType = cn.getAsmType();
|
Type localType = cn.getAsmType();
|
||||||
|
|
||||||
final String fieldName = "$" + vd.getName();
|
final String fieldName = "$" + vd.getName();
|
||||||
StackValue innerValue = StackValue.field(localType, closure.getClassName(), fieldName, false);
|
StackValue innerValue = StackValue.field(localType, className, fieldName, false);
|
||||||
|
|
||||||
closure.recordField(fieldName, localType);
|
closure.recordField(fieldName, localType);
|
||||||
closure.captureVariable(new EnclosedValueDescriptor(d, innerValue, localType));
|
closure.captureVariable(new EnclosedValueDescriptor(d, innerValue, localType));
|
||||||
@@ -101,13 +112,13 @@ public interface LocalLookup {
|
|||||||
DeclarationDescriptor d,
|
DeclarationDescriptor d,
|
||||||
LocalLookup enclosingLocalLookup,
|
LocalLookup enclosingLocalLookup,
|
||||||
GenerationState state,
|
GenerationState state,
|
||||||
MutableClosure closure
|
MutableClosure closure, JvmClassName className
|
||||||
) {
|
) {
|
||||||
if (closure.getEnclosingReceiverDescriptor() != d) return null;
|
if (closure.getEnclosingReceiverDescriptor() != d) return null;
|
||||||
|
|
||||||
final JetType receiverType = ((CallableDescriptor) d).getReceiverParameter().getType();
|
final JetType receiverType = ((CallableDescriptor) d).getReceiverParameter().getType();
|
||||||
Type type = state.getInjector().getJetTypeMapper().mapType(receiverType, MapTypeMode.VALUE);
|
Type type = state.getInjector().getJetTypeMapper().mapType(receiverType, MapTypeMode.VALUE);
|
||||||
StackValue innerValue = StackValue.field(type, closure.getClassName(), CodegenUtil.RECEIVER$0, false);
|
StackValue innerValue = StackValue.field(type, className, CodegenUtil.RECEIVER$0, false);
|
||||||
closure.setCaptureReceiver();
|
closure.setCaptureReceiver();
|
||||||
|
|
||||||
return innerValue;
|
return innerValue;
|
||||||
@@ -126,7 +137,8 @@ public interface LocalLookup {
|
|||||||
DeclarationDescriptor d,
|
DeclarationDescriptor d,
|
||||||
LocalLookup localLookup,
|
LocalLookup localLookup,
|
||||||
GenerationState state,
|
GenerationState state,
|
||||||
MutableClosure closure
|
MutableClosure closure,
|
||||||
|
JvmClassName className
|
||||||
);
|
);
|
||||||
|
|
||||||
public StackValue outerValue(EnclosedValueDescriptor d, ExpressionCodegen expressionCodegen) {
|
public StackValue outerValue(EnclosedValueDescriptor d, ExpressionCodegen expressionCodegen) {
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ public final class MutableClosure implements CalculatedClosure {
|
|||||||
private final ClassDescriptor enclosingClass;
|
private final ClassDescriptor enclosingClass;
|
||||||
private final CallableDescriptor enclosingReceiverDescriptor;
|
private final CallableDescriptor enclosingReceiverDescriptor;
|
||||||
|
|
||||||
private final JvmClassName name;
|
|
||||||
|
|
||||||
private boolean captureThis;
|
private boolean captureThis;
|
||||||
private boolean captureReceiver;
|
private boolean captureReceiver;
|
||||||
|
|
||||||
@@ -49,13 +47,11 @@ public final class MutableClosure implements CalculatedClosure {
|
|||||||
MutableClosure(
|
MutableClosure(
|
||||||
JetDelegatorToSuperCall superCall,
|
JetDelegatorToSuperCall superCall,
|
||||||
ClassDescriptor enclosingClass,
|
ClassDescriptor enclosingClass,
|
||||||
JvmClassName className,
|
|
||||||
CallableDescriptor enclosingReceiverDescriptor
|
CallableDescriptor enclosingReceiverDescriptor
|
||||||
) {
|
) {
|
||||||
this.superCall = superCall;
|
this.superCall = superCall;
|
||||||
this.enclosingClass = enclosingClass;
|
this.enclosingClass = enclosingClass;
|
||||||
this.enclosingReceiverDescriptor = enclosingReceiverDescriptor;
|
this.enclosingReceiverDescriptor = enclosingReceiverDescriptor;
|
||||||
this.name = className;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -64,12 +60,6 @@ public final class MutableClosure implements CalculatedClosure {
|
|||||||
return enclosingClass;
|
return enclosingClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public JvmClassName getClassName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetDelegatorToSuperCall getSuperCall() {
|
public JetDelegatorToSuperCall getSuperCall() {
|
||||||
return superCall;
|
return superCall;
|
||||||
|
|||||||
Reference in New Issue
Block a user