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)
.build();
public static final String RECEIVER$0 = "receiver$0";
public static final String THIS$0 = "this$0";
public static final String CAPTURED_RECEIVER_FIELD = "receiver$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_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 int access = ACC_PUBLIC | ACC_SYNTHETIC | ACC_FINAL;
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);
}
final ClassifierDescriptor captureReceiver = closure.getCaptureReceiver();
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);
}
@@ -247,11 +247,11 @@ public class ClosureCodegen extends GenerationStateAware {
final ClassDescriptor captureThis = closure.getCaptureThis();
if (captureThis != null) {
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();
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()) {
@@ -837,7 +837,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
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 JvmMethodSignature constructorMethod = callableMethod.getSignature();
@@ -859,14 +859,14 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
AnnotationCodegen.forMethod(mv, typeMapper).genAnnotations(constructorDescriptor);
writeParameterAnnotations(constructorDescriptor, constructorMethod, hasThis0, mv);
writeParameterAnnotations(constructorDescriptor, constructorMethod, hasCapturedThis, mv);
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
genStubCode(mv);
return;
}
generatePrimaryConstructorImpl(constructorDescriptor, constructorContext, constructorMethod, callableMethod, hasThis0, closure, mv);
generatePrimaryConstructorImpl(constructorDescriptor, constructorContext, constructorMethod, callableMethod, hasCapturedThis, closure, mv);
}
private void generatePrimaryConstructorImpl(
@@ -874,7 +874,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
ConstructorContext constructorContext,
JvmMethodSignature constructorMethod,
CallableMethod callableMethod,
boolean hasThis0,
boolean hasCapturedThis,
MutableClosure closure,
MethodVisitor mv
) {
@@ -901,24 +901,24 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
generateDelegatorToConstructorCall(iv, codegen, constructorDescriptor, frameMap);
}
if (hasThis0) {
if (hasCapturedThis) {
final Type type = typeMapper
.mapType(enclosingClassDescriptor(bindingContext, descriptor));
String interfaceDesc = type.getDescriptor();
iv.load(0, classAsmType);
iv.load(frameMap.getOuterThisIndex(), type);
iv.putfield(classname.getInternalName(), THIS$0, interfaceDesc);
iv.putfield(classname.getInternalName(), CAPTURED_THIS_FIELD, interfaceDesc);
}
if (closure != null) {
int k = hasThis0 ? 2 : 1;
int k = hasCapturedThis ? 2 : 1;
final String internalName = typeMapper.mapType(descriptor).getInternalName();
final ClassifierDescriptor captureReceiver = closure.getCaptureReceiver();
if (captureReceiver != null) {
iv.load(0, OBJECT_TYPE);
final Type asmType = typeMapper.mapType(captureReceiver.getDefaultType(), JetTypeMapperMode.IMPL);
iv.load(1, asmType);
iv.putfield(internalName, RECEIVER$0, asmType.getDescriptor());
iv.putfield(internalName, CAPTURED_RECEIVER_FIELD, asmType.getDescriptor());
k += asmType.getSize();
}
@@ -31,7 +31,7 @@ import java.util.Collections;
import java.util.HashMap;
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.FQN;
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
@@ -262,7 +262,8 @@ public abstract class CodegenContext {
final ClassDescriptor enclosingClass = getEnclosingClass();
outerExpression = enclosingClass != null
? 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)
: 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.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.isLocalNamedFun;
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.callableDescriptorToDeclaration;
@@ -122,7 +122,7 @@ public interface LocalLookup {
final JetType receiverType = ((CallableDescriptor) d).getReceiverParameter().getType();
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();
return innerValue;