generate typeinfo() function with one argument
This commit is contained in:
@@ -794,6 +794,10 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (state.getStandardLibrary().getTypeInfoFunctionGroup().getFunctionDescriptors().contains(funDescriptor.getOriginal())) {
|
||||||
|
generateTypeInfoCall(expression);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final FunctionDescriptor fd = (FunctionDescriptor) funDescriptor;
|
final FunctionDescriptor fd = (FunctionDescriptor) funDescriptor;
|
||||||
PsiElement declarationPsiElement = resolveCalleeToDeclaration(funDescriptor);
|
PsiElement declarationPsiElement = resolveCalleeToDeclaration(funDescriptor);
|
||||||
@@ -820,6 +824,18 @@ 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;");
|
||||||
|
myStack.push(StackValue.onStack(JetTypeMapper.TYPE_TYPEINFO));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new UnsupportedOperationException("only one-arg form of typeinfo() is now supported");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private PsiElement resolveCalleeToDeclaration(DeclarationDescriptor funDescriptor) {
|
private PsiElement resolveCalleeToDeclaration(DeclarationDescriptor funDescriptor) {
|
||||||
PsiElement declarationPsiElement = bindingContext.getDeclarationPsiElement(funDescriptor);
|
PsiElement declarationPsiElement = bindingContext.getDeclarationPsiElement(funDescriptor);
|
||||||
if (declarationPsiElement == null && isClass(funDescriptor.getContainingDeclaration(), "String")) {
|
if (declarationPsiElement == null && isClass(funDescriptor.getContainingDeclaration(), "String")) {
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ import com.intellij.psi.PsiFileFactory;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.ErrorHandler;
|
import org.jetbrains.jet.lang.ErrorHandler;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||||
import org.jetbrains.jet.lang.descriptors.Annotation;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.*;
|
import org.jetbrains.jet.lang.resolve.*;
|
||||||
import org.jetbrains.jet.plugin.JetFileType;
|
import org.jetbrains.jet.plugin.JetFileType;
|
||||||
@@ -25,7 +24,7 @@ public class JetStandardLibrary {
|
|||||||
|
|
||||||
// TODO : consider releasing this memory
|
// TODO : consider releasing this memory
|
||||||
private static JetStandardLibrary cachedLibrary = null;
|
private static JetStandardLibrary cachedLibrary = null;
|
||||||
// private static final Map<Project, JetStandardLibrary> standardLibraryCache = new HashMap<Project, JetStandardLibrary>();
|
// private static final Map<Project, JetStandardLibrary> standardLibraryCache = new HashMap<Project, JetStandardLibrary>();
|
||||||
|
|
||||||
// TODO : double checked locking
|
// TODO : double checked locking
|
||||||
synchronized public static JetStandardLibrary getJetStandardLibrary(@NotNull Project project) {
|
synchronized public static JetStandardLibrary getJetStandardLibrary(@NotNull Project project) {
|
||||||
@@ -67,6 +66,9 @@ public class JetStandardLibrary {
|
|||||||
private final JetType stringType;
|
private final JetType stringType;
|
||||||
private final JetType nullableStringType;
|
private final JetType nullableStringType;
|
||||||
|
|
||||||
|
private final NamespaceDescriptor typeInfoNamespace;
|
||||||
|
private final FunctionGroup typeInfoFunction;
|
||||||
|
|
||||||
private JetStandardLibrary(@NotNull Project project) {
|
private JetStandardLibrary(@NotNull Project project) {
|
||||||
// TODO : review
|
// TODO : review
|
||||||
InputStream stream = JetStandardClasses.class.getClassLoader().getResourceAsStream("jet/Library.jet");
|
InputStream stream = JetStandardClasses.class.getClassLoader().getResourceAsStream("jet/Library.jet");
|
||||||
@@ -96,7 +98,9 @@ public class JetStandardLibrary {
|
|||||||
this.stringClass = (ClassDescriptor) libraryScope.getClassifier("String");
|
this.stringClass = (ClassDescriptor) libraryScope.getClassifier("String");
|
||||||
this.arrayClass = (ClassDescriptor) libraryScope.getClassifier("Array");
|
this.arrayClass = (ClassDescriptor) libraryScope.getClassifier("Array");
|
||||||
this.iterableClass = (ClassDescriptor) libraryScope.getClassifier("Iterable");
|
this.iterableClass = (ClassDescriptor) libraryScope.getClassifier("Iterable");
|
||||||
this.typeInfoClass = (ClassDescriptor) libraryScope.getNamespace("typeinfo").getMemberScope().getClassifier("TypeInfo");
|
typeInfoNamespace = libraryScope.getNamespace("typeinfo");
|
||||||
|
this.typeInfoClass = (ClassDescriptor) typeInfoNamespace.getMemberScope().getClassifier("TypeInfo");
|
||||||
|
typeInfoFunction = typeInfoNamespace.getMemberScope().getFunctionGroup("typeinfo");
|
||||||
|
|
||||||
this.byteType = new JetTypeImpl(getByte());
|
this.byteType = new JetTypeImpl(getByte());
|
||||||
this.charType = new JetTypeImpl(getChar());
|
this.charType = new JetTypeImpl(getChar());
|
||||||
@@ -172,10 +176,18 @@ public class JetStandardLibrary {
|
|||||||
return iterableClass;
|
return iterableClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NamespaceDescriptor getTypeInfoNamespace() {
|
||||||
|
return typeInfoNamespace;
|
||||||
|
}
|
||||||
|
|
||||||
public ClassDescriptor getTypeInfo() {
|
public ClassDescriptor getTypeInfo() {
|
||||||
return typeInfoClass;
|
return typeInfoClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FunctionGroup getTypeInfoFunctionGroup() {
|
||||||
|
return typeInfoFunction;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType getTypeInfoType(@NotNull JetType type) {
|
public JetType getTypeInfoType(@NotNull JetType type) {
|
||||||
TypeProjection typeProjection = new TypeProjection(type);
|
TypeProjection typeProjection = new TypeProjection(type);
|
||||||
|
|||||||
Reference in New Issue
Block a user