From 5bf2831db7f63e852f664ac54306ddd70a72a3ee Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Wed, 29 Aug 2012 10:22:21 +0300 Subject: [PATCH] className moved out of calculatedClosure/MutableClosure --- .../jet/codegen/ExpressionCodegen.java | 4 ++- .../jetbrains/jet/codegen/ScriptCodegen.java | 6 ++-- .../codegen/context/CalculatedClosure.java | 3 -- .../context/CodegenAnnotatingVisitor.java | 11 ++------ .../jet/codegen/context/CodegenBinding.java | 25 ++++------------- .../jet/codegen/context/CodegenContext.java | 4 ++- .../jet/codegen/context/LocalLookup.java | 28 +++++++++++++------ .../jet/codegen/context/MutableClosure.java | 10 ------- 8 files changed, 39 insertions(+), 52 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 880611c8c4e..9a6479d405c 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -1042,7 +1042,9 @@ public class ExpressionCodegen extends JetVisitor implem assert constructorDescriptor != null; 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(); v.anew(type); v.dup(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java index f43d581a4dd..0f63901b9d2 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ScriptCodegen.java @@ -98,7 +98,8 @@ public class ScriptCodegen { (CodegenContext.ScriptContext) CodegenContext.STATIC .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.defineClass(scriptDeclaration, @@ -144,7 +145,8 @@ public class ScriptCodegen { 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.invokespecial("java/lang/Object", "", "()V"); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/context/CalculatedClosure.java b/compiler/backend/src/org/jetbrains/jet/codegen/context/CalculatedClosure.java index a6e14d7bc48..2a670cf6bd1 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/context/CalculatedClosure.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/context/CalculatedClosure.java @@ -37,9 +37,6 @@ public interface CalculatedClosure { @Nullable ClassDescriptor getEnclosingClass(); - @NotNull - JvmClassName getClassName(); - @Nullable JetDelegatorToSuperCall getSuperCall(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenAnnotatingVisitor.java b/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenAnnotatingVisitor.java index 39dc06e214a..6f9a6fc59b1 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenAnnotatingVisitor.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenAnnotatingVisitor.java @@ -17,7 +17,6 @@ package org.jetbrains.jet.codegen.context; import com.intellij.util.containers.Stack; -import org.jetbrains.jet.codegen.CodegenUtil; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.psi.*; @@ -132,15 +131,10 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid { final boolean trivial = enumEntry.getDeclarations().isEmpty(); if (!trivial) { bindingTrace.record(ENUM_ENTRY_CLASS_NEED_SUBCLASS, descriptor); - - classStack.push(descriptor); - nameStack.push(peekFromStack(nameStack) + "$" + descriptor.getName().getName()); super.visitEnumEntry(enumEntry); - nameStack.pop(); - classStack.pop(); } 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); classStack.push(classDescriptor); - nameStack.push(classNameForClassDescriptor(bindingContext, classDescriptor).getInternalName()); + //noinspection ConstantConditions + nameStack.push(bindingContext.get(FQN, classDescriptor).getInternalName()); super.visitObjectLiteralExpression(expression); nameStack.pop(); classStack.pop(); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenBinding.java b/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenBinding.java index 11911fed87e..df9ca8797cf 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenBinding.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenBinding.java @@ -77,9 +77,8 @@ public class CodegenBinding { @NotNull public static JvmClassName classNameForScriptDescriptor(BindingContext bindingContext, @NotNull ScriptDescriptor scriptDescriptor) { final ClassDescriptor classDescriptor = bindingContext.get(CLASS_FOR_FUNCTION, scriptDescriptor); - final CalculatedClosure closure = bindingContext.get(CLOSURE, classDescriptor); - assert closure != null; - return closure.getClassName(); + //noinspection ConstantConditions + return bindingContext.get(FQN, classDescriptor); } @NotNull @@ -96,11 +95,6 @@ public class CodegenBinding { 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) { if (expression instanceof JetObjectLiteralExpression) { JetObjectLiteralExpression jetObjectLiteralExpression = (JetObjectLiteralExpression) expression; @@ -113,7 +107,7 @@ public class CodegenBinding { assert functionDescriptor != null; descriptor = bindingContext.get(CLASS_FOR_FUNCTION, functionDescriptor); } - return classNameForClassDescriptor(bindingContext, descriptor); + return bindingContext.get(FQN, descriptor); } 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); // 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) { return name.getInternalName(); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java b/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java index a3d2bf6ec97..b569e6af0b2 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java @@ -22,6 +22,7 @@ import org.jetbrains.asm4.Type; import org.jetbrains.jet.codegen.*; import org.jetbrains.jet.lang.descriptors.*; 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.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.context.CodegenBinding.CLASS_FOR_FUNCTION; +import static org.jetbrains.jet.codegen.context.CodegenBinding.FQN; /* * @author max @@ -275,7 +277,7 @@ public abstract class CodegenContext { for (LocalLookup.LocalLookupCase aCase : LocalLookup.LocalLookupCase.values()) { 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) { break; } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/context/LocalLookup.java b/compiler/backend/src/org/jetbrains/jet/codegen/context/LocalLookup.java index a844cfbebce..26eb175cb1a 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/context/LocalLookup.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/context/LocalLookup.java @@ -41,7 +41,12 @@ public interface LocalLookup { } @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; final boolean idx = localLookup != null && localLookup.lookupLocal(vd); @@ -53,8 +58,8 @@ public interface LocalLookup { final String fieldName = "$" + vd.getName(); StackValue innerValue = sharedVarType != null - ? StackValue.fieldForSharedVar(localType, closure.getClassName(), fieldName) - : StackValue.field(type, closure.getClassName(), fieldName, false); + ? StackValue.fieldForSharedVar(localType, className, fieldName) + : StackValue.field(type, className, fieldName, false); closure.recordField(fieldName, type); closure.captureVariable(new EnclosedValueDescriptor(d, innerValue, type)); @@ -70,7 +75,13 @@ public interface LocalLookup { } @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; final boolean idx = localLookup.lookupLocal(vd); @@ -81,7 +92,7 @@ public interface LocalLookup { Type localType = cn.getAsmType(); 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.captureVariable(new EnclosedValueDescriptor(d, innerValue, localType)); @@ -101,13 +112,13 @@ public interface LocalLookup { DeclarationDescriptor d, LocalLookup enclosingLocalLookup, GenerationState state, - MutableClosure closure + MutableClosure closure, JvmClassName className ) { if (closure.getEnclosingReceiverDescriptor() != d) return null; final JetType receiverType = ((CallableDescriptor) d).getReceiverParameter().getType(); 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(); return innerValue; @@ -126,7 +137,8 @@ public interface LocalLookup { DeclarationDescriptor d, LocalLookup localLookup, GenerationState state, - MutableClosure closure + MutableClosure closure, + JvmClassName className ); public StackValue outerValue(EnclosedValueDescriptor d, ExpressionCodegen expressionCodegen) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/context/MutableClosure.java b/compiler/backend/src/org/jetbrains/jet/codegen/context/MutableClosure.java index 0b1a3f98106..0ea11b6e8dc 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/context/MutableClosure.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/context/MutableClosure.java @@ -38,8 +38,6 @@ public final class MutableClosure implements CalculatedClosure { private final ClassDescriptor enclosingClass; private final CallableDescriptor enclosingReceiverDescriptor; - private final JvmClassName name; - private boolean captureThis; private boolean captureReceiver; @@ -49,13 +47,11 @@ public final class MutableClosure implements CalculatedClosure { MutableClosure( JetDelegatorToSuperCall superCall, ClassDescriptor enclosingClass, - JvmClassName className, CallableDescriptor enclosingReceiverDescriptor ) { this.superCall = superCall; this.enclosingClass = enclosingClass; this.enclosingReceiverDescriptor = enclosingReceiverDescriptor; - this.name = className; } @Nullable @@ -64,12 +60,6 @@ public final class MutableClosure implements CalculatedClosure { return enclosingClass; } - @NotNull - @Override - public JvmClassName getClassName() { - return name; - } - @Override public JetDelegatorToSuperCall getSuperCall() { return superCall;