Skip to content

Commit

Permalink
SubNodeNames are known at static analysis time
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Oct 10, 2024
1 parent 8eea230 commit a73955f
Show file tree
Hide file tree
Showing 110 changed files with 660 additions and 125 deletions.
7 changes: 6 additions & 1 deletion lib/PhpParser/Internal/PrintableNewAnonClassNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class PrintableNewAnonClassNode extends Expr {
/** @var Node\Stmt[] Statements */
public array $stmts;

private const SUBNODE_NAMES = ['attrGroups', 'flags', 'args', 'extends', 'implements', 'stmts'];

/**
* @param Node\AttributeGroup[] $attrGroups PHP attribute groups
* @param (Node\Arg|Node\VariadicPlaceholder)[] $args Arguments
Expand Down Expand Up @@ -65,7 +67,10 @@ public function getType(): string {
return 'Expr_PrintableNewAnonClass';
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['attrGroups', 'flags', 'args', 'extends', 'implements', 'stmts'];
return self::SUBNODE_NAMES;
}
}
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/Arg.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Arg extends NodeAbstract {
/** @var bool Whether to unpack the argument */
public bool $unpack;

private const SUBNODE_NAMES = ['name', 'value', 'byRef', 'unpack'];

/**
* Constructs a function call argument node.
*
Expand All @@ -34,8 +36,11 @@ public function __construct(
$this->unpack = $unpack;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['name', 'value', 'byRef', 'unpack'];
return self::SUBNODE_NAMES;
}

public function getType(): string {
Expand Down
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/ArrayItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class ArrayItem extends NodeAbstract {
/** @var bool Whether to unpack the argument */
public bool $unpack;

private const SUBNODE_NAMES = ['key', 'value', 'byRef', 'unpack'];

/**
* Constructs an array item node.
*
Expand All @@ -30,8 +32,11 @@ public function __construct(Expr $value, ?Expr $key = null, bool $byRef = false,
$this->unpack = $unpack;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['key', 'value', 'byRef', 'unpack'];
return self::SUBNODE_NAMES;
}

public function getType(): string {
Expand Down
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Attribute extends NodeAbstract {
/** @var list<Arg> Attribute arguments */
public array $args;

private const SUBNODE_NAMES = ['name', 'args'];

/**
* @param Node\Name $name Attribute name
* @param list<Arg> $args Attribute arguments
Expand All @@ -23,8 +25,11 @@ public function __construct(Name $name, array $args = [], array $attributes = []
$this->args = $args;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['name', 'args'];
return self::SUBNODE_NAMES;
}

public function getType(): string {
Expand Down
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/AttributeGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class AttributeGroup extends NodeAbstract {
/** @var Attribute[] Attributes */
public array $attrs;

private const SUBNODE_NAMES = ['attrs'];

/**
* @param Attribute[] $attrs PHP attributes
* @param array<string, mixed> $attributes Additional node attributes
Expand All @@ -17,8 +19,11 @@ public function __construct(array $attrs, array $attributes = []) {
$this->attrs = $attrs;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['attrs'];
return self::SUBNODE_NAMES;
}

public function getType(): string {
Expand Down
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/ClosureUse.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class ClosureUse extends NodeAbstract {
/** @var bool Whether to use by reference */
public bool $byRef;

private const SUBNODE_NAMES = ['var', 'byRef'];

/**
* Constructs a closure use node.
*
Expand All @@ -23,8 +25,11 @@ public function __construct(Expr\Variable $var, bool $byRef = false, array $attr
$this->byRef = $byRef;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['var', 'byRef'];
return self::SUBNODE_NAMES;
}

public function getType(): string {
Expand Down
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/Const_.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Const_ extends NodeAbstract {
/** @var Name|null Namespaced name (if using NameResolver) */
public ?Name $namespacedName;

private const SUBNODE_NAMES = ['name', 'value'];

/**
* Constructs a const node for use in class const and const statements.
*
Expand All @@ -26,8 +28,11 @@ public function __construct($name, Expr $value, array $attributes = []) {
$this->value = $value;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['name', 'value'];
return self::SUBNODE_NAMES;
}

public function getType(): string {
Expand Down
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/DeclareItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class DeclareItem extends NodeAbstract {
/** @var Node\Expr Value */
public Expr $value;

private const SUBNODE_NAMES = ['key', 'value'];

/**
* Constructs a declare key=>value pair node.
*
Expand All @@ -24,8 +26,11 @@ public function __construct($key, Node\Expr $value, array $attributes = []) {
$this->value = $value;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['key', 'value'];
return self::SUBNODE_NAMES;
}

public function getType(): string {
Expand Down
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/Expr/ArrayDimFetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class ArrayDimFetch extends Expr {
/** @var null|Expr Array index / dim */
public ?Expr $dim;

private const SUBNODE_NAMES = ['var', 'dim'];

/**
* Constructs an array index fetch node.
*
Expand All @@ -23,8 +25,11 @@ public function __construct(Expr $var, ?Expr $dim = null, array $attributes = []
$this->dim = $dim;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['var', 'dim'];
return self::SUBNODE_NAMES;
}

public function getType(): string {
Expand Down
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/Expr/Array_.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Array_ extends Expr {
/** @var ArrayItem[] Items */
public array $items;

private const SUBNODE_NAMES = ['items'];

/**
* Constructs an array node.
*
Expand All @@ -24,8 +26,11 @@ public function __construct(array $items = [], array $attributes = []) {
$this->items = $items;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['items'];
return self::SUBNODE_NAMES;
}

public function getType(): string {
Expand Down
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/Expr/ArrowFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ArrowFunction extends Expr implements FunctionLike {
/** @var Node\AttributeGroup[] */
public array $attrGroups;

private const SUBNODE_NAMES = ['attrGroups', 'static', 'byRef', 'params', 'returnType', 'expr'];

/**
* @param array{
* expr: Expr,
Expand Down Expand Up @@ -51,8 +53,11 @@ public function __construct(array $subNodes, array $attributes = []) {
$this->attrGroups = $subNodes['attrGroups'] ?? [];
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['attrGroups', 'static', 'byRef', 'params', 'returnType', 'expr'];
return self::SUBNODE_NAMES;
}

public function returnsByRef(): bool {
Expand Down
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/Expr/Assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Assign extends Expr {
/** @var Expr Expression */
public Expr $expr;

private const SUBNODE_NAMES = ['var', 'expr'];

/**
* Constructs an assignment node.
*
Expand All @@ -23,8 +25,11 @@ public function __construct(Expr $var, Expr $expr, array $attributes = []) {
$this->expr = $expr;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['var', 'expr'];
return self::SUBNODE_NAMES;
}

public function getType(): string {
Expand Down
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/Expr/AssignOp.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ abstract class AssignOp extends Expr {
/** @var Expr Expression */
public Expr $expr;

private const SUBNODE_NAMES = ['var', 'expr'];

/**
* Constructs a compound assignment operation node.
*
Expand All @@ -23,7 +25,10 @@ public function __construct(Expr $var, Expr $expr, array $attributes = []) {
$this->expr = $expr;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['var', 'expr'];
return self::SUBNODE_NAMES;
}
}
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/Expr/AssignRef.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class AssignRef extends Expr {
/** @var Expr Variable which is referenced */
public Expr $expr;

private const SUBNODE_NAMES = ['var', 'expr'];

/**
* Constructs an assignment node.
*
Expand All @@ -23,8 +25,11 @@ public function __construct(Expr $var, Expr $expr, array $attributes = []) {
$this->expr = $expr;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['var', 'expr'];
return self::SUBNODE_NAMES;
}

public function getType(): string {
Expand Down
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/Expr/BinaryOp.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ abstract class BinaryOp extends Expr {
/** @var Expr The right hand side expression */
public Expr $right;

private const SUBNODE_NAMES = ['left', 'right'];

/**
* Constructs a binary operator node.
*
Expand All @@ -23,8 +25,11 @@ public function __construct(Expr $left, Expr $right, array $attributes = []) {
$this->right = $right;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['left', 'right'];
return self::SUBNODE_NAMES;
}

/**
Expand Down
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/Expr/BitwiseNot.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class BitwiseNot extends Expr {
/** @var Expr Expression */
public Expr $expr;

private const SUBNODE_NAMES = ['expr'];

/**
* Constructs a bitwise not node.
*
Expand All @@ -19,8 +21,11 @@ public function __construct(Expr $expr, array $attributes = []) {
$this->expr = $expr;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['expr'];
return self::SUBNODE_NAMES;
}

public function getType(): string {
Expand Down
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/Expr/BooleanNot.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class BooleanNot extends Expr {
/** @var Expr Expression */
public Expr $expr;

private const SUBNODE_NAMES = ['expr'];

/**
* Constructs a boolean not node.
*
Expand All @@ -19,8 +21,11 @@ public function __construct(Expr $expr, array $attributes = []) {
$this->expr = $expr;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['expr'];
return self::SUBNODE_NAMES;
}

public function getType(): string {
Expand Down
7 changes: 6 additions & 1 deletion lib/PhpParser/Node/Expr/Cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ abstract class Cast extends Expr {
/** @var Expr Expression */
public Expr $expr;

private const SUBNODE_NAMES = ['expr'];

/**
* Constructs a cast node.
*
Expand All @@ -19,7 +21,10 @@ public function __construct(Expr $expr, array $attributes = []) {
$this->expr = $expr;
}

/**
* @return self::SUBNODE_NAMES
*/
public function getSubNodeNames(): array {
return ['expr'];
return self::SUBNODE_NAMES;
}
}
Loading

0 comments on commit a73955f

Please sign in to comment.