summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2003-07-31 14:31:02 +0000
committerMartin Odersky <odersky@gmail.com>2003-07-31 14:31:02 +0000
commit8c0786c2f1555dd7f5ba6dac1a471fe8255cbe68 (patch)
tree12ea5c82b82f5ec7cbacdf5dbf7944b59e57b448 /sources
parent03449ed20a3cca9e8d974c7efeff6b4e01ecb66d (diff)
downloadscala-8c0786c2f1555dd7f5ba6dac1a471fe8255cbe68.tar.gz
scala-8c0786c2f1555dd7f5ba6dac1a471fe8255cbe68.tar.bz2
scala-8c0786c2f1555dd7f5ba6dac1a471fe8255cbe68.zip
*** empty log message ***
Diffstat (limited to 'sources')
-rw-r--r--sources/scalac/symtab/EntryTags.java8
-rw-r--r--sources/scalac/symtab/Modifiers.java1
-rw-r--r--sources/scalac/symtab/Symbol.java7
-rw-r--r--sources/scalac/symtab/classfile/Pickle.java41
-rw-r--r--sources/scalac/symtab/classfile/UnPickle.java93
-rw-r--r--sources/scalac/transformer/LambdaLiftPhase.java2
-rw-r--r--sources/scalac/typechecker/Analyzer.java10
7 files changed, 87 insertions, 75 deletions
diff --git a/sources/scalac/symtab/EntryTags.java b/sources/scalac/symtab/EntryTags.java
index ed1d089641..41e71464ac 100644
--- a/sources/scalac/symtab/EntryTags.java
+++ b/sources/scalac/symtab/EntryTags.java
@@ -20,8 +20,8 @@ public interface EntryTags {
* | 5 ALIASsym len_Nat SymbolInfo
* | 6 CLASSsym len_Nat SymbolInfo thistype_Ref constrsym_Ref
* | 7 VALsym len_Nat SymbolInfo [classsym_Ref]
- * | 8 TERMref len_Nat name_Ref [owner_Ref]
- * | 9 TYPEref len_Nat name_Ref [owner_Ref]
+ * | 8 EXTref len_Nat name_Ref [owner_Ref]
+ * | 9 EXTMODCLASSref len_Nat name_Ref [owner_Ref]
* | 10 NOtpe len_Nat
* | 11 THIStpe len_Nat sym_Ref
* | 12 SINGLEtpe len_Nat type_Ref sym_Ref
@@ -45,8 +45,8 @@ public interface EntryTags {
ALIASsym = 5,
CLASSsym = 6,
VALsym = 7,
- TERMref = 8,
- TYPEref = 9,
+ EXTref = 8,
+ EXTMODCLASSref = 9,
NOtpe = 10,
THIStpe = 11,
SINGLEtpe = 12,
diff --git a/sources/scalac/symtab/Modifiers.java b/sources/scalac/symtab/Modifiers.java
index 9358a2d721..e53bbd92d4 100644
--- a/sources/scalac/symtab/Modifiers.java
+++ b/sources/scalac/symtab/Modifiers.java
@@ -49,6 +49,7 @@ public interface Modifiers {
// value or variable
int BRIDGE = 0x08000000; // function is a bridge method.
int LIFTED = BRIDGE; // transient flag for lambdalift
+ int ALTERNATIVE = BRIDGE; // transient flag for pickle/unpickle
int SNDTIME = BRIDGE; // debug
int INTERFACE = 0x10000000; // symbol is a Java interface
diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java
index 585bc5de95..6f1444f827 100644
--- a/sources/scalac/symtab/Symbol.java
+++ b/sources/scalac/symtab/Symbol.java
@@ -516,9 +516,9 @@ public abstract class Symbol implements Modifiers, Kinds {
/** Return first alternative if this has a (possibly lazy)
* overloaded type, otherwise symbol itself.
- * Needed only in ClassSymbol.primaryConstructor()
+ * Needed in ClassSymbol.primaryConstructor() and in UnPickle.
*/
- Symbol firstAlternative() {
+ public Symbol firstAlternative() {
if (infos.info instanceof Type.OverloadedType)
return infos.info.alternativeSymbols()[0];
else if (infos.info instanceof LazyOverloadedType)
@@ -1419,7 +1419,8 @@ public class ClassSymbol extends TypeSymbol {
super.copyTo(sym);
Symbol symconstr = ((ClassSymbol) sym).constructor;
constructor.copyTo(symconstr);
- symconstr.setInfo(fixConstrType(symconstr.rawInfo(), sym));
+ if (constructor.isInitialized())
+ symconstr.setInfo(fixConstrType(symconstr.type(), sym));
if (thisSym != this) sym.setTypeOfThis(typeOfThis());
}
diff --git a/sources/scalac/symtab/classfile/Pickle.java b/sources/scalac/symtab/classfile/Pickle.java
index ded41362ea..7deaa52675 100644
--- a/sources/scalac/symtab/classfile/Pickle.java
+++ b/sources/scalac/symtab/classfile/Pickle.java
@@ -45,10 +45,13 @@ public class Pickle implements Kinds, Modifiers, EntryTags {
/** Pickle all symbols descending from `root'.
*/
public void add(Symbol root) {
- if (index.get(root) == null) {
- this.rootname = root.name.toTermName();
- this.rootowner = root.owner();
- putSymbol(root);
+ if (root.kind != NONE) {
+ if (debug) System.out.println("adding " + root);//debug
+ if (index.get(root) == null) {
+ this.rootname = root.name.toTermName();
+ this.rootowner = root.owner();
+ putSymbol(root);
+ }
}
}
@@ -138,13 +141,11 @@ public class Pickle implements Kinds, Modifiers, EntryTags {
}
/** Store symbol in index. If symbol is local, also store
- * everything it refers to. Excepted are local primary
- * constructors; their information is stored together with
- * another symbol.
+ * everything it refers to.
*/
private void putSymbol(Symbol sym) {
if (putEntry(sym)) {
- //System.out.println("put sym " + sym);//DEBUG
+ if (debug) System.out.println("put " + sym);
if (isLocal(sym)) {
putEntry(sym.name);
putSymbol(sym.owner());
@@ -172,7 +173,7 @@ public class Pickle implements Kinds, Modifiers, EntryTags {
throw new ApplicationError();
}
} else if (sym.kind != NONE) {
- putEntry(sym.name);
+ putEntry(sym.isModuleClass() ? sym.name.toTermName() : sym.name);
if (sym.owner() != Global.instance.definitions.ROOT_CLASS)
putSymbol(sym.owner());
}
@@ -222,8 +223,9 @@ public class Pickle implements Kinds, Modifiers, EntryTags {
putSymbols(tparams);
break;
case OverloadedType(Symbol[] alts, Type[] alttypes):
- for (int i = 0; i < alts.length; i++)
- putSymbol(alts[i]);
+ for (int i = 0; i < alts.length; i++) alts[i].flags |= ALTERNATIVE;
+ putSymbols(alts);
+ putTypes(alttypes);
break;
default:
throw new ApplicationError();
@@ -301,8 +303,7 @@ public class Pickle implements Kinds, Modifiers, EntryTags {
/** Write a name entry. Names are stored in Utf8 format.
*/
private void writeName(Name name) {
- if (name.isTermName()) writeByte(TERMname);
- else writeByte(TYPEname);
+ writeByte(name.isTermName() ? TERMname : TYPEname);
writeByte(0); // space for length
while (bp + name.length() > bytes.length) resizeTo(bytes.length * 2);
name.copyAscii(bytes, bp);
@@ -313,6 +314,7 @@ public class Pickle implements Kinds, Modifiers, EntryTags {
/** Write a symbol entry.
*/
private void writeSymbol(Symbol sym) {
+ if (debug) System.out.println("write " + sym);
if (isLocal(sym)) {
switch (sym.kind) {
case TYPE:
@@ -356,12 +358,19 @@ public class Pickle implements Kinds, Modifiers, EntryTags {
writeByte(NONEsym);
writeByte(0); // space for length
} else {
- writeByte((sym.isTerm() || sym.isModuleClass()) ? TERMref : TYPEref);
- writeByte(0); // space for length
- writeRef(sym.name);
+ if (sym.isModuleClass()) {
+ writeByte(EXTMODCLASSref);
+ writeByte(0); // space for length
+ writeRef(sym.name.toTermName());
+ } else {
+ writeByte(EXTref);
+ writeByte(0); // space for length
+ writeRef(sym.name);
+ }
if (sym.owner() != Global.instance.definitions.ROOT_CLASS)
writeRef(sym.owner());
}
+ sym.flags &= ~ALTERNATIVE;
}
/** Write a type entry.
diff --git a/sources/scalac/symtab/classfile/UnPickle.java b/sources/scalac/symtab/classfile/UnPickle.java
index ccc4fcf2fe..8f6b817063 100644
--- a/sources/scalac/symtab/classfile/UnPickle.java
+++ b/sources/scalac/symtab/classfile/UnPickle.java
@@ -34,8 +34,8 @@ public class UnPickle implements Kinds, Modifiers, EntryTags {
Global global;
UnPickle(Symbol root, byte[] data, Name sourceName) {
+ assert !root.isInitialized();
global = Global.instance;
- assert root.rawInfoAt(Symbol.FIRST_ID) instanceof LazyType;
if (root.isConstructor()) {
this.classroot = root.primaryConstructorClass();
this.moduleroot = classroot.module();
@@ -82,7 +82,7 @@ public class UnPickle implements Kinds, Modifiers, EntryTags {
if (isSymbolEntry(i)) getSymbol(i);
}
if (global.debug) global.log("unpickled " + root);//debug
- if (root.rawInfoAt(Symbol.FIRST_ID) instanceof LazyType)
+ if (!root.isInitialized())
throw new BadSignature(this, "it does not define " + root);
}
@@ -159,15 +159,28 @@ public class UnPickle implements Kinds, Modifiers, EntryTags {
}
void enterSymbol(Symbol sym) {
- Symbol owner = sym.owner();
- Scope scope = owner.info().members();
- Symbol other = scope.lookup(sym.name);
- if (other == Symbol.NONE) {
- if (global.debug)
- global.log("entering " + sym + ":" + sym.type() + " in " + owner);//debug
- scope.enter(sym);
+ /*
+ if (global.debug) {
+ global.log("entering " + sym + ":" + sym.type() + " in " + sym.owner());//debug
+ if (sym.kind == CLASS)
+ global.log("primconstr = " + sym.primaryConstructor());
+ }
+ */
+ if ((sym.flags & ALTERNATIVE) != 0) {
+ sym.flags &= ~ALTERNATIVE;
} else {
- assert sym.rawInfo() instanceof Type.OverloadedType : sym;
+ Symbol owner = sym.owner();
+ if (owner.kind == CLASS &&
+ !sym.isConstructor() && !sym.isModuleClass()) {
+ Scope scope = owner.info().members();
+ Symbol other = scope.lookup(sym.name);
+ if (other == Symbol.NONE) {
+ scope.enter(sym);
+ } else {
+ assert sym == other
+ : "double enter: " + other + ":" + other.rawInfoAt(Symbol.FIRST_ID) + "," + sym + ":" + sym.rawInfoAt(Symbol.FIRST_ID);
+ }
+ }
}
}
@@ -183,8 +196,8 @@ public class UnPickle implements Kinds, Modifiers, EntryTags {
case NONEsym:
entries[n] = sym = Symbol.NONE;
break;
- case TERMref:
- case TYPEref:
+ case EXTref:
+ case EXTMODCLASSref:
Name name = readNameRef();
if (bp == end) {
owner = Global.instance.definitions.ROOT_CLASS;
@@ -194,18 +207,17 @@ public class UnPickle implements Kinds, Modifiers, EntryTags {
}
if (name.length() == 0 && owner == Symbol.NONE) {
sym = Global.instance.definitions.ROOT_CLASS;
- } else if (tag == TERMref && name.isTypeName()) {
- Symbol module = owner.info().lookup(name.toTermName());
- switch (module.type()) {
- case OverloadedType(Symbol[] alts, _):
- for (int i = 0; i < alts.length; i++)
- if (alts[i].isModule()) module = alts[i];
- }
- assert module.isModule();
- sym = module.moduleClass();
} else {
- assert (tag == TYPEref) == name.isTypeName();
sym = owner.info().lookup(name);
+ if (tag == EXTMODCLASSref) {
+ switch (sym.type()) {
+ case OverloadedType(Symbol[] alts, _):
+ for (int i = 0; i < alts.length; i++)
+ if (alts[i].isModule()) sym = alts[i];
+ }
+ assert sym.isModule();
+ sym = sym.moduleClass();
+ }
}
entries[n] = sym;
if (sym.kind == NONE) {
@@ -252,20 +264,10 @@ public class UnPickle implements Kinds, Modifiers, EntryTags {
sym.setInfo(getType(inforef));
sym.setTypeOfThis(readTypeRef());
Symbol constr = readSymbolRef();
- constr.copyTo(sym.allConstructors());
- if (sym.isCaseClass()) {
- Symbol cf = new TermSymbol(
- Position.NOPOS, name.toTermName(),
- owner, flags | CASE);
- cf.setInfo(setOwner(constr.type(), cf));
- if (name == classroot.name && owner == classroot.owner()) {
- if (global.debug)
- global.log("overwriting " + moduleroot);//debug
- cf.copyTo(moduleroot);
- cf = moduleroot;
- } else {
- enterSymbol(sym);
- }
+ if (constr != sym.primaryConstructor()) {
+ assert constr.type() instanceof Type.OverloadedType
+ : sym + " " + constr + ":" + constr.type();
+ constr.copyTo(sym.allConstructors());
}
break;
@@ -273,23 +275,23 @@ public class UnPickle implements Kinds, Modifiers, EntryTags {
if (bp < end) {
ClassSymbol clazz = (ClassSymbol) readSymbolRef();
if (name.isTypeName()) {
- entries[n] = sym = TermSymbol.newConstructor(
- clazz, flags);
+ entries[n] = sym = clazz.primaryConstructor();
+ sym.flags = flags;
} else {
assert (flags & MODUL) != 0 : name;
entries[n] = sym = TermSymbol.newModule(
Position.NOPOS, name, owner, flags, clazz);
- if (name == moduleroot.name && owner == moduleroot.owner()) {
- if (global.debug)
- global.log("overwriting " + moduleroot);//debug
- sym.copyTo(moduleroot);
- entries[n] = sym = moduleroot;
- }
}
} else {
entries[n] = sym = new TermSymbol(
Position.NOPOS, name, owner, flags);
}
+ if (name == moduleroot.name && owner == moduleroot.owner()) {
+ if (global.debug)
+ global.log("overwriting " + moduleroot);//debug
+ sym.copyTo(moduleroot);
+ entries[n] = sym = moduleroot;
+ }
Type tp = getType(inforef);
sym.setInfo(setOwner(tp, sym));
break;
@@ -298,8 +300,7 @@ public class UnPickle implements Kinds, Modifiers, EntryTags {
throw new BadSignature(this);
}
- if (owner.kind == CLASS)
- enterSymbol(sym);
+ enterSymbol(sym);
}
}
bp = savedBp;
diff --git a/sources/scalac/transformer/LambdaLiftPhase.java b/sources/scalac/transformer/LambdaLiftPhase.java
index a61011cfc9..92ac46cedb 100644
--- a/sources/scalac/transformer/LambdaLiftPhase.java
+++ b/sources/scalac/transformer/LambdaLiftPhase.java
@@ -47,8 +47,10 @@ public class LambdaLiftPhase extends PhaseDescriptor implements Kinds, Modifiers
}
public Type transformInfo(Symbol sym, Type tp) {
+ /*
if (global.debug)
global.log("transform info for " + sym + ":" + tp + sym.locationString());
+ */
Type tp1 = tp;
if (sym != Symbol.NONE) {
switch (tp) {
diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java
index 9976f447df..3a7e49944d 100644
--- a/sources/scalac/typechecker/Analyzer.java
+++ b/sources/scalac/typechecker/Analyzer.java
@@ -124,17 +124,15 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
switch (stats[i]) {
case ClassDef(_, _, _, _, _, _):
case ModuleDef(_, _, _, _):
- case ValDef(_, _, _, _):
Symbol sym = stats[i].symbol();
- Name fullname = sym.kind == VAL
- ? Name.fromString(sym.owner().fullName() + "." + sym.name)
- : sym.fullName();
+ Name fullname = sym.fullName();
Pickle pickle = (Pickle) unit.symdata.get(fullname);
if (pickle == null) {
pickle = new Pickle();
unit.symdata.put(fullname, pickle);
}
- pickle.add(sym);
+ pickle.add(sym.owner().info().lookup(sym.name.toTermName()));
+ pickle.add(sym.owner().info().lookup(sym.name.toTypeName()));
break;
case PackageDef(Tree packaged, Tree.Template templ):
genSymData(symdata, templ.body);
@@ -1436,7 +1434,7 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
tree1 = copy.Select(tree, sym, qual);
break;
case SelectFromType(_, _):
- tree1 = copy.Select(tree, sym, qual);
+ tree1 = copy.SelectFromType(tree, sym, qual);
break;
default:
throw new ApplicationError();