replace String with JvmClassName for readability

This commit is contained in:
Stepan Koltsov
2012-06-01 18:04:46 +04:00
parent 563d5cfd03
commit 59bdeda408
9 changed files with 70 additions and 61 deletions
@@ -199,7 +199,7 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
ClassDescriptor function = state.getInjector().getJetTypeMapper().getClosureAnnotator().classDescriptorForFunctionDescriptor(funDescriptor, name); ClassDescriptor function = state.getInjector().getJetTypeMapper().getClosureAnnotator().classDescriptorForFunctionDescriptor(funDescriptor, name);
final CodegenContexts.ClosureContext closureContext = context.intoClosure( final CodegenContexts.ClosureContext closureContext = context.intoClosure(
funDescriptor, function, name.getInternalName(), this, state.getInjector().getJetTypeMapper()); funDescriptor, function, name, this, state.getInjector().getJetTypeMapper());
FunctionCodegen fc = new FunctionCodegen(closureContext, cv, state); FunctionCodegen fc = new FunctionCodegen(closureContext, cv, state);
JvmMethodSignature jvmMethodSignature = invokeSignature(funDescriptor); JvmMethodSignature jvmMethodSignature = invokeSignature(funDescriptor);
fc.generateMethod(body, jvmMethodSignature, false, null, funDescriptor); fc.generateMethod(body, jvmMethodSignature, false, null, funDescriptor);
@@ -328,7 +328,7 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
} }
i += type.getSize(); i += type.getSize();
StackValue.field(type, name.getInternalName(), fieldName, false).store(iv); StackValue.field(type, name, fieldName, false).store(iv);
} }
iv.visitInsn(RETURN); iv.visitInsn(RETURN);
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.Nullable;
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.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
@@ -129,7 +130,7 @@ public abstract class CodegenContext {
return new CodegenContexts.ScriptContext(script, OwnerKind.IMPLEMENTATION, this, closure); return new CodegenContexts.ScriptContext(script, OwnerKind.IMPLEMENTATION, this, closure);
} }
public CodegenContexts.ClosureContext intoClosure(FunctionDescriptor funDescriptor, ClassDescriptor classDescriptor, String internalClassName, ClosureCodegen closureCodegen, JetTypeMapper typeMapper) { public CodegenContexts.ClosureContext intoClosure(FunctionDescriptor funDescriptor, ClassDescriptor classDescriptor, JvmClassName internalClassName, ClosureCodegen closureCodegen, JetTypeMapper typeMapper) {
return new CodegenContexts.ClosureContext(funDescriptor, classDescriptor, this, closureCodegen, internalClassName, typeMapper); return new CodegenContexts.ClosureContext(funDescriptor, classDescriptor, this, closureCodegen, internalClassName, typeMapper);
} }
@@ -25,6 +25,7 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyAccessorDescriptor; import org.jetbrains.jet.lang.descriptors.PropertyAccessorDescriptor;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
import org.objectweb.asm.commons.InstructionAdapter; import org.objectweb.asm.commons.InstructionAdapter;
@@ -145,7 +146,7 @@ public class CodegenContexts {
final Type type = enclosingClassType(typeMapper); final Type type = enclosingClassType(typeMapper);
outerExpression = type != null outerExpression = type != null
? StackValue.field(type, typeMapper.getFQName(contextType), "this$0", false) ? StackValue.field(type, JvmClassName.byInternalName(typeMapper.getFQName(contextType)), "this$0", false)
: null; : null;
} }
@@ -167,7 +168,7 @@ public class CodegenContexts {
final Type type = enclosingClassType(typeMapper); final Type type = enclosingClassType(typeMapper);
Type owner = closure.state.getInjector().getJetTypeMapper().mapType(contextType.getDefaultType(), MapTypeMode.IMPL); Type owner = closure.state.getInjector().getJetTypeMapper().mapType(contextType.getDefaultType(), MapTypeMode.IMPL);
outerExpression = type != null outerExpression = type != null
? StackValue.field(type, owner.getInternalName(), "this$0", false) ? StackValue.field(type, JvmClassName.byType(owner), "this$0", false)
: null; : null;
} }
@@ -190,7 +191,7 @@ public class CodegenContexts {
public static class ClosureContext extends ReceiverContext { public static class ClosureContext extends ReceiverContext {
private ClassDescriptor classDescriptor; private ClassDescriptor classDescriptor;
public ClosureContext(FunctionDescriptor contextType, ClassDescriptor classDescriptor, CodegenContext parentContext, @NotNull ObjectOrClosureCodegen closureCodegen, String internalClassName, JetTypeMapper typeMapper) { public ClosureContext(FunctionDescriptor contextType, ClassDescriptor classDescriptor, CodegenContext parentContext, @NotNull ObjectOrClosureCodegen closureCodegen, JvmClassName internalClassName, JetTypeMapper typeMapper) {
super(contextType, OwnerKind.IMPLEMENTATION, parentContext, closureCodegen); super(contextType, OwnerKind.IMPLEMENTATION, parentContext, closureCodegen);
this.classDescriptor = classDescriptor; this.classDescriptor = classDescriptor;
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.calls.*; import org.jetbrains.jet.lang.resolve.calls.*;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
@@ -1010,7 +1011,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
if(classDescriptor.getKind() == ClassKind.ENUM_ENTRY) { if(classDescriptor.getKind() == ClassKind.ENUM_ENTRY) {
ClassDescriptor containing = (ClassDescriptor) classDescriptor.getContainingDeclaration().getContainingDeclaration(); ClassDescriptor containing = (ClassDescriptor) classDescriptor.getContainingDeclaration().getContainingDeclaration();
Type type = typeMapper.mapType(containing.getDefaultType(), MapTypeMode.VALUE); Type type = typeMapper.mapType(containing.getDefaultType(), MapTypeMode.VALUE);
StackValue.field(type, type.getInternalName(), classDescriptor.getName().getName(), true).put(TYPE_OBJECT, v); StackValue.field(type, JvmClassName.byType(type), classDescriptor.getName().getName(), true).put(TYPE_OBJECT, v);
// todo: for now we don't generate classes for enum entries, so we need this hack // todo: for now we don't generate classes for enum entries, so we need this hack
type = typeMapper.mapType(classDescriptor.getDefaultType(), MapTypeMode.VALUE); type = typeMapper.mapType(classDescriptor.getDefaultType(), MapTypeMode.VALUE);
@@ -1018,7 +1019,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
} }
else { else {
Type type = typeMapper.mapType(classDescriptor.getDefaultType(), MapTypeMode.VALUE); Type type = typeMapper.mapType(classDescriptor.getDefaultType(), MapTypeMode.VALUE);
return StackValue.field(type, type.getInternalName(), "$instance", true); return StackValue.field(type, JvmClassName.byType(type), "$instance", true);
} }
} }
@@ -1043,7 +1044,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
if(!directToField && resolvedCall != null && !isSuper) { if(!directToField && resolvedCall != null && !isSuper) {
receiver.put(propertyDescriptor.getReceiverParameter().exists() || isStatic receiver.put(propertyDescriptor.getReceiverParameter().exists() || isStatic
? receiver.type ? receiver.type
: Type.getObjectType(iValue.methodOwner), v); : iValue.methodOwner.getAsmType(), v);
} }
else { else {
if (!isStatic) { if (!isStatic) {
@@ -1083,9 +1084,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
assert descriptor1 != null; assert descriptor1 != null;
final Type type = typeMapper.mapType(descriptor1.getDefaultType(), MapTypeMode.VALUE); final Type type = typeMapper.mapType(descriptor1.getDefaultType(), MapTypeMode.VALUE);
return StackValue.field(type, return StackValue.field(type,
typeMapper.mapType(((ClassDescriptor) descriptor).getDefaultType(), MapTypeMode.IMPL).getInternalName(), JvmClassName.byType(typeMapper.mapType(((ClassDescriptor) descriptor).getDefaultType(), MapTypeMode.IMPL)),
"$classobj", "$classobj",
true); true);
} }
else { else {
// todo ? // todo ?
@@ -1115,7 +1116,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
if(value instanceof StackValue.FieldForSharedVar) { if(value instanceof StackValue.FieldForSharedVar) {
StackValue.FieldForSharedVar fieldForSharedVar = (StackValue.FieldForSharedVar) value; StackValue.FieldForSharedVar fieldForSharedVar = (StackValue.FieldForSharedVar) value;
Type sharedType = StackValue.sharedTypeForType(value.type); Type sharedType = StackValue.sharedTypeForType(value.type);
v.visitFieldInsn(Opcodes.GETFIELD, fieldForSharedVar.owner, fieldForSharedVar.name, sharedType.getDescriptor()); v.visitFieldInsn(Opcodes.GETFIELD, fieldForSharedVar.owner.getInternalName(), fieldForSharedVar.name, sharedType.getDescriptor());
} }
return value; return value;
@@ -1129,7 +1130,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
DeclarationDescriptor containingDeclaration = functionDescriptor.getOriginal().getContainingDeclaration(); DeclarationDescriptor containingDeclaration = functionDescriptor.getOriginal().getContainingDeclaration();
boolean isStatic = containingDeclaration instanceof NamespaceDescriptor; boolean isStatic = containingDeclaration instanceof NamespaceDescriptor;
functionDescriptor = functionDescriptor.getOriginal(); functionDescriptor = functionDescriptor.getOriginal();
String owner; JvmClassName owner;
IntrinsicMethod intrinsic = state.getInjector().getIntrinsics().getIntrinsic(functionDescriptor); IntrinsicMethod intrinsic = state.getInjector().getIntrinsics().getIntrinsic(functionDescriptor);
if(intrinsic != null) { if(intrinsic != null) {
@@ -1148,7 +1149,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
isInterface = CodegenUtil.isInterface(containingDeclaration); isInterface = CodegenUtil.isInterface(containingDeclaration);
} }
v.visitMethodInsn(isStatic ? Opcodes.INVOKESTATIC : isInterface ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL, owner, functionDescriptor.getName().getName(), typeMapper.mapSignature(functionDescriptor.getName(),functionDescriptor).getAsmMethod().getDescriptor()); int opcode = isStatic ? Opcodes.INVOKESTATIC : isInterface ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL;
v.visitMethodInsn(opcode, owner.getInternalName(), functionDescriptor.getName().getName(),
typeMapper.mapSignature(functionDescriptor.getName(),functionDescriptor).getAsmMethod().getDescriptor());
StackValue.onStack(asmType(functionDescriptor.getReturnType())).coerce(type, v); StackValue.onStack(asmType(functionDescriptor.getReturnType())).coerce(type, v);
} }
@@ -1221,8 +1224,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
int invokeOpcode; int invokeOpcode;
String owner; JvmClassName owner;
String ownerParam; JvmClassName ownerParam;
boolean isInterface; boolean isInterface;
if (isInsideClass || isStatic || propertyDescriptor.getGetter() == null) { if (isInsideClass || isStatic || propertyDescriptor.getGetter() == null) {
owner = ownerParam = typeMapper.getOwner(propertyDescriptor, contextKind()); owner = ownerParam = typeMapper.getOwner(propertyDescriptor, contextKind());
@@ -1234,8 +1237,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
// TODO ugly // TODO ugly
CallableMethod callableMethod = typeMapper.mapToCallableMethod(propertyDescriptor.getGetter(), isSuper, contextKind()); CallableMethod callableMethod = typeMapper.mapToCallableMethod(propertyDescriptor.getGetter(), isSuper, contextKind());
invokeOpcode = callableMethod.getInvokeOpcode(); invokeOpcode = callableMethod.getInvokeOpcode();
owner = callableMethod.getOwner(); owner = JvmClassName.byInternalName(callableMethod.getOwner());
ownerParam = callableMethod.getDefaultImplParam(); ownerParam = JvmClassName.byInternalName(callableMethod.getDefaultImplParam());
} }
return StackValue.property(propertyDescriptor.getName().getName(), owner, ownerParam, asmType(propertyDescriptor.getType()), isStatic, isInterface, isSuper, getter, setter, invokeOpcode); return StackValue.property(propertyDescriptor.getName().getName(), owner, ownerParam, asmType(propertyDescriptor.getType()), isStatic, isInterface, isSuper, getter, setter, invokeOpcode);
@@ -2715,8 +2718,8 @@ If finally block is present, its last expression is the value of try expression.
expressionToMatch.dupReceiver(v); expressionToMatch.dupReceiver(v);
expressionToMatch.put(TYPE_OBJECT, v); expressionToMatch.put(TYPE_OBJECT, v);
v.dup(); v.dup();
final String tupleClassName = "jet/Tuple" + entries.size(); final JvmClassName tupleClassName = JvmClassName.byInternalName("jet/Tuple" + entries.size());
Type tupleType = Type.getObjectType(tupleClassName); Type tupleType = tupleClassName.getAsmType();
v.instanceOf(tupleType); v.instanceOf(tupleType);
Label lblCheck = new Label(); Label lblCheck = new Label();
v.ifne(lblCheck); v.ifne(lblCheck);
@@ -31,6 +31,7 @@ import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.OverridingUtil; import org.jetbrains.jet.lang.resolve.OverridingUtil;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.java.JvmAbi; import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.lexer.JetTokens;
@@ -318,7 +319,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
//noinspection AssignmentToForLoopParameter //noinspection AssignmentToForLoopParameter
reg += argType.getSize(); reg += argType.getSize();
} }
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), originalMethod.getName(), originalMethod.getDescriptor()); iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), originalMethod.getName(), originalMethod.getDescriptor());
iv.areturn(method.getReturnType()); iv.areturn(method.getReturnType());
FunctionCodegen.endVisit(iv, "accessor", null); FunctionCodegen.endVisit(iv, "accessor", null);
@@ -344,9 +345,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
iv.load(0, JetTypeMapper.TYPE_OBJECT); iv.load(0, JetTypeMapper.TYPE_OBJECT);
if(original.getVisibility() == Visibilities.PRIVATE) if(original.getVisibility() == Visibilities.PRIVATE)
iv.getfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), original.getName().getName(), originalMethod.getReturnType().getDescriptor()); iv.getfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), original.getName().getName(), originalMethod.getReturnType().getDescriptor());
else else
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), originalMethod.getName(), originalMethod.getDescriptor()); iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), originalMethod.getName(), originalMethod.getDescriptor());
iv.areturn(method.getReturnType()); iv.areturn(method.getReturnType());
FunctionCodegen.endVisit(iv, "accessor", null); FunctionCodegen.endVisit(iv, "accessor", null);
@@ -377,9 +378,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
reg += argType.getSize(); reg += argType.getSize();
} }
if(original.getVisibility() == Visibilities.PRIVATE && original.getModality() == Modality.FINAL) if(original.getVisibility() == Visibilities.PRIVATE && original.getModality() == Modality.FINAL)
iv.putfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), original.getName().getName(), originalMethod.getArgumentTypes()[0].getDescriptor()); iv.putfield(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), original.getName().getName(), originalMethod.getArgumentTypes()[0].getDescriptor());
else else
iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION), originalMethod.getName(), originalMethod.getDescriptor()); iv.invokespecial(typeMapper.getOwner(original, OwnerKind.IMPLEMENTATION).getInternalName(), originalMethod.getName(), originalMethod.getDescriptor());
iv.areturn(method.getReturnType()); iv.areturn(method.getReturnType());
FunctionCodegen.endVisit(iv, "accessor", null); FunctionCodegen.endVisit(iv, "accessor", null);
@@ -588,8 +589,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
// codegen.addTypeParameter(descriptor.getTypeConstructor().getParameters().get(slot), StackValue.local(frameMap.getFirstTypeParameter() + slot, JetTypeMapper.TYPE_TYPEINFO)); // codegen.addTypeParameter(descriptor.getTypeConstructor().getParameters().get(slot), StackValue.local(frameMap.getFirstTypeParameter() + slot, JetTypeMapper.TYPE_TYPEINFO));
// } // }
String classname = typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.IMPL).getInternalName(); Type classType = typeMapper.mapType(descriptor.getDefaultType(), MapTypeMode.IMPL);
final Type classType = Type.getType("L" + classname + ";"); JvmClassName classname = JvmClassName.byType(classType);
HashSet<FunctionDescriptor> overridden = new HashSet<FunctionDescriptor>(); HashSet<FunctionDescriptor> overridden = new HashSet<FunctionDescriptor>();
for (JetDeclaration declaration : myClass.getDeclarations()) { for (JetDeclaration declaration : myClass.getDeclarations()) {
@@ -657,7 +658,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
v.newField(myClass, ACC_FINAL, fieldName, interfaceDesc, null, null); v.newField(myClass, ACC_FINAL, fieldName, interfaceDesc, null, null);
iv.load(0, classType); iv.load(0, classType);
iv.load(frameMap.getOuterThisIndex(), type); iv.load(frameMap.getOuterThisIndex(), type);
iv.putfield(classname, fieldName, interfaceDesc); iv.putfield(classname.getInternalName(), fieldName, interfaceDesc);
} }
if(closure != null) { if(closure != null) {
@@ -693,7 +694,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
Type type = typeMapper.mapType(descriptor.getType(), MapTypeMode.VALUE); Type type = typeMapper.mapType(descriptor.getType(), MapTypeMode.VALUE);
iv.load(0, classType); iv.load(0, classType);
iv.load(frameMap.getIndex(descriptor), type); iv.load(frameMap.getIndex(descriptor), type);
iv.putfield(classname, descriptor.getName().getName(), type.getDescriptor()); iv.putfield(classname.getInternalName(), descriptor.getName().getName(), type.getDescriptor());
} }
curParam++; curParam++;
} }
@@ -957,7 +958,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
type = JetTypeMapper.boxType(type); type = JetTypeMapper.boxType(type);
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
String owner = typeMapper.getOwner(propertyDescriptor, OwnerKind.IMPLEMENTATION); JvmClassName owner = typeMapper.getOwner(propertyDescriptor, OwnerKind.IMPLEMENTATION);
StackValue.property(propertyDescriptor.getName().getName(), owner, owner, StackValue.property(propertyDescriptor.getName().getName(), owner, owner,
typeMapper.mapType(propertyDescriptor.getType(), MapTypeMode.VALUE), false, false, false, null, null, 0).store(iv); typeMapper.mapType(propertyDescriptor.getType(), MapTypeMode.VALUE), false, false, false, null, null, 0).store(iv);
} }
@@ -142,13 +142,13 @@ public class JetTypeMapper {
return Type.getType(internalName.substring(1)); return Type.getType(internalName.substring(1));
} }
public String getOwner(DeclarationDescriptor descriptor, OwnerKind kind) { @NotNull
public JvmClassName getOwner(DeclarationDescriptor descriptor, OwnerKind kind) {
MapTypeMode mapTypeMode = ownerKindToMapTypeMode(kind); MapTypeMode mapTypeMode = ownerKindToMapTypeMode(kind);
String owner;
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration(); DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
if (containingDeclaration instanceof NamespaceDescriptor) { if (containingDeclaration instanceof NamespaceDescriptor) {
owner = jvmClassNameForNamespace((NamespaceDescriptor) containingDeclaration).getInternalName(); return jvmClassNameForNamespace((NamespaceDescriptor) containingDeclaration);
} }
else if (containingDeclaration instanceof ClassDescriptor) { else if (containingDeclaration instanceof ClassDescriptor) {
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration; ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
@@ -164,12 +164,11 @@ public class JetTypeMapper {
if (asmType.getSort() != Type.OBJECT) { if (asmType.getSort() != Type.OBJECT) {
throw new IllegalStateException(); throw new IllegalStateException();
} }
owner = asmType.getInternalName(); return JvmClassName.byType(asmType);
} }
else { else {
throw new UnsupportedOperationException("don't know how to generate owner for parent " + containingDeclaration); throw new UnsupportedOperationException("don't know how to generate owner for parent " + containingDeclaration);
} }
return owner;
} }
public static MapTypeMode ownerKindToMapTypeMode(OwnerKind kind) { public static MapTypeMode ownerKindToMapTypeMode(OwnerKind kind) {
@@ -68,8 +68,8 @@ public class ObjectOrClosureCodegen {
StackValue outerValue = StackValue.local(idx, type); StackValue outerValue = StackValue.local(idx, type);
final String fieldName = "$" + vd.getName(); final String fieldName = "$" + vd.getName();
StackValue innerValue = sharedVarType != null StackValue innerValue = sharedVarType != null
? StackValue.fieldForSharedVar(localType, name.getInternalName(), fieldName) ? StackValue.fieldForSharedVar(localType, name, fieldName)
: StackValue.field(type, name.getInternalName(), fieldName, false); : StackValue.field(type, name, fieldName, false);
cv.newField(null, Opcodes.ACC_PUBLIC, fieldName, type.getDescriptor(), null, null); cv.newField(null, Opcodes.ACC_PUBLIC, fieldName, type.getDescriptor(), null, null);
@@ -91,7 +91,7 @@ public class ObjectOrClosureCodegen {
StackValue outerValue = StackValue.local(idx, localType); StackValue outerValue = StackValue.local(idx, localType);
final String fieldName = "$" + vd.getName(); final String fieldName = "$" + vd.getName();
StackValue innerValue = StackValue.field(localType, name.getInternalName(), fieldName, false); StackValue innerValue = StackValue.field(localType, name, fieldName, false);
cv.newField(null, Opcodes.ACC_PUBLIC, fieldName, localType.getDescriptor(), null, null); cv.newField(null, Opcodes.ACC_PUBLIC, fieldName, localType.getDescriptor(), null, null);
@@ -117,7 +117,7 @@ public class ObjectOrClosureCodegen {
boolean isStatic = fcontext.getContextDescriptor().getContainingDeclaration() instanceof NamespaceDescriptor; boolean isStatic = fcontext.getContextDescriptor().getContainingDeclaration() instanceof NamespaceDescriptor;
StackValue outerValue = StackValue.local(isStatic ? 0 : 1, type); StackValue outerValue = StackValue.local(isStatic ? 0 : 1, type);
final String fieldName = "receiver$0"; final String fieldName = "receiver$0";
StackValue innerValue = StackValue.field(type, name.getInternalName(), fieldName, false); StackValue innerValue = StackValue.field(type, name, fieldName, false);
cv.newField(null, Opcodes.ACC_PUBLIC, fieldName, type.getDescriptor(), null, null); cv.newField(null, Opcodes.ACC_PUBLIC, fieldName, type.getDescriptor(), null, null);
@@ -206,8 +206,10 @@ public class PropertyCodegen {
iv.invokeinterface(dk.getOwnerClass(), getterName, descriptor); iv.invokeinterface(dk.getOwnerClass(), getterName, descriptor);
} }
else { else {
iv.visitFieldInsn(kind == OwnerKind.NAMESPACE ? Opcodes.GETSTATIC : Opcodes.GETFIELD, iv.visitFieldInsn(
state.getInjector().getJetTypeMapper().getOwner(propertyDescriptor, kind), propertyDescriptor.getName().getName(), kind == OwnerKind.NAMESPACE ? Opcodes.GETSTATIC : Opcodes.GETFIELD,
state.getInjector().getJetTypeMapper().getOwner(propertyDescriptor, kind).getInternalName(),
propertyDescriptor.getName().getName(),
type.getDescriptor()); type.getDescriptor());
} }
iv.areturn(type); iv.areturn(type);
@@ -297,7 +299,7 @@ public class PropertyCodegen {
else { else {
iv.load(paramCode, type); iv.load(paramCode, type);
iv.visitFieldInsn(kind == OwnerKind.NAMESPACE ? Opcodes.PUTSTATIC : Opcodes.PUTFIELD, iv.visitFieldInsn(kind == OwnerKind.NAMESPACE ? Opcodes.PUTSTATIC : Opcodes.PUTFIELD,
state.getInjector().getJetTypeMapper().getOwner(propertyDescriptor, kind), propertyDescriptor.getName().getName(), state.getInjector().getJetTypeMapper().getOwner(propertyDescriptor, kind).getInternalName(), propertyDescriptor.getName().getName(),
type.getDescriptor()); type.getDescriptor());
} }
@@ -23,6 +23,7 @@ import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethod;
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;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType; import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.lexer.JetTokens;
@@ -114,11 +115,11 @@ public abstract class StackValue {
return new CollectionElement(type, getter, setter, codegen, state); return new CollectionElement(type, getter, setter, codegen, state);
} }
public static StackValue field(Type type, String owner, String name, boolean isStatic) { public static StackValue field(Type type, JvmClassName owner, String name, boolean isStatic) {
return new Field(type, owner, name, isStatic); return new Field(type, owner, name, isStatic);
} }
public static Property property(String name, String methodOwner, String methodOwnerParam, Type type, boolean isStatic, boolean isInterface, boolean isSuper, Method getter, Method setter, int invokeOpcode) { public static Property property(String name, JvmClassName methodOwner, JvmClassName methodOwnerParam, Type type, boolean isStatic, boolean isInterface, boolean isSuper, Method getter, Method setter, int invokeOpcode) {
return new Property(name, methodOwner, methodOwnerParam, getter, setter, isStatic, isInterface, isSuper, type, invokeOpcode); return new Property(name, methodOwner, methodOwnerParam, getter, setter, isStatic, isInterface, isSuper, type, invokeOpcode);
} }
@@ -257,7 +258,7 @@ public abstract class StackValue {
return None.INSTANCE; return None.INSTANCE;
} }
public static StackValue fieldForSharedVar(Type type, String name, String fieldName) { public static StackValue fieldForSharedVar(Type type, JvmClassName name, String fieldName) {
return new FieldForSharedVar(type, name, fieldName); return new FieldForSharedVar(type, name, fieldName);
} }
@@ -745,11 +746,11 @@ public abstract class StackValue {
static class Field extends StackValue { static class Field extends StackValue {
final String owner; final JvmClassName owner;
final String name; final String name;
private final boolean isStatic; private final boolean isStatic;
public Field(Type type, String owner, String name, boolean isStatic) { public Field(Type type, JvmClassName owner, String name, boolean isStatic) {
super(type); super(type);
this.owner = owner; this.owner = owner;
this.name = name; this.name = name;
@@ -758,7 +759,7 @@ public abstract class StackValue {
@Override @Override
public void put(Type type, InstructionAdapter v) { public void put(Type type, InstructionAdapter v) {
v.visitFieldInsn(isStatic ? Opcodes.GETSTATIC : Opcodes.GETFIELD, owner, name, this.type.getDescriptor()); v.visitFieldInsn(isStatic ? Opcodes.GETSTATIC : Opcodes.GETFIELD, owner.getInternalName(), name, this.type.getDescriptor());
coerce(type, v); coerce(type, v);
} }
@@ -775,7 +776,7 @@ public abstract class StackValue {
@Override @Override
public void store(InstructionAdapter v) { public void store(InstructionAdapter v) {
v.visitFieldInsn(isStatic ? Opcodes.PUTSTATIC : Opcodes.PUTFIELD, owner, name, this.type.getDescriptor()); v.visitFieldInsn(isStatic ? Opcodes.PUTSTATIC : Opcodes.PUTFIELD, owner.getInternalName(), name, this.type.getDescriptor());
} }
} }
@@ -787,15 +788,16 @@ public abstract class StackValue {
@Nullable @Nullable
private final Method setter; private final Method setter;
@NotNull @NotNull
public final String methodOwner; public final JvmClassName methodOwner;
@NotNull @NotNull
private final String methodOwnerParam; private final JvmClassName methodOwnerParam;
private final boolean isStatic; private final boolean isStatic;
private final boolean isInterface; private final boolean isInterface;
private final boolean isSuper; private final boolean isSuper;
private final int invokeOpcode; private final int invokeOpcode;
public Property(@NotNull String name, @NotNull String methodOwner, @NotNull String methodOwnerParam, Method getter, Method setter, boolean aStatic, boolean isInterface, boolean isSuper, Type type, int invokeOpcode) { public Property(@NotNull String name, @NotNull JvmClassName methodOwner, @NotNull JvmClassName methodOwnerParam,
Method getter, Method setter, boolean aStatic, boolean isInterface, boolean isSuper, Type type, int invokeOpcode) {
super(type); super(type);
this.name = name; this.name = name;
this.methodOwner = methodOwner; this.methodOwner = methodOwner;
@@ -816,14 +818,14 @@ public abstract class StackValue {
@Override @Override
public void put(Type type, InstructionAdapter v) { public void put(Type type, InstructionAdapter v) {
if(isSuper && isInterface) { if(isSuper && isInterface) {
v.visitMethodInsn(Opcodes.INVOKESTATIC, methodOwner, getter.getName(), getter.getDescriptor().replace("(", "(L" + methodOwnerParam + ";")); v.visitMethodInsn(Opcodes.INVOKESTATIC, methodOwner.getInternalName(), getter.getName(), getter.getDescriptor().replace("(", "(" + methodOwnerParam.getDescriptor()));
} }
else { else {
if (getter == null) { if (getter == null) {
v.visitFieldInsn(isStatic ? Opcodes.GETSTATIC : Opcodes.GETFIELD, methodOwner, name, this.type.getDescriptor()); v.visitFieldInsn(isStatic ? Opcodes.GETSTATIC : Opcodes.GETFIELD, methodOwner.getInternalName(), name, this.type.getDescriptor());
} }
else { else {
v.visitMethodInsn(invokeOpcode, methodOwner, getter.getName(), getter.getDescriptor()); v.visitMethodInsn(invokeOpcode, methodOwner.getInternalName(), getter.getName(), getter.getDescriptor());
} }
} }
coerce(type, v); coerce(type, v);
@@ -832,14 +834,14 @@ public abstract class StackValue {
@Override @Override
public void store(InstructionAdapter v) { public void store(InstructionAdapter v) {
if(isSuper && isInterface) { if(isSuper && isInterface) {
v.visitMethodInsn(Opcodes.INVOKESTATIC, methodOwner, setter.getName(), setter.getDescriptor().replace("(", "(L" + methodOwnerParam + ";")); v.visitMethodInsn(Opcodes.INVOKESTATIC, methodOwner.getInternalName(), setter.getName(), setter.getDescriptor().replace("(", "(" + methodOwnerParam.getDescriptor()));
} }
else { else {
if (setter == null) { if (setter == null) {
v.visitFieldInsn(isStatic ? Opcodes.PUTSTATIC : Opcodes.PUTFIELD, methodOwner, name, this.type.getDescriptor()); v.visitFieldInsn(isStatic ? Opcodes.PUTSTATIC : Opcodes.PUTFIELD, methodOwner.getInternalName(), name, this.type.getDescriptor());
} }
else { else {
v.visitMethodInsn(invokeOpcode, methodOwner, setter.getName(), setter.getDescriptor()); v.visitMethodInsn(invokeOpcode, methodOwner.getInternalName(), setter.getName(), setter.getDescriptor());
} }
} }
} }
@@ -943,10 +945,10 @@ public abstract class StackValue {
} }
static class FieldForSharedVar extends StackValue { static class FieldForSharedVar extends StackValue {
final String owner; final JvmClassName owner;
final String name; final String name;
public FieldForSharedVar(Type type, String owner, String name) { public FieldForSharedVar(Type type, JvmClassName owner, String name) {
super(type); super(type);
this.owner = owner; this.owner = owner;
this.name = name; this.name = name;