Minor refactorings in codegen contexts
Add assertions, nullability annotations, fix formatting, etc.
This commit is contained in:
@@ -145,7 +145,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
||||
|
||||
generateBridgeIfNeeded(owner, state, v, functionDescriptor);
|
||||
|
||||
methodContext.recordSyntheticAccessorIfNeeded(functionDescriptor, typeMapper);
|
||||
methodContext.recordSyntheticAccessorIfNeeded(functionDescriptor, bindingContext);
|
||||
}
|
||||
|
||||
private void generateParameterAnnotations(
|
||||
|
||||
@@ -1157,7 +1157,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
FunctionCodegen.generateConstructorWithoutParametersIfNeeded(state, callableMethod, constructorDescriptor, v);
|
||||
|
||||
if (isClassObject(descriptor)) {
|
||||
context.recordSyntheticAccessorIfNeeded(constructorDescriptor, typeMapper);
|
||||
context.recordSyntheticAccessorIfNeeded(constructorDescriptor, bindingContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
||||
generateGetter(p, propertyDescriptor, p.getGetter());
|
||||
generateSetter(p, propertyDescriptor, p.getSetter());
|
||||
|
||||
context.recordSyntheticAccessorIfNeeded(propertyDescriptor, typeMapper);
|
||||
context.recordSyntheticAccessorIfNeeded(propertyDescriptor, bindingContext);
|
||||
}
|
||||
|
||||
public void generatePrimaryConstructorProperty(JetParameter p, PropertyDescriptor descriptor) {
|
||||
|
||||
@@ -61,7 +61,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
|
||||
public final MutableClosure closure;
|
||||
|
||||
private HashMap<DeclarationDescriptor, DeclarationDescriptor> accessors;
|
||||
private Map<DeclarationDescriptor, DeclarationDescriptor> accessors;
|
||||
|
||||
private Map<DeclarationDescriptor, CodegenContext> childContexts;
|
||||
|
||||
@@ -134,14 +134,15 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
|
||||
private StackValue getOuterExpression(@Nullable StackValue prefix, boolean ignoreNoOuter, boolean captureThis) {
|
||||
if (lazyOuterExpression == null || lazyOuterExpression.invoke() == null) {
|
||||
if (ignoreNoOuter) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException();
|
||||
if (!ignoreNoOuter) {
|
||||
throw new UnsupportedOperationException("Don't know how to generate outer expression for " + getContextDescriptor());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (captureThis) {
|
||||
if (closure == null) {
|
||||
throw new IllegalStateException("Can't capture this for context without closure: " + getContextDescriptor());
|
||||
}
|
||||
closure.setCaptureThis();
|
||||
}
|
||||
return prefix != null ? StackValue.composed(prefix, lazyOuterExpression.invoke()) : lazyOuterExpression.invoke();
|
||||
@@ -173,18 +174,13 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassContext intoAnonymousClass(
|
||||
@NotNull ClassDescriptor descriptor,
|
||||
@NotNull ExpressionCodegen expressionCodegen
|
||||
) {
|
||||
JetTypeMapper typeMapper = expressionCodegen.getState().getTypeMapper();
|
||||
return new AnonymousClassContext(typeMapper, descriptor, OwnerKind.IMPLEMENTATION, this,
|
||||
expressionCodegen);
|
||||
public ClassContext intoAnonymousClass(@NotNull ClassDescriptor descriptor, @NotNull ExpressionCodegen codegen) {
|
||||
return new AnonymousClassContext(codegen.getState().getTypeMapper(), descriptor, OwnerKind.IMPLEMENTATION, this, codegen);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public MethodContext intoFunction(FunctionDescriptor descriptor) {
|
||||
return new MethodContext(descriptor, getContextKind(), this);
|
||||
return new MethodContext(descriptor, getContextKind(), this, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -212,7 +208,8 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
return new ClosureContext(typeMapper, funDescriptor, classDescriptor, this, localLookup);
|
||||
}
|
||||
|
||||
public FrameMap prepareFrame(JetTypeMapper mapper) {
|
||||
@NotNull
|
||||
public FrameMap prepareFrame(@NotNull JetTypeMapper typeMapper) {
|
||||
FrameMap frameMap = new FrameMap();
|
||||
|
||||
if (getContextKind() != OwnerKind.PACKAGE) {
|
||||
@@ -221,7 +218,8 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
|
||||
CallableDescriptor receiverDescriptor = getCallableDescriptorWithReceiver();
|
||||
if (receiverDescriptor != null) {
|
||||
Type type = mapper.mapType(receiverDescriptor.getReceiverParameter().getType());
|
||||
//noinspection ConstantConditions
|
||||
Type type = typeMapper.mapType(receiverDescriptor.getReceiverParameter().getType());
|
||||
frameMap.enterTemp(type); // Next slot for receiver
|
||||
}
|
||||
|
||||
@@ -323,7 +321,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
}
|
||||
|
||||
for (LocalLookup.LocalLookupCase aCase : LocalLookup.LocalLookupCase.values()) {
|
||||
if (aCase.isCase(d, state)) {
|
||||
if (aCase.isCase(d)) {
|
||||
Type classType = state.getBindingContext().get(ASM_TYPE, getThisDescriptor());
|
||||
StackValue innerValue = aCase.innerValue(d, enclosingLocalLookup, state, closure, classType);
|
||||
if (innerValue == null) {
|
||||
@@ -367,27 +365,26 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
return (FunctionDescriptor) accessibleDescriptorIfNeeded(fd, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public void recordSyntheticAccessorIfNeeded(@NotNull FunctionDescriptor fd, @NotNull JetTypeMapper typeMapper) {
|
||||
if (fd instanceof ConstructorDescriptor || needSyntheticAccessorInBindingTrace(fd, typeMapper)) {
|
||||
public void recordSyntheticAccessorIfNeeded(@NotNull FunctionDescriptor fd, @NotNull BindingContext bindingContext) {
|
||||
if (fd instanceof ConstructorDescriptor || needSyntheticAccessorInBindingTrace(fd, bindingContext)) {
|
||||
accessibleDescriptorIfNeeded(fd, false);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public void recordSyntheticAccessorIfNeeded(PropertyDescriptor propertyDescriptor, JetTypeMapper typeMapper) {
|
||||
public void recordSyntheticAccessorIfNeeded(@NotNull PropertyDescriptor propertyDescriptor, @NotNull BindingContext typeMapper) {
|
||||
if (needSyntheticAccessorInBindingTrace(propertyDescriptor, typeMapper)) {
|
||||
accessibleDescriptorIfNeeded(propertyDescriptor, false);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean needSyntheticAccessorInBindingTrace(@NotNull CallableMemberDescriptor descriptor, @NotNull JetTypeMapper typeMapper) {
|
||||
Boolean result = typeMapper.getBindingContext().get(BindingContext.NEED_SYNTHETIC_ACCESSOR, descriptor);
|
||||
return result == null ? false : result.booleanValue();
|
||||
private static boolean needSyntheticAccessorInBindingTrace(
|
||||
@NotNull CallableMemberDescriptor descriptor,
|
||||
@NotNull BindingContext bindingContext
|
||||
) {
|
||||
return Boolean.TRUE.equals(bindingContext.get(BindingContext.NEED_SYNTHETIC_ACCESSOR, descriptor));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private int getAccessFlags(CallableMemberDescriptor descriptor) {
|
||||
private static int getAccessFlags(@NotNull CallableMemberDescriptor descriptor) {
|
||||
int flag = getVisibilityAccessFlag(descriptor);
|
||||
if (descriptor instanceof PropertyDescriptor) {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
||||
|
||||
public class ConstructorContext extends MethodContext {
|
||||
private static final StackValue local1 = StackValue.local(1, OBJECT_TYPE);
|
||||
private static final StackValue LOCAL_1 = StackValue.local(1, OBJECT_TYPE);
|
||||
|
||||
public ConstructorContext(
|
||||
@NotNull ConstructorDescriptor contextDescriptor,
|
||||
@@ -39,16 +39,16 @@ public class ConstructorContext extends MethodContext {
|
||||
|
||||
@Override
|
||||
public StackValue getOuterExpression(StackValue prefix, boolean ignoreNoOuter) {
|
||||
StackValue stackValue = closure != null && closure.getCaptureThis() != null ? local1 : null;
|
||||
StackValue stackValue = closure != null && closure.getCaptureThis() != null ? LOCAL_1 : null;
|
||||
if (!ignoreNoOuter && stackValue == null) {
|
||||
throw new UnsupportedOperationException("Don't know how to generate outer expression for " + getContextDescriptor().getContainingDeclaration());
|
||||
throw new UnsupportedOperationException("Don't know how to generate outer expression for " + getContextDescriptor());
|
||||
}
|
||||
return stackValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Constructor: " + getContextDescriptor().getName();
|
||||
return "Constructor: " + getContextDescriptor();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -48,7 +48,7 @@ public final class EnclosedValueDescriptor {
|
||||
public StackValue getOuterValue(ExpressionCodegen expressionCodegen) {
|
||||
GenerationState state = expressionCodegen.getState();
|
||||
for (LocalLookup.LocalLookupCase aCase : LocalLookup.LocalLookupCase.values()) {
|
||||
if (aCase.isCase(descriptor, state)) {
|
||||
if (aCase.isCase(descriptor)) {
|
||||
return aCase.outerValue(this, expressionCodegen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ public interface LocalLookup {
|
||||
enum LocalLookupCase {
|
||||
VAR {
|
||||
@Override
|
||||
public boolean isCase(DeclarationDescriptor d, GenerationState state) {
|
||||
return (d instanceof VariableDescriptor) && !(d instanceof PropertyDescriptor);
|
||||
public boolean isCase(DeclarationDescriptor d) {
|
||||
return d instanceof VariableDescriptor && !(d instanceof PropertyDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,7 +69,7 @@ public interface LocalLookup {
|
||||
|
||||
LOCAL_NAMED_FUNCTION {
|
||||
@Override
|
||||
public boolean isCase(DeclarationDescriptor d, GenerationState state) {
|
||||
public boolean isCase(DeclarationDescriptor d) {
|
||||
return isLocalNamedFun(d);
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public interface LocalLookup {
|
||||
|
||||
RECEIVER {
|
||||
@Override
|
||||
public boolean isCase(DeclarationDescriptor d, GenerationState state) {
|
||||
public boolean isCase(DeclarationDescriptor d) {
|
||||
return d instanceof CallableDescriptor;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public interface LocalLookup {
|
||||
}
|
||||
};
|
||||
|
||||
public abstract boolean isCase(DeclarationDescriptor d, GenerationState state);
|
||||
public abstract boolean isCase(DeclarationDescriptor d);
|
||||
|
||||
public abstract StackValue innerValue(
|
||||
DeclarationDescriptor d,
|
||||
|
||||
@@ -19,37 +19,29 @@ package org.jetbrains.jet.codegen.context;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.asm4.Label;
|
||||
import org.jetbrains.jet.codegen.binding.MutableClosure;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.codegen.OwnerKind;
|
||||
import org.jetbrains.jet.codegen.StackValue;
|
||||
import org.jetbrains.jet.codegen.binding.MutableClosure;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyAccessorDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
|
||||
public class MethodContext extends CodegenContext {
|
||||
public class MethodContext extends CodegenContext<CallableMemberDescriptor> {
|
||||
|
||||
private Label methodStartLabel;
|
||||
|
||||
public MethodContext(
|
||||
@NotNull FunctionDescriptor contextType,
|
||||
@NotNull OwnerKind contextKind,
|
||||
@NotNull CodegenContext parentContext
|
||||
) {
|
||||
this(contextType, contextKind, parentContext, null);
|
||||
}
|
||||
|
||||
protected MethodContext(
|
||||
@NotNull FunctionDescriptor contextType,
|
||||
@NotNull FunctionDescriptor contextDescriptor,
|
||||
@NotNull OwnerKind contextKind,
|
||||
@NotNull CodegenContext parentContext,
|
||||
@Nullable MutableClosure closure
|
||||
) {
|
||||
super(contextType instanceof PropertyAccessorDescriptor
|
||||
? ((PropertyAccessorDescriptor) contextType).getCorrespondingProperty()
|
||||
: contextType, contextKind, parentContext, closure,
|
||||
super(contextDescriptor instanceof PropertyAccessorDescriptor
|
||||
? ((PropertyAccessorDescriptor) contextDescriptor).getCorrespondingProperty()
|
||||
: contextDescriptor, contextKind, parentContext, closure,
|
||||
parentContext.hasThisDescriptor() ? parentContext.getThisDescriptor() : null, null);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user