summaryrefslogtreecommitdiff
path: root/sources/scalac/symtab
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2004-03-10 19:08:48 +0000
committerpaltherr <paltherr@epfl.ch>2004-03-10 19:08:48 +0000
commitbd9f74861ec3e664fc9e94795fd8c16b7580e1df (patch)
treefd24674b44bb117567372ac2590b1f48aeb9036d /sources/scalac/symtab
parent5998eb1012cf801a22bf494d55410b44ea452fca (diff)
downloadscala-bd9f74861ec3e664fc9e94795fd8c16b7580e1df.tar.gz
scala-bd9f74861ec3e664fc9e94795fd8c16b7580e1df.tar.bz2
scala-bd9f74861ec3e664fc9e94795fd8c16b7580e1df.zip
- Added factory method Symbol.newConstructor
- Changed method Symbol.addConstructor to receive new constructor - as argument Changed Symbol, Analyzer, class parser and - picklers to use new factory method Removed now unused methods - TermSymbol.makeConstructor/newConstructor
Diffstat (limited to 'sources/scalac/symtab')
-rw-r--r--sources/scalac/symtab/Symbol.java41
-rw-r--r--sources/scalac/symtab/classfile/CLRClassParser.java8
-rw-r--r--sources/scalac/symtab/classfile/ClassfileParser.java10
-rw-r--r--sources/scalac/symtab/classfile/Pickle.java4
-rw-r--r--sources/scalac/symtab/classfile/UnPickle.java12
5 files changed, 36 insertions, 39 deletions
diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java
index 64d24000e8..35e52690fc 100644
--- a/sources/scalac/symtab/Symbol.java
+++ b/sources/scalac/symtab/Symbol.java
@@ -87,6 +87,12 @@ public abstract class Symbol implements Modifiers, Kinds {
// Factories --------------------------------------------------------------
+ /** Creates a new constructor of this symbol. */
+ public final TermSymbol newConstructor(int pos, int flags) {
+ assert isType(): Debug.show(this);
+ return new TermSymbol(pos, Names.CONSTRUCTOR, owner(), flags, 0, this);
+ }
+
/** Creates a new module owned by this symbol. */
public final TermSymbol newModule(int pos, int flags, Name name) {
ClassSymbol clasz = newModuleClass(pos, flags, name.toTypeName());
@@ -353,9 +359,9 @@ public abstract class Symbol implements Modifiers, Kinds {
throw new ApplicationError("setLoBound inapplicable for " + this);
}
- /** Add an auxiliary constructor to class; return created symbol.
+ /** Add an auxiliary constructor to class.
*/
- public Symbol addConstructor() {
+ public void addConstructor(Symbol constr) {
throw new ApplicationError("addConstructor inapplicable for " + this);
}
@@ -1266,7 +1272,7 @@ public abstract class Symbol implements Modifiers, Kinds {
int overflags = (this.flags & that.flags & (JAVA | ACCESSFLAGS | DEFERRED)) |
((this.flags | that.flags) & ACCESSOR);
TermSymbol overloaded = (this.isConstructor())
- ? TermSymbol.newConstructor(this.constructorClass(), overflags)
+ ? this.constructorClass().newConstructor(this.constructorClass().pos, overflags)
: new TermSymbol(pos, name, owner, overflags);
overloaded.setInfo(new LazyOverloadedType(this, that));
return overloaded;
@@ -1451,22 +1457,6 @@ public class TermSymbol extends Symbol {
}
}
- public static TermSymbol newConstructor(Symbol clazz, int flags) {
- TermSymbol sym = new TermSymbol(
- clazz.pos, Names.CONSTRUCTOR, clazz.owner(), flags);
- sym.clazz = clazz;
- return sym;
- }
-
- public TermSymbol makeConstructor(ClassSymbol clazz) {
- this.clazz = clazz;
- return this;
- }
-
- public static TermSymbol newJavaConstructor(Symbol clazz) {
- return newConstructor(clazz, clazz.flags & (ACCESSFLAGS | JAVA));
- }
-
/** Dummy symbol for template of given class
*/
public static Symbol newLocalDummy(Symbol clazz) {
@@ -1530,7 +1520,7 @@ public abstract class TypeSymbol extends Symbol {
super(kind, pos, name, owner, flags, attrs);
this.closures = new ClosureHistory();
assert name.isTypeName() : this;
- this.constructor = TermSymbol.newConstructor(this, flags & CONSTRFLAGS);
+ this.constructor = newConstructor(pos, flags & CONSTRFLAGS);
}
protected void update(int pos, int flags) {
@@ -1557,8 +1547,8 @@ public abstract class TypeSymbol extends Symbol {
}
Symbol[] alts = allConstructors().alternativeSymbols();
for (int i = 1; i < alts.length; i++) {
- Symbol constr = other.addConstructor();
- constr.flags = other.flags;
+ Symbol constr = other.newConstructor(alts[i].pos, alts[i].flags);
+ other.addConstructor(constr);
Type info = alts[i].info().cloneType(alts[i], constr);
if (!isTypeAlias()) info = fixConstrType(info, other);
constr.setInfo(info);
@@ -1587,10 +1577,9 @@ public abstract class TypeSymbol extends Symbol {
/** add a constructor
*/
- public final Symbol addConstructor() {
- Symbol constr = TermSymbol.newConstructor(this, flags & CONSTRFLAGS);
+ public final void addConstructor(Symbol constr) {
+ assert constr.isConstructor(): Debug.show(constr);
constructor = constructor.overloadWith(constr);
- return constr;
}
/** Get primary constructor */
@@ -1958,7 +1947,7 @@ public final class ErrorSymbol extends Symbol {
/** Get primary constructor */
public Symbol primaryConstructor() {
- return TermSymbol.newConstructor(this, 0).setInfo(Type.ErrorType);
+ return newConstructor(pos, 0).setInfo(Type.ErrorType);
}
/** Return the next enclosing class */
diff --git a/sources/scalac/symtab/classfile/CLRClassParser.java b/sources/scalac/symtab/classfile/CLRClassParser.java
index 51b156b461..cbcf042e46 100644
--- a/sources/scalac/symtab/classfile/CLRClassParser.java
+++ b/sources/scalac/symtab/classfile/CLRClassParser.java
@@ -199,9 +199,13 @@ public class CLRClassParser extends SymbolLoader {
if (mtype == null)
continue;
Symbol constr = clazz.primaryConstructor();
- if (constr.isInitialized()) constr = clazz.addConstructor();
int mods = translateAttributes(constrs[i]);
- TermSymbol.newConstructor(clazz, mods).copyTo(constr);
+ if (constr.isInitialized()) {
+ clazz.addConstructor(
+ constr = clazz.newConstructor(Position.NOPOS, mods));
+ } else {
+ constr.flags = mods;
+ }
setParamOwners(mtype, constr);
constr.setInfo(mtype);
// System.out.println(clazz.allConstructors() + ": "
diff --git a/sources/scalac/symtab/classfile/ClassfileParser.java b/sources/scalac/symtab/classfile/ClassfileParser.java
index 406f79f54a..bdb76e7b71 100644
--- a/sources/scalac/symtab/classfile/ClassfileParser.java
+++ b/sources/scalac/symtab/classfile/ClassfileParser.java
@@ -208,7 +208,7 @@ public class ClassfileParser implements ClassfileConstants {
Name name = (Name)pool.readPool(in.nextChar());
Type type = readType(in.nextChar());
if (CONSTR_N.equals(name)) {
- Symbol s = TermSymbol.newConstructor(c, sflags);
+ Symbol s = c.newConstructor(Position.NOPOS, sflags);
// kick out package visible or private constructors
if (((flags & JAVA_ACC_PRIVATE) != 0) ||
((flags & (JAVA_ACC_PROTECTED | JAVA_ACC_PUBLIC)) == 0)) {
@@ -223,9 +223,11 @@ public class ClassfileParser implements ClassfileConstants {
throw new ApplicationError();
}
Symbol constr = c.primaryConstructor();
- if (constr.isInitialized())
- constr = c.addConstructor();
- s.copyTo(constr);
+ if (constr.isInitialized()) {
+ c.addConstructor(constr = s);
+ } else {
+ constr.flags = sflags;
+ }
setParamOwners(type, constr);
constr.setInfo(type);
attrib.readAttributes(constr, type, METH_ATTR);
diff --git a/sources/scalac/symtab/classfile/Pickle.java b/sources/scalac/symtab/classfile/Pickle.java
index 9a1f820385..3359e9aac7 100644
--- a/sources/scalac/symtab/classfile/Pickle.java
+++ b/sources/scalac/symtab/classfile/Pickle.java
@@ -117,7 +117,7 @@ public class Pickle implements Kinds, Modifiers, EntryTags {
if (debug) System.out.println("put " + sym);
if (isLocal(sym)) {
putEntry(sym.name);
- putSymbol(sym.owner());
+ putSymbol(sym.isConstructor() ? sym.constructorClass() : sym.owner());
putType(sym.info());
switch (sym.kind) {
case TYPE:
@@ -330,7 +330,7 @@ public class Pickle implements Kinds, Modifiers, EntryTags {
}
writeByte(0); // space for length
writeRef(sym.name);
- writeRef(sym.owner());
+ writeRef(sym.isConstructor() ? sym.constructorClass() : sym.owner());
writeNat(sym.flags);
writeRef(sym.info());
switch (sym.kind) {
diff --git a/sources/scalac/symtab/classfile/UnPickle.java b/sources/scalac/symtab/classfile/UnPickle.java
index 3a3b8fa2a6..c309ed5723 100644
--- a/sources/scalac/symtab/classfile/UnPickle.java
+++ b/sources/scalac/symtab/classfile/UnPickle.java
@@ -253,9 +253,6 @@ public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags {
sym.setTypeOfThis(readTypeRef());
Symbol constr = readSymbolRef();
assert constr == sym.allConstructors();
- Symbol[] alts = constr.alternativeSymbols();
- for (int i = 0; i < alts.length; i++)
- ((TermSymbol)alts[i]).makeConstructor((ClassSymbol)sym);
break;
case VALsym:
@@ -266,8 +263,13 @@ public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags {
entries[n] = sym = moduleroot;
sym.flags = flags;
} else if (tsym == null) {
- entries[n] = sym = new TermSymbol(
- Position.NOPOS, name, owner, flags);
+ if (name == Names.CONSTRUCTOR) {
+ entries[n] = sym = owner.newConstructor(
+ Position.NOPOS, flags);
+ } else {
+ entries[n] = sym = new TermSymbol(
+ Position.NOPOS, name, owner, flags);
+ }
} else {
if (name == Names.CONSTRUCTOR) {
entries[n] = sym = tsym.allConstructors();