aboutsummaryrefslogtreecommitdiffstats
path: root/Model
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2012-11-23 17:35:54 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2012-11-23 17:35:54 +0100
commita2430d429c689656655970f697d8350dd1539527 (patch)
tree00d73d05f3a7686bfcdecb8206a9528d234b34f4 /Model
parent4b5e99f5003b30d98a7c5f74c3d02b33901af136 (diff)
downloadPraspel-a2430d429c689656655970f697d8350dd1539527.zip
Praspel-a2430d429c689656655970f697d8350dd1539527.tar.gz
Praspel-a2430d429c689656655970f697d8350dd1539527.tar.bz2
Welcome to Hoa\Praspel \o/!
Diffstat (limited to 'Model')
-rw-r--r--Model/Behavior.php200
-rw-r--r--Model/Clause.php145
-rw-r--r--Model/Declaration.php230
-rw-r--r--Model/Ensures.php70
-rw-r--r--Model/Forexample.php164
-rw-r--r--Model/Invariant.php70
-rw-r--r--Model/Is.php172
-rw-r--r--Model/Requires.php70
-rw-r--r--Model/Specification.php147
-rw-r--r--Model/Throwable.php104
-rw-r--r--Model/Variable.php409
11 files changed, 1781 insertions, 0 deletions
diff --git a/Model/Behavior.php b/Model/Behavior.php
new file mode 100644
index 0000000..1d59695
--- /dev/null
+++ b/Model/Behavior.php
@@ -0,0 +1,200 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2012, Ivan Enderlin. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace {
+
+from('Hoa')
+
+/**
+ * \Hoa\Praspel\Exception\Model
+ */
+-> import('Praspel.Exception.Model')
+
+/**
+ * \Hoa\Praspel\Model\Clause
+ */
+-> import('Praspel.Model.Clause')
+
+/**
+ * \Hoa\Praspel\Model\Requires
+ */
+-> import('Praspel.Model.Requires')
+
+/**
+ * \Hoa\Praspel\Model\Ensures
+ */
+-> import('Praspel.Model.Ensures')
+
+/**
+ * \Hoa\Praspel\Model\Requires
+ */
+-> import('Praspel.Model.Throwable')
+
+/**
+ * \Hoa\Praspel\Model\Invariant
+ */
+-> import('Praspel.Model.Invariant')
+
+/**
+ * \Hoa\Praspel\Model\Forexample
+ */
+-> import('Praspel.Model.Forexample');
+
+}
+
+namespace Hoa\Praspel\Model {
+
+/**
+ * Class \Hoa\Praspel\Model\Behavior.
+ *
+ * Represent the @behavior clause.
+ *
+ * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
+ * @copyright Copyright © 2007-2012 Ivan Enderlin.
+ * @license New BSD License
+ */
+
+class Behavior extends Clause {
+
+ /**
+ * Name.
+ *
+ * @const string
+ */
+ const NAME = 'behavior';
+
+ /**
+ * Clauses.
+ *
+ * @var \Hoa\Praspel\Model\Behavior array
+ */
+ protected $_clauses = array();
+
+ /**
+ * Identifier (@behavior <identifier> { … }).
+ *
+ * @var \Hoa\Praspel\Model\Behavior string
+ */
+ protected $_identifier = null;
+
+
+
+ /**
+ * Get a specific clause.
+ *
+ * @access public
+ * @param string $clause Clause (without leading arobase).
+ * @return \Hoa\Praspel\Model\Clause
+ * @throw \Hoa\Praspel\Exception\Model
+ */
+ public function getClause ( $clause ) {
+
+ if(isset($this->_clauses[$clause]))
+ return $this->_clauses[$clause];
+
+ $handle = null;
+
+ switch($clause) {
+
+ case 'requires':
+ $handle = new Requires($this);
+ break;
+
+ case 'ensures':
+ $handle = new Ensures($this);
+ break;
+
+ case 'throwable':
+ $handle = new Throwable($this);
+ break;
+
+ case 'invariant':
+ $handle = new Invariant($this);
+ break;
+
+ case 'behavior':
+ $handle = new self($this);
+ break;
+
+ default:
+ throw new \Hoa\Praspel\Exception\Model(
+ 'Clause @%s is unknown or not allowed in %s.',
+ 0, array($clause, $this->getName()));
+ }
+
+ return $this->_clauses[$clause] = $handle;
+ }
+
+ /**
+ * Check if a clause already exists, i.e. has been declared.
+ *
+ * @access public
+ * @param string $clause Clause (without leading arobase).
+ * @return bool
+ */
+ public function clauseExists ( $clause ) {
+
+ return isset($this->_clauses[$clause]);
+ }
+
+ /**
+ * Set identifier.
+ *
+ * @access public
+ * @param string $identifier Identifier.
+ * @return string
+ */
+ public function setIdentifier ( $identifier ) {
+
+ $old = $this->_identifier;
+ $this->_identifier = $identifier;
+
+ return $old;
+ }
+
+ /**
+ * Get identifier.
+ *
+ * @access public
+ * @return string
+ */
+ public function getIdentifier ( ) {
+
+ return $this->_identifier;
+ }
+}
+
+}
diff --git a/Model/Clause.php b/Model/Clause.php
new file mode 100644
index 0000000..0455cab
--- /dev/null
+++ b/Model/Clause.php
@@ -0,0 +1,145 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2012, Ivan Enderlin. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace {
+
+from('Hoa')
+
+/**
+ * \Hoa\Visitor\Element
+ */
+-> import('Visitor.Element');
+
+}
+
+namespace Hoa\Praspel\Model {
+
+/**
+ * Class \Hoa\Praspel\Model\Clause.
+ *
+ * Represent a clause.
+ *
+ * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
+ * @copyright Copyright © 2007-2012 Ivan Enderlin.
+ * @license New BSD License
+ */
+
+abstract class Clause implements \Hoa\Visitor\Element {
+
+ /**
+ * Name.
+ *
+ * @const int
+ */
+ // const NAME = …;
+
+ /**
+ * Parent clause.
+ *
+ * @var \Hoa\Praspel\Model\Clause object
+ */
+ protected $_parent = null;
+
+
+
+ /**
+ * Build a clause.
+ *
+ * @access public
+ * @param \Hoa\Praspel\Model\Clause $parent Parent.
+ * @return void
+ */
+ public function __construct ( Clause $parent ) {
+
+ $this->setParent($parent);
+
+ return;
+ }
+
+ /**
+ * Set parent clause.
+ *
+ * @access protected
+ * @param \Hoa\Praspel\Model\Clause $parent Parent.
+ * @return \Hoa\Praspel\Model\Clause
+ */
+ protected function setParent ( Clause $parent ) {
+
+ $old = $this->_parent;
+ $this->_parent = $parent;
+
+ return $old;
+ }
+
+ /**
+ * Get parent clause.
+ *
+ * @access public
+ * @return \Hoa\Praspel\Model\Clause
+ */
+ public function getParent ( ) {
+
+ return $this->_parent;
+ }
+
+ /**
+ * Get clause name.
+ *
+ * @access public
+ * @return string
+ */
+ public function getName ( ) {
+
+ return static::NAME;
+ }
+
+ /**
+ * Accept a visitor.
+ *
+ * @access public
+ * @param \Hoa\Visitor\Visit $visitor Visitor.
+ * @param mixed &$handle Handle (reference).
+ * @param mixed $eldnah Handle (no reference).
+ * @return mixed
+ */
+ public function accept ( \Hoa\Visitor\Visit $visitor,
+ &$handle = null, $eldnah = null ) {
+
+ return $visitor->visit($this, $handle, $eldnah);
+ }
+}
+
+}
diff --git a/Model/Declaration.php b/Model/Declaration.php
new file mode 100644
index 0000000..a324aa9
--- /dev/null
+++ b/Model/Declaration.php
@@ -0,0 +1,230 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2012, Ivan Enderlin. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace {
+
+from('Hoa')
+
+/**
+ * \Hoa\Praspel\Model\Clause
+ */
+-> import('Praspel.Model.Clause')
+
+/**
+ * \Hoa\Praspel\Model\Variable
+ */
+-> import('Praspel.Model.Variable');
+
+}
+
+namespace Hoa\Praspel\Model {
+
+/**
+ * Class \Hoa\Praspel\Model\Declaration.
+ *
+ * Represent a declaration.
+ *
+ * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
+ * @copyright Copyright © 2007-2012 Ivan Enderlin.
+ * @license New BSD License
+ */
+
+abstract class Declaration
+ extends Clause
+ implements \ArrayAccess,
+ \IteratorAggregate,
+ \Countable {
+
+ /**
+ * Declared variables.
+ *
+ * @var \Hoa\Praspel\Model\Declaration array
+ */
+ protected $_variables = array();
+
+ /**
+ * Predicates.
+ *
+ * @var \Hoa\Praspel\Model\Declaration array
+ */
+ protected $_predicates = array();
+
+
+
+ /**
+ * Check if a variable exists.
+ *
+ * @access public
+ * @param string $offset Variable name.
+ * @return bool
+ */
+ public function offsetExists ( $offset ) {
+
+ return isset($this->_variables[$offset]);
+ }
+
+ /**
+ * Get or create a variable.
+ *
+ * @access public
+ * @param string $offset Variable name.
+ * @return \Hoa\Prasel\Model\Variable
+ */
+ public function offsetGet ( $offset ) {
+
+ if(false === $this->offsetExists($offset))
+ return $this->_variables[$offset] = new Variable($offset, $this);
+
+ return $this->_variables[$offset];
+ }
+
+ /**
+ * Set a value to a variable.
+ *
+ * @access public
+ * @param string $offset Variable name.
+ * @param mixed $value Variable value.
+ * @return mixed
+ */
+ public function offsetSet ( $offset, $value ) {
+
+ $variable = $this->offsetGet($offset);
+ $old = $variable->getValue();
+ $variable->setValue($value);
+
+ return $old;
+ }
+
+ /**
+ * Delete a variable.
+ *
+ * @access public
+ * @param string $offset Variable name.
+ * @return void
+ */
+ public function offsetUnset ( $offset ) {
+
+ unset($this->_variables[$offset]);
+
+ return;
+ }
+
+ /**
+ * Iterator over local variables.
+ *
+ * @access public
+ * @return \ArrayObject
+ */
+ public function getIterator ( ) {
+
+ return new \ArrayObject($this->getLocalVariables());
+ }
+
+ /**
+ * Count number of variables.
+ *
+ * @access public
+ * @return int
+ */
+ public function count ( ) {
+
+ return count($this->_variables);
+ }
+
+ /**
+ * Get local variables.
+ *
+ * @access public
+ * @return array
+ */
+ public function &getLocalVariables ( ) {
+
+ return $this->_variables;
+ }
+
+ /**
+ * Get in-scope variables.
+ *
+ * @access public
+ * @return array
+ */
+ public function getInScopeVariables ( ) {
+
+ $out = array();
+ $clause = $this->getName();
+ $current = $this;
+
+ while(null !== $current = $current->getParent()) {
+
+ if(false === $current->clauseExists($clause))
+ continue;
+
+ $localVariables = &$current->getClause($clause)->getLocalVariables();
+
+ foreach($localVariables as $name => &$variables)
+ $out[$name] = &$variables;
+ }
+
+ return $out;
+ }
+
+ /**
+ * Add a predicate.
+ *
+ * @access public
+ * @param string $predicate Predicate.
+ * @return \Hoa\Praspel\Model\Declaration
+ */
+ public function predicate ( $predicate ) {
+
+ $this->_predicates[] = $predicate;
+
+ return $this;
+ }
+
+ /**
+ * Get all predicates.
+ *
+ * @access public
+ * @return array
+ */
+ public function getPredicates ( ) {
+
+ return $this->_predicates;
+ }
+}
+
+}
diff --git a/Model/Ensures.php b/Model/Ensures.php
new file mode 100644
index 0000000..4043c3f
--- /dev/null
+++ b/Model/Ensures.php
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2012, Ivan Enderlin. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace {
+
+from('Hoa')
+
+/**
+ * \Hoa\Praspel\Model\Declaration
+ */
+-> import('Praspel.Model.Declaration');
+
+}
+
+namespace Hoa\Praspel\Model {
+
+/**
+ * Class \Hoa\Praspel\Model\Ensures.
+ *
+ * Represent the @ensures clause.
+ *
+ * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
+ * @copyright Copyright © 2007-2012 Ivan Enderlin.
+ * @license New BSD License
+ */
+
+class Ensures extends Declaration {
+
+ /**
+ * Name.
+ *
+ * @const string
+ */
+ const NAME = 'ensures';
+}
+
+}
diff --git a/Model/Forexample.php b/Model/Forexample.php
new file mode 100644
index 0000000..2750baa
--- /dev/null
+++ b/Model/Forexample.php
@@ -0,0 +1,164 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2012, Ivan Enderlin. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace {
+
+from('Hoa')
+
+/**
+ * \Hoa\Praspel\Model\Clause
+ */
+-> import('Praspel.Model.Clause');
+
+}
+
+namespace Hoa\Praspel\Model {
+
+/**
+ * Class \Hoa\Praspel\Model\Forexample.
+ *
+ * Represent the @forexample clause.
+ *
+ * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
+ * @copyright Copyright © 2007-2012 Ivan Enderlin.
+ * @license New BSD License
+ */
+
+class Forexample
+ extends Clause
+ implements \ArrayAccess,
+ \IteratorAggregate,
+ \Countable {
+
+ /**
+ * Name.
+ *
+ * @const string
+ */
+ const NAME = 'forexample';
+
+ /**
+ * Examples.
+ *
+ * @var \Hoa\Praspel\Model\Forexample array
+ */
+ protected $_examples = array();
+
+
+
+ /**
+ * Check if an example exists.
+ *
+ * @access public
+ * @param int $offset Offset.
+ * @return bool
+ */
+ public function offsetExists ( $offset ) {
+
+ return isset($this->_examples[$offset]);
+ }
+
+ /**
+ * Get an example.
+ *
+ * @access public
+ * @param int $offset Offset.
+ * @return string
+ */
+ public function offsetGet ( $offset ) {
+
+ if(false === $this->offsetExists($offset))
+ return null;
+
+ return $this->_examples[$offset];
+ }
+
+ /**
+ * Set an example.
+ *
+ * @access public
+ * @param int $offset Offset.
+ * @param string $value Example value.
+ * @return \Hoa\Praspel\Model\Forexample
+ */
+ public function offsetSet ( $offset, $value ) {
+
+ if(null === $offset)
+ $this->_examples[] = $value;
+ else
+ $this->_examples[$offset] = $value;
+
+ return $this;
+ }
+
+ /**
+ * Unset an example.
+ *
+ * @access public
+ * @param int $offset Offset.
+ * @return void
+ */
+ public function offsetUnset ( $offset ) {
+
+ unset($this->_examples[$offset]);
+
+ return;
+ }
+
+ /**
+ * Iterator over examples.
+ *
+ * @access public
+ * @return \ArrayObject
+ */
+ public function getIterator ( ) {
+
+ return new \ArrayObject($this->_examples);
+ }
+
+ /**
+ * Count number of examples.
+ *
+ * @access public
+ * @return int
+ */
+ public function count ( ) {
+
+ return count($this->_examples);
+ }
+}
+
+}
diff --git a/Model/Invariant.php b/Model/Invariant.php
new file mode 100644
index 0000000..9918cf3
--- /dev/null
+++ b/Model/Invariant.php
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2012, Ivan Enderlin. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace {
+
+from('Hoa')
+
+/**
+ * \Hoa\Praspel\Model\Declaration
+ */
+-> import('Praspel.Model.Declaration');
+
+}
+
+namespace Hoa\Praspel\Model {
+
+/**
+ * Class \Hoa\Praspel\Model\Invariant.
+ *
+ * Represent the @invariant clause.
+ *
+ * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
+ * @copyright Copyright © 2007-2012 Ivan Enderlin.
+ * @license New BSD License
+ */
+
+class Invariant extends Declaration {
+
+ /**
+ * Name.
+ *
+ * @const string
+ */
+ const NAME = 'invariant';
+}
+
+}
diff --git a/Model/Is.php b/Model/Is.php
new file mode 100644
index 0000000..ae1d069
--- /dev/null
+++ b/Model/Is.php
@@ -0,0 +1,172 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2012, Ivan Enderlin. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace {
+
+from('Hoa')
+
+/**
+ * \Hoa\Praspel\Model\Clause
+ */
+-> import('Praspel.Model.Clause');
+
+}
+
+namespace Hoa\Praspel\Model {
+
+/**
+ * Class \Hoa\Praspel\Model\Is.
+ *
+ * Represent the @is clause.
+ *
+ * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
+ * @copyright Copyright © 2007-2012 Ivan Enderlin.
+ * @license New BSD License
+ */
+
+class Is extends Clause {
+
+ /**
+ * Name.
+ *
+ * @const string
+ */
+ const NAME = 'is';
+
+ /**
+ * Property: pure.
+ *
+ * @const int
+ */
+ const PURE = 1;
+
+ /**
+ * Properties.
+ *
+ * @var \Hoa\Praspel\Model\Is int
+ */
+ protected $_property = 0;
+
+
+
+ /**
+ * Check if a property is declared.
+ *
+ * @access public
+ * @param int $property Property.
+ * @return bool
+ */
+ public function is ( $property ) {
+
+ return $property === ($this->_property & $property);
+ }
+
+ /**
+ * Set the property value.
+ *
+ * @access public
+ * @param int $property Property.
+ * @return int
+ */
+ public function setProperty ( $property ) {
+
+ $old = $this->_property;
+ $this->_property = $property;
+
+ return $old;
+ }
+
+ /**
+ * Add a property.
+ *
+ * @access public
+ * @param int $property Property.
+ * @return int
+ */
+ public function addProperty ( $property ) {
+
+ $old = $this->_property;
+ $this->_property |= $property;
+
+ return $old;
+ }
+
+ /**
+ * Remove a property.
+ *
+ * @access public
+ * @param int $property Property.
+ * @return int
+ */
+ public function removeProperty ( $property ) {
+
+ $old = $this->_property;
+ $this->_property ^= $property;
+
+ return $old;
+ }
+
+ /**
+ * Get the property value.
+ *
+ * @access public
+ * @return int
+ */
+ public function getProperty ( ) {
+
+ return $this->_property;
+ }
+
+ /**
+ * Get property value from a string.
+ *
+ * @access public
+ * @param string $property Property name.
+ * @return int
+ */
+ public static function getPropertyValue ( $property ) {
+
+ switch($property) {
+
+ case 'pure':
+ return static::PURE;
+ }
+
+ return 0;
+ }
+}
+
+}
diff --git a/Model/Requires.php b/Model/Requires.php
new file mode 100644
index 0000000..5e7dcae
--- /dev/null
+++ b/Model/Requires.php
@@ -0,0 +1,70 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2012, Ivan Enderlin. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace {
+
+from('Hoa')
+
+/**
+ * \Hoa\Praspel\Model\Declaration
+ */
+-> import('Praspel.Model.Declaration');
+
+}
+
+namespace Hoa\Praspel\Model {
+
+/**
+ * Class \Hoa\Praspel\Model\Requires.
+ *
+ * Represent the @requires clause.
+ *
+ * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
+ * @copyright Copyright © 2007-2012 Ivan Enderlin.
+ * @license New BSD License
+ */
+
+class Requires extends Declaration {
+
+ /**
+ * Name.
+ *
+ * @const string
+ */
+ const NAME = 'requires';
+}
+
+}
diff --git a/Model/Specification.php b/Model/Specification.php
new file mode 100644
index 0000000..c84abd9
--- /dev/null
+++ b/Model/Specification.php
@@ -0,0 +1,147 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2012, Ivan Enderlin. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace {
+
+from('Hoa')
+
+/**
+ * \Hoa\Praspel\Model\Behavior
+ */
+-> import('Praspel.Model.Behavior')
+
+/**
+ * \Hoa\Praspel\Model\Is
+ */
+-> import('Praspel.Model.Is')
+
+/**
+ * \Hoa\Realdom\Disjunction
+ */
+-> import('Realdom.Disjunction', true);
+
+}
+
+namespace Hoa\Praspel\Model {
+
+/**
+ * Class \Hoa\Praspel\Model\Specification.
+ *
+ * Represent a specification (contains all clauses).
+ *
+ * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
+ * @copyright Copyright © 2007-2012 Ivan Enderlin.
+ * @license New BSD License
+ */
+
+class Specification extends Behavior {
+
+ /**
+ * Name.
+ *
+ * @const string
+ */
+ const NAME = '';
+
+
+
+ /**
+ * Cancel the constructor from the parent.
+ *
+ * @access public
+ * @return void
+ */
+ public function __construct ( ) {
+
+ return;
+ }
+
+ /**
+ * Get a specific clause.
+ *
+ * @access public
+ * @param string $clause Clause (without leading arobase).
+ * @return \Hoa\Praspel\Model\Clause
+ * @throw \Hoa\Praspel\Exception\Model
+ */
+ public function getClause ( $clause ) {
+
+ if(isset($this->_clauses[$clause]))
+ return $this->_clauses[$clause];
+
+ $handle = null;
+
+ switch($clause) {
+
+ case 'is':
+ $handle = new Is($this);
+ break;
+
+ case 'requires':
+ $handle = new Requires($this);
+ break;
+
+ case 'ensures':
+ $handle = new Ensures($this);
+ break;
+
+ case 'throwable':
+ $handle = new Throwable($this);
+ break;
+
+ case 'invariant':
+ $handle = new Invariant($this);
+ break;
+
+ case 'behavior':
+ $handle = new Behavior($this);
+ break;
+
+ case 'forexample':
+ $handle = new Forexample($this);
+ break;
+
+ default:
+ throw new \Hoa\Praspel\Exception\Model(
+ 'Clause @%s is unknown.',
+ 0, $clause);
+ }
+
+ return $this->_clauses[$clause] = $handle;
+ }
+}
+
+}
diff --git a/Model/Throwable.php b/Model/Throwable.php
new file mode 100644
index 0000000..d71cfcc
--- /dev/null
+++ b/Model/Throwable.php
@@ -0,0 +1,104 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2012, Ivan Enderlin. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace {
+
+from('Hoa')
+
+/**
+ * \Hoa\Praspel\Model\Clause
+ */
+-> import('Praspel.Model.Clause');
+
+}
+
+namespace Hoa\Praspel\Model {
+
+/**
+ * Class \Hoa\Praspel\Model\Throwable.
+ *
+ * Represent the @throwable clause.
+ *
+ * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
+ * @copyright Copyright © 2007-2012 Ivan Enderlin.
+ * @license New BSD License
+ */
+
+class Throwable extends Clause {
+
+ /**
+ * Name.
+ *
+ * @const string
+ */
+ const NAME = 'throwable';
+
+ /**
+ * List of exception names.
+ *
+ * @var \Hoa\Praspel\Model\Throwable array
+ */
+ protected $_exceptions = array();
+
+
+
+ /**
+ * Add an exception to the list.
+ *
+ * @access public
+ * @param string $exception Exception name.
+ * @return \Hoa\Praspel\Model\Throwable
+ */
+ public function exception ( $exception ) {
+
+ $this->_exceptions[] = $exception;
+
+ return $this;
+ }
+
+ /**
+ * Get exceptions list.
+ *
+ * @access public
+ * @return array
+ */
+ public function getExceptions ( ) {
+
+ return $this->_exceptions;
+ }
+}
+
+}
diff --git a/Model/Variable.php b/Model/Variable.php
new file mode 100644
index 0000000..649d9db
--- /dev/null
+++ b/Model/Variable.php
@@ -0,0 +1,409 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2012, Ivan Enderlin. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace {
+
+from('Hoa')
+
+/**
+ * \Hoa\Praspel\Exception\Model
+ */
+-> import('Praspel.Exception.Model')
+
+/**
+ * \Hoa\Visitor\Element
+ */
+-> import('Visitor.Element');
+
+}
+
+namespace Hoa\Praspel\Model {
+
+/**
+ * Class \Hoa\Praspel\Model\Variable.
+ *
+ * Represent a variable.
+ *
+ * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
+ * @copyright Copyright © 2007-2012 Ivan Enderlin.
+ * @license New BSD License
+ */
+
+class Variable implements \Hoa\Visitor\Element {
+
+ /**
+ * Variable name.
+ *
+ * @var \Hoa\Praspel\Model\Variable string
+ */
+ protected $_name = null;
+
+ /**
+ * Clause that contains this variable.
+ *
+ * @var \Hoa\Praspel\Model\Clause object
+ */
+ protected $_clause = null;
+
+ /**
+ * Variable value.
+ *
+ * @var \Hoa\Praspel\Model\Variable mixed
+ */
+ protected $_value = null;
+
+ /**
+ * Domains that describe the variable.
+ *
+ * @var \Hoa\Realdom\Disjunction object
+ */
+ protected $_domains = null;
+
+ /**
+ * References domains.
+ *
+ * @var \Hoa\Realdom\Disjunction object
+ */
+ protected $_refDomains = null;
+
+ /**
+ * Alias variable (please, see “domainof”).
+ *
+ * @var \Hoa\Praspel\Model\Variable object
+ */
+ protected $_alias = null;
+
+ /**
+ * Constraints.
+ *
+ * @var \Hoa\Praspel\Model\Variable array
+ */
+ protected $_constraints = array();
+
+
+
+ /**
+ * Build a variable.
+ *
+ * @access public
+ * @param string $name Name.
+ * @param \Hoa\Praspel\Model\Clause $clause Clause.
+ * @return void
+ * @throw \Hoa\Praspel\Exception\Model
+ */
+ public function __construct ( $name, Clause $clause ) {
+
+ $this->_name = $name;
+ $this->_clause = $clause;
+ $this->_refDomains = &$this->_domains;
+
+ if( ('\old' === substr($name, 0, 4)
+ || '\result' === $name)
+ && !($this->_clause instanceof Ensures))
+ throw new \Hoa\Praspel\Exception\Model(
+ '\old(…) and \result are only allowed in @ensures, ' .
+ 'given %s in %s.',
+ 0, array($name, $this->getClause()->getName()));
+
+ return;
+ }
+
+ /**
+ * Set a value to the variable.
+ *
+ * @access public
+ * @param mixed &$value Value.
+ * @return mixed
+ */
+ public function setValue ( &$value ) {
+
+ $old = $this->_value;
+ $this->_value = &$value;
+
+ return $old;
+ }
+
+ /**
+ * Get value of the variable.
+ *
+ * @access public
+ * @return mixed
+ */
+ public function &getValue ( ) {
+
+ return $this->_value;
+ }
+
+ /**
+ * Allow to write $variable->in = … to define domains (if $name is not equal
+ * to "in", then it is a normal behavior).
+ *
+ * @access public
+ * @param string $name Name.
+ * @param mixed $value Value.
+ * @return void
+ * @throw \Hoa\Praspel\Exception\Model
+ */
+ public function __set ( $name, $value ) {
+
+ if('in' !== $name) {
+
+ $this->$name = $value;
+
+ return;
+ }
+
+ $onDomains = $this->_domains === $this->_refDomains;
+
+ if( true === $onDomains
+ && !empty($this->_domains))
+ throw new \Hoa\Praspel\Exception\Model(
+ 'Variable $%s has already declared domains.',
+ 1, $this->getName());
+
+ if(!($value instanceof \Hoa\Realdom\Disjunction))
+ $value = realdom()->const($value);
+
+ $this->_refDomains = $value;
+
+ unset($this->_refDomains);
+ $this->_refDomains = &$this->_domains;
+
+ if( true === $onDomains
+ && !empty($this->_domains)) {
+
+ $domains = $this->getDomains()->getRealdoms();
+
+ if(null === $domains)
+ return;
+
+ if(!is_array($domains)) {
+
+ $domains->setConstraints($this->_constraints);
+
+ return;
+ }
+
+ foreach($domains as $domain)
+ $domain->setConstraints($this->_constraints);
+ }
+
+ return;
+ }
+
+ /*
+ * Call the predicate() method on realistic domains.
+ *
+ * @access public
+ * @param mixed $q Sampled value.
+ * @return boolean
+ */
+ public function predicate ( ) {
+
+ return $this->getDomains()->predicate($this->getValue());
+ }
+
+ /**
+ * Call the sample() method on realistic domains.
+ *
+ * @access public
+ * @return mixed
+ * @throw \Hoa\Realdom\Exception
+ */
+ public function sample ( ) {
+
+ // @TODO
+ return $this->getDomains()->getRealdoms()->sample();
+ }
+
+ /**
+ * Define a “key” constraint. Use $variable->key(…)->in = …;
+ *
+ * @access public
+ * @param mixed $scalar Value.
+ * @return \Hoa\Praspel\Model\Variable
+ */
+ public function key ( $scalar ) {
+
+ if(!isset($this->_constraints['key']))
+ $this->_constraints['key'] = array();
+
+ unset($this->_refDomains);
+ $handle = &$this->_constraints['key'][];
+ $handle[0] = realdom()->const($scalar);
+ $this->_refDomains = &$handle[1];
+
+ return $this;
+ }
+
+ /**
+ * Define a “contains” constraint.
+ *
+ * @access public
+ * @param mixed $scalar Value.
+ * @return \Hoa\Praspel\Model\Variable
+ */
+ public function contains ( $scalar ) {
+
+ if(!isset($this->_constraints['contains']))
+ $this->_constraints['contains'] = array();
+
+ $this->_constraints['contains'][] = realdom()->const($scalar);
+
+ return $this;
+ }
+
+ /**
+ * Add an “is” constraint.
+ *
+ * @access public
+ * @param string ... Keywords.
+ * @return \Hoa\Praspel\Model\Variable
+ */
+ public function is ( ) {
+
+ if(!isset($this->_constraints['is']))
+ $this->_constraints['is'] = array();
+
+ $this->_constraints['is'] = array_merge(
+ $this->_constraints['is'],
+ func_get_args()
+ );
+
+ return $this;
+ }
+
+ /**
+ * Declare a “domainof” (alias).
+ *
+ * @access public
+ * @param \Hoa\Praspel\Model\Variable $variable Variable.
+ * @return \Hoa\Praspel\Model\Variable
+ * @throw \Hoa\Realdom\Exception
+ */
+ public function domainof ( $variable ) {
+
+ $variables = $this->getClause()->getLocalVariables();
+
+ if(!isset($variables[$variable]))
+ throw new \Hoa\Praspel\Exception\Model(
+ 'Variable $%s does not exist, cannot alias domains to $%s.',
+ 2, array($variable, $this->getName()));
+
+ if(!empty($this->_domains))
+ throw new \Hoa\Praspel\Exception\Model(
+ 'Variable $%s already has domains, cannot alias new domains ' .
+ 'from $%s.',
+ 3, array($this->getName(), $variable));
+
+ $this->_alias = $variable;
+ $this->_domains = &$variables[$variable]->getDomains();
+
+ return $this;
+ }
+
+ /**
+ * Get domains.
+ *
+ * @access public
+ * @return \Hoa\Realdom\Disjunction
+ */
+ public function &getDomains ( ) {
+
+ return $this->_domains;
+ }
+
+ /**
+ * Get constraints.
+ *
+ * @access public
+ * @return array
+ */
+ public function getConstraints ( ) {
+
+ return $this->_constraints;
+ }
+
+ /**
+ * Get alias.
+ *
+ * @access public
+ * @return \Hoa\Praspel\Model\Variable
+ */
+ public function getAlias ( ) {
+
+ return $this->_alias;
+ }
+
+ /**
+ * Get variable name.
+ *
+ * @access public
+ * @return string
+ */
+ public function getName ( ) {
+
+ return $this->_name;
+ }
+
+ /**
+ * Get parent clause.
+ *
+ * @access public
+ * @return \Hoa\Praspel\Model\Clause
+ */
+ public function getClause ( ) {
+
+ return $this->_clause;
+ }
+
+ /**
+ * Accept a visitor.
+ *
+ * @access public
+ * @param \Hoa\Visitor\Visit $visitor Visitor.
+ * @param mixed &$handle Handle (reference).
+ * @param mixed $eldnah Handle (no reference).
+ * @return mixed
+ */
+ public function accept ( \Hoa\Visitor\Visit $visitor,
+ &$handle = null, $eldnah = null ) {
+
+ return $visitor->visit($this, $handle, $eldnah);
+ }
+}
+
+}