JetTypeMapper api cleanup

- mapType got JetTypeMapperMode.VALUE as default parameter
- mapType(ClassifierDescriptor) introduced
- mapType(VariableDescriptor) introduced
This commit is contained in:
Alex Tkachman
2012-09-13 09:22:59 +03:00
parent cf92603f2a
commit ee38d871c4
16 changed files with 99 additions and 102 deletions
@@ -24,7 +24,6 @@ import org.jetbrains.asm4.FieldVisitor;
import org.jetbrains.asm4.MethodVisitor; import org.jetbrains.asm4.MethodVisitor;
import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods; import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods;
import org.jetbrains.jet.codegen.state.JetTypeMapper; import org.jetbrains.jet.codegen.state.JetTypeMapper;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.Annotated; import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
@@ -103,7 +102,7 @@ public abstract class AnnotationCodegen {
return; return;
} }
String internalName = typeMapper.mapType(type, JetTypeMapperMode.VALUE).getDescriptor(); String internalName = typeMapper.mapType(type).getDescriptor();
AnnotationVisitor annotationVisitor = visitAnnotation(internalName, rp == RetentionPolicy.RUNTIME); AnnotationVisitor annotationVisitor = visitAnnotation(internalName, rp == RetentionPolicy.RUNTIME);
getAnnotation(resolvedCall, annotationVisitor); getAnnotation(resolvedCall, annotationVisitor);
@@ -156,8 +155,7 @@ public abstract class AnnotationCodegen {
if (call != null) { if (call != null) {
if (call.getResultingDescriptor() instanceof PropertyDescriptor) { if (call.getResultingDescriptor() instanceof PropertyDescriptor) {
PropertyDescriptor descriptor = (PropertyDescriptor) call.getResultingDescriptor(); PropertyDescriptor descriptor = (PropertyDescriptor) call.getResultingDescriptor();
annotationVisitor.visitEnum(keyName, typeMapper.mapType(descriptor.getReturnType(), JetTypeMapperMode.VALUE).getDescriptor(), annotationVisitor.visitEnum(keyName, typeMapper.mapType(descriptor).getDescriptor(), descriptor.getName().getName());
descriptor.getName().getName());
return; return;
} }
} }
@@ -182,7 +180,7 @@ public abstract class AnnotationCodegen {
if (IntrinsicMethods.KOTLIN_JAVA_CLASS_FUNCTION.equals(value)) { if (IntrinsicMethods.KOTLIN_JAVA_CLASS_FUNCTION.equals(value)) {
//noinspection ConstantConditions //noinspection ConstantConditions
annotationVisitor.visit(keyName, typeMapper annotationVisitor.visit(keyName, typeMapper
.mapType(call.getResultingDescriptor().getReturnType().getArguments().get(0).getType(), JetTypeMapperMode.VALUE)); .mapType(call.getResultingDescriptor().getReturnType().getArguments().get(0).getType()));
return; return;
} }
else if (IntrinsicMethods.KOTLIN_ARRAYS_ARRAY.equals(value)) { else if (IntrinsicMethods.KOTLIN_ARRAYS_ARRAY.equals(value)) {
@@ -197,7 +195,7 @@ public abstract class AnnotationCodegen {
else if (call.getResultingDescriptor() instanceof ConstructorDescriptor) { else if (call.getResultingDescriptor() instanceof ConstructorDescriptor) {
ConstructorDescriptor descriptor = (ConstructorDescriptor) call.getResultingDescriptor(); ConstructorDescriptor descriptor = (ConstructorDescriptor) call.getResultingDescriptor();
AnnotationVisitor visitor = annotationVisitor.visitAnnotation(keyName, typeMapper AnnotationVisitor visitor = annotationVisitor.visitAnnotation(keyName, typeMapper
.mapType(descriptor.getContainingDeclaration().getDefaultType(), JetTypeMapperMode.VALUE).getDescriptor()); .mapType(descriptor.getContainingDeclaration()).getDescriptor());
getAnnotation(call, visitor); getAnnotation(call, visitor);
visitor.visitEnd(); visitor.visitEnd();
return; return;
@@ -22,7 +22,6 @@ import org.jetbrains.asm4.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.context.CodegenContext; import org.jetbrains.jet.codegen.context.CodegenContext;
import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.GenerationStateAware; import org.jetbrains.jet.codegen.state.GenerationStateAware;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
@@ -109,7 +108,7 @@ public abstract class ClassBodyCodegen extends GenerationStateAware {
} }
} }
else { else {
Type type = state.getTypeMapper().mapType(propertyDescriptor.getType(), JetTypeMapperMode.VALUE); Type type = state.getTypeMapper().mapType(propertyDescriptor);
v.newMethod(p, ACC_PUBLIC | ACC_ABSTRACT, p.getName(), "()" + type.getDescriptor(), null, null); v.newMethod(p, ACC_PUBLIC | ACC_ABSTRACT, p.getName(), "()" + type.getDescriptor(), null, null);
} }
} }
@@ -190,15 +190,14 @@ public class ClosureCodegen extends GenerationStateAware {
if (receiver.exists()) { if (receiver.exists()) {
StackValue.local(count, OBJECT_TYPE).put(OBJECT_TYPE, iv); StackValue.local(count, OBJECT_TYPE).put(OBJECT_TYPE, iv);
StackValue.onStack(OBJECT_TYPE) StackValue.onStack(OBJECT_TYPE)
.upcast(typeMapper.mapType(receiver.getType(), JetTypeMapperMode.VALUE), iv); .upcast(typeMapper.mapType(receiver.getType()), iv);
count++; count++;
} }
final List<ValueParameterDescriptor> params = funDescriptor.getValueParameters(); final List<ValueParameterDescriptor> params = funDescriptor.getValueParameters();
for (ValueParameterDescriptor param : params) { for (ValueParameterDescriptor param : params) {
StackValue.local(count, OBJECT_TYPE).put(OBJECT_TYPE, iv); StackValue.local(count, OBJECT_TYPE).put(OBJECT_TYPE, iv);
StackValue.onStack(OBJECT_TYPE) StackValue.onStack(OBJECT_TYPE).upcast(typeMapper.mapType(param.getType()), iv);
.upcast(typeMapper.mapType(param.getType(), JetTypeMapperMode.VALUE), iv);
count++; count++;
} }
@@ -258,13 +257,12 @@ 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.getDefaultType(), JetTypeMapperMode.VALUE); final Type type = typeMapper.mapType(captureThis);
args.add(new Pair<String, Type>(THIS$0, type)); args.add(new Pair<String, Type>(THIS$0, 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, args.add(new Pair<String, Type>(RECEIVER$0, typeMapper.mapType(captureReceiver)));
typeMapper.mapType(captureReceiver.getDefaultType(), JetTypeMapperMode.VALUE)));
} }
for (DeclarationDescriptor descriptor : closure.getCaptureVariables().keySet()) { for (DeclarationDescriptor descriptor : closure.getCaptureVariables().keySet()) {
@@ -273,7 +271,7 @@ public class ClosureCodegen extends GenerationStateAware {
final Type type = sharedVarType != null final Type type = sharedVarType != null
? sharedVarType ? sharedVarType
: typeMapper.mapType(((VariableDescriptor) descriptor).getType(), JetTypeMapperMode.VALUE); : typeMapper.mapType((VariableDescriptor) descriptor);
args.add(new Pair<String, Type>("$" + descriptor.getName().getName(), type)); args.add(new Pair<String, Type>("$" + descriptor.getName().getName(), type));
} }
else if (isLocalNamedFun(state.getBindingContext(), descriptor)) { else if (isLocalNamedFun(state.getBindingContext(), descriptor)) {
@@ -31,7 +31,6 @@ import org.jetbrains.jet.codegen.signature.BothSignatureWriter;
import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind; import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind;
import org.jetbrains.jet.codegen.signature.JvmMethodSignature; import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
import org.jetbrains.jet.codegen.state.JetTypeMapper; import org.jetbrains.jet.codegen.state.JetTypeMapper;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.JetClassObject; import org.jetbrains.jet.lang.psi.JetClassObject;
@@ -216,13 +215,13 @@ public class CodegenUtil {
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.getDefaultType(), JetTypeMapperMode.VALUE).getDescriptor(), null, v.newField(null, access, THIS$0, 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.getDefaultType(), JetTypeMapperMode.VALUE).getDescriptor(), v.newField(null, access, RECEIVER$0, typeMapper.mapType(captureReceiver).getDescriptor(),
null, null); null, null);
} }
@@ -291,7 +291,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
@NotNull @NotNull
private Type asmType(@NotNull JetType type) { private Type asmType(@NotNull JetType type) {
return typeMapper.mapType(type, JetTypeMapperMode.VALUE); return typeMapper.mapType(type);
} }
@NotNull @NotNull
@@ -1118,7 +1118,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
//if (entry.getKey() instanceof VariableDescriptor && !(entry.getKey() instanceof PropertyDescriptor)) { //if (entry.getKey() instanceof VariableDescriptor && !(entry.getKey() instanceof PropertyDescriptor)) {
Type sharedVarType = typeMapper.getSharedVarType(entry.getKey()); Type sharedVarType = typeMapper.getSharedVarType(entry.getKey());
if (sharedVarType == null) { if (sharedVarType == null) {
sharedVarType = typeMapper.mapType(((VariableDescriptor) entry.getKey()).getType(), JetTypeMapperMode.VALUE); sharedVarType = typeMapper.mapType((VariableDescriptor) entry.getKey());
} }
entry.getValue().getOuterValue(this).put(sharedVarType, v); entry.getValue().getOuterValue(this).put(sharedVarType, v);
//} //}
@@ -1400,7 +1400,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
if (declaration instanceof JetClass) { if (declaration instanceof JetClass) {
final ClassDescriptor descriptor1 = ((ClassDescriptor) descriptor).getClassObjectDescriptor(); final ClassDescriptor descriptor1 = ((ClassDescriptor) descriptor).getClassObjectDescriptor();
assert descriptor1 != null; assert descriptor1 != null;
final Type type = typeMapper.mapType(descriptor1.getDefaultType(), JetTypeMapperMode.VALUE); final Type type = typeMapper.mapType(descriptor1);
return StackValue.field(type, return StackValue.field(type,
JvmClassName.byType(typeMapper.mapType(((ClassDescriptor) descriptor).getDefaultType(), JvmClassName.byType(typeMapper.mapType(((ClassDescriptor) descriptor).getDefaultType(),
JetTypeMapperMode.IMPL)), JetTypeMapperMode.IMPL)),
@@ -1450,7 +1450,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
final ClassDescriptor scriptClass = bindingContext.get(CLASS_FOR_FUNCTION, scriptDescriptor); final ClassDescriptor scriptClass = bindingContext.get(CLASS_FOR_FUNCTION, scriptDescriptor);
final StackValue script = StackValue.thisOrOuter(this, scriptClass, false); final StackValue script = StackValue.thisOrOuter(this, scriptClass, false);
script.put(script.type, v); script.put(script.type, v);
Type fieldType = typeMapper.mapType(valueParameterDescriptor.getType(), JetTypeMapperMode.VALUE); Type fieldType = typeMapper.mapType(valueParameterDescriptor);
return StackValue.field(fieldType, scriptClassName, valueParameterDescriptor.getName().getIdentifier(), false); return StackValue.field(fieldType, scriptClassName, valueParameterDescriptor.getName().getIdentifier(), false);
} }
@@ -1462,7 +1462,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
if (isEnumEntry) { if (isEnumEntry) {
ClassDescriptor containing = (ClassDescriptor) variableDescriptor.getContainingDeclaration().getContainingDeclaration(); ClassDescriptor containing = (ClassDescriptor) variableDescriptor.getContainingDeclaration().getContainingDeclaration();
assert containing != null; assert containing != null;
Type type = typeMapper.mapType(containing.getDefaultType(), JetTypeMapperMode.VALUE); Type type = typeMapper.mapType(containing);
return StackValue.field(type, JvmClassName.byType(type), variableDescriptor.getName().getName(), true); return StackValue.field(type, JvmClassName.byType(type), variableDescriptor.getName().getName(), true);
} }
else { else {
@@ -1753,7 +1753,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
} }
JetType type = resolvedCall.getCandidateDescriptor().getReturnType(); JetType type = resolvedCall.getCandidateDescriptor().getReturnType();
assert type != null; assert type != null;
Type callType = typeMapper.mapType(type, JetTypeMapperMode.VALUE); Type callType = typeMapper.mapType(type);
Type exprType = asmTypeOrVoid(type); Type exprType = asmTypeOrVoid(type);
StackValue stackValue = intrinsic.generate(this, v, callType, call.getCallElement(), args, receiver, state); StackValue stackValue = intrinsic.generate(this, v, callType, call.getCallElement(), args, receiver, state);
@@ -1975,7 +1975,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
assert !isSuper; assert !isSuper;
if (context.hasThisDescriptor() && context.getThisDescriptor().equals(calleeContainingClass)) { if (context.hasThisDescriptor() && context.getThisDescriptor().equals(calleeContainingClass)) {
return StackValue.local(0, typeMapper.mapType(calleeContainingClass.getDefaultType(), JetTypeMapperMode.VALUE)); return StackValue.local(0, typeMapper.mapType(calleeContainingClass));
} }
else { else {
return StackValue.singleton(calleeContainingClass, typeMapper); return StackValue.singleton(calleeContainingClass, typeMapper);
@@ -2915,7 +2915,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
//noinspection ConstantConditions //noinspection ConstantConditions
JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression); JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
assert expressionType != null; assert expressionType != null;
type = typeMapper.mapType(expressionType, JetTypeMapperMode.VALUE); type = typeMapper.mapType(expressionType);
if (type.getSort() == Type.ARRAY) { if (type.getSort() == Type.ARRAY) {
generateNewArray(expression, expressionType); generateNewArray(expression, expressionType);
} }
@@ -2987,7 +2987,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
v.newarray(boxType(asmType(arrayType.getArguments().get(0).getType()))); v.newarray(boxType(asmType(arrayType.getArguments().get(0).getType())));
} }
else { else {
Type type = typeMapper.mapType(arrayType, JetTypeMapperMode.VALUE); Type type = typeMapper.mapType(arrayType);
gen(args.get(0), Type.INT_TYPE); gen(args.get(0), Type.INT_TYPE);
v.newarray(correctElementType(type)); v.newarray(correctElementType(type));
} }
@@ -268,7 +268,7 @@ public class FunctionCodegen extends GenerationStateAware {
for (ValueParameterDescriptor parameter : paramDescrs) { for (ValueParameterDescriptor parameter : paramDescrs) {
Type sharedVarType = state.getTypeMapper().getSharedVarType(parameter); Type sharedVarType = state.getTypeMapper().getSharedVarType(parameter);
if (sharedVarType != null) { if (sharedVarType != null) {
Type localVarType = state.getTypeMapper().mapType(parameter.getType(), JetTypeMapperMode.VALUE); Type localVarType = state.getTypeMapper().mapType(parameter);
int index = frameMap.getIndex(parameter); int index = frameMap.getIndex(parameter);
mv.visitTypeInsn(NEW, sharedVarType.getInternalName()); mv.visitTypeInsn(NEW, sharedVarType.getInternalName());
mv.visitInsn(DUP); mv.visitInsn(DUP);
@@ -302,26 +302,25 @@ public class FunctionCodegen extends GenerationStateAware {
int k = 0; int k = 0;
if (expectedThisObject.exists()) { if (expectedThisObject.exists()) {
Type type = state.getTypeMapper().mapType(expectedThisObject.getType(), JetTypeMapperMode.VALUE); Type type = state.getTypeMapper().mapType(expectedThisObject.getType());
// TODO: specify signature // TODO: specify signature
mv.visitLocalVariable("this", type.getDescriptor(), null, methodBegin, methodEnd, k++); mv.visitLocalVariable("this", type.getDescriptor(), null, methodBegin, methodEnd, k++);
} }
else if (fun instanceof JetFunctionLiteralExpression || else if (fun instanceof JetFunctionLiteralExpression ||
isLocalFun(bindingContext, functionDescriptor)) { isLocalFun(bindingContext, functionDescriptor)) {
Type type = state.getTypeMapper().mapType( Type type = state.getTypeMapper().mapType(context.getThisDescriptor());
context.getThisDescriptor().getDefaultType(), JetTypeMapperMode.VALUE);
mv.visitLocalVariable("this", type.getDescriptor(), null, methodBegin, methodEnd, k++); mv.visitLocalVariable("this", type.getDescriptor(), null, methodBegin, methodEnd, k++);
} }
if (receiverParameter.exists()) { if (receiverParameter.exists()) {
Type type = state.getTypeMapper().mapType(receiverParameter.getType(), JetTypeMapperMode.VALUE); Type type = state.getTypeMapper().mapType(receiverParameter.getType());
// TODO: specify signature // TODO: specify signature
mv.visitLocalVariable("this$receiver", type.getDescriptor(), null, methodBegin, methodEnd, k); mv.visitLocalVariable("this$receiver", type.getDescriptor(), null, methodBegin, methodEnd, k);
k += type.getSize(); k += type.getSize();
} }
for (ValueParameterDescriptor parameter : paramDescrs) { for (ValueParameterDescriptor parameter : paramDescrs) {
Type type = state.getTypeMapper().mapType(parameter.getType(), JetTypeMapperMode.VALUE); Type type = state.getTypeMapper().mapType(parameter);
// TODO: specify signature // TODO: specify signature
Label divideLabel = mapLabelsToDivideLocalVarVisibilityForSharedVar.get(parameter.getName()); Label divideLabel = mapLabelsToDivideLocalVarVisibilityForSharedVar.get(parameter.getName());
@@ -515,7 +514,7 @@ public class FunctionCodegen extends GenerationStateAware {
Type receiverType; Type receiverType;
if (hasReceiver) { if (hasReceiver) {
receiverType = state.getTypeMapper().mapType(receiverParameter.getType(), JetTypeMapperMode.VALUE); receiverType = state.getTypeMapper().mapType(receiverParameter.getType());
var += receiverType.getSize(); var += receiverType.getSize();
} }
else { else {
@@ -667,7 +666,7 @@ public class FunctionCodegen extends GenerationStateAware {
} }
iv.invokevirtual(state.getTypeMapper().mapType( iv.invokevirtual(state.getTypeMapper().mapType(
((ClassDescriptor) owner.getContextDescriptor()).getDefaultType(), JetTypeMapperMode.VALUE).getInternalName(), (ClassDescriptor) owner.getContextDescriptor()).getInternalName(),
jvmSignature.getName(), jvmSignature.getDescriptor()); jvmSignature.getName(), jvmSignature.getDescriptor());
if (isPrimitive(jvmSignature.getReturnType()) && !isPrimitive(overridden.getReturnType())) { if (isPrimitive(jvmSignature.getReturnType()) && !isPrimitive(overridden.getReturnType())) {
StackValue.valueOf(iv, jvmSignature.getReturnType()); StackValue.valueOf(iv, jvmSignature.getReturnType());
@@ -722,7 +721,7 @@ public class FunctionCodegen extends GenerationStateAware {
ClassDescriptor classDescriptor = (ClassDescriptor) overriddenDescriptor.getContainingDeclaration(); ClassDescriptor classDescriptor = (ClassDescriptor) overriddenDescriptor.getContainingDeclaration();
String internalName = String internalName =
state.getTypeMapper().mapType(classDescriptor.getDefaultType(), JetTypeMapperMode.VALUE).getInternalName(); state.getTypeMapper().mapType(classDescriptor).getInternalName();
if (classDescriptor.getKind() == ClassKind.TRAIT) { if (classDescriptor.getKind() == ClassKind.TRAIT) {
iv.invokeinterface(internalName, method.getName(), method.getDescriptor()); iv.invokeinterface(internalName, method.getName(), method.getDescriptor());
} }
@@ -317,11 +317,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (superClassType == null) { if (superClassType == null) {
if (descriptor.getKind() == ClassKind.ENUM_CLASS) { if (descriptor.getKind() == ClassKind.ENUM_CLASS) {
superClassType = JetStandardLibrary.getInstance().getEnumType(descriptor.getDefaultType()); superClassType = JetStandardLibrary.getInstance().getEnumType(descriptor.getDefaultType());
superClass = typeMapper.mapType(superClassType, JetTypeMapperMode.VALUE).getInternalName(); superClass = typeMapper.mapType(superClassType).getInternalName();
} }
if (descriptor.getKind() == ClassKind.ENUM_ENTRY) { if (descriptor.getKind() == ClassKind.ENUM_ENTRY) {
superClassType = descriptor.getTypeConstructor().getSupertypes().iterator().next(); superClassType = descriptor.getTypeConstructor().getSupertypes().iterator().next();
superClass = typeMapper.mapType(superClassType, JetTypeMapperMode.VALUE).getInternalName(); superClass = typeMapper.mapType(superClassType).getInternalName();
} }
} }
} }
@@ -410,7 +410,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
MethodVisitor mv = MethodVisitor mv =
v.newMethod(myClass, ACC_PUBLIC | ACC_STATIC, "values", "()" + type.getDescriptor(), null, null); v.newMethod(myClass, ACC_PUBLIC | ACC_STATIC, "values", "()" + type.getDescriptor(), null, null);
mv.visitCode(); mv.visitCode();
mv.visitFieldInsn(GETSTATIC, typeMapper.mapType(descriptor.getDefaultType(), JetTypeMapperMode.VALUE).getInternalName(), mv.visitFieldInsn(GETSTATIC, typeMapper.mapType(descriptor).getInternalName(),
VALUES, VALUES,
type.getDescriptor()); type.getDescriptor());
mv.visitMethodInsn(INVOKEVIRTUAL, type.getInternalName(), "clone", "()Ljava/lang/Object;"); mv.visitMethodInsn(INVOKEVIRTUAL, type.getInternalName(), "clone", "()Ljava/lang/Object;");
@@ -572,7 +572,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
private void generateFieldForObjectInstance() { private void generateFieldForObjectInstance() {
if (isNonLiteralObject(myClass)) { if (isNonLiteralObject(myClass)) {
Type type = typeMapper.mapType(descriptor.getDefaultType(), JetTypeMapperMode.VALUE); Type type = typeMapper.mapType(descriptor);
v.newField(myClass, ACC_PUBLIC | ACC_STATIC | ACC_FINAL, "$instance", type.getDescriptor(), null, null); v.newField(myClass, ACC_PUBLIC | ACC_STATIC | ACC_FINAL, "$instance", type.getDescriptor(), null, null);
staticInitializerChunks.add(new CodeChunk() { staticInitializerChunks.add(new CodeChunk() {
@@ -583,7 +583,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
v.dup(); v.dup();
v.invokespecial(name, "<init>", "()V"); v.invokespecial(name, "<init>", "()V");
v.putstatic(name, "$instance", v.putstatic(name, "$instance",
typeMapper.mapType(descriptor.getDefaultType(), JetTypeMapperMode.VALUE).getDescriptor()); typeMapper.mapType(descriptor).getDescriptor());
} }
}); });
} }
@@ -594,7 +594,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (classObject != null) { if (classObject != null) {
final ClassDescriptor descriptor1 = bindingContext.get(BindingContext.CLASS, classObject.getObjectDeclaration()); final ClassDescriptor descriptor1 = bindingContext.get(BindingContext.CLASS, classObject.getObjectDeclaration());
assert descriptor1 != null; assert descriptor1 != null;
Type type = Type.getObjectType(typeMapper.mapType(descriptor1.getDefaultType(), JetTypeMapperMode.VALUE).getInternalName()); Type type = Type.getObjectType(typeMapper.mapType(descriptor1).getInternalName());
v.newField(classObject, ACC_PUBLIC | ACC_STATIC, "$classobj", type.getDescriptor(), null, null); v.newField(classObject, ACC_PUBLIC | ACC_STATIC, "$classobj", type.getDescriptor(), null, null);
staticInitializerChunks.add(new CodeChunk() { staticInitializerChunks.add(new CodeChunk() {
@@ -607,7 +607,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
v.anew(classObjectType); v.anew(classObjectType);
v.dup(); v.dup();
v.invokespecial(name, "<init>", "()V"); v.invokespecial(name, "<init>", "()V");
v.putstatic(typeMapper.mapType(descriptor.getDefaultType(), JetTypeMapperMode.VALUE).getInternalName(), "$classobj", v.putstatic(typeMapper.mapType(descriptor).getInternalName(), "$classobj",
classObjectType.getDescriptor()); classObjectType.getDescriptor());
} }
}); });
@@ -697,7 +697,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (hasThis0) { if (hasThis0) {
final Type type = typeMapper final Type type = typeMapper
.mapType(enclosingClassDescriptor(bindingContext, descriptor).getDefaultType(), JetTypeMapperMode.VALUE); .mapType(enclosingClassDescriptor(bindingContext, descriptor));
String interfaceDesc = type.getDescriptor(); String interfaceDesc = type.getDescriptor();
iv.load(0, classType); iv.load(0, classType);
iv.load(frameMap.getOuterThisIndex(), type); iv.load(frameMap.getOuterThisIndex(), type);
@@ -706,7 +706,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (closure != null) { if (closure != null) {
int k = hasThis0 ? 2 : 1; int k = hasThis0 ? 2 : 1;
final String internalName = typeMapper.mapType(descriptor.getDefaultType(), JetTypeMapperMode.VALUE).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);
@@ -720,7 +720,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (varDescr instanceof VariableDescriptor && !(varDescr instanceof PropertyDescriptor)) { if (varDescr instanceof VariableDescriptor && !(varDescr instanceof PropertyDescriptor)) {
Type sharedVarType = typeMapper.getSharedVarType(varDescr); Type sharedVarType = typeMapper.getSharedVarType(varDescr);
if (sharedVarType == null) { if (sharedVarType == null) {
sharedVarType = typeMapper.mapType(((VariableDescriptor) varDescr).getType(), JetTypeMapperMode.VALUE); sharedVarType = typeMapper.mapType((VariableDescriptor) varDescr);
} }
iv.load(0, OBJECT_TYPE); iv.load(0, OBJECT_TYPE);
iv.load(k, StackValue.refType(sharedVarType)); iv.load(k, StackValue.refType(sharedVarType));
@@ -747,7 +747,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
for (JetParameter parameter : constructorParameters) { for (JetParameter parameter : constructorParameters) {
if (parameter.getValOrVarNode() != null) { if (parameter.getValOrVarNode() != null) {
VariableDescriptor descriptor = paramDescrs.get(curParam); VariableDescriptor descriptor = paramDescrs.get(curParam);
Type type = typeMapper.mapType(descriptor.getType(), JetTypeMapperMode.VALUE); Type type = typeMapper.mapType(descriptor);
iv.load(0, classType); iv.load(0, classType);
iv.load(frameMap.getIndex(descriptor), type); iv.load(frameMap.getIndex(descriptor), type);
iv.putfield(classname.getInternalName(), descriptor.getName().getName(), type.getDescriptor()); iv.putfield(classname.getInternalName(), descriptor.getName().getName(), type.getDescriptor());
@@ -774,11 +774,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (CodegenBinding.hasThis0(bindingContext, superClassDescriptor)) { if (CodegenBinding.hasThis0(bindingContext, superClassDescriptor)) {
iv.load(1, OBJECT_TYPE); iv.load(1, OBJECT_TYPE);
parameterTypes.add(typeMapper.mapType( parameterTypes.add(typeMapper.mapType(
enclosingClassDescriptor(bindingContext, descriptor).getDefaultType(), JetTypeMapperMode.VALUE)); enclosingClassDescriptor(bindingContext, descriptor)));
} }
Method superCallMethod = new Method("<init>", Type.VOID_TYPE, parameterTypes.toArray(new Type[parameterTypes.size()])); Method superCallMethod = new Method("<init>", Type.VOID_TYPE, parameterTypes.toArray(new Type[parameterTypes.size()]));
//noinspection ConstantConditions //noinspection ConstantConditions
iv.invokespecial(typeMapper.mapType(superClassDescriptor.getDefaultType(), JetTypeMapperMode.VALUE).getInternalName(), "<init>", iv.invokespecial(typeMapper.mapType(superClassDescriptor).getInternalName(), "<init>",
superCallMethod.getDescriptor()); superCallMethod.getDescriptor());
} }
@@ -866,7 +866,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
!propertyDescriptor.isVar() && !propertyDescriptor.isVar() &&
Boolean.TRUE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor))) { Boolean.TRUE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor))) {
// final property with backing field // final property with backing field
field = StackValue.field(typeMapper.mapType(propertyDescriptor.getType(), JetTypeMapperMode.VALUE), classname, field = StackValue.field(typeMapper.mapType(propertyDescriptor.getType()), classname,
propertyDescriptor.getName().getName(), false); propertyDescriptor.getName().getName(), false);
} }
else { else {
@@ -874,7 +874,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
codegen.genToJVMStack(expression); codegen.genToJVMStack(expression);
String delegateField = "$delegate_" + n; String delegateField = "$delegate_" + n;
Type fieldType = typeMapper.mapType(superClassDescriptor.getDefaultType(), JetTypeMapperMode.VALUE); Type fieldType = typeMapper.mapType(superClassDescriptor.getDefaultType());
String fieldDesc = fieldType.getDescriptor(); String fieldDesc = fieldType.getDescriptor();
v.newField(specifier, ACC_PRIVATE|ACC_FINAL|ACC_SYNTHETIC, delegateField, fieldDesc, /*TODO*/null, null); v.newField(specifier, ACC_PRIVATE|ACC_FINAL|ACC_SYNTHETIC, delegateField, fieldDesc, /*TODO*/null, null);
@@ -1258,7 +1258,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
final JetType jetType = propertyDescriptor.getType(); final JetType jetType = propertyDescriptor.getType();
if (compileTimeValue != null) { if (compileTimeValue != null) {
Object value = compileTimeValue.getValue(); Object value = compileTimeValue.getValue();
Type type = typeMapper.mapType(jetType, JetTypeMapperMode.VALUE); Type type = typeMapper.mapType(jetType);
if (skipDefaultValue(propertyDescriptor, value, type)) continue; if (skipDefaultValue(propertyDescriptor, value, type)) continue;
} }
iv.load(0, OBJECT_TYPE); iv.load(0, OBJECT_TYPE);
@@ -1269,7 +1269,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
codegen.gen(initializer, type); codegen.gen(initializer, type);
// @todo write directly to the field. Fix test excloset.jet::test6 // @todo write directly to the field. Fix test excloset.jet::test6
JvmClassName owner = typeMapper.getOwner(propertyDescriptor, OwnerKind.IMPLEMENTATION); JvmClassName owner = typeMapper.getOwner(propertyDescriptor, OwnerKind.IMPLEMENTATION);
Type propType = typeMapper.mapType(jetType, JetTypeMapperMode.VALUE); Type propType = typeMapper.mapType(jetType);
StackValue.property(propertyDescriptor.getName().getName(), owner, owner, StackValue.property(propertyDescriptor.getName().getName(), owner, owner,
propType, false, false, false, null, null, 0).store(propType, iv); propType, false, false, false, null, null, 0).store(propType, iv);
} }
@@ -27,7 +27,6 @@ import org.jetbrains.jet.codegen.context.CodegenContext;
import org.jetbrains.jet.codegen.signature.JvmPropertyAccessorSignature; import org.jetbrains.jet.codegen.signature.JvmPropertyAccessorSignature;
import org.jetbrains.jet.codegen.signature.kotlin.JetMethodAnnotationWriter; import org.jetbrains.jet.codegen.signature.kotlin.JetMethodAnnotationWriter;
import org.jetbrains.jet.codegen.state.GenerationStateAware; import org.jetbrains.jet.codegen.state.GenerationStateAware;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -112,7 +111,7 @@ public class PropertyCodegen extends GenerationStateAware {
if (JetStandardLibrary.getInstance().isVolatile(propertyDescriptor)) { if (JetStandardLibrary.getInstance().isVolatile(propertyDescriptor)) {
modifiers |= ACC_VOLATILE; modifiers |= ACC_VOLATILE;
} }
Type type = state.getTypeMapper().mapType(propertyDescriptor.getType(), JetTypeMapperMode.VALUE); Type type = state.getTypeMapper().mapType(propertyDescriptor);
FieldVisitor fieldVisitor = v.newField(p, modifiers, propertyDescriptor.getName().getName(), type.getDescriptor(), null, value); FieldVisitor fieldVisitor = v.newField(p, modifiers, propertyDescriptor.getName().getName(), type.getDescriptor(), null, value);
AnnotationCodegen.forField(fieldVisitor, state.getTypeMapper()).genAnnotations(propertyDescriptor); AnnotationCodegen.forField(fieldVisitor, state.getTypeMapper()).genAnnotations(propertyDescriptor);
} }
@@ -220,7 +219,7 @@ public class PropertyCodegen extends GenerationStateAware {
if (kind != OwnerKind.NAMESPACE) { if (kind != OwnerKind.NAMESPACE) {
iv.load(0, OBJECT_TYPE); iv.load(0, OBJECT_TYPE);
} }
final Type type = state.getTypeMapper().mapType(propertyDescriptor.getType(), JetTypeMapperMode.VALUE); final Type type = state.getTypeMapper().mapType(propertyDescriptor);
if ((kind instanceof OwnerKind.DelegateKind) != (propertyDescriptor.getKind() == FunctionDescriptor.Kind.DELEGATION)) { if ((kind instanceof OwnerKind.DelegateKind) != (propertyDescriptor.getKind() == FunctionDescriptor.Kind.DELEGATION)) {
throw new IllegalStateException("mismatching kind in " + propertyDescriptor); throw new IllegalStateException("mismatching kind in " + propertyDescriptor);
@@ -318,7 +317,7 @@ public class PropertyCodegen extends GenerationStateAware {
} }
else { else {
InstructionAdapter iv = new InstructionAdapter(mv); InstructionAdapter iv = new InstructionAdapter(mv);
final Type type = state.getTypeMapper().mapType(propertyDescriptor.getType(), JetTypeMapperMode.VALUE); final Type type = state.getTypeMapper().mapType(propertyDescriptor);
int paramCode = 0; int paramCode = 0;
if (kind != OwnerKind.NAMESPACE) { if (kind != OwnerKind.NAMESPACE) {
iv.load(0, OBJECT_TYPE); iv.load(0, OBJECT_TYPE);
@@ -29,7 +29,6 @@ import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.GenerationStateAware; import org.jetbrains.jet.codegen.state.GenerationStateAware;
import org.jetbrains.jet.codegen.state.GenerationStrategy; import org.jetbrains.jet.codegen.state.GenerationStrategy;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor; import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
@@ -115,7 +114,7 @@ public class ScriptCodegen extends GenerationStateAware {
@NotNull List<ScriptDescriptor> importedScripts @NotNull List<ScriptDescriptor> importedScripts
) { ) {
Type blockType = typeMapper.mapType(scriptDescriptor.getReturnType(), JetTypeMapperMode.VALUE); Type blockType = typeMapper.mapType(scriptDescriptor.getReturnType());
classBuilder.newField(null, ACC_PUBLIC | ACC_FINAL, ScriptNameUtil.LAST_EXPRESSION_VALUE_FIELD_NAME, classBuilder.newField(null, ACC_PUBLIC | ACC_FINAL, ScriptNameUtil.LAST_EXPRESSION_VALUE_FIELD_NAME,
blockType.getDescriptor(), null, null); blockType.getDescriptor(), null, null);
@@ -173,7 +172,7 @@ public class ScriptCodegen extends GenerationStateAware {
} }
for (ValueParameterDescriptor parameter : scriptDescriptor.getValueParameters()) { for (ValueParameterDescriptor parameter : scriptDescriptor.getValueParameters()) {
Type parameterType = typeMapper.mapType(parameter.getType(), JetTypeMapperMode.VALUE); Type parameterType = typeMapper.mapType(parameter.getType());
instructionAdapter.load(0, className.getAsmType()); instructionAdapter.load(0, className.getAsmType());
instructionAdapter.load(offset, parameterType); instructionAdapter.load(offset, parameterType);
offset += parameterType.getSize(); offset += parameterType.getSize();
@@ -202,7 +201,7 @@ public class ScriptCodegen extends GenerationStateAware {
} }
for (ValueParameterDescriptor parameter : script.getValueParameters()) { for (ValueParameterDescriptor parameter : script.getValueParameters()) {
Type parameterType = typeMapper.mapType(parameter.getType(), JetTypeMapperMode.VALUE); Type parameterType = typeMapper.mapType(parameter);
int access = ACC_PUBLIC | ACC_FINAL; int access = ACC_PUBLIC | ACC_FINAL;
classBuilder.newField(null, access, parameter.getName().getIdentifier(), parameterType.getDescriptor(), null, null); classBuilder.newField(null, access, parameter.getName().getIdentifier(), parameterType.getDescriptor(), null, null);
} }
@@ -27,7 +27,6 @@ import org.jetbrains.jet.codegen.binding.CodegenBinding;
import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethod; import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethod;
import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.JetTypeMapper; import org.jetbrains.jet.codegen.state.JetTypeMapper;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
@@ -357,7 +356,7 @@ public abstract class StackValue {
} }
public static StackValue singleton(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) { public static StackValue singleton(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
final Type type = typeMapper.mapType(classDescriptor.getDefaultType(), JetTypeMapperMode.VALUE); final Type type = typeMapper.mapType(classDescriptor.getDefaultType());
final ClassKind kind = classDescriptor.getKind(); final ClassKind kind = classDescriptor.getKind();
if (kind == ClassKind.CLASS_OBJECT || kind == ClassKind.OBJECT) { if (kind == ClassKind.CLASS_OBJECT || kind == ClassKind.OBJECT) {
@@ -727,7 +726,7 @@ public abstract class StackValue {
List<ValueParameterDescriptor> valueParameters = resolvedGetCall.getResultingDescriptor().getValueParameters(); List<ValueParameterDescriptor> valueParameters = resolvedGetCall.getResultingDescriptor().getValueParameters();
int firstParamIndex = -1; int firstParamIndex = -1;
for (int i = valueParameters.size() - 1; i >= 0; --i) { for (int i = valueParameters.size() - 1; i >= 0; --i) {
Type type = codegen.typeMapper.mapType(valueParameters.get(i).getType(), JetTypeMapperMode.VALUE); Type type = codegen.typeMapper.mapType(valueParameters.get(i).getType());
int sz = type.getSize(); int sz = type.getSize();
frame.enterTemp(type); frame.enterTemp(type);
lastIndex += sz; lastIndex += sz;
@@ -749,7 +748,7 @@ public abstract class StackValue {
ReceiverDescriptor receiverParameter = resolvedGetCall.getReceiverArgument(); ReceiverDescriptor receiverParameter = resolvedGetCall.getReceiverArgument();
int receiverIndex = -1; int receiverIndex = -1;
if (receiverParameter.exists()) { if (receiverParameter.exists()) {
Type type = codegen.typeMapper.mapType(receiverParameter.getType(), JetTypeMapperMode.VALUE); Type type = codegen.typeMapper.mapType(receiverParameter.getType());
int sz = type.getSize(); int sz = type.getSize();
frame.enterTemp(type); frame.enterTemp(type);
lastIndex += sz; lastIndex += sz;
@@ -773,7 +772,7 @@ public abstract class StackValue {
if (thisIndex != -1) { if (thisIndex != -1) {
if (receiverIndex != -1) { if (receiverIndex != -1) {
realReceiverIndex = receiverIndex; realReceiverIndex = receiverIndex;
realReceiverType = codegen.typeMapper.mapType(receiverParameter.getType(), JetTypeMapperMode.VALUE); realReceiverType = codegen.typeMapper.mapType(receiverParameter.getType());
} }
else { else {
realReceiverIndex = thisIndex; realReceiverIndex = thisIndex;
@@ -782,7 +781,7 @@ public abstract class StackValue {
} }
else { else {
if (receiverIndex != -1) { if (receiverIndex != -1) {
realReceiverType = codegen.typeMapper.mapType(receiverParameter.getType(), JetTypeMapperMode.VALUE); realReceiverType = codegen.typeMapper.mapType(receiverParameter.getType());
realReceiverIndex = receiverIndex; realReceiverIndex = receiverIndex;
} }
else { else {
@@ -807,7 +806,7 @@ public abstract class StackValue {
int index = firstParamIndex; int index = firstParamIndex;
for (int i = 0; i != valueParameters.size(); ++i) { for (int i = 0; i != valueParameters.size(); ++i) {
Type type = codegen.typeMapper.mapType(valueParameters.get(i).getType(), JetTypeMapperMode.VALUE); Type type = codegen.typeMapper.mapType(valueParameters.get(i).getType());
int sz = type.getSize(); int sz = type.getSize();
v.load(index - sz, type); v.load(index - sz, type);
index -= sz; index -= sz;
@@ -819,7 +818,7 @@ public abstract class StackValue {
} }
if (receiverIndex != -1) { if (receiverIndex != -1) {
Type type = codegen.typeMapper.mapType(receiverParameter.getType(), JetTypeMapperMode.VALUE); Type type = codegen.typeMapper.mapType(receiverParameter.getType());
v.load(receiverIndex - type.getSize(), type); v.load(receiverIndex - type.getSize(), type);
} }
@@ -835,7 +834,7 @@ public abstract class StackValue {
index = firstParamIndex; index = firstParamIndex;
for (int i = 0; i != valueParameters.size(); ++i) { for (int i = 0; i != valueParameters.size(); ++i) {
Type type = codegen.typeMapper.mapType(valueParameters.get(i).getType(), JetTypeMapperMode.VALUE); Type type = codegen.typeMapper.mapType(valueParameters.get(i).getType());
int sz = type.getSize(); int sz = type.getSize();
v.load(index - sz, type); v.load(index - sz, type);
index -= sz; index -= sz;
@@ -864,7 +863,7 @@ public abstract class StackValue {
} }
for (ValueParameterDescriptor valueParameter : valueParameters) { for (ValueParameterDescriptor valueParameter : valueParameters) {
if (codegen.typeMapper.mapType(valueParameter.getType(), JetTypeMapperMode.VALUE).getSize() != 1) { if (codegen.typeMapper.mapType(valueParameter.getType()).getSize() != 1) {
return false; return false;
} }
} }
@@ -875,7 +874,7 @@ public abstract class StackValue {
} }
} }
else { else {
if (codegen.typeMapper.mapType(call.getResultingDescriptor().getReceiverParameter().getType(), JetTypeMapperMode.VALUE) if (codegen.typeMapper.mapType(call.getResultingDescriptor().getReceiverParameter().getType())
.getSize() != 1) { .getSize() != 1) {
return false; return false;
} }
@@ -1267,10 +1266,10 @@ public abstract class StackValue {
} }
else { else {
if (receiverArgument.exists()) { if (receiverArgument.exists()) {
return codegen.typeMapper.mapType(descriptor.getReceiverParameter().getType(), JetTypeMapperMode.VALUE); return codegen.typeMapper.mapType(descriptor.getReceiverParameter().getType());
} }
else { else {
return codegen.typeMapper.mapType(descriptor.getExpectedThisObject().getType(), JetTypeMapperMode.VALUE); return codegen.typeMapper.mapType(descriptor.getExpectedThisObject().getType());
} }
} }
} }
@@ -1280,7 +1279,7 @@ public abstract class StackValue {
return callableMethod.getReceiverClass(); return callableMethod.getReceiverClass();
} }
else { else {
return codegen.typeMapper.mapType(descriptor.getReceiverParameter().getType(), JetTypeMapperMode.VALUE); return codegen.typeMapper.mapType(descriptor.getReceiverParameter().getType());
} }
} }
else { else {
@@ -1302,7 +1301,7 @@ public abstract class StackValue {
} }
else { else {
codegen.generateFromResolvedCall(thisObject, codegen.typeMapper codegen.generateFromResolvedCall(thisObject, codegen.typeMapper
.mapType(descriptor.getExpectedThisObject().getType(), JetTypeMapperMode.VALUE)); .mapType(descriptor.getExpectedThisObject().getType()));
} }
genReceiver(v, receiverArgument, type, descriptor.getReceiverParameter(), 1); genReceiver(v, receiverArgument, type, descriptor.getReceiverParameter(), 1);
} }
@@ -1323,7 +1322,7 @@ public abstract class StackValue {
) { ) {
if (receiver == StackValue.none()) { if (receiver == StackValue.none()) {
if (receiverParameter != null) { if (receiverParameter != null) {
Type receiverType = codegen.typeMapper.mapType(receiverParameter.getType(), JetTypeMapperMode.VALUE); Type receiverType = codegen.typeMapper.mapType(receiverParameter.getType());
codegen.generateFromResolvedCall(receiverArgument, receiverType); codegen.generateFromResolvedCall(receiverArgument, receiverType);
StackValue.onStack(receiverType).put(type, v); StackValue.onStack(receiverType).put(type, v);
} }
@@ -24,7 +24,6 @@ import org.jetbrains.jet.codegen.binding.CodegenBinding;
import org.jetbrains.jet.codegen.binding.MutableClosure; import org.jetbrains.jet.codegen.binding.MutableClosure;
import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.JetTypeMapper; import org.jetbrains.jet.codegen.state.JetTypeMapper;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
@@ -196,7 +195,7 @@ public abstract class CodegenContext {
CallableDescriptor receiverDescriptor = getCallableDescriptorWithReceiver(); CallableDescriptor receiverDescriptor = getCallableDescriptorWithReceiver();
if (receiverDescriptor != null) { if (receiverDescriptor != null) {
Type type = mapper.mapType(receiverDescriptor.getReceiverParameter().getType(), JetTypeMapperMode.VALUE); Type type = mapper.mapType(receiverDescriptor.getReceiverParameter().getType());
frameMap.enterTemp(type); // Next slot for receiver frameMap.enterTemp(type); // Next slot for receiver
} }
@@ -243,7 +242,7 @@ public abstract class CodegenContext {
public StackValue getReceiverExpression(JetTypeMapper typeMapper) { public StackValue getReceiverExpression(JetTypeMapper typeMapper) {
assert getCallableDescriptorWithReceiver() != null; assert getCallableDescriptorWithReceiver() != null;
@SuppressWarnings("ConstantConditions") @SuppressWarnings("ConstantConditions")
Type asmType = typeMapper.mapType(getCallableDescriptorWithReceiver().getReceiverParameter().getType(), JetTypeMapperMode.VALUE); Type asmType = typeMapper.mapType(getCallableDescriptorWithReceiver().getReceiverParameter().getType());
return hasThisDescriptor() ? StackValue.local(1, asmType) : StackValue.local(0, asmType); return hasThisDescriptor() ? StackValue.local(1, asmType) : StackValue.local(0, asmType);
} }
@@ -262,7 +261,7 @@ public abstract class CodegenContext {
final ClassDescriptor enclosingClass = getEnclosingClass(); final ClassDescriptor enclosingClass = getEnclosingClass();
outerExpression = enclosingClass != null outerExpression = enclosingClass != null
? StackValue ? StackValue
.field(typeMapper.mapType(enclosingClass.getDefaultType(), JetTypeMapperMode.VALUE), CodegenBinding.getJvmClassName( .field(typeMapper.mapType(enclosingClass), CodegenBinding.getJvmClassName(
typeMapper.getBindingTrace(), classDescriptor), CodegenUtil.THIS$0, typeMapper.getBindingTrace(), classDescriptor), CodegenUtil.THIS$0,
false) false)
: null; : null;
@@ -22,7 +22,6 @@ import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.codegen.binding.MutableClosure; import org.jetbrains.jet.codegen.binding.MutableClosure;
import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.JetElement; import org.jetbrains.jet.lang.psi.JetElement;
import org.jetbrains.jet.lang.resolve.java.JvmClassName; import org.jetbrains.jet.lang.resolve.java.JvmClassName;
@@ -58,7 +57,7 @@ public interface LocalLookup {
if (!idx) return null; if (!idx) return null;
final Type sharedVarType = state.getTypeMapper().getSharedVarType(vd); final Type sharedVarType = state.getTypeMapper().getSharedVarType(vd);
Type localType = state.getTypeMapper().mapType(vd.getType(), JetTypeMapperMode.VALUE); Type localType = state.getTypeMapper().mapType(vd);
final Type type = sharedVarType != null ? sharedVarType : localType; final Type type = sharedVarType != null ? sharedVarType : localType;
final String fieldName = "$" + vd.getName(); final String fieldName = "$" + vd.getName();
@@ -122,7 +121,7 @@ public interface LocalLookup {
if (closure.getEnclosingReceiverDescriptor() != d) return null; if (closure.getEnclosingReceiverDescriptor() != d) return null;
final JetType receiverType = ((CallableDescriptor) d).getReceiverParameter().getType(); final JetType receiverType = ((CallableDescriptor) d).getReceiverParameter().getType();
Type type = state.getTypeMapper().mapType(receiverType, JetTypeMapperMode.VALUE); Type type = state.getTypeMapper().mapType(receiverType);
StackValue innerValue = StackValue.field(type, className, CodegenUtil.RECEIVER$0, false); StackValue innerValue = StackValue.field(type, className, CodegenUtil.RECEIVER$0, false);
closure.setCaptureReceiver(); closure.setCaptureReceiver();
@@ -25,7 +25,6 @@ import org.jetbrains.jet.codegen.AsmTypeConstants;
import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor; import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.psi.JetCallExpression; import org.jetbrains.jet.lang.psi.JetCallExpression;
import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.psi.JetExpression;
@@ -51,8 +50,7 @@ public class EnumValueOf implements IntrinsicMethod {
CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor(); CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor();
JetType returnType = resultingDescriptor.getReturnType(); JetType returnType = resultingDescriptor.getReturnType();
assert returnType != null; assert returnType != null;
Type type = state.getTypeMapper().mapType( Type type = state.getTypeMapper().mapType(returnType);
returnType, JetTypeMapperMode.VALUE);
assert arguments != null; assert arguments != null;
codegen.gen(arguments.get(0), AsmTypeConstants.JAVA_STRING_TYPE); codegen.gen(arguments.get(0), AsmTypeConstants.JAVA_STRING_TYPE);
v.invokestatic(type.getInternalName(), "valueOf", "(Ljava/lang/String;)" + type.getDescriptor()); v.invokestatic(type.getInternalName(), "valueOf", "(Ljava/lang/String;)" + type.getDescriptor());
@@ -24,7 +24,6 @@ import org.jetbrains.asm4.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor; import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.psi.JetCallExpression; import org.jetbrains.jet.lang.psi.JetCallExpression;
import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.psi.JetExpression;
@@ -50,8 +49,7 @@ public class EnumValues implements IntrinsicMethod {
CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor(); CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor();
JetType returnType = resultingDescriptor.getReturnType(); JetType returnType = resultingDescriptor.getReturnType();
assert returnType != null; assert returnType != null;
Type type = state.getTypeMapper().mapType( Type type = state.getTypeMapper().mapType(returnType);
returnType, JetTypeMapperMode.VALUE);
v.invokestatic(type.getElementType().getInternalName(), "values", "()" + type); v.invokestatic(type.getElementType().getInternalName(), "values", "()" + type);
StackValue.onStack(type).put(expectedType, v); StackValue.onStack(type).put(expectedType, v);
return StackValue.onStack(expectedType); return StackValue.onStack(expectedType);
@@ -25,7 +25,6 @@ import org.jetbrains.jet.codegen.AsmTypeConstants;
import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.codegen.state.GenerationState; import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor; import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.psi.JetCallExpression; import org.jetbrains.jet.lang.psi.JetCallExpression;
import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.psi.JetExpression;
@@ -52,8 +51,7 @@ public class JavaClassFunction implements IntrinsicMethod {
CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor(); CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor();
JetType returnType = resultingDescriptor.getReturnType(); JetType returnType = resultingDescriptor.getReturnType();
assert returnType != null; assert returnType != null;
Type type = state.getTypeMapper().mapType( Type type = state.getTypeMapper().mapType(returnType.getArguments().get(0).getType());
returnType.getArguments().get(0).getType(), JetTypeMapperMode.VALUE);
JvmPrimitiveType primitiveType = JvmPrimitiveType.getByAsmType(type); JvmPrimitiveType primitiveType = JvmPrimitiveType.getByAsmType(type);
if (primitiveType != null) { if (primitiveType != null) {
v.getstatic(primitiveType.getWrapper().getAsmType().getInternalName(), "TYPE", "Ljava/lang/Class;"); v.getstatic(primitiveType.getWrapper().getAsmType().getInternalName(), "TYPE", "Ljava/lang/Class;");
@@ -200,6 +200,21 @@ public class JetTypeMapper extends BindingTraceAware {
return mapType(jetType, null, kind); return mapType(jetType, null, kind);
} }
@NotNull
public Type mapType(@NotNull final JetType jetType) {
return mapType(jetType, null, JetTypeMapperMode.VALUE);
}
@NotNull
public Type mapType(@NotNull final VariableDescriptor variableDescriptor) {
return mapType(variableDescriptor.getType(), null, JetTypeMapperMode.VALUE);
}
@NotNull
public Type mapType(@NotNull final ClassifierDescriptor classifierDescriptor) {
return mapType(classifierDescriptor.getDefaultType());
}
@NotNull @NotNull
public Type mapType(JetType jetType, @Nullable BothSignatureWriter signatureVisitor, @NotNull JetTypeMapperMode kind) { public Type mapType(JetType jetType, @Nullable BothSignatureWriter signatureVisitor, @NotNull JetTypeMapperMode kind) {
Type known = null; Type known = null;
@@ -422,7 +437,7 @@ public class JetTypeMapper extends BindingTraceAware {
descriptor = mapSignature(functionDescriptor, false, OwnerKind.TRAIT_IMPL); descriptor = mapSignature(functionDescriptor, false, OwnerKind.TRAIT_IMPL);
owner = JvmClassName.byInternalName(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX); owner = JvmClassName.byInternalName(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
} }
thisClass = JvmClassName.byType(mapType(receiver.getDefaultType(), JetTypeMapperMode.VALUE)); thisClass = JvmClassName.byType(mapType(receiver.getDefaultType()));
} }
else { else {
throw new UnsupportedOperationException("unknown function parent"); throw new UnsupportedOperationException("unknown function parent");
@@ -431,7 +446,7 @@ public class JetTypeMapper extends BindingTraceAware {
Type receiverParameterType; Type receiverParameterType;
if (functionDescriptor.getReceiverParameter().exists()) { if (functionDescriptor.getReceiverParameter().exists()) {
receiverParameterType = mapType(functionDescriptor.getOriginal().getReceiverParameter().getType(), JetTypeMapperMode.VALUE); receiverParameterType = mapType(functionDescriptor.getOriginal().getReceiverParameter().getType());
} }
else { else {
receiverParameterType = null; receiverParameterType = null;
@@ -480,10 +495,10 @@ public class JetTypeMapper extends BindingTraceAware {
if (kind == OwnerKind.TRAIT_IMPL) { if (kind == OwnerKind.TRAIT_IMPL) {
ClassDescriptor containingDeclaration = (ClassDescriptor) f.getContainingDeclaration(); ClassDescriptor containingDeclaration = (ClassDescriptor) f.getContainingDeclaration();
JetType jetType = CodegenUtil.getSuperClass(containingDeclaration); JetType jetType = CodegenUtil.getSuperClass(containingDeclaration);
Type type = mapType(jetType, JetTypeMapperMode.VALUE); Type type = mapType(jetType);
if (type.getInternalName().equals("java/lang/Object")) { if (type.getInternalName().equals("java/lang/Object")) {
jetType = containingDeclaration.getDefaultType(); jetType = containingDeclaration.getDefaultType();
type = mapType(jetType, JetTypeMapperMode.VALUE); type = mapType(jetType);
} }
signatureVisitor.writeParameterType(JvmMethodParameterKind.THIS); signatureVisitor.writeParameterType(JvmMethodParameterKind.THIS);
@@ -743,7 +758,7 @@ public class JetTypeMapper extends BindingTraceAware {
if (entry.getKey() instanceof VariableDescriptor && !(entry.getKey() instanceof PropertyDescriptor)) { if (entry.getKey() instanceof VariableDescriptor && !(entry.getKey() instanceof PropertyDescriptor)) {
Type sharedVarType = getSharedVarType(entry.getKey()); Type sharedVarType = getSharedVarType(entry.getKey());
if (sharedVarType == null) { if (sharedVarType == null) {
sharedVarType = mapType(((VariableDescriptor) entry.getKey()).getType(), JetTypeMapperMode.VALUE); sharedVarType = mapType(((VariableDescriptor) entry.getKey()).getType());
} }
signatureWriter.writeParameterType(JvmMethodParameterKind.SHARED_VAR); signatureWriter.writeParameterType(JvmMethodParameterKind.SHARED_VAR);
signatureWriter.writeAsmType(sharedVarType, false); signatureWriter.writeAsmType(sharedVarType, false);
@@ -839,7 +854,7 @@ public class JetTypeMapper extends BindingTraceAware {
public Type getSharedVarType(DeclarationDescriptor descriptor) { public Type getSharedVarType(DeclarationDescriptor descriptor) {
if (descriptor instanceof PropertyDescriptor) { if (descriptor instanceof PropertyDescriptor) {
return StackValue return StackValue
.sharedTypeForType(mapType(((PropertyDescriptor) descriptor).getReceiverParameter().getType(), JetTypeMapperMode.VALUE)); .sharedTypeForType(mapType(((PropertyDescriptor) descriptor).getReceiverParameter().getType()));
} }
else if (descriptor instanceof SimpleFunctionDescriptor && descriptor.getContainingDeclaration() instanceof FunctionDescriptor) { else if (descriptor instanceof SimpleFunctionDescriptor && descriptor.getContainingDeclaration() instanceof FunctionDescriptor) {
PsiElement psiElement = descriptorToDeclaration(bindingContext, descriptor); PsiElement psiElement = descriptorToDeclaration(bindingContext, descriptor);
@@ -847,11 +862,11 @@ public class JetTypeMapper extends BindingTraceAware {
} }
else if (descriptor instanceof FunctionDescriptor) { else if (descriptor instanceof FunctionDescriptor) {
return StackValue return StackValue
.sharedTypeForType(mapType(((FunctionDescriptor) descriptor).getReceiverParameter().getType(), JetTypeMapperMode.VALUE)); .sharedTypeForType(mapType(((FunctionDescriptor) descriptor).getReceiverParameter().getType()));
} }
else if (descriptor instanceof VariableDescriptor && isVarCapturedInClosure(bindingContext, descriptor)) { else if (descriptor instanceof VariableDescriptor && isVarCapturedInClosure(bindingContext, descriptor)) {
JetType outType = ((VariableDescriptor) descriptor).getType(); JetType outType = ((VariableDescriptor) descriptor).getType();
return StackValue.sharedTypeForType(mapType(outType, JetTypeMapperMode.VALUE)); return StackValue.sharedTypeForType(mapType(outType));
} }
return null; return null;
} }
@@ -865,7 +880,7 @@ public class JetTypeMapper extends BindingTraceAware {
JvmClassName owner = getInternalClassName(fd); JvmClassName owner = getInternalClassName(fd);
Type receiverParameterType; Type receiverParameterType;
if (fd.getReceiverParameter().exists()) { if (fd.getReceiverParameter().exists()) {
receiverParameterType = mapType(fd.getOriginal().getReceiverParameter().getType(), JetTypeMapperMode.VALUE); receiverParameterType = mapType(fd.getOriginal().getReceiverParameter().getType());
} }
else { else {
receiverParameterType = null; receiverParameterType = null;