aboutsummaryrefslogtreecommitdiffstats
path: root/Visitor/Compiler.php
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/Compiler.php
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/Compiler.php')
-rw-r--r--Visitor/Compiler.php105
1 files changed, 67 insertions, 38 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) {