mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-30 04:19:30 +01:00
Represent builtin types using Identifier as well
This commit is contained in:
parent
6bcc6c31dd
commit
122f449960
@ -380,8 +380,8 @@ parameter:
|
||||
|
||||
type:
|
||||
name { $$ = $1; }
|
||||
| T_ARRAY { $$ = 'array'; }
|
||||
| T_CALLABLE { $$ = 'callable'; }
|
||||
| T_ARRAY { $$ = makeIdent('array'); }
|
||||
| T_CALLABLE { $$ = makeIdent('callable'); }
|
||||
;
|
||||
|
||||
optional_param_type:
|
||||
|
@ -387,8 +387,8 @@ type_expr:
|
||||
|
||||
type:
|
||||
name { $$ = $this->handleBuiltinTypes($1); }
|
||||
| T_ARRAY { $$ = 'array'; }
|
||||
| T_CALLABLE { $$ = 'callable'; }
|
||||
| T_ARRAY { $$ = makeIdent('array'); }
|
||||
| T_CALLABLE { $$ = makeIdent('callable'); }
|
||||
;
|
||||
|
||||
optional_param_type:
|
||||
|
@ -1819,11 +1819,11 @@ class Php5 extends \PhpParser\ParserAbstract
|
||||
}
|
||||
|
||||
protected function reduceRule227() {
|
||||
$this->semValue = 'array';
|
||||
$this->semValue = ($this->useIdentifierNodes ? new Node\Identifier('array', $this->startAttributeStack[$this->stackPos-(1-1)] + $this->endAttributes) : 'array');
|
||||
}
|
||||
|
||||
protected function reduceRule228() {
|
||||
$this->semValue = 'callable';
|
||||
$this->semValue = ($this->useIdentifierNodes ? new Node\Identifier('callable', $this->startAttributeStack[$this->stackPos-(1-1)] + $this->endAttributes) : 'callable');
|
||||
}
|
||||
|
||||
protected function reduceRule229() {
|
||||
|
@ -1726,11 +1726,11 @@ class Php7 extends \PhpParser\ParserAbstract
|
||||
}
|
||||
|
||||
protected function reduceRule228() {
|
||||
$this->semValue = 'array';
|
||||
$this->semValue = ($this->useIdentifierNodes ? new Node\Identifier('array', $this->startAttributeStack[$this->stackPos-(1-1)] + $this->endAttributes) : 'array');
|
||||
}
|
||||
|
||||
protected function reduceRule229() {
|
||||
$this->semValue = 'callable';
|
||||
$this->semValue = ($this->useIdentifierNodes ? new Node\Identifier('callable', $this->startAttributeStack[$this->stackPos-(1-1)] + $this->endAttributes) : 'callable');
|
||||
}
|
||||
|
||||
protected function reduceRule230() {
|
||||
|
@ -539,7 +539,13 @@ abstract class ParserAbstract implements Parser
|
||||
}
|
||||
|
||||
$lowerName = strtolower($name->toString());
|
||||
return isset($scalarTypes[$lowerName]) ? $lowerName : $name;
|
||||
if (!isset($scalarTypes[$lowerName])) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
return $this->useIdentifierNodes
|
||||
? new Node\Identifier($lowerName, $name->getAttributes())
|
||||
: $lowerName;
|
||||
}
|
||||
|
||||
protected static $specialNames = array(
|
||||
|
@ -16,7 +16,7 @@ class Foo {
|
||||
interface Bar {}
|
||||
trait Baz {}
|
||||
|
||||
function foo() {}
|
||||
function foo(array $x) : callable {}
|
||||
|
||||
const FOO = 1;
|
||||
|
||||
@ -148,8 +148,19 @@ array(
|
||||
name: foo
|
||||
)
|
||||
params: array(
|
||||
0: Param(
|
||||
type: Identifier(
|
||||
name: array
|
||||
)
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: x
|
||||
default: null
|
||||
)
|
||||
)
|
||||
returnType: Identifier(
|
||||
name: callable
|
||||
)
|
||||
returnType: null
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
@ -243,4 +254,34 @@ array(
|
||||
14: Expr_Variable(
|
||||
name: foo
|
||||
)
|
||||
)
|
||||
-----
|
||||
<?php
|
||||
|
||||
function foo(int $bar) : bool {}
|
||||
-----
|
||||
!!php7,ident
|
||||
array(
|
||||
0: Stmt_Function(
|
||||
byRef: false
|
||||
name: Identifier(
|
||||
name: foo
|
||||
)
|
||||
params: array(
|
||||
0: Param(
|
||||
type: Identifier(
|
||||
name: int
|
||||
)
|
||||
byRef: false
|
||||
variadic: false
|
||||
name: bar
|
||||
default: null
|
||||
)
|
||||
)
|
||||
returnType: Identifier(
|
||||
name: bool
|
||||
)
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
)
|
Loading…
Reference in New Issue
Block a user