diff options
author | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2005-12-19 13:49:03 +0000 |
---|---|---|
committer | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2005-12-19 13:49:03 +0000 |
commit | ac849228490d5a0e2d3f048d649297d5c59b6ade (patch) | |
tree | 6314f2c06f37e67dec5827c3f94e25cf844a085c /src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala | |
parent | d6c0efe5b4b89a0337f1cdcdabf8c607d81f4ae1 (diff) | |
download | scala-ac849228490d5a0e2d3f048d649297d5c59b6ade.tar.gz scala-ac849228490d5a0e2d3f048d649297d5c59b6ade.tar.bz2 scala-ac849228490d5a0e2d3f048d649297d5c59b6ade.zip |
Switching to the new build system and to the ne...
Switching to the new build system and to the new build system. This is a
MAJOR commit, so be careful when updating.
Diffstat (limited to 'src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala b/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala new file mode 100644 index 0000000000..6676c820bc --- /dev/null +++ b/src/compiler/scala/tools/nsc/backend/WorklistAlgorithm.scala @@ -0,0 +1,50 @@ +/* NSC -- new scala compiler + * Copyright 2005 LAMP/EPFL + * @author Martin Odersky + */ + +// $Id$ + +package scala.tools.nsc.backend; + +import scala.tools.nsc.ast._; +import scala.collection.mutable.MutableList; + +/** + * Simple implementation of a worklist algorithm. A processing + * function is applied repeatedly to the first element in the + * worklist, as long as the stack is not empty. + * + * The client class should mix-in this trait and initialize the + * worklist field and define the processElement method. Then call + * the 'run' method providing a function that initializes the + * worklist. + * + * @see scala.tools.nsc.backend.icode.Linearizers + */ +trait WorklistAlgorithm { + type Elem; + type WList <: MutableList[Elem]; + + val worklist: WList; + + /** + * Run the iterative algorithm until the worklist + * remains empty. The initializer is run once before + * the loop starts and should initialize the worklist. + */ + def run(initWorklist: => Unit) = { + initWorklist; + + while (!(worklist.length == 0)) + processElement(dequeue); + } + + /** + * Process the current element from the worklist. + */ + def processElement(e: Elem): Unit; + + /** Remove and return the first element to be processed from the worklist. */ + def dequeue: Elem; +} |