summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorschinz <schinz@epfl.ch>2004-10-14 07:38:22 +0000
committerschinz <schinz@epfl.ch>2004-10-14 07:38:22 +0000
commit24b9bbe78b5be0ae553cdfbb973973888a5e7178 (patch)
tree360554e821e1d21d541d72692652b2ebe112e304 /sources
parent534204a7eea4a87d1cc60789c909429f2780c079 (diff)
downloadscala-24b9bbe78b5be0ae553cdfbb973973888a5e7178.tar.gz
scala-24b9bbe78b5be0ae553cdfbb973973888a5e7178.tar.bz2
scala-24b9bbe78b5be0ae553cdfbb973973888a5e7178.zip
- moved all subclasses to their own files
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/Type.java194
1 files changed, 14 insertions, 180 deletions
diff --git a/sources/scala/Type.java b/sources/scala/Type.java
index 932b1d73bc..d1c0dcbf10 100644
--- a/sources/scala/Type.java
+++ b/sources/scala/Type.java
@@ -11,6 +11,15 @@
package scala;
import scala.runtime.RunTime;
+import scala.runtime.types.ScalaClassType;
+import scala.runtime.types.TypeBoolean;
+import scala.runtime.types.TypeByte;
+import scala.runtime.types.TypeChar;
+import scala.runtime.types.TypeDouble;
+import scala.runtime.types.TypeFloat;
+import scala.runtime.types.TypeInt;
+import scala.runtime.types.TypeLong;
+import scala.runtime.types.TypeShort;
/**
* Run-time types for Scala.
@@ -32,7 +41,9 @@ abstract public class Type {
* Return true iff the given object is an instance of a subtype of
* this type (implement Scala's isInstanceOf operation).
*/
- abstract public boolean hasAsInstance(Object o);
+ abstract public boolean isInstance(Object o);
+
+ abstract public boolean isSubType(Type that);
/**
* Check that the given object can be cast to this type, and throw
@@ -40,8 +51,8 @@ abstract public class Type {
* asInstanceOf operation).
*/
public Object checkCastability(Object o) {
- if (! (o == null || hasAsInstance(o)))
- throw new ClassCastException(); // TODO provide a message
+ if (! (o == null || isInstance(o)))
+ throw new ClassCastException(this.toString());
return o;
}
@@ -55,180 +66,3 @@ abstract public class Type {
public static final TypeByte Byte = new TypeByte();
public static final TypeBoolean Boolean = new TypeBoolean();
}
-
-public class ConstructedType extends Type {
- private Object outer;
- private Class typeConstr;
- private Type[] args;
-
- public ConstructedType(Object outer, String typeConstrName) {
- this(outer, typeConstrName, Type.EMPTY_ARRAY);
- }
-
- public ConstructedType(Object outer, String typeConstrName, Type arg1) {
- this(outer, typeConstrName, new Type[]{ arg1 });
- }
-
- public ConstructedType(Object outer,
- String typeConstrName,
- Type arg1,
- Type arg2) {
- this(outer, typeConstrName, new Type[]{ arg1, arg2 });
- }
-
- public ConstructedType(Object outer,
- String typeConstrName,
- Type arg1,
- Type arg2,
- Type arg3) {
- this(outer, typeConstrName, new Type[]{ arg1, arg2, arg3 });
- }
-
- public ConstructedType(Object outer,
- String typeConstrName,
- Type arg1,
- Type arg2,
- Type arg3,
- Type arg4) {
- this(outer, typeConstrName, new Type[]{ arg1, arg2, arg3, arg4 });
- }
-
- public ConstructedType(Object outer, String typeConstrName, Type[] args) {
- try {
- this.outer = outer;
- this.typeConstr = Class.forName(typeConstrName,
- false,
- getClass().getClassLoader());
- this.args = args;
- } catch (ClassNotFoundException e) {
- throw new Error(e);
- }
- }
-
- public Array newArray(int size) {
- // TODO is that correct if we have type arguments?
- Object[] array =
- (Object[])java.lang.reflect.Array.newInstance(typeConstr, size);
- return RunTime.box_oarray(array);
- }
-
- public Object defaultValue() {
- return null;
- }
-
- public boolean hasAsInstance(Object o) {
- return typeConstr.isInstance(o); // TODO complete
- }
-}
-
-public class SingleType extends Type {
- private final Object instance;
-
- public SingleType(Object instance) {
- this.instance = instance;
- }
-
- public Array newArray(int size) {
- throw new Error(); // TODO
- }
-
- public Object defaultValue() {
- throw new Error(); // TODO
- }
-
- public boolean hasAsInstance(Object o) {
- return (o == instance);
- }
-}
-
-// The following classes may not be defined in class Type because
-// inner classes confuse pico which then attributes the metadata to
-// the wrong members.
-
-class TypeDouble extends Type {
- private final Double ZERO = RunTime.box_dvalue(0.0);
- public Array newArray(int size) {
- return RunTime.box_darray(new double[size]);
- }
- public Object defaultValue() { return ZERO; }
- public boolean hasAsInstance(Object o) {
- throw new UnsupportedOperationException();
- }
-};
-
-class TypeFloat extends Type {
- private final Float ZERO = RunTime.box_fvalue(0.0f);
- public Array newArray(int size) {
- return RunTime.box_farray(new float[size]);
- }
- public Object defaultValue() { return ZERO; }
- public boolean hasAsInstance(Object o) {
- throw new UnsupportedOperationException();
- }
-};
-
-class TypeLong extends Type {
- private final Long ZERO = RunTime.box_lvalue(0l);
- public Array newArray(int size) {
- return RunTime.box_larray(new long[size]);
- }
- public Object defaultValue() { return ZERO; }
- public boolean hasAsInstance(Object o) {
- throw new UnsupportedOperationException();
- }
-};
-
-class TypeInt extends Type {
- private final Int ZERO = RunTime.box_ivalue(0);
- public Array newArray(int size) {
- return RunTime.box_iarray(new int[size]);
- }
- public Object defaultValue() { return ZERO; }
- public boolean hasAsInstance(Object o) {
- throw new UnsupportedOperationException();
- }
-};
-
-class TypeShort extends Type {
- private final Short ZERO = RunTime.box_svalue((short)0);
- public Array newArray(int size) {
- return RunTime.box_sarray(new short[size]);
- }
- public Object defaultValue() { return ZERO; }
- public boolean hasAsInstance(Object o) {
- throw new UnsupportedOperationException();
- }
-};
-
-class TypeChar extends Type {
- private final Char ZERO = RunTime.box_cvalue((char)0);
- public Array newArray(int size) {
- return RunTime.box_carray(new char[size]);
- }
- public Object defaultValue() { return ZERO; }
- public boolean hasAsInstance(Object o) {
- throw new UnsupportedOperationException();
- }
-};
-
-class TypeByte extends Type {
- private final Byte ZERO = RunTime.box_bvalue((byte)0);
- public Array newArray(int size) {
- return RunTime.box_barray(new byte[size]);
- }
- public Object defaultValue() { return ZERO; }
- public boolean hasAsInstance(Object o) {
- throw new UnsupportedOperationException();
- }
-};
-
-class TypeBoolean extends Type {
- private final Boolean ZERO = RunTime.box_zvalue(false);
- public Array newArray(int size) {
- return RunTime.box_zarray(new boolean[size]);
- }
- public Object defaultValue() { return ZERO; }
- public boolean hasAsInstance(Object o) {
- throw new UnsupportedOperationException();
- }
-};