Compare commits

...

6 Commits

Author SHA1 Message Date
adf44419c0 Release PHP-Parser 3.0.2 2016-12-06 12:30:35 +01:00
5219f75719 Fix pretty-printing of nullable types 2016-12-06 12:26:21 +01:00
a485ecd7ba NameResolver - resolve Name in NullableType 2016-12-06 12:21:30 +01:00
030de805e1 Add NullableType to types of properties/args that offer it (#323) 2016-12-05 13:30:29 +01:00
aa6aec90e1 Release PHP-Parser 3.0.1 2016-12-01 13:37:30 +01:00
3e158a2313 Wrap List_ in ArrayItem
This was correctly done for the 'key'=>list() form, but not for
unkeyed nested lists.
2016-12-01 13:32:37 +01:00
19 changed files with 78 additions and 38 deletions

View File

@ -1,8 +1,25 @@
Version 3.0.1-dev Version 3.0.3-dev
----------------- -----------------
Nothing yet. Nothing yet.
Version 3.0.2 (2016-12-06)
--------------------------
### Fixed
* Fixed name resolution of nullable types.
* Fixed pretty-printing of nullable types.
Version 3.0.1 (2016-12-01)
--------------------------
### Fixed
* Fixed handling of nested `list()`s: If the nested list was unkeyed, it was directly included in
the list items. If it was keyed, it was wrapped in `ArrayItem`. Now nested `List_` nodes are
always wrapped in `ArrayItem`s.
Version 3.0.0 (2016-11-30) Version 3.0.0 (2016-11-30)
-------------------------- --------------------------

View File

@ -939,7 +939,7 @@ list_expr_elements:
list_expr_element: list_expr_element:
variable { $$ = Expr\ArrayItem[$1, null, false]; } variable { $$ = Expr\ArrayItem[$1, null, false]; }
| list_expr { $$ = $1; } | list_expr { $$ = Expr\ArrayItem[$1, null, false]; }
| /* empty */ { $$ = null; } | /* empty */ { $$ = null; }
; ;

View File

@ -823,7 +823,7 @@ list_expr_elements:
list_expr_element: list_expr_element:
variable { $$ = Expr\ArrayItem[$1, null, false]; } variable { $$ = Expr\ArrayItem[$1, null, false]; }
| list_expr { $$ = $1; } | list_expr { $$ = Expr\ArrayItem[$1, null, false]; }
| expr T_DOUBLE_ARROW variable { $$ = Expr\ArrayItem[$3, $1, false]; } | expr T_DOUBLE_ARROW variable { $$ = Expr\ArrayItem[$3, $1, false]; }
| expr T_DOUBLE_ARROW list_expr { $$ = Expr\ArrayItem[$3, $1, false]; } | expr T_DOUBLE_ARROW list_expr { $$ = Expr\ArrayItem[$3, $1, false]; }
| /* empty */ { $$ = null; } | /* empty */ { $$ = null; }

View File

@ -9,6 +9,8 @@ abstract class FunctionLike extends Declaration
{ {
protected $returnByRef = false; protected $returnByRef = false;
protected $params = array(); protected $params = array();
/** @var string|Node\Name|Node\NullableType|null */
protected $returnType = null; protected $returnType = null;
/** /**
@ -59,7 +61,7 @@ abstract class FunctionLike extends Declaration
/** /**
* Sets the return type for PHP 7. * Sets the return type for PHP 7.
* *
* @param string|Node\Name $type One of array, callable, string, int, float, bool, iterable, * @param string|Node\Name|Node\NullableType $type One of array, callable, string, int, float, bool, iterable,
* or a class/interface name. * or a class/interface name.
* *
* @return $this The builder instance (for fluid interface) * @return $this The builder instance (for fluid interface)

View File

@ -10,6 +10,8 @@ class Method extends FunctionLike
{ {
protected $name; protected $name;
protected $flags = 0; protected $flags = 0;
/** @var array|null */
protected $stmts = array(); protected $stmts = array();
/** /**

View File

@ -10,7 +10,10 @@ class Param extends PhpParser\BuilderAbstract
protected $name; protected $name;
protected $default = null; protected $default = null;
/** @var string|Node\Name|Node\NullableType|null */
protected $type = null; protected $type = null;
protected $byRef = false; protected $byRef = false;
/** /**
@ -38,7 +41,7 @@ class Param extends PhpParser\BuilderAbstract
/** /**
* Sets type hint for the parameter. * Sets type hint for the parameter.
* *
* @param string|Node\Name $type Type hint to use * @param string|Node\Name|Node\NullableType $type Type hint to use
* *
* @return $this The builder instance (for fluid interface) * @return $this The builder instance (for fluid interface)
*/ */

View File

@ -60,9 +60,9 @@ abstract class BuilderAbstract implements Builder {
* In particular, builtin types are left as strings, custom types become Names and nullables * In particular, builtin types are left as strings, custom types become Names and nullables
* are wrapped in NullableType nodes. * are wrapped in NullableType nodes.
* *
* @param Name|string $type The type to normalize * @param Name|string|NullableType $type The type to normalize
* *
* @return Name|string The normalized type * @return Name|string|NullableType The normalized type
*/ */
protected function normalizeType($type) { protected function normalizeType($type) {
if (!is_string($type)) { if (!is_string($type)) {

View File

@ -16,7 +16,7 @@ class Closure extends Expr implements FunctionLike
public $params; public $params;
/** @var ClosureUse[] use()s */ /** @var ClosureUse[] use()s */
public $uses; public $uses;
/** @var null|string|Node\Name Return type */ /** @var null|string|Node\Name|Node\NullableType Return type */
public $returnType; public $returnType;
/** @var Node[] Statements */ /** @var Node[] Statements */
public $stmts; public $stmts;

View File

@ -23,7 +23,7 @@ interface FunctionLike extends Node
/** /**
* Get the declared return type or null * Get the declared return type or null
* *
* @return null|string|Node\Name * @return null|string|Node\Name|Node\NullableType
*/ */
public function getReturnType(); public function getReturnType();

View File

@ -6,7 +6,7 @@ use PhpParser\NodeAbstract;
class Param extends NodeAbstract class Param extends NodeAbstract
{ {
/** @var null|string|Name Typehint */ /** @var null|string|Name|NullableType Typehint */
public $type; public $type;
/** @var bool Whether parameter is passed by reference */ /** @var bool Whether parameter is passed by reference */
public $byRef; public $byRef;
@ -20,12 +20,12 @@ class Param extends NodeAbstract
/** /**
* Constructs a parameter node. * Constructs a parameter node.
* *
* @param string $name Name * @param string $name Name
* @param null|Expr $default Default value * @param null|Expr $default Default value
* @param null|string|Name $type Typehint * @param null|string|Name|NullableType $type Typehint
* @param bool $byRef Whether is passed by reference * @param bool $byRef Whether is passed by reference
* @param bool $variadic Whether this is a variadic argument * @param bool $variadic Whether this is a variadic argument
* @param array $attributes Additional attributes * @param array $attributes Additional attributes
*/ */
public function __construct($name, Expr $default = null, $type = null, $byRef = false, $variadic = false, array $attributes = array()) { public function __construct($name, Expr $default = null, $type = null, $byRef = false, $variadic = false, array $attributes = array()) {
parent::__construct($attributes); parent::__construct($attributes);

View File

@ -15,7 +15,7 @@ class ClassMethod extends Node\Stmt implements FunctionLike
public $name; public $name;
/** @var Node\Param[] Parameters */ /** @var Node\Param[] Parameters */
public $params; public $params;
/** @var null|string|Node\Name Return type */ /** @var null|string|Node\Name|Node\NullableType Return type */
public $returnType; public $returnType;
/** @var Node[] Statements */ /** @var Node[] Statements */
public $stmts; public $stmts;

View File

@ -13,7 +13,7 @@ class Function_ extends Node\Stmt implements FunctionLike
public $name; public $name;
/** @var Node\Param[] Parameters */ /** @var Node\Param[] Parameters */
public $params; public $params;
/** @var null|string|Node\Name Return type */ /** @var null|string|Node\Name|Node\NullableType Return type */
public $returnType; public $returnType;
/** @var Node[] Statements */ /** @var Node[] Statements */
public $stmts; public $stmts;

View File

@ -112,7 +112,10 @@ class NameResolver extends NodeVisitorAbstract
} }
} }
} }
} elseif ($node instanceof Node\NullableType) {
if ($node->type instanceof Name) {
$node->type = $this->resolveClassName($node->type);
}
} }
} }

View File

@ -3035,7 +3035,7 @@ class Php5 extends \PhpParser\ParserAbstract
} }
protected function reduceRule523() { protected function reduceRule523() {
$this->semValue = $this->semStack[$this->stackPos-(1-1)]; $this->semValue = new Expr\ArrayItem($this->semStack[$this->stackPos-(1-1)], null, false, $this->startAttributeStack[$this->stackPos-(1-1)] + $this->endAttributes);
} }
protected function reduceRule524() { protected function reduceRule524() {

View File

@ -2657,7 +2657,7 @@ class Php7 extends \PhpParser\ParserAbstract
} }
protected function reduceRule460() { protected function reduceRule460() {
$this->semValue = $this->semStack[$this->stackPos-(1-1)]; $this->semValue = new Expr\ArrayItem($this->semStack[$this->stackPos-(1-1)], null, false, $this->startAttributeStack[$this->stackPos-(1-1)] + $this->endAttributes);
} }
protected function reduceRule461() { protected function reduceRule461() {

View File

@ -34,7 +34,7 @@ class Standard extends PrettyPrinterAbstract
} }
protected function pNullableType(Node\NullableType $node) { protected function pNullableType(Node\NullableType $node) {
return '?' . $node->type; return '?' . $this->pType($node->type);
} }
// Names // Names

