removing unnneded InstructionAdapterEx
This commit is contained in:
@@ -49,7 +49,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
|
|
||||||
private int myLastLineNumber = -1;
|
private int myLastLineNumber = -1;
|
||||||
|
|
||||||
private final InstructionAdapterEx v;
|
private final InstructionAdapter v;
|
||||||
private final FrameMap myMap;
|
private final FrameMap myMap;
|
||||||
private final JetTypeMapper typeMapper;
|
private final JetTypeMapper typeMapper;
|
||||||
private final GenerationState state;
|
private final GenerationState state;
|
||||||
@@ -68,7 +68,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
this.typeMapper = state.getTypeMapper();
|
this.typeMapper = state.getTypeMapper();
|
||||||
this.returnType = returnType;
|
this.returnType = returnType;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.v = new InstructionAdapterEx(v);
|
this.v = new InstructionAdapter(v);
|
||||||
this.bindingContext = state.getBindingContext();
|
this.bindingContext = state.getBindingContext();
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.intrinsics = state.getIntrinsics();
|
this.intrinsics = state.getIntrinsics();
|
||||||
@@ -773,7 +773,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
return myMap.getIndex(descriptor);
|
return myMap.getIndex(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invokeFunctionNoParams(FunctionDescriptor functionDescriptor, Type type, InstructionAdapterEx v) {
|
public void invokeFunctionNoParams(FunctionDescriptor functionDescriptor, Type type, InstructionAdapter v) {
|
||||||
DeclarationDescriptor containingDeclaration = functionDescriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = functionDescriptor.getContainingDeclaration();
|
||||||
boolean isStatic = containingDeclaration instanceof NamespaceDescriptorImpl;
|
boolean isStatic = containingDeclaration instanceof NamespaceDescriptorImpl;
|
||||||
functionDescriptor = functionDescriptor.getOriginal();
|
functionDescriptor = functionDescriptor.getOriginal();
|
||||||
@@ -1085,7 +1085,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
Type type = propValue.type;
|
Type type = propValue.type;
|
||||||
propValue.put(type, v);
|
propValue.put(type, v);
|
||||||
if(JetTypeMapper.isPrimitive(type) && !type.equals(Type.VOID_TYPE)) {
|
if(JetTypeMapper.isPrimitive(type) && !type.equals(Type.VOID_TYPE)) {
|
||||||
v.valueOf(type);
|
StackValue.valueOf(v, type);
|
||||||
type = JetTypeMapper.boxType(type);
|
type = JetTypeMapper.boxType(type);
|
||||||
}
|
}
|
||||||
v.goTo(end);
|
v.goTo(end);
|
||||||
@@ -1265,10 +1265,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
|
|
||||||
if(JetTypeMapper.isPrimitive(leftType) != JetTypeMapper.isPrimitive(rightType)) {
|
if(JetTypeMapper.isPrimitive(leftType) != JetTypeMapper.isPrimitive(rightType)) {
|
||||||
gen(left, leftType);
|
gen(left, leftType);
|
||||||
v.valueOf(leftType);
|
StackValue.valueOf(v, leftType);
|
||||||
leftType = JetTypeMapper.boxType(leftType);
|
leftType = JetTypeMapper.boxType(leftType);
|
||||||
gen(right, rightType);
|
gen(right, rightType);
|
||||||
v.valueOf(rightType);
|
StackValue.valueOf(v, rightType);
|
||||||
rightType = JetTypeMapper.boxType(rightType);
|
rightType = JetTypeMapper.boxType(rightType);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -55,17 +55,18 @@ public class FunctionCodegen {
|
|||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
|
|
||||||
Type[] argTypes = function.getArgumentTypes();
|
Type[] argTypes = function.getArgumentTypes();
|
||||||
InstructionAdapterEx iv = new InstructionAdapterEx(mv);
|
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||||
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||||
for (int i = 0, reg = 1; i < argTypes.length; i++) {
|
for (int i = 0, reg = 1; i < argTypes.length; i++) {
|
||||||
Type argType = argTypes[i];
|
Type argType = argTypes[i];
|
||||||
iv.load(reg, argType);
|
iv.load(reg, argType);
|
||||||
|
//noinspection AssignmentToForLoopParameter
|
||||||
reg += argType.getSize();
|
reg += argType.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
iv.invokevirtual(state.getTypeMapper().jvmName((ClassDescriptor) owner.getContextDescriptor(), OwnerKind.IMPLEMENTATION), function.getName(), function.getDescriptor());
|
iv.invokevirtual(state.getTypeMapper().jvmName((ClassDescriptor) owner.getContextDescriptor(), OwnerKind.IMPLEMENTATION), function.getName(), function.getDescriptor());
|
||||||
if(JetTypeMapper.isPrimitive(function.getReturnType()) && !JetTypeMapper.isPrimitive(overriden.getReturnType()))
|
if(JetTypeMapper.isPrimitive(function.getReturnType()) && !JetTypeMapper.isPrimitive(overriden.getReturnType()))
|
||||||
iv.valueOf(function.getReturnType());
|
StackValue.valueOf(iv, function.getReturnType());
|
||||||
if(function.getReturnType() == Type.VOID_TYPE)
|
if(function.getReturnType() == Type.VOID_TYPE)
|
||||||
iv.aconst(null);
|
iv.aconst(null);
|
||||||
iv.areturn(overriden.getReturnType());
|
iv.areturn(overriden.getReturnType());
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
|
||||||
|
|
||||||
import org.objectweb.asm.MethodVisitor;
|
|
||||||
import org.objectweb.asm.Opcodes;
|
|
||||||
import org.objectweb.asm.Type;
|
|
||||||
import org.objectweb.asm.commons.InstructionAdapter;
|
|
||||||
import org.objectweb.asm.commons.Method;
|
|
||||||
|
|
||||||
public class InstructionAdapterEx extends InstructionAdapter {
|
|
||||||
private static final Method BOOLEAN_VALUE = Method.getMethod("boolean booleanValue()");
|
|
||||||
|
|
||||||
private static final Method CHAR_VALUE = Method.getMethod("char charValue()");
|
|
||||||
|
|
||||||
private static final Method INT_VALUE = Method.getMethod("int intValue()");
|
|
||||||
|
|
||||||
private static final Method FLOAT_VALUE = Method.getMethod("float floatValue()");
|
|
||||||
|
|
||||||
private static final Method LONG_VALUE = Method.getMethod("long longValue()");
|
|
||||||
|
|
||||||
private static final Method DOUBLE_VALUE = Method.getMethod("double doubleValue()");
|
|
||||||
|
|
||||||
public InstructionAdapterEx(MethodVisitor methodVisitor) {
|
|
||||||
super(methodVisitor);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Type getBoxedType(final Type type) {
|
|
||||||
switch (type.getSort()) {
|
|
||||||
case Type.BYTE:
|
|
||||||
return JetTypeMapper.JL_BYTE_TYPE;
|
|
||||||
case Type.BOOLEAN:
|
|
||||||
return JetTypeMapper.JL_BOOLEAN_TYPE;
|
|
||||||
case Type.SHORT:
|
|
||||||
return JetTypeMapper.JL_SHORT_TYPE;
|
|
||||||
case Type.CHAR:
|
|
||||||
return JetTypeMapper.JL_CHAR_TYPE;
|
|
||||||
case Type.INT:
|
|
||||||
return JetTypeMapper.JL_INTEGER_TYPE;
|
|
||||||
case Type.FLOAT:
|
|
||||||
return JetTypeMapper.JL_FLOAT_TYPE;
|
|
||||||
case Type.LONG:
|
|
||||||
return JetTypeMapper.JL_LONG_TYPE;
|
|
||||||
case Type.DOUBLE:
|
|
||||||
return JetTypeMapper.JL_DOUBLE_TYPE;
|
|
||||||
}
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void valueOf(final Type type) {
|
|
||||||
if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (type == Type.VOID_TYPE) {
|
|
||||||
aconst(null);
|
|
||||||
} else {
|
|
||||||
Type boxed = getBoxedType(type);
|
|
||||||
invokestatic(boxed.getInternalName(), "valueOf", "(" + type.getDescriptor() + ")" + boxed.getDescriptor());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unbox(final Type type) {
|
|
||||||
Type t = JetTypeMapper.JL_NUMBER_TYPE;
|
|
||||||
Method sig = null;
|
|
||||||
switch (type.getSort()) {
|
|
||||||
case Type.VOID:
|
|
||||||
return;
|
|
||||||
case Type.CHAR:
|
|
||||||
t = JetTypeMapper.JL_CHAR_TYPE;
|
|
||||||
sig = CHAR_VALUE;
|
|
||||||
break;
|
|
||||||
case Type.BOOLEAN:
|
|
||||||
t = JetTypeMapper.JL_BOOLEAN_TYPE;
|
|
||||||
sig = BOOLEAN_VALUE;
|
|
||||||
break;
|
|
||||||
case Type.DOUBLE:
|
|
||||||
sig = DOUBLE_VALUE;
|
|
||||||
break;
|
|
||||||
case Type.FLOAT:
|
|
||||||
sig = FLOAT_VALUE;
|
|
||||||
break;
|
|
||||||
case Type.LONG:
|
|
||||||
sig = LONG_VALUE;
|
|
||||||
break;
|
|
||||||
case Type.INT:
|
|
||||||
case Type.SHORT:
|
|
||||||
case Type.BYTE:
|
|
||||||
sig = INT_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkcast(t);
|
|
||||||
invokevirtual(t.getInternalName(), sig.getName(), sig.getDescriptor());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -173,6 +173,28 @@ public class JetTypeMapper {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Type getBoxedType(final Type type) {
|
||||||
|
switch (type.getSort()) {
|
||||||
|
case Type.BYTE:
|
||||||
|
return JL_BYTE_TYPE;
|
||||||
|
case Type.BOOLEAN:
|
||||||
|
return JL_BOOLEAN_TYPE;
|
||||||
|
case Type.SHORT:
|
||||||
|
return JL_SHORT_TYPE;
|
||||||
|
case Type.CHAR:
|
||||||
|
return JL_CHAR_TYPE;
|
||||||
|
case Type.INT:
|
||||||
|
return JL_INTEGER_TYPE;
|
||||||
|
case Type.FLOAT:
|
||||||
|
return JL_FLOAT_TYPE;
|
||||||
|
case Type.LONG:
|
||||||
|
return JL_LONG_TYPE;
|
||||||
|
case Type.DOUBLE:
|
||||||
|
return JL_DOUBLE_TYPE;
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
public String jvmName(ClassDescriptor jetClass, OwnerKind kind) {
|
public String jvmName(ClassDescriptor jetClass, OwnerKind kind) {
|
||||||
PsiElement declaration = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, jetClass);
|
PsiElement declaration = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, jetClass);
|
||||||
if (declaration instanceof PsiClass) {
|
if (declaration instanceof PsiClass) {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.jetbrains.jet.codegen;
|
|||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JavaClassDescriptor;
|
import org.jetbrains.jet.lang.resolve.java.JavaClassDescriptor;
|
||||||
@@ -69,14 +68,14 @@ public class NamespaceCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasNonConstantPropertyInitializers(namespace, context)) {
|
if (hasNonConstantPropertyInitializers(namespace)) {
|
||||||
generateStaticInitializers(namespace, context);
|
generateStaticInitializers(namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
generateTypeInfoFields(namespace, context);
|
generateTypeInfoFields(namespace, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateStaticInitializers(JetNamespace namespace, ClassContext context) {
|
private void generateStaticInitializers(JetNamespace namespace) {
|
||||||
MethodVisitor mv = v.visitMethod(ACC_PUBLIC | ACC_STATIC,
|
MethodVisitor mv = v.visitMethod(ACC_PUBLIC | ACC_STATIC,
|
||||||
"<clinit>", "()V", null, null);
|
"<clinit>", "()V", null, null);
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
@@ -88,7 +87,7 @@ public class NamespaceCodegen {
|
|||||||
if (declaration instanceof JetProperty) {
|
if (declaration instanceof JetProperty) {
|
||||||
final JetExpression initializer = ((JetProperty) declaration).getInitializer();
|
final JetExpression initializer = ((JetProperty) declaration).getInitializer();
|
||||||
if (initializer != null && !(initializer instanceof JetConstantExpression)) {
|
if (initializer != null && !(initializer instanceof JetConstantExpression)) {
|
||||||
final PropertyDescriptor descriptor = (PropertyDescriptor) state.getBindingContext().get(BindingContext.VARIABLE, (JetProperty) declaration);
|
final PropertyDescriptor descriptor = (PropertyDescriptor) state.getBindingContext().get(BindingContext.VARIABLE, declaration);
|
||||||
codegen.genToJVMStack(initializer);
|
codegen.genToJVMStack(initializer);
|
||||||
codegen.intermediateValueForProperty(descriptor, true, false).store(new InstructionAdapter(mv));
|
codegen.intermediateValueForProperty(descriptor, true, false).store(new InstructionAdapter(mv));
|
||||||
}
|
}
|
||||||
@@ -108,7 +107,7 @@ public class NamespaceCodegen {
|
|||||||
v.visitField(ACC_PRIVATE|ACC_STATIC|ACC_SYNTHETIC, fieldName, "Ljet/typeinfo/TypeInfo;", null, null);
|
v.visitField(ACC_PRIVATE|ACC_STATIC|ACC_SYNTHETIC, fieldName, "Ljet/typeinfo/TypeInfo;", null, null);
|
||||||
|
|
||||||
MethodVisitor mmv = v.visitMethod(ACC_PUBLIC|ACC_STATIC|ACC_SYNTHETIC, "$getCachedTypeInfo$" + e.getValue(), "()Ljet/typeinfo/TypeInfo;", null, null);
|
MethodVisitor mmv = v.visitMethod(ACC_PUBLIC|ACC_STATIC|ACC_SYNTHETIC, "$getCachedTypeInfo$" + e.getValue(), "()Ljet/typeinfo/TypeInfo;", null, null);
|
||||||
InstructionAdapterEx v = new InstructionAdapterEx(mmv);
|
InstructionAdapter v = new InstructionAdapter(mmv);
|
||||||
v.visitFieldInsn(GETSTATIC, jvmClassName, fieldName, "Ljet/typeinfo/TypeInfo;");
|
v.visitFieldInsn(GETSTATIC, jvmClassName, fieldName, "Ljet/typeinfo/TypeInfo;");
|
||||||
v.visitInsn(DUP);
|
v.visitInsn(DUP);
|
||||||
Label end = new Label();
|
Label end = new Label();
|
||||||
@@ -127,7 +126,7 @@ public class NamespaceCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateTypeInfo(ClassContext context, InstructionAdapterEx v, JetType jetType, JetTypeMapper typeMapper, JetType root) {
|
private static void generateTypeInfo(ClassContext context, InstructionAdapter v, JetType jetType, JetTypeMapper typeMapper, JetType root) {
|
||||||
String knownTypeInfo = typeMapper.isKnownTypeInfo(jetType);
|
String knownTypeInfo = typeMapper.isKnownTypeInfo(jetType);
|
||||||
if(knownTypeInfo != null) {
|
if(knownTypeInfo != null) {
|
||||||
v.getstatic("jet/typeinfo/TypeInfo", knownTypeInfo, "Ljet/typeinfo/TypeInfo;");
|
v.getstatic("jet/typeinfo/TypeInfo", knownTypeInfo, "Ljet/typeinfo/TypeInfo;");
|
||||||
@@ -172,7 +171,7 @@ public class NamespaceCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasNonConstantPropertyInitializers(JetNamespace namespace, ClassContext context) {
|
private static boolean hasNonConstantPropertyInitializers(JetNamespace namespace) {
|
||||||
for (JetDeclaration declaration : namespace.getDeclarations()) {
|
for (JetDeclaration declaration : namespace.getDeclarations()) {
|
||||||
if (declaration instanceof JetProperty) {
|
if (declaration instanceof JetProperty) {
|
||||||
final JetExpression initializer = ((JetProperty) declaration).getInitializer();
|
final JetExpression initializer = ((JetProperty) declaration).getInitializer();
|
||||||
|
|||||||
@@ -19,6 +19,18 @@ public abstract class StackValue {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void valueOf(InstructionAdapter instructionAdapter, final Type type) {
|
||||||
|
if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (type == Type.VOID_TYPE) {
|
||||||
|
instructionAdapter.aconst(null);
|
||||||
|
} else {
|
||||||
|
Type boxed = JetTypeMapper.getBoxedType(type);
|
||||||
|
instructionAdapter.invokestatic(boxed.getInternalName(), "valueOf", "(" + type.getDescriptor() + ")" + boxed.getDescriptor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void put(Type type, InstructionAdapter v);
|
public abstract void put(Type type, InstructionAdapter v);
|
||||||
|
|
||||||
public void store(InstructionAdapter v) {
|
public void store(InstructionAdapter v) {
|
||||||
|
|||||||
Reference in New Issue
Block a user