Merge remote branch 'origin/master'

This commit is contained in:
Andrey Breslav
2011-05-13 15:23:41 +04:00
27 changed files with 41 additions and 22 deletions
@@ -49,6 +49,7 @@ public class JetStandardLibrary {
private final ClassDescriptor stringClass; private final ClassDescriptor stringClass;
private final ClassDescriptor arrayClass; private final ClassDescriptor arrayClass;
private final ClassDescriptor iterableClass; private final ClassDescriptor iterableClass;
private final ClassDescriptor typeInfoClass;
private final JetType byteType; private final JetType byteType;
private final JetType charType; private final JetType charType;
@@ -89,6 +90,7 @@ 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.getClassifier("TypeInfo");
this.byteType = new JetTypeImpl(getByte()); this.byteType = new JetTypeImpl(getByte());
this.charType = new JetTypeImpl(getChar()); this.charType = new JetTypeImpl(getChar());
@@ -164,6 +166,17 @@ public class JetStandardLibrary {
return iterableClass; return iterableClass;
} }
public ClassDescriptor getTypeInfo() {
return typeInfoClass;
}
@NotNull
public JetType getTypeInfoType(@NotNull JetType type) {
TypeProjection typeProjection = new TypeProjection(type);
List<TypeProjection> arguments = Collections.singletonList(typeProjection);
return new JetTypeImpl(Collections.<Annotation>emptyList(), getTypeInfo().getTypeConstructor(), false, arguments, getTypeInfo().getMemberScope(arguments));
}
@NotNull @NotNull
public JetType getIntType() { public JetType getIntType() {
return intType; return intType;
@@ -820,7 +820,8 @@ public class JetTypeInferrer {
@Override @Override
public void visitTypeofExpression(JetTypeofExpression expression) { public void visitTypeofExpression(JetTypeofExpression expression) {
trace.getErrorHandler().genericError(expression.getNode(), "Return some reflection interface"); // TODO JetType type = safeGetType(scope, expression.getBaseExpression(), false);
result = semanticServices.getStandardLibrary().getTypeInfoType(type);
} }
@Override @Override
@@ -8,7 +8,7 @@ import java.util.List;
*/ */
public class ClassGenTest extends CodegenTestCase { public class ClassGenTest extends CodegenTestCase {
public void testPSVMClass() throws Exception { public void testPSVMClass() throws Exception {
loadFile("simpleClass.jet"); loadFile("classes/simpleClass.jet");
System.out.println(generateToText()); System.out.println(generateToText());
final Class aClass = loadClass("SimpleClass", generateClassesInFile()); final Class aClass = loadClass("SimpleClass", generateClassesInFile());
@@ -17,7 +17,7 @@ public class ClassGenTest extends CodegenTestCase {
} }
public void testArrayListInheritance() throws Exception { public void testArrayListInheritance() throws Exception {
loadFile("inheritingFromArrayList.jet"); loadFile("classes/inheritingFromArrayList.jet");
System.out.println(generateToText()); System.out.println(generateToText());
final Class aClass = loadClass("Foo", generateClassesInFile()); final Class aClass = loadClass("Foo", generateClassesInFile());
@@ -25,15 +25,15 @@ public class ClassGenTest extends CodegenTestCase {
} }
public void testInheritanceAndDelegation_DelegatingDefaultConstructorProperties() throws Exception { public void testInheritanceAndDelegation_DelegatingDefaultConstructorProperties() throws Exception {
blackBoxFile("inheritance.jet"); blackBoxFile("classes/inheritance.jet");
} }
public void testFunDelegation() throws Exception { public void testFunDelegation() throws Exception {
blackBoxFile("funDelegation.jet"); blackBoxFile("classes/funDelegation.jet");
} }
public void testPropertyDelegation() throws Exception { public void testPropertyDelegation() throws Exception {
blackBoxFile("propertyDelegation.jet"); blackBoxFile("classes/propertyDelegation.jet");
} }
private static void checkInterface(Class aClass, Class ifs) { private static void checkInterface(Class aClass, Class ifs) {
@@ -44,7 +44,7 @@ public class ClassGenTest extends CodegenTestCase {
} }
public void testNewInstanceExplicitConstructor() throws Exception { public void testNewInstanceExplicitConstructor() throws Exception {
loadFile("newInstanceDefaultConstructor.jet"); loadFile("classes/newInstanceDefaultConstructor.jet");
System.out.println(generateToText()); System.out.println(generateToText());
final Codegens codegens = generateClassesInFile(); final Codegens codegens = generateClassesInFile();
loadImplementationClass(codegens, "SimpleClass"); loadImplementationClass(codegens, "SimpleClass");
@@ -10,7 +10,7 @@ import java.util.List;
*/ */
public class ControlStructuresTest extends CodegenTestCase { public class ControlStructuresTest extends CodegenTestCase {
public void testIf() throws Exception { public void testIf() throws Exception {
loadFile("if.jet"); loadFile("controlStructures/if.jet");
System.out.println(generateToText()); System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
@@ -19,7 +19,7 @@ public class ControlStructuresTest extends CodegenTestCase {
} }
public void testSingleBranchIf() throws Exception { public void testSingleBranchIf() throws Exception {
loadFile("singleBranchIf.jet"); loadFile("controlStructures/singleBranchIf.jet");
System.out.println(generateToText()); System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
@@ -28,15 +28,15 @@ public class ControlStructuresTest extends CodegenTestCase {
} }
public void testWhile() throws Exception { public void testWhile() throws Exception {
factorialTest("while.jet"); factorialTest("controlStructures/while.jet");
} }
public void testDoWhile() throws Exception { public void testDoWhile() throws Exception {
factorialTest("doWhile.jet"); factorialTest("controlStructures/doWhile.jet");
} }
public void testBreak() throws Exception { public void testBreak() throws Exception {
factorialTest("break.jet"); factorialTest("controlStructures/break.jet");
} }
private void factorialTest(final String name) throws IllegalAccessException, InvocationTargetException { private void factorialTest(final String name) throws IllegalAccessException, InvocationTargetException {
@@ -49,7 +49,7 @@ public class ControlStructuresTest extends CodegenTestCase {
} }
public void testContinue() throws Exception { public void testContinue() throws Exception {
loadFile("continue.jet"); loadFile("controlStructures/continue.jet");
System.out.println(generateToText()); System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(3, main.invoke(null, 4)); assertEquals(3, main.invoke(null, 4));
@@ -57,7 +57,7 @@ public class ControlStructuresTest extends CodegenTestCase {
} }
public void testIfNoElse() throws Exception { public void testIfNoElse() throws Exception {
loadFile("ifNoElse.jet"); loadFile("controlStructures/ifNoElse.jet");
System.out.println(generateToText()); System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(5, main.invoke(null, 5, true)); assertEquals(5, main.invoke(null, 5, true));
@@ -72,7 +72,7 @@ public class ControlStructuresTest extends CodegenTestCase {
} }
public void testFor() throws Exception { public void testFor() throws Exception {
loadFile("for.jet"); loadFile("controlStructures/for.jet");
System.out.println(generateToText()); System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
List<String> args = Arrays.asList("IntelliJ", " ", "IDEA"); List<String> args = Arrays.asList("IntelliJ", " ", "IDEA");
@@ -80,7 +80,7 @@ public class ControlStructuresTest extends CodegenTestCase {
} }
public void testForInArray() throws Exception { public void testForInArray() throws Exception {
loadFile("forInArray.jet"); loadFile("controlStructures/forInArray.jet");
System.out.println(generateToText()); System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
String[] args = new String[] { "IntelliJ", " ", "IDEA" }; String[] args = new String[] { "IntelliJ", " ", "IDEA" };
@@ -102,7 +102,7 @@ public class ControlStructuresTest extends CodegenTestCase {
} }
public void testTryCatch() throws Exception { public void testTryCatch() throws Exception {
loadFile("tryCatch.jet"); loadFile("controlStructures/tryCatch.jet");
System.out.println(generateToText()); System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals("no message", main.invoke(null, "0")); assertEquals("no message", main.invoke(null, "0"));
@@ -9,7 +9,7 @@ import java.lang.reflect.Modifier;
*/ */
public class PropertyGenTest extends CodegenTestCase { public class PropertyGenTest extends CodegenTestCase {
public void testPrivateVal() throws Exception { public void testPrivateVal() throws Exception {
loadFile("privateVal.jet"); loadFile("properties/privateVal.jet");
System.out.println(generateToText()); System.out.println(generateToText());
final Class aClass = loadImplementationClass(generateClassesInFile(), "PrivateVal"); final Class aClass = loadImplementationClass(generateClassesInFile(), "PrivateVal");
final Field[] fields = aClass.getDeclaredFields(); final Field[] fields = aClass.getDeclaredFields();
@@ -19,7 +19,7 @@ public class PropertyGenTest extends CodegenTestCase {
} }
public void testPrivateVar() throws Exception { public void testPrivateVar() throws Exception {
loadFile("privateVar.jet"); loadFile("properties/privateVar.jet");
System.out.println(generateToText()); System.out.println(generateToText());
final Class aClass = loadImplementationClass(generateClassesInFile(), "PrivateVar"); final Class aClass = loadImplementationClass(generateClassesInFile(), "PrivateVar");
final Object instance = aClass.newInstance(); final Object instance = aClass.newInstance();
@@ -60,7 +60,7 @@ public class PropertyGenTest extends CodegenTestCase {
} }
public void testFieldPropertyAccess() throws Exception { public void testFieldPropertyAccess() throws Exception {
loadFile("fieldPropertyAccess.jet"); loadFile("properties/fieldPropertyAccess.jet");
final Method method = generateFunction(); final Method method = generateFunction();
assertEquals(1, method.invoke(null)); assertEquals(1, method.invoke(null));
assertEquals(2, method.invoke(null)); assertEquals(2, method.invoke(null));
@@ -73,7 +73,7 @@ public class PropertyGenTest extends CodegenTestCase {
} }
public void testFieldSetter() throws Exception { public void testFieldSetter() throws Exception {
loadFile("fieldSetter.jet"); loadFile("properties/fieldSetter.jet");
System.out.println(generateToText()); System.out.println(generateToText());
final Method method = generateFunction("append"); final Method method = generateFunction("append");
method.invoke(null, "IntelliJ "); method.invoke(null, "IntelliJ ");
@@ -82,7 +82,7 @@ public class PropertyGenTest extends CodegenTestCase {
} }
public void testFieldSetterPlusEq() throws Exception { public void testFieldSetterPlusEq() throws Exception {
loadFile("fieldSetterPlusEq.jet"); loadFile("properties/fieldSetterPlusEq.jet");
System.out.println(generateToText()); System.out.println(generateToText());
final Method method = generateFunction("append"); final Method method = generateFunction("append");
method.invoke(null, "IntelliJ "); method.invoke(null, "IntelliJ ");
@@ -81,6 +81,11 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
assertType("(1, 'a')", JetStandardClasses.getTupleType(library.getIntType(), library.getCharType())); assertType("(1, 'a')", JetStandardClasses.getTupleType(library.getIntType(), library.getCharType()));
} }
public void testTypeInfo() throws Exception {
assertType("typeof(1)", "TypeInfo<Int>");
assertType("typeof(typeof(1))", "TypeInfo<TypeInfo<Int>>");
}
public void testJumps() throws Exception { public void testJumps() throws Exception {
assertType("throw e", JetStandardClasses.getNothingType()); assertType("throw e", JetStandardClasses.getNothingType());
assertType("return", JetStandardClasses.getNothingType()); assertType("return", JetStandardClasses.getNothingType());