diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassBodyCodegen.java index 9933c26c351..0e76b45a8d3 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassBodyCodegen.java @@ -40,16 +40,16 @@ public abstract class ClassBodyCodegen extends MemberCodegen { protected final ClassDescriptor descriptor; protected ClassBodyCodegen( - @NotNull JetClassOrObject aClass, + @NotNull JetClassOrObject myClass, @NotNull ClassContext context, @NotNull ClassBuilder v, @NotNull GenerationState state, @Nullable MemberCodegen parentCodegen ) { - super(state, parentCodegen, context, aClass, v); - myClass = aClass; - kind = context.getContextKind(); - descriptor = bindingContext.get(BindingContext.CLASS, aClass); + super(state, parentCodegen, context, myClass, v); + this.myClass = myClass; + this.kind = context.getContextKind(); + this.descriptor = bindingContext.get(BindingContext.CLASS, myClass); } @Override @@ -93,7 +93,7 @@ public abstract class ClassBodyCodegen extends MemberCodegen { genFunctionOrProperty(declaration); } else if (declaration instanceof JetClassOrObject) { - if (declaration instanceof JetEnumEntry && !enumEntryNeedSubclass(state.getBindingContext(), (JetEnumEntry) declaration)) { + if (declaration instanceof JetEnumEntry && !enumEntryNeedSubclass(bindingContext, (JetEnumEntry) declaration)) { return; } @@ -108,7 +108,7 @@ public abstract class ClassBodyCodegen extends MemberCodegen { boolean isAnnotation = origin instanceof JetClass && ((JetClass) origin).isAnnotation(); for (JetParameter p : getPrimaryConstructorParameters()) { if (p.hasValOrVarNode()) { - PropertyDescriptor propertyDescriptor = state.getBindingContext().get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, p); + PropertyDescriptor propertyDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, p); if (propertyDescriptor != null) { if (!isAnnotation) { propertyCodegen.generatePrimaryConstructorProperty(p, propertyDescriptor); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java index 9da3fe94ab0..e157a8c8f43 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java @@ -76,7 +76,7 @@ public class ClosureCodegen extends MemberCodegen { @NotNull ClassContext context, @NotNull KotlinSyntheticClass.Kind syntheticClassKind, @NotNull FunctionGenerationStrategy strategy, - @Nullable MemberCodegen parentCodegen, + @NotNull MemberCodegen parentCodegen, @NotNull ClassBuilder classBuilder, @NotNull Type asmType ) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index 3489bcefc1f..73592206aab 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -79,20 +79,26 @@ import static org.jetbrains.kotlin.resolve.jvm.diagnostics.DiagnosticsPackage.Ot import static org.jetbrains.kotlin.resolve.jvm.diagnostics.DiagnosticsPackage.Synthetic; import static org.jetbrains.org.objectweb.asm.Opcodes.*; -public class FunctionCodegen extends ParentCodegenAware { +public class FunctionCodegen { + public final GenerationState state; + private final JetTypeMapper typeMapper; + private final BindingContext bindingContext; private final CodegenContext owner; - private final ClassBuilder v; + private final MemberCodegen memberCodegen; public FunctionCodegen( @NotNull CodegenContext owner, @NotNull ClassBuilder v, @NotNull GenerationState state, - MemberCodegen parentCodegen + @NotNull MemberCodegen memberCodegen ) { - super(state, parentCodegen); this.owner = owner; this.v = v; + this.state = state; + this.typeMapper = state.getTypeMapper(); + this.bindingContext = state.getBindingContext(); + this.memberCodegen = memberCodegen; } public void gen(@NotNull JetNamedFunction function) { @@ -166,8 +172,8 @@ public class FunctionCodegen extends ParentCodegenAware { boolean staticInClassObject = AnnotationsPackage.isPlatformStaticInClassObject(functionDescriptor); if (staticInClassObject) { - MemberCodegen codegen = getParentCodegen().getParentCodegen(); - ((ImplementationBodyCodegen) codegen).addAdditionalTask(new PlatformStaticGenerator(functionDescriptor, origin, state)); + ImplementationBodyCodegen parentBodyCodegen = (ImplementationBodyCodegen) memberCodegen.getParentCodegen(); + parentBodyCodegen.addAdditionalTask(new PlatformStaticGenerator(functionDescriptor, origin, state)); } if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES || isAbstractMethod(functionDescriptor, methodContextKind)) { @@ -186,14 +192,14 @@ public class FunctionCodegen extends ParentCodegenAware { } if (!isNative) { - generateMethodBody(mv, functionDescriptor, methodContext, jvmSignature, strategy, getParentCodegen()); + generateMethodBody(mv, functionDescriptor, methodContext, jvmSignature, strategy, memberCodegen); } else if (staticInClassObject) { // native platformStatic foo() in class object should delegate to the static native function moved to the outer class mv.visitCode(); FunctionDescriptor staticFunctionDescriptor = PlatformStaticGenerator.createStaticFunctionDescriptor(functionDescriptor); JvmMethodSignature jvmMethodSignature = - typeMapper.mapSignature(getParentCodegen().getContext().accessibleFunctionDescriptor(staticFunctionDescriptor)); + typeMapper.mapSignature(memberCodegen.getContext().accessibleFunctionDescriptor(staticFunctionDescriptor)); Type owningType = typeMapper.mapClass((ClassifierDescriptor) staticFunctionDescriptor.getContainingDeclaration()); generateDelegateToMethodBody(false, mv, jvmMethodSignature.getAsmMethod(), owningType.getInternalName()); } @@ -642,7 +648,7 @@ public class FunctionCodegen extends ParentCodegenAware { @Nullable JetNamedFunction function ) { mv.visitCode(); - generateDefaultImplBody(methodContext, signature, functionDescriptor, isStatic, mv, loadStrategy, function, getParentCodegen(), state); + generateDefaultImplBody(methodContext, signature, functionDescriptor, isStatic, mv, loadStrategy, function, memberCodegen, state); endVisit(mv, "default method", callableDescriptorToDeclaration(functionDescriptor)); } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java index 3f66252c43a..87d6d0892e2 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java @@ -190,7 +190,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { if (isEnum) { for (JetDeclaration declaration : myClass.getDeclarations()) { if (declaration instanceof JetEnumEntry) { - if (enumEntryNeedSubclass(state.getBindingContext(), (JetEnumEntry) declaration)) { + if (enumEntryNeedSubclass(bindingContext, (JetEnumEntry) declaration)) { access &= ~ACC_FINAL; } } @@ -1166,7 +1166,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { } if (isClassObjectWithBackingFieldsInOuter(descriptor)) { - final ImplementationBodyCodegen parentCodegen = getParentBodyCodegen(this); + final ImplementationBodyCodegen parentCodegen = (ImplementationBodyCodegen) getParentCodegen(); //generate OBJECT$ parentCodegen.generateClassObjectInitializer(descriptor); generateInitializers(new Function0() { @@ -1248,7 +1248,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { result.addField((JetDelegatorByExpressionSpecifier) specifier, propertyDescriptor); } else { - JetType expressionType = state.getBindingContext().get(BindingContext.EXPRESSION_TYPE, expression); + JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression); Type asmType = expressionType != null ? typeMapper.mapType(expressionType) : typeMapper.mapType(getSuperClass(specifier)); result.addField((JetDelegatorByExpressionSpecifier) specifier, asmType, "$delegate_" + n); @@ -1599,7 +1599,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { iv.aconst(enumConstant.getName()); iv.iconst(ordinal); - if (delegationSpecifiers.size() == 1 && !enumEntryNeedSubclass(state.getBindingContext(), enumConstant)) { + if (delegationSpecifiers.size() == 1 && !enumEntryNeedSubclass(bindingContext, enumConstant)) { JetDelegationSpecifier specifier = delegationSpecifiers.get(0); if (!(specifier instanceof JetDelegatorToSuperCall)) { throw new UnsupportedOperationException("unsupported type of enum constant initializer: " + specifier); @@ -1626,7 +1626,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { DelegationFieldsInfo.Field field = delegationFieldsInfo.getInfo((JetDelegatorByExpressionSpecifier) specifier); generateDelegateField(field); JetExpression delegateExpression = ((JetDelegatorByExpressionSpecifier) specifier).getDelegateExpression(); - JetType delegateExpressionType = state.getBindingContext().get(BindingContext.EXPRESSION_TYPE, delegateExpression); + JetType delegateExpressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, delegateExpression); generateDelegates(getSuperClass(specifier), delegateExpressionType, field); } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java index f7cb20c5b13..896d78716d1 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java @@ -194,14 +194,6 @@ public class JvmCodegenUtil { return file != null && CodeFragmentUtilPackage.getSuppressDiagnosticsInDebugMode(file); } - @NotNull - public static ImplementationBodyCodegen getParentBodyCodegen(@Nullable MemberCodegen classBodyCodegen) { - assert classBodyCodegen != null && classBodyCodegen.getParentCodegen() instanceof ImplementationBodyCodegen - : "Class object should have appropriate parent BodyCodegen"; - - return (ImplementationBodyCodegen) classBodyCodegen.getParentCodegen(); - } - @Nullable public static ClassDescriptor getDispatchReceiverParameterForConstructorCall( @NotNull ConstructorDescriptor descriptor, diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java index beea4393474..ae1433da07e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java @@ -27,6 +27,7 @@ import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil; import org.jetbrains.kotlin.codegen.inline.NameGenerator; import org.jetbrains.kotlin.codegen.inline.ReifiedTypeParametersUsages; import org.jetbrains.kotlin.codegen.state.GenerationState; +import org.jetbrains.kotlin.codegen.state.JetTypeMapper; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.annotations.Annotations; import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl; @@ -61,16 +62,20 @@ import static org.jetbrains.kotlin.resolve.jvm.diagnostics.DiagnosticsPackage.Tr import static org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin.NO_ORIGIN; import static org.jetbrains.org.objectweb.asm.Opcodes.*; -public abstract class MemberCodegen extends ParentCodegenAware { +public abstract class MemberCodegen { + protected final GenerationState state; protected final T element; protected final FieldOwnerContext context; protected final ClassBuilder v; protected final FunctionCodegen functionCodegen; protected final PropertyCodegen propertyCodegen; + protected final JetTypeMapper typeMapper; + protected final BindingContext bindingContext; + private final MemberCodegen parentCodegen; + private final ReifiedTypeParametersUsages reifiedTypeParametersUsages = new ReifiedTypeParametersUsages(); protected ExpressionCodegen clInit; private NameGenerator inlineNameGenerator; - private final ReifiedTypeParametersUsages reifiedTypeParametersUsages = new ReifiedTypeParametersUsages(); public MemberCodegen( @NotNull GenerationState state, @@ -79,12 +84,15 @@ public abstract class MemberCodegen wrapped) { @@ -249,8 +257,9 @@ public abstract class MemberCodegen getParentCodegen() { + return parentCodegen; + } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ParentCodegenAware.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ParentCodegenAware.java deleted file mode 100644 index c760510fe02..00000000000 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ParentCodegenAware.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2010-2015 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.kotlin.codegen; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.codegen.state.GenerationState; -import org.jetbrains.kotlin.codegen.state.JetTypeMapper; -import org.jetbrains.kotlin.resolve.BindingContext; - -public class ParentCodegenAware { - protected final GenerationState state; - protected final JetTypeMapper typeMapper; - protected final BindingContext bindingContext; - private final MemberCodegen parentCodegen; - - public ParentCodegenAware(@NotNull GenerationState state, @Nullable MemberCodegen parentCodegen) { - this.state = state; - this.typeMapper = state.getTypeMapper(); - this.bindingContext = state.getBindingContext(); - this.parentCodegen = parentCodegen; - } - - @Nullable - public MemberCodegen getParentCodegen() { - return parentCodegen; - } -} diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java index 7cc38149cbe..a8b22f957b3 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java @@ -46,7 +46,6 @@ import org.jetbrains.org.objectweb.asm.commons.Method; import java.util.List; import static org.jetbrains.kotlin.codegen.AsmUtil.*; -import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.getParentBodyCodegen; import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isInterface; import static org.jetbrains.kotlin.codegen.JvmSerializationBindings.*; import static org.jetbrains.kotlin.resolve.DescriptorUtils.isClassObject; @@ -62,14 +61,14 @@ public class PropertyCodegen { private final JetTypeMapper typeMapper; private final BindingContext bindingContext; private final FieldOwnerContext context; - private final MemberCodegen classBodyCodegen; + private final MemberCodegen memberCodegen; private final OwnerKind kind; public PropertyCodegen( @NotNull FieldOwnerContext context, @NotNull ClassBuilder v, @NotNull FunctionCodegen functionCodegen, - @Nullable MemberCodegen classBodyCodegen + @NotNull MemberCodegen memberCodegen ) { this.state = functionCodegen.state; this.v = v; @@ -77,7 +76,7 @@ public class PropertyCodegen { this.typeMapper = state.getTypeMapper(); this.bindingContext = state.getBindingContext(); this.context = context; - this.classBodyCodegen = classBodyCodegen; + this.memberCodegen = memberCodegen; this.kind = context.getContextKind(); } @@ -254,7 +253,7 @@ public class PropertyCodegen { if (AsmUtil.isInstancePropertyWithStaticBackingField(propertyDescriptor) ) { modifiers |= ACC_STATIC | getVisibilityForSpecialPropertyBackingField(propertyDescriptor, isDelegate); if (AsmUtil.isPropertyWithBackingFieldInOuterClass(propertyDescriptor)) { - ImplementationBodyCodegen codegen = getParentBodyCodegen(classBodyCodegen); + ImplementationBodyCodegen codegen = (ImplementationBodyCodegen) memberCodegen.getParentCodegen(); builder = codegen.v; backingFieldContext = codegen.context; v.getSerializationBindings().put(STATIC_FIELD_IN_OUTER_CLASS, propertyDescriptor); @@ -265,7 +264,7 @@ public class PropertyCodegen { } if (AsmUtil.isPropertyWithBackingFieldCopyInOuterClass(propertyDescriptor)) { - ImplementationBodyCodegen parentBodyCodegen = getParentBodyCodegen(classBodyCodegen); + ImplementationBodyCodegen parentBodyCodegen = (ImplementationBodyCodegen) memberCodegen.getParentCodegen(); parentBodyCodegen.addClassObjectPropertyToCopy(propertyDescriptor, defaultValue); }