summaryrefslogtreecommitdiff
path: root/sources/scalac/symtab/classfile
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2004-04-14 13:31:35 +0000
committerpaltherr <paltherr@epfl.ch>2004-04-14 13:31:35 +0000
commit3ec2af254866c60389b3fd304c14d1137b9cf4c8 (patch)
treec4cb09396b20ca0a2412930c891cee3566c7a2c6 /sources/scalac/symtab/classfile
parentfbd9b93cc4f10e90da94d963f3e052803e93acfd (diff)
downloadscala-3ec2af254866c60389b3fd304c14d1137b9cf4c8.tar.gz
scala-3ec2af254866c60389b3fd304c14d1137b9cf4c8.tar.bz2
scala-3ec2af254866c60389b3fd304c14d1137b9cf4c8.zip
- Replaced Symbol.module by Symbol.sourceModule
- Made Symbol.linkedModule and Symbol.linkedClass a bit less ambiguous - Added documentation to Symbol.sourceModule and Symbol.linkedModule - Added classes ConstructorSymbol, ModuleSymbol ModuleClassSymbol - Added classes LinkedModuleSymbol and LinkedClassSymbol - Changed the argument order in symbol constructors to be the same as in the symbol factories - Changed Pickle to use sourceModule instead of HashTable - Replaced notion of main class by notion of root symbol in SymbolLoader - Fixed UnPickle to work with any root symbol
Diffstat (limited to 'sources/scalac/symtab/classfile')
-rw-r--r--sources/scalac/symtab/classfile/CLRClassParser.java10
-rw-r--r--sources/scalac/symtab/classfile/CLRPackageParser.java4
-rw-r--r--sources/scalac/symtab/classfile/ClassParser.java6
-rw-r--r--sources/scalac/symtab/classfile/PackageParser.java5
-rw-r--r--sources/scalac/symtab/classfile/Pickle.java15
-rw-r--r--sources/scalac/symtab/classfile/SymblParser.java4
-rw-r--r--sources/scalac/symtab/classfile/UnPickle.java30
7 files changed, 41 insertions, 33 deletions
diff --git a/sources/scalac/symtab/classfile/CLRClassParser.java b/sources/scalac/symtab/classfile/CLRClassParser.java
index 7c7f2f1376..9de9d17629 100644
--- a/sources/scalac/symtab/classfile/CLRClassParser.java
+++ b/sources/scalac/symtab/classfile/CLRClassParser.java
@@ -39,10 +39,14 @@ public class CLRClassParser extends SymbolLoader {
private static Name[] ENUM_BIT_LOG_NAMES = new Name[]
{ Names.OR, Names.AND, Names.XOR };
- protected String doComplete(Symbol clazz) {
- try { return doComplete0(clazz); }
+ protected String doComplete(Symbol root) {
+ assert root.isClassType(): Debug.show(root);
+ try { return doComplete0(root); }
catch (Throwable e) {
- System.err.println("\nWhile processing " + Debug.show(clazz));
+ // !!! doComplete may throw an IOException which is then
+ // caught by SymbolLoader and reported to the user as
+ // normal error message
+ System.err.println("\nWhile processing " + Debug.show(root));
e.printStackTrace();
System.exit(1);
return null; // !!!
diff --git a/sources/scalac/symtab/classfile/CLRPackageParser.java b/sources/scalac/symtab/classfile/CLRPackageParser.java
index 10e6d4acd6..90fd0fcc47 100644
--- a/sources/scalac/symtab/classfile/CLRPackageParser.java
+++ b/sources/scalac/symtab/classfile/CLRPackageParser.java
@@ -221,7 +221,9 @@ public class CLRPackageParser extends SymbolLoader {
//##########################################################################
// main functionality
- protected String doComplete(Symbol p) {
+ protected String doComplete(Symbol root) {
+ assert root.isRoot() || root.isPackage(): Debug.show(root);
+ Symbol p = root.isRoot() ? root : root.moduleClass();
Scope members = new Scope();
importCLRTypes(p, members);
p.setInfo(scalac.symtab.Type.compoundType
diff --git a/sources/scalac/symtab/classfile/ClassParser.java b/sources/scalac/symtab/classfile/ClassParser.java
index f920a5ef79..5284d9cfed 100644
--- a/sources/scalac/symtab/classfile/ClassParser.java
+++ b/sources/scalac/symtab/classfile/ClassParser.java
@@ -15,6 +15,7 @@ import scala.tools.util.AbstractFile;
import scalac.Global;
import scalac.symtab.Symbol;
import scalac.symtab.SymbolLoader;
+import scalac.util.Debug;
/** This class implements a SymbolLoader that reads a class file. */
public class ClassParser extends SymbolLoader {
@@ -38,8 +39,9 @@ public class ClassParser extends SymbolLoader {
// Protected Methods
/** Completes the specified symbol by reading the class file. */
- protected String doComplete(Symbol clasz) throws IOException {
- ClassfileParser.parse(global, file, clasz);
+ protected String doComplete(Symbol root) throws IOException {
+ assert root.isClassType(): Debug.show(root);
+ ClassfileParser.parse(global, file, root);
return "class file '" + file + "'";
}
diff --git a/sources/scalac/symtab/classfile/PackageParser.java b/sources/scalac/symtab/classfile/PackageParser.java
index 13882f7714..07d196312c 100644
--- a/sources/scalac/symtab/classfile/PackageParser.java
+++ b/sources/scalac/symtab/classfile/PackageParser.java
@@ -21,6 +21,7 @@ import scalac.symtab.Symbol;
import scalac.symtab.SymbolLoader;
import scalac.symtab.Type;
import scalac.util.Name;
+import scalac.util.Debug;
/**
* This class implements a package member loader. It can be used to
@@ -47,7 +48,9 @@ public class PackageParser extends SymbolLoader {
// Protected Methods
/** Completes the package symbol by loading all its members. */
- protected String doComplete(Symbol peckage) {
+ protected String doComplete(Symbol root) {
+ assert root.isRoot() || root.isPackage(): Debug.show(root);
+ Symbol peckage = root.isRoot() ? root : root.moduleClass();
// collect JVM and source members
boolean isRoot = peckage.isRoot();
HashMap sources = new HashMap();
diff --git a/sources/scalac/symtab/classfile/Pickle.java b/sources/scalac/symtab/classfile/Pickle.java
index bd2f1f0ef2..6891093e75 100644
--- a/sources/scalac/symtab/classfile/Pickle.java
+++ b/sources/scalac/symtab/classfile/Pickle.java
@@ -34,7 +34,6 @@ public class Pickle implements Kinds, Modifiers, EntryTags {
private HashMap index;
private Object[] entries;
private int ep;
- private final HashMap modules; // maps module-classes to modules
/** Write symbol table info for root.
* root must be either a module or a class.
@@ -43,7 +42,6 @@ public class Pickle implements Kinds, Modifiers, EntryTags {
index = new HashMap();
entries = new Object[256];
ep = 0;
- modules = new HashMap();
}
/** Pickle all symbols descending from `root'.
@@ -132,6 +130,7 @@ public class Pickle implements Kinds, Modifiers, EntryTags {
break;
case CLASS:
putType(sym.info());
+ if (sym.isModuleClass()) putSymbol(sym.sourceModule());
putType(sym.typeOfThis());
putSymbol(sym.allConstructors());
for (Scope.SymbolIterator it = sym.members().iterator();
@@ -143,12 +142,8 @@ public class Pickle implements Kinds, Modifiers, EntryTags {
if (sym.isConstructor() &&
sym == sym.constructorClass().allConstructors())
putSymbol(sym.constructorClass());
- else if (sym.isModule()) {
- Symbol clasz = sym.moduleClass();
+ else if (sym.isModule())
putSymbol(sym.moduleClass());
- assert !modules.containsKey(clasz): Debug.show(sym);
- modules.put(clasz, sym);
- }
break;
default:
throw new ApplicationError();
@@ -358,11 +353,7 @@ public class Pickle implements Kinds, Modifiers, EntryTags {
break;
case CLASS:
writeRef(sym.info());
- if (sym.isModuleClass()) {
- Symbol module = (Symbol)modules.remove(sym);
- assert module != null: Debug.show(sym);
- writeRef(module);
- }
+ if (sym.isModuleClass()) writeRef(sym.sourceModule());
writeRef(sym.typeOfThis());
writeRef(sym.allConstructors());
break;
diff --git a/sources/scalac/symtab/classfile/SymblParser.java b/sources/scalac/symtab/classfile/SymblParser.java
index 56873215e8..5c948d9176 100644
--- a/sources/scalac/symtab/classfile/SymblParser.java
+++ b/sources/scalac/symtab/classfile/SymblParser.java
@@ -38,8 +38,8 @@ public class SymblParser extends SymbolLoader {
// Protected Methods
/** Completes the specified symbol by reading the symbol file. */
- public String doComplete(Symbol clasz) throws IOException {
- UnPickle.parse(global, file, clasz);
+ public String doComplete(Symbol root) throws IOException {
+ UnPickle.parse(global, file, root);
return "symbol file '" + file + "'";
}
diff --git a/sources/scalac/symtab/classfile/UnPickle.java b/sources/scalac/symtab/classfile/UnPickle.java
index 61c62dc63f..9579458394 100644
--- a/sources/scalac/symtab/classfile/UnPickle.java
+++ b/sources/scalac/symtab/classfile/UnPickle.java
@@ -38,6 +38,11 @@ public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags {
}
}
+ /**
+ * The root symbol must be either a module or a non-module
+ * class. The unpickler initializes it. If it has a linked module
+ * or class, it will also be initialized.
+ */
public static void parse(Global global, byte[] data, Symbol root)
throws BadSignature
{
@@ -55,17 +60,16 @@ public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags {
private UnPickle(Global global, byte[] data, Symbol root) {
this.global = global;
- this.classroot = root.linkedClass();
- this.moduleroot = root.linkedModule();
- assert !classroot.isNone(): Debug.show(root);
- assert !moduleroot.isNone(): Debug.show(root);
- if (root != moduleroot && moduleroot.isModule()) {
+ this.classroot = root.isModule() ? root.linkedClass() : root;
+ this.moduleroot = root.isClassType() ? root.linkedModule() : root;
+ assert classroot == null || classroot.isClassType(): Debug.show(root);
+ assert moduleroot == null || moduleroot.isModule(): Debug.show(root);
+ if (root != moduleroot && moduleroot != null) {
moduleroot.moduleClass().setInfo(Type.NoType);
}
- if (global.debug)
- global.log(
- "unpickle " + root + " " + classroot + " " + moduleroot + " " +
- moduleroot.moduleClass() + " " + moduleroot.moduleClass().primaryConstructor());
+ if (global.debug) global.log(
+ "unpickle " + root + " " + classroot + " " + moduleroot
+ + (moduleroot != null ? " " + moduleroot.moduleClass() : ""));
this.bytes = data;
this.bp = 0;
index = new int[readNat()];
@@ -84,7 +88,9 @@ public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags {
if (global.debug) global.log("unpickled " + root + ":" + root.rawInfo());//debug
if (!root.isInitialized())
throw new BadSignature(this, "it does not define " + root);
- if (moduleroot.isModule() && moduleroot.moduleClass().type() == Type.NoType) {
+ // the isModule test is needed because moduleroot may become
+ // the case class factory method of classroot
+ if (moduleroot != null && moduleroot.isModule() && moduleroot.moduleClass().type() == Type.NoType) {
moduleroot.setInfo(Type.NoType);
}
}
@@ -259,7 +265,7 @@ public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags {
Symbol modulesym = readSymbolRef();
entries[n] = sym = modulesym.moduleClass();
sym.flags = flags;
- } else if (name == classroot.name && owner == classroot.owner()) {
+ } else if (classroot != null && name == classroot.name && owner == classroot.owner()) {
if (global.debug)
global.log("overwriting " + classroot);
entries[n] = sym = classroot;
@@ -275,7 +281,7 @@ public class UnPickle implements Kinds, Modifiers, EntryTags, TypeTags {
break;
case VALsym:
- if (name == moduleroot.name && owner == moduleroot.owner()) {
+ if (moduleroot != null && name == moduleroot.name && owner == moduleroot.owner()) {
if (global.debug)
global.log("overwriting " + moduleroot);
entries[n] = sym = moduleroot;