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.jet.codegen.context.CodegenContext;
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.PropertyDescriptor;
import org.jetbrains.jet.lang.psi.*;
@@ -39,9 +40,7 @@ import static org.jetbrains.jet.codegen.CodegenUtil.getVisibilityAccessFlag;
* @author max
* @author yole
*/
public abstract class ClassBodyCodegen {
protected final GenerationState state;
public abstract class ClassBodyCodegen extends GenerationStateAware {
protected final JetClassOrObject myClass;
protected final OwnerKind kind;
protected final ClassDescriptor descriptor;
@@ -51,7 +50,7 @@ public abstract class ClassBodyCodegen {
protected final List<CodeChunk> staticInitializerChunks = new ArrayList<CodeChunk>();
protected ClassBodyCodegen(JetClassOrObject aClass, CodegenContext context, ClassBuilder v, GenerationState state) {
this.state = state;
super(state);
descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass);
myClass = aClass;
this.context = context;
@@ -78,7 +77,7 @@ public abstract class ClassBodyCodegen {
private void generateClassBody() {
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()) {
generateDeclaration(propertyCodegen, declaration, functionCodegen);
@@ -71,13 +71,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
private String superClass;
@Nullable // null means java/lang/Object
private JetType superClassType;
private final JetTypeMapper typeMapper;
private final BindingContext bindingContext;
public ImplementationBodyCodegen(JetClassOrObject aClass, CodegenContext context, ClassBuilder v, GenerationState state) {
super(aClass, context, v, state);
typeMapper = state.getTypeMapper();
bindingContext = state.getBindingContext();
}
@Override
@@ -1213,7 +1209,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
protected void generateDelegates(ClassDescriptor toClass, CodegenContext delegateContext, StackValue field) {
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()) {
if (declaration instanceof CallableMemberDescriptor) {
@@ -53,7 +53,7 @@ public class MemberCodegen extends GenerationStateAware {
}
else if (functionOrProperty instanceof JetProperty) {
try {
new PropertyCodegen(context, classBuilder, functionCodegen, state).gen((JetProperty) functionOrProperty);
new PropertyCodegen(context, classBuilder, functionCodegen).gen((JetProperty) functionOrProperty);
}
catch (CompilationException 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.kotlin.JetMethodAnnotationWriter;
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.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -48,16 +49,15 @@ import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDec
* @author max
* @author alex.tkachman
*/
public class PropertyCodegen {
private final GenerationState state;
public class PropertyCodegen extends GenerationStateAware {
private final FunctionCodegen functionCodegen;
private final ClassBuilder v;
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.functionCodegen = functionCodegen;
this.state = state;
this.kind = context.getContextKind();
}
@@ -47,6 +47,6 @@ public class TraitImplBodyCodegen extends ClassBodyCodegen {
}
private String jvmName() {
return state.getTypeMapper().mapType(descriptor.getDefaultType(), MapTypeMode.TRAIT_IMPL).getInternalName();
return typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.TRAIT_IMPL).getInternalName();
}
}