diff options
author | Sean McDirmid <sean.mcdirmid@gmail.com> | 2006-01-22 20:38:08 +0000 |
---|---|---|
committer | Sean McDirmid <sean.mcdirmid@gmail.com> | 2006-01-22 20:38:08 +0000 |
commit | 9007f0b447640219b942d2fab29a0cd22c7b5b26 (patch) | |
tree | 7c8efe456c4e1164f732a422a4b8561b94c9578c | |
parent | 6dc1abb28a682ea1ad10d1383024f70f7119d318 (diff) | |
download | scala-9007f0b447640219b942d2fab29a0cd22c7b5b26.tar.gz scala-9007f0b447640219b942d2fab29a0cd22c7b5b26.tar.bz2 scala-9007f0b447640219b942d2fab29a0cd22c7b5b26.zip |
* removed tabs from core compiler files.
* improved coverage of semantic tokens class
* enhanced classpath stability
-rw-r--r-- | src/compiler/scala/tools/nsc/Global.scala | 51 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/models/SemanticTokens.scala | 212 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Symbols.scala | 30 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 73 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/util/ClassPath.scala | 21 |
5 files changed, 204 insertions, 183 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index cafe682170..53b86da085 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -15,6 +15,9 @@ import scala.tools.nsc.reporters._; import scala.collection.mutable.{HashSet,HashMap,ListBuffer} + + + import symtab._; import symtab.classfile.{PickleBuffer, Pickler}; import util.Statistics; @@ -377,24 +380,24 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable val startTime = System.currentTimeMillis(); reporter.reset; for (val source <- sources) - addUnit(new CompilationUnit(source)); + addUnit(new CompilationUnit(source)); globalPhase = firstPhase; while (globalPhase != terminalPhase && reporter.errors == 0) { - val startTime = System.currentTimeMillis(); - phase = globalPhase; - globalPhase.run; - if (settings.print contains globalPhase.name) treePrinter.printAll(); - if (settings.browse contains globalPhase.name) treeBrowser.browse(units); - informTime(globalPhase.description, startTime); - globalPhase = globalPhase.next; - if (settings.check contains globalPhase.name) { + val startTime = System.currentTimeMillis(); + phase = globalPhase; + globalPhase.run; + if (settings.print contains globalPhase.name) treePrinter.printAll(); + if (settings.browse contains globalPhase.name) treeBrowser.browse(units); + informTime(globalPhase.description, startTime); + globalPhase = globalPhase.next; + if (settings.check contains globalPhase.name) { phase = globalPhase; if (globalPhase.name == "jvm") icodeChecker.checkICodes; else checker.checkTrees; - } - if (settings.statistics.value) statistics.print(phase); - advancePhase; + } + if (settings.statistics.value) statistics.print(phase); + advancePhase; } if (settings.Xshowcls.value != "") showDef(newTermName(settings.Xshowcls.value), false); @@ -404,10 +407,10 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable if (reporter.errors == 0) { assert(symData.isEmpty, symData.elements.toList); } else { - for (val Pair(sym, file) <- symSource.elements) { - sym.reset(new loaders.SourcefileLoader(file)); - if (sym.isTerm) sym.moduleClass.reset(loaders.moduleClassLoader); - } + for (val Pair(sym, file) <- symSource.elements) { + sym.reset(new loaders.SourcefileLoader(file)); + if (sym.isTerm) sym.moduleClass.reset(loaders.moduleClassLoader); + } } for (val Pair(sym, file) <- symSource.elements) resetPackageClass(sym.owner); informTime("total", startTime); @@ -424,31 +427,31 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable addUnit(unit); var localPhase = firstPhase.asInstanceOf[GlobalPhase]; while ((localPhase.id < globalPhase.id || localPhase.id <= namerPhase.id) && - reporter.errors == 0) { + reporter.errors == 0) { atPhase(localPhase)(localPhase.applyPhase(unit)); localPhase = localPhase.next.asInstanceOf[GlobalPhase]; - } - refreshProgress; + } + refreshProgress; } def compileFiles(files: List[AbstractFile]): unit = try { - compileSources(files map getSourceFile) + compileSources(files map getSourceFile) } catch { - case ex: IOException => error(ex.getMessage()); + case ex: IOException => error(ex.getMessage()); } def compile(filenames: List[String]): unit = try { - compileSources(filenames map getSourceFile) + compileSources(filenames map getSourceFile) } catch { - case ex: IOException => error(ex.getMessage()); + case ex: IOException => error(ex.getMessage()); } private def resetPackageClass(pclazz: Symbol): unit = { assert(pclazz.isPackageClass, pclazz); atPhase(firstPhase) { - pclazz.setInfo(atPhase(typerPhase)(pclazz.info)) + pclazz.setInfo(atPhase(typerPhase)(pclazz.info)) } if (!pclazz.isRoot) resetPackageClass(pclazz.owner); } diff --git a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala index 42d802929e..0f0c5c1824 100644 --- a/src/compiler/scala/tools/nsc/models/SemanticTokens.scala +++ b/src/compiler/scala/tools/nsc/models/SemanticTokens.scala @@ -1,13 +1,13 @@ package scala.tools.nsc.models; -import scala.tools.nsc.{Global => Compiler}; +import scala.tools.nsc.Global; import scala.tools.nsc.symtab.{Flags,Names}; import scala.tools.nsc.util.{NameTransformer,Position,SourceFile}; import scala.collection.mutable.{HashMap,HashSet}; -class SemanticTokens(val compiler: Compiler) { +class SemanticTokens(val compiler: Global) { import compiler._; abstract class Kind {} @@ -23,49 +23,51 @@ class SemanticTokens(val compiler: Compiler) { abstract class Token { def length : Int; - def prev : HasNext; def next : HasPrev; + } [_trait_] abstract class HasNext extends Token { var next0 : HasPrev = _; def next = next0; + } [_trait_] abstract class HasPrev extends Token { var prev0 : HasNext = _; def prev = prev0; } abstract class Actual extends HasNext with HasPrev { - def convertToGap : Pair[Int,Actual] = { + def convertToGap : Pair[Int,Actual] = { val nextGap = next.isInstanceOf[Gap]; val prevGap = prev.isInstanceOf[Gap]; if (prevGap) { - val ret = prev.length; - val gap = prev.asInstanceOf[Gap]; - gap.setLength(gap.length + length); - if (nextGap) { - gap.setLength(gap.length + next.length); - gap.next0 = next.next; - next.next.prev0 = gap; - } else { - gap.next0 = next; - next.prev0 = gap; - } - new Pair(ret,gap); + val ret = prev.length; + val gap = prev.asInstanceOf[Gap]; + gap.setLength(gap.length + length); + if (nextGap) { + gap.setLength(gap.length + next.length); + gap.next0 = next.next; + next.next.prev0 = gap; + } else { + gap.next0 = next; + next.prev0 = gap; + } + new Pair(ret,gap); } else if (nextGap) { - val gap = next.asInstanceOf[Gap]; - gap.setLength(gap.length + length); - gap.prev0 = prev; - prev.next0 = gap; - new Pair(0,gap); + val gap = next.asInstanceOf[Gap]; + gap.setLength(gap.length + length); + gap.prev0 = prev; + prev.next0 = gap; + new Pair(0,gap); } else { - prev.next0 = next; - next.prev0 = prev; - val gap = new Gap(prev); - gap.setLength(length); - new Pair(0,gap); + prev.next0 = next; + next.prev0 = prev; + val gap = new Gap(prev); + gap.setLength(length); + new Pair(0,gap); } + } def insert(prev1 : HasNext) = { next0 = prev1.next; @@ -82,7 +84,7 @@ class SemanticTokens(val compiler: Compiler) { override def toString() = "gap-" + length; var length0 : Int = -1; - def length : Int = length0; + def length : Int = length0; def setLength(length1 : Int) = length0 = length1; // already gap @@ -92,12 +94,14 @@ class SemanticTokens(val compiler: Compiler) { class Process(val unit : CompilationUnit) { def source = unit.source; + + def dbg(tree : Tree) = {( - "TREE=" + tree + - (if (tree != null) (" CLASS=" + tree.getClass()) else "") + - " SYM=" + tree.symbol + - " POS=" + - (new Position(source, if (tree != null) tree.pos else -1)).dbgString + "TREE=" + tree + + (if (tree != null) (" CLASS=" + tree.getClass()) else "") + + " SYM=" + tree.symbol + + " POS=" + + (new Position(source, if (tree != null) tree.pos else -1)).dbgString )} val symbols = new HashMap[Symbol,Info]; @@ -120,10 +124,10 @@ class SemanticTokens(val compiler: Compiler) { def info : Info = if (symbols.contains(symbol)) symbols(symbol) else new Info(symbol); def kind = { - val term0 = symbol; - if (false) null; - else if (term0.isVariable) VAR; - else if (term0.isValueParameter) ARG; + val term0 = symbol; + if (false) null; + else if (term0.isVariable) VAR; + else if (term0.isValueParameter) ARG; else if (term0.isMethod) DEF; else if (term0.isClass) CLASS; else if (term0.isModule) OBJECT; @@ -154,17 +158,17 @@ class SemanticTokens(val compiler: Compiler) { def build(tree0 : Tree) : Unit = { if (tree0.pos != Position.NOPOS) tree0 match { - case tree : ImplDef => - 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 _ => ; - } + case tree : ImplDef => + 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 _ => ; + } build(tree.impl.parents); build(tree.impl.body); case tree : ValOrDefDef => if (!tree.symbol.hasFlag(Flags.ACCESSOR)) { @@ -172,7 +176,7 @@ class SemanticTokens(val compiler: Compiler) { val pos = if (tree.name.toString().equals("<init>")) Position.NOPOS else tree.namePos(unit.source); if (pos != Position.NOPOS) { if (!tree.hasFlag(Flags.SYNTHETIC)) - buildDef(tree.symbol, pos); + buildDef(tree.symbol, pos); } } @@ -267,9 +271,12 @@ class SemanticTokens(val compiler: Compiler) { } case tpe0 : ThisType => tree match { - case stt : SingletonTypeTree => stt.ref match { - case ths : This => build(ths); - } + case stt : SingletonTypeTree => stt.ref match { + case ths : This => build(ths); + case _ => System.err.println("UNKNOWN TPE11: " + tpe0 + " " + stt + " " + stt.ref + " " + stt.ref.getClass() + " " + unit.source.dbg(tree.pos)); + } + case tt : TypeTree => /* ignore */ + case _ => System.err.println("UNKNOWN TPE10: " + tpe0 + " " + tree + " " + tree.getClass() + " " + unit.source.dbg(tree.pos)); } case tpe0 : SingleType => { @@ -298,7 +305,7 @@ class SemanticTokens(val compiler: Compiler) { } try { if (tree.pos >= unit.source.content.length) - System.err.println("BAD_SELECT_QUALIFIER " + tree + " @ " + tree.pos); + System.err.println("BAD_SELECT_QUALIFIER " + tree + " @ " + unit.source.dbg(tree.pos)); else { buildUse(tree.symbol, selectPos(tree), tree.tpe); } @@ -331,9 +338,10 @@ class SemanticTokens(val compiler: Compiler) { case tree : AppliedTypeTree => ; case tree : SingletonTypeTree => ; case tree : Attributed => ; + case tree : AliasTypeDef => build(tree.rhs); build(tree.tparams); buildDef(tree.symbol, tree.pos); case EmptyTree => ; case _ => ; - System.err.println("BAIL: " + tree0.pos + " " + tree0 + " " + tree0.getClass()); + System.err.println("BAIL: " + unit.source.dbg(tree0.pos) + " " + tree0 + " " + tree0.getClass()); } } @@ -481,56 +489,56 @@ class SemanticTokens(val compiler: Compiler) { } str; }; - object cursor { - var token : Token = end; - var offset : Int = 0; - - def next : Unit = if (token == end) end else { - offset = offset + token.length; - token = token.next; - } - def prev : Unit = if (token.prev == begin) token else { - offset = offset - token.prev.length; - token = token.prev; - } - def seek(soffset : Int) : Unit = if (soffset == 0) { - token = begin.next; - offset = 0; - } else { - assert(soffset > 0); - while (offset > soffset) prev; - while (offset + token.length <= soffset && token != end) { - val len0 = offset; - next; - } - } - def convertToGap = if (token.isInstanceOf[Actual]) { - val ret = token.asInstanceOf[Actual].convertToGap; - offset = offset - ret._1; - token = ret._2; - } + object cursor { + var token : Token = end; + var offset : Int = 0; + + def next : Unit = if (token == end) end else { + offset = offset + token.length; + token = token.next; + } + def prev : Unit = if (token.prev == begin) token else { + offset = offset - token.prev.length; + token = token.prev; + } + def seek(soffset : Int) : Unit = if (soffset == 0) { + token = begin.next; + offset = 0; + } else { + assert(soffset > 0); + while (offset > soffset) prev; + while (offset + token.length <= soffset && token != end) { + val len0 = offset; + next; + } + } + def convertToGap = if (token.isInstanceOf[Actual]) { + val ret = token.asInstanceOf[Actual].convertToGap; + offset = offset - ret._1; + token = ret._2; + } + } + // add or delete characters + def adjust(offset: Int, /* where */ + length: Int, /* how many characters are modified */ + to : Int /* length of new string */) = { + cursor.seek(offset); + if (cursor.token != end) { + cursor.convertToGap; + while (cursor.offset + cursor.token.length < offset + length && cursor.token.next != end) { + val save = cursor.offset; + cursor.next; + cursor.convertToGap; + assert(cursor.offset == save); + } + if (length != to && cursor.token != end) { + val diff = to - length; + val gap = cursor.token.asInstanceOf[Gap]; + gap.setLength(gap.length + diff); + }; } - // add or delete characters - def adjust(offset: Int, /* where */ - length: Int, /* how many characters are modified */ - to : Int /* length of new string */) = { - cursor.seek(offset); - if (cursor.token != end) { - cursor.convertToGap; - while (cursor.offset + cursor.token.length < offset + length && cursor.token.next != end) { - val save = cursor.offset; - cursor.next; - cursor.convertToGap; - assert(cursor.offset == save); - } - if (length != to && cursor.token != end) { - val diff = to - length; - val gap = cursor.token.asInstanceOf[Gap]; - gap.setLength(gap.length + diff); - }; - } - } - }; + } + }; } } diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 2965cb7f8b..c73689ac98 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -19,6 +19,7 @@ mixin class Symbols requires SymbolTable { var typeSymbolCount = 0; var classSymbolCount = 0; + type AttrInfo = Pair[Type, List[Constant]]; val emptySymbolArray = new Array[Symbol](0); @@ -42,16 +43,27 @@ mixin class Symbols requires SymbolTable { if (pos == Position.NOPOS) Position.NOPOS; else if (isTypeParameter) pos - name.length; else if (isVariable || isMethod || isClass || isModule) { - var ret = pos; - - if (buf(pos) == ',') ret = ret + 1; - else if (isClass) ret = ret + ("class").length(); - else if (isModule) ret = ret + ("object").length(); - else ret = ret + ("var").length(); - while (Character.isWhitespace(buf(ret))) ret = ret + 1; - ret; + var ret = pos; + if (buf(pos) == ',') ret = ret + 1; + else if (isClass) ret = ret + ("class").length(); + else if (isModule) ret = ret + ("object").length(); + else ret = ret + ("var").length(); + while (Character.isWhitespace(buf(ret))) ret = ret + 1; + ret; + } + else if (isValue) { + if (pos < (buf.length + ("val ").length())) { + if ((buf(pos + 0) == 'v') && + (buf(pos + 1) == 'a') && + (buf(pos + 2) == 'l') && + (buf(pos + 3) == ' ')) { + var pos0 = pos + 4; + while (pos0 < buf.length && Character.isWhitespace(pos0)) pos0 = pos0 + 1; + pos0; + + } else pos; + } else pos; } - else if (isValue) pos; else -1; } diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index cfea971284..1850d2dc29 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -22,20 +22,20 @@ trait Namers requires Analyzer { class DeSkolemizeMap(tparams: List[Symbol]) extends TypeMap { def apply(tp: Type): Type = tp match { case TypeRef(pre, sym, args) => - val tparam = sym.deSkolemize; - mapOver( - if (tparam == sym || !(tparams contains tparam)) tp - else rawTypeRef(NoPrefix, tparam, args)) + val tparam = sym.deSkolemize; + mapOver( + if (tparam == sym || !(tparams contains tparam)) tp + else rawTypeRef(NoPrefix, tparam, args)) case SingleType(pre, sym) if (sym.isThisSkolem) => ThisType(sym.deSkolemize) case PolyType(tparams1, restpe) => - new DeSkolemizeMap(tparams1 ::: tparams).mapOver(tp) + new DeSkolemizeMap(tparams1 ::: tparams).mapOver(tp) case ClassInfoType(parents, decls, clazz) => - val parents1 = List.mapConserve(parents)(this); - if (parents1 eq parents) tp else ClassInfoType(parents1, decls, clazz); + val parents1 = List.mapConserve(parents)(this); + if (parents1 eq parents) tp else ClassInfoType(parents1, decls, clazz); case _ => - mapOver(tp) - } + mapOver(tp) + } } class Namer(val context: Context) { @@ -83,17 +83,17 @@ trait Namers requires Analyzer { def enterInScope(sym: Symbol): Symbol = { if (!(sym.isSourceMethod && sym.owner.isClass)) { - val prev = context.scope.lookupEntry(sym.name); - if (prev != null && prev.owner == context.scope && !prev.sym.isSourceMethod) { - if (sym.sourceFile == null && prev.sym.sourceFile == null) {} - else if (sym.sourceFile != null && prev.sym.sourceFile != null && - sym.sourceFile.equals(prev.sym.sourceFile)) {} - else { - System.err.println("SYM: " + sym.sourceFile); - System.err.println("PRV: " + prev.sym.sourceFile); - doubleDefError(sym.pos, prev.sym); - } - } + val prev = context.scope.lookupEntry(sym.name); + if (prev != null && prev.owner == context.scope && !prev.sym.isSourceMethod) { + if (sym.sourceFile == null && prev.sym.sourceFile == null) {} + else if (sym.sourceFile != null && prev.sym.sourceFile != null && + sym.sourceFile.equals(prev.sym.sourceFile)) {} + else { + System.err.println("SYM: " + sym.sourceFile); + System.err.println("PRV: " + prev.sym.sourceFile); + doubleDefError(sym.pos, prev.sym); + } + } } context.scope enter sym; sym @@ -123,21 +123,20 @@ trait Namers requires Analyzer { if (c.isType && !currentRun.compiles(c) && context.scope == c.owner.info.decls) { updatePosFlags(c, pos, flags); } else { - c = enterInScope(context.owner.newClass(pos, name)).setFlag(flags | inConstructorFlag); + c = enterInScope(context.owner.newClass(pos, name)).setFlag(flags | inConstructorFlag); } if (c.owner.isPackageClass) { - val file = context.unit.source.getFile(); - val clazz = c.asInstanceOf[ClassSymbol]; - if (file != null) { - if (clazz.sourceFile != null && !clazz.sourceFile.equals(file)) // double def. - throw new Error(""+clazz.sourceFile + " vs. " + file + " SYM=" + c); - else clazz.sourceFile = file; - - } - if (clazz.sourceFile != null) { - assert(!currentRun.compiles(clazz) || clazz.sourceFile == currentRun.symSource(c)); - currentRun.symSource(c) = clazz.sourceFile - } + val file = context.unit.source.getFile(); + val clazz = c.asInstanceOf[ClassSymbol]; + if (file != null) { + if (clazz.sourceFile != null && !clazz.sourceFile.equals(file)) { + System.err.println("SOURCE MISMATCH: " + clazz.sourceFile + " vs. " + file + " SYM=" + c); + } else clazz.sourceFile = file; + } + if (clazz.sourceFile != null) { + assert(!currentRun.compiles(clazz) || clazz.sourceFile == currentRun.symSource(c)); + currentRun.symSource(c) = clazz.sourceFile + } } c } @@ -220,10 +219,10 @@ trait Namers requires Analyzer { case ClassDef(mods, name, tparams, _, impl) => if ((mods.flags & (CASE | ABSTRACT)) == CASE) { // enter case factory method. tree.symbol = enterCaseFactorySymbol( - tree.pos, mods.flags & AccessFlags | METHOD | CASE, name.toTermName) - .setInfo(innerNamer.caseFactoryCompleter(tree)); - setPrivateWithin(tree.symbol, mods); - } + tree.pos, mods.flags & AccessFlags | METHOD | CASE, name.toTermName) + .setInfo(innerNamer.caseFactoryCompleter(tree)); + setPrivateWithin(tree.symbol, mods); + } tree.symbol = enterClassSymbol(tree.pos, mods.flags, name); setPrivateWithin(tree.symbol, mods); finishWith(tparams); diff --git a/src/compiler/scala/tools/nsc/util/ClassPath.scala b/src/compiler/scala/tools/nsc/util/ClassPath.scala index a4acfae9cb..d24c4b1348 100644 --- a/src/compiler/scala/tools/nsc/util/ClassPath.scala +++ b/src/compiler/scala/tools/nsc/util/ClassPath.scala @@ -186,19 +186,18 @@ object ClassPath { private def addArchivesInExtDirPath(path: String) = { val strtok = new StringTokenizer(path, File.pathSeparator); while (strtok.hasMoreTokens()) { - val file = AbstractFile.getDirectory(strtok.nextToken()); - val files = (if (file != null) file.list() else null); - if (files != null) while(files.hasNext()) { - val file0 = files.next().asInstanceOf[AbstractFile]; - val name = file0.getName(); - if (name.endsWith(".jar") || name.endsWith(".zip")) { - val archive = AbstractFile.getDirectory(new File(file.getFile(), name)); - if (archive != null) entries += (new Library(archive)); - } - } + val file = AbstractFile.getDirectory(strtok.nextToken()); + val files = (if (file != null) file.list() else null); + if (files != null) while(files.hasNext()) { + val file0 = files.next().asInstanceOf[AbstractFile]; + val name = file0.getName(); + if (name.endsWith(".jar") || name.endsWith(".zip")) { + val archive = AbstractFile.getDirectory(new File(file.getFile(), name)); + if (archive != null) entries += (new Library(archive)); + } + } } } - } // class Build } |