ClassBodyCodegen & PropertyCodegen extend GenerationStateAware

This commit is contained in:
Alex Tkachman
2012-08-30 12:24:56 +03:00
parent 7bd88f5031
commit df094a4cd0
5 changed files with 11 additions and 16 deletions
@@ -21,6 +21,7 @@ import org.jetbrains.asm4.Type;
import org.jetbrains.asm4.commons.InstructionAdapter; import org.jetbrains.asm4.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.context.CodegenContext; import org.jetbrains.jet.codegen.context.CodegenContext;
import org.jetbrains.jet.codegen.state.GenerationState; 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.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
@@ -39,9 +40,7 @@ import static org.jetbrains.jet.codegen.CodegenUtil.getVisibilityAccessFlag;
* @author max * @author max
* @author yole * @author yole
*/ */
public abstract class ClassBodyCodegen { public abstract class ClassBodyCodegen extends GenerationStateAware {
protected final GenerationState state;
protected final JetClassOrObject myClass; protected final JetClassOrObject myClass;
protected final OwnerKind kind; protected final OwnerKind kind;
protected final ClassDescriptor descriptor; protected final ClassDescriptor descriptor;
@@ -51,7 +50,7 @@ public abstract class ClassBodyCodegen {
protected final List<CodeChunk> staticInitializerChunks = new ArrayList<CodeChunk>(); protected final List<CodeChunk> staticInitializerChunks = new ArrayList<CodeChunk>();
protected ClassBodyCodegen(JetClassOrObject aClass, CodegenContext context, ClassBuilder v, GenerationState state) { protected ClassBodyCodegen(JetClassOrObject aClass, CodegenContext context, ClassBuilder v, GenerationState state) {
this.state = state; super(state);
descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass); descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass);
myClass = aClass; myClass = aClass;
this.context = context; this.context = context;
@@ -78,7 +77,7 @@ public abstract class ClassBodyCodegen {
private void generateClassBody() { private void generateClassBody() {
final FunctionCodegen functionCodegen = new FunctionCodegen(context, v, state); final FunctionCodegen functionCodegen = new FunctionCodegen(context, v, state);
final PropertyCodegen propertyCodegen = new PropertyCodegen(context, v, functionCodegen, state); final PropertyCodegen propertyCodegen = new PropertyCodegen(context, v, functionCodegen);
for (JetDeclaration declaration : myClass.getDeclarations()) { for (JetDeclaration declaration : myClass.getDeclarations()) {
generateDeclaration(propertyCodegen, declaration, functionCodegen); generateDeclaration(propertyCodegen, declaration, functionCodegen);
@@ -71,13 +71,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
private String superClass; private String superClass;
@Nullable // null means java/lang/Object @Nullable // null means java/lang/Object
private JetType superClassType; private JetType superClassType;
private final JetTypeMapper typeMapper;
private final BindingContext bindingContext;
public ImplementationBodyCodegen(JetClassOrObject aClass, CodegenContext context, ClassBuilder v, GenerationState state) { public ImplementationBodyCodegen(JetClassOrObject aClass, CodegenContext context, ClassBuilder v, GenerationState state) {
super(aClass, context, v, state); super(aClass, context, v, state);
typeMapper = state.getTypeMapper();
bindingContext = state.getBindingContext();
} }
@Override @Override
@@ -1213,7 +1209,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
protected void generateDelegates(ClassDescriptor toClass, CodegenContext delegateContext, StackValue field) { protected void generateDelegates(ClassDescriptor toClass, CodegenContext delegateContext, StackValue field) {
final FunctionCodegen functionCodegen = new FunctionCodegen(delegateContext, v, state); final FunctionCodegen functionCodegen = new FunctionCodegen(delegateContext, v, state);
final PropertyCodegen propertyCodegen = new PropertyCodegen(delegateContext, v, functionCodegen, state); final PropertyCodegen propertyCodegen = new PropertyCodegen(delegateContext, v, functionCodegen);
for (DeclarationDescriptor declaration : descriptor.getDefaultType().getMemberScope().getAllDescriptors()) { for (DeclarationDescriptor declaration : descriptor.getDefaultType().getMemberScope().getAllDescriptors()) {
if (declaration instanceof CallableMemberDescriptor) { if (declaration instanceof CallableMemberDescriptor) {
@@ -53,7 +53,7 @@ public class MemberCodegen extends GenerationStateAware {
} }
else if (functionOrProperty instanceof JetProperty) { else if (functionOrProperty instanceof JetProperty) {
try { try {
new PropertyCodegen(context, classBuilder, functionCodegen, state).gen((JetProperty) functionOrProperty); new PropertyCodegen(context, classBuilder, functionCodegen).gen((JetProperty) functionOrProperty);
} }
catch (CompilationException e) { catch (CompilationException e) {
throw e; throw e;
@@ -27,6 +27,7 @@ import org.jetbrains.jet.codegen.context.CodegenContext;
import org.jetbrains.jet.codegen.signature.JvmPropertyAccessorSignature; import org.jetbrains.jet.codegen.signature.JvmPropertyAccessorSignature;
import org.jetbrains.jet.codegen.signature.kotlin.JetMethodAnnotationWriter; import org.jetbrains.jet.codegen.signature.kotlin.JetMethodAnnotationWriter;
import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.GenerationStateAware;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -48,16 +49,15 @@ import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDec
* @author max * @author max
* @author alex.tkachman * @author alex.tkachman
*/ */
public class PropertyCodegen { public class PropertyCodegen extends GenerationStateAware {
private final GenerationState state;
private final FunctionCodegen functionCodegen; private final FunctionCodegen functionCodegen;
private final ClassBuilder v; private final ClassBuilder v;
private final OwnerKind kind; private final OwnerKind kind;
public PropertyCodegen(CodegenContext context, ClassBuilder v, FunctionCodegen functionCodegen, GenerationState state) { public PropertyCodegen(CodegenContext context, ClassBuilder v, FunctionCodegen functionCodegen) {
super(functionCodegen.getState());
this.v = v; this.v = v;
this.functionCodegen = functionCodegen; this.functionCodegen = functionCodegen;
this.state = state;
this.kind = context.getContextKind(); this.kind = context.getContextKind();
} }
@@ -47,6 +47,6 @@ public class TraitImplBodyCodegen extends ClassBodyCodegen {
} }
private String jvmName() { private String jvmName() {
return state.getTypeMapper().mapType(descriptor.getDefaultType(), MapTypeMode.TRAIT_IMPL).getInternalName(); return typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.TRAIT_IMPL).getInternalName();
} }
} }