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());
try {
lookupConstructorExpressionsInClosureIfPresent();
generatePrimaryConstructor(delegationFieldsInfo);
}
catch (CompilationException e) {
@@ -1076,10 +1077,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
ConstructorContext constructorContext = context.intoConstructor(constructorDescriptor);
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
lookupConstructorExpressionsInClosureIfPresent(constructorContext);
}
functionCodegen.generateMethod(OtherOrigin(myClass, constructorDescriptor), constructorDescriptor, constructorContext,
new FunctionGenerationStrategy.CodegenBased<ConstructorDescriptor>(state, constructorDescriptor) {
@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() {
@Override
public void visitJetElement(@NotNull JetElement e) {
@@ -1275,15 +1274,16 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
toLookup = descriptor.getContainingDeclaration();
}
else if (descriptor instanceof VariableDescriptor) {
ConstructorDescriptor constructorDescriptor = (ConstructorDescriptor) constructorContext.getContextDescriptor();
for (ValueParameterDescriptor parameterDescriptor : constructorDescriptor.getValueParameters()) {
if (descriptor.equals(parameterDescriptor)) return;
if (descriptor.getContainingDeclaration() instanceof ConstructorDescriptor) {
ClassDescriptor classDescriptor =
(ClassDescriptor) descriptor.getContainingDeclaration().getContainingDeclaration();
if (classDescriptor == ImplementationBodyCodegen.this.descriptor) return;
}
toLookup = descriptor;
}
else return;
constructorContext.lookupInContext(toLookup, StackValue.LOCAL_0, state, true);
context.lookupInContext(toLookup, StackValue.LOCAL_0, state, true);
}
@Override
@@ -1296,7 +1296,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
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);
if (superClass != null) {
if (superClass.isInner()) {
constructorContext.lookupInContext(superClass.getContainingDeclaration(), StackValue.LOCAL_0, state, true);
context.lookupInContext(superClass.getContainingDeclaration(), StackValue.LOCAL_0, state, true);
}
if (!isAnonymousObject(descriptor)) {