Delete JvmClassName.getDescriptor()
It shouldn't be available in descriptor.loader.java, since it wouldn't depend on ASM and its descriptors won't make any sense there. Most of the places where this method was used were in codegen. The few exceptions are reading annotations for compiled Kotlin classes by ASM visitors, but that will be abstracted away soon
This commit is contained in:
@@ -667,6 +667,6 @@ public class AsmUtil {
|
||||
|
||||
@NotNull
|
||||
public static String asmDescByFqNameWithoutInnerClasses(@NotNull FqName fqName) {
|
||||
return JvmClassName.byFqNameWithoutInnerClasses(fqName).getDescriptor();
|
||||
return "L" + JvmClassName.byFqNameWithoutInnerClasses(fqName).getInternalName() + ';';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class CallableMethod implements Callable {
|
||||
@Nullable
|
||||
private final JvmClassName defaultImplOwner;
|
||||
@Nullable
|
||||
private final JvmClassName defaultImplParam;
|
||||
private final Type defaultImplParam;
|
||||
private final JvmMethodSignature signature;
|
||||
private final int invokeOpcode;
|
||||
@Nullable
|
||||
@@ -55,7 +55,7 @@ public class CallableMethod implements Callable {
|
||||
) {
|
||||
this.owner = owner;
|
||||
this.defaultImplOwner = defaultImplOwner;
|
||||
this.defaultImplParam = defaultImplParam;
|
||||
this.defaultImplParam = defaultImplParam == null ? null : defaultImplParam.getAsmType();
|
||||
this.signature = signature;
|
||||
this.invokeOpcode = invokeOpcode;
|
||||
this.thisClass = thisClass;
|
||||
@@ -68,11 +68,6 @@ public class CallableMethod implements Callable {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JvmClassName getDefaultImplParam() {
|
||||
return defaultImplParam;
|
||||
}
|
||||
|
||||
public JvmMethodSignature getSignature() {
|
||||
return signature;
|
||||
}
|
||||
@@ -157,12 +152,6 @@ public class CallableMethod implements Callable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(Printer.OPCODES[invokeOpcode]);
|
||||
sb.append(" ");
|
||||
sb.append(owner);
|
||||
sb.append(".");
|
||||
sb.append(signature);
|
||||
return sb.toString();
|
||||
return Printer.OPCODES[invokeOpcode] + " " + owner + "." + signature;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
||||
private final CodegenContext context;
|
||||
private final FunctionGenerationStrategy strategy;
|
||||
private final CalculatedClosure closure;
|
||||
private final JvmClassName name;
|
||||
private final Type asmType;
|
||||
|
||||
private Method constructor;
|
||||
|
||||
@@ -87,12 +87,12 @@ public class ClosureCodegen extends GenerationStateAware {
|
||||
this.closure = bindingContext.get(CLOSURE, classDescriptor);
|
||||
assert closure != null : "Closure must be calculated for class: " + classDescriptor;
|
||||
|
||||
this.name = classNameForAnonymousClass(bindingContext, funDescriptor);
|
||||
this.asmType = classNameForAnonymousClass(bindingContext, funDescriptor).getAsmType();
|
||||
}
|
||||
|
||||
|
||||
public void gen() {
|
||||
ClassBuilder cv = state.getFactory().newVisitor(name, fun.getContainingFile());
|
||||
ClassBuilder cv = state.getFactory().newVisitor(JvmClassName.byType(asmType), fun.getContainingFile());
|
||||
|
||||
FunctionDescriptor interfaceFunction;
|
||||
String[] superInterfaces;
|
||||
@@ -109,7 +109,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
||||
cv.defineClass(fun,
|
||||
V1_6,
|
||||
ACC_FINAL | ACC_SUPER,
|
||||
name.getInternalName(),
|
||||
asmType.getInternalName(),
|
||||
getGenericSignature(),
|
||||
superClass.getInternalName(),
|
||||
superInterfaces
|
||||
@@ -141,16 +141,15 @@ public class ClosureCodegen extends GenerationStateAware {
|
||||
|
||||
@NotNull
|
||||
public StackValue putInstanceOnStack(@NotNull InstructionAdapter v, @NotNull ExpressionCodegen codegen) {
|
||||
Type asmType = name.getAsmType();
|
||||
if (isConst(closure)) {
|
||||
v.getstatic(name.getInternalName(), JvmAbi.INSTANCE_FIELD, name.getDescriptor());
|
||||
v.getstatic(asmType.getInternalName(), JvmAbi.INSTANCE_FIELD, asmType.getDescriptor());
|
||||
}
|
||||
else {
|
||||
v.anew(asmType);
|
||||
v.dup();
|
||||
|
||||
codegen.pushClosureOnStack(closure, false);
|
||||
v.invokespecial(name.getInternalName(), "<init>", constructor.getDescriptor());
|
||||
v.invokespecial(asmType.getInternalName(), "<init>", constructor.getDescriptor());
|
||||
}
|
||||
return StackValue.onStack(asmType);
|
||||
}
|
||||
@@ -160,14 +159,14 @@ public class ClosureCodegen extends GenerationStateAware {
|
||||
MethodVisitor mv = cv.newMethod(fun, ACC_STATIC | ACC_SYNTHETIC, "<clinit>", "()V", null, ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||
|
||||
cv.newField(fun, ACC_STATIC | ACC_FINAL, JvmAbi.INSTANCE_FIELD, name.getDescriptor(), null, null);
|
||||
cv.newField(fun, ACC_STATIC | ACC_FINAL, JvmAbi.INSTANCE_FIELD, asmType.getDescriptor(), null, null);
|
||||
|
||||
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
||||
genStubCode(mv);
|
||||
}
|
||||
else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
||||
mv.visitCode();
|
||||
genInitSingletonField(name.getAsmType(), iv);
|
||||
genInitSingletonField(asmType, iv);
|
||||
mv.visitInsn(RETURN);
|
||||
FunctionCodegen.endVisit(mv, "<clinit>", fun);
|
||||
}
|
||||
@@ -192,7 +191,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
||||
|
||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||
|
||||
iv.load(0, name.getAsmType());
|
||||
iv.load(0, asmType);
|
||||
|
||||
ReceiverParameterDescriptor receiver = funDescriptor.getReceiverParameter();
|
||||
int count = 1;
|
||||
@@ -207,7 +206,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
||||
count++;
|
||||
}
|
||||
|
||||
iv.invokevirtual(name.getInternalName(), interfaceFunction.getName().asString(), delegate.getDescriptor());
|
||||
iv.invokevirtual(asmType.getInternalName(), interfaceFunction.getName().asString(), delegate.getDescriptor());
|
||||
StackValue.onStack(delegate.getReturnType()).put(bridge.getReturnType(), iv);
|
||||
|
||||
iv.areturn(bridge.getReturnType());
|
||||
@@ -218,7 +217,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
||||
|
||||
@NotNull
|
||||
private Method generateConstructor(@NotNull ClassBuilder cv) {
|
||||
List<FieldInfo> args = calculateConstructorParameters(typeMapper, closure, name.getAsmType());
|
||||
List<FieldInfo> args = calculateConstructorParameters(typeMapper, closure, asmType);
|
||||
|
||||
Type[] argTypes = fieldListToTypeArray(args);
|
||||
|
||||
|
||||
@@ -532,17 +532,15 @@ public class FunctionCodegen extends GenerationStateAware {
|
||||
|
||||
int flags = ACC_PUBLIC | ACC_SYNTHETIC; // TODO.
|
||||
|
||||
JvmClassName ownerInternalName;
|
||||
Type ownerType;
|
||||
if (contextClass instanceof NamespaceDescriptor) {
|
||||
ownerInternalName = state.getTypeMapper().getOwner(functionDescriptor, kind, true);
|
||||
ownerType = state.getTypeMapper().getOwner(functionDescriptor, kind, true).getAsmType();
|
||||
}
|
||||
else if (contextClass instanceof ClassDescriptor) {
|
||||
ownerInternalName = JvmClassName.byType(state.getTypeMapper()
|
||||
.mapType(((ClassDescriptor) contextClass).getDefaultType(),
|
||||
JetTypeMapperMode.IMPL));
|
||||
ownerType = state.getTypeMapper().mapType(((ClassDescriptor) contextClass).getDefaultType(), JetTypeMapperMode.IMPL);
|
||||
}
|
||||
else if (isLocalNamedFun(functionDescriptor)) {
|
||||
ownerInternalName = classNameForAnonymousClass(state.getBindingContext(), functionDescriptor);
|
||||
ownerType = classNameForAnonymousClass(state.getBindingContext(), functionDescriptor).getAsmType();
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Couldn't obtain owner name for " + functionDescriptor);
|
||||
@@ -551,7 +549,7 @@ public class FunctionCodegen extends GenerationStateAware {
|
||||
String descriptor = jvmSignature.getDescriptor().replace(")", "I)");
|
||||
boolean isConstructor = "<init>".equals(jvmSignature.getName());
|
||||
if (!isStatic && !isConstructor) {
|
||||
descriptor = descriptor.replace("(", "(" + ownerInternalName.getDescriptor());
|
||||
descriptor = descriptor.replace("(", "(" + ownerType.getDescriptor());
|
||||
}
|
||||
MethodVisitor mv = v.newMethod(null, flags | (isConstructor ? 0 : ACC_STATIC),
|
||||
isConstructor ? "<init>" : jvmSignature.getName() + JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX,
|
||||
|
||||
@@ -217,7 +217,7 @@ public class NamespaceCodegen extends MemberCodegen {
|
||||
}
|
||||
|
||||
private static void writeKotlinPackageFragmentAnnotation(@NotNull ClassBuilder builder) {
|
||||
AnnotationVisitor av = builder.newAnnotation(JvmClassName.byFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_PACKAGE_FRAGMENT).getDescriptor(), true);
|
||||
AnnotationVisitor av = builder.newAnnotation(asmDescByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_PACKAGE_FRAGMENT), true);
|
||||
av.visit(JvmAnnotationNames.ABI_VERSION_FIELD_NAME, JvmAbi.VERSION);
|
||||
av.visitEnd();
|
||||
}
|
||||
|
||||
@@ -182,10 +182,9 @@ public class ScriptCodegen extends MemberCodegen {
|
||||
|
||||
private void genFieldsForParameters(@NotNull ScriptDescriptor script, @NotNull ClassBuilder classBuilder) {
|
||||
for (ScriptDescriptor earlierScript : earlierScripts) {
|
||||
JvmClassName earlierClassName;
|
||||
earlierClassName = classNameForScriptDescriptor(bindingContext, earlierScript);
|
||||
JvmClassName earlierClassName = classNameForScriptDescriptor(bindingContext, earlierScript);
|
||||
int access = ACC_PRIVATE | ACC_FINAL;
|
||||
classBuilder.newField(null, access, getScriptFieldName(earlierScript), earlierClassName.getDescriptor(), null, null);
|
||||
classBuilder.newField(null, access, getScriptFieldName(earlierScript), earlierClassName.getAsmType().getDescriptor(), null, null);
|
||||
}
|
||||
|
||||
for (ValueParameterDescriptor parameter : script.getValueParameters()) {
|
||||
|
||||
@@ -30,13 +30,15 @@ import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.asmDescByFqNameWithoutInnerClasses;
|
||||
|
||||
public class ArrayIterator implements IntrinsicMethod {
|
||||
@Override
|
||||
public StackValue generate(
|
||||
@@ -58,18 +60,18 @@ public class ArrayIterator implements IntrinsicMethod {
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Ljava/lang/Object;)Ljava/util/Iterator;");
|
||||
return StackValue.onStack(AsmTypeConstants.JET_ITERATOR_TYPE);
|
||||
}
|
||||
else {
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
ClassDescriptor arrayClass = KotlinBuiltIns.getInstance().getPrimitiveArrayClassDescriptor(primitiveType);
|
||||
if (containingDeclaration.equals(arrayClass)) {
|
||||
JvmClassName iterator = JvmClassName.byFqNameWithoutInnerClasses("jet." + primitiveType.getTypeName() + "Iterator");
|
||||
String methodSignature = "([" + jvmPrimitiveType.getAsmType() + ")" + iterator.getDescriptor();
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature);
|
||||
return StackValue.onStack(iterator.getAsmType());
|
||||
}
|
||||
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
ClassDescriptor arrayClass = KotlinBuiltIns.getInstance().getPrimitiveArrayClassDescriptor(primitiveType);
|
||||
if (containingDeclaration.equals(arrayClass)) {
|
||||
String iteratorDesc = asmDescByFqNameWithoutInnerClasses(new FqName("jet." + primitiveType.getTypeName() + "Iterator"));
|
||||
String methodSignature = "([" + jvmPrimitiveType.getAsmType() + ")" + iteratorDesc;
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature);
|
||||
return StackValue.onStack(Type.getType(iteratorDesc));
|
||||
}
|
||||
throw new UnsupportedOperationException(containingDeclaration.toString());
|
||||
}
|
||||
|
||||
throw new UnsupportedOperationException(containingDeclaration.toString());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-10
@@ -81,7 +81,6 @@ public class JvmClassName {
|
||||
|
||||
private final String internalName;
|
||||
private FqName fqName;
|
||||
private String descriptor;
|
||||
private Type asmType;
|
||||
|
||||
private JvmClassName(@NotNull String internalName) {
|
||||
@@ -101,18 +100,10 @@ public class JvmClassName {
|
||||
return internalName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getDescriptor() {
|
||||
if (descriptor == null) {
|
||||
descriptor = "L" + internalName + ';';
|
||||
}
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type getAsmType() {
|
||||
if (asmType == null) {
|
||||
asmType = Type.getType(getDescriptor());
|
||||
asmType = Type.getType("L" + internalName + ';');
|
||||
}
|
||||
return asmType;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user