diff options
author | Martin Odersky <odersky@gmail.com> | 2004-08-25 13:46:10 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2004-08-25 13:46:10 +0000 |
commit | 8da050118d71c78ef3a4f45daef1edd1b65a5e41 (patch) | |
tree | 89d00ffab5c10f31bfef57466c5b96f6faee0089 /sources | |
parent | bcde7a440694c3ca30547f3ab35ea199f2b1d9bc (diff) | |
download | scala-8da050118d71c78ef3a4f45daef1edd1b65a5e41.tar.gz scala-8da050118d71c78ef3a4f45daef1edd1b65a5e41.tar.bz2 scala-8da050118d71c78ef3a4f45daef1edd1b65a5e41.zip |
*** empty log message ***
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/Iterator.scala | 8 | ||||
-rw-r--r-- | sources/scala/List.scala | 39 | ||||
-rw-r--r-- | sources/scala/tools/scalac/wholeprog/ApplicationBuilder.scala | 2 | ||||
-rw-r--r-- | sources/scalac/symtab/Type.java | 27 |
4 files changed, 61 insertions, 15 deletions
diff --git a/sources/scala/Iterator.scala b/sources/scala/Iterator.scala index 1d1a16b2dd..f3baf774d0 100644 --- a/sources/scala/Iterator.scala +++ b/sources/scala/Iterator.scala @@ -277,6 +277,14 @@ trait Iterator[+A] { res } + /** Tests if the given value <code>elem</code> is a member of this list. + * + * @param elem element whose membership has to be tested. + * @return True iff there is an element of this list which is + * equal (w.r.t. <code>==</code>) to <code>elem</code>. + */ + def contains(elem: Any): boolean = exists { x => x == elem }; + /** Find and return the first element of the iterable object satisfying a * predicate, if any. * diff --git a/sources/scala/List.scala b/sources/scala/List.scala index ec05522eda..d66728f97e 100644 --- a/sources/scala/List.scala +++ b/sources/scala/List.scala @@ -111,6 +111,14 @@ object List { if (it.hasNext) it.next :: fromIterator(it); else Nil; + /** Converts an array into a list. + * + * @param arr the array to convert + * @return a list that contains the same elements than <code>arr</code> + * in the same order + */ + def fromArray[a](arr: Array[a]): List[a] = fromArray(arr, 0, arr.length); + /** Converts a range of an array into a list. * * @param arr the array to convert @@ -129,6 +137,8 @@ object List { res } + + /** Parses a string which contains substrings separated by a * * separator character and returns a list of all substrings. @@ -188,9 +198,9 @@ object List { * <code>[a0, ..., ak]</code>, <code>[b0, ..., bl]</code> and * <code>m = min(k,l)</code> */ - def map2[a,b,c](xs: List[a], ys: List[b], f: (a, b) => c): List[c] = + def map2[a,b,c](xs: List[a], ys: List[b])(f: (a, b) => c): List[c] = if (xs.isEmpty || ys.isEmpty) Nil - else f(xs.head, ys.head) :: map2(xs.tail, ys.tail, f); + else f(xs.head, ys.head) :: map2(xs.tail, ys.tail)(f); /** Tests whether the given predicate <code>p</code> holds * for all corresponding elements of the argument lists. @@ -200,9 +210,9 @@ object List { * <code>[a0, ..., ak]</code>, <code>[b0, ..., bl]</code> and * <code>m = min(k,l)</code> */ - def forall2[a,b](xs: List[a], ys: List[b], f: (a, b) => boolean): boolean = + def forall2[a,b](xs: List[a], ys: List[b])(f: (a, b) => boolean): boolean = if (xs.isEmpty || ys.isEmpty) true - else f(xs.head, ys.head) && forall2(xs.tail, ys.tail, f); + else f(xs.head, ys.head) && forall2(xs.tail, ys.tail)(f); /** Tests whether the given predicate <code>p</code> holds * for some corresponding elements of the argument lists. @@ -212,9 +222,9 @@ object List { * <code>[a0, ..., ak]</code>, <code>[b0, ..., bl]</code> and * <code>m = min(k,l)</code> */ - def exists2[a,b](xs: List[a], ys: List[b], f: (a, b) => boolean): boolean = + def exists2[a,b](xs: List[a], ys: List[b])(f: (a, b) => boolean): boolean = if (xs.isEmpty || ys.isEmpty) false - else f(xs.head, ys.head) || exists2(xs.tail, ys.tail, f); + else f(xs.head, ys.head) || exists2(xs.tail, ys.tail)(f); /** Transposes a list of lists. * pre: All element lists have the same length. @@ -646,6 +656,15 @@ sealed trait List[+a] extends Seq[a] { override def exists(p: a => Boolean): Boolean = !isEmpty && (p(head) || (tail exists p)); + /** Tests if the given value <code>elem</code> is a member of this + * iterable object. + * + * @param elem element whose membership has to be tested. + * @return True iff there is an element of this list which is + * equal (w.r.t. <code>==</code>) to <code>elem</code>. + */ + def contains(elem: Any): boolean = exists { x => x == elem }; + /** Find and return the first element of the list satisfying a * predicate, if any. * @@ -749,14 +768,6 @@ sealed trait List[+a] extends Seq[a] { if (this.isEmpty || that.isEmpty) Nil else Pair(this.head, that.head) :: this.tail.zip(that.tail); - /** Tests if the given value <code>elem</code> is a member of this list. - * - * @param elem element whose membership has to be tested. - * @return True iff there is an element of this list which is - * equal (w.r.t. <code>==</code>) to <code>elem</code>. - */ - def contains(elem: Any): boolean = exists { x => x == elem }; - /** Computes the union of this list and the given list * <code>that</code>. * diff --git a/sources/scala/tools/scalac/wholeprog/ApplicationBuilder.scala b/sources/scala/tools/scalac/wholeprog/ApplicationBuilder.scala index 3af9431e96..244c6ae1e4 100644 --- a/sources/scala/tools/scalac/wholeprog/ApplicationBuilder.scala +++ b/sources/scala/tools/scalac/wholeprog/ApplicationBuilder.scala @@ -181,7 +181,7 @@ class ApplicationBuilder(globall: scalac_Global) { // updateClassHierarchy(clsSym); // superclasses - addTypesToWorklist(List.fromArray[Type](parents, 0, parents.length)); + addTypesToWorklist(List.fromArray(parents, 0, parents.length)); addReferences(cls); } diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java index 2fbb72f0c3..962660b953 100644 --- a/sources/scalac/symtab/Type.java +++ b/sources/scalac/symtab/Type.java @@ -1995,6 +1995,7 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { return false; case ThisType(_): case SingleType(_, _): + if (this.isSameAs(that)) return true; if (this.singleDeref().isSubType(that)) return true; break; case ConstantType(_, _): @@ -2163,15 +2164,20 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { return sym1.isModule() && sym == sym1.moduleClass() && sym.owner().thisType().isSameAs(pre1) +/* || this.singleDeref().isSingletonType() && this.singleDeref().isSameAs(that) || that.singleDeref().isSingletonType() && this.isSameAs(that.singleDeref()) +*/ || deAlias(that) != that && this.isSameAs(deAlias(that)); + default: + if (deAlias(this) != this) + return deAlias(this).isSameAs(that); } break; @@ -2179,12 +2185,14 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { switch (that) { case SingleType(Type pre1, Symbol sym1): return sym == sym1 && pre.isSameAs(pre1) +/* || this.singleDeref().isSingletonType() && this.singleDeref().isSameAs(that) || that.singleDeref().isSingletonType() && this.isSameAs(that.singleDeref()) +*/ || (deAlias(this) != this || deAlias(that) != that) && deAlias(this).isSameAs(deAlias(that)); @@ -2192,12 +2200,14 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { return sym.isModule() && sym.moduleClass() == sym1 && pre.isSameAs(sym1.owner().thisType()) +/* || this.singleDeref().isSingletonType() && this.singleDeref().isSameAs(that) || that.singleDeref().isSingletonType() && this.isSameAs(that.singleDeref()) +*/ || deAlias(this) != this && deAlias(this).isSameAs(that); @@ -2293,6 +2303,10 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { case TypeVar(Type origin, Constraint constr): if (constr.inst != NoType) return constr.inst.isSameAs(this); else return constr.instantiate(this.any2typevar()); + case ThisType(_): + case SingleType(_, _): + if (deAlias(that) != that) + return this.isSameAs(deAlias(that)); } switch (this) { @@ -2310,6 +2324,7 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { static Type deAlias(Type tp) { switch (tp) { + case ThisType(_): case SingleType(_, _): Type tp1 = tp.singleDeref(); if (tp1.isStable()) return deAlias(tp1); @@ -2697,6 +2712,18 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { tps = elimRedundant(tps, true); if (tps.length == 1) return tps[0]; + // singleDeref singletypes and try again + Type[] tps1 = tps; + for (int i = 0; i < tps.length; i++) { + Type tp1 = tps[i].singleDeref(); + if (tp1 != tps[i] && tps1 == tps) { + tps1 = new Type[tps.length]; + System.arraycopy(tps, 0, tps1, 0, i); + } + tps1[i] = tp1; + } + if (tps1 != tps) return lub0(tps1); + // intersect closures and build frontier. Type[][] closures = new Type[tps.length][]; for (int i = 0; i < tps.length; i++) { |