String.length property added

This commit is contained in:
Alex Tkachman
2011-08-31 11:01:28 +02:00
parent f01c424eb5
commit 1a62b8c0bd
2 changed files with 24 additions and 0 deletions
@@ -72,6 +72,7 @@ public class IntrinsicMethods {
declareIntrinsicFunction("String", "plus", 1, new Concat());
declareIntrinsicStringMethods();
declareIntrinsicProperty("String", "length", new StringLength());
}
private void declareIntrinsicStringMethods() {
@@ -0,0 +1,23 @@
package org.jetbrains.jet.codegen.intrinsics;
import com.intellij.psi.PsiElement;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.JetTypeMapper;
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 alex.tkachman
*/
public class StringLength implements IntrinsicMethod {
@Override
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, PsiElement element, List<JetExpression> arguments, StackValue receiver) {
receiver.put(JetTypeMapper.TYPE_OBJECT, v);
v.invokevirtual("java/lang/String", "length", "()I");
return StackValue.onStack(Type.INT_TYPE);
}
}