aboutsummaryrefslogtreecommitdiffstats
path: root/Visitor
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2013-06-10 10:27:58 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2013-06-10 10:27:58 +0200
commit824e66a0399b20931678e1fdea2ce5fa018f6319 (patch)
treef1cb6550c318b05eabb4f3511917eddd59c7fccb /Visitor
parentfaba6ec19b03e8ae2e37d4a8a5bb01e7107b7cb3 (diff)
downloadPraspel-824e66a0399b20931678e1fdea2ce5fa018f6319.zip
Praspel-824e66a0399b20931678e1fdea2ce5fa018f6319.tar.gz
Praspel-824e66a0399b20931678e1fdea2ce5fa018f6319.tar.bz2
Add support of “with” in @throwable.
It allows to specify the post-state of data. Example: @throwable T1 t1 with this->foo: true;
Diffstat (limited to 'Visitor')
-rw-r--r--Visitor/Compiler.php105
-rw-r--r--Visitor/Interpreter.php63
-rw-r--r--Visitor/Praspel.php35
3 files changed, 144 insertions, 59 deletions
diff --git a/Visitor/Compiler.php b/Visitor/Compiler.php
index c14e6a3..d083572 100644
--- a/Visitor/Compiler.php
+++ b/Visitor/Compiler.php
@@ -110,58 +110,87 @@ class Compiler implements \Hoa\Visitor\Visit {
}
elseif($element instanceof \Hoa\Praspel\Model\Declaration) {
- $parent = '$' . $element->getParent()->getId();
- $variable = '$' . $element->getId();
- $clause = $element->getName();
+ $variable = '$' . ($eldnah ?: $element->getId());
$out = "\n" .
- $variable . ' = ' . $parent .
- '->getClause(\'' . $clause . '\');' . "\n";
+ $variable . ' = $' . $element->getParent()->getId() .
+ '->getClause(\'' . $element->getName() . '\');' . "\n";
- foreach($element as $name => $var) {
+ foreach($element as $var)
+ $out .= $var->accept($this, $handle, $eldnah);
- $start = $variable . '[\'' . $name . '\']';
+ foreach($element->getPredicates() as $predicate)
+ $out .= $variable . '->predicate(\'' . $predicate . '\');' . "\n";
+ }
+ elseif($element instanceof \Hoa\Praspel\Model\Variable) {
- if(true === $var->isLocal())
- $out .= $variable . '->let[\'' . $name . '\']';
- else
- $out .= $start;
+ $variable = '$' . ($eldnah ?: $element->getClause()->getId());
+ $name = $element->getName();
+ $start = $variable . '[\'' . $name . '\']';
- if(null === $alias = $var->getAlias())
- $out .= '->in = ' . $var->getDomains() . ';' . "\n";
- else
- $out .= '->domainof(\'' . $alias . '\');' . "\n";
+ if(true === $element->isLocal())
+ $out .= $variable . '->let[\'' . $name . '\']';
+ else
+ $out .= $start;
- $constraints = $var->getConstraints();
+ if(null === $alias = $element->getAlias())
+ $out .= '->in = ' . $element->getDomains() . ';' . "\n";
+ else
+ $out .= '->domainof(\'' . $alias . '\');' . "\n";
- if(isset($constraints['is']))
- $out .= $start . '->is(\'' .
- implode('\', \'', $constraints['is']) . '\');' .
- "\n";
+ $constraints = $element->getConstraints();
- if(isset($constraints['contains']))
- foreach($constraints['contains'] as $contains)
- $out .= $start . '->contains(' . $contains . ');' . "\n";
+ if(isset($constraints['is']))
+ $out .= $start . '->is(\'' .
+ implode('\', \'', $constraints['is']) . '\');' .
+ "\n";
- if(isset($constraints['key']))
- foreach($constraints['key'] as $pairs)
- $out .= $start . '->key(' . $pairs[0] . ')->in = ' .
- $pairs[1] . ';' . "\n";
- }
+ if(isset($constraints['contains']))
+ foreach($constraints['contains'] as $contains)
+ $out .= $start . '->contains(' . $contains . ');' . "\n";
- foreach($element->getPredicates() as $predicate)
- $out .= $variable . '->predicate(\'' . $predicate . '\');' . "\n";
+ if(isset($constraints['key']))
+ foreach($constraints['key'] as $pairs)
+ $out .= $start . '->key(' . $pairs[0] . ')->in = ' .
+ $pairs[1] . ';' . "\n";
}
elseif($element instanceof \Hoa\Praspel\Model\Throwable) {
- $parent = '$' . $element->getParent()->getId();
- $variable = '$' . $element->getId();
- $out = "\n" .
- $variable . ' = ' . $parent .
- '->getClause(\'throwable\');' . "\n";
+ $parent = '$' . $element->getParent()->getId();
+ $_variable = $element->getId();
+ $variable = '$' . $_variable;
+ $out = "\n" .
+ $variable . ' = ' . $parent .
+ '->getClause(\'throwable\');' . "\n";
- foreach($element->getExceptions() as $identifier => $class)
- $out .= $variable . '[\'' . $identifier . '\'] = \'' . $class .
- '\';' . "\n";
+ foreach($element as $identifier) {
+
+ $exception = $element[$identifier];
+ $start = $variable . '[\'' . $identifier . '\']';
+ $out .= $start . ' = \'' . $exception->getInstanceName() .
+ '\';' . "\n";
+
+ if(false === $element->isDisjointed()) {
+
+ if(null !== $with = $element->getWith()) {
+
+ $temp = $_variable . '_' . $identifier . '_with';
+ $out .= '$' . $temp . ' = ' .
+ $variable . '->newWith();' . "\n";
+
+ foreach($with as $var)
+ $out .= $var->accept($this, $handle, $temp);
+
+ foreach($with->getPredicates() as $predicate)
+ $out .= '$' . $temp . '->predicate(\'' . $predicate .
+ '\');' . "\n";
+
+ $out .= $start . '->setWith($' . $temp . ');' . "\n";
+ }
+ }
+ else
+ $out .= $start . '->disjunctionWith(\'' .
+ $exception->getDisjunction() . '\');' . "\n";
+ }
}
elseif($element instanceof \Hoa\Praspel\Model\Behavior) {
diff --git a/Visitor/Interpreter.php b/Visitor/Interpreter.php
index f0f6fc3..4337740 100644
--- a/Visitor/Interpreter.php
+++ b/Visitor/Interpreter.php
@@ -139,7 +139,6 @@ class Interpreter implements \Hoa\Visitor\Visit {
case '#requires':
case '#ensures':
case '#invariant':
- case '#throwable':
$this->_clause = $this->_current->getClause(substr($id, 1));
foreach($element->getChildren() as $child)
@@ -163,6 +162,50 @@ class Interpreter implements \Hoa\Visitor\Visit {
$this->_current = $previous;
break;
+ case '#throwable':
+ $this->_clause = $this->_current->getClause('throwable');
+ $identifier = null;
+
+ foreach($element->getChildren() as $child) {
+
+ switch($child->getId()) {
+
+ case '#exception_identifier':
+ $_identifier = $child->getChild(1)->accept(
+ $this,
+ $handle,
+ false
+ );
+ $_instanceof = $child->getChild(0)->accept(
+ $this,
+ $handle,
+ false
+ );
+
+ $this->_clause[$_identifier] = $_instanceof;
+
+ if(null === $identifier)
+ $identifier = $_identifier;
+ else
+ $this->_clause[$_identifier]->disjunctionWith(
+ $identifier
+ );
+ break;
+
+ case '#exception_with':
+ $old = $this->_clause;
+ $this->_clause = $old->newWith();
+
+ foreach($child->getChildren() as $_child)
+ $_child->accept($this, $handle, $eldnah);
+
+ $old[$identifier]->setWith($this->_clause);
+ $this->_clause = $old;
+ break;
+ }
+ }
+ break;
+
case '#description':
$this->_clause = $this->_root->getClause('description');
$this->_clause[] = $element->getChild(0)->accept(
@@ -172,24 +215,6 @@ class Interpreter implements \Hoa\Visitor\Visit {
);
break;
- case '#exception_list':
- for($i = 0, $max = $element->getChildrenNumber(); $i < $max; $i += 2) {
-
- $identifier = $element->getChild($i + 1)->accept(
- $this,
- $handle,
- false
- );
- $classname = $element->getChild($i)->accept(
- $this,
- $handle,
- false
- );
-
- $this->_clause[$identifier] = $classname;
- }
- break;
-
case '#declaration':
$variable = $element->getChild(0)
->accept($this, $handle, false);
diff --git a/Visitor/Praspel.php b/Visitor/Praspel.php
index b2c0da6..4ad2b07 100644
--- a/Visitor/Praspel.php
+++ b/Visitor/Praspel.php
@@ -154,8 +154,39 @@ class Praspel implements \Hoa\Visitor\Visit {
$oout = array();
- foreach($element->getExceptions() as $identifier => $class)
- $oout[] = ' ' . $class . ' ' . $identifier;
+ foreach($element as $identifier) {
+
+ $exception = $element[$identifier];
+
+ if(true === $exception->isDisjointed())
+ continue;
+
+ $line = ' ' . $exception->getInstanceName() . ' ' .
+ $identifier;
+
+ foreach((array) $exception->getDisjunction() as $_identifier) {
+
+ $_exception = $element[$_identifier];
+ $line .= ' or ' . $_exception->getInstanceName() . ' ' .
+ $_identifier;
+ }
+
+ if(null !== $with = $exception->getWith()) {
+
+ $line .= ' with ';
+ $liine = array();
+
+ foreach($with as $var)
+ $liine[] = $var->accept($this, $handle, $eldnah);
+
+ foreach($with->getPredicates() as $predicate)
+ $liine[] = '\pred(\'' . $predicate . '\')';
+
+ $line .= implode(' and ', $liine);
+ }
+
+ $oout[] = $line;
+ }
$out = '@throwable' . implode(' or', $oout) . ';';
}