Create and store necessary codegens in MemberCodegen
This commit is contained in:
@@ -54,9 +54,6 @@ public abstract class ClassBodyCodegen extends MemberCodegen<JetClassOrObject> {
|
||||
|
||||
@Override
|
||||
protected void generateBody() {
|
||||
FunctionCodegen functionCodegen = new FunctionCodegen(context, v, state, this);
|
||||
PropertyCodegen propertyCodegen = new PropertyCodegen(context, v, functionCodegen, this);
|
||||
|
||||
if (kind != OwnerKind.TRAIT_IMPL) {
|
||||
//generate nested classes first and only then generate class body. It necessary to access to nested CodegenContexts
|
||||
for (JetDeclaration declaration : myClass.getDeclarations()) {
|
||||
@@ -93,7 +90,7 @@ public abstract class ClassBodyCodegen extends MemberCodegen<JetClassOrObject> {
|
||||
|
||||
protected void generateDeclaration(PropertyCodegen propertyCodegen, JetDeclaration declaration) {
|
||||
if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) {
|
||||
genFunctionOrProperty(declaration, v);
|
||||
genFunctionOrProperty(declaration);
|
||||
}
|
||||
else if (declaration instanceof JetClassOrObject) {
|
||||
if (declaration instanceof JetEnumEntry && !enumEntryNeedSubclass(state.getBindingContext(), (JetEnumEntry) declaration)) {
|
||||
|
||||
@@ -81,9 +81,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
private JetType superClassType;
|
||||
private final Type classAsmType;
|
||||
|
||||
private final FunctionCodegen functionCodegen;
|
||||
private final PropertyCodegen propertyCodegen;
|
||||
|
||||
private List<PropertyAndDefaultValue> classObjectPropertiesToCopy;
|
||||
|
||||
public ImplementationBodyCodegen(
|
||||
@@ -95,8 +92,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
) {
|
||||
super(aClass, context, v, state, parentCodegen);
|
||||
this.classAsmType = typeMapper.mapClass(descriptor);
|
||||
this.functionCodegen = new FunctionCodegen(context, v, state, this);
|
||||
this.propertyCodegen = new PropertyCodegen(context, v, this.functionCodegen, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -59,8 +59,10 @@ public abstract class MemberCodegen<T extends JetElement/* TODO: & JetDeclaratio
|
||||
protected final T element;
|
||||
protected final FieldOwnerContext context;
|
||||
protected final ClassBuilder v;
|
||||
protected ExpressionCodegen clInit;
|
||||
protected final FunctionCodegen functionCodegen;
|
||||
protected final PropertyCodegen propertyCodegen;
|
||||
|
||||
protected ExpressionCodegen clInit;
|
||||
private NameGenerator inlineNameGenerator;
|
||||
|
||||
public MemberCodegen(
|
||||
@@ -68,12 +70,14 @@ public abstract class MemberCodegen<T extends JetElement/* TODO: & JetDeclaratio
|
||||
@Nullable MemberCodegen<?> parentCodegen,
|
||||
@NotNull FieldOwnerContext context,
|
||||
T element,
|
||||
ClassBuilder builder
|
||||
@NotNull ClassBuilder builder
|
||||
) {
|
||||
super(state, parentCodegen);
|
||||
this.element = element;
|
||||
this.context = context;
|
||||
this.v = builder;
|
||||
this.functionCodegen = new FunctionCodegen(context, v, state, this);
|
||||
this.propertyCodegen = new PropertyCodegen(context, v, functionCodegen, this);
|
||||
}
|
||||
|
||||
public void generate() {
|
||||
@@ -106,8 +110,7 @@ public abstract class MemberCodegen<T extends JetElement/* TODO: & JetDeclaratio
|
||||
v.done();
|
||||
}
|
||||
|
||||
public void genFunctionOrProperty(@NotNull JetDeclaration functionOrProperty, @NotNull ClassBuilder classBuilder) {
|
||||
FunctionCodegen functionCodegen = new FunctionCodegen(context, classBuilder, state, this);
|
||||
public void genFunctionOrProperty(@NotNull JetDeclaration functionOrProperty) {
|
||||
if (functionOrProperty instanceof JetNamedFunction) {
|
||||
try {
|
||||
functionCodegen.gen((JetNamedFunction) functionOrProperty);
|
||||
@@ -124,7 +127,7 @@ public abstract class MemberCodegen<T extends JetElement/* TODO: & JetDeclaratio
|
||||
}
|
||||
else if (functionOrProperty instanceof JetProperty) {
|
||||
try {
|
||||
new PropertyCodegen(context, classBuilder, functionCodegen, this).gen((JetProperty) functionOrProperty);
|
||||
propertyCodegen.gen((JetProperty) functionOrProperty);
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
throw e;
|
||||
|
||||
@@ -145,30 +145,30 @@ public class PackageCodegen {
|
||||
public void run() {
|
||||
FieldOwnerContext context = CodegenContext.STATIC.intoPackageFacade(
|
||||
Type.getObjectType(getPackagePartInternalName(member)),
|
||||
compiledPackageFragment);
|
||||
compiledPackageFragment
|
||||
);
|
||||
|
||||
FunctionCodegen functionCodegen = new FunctionCodegen(context, v, state, getMemberCodegen(context));
|
||||
MemberCodegen<?> memberCodegen = createCodegenForPartOfPackageFacade(context);
|
||||
|
||||
if (member instanceof DeserializedSimpleFunctionDescriptor) {
|
||||
DeserializedSimpleFunctionDescriptor function = (DeserializedSimpleFunctionDescriptor) member;
|
||||
JvmMethodSignature signature = state.getTypeMapper().mapSignature(function, OwnerKind.PACKAGE);
|
||||
functionCodegen.generateMethod(null, signature, function,
|
||||
new FunctionGenerationStrategy() {
|
||||
@Override
|
||||
public void generateBody(
|
||||
@NotNull MethodVisitor mv,
|
||||
@NotNull JvmMethodSignature signature,
|
||||
@NotNull MethodContext context,
|
||||
@NotNull MemberCodegen<?> parentCodegen
|
||||
) {
|
||||
throw new IllegalStateException("shouldn't be called");
|
||||
}
|
||||
}
|
||||
memberCodegen.functionCodegen.generateMethod(null, signature, function,
|
||||
new FunctionGenerationStrategy() {
|
||||
@Override
|
||||
public void generateBody(
|
||||
@NotNull MethodVisitor mv,
|
||||
@NotNull JvmMethodSignature signature,
|
||||
@NotNull MethodContext context,
|
||||
@NotNull MemberCodegen<?> parentCodegen
|
||||
) {
|
||||
throw new IllegalStateException("shouldn't be called");
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
else if (member instanceof DeserializedPropertyDescriptor) {
|
||||
PropertyCodegen propertyCodegen = new PropertyCodegen(context, v, functionCodegen, getMemberCodegen(context));
|
||||
propertyCodegen.generateInPackageFacade((DeserializedPropertyDescriptor) member);
|
||||
memberCodegen.propertyCodegen.generateInPackageFacade((DeserializedPropertyDescriptor) member);
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Unexpected member: " + member);
|
||||
@@ -276,7 +276,7 @@ public class PackageCodegen {
|
||||
|
||||
FieldOwnerContext packageFacade = CodegenContext.STATIC.intoPackageFacade(packagePartType, packageFragment);
|
||||
|
||||
final MemberCodegen<?> memberCodegen = getMemberCodegen(packageFacade);
|
||||
final MemberCodegen<?> memberCodegen = createCodegenForPartOfPackageFacade(packageFacade);
|
||||
|
||||
for (final JetDeclaration declaration : file.getDeclarations()) {
|
||||
if (declaration instanceof JetNamedFunction || declaration instanceof JetProperty) {
|
||||
@@ -288,7 +288,7 @@ public class PackageCodegen {
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
memberCodegen.genFunctionOrProperty(declaration, v);
|
||||
memberCodegen.genFunctionOrProperty(declaration);
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -298,8 +298,8 @@ public class PackageCodegen {
|
||||
return builder;
|
||||
}
|
||||
|
||||
private MemberCodegen<?> getMemberCodegen(@NotNull FieldOwnerContext packageFacade) {
|
||||
return new MemberCodegen<JetFile>(state, null, packageFacade, null, null) {
|
||||
private MemberCodegen<?> createCodegenForPartOfPackageFacade(@NotNull FieldOwnerContext packageFacade) {
|
||||
return new MemberCodegen<JetFile>(state, null, packageFacade, null, v) {
|
||||
@Override
|
||||
protected void generateDeclaration() {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
@@ -61,7 +61,7 @@ public class PackagePartCodegen extends MemberCodegen<JetFile> {
|
||||
protected void generateBody() {
|
||||
for (JetDeclaration declaration : element.getDeclarations()) {
|
||||
if (declaration instanceof JetNamedFunction || declaration instanceof JetProperty) {
|
||||
genFunctionOrProperty(declaration, v);
|
||||
genFunctionOrProperty(declaration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ public class ScriptCodegen extends MemberCodegen<JetScript> {
|
||||
|
||||
@Override
|
||||
protected void generateBody() {
|
||||
genMembers(v);
|
||||
genMembers();
|
||||
genFieldsForParameters(scriptDescriptor, v);
|
||||
genConstructor(scriptDescriptor, context.getContextDescriptor(), v,
|
||||
context.intoFunction(scriptDescriptor.getScriptCodeDescriptor()));
|
||||
@@ -205,9 +205,9 @@ public class ScriptCodegen extends MemberCodegen<JetScript> {
|
||||
}
|
||||
}
|
||||
|
||||
private void genMembers(@NotNull ClassBuilder classBuilder) {
|
||||
private void genMembers() {
|
||||
for (JetDeclaration declaration : scriptDeclaration.getDeclarations()) {
|
||||
genFunctionOrProperty(declaration, classBuilder);
|
||||
genFunctionOrProperty(declaration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user