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