aboutsummaryrefslogtreecommitdiffstats
path: root/AssertionChecker
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2014-05-21 16:13:01 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2014-05-21 16:13:01 +0200
commitf0479006caa98b59f0d3f2336263ebee70539d7c (patch)
tree5e3a248fd895b4cdd4f9bb08dbe15327756918e7 /AssertionChecker
parent7462328eeb1cda5962e8fa24f8aa25c2509e3045 (diff)
downloadPraspel-f0479006caa98b59f0d3f2336263ebee70539d7c.zip
Praspel-f0479006caa98b59f0d3f2336263ebee70539d7c.tar.gz
Praspel-f0479006caa98b59f0d3f2336263ebee70539d7c.tar.bz2
Evaluate the \pred(p) construction.
Diffstat (limited to 'AssertionChecker')
-rw-r--r--AssertionChecker/Runtime.php51
1 files changed, 51 insertions, 0 deletions
diff --git a/AssertionChecker/Runtime.php b/AssertionChecker/Runtime.php
index 0b2f8de..9b3b0b9 100644
--- a/AssertionChecker/Runtime.php
+++ b/AssertionChecker/Runtime.php
@@ -637,6 +637,57 @@ class Runtime extends AssertionChecker {
$verdict &= $_verdict;
}
+ $predicateEvaluator = function ( $__hoa_arguments, $__hoa_code ) {
+
+ extract($__hoa_arguments);
+
+ return true == eval('return ' . $__hoa_code . ';');
+ };
+
+ foreach($clause->getPredicates() as $predicate) {
+
+ $_predicate = $predicate;
+
+ preg_match_all(
+ '#(?<!\\\)\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)#',
+ $_predicate,
+ $matches
+ );
+
+ $predicateArguments = array();
+
+ foreach($matches[1] as $variable)
+ if(true === array_key_exists($variable, $data))
+ $predicateArguments[$variable] = $data[$variable];
+
+ if(false !== strpos($_predicate, '\result')) {
+
+ if( !($clause instanceof \Hoa\Praspel\Model\Ensures)
+ && !($clause instanceof \Hoa\Praspel\Model\Throwable)) {
+
+ $verdict &= false;
+ $exceptions[] = new $exception(
+ 'Illegal \result in the following predicate: %s.',
+ 11, $predicate);
+
+ continue;
+ }
+
+ $placeholder = '__hoa_praspel_' . uniqid();
+ $_predicate = str_replace('\\result', '$' . $placeholder, $_predicate);
+ $predicateArguments[$placeholder] = $data['\result'];
+ }
+
+ $_verdict = $predicateEvaluator($predicateArguments, $_predicate);
+
+ if(false === $_verdict)
+ $exceptions[] = new $exception(
+ 'Violation of the following predicate: %s.',
+ 11, $predicate);
+
+ $verdict &= $_verdict;
+ }
+
if(!empty($trace))
$trace->addClause($traceClause);