diff options
author | Matthias Zenger <mzenger@gmail.com> | 2003-09-24 22:21:00 +0000 |
---|---|---|
committer | Matthias Zenger <mzenger@gmail.com> | 2003-09-24 22:21:00 +0000 |
commit | 423ecdde9b683f8b32624e5e08930c7f461dca4e (patch) | |
tree | 023d3e4d85ed27a5def1dfe7946da6c77e5b75e9 /sources/scalac | |
parent | 191c921e2e289b9e2daf7cb4e5b5a45d5dff8de5 (diff) | |
download | scala-423ecdde9b683f8b32624e5e08930c7f461dca4e.tar.gz scala-423ecdde9b683f8b32624e5e08930c7f461dca4e.tar.bz2 scala-423ecdde9b683f8b32624e5e08930c7f461dca4e.zip |
Support for pattern matching on Jaco case class...
Support for pattern matching on Jaco case classes in Scala.
Diffstat (limited to 'sources/scalac')
-rw-r--r-- | sources/scalac/symtab/Symbol.java | 1053 | ||||
-rw-r--r-- | sources/scalac/symtab/classfile/AttributeParser.java | 94 | ||||
-rw-r--r-- | sources/scalac/symtab/classfile/ClassfileConstants.java | 2 | ||||
-rw-r--r-- | sources/scalac/symtab/classfile/ClassfileParser.java | 97 | ||||
-rw-r--r-- | sources/scalac/transformer/matching/PatternMatcher.java | 37 | ||||
-rw-r--r-- | sources/scalac/typechecker/Analyzer.java | 7 |
6 files changed, 658 insertions, 632 deletions
diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java index 200e9acecf..cc070c24af 100644 --- a/sources/scalac/symtab/Symbol.java +++ b/sources/scalac/symtab/Symbol.java @@ -68,9 +68,9 @@ public abstract class Symbol implements Modifiers, Kinds { } protected void update(int pos, int flags) { - this.pos = pos; - this.flags = (flags & ~(INITIALIZED | LOCKED)) | - (this.flags & (INITIALIZED | LOCKED)); + this.pos = pos; + this.flags = (flags & ~(INITIALIZED | LOCKED)) | + (this.flags & (INITIALIZED | LOCKED)); } /** Return a fresh symbol with the same fields as this one. @@ -130,12 +130,12 @@ public abstract class Symbol implements Modifiers, Kinds { /** copy all fields to `sym' */ public void copyTo(Symbol sym) { - sym.kind = kind; - sym.pos = pos; - sym.name = name; - sym.flags = flags; - sym.owner = owner; - sym.infos = infos; + sym.kind = kind; + sym.pos = pos; + sym.name = name; + sym.flags = flags; + sym.owner = owner; + sym.infos = infos; } // Setters --------------------------------------------------------------- @@ -158,9 +158,9 @@ public abstract class Symbol implements Modifiers, Kinds { assert symbol != Symbol.ERROR; if (symbol.isModule()) setOwner(symbol.moduleClass(), owner); if (symbol.isClass()) { - Symbol[] alts = symbol.allConstructors().alternativeSymbols(); - for (int i = 0; i < alts.length; i++) setOwner(alts[i], owner); - } + Symbol[] alts = symbol.allConstructors().alternativeSymbols(); + for (int i = 0; i < alts.length; i++) setOwner(alts[i], owner); + } symbol.owner = owner; } @@ -228,57 +228,57 @@ public abstract class Symbol implements Modifiers, Kinds { assert infos != null : this; assert !phase.precedes(infos.limit()) : this + " -- " + phase + " -- " + infos.limit(); - if (infos.limit() == phase) { + if (infos.limit() == phase) { if (infos.start == phase) infos = infos.prev; else infos.setLimit(infos.limit().prev); } infos = new TypeIntervalList(infos, info, phase); - return this; + return this; } /** Set type of `this' in current class */ public Symbol setTypeOfThis(Type tp) { - throw new ApplicationError(this + ".setTypeOfThis"); + throw new ApplicationError(this + ".setTypeOfThis"); } /** Set the low bound of this type variable */ public Symbol setLoBound(Type lobound) { - throw new ApplicationError("setLoBound inapplicable for " + this); + throw new ApplicationError("setLoBound inapplicable for " + this); } /** Add an auxiliary constructor to class; return created symbol. */ public Symbol addConstructor() { - throw new ApplicationError("addConstructor inapplicable for " + this); + throw new ApplicationError("addConstructor inapplicable for " + this); } // Symbol classification ---------------------------------------------------- /** Does this symbol denote a type? */ public final boolean isType() { - return kind == TYPE || kind == CLASS || kind == ALIAS; + return kind == TYPE || kind == CLASS || kind == ALIAS; } /** Does this symbol denote a term? */ public final boolean isTerm() { - return kind == VAL; + return kind == VAL; } /** Does this symbol denote a value? */ public final boolean isValue() { - preInitialize(); + preInitialize(); return kind == VAL && !(isModule() && isJava()) && !isPackage(); } /** Does this symbol denote a stable value? */ public final boolean isStable() { - return kind == VAL && - ((flags & STABLE) != 0 || - (flags & MUTABLE) == 0 && type().isObjectType()); + return kind == VAL && + ((flags & STABLE) != 0 || + (flags & MUTABLE) == 0 && type().isObjectType()); } /** Does this symbol denote a variable? */ @@ -303,49 +303,49 @@ public abstract class Symbol implements Modifiers, Kinds { /** Does this symbol denote a method? */ public final boolean isInitializedMethod() { - if (infos == null) return false; - switch (rawInfo()) { - case MethodType(_, _): - case PolyType(_, _): - return true; - case OverloadedType(Symbol[] alts, _): - for (int i = 0; i < alts.length; i++) - if (alts[i].isMethod()) return true; - return false; - default: - return false; - } + if (infos == null) return false; + switch (rawInfo()) { + case MethodType(_, _): + case PolyType(_, _): + return true; + case OverloadedType(Symbol[] alts, _): + for (int i = 0; i < alts.length; i++) + if (alts[i].isMethod()) return true; + return false; + default: + return false; + } } public final boolean isMethod() { - initialize(); - return isInitializedMethod(); + initialize(); + return isInitializedMethod(); } public final boolean isCaseFactory() { - return isMethod() && !isConstructor() && (flags & CASE) != 0; + return isMethod() && !isConstructor() && (flags & CASE) != 0; } public final boolean isAbstractClass() { - preInitialize(); - return (flags & ABSTRACTCLASS) != 0 && - this != Global.instance.definitions.ARRAY_CLASS; + preInitialize(); + return (flags & ABSTRACTCLASS) != 0 && + this != Global.instance.definitions.ARRAY_CLASS; } /* Does this symbol denote an anonymous class? */ public final boolean isAnonymousClass() { - return isClass() && name.startsWith(Names.ANON_CLASS_NAME); + return isClass() && name.startsWith(Names.ANON_CLASS_NAME); } /** Does this symbol denote the root class or root module? */ public final boolean isRoot() { - return this.moduleClass() == Global.instance.definitions.ROOT_CLASS; + return this.moduleClass() == Global.instance.definitions.ROOT_CLASS; } /** Does this symbol denote something loaded from a Java class? */ public final boolean isJava() { - preInitialize(); + preInitialize(); return (flags & JAVA) != 0; } @@ -361,7 +361,7 @@ public abstract class Symbol implements Modifiers, Kinds { /** Does this symbol denote a global module? */ public final boolean isGlobalModule() { - return isModule() && (owner().isPackage() + return isModule() && (owner().isPackage() //|| owner().isGlobalModule() // add later? translation does not work (yet?) ); } @@ -379,26 +379,26 @@ public abstract class Symbol implements Modifiers, Kinds { /** Does this symbol denote a case class? */ public final boolean isCaseClass() { - preInitialize(); - return kind == CLASS && (flags & CASE) != 0; + preInitialize(); + return kind == CLASS && (flags & CASE) != 0; } /** Does this symbol denote a uniform (i.e. parameterless) class? */ public final boolean isTrait() { - //preInitialize(); todo: enable, problem is that then we cannot print - // during unpickle - return kind == CLASS && (flags & TRAIT) != 0; + //preInitialize(); todo: enable, problem is that then we cannot print + // during unpickle + return kind == CLASS && (flags & TRAIT) != 0; } /** Does this class symbol denote a compound type symbol? */ public final boolean isCompoundSym() { - return name == Names.COMPOUND_NAME.toTypeName(); + return name == Names.COMPOUND_NAME.toTypeName(); } /** Does this symbol denote an interface? */ public final boolean isInterface() { - preInitialize(); + preInitialize(); return (flags & INTERFACE) != 0; } @@ -409,19 +409,19 @@ public abstract class Symbol implements Modifiers, Kinds { /** Does this symbol denote a protected symbol? */ public final boolean isProtected() { - preInitialize(); + preInitialize(); return (flags & PROTECTED) != 0; } /** Does this symbol denote a private symbol? */ public final boolean isPrivate() { - preInitialize(); + preInitialize(); return (flags & PRIVATE) != 0; } /** Has this symbol been lifted? */ public final boolean isLifted() { - preInitialize(); + preInitialize(); return (flags & LIFTED) != 0; } @@ -447,20 +447,20 @@ public abstract class Symbol implements Modifiers, Kinds { /** Is this symbol locally defined? I.e. not a member of a class or module */ public final boolean isLocal() { - return owner.kind == VAL && - !((flags & PARAM) != 0 && owner.isPrimaryConstructor()); + return owner.kind == VAL && + !((flags & PARAM) != 0 && owner.isPrimaryConstructor()); } /** Is this symbol a parameter? Includes type parameters of methods. */ public final boolean isParameter() { - return (flags & PARAM) != 0; + return (flags & PARAM) != 0; } /** Is this symbol a def parameter? */ public final boolean isDefParameter() { - return (flags & (PARAM | DEF)) == (PARAM | DEF); + return (flags & (PARAM | DEF)) == (PARAM | DEF); } /** Is this class locally defined? @@ -470,30 +470,30 @@ public abstract class Symbol implements Modifiers, Kinds { * - it is defined within a local class */ public final boolean isLocalClass() { - return isClass() && - (isAnonymousClass() || - owner.isValue() || - owner.isLocalClass()); + return isClass() && + (isAnonymousClass() || + owner.isValue() || + owner.isLocalClass()); } /** Is this symbol a constructor? */ public boolean isConstructor() { - return false; + return false; } /** Is this symbol the primary constructor of a type? */ public final boolean isPrimaryConstructor() { - return isConstructor() && this == constructorClass().primaryConstructor(); + return isConstructor() && this == constructorClass().primaryConstructor(); } public final boolean isGenerated() { - return name.pos((byte)'$') < name.length(); + return name.pos((byte)'$') < name.length(); } /** Symbol was preloaded from package */ public final boolean isExternal() { - return pos == Position.NOPOS; + return pos == Position.NOPOS; } /** Is this symbol an overloaded symbol? */ @@ -512,9 +512,9 @@ public abstract class Symbol implements Modifiers, Kinds { /** The variance of this symbol as an integer */ public int variance() { - if ((flags & COVARIANT) != 0) return 1; - else if ((flags & CONTRAVARIANT) != 0) return -1; - else return 0; + if ((flags & COVARIANT) != 0) return 1; + else if ((flags & CONTRAVARIANT) != 0) return -1; + else return 0; } // Symbol names ---------------------------------------------------------------- @@ -526,13 +526,13 @@ public abstract class Symbol implements Modifiers, Kinds { /** Get the simple name of this Symbol (this is always a term name) */ public Name simpleName() { - return isConstructor() ? constructorClass().name.toTermName() - : name.toTermName(); + return isConstructor() ? constructorClass().name.toTermName() + : name.toTermName(); } /** Get the fully qualified name of this Symbol */ public Name fullName() { - return simpleName(); + return simpleName(); } /** Get the mangled name of this Symbol @@ -551,12 +551,12 @@ public abstract class Symbol implements Modifiers, Kinds { /** Get type parameters */ public Symbol[] typeParams() { - return EMPTY_ARRAY; + return EMPTY_ARRAY; } /** Get value parameters */ public Symbol[] valueParams() { - return EMPTY_ARRAY; + return EMPTY_ARRAY; } /** Get type parameters at start of next phase */ @@ -601,10 +601,10 @@ public abstract class Symbol implements Modifiers, Kinds { * as owner. */ public Symbol classOwner() { - Symbol owner = owner(); - Symbol clazz = owner.constructorClass(); - if (clazz.primaryConstructor() == owner) return clazz; - else return owner; + Symbol owner = owner(); + Symbol clazz = owner.constructorClass(); + if (clazz.primaryConstructor() == owner) return clazz; + else return owner; } /** The next enclosing class */ @@ -620,19 +620,19 @@ public abstract class Symbol implements Modifiers, Kinds { /** The top-level class enclosing `sym' */ Symbol enclToplevelClass() { - Symbol sym = this; - while (sym.kind == VAL || - (sym.kind == CLASS && !sym.owner().isPackage())) { - sym = sym.owner(); - } - return sym; + Symbol sym = this; + while (sym.kind == VAL || + (sym.kind == CLASS && !sym.owner().isPackage())) { + sym = sym.owner(); + } + return sym; } /** If this is a constructor, return the class it constructs. * Otherwise return the symbol itself. */ public Symbol constructorClass() { - return this; + return this; } /** Return first alternative if this has a (possibly lazy) @@ -642,51 +642,51 @@ public abstract class Symbol implements Modifiers, Kinds { public Symbol firstAlternative() { if (infos == null) return this; - else if (infos.info instanceof Type.OverloadedType) - return infos.info.alternativeSymbols()[0]; - else if (infos.info instanceof LazyOverloadedType) - return ((LazyOverloadedType) infos.info).sym1.firstAlternative(); - else - return this; + else if (infos.info instanceof Type.OverloadedType) + return infos.info.alternativeSymbols()[0]; + else if (infos.info instanceof LazyOverloadedType) + return ((LazyOverloadedType) infos.info).sym1.firstAlternative(); + else + return this; } /* If this is a module, return its class. * Otherwise return the symbol itself. */ public Symbol moduleClass() { - return this; + return this; } /** if type is a (possibly lazy) overloaded type, return its alternatves * else return array consisting of symbol itself */ public Symbol[] alternativeSymbols() { - Symbol[] alts = type().alternativeSymbols(); - if (alts.length == 0) return new Symbol[]{this}; - else return alts; + Symbol[] alts = type().alternativeSymbols(); + if (alts.length == 0) return new Symbol[]{this}; + else return alts; } /** if type is a (possibly lazy) overloaded type, return its alternatves * else return array consisting of type itself */ public Type[] alternativeTypes() { - return type().alternativeTypes(); + return type().alternativeTypes(); } /** The symbol accessed by this accessor function. */ public Symbol accessed() { - assert (flags & ACCESSOR) != 0; - Name name1 = name; - if (name1.endsWith(Names._EQ)) - name1 = name1.subName(0, name1.length() - Names._EQ.length()); - return owner.info().lookup(Name.fromString(name1 + "$")); + assert (flags & ACCESSOR) != 0; + Name name1 = name; + if (name1.endsWith(Names._EQ)) + name1 = name1.subName(0, name1.length() - Names._EQ.length()); + return owner.info().lookup(Name.fromString(name1 + "$")); } /** The members of this class or module symbol */ public Scope members() { - return info().members(); + return info().members(); } /** Lookup symbol with given name; return Symbol.NONE if not found. @@ -722,11 +722,11 @@ public abstract class Symbol implements Modifiers, Kinds { /** Make sure symbol is entered */ public final void preInitialize() { - //todo: clean up - if (infos.info instanceof ClassParser || - infos.info instanceof SourceCompleter || - infos.info instanceof ClassParser.StaticsParser) - infos.info.complete(this); + //todo: clean up + if (infos.info instanceof ClassParser || + infos.info instanceof SourceCompleter || + infos.info instanceof ClassParser.StaticsParser) + infos.info.complete(this); } /** Get info at start of current phase; This is: @@ -737,31 +737,31 @@ public abstract class Symbol implements Modifiers, Kinds { * its baseclasses and members. */ public final Type info() { - //if (isModule()) moduleClass().initialize(); - Phase phase = Global.instance.currentPhase; - if ((flags & INITIALIZED) == 0) { - Type info = rawFirstInfo(); - assert info != null : this; - if ((flags & LOCKED) != 0) { - setInfo(Type.ErrorType); - flags |= INITIALIZED; - throw new CyclicReference(this, info); - } - flags |= LOCKED; - //System.out.println("completing " + this);//DEBUG - info.complete(this); + //if (isModule()) moduleClass().initialize(); + Phase phase = Global.instance.currentPhase; + if ((flags & INITIALIZED) == 0) { + Type info = rawFirstInfo(); + assert info != null : this; + if ((flags & LOCKED) != 0) { + setInfo(Type.ErrorType); + flags |= INITIALIZED; + throw new CyclicReference(this, info); + } + flags |= LOCKED; + //System.out.println("completing " + this);//DEBUG + info.complete(this); flags = flags & ~LOCKED; - if (info instanceof SourceCompleter && (flags & SNDTIME) == 0) { - flags |= SNDTIME; - Type tp = info(); - flags &= ~SNDTIME; - } else { - assert !(rawInfoAt(phase) instanceof Type.LazyType) : this; - //flags |= INITIALIZED; - } - //System.out.println("done: " + this);//DEBUG - } - return rawInfoAt(phase); + if (info instanceof SourceCompleter && (flags & SNDTIME) == 0) { + flags |= SNDTIME; + Type tp = info(); + flags &= ~SNDTIME; + } else { + assert !(rawInfoAt(phase) instanceof Type.LazyType) : this; + //flags |= INITIALIZED; + } + //System.out.println("done: " + this);//DEBUG + } + return rawInfoAt(phase); } /** Get info at start of next phase @@ -797,26 +797,26 @@ public abstract class Symbol implements Modifiers, Kinds { /** Get info at start of given phase, without forcing lazy types. */ private final Type rawInfoAt(Phase phase) { - //if (infos == null) return Type.NoType;//DEBUG - assert infos != null : this; + //if (infos == null) return Type.NoType;//DEBUG + assert infos != null : this; assert phase != null : this; - if (infos.limit().precedes(phase)) { + if (infos.limit().precedes(phase)) { while (infos.limit().next != phase) { Phase next = infos.limit().next; Type info = transformInfo(next, infos.info); - if (info != infos.info) { - infos = new TypeIntervalList(infos, info, next); - } else { + if (info != infos.info) { + infos = new TypeIntervalList(infos, info, next); + } else { infos.setLimit(next); } } - return infos.info; - } else { - TypeIntervalList infos = this.infos; - while (!infos.start.precedes(phase) && infos.prev != null) + return infos.info; + } else { + TypeIntervalList infos = this.infos; + while (!infos.start.precedes(phase) && infos.prev != null) infos = infos.prev; - return infos.info; - } + return infos.info; + } } // where private Type transformInfo(Phase phase, Type info) { @@ -888,10 +888,10 @@ public abstract class Symbol implements Modifiers, Kinds { /** The types of these symbols as an array. */ static public Type[] type(Symbol[] syms) { - Type[] tps = new Type[syms.length]; - for (int i = 0; i < syms.length; i++) - tps[i] = syms[i].type(); - return tps; + Type[] tps = new Type[syms.length]; + for (int i = 0; i < syms.length; i++) + tps[i] = syms[i].type(); + return tps; } /** The type constructor of a symbol is: @@ -900,25 +900,25 @@ public abstract class Symbol implements Modifiers, Kinds { * Not applicable for term symbols. */ public Type typeConstructor() { - throw new ApplicationError("typeConstructor inapplicable for " + this); + throw new ApplicationError("typeConstructor inapplicable for " + this); } /** The low bound of this type variable */ public Type loBound() { - return Global.instance.definitions.ALL_TYPE; + return Global.instance.definitions.ALL_TYPE; } /** Get this.type corresponding to this symbol */ public Type thisType() { - return Type.localThisType; + return Type.localThisType; } /** Get type of `this' in current class. */ public Type typeOfThis() { - return type(); + return type(); } /** Get this symbol of current class @@ -930,83 +930,83 @@ public abstract class Symbol implements Modifiers, Kinds { * inheritance graph (i.e. subclass.isLess(superclass) always holds). */ public boolean isLess(Symbol that) { - if (this == that) return false; - int diff; - if (this.isType()) { - if (that.isType()) { - diff = this.closure().length - that.closure().length; - if (diff > 0) return true; - if (diff < 0) return false; - } else { - return true; - } - } else if (that.isType()) { - return false; - } - - diff = that.mangledName().index - this.mangledName().index; - if (diff > 0) return true; - if (diff < 0) return false; - - diff = that.mangledFullName().index - this.mangledFullName().index; - if (diff > 0) return true; - if (diff < 0) return false; - - diff = that.hashCode() - this.hashCode(); - if (diff > 0) return true; - if (diff < 0) return false; - - if (owner().isLess(that.owner())) return true; - if (that.owner().isLess(owner())) return false; - - throw new ApplicationError( - "Giving up: can't order two incarnations of class " + - this.mangledFullName()); + if (this == that) return false; + int diff; + if (this.isType()) { + if (that.isType()) { + diff = this.closure().length - that.closure().length; + if (diff > 0) return true; + if (diff < 0) return false; + } else { + return true; + } + } else if (that.isType()) { + return false; + } + + diff = that.mangledName().index - this.mangledName().index; + if (diff > 0) return true; + if (diff < 0) return false; + + diff = that.mangledFullName().index - this.mangledFullName().index; + if (diff > 0) return true; + if (diff < 0) return false; + + diff = that.hashCode() - this.hashCode(); + if (diff > 0) return true; + if (diff < 0) return false; + + if (owner().isLess(that.owner())) return true; + if (that.owner().isLess(owner())) return false; + + throw new ApplicationError( + "Giving up: can't order two incarnations of class " + + this.mangledFullName()); } /** Return the symbol's type itself followed by all its direct and indirect * base types, sorted by isLess(). Overridden for class symbols. */ public Type[] closure() { - return info().closure(); + return info().closure(); } /** Return position of `c' in the closure of this type; -1 if not there. */ public int closurePos(Symbol c) { - if (this == c) return 0; - if (c.isCompoundSym()) return -1; - Type[] closure = closure(); - int lo = 0; - int hi = closure.length - 1; - while (lo <= hi) { - int mid = (lo + hi) / 2; - Symbol clsym = closure[mid].symbol(); - if (c == clsym) return mid; - else if (c.isLess(clsym)) hi = mid - 1; - else if (clsym.isLess(c)) lo = mid + 1; - else throw new ApplicationError(); - } - return -1; + if (this == c) return 0; + if (c.isCompoundSym()) return -1; + Type[] closure = closure(); + int lo = 0; + int hi = closure.length - 1; + while (lo <= hi) { + int mid = (lo + hi) / 2; + Symbol clsym = closure[mid].symbol(); + if (c == clsym) return mid; + else if (c.isLess(clsym)) hi = mid - 1; + else if (clsym.isLess(c)) lo = mid + 1; + else throw new ApplicationError(); + } + return -1; } public Type baseType(Symbol sym) { - int i = closurePos(sym); - if (i >= 0) return closure()[i]; - else return Type.NoType; + int i = closurePos(sym); + if (i >= 0) return closure()[i]; + else return Type.NoType; } /** Is this class a subclass of `c'? I.e. does it have a type instance * of `c' as indirect base class? */ public boolean isSubClass(Symbol c) { - return this == c || - c.kind == Kinds.ERROR || - closurePos(c) >= 0 || - this == Global.instance.definitions.ALL_CLASS || - (this == Global.instance.definitions.ALLREF_CLASS && - c != Global.instance.definitions.ALL_CLASS && - c.isSubClass(Global.instance.definitions.ANYREF_CLASS)); + return this == c || + c.kind == Kinds.ERROR || + closurePos(c) >= 0 || + this == Global.instance.definitions.ALL_CLASS || + (this == Global.instance.definitions.ALLREF_CLASS && + c != Global.instance.definitions.ALL_CLASS && + c.isSubClass(Global.instance.definitions.ANYREF_CLASS)); } /** Get base types of this symbol */ @@ -1021,7 +1021,7 @@ public abstract class Symbol implements Modifiers, Kinds { * $eq => =. */ public String nameString() { - return NameTransformer.decode(simpleName()).toString(); + return NameTransformer.decode(simpleName()).toString(); } /** String representation of symbol's full name. @@ -1029,7 +1029,7 @@ public abstract class Symbol implements Modifiers, Kinds { * $eq => =. */ public String fullNameString() { - return NameTransformer.decode(fullName()).toString(); + return NameTransformer.decode(fullName()).toString(); } /** String representation, including symbol's kind @@ -1042,12 +1042,12 @@ public abstract class Symbol implements Modifiers, Kinds { /** String representation of location. */ public String locationString() { - if (owner.kind == CLASS && - !owner.isAnonymousClass() && !owner.isCompoundSym() || - Global.instance.debug) - return " in " + owner; - else - return ""; + if (owner.kind == CLASS && + !owner.isAnonymousClass() && !owner.isCompoundSym() || + Global.instance.debug) + return " in " + owner; + else + return ""; } /** String representation of definition. @@ -1057,10 +1057,10 @@ public abstract class Symbol implements Modifiers, Kinds { } public static String[] defString(Symbol[] defs) { - String[] strs = new String[defs.length]; - for (int i = 0; i < defs.length; i++) - strs[i] = defs[i].defString(); - return strs; + String[] strs = new String[defs.length]; + for (int i = 0; i < defs.length; i++) + strs[i] = defs[i].defString(); + return strs; } // Overloading and Overriding ------------------------------------------- @@ -1069,14 +1069,14 @@ public abstract class Symbol implements Modifiers, Kinds { */ public Symbol overloadWith(Symbol that) { assert isTerm() : Debug.show(this); - assert this.name == that.name : Debug.show(this) + " <> " + Debug.show(that); - assert this.owner == that.owner : Debug.show(this) + " != " + Debug.show(that); - assert this.isConstructor() == that.isConstructor(); - int overflags = (this.flags & that.flags & (JAVA | ACCESSFLAGS)) | - ((this.flags | that.flags) & ACCESSOR); - TermSymbol overloaded = (this.isConstructor()) - ? TermSymbol.newConstructor(this.constructorClass(), overflags) - : new TermSymbol(pos, name, owner, overflags); + assert this.name == that.name : Debug.show(this) + " <> " + Debug.show(that); + assert this.owner == that.owner : Debug.show(this) + " != " + Debug.show(that); + assert this.isConstructor() == that.isConstructor(); + int overflags = (this.flags & that.flags & (JAVA | ACCESSFLAGS)) | + ((this.flags | that.flags) & ACCESSOR); + TermSymbol overloaded = (this.isConstructor()) + ? TermSymbol.newConstructor(this.constructorClass(), overflags) + : new TermSymbol(pos, name, owner, overflags); overloaded.setInfo(new LazyOverloadedType(this, that)); return overloaded; } @@ -1085,127 +1085,127 @@ public abstract class Symbol implements Modifiers, Kinds { * of symbols `sym1' and `sym2'. It also checks that this type is well-formed. */ public static class LazyOverloadedType extends Type.LazyType { - Symbol sym1; - Symbol sym2; - LazyOverloadedType(Symbol sym1, Symbol sym2) { - this.sym1 = sym1; - this.sym2 = sym2; - } - - public Symbol[] alternativeSymbols() { - Symbol[] alts1 = sym1.alternativeSymbols(); - Symbol[] alts2 = sym2.alternativeSymbols(); - Symbol[] alts3 = new Symbol[alts1.length + alts2.length]; - System.arraycopy(alts1, 0, alts3, 0, alts1.length); - System.arraycopy(alts2, 0, alts3, alts1.length, alts2.length); - return alts3; - } - - public Type[] alternativeTypes() { - Type[] alts1 = sym1.alternativeTypes(); - Type[] alts2 = sym2.alternativeTypes(); - Type[] alts3 = new Type[alts1.length + alts2.length]; - System.arraycopy(alts1, 0, alts3, 0, alts1.length); - System.arraycopy(alts2, 0, alts3, alts1.length, alts2.length); - return alts3; - } - - public void complete(Symbol overloaded) { - overloaded.setInfo( - Type.OverloadedType( - alternativeSymbols(), alternativeTypes())); - } - - public String toString() { - return "LazyOverloadedType(" + sym1 + "," + sym2 + ")"; - } + Symbol sym1; + Symbol sym2; + LazyOverloadedType(Symbol sym1, Symbol sym2) { + this.sym1 = sym1; + this.sym2 = sym2; + } + + public Symbol[] alternativeSymbols() { + Symbol[] alts1 = sym1.alternativeSymbols(); + Symbol[] alts2 = sym2.alternativeSymbols(); + Symbol[] alts3 = new Symbol[alts1.length + alts2.length]; + System.arraycopy(alts1, 0, alts3, 0, alts1.length); + System.arraycopy(alts2, 0, alts3, alts1.length, alts2.length); + return alts3; + } + + public Type[] alternativeTypes() { + Type[] alts1 = sym1.alternativeTypes(); + Type[] alts2 = sym2.alternativeTypes(); + Type[] alts3 = new Type[alts1.length + alts2.length]; + System.arraycopy(alts1, 0, alts3, 0, alts1.length); + System.arraycopy(alts2, 0, alts3, alts1.length, alts2.length); + return alts3; + } + + public void complete(Symbol overloaded) { + overloaded.setInfo( + Type.OverloadedType( + alternativeSymbols(), alternativeTypes())); + } + + public String toString() { + return "LazyOverloadedType(" + sym1 + "," + sym2 + ")"; + } } /** The symbol which is overridden by this symbol in base class `base' * `base' must be a superclass of this.owner(). */ public Symbol overriddenSymbol(Type base) { - assert !isOverloaded() : this; - Symbol sym1 = base.lookupNonPrivate(name); - if (sym1.kind == Kinds.NONE || (sym1.flags & STATIC) != 0) { - return Symbol.NONE; - } else { - //System.out.println(this + ":" + this.type() + locationString() + " overrides? " + sym1 + ":" + owner.thisType().memberType(sym1) + sym1.locationString()); //DEBUG - - Type symtype = this.type().derefDef(); - Type sym1type = owner.thisType().memberType(sym1).derefDef(); - switch (sym1type) { - case OverloadedType(Symbol[] alts, Type[] alttypes): - for (int i = 0; i < alts.length; i++) { - if (symtype.isSubType(alttypes[i].derefDef())) - return alts[i]; - } - return Symbol.NONE; - default: - if (symtype.isSubType(sym1type)) return sym1; - else { - if (Global.instance.debug) System.out.println(this + locationString() + " does not override " + sym1 + sym1.locationString() + ", since " + symtype + " !<= " + sym1type);//DEBUG - return Symbol.NONE; - } - } - } + assert !isOverloaded() : this; + Symbol sym1 = base.lookupNonPrivate(name); + if (sym1.kind == Kinds.NONE || (sym1.flags & STATIC) != 0) { + return Symbol.NONE; + } else { + //System.out.println(this + ":" + this.type() + locationString() + " overrides? " + sym1 + ":" + owner.thisType().memberType(sym1) + sym1.locationString()); //DEBUG + + Type symtype = this.type().derefDef(); + Type sym1type = owner.thisType().memberType(sym1).derefDef(); + switch (sym1type) { + case OverloadedType(Symbol[] alts, Type[] alttypes): + for (int i = 0; i < alts.length; i++) { + if (symtype.isSubType(alttypes[i].derefDef())) + return alts[i]; + } + return Symbol.NONE; + default: + if (symtype.isSubType(sym1type)) return sym1; + else { + if (Global.instance.debug) System.out.println(this + locationString() + " does not override " + sym1 + sym1.locationString() + ", since " + symtype + " !<= " + sym1type);//DEBUG + return Symbol.NONE; + } + } + } } /** The symbol which overrides this symbol in subclass `sub' * `sub' must be a subclass of this.owner(). */ public Symbol overridingSymbol(Type sub) { - assert !isOverloaded() : this; - Symbol sym1 = sub.lookup(name); - if (sym1.kind == Kinds.NONE || (sym1.flags & STATIC) != 0) { - return Symbol.NONE; - } else { - //System.out.println(this + ":" + this.type() + locationString() + " overrides? " + sym1 + sym1.type() + sym1.locationString()); //DEBUG - //System.out.println(owner.thisType());//DEBUG - - Type symtype = sub.memberType(this).derefDef(); - Type sym1type = sub.memberType(sym1).derefDef(); - switch (sym1type) { - case OverloadedType(Symbol[] alts, Type[] alttypes): - for (int i = 0; i < alts.length; i++) { - if (alttypes[i].derefDef().isSubType(symtype)) return alts[i]; - } - return Symbol.NONE; - default: - if (sym1type.isSubType(symtype)) return sym1; - else { - if (Global.instance.debug) System.out.println(this + locationString() + " is not overridden by " + sym1 + sym1.locationString() + ", since " + sym1type + " !<= " + symtype);//DEBUG - return Symbol.NONE; - } - } - } + assert !isOverloaded() : this; + Symbol sym1 = sub.lookup(name); + if (sym1.kind == Kinds.NONE || (sym1.flags & STATIC) != 0) { + return Symbol.NONE; + } else { + //System.out.println(this + ":" + this.type() + locationString() + " overrides? " + sym1 + sym1.type() + sym1.locationString()); //DEBUG + //System.out.println(owner.thisType());//DEBUG + + Type symtype = sub.memberType(this).derefDef(); + Type sym1type = sub.memberType(sym1).derefDef(); + switch (sym1type) { + case OverloadedType(Symbol[] alts, Type[] alttypes): + for (int i = 0; i < alts.length; i++) { + if (alttypes[i].derefDef().isSubType(symtype)) return alts[i]; + } + return Symbol.NONE; + default: + if (sym1type.isSubType(symtype)) return sym1; + else { + if (Global.instance.debug) System.out.println(this + locationString() + " is not overridden by " + sym1 + sym1.locationString() + ", since " + sym1type + " !<= " + symtype);//DEBUG + return Symbol.NONE; + } + } + } } /** Does this symbol override that symbol? */ public boolean overrides(Symbol that) { - return - ((this.flags | that.flags) & (PRIVATE | STATIC)) == 0 && - this.name == that.name && - owner.thisType().memberType(this).derefDef().isSubType( - owner.thisType().memberType(that).derefDef()); + return + ((this.flags | that.flags) & (PRIVATE | STATIC)) == 0 && + this.name == that.name && + owner.thisType().memberType(this).derefDef().isSubType( + owner.thisType().memberType(that).derefDef()); } /** Reset symbol to initial state */ public void reset(Type completer) { - this.flags &= SOURCEFLAGS; - this.pos = 0; - this.infos = null; - this.setInfo(completer); + this.flags &= SOURCEFLAGS; + this.pos = 0; + this.infos = null; + this.setInfo(completer); } /** return a tag which (in the ideal case) uniquely identifies * class symbols */ - public int tag() { - return name.toString().hashCode(); - } + public int tag() { + return name.toString().hashCode(); + } } /** A class for term symbols @@ -1217,66 +1217,66 @@ public class TermSymbol extends Symbol { /** Constructor */ public TermSymbol(int pos, Name name, Symbol owner, int flags) { super(VAL, pos, name, owner, flags); - assert !name.isTypeName() : this; + assert !name.isTypeName() : this; } public static TermSymbol define( - int pos, Name name, Symbol owner, int flags, Scope scope) { - Scope.Entry e = scope.lookupEntry(name); - if (e.owner == scope && e.sym.isExternal() && e.sym.kind == VAL) { - TermSymbol sym = (TermSymbol) e.sym; - sym.update(pos, flags); - return sym; - } else { - return new TermSymbol(pos, name, owner, flags); - } + int pos, Name name, Symbol owner, int flags, Scope scope) { + Scope.Entry e = scope.lookupEntry(name); + if (e.owner == scope && e.sym.isExternal() && e.sym.kind == VAL) { + TermSymbol sym = (TermSymbol) e.sym; + sym.update(pos, flags); + return sym; + } else { + return new TermSymbol(pos, name, owner, flags); + } } public static TermSymbol newConstructor(Symbol clazz, int flags) { TermSymbol sym = new TermSymbol( - clazz.pos, Names.CONSTRUCTOR, clazz.owner(), flags); - sym.clazz = clazz; - return sym; + clazz.pos, Names.CONSTRUCTOR, clazz.owner(), flags); + sym.clazz = clazz; + return sym; } public static TermSymbol newJavaConstructor(Symbol clazz) { - return newConstructor(clazz, clazz.flags & (ACCESSFLAGS | JAVA)); + return newConstructor(clazz, clazz.flags & (ACCESSFLAGS | JAVA)); } public TermSymbol makeModule(ClassSymbol clazz) { - flags |= MODUL | FINAL; - this.clazz = clazz; - clazz.setModule(this); - setInfo(clazz.typeConstructor()); - return this; + flags |= MODUL | FINAL; + this.clazz = clazz; + clazz.setModule(this); + setInfo(clazz.typeConstructor()); + return this; } public TermSymbol makeModule() { ClassSymbol clazz = new ClassSymbol( - pos, name.toTypeName(), owner(), flags | MODUL | FINAL); + pos, name.toTypeName(), owner(), flags | MODUL | FINAL); clazz.primaryConstructor().setInfo( - Type.MethodType(Symbol.EMPTY_ARRAY, clazz.typeConstructor())); - return makeModule(clazz); + Type.MethodType(Symbol.EMPTY_ARRAY, clazz.typeConstructor())); + return makeModule(clazz); } /** Constructor for companion modules to classes, which need to be completed. */ public static TermSymbol newCompanionModule(Symbol clazz, int flags, Type.LazyType parser) { TermSymbol sym = new TermSymbol( - Position.NOPOS, clazz.name.toTermName(), clazz.owner(), flags) - .makeModule(); + Position.NOPOS, clazz.name.toTermName(), clazz.owner(), flags) + .makeModule(); sym.clazz.setInfo(parser); - return sym; + return sym; } /** Java package module constructor */ public static TermSymbol newJavaPackageModule(Name name, Symbol owner, Type.LazyType parser) { TermSymbol sym = new TermSymbol(Position.NOPOS, name, owner, JAVA | PACKAGE) - .makeModule(); + .makeModule(); sym.clazz.flags |= SYNTHETIC; sym.clazz.setInfo(parser != null ? parser : Type.compoundType(Type.EMPTY_ARRAY, new Scope(), sym)); - return sym; + return sym; } /** Dummy symbol for template of given class @@ -1289,18 +1289,18 @@ public class TermSymbol extends Symbol { /** Get this.type corresponding to this class or module */ public Type thisType() { - if ((flags & MODUL) != 0) return moduleClass().thisType(); - else return Type.localThisType; + if ((flags & MODUL) != 0) return moduleClass().thisType(); + else return Type.localThisType; } /** Get the fully qualified name of this Symbol */ public Name fullName() { - if (clazz != null) return clazz.fullName(); - else return super.fullName(); + if (clazz != null) return clazz.fullName(); + else return super.fullName(); } /** Is this symbol a constructor? */ public boolean isConstructor() { - return name == Names.CONSTRUCTOR; + return name == Names.CONSTRUCTOR; } /** Return a fresh symbol with the same fields as this one. @@ -1308,30 +1308,30 @@ public class TermSymbol extends Symbol { public Symbol cloneSymbol(Symbol owner) { assert !isPrimaryConstructor() : Debug.show(this); TermSymbol other; - if (isModule()) { - other = new TermSymbol(pos, name, owner, flags).makeModule(); - } else { - other = new TermSymbol(pos, name, owner, flags); - other.clazz = clazz; - } + if (isModule()) { + other = new TermSymbol(pos, name, owner, flags).makeModule(); + } else { + other = new TermSymbol(pos, name, owner, flags); + other.clazz = clazz; + } other.setInfo(info()); return other; } public Symbol[] typeParams() { - return type().typeParams(); + return type().typeParams(); } public Symbol[] valueParams() { - return type().valueParams(); + return type().valueParams(); } public Symbol constructorClass() { - return isConstructor() && clazz != null ? clazz : this; + return isConstructor() && clazz != null ? clazz : this; } public Symbol moduleClass() { - return (flags & MODUL) != 0 ? clazz : this; + return (flags & MODUL) != 0 ? clazz : this; } } @@ -1357,42 +1357,42 @@ public abstract class TypeSymbol extends Symbol { /** Constructor */ public TypeSymbol(int kind, int pos, Name name, Symbol owner, int flags) { super(kind, pos, name, owner, flags); - assert name.isTypeName() : this; - if (kind != TYPE) - this.constructor = TermSymbol.newConstructor(this, flags & ~MODUL); + assert name.isTypeName() : this; + if (kind != TYPE) + this.constructor = TermSymbol.newConstructor(this, flags & ~MODUL); } protected void update(int pos, int flags) { - super.update(pos, flags); - this.template = null; + super.update(pos, flags); + this.template = null; } /** copy all fields to `sym' */ public void copyTo(Symbol sym) { - super.copyTo(sym); - if (kind != TYPE) { - Symbol symconstr = ((TypeSymbol) sym).constructor; - constructor.copyTo(symconstr); - if (constructor.isInitialized()) - symconstr.setInfo(fixConstrType(symconstr.type(), sym)); - } + super.copyTo(sym); + if (kind != TYPE) { + Symbol symconstr = ((TypeSymbol) sym).constructor; + constructor.copyTo(symconstr); + if (constructor.isInitialized()) + symconstr.setInfo(fixConstrType(symconstr.type(), sym)); + } } protected void copyConstructorInfo(TypeSymbol other) { - other.primaryConstructor().setInfo( - fixConstrType( - primaryConstructor().info().cloneType( - primaryConstructor(), other.primaryConstructor()), - other)); - Symbol[] alts = allConstructors().alternativeSymbols(); - for (int i = 1; i < alts.length; i++) { - Symbol constr = other.addConstructor(); - constr.setInfo( - fixConstrType( - alts[i].info().cloneType(alts[i], constr), - other)); - } + other.primaryConstructor().setInfo( + fixConstrType( + primaryConstructor().info().cloneType( + primaryConstructor(), other.primaryConstructor()), + other)); + Symbol[] alts = allConstructors().alternativeSymbols(); + for (int i = 1; i < alts.length; i++) { + Symbol constr = other.addConstructor(); + constr.setInfo( + fixConstrType( + alts[i].info().cloneType(alts[i], constr), + other)); + } } private Type fixConstrType(Type type, Symbol clone) { @@ -1406,8 +1406,8 @@ public abstract class TypeSymbol extends Symbol { case TypeRef(Type pre, Symbol sym, Type[] args): assert sym == this : Debug.show(sym) + " != " + Debug.show(this); return new Type.TypeRef(pre, clone, args); - case LazyType(): - return type; + case LazyType(): + return type; default: throw Debug.abort("unexpected constructor type:" + clone + ":" + type); } @@ -1416,9 +1416,9 @@ public abstract class TypeSymbol extends Symbol { /** add a constructor */ public Symbol addConstructor() { - Symbol constr = TermSymbol.newConstructor(this, flags & ~MODUL); - constructor = constructor.overloadWith(constr); - return constr; + Symbol constr = TermSymbol.newConstructor(this, flags & ~MODUL); + constructor = constructor.overloadWith(constr); + return constr; } /** Get primary constructor */ @@ -1428,50 +1428,50 @@ public abstract class TypeSymbol extends Symbol { /** Get all constructors */ public Symbol allConstructors() { - return (kind == TYPE) ? Symbol.NONE : constructor; + return (kind == TYPE) ? Symbol.NONE : constructor; } /** Get type parameters */ public Symbol[] typeParams() { - return (kind == TYPE) ? Symbol.EMPTY_ARRAY - : primaryConstructor().info().typeParams(); + return (kind == TYPE) ? Symbol.EMPTY_ARRAY + : primaryConstructor().info().typeParams(); } /** Get value parameters */ public Symbol[] valueParams() { - return (kind == CLASS) ? primaryConstructor().info().valueParams() - : Symbol.EMPTY_ARRAY; + return (kind == CLASS) ? primaryConstructor().info().valueParams() + : Symbol.EMPTY_ARRAY; } /** Get type constructor */ public Type typeConstructor() { - if (tycon == null) - tycon = Type.TypeRef(owner().thisType(), this, Type.EMPTY_ARRAY); - return tycon; + if (tycon == null) + tycon = Type.TypeRef(owner().thisType(), this, Type.EMPTY_ARRAY); + return tycon; } public Symbol setOwner(Symbol owner) { tycon = null; - template = null; + template = null; return super.setOwner(owner); } /** Get type */ public Type type() { - Symbol[] tparams = typeParams(); - if (template != null) { - switch (template) { - case TypeRef(_, _, Type[] targs): - if (targs.length == tparams.length) - return template; - } - } - if (tparams.length == 0) - template = typeConstructor(); - else - template = Type.TypeRef( - owner().thisType(), this, type(tparams)); - return template; + Symbol[] tparams = typeParams(); + if (template != null) { + switch (template) { + case TypeRef(_, _, Type[] targs): + if (targs.length == tparams.length) + return template; + } + } + if (tparams.length == 0) + template = typeConstructor(); + else + template = Type.TypeRef( + owner().thisType(), this, type(tparams)); + return template; } /** @@ -1550,28 +1550,28 @@ public abstract class TypeSymbol extends Symbol { return inclClosure(set.incl(sym), sym.type().parents()); } - private void adjustType(Type tp) { - Type tp1 = tp.unalias(); - switch (tp) { - case CompoundType(Type[] parents, _): - break; - default: + private void adjustType(Type tp) { + Type tp1 = tp.unalias(); + switch (tp) { + case CompoundType(Type[] parents, _): + break; + default: Symbol sym = tp1.symbol(); - int pos = closurePos(sym); - assert pos >= 0 : this + " " + tp1 + " " + tp1.symbol() + " " + pos; - closures.closure[pos] = tp1; - } - Type[] parents = tp1.parents(); - for (int i = 0; i < parents.length; i++) { - adjustType(parents[i]); - } - } + int pos = closurePos(sym); + assert pos >= 0 : this + " " + tp1 + " " + tp1.symbol() + " " + pos; + closures.closure[pos] = tp1; + } + Type[] parents = tp1.parents(); + for (int i = 0; i < parents.length; i++) { + adjustType(parents[i]); + } + } public void reset(Type completer) { - super.reset(completer); - closures = null; - tycon = null; - template = null; + super.reset(completer); + closures = null; + tycon = null; + template = null; } } @@ -1583,15 +1583,15 @@ public class AliasTypeSymbol extends TypeSymbol { } public static AliasTypeSymbol define( - int pos, Name name, Symbol owner, int flags, Scope scope) { - Scope.Entry e = scope.lookupEntry(name); - if (e.owner == scope && e.sym.isExternal() && e.sym.kind == ALIAS) { - AliasTypeSymbol sym = (AliasTypeSymbol) e.sym; - sym.update(pos, flags); - return sym; - } else { - return new AliasTypeSymbol(pos, name, owner, flags); - } + int pos, Name name, Symbol owner, int flags, Scope scope) { + Scope.Entry e = scope.lookupEntry(name); + if (e.owner == scope && e.sym.isExternal() && e.sym.kind == ALIAS) { + AliasTypeSymbol sym = (AliasTypeSymbol) e.sym; + sym.update(pos, flags); + return sym; + } else { + return new AliasTypeSymbol(pos, name, owner, flags); + } } /** Return a fresh symbol with the same fields as this one. @@ -1599,7 +1599,7 @@ public class AliasTypeSymbol extends TypeSymbol { public Symbol cloneSymbol(Symbol owner) { AliasTypeSymbol other = new AliasTypeSymbol(pos, name, owner, flags); other.setInfo(info()); - copyConstructorInfo(other); + copyConstructorInfo(other); return other; } } @@ -1614,15 +1614,15 @@ public class AbsTypeSymbol extends TypeSymbol { } public static AbsTypeSymbol define( - int pos, Name name, Symbol owner, int flags, Scope scope) { - Scope.Entry e = scope.lookupEntry(name); - if (e.owner == scope && e.sym.isExternal() && e.sym.kind == TYPE) { - AbsTypeSymbol sym = (AbsTypeSymbol) e.sym; - sym.update(pos, flags); - return sym; - } else { - return new AbsTypeSymbol(pos, name, owner, flags); - } + int pos, Name name, Symbol owner, int flags, Scope scope) { + Scope.Entry e = scope.lookupEntry(name); + if (e.owner == scope && e.sym.isExternal() && e.sym.kind == TYPE) { + AbsTypeSymbol sym = (AbsTypeSymbol) e.sym; + sym.update(pos, flags); + return sym; + } else { + return new AbsTypeSymbol(pos, name, owner, flags); + } } /** Return a fresh symbol with the same fields as this one. @@ -1630,25 +1630,25 @@ public class AbsTypeSymbol extends TypeSymbol { public Symbol cloneSymbol(Symbol owner) { TypeSymbol other = new AbsTypeSymbol(pos, name, owner, flags); other.setInfo(info()); - other.setLoBound(loBound()); + other.setLoBound(loBound()); return other; } /** copy all fields to `sym' */ public void copyTo(Symbol sym) { - super.copyTo(sym); - ((AbsTypeSymbol) sym).lobound = lobound; + super.copyTo(sym); + ((AbsTypeSymbol) sym).lobound = lobound; } public Type loBound() { - initialize(); - return lobound == null ? Global.instance.definitions.ALL_TYPE : lobound; + initialize(); + return lobound == null ? Global.instance.definitions.ALL_TYPE : lobound; } public Symbol setLoBound(Type lobound) { - this.lobound = lobound; - return this; + this.lobound = lobound; + return this; } } @@ -1684,30 +1684,30 @@ public class ClassSymbol extends TypeSymbol { } public static ClassSymbol define( - int pos, Name name, Symbol owner, int flags, Scope scope) { - Scope.Entry e = scope.lookupEntry(name); - if (e.owner == scope && e.sym.isExternal() && e.sym.kind == CLASS) { - ClassSymbol sym = (ClassSymbol) e.sym; - sym.update(pos, flags); - return sym; - } else { - return new ClassSymbol(pos, name, owner, flags); - } + int pos, Name name, Symbol owner, int flags, Scope scope) { + Scope.Entry e = scope.lookupEntry(name); + if (e.owner == scope && e.sym.isExternal() && e.sym.kind == CLASS) { + ClassSymbol sym = (ClassSymbol) e.sym; + sym.update(pos, flags); + return sym; + } else { + return new ClassSymbol(pos, name, owner, flags); + } } /** Constructor for classes to load as source files */ public ClassSymbol(Name name, Symbol owner, SourceCompleter parser) { - this(Position.NOPOS, name, owner, 0); - this.module = TermSymbol.newCompanionModule(this, 0, parser); + this(Position.NOPOS, name, owner, 0); + this.module = TermSymbol.newCompanionModule(this, 0, parser); this.setInfo(parser); } /** Constructor for classes to load as class files. */ public ClassSymbol(Name name, Symbol owner, ClassParser parser) { - this(Position.NOPOS, name, owner, JAVA); - this.module = TermSymbol.newCompanionModule(this, JAVA, parser.staticsParser(this)); + this(Position.NOPOS, name, owner, JAVA); + this.module = TermSymbol.newCompanionModule(this, JAVA, parser.staticsParser(this)); this.setInfo(parser); } @@ -1715,19 +1715,19 @@ public class ClassSymbol extends TypeSymbol { */ public Symbol cloneSymbol(Symbol owner) { ClassSymbol other = new ClassSymbol(pos, name, owner, flags); - other.module = module; + other.module = module; other.setInfo(info()); - copyConstructorInfo(other); - other.mangled = mangled; - if (thisSym != this) other.setTypeOfThis(typeOfThis()); + copyConstructorInfo(other); + other.mangled = mangled; + if (thisSym != this) other.setTypeOfThis(typeOfThis()); return other; } /** copy all fields to `sym' */ public void copyTo(Symbol sym) { - super.copyTo(sym); - if (thisSym != this) sym.setTypeOfThis(typeOfThis()); + super.copyTo(sym); + if (thisSym != this) sym.setTypeOfThis(typeOfThis()); } /** Get module */ @@ -1760,31 +1760,31 @@ public class ClassSymbol extends TypeSymbol { /** Get the fully qualified mangled name of this Symbol */ public Name mangledFullName() { - if (mangled == name) { - return fullName().replace((byte)'.', (byte)'$'); - } else { - Symbol tc = enclToplevelClass(); - if (tc != this) { - return Name.fromString( - enclToplevelClass().mangledFullName() + "$" + mangled); - } else { - return mangled; - } - } + if (mangled == name) { + return fullName().replace((byte)'.', (byte)'$'); + } else { + Symbol tc = enclToplevelClass(); + if (tc != this) { + return Name.fromString( + enclToplevelClass().mangledFullName() + "$" + mangled); + } else { + return mangled; + } + } } public Type thisType() { - return thistp; + return thistp; } public Type typeOfThis() { - return thisSym.type(); + return thisSym.type(); } public Symbol setTypeOfThis(Type tp) { - thisSym = new TermSymbol(this.pos, Names.this_, this, SYNTHETIC); - thisSym.setInfo(tp); - return this; + thisSym = new TermSymbol(this.pos, Names.this_, this, SYNTHETIC); + thisSym.setInfo(tp); + return this; } /** Return the next enclosing class */ @@ -1793,23 +1793,34 @@ public class ClassSymbol extends TypeSymbol { } public Symbol caseFieldAccessor(int index) { - assert (flags & CASE) != 0 : this; - Scope.SymbolIterator it = info().members().iterator(); - Symbol sym = null; - for (int i = 0; i <= index; i++) { - do { - sym = it.next(); - } while (sym.kind != VAL || (sym.flags & CASEACCESSOR) == 0 || !sym.isMethod()); - } - //System.out.println(this + ", case field[" + index + "] = " + sym);//DEBUG - assert sym != null : this; - return sym; + assert (flags & CASE) != 0 : this; + Scope.SymbolIterator it = info().members().iterator(); + Symbol sym = null; + if ((flags & JAVA) == 0) { + for (int i = 0; i <= index; i++) { + do { + sym = it.next(); + } while (sym.kind != VAL || (sym.flags & CASEACCESSOR) == 0 || !sym.isMethod()); + } + //System.out.println(this + ", case field[" + index + "] = " + sym);//DEBUG + } else { + sym = it.next(); + while ((sym.flags & SYNTHETIC) == 0) { + System.out.println("skipping " + sym); + sym = it.next(); + } + for (int i = 0; i < index; i++) + sym = it.next(); + System.out.println("field accessor = " + sym); + } + assert sym != null : this; + return sym; } public void reset(Type completer) { - super.reset(completer); - module().reset(completer); - thisSym = this; + super.reset(completer); + module().reset(completer); + thisSym = this; } } @@ -1826,7 +1837,7 @@ public final class ErrorSymbol extends Symbol { public Symbol cloneSymbol(Symbol owner) { assert owner == this : Debug.show(owner); - return this; + return this; } /** Set the mangled name of this Symbol */ @@ -1848,7 +1859,7 @@ public final class ErrorSymbol extends Symbol { /** Get primary constructor */ public Symbol primaryConstructor() { - return TermSymbol.newConstructor(this, 0).setInfo(Type.ErrorType); + return TermSymbol.newConstructor(this, 0).setInfo(Type.ErrorType); } /** Return the next enclosing class */ @@ -1862,7 +1873,7 @@ public final class ErrorSymbol extends Symbol { } public Type loBound() { - return Type.ErrorType; + return Type.ErrorType; } public void reset(Type completer) { @@ -1915,7 +1926,7 @@ public final class NoSymbol extends Symbol { } public Symbol owner() { - throw new ApplicationError(); + throw new ApplicationError(); } public void reset(Type completer) { @@ -1927,9 +1938,9 @@ public final class NoSymbol extends Symbol { public class LabelSymbol extends TermSymbol { /** give as argument the symbol of the function that triggered - the creation of this label */ + the creation of this label */ public LabelSymbol(Symbol f) { - super(f.pos, f.name, f, LABEL); + super(f.pos, f.name, f, LABEL); } } @@ -1939,9 +1950,9 @@ public class CyclicReference extends Type.Error { public Symbol sym; public Type info; public CyclicReference(Symbol sym, Type info) { - super("illegal cyclic reference involving " + sym); - this.sym = sym; - this.info = info; + super("illegal cyclic reference involving " + sym); + this.sym = sym; + this.info = info; } } diff --git a/sources/scalac/symtab/classfile/AttributeParser.java b/sources/scalac/symtab/classfile/AttributeParser.java index 7c52cd347e..d7bda1c82d 100644 --- a/sources/scalac/symtab/classfile/AttributeParser.java +++ b/sources/scalac/symtab/classfile/AttributeParser.java @@ -57,6 +57,8 @@ public class AttributeParser implements ClassfileConstants { return META_ATTR; if (name == SCALA_N) return SCALA_ATTR; + if (name == JACO_N) + return JACO_ATTR; return BAD_ATTR; } @@ -82,8 +84,7 @@ public class AttributeParser implements ClassfileConstants { // class attributes case SCALA_ATTR: new UnPickle(sym, in.nextBytes(attrLen), Name.fromString(in.path)); - return; - + return; case INNERCLASSES_ATTR: /* int n = in.nextChar(); for (int i = 0; i < n; i++) { @@ -99,12 +100,10 @@ public class AttributeParser implements ClassfileConstants { } */ in.skip(attrLen); return; - // method attributes case CODE_ATTR: in.skip(attrLen); return; - case EXCEPTIONS_ATTR: //int nexceptions = in.nextChar(); //Type[] thrown = new Type[nexceptions]; @@ -113,39 +112,42 @@ public class AttributeParser implements ClassfileConstants { //((MethodType)def.type).thrown = thrown; in.skip(attrLen); return; - case LINE_NUM_TABLE_ATTR: in.skip(attrLen); return; - case LOCAL_VAR_TABLE_ATTR: in.skip(attrLen); return; - // general attributes case SYNTHETIC_ATTR: sym.flags |= Modifiers.SYNTHETIC; return; - case DEPRECATED_ATTR: sym.flags |= Modifiers.DEPRECATED; return; - case CONSTANT_VALUE_ATTR: // Type ctype = (Type)reader.readPool(in.nextChar()); // def.type = types.coerce(ctype, def.type); in.skip(attrLen); return; - case META_ATTR: //System.out.println("parsing meta data for " + sym); String meta = pool.readPool(in.nextChar()).toString().trim(); sym.setFirstInfo( - new MetaParser(meta, tvars, sym, type).parse()); + new MetaParser(meta, tvars, sym, type).parse()); return; - - default: - in.skip(attrLen); + case JACO_ATTR: + // this attribute is present in all PiCo generated classfiles + int mods = in.nextChar(); + mods |= (in.nextChar() << 16); + boolean algebraicClass = (mods & 0x00100000) != 0; + boolean caseClass = (mods & 0x00200000) != 0; + if (caseClass) + sym.flags |= Modifiers.CASE | Modifiers.JAVA; + in.skip(attrLen - 4); + return; + default: + in.skip(attrLen); return; } } @@ -175,22 +177,22 @@ public class AttributeParser implements ClassfileConstants { private Symbol getTVar(String name, Symbol owner) { if (name.startsWith("?")) { - Symbol s = ((locals != null) ? locals : tvars) - .lookup(Name.fromString(name).toTypeName()); - if (s != Symbol.NONE) - return s; - else if (locals != null) { - s = tvars.lookup(Name.fromString(name).toTypeName()); - if (s != Symbol.NONE) - return s; - } + Symbol s = ((locals != null) ? locals : tvars) + .lookup(Name.fromString(name).toTypeName()); + if (s != Symbol.NONE) + return s; + else if (locals != null) { + s = tvars.lookup(Name.fromString(name).toTypeName()); + if (s != Symbol.NONE) + return s; + } s = new AbsTypeSymbol( - Position.NOPOS, - Name.fromString(token).toTypeName(), - owner, - Modifiers.PARAM); - s.setFirstInfo(parser.defs.ANY_TYPE); - tvars.enter(s); + Position.NOPOS, + Name.fromString(token).toTypeName(), + owner, + Modifiers.PARAM); + s.setFirstInfo(parser.defs.ANY_TYPE); + tvars.enter(s); return s; } else return Symbol.NONE; @@ -254,17 +256,17 @@ public class AttributeParser implements ClassfileConstants { Symbol[] smbls = (Symbol[])syms.toArray(new Symbol[syms.size()]); //System.out.println("*** " + syms);//DEBUG Type clazztype = Type.appliedType( - parser.ctype, Symbol.type(smbls)); - Symbol constr = parser.c.primaryConstructor(); - switch (constr.rawInfo()) { - case MethodType(Symbol[] vparams, _): - constr.setFirstInfo( - Type.PolyType( - smbls, Type.MethodType(vparams, clazztype))); - break; - default: - throw new ApplicationError(constr.rawInfo()); - } + parser.ctype, Symbol.type(smbls)); + Symbol constr = parser.c.primaryConstructor(); + switch (constr.rawInfo()) { + case MethodType(Symbol[] vparams, _): + constr.setFirstInfo( + Type.PolyType( + smbls, Type.MethodType(vparams, clazztype))); + break; + default: + throw new ApplicationError(constr.rawInfo()); + } } catch (NoSuchElementException e) { } } @@ -324,12 +326,12 @@ public class AttributeParser implements ClassfileConstants { break; assert token.startsWith("?"); Symbol s = new AbsTypeSymbol( - Position.NOPOS, - Name.fromString(token).toTypeName(), - owner, - Modifiers.PARAM); - s.setFirstInfo(parser.defs.ANY_TYPE); - locals.enter(s); + Position.NOPOS, + Name.fromString(token).toTypeName(), + owner, + Modifiers.PARAM); + s.setFirstInfo(parser.defs.ANY_TYPE); + locals.enter(s); nextToken(); if (token.equals("<")) { nextToken(); diff --git a/sources/scalac/symtab/classfile/ClassfileConstants.java b/sources/scalac/symtab/classfile/ClassfileConstants.java index 16b9f5af44..e35150ae30 100644 --- a/sources/scalac/symtab/classfile/ClassfileConstants.java +++ b/sources/scalac/symtab/classfile/ClassfileConstants.java @@ -41,6 +41,7 @@ public interface ClassfileConstants { int INNERCLASSES_ATTR = 0x08000; int META_ATTR = 0x10000; int SCALA_ATTR = 0x20000; + int JACO_ATTR = 0x40000; Name SOURCEFILE_N = Name.fromString("SourceFile"); Name SYNTHETIC_N = Name.fromString("Synthetic"); @@ -53,5 +54,6 @@ public interface ClassfileConstants { Name INNERCLASSES_N = Name.fromString("InnerClasses"); Name META_N = Name.fromString("JacoMeta"); Name SCALA_N = Name.fromString("ScalaSignature"); + Name JACO_N = Name.fromString("JacoInterface"); Name CONSTR_N = Name.fromString("<init>"); } diff --git a/sources/scalac/symtab/classfile/ClassfileParser.java b/sources/scalac/symtab/classfile/ClassfileParser.java index 04d876fce8..28f31c3647 100644 --- a/sources/scalac/symtab/classfile/ClassfileParser.java +++ b/sources/scalac/symtab/classfile/ClassfileParser.java @@ -24,7 +24,8 @@ public class ClassfileParser implements ClassfileConstants { | SYNTHETIC_ATTR | DEPRECATED_ATTR | META_ATTR - | SCALA_ATTR; + | SCALA_ATTR + | JACO_ATTR; static final int METH_ATTR = CODE_ATTR | EXCEPTIONS_ATTR | SYNTHETIC_ATTR @@ -52,7 +53,7 @@ public class ClassfileParser implements ClassfileConstants { this.global = global; this.in = in; this.c = c; - this.ctype = c.typeConstructor(); + this.ctype = c.typeConstructor(); this.make = new JavaTypeCreator(global); this.sigs = new Signatures(global, make); this.pool = new ConstantPool(in, sigs); @@ -84,8 +85,8 @@ public class ClassfileParser implements ClassfileConstants { "' contains wrong class " + name); // todo: correct flag transition c.flags = transFlags(flags); - if ((c.flags & Modifiers.DEFERRED) != 0) - c.flags = c.flags & ~Modifiers.DEFERRED | Modifiers.ABSTRACTCLASS; + if ((c.flags & Modifiers.DEFERRED) != 0) + c.flags = c.flags & ~Modifiers.DEFERRED | Modifiers.ABSTRACTCLASS; Type supertpe = readClassType(in.nextChar()); Type[] basetpes = new Type[in.nextChar() + 1]; this.locals = new Scope(); @@ -94,13 +95,13 @@ public class ClassfileParser implements ClassfileConstants { Type classType = Type.compoundType(basetpes, locals, c); c.setFirstInfo(classType); // set type of statics - Symbol staticsClass = c.module().moduleClass(); - if (staticsClass.isModuleClass()) { - Type staticsInfo = Type.compoundType(Type.EMPTY_ARRAY, statics, staticsClass); - staticsClass.setFirstInfo(staticsInfo); - c.module().setInfo(Type.TypeRef(staticsClass.owner().thisType(), - staticsClass, Type.EMPTY_ARRAY)); - } + Symbol staticsClass = c.module().moduleClass(); + if (staticsClass.isModuleClass()) { + Type staticsInfo = Type.compoundType(Type.EMPTY_ARRAY, statics, staticsClass); + staticsClass.setFirstInfo(staticsInfo); + c.module().setInfo(Type.TypeRef(staticsClass.owner().thisType(), + staticsClass, Type.EMPTY_ARRAY)); + } basetpes[0] = supertpe; for (int i = 1; i < basetpes.length; i++) basetpes[i] = readClassType(in.nextChar()); @@ -111,18 +112,18 @@ public class ClassfileParser implements ClassfileConstants { for (int i = 0; i < methodCount; i++) parseMethod(); - Symbol constr = c.primaryConstructor(); - if (!constr.isInitialized()) { - constr.setFirstInfo( - Type.MethodType(Symbol.EMPTY_ARRAY, ctype)); - if ((c.flags & Modifiers.INTERFACE) == 0) - constr.flags |= Modifiers.PRIVATE; - } + Symbol constr = c.primaryConstructor(); + if (!constr.isInitialized()) { + constr.setFirstInfo( + Type.MethodType(Symbol.EMPTY_ARRAY, ctype)); + if ((c.flags & Modifiers.INTERFACE) == 0) + constr.flags |= Modifiers.PRIVATE; + } attrib.readAttributes(c, classType, CLASS_ATTR); - //System.out.println("dynamic class: " + c); - //System.out.println("statics class: " + staticsClass); - //System.out.println("module: " + c.module()); - //System.out.println("modules class: " + c.module().type().symbol()); + //System.out.println("dynamic class: " + c); + //System.out.println("statics class: " + staticsClass); + //System.out.println("module: " + c.module()); + //System.out.println("modules class: " + c.module().type().symbol()); } catch (RuntimeException e) { if (global.debug) e.printStackTrace(); String s = e.getMessage() == null ? "" : " (" +e.getMessage()+ ")"; @@ -178,16 +179,16 @@ public class ClassfileParser implements ClassfileConstants { int flags = in.nextChar(); Name name = (Name)pool.readPool(in.nextChar()); Type type = readType(in.nextChar()); - int mods = transFlags(flags); - if ((flags & 0x0010) == 0) - mods |= Modifiers.MUTABLE; - Symbol owner = c; - if ((flags & 0x0008) != 0) - owner = c.module().moduleClass(); + int mods = transFlags(flags); + if ((flags & 0x0010) == 0) + mods |= Modifiers.MUTABLE; + Symbol owner = c; + if ((flags & 0x0008) != 0) + owner = c.module().moduleClass(); Symbol s = new TermSymbol(Position.NOPOS, name, owner, mods); s.setFirstInfo(type); attrib.readAttributes(s, type, FIELD_ATTR); - ((flags & 0x0008) != 0 ? statics : locals).enterOrOverload(s); + ((flags & 0x0008) != 0 ? statics : locals).enterOrOverload(s); } /** read a method @@ -206,27 +207,27 @@ public class ClassfileParser implements ClassfileConstants { return; } switch (type) { - case MethodType(Symbol[] vparams, _): - type = Type.MethodType(vparams, ctype); - break; - default: - throw new ApplicationError(); - } - s.setFirstInfo(type); + case MethodType(Symbol[] vparams, _): + type = Type.MethodType(vparams, ctype); + break; + default: + throw new ApplicationError(); + } + s.setFirstInfo(type); attrib.readAttributes(s, type, METH_ATTR); - Symbol constr = c.primaryConstructor(); - if (constr.isInitialized()) constr = c.addConstructor(); - s.copyTo(constr); - //System.out.println(c + " " + c.allConstructors() + ":" + c.allConstructors().info());//debug + Symbol constr = c.primaryConstructor(); + if (constr.isInitialized()) constr = c.addConstructor(); + s.copyTo(constr); + //System.out.println(c + " " + c.allConstructors() + ":" + c.allConstructors().info());//debug //System.out.println("-- enter " + s); } else { - Symbol s = new TermSymbol( - Position.NOPOS, name, - ((flags & 0x0008) != 0) ? c.module().moduleClass() : c, - transFlags(flags)); - s.setFirstInfo(type); - attrib.readAttributes(s, type, METH_ATTR); - ((flags & 0x0008) != 0 ? statics : locals).enterOrOverload(s); - } + Symbol s = new TermSymbol( + Position.NOPOS, name, + ((flags & 0x0008) != 0) ? c.module().moduleClass() : c, + transFlags(flags)); + s.setFirstInfo(type); + attrib.readAttributes(s, type, METH_ATTR); + ((flags & 0x0008) != 0 ? statics : locals).enterOrOverload(s); + } } } diff --git a/sources/scalac/transformer/matching/PatternMatcher.java b/sources/scalac/transformer/matching/PatternMatcher.java index 8466362731..2d644ab11b 100644 --- a/sources/scalac/transformer/matching/PatternMatcher.java +++ b/sources/scalac/transformer/matching/PatternMatcher.java @@ -473,22 +473,27 @@ public class PatternMatcher extends PatternTool { Symbol ts = ((ClassSymbol) casted.type().symbol()) .caseFieldAccessor(index); Type accType = casted.type().memberType(ts); - target.and = curHeader = mk.Header( - pat.pos, - accType.resultType(), - make.Apply( - pat.pos, - make.Select( - pat.pos, - make.Ident(pat.pos, casted.name) - .setType(casted.type()) - .setSymbol(casted), - ts.name) - .setType(Type.MethodType( - Symbol.EMPTY_ARRAY, - accType.resultType())) - .setSymbol(ts), - Tree.EMPTY_ARRAY).setType(accType.resultType())); + Tree accTree = make.Select( + pat.pos, + make.Ident(pat.pos, casted.name) + .setType(casted.type()).setSymbol(casted), + ts.name) + .setType(accType).setSymbol(ts); + switch (accType) { + // scala case accessor + case MethodType(_, _): + target.and = curHeader = mk.Header( + pat.pos, + accType.resultType(), + make.Apply( + pat.pos, + accTree, + Tree.EMPTY_ARRAY).setType(accType.resultType())); + break; + // jaco case accessor + default: + target.and = curHeader = mk.Header(pat.pos, accType, accTree); + } } curHeader.or = patternNode(pat, curHeader, env); return enter(patArgs, curHeader.or, casted, env); diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java index f840da0c30..3bec1700e2 100644 --- a/sources/scalac/typechecker/Analyzer.java +++ b/sources/scalac/typechecker/Analyzer.java @@ -1226,7 +1226,12 @@ public class Analyzer extends Transformer implements Modifiers, Kinds { if (clazz.isCaseClass()) { // set type to instantiated case class constructor tree.type = tree.type.prefix().memberType( - clazz.primaryConstructor()); + clazz.primaryConstructor()); + // MZ: this is a hack, but I didn't know how to do it better + if ((clazz.flags & (JAVA | CASE)) == (JAVA | CASE)) { + tree.type = tree.type.prefix().memberType( + clazz.allConstructors().alternativeSymbols()[1]); + } switch (tree.type) { case PolyType(Symbol[] tparams, Type restp): try { |