Remove Stmt\Throw

This was a backwards-compatibility shim for Expr\Throw.
This commit is contained in:
Nikita Popov 2023-09-25 18:37:07 +02:00
parent a1ccf57727
commit b4183c2b09
7 changed files with 13 additions and 69 deletions

View File

@ -386,16 +386,7 @@ non_empty_statement:
$$ = Stmt\InlineHTML[$1]; $$ = Stmt\InlineHTML[$1];
$$->setAttribute('hasLeadingNewline', $this->inlineHtmlHasLeadingNewline(#1)); $$->setAttribute('hasLeadingNewline', $this->inlineHtmlHasLeadingNewline(#1));
} }
| expr semi { | expr semi { $$ = Stmt\Expression[$1]; }
$e = $1;
if ($e instanceof Expr\Throw_) {
// For backwards-compatibility reasons, convert throw in statement position into
// Stmt\Throw_ rather than Stmt\Expression(Expr\Throw_).
$$ = Stmt\Throw_[$e->expr];
} else {
$$ = Stmt\Expression[$e];
}
}
| T_UNSET '(' variables_list ')' semi { $$ = Stmt\Unset_[$3]; } | T_UNSET '(' variables_list ')' semi { $$ = Stmt\Unset_[$3]; }
| T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement | T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement
{ $$ = Stmt\Foreach_[$3, $5[0], ['keyVar' => null, 'byRef' => $5[1], 'stmts' => $7]]; } { $$ = Stmt\Foreach_[$3, $5[0], ['keyVar' => null, 'byRef' => $5[1], 'stmts' => $7]]; }

View File

@ -1,29 +0,0 @@
<?php declare(strict_types=1);
namespace PhpParser\Node\Stmt;
use PhpParser\Node;
class Throw_ extends Node\Stmt {
/** @var Node\Expr Expression */
public Node\Expr $expr;
/**
* Constructs a legacy throw statement node.
*
* @param Node\Expr $expr Expression
* @param array<string, mixed> $attributes Additional attributes
*/
public function __construct(Node\Expr $expr, array $attributes = []) {
$this->attributes = $attributes;
$this->expr = $expr;
}
public function getSubNodeNames(): array {
return ['expr'];
}
public function getType(): string {
return 'Stmt_Throw';
}
}

View File

@ -1473,16 +1473,7 @@ class Php7 extends \PhpParser\ParserAbstract
}, },
172 => function ($stackPos) { 172 => function ($stackPos) {
$this->semValue = new Stmt\Expression($this->semStack[$stackPos-(2-1)], $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos]));
$e = $this->semStack[$stackPos-(2-1)];
if ($e instanceof Expr\Throw_) {
// For backwards-compatibility reasons, convert throw in statement position into
// Stmt\Throw_ rather than Stmt\Expression(Expr\Throw_).
$this->semValue = new Stmt\Throw_($e->expr, $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos]));
} else {
$this->semValue = new Stmt\Expression($e, $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos]));
}
}, },
173 => function ($stackPos) { 173 => function ($stackPos) {
$this->semValue = new Stmt\Unset_($this->semStack[$stackPos-(5-3)], $this->getAttributes($this->tokenStartStack[$stackPos-(5-1)], $this->tokenEndStack[$stackPos])); $this->semValue = new Stmt\Unset_($this->semStack[$stackPos-(5-3)], $this->getAttributes($this->tokenStartStack[$stackPos-(5-1)], $this->tokenEndStack[$stackPos]));

View File

@ -1491,16 +1491,7 @@ class Php8 extends \PhpParser\ParserAbstract
}, },
172 => function ($stackPos) { 172 => function ($stackPos) {
$this->semValue = new Stmt\Expression($this->semStack[$stackPos-(2-1)], $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos]));
$e = $this->semStack[$stackPos-(2-1)];
if ($e instanceof Expr\Throw_) {
// For backwards-compatibility reasons, convert throw in statement position into
// Stmt\Throw_ rather than Stmt\Expression(Expr\Throw_).
$this->semValue = new Stmt\Throw_($e->expr, $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos]));
} else {
$this->semValue = new Stmt\Expression($e, $this->getAttributes($this->tokenStartStack[$stackPos-(2-1)], $this->tokenEndStack[$stackPos]));
}
}, },
173 => function ($stackPos) { 173 => function ($stackPos) {
$this->semValue = new Stmt\Unset_($this->semStack[$stackPos-(5-3)], $this->getAttributes($this->tokenStartStack[$stackPos-(5-1)], $this->tokenEndStack[$stackPos])); $this->semValue = new Stmt\Unset_($this->semStack[$stackPos-(5-3)], $this->getAttributes($this->tokenStartStack[$stackPos-(5-1)], $this->tokenEndStack[$stackPos]));

View File

@ -960,10 +960,6 @@ class Standard extends PrettyPrinterAbstract {
return 'return' . (null !== $node->expr ? ' ' . $this->p($node->expr) : '') . ';'; return 'return' . (null !== $node->expr ? ' ' . $this->p($node->expr) : '') . ';';
} }
protected function pStmt_Throw(Stmt\Throw_ $node): string {
return 'throw ' . $this->p($node->expr) . ';';
}
protected function pStmt_Label(Stmt\Label $node): string { protected function pStmt_Label(Stmt\Label $node): string {
return $node->name . ':'; return $node->name . ':';
} }

View File

@ -525,9 +525,11 @@ array(
) )
) )
) )
12: Stmt_Throw( 12: Stmt_Expression(
expr: Expr_Variable( expr: Expr_Throw(
name: x expr: Expr_Variable(
name: x
)
) )
) )
13: Stmt_Goto( 13: Stmt_Goto(

View File

@ -41,9 +41,11 @@ array(
name: a name: a
) )
) )
6: Stmt_Throw( 6: Stmt_Expression(
expr: Expr_Variable( expr: Expr_Throw(
name: e expr: Expr_Variable(
name: e
)
) )
) )
7: Stmt_Label( 7: Stmt_Label(