View File

@ -199,9 +199,12 @@ interface A extends C, D {
public function a(A $a) : A; public function a(A $a) : A;
} }
function fn() : A {} function fn(A $a) : A {}
function fn2() : array {} function fn2(array $a) : array {}
function() : A {}; function(A $a) : A {};
function fn3(?A $a) : ?A {}
function fn4(?array $a) : ?array {}
A::b(); A::b();
A::$b; A::$b;
@ -233,14 +236,20 @@ interface A extends \NS\C, \NS\D
{ {
public function a(\NS\A $a) : \NS\A; public function a(\NS\A $a) : \NS\A;
} }
function fn() : \NS\A function fn(\NS\A $a) : \NS\A
{ {
} }
function fn2() : array function fn2(array $a) : array
{ {
} }
function () : \NS\A { function (\NS\A $a) : \NS\A {
}; };
function fn3(?\NS\A $a) : ?\NS\A
{
}
function fn4(?array $a) : ?array
{
}
\NS\A::b(); \NS\A::b();
\NS\A::$b; \NS\A::$b;
\NS\A::B; \NS\A::B;

View File

@ -246,17 +246,21 @@ array(
) )
byRef: false byRef: false
) )
1: Expr_List( 1: Expr_ArrayItem(
items: array( key: null
0: null value: Expr_List(
1: Expr_ArrayItem( items: array(
key: null 0: null
value: Expr_Variable( 1: Expr_ArrayItem(
name: c key: null
value: Expr_Variable(
name: c
)
byRef: false
) )
byRef: false
) )
) )
byRef: false
) )
2: Expr_ArrayItem( 2: Expr_ArrayItem(
key: null key: null

View File

@ -1,11 +1,11 @@
Nullable types Nullable types
----- -----
<?php <?php
function test(?Foo $bar, ?string $foo) : ?Baz function test(?Foo $bar, ?string $foo, ?\Xyz $zyx) : ?Baz
{ {
} }
----- -----
!!php7 !!php7
function test(?Foo $bar, ?string $foo) : ?Baz function test(?Foo $bar, ?string $foo, ?\Xyz $zyx) : ?Baz
{ {
} }