string plus is an intrinsic
This commit is contained in:
@@ -35,7 +35,7 @@ import java.util.*;
|
|||||||
public class ExpressionCodegen extends JetVisitor {
|
public class ExpressionCodegen extends JetVisitor {
|
||||||
private static final String CLASS_OBJECT = "java/lang/Object";
|
private static final String CLASS_OBJECT = "java/lang/Object";
|
||||||
private static final String CLASS_STRING = "java/lang/String";
|
private static final String CLASS_STRING = "java/lang/String";
|
||||||
private static final String CLASS_STRING_BUILDER = "java/lang/StringBuilder";
|
public static final String CLASS_STRING_BUILDER = "java/lang/StringBuilder";
|
||||||
private static final String CLASS_COMPARABLE = "java/lang/Comparable";
|
private static final String CLASS_COMPARABLE = "java/lang/Comparable";
|
||||||
private static final String CLASS_ITERABLE = "java/lang/Iterable";
|
private static final String CLASS_ITERABLE = "java/lang/Iterable";
|
||||||
private static final String CLASS_ITERATOR = "java/util/Iterator";
|
private static final String CLASS_ITERATOR = "java/util/Iterator";
|
||||||
@@ -1085,11 +1085,6 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
Arrays.asList(expression.getLeft(), expression.getRight())));
|
Arrays.asList(expression.getLeft(), expression.getRight())));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DeclarationDescriptor cls = op.getContainingDeclaration();
|
|
||||||
if (isClass(cls, "String") && op.getName().equals("plus")) {
|
|
||||||
generateConcatenation(expression);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
throw new UnsupportedOperationException("Don't know how to generate binary op " + expression);
|
throw new UnsupportedOperationException("Don't know how to generate binary op " + expression);
|
||||||
}
|
}
|
||||||
@@ -1289,15 +1284,7 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateConcatenation(JetBinaryExpression expression) {
|
public void generateStringBuilderConstructor() {
|
||||||
generateStringBuilderConstructor();
|
|
||||||
invokeAppend(expression.getLeft());
|
|
||||||
invokeAppend(expression.getRight());
|
|
||||||
v.invokevirtual(CLASS_STRING_BUILDER, "toString", "()Ljava/lang/String;");
|
|
||||||
myStack.push(StackValue.onStack(Type.getObjectType(CLASS_STRING)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateStringBuilderConstructor() {
|
|
||||||
Type type = Type.getObjectType(CLASS_STRING_BUILDER);
|
Type type = Type.getObjectType(CLASS_STRING_BUILDER);
|
||||||
v.anew(type);
|
v.anew(type);
|
||||||
v.dup();
|
v.dup();
|
||||||
@@ -1305,7 +1292,7 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
v.invokespecial(CLASS_STRING_BUILDER, method.getName(), method.getDescriptor());
|
v.invokespecial(CLASS_STRING_BUILDER, method.getName(), method.getDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void invokeAppend(final JetExpression expr) {
|
public void invokeAppend(final JetExpression expr) {
|
||||||
if (expr instanceof JetBinaryExpression) {
|
if (expr instanceof JetBinaryExpression) {
|
||||||
final JetBinaryExpression binaryExpression = (JetBinaryExpression) expr;
|
final JetBinaryExpression binaryExpression = (JetBinaryExpression) expr;
|
||||||
if (binaryExpression.getOperationToken() == JetTokens.PLUS) {
|
if (binaryExpression.getOperationToken() == JetTokens.PLUS) {
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package org.jetbrains.jet.codegen.intrinsics;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
import org.objectweb.asm.commons.InstructionAdapter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yole
|
||||||
|
*/
|
||||||
|
public class Concat implements IntrinsicMethod {
|
||||||
|
@Override
|
||||||
|
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, PsiElement element, List<JetExpression> arguments) {
|
||||||
|
codegen.generateStringBuilderConstructor();
|
||||||
|
codegen.invokeAppend(arguments.get(0));
|
||||||
|
codegen.invokeAppend(arguments.get(1));
|
||||||
|
v.invokevirtual(ExpressionCodegen.CLASS_STRING_BUILDER, "toString", "()Ljava/lang/String;");
|
||||||
|
return StackValue.onStack(Type.getObjectType("java/lang/String"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,7 +19,6 @@ import java.util.Map;
|
|||||||
public class IntrinsicMethods {
|
public class IntrinsicMethods {
|
||||||
private static final IntrinsicMethod UNARY_MINUS = new UnaryMinus();
|
private static final IntrinsicMethod UNARY_MINUS = new UnaryMinus();
|
||||||
private static final IntrinsicMethod NUMBER_CAST = new NumberCast();
|
private static final IntrinsicMethod NUMBER_CAST = new NumberCast();
|
||||||
private static final IntrinsicMethod ARRAY_SIZE = new ArraySize();
|
|
||||||
private static final IntrinsicMethod INV = new Inv();
|
private static final IntrinsicMethod INV = new Inv();
|
||||||
private static final IntrinsicMethod TYPEINFO = new TypeInfo();
|
private static final IntrinsicMethod TYPEINFO = new TypeInfo();
|
||||||
private static final IntrinsicMethod VALUE_TYPEINFO = new ValueTypeInfo();
|
private static final IntrinsicMethod VALUE_TYPEINFO = new ValueTypeInfo();
|
||||||
@@ -35,7 +34,7 @@ public class IntrinsicMethods {
|
|||||||
for (String method : primitiveCastMethods) {
|
for (String method : primitiveCastMethods) {
|
||||||
declareIntrinsicProperty("Number", method, NUMBER_CAST);
|
declareIntrinsicProperty("Number", method, NUMBER_CAST);
|
||||||
}
|
}
|
||||||
declareIntrinsicProperty("Array", "size", ARRAY_SIZE);
|
declareIntrinsicProperty("Array", "size", new ArraySize());
|
||||||
|
|
||||||
for (String primitiveNumberType : PRIMITIVE_NUMBER_TYPES) {
|
for (String primitiveNumberType : PRIMITIVE_NUMBER_TYPES) {
|
||||||
declareIntrinsicFunction(primitiveNumberType, "minus", 0, UNARY_MINUS);
|
declareIntrinsicFunction(primitiveNumberType, "minus", 0, UNARY_MINUS);
|
||||||
@@ -57,6 +56,8 @@ public class IntrinsicMethods {
|
|||||||
declareBinaryOp("and", Opcodes.IAND);
|
declareBinaryOp("and", Opcodes.IAND);
|
||||||
declareBinaryOp("or", Opcodes.IOR);
|
declareBinaryOp("or", Opcodes.IOR);
|
||||||
declareBinaryOp("xor", Opcodes.IXOR);
|
declareBinaryOp("xor", Opcodes.IXOR);
|
||||||
|
|
||||||
|
declareIntrinsicFunction("String", "plus", 1, new Concat());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void declareBinaryOp(String methodName, int opcode) {
|
private void declareBinaryOp(String methodName, int opcode) {
|
||||||
|
|||||||
Reference in New Issue
Block a user