Remove GenerationStateAware
This commit is contained in:
@@ -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<FqName, PackageCodegen> package2codegen = new HashMap<FqName, PackageCodegen>();
|
||||
private final Map<String, ClassBuilderAndSourceFileList> generators = new LinkedHashMap<String, ClassBuilderAndSourceFileList>();
|
||||
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<JetFile> files;
|
||||
private final PackageFragmentDescriptor packageFragment;
|
||||
private final PackageFragmentDescriptor compiledPackageFragment;
|
||||
@@ -84,8 +81,7 @@ public class PackageCodegen extends GenerationStateAware {
|
||||
@NotNull GenerationState state,
|
||||
@NotNull Collection<JetFile> 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<PackageFragmentDescriptor> fragments = new SmartList<PackageFragmentDescriptor>();
|
||||
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)) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user