From 8b823d83ef58fe95890cdde2e7533bb60cdd2d8a Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 12 Jul 2011 13:10:16 +0200 Subject: [PATCH] generate typeinfo() function with one argument --- .../jet/codegen/ExpressionCodegen.java | 16 +++++++++++++++ .../jet/lang/types/JetStandardLibrary.java | 20 +++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index f5ae48e8cd1..ab362550b7a 100644 --- a/idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/idea/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -794,6 +794,10 @@ public class ExpressionCodegen extends JetVisitor { return; } } + if (state.getStandardLibrary().getTypeInfoFunctionGroup().getFunctionDescriptors().contains(funDescriptor.getOriginal())) { + generateTypeInfoCall(expression); + return; + } final FunctionDescriptor fd = (FunctionDescriptor) funDescriptor; PsiElement declarationPsiElement = resolveCalleeToDeclaration(funDescriptor); @@ -820,6 +824,18 @@ public class ExpressionCodegen extends JetVisitor { } } + private void generateTypeInfoCall(JetCallExpression expression) { + final List 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) { PsiElement declarationPsiElement = bindingContext.getDeclarationPsiElement(funDescriptor); if (declarationPsiElement == null && isClass(funDescriptor.getContainingDeclaration(), "String")) { diff --git a/idea/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java b/idea/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java index 420e97938d7..84e6cbf549d 100644 --- a/idea/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java +++ b/idea/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java @@ -6,8 +6,7 @@ import com.intellij.psi.PsiFileFactory; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.ErrorHandler; import org.jetbrains.jet.lang.JetSemanticServices; -import org.jetbrains.jet.lang.descriptors.Annotation; -import org.jetbrains.jet.lang.descriptors.ClassDescriptor; +import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.plugin.JetFileType; @@ -25,7 +24,7 @@ public class JetStandardLibrary { // TODO : consider releasing this memory private static JetStandardLibrary cachedLibrary = null; -// private static final Map standardLibraryCache = new HashMap(); + // private static final Map standardLibraryCache = new HashMap(); // TODO : double checked locking synchronized public static JetStandardLibrary getJetStandardLibrary(@NotNull Project project) { @@ -67,6 +66,9 @@ public class JetStandardLibrary { private final JetType stringType; private final JetType nullableStringType; + private final NamespaceDescriptor typeInfoNamespace; + private final FunctionGroup typeInfoFunction; + private JetStandardLibrary(@NotNull Project project) { // TODO : review InputStream stream = JetStandardClasses.class.getClassLoader().getResourceAsStream("jet/Library.jet"); @@ -96,7 +98,9 @@ public class JetStandardLibrary { this.stringClass = (ClassDescriptor) libraryScope.getClassifier("String"); this.arrayClass = (ClassDescriptor) libraryScope.getClassifier("Array"); 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.charType = new JetTypeImpl(getChar()); @@ -172,10 +176,18 @@ public class JetStandardLibrary { return iterableClass; } + public NamespaceDescriptor getTypeInfoNamespace() { + return typeInfoNamespace; + } + public ClassDescriptor getTypeInfo() { return typeInfoClass; } + public FunctionGroup getTypeInfoFunctionGroup() { + return typeInfoFunction; + } + @NotNull public JetType getTypeInfoType(@NotNull JetType type) { TypeProjection typeProjection = new TypeProjection(type);