Simplify closure analysis within constructors

Using of ConstructorContext instance almost has no sense,
but it complicates logic when there are several constructors.
This commit is contained in:
Denis Zharkov
2015-02-24 18:42:50 +03:00
parent 31be68de0a
commit 6779e95767
@@ -372,6 +372,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
DelegationFieldsInfo delegationFieldsInfo = getDelegationFieldsInfo(myClass.getDelegationSpecifiers()); DelegationFieldsInfo delegationFieldsInfo = getDelegationFieldsInfo(myClass.getDelegationSpecifiers());
try { try {
lookupConstructorExpressionsInClosureIfPresent();
generatePrimaryConstructor(delegationFieldsInfo); generatePrimaryConstructor(delegationFieldsInfo);
} }
catch (CompilationException e) { catch (CompilationException e) {
@@ -1076,10 +1077,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
ConstructorContext constructorContext = context.intoConstructor(constructorDescriptor); ConstructorContext constructorContext = context.intoConstructor(constructorDescriptor);
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
lookupConstructorExpressionsInClosureIfPresent(constructorContext);
}
functionCodegen.generateMethod(OtherOrigin(myClass, constructorDescriptor), constructorDescriptor, constructorContext, functionCodegen.generateMethod(OtherOrigin(myClass, constructorDescriptor), constructorDescriptor, constructorContext,
new FunctionGenerationStrategy.CodegenBased<ConstructorDescriptor>(state, constructorDescriptor) { new FunctionGenerationStrategy.CodegenBased<ConstructorDescriptor>(state, constructorDescriptor) {
@Override @Override
@@ -1256,7 +1253,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
} }
} }
private void lookupConstructorExpressionsInClosureIfPresent(final ConstructorContext constructorContext) { private void lookupConstructorExpressionsInClosureIfPresent() {
if (state.getClassBuilderMode() != ClassBuilderMode.FULL || descriptor.getConstructors().isEmpty()) return;
JetVisitorVoid visitor = new JetVisitorVoid() { JetVisitorVoid visitor = new JetVisitorVoid() {
@Override @Override
public void visitJetElement(@NotNull JetElement e) { public void visitJetElement(@NotNull JetElement e) {
@@ -1275,15 +1274,16 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
toLookup = descriptor.getContainingDeclaration(); toLookup = descriptor.getContainingDeclaration();
} }
else if (descriptor instanceof VariableDescriptor) { else if (descriptor instanceof VariableDescriptor) {
ConstructorDescriptor constructorDescriptor = (ConstructorDescriptor) constructorContext.getContextDescriptor(); if (descriptor.getContainingDeclaration() instanceof ConstructorDescriptor) {
for (ValueParameterDescriptor parameterDescriptor : constructorDescriptor.getValueParameters()) { ClassDescriptor classDescriptor =
if (descriptor.equals(parameterDescriptor)) return; (ClassDescriptor) descriptor.getContainingDeclaration().getContainingDeclaration();
if (classDescriptor == ImplementationBodyCodegen.this.descriptor) return;
} }
toLookup = descriptor; toLookup = descriptor;
} }
else return; else return;
constructorContext.lookupInContext(toLookup, StackValue.LOCAL_0, state, true); context.lookupInContext(toLookup, StackValue.LOCAL_0, state, true);
} }
@Override @Override
@@ -1296,7 +1296,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
} }
if (descriptor instanceof CallableDescriptor) { if (descriptor instanceof CallableDescriptor) {
constructorContext.generateReceiver((CallableDescriptor) descriptor, state, true); ReceiverParameterDescriptor parameter = ((CallableDescriptor) descriptor).getExtensionReceiverParameter();
if (parameter != null) {
context.lookupInContext(parameter, StackValue.LOCAL_0, state, true);
}
} }
} }
}; };
@@ -1326,7 +1329,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
ClassDescriptor superClass = DescriptorUtilPackage.getSuperClassNotAny(descriptor); ClassDescriptor superClass = DescriptorUtilPackage.getSuperClassNotAny(descriptor);
if (superClass != null) { if (superClass != null) {
if (superClass.isInner()) { if (superClass.isInner()) {
constructorContext.lookupInContext(superClass.getContainingDeclaration(), StackValue.LOCAL_0, state, true); context.lookupInContext(superClass.getContainingDeclaration(), StackValue.LOCAL_0, state, true);
} }
if (!isAnonymousObject(descriptor)) { if (!isAnonymousObject(descriptor)) {