mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-06-25 17:43:47 +02:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
1bd73cc04c | |||
94d93f27a5 | |||
a167aa2061 | |||
993f29906b | |||
9d44edf85d | |||
aa97a9bb69 | |||
aa72c5d674 | |||
60d025a914 | |||
b2cecec6bc | |||
8012faea54 | |||
f3b19c19ef | |||
78d9985d11 | |||
57b8673ea7 |
@ -16,7 +16,7 @@ php:
|
||||
|
||||
install:
|
||||
- if [ $TRAVIS_PHP_VERSION = '7.0' ]; then composer require satooshi/php-coveralls '~1.0'; fi
|
||||
- composer install --prefer-dist
|
||||
- composer install --prefer-dist --ignore-platform-reqs
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
|
21
CHANGELOG.md
21
CHANGELOG.md
@ -1,8 +1,27 @@
|
||||
Version 4.2.2-dev
|
||||
Version 4.2.3-dev
|
||||
-----------------
|
||||
|
||||
Nothing yet.
|
||||
|
||||
Version 4.2.2 (2019-05-25)
|
||||
--------------------------
|
||||
|
||||
### Added
|
||||
|
||||
* [PHP 7.4] Add support for arrow functions using a new `Expr\ArrowFunction` node. (#602)
|
||||
* [PHP 7.4] Add support for array spreads, using a new `unpack` subnode on `ArrayItem`. (#609)
|
||||
* Added support for inserting into empty list nodes in the formatting preserving pretty printer.
|
||||
|
||||
### Changed
|
||||
|
||||
* `php-parse` will now print messages to stderr, so that stdout only contains the actual result of
|
||||
the operation (such as a JSON dump). (#605)
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed attribute assignment for zero-length nop statements, and a related assertion failure in
|
||||
the formatting-preserving pretty printer. (#589)
|
||||
|
||||
Version 4.2.1 (2019-02-16)
|
||||
--------------------------
|
||||
|
||||
|
@ -45,14 +45,15 @@ $traverser->addVisitor(new PhpParser\NodeVisitor\NameResolver);
|
||||
foreach ($files as $file) {
|
||||
if (strpos($file, '<?php') === 0) {
|
||||
$code = $file;
|
||||
echo "====> Code $code\n";
|
||||
fwrite(STDERR, "====> Code $code\n");
|
||||
} else {
|
||||
if (!file_exists($file)) {
|
||||
die("File $file does not exist.\n");
|
||||
fwrite(STDERR, "File $file does not exist.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$code = file_get_contents($file);
|
||||
echo "====> File $file:\n";
|
||||
fwrite(STDERR, "====> File $file:\n");
|
||||
}
|
||||
|
||||
if ($attributes['with-recovery']) {
|
||||
@ -60,7 +61,7 @@ foreach ($files as $file) {
|
||||
$stmts = $parser->parse($code, $errorHandler);
|
||||
foreach ($errorHandler->getErrors() as $error) {
|
||||
$message = formatErrorMessage($error, $code, $attributes['with-column-info']);
|
||||
echo $message . "\n";
|
||||
fwrite(STDERR, $message . "\n");
|
||||
}
|
||||
if (null === $stmts) {
|
||||
continue;
|
||||
@ -70,25 +71,26 @@ foreach ($files as $file) {
|
||||
$stmts = $parser->parse($code);
|
||||
} catch (PhpParser\Error $error) {
|
||||
$message = formatErrorMessage($error, $code, $attributes['with-column-info']);
|
||||
die($message . "\n");
|
||||
fwrite(STDERR, $message . "\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($operations as $operation) {
|
||||
if ('dump' === $operation) {
|
||||
echo "==> Node dump:\n";
|
||||
fwrite(STDERR, "==> Node dump:\n");
|
||||
echo $dumper->dump($stmts, $code), "\n";
|
||||
} elseif ('pretty-print' === $operation) {
|
||||
echo "==> Pretty print:\n";
|
||||
fwrite(STDERR, "==> Pretty print:\n");
|
||||
echo $prettyPrinter->prettyPrintFile($stmts), "\n";
|
||||
} elseif ('json-dump' === $operation) {
|
||||
echo "==> JSON dump:\n";
|
||||
fwrite(STDERR, "==> JSON dump:\n");
|
||||
echo json_encode($stmts, JSON_PRETTY_PRINT), "\n";
|
||||
} elseif ('var-dump' === $operation) {
|
||||
echo "==> var_dump():\n";
|
||||
fwrite(STDERR, "==> var_dump():\n");
|
||||
var_dump($stmts);
|
||||
} elseif ('resolve-names' === $operation) {
|
||||
echo "==> Resolved names.\n";
|
||||
fwrite(STDERR, "==> Resolved names.\n");
|
||||
$stmts = $traverser->traverse($stmts);
|
||||
}
|
||||
}
|
||||
@ -104,9 +106,9 @@ function formatErrorMessage(PhpParser\Error $e, $code, $withColumnInfo) {
|
||||
|
||||
function showHelp($error = '') {
|
||||
if ($error) {
|
||||
echo $error . "\n\n";
|
||||
fwrite(STDERR, $error . "\n\n");
|
||||
}
|
||||
die(<<<OUTPUT
|
||||
fwrite($error ? STDERR : STDOUT, <<<OUTPUT
|
||||
Usage: php-parse [operations] file1.php [file2.php ...]
|
||||
or: php-parse [operations] "<?php code"
|
||||
Turn PHP source code into an abstract syntax tree.
|
||||
@ -131,6 +133,7 @@ Example:
|
||||
|
||||
OUTPUT
|
||||
);
|
||||
exit($error ? 1 : 0);
|
||||
}
|
||||
|
||||
function parseArgs($args) {
|
||||
|
@ -16,7 +16,7 @@ top_statement_list_ex:
|
||||
|
||||
top_statement_list:
|
||||
top_statement_list_ex
|
||||
{ makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
|
||||
{ makeZeroLengthNop($nop, $this->lookaheadStartAttributes);
|
||||
if ($nop !== null) { $1[] = $nop; } $$ = $1; }
|
||||
;
|
||||
|
||||
@ -27,7 +27,7 @@ reserved_non_modifiers:
|
||||
| T_FINALLY | T_THROW | T_USE | T_INSTEADOF | T_GLOBAL | T_VAR | T_UNSET | T_ISSET | T_EMPTY | T_CONTINUE | T_GOTO
|
||||
| T_FUNCTION | T_CONST | T_RETURN | T_PRINT | T_YIELD | T_LIST | T_SWITCH | T_ENDSWITCH | T_CASE | T_DEFAULT
|
||||
| T_BREAK | T_ARRAY | T_CALLABLE | T_EXTENDS | T_IMPLEMENTS | T_NAMESPACE | T_TRAIT | T_INTERFACE | T_CLASS
|
||||
| T_CLASS_C | T_TRAIT_C | T_FUNC_C | T_METHOD_C | T_LINE | T_FILE | T_DIR | T_NS_C | T_HALT_COMPILER
|
||||
| T_CLASS_C | T_TRAIT_C | T_FUNC_C | T_METHOD_C | T_LINE | T_FILE | T_DIR | T_NS_C | T_HALT_COMPILER | T_FN
|
||||
;
|
||||
|
||||
semi_reserved:
|
||||
@ -160,7 +160,7 @@ inner_statement_list_ex:
|
||||
|
||||
inner_statement_list:
|
||||
inner_statement_list_ex
|
||||
{ makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
|
||||
{ makeZeroLengthNop($nop, $this->lookaheadStartAttributes);
|
||||
if ($nop !== null) { $1[] = $nop; } $$ = $1; }
|
||||
;
|
||||
|
||||
@ -461,7 +461,7 @@ class_statement_list_ex:
|
||||
|
||||
class_statement_list:
|
||||
class_statement_list_ex
|
||||
{ makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
|
||||
{ makeZeroLengthNop($nop, $this->lookaheadStartAttributes);
|
||||
if ($nop !== null) { $1[] = $nop; } $$ = $1; }
|
||||
;
|
||||
|
||||
@ -988,6 +988,7 @@ array_pair:
|
||||
| expr { $$ = Expr\ArrayItem[$1, null, false]; }
|
||||
| expr T_DOUBLE_ARROW '&' variable { $$ = Expr\ArrayItem[$4, $1, true]; }
|
||||
| '&' variable { $$ = Expr\ArrayItem[$2, null, true]; }
|
||||
| T_ELLIPSIS expr { $$ = Expr\ArrayItem[$2, null, false, attributes(), true]; }
|
||||
;
|
||||
|
||||
encaps_list:
|
||||
|
@ -16,7 +16,7 @@ top_statement_list_ex:
|
||||
|
||||
top_statement_list:
|
||||
top_statement_list_ex
|
||||
{ makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
|
||||
{ makeZeroLengthNop($nop, $this->lookaheadStartAttributes);
|
||||
if ($nop !== null) { $1[] = $nop; } $$ = $1; }
|
||||
;
|
||||
|
||||
@ -27,7 +27,7 @@ reserved_non_modifiers:
|
||||
| T_FINALLY | T_THROW | T_USE | T_INSTEADOF | T_GLOBAL | T_VAR | T_UNSET | T_ISSET | T_EMPTY | T_CONTINUE | T_GOTO
|
||||
| T_FUNCTION | T_CONST | T_RETURN | T_PRINT | T_YIELD | T_LIST | T_SWITCH | T_ENDSWITCH | T_CASE | T_DEFAULT
|
||||
| T_BREAK | T_ARRAY | T_CALLABLE | T_EXTENDS | T_IMPLEMENTS | T_NAMESPACE | T_TRAIT | T_INTERFACE | T_CLASS
|
||||
| T_CLASS_C | T_TRAIT_C | T_FUNC_C | T_METHOD_C | T_LINE | T_FILE | T_DIR | T_NS_C | T_HALT_COMPILER
|
||||
| T_CLASS_C | T_TRAIT_C | T_FUNC_C | T_METHOD_C | T_LINE | T_FILE | T_DIR | T_NS_C | T_HALT_COMPILER | T_FN
|
||||
;
|
||||
|
||||
semi_reserved:
|
||||
@ -196,7 +196,7 @@ inner_statement_list_ex:
|
||||
|
||||
inner_statement_list:
|
||||
inner_statement_list_ex
|
||||
{ makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
|
||||
{ makeZeroLengthNop($nop, $this->lookaheadStartAttributes);
|
||||
if ($nop !== null) { $1[] = $nop; } $$ = $1; }
|
||||
;
|
||||
|
||||
@ -530,7 +530,7 @@ class_statement_list_ex:
|
||||
|
||||
class_statement_list:
|
||||
class_statement_list_ex
|
||||
{ makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
|
||||
{ makeZeroLengthNop($nop, $this->lookaheadStartAttributes);
|
||||
if ($nop !== null) { $1[] = $nop; } $$ = $1; }
|
||||
;
|
||||
|
||||
@ -729,6 +729,12 @@ expr:
|
||||
| T_YIELD expr { $$ = Expr\Yield_[$2, null]; }
|
||||
| T_YIELD expr T_DOUBLE_ARROW expr { $$ = Expr\Yield_[$4, $2]; }
|
||||
| T_YIELD_FROM expr { $$ = Expr\YieldFrom[$2]; }
|
||||
|
||||
| T_FN optional_ref '(' parameter_list ')' optional_return_type T_DOUBLE_ARROW expr
|
||||
{ $$ = Expr\ArrowFunction[['static' => false, 'byRef' => $2, 'params' => $4, 'returnType' => $6, 'expr' => $8]]; }
|
||||
| T_STATIC T_FN optional_ref '(' parameter_list ')' optional_return_type T_DOUBLE_ARROW expr
|
||||
{ $$ = Expr\ArrowFunction[['static' => true, 'byRef' => $3, 'params' => $5, 'returnType' => $7, 'expr' => $9]]; }
|
||||
|
||||
| T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type
|
||||
block_or_error
|
||||
{ $$ = Expr\Closure[['static' => false, 'byRef' => $2, 'params' => $4, 'uses' => $6, 'returnType' => $7, 'stmts' => $8]]; }
|
||||
@ -977,6 +983,7 @@ array_pair:
|
||||
| expr { $$ = Expr\ArrayItem[$1, null, false]; }
|
||||
| expr T_DOUBLE_ARROW '&' variable { $$ = Expr\ArrayItem[$4, $1, true]; }
|
||||
| '&' variable { $$ = Expr\ArrayItem[$2, null, true]; }
|
||||
| T_ELLIPSIS expr { $$ = Expr\ArrayItem[$2, null, false, attributes(), true]; }
|
||||
| /* empty */ { $$ = null; }
|
||||
;
|
||||
|
||||
|
@ -13,9 +13,12 @@ $tmpResultFile = __DIR__ . '/tmp_parser.php';
|
||||
$resultDir = __DIR__ . '/../lib/PhpParser/Parser';
|
||||
$tokensResultsFile = $resultDir . '/Tokens.php';
|
||||
|
||||
// check for kmyacc.exe binary in this directory, otherwise fall back to global name
|
||||
$kmyacc = __DIR__ . '/kmyacc.exe';
|
||||
if (!file_exists($kmyacc)) {
|
||||
// check for kmyacc binary in this directory, otherwise fall back to global name
|
||||
if (file_exists(__DIR__ . '/kmyacc.exe')) {
|
||||
$kmyacc = __DIR__ . '/kmyacc.exe';
|
||||
} else if (file_exists(__DIR__ . '/kmyacc')) {
|
||||
$kmyacc = __DIR__ . '/kmyacc';
|
||||
} else {
|
||||
$kmyacc = 'kmyacc';
|
||||
}
|
||||
|
||||
@ -175,6 +178,15 @@ function resolveMacros($code) {
|
||||
. ' else { ' . $args[0] . ' = null; }';
|
||||
}
|
||||
|
||||
if ('makeZeroLengthNop' == $name) {
|
||||
assertArgs(2, $args, $name);
|
||||
|
||||
return '$startAttributes = ' . $args[1] . ';'
|
||||
. ' if (isset($startAttributes[\'comments\']))'
|
||||
. ' { ' . $args[0] . ' = new Stmt\Nop($this->createZeroLengthAttributes($startAttributes)); }'
|
||||
. ' else { ' . $args[0] . ' = null; }';
|
||||
}
|
||||
|
||||
if ('strKind' == $name) {
|
||||
assertArgs(1, $args, $name);
|
||||
|
||||
|
@ -64,6 +64,7 @@
|
||||
%token T_CONTINUE
|
||||
%token T_GOTO
|
||||
%token T_FUNCTION
|
||||
%token T_FN
|
||||
%token T_CONST
|
||||
%token T_RETURN
|
||||
%token T_TRY
|
||||
|
@ -16,7 +16,13 @@ class Lexer
|
||||
protected $tokenMap;
|
||||
protected $dropTokens;
|
||||
|
||||
protected $usedAttributes;
|
||||
private $attributeStartLineUsed;
|
||||
private $attributeEndLineUsed;
|
||||
private $attributeStartTokenPosUsed;
|
||||
private $attributeEndTokenPosUsed;
|
||||
private $attributeStartFilePosUsed;
|
||||
private $attributeEndFilePosUsed;
|
||||
private $attributeCommentsUsed;
|
||||
|
||||
/**
|
||||
* Creates a Lexer.
|
||||
@ -37,12 +43,17 @@ class Lexer
|
||||
[\T_WHITESPACE, \T_OPEN_TAG, \T_COMMENT, \T_DOC_COMMENT], 1
|
||||
);
|
||||
|
||||
// the usedAttributes member is a map of the used attribute names to a dummy
|
||||
// value (here "true")
|
||||
$options += [
|
||||
'usedAttributes' => ['comments', 'startLine', 'endLine'],
|
||||
];
|
||||
$this->usedAttributes = array_fill_keys($options['usedAttributes'], true);
|
||||
$defaultAttributes = ['comments', 'startLine', 'endLine'];
|
||||
$usedAttributes = array_fill_keys($options['usedAttributes'] ?? $defaultAttributes, true);
|
||||
|
||||
// Create individual boolean properties to make these checks faster.
|
||||
$this->attributeStartLineUsed = isset($usedAttributes['startLine']);
|
||||
$this->attributeEndLineUsed = isset($usedAttributes['endLine']);
|
||||
$this->attributeStartTokenPosUsed = isset($usedAttributes['startTokenPos']);
|
||||
$this->attributeEndTokenPosUsed = isset($usedAttributes['endTokenPos']);
|
||||
$this->attributeStartFilePosUsed = isset($usedAttributes['startFilePos']);
|
||||
$this->attributeEndFilePosUsed = isset($usedAttributes['endFilePos']);
|
||||
$this->attributeCommentsUsed = isset($usedAttributes['comments']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -230,13 +241,13 @@ class Lexer
|
||||
$token = "\0";
|
||||
}
|
||||
|
||||
if (isset($this->usedAttributes['startLine'])) {
|
||||
if ($this->attributeStartLineUsed) {
|
||||
$startAttributes['startLine'] = $this->line;
|
||||
}
|
||||
if (isset($this->usedAttributes['startTokenPos'])) {
|
||||
if ($this->attributeStartTokenPosUsed) {
|
||||
$startAttributes['startTokenPos'] = $this->pos;
|
||||
}
|
||||
if (isset($this->usedAttributes['startFilePos'])) {
|
||||
if ($this->attributeStartFilePosUsed) {
|
||||
$startAttributes['startFilePos'] = $this->filePos;
|
||||
}
|
||||
|
||||
@ -263,7 +274,7 @@ class Lexer
|
||||
$this->filePos += \strlen($value);
|
||||
} else {
|
||||
if (\T_COMMENT === $token[0] || \T_DOC_COMMENT === $token[0]) {
|
||||
if (isset($this->usedAttributes['comments'])) {
|
||||
if ($this->attributeCommentsUsed) {
|
||||
$comment = \T_DOC_COMMENT === $token[0]
|
||||
? new Comment\Doc($token[1], $this->line, $this->filePos, $this->pos)
|
||||
: new Comment($token[1], $this->line, $this->filePos, $this->pos);
|
||||
@ -276,13 +287,13 @@ class Lexer
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($this->usedAttributes['endLine'])) {
|
||||
if ($this->attributeEndLineUsed) {
|
||||
$endAttributes['endLine'] = $this->line;
|
||||
}
|
||||
if (isset($this->usedAttributes['endTokenPos'])) {
|
||||
if ($this->attributeEndTokenPosUsed) {
|
||||
$endAttributes['endTokenPos'] = $this->pos;
|
||||
}
|
||||
if (isset($this->usedAttributes['endFilePos'])) {
|
||||
if ($this->attributeEndFilePosUsed) {
|
||||
$endAttributes['endFilePos'] = $this->filePos - 1;
|
||||
}
|
||||
|
||||
|
@ -4,9 +4,12 @@ namespace PhpParser\Lexer;
|
||||
|
||||
use PhpParser\Error;
|
||||
use PhpParser\ErrorHandler;
|
||||
use PhpParser\Parser;
|
||||
use PhpParser\Lexer;
|
||||
use PhpParser\Lexer\TokenEmulator\CoaleseEqualTokenEmulator;
|
||||
use PhpParser\Lexer\TokenEmulator\FnTokenEmulator;
|
||||
use PhpParser\Lexer\TokenEmulator\TokenEmulatorInterface;
|
||||
|
||||
class Emulative extends \PhpParser\Lexer
|
||||
class Emulative extends Lexer
|
||||
{
|
||||
const PHP_7_3 = '7.3.0dev';
|
||||
const PHP_7_4 = '7.4.0dev';
|
||||
@ -17,13 +20,12 @@ class Emulative extends \PhpParser\Lexer
|
||||
(?<indentation>\h*)\2(?![a-zA-Z_\x80-\xff])(?<separator>(?:;?[\r\n])?)/x
|
||||
REGEX;
|
||||
|
||||
const T_COALESCE_EQUAL = 1007;
|
||||
|
||||
/**
|
||||
* @var mixed[] Patches used to reverse changes introduced in the code
|
||||
*/
|
||||
/** @var mixed[] Patches used to reverse changes introduced in the code */
|
||||
private $patches = [];
|
||||
|
||||
/** @var TokenEmulatorInterface[] */
|
||||
private $tokenEmulators = [];
|
||||
|
||||
/**
|
||||
* @param mixed[] $options
|
||||
*/
|
||||
@ -31,8 +33,14 @@ REGEX;
|
||||
{
|
||||
parent::__construct($options);
|
||||
|
||||
// prepare token emulators
|
||||
$this->tokenEmulators[] = new FnTokenEmulator();
|
||||
$this->tokenEmulators[] = new CoaleseEqualTokenEmulator();
|
||||
|
||||
// add emulated tokens here
|
||||
$this->tokenMap[self::T_COALESCE_EQUAL] = Parser\Tokens::T_COALESCE_EQUAL;
|
||||
foreach ($this->tokenEmulators as $emulativeToken) {
|
||||
$this->tokenMap[$emulativeToken->getTokenId()] = $emulativeToken->getParserTokenId();
|
||||
}
|
||||
}
|
||||
|
||||
public function startLexing(string $code, ErrorHandler $errorHandler = null) {
|
||||
@ -50,8 +58,13 @@ REGEX;
|
||||
$preparedCode = $this->processHeredocNowdoc($code);
|
||||
parent::startLexing($preparedCode, $collector);
|
||||
|
||||
// 2. emulation of ??= token
|
||||
$this->processCoaleseEqual($code);
|
||||
// add token emulation
|
||||
foreach ($this->tokenEmulators as $emulativeToken) {
|
||||
if ($emulativeToken->isEmulationNeeded($code)) {
|
||||
$this->tokens = $emulativeToken->emulate($code, $this->tokens);
|
||||
}
|
||||
}
|
||||
|
||||
$this->fixupTokens();
|
||||
|
||||
$errors = $collector->getErrors();
|
||||
@ -63,41 +76,6 @@ REGEX;
|
||||
}
|
||||
}
|
||||
|
||||
private function isCoalesceEqualEmulationNeeded(string $code): bool
|
||||
{
|
||||
// skip version where this works without emulation
|
||||
if (version_compare(\PHP_VERSION, self::PHP_7_4, '>=')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return strpos($code, '??=') !== false;
|
||||
}
|
||||
|
||||
private function processCoaleseEqual(string $code)
|
||||
{
|
||||
if ($this->isCoalesceEqualEmulationNeeded($code) === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We need to manually iterate and manage a count because we'll change
|
||||
// the tokens array on the way
|
||||
$line = 1;
|
||||
for ($i = 0, $c = count($this->tokens); $i < $c; ++$i) {
|
||||
if (isset($this->tokens[$i + 1])) {
|
||||
if ($this->tokens[$i][0] === T_COALESCE && $this->tokens[$i + 1] === '=') {
|
||||
array_splice($this->tokens, $i, 2, [
|
||||
[self::T_COALESCE_EQUAL, '??=', $line]
|
||||
]);
|
||||
$c--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (\is_array($this->tokens[$i])) {
|
||||
$line += substr_count($this->tokens[$i][1], "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function isHeredocNowdocEmulationNeeded(string $code): bool
|
||||
{
|
||||
// skip version where this works without emulation
|
||||
@ -155,15 +133,13 @@ REGEX;
|
||||
|
||||
private function isEmulationNeeded(string $code): bool
|
||||
{
|
||||
if ($this->isHeredocNowdocEmulationNeeded($code)) {
|
||||
return true;
|
||||
foreach ($this->tokenEmulators as $emulativeToken) {
|
||||
if ($emulativeToken->isEmulationNeeded($code)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->isCoalesceEqualEmulationNeeded($code)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $this->isHeredocNowdocEmulationNeeded($code);
|
||||
}
|
||||
|
||||
private function fixupTokens()
|
||||
|
@ -0,0 +1,54 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace PhpParser\Lexer\TokenEmulator;
|
||||
|
||||
use PhpParser\Lexer\Emulative;
|
||||
use PhpParser\Parser\Tokens;
|
||||
|
||||
final class CoaleseEqualTokenEmulator implements TokenEmulatorInterface
|
||||
{
|
||||
const T_COALESCE_EQUAL = 1007;
|
||||
|
||||
public function getTokenId(): int
|
||||
{
|
||||
return self::T_COALESCE_EQUAL;
|
||||
}
|
||||
|
||||
public function getParserTokenId(): int
|
||||
{
|
||||
return Tokens::T_COALESCE_EQUAL;
|
||||
}
|
||||
|
||||
public function isEmulationNeeded(string $code) : bool
|
||||
{
|
||||
// skip version where this is supported
|
||||
if (version_compare(\PHP_VERSION, Emulative::PHP_7_4, '>=')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return strpos($code, '??=') !== false;
|
||||
}
|
||||
|
||||
public function emulate(string $code, array $tokens): array
|
||||
{
|
||||
// We need to manually iterate and manage a count because we'll change
|
||||
// the tokens array on the way
|
||||
$line = 1;
|
||||
for ($i = 0, $c = count($tokens); $i < $c; ++$i) {
|
||||
if (isset($tokens[$i + 1])) {
|
||||
if ($tokens[$i][0] === T_COALESCE && $tokens[$i + 1] === '=') {
|
||||
array_splice($tokens, $i, 2, [
|
||||
[self::T_COALESCE_EQUAL, '??=', $line]
|
||||
]);
|
||||
$c--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (\is_array($tokens[$i])) {
|
||||
$line += substr_count($tokens[$i][1], "\n");
|
||||
}
|
||||
}
|
||||
|
||||
return $tokens;
|
||||
}
|
||||
}
|
66
lib/PhpParser/Lexer/TokenEmulator/FnTokenEmulator.php
Normal file
66
lib/PhpParser/Lexer/TokenEmulator/FnTokenEmulator.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace PhpParser\Lexer\TokenEmulator;
|
||||
|
||||
use PhpParser\Lexer\Emulative;
|
||||
use PhpParser\Parser\Tokens;
|
||||
|
||||
final class FnTokenEmulator implements TokenEmulatorInterface
|
||||
{
|
||||
const T_FN = 1008;
|
||||
|
||||
public function getTokenId(): int
|
||||
{
|
||||
return self::T_FN;
|
||||
}
|
||||
|
||||
public function getParserTokenId(): int
|
||||
{
|
||||
return Tokens::T_FN;
|
||||
}
|
||||
|
||||
public function isEmulationNeeded(string $code) : bool
|
||||
{
|
||||
// skip version where this is supported
|
||||
if (version_compare(\PHP_VERSION, Emulative::PHP_7_4, '>=')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return strpos($code, 'fn') !== false;
|
||||
}
|
||||
|
||||
public function emulate(string $code, array $tokens): array
|
||||
{
|
||||
// We need to manually iterate and manage a count because we'll change
|
||||
// the tokens array on the way
|
||||
foreach ($tokens as $i => $token) {
|
||||
if ($token[0] === T_STRING && $token[1] === 'fn') {
|
||||
$previousNonSpaceToken = $this->getPreviousNonSpaceToken($tokens, $i);
|
||||
if ($previousNonSpaceToken !== null && $previousNonSpaceToken[0] === T_OBJECT_OPERATOR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tokens[$i][0] = self::T_FN;
|
||||
}
|
||||
}
|
||||
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $tokens
|
||||
* @return mixed[]|null
|
||||
*/
|
||||
private function getPreviousNonSpaceToken(array $tokens, int $start)
|
||||
{
|
||||
for ($i = $start - 1; $i >= 0; --$i) {
|
||||
if ($tokens[$i][0] === T_WHITESPACE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $tokens[$i];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
17
lib/PhpParser/Lexer/TokenEmulator/TokenEmulatorInterface.php
Normal file
17
lib/PhpParser/Lexer/TokenEmulator/TokenEmulatorInterface.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace PhpParser\Lexer\TokenEmulator;
|
||||
|
||||
interface TokenEmulatorInterface
|
||||
{
|
||||
public function getTokenId(): int;
|
||||
|
||||
public function getParserTokenId(): int;
|
||||
|
||||
public function isEmulationNeeded(string $code): bool;
|
||||
|
||||
/**
|
||||
* @return array Modified Tokens
|
||||
*/
|
||||
public function emulate(string $code, array $tokens): array;
|
||||
}
|
@ -22,7 +22,7 @@ class Arg extends NodeAbstract
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $value, bool $byRef = false, bool $unpack = false, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->value = $value;
|
||||
$this->byRef = $byRef;
|
||||
$this->unpack = $unpack;
|
||||
|
@ -22,7 +22,7 @@ class Const_ extends NodeAbstract
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, Expr $value, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->name = \is_string($name) ? new Identifier($name) : $name;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ class ArrayDimFetch extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, Expr $dim = null, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->var = $var;
|
||||
$this->dim = $dim;
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ class ArrayItem extends Expr
|
||||
public $value;
|
||||
/** @var bool Whether to assign by reference */
|
||||
public $byRef;
|
||||
/** @var bool Whether to unpack the argument */
|
||||
public $unpack;
|
||||
|
||||
/**
|
||||
* Constructs an array item node.
|
||||
@ -21,17 +23,18 @@ class ArrayItem extends Expr
|
||||
* @param bool $byRef Whether to assign by reference
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $value, Expr $key = null, bool $byRef = false, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
public function __construct(Expr $value, Expr $key = null, bool $byRef = false, array $attributes = [], bool $unpack = false) {
|
||||
$this->attributes = $attributes;
|
||||
$this->key = $key;
|
||||
$this->value = $value;
|
||||
$this->byRef = $byRef;
|
||||
$this->unpack = $unpack;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() : array {
|
||||
return ['key', 'value', 'byRef'];
|
||||
return ['key', 'value', 'byRef', 'unpack'];
|
||||
}
|
||||
|
||||
|
||||
public function getType() : string {
|
||||
return 'Expr_ArrayItem';
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class Array_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $items = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->items = $items;
|
||||
}
|
||||
|
||||
|
71
lib/PhpParser/Node/Expr/ArrowFunction.php
Normal file
71
lib/PhpParser/Node/Expr/ArrowFunction.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
|
||||
class ArrowFunction extends Expr implements FunctionLike
|
||||
{
|
||||
/** @var bool */
|
||||
public $static;
|
||||
|
||||
/** @var bool */
|
||||
public $byRef;
|
||||
|
||||
/** @var Node\Param[] */
|
||||
public $params = [];
|
||||
|
||||
/** @var null|Node\Identifier|Node\Name|Node\NullableType */
|
||||
public $returnType;
|
||||
|
||||
/** @var Expr */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* @param array $subNodes Array of the following optional subnodes:
|
||||
* 'static' => false : Whether the closure is static
|
||||
* 'byRef' => false : Whether to return by reference
|
||||
* 'params' => array() : Parameters
|
||||
* 'returnType' => null : Return type
|
||||
* 'expr' => Expr : Expression body
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $subNodes = [], array $attributes = []) {
|
||||
$this->attributes = $attributes;
|
||||
$this->static = $subNodes['static'] ?? false;
|
||||
$this->byRef = $subNodes['byRef'] ?? false;
|
||||
$this->params = $subNodes['params'] ?? [];
|
||||
$returnType = $subNodes['returnType'] ?? null;
|
||||
$this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType;
|
||||
$this->expr = $subNodes['expr'] ?? null;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() : array {
|
||||
return ['static', 'byRef', 'params', 'returnType', 'expr'];
|
||||
}
|
||||
|
||||
public function returnsByRef() : bool {
|
||||
return $this->byRef;
|
||||
}
|
||||
|
||||
public function getParams() : array {
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
public function getReturnType() {
|
||||
return $this->returnType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Node\Stmt\Return_[]
|
||||
*/
|
||||
public function getStmts() : array {
|
||||
return [new Node\Stmt\Return_($this->expr)];
|
||||
}
|
||||
|
||||
public function getType() : string {
|
||||
return 'Expr_ArrowFunction';
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ class Assign extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, Expr $expr, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->var = $var;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ abstract class AssignOp extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, Expr $expr, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->var = $var;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ class AssignRef extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, Expr $expr, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->var = $var;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ abstract class BinaryOp extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $left, Expr $right, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->left = $left;
|
||||
$this->right = $right;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class BitwiseNot extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class BooleanNot extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ abstract class Cast extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ class ClassConstFetch extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($class, $name, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->class = $class;
|
||||
$this->name = \is_string($name) ? new Identifier($name) : $name;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class Clone_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ class Closure extends Expr implements FunctionLike
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $subNodes = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->static = $subNodes['static'] ?? false;
|
||||
$this->byRef = $subNodes['byRef'] ?? false;
|
||||
$this->params = $subNodes['params'] ?? [];
|
||||
|
@ -19,7 +19,7 @@ class ClosureUse extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr\Variable $var, bool $byRef = false, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->var = $var;
|
||||
$this->byRef = $byRef;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class ConstFetch extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Name $name, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class Empty_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ class Error extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() : array {
|
||||
|
@ -16,7 +16,7 @@ class ErrorSuppress extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class Eval_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ class Exit_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr = null, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ class FuncCall extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, array $args = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->name = $name;
|
||||
$this->args = $args;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class Include_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, int $type, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class Instanceof_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, $class, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
$this->class = $class;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class Isset_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $vars, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->vars = $vars;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class List_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $items, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->items = $items;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ class MethodCall extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, $name, array $args = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->var = $var;
|
||||
$this->name = \is_string($name) ? new Identifier($name) : $name;
|
||||
$this->args = $args;
|
||||
|
@ -20,7 +20,7 @@ class New_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($class, array $args = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->class = $class;
|
||||
$this->args = $args;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class PostDec extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->var = $var;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class PostInc extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->var = $var;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class PreDec extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->var = $var;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class PreInc extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->var = $var;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class Print_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ class PropertyFetch extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, $name, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->var = $var;
|
||||
$this->name = \is_string($name) ? new Identifier($name) : $name;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class ShellExec extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $parts, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->parts = $parts;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ class StaticCall extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($class, $name, array $args = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->class = $class;
|
||||
$this->name = \is_string($name) ? new Identifier($name) : $name;
|
||||
$this->args = $args;
|
||||
|
@ -21,7 +21,7 @@ class StaticPropertyFetch extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($class, $name, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->class = $class;
|
||||
$this->name = \is_string($name) ? new VarLikeIdentifier($name) : $name;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class Ternary extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $cond, $if, Expr $else, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->cond = $cond;
|
||||
$this->if = $if;
|
||||
$this->else = $else;
|
||||
|
@ -16,7 +16,7 @@ class UnaryMinus extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class UnaryPlus extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class Variable extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class YieldFrom extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ class Yield_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $value = null, Expr $key = null, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->key = $key;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class Identifier extends NodeAbstract
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(string $name, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
|
@ -6,9 +6,7 @@ use PhpParser\NodeAbstract;
|
||||
|
||||
class Name extends NodeAbstract
|
||||
{
|
||||
/**
|
||||
* @var string[] Parts of the name
|
||||
*/
|
||||
/** @var string[] Parts of the name */
|
||||
public $parts;
|
||||
|
||||
private static $specialClassNames = [
|
||||
@ -24,7 +22,7 @@ class Name extends NodeAbstract
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->parts = self::prepareName($name);
|
||||
}
|
||||
|
||||
@ -237,7 +235,7 @@ class Name extends NodeAbstract
|
||||
'Expected string, array of parts or Name instance'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function getType() : string {
|
||||
return 'Name';
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class NullableType extends NodeAbstract
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($type, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->type = \is_string($type) ? new Identifier($type) : $type;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ class Param extends NodeAbstract
|
||||
$var, Expr $default = null, $type = null,
|
||||
bool $byRef = false, bool $variadic = false, array $attributes = []
|
||||
) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->type = \is_string($type) ? new Identifier($type) : $type;
|
||||
$this->byRef = $byRef;
|
||||
$this->variadic = $variadic;
|
||||
|
@ -16,7 +16,7 @@ class DNumber extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(float $value, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ class Encapsed extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $parts, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->parts = $parts;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class EncapsedStringPart extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(string $value, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ class LNumber extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(int $value, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ abstract class MagicConst extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() : array {
|
||||
|
@ -34,7 +34,7 @@ class String_ extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(string $value, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class Break_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Node\Expr $num = null, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->num = $num;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ class Case_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($cond, array $stmts = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->cond = $cond;
|
||||
$this->stmts = $stmts;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class Catch_ extends Node\Stmt
|
||||
public function __construct(
|
||||
array $types, Expr\Variable $var, array $stmts = [], array $attributes = []
|
||||
) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->types = $types;
|
||||
$this->var = $var;
|
||||
$this->stmts = $stmts;
|
||||
|
@ -19,7 +19,7 @@ class ClassConst extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $consts, int $flags = 0, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->flags = $flags;
|
||||
$this->consts = $consts;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class ClassMethod extends Node\Stmt implements FunctionLike
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, array $subNodes = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->flags = $subNodes['flags'] ?? $subNodes['type'] ?? 0;
|
||||
$this->byRef = $subNodes['byRef'] ?? false;
|
||||
$this->name = \is_string($name) ? new Node\Identifier($name) : $name;
|
||||
|
@ -35,7 +35,7 @@ class Class_ extends ClassLike
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, array $subNodes = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->flags = $subNodes['flags'] ?? $subNodes['type'] ?? 0;
|
||||
$this->name = \is_string($name) ? new Node\Identifier($name) : $name;
|
||||
$this->extends = $subNodes['extends'] ?? null;
|
||||
|
@ -16,7 +16,7 @@ class Const_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $consts, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->consts = $consts;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class Continue_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Node\Expr $num = null, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->num = $num;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ class DeclareDeclare extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($key, Node\Expr $value, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->key = \is_string($key) ? new Node\Identifier($key) : $key;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ class Declare_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $declares, array $stmts = null, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->declares = $declares;
|
||||
$this->stmts = $stmts;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ class Do_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Node\Expr $cond, array $stmts = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->cond = $cond;
|
||||
$this->stmts = $stmts;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class Echo_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $exprs, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->exprs = $exprs;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ class ElseIf_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Node\Expr $cond, array $stmts = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->cond = $cond;
|
||||
$this->stmts = $stmts;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class Else_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $stmts = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->stmts = $stmts;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ class Expression extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Node\Expr $expr, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ class Finally_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $stmts = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->stmts = $stmts;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ class For_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $subNodes = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->init = $subNodes['init'] ?? [];
|
||||
$this->cond = $subNodes['cond'] ?? [];
|
||||
$this->loop = $subNodes['loop'] ?? [];
|
||||
|
@ -29,7 +29,7 @@ class Foreach_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Node\Expr $expr, Node\Expr $valueVar, array $subNodes = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
$this->keyVar = $subNodes['keyVar'] ?? null;
|
||||
$this->byRef = $subNodes['byRef'] ?? false;
|
||||
|
@ -33,7 +33,7 @@ class Function_ extends Node\Stmt implements FunctionLike
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, array $subNodes = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->byRef = $subNodes['byRef'] ?? false;
|
||||
$this->name = \is_string($name) ? new Node\Identifier($name) : $name;
|
||||
$this->params = $subNodes['params'] ?? [];
|
||||
|
@ -16,7 +16,7 @@ class Global_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $vars, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->vars = $vars;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ class Goto_ extends Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->name = \is_string($name) ? new Identifier($name) : $name;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ class GroupUse extends Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Name $prefix, array $uses, int $type = Use_::TYPE_NORMAL, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->type = $type;
|
||||
$this->prefix = $prefix;
|
||||
$this->uses = $uses;
|
||||
|
@ -16,7 +16,7 @@ class HaltCompiler extends Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(string $remaining, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->remaining = $remaining;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ class If_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Node\Expr $cond, array $subNodes = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->cond = $cond;
|
||||
$this->stmts = $subNodes['stmts'] ?? [];
|
||||
$this->elseifs = $subNodes['elseifs'] ?? [];
|
||||
|
@ -16,7 +16,7 @@ class InlineHTML extends Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(string $value, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ class Interface_ extends ClassLike
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, array $subNodes = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->name = \is_string($name) ? new Node\Identifier($name) : $name;
|
||||
$this->extends = $subNodes['extends'] ?? [];
|
||||
$this->stmts = $subNodes['stmts'] ?? [];
|
||||
|
@ -17,7 +17,7 @@ class Label extends Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->name = \is_string($name) ? new Identifier($name) : $name;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ class Namespace_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Node\Name $name = null, $stmts = [], array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->name = $name;
|
||||
$this->stmts = $stmts;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class Property extends Node\Stmt
|
||||
* @param null|string|Identifier|Name|NullableType $type Type declaration
|
||||
*/
|
||||
public function __construct(int $flags, array $props, array $attributes = [], $type = null) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->flags = $flags;
|
||||
$this->props = $props;
|
||||
$this->type = \is_string($type) ? new Identifier($type) : $type;
|
||||
|
@ -19,7 +19,7 @@ class PropertyProperty extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, Node\Expr $default = null, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->name = \is_string($name) ? new Node\VarLikeIdentifier($name) : $name;
|
||||
$this->default = $default;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class Return_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Node\Expr $expr = null, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ class StaticVar extends Node\Stmt
|
||||
public function __construct(
|
||||
Expr\Variable $var, Node\Expr $default = null, array $attributes = []
|
||||
) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->var = $var;
|
||||
$this->default = $default;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class Static_ extends Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $vars, array $attributes = []) {
|
||||
parent::__construct($attributes);
|
||||
$this->attributes = $attributes;
|
||||
$this->vars = $vars;
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user