summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-02-28 00:30:21 +0000
committerPaul Phillips <paulp@improving.org>2010-02-28 00:30:21 +0000
commit432e16ce906cb1f03aabe26c0e51674780f44625 (patch)
treea7ef5b095ad3d4cddff9683452e4a3af45a410b5 /src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
parent7476ed45af6cf90f8c0e03f6ed429dcb436baf87 (diff)
downloadscala-432e16ce906cb1f03aabe26c0e51674780f44625.tar.gz
scala-432e16ce906cb1f03aabe26c0e51674780f44625.tar.bz2
scala-432e16ce906cb1f03aabe26c0e51674780f44625.zip
While working on Any.## I ran across some inter...
While working on Any.## I ran across some interesting tests being made in TreeBuilder: val buf = new ListBuffer[(Name, Tree, Position)] [...] if (buf.iterator forall (name !=)) ... This is always true because a Name will never equal a Tuple3. Oh universal equality, will you never tire of toying with us? Given that this bug has existed since r12886 one might reasonably question the necessity of the conditionals falling prey to this, but leaving that for another day, it should at least check what it's trying to check. No review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala')
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala46
1 files changed, 27 insertions, 19 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
index 9a3760b8c6..812ad23078 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala
@@ -64,46 +64,54 @@ abstract class TreeBuilder {
* The variables keep their positions; whereas the pattern is converted to be synthetic
* for all nodes that contain a variable position.
*/
- private object getvarTraverser extends Traverser {
+ class GetVarTraverser extends Traverser {
val buf = new ListBuffer[(Name, Tree, Position)]
- def init: Traverser = { buf.clear; this }
+
def namePos(tree: Tree, name: Name): Position =
- if (!tree.pos.isRange || name.toString.contains('$')) tree.pos.focus
+ if (!tree.pos.isRange || name.containsName(nme.DOLLARraw)) tree.pos.focus
else {
val start = tree.pos.start
val end = start + name.decode.length
r2p(start, start, end)
}
+
override def traverse(tree: Tree): Unit = {
+ def seenName(name: Name) = buf exists (_._1 == name)
+ def add(name: Name, t: Tree) = if (!seenName(name)) buf += ((name, t, namePos(tree, name)))
val bl = buf.length
+
tree match {
- case Bind(name, Typed(tree1, tpt)) =>
- if ((name != nme.WILDCARD) && (buf.iterator forall (name !=))) {
- buf += ((name, if (treeInfo.mayBeTypePat(tpt)) TypeTree() else tpt.duplicate, namePos(tree, name)))
- }
+ case Bind(nme.WILDCARD, _) =>
+ super.traverse(tree)
+
+ case Bind(name, Typed(tree1, tpt)) =>
+ val newTree = if (treeInfo.mayBeTypePat(tpt)) TypeTree() else tpt.duplicate
+ add(name, newTree)
traverse(tree1)
- case Bind(name, tree1) =>
- if ((name != nme.WILDCARD) && (buf.iterator forall (name !=))) {
- // can assume only name range as position, as otherwise might overlap
- // with binds embedded in pattern tree1
- buf += ((name, TypeTree(), namePos(tree, name)))
- //println("found var "+name+" at "+namePos.show) //DEBUG
- }
+
+ case Bind(name, tree1) =>
+ // can assume only name range as position, as otherwise might overlap
+ // with binds embedded in pattern tree1
+ add(name, TypeTree())
traverse(tree1)
+
case _ =>
super.traverse(tree)
}
- if (buf.length > bl) tree setPos tree.pos.makeTransparent
+ if (buf.length > bl)
+ tree setPos tree.pos.makeTransparent
+ }
+ def apply(tree: Tree) = {
+ traverse(tree)
+ buf.toList
}
}
/** Returns list of all pattern variables, possibly with their types,
* without duplicates
*/
- private def getVariables(tree: Tree): List[(Name, Tree, Position)] = {
- getvarTraverser.init.traverse(tree)
- getvarTraverser.buf.toList
- }
+ private def getVariables(tree: Tree): List[(Name, Tree, Position)] =
+ new GetVarTraverser apply tree
private def makeTuple(trees: List[Tree], isType: Boolean): Tree = {
val tupString = "Tuple" + trees.length