diff --git a/lib/PHPCfg/Op/Expr/Exit_.php b/lib/PHPCfg/Op/Terminal/Exit_.php old mode 100755 new mode 100644 similarity index 72% rename from lib/PHPCfg/Op/Expr/Exit_.php rename to lib/PHPCfg/Op/Terminal/Exit_.php index 4c46613..8350a38 --- a/lib/PHPCfg/Op/Expr/Exit_.php +++ b/lib/PHPCfg/Op/Terminal/Exit_.php @@ -9,27 +9,25 @@ * @license MIT See LICENSE at the root of the project for more info */ -namespace PHPCfg\Op\Expr; +namespace PHPCfg\Op\Terminal; -use PHPCfg\Op\Expr; +use PHPCfg\Op\Terminal; use PhpCfg\Operand; -class Exit_ extends Expr +class Exit_ extends Terminal { - public ?Operand $expr; + public ?Operand $expr = null; public function __construct(Operand $expr = null, array $attributes = []) { parent::__construct($attributes); - if ($expr) { + if (!is_null($expr)) { $this->expr = $this->addReadRef($expr); - } else { - $this->expr = null; } } public function getVariableNames(): array { - return ['expr', 'result']; + return ['expr']; } } diff --git a/lib/PHPCfg/Parser.php b/lib/PHPCfg/Parser.php index 3fec0c4..145ebaa 100755 --- a/lib/PHPCfg/Parser.php +++ b/lib/PHPCfg/Parser.php @@ -838,6 +838,7 @@ protected function parseExprNode($expr) return $op->result; } + $method = 'parse'.$expr->getType(); if (method_exists($this, $method)) { $op = $this->{$method}($expr); @@ -1028,7 +1029,12 @@ protected function parseExpr_Exit(Expr\Exit_ $expr) $e = $this->readVariable($this->parseExprNode($expr->expr)); } - return new Op\Expr\Exit_($e, $this->mapAttributes($expr)); + $this->block->children[] = new Op\Terminal\Exit_($e, $this->mapAttributes($expr)); + // Dump everything after the exit + $this->block = new Block(); + $this->block->dead = true; + + return new Literal(1); } protected function parseExpr_FuncCall(Expr\FuncCall $expr) diff --git a/test/code/exit.test b/test/code/exit.test new file mode 100755 index 0000000..cbb4a1c --- /dev/null +++ b/test/code/exit.test @@ -0,0 +1,11 @@ + + expr: LITERAL(1) + result: Var#2 + Terminal_Exit diff --git a/test/code/exit_message.test b/test/code/exit_message.test new file mode 100755 index 0000000..b51f403 --- /dev/null +++ b/test/code/exit_message.test @@ -0,0 +1,16 @@ + + expr: LITERAL(1) + result: Var#2 + Expr_BinaryOp_Concat + left: LITERAL('Quitting with message: ') + right: Var#1<$a> + result: Var#3 + Terminal_Exit + expr: Var#3