diff options
author | Simon Ochsenreither <simon@ochsenreither.de> | 2013-06-19 03:37:49 +0200 |
---|---|---|
committer | Simon Ochsenreither <simon@ochsenreither.de> | 2013-06-19 16:54:56 +0200 |
commit | f94d86ed9e27c57c5996dbb022b350d32fa6698f (patch) | |
tree | b53e79f04f9466a589098d6fbf85f57315e7d4f3 /src/compiler | |
parent | 70a93f52c3efafe604d6547b335cc361deff4f29 (diff) | |
download | scala-f94d86ed9e27c57c5996dbb022b350d32fa6698f.tar.gz scala-f94d86ed9e27c57c5996dbb022b350d32fa6698f.tar.bz2 scala-f94d86ed9e27c57c5996dbb022b350d32fa6698f.zip |
SI-7592 Replace s.t.n.u.TreeSet with s.c.m.TreeSet
This means
- migrating usages from the compiler-specific implementation to the
one in the standard library
- removing the now unused compiler-specific implementation
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/Constructors.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/LambdaLift.scala | 34 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/util/TreeSet.scala | 64 |
3 files changed, 20 insertions, 84 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala index 75fb043070..7dfa7cdf8d 100644 --- a/src/compiler/scala/tools/nsc/transform/Constructors.scala +++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala @@ -9,7 +9,6 @@ package transform import scala.collection.{ mutable, immutable } import scala.collection.mutable.ListBuffer import symtab.Flags._ -import util.TreeSet /** This phase converts classes with parameters into Java-like classes with * fields, which are assigned to from constructors. @@ -239,7 +238,8 @@ abstract class Constructors extends Transform with ast.TreeDSL { // ----------- avoid making parameter-accessor fields for symbols accessed only within the primary constructor -------------- // A sorted set of symbols that are known to be accessed outside the primary constructor. - val accessedSyms = new TreeSet[Symbol]((x, y) => x isLess y) + val ord = Ordering.fromLessThan[Symbol](_ isLess _) + val accessedSyms = mutable.TreeSet.empty[Symbol](ord) // a list of outer accessor symbols and their bodies var outerAccessors: List[(Symbol, Tree)] = List() @@ -271,7 +271,7 @@ abstract class Constructors extends Transform with ast.TreeDSL { case Select(_, _) => if (!mustbeKept(tree.symbol)) { debuglog("accessedSyms += " + tree.symbol.fullName) - accessedSyms addEntry tree.symbol + accessedSyms += tree.symbol } super.traverse(tree) case _ => diff --git a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala index 7888198531..ce495ca8ca 100644 --- a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala +++ b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala @@ -8,9 +8,8 @@ package transform import symtab._ import Flags._ -import util.TreeSet import scala.collection.{ mutable, immutable } -import scala.collection.mutable.{ LinkedHashMap, LinkedHashSet } +import scala.collection.mutable.{ LinkedHashMap, LinkedHashSet, TreeSet } abstract class LambdaLift extends InfoTransform { import global._ @@ -56,6 +55,8 @@ abstract class LambdaLift extends InfoTransform { class LambdaLifter(unit: CompilationUnit) extends explicitOuter.OuterPathTransformer(unit) { + private type SymSet = TreeSet[Symbol] + /** A map storing free variables of functions and classes */ private val free = new LinkedHashMap[Symbol, SymSet] @@ -68,6 +69,12 @@ abstract class LambdaLift extends InfoTransform { /** Symbols that are called from an inner class. */ private val calledFromInner = new LinkedHashSet[Symbol] + private val ord = Ordering.fromLessThan[Symbol](_ isLess _) + private def newSymSet = TreeSet.empty[Symbol](ord) + + private def symSet(f: LinkedHashMap[Symbol, SymSet], sym: Symbol): SymSet = + f.getOrElseUpdate(sym, newSymSet) + /** The set of symbols that need to be renamed. */ private val renamable = newSymSet @@ -107,13 +114,6 @@ abstract class LambdaLift extends InfoTransform { /** Buffers for lifted out classes and methods */ private val liftedDefs = new LinkedHashMap[Symbol, List[Tree]] - private type SymSet = TreeSet[Symbol] - - private def newSymSet = new TreeSet[Symbol](_ isLess _) - - private def symSet(f: LinkedHashMap[Symbol, SymSet], sym: Symbol): SymSet = - f.getOrElseUpdate(sym, newSymSet) - private def isSameOwnerEnclosure(sym: Symbol) = sym.owner.logicallyEnclosingMember == currentOwner.logicallyEnclosingMember @@ -155,8 +155,8 @@ abstract class LambdaLift extends InfoTransform { else { val ss = symSet(free, enclosure) if (!ss(sym)) { - ss addEntry sym - renamable addEntry sym + ss += sym + renamable += sym changedFreeVars = true debuglog("" + sym + " is free in " + enclosure) if (sym.isVariable) sym setFlag CAPTURED @@ -168,7 +168,7 @@ abstract class LambdaLift extends InfoTransform { private def markCalled(sym: Symbol, owner: Symbol) { debuglog("mark called: " + sym + " of " + sym.owner + " is called by " + owner) - symSet(called, owner) addEntry sym + symSet(called, owner) += sym if (sym.enclClass != owner.enclClass) calledFromInner += sym } @@ -195,17 +195,17 @@ abstract class LambdaLift extends InfoTransform { if (sym.isImplClass) localImplClasses((sym.owner, tpnme.interfaceName(sym.name))) = sym else { - renamable addEntry sym + renamable += sym if (sym.isTrait) localTraits((sym, sym.name)) = sym.owner } } case DefDef(_, _, _, _, _, _) => if (sym.isLocal) { - renamable addEntry sym + renamable += sym sym setFlag (PrivateLocal | FINAL) } else if (sym.isPrimaryConstructor) { - symSet(called, sym) addEntry sym.owner + symSet(called, sym) += sym.owner } case Ident(name) => if (sym == NoSymbol) { @@ -214,7 +214,7 @@ abstract class LambdaLift extends InfoTransform { val owner = currentOwner.logicallyEnclosingMember if (sym.isTerm && !sym.isMethod) markFree(sym, owner) else if (sym.isMethod) markCalled(sym, owner) - //symSet(called, owner) addEntry sym + //symSet(called, owner) += sym } case Select(_, _) => if (sym.isConstructor && sym.owner.isLocal) @@ -224,7 +224,7 @@ abstract class LambdaLift extends InfoTransform { super.traverse(tree) } catch {//debug case ex: Throwable => - Console.println("exception when traversing " + tree) + Console.println(s"$ex while traversing $tree") throw ex } } diff --git a/src/compiler/scala/tools/nsc/util/TreeSet.scala b/src/compiler/scala/tools/nsc/util/TreeSet.scala deleted file mode 100644 index d2e9238e8f..0000000000 --- a/src/compiler/scala/tools/nsc/util/TreeSet.scala +++ /dev/null @@ -1,64 +0,0 @@ -/* NSC -- new Scala compiler - * Copyright 2005-2013 LAMP/EPFL - * @author Martin Odersky - */ - -package scala.tools.nsc -package util - -/** Sets implemented as binary trees. - * - * @author Martin Odersky - * @version 1.0 - */ -class TreeSet[T >: Null <: AnyRef](less: (T, T) => Boolean) extends Set[T] { - - private class Tree(val elem: T) { - var l: Tree = null - var r: Tree = null - } - - private var tree: Tree = null - - def findEntry(x: T): T = { - def find(t: Tree): T = { - if (t eq null) null - else if (less(x, t.elem)) find(t.l) - else if (less(t.elem, x)) find(t.r) - else t.elem - } - find(tree) - } - - def addEntry(x: T) { - def add(t: Tree): Tree = { - if (t eq null) new Tree(x) - else if (less(x, t.elem)) { t.l = add(t.l); t } - else if (less(t.elem, x)) { t.r = add(t.r); t } - else t - } - tree = add(tree) - } - - def iterator = toList.iterator - - override def foreach[U](f: T => U) { - def loop(t: Tree) { - if (t ne null) { - loop(t.l) - f(t.elem) - loop(t.r) - } - } - loop(tree) - } - override def toList = { - val xs = scala.collection.mutable.ListBuffer[T]() - foreach(xs += _) - xs.toList - } - - override def toString(): String = { - if (tree eq null) "<empty>" else "(..." + tree.elem + "...)" - } -} |