Skip to content

Commit 8b5e00b

Browse files
committed
Implement Iterable for ast.Node instead of a hand-crafted Traversable
1 parent 4e9b964 commit 8b5e00b

2 files changed

Lines changed: 12 additions & 60 deletions

File tree

src/main/scala/viper/silver/ast/Ast.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package viper.silver.ast
88

9+
import scala.collection.mutable
910
import scala.reflect.ClassTag
1011
import pretty.FastPrettyPrinter
1112
import utility._
@@ -48,7 +49,7 @@ Some design choices:
4849
* Note that all but Program are transitive subtypes of `Node` via `Hashable`. The reason is
4950
* that AST node hashes may depend on the entire program, not just their sub-AST.
5051
*/
51-
trait Node extends Traversable[Node] with Rewritable {
52+
trait Node extends Iterable[Node] with Rewritable {
5253

5354
/** @see [[Nodes.subnodes()]] */
5455
def subnodes = Nodes.subnodes(this)
@@ -61,8 +62,18 @@ trait Node extends Traversable[Node] with Rewritable {
6162
Visitor.reduceWithContext(this, Nodes.subnodes)(context, enter, combine)
6263
}
6364

65+
/** Apply the given function to the AST node and all its subnodes. */
6466
override def foreach[A](f: Node => A) = Visitor.visit(this, Nodes.subnodes) { case a: Node => f(a) }
6567

68+
/** Builds a new collection with all the AST nodes and returns an iterator over it. */
69+
def iterator: Iterator[Node] = {
70+
val elements = mutable.Queue.empty[Node]
71+
for (x <- this) {
72+
elements.append(x)
73+
}
74+
elements.iterator
75+
}
76+
6677
/** @see [[Visitor.visit()]] */
6778
def visit[A](f: PartialFunction[Node, A]): Unit = {
6879
Visitor.visit(this, Nodes.subnodes)(f)

src/main/scala/viper/silver/ast/utility/Traversable.scala

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)