Remove BindingTraceAware, TypeMapperAware, BindingContextAware
- delete suspicious caching logic from CodegenBinding.getAsmType(), which makes JetTypeMapper now depend only on BindingContext - inline all of these classes into GenerationStateAware and the latter into JetTypeMapper
This commit is contained in:
@@ -245,8 +245,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
boolean isLocalOrAnonymousClass = isObjectLiteral ||
|
||||
!(parentDescriptor instanceof PackageFragmentDescriptor || parentDescriptor instanceof ClassDescriptor);
|
||||
// Do not emit enclosing method in "light-classes mode" since currently we genenerate local light classes as if they're top level
|
||||
if (isLocalOrAnonymousClass && getState().getClassBuilderMode() != ClassBuilderMode.LIGHT_CLASSES) {
|
||||
// Do not emit enclosing method in "light-classes mode" since currently we generate local light classes as if they're top level
|
||||
if (isLocalOrAnonymousClass && state.getClassBuilderMode() != ClassBuilderMode.LIGHT_CLASSES) {
|
||||
String outerClassName = getOuterClassName(descriptor, typeMapper);
|
||||
FunctionDescriptor function = DescriptorUtils.getParentOfType(descriptor, FunctionDescriptor.class);
|
||||
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.codegen.binding;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
|
||||
public class BindingContextAware {
|
||||
@NotNull protected final BindingContext bindingContext;
|
||||
|
||||
public BindingContextAware(@NotNull BindingContext context) {
|
||||
bindingContext = context;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public final BindingContext getBindingContext() {
|
||||
return bindingContext;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.codegen.binding;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
|
||||
public class BindingTraceAware extends BindingContextAware {
|
||||
@NotNull protected final BindingTrace bindingTrace;
|
||||
|
||||
public BindingTraceAware(@NotNull BindingTrace bindingTrace) {
|
||||
super(bindingTrace.getBindingContext());
|
||||
this.bindingTrace = bindingTrace;
|
||||
}
|
||||
|
||||
@NotNull public final BindingTrace getBindingTrace() {
|
||||
return bindingTrace;
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -172,7 +172,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
|
||||
}
|
||||
else {
|
||||
Type asmType = bindingTrace.get(ASM_TYPE, getOuterClassDescriptor());
|
||||
assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingTrace, descriptor, asmType);
|
||||
assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingContext, descriptor, asmType);
|
||||
bindingTrace.record(ASM_TYPE, descriptor, asmType);
|
||||
}
|
||||
}
|
||||
@@ -338,8 +338,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
|
||||
@NotNull ClassDescriptor classDescriptor,
|
||||
@NotNull String name
|
||||
) {
|
||||
CodegenBinding.recordClosure(bindingTrace, element, classDescriptor, getOuterClassDescriptor(),
|
||||
Type.getObjectType(name));
|
||||
CodegenBinding.recordClosure(bindingTrace, element, classDescriptor, getOuterClassDescriptor(), Type.getObjectType(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -171,11 +171,11 @@ public class CodegenBinding {
|
||||
}
|
||||
|
||||
static void recordClosure(
|
||||
BindingTrace bindingTrace,
|
||||
@NotNull BindingTrace bindingTrace,
|
||||
@Nullable JetElement element,
|
||||
ClassDescriptor classDescriptor,
|
||||
@NotNull ClassDescriptor classDescriptor,
|
||||
@Nullable ClassDescriptor enclosing,
|
||||
Type asmType
|
||||
@NotNull Type asmType
|
||||
) {
|
||||
JetDelegatorToSuperCall superCall = findSuperCall(bindingTrace.getBindingContext(), element);
|
||||
|
||||
@@ -193,7 +193,7 @@ public class CodegenBinding {
|
||||
|
||||
MutableClosure closure = new MutableClosure(superCall, enclosing, enclosingReceiver);
|
||||
|
||||
assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingTrace, classDescriptor, asmType);
|
||||
assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingTrace.getBindingContext(), classDescriptor, asmType);
|
||||
bindingTrace.record(ASM_TYPE, classDescriptor, asmType);
|
||||
bindingTrace.record(CLOSURE, classDescriptor, closure);
|
||||
|
||||
@@ -284,22 +284,20 @@ public class CodegenBinding {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Type getAsmType(@NotNull BindingTrace bindingTrace, @NotNull ClassDescriptor klass) {
|
||||
public static Type getAsmType(@NotNull BindingContext bindingContext, @NotNull ClassDescriptor klass) {
|
||||
klass = (ClassDescriptor) klass.getOriginal();
|
||||
Type alreadyComputedType = bindingTrace.getBindingContext().get(ASM_TYPE, klass);
|
||||
Type alreadyComputedType = bindingContext.get(ASM_TYPE, klass);
|
||||
if (alreadyComputedType != null) {
|
||||
return alreadyComputedType;
|
||||
}
|
||||
|
||||
Type asmType = Type.getObjectType(getAsmTypeImpl(bindingTrace, klass));
|
||||
|
||||
assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingTrace, klass, asmType);
|
||||
bindingTrace.record(ASM_TYPE, klass, asmType);
|
||||
Type asmType = Type.getObjectType(getAsmTypeImpl(bindingContext, klass));
|
||||
assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingContext, klass, asmType);
|
||||
return asmType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getAsmTypeImpl(@NotNull BindingTrace bindingTrace, @NotNull ClassDescriptor klass) {
|
||||
private static String getAsmTypeImpl(@NotNull BindingContext bindingContext, @NotNull ClassDescriptor klass) {
|
||||
DeclarationDescriptor container = klass.getContainingDeclaration();
|
||||
|
||||
if (container instanceof PackageFragmentDescriptor) {
|
||||
@@ -310,7 +308,7 @@ public class CodegenBinding {
|
||||
|
||||
assert container instanceof ClassDescriptor : "Unexpected container: " + container + " for " + klass;
|
||||
|
||||
String containerInternalName = getAsmType(bindingTrace, (ClassDescriptor) container).getInternalName();
|
||||
String containerInternalName = getAsmType(bindingContext, (ClassDescriptor) container).getInternalName();
|
||||
if (klass.getKind() == ClassKind.OBJECT || klass.getKind() == ClassKind.CLASS_OBJECT) {
|
||||
if (isEnumClass(container)) {
|
||||
return containerInternalName;
|
||||
|
||||
@@ -47,9 +47,9 @@ public final class PsiCodegenPredictor {
|
||||
}
|
||||
|
||||
public static boolean checkPredictedNameFromPsi(
|
||||
@NotNull BindingTrace bindingTrace, @NotNull DeclarationDescriptor descriptor, @Nullable Type nameFromDescriptors
|
||||
@NotNull BindingContext bindingContext, @NotNull DeclarationDescriptor descriptor, @Nullable Type nameFromDescriptors
|
||||
) {
|
||||
PsiElement element = descriptorToDeclaration(bindingTrace.getBindingContext(), descriptor);
|
||||
PsiElement element = descriptorToDeclaration(bindingContext, descriptor);
|
||||
if (element instanceof JetDeclaration) {
|
||||
String classNameFromPsi = getPredefinedJvmInternalName((JetDeclaration) element);
|
||||
assert classNameFromPsi == null || Type.getObjectType(classNameFromPsi).equals(nameFromDescriptors) :
|
||||
|
||||
@@ -304,10 +304,11 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
lazyOuterExpression = LockBasedStorageManager.NO_LOCKS.createNullableLazyValue(new Function0<StackValue>() {
|
||||
@Override
|
||||
public StackValue invoke() {
|
||||
BindingContext bindingContext = typeMapper.getBindingContext();
|
||||
ClassDescriptor enclosingClass = getEnclosingClass();
|
||||
return enclosingClass != null && canHaveOuter(typeMapper.getBindingContext(), classDescriptor)
|
||||
return enclosingClass != null && canHaveOuter(bindingContext, classDescriptor)
|
||||
? StackValue.field(typeMapper.mapType(enclosingClass),
|
||||
CodegenBinding.getAsmType(typeMapper.getBindingTrace(), classDescriptor),
|
||||
CodegenBinding.getAsmType(bindingContext, classDescriptor),
|
||||
CAPTURED_THIS_FIELD,
|
||||
false)
|
||||
: null;
|
||||
|
||||
@@ -130,7 +130,7 @@ public class GenerationState {
|
||||
this.bindingTrace = new DelegatingBindingTrace(bindingContext, "trace in GenerationState");
|
||||
this.bindingContext = bindingTrace.getBindingContext();
|
||||
|
||||
this.typeMapper = new JetTypeMapper(bindingTrace, classBuilderMode);
|
||||
this.typeMapper = new JetTypeMapper(this.bindingContext, classBuilderMode);
|
||||
|
||||
this.intrinsics = new IntrinsicMethods();
|
||||
this.classFileFactory = new ClassFileFactory(this);
|
||||
|
||||
@@ -17,16 +17,21 @@
|
||||
package org.jetbrains.jet.codegen.state;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
|
||||
public class GenerationStateAware extends TypeMapperAware {
|
||||
@NotNull protected final GenerationState state;
|
||||
public class GenerationStateAware {
|
||||
protected final GenerationState state;
|
||||
protected final JetTypeMapper typeMapper;
|
||||
protected final BindingContext bindingContext;
|
||||
|
||||
public GenerationStateAware(@NotNull GenerationState state) {
|
||||
super(state.getTypeMapper());
|
||||
this.state = state;
|
||||
this.typeMapper = state.getTypeMapper();
|
||||
this.bindingContext = state.getBindingContext();
|
||||
}
|
||||
|
||||
@NotNull public GenerationState getState() {
|
||||
@NotNull
|
||||
public GenerationState getState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.codegen.*;
|
||||
import org.jetbrains.jet.codegen.binding.BindingTraceAware;
|
||||
import org.jetbrains.jet.codegen.binding.CalculatedClosure;
|
||||
import org.jetbrains.jet.codegen.binding.CodegenBinding;
|
||||
import org.jetbrains.jet.codegen.context.CodegenContext;
|
||||
@@ -36,7 +35,6 @@ import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
@@ -59,13 +57,18 @@ import static org.jetbrains.jet.lang.resolve.BindingContextUtils.isVarCapturedIn
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.*;
|
||||
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
|
||||
|
||||
public class JetTypeMapper extends BindingTraceAware {
|
||||
|
||||
public class JetTypeMapper {
|
||||
private final BindingContext bindingContext;
|
||||
private final ClassBuilderMode classBuilderMode;
|
||||
|
||||
public JetTypeMapper(BindingTrace bindingTrace, ClassBuilderMode mode) {
|
||||
super(bindingTrace);
|
||||
classBuilderMode = mode;
|
||||
public JetTypeMapper(@NotNull BindingContext bindingContext, @NotNull ClassBuilderMode classBuilderMode) {
|
||||
this.bindingContext = bindingContext;
|
||||
this.classBuilderMode = classBuilderMode;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BindingContext getBindingContext() {
|
||||
return bindingContext;
|
||||
}
|
||||
|
||||
private enum JetTypeMapperMode {
|
||||
@@ -267,7 +270,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
}
|
||||
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
Type asmType = getAsmType(bindingTrace, (ClassDescriptor) descriptor);
|
||||
Type asmType = getAsmType(bindingContext, (ClassDescriptor) descriptor);
|
||||
writeGenericType(signatureVisitor, asmType, jetType, howThisTypeIsUsed, projectionsAllowed);
|
||||
return asmType;
|
||||
}
|
||||
@@ -286,7 +289,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
|
||||
@NotNull
|
||||
public Type mapTraitImpl(@NotNull ClassDescriptor descriptor) {
|
||||
return Type.getObjectType(getAsmType(bindingTrace, descriptor).getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
|
||||
return Type.getObjectType(getAsmType(bindingContext, descriptor).getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.codegen.state;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.codegen.binding.BindingTraceAware;
|
||||
|
||||
public class TypeMapperAware extends BindingTraceAware {
|
||||
@NotNull protected final JetTypeMapper typeMapper;
|
||||
|
||||
public TypeMapperAware(@NotNull JetTypeMapper typeMapper) {
|
||||
super(typeMapper.getBindingTrace());
|
||||
this.typeMapper = typeMapper;
|
||||
}
|
||||
|
||||
@NotNull public JetTypeMapper getTypeMapper() {
|
||||
return typeMapper;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user