From 8041cac9dd3b0408aae73f35b0a21c5617ee9f6a Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 7 May 2014 17:36:33 +0400 Subject: [PATCH] Remove GenerationStateAware --- .../jet/codegen/ClassFileFactory.java | 27 ++++++-------- .../jet/codegen/FunctionCodegen.java | 5 +-- .../jetbrains/jet/codegen/PackageCodegen.java | 16 +++----- .../jet/codegen/ParentCodegenAwareImpl.java | 12 ++++-- .../jet/codegen/PropertyCodegen.java | 26 ++++++------- .../jet/codegen/state/GenerationState.java | 3 +- .../codegen/state/GenerationStateAware.java | 37 ------------------- 7 files changed, 40 insertions(+), 86 deletions(-) delete mode 100644 compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationStateAware.java diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClassFileFactory.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClassFileFactory.java index 98d74c21f46..b56f9e34899 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClassFileFactory.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClassFileFactory.java @@ -24,16 +24,14 @@ import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.org.objectweb.asm.Type; import org.jetbrains.jet.OutputFile; import org.jetbrains.jet.OutputFileCollection; import org.jetbrains.jet.codegen.state.GenerationState; -import org.jetbrains.jet.codegen.state.GenerationStateAware; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.resolve.name.FqName; +import org.jetbrains.org.objectweb.asm.Type; -import javax.inject.Inject; import java.io.File; import java.util.*; @@ -41,19 +39,16 @@ import static org.jetbrains.jet.codegen.AsmUtil.asmTypeByFqNameWithoutInnerClass import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive; import static org.jetbrains.jet.lang.resolve.java.PackageClassUtils.getPackageClassFqName; -public final class ClassFileFactory extends GenerationStateAware implements OutputFileCollection { - @NotNull private ClassBuilderFactory builderFactory; - +public class ClassFileFactory implements OutputFileCollection { + private final GenerationState state; + private final ClassBuilderFactory builderFactory; private final Map package2codegen = new HashMap(); private final Map generators = new LinkedHashMap(); + private boolean isDone = false; - public ClassFileFactory(@NotNull GenerationState state) { - super(state); - } - - @Inject - public void setBuilderFactory(@NotNull ClassBuilderFactory builderFactory) { + public ClassFileFactory(@NotNull GenerationState state, @NotNull ClassBuilderFactory builderFactory) { + this.state = state; this.builderFactory = builderFactory; } @@ -137,11 +132,11 @@ public final class ClassFileFactory extends GenerationStateAware implements Outp return newVisitor(type, sourceFile); } - public ClassBuilder forLambdaInlining(Type lambaType, PsiFile sourceFile) { - if (isPrimitive(lambaType)) { - throw new IllegalStateException("Codegen for primitive type is not possible: " + lambaType); + public ClassBuilder forLambdaInlining(Type lambdaType, PsiFile sourceFile) { + if (isPrimitive(lambdaType)) { + throw new IllegalStateException("Codegen for primitive type is not possible: " + lambdaType); } - return newVisitor(lambaType, sourceFile); + return newVisitor(lambdaType, sourceFile); } @NotNull diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index d54525406cd..052cdc80ac7 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -289,8 +289,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl { Label methodBegin = new Label(); mv.visitLabel(methodBegin); - GenerationState state = parentCodegen.getState(); - JetTypeMapper typeMapper = state.getTypeMapper(); + JetTypeMapper typeMapper = parentCodegen.typeMapper; if (context.getParentContext() instanceof PackageFacadeContext) { generateStaticDelegateMethodBody(mv, signature.getAsmMethod(), (PackageFacadeContext) context.getParentContext()); @@ -307,7 +306,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl { context.setMethodStartLabel(methodEntry); if (!JetTypeMapper.isAccessor(functionDescriptor)) { - genNotNullAssertionsForParameters(new InstructionAdapter(mv), state, functionDescriptor, frameMap); + genNotNullAssertionsForParameters(new InstructionAdapter(mv), parentCodegen.state, functionDescriptor, frameMap); } strategy.generateBody(mv, signature, context, parentCodegen); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/PackageCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/PackageCodegen.java index 35665125086..ac702ffdbf7 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/PackageCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/PackageCodegen.java @@ -34,7 +34,6 @@ import org.jetbrains.jet.codegen.context.MethodContext; import org.jetbrains.jet.codegen.context.PackageContext; import org.jetbrains.jet.codegen.signature.JvmMethodSignature; import org.jetbrains.jet.codegen.state.GenerationState; -import org.jetbrains.jet.codegen.state.GenerationStateAware; import org.jetbrains.jet.config.IncrementalCompilation; import org.jetbrains.jet.descriptors.serialization.BitEncoding; import org.jetbrains.jet.descriptors.serialization.DescriptorSerializer; @@ -69,11 +68,9 @@ import static org.jetbrains.jet.descriptors.serialization.NameSerializationUtil. import static org.jetbrains.jet.lang.resolve.java.PackageClassUtils.getPackageClassFqName; import static org.jetbrains.org.objectweb.asm.Opcodes.*; -public class PackageCodegen extends GenerationStateAware { - @NotNull +public class PackageCodegen { + private final GenerationState state; private final ClassBuilderOnDemand v; - - @NotNull private final Collection files; private final PackageFragmentDescriptor packageFragment; private final PackageFragmentDescriptor compiledPackageFragment; @@ -84,8 +81,7 @@ public class PackageCodegen extends GenerationStateAware { @NotNull GenerationState state, @NotNull Collection packageFiles ) { - super(state); - + this.state = state; this.v = v; this.files = packageFiles; this.packageFragment = getOnlyPackageFragment(); @@ -159,7 +155,7 @@ public class PackageCodegen extends GenerationStateAware { if (member instanceof DeserializedSimpleFunctionDescriptor) { DeserializedSimpleFunctionDescriptor function = (DeserializedSimpleFunctionDescriptor) member; - JvmMethodSignature signature = typeMapper.mapSignature(function, OwnerKind.PACKAGE); + JvmMethodSignature signature = state.getTypeMapper().mapSignature(function, OwnerKind.PACKAGE); functionCodegen.generateMethod(null, signature, function, new FunctionGenerationStrategy() { @Override @@ -299,7 +295,7 @@ public class PackageCodegen extends GenerationStateAware { for (final JetDeclaration declaration : file.getDeclarations()) { if (declaration instanceof JetNamedFunction || declaration instanceof JetProperty) { - DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration); + DeclarationDescriptor descriptor = state.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration); assert descriptor instanceof CallableMemberDescriptor : "Expected callable member, was " + descriptor + " for " + declaration.getText(); generateCallableMemberTasks.put( @@ -341,7 +337,7 @@ public class PackageCodegen extends GenerationStateAware { private PackageFragmentDescriptor getOnlyPackageFragment() { SmartList fragments = new SmartList(); for (JetFile file : files) { - PackageFragmentDescriptor fragment = bindingContext.get(BindingContext.FILE_TO_PACKAGE_FRAGMENT, file); + PackageFragmentDescriptor fragment = state.getBindingContext().get(BindingContext.FILE_TO_PACKAGE_FRAGMENT, file); assert fragment != null : "package fragment is null for " + file; if (!fragments.contains(fragment)) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ParentCodegenAwareImpl.java b/compiler/backend/src/org/jetbrains/jet/codegen/ParentCodegenAwareImpl.java index 6703208f70d..e4ff0837834 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ParentCodegenAwareImpl.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ParentCodegenAwareImpl.java @@ -19,13 +19,19 @@ package org.jetbrains.jet.codegen; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.codegen.state.GenerationState; -import org.jetbrains.jet.codegen.state.GenerationStateAware; +import org.jetbrains.jet.codegen.state.JetTypeMapper; +import org.jetbrains.jet.lang.resolve.BindingContext; -public class ParentCodegenAwareImpl extends GenerationStateAware implements ParentCodegenAware { +public class ParentCodegenAwareImpl implements ParentCodegenAware { + protected final GenerationState state; + protected final JetTypeMapper typeMapper; + protected final BindingContext bindingContext; private final MemberCodegen parentCodegen; public ParentCodegenAwareImpl(@NotNull GenerationState state, @Nullable MemberCodegen parentCodegen) { - super(state); + this.state = state; + this.typeMapper = state.getTypeMapper(); + this.bindingContext = state.getBindingContext(); this.parentCodegen = parentCodegen; } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java index 2ad7e1bd16d..b7c0a7b283d 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java @@ -24,7 +24,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.codegen.context.*; import org.jetbrains.jet.codegen.signature.JvmMethodSignature; import org.jetbrains.jet.codegen.state.GenerationState; -import org.jetbrains.jet.codegen.state.GenerationStateAware; +import org.jetbrains.jet.codegen.state.JetTypeMapper; import org.jetbrains.jet.descriptors.serialization.descriptors.DeserializedPropertyDescriptor; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; @@ -52,20 +52,14 @@ import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE; import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.PROPERTY_METADATA_TYPE; import static org.jetbrains.org.objectweb.asm.Opcodes.*; -public class PropertyCodegen extends GenerationStateAware { - @NotNull - private final FunctionCodegen functionCodegen; - - @NotNull +public class PropertyCodegen { + private final GenerationState state; private final ClassBuilder v; - - @NotNull + private final FunctionCodegen functionCodegen; + private final JetTypeMapper typeMapper; + private final BindingContext bindingContext; private final FieldOwnerContext context; - - @Nullable private final MemberCodegen classBodyCodegen; - - @NotNull private final OwnerKind kind; public PropertyCodegen( @@ -74,9 +68,11 @@ public class PropertyCodegen extends GenerationStateAware { @NotNull FunctionCodegen functionCodegen, @Nullable MemberCodegen classBodyCodegen ) { - super(functionCodegen.getState()); + this.state = functionCodegen.state; this.v = v; this.functionCodegen = functionCodegen; + this.typeMapper = state.getTypeMapper(); + this.bindingContext = state.getBindingContext(); this.context = context; this.classBodyCodegen = classBodyCodegen; this.kind = context.getContextKind(); @@ -130,13 +126,13 @@ public class PropertyCodegen extends GenerationStateAware { } public void generateConstructorPropertyAsMethodForAnnotationClass(JetParameter p, PropertyDescriptor descriptor) { - Type type = state.getTypeMapper().mapType(descriptor); + Type type = typeMapper.mapType(descriptor); String name = p.getName(); assert name != null : "Annotation parameter has no name: " + p.getText(); MethodVisitor visitor = v.newMethod(p, ACC_PUBLIC | ACC_ABSTRACT, name, "()" + type.getDescriptor(), null, null); JetExpression defaultValue = p.getDefaultValue(); if (defaultValue != null) { - CompileTimeConstant constant = ExpressionCodegen.getCompileTimeConstant(defaultValue, state.getBindingContext()); + CompileTimeConstant constant = ExpressionCodegen.getCompileTimeConstant(defaultValue, bindingContext); assert constant != null : "Default value for annotation parameter should be compile time value: " + defaultValue.getText(); AnnotationCodegen annotationCodegen = AnnotationCodegen.forAnnotationDefaultValue(visitor, typeMapper); annotationCodegen.generateAnnotationDefaultValue(constant, descriptor.getType()); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java b/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java index 01722da13b9..1e56e48b771 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java @@ -133,8 +133,7 @@ public class GenerationState { this.typeMapper = new JetTypeMapper(this.bindingContext, classBuilderMode); this.intrinsics = new IntrinsicMethods(); - this.classFileFactory = new ClassFileFactory(this); - this.classFileFactory.setBuilderFactory(builderFactory); + this.classFileFactory = new ClassFileFactory(this, builderFactory); this.generateNotNullAssertions = generateNotNullAssertions; this.generateNotNullParamAssertions = generateNotNullParamAssertions; diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationStateAware.java b/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationStateAware.java deleted file mode 100644 index 34d163d5781..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationStateAware.java +++ /dev/null @@ -1,37 +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.lang.resolve.BindingContext; - -public class GenerationStateAware { - protected final GenerationState state; - protected final JetTypeMapper typeMapper; - protected final BindingContext bindingContext; - - public GenerationStateAware(@NotNull GenerationState state) { - this.state = state; - this.typeMapper = state.getTypeMapper(); - this.bindingContext = state.getBindingContext(); - } - - @NotNull - public GenerationState getState() { - return state; - } -}