typeinfo() is an intrinsic
This commit is contained in:
@@ -8,7 +8,6 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import gnu.trove.THashSet;
|
||||
import jet.IntRange;
|
||||
import jet.JetObject;
|
||||
import jet.Range;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethod;
|
||||
@@ -59,7 +58,6 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
|
||||
private static final Type RANGE_TYPE = Type.getType(Range.class);
|
||||
private static final Type INT_RANGE_TYPE = Type.getType(IntRange.class);
|
||||
private static final Type JET_OBJECT_TYPE = Type.getType(JetObject.class);
|
||||
|
||||
private final Stack<Label> myContinueTargets = new Stack<Label>();
|
||||
private final Stack<Label> myBreakTargets = new Stack<Label>();
|
||||
@@ -794,12 +792,6 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
return;
|
||||
}
|
||||
|
||||
final DeclarationDescriptor functionParent = funDescriptor.getContainingDeclaration();
|
||||
if (state.getStandardLibrary().getTypeInfoFunctionGroup().getFunctionDescriptors().contains(funDescriptor.getOriginal())) {
|
||||
generateTypeInfoCall(expression);
|
||||
return;
|
||||
}
|
||||
|
||||
final FunctionDescriptor fd = (FunctionDescriptor) funDescriptor;
|
||||
PsiElement declarationPsiElement = resolveCalleeToDeclaration(funDescriptor);
|
||||
|
||||
@@ -825,25 +817,6 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
private void generateTypeInfoCall(JetCallExpression expression) {
|
||||
final List<JetArgument> args = expression.getValueArguments();
|
||||
if (args.size() == 1) {
|
||||
gen(args.get(0).getArgumentExpression(), JET_OBJECT_TYPE);
|
||||
v.invokeinterface("jet/JetObject", "getTypeInfo", "()Ljet/typeinfo/TypeInfo;");
|
||||
}
|
||||
else if (args.size() == 0) {
|
||||
final List<JetTypeProjection> typeArguments = expression.getTypeArguments();
|
||||
if (typeArguments.size() != 1) {
|
||||
throw new UnsupportedOperationException("one type argument expected");
|
||||
}
|
||||
pushTypeArgument(typeArguments.get(0));
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("no such form of typeinfo()");
|
||||
}
|
||||
myStack.push(StackValue.onStack(JetTypeMapper.TYPE_TYPEINFO));
|
||||
}
|
||||
|
||||
private PsiElement resolveCalleeToDeclaration(DeclarationDescriptor funDescriptor) {
|
||||
PsiElement declarationPsiElement = bindingContext.getDeclarationPsiElement(funDescriptor);
|
||||
if (declarationPsiElement == null && isClass(funDescriptor.getContainingDeclaration(), "String")) {
|
||||
@@ -1506,7 +1479,7 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
private void pushTypeArgument(JetTypeProjection jetTypeArgument) {
|
||||
public void pushTypeArgument(JetTypeProjection jetTypeArgument) {
|
||||
JetType typeArgument = bindingContext.resolveTypeReference(jetTypeArgument.getTypeReference());
|
||||
generateTypeInfo(typeArgument);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import jet.JetObject;
|
||||
import jet.typeinfo.TypeInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -20,8 +21,9 @@ import java.util.*;
|
||||
* @author yole
|
||||
*/
|
||||
public class JetTypeMapper {
|
||||
static final Type TYPE_OBJECT = Type.getObjectType("java/lang/Object");
|
||||
static final Type TYPE_TYPEINFO = Type.getType(TypeInfo.class);
|
||||
public static final Type TYPE_OBJECT = Type.getObjectType("java/lang/Object");
|
||||
public static final Type TYPE_TYPEINFO = Type.getType(TypeInfo.class);
|
||||
public static final Type TYPE_JET_OBJECT = Type.getType(JetObject.class);
|
||||
|
||||
private final JetStandardLibrary standardLibrary;
|
||||
private final BindingContext bindingContext;
|
||||
|
||||
@@ -17,6 +17,8 @@ public class IntrinsicMethods {
|
||||
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 TYPEINFO = new TypeInfo();
|
||||
private static final IntrinsicMethod VALUE_TYPEINFO = new ValueTypeInfo();
|
||||
|
||||
private final JetStandardLibrary myStdLib;
|
||||
private final Map<DeclarationDescriptor, IntrinsicMethod> myMethods = new HashMap<DeclarationDescriptor, IntrinsicMethod>();
|
||||
@@ -34,6 +36,10 @@ public class IntrinsicMethods {
|
||||
declareIntrinsicFunction(primitiveNumberType, "minus", 0, UNARY_MINUS);
|
||||
declareIntrinsicFunction(primitiveNumberType, "inv", 0, INV);
|
||||
}
|
||||
|
||||
final FunctionGroup typeInfoFunctionGroup = stdlib.getTypeInfoFunctionGroup();
|
||||
declareOverload(typeInfoFunctionGroup, 0, TYPEINFO);
|
||||
declareOverload(typeInfoFunctionGroup, 1, VALUE_TYPEINFO);
|
||||
}
|
||||
|
||||
private void declareIntrinsicProperty(String className, String methodName, IntrinsicMethod implementation) {
|
||||
@@ -44,8 +50,12 @@ public class IntrinsicMethods {
|
||||
|
||||
private void declareIntrinsicFunction(String className, String functionName, int arity, IntrinsicMethod implementation) {
|
||||
JetScope memberScope = getClassMemberScope(className);
|
||||
final FunctionGroup minus = memberScope.getFunctionGroup(functionName);
|
||||
for (FunctionDescriptor descriptor : minus.getFunctionDescriptors()) {
|
||||
final FunctionGroup group = memberScope.getFunctionGroup(functionName);
|
||||
declareOverload(group, arity, implementation);
|
||||
}
|
||||
|
||||
private void declareOverload(FunctionGroup group, int arity, IntrinsicMethod implementation) {
|
||||
for (FunctionDescriptor descriptor : group.getFunctionDescriptors()) {
|
||||
if (descriptor.getValueParameters().size() == arity) {
|
||||
myMethods.put(descriptor, implementation);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
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.JetCallExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeProjection;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.commons.InstructionAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class TypeInfo implements IntrinsicMethod {
|
||||
@Override
|
||||
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, PsiElement element, List<JetExpression> arguments) {
|
||||
final List<JetTypeProjection> typeArguments = ((JetCallExpression) element).getTypeArguments();
|
||||
if (typeArguments.size() != 1) {
|
||||
throw new UnsupportedOperationException("one type argument expected");
|
||||
}
|
||||
codegen.pushTypeArgument(typeArguments.get(0));
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_TYPEINFO);
|
||||
}
|
||||
}
|
||||
@@ -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 yole
|
||||
*/
|
||||
public class ValueTypeInfo implements IntrinsicMethod {
|
||||
@Override
|
||||
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, PsiElement element, List<JetExpression> arguments) {
|
||||
codegen.gen(arguments.get(0), JetTypeMapper.TYPE_JET_OBJECT);
|
||||
v.invokeinterface("jet/JetObject", "getTypeInfo", "()Ljet/typeinfo/TypeInfo;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_TYPEINFO);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user