diff options
author | Martin Odersky <odersky@gmail.com> | 2003-08-04 09:43:44 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2003-08-04 09:43:44 +0000 |
commit | 8ccfe152e029e2a0a1a444bea8ab7cb686f7cd5b (patch) | |
tree | 739662fa27505299c547c34d7d981b0366bb6032 /sources/scalac/symtab | |
parent | e41aa28a336a5d6ac3e838780b2b70753c00eb3c (diff) | |
download | scala-8ccfe152e029e2a0a1a444bea8ab7cb686f7cd5b.tar.gz scala-8ccfe152e029e2a0a1a444bea8ab7cb686f7cd5b.tar.bz2 scala-8ccfe152e029e2a0a1a444bea8ab7cb686f7cd5b.zip |
*** empty log message ***
Diffstat (limited to 'sources/scalac/symtab')
-rw-r--r-- | sources/scalac/symtab/EntryTags.java | 2 | ||||
-rw-r--r-- | sources/scalac/symtab/SourceCompleter.java | 15 | ||||
-rw-r--r-- | sources/scalac/symtab/Symbol.java | 90 | ||||
-rw-r--r-- | sources/scalac/symtab/SymbolTablePrinter.java | 2 | ||||
-rw-r--r-- | sources/scalac/symtab/classfile/PackageParser.java | 7 | ||||
-rw-r--r-- | sources/scalac/symtab/classfile/Pickle.java | 5 | ||||
-rw-r--r-- | sources/scalac/symtab/classfile/SymblParser.java | 7 | ||||
-rw-r--r-- | sources/scalac/symtab/classfile/UnPickle.java | 114 |
8 files changed, 177 insertions, 65 deletions
diff --git a/sources/scalac/symtab/EntryTags.java b/sources/scalac/symtab/EntryTags.java index 41e71464ac..512027944b 100644 --- a/sources/scalac/symtab/EntryTags.java +++ b/sources/scalac/symtab/EntryTags.java @@ -30,7 +30,7 @@ public interface EntryTags { * | 15 METHODtpe len_Nat tpe_Ref {tpe_Ref} * | 16 POLYTtpe len_Nat tpe_Ref {sym_Ref} * | 17 OVERLOADEDtpe len_Nat {sym_Ref} {tpe_Ref} - * | 20 FLAGGEDtype len_Nat flags_Nat tpe_Ref + * | 20 FLAGGEDtpe len_Nat flags_Nat tpe_Ref * SymbolInfo = name_Ref owner_Ref flags_Nat info_Ref * NameInfo = <character sequence of length len_Nat in Utf8 format> * Ref = Nat diff --git a/sources/scalac/symtab/SourceCompleter.java b/sources/scalac/symtab/SourceCompleter.java index cf4938ccde..f835160b50 100644 --- a/sources/scalac/symtab/SourceCompleter.java +++ b/sources/scalac/symtab/SourceCompleter.java @@ -21,12 +21,10 @@ public class SourceCompleter extends Type.LazyType { /** the global compilation environment */ protected Global global; - protected String filename; private boolean completed = false; - public SourceCompleter(Global global, String filename) { + public SourceCompleter(Global global) { this.global = global; - this.filename = filename; } /** complete class symbol c by loading the unit @@ -34,15 +32,16 @@ public class SourceCompleter extends Type.LazyType { public void complete(Symbol c) { if (completed) { c.setInfo(Type.NoType); - } else if (filename != null) { + } else { try { - String fname = filename; long msec = System.currentTimeMillis(); - Unit unit = new Unit(global, new SourceFile(filename), false); - filename = null; + String filename = SourceRepresentation.externalizeFileName( + c.fullName()) + ".scala"; + java.io.File f = global.classPath.openJavaFile(filename); + Unit unit = new Unit(global, new SourceFile(f), false); global.PHASE.PARSER.apply(unit); global.PHASE.ANALYZER.lateEnter(global, unit, c); - global.operation("added " + fname + " in " + + global.operation("added " + filename + " in " + (System.currentTimeMillis() - msec) + "ms"); } catch (IOException e) { e.printStackTrace(); diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java index 6f1444f827..280d3f73e6 100644 --- a/sources/scalac/symtab/Symbol.java +++ b/sources/scalac/symtab/Symbol.java @@ -71,6 +71,12 @@ public abstract class Symbol implements Modifiers, Kinds { this.flags = flags & ~(INITIALIZED | LOCKED); // safety first } + protected void update(int pos, int flags) { + this.pos = pos; + this.flags = (flags & ~(INITIALIZED | LOCKED)) | + (this.flags & (INITIALIZED | LOCKED)); + } + /** Return a fresh symbol with the same fields as this one. */ public final Symbol cloneSymbol() { @@ -631,7 +637,7 @@ public abstract class Symbol implements Modifiers, Kinds { throw new CyclicReference(this, info); } flags |= LOCKED; - //System.out.println("completing " + this.name);//DEBUG + //System.out.println("completing " + this);//DEBUG info.complete(this); flags = flags & ~LOCKED; if (info instanceof SourceCompleter && (flags & SNDTIME) == 0) { @@ -642,7 +648,7 @@ public abstract class Symbol implements Modifiers, Kinds { assert !(rawInfoAt(id) instanceof Type.LazyType) : this; //flags |= INITIALIZED; } - //System.out.println("done: " + this.name);//DEBUG + //System.out.println("done: " + this);//DEBUG } return rawInfoAt(id); } @@ -666,6 +672,7 @@ public abstract class Symbol implements Modifiers, Kinds { /** get info at phase #id, without forcing lazy types. */ public Type rawInfoAt(int id) { + //if (infos == TypeIntervalList.EMPTY) return Type.NoType;//DEBUG assert infos != TypeIntervalList.EMPTY : this; int nextid = infos.limit; if (nextid < id) { @@ -1009,6 +1016,18 @@ public class TermSymbol extends Symbol { super(VAL, pos, name, owner, flags); } + public static TermSymbol define( + int pos, Name name, Symbol owner, int flags, Scope scope) { + Scope.Entry e = scope.lookupEntry(name); + if (e.owner == scope && e.sym.pos == Position.NOPOS && e.sym.kind == VAL) { + TermSymbol sym = (TermSymbol) e.sym; + sym.update(pos, flags); + return sym; + } else { + return new TermSymbol(pos, name, owner, flags); + } + } + public static TermSymbol newConstructor(Symbol clazz, int flags) { TermSymbol sym = new TermSymbol( clazz.pos, clazz.name, clazz.owner(), flags | FINAL); @@ -1020,30 +1039,28 @@ public class TermSymbol extends Symbol { return newConstructor(clazz, clazz.flags & (ACCESSFLAGS | JAVA)); } - public static TermSymbol newModule(int pos, Name name, Symbol owner, - int flags, ClassSymbol clazz) { - TermSymbol sym = new TermSymbol(pos, name, owner, flags | MODUL | FINAL); - sym.clazz = clazz; - clazz.setModule(sym); - sym.setInfo(clazz.typeConstructor()); - return sym; + public TermSymbol makeModule(ClassSymbol clazz) { + flags |= MODUL | FINAL; + this.clazz = clazz; + clazz.setModule(this); + setInfo(clazz.typeConstructor()); + return this; } - public static TermSymbol newModule(int pos, Name name, Symbol owner, - int flags) { + public TermSymbol makeModule() { ClassSymbol clazz = new ClassSymbol( - pos, name.toTypeName(), owner, flags | MODUL | FINAL); + pos, name.toTypeName(), owner(), flags | MODUL | FINAL); clazz.primaryConstructor().setInfo( Type.MethodType(Symbol.EMPTY_ARRAY, clazz.typeConstructor())); - - return newModule(pos, name, owner, flags, clazz); + return makeModule(clazz); } /** Constructor for companion modules to classes, which need to be completed. */ public static TermSymbol newCompanionModule(Symbol clazz, int flags, Type.LazyType parser) { - TermSymbol sym = newModule(Position.NOPOS, clazz.name.toTermName(), clazz.owner(), - flags); + TermSymbol sym = new TermSymbol( + Position.NOPOS, clazz.name.toTermName(), clazz.owner(), flags) + .makeModule(); sym.clazz.setInfo(parser); return sym; } @@ -1051,7 +1068,8 @@ public class TermSymbol extends Symbol { /** Java package module constructor */ public static TermSymbol newJavaPackageModule(Name name, Symbol owner, Type.LazyType parser) { - TermSymbol sym = newModule(Position.NOPOS, name, owner, JAVA | PACKAGE); + TermSymbol sym = new TermSymbol(Position.NOPOS, name, owner, JAVA | PACKAGE) + .makeModule(); sym.clazz.flags |= SYNTHETIC; sym.clazz.setInfo(parser != null ? parser : Type.compoundType(Type.EMPTY_ARRAY, new Scope(), sym)); return sym; @@ -1080,7 +1098,7 @@ public class TermSymbol extends Symbol { assert !isPrimaryConstructor() : Debug.show(this); TermSymbol other; if (isModule()) { - other = newModule(pos, name, owner, flags); + other = new TermSymbol(pos, name, owner, flags).makeModule(); } else { other = new TermSymbol(pos, name, owner, flags); other.clazz = clazz; @@ -1123,6 +1141,17 @@ public class TypeSymbol extends Symbol { super(kind, pos, name, owner, flags); } + public static TypeSymbol define( + int pos, Name name, Symbol owner, int flags, Scope scope) { + Scope.Entry e = scope.lookupEntry(name); + if (e.owner == scope && e.sym.pos == Position.NOPOS && e.sym.kind == ALIAS) { + TypeSymbol sym = (TypeSymbol) e.sym; + sym.update(pos, flags); + return sym; + } else { + return new TypeSymbol(ALIAS, pos, name, owner, flags); + } + } /** Return a fresh symbol with the same fields as this one. */ @@ -1283,6 +1312,18 @@ public class AbsTypeSymbol extends TypeSymbol { super(TYPE, pos, name, owner, flags); } + public static AbsTypeSymbol define( + int pos, Name name, Symbol owner, int flags, Scope scope) { + Scope.Entry e = scope.lookupEntry(name); + if (e.owner == scope && e.sym.pos == Position.NOPOS && e.sym.kind == TYPE) { + AbsTypeSymbol sym = (AbsTypeSymbol) e.sym; + sym.update(pos, flags); + return sym; + } else { + return new AbsTypeSymbol(pos, name, owner, flags); + } + } + /** Return a fresh symbol with the same fields as this one. */ public Symbol cloneSymbol(Symbol owner) { @@ -1356,6 +1397,19 @@ public class ClassSymbol extends TypeSymbol { this.mangled = name; } + public static ClassSymbol define( + int pos, Name name, Symbol owner, int flags, Scope scope) { + Scope.Entry e = scope.lookupEntry(name); + if (e.owner == scope && e.sym.pos == Position.NOPOS && e.sym.kind == CLASS) { + ClassSymbol sym = (ClassSymbol) e.sym; + sym.update(pos, flags); + sym.template = null; + return sym; + } else { + return new ClassSymbol(pos, name, owner, flags); + } + } + /** Constructor for classes to load as source files */ public ClassSymbol(Name name, Symbol owner, SourceCompleter parser) { diff --git a/sources/scalac/symtab/SymbolTablePrinter.java b/sources/scalac/symtab/SymbolTablePrinter.java index e934073e94..a28abc9457 100644 --- a/sources/scalac/symtab/SymbolTablePrinter.java +++ b/sources/scalac/symtab/SymbolTablePrinter.java @@ -337,6 +337,7 @@ public class SymbolTablePrinter { /** Prints the full name of the given symbol */ public SymbolTablePrinter printSymbolFullName(Symbol symbol) { print(getSymbolFullName(symbol)); + //print("{" + symbol.owner() + "}");//DEBUG return printSymbolUniqueId(symbol); } @@ -514,6 +515,7 @@ public class SymbolTablePrinter { return printTemplateType(pre.memberInfo(sym).parents()); } printPrefix(pre).printSymbolName(sym); + //print("{" + sym.owner() + "}");//DEBUG if (args.length != 0) print('[').printTypes(args, ",").print(']'); return this; case SingleType(Type pre, Symbol sym): diff --git a/sources/scalac/symtab/classfile/PackageParser.java b/sources/scalac/symtab/classfile/PackageParser.java index e523bc4dbb..9fdbe797ed 100644 --- a/sources/scalac/symtab/classfile/PackageParser.java +++ b/sources/scalac/symtab/classfile/PackageParser.java @@ -101,12 +101,13 @@ public class PackageParser extends Type.LazyType { locals.enter(module); locals.enter(module.moduleClass()); } - } else if (inclClasses && global.separate && fname.endsWith(".symbl")) { + } else if (inclClasses && fname.endsWith(".symbl")) { //todo: compare dates between symbl and scala. Name n = Name.fromString(fname.substring(0, fname.length() - 6)) .toTypeName(); Symbol sym = locals.lookup(n); if (sym == Symbol.NONE || + sym.isPackage() || sym.rawInfoAt(Symbol.FIRST_ID) instanceof ClassParser && !(sym.rawInfoAt(Symbol.FIRST_ID) instanceof SymblParser)) { ClassSymbol clazz = new ClassSymbol(n, p, symblCompletion); @@ -121,10 +122,10 @@ public class PackageParser extends Type.LazyType { .toTypeName(); Symbol sym = locals.lookup(n); if (sym == Symbol.NONE || + sym.isPackage() || sym.rawInfoAt(Symbol.FIRST_ID) instanceof ClassParser && !(sym.rawInfoAt(Symbol.FIRST_ID) instanceof SymblParser)) { - SourceCompleter completer = new SourceCompleter(global, - dir.getPath() + File.separatorChar + fname); + SourceCompleter completer = new SourceCompleter(global); ClassSymbol clazz = new ClassSymbol(n, p, completer); //todo: needed? clazz.allConstructors().setInfo(completer); diff --git a/sources/scalac/symtab/classfile/Pickle.java b/sources/scalac/symtab/classfile/Pickle.java index 7deaa52675..a82962dfb5 100644 --- a/sources/scalac/symtab/classfile/Pickle.java +++ b/sources/scalac/symtab/classfile/Pickle.java @@ -8,6 +8,7 @@ package scalac.symtab.classfile; +import ch.epfl.lamp.util.Position; import java.util.HashMap; import java.io.*; import scalac.Global; @@ -45,8 +46,8 @@ public class Pickle implements Kinds, Modifiers, EntryTags { /** Pickle all symbols descending from `root'. */ public void add(Symbol root) { - if (root.kind != NONE) { - if (debug) System.out.println("adding " + root);//debug + if (root.pos != Position.NOPOS) { + if (Global.instance.debug) System.out.println("pickling " + root); if (index.get(root) == null) { this.rootname = root.name.toTermName(); this.rootowner = root.owner(); diff --git a/sources/scalac/symtab/classfile/SymblParser.java b/sources/scalac/symtab/classfile/SymblParser.java index 1c2ef25618..2f8956d608 100644 --- a/sources/scalac/symtab/classfile/SymblParser.java +++ b/sources/scalac/symtab/classfile/SymblParser.java @@ -38,9 +38,10 @@ public class SymblParser extends ClassParser { new UnPickle(c, data, Name.fromString(filename)); global.operation("loaded " + f.getPath() + " in " + (System.currentTimeMillis() - msec) + "ms"); - //for (Definition e = c.locals().elems; e != null; e = e.sibling) - // if (e.def.kind == TYP) - // e.def.complete(); + /* + if (!global.separate) + new SourceCompleter(global).complete(c);//for now + */ } } catch (IOException e) { e.printStackTrace(); diff --git a/sources/scalac/symtab/classfile/UnPickle.java b/sources/scalac/symtab/classfile/UnPickle.java index 8f6b817063..de755fd7fd 100644 --- a/sources/scalac/symtab/classfile/UnPickle.java +++ b/sources/scalac/symtab/classfile/UnPickle.java @@ -9,6 +9,7 @@ package scalac.symtab.classfile; import java.util.HashMap; +import java.io.PrintStream; import scalac.*; import scalac.util.*; import ch.epfl.lamp.util.Position; @@ -60,28 +61,13 @@ public class UnPickle implements Kinds, Modifiers, EntryTags { bp = readNat() + bp; } entries = new Object[index.length]; - if (global.debug) { - global.log("length: " + index.length); - for (int i = 0; i < index.length; i++) { - System.out.print(i + "," + index[i] + ": "); - bp = index[i]; - int tag = readByte(); - System.out.print(tag + " "); - int len = readNat(); - System.out.print(len + " "); - if (tag == TERMname || tag == TYPEname) - System.out.print( - SourceRepresentation.ascii2string(bytes, bp, len)); - else - for (int j = 0; j < len; j++) - System.out.print(readByte() + " "); - System.out.println(); - } - } + + if (global.debug) print(System.out); + for (int i = 0; i < index.length; i++) { if (isSymbolEntry(i)) getSymbol(i); } - if (global.debug) global.log("unpickled " + root);//debug + if (global.debug) global.log("unpickled " + root + ":" + root.rawInfo());//debug if (!root.isInitialized()) throw new BadSignature(this, "it does not define " + root); } @@ -98,8 +84,10 @@ public class UnPickle implements Kinds, Modifiers, EntryTags { params[0].owner() != owner && params[0].owner() != Symbol.NONE) { params1 = new Symbol[params.length]; for (int i = 0; i < params.length; i++) - params1[i] = params[i].cloneSymbol().setOwner(owner); + params1[i] = params[i].cloneSymbol(); } + for (int i = 0; i < params.length; i++) + params1[i].setOwner(owner); Type restpe1 = setOwner(restpe, owner); if (params1 == params && restpe1 == restpe) return tp; else return Type.MethodType(params1, restpe1); @@ -222,7 +210,7 @@ public class UnPickle implements Kinds, Modifiers, EntryTags { entries[n] = sym; if (sym.kind == NONE) { if (global.debug) - global.log(owner.info().members().toString());//debug + global.log(owner.info().members().toString()); throw new BadSignature(this, "reference " + decode(name) + " of " + owner + " refers to nonexisting symbol."); @@ -232,7 +220,7 @@ public class UnPickle implements Kinds, Modifiers, EntryTags { assert isSymbolEntry(n) : n; Name name = readNameRef(); if (global.debug) - global.log("reading " + name + " at " + n);//debug + global.log("reading " + name + " at " + n); owner = readSymbolRef(); if (entries[n] == null) { int flags = readNat(); @@ -241,14 +229,14 @@ public class UnPickle implements Kinds, Modifiers, EntryTags { case TYPEsym: entries[n] = sym = new AbsTypeSymbol( Position.NOPOS, name, owner, flags); - sym.setInfo(getType(inforef)); + sym.setInfo(getType(inforef), Symbol.FIRST_ID); sym.setLoBound(readTypeRef()); break; case ALIASsym: entries[n] = sym = new TypeSymbol( ALIAS, Position.NOPOS, name, owner, flags); - sym.setInfo(getType(inforef)); + sym.setInfo(getType(inforef), Symbol.FIRST_ID); break; case CLASSsym: @@ -261,7 +249,7 @@ public class UnPickle implements Kinds, Modifiers, EntryTags { sym.copyTo(clr); entries[n] = sym = clr; } - sym.setInfo(getType(inforef)); + sym.setInfo(getType(inforef), Symbol.FIRST_ID); sym.setTypeOfThis(readTypeRef()); Symbol constr = readSymbolRef(); if (constr != sym.primaryConstructor()) { @@ -279,8 +267,9 @@ public class UnPickle implements Kinds, Modifiers, EntryTags { sym.flags = flags; } else { assert (flags & MODUL) != 0 : name; - entries[n] = sym = TermSymbol.newModule( - Position.NOPOS, name, owner, flags, clazz); + entries[n] = sym = new TermSymbol( + Position.NOPOS, name, owner, flags) + .makeModule(clazz); } } else { entries[n] = sym = new TermSymbol( @@ -288,12 +277,12 @@ public class UnPickle implements Kinds, Modifiers, EntryTags { } if (name == moduleroot.name && owner == moduleroot.owner()) { if (global.debug) - global.log("overwriting " + moduleroot);//debug + global.log("overwriting " + moduleroot); sym.copyTo(moduleroot); entries[n] = sym = moduleroot; } Type tp = getType(inforef); - sym.setInfo(setOwner(tp, sym)); + sym.setInfo(setOwner(tp, sym), Symbol.FIRST_ID); break; default: @@ -375,7 +364,7 @@ public class UnPickle implements Kinds, Modifiers, EntryTags { params[i] = new TermSymbol( Position.NOPOS, Name.fromString("$" + i), Symbol.NONE, PARAM | flags[i]); - params[i].setInfo(argtypes[i]); + params[i].setInfo(argtypes[i], Symbol.FIRST_ID); } tpe = Type.MethodType(params, restype); break; @@ -468,5 +457,70 @@ public class UnPickle implements Kinds, Modifiers, EntryTags { this(outer, "malformed signature at " + outer.bp); } } + +// --- print symbl files ------------------------------------------------- + + private static String tag2string(int tag) { + switch (tag) { + case TERMname: return "TERMname"; + case TYPEname: return "TYPEname"; + case NONEsym: return "NONEsym"; + case TYPEsym: return "TYPEsym"; + case ALIASsym: return "ALIASsym"; + case CLASSsym: return "CLASSsym"; + case VALsym: return "VALsym"; + case EXTref: return "EXTref"; + case EXTMODCLASSref: return "EXTMODCLASSref"; + case NOtpe: return "NOtpe"; + case THIStpe: return "THIStpe"; + case SINGLEtpe: return "SINGLEtpe"; + case TYPEREFtpe: return "TYPEREFtpe"; + case COMPOUNDtpe: return "COMPOUNDtpe"; + case METHODtpe: return "METHODtpe"; + case POLYtpe: return "POLYtpe"; + case OVERLOADEDtpe: return "OVERLOADEDtpe"; + case UNBOXEDtpe: return "UNBOXEDtpe"; + case UNBOXEDARRAYtpe: return "UNBOXEDARRAYtpe"; + case FLAGGEDtpe: return "FLAGGEDtpe"; + case ERRORtpe: return "ERRORtpe"; + default: return "***BAD TAG***(" + tag + ")"; + } + } + + private void print(PrintStream out) { + out.println("symbl attribute for " + classroot + ":"); + for (int i = 0; i < index.length; i++) { + out.print(i + "," + index[i] + ": "); + bp = index[i]; + int tag = readByte(); + out.print(tag2string(tag)); + int len = readNat(); + int end = len + bp; + out.print(" " + len); + switch (tag) { + case TERMname: + case TYPEname: + out.print(" " + + SourceRepresentation.ascii2string(bytes, bp, len)); + bp = end; + break; + case NONEsym: + break; + case TYPEsym: + case ALIASsym: + case CLASSsym: + case VALsym: + out.print(" " + readNat()); //name + out.print(" " + readNat()); //owner + out.print(" " + Integer.toHexString(readNat())); //flags + out.print(" " + readNat()); //type + break; + case FLAGGEDtpe: + out.print(" " + Integer.toHexString(readNat())); //flags + } + while (bp < end) out.print(" " + readNat()); + out.println(); + } + } } |