optimized bytecode of is
This commit is contained in:
@@ -2445,18 +2445,28 @@ If finally block is present, its last expression is the value of try expression.
|
|||||||
return StackValue.onStack(Type.BOOLEAN_TYPE);
|
return StackValue.onStack(Type.BOOLEAN_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasTypeInfoForInstanceOf(JetType type) {
|
||||||
|
DeclarationDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor();
|
||||||
|
if(declarationDescriptor instanceof TypeParameterDescriptor)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor.getOriginal();
|
||||||
|
if(classDescriptor.equals(state.getStandardLibrary().getArray())) {
|
||||||
|
return hasTypeInfoForInstanceOf(type.getArguments().get(0).getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
for(TypeParameterDescriptor proj : classDescriptor.getTypeConstructor().getParameters()) {
|
||||||
|
if(proj.isReified()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void generateInstanceOf(StackValue expressionToGen, JetType jetType, boolean leaveExpressionOnStack) {
|
private void generateInstanceOf(StackValue expressionToGen, JetType jetType, boolean leaveExpressionOnStack) {
|
||||||
DeclarationDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
|
DeclarationDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
|
||||||
boolean javaClass = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, descriptor) instanceof PsiClass;
|
if (!hasTypeInfoForInstanceOf(jetType)) {
|
||||||
if (!javaClass && (jetType.getArguments().size() > 0 || !(descriptor instanceof ClassDescriptor))) {
|
|
||||||
generateTypeInfo(jetType);
|
|
||||||
expressionToGen.put(OBJECT_TYPE, v);
|
|
||||||
if (leaveExpressionOnStack) {
|
|
||||||
v.dupX1();
|
|
||||||
}
|
|
||||||
v.invokevirtual("jet/typeinfo/TypeInfo", "isInstance", "(Ljava/lang/Object;)Z");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
expressionToGen.put(OBJECT_TYPE, v);
|
expressionToGen.put(OBJECT_TYPE, v);
|
||||||
if (leaveExpressionOnStack) {
|
if (leaveExpressionOnStack) {
|
||||||
v.dup();
|
v.dup();
|
||||||
@@ -2479,6 +2489,14 @@ If finally block is present, its last expression is the value of try expression.
|
|||||||
v.instanceOf(type);
|
v.instanceOf(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
generateTypeInfo(jetType);
|
||||||
|
expressionToGen.put(OBJECT_TYPE, v);
|
||||||
|
if (leaveExpressionOnStack) {
|
||||||
|
v.dupX1();
|
||||||
|
}
|
||||||
|
v.invokevirtual("jet/typeinfo/TypeInfo", "isInstance", "(Ljava/lang/Object;)Z");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateTypeInfo(JetType jetType) {
|
public void generateTypeInfo(JetType jetType) {
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ public class JetStandardLibrary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ClassDescriptor getArray() {
|
public ClassDescriptor getArray() {
|
||||||
initStdClasses();
|
initStdClasses();
|
||||||
return arrayClass;
|
return arrayClass;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -278,6 +278,7 @@ public class ArrayGenTest extends CodegenTestCase {
|
|||||||
|
|
||||||
public void testKt602() {
|
public void testKt602() {
|
||||||
blackBoxFile("regressions/kt602.jet");
|
blackBoxFile("regressions/kt602.jet");
|
||||||
|
System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt594() throws Exception {
|
public void testKt594() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user