diff options
author | paltherr <paltherr@epfl.ch> | 2004-03-18 18:23:12 +0000 |
---|---|---|
committer | paltherr <paltherr@epfl.ch> | 2004-03-18 18:23:12 +0000 |
commit | f6835d10b6db16b30e94c2cd4038014a97243eb6 (patch) | |
tree | 95c039054d0fe5d02ea1d1dee192502a7bba0eb2 /sources/scalac | |
parent | 0a10a202bb3f2ced07f6bb63bd9e4bf8f9d8ad34 (diff) | |
download | scala-f6835d10b6db16b30e94c2cd4038014a97243eb6.tar.gz scala-f6835d10b6db16b30e94c2cd4038014a97243eb6.tar.bz2 scala-f6835d10b6db16b30e94c2cd4038014a97243eb6.zip |
- Added factory methods for term symbol in clas...
- Added factory methods for term symbol in class Symbol Made subclasses
- of Symbol private (except for ClassSymbol)
Diffstat (limited to 'sources/scalac')
23 files changed, 279 insertions, 294 deletions
diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java index 47194c947d..bba074a80a 100644 --- a/sources/scalac/ast/TreeGen.java +++ b/sources/scalac/ast/TreeGen.java @@ -785,8 +785,8 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { public Tree mkNewArray(int pos, Type element, Tree[] values, Symbol owner){ if (values.length == 0) return mkNewArray(pos, element, 0); Tree[] trees = new Tree[1 + values.length]; - Symbol array = - newLocal(pos, Names.array, owner, definitions.ARRAY_TYPE(element)); + Symbol array = newLocal( + owner, pos, FINAL, "array", definitions.ARRAY_TYPE(element)); trees[0] = ValDef(array, mkNewArray(pos, element, values.length)); for (int i = 0; i < values.length; i++) trees[1 + i] = mkArraySet(Ident(pos, array), i, values[i]); @@ -1046,10 +1046,13 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { return true; } - /** Creates a local variable with given prefix, owner and type. */ - private Symbol newLocal(int pos, Name prefix, Symbol owner, Type type) { + /** Creates a new local variable and initializes it. */ + private Symbol newLocal(Symbol owner, int pos, int flags, String prefix, + Type type) + { Name name = global.freshNameCreator.newName(prefix); - Symbol local = new TermSymbol(pos, name, owner, Modifiers.SYNTHETIC); + flags |= Modifiers.SYNTHETIC; + Symbol local = owner.newVariable(pos, flags, name); global.nextPhase(); local.setType(type); global.prevPhase(); @@ -1110,7 +1113,7 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { clazz.allConstructors().setInfo( Type.MethodType(Symbol.EMPTY_ARRAY, clazz.typeConstructor())); - Symbol applyMeth = new TermSymbol(pos, Names.apply, clazz, FINAL) + Symbol applyMeth = clazz.newMethod(pos, FINAL, Names.apply) .setInfo(Type.MethodType(params, restype)); clazz.info().members().enter(applyMeth); @@ -1150,9 +1153,8 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { private Tree makeVisitorMethod(int pos, Name name, Tree visitor, Type pattype, Type restype, Symbol clazz, Symbol prevOwner) { - Symbol meth = new TermSymbol(pos, name, clazz, FINAL); - Symbol param = new TermSymbol(pos, Name.fromString("x$"), meth, PARAM) - .setInfo(pattype); + Symbol meth = clazz.newMethod(pos, FINAL, name); + Symbol param = meth.newVParam(pos, 0, Name.fromString("x$"), pattype); meth.setInfo(Type.MethodType(new Symbol[]{param}, restype)); clazz.info().members().enter(meth); changeOwner(visitor, prevOwner, meth); @@ -1187,13 +1189,9 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { if (TreeInfo.isPureExpr(obj) || TreeInfo.isPureExpr(fn)) { return Apply(Select(fn, definitions.FUNCTION_APPLY(1)), new Tree[]{obj}); } else { - Name tmpname = global.freshNameCreator.newName("tmp", '$'); - Symbol tmp = new TermSymbol( - obj.pos, tmpname, owner, SYNTHETIC | FINAL) - .setInfo(obj.type); - Tree tmpdef = ValDef(tmp, obj); + Symbol tmp = newLocal(owner, obj.pos, FINAL, "postfix", obj.type); Tree expr = postfixApply(Ident(obj.pos, tmp), fn, owner); - return mkBlock(tmpdef, expr); + return mkBlock(ValDef(tmp, obj), expr); } } diff --git a/sources/scalac/atree/ATreeFromSTree.java b/sources/scalac/atree/ATreeFromSTree.java index 8929eaf7cf..e886ece922 100644 --- a/sources/scalac/atree/ATreeFromSTree.java +++ b/sources/scalac/atree/ATreeFromSTree.java @@ -19,7 +19,6 @@ import scalac.ast.Tree.Ident; import scalac.ast.Tree.Template; import scalac.symtab.Definitions; import scalac.symtab.Symbol; -import scalac.symtab.TermSymbol; import scalac.symtab.Type; import scalac.util.Debug; import scalac.util.Name; @@ -437,7 +436,7 @@ public class ATreeFromSTree { private Symbol newLocal(Tree tree, Type type) { Symbol owner = Symbol.NONE; // !!! Name name = Name.fromString("local"); // !!! - return new TermSymbol(tree.pos, name, owner, 0).setType(type); + return owner.newTerm(tree.pos, 0, name).setType(type); } /** Returns the type kind of given type. */ diff --git a/sources/scalac/atree/ATreeTyper.java b/sources/scalac/atree/ATreeTyper.java index 70156802d5..686ada1c2d 100644 --- a/sources/scalac/atree/ATreeTyper.java +++ b/sources/scalac/atree/ATreeTyper.java @@ -14,7 +14,6 @@ import scalac.Global; import scalac.symtab.Definitions; import scalac.symtab.Modifiers; import scalac.symtab.Symbol; -import scalac.symtab.TermSymbol; import scalac.symtab.Type; import scalac.util.Debug; import scalac.util.Name; @@ -303,8 +302,8 @@ public class ATreeTyper { Symbol[] tparams = new Symbol[targs.length]; for (int i = 0; i < tparams.length; i++) { Name name = Name.fromString("v" + i); - tparams[i] = new TermSymbol( - Position.NOPOS, name, Symbol.NONE, Modifiers.PARAM); + tparams[i] = Symbol.NONE.newTerm( // !!! should be newVParam + Position.NOPOS, Modifiers.PARAM, name); tparams[i].setType(targs[i]); } return Type.MethodType(tparams, result); diff --git a/sources/scalac/symtab/Definitions.java b/sources/scalac/symtab/Definitions.java index 0dd25108bb..01c6b85b66 100644 --- a/sources/scalac/symtab/Definitions.java +++ b/sources/scalac/symtab/Definitions.java @@ -642,30 +642,30 @@ public class Definitions { initClass(ALL_CLASS, new Type[]{ANY_TYPE()}); // create type symbols - UNIT_TYPE = newTypeSymbol(Names.Unit ,UNIT_CLASS .staticType()); - BOOLEAN_TYPE = newTypeSymbol(Names.Boolean,BOOLEAN_CLASS.staticType()); - BYTE_TYPE = newTypeSymbol(Names.Byte ,BYTE_CLASS .staticType()); - SHORT_TYPE = newTypeSymbol(Names.Short ,SHORT_CLASS .staticType()); - CHAR_TYPE = newTypeSymbol(Names.Char ,CHAR_CLASS .staticType()); - INT_TYPE = newTypeSymbol(Names.Int ,INT_CLASS .staticType()); - LONG_TYPE = newTypeSymbol(Names.Long ,LONG_CLASS .staticType()); - FLOAT_TYPE = newTypeSymbol(Names.Float ,FLOAT_CLASS .staticType()); - DOUBLE_TYPE = newTypeSymbol(Names.Double ,DOUBLE_CLASS .staticType()); - ARRAY_TYPE = newTypeSymbol(Names.Array , + UNIT_TYPE = newTypeMethod(Names.Unit ,UNIT_CLASS .staticType()); + BOOLEAN_TYPE = newTypeMethod(Names.Boolean,BOOLEAN_CLASS.staticType()); + BYTE_TYPE = newTypeMethod(Names.Byte ,BYTE_CLASS .staticType()); + SHORT_TYPE = newTypeMethod(Names.Short ,SHORT_CLASS .staticType()); + CHAR_TYPE = newTypeMethod(Names.Char ,CHAR_CLASS .staticType()); + INT_TYPE = newTypeMethod(Names.Int ,INT_CLASS .staticType()); + LONG_TYPE = newTypeMethod(Names.Long ,LONG_CLASS .staticType()); + FLOAT_TYPE = newTypeMethod(Names.Float ,FLOAT_CLASS .staticType()); + DOUBLE_TYPE = newTypeMethod(Names.Double ,DOUBLE_CLASS .staticType()); + ARRAY_TYPE = newTypeMethod(Names.Array , ARRAY_CLASS.staticType(new Type[]{ANYREF_TYPE()})); - TYPE_TYPE = newTypeSymbol(Names.Type , TYPE_CLASS.type ()); + TYPE_TYPE = newTypeMethod(Names.Type , TYPE_CLASS.type ()); // add members to scala.Any - ANY_EQ = newTerm(ANY_CLASS, Names.eq , 0); - ANY_EQEQ = newTerm(ANY_CLASS, Names.EQEQ , Modifiers.FINAL); - ANY_BANGEQ = newTerm(ANY_CLASS, Names.BANGEQ , Modifiers.FINAL); - ANY_EQUALS = newTerm(ANY_CLASS, Names.equals , 0); - ANY_HASHCODE = newTerm(ANY_CLASS, Names.hashCode , 0); - ANY_TOSTRING = newTerm(ANY_CLASS, Names.toString , 0); - // ANY_PLUS = newTerm(ANY_CLASS, Names.PLUS , Modifiers.FINAL); - ANY_IS = newTerm(ANY_CLASS, Names.isInstanceOf, Modifiers.FINAL); - ANY_AS = newTerm(ANY_CLASS, Names.asInstanceOf, Modifiers.FINAL); - ANY_MATCH = newTerm(ANY_CLASS, Names.match , Modifiers.FINAL); + ANY_EQ = newMethod(ANY_CLASS,Names.eq , 0); + ANY_EQEQ = newMethod(ANY_CLASS,Names.EQEQ ,Modifiers.FINAL); + ANY_BANGEQ = newMethod(ANY_CLASS,Names.BANGEQ ,Modifiers.FINAL); + ANY_EQUALS = newMethod(ANY_CLASS,Names.equals ,0); + ANY_HASHCODE = newMethod(ANY_CLASS,Names.hashCode ,0); + ANY_TOSTRING = newMethod(ANY_CLASS,Names.toString ,0); + // ANY_PLUS = newMethod(ANY_CLASS,Names.PLUS ,Modifiers.FINAL); + ANY_IS = newMethod(ANY_CLASS,Names.isInstanceOf,Modifiers.FINAL); + ANY_AS = newMethod(ANY_CLASS,Names.asInstanceOf,Modifiers.FINAL); + ANY_MATCH = newMethod(ANY_CLASS,Names.match ,Modifiers.FINAL); initMethod(ANY_EQ , new Type[]{ANY_TYPE()} , BOOLEAN_TYPE()); initMethod(ANY_EQEQ , new Type[]{ANY_TYPE()} , BOOLEAN_TYPE()); @@ -697,7 +697,7 @@ public class Definitions { // add members to java.lang.Object OBJECT_SYNCHRONIZED = - newTerm(OBJECT_CLASS, Names.synchronized_, Modifiers.FINAL); + newMethod(OBJECT_CLASS, Names.synchronized_, Modifiers.FINAL); Symbol OBJECT_SYNCHRONIZED_TPARAM = newTParam(OBJECT_SYNCHRONIZED,0,ANY_TYPE()); @@ -711,16 +711,17 @@ public class Definitions { OBJECT_SYNCHRONIZED_TPARAM.type()))); // add members to java.lang.String - STRING_PLUS = newTerm(STRING_CLASS, Names.PLUS, Modifiers.FINAL); + STRING_PLUS = newMethod(STRING_CLASS, Names.PLUS, Modifiers.FINAL); initMethod(STRING_PLUS, new Type[]{ANY_TYPE()}, STRING_TYPE()); // add members to java.lang.Throwable - THROWABLE_THROW =newTerm(THROWABLE_CLASS,Names.throw_,Modifiers.FINAL); + THROWABLE_THROW = + newMethod(THROWABLE_CLASS, Names.throw_, Modifiers.FINAL); THROWABLE_THROW.setInfo(Type.PolyType(Symbol.EMPTY_ARRAY, ALL_TYPE())); // create global values - PATTERN_WILDCARD = new TermSymbol( - Position.NOPOS, Names.PATTERN_WILDCARD, Symbol.NONE, 0); + PATTERN_WILDCARD = Symbol.NONE.newTerm( + Position.NOPOS, 0, Names.PATTERN_WILDCARD); PATTERN_WILDCARD.setInfo(ALL_TYPE()); // initialize unboxed types in class Type @@ -792,10 +793,10 @@ public class Definitions { return alias; } - /** Creates a new term */ - private Symbol newTerm(Symbol owner, Name name, int flags) { + /** Creates a new method */ + private Symbol newMethod(Symbol owner, Name name, int flags) { assert owner.isClassType(): Debug.show(owner) + " -- " + name; - Symbol term = new TermSymbol(Position.NOPOS, name, owner, flags); + Symbol term = owner.newMethod(Position.NOPOS, flags, name); owner.members().enterOrOverload(term); return term; } @@ -809,13 +810,12 @@ public class Definitions { /** Creates a new value parameter */ private Symbol newVParam(Symbol owner, int index, Type type) { Name name = Name.fromString("v" + index); - return new TermSymbol(Position.NOPOS, name, owner, Modifiers.PARAM) - .setInfo(type); + return owner.newVParam(Position.NOPOS, 0, name, type); } - /** Creates a new type symbol */ - private Symbol newTypeSymbol(Name name, Type type) { - Symbol symbol = new TermSymbol(Position.NOPOS, name, ROOT_CLASS, 0); + /** Creates a new type method */ + private Symbol newTypeMethod(Name name, Type type) { + Symbol symbol = ANY_CLASS.newMethod(Position.NOPOS, 0, name); initMethod(symbol, Type.EMPTY_ARRAY, type); return symbol; } diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java index 9f44c821c6..9804e5c121 100644 --- a/sources/scalac/symtab/Symbol.java +++ b/sources/scalac/symtab/Symbol.java @@ -32,16 +32,18 @@ public abstract class Symbol implements Modifiers, Kinds { public static final Symbol[][] EMPTY_ARRAY_ARRAY = new Symbol[0][]; /** The error symbol */ - public static final ErrorSymbol ERROR = new ErrorSymbol(); + public static final Symbol ERROR = new ErrorSymbol(); /** The absent symbol */ - public static final NoSymbol NONE = new NoSymbol(); + public static final Symbol NONE = new NoSymbol(); // Attribues ------------------------------------------------------------- - public static final int IS_ROOT = 0x00000001; - public static final int IS_LABEL = 0x00000010; - public static final int IS_COMPOUND = 0x80000000; + public static final int IS_ROOT = 0x00000001; + public static final int IS_LABEL = 0x00000010; + public static final int IS_THISTYPE = 0x20000000; + public static final int IS_LOCALDUMMY = 0x40000000; + public static final int IS_COMPOUND = 0x80000000; // Fields ------------------------------------------------------------- @@ -88,25 +90,66 @@ public abstract class Symbol implements Modifiers, Kinds { // Factories -------------------------------------------------------------- - /** Creates a new constructor of this symbol. */ - public final TermSymbol newTerm(int pos, int flags, Name name) { - return new TermSymbol(pos, name, this, flags, 0); + /** Creates a new term owned by this symbol. */ + public final Symbol newTerm(int pos, int flags, Name name) { + return newTerm(pos, flags, name, 0); } /** Creates a new constructor of this symbol. */ - public final TermSymbol newConstructor(int pos, int flags) { + public final Symbol newConstructor(int pos, int flags) { assert isType(): Debug.show(this); return new TermSymbol(pos, Names.CONSTRUCTOR, owner(), flags, 0, this); } - /** Creates a new Label owned by this symbol. */ - public final TermSymbol newLabel(int pos, Name name) { + /** Creates a new method owned by this symbol. */ + public final Symbol newMethod(int pos, int flags, Name name) { + assert isClass(): Debug.show(this); + return newTerm(pos, flags, name, 0); + } + + /** Creates a new function owned by this symbol. */ + public final Symbol newFunction(int pos, int flags, Name name) { + assert isTerm(): Debug.show(this); + return newTerm(pos, flags, name, 0); + } + + /** Creates a new method or function owned by this symbol. */ + public final Symbol newMethodOrFunction(int pos, int flags, Name name){ + assert isClass() || isTerm(): Debug.show(this); + return newTerm(pos, flags, name, 0); + } + + /** Creates a new label owned by this symbol. */ + public final Symbol newLabel(int pos, Name name) { + assert isTerm(): Debug.show(this); + return newTerm(pos, 0, name, IS_LABEL); + } + + /** Creates a new field owned by this symbol. */ + public final Symbol newField(int pos, int flags, Name name) { + assert isClass(): Debug.show(this); + return newTerm(pos, flags, name, 0); + } + + /** Creates a new variable owned by this symbol. */ + public final Symbol newVariable(int pos, int flags, Name name) { assert isTerm(): Debug.show(this); - return new TermSymbol(pos, name, this, 0, IS_LABEL); + return newTerm(pos, flags, name, 0); + } + + /** Creates a new variable owned by this symbol. */ + public final Symbol newFieldOrVariable(int pos, int flags, Name name) { + assert isClass() || isTerm(): Debug.show(this); + return newTerm(pos, flags, name, 0); + } + + /** Creates a new pattern variable owned by this symbol. */ + public final Symbol newPatternVariable(int pos, Name name) { + return newVariable(pos, 0, name); } /** Creates a new value parameter owned by this symbol. */ - public final TermSymbol newVParam(int pos, int flags, Name name) { + public final Symbol newVParam(int pos, int flags, Name name) { assert isTerm(): Debug.show(this); return newTerm(pos, flags | PARAM, name); } @@ -115,8 +158,8 @@ public abstract class Symbol implements Modifiers, Kinds { * Creates a new value parameter owned by this symbol and * initializes it with the type. */ - public final TermSymbol newVParam(int pos, int flags, Name name,Type type){ - TermSymbol tparam = newVParam(pos, flags, name); + public final Symbol newVParam(int pos, int flags, Name name, Type type) { + Symbol tparam = newVParam(pos, flags, name); tparam.setInfo(type); return tparam; } @@ -125,24 +168,24 @@ public abstract class Symbol implements Modifiers, Kinds { * Creates a new initialized dummy symbol for template of this * class. */ - public final TermSymbol newLocalDummy() { + public final Symbol newLocalDummy() { assert isClass(): Debug.show(this); - TermSymbol local = new TermSymbol(pos, Names.LOCAL(this), this, 0); + Symbol local = newTerm(pos, 0, Names.LOCAL(this), IS_LOCALDUMMY); local.setInfo(Type.NoType); return local; } /** Creates a new module owned by this symbol. */ - public final TermSymbol newModule(int pos, int flags, Name name) { + public final Symbol newModule(int pos, int flags, Name name) { ClassSymbol clasz = newModuleClass(pos, flags, name.toTypeName()); - return (TermSymbol)clasz.module(); + return clasz.module(); } /** * Creates a new package owned by this symbol and initializes it * with an empty scope. */ - public final TermSymbol newPackage(int pos, Name name) { + public final Symbol newPackage(int pos, Name name) { return newPackage(pos, name, null); } @@ -150,27 +193,27 @@ public abstract class Symbol implements Modifiers, Kinds { * Creates a new package owned by this symbol, initializes it with * the loader and enters it in the scope if it's non-null. */ - public final TermSymbol newLoadedPackage(Name name, SymbolLoader loader, + public final Symbol newLoadedPackage(Name name, SymbolLoader loader, Scope scope) { assert loader != null: Debug.show(this) + " - " + name; - TermSymbol peckage = newPackage(Position.NOPOS, name, loader); + Symbol peckage = newPackage(Position.NOPOS, name, loader); if (scope != null) scope.enterNoHide(peckage); return peckage; } /** Creates a new type alias owned by this symbol. */ - public final AliasTypeSymbol newTypeAlias(int pos, int flags, Name name) { + public final Symbol newTypeAlias(int pos, int flags, Name name) { return new AliasTypeSymbol(pos, name, this, flags, 0); } /** Creates a new abstract type owned by this symbol. */ - public final AbsTypeSymbol newAbstractType(int pos, int flags, Name name) { + public final Symbol newAbstractType(int pos, int flags, Name name) { return new AbsTypeSymbol(pos, name, this, flags, 0); } /** Creates a new type parameter owned by this symbol. */ - public final AbsTypeSymbol newTParam(int pos, int flags, Name name) { + public final Symbol newTParam(int pos, int flags, Name name) { assert isTerm(): Debug.show(this); return newAbstractType(pos, flags | PARAM, name); } @@ -179,8 +222,8 @@ public abstract class Symbol implements Modifiers, Kinds { * Creates a new type parameter owned by this symbol and * initializes it with the type. */ - public final AbsTypeSymbol newTParam(int pos, int flags, Name name, Type type) { - AbsTypeSymbol tparam = newTParam(pos, flags, name); + public final Symbol newTParam(int pos, int flags, Name name, Type type) { + Symbol tparam = newTParam(pos, flags, name); tparam.setInfo(type); return tparam; } @@ -189,10 +232,8 @@ public abstract class Symbol implements Modifiers, Kinds { * Creates a new type alias owned by this symbol and initializes * it with the info. */ - public final AliasTypeSymbol newTypeAlias(int pos, int flags, Name name, - Type info) - { - AliasTypeSymbol alias = newTypeAlias(pos, flags, name); + public final Symbol newTypeAlias(int pos, int flags, Name name, Type info){ + Symbol alias = newTypeAlias(pos, flags, name); alias.setInfo(info); alias.allConstructors().setInfo(Type.MethodType(EMPTY_ARRAY, info)); return alias; @@ -228,10 +269,15 @@ public abstract class Symbol implements Modifiers, Kinds { return clasz; } + /** Creates a new term owned by this symbol. */ + final Symbol newTerm(int pos, int flags, Name name, int attrs) { + return new TermSymbol(pos, name, this, flags, attrs, null); + } + /** Creates a new package owned by this symbol. */ - final TermSymbol newPackage(int pos, Name name, Type info) { + final Symbol newPackage(int pos, Name name, Type info) { assert isPackageClass(): Debug.show(this); - TermSymbol peckage = newModule(pos, JAVA | PACKAGE, name); + Symbol peckage = newModule(pos, JAVA | PACKAGE, name); if (info == null) info = Type.compoundType( Type.EMPTY_ARRAY, new Scope(), peckage.moduleClass()); peckage.moduleClass().setInfo(info); @@ -1331,9 +1377,9 @@ public abstract class Symbol implements Modifiers, Kinds { assert this.isConstructor() == that.isConstructor(); int overflags = (this.flags & that.flags & (JAVA | ACCESSFLAGS | DEFERRED)) | ((this.flags | that.flags) & ACCESSOR); - TermSymbol overloaded = (this.isConstructor()) + Symbol overloaded = (this.isConstructor()) ? this.constructorClass().newConstructor(this.constructorClass().pos, overflags) - : new TermSymbol(pos, name, owner, overflags); + : owner.newTerm(pos, overflags, name, 0); overloaded.setInfo(new LazyOverloadedType(this, that)); return overloaded; } @@ -1466,7 +1512,7 @@ public abstract class Symbol implements Modifiers, Kinds { /** A class for term symbols */ -public class TermSymbol extends Symbol { +final class TermSymbol extends Symbol { /** * The module class if this is a module, the constructed class if @@ -1475,12 +1521,6 @@ public class TermSymbol extends Symbol { private final Symbol clasz; /** Constructor */ - public TermSymbol(int pos, Name name, Symbol owner, int flags) { - this(pos, name, owner, flags, 0); - } - public TermSymbol(int pos, Name name, Symbol owner, int flags, int attrs) { - this(pos, name, owner, flags, attrs, null); - } TermSymbol(int pos, Name name, Symbol owner, int flags, int attrs, Symbol clasz) { super(VAL, pos, name, owner, flags, attrs); this.clasz = clasz; @@ -1523,7 +1563,7 @@ public class TermSymbol extends Symbol { /** A base class for all type symbols. * It has AliasTypeSymbol, AbsTypeSymbol, ClassSymbol as subclasses. */ -public abstract class TypeSymbol extends Symbol { +abstract class TypeSymbol extends Symbol { /** The history of closures of this symbol */ private final History/*<Type[]>*/ closures; @@ -1660,7 +1700,7 @@ public abstract class TypeSymbol extends Symbol { protected abstract TypeSymbol cloneTypeSymbolImpl(Symbol owner, int attrs); } -public final class AliasTypeSymbol extends TypeSymbol { +final class AliasTypeSymbol extends TypeSymbol { /** Initializes this instance. */ AliasTypeSymbol(int pos, Name name, Symbol owner, int flags, int attrs) { @@ -1673,7 +1713,7 @@ public final class AliasTypeSymbol extends TypeSymbol { } -public final class AbsTypeSymbol extends TypeSymbol { +final class AbsTypeSymbol extends TypeSymbol { private Type lobound = null; @@ -1767,12 +1807,17 @@ public final class ClassSymbol extends TypeSymbol { return clasz; } + /** Creates the this-type symbol associated to this class. */ + private final Symbol newThisType() { + return newTerm(pos, SYNTHETIC, Names.this_, IS_THISTYPE); + } + /** Creates the module associated to this module class. */ - final TermSymbol newModule() { + final Symbol newModule() { assert isModuleClass(): Debug.show(this); int flags = (this.flags & CLASS2MODULEFLAGS) | MODUL | FINAL | STABLE; Name name = this.name.toTermName(); - TermSymbol module = new TermSymbol(pos, name, owner(), flags, 0, this); + Symbol module = new TermSymbol(pos, name, owner(), flags, 0, this); module.setType(typeConstructor()); return module; } @@ -1805,7 +1850,7 @@ public final class ClassSymbol extends TypeSymbol { } public Symbol setTypeOfThis(Type tp) { - thisSym = new TermSymbol(this.pos, Names.this_, this, SYNTHETIC); + thisSym = newThisType(); thisSym.setInfo(tp); return this; } @@ -1861,7 +1906,7 @@ public final class ClassSymbol extends TypeSymbol { /** A class for error symbols. */ -public final class ErrorSymbol extends Symbol { +final class ErrorSymbol extends Symbol { /** Constructor */ public ErrorSymbol() { @@ -1905,7 +1950,7 @@ public final class ErrorSymbol extends Symbol { /** The class of Symbol.NONE */ -public final class NoSymbol extends Symbol { +final class NoSymbol extends Symbol { /** Constructor */ public NoSymbol() { diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java index 02808fe755..11665b7a14 100644 --- a/sources/scalac/symtab/Type.java +++ b/sources/scalac/symtab/Type.java @@ -2715,7 +2715,7 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags { Symbol lubSym; switch (lubKind) { case VAL: - lubSym = new TermSymbol(syms[0].pos, syms[0].name, owner, 0); + lubSym = owner.newTerm(syms[0].pos, 0, syms[0].name); break; case TYPE: case ALIAS: case CLASS: lubSym = owner.newAbstractType(syms[0].pos, 0, syms[0].name); diff --git a/sources/scalac/symtab/classfile/AttributeParser.java b/sources/scalac/symtab/classfile/AttributeParser.java index f6477eb3f5..c0b2444737 100644 --- a/sources/scalac/symtab/classfile/AttributeParser.java +++ b/sources/scalac/symtab/classfile/AttributeParser.java @@ -397,16 +397,15 @@ public class AttributeParser implements ClassfileConstants { nextToken(); if (")".equals(token)) break; - int flags = Modifiers.PARAM; + int flags = 0; if ("def".equals(token)) { nextToken(); flags |= Modifiers.DEF; } - params.add(new TermSymbol( + params.add(owner.newVParam( Position.NOPOS, - Name.fromString("x" + (i++)), - owner, - flags).setInfo(parseType())); + flags, + Name.fromString("x" + (i++))).setInfo(parseType())); //System.out.println(" + " + token); } while (token.equals(",")); assert ")".equals(token); @@ -455,11 +454,10 @@ public class AttributeParser implements ClassfileConstants { nextToken(); if (")".equals(token)) break; - params.add(new TermSymbol( + params.add(owner.newVParam( Position.NOPOS, - Name.fromString("x" + (i++)), - owner, - Modifiers.PARAM).setInfo(parseType())); + 0, + Name.fromString("x" + (i++))).setInfo(parseType())); //System.out.println(" + " + token); } while (token.equals(",")); assert ")".equals(token); diff --git a/sources/scalac/symtab/classfile/CLRClassParser.java b/sources/scalac/symtab/classfile/CLRClassParser.java index 393f8b1130..2914cae6bc 100644 --- a/sources/scalac/symtab/classfile/CLRClassParser.java +++ b/sources/scalac/symtab/classfile/CLRClassParser.java @@ -12,8 +12,6 @@ import scalac.Global; import scalac.atree.AConstant; import scalac.symtab.Symbol; import scalac.symtab.SymbolLoader; -import scalac.symtab.TermSymbol; -import scalac.symtab.ClassSymbol; import scalac.symtab.Scope; import scalac.symtab.Modifiers; import scalac.symtab.Type.*; @@ -114,7 +112,7 @@ public class CLRClassParser extends SymbolLoader { fieldType = make.constantType( getConstant(fieldType.symbol(), fields[i].getValue())); Symbol owner = fields[i].IsStatic() ? staticsClass : clazz; - Symbol field = new TermSymbol(Position.NOPOS, name, owner, mods); + Symbol field = owner.newField(Position.NOPOS, mods, name); field.setInfo(fieldType); (fields[i].IsStatic() ? statics : members).enterOrOverload(field); importer.map(field, fields[i]); @@ -135,7 +133,7 @@ public class CLRClassParser extends SymbolLoader { scalac.symtab.Type.PolyType(Symbol.EMPTY_ARRAY, proptype); int mods = translateAttributes(getter); Symbol owner = getter.IsStatic() ? staticsClass : clazz; - Symbol method = new TermSymbol(Position.NOPOS, n, owner, mods); + Symbol method = owner.newMethod(Position.NOPOS, mods, n); setParamOwners(mtype, method); method.setInfo(mtype); (getter.IsStatic() ? statics : members).enterOrOverload(method); @@ -150,7 +148,7 @@ public class CLRClassParser extends SymbolLoader { continue; n = n.append(Names._EQ); mods = translateAttributes(setter); - method = new TermSymbol(Position.NOPOS, n, owner, mods); + method = owner.newMethod(Position.NOPOS, mods, n); setParamOwners(mtype, method); method.setInfo(mtype); (setter.IsStatic() ? statics : members).enterOrOverload(method); @@ -178,7 +176,7 @@ public class CLRClassParser extends SymbolLoader { else n = Name.fromString(name); int mods = translateAttributes(methods[i]); Symbol owner = methods[i].IsStatic() ? staticsClass : clazz; - Symbol method = new TermSymbol(Position.NOPOS, n, owner, mods); + Symbol method = owner.newMethod(Position.NOPOS, mods, n); setParamOwners(mtype, method); method.setInfo(mtype); (methods[i].IsStatic() ? statics : members).enterOrOverload(method); @@ -196,8 +194,8 @@ public class CLRClassParser extends SymbolLoader { make.methodType(argTypes, global.definitions.BOOLEAN_TYPE(), scalac.symtab.Type.EMPTY_ARRAY); - Symbol enumCmp = new TermSymbol - (Position.NOPOS, ENUM_CMP_NAMES[i], clazz, mods); + Symbol enumCmp = clazz.newMethod + (Position.NOPOS, mods, ENUM_CMP_NAMES[i]); setParamOwners(enumCmpType, enumCmp); enumCmp.setInfo(enumCmpType); members.enterOrOverload(enumCmp); diff --git a/sources/scalac/symtab/classfile/CLRPackageParser.java b/sources/scalac/symtab/classfile/CLRPackageParser.java index f1ab177184..05a0c4ca4f 100644 --- a/sources/scalac/symtab/classfile/CLRPackageParser.java +++ b/sources/scalac/symtab/classfile/CLRPackageParser.java @@ -19,8 +19,6 @@ import java.io.File; import ch.epfl.lamp.compiler.msil.*; import scalac.symtab.Symbol; import scalac.symtab.SymbolLoader; -import scalac.symtab.TermSymbol; -import scalac.symtab.ClassSymbol; import scalac.symtab.Scope; import scalac.util.Debug; import scalac.util.Name; diff --git a/sources/scalac/symtab/classfile/JavaTypeCreator.java b/sources/scalac/symtab/classfile/JavaTypeCreator.java index 01e4bf05ba..4e320cb529 100644 --- a/sources/scalac/symtab/classfile/JavaTypeCreator.java +++ b/sources/scalac/symtab/classfile/JavaTypeCreator.java @@ -114,8 +114,8 @@ public class JavaTypeCreator implements JavaTypeFactory { public Type methodType(Type[] argtpes, Type restpe, Type[] thrown) { Symbol[] args = new Symbol[argtpes.length]; for (int i = 0; i < args.length; i++) { - args[i] = new TermSymbol( - Position.NOPOS, Name.fromString("x" + i), Symbol.NONE, Modifiers.PARAM); + args[i] = Symbol.NONE.newTerm( // !!! should be newVParam + Position.NOPOS, Modifiers.PARAM, Name.fromString("x" + i)); args[i].setInfo(objToAny(argtpes[i])); } return new MethodType(args, restpe); diff --git a/sources/scalac/symtab/classfile/UnPickle.java b/sources/scalac/symtab/classfile/UnPickle.java index e4dfc58e8d..c0a62b5724 100644 --- a/sources/scalac/symtab/classfile/UnPickle.java +++ b/sources/scalac/symtab/classfile/UnPickle.java @@ -227,14 +227,14 @@ public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags { case TYPEsym: entries[n] = sym = owner.newAbstractType( Position.NOPOS, flags, name); - sym.setInfo(getType(inforef)); - sym.setLoBound(readTypeRef()); + sym.setInfo(getType(inforef, sym)); + sym.setLoBound(readTypeRef(sym)); break; case ALIASsym: entries[n] = sym = owner.newTypeAlias( Position.NOPOS, flags, name); - sym.setInfo(getType(inforef)); + sym.setInfo(getType(inforef, sym)); Symbol constr = readSymbolRef(); break; @@ -249,8 +249,8 @@ public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags { entries[n] = sym = owner.newClass( Position.NOPOS, flags, name); } - sym.setInfo(getType(inforef)); - sym.setTypeOfThis(readTypeRef()); + sym.setInfo(getType(inforef, sym)); + sym.setTypeOfThis(readTypeRef(sym)); Symbol constr = readSymbolRef(); assert constr == sym.allConstructors(); break; @@ -267,8 +267,8 @@ public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags { entries[n] = sym = owner.newConstructor( Position.NOPOS, flags); } else { - entries[n] = sym = new TermSymbol( - Position.NOPOS, name, owner, flags); + entries[n] = sym = owner.newTerm( + Position.NOPOS, flags, name); } } else { if (name == Names.CONSTRUCTOR) { @@ -280,8 +280,7 @@ public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags { } sym.flags = flags; } - Type tp = getType(inforef); - sym.setInfo(tp.setOwner(sym)); + sym.setInfo(getType(inforef, sym)); break; default: @@ -323,13 +322,13 @@ public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags { } } - Type getType(int n) { - if (entries[n] == null) { + Type getType(int n, Symbol owner) { + Type tpe = (Type)entries[n]; + if (tpe == null) { int savedBp = bp; bp = index[n]; int tag = bytes[bp++]; int end = readNat() + bp; - Type tpe; switch (tag) { case NOtpe: tpe = Type.NoType; @@ -345,7 +344,7 @@ public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags { // !!! tpe = Type.ThisType(readSymbolRef()); break; case SINGLEtpe: - Type prefix = readTypeRef(); + Type prefix = readTypeRef(owner); Symbol symbol = readSymbolRef(); tpe = symbol.isRoot() ? symbol.thisType() : Type.singleType(prefix, symbol); // !!! code above is usefull for the transition @@ -353,74 +352,76 @@ public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags { // !!! tpe = Type.singleType(readTypeRef(), readSymbolRef()); break; case CONSTANTtpe: - Type base = readTypeRef(); + Type base = readTypeRef(owner); AConstant value = readConstantRef(); tpe = new Type.ConstantType(base, value); break; case TYPEREFtpe: tpe = Type.newTypeRefUnsafe( // !!! - readTypeRef(), readSymbolRef(), readTypeRefs(end)); + readTypeRef(owner), readSymbolRef(), readTypeRefs(end, owner)); break; case COMPOUNDtpe: Symbol[] clazzs = readSymbolRefs(end); assert clazzs.length == 1; - Type[] parents = readTypeRefs(end); + Type[] parents = readTypeRefs(end, owner); tpe = Type.compoundType(parents, new Scope(), clazzs[0]); break; case METHODtpe: - Type restype = readTypeRef(); + Type restype = readTypeRef(owner); int bp1 = bp; - Type[] argtypes = readTypeRefs(end); + Type[] argtypes = readTypeRefs(end, owner); int[] flags = new int[argtypes.length]; bp = bp1; readFlags(flags); Symbol[] params = new Symbol[argtypes.length]; for (int i = 0; i < argtypes.length; i++) { - params[i] = new TermSymbol( - Position.NOPOS, Name.fromString("$" + i), - Symbol.NONE, PARAM | flags[i]); - params[i].setInfo(argtypes[i]); + Name name = Name.fromString("$" + i); + params[i] = owner.newVParam( + Position.NOPOS, flags[i], name, argtypes[i]); } tpe = Type.MethodType(params, restype); break; case POLYtpe: - Type restype = readTypeRef(); + Type restype = readTypeRef(owner); tpe = Type.PolyType(readSymbolRefs(end), restype); break; case OVERLOADEDtpe: int bp0 = bp; Symbol[] alts = readSymbolRefs(end); int bp1 = bp; - Type[] alttypes = readTypeRefs(end); + Type[] alttypes = readTypeRefs(end, alts); assert alts.length == alttypes.length : alts.length + "!=" + alttypes.length + " at " + bp0 + "/" + bp1 + "/" + bp; - for (int i = 0; i < alts.length; i++) - alttypes[i] = alttypes[i].setOwner(alts[i]); tpe = Type.OverloadedType(alts, alttypes); break; case FLAGGEDtpe: readNat(); // skip flags - tpe = readTypeRef(); + tpe = readTypeRef(owner); break; default: throw new BadSignature(this); } - entries[n] = tpe; + if (tag != METHODtpe) entries[n] = tpe; bp = savedBp; } - return (Type) entries[n]; + return tpe; + } + + Type readTypeRef(Symbol owner) { + return getType(readNat(), owner); } - Type readTypeRef() { - return getType(readNat()); + Type[] readTypeRefs(int end, Symbol owner) { + return readTypeRefs(0, end, owner, null); } - Type[] readTypeRefs(int end) { - return readTypeRefs(0, end); + Type[] readTypeRefs(int end, Symbol[] owners) { + return readTypeRefs(0, end, null, owners); } - Type[] readTypeRefs(int nread, int end) { + Type[] readTypeRefs(int nread, int end, Symbol owner, Symbol[] owners) { + assert (owner != null) ^ (owners != null); if (bp == end) { return new Type[nread]; } else { @@ -428,8 +429,8 @@ public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags { int bp0 = bp; int ref = readNat(); if (isTypeEntry(ref)) { - Type t = getType(ref); - Type[] ts = readTypeRefs(nread + 1, end); + Type t = getType(ref, owner != null ? owner : owners[nread]); + Type[] ts = readTypeRefs(nread + 1, end, owner, owners); ts[nread] = t; return ts; } else { diff --git a/sources/scalac/transformer/AddAccessorsPhase.java b/sources/scalac/transformer/AddAccessorsPhase.java index e93011cdd3..9fe48d52e0 100644 --- a/sources/scalac/transformer/AddAccessorsPhase.java +++ b/sources/scalac/transformer/AddAccessorsPhase.java @@ -22,7 +22,6 @@ import scalac.ast.Tree.Template; import scalac.ast.TreeList; import scalac.symtab.Modifiers; import scalac.symtab.Symbol; -import scalac.symtab.TermSymbol; import scalac.symtab.Type; import scalac.util.Name; import scalac.util.Debug; @@ -65,7 +64,7 @@ public class AddAccessorsPhase extends Phase { int flags = Modifiers.PRIVATE | Modifiers.STABLE; Name name = Name.fromString(param.name + "$"); Symbol owner = param.owner().constructorClass(); - Symbol field = new TermSymbol(param.pos, name, owner, flags); + Symbol field = owner.newField(param.pos, flags, name); field.setType(param.type()); owner.members().enterOrOverload(field); return field; @@ -76,7 +75,7 @@ public class AddAccessorsPhase extends Phase { int flags = Modifiers.PRIVATE | Modifiers.STABLE | Modifiers.ACCESSOR; Name name = param.name; Symbol owner = param.owner().constructorClass(); - Symbol method = new TermSymbol(param.pos, name, owner, flags); + Symbol method = owner.newMethod(param.pos, flags, name); method.setType(Type.MethodType(Symbol.EMPTY_ARRAY, param.type())); owner.members().enterOrOverload(method); methods.put(param, method); diff --git a/sources/scalac/transformer/AddConstructors.java b/sources/scalac/transformer/AddConstructors.java index d08581aa7c..79400cf6d1 100644 --- a/sources/scalac/transformer/AddConstructors.java +++ b/sources/scalac/transformer/AddConstructors.java @@ -18,7 +18,6 @@ import scalac.ast.GenTransformer; import scalac.symtab.Type; import scalac.symtab.Symbol; import scalac.symtab.SymbolSubstTypeMap; -import scalac.symtab.TermSymbol; import scalac.symtab.Modifiers; import scalac.util.Debug; @@ -89,11 +88,10 @@ public class AddConstructors extends GenTransformer { int flags = constructor.isPrivate() ? (constructor.flags & ~Modifiers.PRIVATE) | Modifiers.PROTECTED : constructor.flags; - initializer = new TermSymbol( + initializer = constructor.constructorClass().newMethod( constructor.pos, - constructor.name, - constructor.constructorClass(), - flags & Modifiers.ACCESSFLAGS); + flags & Modifiers.ACCESSFLAGS, + constructor.name); initializer.setInfo( Type.MethodType( constructor.valueParams(), diff --git a/sources/scalac/transformer/ExplicitOuterClassesPhase.java b/sources/scalac/transformer/ExplicitOuterClassesPhase.java index fe9d669b5b..334b6ec153 100644 --- a/sources/scalac/transformer/ExplicitOuterClassesPhase.java +++ b/sources/scalac/transformer/ExplicitOuterClassesPhase.java @@ -23,7 +23,6 @@ import scalac.ast.Tree.Template; import scalac.symtab.Modifiers; import scalac.symtab.Scope; import scalac.symtab.Symbol; -import scalac.symtab.TermSymbol; import scalac.symtab.Type; import scalac.util.Debug; import scalac.util.Name; @@ -158,9 +157,9 @@ public class ExplicitOuterClassesPhase extends Phase { if (outers.length > 0 && (outers[0].vlink != null || !outers[0].isStable)) { int index = 0; while (outers[index].isStable) index++; - int vflags = Modifiers.PARAM | Modifiers.SYNTHETIC; + int vflags = Modifiers.SYNTHETIC; Name vname = Names.OUTER(constructor); - vlink = new TermSymbol(constructor.pos, vname, constructor, vflags); + vlink = constructor.newVParam(constructor.pos, vflags, vname); vlink.setInfo(outers[index].clasz.thisType()); } @@ -488,7 +487,7 @@ public class ExplicitOuterClassesPhase extends Phase { if (forward == null) { Name name = Names.SUPER(method); int flags = Modifiers.PRIVATE | Modifiers.FINAL; - forward = new TermSymbol(method.pos, name, clasz, flags); + forward = clasz.newMethod(method.pos, flags, name); forward.setInfo(method.nextType().cloneType(method, forward)); context.supers.put(method, forward); clasz.nextInfo().members().enter(forward); diff --git a/sources/scalac/transformer/TypesAsValuesPhase.java b/sources/scalac/transformer/TypesAsValuesPhase.java index 9ebf5bca98..d4d194bbc6 100644 --- a/sources/scalac/transformer/TypesAsValuesPhase.java +++ b/sources/scalac/transformer/TypesAsValuesPhase.java @@ -19,7 +19,6 @@ import scalac.Unit; import scalac.symtab.Definitions; import scalac.symtab.Scope; import scalac.symtab.Symbol; -import scalac.symtab.TermSymbol; import scalac.symtab.Type; import scalac.atree.AConstant; import scalac.ast.Transformer; @@ -140,10 +139,9 @@ public class TypesAsValuesPhase extends Phase { assert typeSym.isType(); Symbol accessorSym = (Symbol)accessors.get(typeSym); if (accessorSym == null) { - accessorSym = new TermSymbol(typeSym.pos, - Names.TYPE(typeSym), - typeSym.owner(), - typeSym.flags); + accessorSym = typeSym.owner().newVariable(typeSym.pos, + typeSym.flags, + Names.TYPE(typeSym)); accessorSym.setInfo(typeSym.owner().isClass() ? typeAccessorType : typeType); diff --git a/sources/scalac/transformer/matching/Autom2Scala.java b/sources/scalac/transformer/matching/Autom2Scala.java index 102353c8d4..4c302b9c00 100644 --- a/sources/scalac/transformer/matching/Autom2Scala.java +++ b/sources/scalac/transformer/matching/Autom2Scala.java @@ -3,7 +3,6 @@ package scalac.transformer.matching ; import scalac.* ; import scalac.symtab.Symbol ; import scalac.symtab.Type ; -import scalac.symtab.TermSymbol ; import scalac.symtab.Definitions ; import scalac.symtab.Modifiers; import scalac.ast.Tree; diff --git a/sources/scalac/transformer/matching/FreshVariableTraverser.java b/sources/scalac/transformer/matching/FreshVariableTraverser.java index a90bd5bb06..04f9a8a684 100644 --- a/sources/scalac/transformer/matching/FreshVariableTraverser.java +++ b/sources/scalac/transformer/matching/FreshVariableTraverser.java @@ -63,10 +63,9 @@ class FreshVariableTraverser extends VariableTraverser { */ void handleVariableSymbol(Symbol sym) { Symbol helpVar = - new TermSymbol(pos, - fresh.newName(sym.name.toString()), - owner, - 0); + owner.newVariable(pos, + 0, + fresh.newName(sym.name.toString())); helpVar.setType(sym.type()); helpMap.put(sym, helpVar); diff --git a/sources/scalac/transformer/matching/LeftTracerInScala.java b/sources/scalac/transformer/matching/LeftTracerInScala.java index 56604e511d..5a407a7a88 100644 --- a/sources/scalac/transformer/matching/LeftTracerInScala.java +++ b/sources/scalac/transformer/matching/LeftTracerInScala.java @@ -41,24 +41,21 @@ public class LeftTracerInScala extends TracerInScala { this.funSym = owner.newLabel( pos, cf.fresh.newName( "left" )); - this.iterSym = new TermSymbol( pos, - cf.fresh.newName( "iter" ), - owner, - Modifiers.MUTABLE ) + this.iterSym = owner.newVariable( pos, + Modifiers.MUTABLE, + cf.fresh.newName( "iter" )) .setType( cf._seqIterType( elementType ) ) ; - this.stateSym = new TermSymbol( pos, - cf.fresh.newName( "q" ), - owner, - Modifiers.MUTABLE ) + this.stateSym = owner.newVariable( pos, + Modifiers.MUTABLE, + cf.fresh.newName( "q" )) .setType( defs.INT_TYPE() ) ; this.accumType = _accumType( elementType ); this.accumTypeArg = accumType.typeArgs()[0]; - this.accumSym = new TermSymbol( pos, // accumulator - cf.fresh.newName( "acc" ), - owner, - Modifiers.MUTABLE ) + this.accumSym = owner.newVariable( pos, // accumulator + Modifiers.MUTABLE, + cf.fresh.newName( "acc" )) .setType( accumType ); //this.funSym @@ -68,29 +65,19 @@ public class LeftTracerInScala extends TracerInScala { this.funSym .setType( new Type.MethodType( new Symbol[] { // dummy symbol MethodType - new TermSymbol( pos, - cf.fresh.newName( "q" ), // q:int - funSym, - Modifiers.PARAM ) - .setType( defs.INT_TYPE() ), - new TermSymbol( pos, // acc:List[T] accumulator - cf.fresh.newName( "acc" ), - funSym, - Modifiers.PARAM ) - .setType( accumType ) - }, + funSym.newVParam( pos, 0, cf.fresh.newName( "q" ), defs.INT_TYPE()), + funSym.newVParam( pos, 0, cf.fresh.newName( "acc" ), accumType ) }, accumType)); // result type = List[T] - this.resultSym = new TermSymbol(pos, - cf.fresh.newName("trace"), - owner, - 0 ) + this.resultSym = owner.newVariable(pos, + 0, + cf.fresh.newName("trace")) .setType( accumType ) ; - this.curSym = new TermSymbol( pos, CURRENT_ELEM, owner, 0) + this.curSym = owner.newVariable( pos, 0, CURRENT_ELEM ) .setType( elementType ); - this.hasnSym = new TermSymbol( pos, HASNEXT, owner, 0) + this.hasnSym = owner.newVariable( pos, 0, HASNEXT ) .setType( defs.BOOLEAN_TYPE() ); } diff --git a/sources/scalac/transformer/matching/PatternMatcher.java b/sources/scalac/transformer/matching/PatternMatcher.java index 085e0d8d17..380927676f 100644 --- a/sources/scalac/transformer/matching/PatternMatcher.java +++ b/sources/scalac/transformer/matching/PatternMatcher.java @@ -71,10 +71,9 @@ public class PatternMatcher extends PatternTool { this.root.and = mk.Header(selector.pos, selector.type.widen(), gen.Ident(selector.pos, root.symbol())); - this.resultVar = new TermSymbol(selector.pos, - fresh.newName(RESULT_N), - owner, - Modifiers.MUTABLE); + this.resultVar = owner.newVariable(selector.pos, + Modifiers.MUTABLE, + fresh.newName(RESULT_N)); this.resultVar.setType(resultType); this.owner = owner; this.selector = selector; diff --git a/sources/scalac/transformer/matching/PatternNodeCreator.java b/sources/scalac/transformer/matching/PatternNodeCreator.java index dedae105d0..3a0d7cf0b9 100644 --- a/sources/scalac/transformer/matching/PatternNodeCreator.java +++ b/sources/scalac/transformer/matching/PatternNodeCreator.java @@ -99,15 +99,15 @@ public class PatternNodeCreator extends PatternTool { return node; } - public TermSymbol newVar(int pos, Name name, Type type) { - TermSymbol sym = new TermSymbol(pos, name, owner, 0); + public Symbol newVar(int pos, Name name, Type type) { + Symbol sym = owner.newVariable(pos, 0, name); sym.setType(type); //System.out.println("PatternNodeCreator::newVar creates symbol "+sym); //System.out.println("owner: "+sym.owner()); return sym; } - public TermSymbol newVar(int pos, Type type) { + public Symbol newVar(int pos, Type type) { return newVar(pos, fresh.newName("temp"), type); } } diff --git a/sources/scalac/transformer/matching/RightTracerInScala.java b/sources/scalac/transformer/matching/RightTracerInScala.java index 2d41544331..9d6c70e378 100644 --- a/sources/scalac/transformer/matching/RightTracerInScala.java +++ b/sources/scalac/transformer/matching/RightTracerInScala.java @@ -87,11 +87,10 @@ public class RightTracerInScala extends TracerInScala { */ void makeHelpVar( Symbol realVar, boolean keepType ) { - Symbol helpVar = new TermSymbol( cf.pos, - cf.fresh.newName( realVar.name - .toString()+"RTIS" ), - owner, - 0); + Symbol helpVar = owner.newVariable( cf.pos, + 0, + cf.fresh.newName( realVar.name + .toString()+"RTIS" )); Tree rhs; //System.out.println("RTiS making helpvar : "+realVar+" -> "+helpVar); @@ -129,41 +128,29 @@ public class RightTracerInScala extends TracerInScala { this.funSym = owner.newLabel( pos, cf.fresh.newName( "right" )); - this.iterSym = new TermSymbol( pos, - cf.fresh.newName("iter"), - owner, - Modifiers.MUTABLE ) + this.iterSym = owner.newVariable( pos, + Modifiers.MUTABLE, + cf.fresh.newName("iter")) .setType( cf.SeqTraceType( elementType )); - this.stateSym = new TermSymbol( pos, - cf.fresh.newName("q"), - owner, - Modifiers.MUTABLE ) + this.stateSym = owner.newVariable ( pos, + Modifiers.MUTABLE, + cf.fresh.newName("q")) .setType( defs.INT_TYPE() ) ; - this.curSym = new TermSymbol( pos, - cf.fresh.newName("cur"), - owner, - 0) + this.curSym = owner.newVariable( pos, + Modifiers.MUTABLE, + cf.fresh.newName("cur")) .setType( elementType ) ; - this.targetSym = new TermSymbol( pos, - cf.fresh.newName("p"), - owner, - 0) + this.targetSym = owner.newVariable( pos, + Modifiers.MUTABLE, + cf.fresh.newName("p")) .setType( defs.INT_TYPE() ) ; funSym.setType( new Type.MethodType( new Symbol[] { // dummy symbol MethodType - new TermSymbol( pos, - cf.fresh.newName("iter"), // iter:List[Pair[int,T]] - funSym, - Modifiers.PARAM ) - .setType( cf.SeqTraceType( elementType )) , - new TermSymbol( pos, - cf.fresh.newName( "q" ), // q:int - funSym, - Modifiers.PARAM ) - .setType( defs.INT_TYPE() ) }, + funSym.newVParam( pos, 0, cf.fresh.newName("iter"), cf.SeqTraceType( elementType )), + funSym.newVParam( pos, 0, cf.fresh.newName( "q" ), defs.INT_TYPE()) }, defs.UNIT_TYPE() )); // result } diff --git a/sources/scalac/transformer/matching/WordAutomInScala.java b/sources/scalac/transformer/matching/WordAutomInScala.java index c1d5c439f6..dff5603bb6 100644 --- a/sources/scalac/transformer/matching/WordAutomInScala.java +++ b/sources/scalac/transformer/matching/WordAutomInScala.java @@ -15,7 +15,6 @@ import scalac.ast.Tree; import scalac.ast.TreeGen; import scalac.symtab.Type; import scalac.symtab.Symbol; -import scalac.symtab.TermSymbol; // test import scalac.symtab.Modifiers; // test import scalac.transformer.TransMatch.Matcher; //import scalac.typechecker.*; @@ -71,42 +70,30 @@ public class WordAutomInScala extends Autom2Scala { this.funSym = owner.newLabel( pos, cf.fresh.newName( "matcher" )); - this.iterSym = new TermSymbol( pos, - cf.fresh.newName("iter"), - owner, - Modifiers.MUTABLE /*| NOT : Modifiers.PARAM*/ ) + this.iterSym = owner.newVariable( pos, + Modifiers.MUTABLE, + cf.fresh.newName("iter")) .setType( cf._seqIterType( elementType ) ) ; - this.stateSym = new TermSymbol( pos, - cf.fresh.newName("q"), - owner, - Modifiers.MUTABLE ) + this.stateSym = owner.newVariable( pos, + Modifiers.MUTABLE, + cf.fresh.newName("q")) .setType( defs.INT_TYPE() ) ; - this.resultSym = new TermSymbol( pos, - cf.fresh.newName("swRes"), - owner, - 0 ) + this.resultSym = owner.newVariable( pos, + Modifiers.MUTABLE, + cf.fresh.newName("swRes")) .setType( defs.INT_TYPE() ) ; this.funSym .setType( new Type.MethodType( new Symbol[] { - new TermSymbol( pos, - cf.fresh.newName("q"), - funSym, - Modifiers.PARAM ).setType( defs.INT_TYPE() ) + funSym.newVParam( pos, 0, cf.fresh.newName("q"), defs.INT_TYPE()) }, defs.INT_TYPE() )); - this.curSym = new TermSymbol( pos, - CURRENT_ELEM, - owner, - 0) + this.curSym = owner.newVariable( pos, 0, CURRENT_ELEM ) .setType( elementType ); - this.hasnSym = new TermSymbol( pos, - HASNEXT, - owner, - 0) + this.hasnSym = owner.newVariable( pos, 0, HASNEXT ) .setType( defs.BOOLEAN_TYPE() ); } diff --git a/sources/scalac/typechecker/RefCheck.java b/sources/scalac/typechecker/RefCheck.java index 961776b7cd..c293ea2d13 100644 --- a/sources/scalac/typechecker/RefCheck.java +++ b/sources/scalac/typechecker/RefCheck.java @@ -530,8 +530,8 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { { // var m$: T = null; Name varname = Name.fromString(name + "$"); - Symbol mvar = new TermSymbol( - tree.pos, varname, sym.owner(), PRIVATE | MUTABLE | SYNTHETIC) + Symbol mvar = sym.owner().newFieldOrVariable( + tree.pos, PRIVATE | MUTABLE | SYNTHETIC, varname) .setInfo(sym.type()); sym.owner().members().enterOrOverload(mvar); Tree vdef = gen.ValDef(mvar, gen.mkNullLit(tree.pos)); @@ -554,10 +554,9 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { // def m_eq(m: T): Unit = { m$ = m } Name m_eqname = name.append(Names._EQ); - Symbol m_eq = new TermSymbol( - tree.pos, m_eqname, sym.owner(), PRIVATE | SYNTHETIC); - Symbol m_eqarg = new TermSymbol(tree.pos, name, m_eq, PARAM | SYNTHETIC) - .setType(sym.type()); + Symbol m_eq = sym.owner().newMethodOrFunction( + tree.pos, PRIVATE | SYNTHETIC, m_eqname); + Symbol m_eqarg = m_eq.newVParam(tree.pos, SYNTHETIC, name, sym.type()); m_eq.setInfo( Type.MethodType(new Symbol[] {m_eqarg}, defs.UNIT_TYPE())); Tree m_eqdef = gen.DefDef(m_eq, @@ -629,8 +628,8 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { } private Tree toStringMethod(ClassSymbol clazz) { - Symbol toStringSym = new TermSymbol( - clazz.pos, Names.toString, clazz, OVERRIDE) + Symbol toStringSym = clazz.newMethod( + clazz.pos, OVERRIDE, Names.toString) .setInfo(defs.ANY_TOSTRING.type()); clazz.info().members().enter(toStringSym); Tree[] fields = caseFields(clazz); @@ -655,10 +654,9 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { } private Tree equalsMethod(ClassSymbol clazz) { - Symbol equalsSym = new TermSymbol(clazz.pos, Names.equals, clazz, OVERRIDE); - Symbol equalsParam = - new TermSymbol(clazz.pos, Names.that, equalsSym, PARAM) - .setInfo(defs.ANY_TYPE()); + Symbol equalsSym = clazz.newMethod(clazz.pos, OVERRIDE, Names.equals); + Symbol equalsParam = equalsSym.newVParam( + clazz.pos, 0, Names.that, defs.ANY_TYPE()); equalsSym.setInfo( Type.MethodType(new Symbol[]{equalsParam}, defs.BOOLEAN_TYPE())); clazz.info().members().enter(equalsSym); @@ -688,7 +686,7 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { gen.mkLocalRef(clazz.pos, equalsParam), defs.ANY_AS), new Tree[]{gen.mkType(clazz.pos, testtp)}); - Symbol that1sym = new TermSymbol(clazz.pos, Names.that1, equalsSym, 0) + Symbol that1sym = equalsSym.newVariable(clazz.pos, 0, Names.that1) .setType(testtp); Tree that1def = gen.ValDef(that1sym, cast); @@ -721,9 +719,8 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { } private Tree tagMethod(ClassSymbol clazz) { - Symbol tagSym = new TermSymbol( - clazz.pos, Names.tag, clazz, - clazz.isSubClass(defs.SCALAOBJECT_CLASS) ? OVERRIDE : 0) + int flags =clazz.isSubClass(defs.SCALAOBJECT_CLASS) ? OVERRIDE : 0; + Symbol tagSym = clazz.newMethod(clazz.pos, flags, Names.tag) .setInfo(Type.MethodType(Symbol.EMPTY_ARRAY, defs.INT_TYPE())); clazz.info().members().enter(tagSym); return gen.DefDef( @@ -734,8 +731,8 @@ public class RefCheck extends Transformer implements Modifiers, Kinds { } private Tree hashCodeMethod(ClassSymbol clazz) { - Symbol hashCodeSym = new TermSymbol( - clazz.pos, Names.hashCode, clazz, OVERRIDE) + Symbol hashCodeSym = clazz.newMethod( + clazz.pos, OVERRIDE, Names.hashCode) .setInfo(defs.ANY_HASHCODE.type()); clazz.info().members().enter(hashCodeSym); Tree[] fields = caseFields(clazz); |