diff options
author | paltherr <paltherr@epfl.ch> | 2003-10-17 15:50:31 +0000 |
---|---|---|
committer | paltherr <paltherr@epfl.ch> | 2003-10-17 15:50:31 +0000 |
commit | d5488e582aa821b9b996fc84583dc0238fe74b81 (patch) | |
tree | e9f2a57b567f8e9ce60216795cada6a8c9e95d44 /sources/scalac/symtab | |
parent | abee72fd555780730d939275da8257de74926383 (diff) | |
download | scala-d5488e582aa821b9b996fc84583dc0238fe74b81.tar.gz scala-d5488e582aa821b9b996fc84583dc0238fe74b81.tar.bz2 scala-d5488e582aa821b9b996fc84583dc0238fe74b81.zip |
- Added class Relation
- Added method compareTo
- Added method lookup(Symbol,Type,Relation)
Diffstat (limited to 'sources/scalac/symtab')
-rw-r--r-- | sources/scalac/symtab/Type.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java index 1532d9c0e6..1b31035eed 100644 --- a/sources/scalac/symtab/Type.java +++ b/sources/scalac/symtab/Type.java @@ -727,6 +727,42 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { } } + /** + * Looks up in the current type a symbol with the same name as the + * given symbol and whose type (as seen from the given prefix) is + * in the given relation to the type (as seen from the given + * prefix) of the given symbol. If no such symbol is found, + * returns NONE. Note that in some cases, the returned symbol may + * be equal to the given one. The main purpose of this method is + * look up overridden and overriding symbols. + */ + public Symbol lookup(Symbol sym, Type pre, Relation relation) { + assert !sym.isOverloaded(): Debug.show(sym); + Symbol sym1 = lookupNonPrivate(sym.name); + if (sym1.kind == Kinds.NONE || sym1.isStatic()) { + return Symbol.NONE; + } else { + //System.out.println(sym1 + ":" + sym1.type() + sym1.locationString() + " is" + relation + " to " + sym + ":" + sym.type() + sym.locationString() + " in " + pre + " ?"); //DEBUG + + Type symtype = pre.memberType(sym).derefDef(); + Type sym1type = pre.memberType(sym1).derefDef(); + switch (sym1type) { + case OverloadedType(Symbol[] alts, Type[] alttypes): + for (int i = 0; i < alts.length; i++) { + if (alttypes[i].derefDef().compareTo(symtype, relation)) + return alts[i]; + } + return Symbol.NONE; + default: + if (sym1type.compareTo(symtype, relation)) return sym1; + else { + if (Global.instance.debug) System.out.println(sym1 + sym1.locationString() + " is not" + relation + "to " + sym + sym.locationString() + " in " + pre + ", since " + sym1type + relation.toString(true) + symtype);//DEBUG + return Symbol.NONE; + } + } + } + } + // Set Owner ------------------------------------------------------------------ public Type setOwner(Symbol owner) { @@ -1554,6 +1590,36 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { // Comparisons ------------------------------------------------------------------ + /** Type relations */ + public static class Relation { + public case SubType; // this SubType that <=> this.isSubType(that) + public case SameType; // this SameType that <=> this.isSameAs(that) + public case SuperType; // this SuperType that <=> that.isSubType(this) + + public String toString() { + return toString(false); + } + public String toString(boolean negate) { + switch (this) { + case SubType : return negate ? " <= " : " !<= "; + case SameType : return negate ? " == " : " != "; + case SuperType: return negate ? " >= " : " !>= "; + default : throw Debug.abort("unknown relation", this); + } + } + } + + /** Is this type in given relation to that type? + */ + public boolean compareTo(Type that, Relation relation) { + switch (relation) { + case SubType : return this.isSubType(that); + case SameType : return this.isSameAs(that); + case SuperType: return that.isSubType(this); + default : throw Debug.abort("unknown relation", relation); + } + } + /** Is this type a subtype of that type? */ public boolean isSubType(Type that) { |