summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsources/scala/tools/nsc/Global.scala29
-rw-r--r--sources/scala/tools/nsc/ast/Trees.scala13
-rwxr-xr-xsources/scala/tools/nsc/ast/parser/Parsers.scala28
-rw-r--r--sources/scala/tools/nsc/models/SemanticTokens.scala143
-rw-r--r--sources/scala/tools/nsc/reporters/StoreReporter.scala4
-rwxr-xr-xsources/scala/tools/nsc/symtab/Definitions.scala8
-rwxr-xr-xsources/scala/tools/nsc/symtab/Types.scala2
-rwxr-xr-xsources/scala/tools/nsc/util/Position.scala12
-rw-r--r--sources/scala/tools/nsc/util/SourceFile.scala3
9 files changed, 182 insertions, 60 deletions
diff --git a/sources/scala/tools/nsc/Global.scala b/sources/scala/tools/nsc/Global.scala
index 9219646bca..9fee761272 100755
--- a/sources/scala/tools/nsc/Global.scala
+++ b/sources/scala/tools/nsc/Global.scala
@@ -171,6 +171,7 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
val unit0 = currentRun.currentUnit;
currentRun.currentUnit = unit;
apply(unit);
+ currentRun.advanceUnit;
assert(currentRun.currentUnit == unit);
currentRun.currentUnit = unit0;
}
@@ -280,8 +281,12 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
override def currentRun: Run = curRun;
class TyperRun extends Run {
- override val terminalPhase : Phase = typerPhase.next;
+ override val terminalPhase : Phase = typerPhase.next.next;
+ //override val terminalPhase : Phase = superAccessors.next;
}
+
+
+
class Run extends CompilerRun {
var currentUnit : CompilationUnit = _;
curRun = this;
@@ -299,11 +304,29 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
}
}
+ // progress tracking
+ def progress(current : Int, total : Int) : Unit = {}
+ private var phasec : Int = 0;
+ private var unitc : Int = 0;
+ def advancePhase : Unit = {
+ unitc = 0;
+ phasec = phasec + 1;
+ refreshProgress;
+ }
+ def advanceUnit : Unit = {
+ unitc = unitc + 1;
+ refreshProgress;
+ }
+ private def refreshProgress = if (fileset.size > 0)
+ progress((phasec * fileset.size) + unitc,
+ (phaseDescriptors.length+1) * fileset.size);
+
+
+
override val terminalPhase : Phase = new GlobalPhase(p) {
def name = "terminal";
def apply(unit: CompilationUnit): unit = {}
}
-
override def phaseNamed(name: String): Phase = {
var p: Phase = firstPhase;
while (p.next != p && p.name != name) p = p.next;
@@ -357,6 +380,7 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
else checker.checkTrees;
}
if (settings.statistics.value) statistics.print(phase);
+ advancePhase;
}
if (settings.Xshowcls.value != "") showDef(newTermName(settings.Xshowcls.value), false);
@@ -399,6 +423,7 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
atPhase(localPhase)(localPhase.applyPhase(unit));
localPhase = localPhase.next.asInstanceOf[GlobalPhase];
}
+ refreshProgress;
}
def compileFiles(files: List[AbstractFile]): unit =
diff --git a/sources/scala/tools/nsc/ast/Trees.scala b/sources/scala/tools/nsc/ast/Trees.scala
index 3ff630da12..fba4e84db5 100644
--- a/sources/scala/tools/nsc/ast/Trees.scala
+++ b/sources/scala/tools/nsc/ast/Trees.scala
@@ -453,10 +453,8 @@ import symtab.Flags._;
override def setPos(pos : Int) : this.type = {
val ret = super.setPos(pos);
- if (pos == 23) {
- //System.err.println("SELECT: " + this);
- //Thread.dumpStack();
- }
+ // System.err.println("SELECT_POS: " + pos + " " + this);
+ // if (pos == 74) Thread.dumpStack();
ret;
}
@@ -496,6 +494,13 @@ import symtab.Flags._;
var original : Tree = _;
def setOriginal(tree : Tree) : this.type = {
+ tree match {
+ case tt : TypeTree =>
+ System.err.println("Illegal: " + this + " to " + tree);
+ Thread.dumpStack();
+ case _ =>
+ }
+
original = tree;
setPos(tree.pos);
}
diff --git a/sources/scala/tools/nsc/ast/parser/Parsers.scala b/sources/scala/tools/nsc/ast/parser/Parsers.scala
index 49a958c617..74183c83f8 100755
--- a/sources/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/sources/scala/tools/nsc/ast/parser/Parsers.scala
@@ -324,14 +324,14 @@ import Tokens._;
if (in.token == THIS) {
t = atPos(in.skipToken()) { This(nme.EMPTY.toTypeName) }
if (!thisOK || in.token == DOT)
- t = atPos(accept(DOT)) { selectors(t, typeOK) }
+ t = { selectors(t, typeOK, accept(DOT)) }
} else if (in.token == SUPER) {
t = atPos(in.skipToken()) {
Super(nme.EMPTY.toTypeName, mixinQualifierOpt())
}
t = atPos(accept(DOT)) { Select(t, ident()) }
if (in.token == DOT)
- t = atPos(in.skipToken()) { selectors(t, typeOK) }
+ t = { selectors(t, typeOK, in.skipToken()) }
} else {
val i = atPos(in.currentPos) { Ident(ident()) }
t = i;
@@ -341,29 +341,35 @@ import Tokens._;
in.nextToken();
t = atPos(i.pos) { This(i.name.toTypeName) }
if (!thisOK || in.token == DOT)
- t = atPos(accept(DOT)) { selectors(t, typeOK) }
+ t = { selectors(t, typeOK, accept(DOT)) }
} else if (in.token == SUPER) {
in.nextToken();
t = atPos(i.pos) { Super(i.name.toTypeName, mixinQualifierOpt()) }
t = atPos(accept(DOT)) { Select(t, ident())}
if (in.token == DOT)
- t = atPos(in.skipToken()) { selectors(t, typeOK) }
+ t = { selectors(t, typeOK, in.skipToken()) }
} else {
- t = atPos(pos) { selectors(t, typeOK) }
+ t = { selectors(t, typeOK, pos) }
}
}
}
t
}
- def selectors(t: Tree, typeOK: boolean): Tree =
+ def selectors(t: Tree, typeOK: boolean, pos: Int): Tree =
if (typeOK && in.token == TYPE) {
in.nextToken();
- SingletonTypeTree(t)
+ atPos(pos) { SingletonTypeTree(t) }
} else {
- val t1 = Select(t, ident());
- if (in.token == DOT) atPos(in.skipToken()) { selectors(t1, typeOK) }
- else t1
+ val ident0 : Name = ident();
+ //System.err.println("IDENT: " + ident0);
+ val t1 = atPos(pos) { Select(t, ident0); }
+ if (in.token == DOT) {
+ val skipPos = in.skipToken();
+ //System.err.println("SKIP: " + skipPos);
+ //Thread.dumpStack();
+ selectors(t1, typeOK, skipPos);
+ } else t1;
}
/** MixinQualifier ::= `[' Id `]'
@@ -389,7 +395,7 @@ import Tokens._;
*/
def qualId(): Tree = {
val id = atPos(in.currentPos) { Ident(ident()) }
- if (in.token == DOT) atPos(in.skipToken()) { selectors(id, false) }
+ if (in.token == DOT) { selectors(id, false, in.skipToken()) }
else id
}
diff --git a/sources/scala/tools/nsc/models/SemanticTokens.scala b/sources/scala/tools/nsc/models/SemanticTokens.scala
index 46763040aa..d92fb33ac5 100644
--- a/sources/scala/tools/nsc/models/SemanticTokens.scala
+++ b/sources/scala/tools/nsc/models/SemanticTokens.scala
@@ -126,20 +126,10 @@ class SemanticTokens(val compiler: Compiler) {
}
};
}
- class Def(tree0 : DefTree) extends Semantic(tree0.symbol) {
- // if (info.defined != null) throw new Error("old=" + info.defined + " vs. new=" + this);
+ class Def(symbol0 : Symbol) extends Semantic(symbol0) {
info.defined = this;
override def toString() = "def-" + name + "-" + symbol.getClass();
-
- // if (name.equals("x$0")) throw new Error("SYM=" + symbol + " TREE: " + tree0);
-
}
- def Def(tree : DefTree) = if (tree.symbol == NoSymbol) {
- val gap = new Gap();
- gap.setLength(1);
- gap;
- } else new Def(tree);
-
class Use(symbol0 : Symbol) extends Semantic(symbol0) {
info.uses += this;
@@ -152,9 +142,21 @@ class SemanticTokens(val compiler: Compiler) {
// ok start building....
def build[T <: Tree](trees : List[T]) : Unit = for (val tree : T <- trees) build(tree);
- def build(tree0 : Tree) : Unit = if (tree0.pos != Position.NOPOS) tree0 match {
+ def build(tree0 : Tree) : Unit = {
+ tree0 match {
+ //case tree: SymTree => System.err.println("TREE: " + tree.getClass() + " " + tree.symbol + " " + (new Position(unit.source, tree.pos)).dbgString);
+ case _ =>
+ }
+ if (tree0.pos != Position.NOPOS) tree0 match {
+
+
case tree : ImplDef =>
- list.put(tree.namePos(unit.source), Def(tree));
+ val pos = tree.namePos(unit.source);
+ if (pos == Position.NOPOS) {
+ // inner types.
+ // System.err.println("NOPOS: " + tree.getClass() + " " + (new Position(unit.source, tree.pos)).dbgString);
+ //Thread.dumpStack();
+ } else buildDef(tree.symbol, tree.namePos(unit.source));
tree match {
case cdef : ClassDef => build(cdef.tparams);
case _ => ;
@@ -170,7 +172,7 @@ class SemanticTokens(val compiler: Compiler) {
val pos = if (tree.name0.toString().equals("<init>")) Position.NOPOS else tree.namePos(unit.source);
if (pos != Position.NOPOS) {
if (!tree.hasFlag(Flags.SYNTHETIC))
- list.put(pos, Def(tree));
+ buildDef(tree.symbol, pos);
}
}
@@ -182,17 +184,27 @@ class SemanticTokens(val compiler: Compiler) {
val pos0 = if (!unit.source.beginsWith(arg.pos, "val ")) arg.pos;
else unit.source.skipWhitespace(arg.pos + ("val ").length());
- list.put(pos0, Def(arg));
+ buildDef(arg.symbol, pos0);
build(arg.tpt0);
}
}
- build(tree.tpt0);
+ try {
+ build(tree.tpt0);
+ } catch {
+ case e: Error =>
+ System.err.println("VALDEF: " + tree + " " + tree.tpt0 + " " + tree.pos + " " + tree.tpt0.pos);
+ throw e;
+ }
build(tree.rhs0);
}
case tree : PackageDef =>
- val pos = tree.namePos(unit.source);
- list.put(pos, Def(tree));
- build(tree.stats);
+ //System.err.println("PACKAGE: " + tree.name0);
+ if (false) {
+ val pos = tree.namePos(unit.source);
+ if (pos != Position.NOPOS)
+ buildDef(tree.symbol, pos);
+ }
+ build(tree.stats);
case tree : Function =>
for (val arg <- tree.vparams) if (arg.pos != Position.NOPOS) {
val name = arg.name0.toString().trim();
@@ -203,7 +215,7 @@ class SemanticTokens(val compiler: Compiler) {
while (Character.isWhitespace(unit.source.content(posx - 1))) posx = posx - 1;
posx - name.length();
} else arg.pos;
- list.put(pos, Def(arg));
+ buildDef(arg.symbol, pos);
build(arg.tpt0);
}
build(tree.body);
@@ -213,15 +225,28 @@ class SemanticTokens(val compiler: Compiler) {
def buildT( tree : Tree, tpe : Type) : Unit = if (tree.pos != Position.NOPOS) tpe match {
case tpe0 : TypeRef => tree match {
case apt : AppliedTypeTree =>
- build(apt.tpt);
- //buildSym(tpe0.sym, apt.tpt.pos);
+ buildUse(tpe.symbol, apt.tpt.pos);
+ //System.err.println("APT: " + apt.tpt + " sym0=" + apt.tpt.symbol + " sym1=" + tpe0.sym + " " + " " + apt.args + " " + tpe0.args);
+
buildTs (apt.args, tpe0.args);
- case ident : Ident => buildSym(tpe0.sym, ident.pos);
+ case ident : Ident => buildUse(tpe0.sym, ident.pos);
case select : Select =>
// System.err.println("BUILD_SELECT: " + select + " @ " + tpe0);
- build(select);
+ try {
+ build(select);
+ } catch {
+ case e : Error =>
+ System.err.println("BUILD_SELECT: " + select + " @ " + tpe0 + " " + unit.source.dbg(select.pos));
+ throw e;
+ }
case tpt : TypeTree =>
- // System.err.println("UNKNOWN TPT0: " + tpe0 + " vs. " + tpt);
+ //System.err.println("UNKNOWN TPT0: " + tpe0 + " " + tpe0.args + " " + tpt);
+ case sft : SelectFromTypeTree =>
+ build(sft.qualifier); // XXX: broken
+ if (false) System.err.println("SFTT: " + sft + " sym=" + sft.symbol + " selector=" + sft.selector + " qual=" + sft.qualifier + " qual.sym=" +
+ sft.qualifier.symbol +
+ " qual.pos=" + unit.source.dbg(sft.qualifier.pos) + " symbol=" + sft.symbol + " type=" + tpe0 +
+ " type.sym=" + tpe0.symbol);
case _ => System.err.println("UNKNOWN TPT2: " + tree + " vs. " + tpe0 + " " + tree.getClass() + " " + unit.source.content(tree.pos));
}
case tpe0 : MethodType => tree match {
@@ -241,20 +266,35 @@ class SemanticTokens(val compiler: Compiler) {
buildTs(trees.tail, types.tail);
};
case tree : AbsTypeDef =>
- list.put(tree.namePos, Def(tree));
+ buildDef(tree.symbol, tree.namePos);
case tree : Bind =>
- list.put(tree.pos, Def(tree));
+ buildDef(tree.symbol, tree.pos);
build(tree.body);
- case tree : Ident => buildSym(tree.symbol, tree.pos);
+ case tree : Ident => buildUse(tree.symbol, tree.pos);
case tree : Select =>
// System.err.println("SELECT: " + tree.qualifier + " ** " + tree.symbol + " " + selectPos(tree));
- build(tree.qualifier);
- buildSym(tree.symbol, selectPos(tree));
+ try {
+ build(tree.qualifier);
+ } catch {
+ case e : Error => System.err.println("SELECTQ: " + tree + " " + tree.qualifier + " " + unit.source.dbg(tree.qualifier.pos)); throw e;
+ }
+ try {
+ if (tree.pos >= unit.source.content.length)
+ System.err.println("BAD_SELECT_QUALIFIER " + tree + " @ " + tree.pos);
+ else buildUse(tree.symbol, selectPos(tree));
+ } catch {
+ case e : Error => System.err.println("SELECTU: " + tree + " " + tree.symbol + " " + unit.source.dbg(tree.pos)); throw e;
+ }
case tree : GenericApply =>
- // System.err.println("APPLY: " + tree.fun0 + " " + tree.args0);
- build(tree.fun0); build(tree.args0);
+ //System.err.println("APPLY-FUN: " + tree.fun0 + " " + tree.args0);
+ build(tree.fun0);
+ //System.err.println("APPLY-ARG: " + tree.fun0 + " " + tree.args0);
+ build(tree.args0);
case tree : Typed => build(tree.expr); build(tree.tpt);
- case tree : Import => build(tree.expr);
+ case tree : Import =>
+ //System.err.println("IMPORT: " + tree.expr + " " + tree.selectors);
+
+ build(tree.expr);
case tree : Block => build(tree.stats); build(tree.expr);
case tree : CaseDef =>
build(tree.pat); build(tree.guard); build(tree.body);
@@ -264,6 +304,9 @@ class SemanticTokens(val compiler: Compiler) {
case tree : New => build(tree.tpt);
case tree : Match => build(tree.selector); build(tree.cases);
case tree : Return => build(tree.expr);
+ case tree : LabelDef => build(tree.rhs);
+ case tree : Throw => build(tree.expr);
+ case tree : Try => build(tree.block); build(tree.catches); build(tree.finalizer);
case tree : Literal => ;
case tree : This => ;
case tree : Super => ;
@@ -271,11 +314,17 @@ class SemanticTokens(val compiler: Compiler) {
if (tree0 != EmptyTree)
System.err.println("BAIL: " + tree0.pos + " " + tree0 + " " + tree0.getClass());
}
- def buildSym(term : Symbol, pos : Int) : Unit = {
- val term0 = if (term.hasFlag(Flags.ACCESSOR)) term.accessed; else term;
- val name = NameTransformer.decode(term0.name.toString()).toString().trim();
+ }
+ def buildUse(term : Symbol, pos : Int) = buildSym(term, pos, false);
+ def buildDef(term : Symbol, pos : Int) = buildSym(term, pos, true);
+
+ def buildSym(term : Symbol, pos : Int, isDef : Boolean) : Unit = if (term.hasFlag(Flags.ACCESSOR)) buildSym(term.accessed, pos, isDef)
+ else if (pos == Position.NOPOS) {
+ System.err.println("NOPOS: " + term);
+ Thread.dumpStack();
+ } else if (term != NoSymbol) {
+ val name = NameTransformer.decode(term.name.toString()).toString().trim();
val buf = unit.source.content;
-
val cs = name.toChars;
var idx = 0;
if (cs.length + pos > buf.length) {
@@ -288,10 +337,16 @@ class SemanticTokens(val compiler: Compiler) {
}
else idx = idx + 1;
- list.put(pos, new Use(term0));
+ list.put(pos, (if (isDef) new Def(term) else new Use(term)));
}
def selectPos(tree : Select): Int = if (tree.pos == Position.NOPOS) Position.NOPOS else {
val buf = unit.source.content;
+ if (tree.pos >= buf.length) {
+ System.err.println(""+tree + "@" + tree.pos + " not in " + unit.source.file.getName() + "[" + buf.length + "]");
+ Thread.dumpStack();
+ throw new Error();
+ }
+
val pos =
if (buf(tree.pos) != '.') tree.pos;
else {
@@ -348,9 +403,17 @@ class SemanticTokens(val compiler: Compiler) {
} else if (!cursor.token.isInstanceOf[Gap]) {
val sem = cursor.token.asInstanceOf[Semantic];
if (sem.symbol == tok.symbol) return;
- System.err.println("NOT_GAP: " + sem.symbol + " " + sem.symbol.getClass());
- System.err.println("NOT_GAP: " + tok.symbol + " " + tok.symbol.getClass());
+ if (sem.symbol != tok.symbol &&
+ sem.symbol.getClass() == tok.symbol.getClass() &&
+ sem.symbol.pos == tok.symbol.pos) return;
+
+ System.err.println("NOT_GAP: " + sem.symbol + " " + sem.symbol.getClass() + " " + unit.source.dbg(sem.symbol.pos) + " " + sem.symbol.flags);
+ System.err.println("NOT_GAP: " + tok.symbol + " " + tok.symbol.getClass() + " " + unit.source.dbg(tok.symbol.pos) + " " + tok.symbol.flags);
System.err.println("LIST: " + this);
+ System.err.println("POS: " + unit.source.dbg(offset));
+
+
+ Thread.dumpStack();
throw new Error();
} else {
val gap = cursor.token.asInstanceOf[Gap];
diff --git a/sources/scala/tools/nsc/reporters/StoreReporter.scala b/sources/scala/tools/nsc/reporters/StoreReporter.scala
index c4aa973dab..e4734fcee7 100644
--- a/sources/scala/tools/nsc/reporters/StoreReporter.scala
+++ b/sources/scala/tools/nsc/reporters/StoreReporter.scala
@@ -21,7 +21,9 @@ import java.io.PrintWriter;
*/
class StoreReporter extends Reporter {
- class Info(val pos: Position, val msg: String, val severity: Severity);
+ class Info(val pos: Position, val msg: String, val severity: Severity) {
+ override def toString() = "pos: " + pos + " " + msg + " " + severity;
+ }
val infos = new HashSet[Info];
diff --git a/sources/scala/tools/nsc/symtab/Definitions.scala b/sources/scala/tools/nsc/symtab/Definitions.scala
index 8e64230c53..a5de7158f4 100755
--- a/sources/scala/tools/nsc/symtab/Definitions.scala
+++ b/sources/scala/tools/nsc/symtab/Definitions.scala
@@ -191,8 +191,12 @@ import Flags._;
val result =
if (module) sym.info.nonPrivateMember(fullname.subName(i, j)).suchThat(.hasFlag(MODULE));
else sym.info.nonPrivateMember(fullname.subName(i, j).toTypeName);
- if (result == NoSymbol)
- throw new FatalError((if (module) "object " else "class ") + fullname + " not found.");
+ if (result == NoSymbol) {
+ val msg = (if (module) "object " else "class ") + fullname + " not found.";
+ System.err.println("MSG: " + msg);
+ Thread.dumpStack();
+ throw new FatalError(msg);
+ }
result
}
diff --git a/sources/scala/tools/nsc/symtab/Types.scala b/sources/scala/tools/nsc/symtab/Types.scala
index f4db96025a..355eca2e82 100755
--- a/sources/scala/tools/nsc/symtab/Types.scala
+++ b/sources/scala/tools/nsc/symtab/Types.scala
@@ -2026,6 +2026,8 @@ import Flags._;
/** An exception signalling a malformed type */
class MalformedType(msg: String) extends TypeError(msg) {
def this(pre: Type, tp: String) = this("malformed type: " + pre + "#" + tp);
+ // System.err.println("MALFORMED_TYPE: " + msg);
+ // Thread.dumpStack();
}
/** An exception signalling a malformed closure */
diff --git a/sources/scala/tools/nsc/util/Position.scala b/sources/scala/tools/nsc/util/Position.scala
index 9a16f5390a..bf502cac3b 100755
--- a/sources/scala/tools/nsc/util/Position.scala
+++ b/sources/scala/tools/nsc/util/Position.scala
@@ -51,6 +51,18 @@ class Position( val source : SourceFile, val offset: Int) {
} else 0;
+ def dbgString =
+ if (!hasOffset) "NOP"
+ else if (offset >= source.content.length) "OB-" + offset else {
+ val ret = "offset=" + offset + " line=" + line;
+ var add = "";
+ while (offset + add.length() < source.content.length &&
+ add.length() < 10) add = add + source.content(offset + add.length());
+ ret + " c[0..9]=\"" + add + "\"";
+ }
+
+
+
def lineContent: String = if (hasOffset) source.lineToString(line - FIRSTLINE) else "NO_LINE";
/** Returns a string representation of the encoded position. */
diff --git a/sources/scala/tools/nsc/util/SourceFile.scala b/sources/scala/tools/nsc/util/SourceFile.scala
index 0138f6a48c..0d4354d325 100644
--- a/sources/scala/tools/nsc/util/SourceFile.scala
+++ b/sources/scala/tools/nsc/util/SourceFile.scala
@@ -52,6 +52,9 @@ class SourceFile(_file : AbstractFile, _content : Array[Char]) {
override def toString(): String = file.getName() /* + ":" + content.length */ ;
+ def dbg(offset : Int) = (new Position(this, offset)).dbgString;
+
+
object line {
var index = 0;
var offset = 0;