replace String with JvmClassName

This commit is contained in:
Stepan Koltsov
2012-06-01 19:18:56 +04:00
parent 39dc1a1cb8
commit 3512415f3f
6 changed files with 43 additions and 40 deletions
@@ -22,6 +22,7 @@ import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.types.JetType;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
@@ -35,11 +36,11 @@ import java.util.List;
*/
public class CallableMethod implements Callable {
@NotNull
private final String owner;
@NotNull
private final String defaultImplOwner;
@NotNull
private final String defaultImplParam;
private final JvmClassName owner;
@Nullable
private final JvmClassName defaultImplOwner;
@Nullable
private final JvmClassName defaultImplParam;
private final JvmMethodSignature signature;
private final int invokeOpcode;
private ClassDescriptor thisClass = null;
@@ -47,7 +48,7 @@ public class CallableMethod implements Callable {
private CallableDescriptor receiverFunction = null;
private Type generateCalleeType = null;
public CallableMethod(@NotNull String owner, @NotNull String defaultImplOwner, @NotNull String defaultImplParam,
public CallableMethod(@NotNull JvmClassName owner, @Nullable JvmClassName defaultImplOwner, @Nullable JvmClassName defaultImplParam,
JvmMethodSignature signature, int invokeOpcode) {
this.owner = owner;
this.defaultImplOwner = defaultImplOwner;
@@ -57,12 +58,12 @@ public class CallableMethod implements Callable {
}
@NotNull
public String getOwner() {
public JvmClassName getOwner() {
return owner;
}
@NotNull
public String getDefaultImplParam() {
public JvmClassName getDefaultImplParam() {
return defaultImplParam;
}
@@ -95,7 +96,7 @@ public class CallableMethod implements Callable {
}
void invoke(InstructionAdapter v) {
v.visitMethodInsn(getInvokeOpcode(), owner, getSignature().getAsmMethod().getName(), getSignature().getAsmMethod().getDescriptor());
v.visitMethodInsn(getInvokeOpcode(), owner.getInternalName(), getSignature().getAsmMethod().getName(), getSignature().getAsmMethod().getDescriptor());
}
public void requestGenerateCallee(Type objectType) {
@@ -107,19 +108,19 @@ public class CallableMethod implements Callable {
}
public void invokeWithDefault(InstructionAdapter v, int mask) {
if (defaultImplOwner.length() == 0 || defaultImplParam.length() == 0) {
if (defaultImplOwner == null || defaultImplParam == null) {
throw new IllegalStateException();
}
v.iconst(mask);
String desc = getSignature().getAsmMethod().getDescriptor().replace(")", "I)");
if("<init>".equals(getSignature().getAsmMethod().getName())) {
v.visitMethodInsn(Opcodes.INVOKESPECIAL, defaultImplOwner, "<init>", desc);
v.visitMethodInsn(Opcodes.INVOKESPECIAL, defaultImplOwner.getInternalName(), "<init>", desc);
}
else {
if(getInvokeOpcode() != Opcodes.INVOKESTATIC)
desc = desc.replace("(", "(L" + defaultImplParam + ";");
v.visitMethodInsn(Opcodes.INVOKESTATIC, defaultImplOwner,
desc = desc.replace("(", "(" + defaultImplParam.getDescriptor());
v.visitMethodInsn(Opcodes.INVOKESTATIC, defaultImplOwner.getInternalName(),
getSignature().getAsmMethod().getName() + JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX, desc);
}
}
@@ -22,6 +22,7 @@ package org.jetbrains.jet.codegen;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.codegen.signature.BothSignatureWriter;
import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind;
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
@@ -89,13 +90,13 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
public static CallableMethod asCallableMethod(FunctionDescriptor fd) {
JvmMethodSignature descriptor = erasedInvokeSignature(fd);
String owner = getInternalClassName(fd);
final CallableMethod result = new CallableMethod(owner, "", "", descriptor, INVOKEVIRTUAL);
JvmClassName owner = getInternalClassName(fd);
final CallableMethod result = new CallableMethod(owner, null, null, descriptor, INVOKEVIRTUAL);
if (fd.getReceiverParameter().exists()) {
result.setNeedsReceiver(fd);
}
result.setNeedsThis(getInternalType(fd));
result.requestGenerateCallee(Type.getObjectType(getInternalClassName(fd)));
result.requestGenerateCallee(getInternalClassName(fd).getAsmType());
return result;
}
@@ -114,8 +115,8 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
SignatureWriter signatureWriter = new SignatureWriter();
final List<ValueParameterDescriptor> parameters = funDescriptor.getValueParameters();
final String funClass = getInternalClassName(funDescriptor);
signatureWriter.visitClassType(funClass);
final JvmClassName funClass = getInternalClassName(funDescriptor);
signatureWriter.visitClassType(funClass.getInternalName());
for (ValueParameterDescriptor parameter : parameters) {
appendType(signatureWriter, parameter.getType(), '=');
}
@@ -128,7 +129,7 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
ACC_PUBLIC/*|ACC_SUPER*/,
name.getInternalName(),
null,
funClass,
funClass.getInternalName(),
new String[0]
);
cv.visitSource(fun.getContainingFile().getName(), null);
@@ -248,7 +249,7 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
}
}
private Method generateConstructor(String funClass, PsiElement fun) {
private Method generateConstructor(JvmClassName funClass, PsiElement fun) {
int argCount = captureThis != null ? 1 : 0;
argCount += (captureReceiver != null ? 1 : 0);
@@ -306,8 +307,8 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
mv.visitCode();
InstructionAdapter iv = new InstructionAdapter(mv);
iv.load(0, Type.getObjectType(funClass));
iv.invokespecial(funClass, "<init>", "()V");
iv.load(0, funClass.getAsmType());
iv.invokespecial(funClass.getInternalName(), "<init>", "()V");
i = 1;
for (Type type : argTypes) {
@@ -338,13 +339,14 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
return constructor;
}
public static String getInternalClassName(FunctionDescriptor descriptor) {
@NotNull
public static JvmClassName getInternalClassName(FunctionDescriptor descriptor) {
final int paramCount = descriptor.getValueParameters().size();
if (descriptor.getReceiverParameter().exists()) {
return "jet/ExtensionFunction" + paramCount;
return JvmClassName.byInternalName("jet/ExtensionFunction" + paramCount);
}
else {
return "jet/Function" + paramCount;
return JvmClassName.byInternalName("jet/Function" + paramCount);
}
}
@@ -1249,8 +1249,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
// TODO ugly
CallableMethod callableMethod = typeMapper.mapToCallableMethod(propertyDescriptor.getGetter(), isSuper, contextKind());
invokeOpcode = callableMethod.getInvokeOpcode();
owner = JvmClassName.byInternalName(callableMethod.getOwner());
ownerParam = JvmClassName.byInternalName(callableMethod.getDefaultImplParam());
owner = callableMethod.getOwner();
ownerParam = callableMethod.getDefaultImplParam();
}
return StackValue.property(propertyDescriptor.getName().getName(), owner, ownerParam, asmType(propertyDescriptor.getType()), isStatic, isInterface, isSuper, getter, setter, invokeOpcode);
@@ -474,7 +474,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
signatureWriter.writeVoidReturn();
constructorMethod = signatureWriter.makeJvmMethodSignature("<init>");
callableMethod = new CallableMethod("", "", "", constructorMethod, INVOKESPECIAL);
callableMethod = new CallableMethod(JvmClassName.byInternalName("Ignored"), null, null, constructorMethod, INVOKESPECIAL);
}
else {
callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor, kind, typeMapper.hasThis0(constructorDescriptor.getContainingDeclaration()));
@@ -541,14 +541,14 @@ public class JetTypeMapper {
}
JvmMethodSignature descriptor = mapSignature(functionDescriptor.getOriginal(), true, kind);
String owner;
String ownerForDefaultImpl;
String ownerForDefaultParam;
JvmClassName owner;
JvmClassName ownerForDefaultImpl;
JvmClassName ownerForDefaultParam;
int invokeOpcode;
ClassDescriptor thisClass;
if (functionParent instanceof NamespaceDescriptor) {
assert !superCall;
owner = jvmClassNameForNamespace((NamespaceDescriptor) functionParent).getInternalName();
owner = jvmClassNameForNamespace((NamespaceDescriptor) functionParent);
ownerForDefaultImpl = ownerForDefaultParam = owner;
invokeOpcode = INVOKESTATIC;
thisClass = null;
@@ -556,7 +556,7 @@ public class JetTypeMapper {
else if (functionDescriptor instanceof ConstructorDescriptor) {
assert !superCall;
ClassDescriptor containingClass = (ClassDescriptor) functionParent;
owner = mapType(containingClass.getDefaultType(), MapTypeMode.IMPL).getInternalName();
owner = JvmClassName.byType(mapType(containingClass.getDefaultType(), MapTypeMode.IMPL));
ownerForDefaultImpl = ownerForDefaultParam = owner;
invokeOpcode = INVOKESPECIAL;
thisClass = null;
@@ -583,17 +583,17 @@ public class JetTypeMapper {
boolean isInterface = originalIsInterface && currentIsInterface;
Type type = mapType(receiver.getDefaultType(), MapTypeMode.TYPE_PARAMETER);
owner = type.getInternalName();
ownerForDefaultParam = mapType(declarationOwner.getDefaultType(), MapTypeMode.TYPE_PARAMETER).getInternalName();
ownerForDefaultImpl = ownerForDefaultParam
+ (originalIsInterface ? JvmAbi.TRAIT_IMPL_SUFFIX : "");
owner = JvmClassName.byType(type);
ownerForDefaultParam = JvmClassName.byType(mapType(declarationOwner.getDefaultType(), MapTypeMode.TYPE_PARAMETER));
ownerForDefaultImpl = JvmClassName.byInternalName(
ownerForDefaultParam.getInternalName() + (originalIsInterface ? JvmAbi.TRAIT_IMPL_SUFFIX : ""));
invokeOpcode = isInterface
? (superCall ? Opcodes.INVOKESTATIC : Opcodes.INVOKEINTERFACE)
: (superCall ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL);
if(isInterface && superCall) {
descriptor = mapSignature(functionDescriptor, false, OwnerKind.TRAIT_IMPL);
owner += JvmAbi.TRAIT_IMPL_SUFFIX;
owner = JvmClassName.byInternalName(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
}
thisClass = receiver;
}
@@ -899,7 +899,7 @@ public class JetTypeMapper {
if (mapped.getSort() != Type.OBJECT) {
throw new IllegalStateException("type must have been mapped to object: " + defaultType + ", actual: " + mapped);
}
String owner = mapped.getInternalName();
JvmClassName owner = JvmClassName.byType(mapped);
return new CallableMethod(owner, owner, owner, method, INVOKESPECIAL);
}
@@ -1120,7 +1120,7 @@ public abstract class StackValue {
if (thisObject.exists()) {
if(receiverArgument.exists()) {
if (callableMethod != null) {
codegen.generateFromResolvedCall(thisObject, Type.getObjectType(callableMethod.getOwner()));
codegen.generateFromResolvedCall(thisObject, callableMethod.getOwner().getAsmType());
}
else {
codegen.generateFromResolvedCall(thisObject, codegen.typeMapper.mapType(descriptor.getExpectedThisObject().getType(), MapTypeMode.VALUE));