aboutsummaryrefslogtreecommitdiffstats
path: root/Iterator
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2013-04-23 17:40:04 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2013-04-23 17:40:04 +0200
commit59c0d3bcef0d198d069ee980fa73384d814c1bd8 (patch)
tree599bd2da9ecda3fe2773ea983530794c793c87c3 /Iterator
parent2af5ad6a1369e1c6c810dab998b1eab1215f2349 (diff)
downloadPraspel-59c0d3bcef0d198d069ee980fa73384d814c1bd8.zip
Praspel-59c0d3bcef0d198d069ee980fa73384d814c1bd8.tar.gz
Praspel-59c0d3bcef0d198d069ee980fa73384d814c1bd8.tar.bz2
Take @throwable into account when iterating.
Diffstat (limited to 'Iterator')
-rw-r--r--Iterator/Coverage/Structural.php128
1 files changed, 79 insertions, 49 deletions
diff --git a/Iterator/Coverage/Structural.php b/Iterator/Coverage/Structural.php
index f3e34f2..67a58b4 100644
--- a/Iterator/Coverage/Structural.php
+++ b/Iterator/Coverage/Structural.php
@@ -34,6 +34,17 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+namespace {
+
+from('Hoa')
+
+/**
+ * \Hoa\Praspel\Iterator\WeakStack
+ */
+-> import('Praspel.Iterator.WeakStack');
+
+}
+
namespace Hoa\Praspel\Iterator\Coverage {
/**
@@ -70,7 +81,7 @@ class Structural implements \Iterator {
protected $_key = -1;
/**
- * Current (with two indexes: requires and ensures, with SplStack
+ * Current (with two indexes: pre and post, with SplStack
* associated).
*
* @var \Hoa\Praspel\Iterator\Coverage\Structural array
@@ -84,6 +95,13 @@ class Structural implements \Iterator {
*/
protected $_up = false;
+ /**
+ * Post-condition clause: ensure or throwable.
+ *
+ * @var \Hoa\Praspel\Iterator\Coverage\Structural string
+ */
+ protected $_post = 'ensures';
+
/**
@@ -136,6 +154,15 @@ class Structural implements \Iterator {
if(true === $this->_up) {
+ if('ensures' === $this->_post) {
+
+ $this->_up = false;
+ $this->_post = 'throwable';
+ $this->_rewindCurrent();
+
+ return $this->current();
+ }
+
unset($this->_current);
$this->_current = null;
@@ -156,14 +183,8 @@ class Structural implements \Iterator {
&& true === $handle->clauseExists('behavior'))
return $this->_next($handle);
- $countRequires = count($this->_current['requires']);
- $countEnsures = count($this->_current['ensures']);
-
- if($countRequires >= $countEnsures)
- $this->_current['requires']->pop();
-
- if($countRequires <= $countEnsures)
- $this->_current['ensures']->pop();
+ $this->_current['pre']->pop();
+ $this->_current['post']->pop();
next($collection);
$handle = current($collection);
@@ -177,16 +198,7 @@ class Structural implements \Iterator {
}
$this->_up = false;
-
- if(true === $handle->clauseExists('requires'))
- $this->_current['requires']->push(
- $handle->getClause('requires')
- );
-
- if(true === $handle->clauseExists('ensures'))
- $this->_current['ensures']->push(
- $handle->getClause('ensures')
- );
+ $this->pushCurrent($handle);
++$this->_key;
@@ -213,16 +225,7 @@ class Structural implements \Iterator {
return $this->next();
}
- if(true === $current->clauseExists('requires'))
- $this->_current['requires']->push(
- $current->getClause('requires')
- );
-
- if(true === $current->clauseExists('ensures'))
- $this->_current['ensures']->push(
- $current->getClause('ensures')
- );
-
+ $this->pushCurrent($current);
++$this->_key;
return $this->current();
@@ -236,36 +239,63 @@ class Structural implements \Iterator {
*/
public function rewind ( ) {
- $iterator = new \SplStack();
- $iterator->setIteratorMode(
+ $this->_up = false;
+ $this->_key = 0;
+
+ unset($this->_stack);
+ $this->_stack = new \SplStack();
+ $this->_stack->push($this->_specification);
+
+ $this->_rewindCurrent();
+
+ return $this->current();
+ }
+
+ /**
+ * Rewind $this->_current.
+ *
+ * @access protected
+ * @return void
+ */
+ protected function _rewindCurrent ( ) {
+
+ $stack = new \Hoa\Praspel\Iterator\WeakStack();
+ $stack->setIteratorMode(
\SplDoublyLinkedList::IT_MODE_LIFO
| \SplDoublyLinkedList::IT_MODE_KEEP
);
-
- $this->_up = false;
- $this->_key = 0;
unset($this->_current);
$this->_current = array(
- 'requires' => $iterator,
- 'ensures' => clone $iterator
+ 'pre' => $stack,
+ 'post' => clone $stack
);
+ $this->pushCurrent($this->_stack->top());
- unset($this->_stack);
- $this->_stack = new \SplStack();
- $this->_stack->push($this->_specification);
- $handle = &$this->_specification;
+ return;
+ }
+
+ /**
+ * Push pre and post clauses in $this->_current.
+ *
+ * @access protected
+ * @param \Hoa\Praspel\Model\Behavior $current Current.
+ * @return void
+ */
+ protected function pushCurrent ( \Hoa\Praspel\Model\Behavior $current ) {
- if(true === $handle->clauseExists('requires'))
- $this->_current['requires']->push(
- $handle->getClause('requires')
- );
+ $pre = null;
+ $post = null;
- if(true === $handle->clauseExists('ensures'))
- $this->_current['ensures']->push(
- $handle->getClause('ensures')
- );
+ if(true === $current->clauseExists('requires'))
+ $pre = $current->getClause('requires');
- return $this->current();
+ if(true === $current->clauseExists($this->_post))
+ $post = $current->getClause($this->_post);
+
+ $this->_current['pre']->push($pre);
+ $this->_current['post']->push($post);
+
+ return;
}
/**