Add specialized constructors for statement nodes with only one subnode

This commit is contained in:
nikic 2011-09-22 20:27:12 +02:00
parent a551bbc5a4
commit 06b7d63406
16 changed files with 255 additions and 45 deletions

View File

@ -126,12 +126,12 @@ top_statement:
| function_declaration_statement { $$ = $1; }
| class_declaration_statement { $$ = $1; }
| T_HALT_COMPILER
{ $$ = Stmt_HaltCompiler[remaining: $this->lexer->handleHaltCompiler()]; }
{ $$ = Stmt_HaltCompiler[$this->lexer->handleHaltCompiler()]; }
| T_NAMESPACE namespace_name ';' { $$ = Stmt_Namespace[name: $2, stmts: null]; }
| T_NAMESPACE namespace_name '{' top_statement_list '}' { $$ = Stmt_Namespace[name: $2, stmts: $4]; }
| T_NAMESPACE '{' top_statement_list '}' { $$ = Stmt_Namespace[name: null, stmts: $3]; }
| T_USE use_declarations ';' { $$ = Stmt_Use[uses: $2]; }
| constant_declaration ';' { $$ = Stmt_Const[consts: $1]; }
| T_USE use_declarations ';' { $$ = Stmt_Use[$2]; }
| constant_declaration ';' { $$ = Stmt_Const[$1]; }
;
use_declarations:
@ -173,18 +173,18 @@ statement:
| T_FOR '(' for_expr ';' for_expr ';' for_expr ')' for_statement
{ $$ = Stmt_For[init: $3, cond: $5, loop: $7, stmts: toArray($9)]; }
| T_SWITCH '(' expr ')' switch_case_list { $$ = Stmt_Switch[cond: $3, caseList: $5]; }
| T_BREAK ';' { $$ = Stmt_Break[num: null]; }
| T_BREAK expr ';' { $$ = Stmt_Break[num: $2]; }
| T_CONTINUE ';' { $$ = Stmt_Continue[num: null]; }
| T_CONTINUE expr ';' { $$ = Stmt_Continue[num: $2]; }
| T_RETURN ';' { $$ = Stmt_Return[expr: null]; }
| T_RETURN expr ';' { $$ = Stmt_Return[expr: $2]; }
| T_GLOBAL global_var_list ';' { $$ = Stmt_Global[vars: $2]; }
| T_STATIC static_var_list ';' { $$ = Stmt_Static[vars: $2]; }
| T_ECHO expr_list ';' { $$ = Stmt_Echo[exprs: $2]; }
| T_INLINE_HTML { $$ = Stmt_InlineHTML[value: $1]; }
| T_BREAK ';' { $$ = Stmt_Break[null]; }
| T_BREAK expr ';' { $$ = Stmt_Break[$2]; }
| T_CONTINUE ';' { $$ = Stmt_Continue[null]; }
| T_CONTINUE expr ';' { $$ = Stmt_Continue[$2]; }
| T_RETURN ';' { $$ = Stmt_Return[null]; }
| T_RETURN expr ';' { $$ = Stmt_Return[$2]; }
| T_GLOBAL global_var_list ';' { $$ = Stmt_Global[$2]; }
| T_STATIC static_var_list ';' { $$ = Stmt_Static[$2]; }
| T_ECHO expr_list ';' { $$ = Stmt_Echo[$2]; }
| T_INLINE_HTML { $$ = Stmt_InlineHTML[$1]; }
| expr ';' { $$ = $1; }
| T_UNSET '(' variables_list ')' ';' { $$ = Stmt_Unset[vars: $3]; }
| T_UNSET '(' variables_list ')' ';' { $$ = Stmt_Unset[$3]; }
| T_FOREACH '(' expr T_AS variable ')' foreach_statement
{ $$ = Stmt_Foreach[expr: $3, keyVar: null, byRef: false, valueVar: $5, stmts: toArray($7)]; }
| T_FOREACH '(' expr T_AS '&' variable ')' foreach_statement
@ -194,9 +194,9 @@ statement:
| T_DECLARE '(' declare_list ')' declare_statement { $$ = Stmt_Declare[declares: $3, stmts: toArray($5)]; }
| ';' { $$ = array(); /* means: no statement */ }
| T_TRY '{' inner_statement_list '}' catches { $$ = Stmt_TryCatch[stmts: $3, catches: $5]; }
| T_THROW expr ';' { $$ = Stmt_Throw[expr: $2]; }
| T_GOTO T_STRING ';' { $$ = Stmt_Goto[name: $2]; }
| T_STRING ':' { $$ = Stmt_Label[name: $1]; }
| T_THROW expr ';' { $$ = Stmt_Throw[$2]; }
| T_GOTO T_STRING ';' { $$ = Stmt_Goto[$2]; }
| T_STRING ':' { $$ = Stmt_Label[$1]; }
;
catches:
@ -384,7 +384,7 @@ class_statement_list:
class_statement:
variable_modifiers class_variable_declaration ';' { $$ = Stmt_Property[type: $1, props: $2]; }
| class_constant_declaration ';' { $$ = Stmt_ClassConst[consts: $1]; }
| class_constant_declaration ';' { $$ = Stmt_ClassConst[$1]; }
| method_modifiers T_FUNCTION optional_ref T_STRING '(' parameter_list ')' method_body
{ $$ = Stmt_ClassMethod[type: $1, byRef: $3, name: $4, params: $6, stmts: $8]; }
;

