summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2004-03-11 14:48:40 +0000
committerpaltherr <paltherr@epfl.ch>2004-03-11 14:48:40 +0000
commitb40e2e68797687d4cd5b6c1bf9e69714e7983feb (patch)
tree8af7eb8f6795cca19a659a4fa7eb15ac41226e5e
parente7bb2275e3d1224a827faa00973de3c235dc7fb6 (diff)
downloadscala-b40e2e68797687d4cd5b6c1bf9e69714e7983feb.tar.gz
scala-b40e2e68797687d4cd5b6c1bf9e69714e7983feb.tar.bz2
scala-b40e2e68797687d4cd5b6c1bf9e69714e7983feb.zip
- Redesigned symbol cloning
-rw-r--r--sources/scalac/symtab/Symbol.java99
1 files changed, 50 insertions, 49 deletions
diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java
index 55b6f84420..62a143c45e 100644
--- a/sources/scalac/symtab/Symbol.java
+++ b/sources/scalac/symtab/Symbol.java
@@ -209,7 +209,13 @@ public abstract class Symbol implements Modifiers, Kinds {
/** Return a fresh symbol with the same fields as this one and the
* given owner.
*/
- public abstract Symbol cloneSymbol(Symbol owner);
+ public final Symbol cloneSymbol(Symbol owner) {
+ Symbol clone = cloneSymbolImpl(owner, attrs);
+ clone.setInfo(info());
+ return clone;
+ }
+
+ protected abstract Symbol cloneSymbolImpl(Symbol owner, int attrs);
/** Returns a shallow copy of the given array. */
public static Symbol[] cloneArray(Symbol[] array) {
@@ -1460,15 +1466,6 @@ public class TermSymbol extends Symbol {
return clazz != null && name == Names.CONSTRUCTOR;
}
- /** Return a fresh symbol with the same fields as this one.
- */
- public Symbol cloneSymbol(Symbol owner) {
- assert !isPrimaryConstructor() : Debug.show(this);
- TermSymbol other = new TermSymbol(pos, name, owner, flags, 0, clazz);
- other.setInfo(info());
- return other;
- }
-
public Symbol[] typeParams() {
return type().typeParams();
}
@@ -1484,6 +1481,12 @@ public class TermSymbol extends Symbol {
public Symbol moduleClass() {
return (flags & MODUL) != 0 ? clazz : this;
}
+
+ protected final Symbol cloneSymbolImpl(Symbol owner, int attrs) {
+ assert !isPrimaryConstructor() : Debug.show(this);
+ return new TermSymbol(pos, name, owner, flags, attrs, clazz);
+ }
+
}
/** A base class for all type symbols.
@@ -1620,6 +1623,15 @@ public abstract class TypeSymbol extends Symbol {
closures.reset();
tycon = null;
}
+
+
+ protected final Symbol cloneSymbolImpl(Symbol owner, int attrs) {
+ TypeSymbol clone = cloneTypeSymbolImpl(owner, attrs);
+ copyConstructorInfo(clone);
+ return clone;
+ }
+
+ protected abstract TypeSymbol cloneTypeSymbolImpl(Symbol owner, int attrs);
}
public class AliasTypeSymbol extends TypeSymbol {
@@ -1644,14 +1656,10 @@ public class AliasTypeSymbol extends TypeSymbol {
}
}
- /** Return a fresh symbol with the same fields as this one.
- */
- public Symbol cloneSymbol(Symbol owner) {
- AliasTypeSymbol other = new AliasTypeSymbol(pos, name, owner, flags);
- other.setInfo(info());
- copyConstructorInfo(other);
- return other;
+ protected TypeSymbol cloneTypeSymbolImpl(Symbol owner, int attrs) {
+ return new AliasTypeSymbol(pos, name, owner, flags, attrs);
}
+
}
public class AbsTypeSymbol extends TypeSymbol {
@@ -1679,15 +1687,6 @@ public class AbsTypeSymbol extends TypeSymbol {
}
}
- /** Return a fresh symbol with the same fields as this one.
- */
- public Symbol cloneSymbol(Symbol owner) {
- TypeSymbol other = new AbsTypeSymbol(pos, name, owner, flags);
- other.setInfo(info());
- other.setLoBound(loBound());
- return other;
- }
-
public Type loBound() {
initialize();
return lobound == null ? Global.instance.definitions.ALL_TYPE() : lobound;
@@ -1697,6 +1696,13 @@ public class AbsTypeSymbol extends TypeSymbol {
this.lobound = lobound;
return this;
}
+
+ protected TypeSymbol cloneTypeSymbolImpl(Symbol owner, int attrs) {
+ TypeSymbol clone = new AbsTypeSymbol(pos, name, owner, flags, attrs);
+ clone.setLoBound(loBound());
+ return clone;
+ }
+
}
/** A class for class symbols. It has JavaClassSymbol as a subclass.
@@ -1805,17 +1811,6 @@ public class ClassSymbol extends TypeSymbol {
return owner().newModuleClass(pos, flags, name, 0, this);
}
- /** Return a fresh symbol with the same fields as this one.
- */
- public Symbol cloneSymbol(Symbol owner) {
- ClassSymbol other = new ClassSymbol(pos, name, owner, flags);
- other.module = module;
- other.setInfo(info());
- copyConstructorInfo(other);
- if (thisSym != this) other.setTypeOfThis(typeOfThis());
- return other;
- }
-
/** Get module */
public Symbol module() {
assert !isRoot(): this + ".module()";
@@ -1884,6 +1879,14 @@ public class ClassSymbol extends TypeSymbol {
module().reset(completer);
thisSym = this;
}
+
+ protected TypeSymbol cloneTypeSymbolImpl(Symbol owner, int attrs) {
+ ClassSymbol clone = new ClassSymbol(pos, name, owner, flags, attrs);
+ clone.module = module;
+ if (thisSym != this) clone.setTypeOfThis(typeOfThis());
+ return clone;
+ }
+
}
/** A class for error symbols.
@@ -1896,11 +1899,6 @@ public final class ErrorSymbol extends Symbol {
super.setInfo(Type.ErrorType);
}
- public Symbol cloneSymbol(Symbol owner) {
- assert owner == this : Debug.show(owner);
- return this;
- }
-
/** Set type */
public Symbol setInfo(Type info) {
assert info == Type.ErrorType : info;
@@ -1928,6 +1926,11 @@ public final class ErrorSymbol extends Symbol {
public void reset(Type completer) {
}
+
+ protected Symbol cloneSymbolImpl(Symbol owner, int attrs) {
+ throw Debug.abort("illegal clone", this);
+ }
+
}
/** The class of Symbol.NONE
@@ -1940,13 +1943,6 @@ public final class NoSymbol extends Symbol {
super.setInfo(Type.NoType);
}
- /** Return a fresh symbol with the same fields as this one.
- */
- public Symbol cloneSymbol(Symbol owner) {
- assert owner == this : Debug.show(owner);
- return this;
- }
-
/** Set type */
public Symbol setInfo(Type info) {
assert info == Type.NoType : info;
@@ -1973,6 +1969,11 @@ public final class NoSymbol extends Symbol {
public void reset(Type completer) {
}
+
+ protected Symbol cloneSymbolImpl(Symbol owner, int attrs) {
+ throw Debug.abort("illegal clone", this);
+ }
+
}
/** A class for symbols generated in label definitions.