aboutsummaryrefslogtreecommitdiffstats
path: root/Visitor
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2013-04-09 18:08:51 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2013-04-09 18:08:51 +0200
commitaf13e47350ad298432aef013e590e8ad1292b543 (patch)
tree401b16fba26a54e46fd2f14a8c672e03987d188f /Visitor
parentf9b766ceefeb3c996df7e7758ae878b9bf5b22f7 (diff)
downloadPraspel-af13e47350ad298432aef013e590e8ad1292b543.zip
Praspel-af13e47350ad298432aef013e590e8ad1292b543.tar.gz
Praspel-af13e47350ad298432aef013e590e8ad1292b543.tar.bz2
Add local variable with the “let” keyword.
A local variable is a contract variable, it does not represent a data of the program (class attribute or method argument). In Praspel: @requires let size: 1..5 and arr: array([…], size); In PHP $requires = $specification->getClause('requires'); $requires->let['size']->in = realdom()->boundinteger(1, 5); $requires['arr']->in = realdom()->array(…, $requires['size']);
Diffstat (limited to 'Visitor')
-rw-r--r--Visitor/Compiler.php6
-rw-r--r--Visitor/Interpreter.php7
2 files changed, 12 insertions, 1 deletions
diff --git a/Visitor/Compiler.php b/Visitor/Compiler.php
index 3159d4f..e8234cf 100644
--- a/Visitor/Compiler.php
+++ b/Visitor/Compiler.php
@@ -115,7 +115,11 @@ class Compiler implements \Hoa\Visitor\Visit {
foreach($element as $name => $var) {
$start = $variable . '[\'' . $name . '\']';
- $out .= $start;
+
+ if(true === $var->isLocal())
+ $out .= $variable . '->let[\'' . $name . '\']';
+ else
+ $out .= $start;
if(null === $alias = $var->getAlias())
$out .= '->in = ' . $var->getDomains() . ';' . "\n";
diff --git a/Visitor/Interpreter.php b/Visitor/Interpreter.php
index c53a1cc..22e66ac 100644
--- a/Visitor/Interpreter.php
+++ b/Visitor/Interpreter.php
@@ -185,6 +185,13 @@ class Interpreter implements \Hoa\Visitor\Visit {
->accept($this, $handle, $eldnah);
break;
+ case '#local_declaration':
+ $variable = $element->getChild(0)
+ ->accept($this, $handle, false);
+ $this->_clause->let[$variable]->in = $element->getChild(1)
+ ->accept($this, $handle, $eldnah);
+ break;
+
case '#qualification':
$children = $element->getChildren();
$variable = $this->_clause[array_shift($children)->accept(