View File

@ -5,4 +5,19 @@
*/
class PHPParser_Node_Stmt_Break extends PHPParser_Node_Stmt
{
/**
* Constructs a break node.
*
* @param null|PHPParser_Node_Expr $num Number of loops to break
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(PHPParser_Node_Expr $num = null, $line = -1, $docComment = null) {
parent::__construct(
array(
'num' => $num,
),
$line, $docComment
);
}
}

View File

@ -1,8 +1,23 @@
<?php
/**
* @property array $consts Constant declarations
* @property PHPParser_Node_Stmt_ClassConstConst[] $consts Constant declarations
*/
class PHPParser_Node_Stmt_ClassConst extends PHPParser_Node_Stmt
{
/**
* Constructs a class const list node.
*
* @param PHPParser_Node_Stmt_ClassConstConst[] $consts Constant declarations
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(array $consts, $line = -1, $docComment = null) {
parent::__construct(
array(
'consts' => $consts,
),
$line, $docComment
);
}
}

View File

@ -1,8 +1,23 @@
<?php
/**
* @property null|PHPParser_Node_Expr $num Number of loops to break
* @property null|PHPParser_Node_Expr $num Number of loops to continue
*/
class PHPParser_Node_Stmt_Continue extends PHPParser_Node_Stmt
{
/**
* Constructs a continue node.
*
* @param null|PHPParser_Node_Expr $num Number of loops to continue
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(PHPParser_Node_Expr $num = null, $line = -1, $docComment = null) {
parent::__construct(
array(
'num' => $num,
),
$line, $docComment
);
}
}

View File

@ -1,8 +1,23 @@
<?php
/**
* @property array $exprs Expressions
* @property PHPParser_Node_Expr[] $exprs Expressions
*/
class PHPParser_Node_Stmt_Echo extends PHPParser_Node_Stmt
{
/**
* Constructs an echo node.
*
* @param PHPParser_Node_Expr[] $exprs Expressions
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(array $exprs, $line = -1, $docComment = null) {
parent::__construct(
array(
'exprs' => $exprs,
),
$line, $docComment
);
}
}

View File

@ -1,8 +1,23 @@
<?php
/**
* @property array $vars Variables
* @property PHPParser_Node_Expr[] $vars Variables
*/
class PHPParser_Node_Stmt_Global extends PHPParser_Node_Stmt
{
/**
* Constructs a global variables list node.
*
* @param PHPParser_Node_Expr[] $vars Variables to unset
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(array $vars, $line = -1, $docComment = null) {
parent::__construct(
array(
'vars' => $vars,
),
$line, $docComment
);
}
}

View File

@ -1,8 +1,23 @@
<?php
/**
* @property string $name Name
* @property string $name Name of label to jump to
*/
class PHPParser_Node_Stmt_Goto extends PHPParser_Node_Stmt
{
/**
* Constructs a goto node.
*
* @param string $name Name of label to jump to
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($name, $line = -1, $docComment = null) {
parent::__construct(
array(
'name' => $name,
),
$line, $docComment
);
}
}

View File

@ -5,4 +5,19 @@
*/
class PHPParser_Node_Stmt_HaltCompiler extends PHPParser_Node_Stmt
{
/**
* Constructs a __halt_compiler node.
*
* @param string $remaining Remaining text after halt compiler statement.
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($remaining, $line = -1, $docComment = null) {
parent::__construct(
array(
'remaining' => $remaining,
),
$line, $docComment
);
}
}

View File

@ -5,4 +5,19 @@
*/
class PHPParser_Node_Stmt_InlineHTML extends PHPParser_Node_Stmt
{
/**
* Constructs an inline HTML node.
*
* @param string $value String
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($value, $line = -1, $docComment = null) {
parent::__construct(
array(
'value' => $value,
),
$line, $docComment
);
}
}

View File

@ -5,4 +5,19 @@
*/
class PHPParser_Node_Stmt_Label extends PHPParser_Node_Stmt
{
/**
* Constructs a label node.
*
* @param string $name Name
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct($name, $line = -1, $docComment = null) {
parent::__construct(
array(
'name' => $name,
),
$line, $docComment
);
}
}

View File

@ -1,8 +1,23 @@
<?php
/**
* @property PHPParser_Node_Expr $expr Expression
* @property null|PHPParser_Node_Expr $expr Expression
*/
class PHPParser_Node_Stmt_Return extends PHPParser_Node_Stmt
{
/**
* Constructs a return node.
*
* @param null|PHPParser_Node_Expr $expr Expression
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(PHPParser_Node_Expr $expr = null, $line = -1, $docComment = null) {
parent::__construct(
array(
'expr' => $expr,
),
$line, $docComment
);
}
}

View File

@ -1,8 +1,23 @@
<?php
/**
* @property array $vars Variable definitions
* @property PHPParser_Node_Stmts_StaticVar[] $vars Variable definitions
*/
class PHPParser_Node_Stmt_Static extends PHPParser_Node_Stmt
{
/**
* Constructs a static variables list node.
*
* @param PHPParser_Node_Stmts_StaticVar[] $vars Variable definitions
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(array $vars, $line = -1, $docComment = null) {
parent::__construct(
array(
'vars' => $vars,
),
$line, $docComment
);
}
}

View File

@ -5,4 +5,19 @@
*/
class PHPParser_Node_Stmt_Throw extends PHPParser_Node_Stmt
{
/**
* Constructs a throw node.
*
* @param null|PHPParser_Node_Expr $expr Expression
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(PHPParser_Node_Expr $expr, $line = -1, $docComment = null) {
parent::__construct(
array(
'expr' => $expr,
),
$line, $docComment
);
}
}

View File

@ -1,8 +1,23 @@
<?php
/**
* @property array $vars Variables to unset
* @property PHPParser_Node_Expr[] $vars Variables to unset
*/
class PHPParser_Node_Stmt_Unset extends PHPParser_Node_Stmt
{
/**
* Constructs an unset node.
*
* @param PHPParser_Node_Expr[] $vars Variables to unset
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(array $vars, $line = -1, $docComment = null) {
parent::__construct(
array(
'vars' => $vars,
),
$line, $docComment
);
}
}

View File

@ -1,8 +1,23 @@
<?php
/**
* @property array $uses Aliases
* @property PHPParser_Node_Stmt_UseUse[] $uses Aliases
*/
class PHPParser_Node_Stmt_Use extends PHPParser_Node_Stmt
{
/**
* Constructs an alias (use) node.
*
* @param PHPParser_Node_Stmt_UseUse[] $uses Aliases
* @param int $line Line
* @param null|string $docComment Nearest doc comment
*/
public function __construct(array $uses, $line = -1, $docComment = null) {
parent::__construct(
array(
'uses' => $uses,
),
$line, $docComment
);
}
}

View File

@ -1020,7 +1020,7 @@ class PHPParser_Parser
}
protected function yyn10($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_HaltCompiler(array('remaining' => $this->lexer->handleHaltCompiler()), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_HaltCompiler($this->lexer->handleHaltCompiler(), $line, $docComment);
}
protected function yyn11($line, $docComment) {
@ -1036,11 +1036,11 @@ class PHPParser_Parser
}
protected function yyn14($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Use(array('uses' => $this->yyastk[$this->yysp-(3-2)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Use($this->yyastk[$this->yysp-(3-2)], $line, $docComment);
}
protected function yyn15($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Const(array('consts' => $this->yyastk[$this->yysp-(2-1)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Const($this->yyastk[$this->yysp-(2-1)], $line, $docComment);
}
protected function yyn16($line, $docComment) {
@ -1128,43 +1128,43 @@ class PHPParser_Parser
}
protected function yyn37($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Break(array('num' => null), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Break(null, $line, $docComment);
}
protected function yyn38($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Break(array('num' => $this->yyastk[$this->yysp-(3-2)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Break($this->yyastk[$this->yysp-(3-2)], $line, $docComment);
}
protected function yyn39($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Continue(array('num' => null), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Continue(null, $line, $docComment);
}
protected function yyn40($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Continue(array('num' => $this->yyastk[$this->yysp-(3-2)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Continue($this->yyastk[$this->yysp-(3-2)], $line, $docComment);
}
protected function yyn41($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Return(array('expr' => null), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Return(null, $line, $docComment);
}
protected function yyn42($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Return(array('expr' => $this->yyastk[$this->yysp-(3-2)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Return($this->yyastk[$this->yysp-(3-2)], $line, $docComment);
}
protected function yyn43($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Global(array('vars' => $this->yyastk[$this->yysp-(3-2)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Global($this->yyastk[$this->yysp-(3-2)], $line, $docComment);
}
protected function yyn44($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Static(array('vars' => $this->yyastk[$this->yysp-(3-2)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Static($this->yyastk[$this->yysp-(3-2)], $line, $docComment);
}
protected function yyn45($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Echo(array('exprs' => $this->yyastk[$this->yysp-(3-2)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Echo($this->yyastk[$this->yysp-(3-2)], $line, $docComment);
}
protected function yyn46($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_InlineHTML(array('value' => $this->yyastk[$this->yysp-(1-1)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_InlineHTML($this->yyastk[$this->yysp-(1-1)], $line, $docComment);
}
protected function yyn47($line, $docComment) {
@ -1172,7 +1172,7 @@ class PHPParser_Parser
}
protected function yyn48($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Unset(array('vars' => $this->yyastk[$this->yysp-(5-3)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Unset($this->yyastk[$this->yysp-(5-3)], $line, $docComment);
}
protected function yyn49($line, $docComment) {
@ -1200,15 +1200,15 @@ class PHPParser_Parser
}
protected function yyn55($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Throw(array('expr' => $this->yyastk[$this->yysp-(3-2)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Throw($this->yyastk[$this->yysp-(3-2)], $line, $docComment);
}
protected function yyn56($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Goto(array('name' => $this->yyastk[$this->yysp-(3-2)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Goto($this->yyastk[$this->yysp-(3-2)], $line, $docComment);
}
protected function yyn57($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_Label(array('name' => $this->yyastk[$this->yysp-(2-1)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_Label($this->yyastk[$this->yysp-(2-1)], $line, $docComment);
}
protected function yyn58($line, $docComment) {
@ -1512,7 +1512,7 @@ class PHPParser_Parser
}
protected function yyn133($line, $docComment) {
$this->yyval = new PHPParser_Node_Stmt_ClassConst(array('consts' => $this->yyastk[$this->yysp-(2-1)]), $line, $docComment);
$this->yyval = new PHPParser_Node_Stmt_ClassConst($this->yyastk[$this->yysp-(2-1)], $line, $docComment);
}
protected function yyn134($line, $docComment) {