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
|
@NotNull
|
||||||
public static String asmDescByFqNameWithoutInnerClasses(@NotNull FqName fqName) {
|
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
|
@Nullable
|
||||||
private final JvmClassName defaultImplOwner;
|
private final JvmClassName defaultImplOwner;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final JvmClassName defaultImplParam;
|
private final Type defaultImplParam;
|
||||||
private final JvmMethodSignature signature;
|
private final JvmMethodSignature signature;
|
||||||
private final int invokeOpcode;
|
private final int invokeOpcode;
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -55,7 +55,7 @@ public class CallableMethod implements Callable {
|
|||||||
) {
|
) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.defaultImplOwner = defaultImplOwner;
|
this.defaultImplOwner = defaultImplOwner;
|
||||||
this.defaultImplParam = defaultImplParam;
|
this.defaultImplParam = defaultImplParam == null ? null : defaultImplParam.getAsmType();
|
||||||
this.signature = signature;
|
this.signature = signature;
|
||||||
this.invokeOpcode = invokeOpcode;
|
this.invokeOpcode = invokeOpcode;
|
||||||
this.thisClass = thisClass;
|
this.thisClass = thisClass;
|
||||||
@@ -68,11 +68,6 @@ public class CallableMethod implements Callable {
|
|||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public JvmClassName getDefaultImplParam() {
|
|
||||||
return defaultImplParam;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JvmMethodSignature getSignature() {
|
public JvmMethodSignature getSignature() {
|
||||||
return signature;
|
return signature;
|
||||||
}
|
}
|
||||||
@@ -157,12 +152,6 @@ public class CallableMethod implements Callable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
return Printer.OPCODES[invokeOpcode] + " " + owner + "." + signature;
|
||||||
sb.append(Printer.OPCODES[invokeOpcode]);
|
|
||||||
sb.append(" ");
|
|
||||||
sb.append(owner);
|
|
||||||
sb.append(".");
|
|
||||||
sb.append(signature);
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
|||||||
private final CodegenContext context;
|
private final CodegenContext context;
|
||||||
private final FunctionGenerationStrategy strategy;
|
private final FunctionGenerationStrategy strategy;
|
||||||
private final CalculatedClosure closure;
|
private final CalculatedClosure closure;
|
||||||
private final JvmClassName name;
|
private final Type asmType;
|
||||||
|
|
||||||
private Method constructor;
|
private Method constructor;
|
||||||
|
|
||||||
@@ -87,12 +87,12 @@ public class ClosureCodegen extends GenerationStateAware {
|
|||||||
this.closure = bindingContext.get(CLOSURE, classDescriptor);
|
this.closure = bindingContext.get(CLOSURE, classDescriptor);
|
||||||
assert closure != null : "Closure must be calculated for class: " + 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() {
|
public void gen() {
|
||||||
ClassBuilder cv = state.getFactory().newVisitor(name, fun.getContainingFile());
|
ClassBuilder cv = state.getFactory().newVisitor(JvmClassName.byType(asmType), fun.getContainingFile());
|
||||||
|
|
||||||
FunctionDescriptor interfaceFunction;
|
FunctionDescriptor interfaceFunction;
|
||||||
String[] superInterfaces;
|
String[] superInterfaces;
|
||||||
@@ -109,7 +109,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
|||||||
cv.defineClass(fun,
|
cv.defineClass(fun,
|
||||||
V1_6,
|
V1_6,
|
||||||
ACC_FINAL | ACC_SUPER,
|
ACC_FINAL | ACC_SUPER,
|
||||||
name.getInternalName(),
|
asmType.getInternalName(),
|
||||||
getGenericSignature(),
|
getGenericSignature(),
|
||||||
superClass.getInternalName(),
|
superClass.getInternalName(),
|
||||||
superInterfaces
|
superInterfaces
|
||||||
@@ -141,16 +141,15 @@ public class ClosureCodegen extends GenerationStateAware {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public StackValue putInstanceOnStack(@NotNull InstructionAdapter v, @NotNull ExpressionCodegen codegen) {
|
public StackValue putInstanceOnStack(@NotNull InstructionAdapter v, @NotNull ExpressionCodegen codegen) {
|
||||||
Type asmType = name.getAsmType();
|
|
||||||
if (isConst(closure)) {
|
if (isConst(closure)) {
|
||||||
v.getstatic(name.getInternalName(), JvmAbi.INSTANCE_FIELD, name.getDescriptor());
|
v.getstatic(asmType.getInternalName(), JvmAbi.INSTANCE_FIELD, asmType.getDescriptor());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
v.anew(asmType);
|
v.anew(asmType);
|
||||||
v.dup();
|
v.dup();
|
||||||
|
|
||||||
codegen.pushClosureOnStack(closure, false);
|
codegen.pushClosureOnStack(closure, false);
|
||||||
v.invokespecial(name.getInternalName(), "<init>", constructor.getDescriptor());
|
v.invokespecial(asmType.getInternalName(), "<init>", constructor.getDescriptor());
|
||||||
}
|
}
|
||||||
return StackValue.onStack(asmType);
|
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);
|
MethodVisitor mv = cv.newMethod(fun, ACC_STATIC | ACC_SYNTHETIC, "<clinit>", "()V", null, ArrayUtil.EMPTY_STRING_ARRAY);
|
||||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
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) {
|
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
||||||
genStubCode(mv);
|
genStubCode(mv);
|
||||||
}
|
}
|
||||||
else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
genInitSingletonField(name.getAsmType(), iv);
|
genInitSingletonField(asmType, iv);
|
||||||
mv.visitInsn(RETURN);
|
mv.visitInsn(RETURN);
|
||||||
FunctionCodegen.endVisit(mv, "<clinit>", fun);
|
FunctionCodegen.endVisit(mv, "<clinit>", fun);
|
||||||
}
|
}
|
||||||
@@ -192,7 +191,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
|||||||
|
|
||||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||||
|
|
||||||
iv.load(0, name.getAsmType());
|
iv.load(0, asmType);
|
||||||
|
|
||||||
ReceiverParameterDescriptor receiver = funDescriptor.getReceiverParameter();
|
ReceiverParameterDescriptor receiver = funDescriptor.getReceiverParameter();
|
||||||
int count = 1;
|
int count = 1;
|
||||||
@@ -207,7 +206,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
|||||||
count++;
|
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);
|
StackValue.onStack(delegate.getReturnType()).put(bridge.getReturnType(), iv);
|
||||||
|
|
||||||
iv.areturn(bridge.getReturnType());
|
iv.areturn(bridge.getReturnType());
|
||||||
@@ -218,7 +217,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Method generateConstructor(@NotNull ClassBuilder cv) {
|
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);
|
Type[] argTypes = fieldListToTypeArray(args);
|
||||||
|
|
||||||
|
|||||||
@@ -532,17 +532,15 @@ public class FunctionCodegen extends GenerationStateAware {
|
|||||||
|
|
||||||
int flags = ACC_PUBLIC | ACC_SYNTHETIC; // TODO.
|
int flags = ACC_PUBLIC | ACC_SYNTHETIC; // TODO.
|
||||||
|
|
||||||
JvmClassName ownerInternalName;
|
Type ownerType;
|
||||||
if (contextClass instanceof NamespaceDescriptor) {
|
if (contextClass instanceof NamespaceDescriptor) {
|
||||||
ownerInternalName = state.getTypeMapper().getOwner(functionDescriptor, kind, true);
|
ownerType = state.getTypeMapper().getOwner(functionDescriptor, kind, true).getAsmType();
|
||||||
}
|
}
|
||||||
else if (contextClass instanceof ClassDescriptor) {
|
else if (contextClass instanceof ClassDescriptor) {
|
||||||
ownerInternalName = JvmClassName.byType(state.getTypeMapper()
|
ownerType = state.getTypeMapper().mapType(((ClassDescriptor) contextClass).getDefaultType(), JetTypeMapperMode.IMPL);
|
||||||
.mapType(((ClassDescriptor) contextClass).getDefaultType(),
|
|
||||||
JetTypeMapperMode.IMPL));
|
|
||||||
}
|
}
|
||||||
else if (isLocalNamedFun(functionDescriptor)) {
|
else if (isLocalNamedFun(functionDescriptor)) {
|
||||||
ownerInternalName = classNameForAnonymousClass(state.getBindingContext(), functionDescriptor);
|
ownerType = classNameForAnonymousClass(state.getBindingContext(), functionDescriptor).getAsmType();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalStateException("Couldn't obtain owner name for " + functionDescriptor);
|
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)");
|
String descriptor = jvmSignature.getDescriptor().replace(")", "I)");
|
||||||
boolean isConstructor = "<init>".equals(jvmSignature.getName());
|
boolean isConstructor = "<init>".equals(jvmSignature.getName());
|
||||||
if (!isStatic && !isConstructor) {
|
if (!isStatic && !isConstructor) {
|
||||||
descriptor = descriptor.replace("(", "(" + ownerInternalName.getDescriptor());
|
descriptor = descriptor.replace("(", "(" + ownerType.getDescriptor());
|
||||||
}
|
}
|
||||||
MethodVisitor mv = v.newMethod(null, flags | (isConstructor ? 0 : ACC_STATIC),
|
MethodVisitor mv = v.newMethod(null, flags | (isConstructor ? 0 : ACC_STATIC),
|
||||||
isConstructor ? "<init>" : jvmSignature.getName() + JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX,
|
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) {
|
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.visit(JvmAnnotationNames.ABI_VERSION_FIELD_NAME, JvmAbi.VERSION);
|
||||||
av.visitEnd();
|
av.visitEnd();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,10 +182,9 @@ public class ScriptCodegen extends MemberCodegen {
|
|||||||
|
|
||||||
private void genFieldsForParameters(@NotNull ScriptDescriptor script, @NotNull ClassBuilder classBuilder) {
|
private void genFieldsForParameters(@NotNull ScriptDescriptor script, @NotNull ClassBuilder classBuilder) {
|
||||||
for (ScriptDescriptor earlierScript : earlierScripts) {
|
for (ScriptDescriptor earlierScript : earlierScripts) {
|
||||||
JvmClassName earlierClassName;
|
JvmClassName earlierClassName = classNameForScriptDescriptor(bindingContext, earlierScript);
|
||||||
earlierClassName = classNameForScriptDescriptor(bindingContext, earlierScript);
|
|
||||||
int access = ACC_PRIVATE | ACC_FINAL;
|
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()) {
|
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.psi.JetSimpleNameExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
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.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.KotlinBuiltIns;
|
||||||
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.codegen.AsmUtil.asmDescByFqNameWithoutInnerClasses;
|
||||||
|
|
||||||
public class ArrayIterator implements IntrinsicMethod {
|
public class ArrayIterator implements IntrinsicMethod {
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public StackValue generate(
|
||||||
@@ -58,18 +60,18 @@ public class ArrayIterator implements IntrinsicMethod {
|
|||||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Ljava/lang/Object;)Ljava/util/Iterator;");
|
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Ljava/lang/Object;)Ljava/util/Iterator;");
|
||||||
return StackValue.onStack(AsmTypeConstants.JET_ITERATOR_TYPE);
|
return StackValue.onStack(AsmTypeConstants.JET_ITERATOR_TYPE);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||||
ClassDescriptor arrayClass = KotlinBuiltIns.getInstance().getPrimitiveArrayClassDescriptor(primitiveType);
|
ClassDescriptor arrayClass = KotlinBuiltIns.getInstance().getPrimitiveArrayClassDescriptor(primitiveType);
|
||||||
if (containingDeclaration.equals(arrayClass)) {
|
if (containingDeclaration.equals(arrayClass)) {
|
||||||
JvmClassName iterator = JvmClassName.byFqNameWithoutInnerClasses("jet." + primitiveType.getTypeName() + "Iterator");
|
String iteratorDesc = asmDescByFqNameWithoutInnerClasses(new FqName("jet." + primitiveType.getTypeName() + "Iterator"));
|
||||||
String methodSignature = "([" + jvmPrimitiveType.getAsmType() + ")" + iterator.getDescriptor();
|
String methodSignature = "([" + jvmPrimitiveType.getAsmType() + ")" + iteratorDesc;
|
||||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature);
|
v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature);
|
||||||
return StackValue.onStack(iterator.getAsmType());
|
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 final String internalName;
|
||||||
private FqName fqName;
|
private FqName fqName;
|
||||||
private String descriptor;
|
|
||||||
private Type asmType;
|
private Type asmType;
|
||||||
|
|
||||||
private JvmClassName(@NotNull String internalName) {
|
private JvmClassName(@NotNull String internalName) {
|
||||||
@@ -101,18 +100,10 @@ public class JvmClassName {
|
|||||||
return internalName;
|
return internalName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public String getDescriptor() {
|
|
||||||
if (descriptor == null) {
|
|
||||||
descriptor = "L" + internalName + ';';
|
|
||||||
}
|
|
||||||
return descriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Type getAsmType() {
|
public Type getAsmType() {
|
||||||
if (asmType == null) {
|
if (asmType == null) {
|
||||||
asmType = Type.getType(getDescriptor());
|
asmType = Type.getType("L" + internalName + ';');
|
||||||
}
|
}
|
||||||
return asmType;
|
return asmType;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user