Better names for THIS$0 and RECEIVER$0 constants.

This commit is contained in:
Evgeny Gerashchenko
2012-10-01 18:37:06 +04:00
parent 3d8b6e758a
commit e4f2fdc5f2
5 changed files with 19 additions and 18 deletions
@@ -72,8 +72,8 @@ public class AsmUtil {
.put(JavaDescriptorResolver.PACKAGE_VISIBILITY, NO_FLAG_PACKAGE_PRIVATE) .put(JavaDescriptorResolver.PACKAGE_VISIBILITY, NO_FLAG_PACKAGE_PRIVATE)
.build(); .build();
public static final String RECEIVER$0 = "receiver$0"; public static final String CAPTURED_RECEIVER_FIELD = "receiver$0";
public static final String THIS$0 = "this$0"; public static final String CAPTURED_THIS_FIELD = "this$0";
private static final String STUB_EXCEPTION = "java/lang/RuntimeException"; private static final String STUB_EXCEPTION = "java/lang/RuntimeException";
private static final String STUB_EXCEPTION_MESSAGE = "Stubs are for compiler only, do not add them to runtime classpath"; private static final String STUB_EXCEPTION_MESSAGE = "Stubs are for compiler only, do not add them to runtime classpath";
@@ -201,13 +201,13 @@ public class AsmUtil {
final ClassifierDescriptor captureThis = closure.getCaptureThis(); final ClassifierDescriptor captureThis = closure.getCaptureThis();
final int access = ACC_PUBLIC | ACC_SYNTHETIC | ACC_FINAL; final int access = ACC_PUBLIC | ACC_SYNTHETIC | ACC_FINAL;
if (captureThis != null) { if (captureThis != null) {
v.newField(null, access, THIS$0, typeMapper.mapType(captureThis).getDescriptor(), null, v.newField(null, access, CAPTURED_THIS_FIELD, typeMapper.mapType(captureThis).getDescriptor(), null,
null); null);
} }
final ClassifierDescriptor captureReceiver = closure.getCaptureReceiver(); final ClassifierDescriptor captureReceiver = closure.getCaptureReceiver();
if (captureReceiver != null) { if (captureReceiver != null) {
v.newField(null, access, RECEIVER$0, typeMapper.mapType(captureReceiver).getDescriptor(), v.newField(null, access, CAPTURED_RECEIVER_FIELD, typeMapper.mapType(captureReceiver).getDescriptor(),
null, null); null, null);
} }
@@ -247,11 +247,11 @@ public class ClosureCodegen extends GenerationStateAware {
final ClassDescriptor captureThis = closure.getCaptureThis(); final ClassDescriptor captureThis = closure.getCaptureThis();
if (captureThis != null) { if (captureThis != null) {
final Type type = typeMapper.mapType(captureThis); final Type type = typeMapper.mapType(captureThis);
args.add(new Pair<String, Type>(THIS$0, type)); args.add(new Pair<String, Type>(CAPTURED_THIS_FIELD, type));
} }
final ClassifierDescriptor captureReceiver = closure.getCaptureReceiver(); final ClassifierDescriptor captureReceiver = closure.getCaptureReceiver();
if (captureReceiver != null) { if (captureReceiver != null) {
args.add(new Pair<String, Type>(RECEIVER$0, typeMapper.mapType(captureReceiver))); args.add(new Pair<String, Type>(CAPTURED_RECEIVER_FIELD, typeMapper.mapType(captureReceiver)));
} }
for (DeclarationDescriptor descriptor : closure.getCaptureVariables().keySet()) { for (DeclarationDescriptor descriptor : closure.getCaptureVariables().keySet()) {
@@ -837,7 +837,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
} }
MutableClosure closure = context.closure; MutableClosure closure = context.closure;
boolean hasThis0 = closure != null && closure.getCaptureThis() != null; boolean hasCapturedThis = closure != null && closure.getCaptureThis() != null;
final CallableMethod callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor, context.closure); final CallableMethod callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor, context.closure);
final JvmMethodSignature constructorMethod = callableMethod.getSignature(); final JvmMethodSignature constructorMethod = callableMethod.getSignature();
@@ -859,14 +859,14 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
AnnotationCodegen.forMethod(mv, typeMapper).genAnnotations(constructorDescriptor); AnnotationCodegen.forMethod(mv, typeMapper).genAnnotations(constructorDescriptor);
writeParameterAnnotations(constructorDescriptor, constructorMethod, hasThis0, mv); writeParameterAnnotations(constructorDescriptor, constructorMethod, hasCapturedThis, mv);
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
genStubCode(mv); genStubCode(mv);
return; return;
} }
generatePrimaryConstructorImpl(constructorDescriptor, constructorContext, constructorMethod, callableMethod, hasThis0, closure, mv); generatePrimaryConstructorImpl(constructorDescriptor, constructorContext, constructorMethod, callableMethod, hasCapturedThis, closure, mv);
} }
private void generatePrimaryConstructorImpl( private void generatePrimaryConstructorImpl(
@@ -874,7 +874,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
ConstructorContext constructorContext, ConstructorContext constructorContext,
JvmMethodSignature constructorMethod, JvmMethodSignature constructorMethod,
CallableMethod callableMethod, CallableMethod callableMethod,
boolean hasThis0, boolean hasCapturedThis,
MutableClosure closure, MutableClosure closure,
MethodVisitor mv MethodVisitor mv
) { ) {
@@ -901,24 +901,24 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
generateDelegatorToConstructorCall(iv, codegen, constructorDescriptor, frameMap); generateDelegatorToConstructorCall(iv, codegen, constructorDescriptor, frameMap);
} }
if (hasThis0) { if (hasCapturedThis) {
final Type type = typeMapper final Type type = typeMapper
.mapType(enclosingClassDescriptor(bindingContext, descriptor)); .mapType(enclosingClassDescriptor(bindingContext, descriptor));
String interfaceDesc = type.getDescriptor(); String interfaceDesc = type.getDescriptor();
iv.load(0, classAsmType); iv.load(0, classAsmType);
iv.load(frameMap.getOuterThisIndex(), type); iv.load(frameMap.getOuterThisIndex(), type);
iv.putfield(classname.getInternalName(), THIS$0, interfaceDesc); iv.putfield(classname.getInternalName(), CAPTURED_THIS_FIELD, interfaceDesc);
} }
if (closure != null) { if (closure != null) {
int k = hasThis0 ? 2 : 1; int k = hasCapturedThis ? 2 : 1;
final String internalName = typeMapper.mapType(descriptor).getInternalName(); final String internalName = typeMapper.mapType(descriptor).getInternalName();
final ClassifierDescriptor captureReceiver = closure.getCaptureReceiver(); final ClassifierDescriptor captureReceiver = closure.getCaptureReceiver();
if (captureReceiver != null) { if (captureReceiver != null) {
iv.load(0, OBJECT_TYPE); iv.load(0, OBJECT_TYPE);
final Type asmType = typeMapper.mapType(captureReceiver.getDefaultType(), JetTypeMapperMode.IMPL); final Type asmType = typeMapper.mapType(captureReceiver.getDefaultType(), JetTypeMapperMode.IMPL);
iv.load(1, asmType); iv.load(1, asmType);
iv.putfield(internalName, RECEIVER$0, asmType.getDescriptor()); iv.putfield(internalName, CAPTURED_RECEIVER_FIELD, asmType.getDescriptor());
k += asmType.getSize(); k += asmType.getSize();
} }
@@ -31,7 +31,7 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.jetbrains.jet.codegen.AsmUtil.THIS$0; import static org.jetbrains.jet.codegen.AsmUtil.CAPTURED_THIS_FIELD;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.CLASS_FOR_FUNCTION; import static org.jetbrains.jet.codegen.binding.CodegenBinding.CLASS_FOR_FUNCTION;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.FQN; import static org.jetbrains.jet.codegen.binding.CodegenBinding.FQN;
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE; import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
@@ -262,7 +262,8 @@ public abstract class CodegenContext {
final ClassDescriptor enclosingClass = getEnclosingClass(); final ClassDescriptor enclosingClass = getEnclosingClass();
outerExpression = enclosingClass != null outerExpression = enclosingClass != null
? StackValue ? StackValue
.field(typeMapper.mapType(enclosingClass), CodegenBinding.getJvmInternalName(typeMapper.getBindingTrace(), classDescriptor), THIS$0, .field(typeMapper.mapType(enclosingClass), CodegenBinding.getJvmInternalName(typeMapper.getBindingTrace(), classDescriptor),
CAPTURED_THIS_FIELD,
false) false)
: null; : null;
} }
@@ -26,7 +26,7 @@ import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.lang.resolve.java.JvmClassName; import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import static org.jetbrains.jet.codegen.AsmUtil.RECEIVER$0; import static org.jetbrains.jet.codegen.AsmUtil.CAPTURED_RECEIVER_FIELD;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.classNameForAnonymousClass; import static org.jetbrains.jet.codegen.binding.CodegenBinding.classNameForAnonymousClass;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun; import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun;
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.callableDescriptorToDeclaration; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.callableDescriptorToDeclaration;
@@ -122,7 +122,7 @@ public interface LocalLookup {
final JetType receiverType = ((CallableDescriptor) d).getReceiverParameter().getType(); final JetType receiverType = ((CallableDescriptor) d).getReceiverParameter().getType();
Type type = state.getTypeMapper().mapType(receiverType); Type type = state.getTypeMapper().mapType(receiverType);
StackValue innerValue = StackValue.field(type, className, RECEIVER$0, false); StackValue innerValue = StackValue.field(type, className, CAPTURED_RECEIVER_FIELD, false);
closure.setCaptureReceiver(); closure.setCaptureReceiver();
return innerValue; return innerValue;