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