diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..9c76d07083 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*.y] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 4 diff --git a/.gitattributes b/.gitattributes index f0db0ea889..5031accf24 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,9 +1,17 @@ /.github export-ignore /doc export-ignore +/grammar export-ignore /test export-ignore /test_old export-ignore +/tools export-ignore +.editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore +.php-cs-fixer.dist.php export-ignore +Makefile export-ignore CHANGELOG.md export-ignore +CONTRIBUTING.md export-ignore +phpstan-baseline.neon export-ignore +phpstan.neon.dist export-ignore phpunit.xml.dist export-ignore UPGRADE-*.md export-ignore diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 426d4c83d2..efa88241aa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,22 +5,22 @@ on: pull_request: jobs: - tests_70: + tests_coverage: runs-on: "ubuntu-latest" - name: "PHP 7.0 Unit Tests" + name: "PHP 7.4 Unit Tests (with coverage)" steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: coverage: "xdebug" - php-version: "7.0" + php-version: "7.4" tools: composer:v2 - name: "Install dependencies" run: | composer require php-coveralls/php-coveralls:^2.2 --dev --no-update - composer update --no-progress --prefer-dist + COMPOSER_ROOT_VERSION=dev-master composer update --no-progress --prefer-dist - name: "Tests" run: "php vendor/bin/phpunit --coverage-clover build/logs/clover.xml" - name: Coveralls @@ -34,53 +34,92 @@ jobs: strategy: matrix: php-version: - - "7.1" - - "7.2" - - "7.3" - - "7.4" - "8.0" + - "8.1" + - "8.2" + - "8.3" + - "8.4" + - "8.5" + fail-fast: false steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: coverage: "none" php-version: "${{ matrix.php-version }}" + ini-file: "development" tools: composer:v2 - name: "Install dependencies" - run: "composer update --no-progress --prefer-dist" + run: "COMPOSER_ROOT_VERSION=dev-master composer update --no-progress --prefer-dist ${{ matrix.flags }}" - name: "PHPUnit" run: "php vendor/bin/phpunit" test_old_73_80: runs-on: "ubuntu-latest" - name: "PHP 7.3 Code on PHP 8.0 Integration Tests" + name: "PHP 7.4 Code on PHP 8.4 Integration Tests" steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: coverage: "none" - php-version: "8.0" + php-version: "8.4" + ini-file: "development" tools: composer:v2 - name: "Install PHP 8 dependencies" - run: "composer update --no-progress --prefer-dist" + run: "COMPOSER_ROOT_VERSION=dev-master composer update --no-progress --prefer-dist" - name: "Tests" - run: "test_old/run-php-src.sh 7.3.21" + run: "test_old/run-php-src.sh 7.4.33" test_old_80_70: runs-on: "ubuntu-latest" - name: "PHP 8.0 Code on PHP 7.0 Integration Tests" + name: "PHP 8.4 Code on PHP 7.4 Integration Tests" steps: - name: "Checkout" - uses: "actions/checkout@v2" + uses: "actions/checkout@v4" - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: coverage: "none" - php-version: "7.0" + php-version: "7.4" + ini-file: "development" tools: composer:v2 - name: "Install PHP 8 dependencies" - run: "composer update --no-progress --prefer-dist" + run: "COMPOSER_ROOT_VERSION=dev-master composer update --no-progress --prefer-dist" - name: "Tests" - run: "test_old/run-php-src.sh 8.0.0" + run: "test_old/run-php-src.sh 8.4.0beta5" + phpstan: + runs-on: "ubuntu-latest" + name: "PHPStan" + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "8.3" + tools: composer:v2 + - name: "Install dependencies" + run: | + cd tools && composer install + - name: "PHPStan" + run: "php tools/vendor/bin/phpstan" + php-cs-fixer: + runs-on: "ubuntu-latest" + name: "PHP-CS-Fixer" + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "8.3" + tools: composer:v2 + - name: "Install dependencies" + run: | + cd tools && composer install + - name: "php-cs-fixer" + run: "php tools/vendor/bin/php-cs-fixer fix --dry-run" diff --git a/.gitignore b/.gitignore index 9772bead8c..aad97c0cd0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ +.idea/ vendor/ composer.lock grammar/kmyacc.exe grammar/y.output .phpunit.result.cache +.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000000..314307ef83 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,31 @@ +exclude('PhpParser/Parser') + ->in(__DIR__ . '/lib') + ->in(__DIR__ . '/test') + ->in(__DIR__ . '/grammar') +; + +$config = new PhpCsFixer\Config(); +return $config->setRiskyAllowed(true) + ->setRules([ + '@PSR12' => true, + // We use PSR12 with consistent brace placement. + 'curly_braces_position' => [ + 'functions_opening_brace' => 'same_line', + 'classes_opening_brace' => 'same_line', + ], + // declare(strict_types=1) on the same line as false, + 'declare_strict_types' => true, + // Keep argument formatting for now. + 'method_argument_space' => ['on_multiline' => 'ignore'], + 'phpdoc_align' => ['align' => 'left'], + 'phpdoc_trim' => true, + 'no_empty_phpdoc' => true, + 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true], + 'no_extra_blank_lines' => true, + ]) + ->setFinder($finder) +; diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c44bc648e..6002138209 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,438 @@ -Version 4.10.5-dev ------------------- +Version 5.6.0 (2025-07-27) +-------------------------- + +### Added + +* [8.5] Added support for `clone` with arbitrary function arguments. This will be parsed as an + `Expr\FuncCall` node, instead of the usual `Expr\Clone_` node. +* [8.5] Permit declaration of `function clone` for use in stubs. +* [8.5] Added support for the pipe operator, represented by `Expr\BinaryOp\Pipe`. +* [8.5] Added support for the `(void)` cast, represented by `Expr\Cast\Void_`. +* [8.5] Added support for the `final` modifier on promoted properties. +* Added `CallLike::getArg()` to fetch an argument by position and name. + +Version 5.5.0 (2025-05-31) +-------------------------- + +### Added + +* [8.5] Added support for attributes on constants. `Stmt\Const_` now has an `attrGroups` subnode. +* Added `weakReferences` option to `NodeConnectingVisitor` and `ParentConnectingVisitor`. This + will create the parent/next/prev references as WeakReferences, to avoid making the AST cyclic + and thus increasing GC pressure. + +### Changed + +* Attributes on parameters are now printed on separate lines if the pretty printer target version + is PHP 7.4 or older (which is the default). This allows them to be interpreted as comments, + instead of causing a parse error. Specify a target version of PHP 8.0 or newer to restore the + previous behavior. + +Version 5.4.0 (2024-12-30) +-------------------------- + +### Added + +* Added `Property::isAbstract()` and `Property::isFinal()` methods. +* Added `PropertyHook::isFinal()` method. +* Emit an error if property hook is used on declaration with multiple properties. + +### Fixed + +* Make legacy class aliases compatible with classmap-authoritative autoloader. +* `Param::isPromoted()` and `Param::isPublic()` now returns true for parameters that have property + hooks but no explicit visibility modifier. +* `PropertyHook::getStmts()` now correctly desugars short `set` hooks. `set => $value` will be + expanded to `set { $this->propertyName = $value; }`. This requires the `propertyName` attribute + on the hook to be set, which is now also set by the parser. If the attribute is not set, + `getStmts()` will throw an error for short set hooks, as it is not possible to produce a correct + desugaring. + +Version 5.3.1 (2024-10-08) +-------------------------- + +### Added + +* Added support for declaring functions with name `exit` or `die`, to allow their use in stubs. + +Version 5.3.0 (2024-09-29) +-------------------------- + +### Added + +* Added `indent` option to pretty printer, which can be used to specify the indentation to use + (defaulting to four spaces). This also allows using tab indentation. + +### Fixed + +* Resolve names in `PropertyHook`s in the `NameResolver`. +* Include the trailing semicolon inside `Stmt\GroupUse` nodes, making them consistent with + `Stmt\Use_` nodes. +* Fixed indentation sometimes becoming negative in formatting-preserving pretty printer, resulting + in `ValueError`s. + +Version 5.2.0 (2024-09-15) +-------------------------- + +### Added + +* [8.4] Added support for `__PROPERTY__` magic constant, represented using a + `Node\Scalar\MagicConst\Property` node. +* [8.4] Added support for property hooks, which are represented using a new `hooks` subnode on + `Node\Stmt\Property` and `Node\Param`, which contains an array of `Node\PropertyHook`. +* [8.4] Added support for asymmetric visibility modifiers. Property `flags` can now hold the + additional bits `Modifiers::PUBLIC_SET`, `Modifiers::PROTECTED_SET` and `Modifiers::PRIVATE_SET`. +* [8.4] Added support for generalized exit function. For backwards compatibility, exit without + argument or a single plain argument continues to use a `Node\Expr\Exit_` node. Otherwise (e.g. + if a named argument is used) it will be represented as a plain `Node\Expr\FuncCall`. +* Added support for passing enum values to various builder methods, like `BuilderFactory::val()`. + +### Removed + +* Removed support for alternative array syntax `$array{0}` from the PHP 8 parser. It is still + supported by the PHP 7 parser. This is necessary in order to support property hooks. + +Version 5.1.0 (2024-07-01) +-------------------------- + +### Added + +* [8.4] Added support for dereferencing `new` expressions without parentheses. + +### Fixed + +* Fixed redundant parentheses being added when pretty printing ternary expressions. + +### Changed + +* Made some phpdoc types more precise. + +Version 5.0.2 (2024-03-05) +-------------------------- + +### Fixed + +* Fix handling of indentation on next line after opening PHP tag in formatting-preserving pretty +printer. + +### Changed + +* Avoid cyclic references in `Parser` objects. This means that no longer used parser objects are + immediately destroyed now, instead of requiring cycle GC. +* Update `PhpVersion::getNewestSupported()` to report PHP 8.3 instead of PHP 8.2. + +Version 5.0.1 (2024-02-21) +-------------------------- + +### Changed + +* Added check to detect use of PHP-Parser with libraries that define `T_*` compatibility tokens + with incorrect type (such as string instead of int). This would lead to `TypeError`s down the + line. Now an `Error` will be thrown early to indicate the problem. + +Version 5.0.0 (2024-01-07) +-------------------------- + +See UPGRADE-5.0 for detailed migration instructions. + +### Fixed + +* Fixed parent class of `PropertyItem` and `UseItem`. + +Version 5.0.0-rc1 (2023-12-20) +------------------------------ + +See UPGRADE-5.0 for detailed migration instructions. + +### Fixed + +* Fixed parsing of empty files. + +### Added + +* Added support for printing additional attributes (like `kind`) in `NodeDumper`. +* Added `rawValue` attribute to `InterpolatedStringPart` and heredoc/nowdoc `String_`s, which + provides the original, unparsed value. It was previously only available for non-interpolated + single/double quoted strings. +* Added `Stmt\Block` to represent `{}` code blocks. Previously, such code blocks were flattened + into the parent statements array. `Stmt\Block` will not be created for structures that are + typically used with code blocks, for example `if ($x) { $y; }` will be represented as previously, + while `if ($x) { { $x; } }` will have an extra `Stmt\Block` wrapper. + +### Changed + +* Use visitor to assign comments. This fixes the long-standing issue where comments were assigned + to all nodes sharing a starting position. Now only the outer-most node will hold the comments. +* Don't parse unicode escape sequences when targeting PHP < 7.0. +* Improve NodeDumper performance for large dumps. + +### Removed + +* Removed `Stmt\Throw_` node, use `Expr\Throw_` inside `Stmt\Expression` instead. +* Removed `ParserFactory::create()`. + +Version 5.0.0-beta1 (2023-09-17) +-------------------------------- + +See UPGRADE-5.0 for detailed migration instructions. + +### Added + +* Visitors can now be passed directly to the `NodeTraverser` constructor. A separate call to + `addVisitor()` is no longer required. + +### Changed + +* The minimum host PHP version is now PHP 7.4. It is still possible to parse code from older + versions. Property types have been added where possible. +* The `Lexer` no longer accepts options. `Lexer\Emulative` only accepts a `PhpVersion`. The + `startLexing()`, `getTokens()` and `handleHaltCompiler()` methods have been removed. Instead, + there is a single method `tokenize()` returning the tokens. +* The `Parser::getLexer()` method has been replaced by `Parser::getTokens()`. +* Attribute handling has been moved from the lexer to the parser, and is no longer configurable. + The comments, startLine, endLine, startTokenPos, endTokenPos, startFilePos, and endFilePos + attributes will always be added. +* The pretty printer now defaults to PHP 7.4 as the target version. +* The pretty printer now indents heredoc/nowdoc strings if the target version is >= 7.3 + (flexible heredoc/nowdoc). + +### Removed + +* The deprecated `Comment::getLine()`, `Comment::getTokenPos()` and `Comment::getFilePos()` methods + have been removed. Use `Comment::getStartLine()`, `Comment::getStartTokenPos()` and + `Comment::getStartFilePos()` instead. + +### Deprecated + +* The `Node::getLine()` method has been deprecated. Use `Node::getStartLine()` instead. + +Version 5.0.0-alpha3 (2023-06-24) +--------------------------------- + +See UPGRADE-5.0 for detailed migration instructions. + +### Added + +* [PHP 8.3] Added support for typed constants. +* [PHP 8.3] Added support for readonly anonymous classes. +* Added support for `NodeVisitor::REPLACE_WITH_NULL`. +* Added support for CRLF newlines in the pretty printer, using the new `newline` option. + +### Changed + +* Use PHP 7.1 as the default target version for the pretty printer. +* Print `else if { }` instead of `else { if { } }`. +* The `leaveNode()` method on visitors is now invoked in reverse order of `enterNode()`. +* Moved `NodeTraverser::REMOVE_NODE` etc. to `NodeVisitor::REMOVE_NODE`. The old constants are still + available for compatibility. +* The `Name` subnode `parts` has been replaced by `name`, which stores the name as a string rather + than an array of parts separated by namespace separators. The `getParts()` method returns the old + representation. +* No longer accept strings for types in Node constructors. Instead, either an `Identifier`, `Name` + or `ComplexType` must be passed. +* `Comment::getReformattedText()` now normalizes CRLF newlines to LF newlines. + +### Fixed + +* Don't trim leading whitespace in formatting preserving printer. +* Treat DEL as a label character in the formatting preserving printer depending on the targeted + PHP version. +* Fix error reporting in emulative lexer without explicitly specified error handler. +* Gracefully handle non-contiguous array indices in the `Differ`. + +Version 5.0.0-alpha2 (2023-03-05) +--------------------------------- + +See UPGRADE-5.0 for detailed migration instructions. + +### Added + +* [PHP 8.3] Added support for dynamic class constant fetch. +* Added many additional type annotations. PhpStan is now used. +* Added a fuzzing target for PHP-Fuzzer, which was how a lot of pretty printer bugs were found. +* Added `isPromoted()`, `isPublic()`, `isProtected()`, `isPrivate()` and `isReadonly()` methods + on `Param`. +* Added support for class constants in trait builder. +* Added `PrettyPrinter` interface. +* Added support for formatting preservation when toggling static modifiers. +* The `php-parse` binary now accepts `-` as the file name, in which case it will read from stdin. + +### Fixed + +* The pretty printer now uses a more accurate treatment of unary operator precedence, and will only + wrap them in parentheses if required. This allowed fixing a number of other precedence related + bugs. +* The pretty printer now respects the precedence of `clone`, `throw` and arrow functions. +* The pretty printer no longer unconditionally wraps `yield` in parentheses, unless the target + version is set to older than PHP 7.0. +* Fixed formatting preservation for alternative elseif/else syntax. +* Fixed checks for when it is safe to print strings as heredoc/nowdoc to accommodate flexible + doc string semantics. +* The pretty printer now prints parentheses around new/instanceof operands in all required + situations. +* Similar, differences in allowed expressions on the LHS of `->` and `::` are now taken into account. +* Fixed various cases where `\r` at the end of a doc string could be incorrectly merged into a CRLF + sequence with a following `\n`. +* `__halt_compiler` is no longer recognized as a semi-reserved keyword, in line with PHP behavior. +* ``. + +### Fixed + +* Multiple modifiers for promoted properties are now accepted. In particular this allows something + like `public readonly` for promoted properties. +* Formatting-preserving pretty printing for comments in array literals has been fixed. + +Version 4.12.0 (2021-07-21) +--------------------------- + +### Added + +* [PHP 8.1] Added support for readonly properties (through a new `MODIFIER_READONLY`). +* [PHP 8.1] Added support for final class constants. + +### Fixed + +* Fixed compatibility with PHP 8.1. `&` tokens are now canonicalized to the + `T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG` and `T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG` tokens + used in PHP 8.1. This happens unconditionally, regardless of whether the emulative lexer is used. + +Version 4.11.0 (2021-07-03) +--------------------------- + +### Added + +* `BuilderFactory::args()` now accepts named arguments. +* `BuilderFactory::attribute()` has been added. +* An `addAttribute()` method accepting an `Attribute` or `AttributeGroup` has been adde to all + builders that accept attributes, such as `Builder\Class_`. + +### Fixed + +* `NameResolver` now handles enums. +* `PrettyPrinter` now prints backing enum type. +* Builder methods for types now property handle `never` type. + +Version 4.10.5 (2021-05-03) +--------------------------- + +### Added + +* [PHP 8.1] Added support for enums. These are represented using the `Stmt\Enum_` and + `Stmt\EnumCase` nodes. +* [PHP 8.1] Added support for never type. This type will now be returned as an `Identifier` rather + than `Name`. +* Added `ClassConst` builder. + +### Changed + +* Non-UTF-8 code units in strings will now be hex-encoded. + +### Fixed -Nothing yet. +* Fixed precedence of arrow functions. Version 4.10.4 (2020-12-20) --------------------------- diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000..11d7d1469c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,32 @@ +## Coding Style + +This project uses PSR-12 with consistent brace placement. This means that the opening brace is +always on the same line, even for class and method declarations. + +## Tools + +This project uses PHP-CS-Fixer and PHPStan. You can invoke them using `make`: + +```shell +make php-cs-fixer +make phpstan +``` + +## Adding support for new PHP syntax + +1. If necessary, add emulation support for new tokens. + * Add a new subclass of `Lexer\TokenEmulator`. Take inspiration from existing classes. + * Add the new class to the array in `Lexer\Emulative`. + * Add tests for the emulation in `Lexer\EmulativeTest`. You'll want to modify + `provideTestReplaceKeywords()` for new reserved keywords and `provideTestLexNewFeatures()` for + other emulations. +2. Add any new node classes that are needed. +3. Add support for the new syntax in `grammar/php.y`. Regenerate the parser by running + `php grammar/rebuildParsers.php`. Use `--debug` if there are conflicts. +4. Add pretty-printing support by implementing a `pFooBar()` method in `PrettyPrinter\Standard`. +5. Add tests both in `test/code/parser` and `test/code/prettyPrinter`. +6. Add support for formatting-preserving pretty-printing. This is done by modifying the data tables + at the end of `PrettyPrinterAbstract`. Add a test in `test/code/formatPreservation`. +7. Does the new syntax feature namespaced names? If so, add support for name resolution in + `NodeVisitor\NameResolver`. Test it in `NodeVisitor\NameResolverTest`. +8. Does the new syntax require any changes to builders? Is so, make them :) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..a1057d052c --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +.PHONY: phpstan php-cs-fixer + +tools/vendor: + composer install -d tools + +phpstan: tools/vendor + php tools/vendor/bin/phpstan + +php-cs-fixer: tools/vendor + php tools/vendor/bin/php-cs-fixer fix + +tests: + php vendor/bin/phpunit \ No newline at end of file diff --git a/README.md b/README.md index 4c8deada93..edb3ed32f3 100644 --- a/README.md +++ b/README.md @@ -3,24 +3,24 @@ PHP Parser [![Coverage Status](https://coveralls.io/repos/github/nikic/PHP-Parser/badge.svg?branch=master)](https://coveralls.io/github/nikic/PHP-Parser?branch=master) -This is a PHP 5.2 to PHP 8.0 parser written in PHP. Its purpose is to simplify static code analysis and +This is a PHP parser written in PHP. Its purpose is to simplify static code analysis and manipulation. -[**Documentation for version 4.x**][doc_master] (stable; for running on PHP >= 7.0; for parsing PHP 5.2 to PHP 8.0). +[**Documentation for version 5.x**][doc_master] (current; for running on PHP >= 7.4; for parsing PHP 7.0 to PHP 8.4, with limited support for parsing PHP 5.x). -[Documentation for version 3.x][doc_3_x] (unsupported; for running on PHP >= 5.5; for parsing PHP 5.2 to PHP 7.2). +[Documentation for version 4.x][doc_4_x] (supported; for running on PHP >= 7.0; for parsing PHP 5.2 to PHP 8.3). Features -------- The main features provided by this library are: - * Parsing PHP 5, PHP 7, and PHP 8 code into an abstract syntax tree (AST). + * Parsing PHP 7, and PHP 8 code into an abstract syntax tree (AST). * Invalid code can be parsed into a partial AST. * The AST contains accurate location information. * Dumping the AST in human-readable form. * Converting an AST back to PHP code. - * Experimental: Formatting can be preserved for partially changed ASTs. + * Formatting can be preserved for partially changed ASTs. * Infrastructure to traverse and modify ASTs. * Resolution of namespaced names. * Evaluation of constant expressions. @@ -51,7 +51,7 @@ function test($foo) } CODE; -$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); +$parser = (new ParserFactory())->createForNewestSupportedVersion(); try { $ast = $parser->parse($code); } catch (Error $error) { @@ -68,12 +68,17 @@ This dumps an AST looking something like this: ``` array( 0: Stmt_Function( + attrGroups: array( + ) byRef: false name: Identifier( name: test ) params: array( 0: Param( + attrGroups: array( + ) + flags: 0 type: null byRef: false variadic: false @@ -88,12 +93,11 @@ array( 0: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: var_dump - ) + name: var_dump ) args: array( 0: Arg( + name: null value: Expr_Variable( name: foo ) @@ -135,12 +139,16 @@ This gives us an AST where the `Function_::$stmts` are empty: ``` array( 0: Stmt_Function( + attrGroups: array( + ) byRef: false name: Identifier( name: test ) params: array( 0: Param( + attrGroups: array( + ) type: null byRef: false variadic: false @@ -203,9 +211,8 @@ Component documentation: * [AST builders](doc/component/AST_builders.markdown) * Fluent builders for AST nodes * [Lexer](doc/component/Lexer.markdown) - * Lexer options - * Token and file positions for nodes - * Custom attributes + * Emulation + * Tokens, positions and attributes * [Error handling](doc/component/Error_handling.markdown) * Column information for errors * Error recovery (parsing of syntactically incorrect code) @@ -215,11 +222,12 @@ Component documentation: * [JSON representation](doc/component/JSON_representation.markdown) * JSON encoding and decoding of ASTs * [Performance](doc/component/Performance.markdown) - * Disabling XDebug + * Disabling Xdebug * Reusing objects * Garbage collection impact * [Frequently asked questions](doc/component/FAQ.markdown) * Parent and sibling references [doc_3_x]: https://github.com/nikic/PHP-Parser/tree/3.x/doc + [doc_4_x]: https://github.com/nikic/PHP-Parser/tree/4.x/doc [doc_master]: https://github.com/nikic/PHP-Parser/tree/master/doc diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md new file mode 100644 index 0000000000..cc323cad1e --- /dev/null +++ b/UPGRADE-5.0.md @@ -0,0 +1,534 @@ +Upgrading from PHP-Parser 4.x to 5.0 +==================================== + +### PHP version requirements + +PHP-Parser now requires PHP 7.4 or newer to run. It is however still possible to *parse* code for older versions, while running on a newer version. + +### PHP 5 parsing support + +The dedicated parser for PHP 5 has been removed. The PHP 7 parser now accepts a `PhpVersion` argument, which can be used to improve compatibility with older PHP versions. + +In particular, if an older `PhpVersion` is specified, then: + + * For versions before PHP 7.0, `$foo =& new Bar()` assignments are allowed without error. + * For versions before PHP 7.0, invalid octal literals `089` are allowed without error. + * For versions before PHP 7.0, unicode escape sequences `\u{123}` in strings are not parsed. + * Type hints are interpreted as a class `Name` or as a built-in `Identifier` depending on PHP + version, for example `int` is treated as a class name on PHP 5.6 and as a built-in on PHP 7.0. + +However, some aspects of PHP 5 parsing are no longer supported: + + * Some variables like `$$foo[0]` are valid in both PHP 5 and PHP 7, but have different interpretation. In that case, the PHP 7 AST will always be constructed (`($$foo)[0]` rather than `${$foo[0]}`). + * Declarations of the form `global $$var[0]` are not supported in PHP 7 and will cause a parse error. In error recovery mode, it is possible to continue parsing after such declarations. + * The PHP 7 parser will accept many constructs that are not valid in PHP 5. However, this was also true of the dedicated PHP 5 parser. + +The following symbols are affected by this removal: + + * The `PhpParser\Parser\Php5` class has been removed. + * The `PhpParser\Parser\Multiple` class has been removed. While not strictly related to PHP 5 support, this functionality is no longer useful without it. + * The `PhpParser\ParserFactory::ONLY_PHP5` and `PREFER_PHP5` options have been removed. + +### Changes to the parser factory + +The `ParserFactory::create()` method has been removed in favor of three new methods that provide more fine-grained control over the PHP version being targeted: + + * `createForNewestSupportedVersion()`: Use this if you don't know the PHP version of the code you're parsing. It's better to assume a too new version than a too old one. + * `createForHostVersion()`: Use this if you're parsing code for the PHP version you're running on. + * `createForVersion()`: Use this if you know the PHP version of the code you want to parse. + +The `createForNewestSupportedVersion()` and `createForHostVersion()` are available since PHP-Parser 4.18.0, to allow libraries to support PHP-Parser 4 and 5 at the same time more easily. + +In all cases, the PHP version is a fairly weak hint that is only used on a best-effort basis. The parser will usually accept code for newer versions if it does not have any backwards-compatibility implications. + +For example, if you specify version `"8.0"`, then `class ReadOnly {}` is treated as a valid class declaration, while using `public readonly int $prop` will lead to a parse error. However, `final public const X = Y;` will be accepted in both cases. + +```php +use PhpParser\ParserFactory; +use PhpParser\PhpVersion; + +$factory = new ParserFactory(); + +# Before +$parser = $factory->create(ParserFactory::PREFER_PHP7); + +# After (this is roughly equivalent to PREFER_PHP7 behavior) +$parser = $factory->createForNewestSupportedVersion(); +# Or +$parser = $factory->createForHostVersion(); + +# Before +$parser = $factory->create(ParserFactory::ONLY_PHP5); +# After (supported on a best-effort basis) +$parser = $factory->createForVersion(PhpVersion::fromString("5.6")); +``` + +### Changes to the throw representation + +Previously, `throw` statements like `throw $e;` were represented using the `Stmt\Throw_` class, +while uses inside other expressions (such as `$x ?? throw $e`) used the `Expr\Throw_` class. + +Now, `throw $e;` is represented as a `Stmt\Expression` that contains an `Expr\Throw_`. The +`Stmt\Throw_` class has been removed. + +```php +# Code +throw $e; + +# Before +Stmt_Throw( + expr: Expr_Variable( + name: e + ) +) + +# After +Stmt_Expression( + expr: Expr_Throw( + expr: Expr_Variable( + name: e + ) + ) +) +``` + +### Changes to the array destructuring representation + +Previously, the `list($x) = $y` destructuring syntax was represented using a `Node\Expr\List_` +node, while `[$x] = $y` used a `Node\Expr\Array_` node, the same used for the creation (rather than +destructuring) of arrays. + +Now, destructuring is always represented using `Node\Expr\List_`. The `kind` attribute with value +`Node\Expr\List_::KIND_LIST` or `Node\Expr\List_::KIND_ARRAY` specifies which syntax was actually +used. + +```php +# Code +[$x] = $y; + +# Before +Expr_Assign( + var: Expr_Array( + items: array( + 0: Expr_ArrayItem( + key: null + value: Expr_Variable( + name: x + ) + byRef: false + unpack: false + ) + ) + ) + expr: Expr_Variable( + name: y + ) +) + +# After +Expr_Assign( + var: Expr_List( + items: array( + 0: ArrayItem( + key: null + value: Expr_Variable( + name: x + ) + byRef: false + unpack: false + ) + ) + ) + expr: Expr_Variable( + name: y + ) +) +``` + +### Changes to the name representation + +Previously, `Name` nodes had a `parts` subnode, which stores an array of name parts, split by +namespace separators. Now, `Name` nodes instead have a `name` subnode, which stores a plain string. + +For example, the name `Foo\Bar` was previously represented by `Name(parts: ['Foo', 'Bar'])` and is +now represented by `Name(name: 'Foo\Bar')` instead. + +It is possible to convert the name to the previous representation using `$name->getParts()`. The +`Name` constructor continues to accept both the string and the array representation. + +The `Name::getParts()` method is available since PHP-Parser 4.16.0, to allow libraries to support +PHP-Parser 4 and 5 at the same time more easily. + +### Changes to the block representation + +Previously, code blocks `{ ... }` were always flattened into their parent statement list. For +example `while ($x) { $a; { $b; } $c; }` would produce the same node structure as +`if ($x) { $a; $b; $c; }`, namely a `Stmt\While_` node whose `stmts` subnode is an array of three +statements. + +Now, the nested `{ $b; }` block is represented using an explicit `Stmt\Block` node. However, the +outer `{ $a; { $b; } $c; }` block is still represented using a simple array in the `stmts` subnode. + +```php +# Code +while ($x) { $a; { $b; } $c; } + +# Before +Stmt_While( + cond: Expr_Variable( + name: x + ) + stmts: array( + 0: Stmt_Expression( + expr: Expr_Variable( + name: a + ) + ) + 1: Stmt_Expression( + expr: Expr_Variable( + name: b + ) + ) + 2: Stmt_Expression( + expr: Expr_Variable( + name: c + ) + ) + ) +) + +# After +Stmt_While( + cond: Expr_Variable( + name: x + ) + stmts: array( + 0: Stmt_Expression( + expr: Expr_Variable( + name: a + ) + ) + 1: Stmt_Block( + stmts: array( + 0: Stmt_Expression( + expr: Expr_Variable( + name: b + ) + ) + ) + ) + 2: Stmt_Expression( + expr: Expr_Variable( + name: c + ) + ) + ) +) +``` + +### Changes to comment assignment + +Previously, comments were assigned to all nodes starting at the same position. Now they will be +assigned to the outermost node only. + +```php +# Code +// Comment +$a + $b; + +# Before +Stmt_Expression( + expr: Expr_BinaryOp_Plus( + left: Expr_Variable( + name: a + comments: array( + 0: // Comment + ) + ) + right: Expr_Variable( + name: b + ) + comments: array( + 0: // Comment + ) + ) + comments: array( + 0: // Comment + ) +) + +# After +Stmt_Expression( + expr: Expr_BinaryOp_Plus( + left: Expr_Variable( + name: a + ) + right: Expr_Variable( + name: b + ) + ) + comments: array( + 0: // Comment + ) +) +``` + +### Renamed nodes + +A number of AST nodes have been renamed or moved in the AST hierarchy: + + * `Node\Scalar\LNumber` is now `Node\Scalar\Int_`. + * `Node\Scalar\DNumber` is now `Node\Scalar\Float_`. + * `Node\Scalar\Encapsed` is now `Node\Scalar\InterpolatedString`. + * `Node\Scalar\EncapsedStringPart` is now `Node\InterpolatedStringPart` and no longer extends + `Node\Scalar` or `Node\Expr`. + * `Node\Expr\ArrayItem` is now `Node\ArrayItem` and no longer extends `Node\Expr`. + * `Node\Expr\ClosureUse` is now `Node\ClosureUse` and no longer extends `Node\Expr`. + * `Node\Stmt\DeclareDeclare` is now `Node\DeclareItem` and no longer extends `Node\Stmt`. + * `Node\Stmt\PropertyProperty` is now `Node\PropertyItem` and no longer extends `Node\Stmt`. + * `Node\Stmt\StaticVar` is now `Node\StaticVar` and no longer extends `Node\Stmt`. + * `Node\Stmt\UseUse` is now `Node\UseItem` and no longer extends `Node\Stmt`. + +The old class names have been retained as aliases for backwards compatibility. However, the `Node::getType()` method will now always return the new name (e.g. `ClosureUse` instead of `Expr_ClosureUse`). + +### Modifiers + +Modifier flags (as used by the `$flags` subnode of `Class_`, `ClassMethod`, `Property`, etc.) are now available as class constants on a separate `PhpParser\Modifiers` class, instead of being part of `PhpParser\Node\Stmt\Class_`, to make it clearer that these are used by many different nodes. The old constants are deprecated, but are still available. + +```php +PhpParser\Node\Stmt\Class_::MODIFIER_PUBLIC -> PhpParser\Modifiers::PUBLIC +PhpParser\Node\Stmt\Class_::MODIFIER_PROTECTED -> PhpParser\Modifiers::PROTECTED +PhpParser\Node\Stmt\Class_::MODIFIER_PRIVATE -> PhpParser\Modifiers::PRIVATE +PhpParser\Node\Stmt\Class_::MODIFIER_STATIC -> PhpParser\Modifiers::STATIC +PhpParser\Node\Stmt\Class_::MODIFIER_ABSTRACT -> PhpParser\Modifiers::ABSTRACT +PhpParser\Node\Stmt\Class_::MODIFIER_FINAL -> PhpParser\Modifiers::FINAL +PhpParser\Node\Stmt\Class_::MODIFIER_READONLY -> PhpParser\Modifiers::READONLY +PhpParser\Node\Stmt\Class_::VISIBILITY_MODIFIER_MASK -> PhpParser\Modifiers::VISIBILITY_MASK +``` + +### Changes to node constructors + +Node constructor arguments accepting types no longer accept plain strings. Either an `Identifier` or `Name` (or `ComplexType`) should be passed instead. This affects the following constructor arguments: + +* The `'returnType'` key of `$subNodes` argument of `Node\Expr\ArrowFunction`. +* The `'returnType'` key of `$subNodes` argument of `Node\Expr\Closure`. +* The `'returnType'` key of `$subNodes` argument of `Node\Stmt\ClassMethod`. +* The `'returnType'` key of `$subNodes` argument of `Node\Stmt\Function_`. +* The `$type` argument of `Node\NullableType`. +* The `$type` argument of `Node\Param`. +* The `$type` argument of `Node\Stmt\Property`. +* The `$type` argument of `Node\ClassConst`. + +To follow the previous behavior, an `Identifier` should be passed, which indicates a built-in type. + +### Changes to the pretty printer + +A number of changes to the standard pretty printer have been made, to make it match contemporary coding style conventions (and in particular PSR-12). Options to restore the previous behavior are not provided, but it is possible to override the formatting methods (such as `pStmt_ClassMethod`) with your preferred formatting. + +Return types are now formatted without a space before the `:`: + +```php +# Before +function test() : Type +{ +} + +# After +function test(): Type +{ +} +``` + +`abstract` and `final` are now printed before visibility modifiers: + +```php +# Before +public abstract function test(); + +# After +abstract public function test(); +``` + +A space is now printed between `use` and the following `(` for closures: + +```php +# Before +function () use($var) { +}; + +# After +function () use ($var) { +}; +``` + +Backslashes in single-quoted strings are now only printed if they are necessary: + +```php +# Before +'Foo\\Bar'; +'\\\\'; + +# After +'Foo\Bar'; +'\\\\'; +``` + +`else if` structures will now omit redundant parentheses: + +```php +# Before +else { + if ($x) { + // ... + } +} + +# After +else if ($x) { + // ... +} +``` + +The pretty printer now accepts a `phpVersion` option, which accepts a `PhpVersion` object and defaults to PHP 7.4. The pretty printer will make formatting choices to make the code valid for that version. It currently controls the following behavior: + +* For PHP >= 7.0 (default), short array syntax `[]` will be used by default. This does not affect nodes that specify an explicit array syntax using the `kind` attribute. +* For PHP >= 7.0 (default), parentheses around `yield` expressions will only be printed when necessary. Previously, parentheses were always printed, even if `yield` was used as a statement. +* For PHP >= 7.1 (default), the short array syntax `[]` will be used for destructuring by default (instead of `list()`). This does not affect nodes that specify an explicit syntax using the `kind` attribute. +* For PHP >= 7.3 (default), a newline is no longer forced after heredoc/nowdoc strings, as the requirement for this has been removed with the introduction of flexible heredoc/nowdoc strings. +* For PHP >= 7.3 (default), heredoc/nowdoc strings are now indented just like regular code. This was allowed with the introduction of flexible heredoc/nowdoc strings. + +### Changes to precedence handling in the pretty printer + +The pretty printer now more accurately models operator precedence. Especially for unary operators, less unnecessary parentheses will be printed. Conversely, many bugs where semantically meaningful parentheses were omitted have been fixed. + +To support these changes, precedence is now handled differently in the pretty printer. The internal `p()` method, which is used to recursively print nodes, now has the following signature: +```php +protected function p( + Node $node, int $precedence = self::MAX_PRECEDENCE, int $lhsPrecedence = self::MAX_PRECEDENCE, + bool $parentFormatPreserved = false +): string; +``` + +The `$precedence` is the precedence of the direct parent operator (if any), while `$lhsPrecedence` is that precedence of the nearest binary operator on whose left-hand-side the node occurs. For unary operators, only the `$lhsPrecedence` is relevant. + +Recursive calls in pretty-printer methods should generally continue calling `p()` without additional parameters. However, pretty-printer methods for operators that participate in precedence resolution need to be adjusted. For example, typical implementations for operators look as follows now: + +```php +protected function pExpr_BinaryOp_Plus( + BinaryOp\Plus $node, int $precedence, int $lhsPrecedence +): string { + return $this->pInfixOp( + BinaryOp\Plus::class, $node->left, ' + ', $node->right, $precedence, $lhsPrecedence); +} + +protected function pExpr_UnaryPlus( + Expr\UnaryPlus $node, int $precedence, int $lhsPrecedence +): string { + return $this->pPrefixOp(Expr\UnaryPlus::class, '+', $node->expr, $precedence, $lhsPrecedence); +} +``` + +The new `$precedence` and `$lhsPrecedence` arguments need to be passed down to the `pInfixOp()`, `pPrefixOp()` and `pPostfixOp()` methods. + +### Changes to the node traverser + +If there are multiple visitors, the node traverser will now call `leaveNode()` and `afterTraverse()` methods in the reverse order of the corresponding `enterNode()` and `beforeTraverse()` calls: + +```php +# Before +$visitor1->enterNode($node); +$visitor2->enterNode($node); +$visitor1->leaveNode($node); +$visitor2->leaveNode($node); + +# After +$visitor1->enterNode($node); +$visitor2->enterNode($node); +$visitor2->leaveNode($node); +$visitor1->leaveNode($node); +``` + +Additionally, the special `NodeVisitor` return values have been moved from `NodeTraverser` to `NodeVisitor`. The old names are deprecated, but still available. + +```php +PhpParser\NodeTraverser::REMOVE_NODE -> PhpParser\NodeVisitor::REMOVE_NODE +PhpParser\NodeTraverser::DONT_TRAVERSE_CHILDREN -> PhpParser\NodeVisitor::DONT_TRAVERSE_CHILDREN +PhpParser\NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN -> PhpParser\NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN +PhpParser\NodeTraverser::STOP_TRAVERSAL -> PhpParser\NodeVisitor::STOP_TRAVERSAL +``` + +Visitors can now also be passed directly to the `NodeTraverser` constructor: + +```php +# Before (and still supported) +$traverser = new NodeTraverser(); +$traverser->addVisitor(new NameResolver()); + +# After +$traverser = new NodeTraverser(new NameResolver()); +``` + +### Changes to token representation + +Tokens are now internally represented using the `PhpParser\Token` class, which exposes the same base interface as +the `PhpToken` class introduced in PHP 8.0. On PHP 8.0 or newer, `PhpParser\Token` extends from `PhpToken`, otherwise +it extends from a polyfill implementation. The most important parts of the interface may be summarized as follows: + +```php +class Token { + public int $id; + public string $text; + public int $line; + public int $pos; + + public function is(int|string|array $kind): bool; +} +``` + +The token array is now an array of `Token`s, rather than an array of arrays and strings. +Additionally, the token array is now terminated by a sentinel token with ID 0. + +### Changes to the lexer + +The lexer API is reduced to a single `Lexer::tokenize()` method, which returns an array of tokens. The `startLexing()` and `getNextToken()` methods have been removed. + +Responsibility for determining start and end attributes for nodes has been moved from the lexer to the parser. The lexer no longer accepts an options array. The `usedAttributes` option has been removed without replacement, and the parser will now unconditionally add the `comments`, `startLine`, `endLine`, `startFilePos`, `endFilePos`, `startTokenPos` and `endTokenPos` attributes. + +There should no longer be a need to directly interact with the `Lexer` for end users, as the `ParserFactory` will create an appropriate instance, and no additional configuration of the lexer is necessary. To use formatting-preserving pretty printing, the setup boilerplate changes as follows: + +```php +# Before + +$lexer = new Lexer\Emulative([ + 'usedAttributes' => [ + 'comments', + 'startLine', 'endLine', + 'startTokenPos', 'endTokenPos', + ], +]); + +$parser = new Parser\Php7($lexer); +$oldStmts = $parser->parse($code); +$oldTokens = $lexer->getTokens(); + +$traverser = new NodeTraverser(); +$traverser->addVisitor(new NodeVisitor\CloningVisitor()); +$newStmts = $traverser->traverse($oldStmts); + +# After + +$parser = (new ParserFactory())->createForNewestSupportedVersion(); +$oldStmts = $parser->parse($code); +$oldTokens = $parser->getTokens(); + +$traverser = new NodeTraverser(new NodeVisitor\CloningVisitor()); +$newStmts = $traverser->traverse($oldStmts); +``` + +### Miscellaneous changes + + * The deprecated `Builder\Param::setTypeHint()` method has been removed in favor of `Builder\Param::setType()`. + * The deprecated `Error` constructor taking a start line has been removed. Pass `['startLine' => $startLine]` attributes instead. + * The deprecated `Comment::getLine()`, `Comment::getTokenPos()` and `Comment::getFilePos()` methods have been removed. Use `Comment::getStartLine()`, `Comment::getStartTokenPos()` and `Comment::getStartFilePos()` instead. + * `Comment::getReformattedText()` now normalizes CRLF newlines to LF newlines. + * The `Node::getLine()` method has been deprecated. Use `Node::getStartLine()` instead. diff --git a/bin/php-parse b/bin/php-parse index a002f85271..fc44f234c5 100755 --- a/bin/php-parse +++ b/bin/php-parse @@ -10,7 +10,7 @@ foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php ini_set('xdebug.max_nesting_level', 3000); -// Disable XDebug var_dump() output truncation +// Disable Xdebug var_dump() output truncation ini_set('xdebug.var_display_max_children', -1); ini_set('xdebug.var_display_max_data', -1); ini_set('xdebug.var_display_max_depth', -1); @@ -26,13 +26,7 @@ if (empty($files)) { showHelp("Must specify at least one file."); } -$lexer = new PhpParser\Lexer\Emulative(['usedAttributes' => [ - 'startLine', 'endLine', 'startFilePos', 'endFilePos', 'comments' -]]); -$parser = (new PhpParser\ParserFactory)->create( - PhpParser\ParserFactory::PREFER_PHP7, - $lexer -); +$parser = (new PhpParser\ParserFactory())->createForVersion($attributes['version']); $dumper = new PhpParser\NodeDumper([ 'dumpComments' => true, 'dumpPositions' => $attributes['with-positions'], @@ -43,7 +37,10 @@ $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor(new PhpParser\NodeVisitor\NameResolver); foreach ($files as $file) { - if (strpos($file, ' Stdin:\n"); + } else if (strpos($file, ' Code $code\n"); } else { @@ -108,7 +105,7 @@ function showHelp($error = '') { if ($error) { fwrite(STDERR, $error . "\n\n"); } - fwrite($error ? STDERR : STDOUT, << false, 'with-positions' => false, 'with-recovery' => false, + 'version' => PhpParser\PhpVersion::getNewestSupported(), ]; array_shift($args); @@ -193,7 +192,9 @@ function parseArgs($args) { $parseOptions = false; break; default: - if ($arg[0] === '-') { + if (preg_match('/^--version=(.*)$/', $arg, $matches)) { + $attributes['version'] = PhpParser\PhpVersion::fromString($matches[1]); + } elseif ($arg[0] === '-' && \strlen($arg[0]) > 1) { showHelp("Invalid operation $arg."); } else { $files[] = $arg; diff --git a/composer.json b/composer.json index 2fd064a212..b52f3ee57d 100644 --- a/composer.json +++ b/composer.json @@ -13,16 +13,18 @@ } ], "require": { - "php": ">=7.0", - "ext-tokenizer": "*" + "php": ">=7.4", + "ext-tokenizer": "*", + "ext-json": "*", + "ext-ctype": "*" }, "require-dev": { - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0", + "phpunit/phpunit": "^9.0", "ircmaxell/php-yacc": "^0.0.7" }, "extra": { "branch-alias": { - "dev-master": "4.9-dev" + "dev-master": "5.0-dev" } }, "autoload": { diff --git a/doc/0_Introduction.markdown b/doc/0_Introduction.markdown index 433cf10499..3c1de6fc38 100644 --- a/doc/0_Introduction.markdown +++ b/doc/0_Introduction.markdown @@ -1,7 +1,7 @@ Introduction ============ -This project is a PHP 5.2 to PHP 7.4 parser **written in PHP itself**. +This project is a PHP parser **written in PHP itself**. What is this for? ----------------- @@ -13,25 +13,42 @@ application dealing with code programmatically. A parser constructs an [Abstract There are other ways of processing source code. One that PHP supports natively is using the token stream generated by [`token_get_all`][2]. The token stream is much more low level than the AST and thus has different applications: It allows to also analyze the exact formatting of -a file. On the other hand the token stream is much harder to deal with for more complex analysis. +a file. On the other hand, the token stream is much harder to deal with for more complex analysis. For example, an AST abstracts away the fact that, in PHP, variables can be written as `$foo`, but also as `$$bar`, `${'foobar'}` or even `${!${''}=barfoo()}`. You don't have to worry about recognizing all the different syntaxes from a stream of tokens. Another question is: Why would I want to have a PHP parser *written in PHP*? Well, PHP might not be a language especially suited for fast parsing, but processing the AST is much easier in PHP than it -would be in other, faster languages like C. Furthermore the people most probably wanting to do +would be in other, faster languages like C. Furthermore the people most likely wanting to do programmatic PHP code analysis are incidentally PHP developers, not C developers. What can it parse? ------------------ -The parser supports parsing PHP 5.2-7.4. +The parser supports parsing PHP 7 and PHP 8 code, with the following exceptions: + + * Namespaced names containing whitespace (e.g. `Foo \ Bar` instead of `Foo\Bar`) are not supported. + These are illegal in PHP 8, but are legal in earlier versions. However, PHP-Parser does not + support them for any version. + +PHP-Parser 4.x had full support for parsing PHP 5. PHP-Parser 5.x has only limited support, with the +following caveats: + + * Some variable expressions like `$$foo[0]` are valid in both PHP 5 and PHP 7, but have different + interpretation. In such cases, the PHP 7 AST will always be constructed (using `($$foo)[0]` + rather than `${$foo[0]}`). + * Declarations of the form `global $$var[0]` are not supported in PHP 7 and will cause a parse + error. In error recovery mode, it is possible to continue parsing after such declarations. As the parser is based on the tokens returned by `token_get_all` (which is only able to lex the PHP version it runs on), additionally a wrapper for emulating tokens from newer versions is provided. -This allows to parse PHP 7.4 source code running on PHP 7.0, for example. This emulation is somewhat -hacky and not perfect, but it should work well on any sane code. +This allows to parse PHP 8.4 source code running on PHP 7.4, for example. This emulation is not +perfect, but works well in practice. + +Finally, it should be noted that the parser aims to accept all valid code, not reject all invalid +code. It will generally accept code that is only valid in newer versions (even when targeting an +older one), and accept code that is syntactically correct, but would result in a compiler error. What output does it produce? ---------------------------- @@ -59,21 +76,21 @@ This matches the structure of the code: An echo statement, which takes two strin with the values `Hi` and `World`. You can also see that the AST does not contain any whitespace information (but most comments are saved). -So using it for formatting analysis is not possible. +However, it does retain accurate position information, which can be used to inspect precise formatting. What else can it do? -------------------- -Apart from the parser itself this package also bundles support for some other, related features: +Apart from the parser itself, this package also bundles support for some other, related features: * Support for pretty printing, which is the act of converting an AST into PHP code. Please note that "pretty printing" does not imply that the output is especially pretty. It's just how it's called ;) - * Support for serializing and unserializing the node tree to JSON - * Support for dumping the node tree in a human readable form (see the section above for an - example of how the output looks like) - * Infrastructure for traversing and changing the AST (node traverser and node visitors) - * A node visitor for resolving namespaced names + * Support for serializing and unserializing the node tree to JSON. + * Support for dumping the node tree in a human-readable form (see the section above for an + example of how the output looks like). + * Infrastructure for traversing and changing the AST (node traverser and node visitors). + * A node visitor for resolving namespaced names. [0]: http://en.wikipedia.org/wiki/Static_program_analysis [1]: http://en.wikipedia.org/wiki/Abstract_syntax_tree diff --git a/doc/2_Usage_of_basic_components.markdown b/doc/2_Usage_of_basic_components.markdown index 7fabd5cf69..462c8adf3e 100644 --- a/doc/2_Usage_of_basic_components.markdown +++ b/doc/2_Usage_of_basic_components.markdown @@ -12,14 +12,14 @@ To bootstrap the library, include the autoloader generated by composer: require 'path/to/vendor/autoload.php'; ``` -Additionally you may want to set the `xdebug.max_nesting_level` ini option to a higher value: +Additionally, you may want to set the `xdebug.max_nesting_level` ini option to a higher value: ```php ini_set('xdebug.max_nesting_level', 3000); ``` This ensures that there will be no errors when traversing highly nested node trees. However, it is -preferable to disable XDebug completely, as it can easily make this library more than five times +preferable to disable Xdebug completely, as it can easily make this library more than five times slower. Parsing @@ -29,25 +29,29 @@ In order to parse code, you first have to create a parser instance: ```php use PhpParser\ParserFactory; -$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); -``` +use PhpParser\PhpVersion; + +// Parser for the version you are running on. +$parser = (new ParserFactory())->createForHostVersion(); -The factory accepts a kind argument, that determines how different PHP versions are treated: +// Parser for the newest PHP version supported by the PHP-Parser library. +$parser = (new ParserFactory())->createForNewestSupportedVersion(); -Kind | Behavior ------|--------- -`ParserFactory::PREFER_PHP7` | Try to parse code as PHP 7. If this fails, try to parse it as PHP 5. -`ParserFactory::PREFER_PHP5` | Try to parse code as PHP 5. If this fails, try to parse it as PHP 7. -`ParserFactory::ONLY_PHP7` | Parse code as PHP 7. -`ParserFactory::ONLY_PHP5` | Parse code as PHP 5. +// Parser for a specific PHP version. +$parser = (new ParserFactory())->createForVersion(PhpVersion::fromString('8.1')); +``` -Unless you have a strong reason to use something else, `PREFER_PHP7` is a reasonable default. +Which version you should target depends on your use case. In many cases you will want to use the +host version, as people typically analyze code for the version they are running on. However, when +analyzing arbitrary code you are usually best off using the newest supported version, which tends +to accept the widest range of code (unless there are breaking changes in PHP). -The `create()` method optionally accepts a `Lexer` instance as the second argument. Some use cases -that require customized lexers are discussed in the [lexer documentation](component/Lexer.markdown). +The `createXYZ()` methods optionally accept an array of lexer options. Some use cases that require +customized lexer options are discussed in the [lexer documentation](component/Lexer.markdown). -Subsequently you can pass PHP code (including the opening `create(ParserFactory::PREFER_PHP7); +$parser = (new ParserFactory())->createForHostVersion(); try { $stmts = $parser->parse($code); // $stmts is an array of statement nodes } catch (Error $e) { - echo 'Parse Error: ', $e->getMessage(); + echo 'Parse Error: ', $e->getMessage(), "\n"; } ``` @@ -77,7 +81,7 @@ A parser instance can be reused to parse multiple files. Node dumping ------------ -To dump the abstract syntax tree in human readable form, a `NodeDumper` can be used: +To dump the abstract syntax tree in human-readable form, a `NodeDumper` can be used: ```php create(ParserFactory::PREFER_PHP7); -$prettyPrinter = new PrettyPrinter\Standard; +$parser = (new ParserFactory())->createForHostVersion(); +$prettyPrinter = new PrettyPrinter\Standard(); try { // parse @@ -237,7 +246,7 @@ try { echo $code; } catch (Error $e) { - echo 'Parse Error: ', $e->getMessage(); + echo 'Parse Error: ', $e->getMessage(), "\n"; } ``` @@ -245,7 +254,7 @@ The above code will output: echo 'Hello ', hi\getTarget(); -As you can see the source code was first parsed using `PhpParser\Parser->parse()`, then changed and then +As you can see, the source code was first parsed using `PhpParser\Parser->parse()`, then changed and then again converted to code using `PhpParser\PrettyPrinter\Standard->prettyPrint()`. The `prettyPrint()` method pretty prints a statements array. It is also possible to pretty print only a @@ -254,10 +263,13 @@ single expression using `prettyPrintExpr()`. The `prettyPrintFile()` method can be used to print an entire file. This will include the opening ` Read more: [Pretty printing documentation](component/Pretty_printing.markdown) -Node traversation ------------------ +Node traversal +-------------- The above pretty printing example used the fact that the source code was known and thus it was easy to write code that accesses a certain part of a node tree and changes it. Normally this is not the case. @@ -272,7 +284,7 @@ use PhpParser\NodeTraverser; use PhpParser\ParserFactory; use PhpParser\PrettyPrinter; -$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); +$parser = (new ParserFactory())->createForHostVersion(); $traverser = new NodeTraverser; $prettyPrinter = new PrettyPrinter\Standard; @@ -303,8 +315,7 @@ The corresponding node visitor might look like this: use PhpParser\Node; use PhpParser\NodeVisitorAbstract; -class MyNodeVisitor extends NodeVisitorAbstract -{ +class MyNodeVisitor extends NodeVisitorAbstract { public function leaveNode(Node $node) { if ($node instanceof Node\Scalar\String_) { $node->value = 'foo'; @@ -326,7 +337,7 @@ public function afterTraverse(array $nodes); ``` The `beforeTraverse()` method is called once before the traversal begins and is passed the nodes the -traverser was called with. This method can be used for resetting values before traversation or +traverser was called with. This method can be used for resetting values before traversal or preparing the tree for traversal. The `afterTraverse()` method is similar to the `beforeTraverse()` method, with the only difference that @@ -338,15 +349,18 @@ i.e. before its subnodes are traversed, the latter when it is left. All four methods can either return the changed node or not return at all (i.e. `null`) in which case the current node is not changed. -The `enterNode()` method can additionally return the value `NodeTraverser::DONT_TRAVERSE_CHILDREN`, +The `enterNode()` method can additionally return the value `NodeVisitor::DONT_TRAVERSE_CHILDREN`, which instructs the traverser to skip all children of the current node. To furthermore prevent subsequent -visitors from visiting the current node, `NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN` can be used instead. +visitors from visiting the current node, `NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN` can be used instead. + +Both methods can additionally return the following values: -The `leaveNode()` method can additionally return the value `NodeTraverser::REMOVE_NODE`, in which -case the current node will be removed from the parent array. Furthermore it is possible to return -an array of nodes, which will be merged into the parent array at the offset of the current node. -I.e. if in `array(A, B, C)` the node `B` should be replaced with `array(X, Y, Z)` the result will -be `array(A, X, Y, Z, C)`. + * `NodeVisitor::STOP_TRAVERSAL`, in which case no further nodes will be visited. + * `NodeVisitor::REMOVE_NODE`, in which case the current node will be removed from the parent array. + * `NodeVisitor::REPLACE_WITH_NULL`, in which case the current node will be replaced with `null`. + * An array of nodes, which will be merged into the parent array at the offset of the current node. + I.e. if in `array(A, B, C)` the node `B` should be replaced with `array(X, Y, Z)` the result will + be `array(A, X, Y, Z, C)`. Instead of manually implementing the `NodeVisitor` interface you can also extend the `NodeVisitorAbstract` class, which will define empty default implementations for all the above methods. @@ -372,15 +386,16 @@ unqualified function and constant names. These are resolved at runtime and thus know which function they are referring to. In most cases this is a non-issue as the global functions are meant. -Also the `NameResolver` adds a `namespacedName` subnode to class, function and constant declarations -that contains the namespaced name instead of only the shortname that is available via `name`. +Additionally, the `NameResolver` adds a `namespacedName` subnode to class, function and constant +declarations that contains the namespaced name instead of only the shortname that is available via +`name`. > Read more: [Name resolution documentation](component/Name_resolution.markdown) Example: Converting namespaced code to pseudo namespaces -------------------------------------------------------- -A small example to understand the concept: We want to convert namespaced code to pseudo namespaces +A small example to understand the concept: We want to convert namespaced code to pseudo namespaces, so it works on 5.2, i.e. names like `A\\B` should be converted to `A_B`. Note that such conversions are fairly complicated if you take PHP's dynamic features into account, so our conversion will assume that no dynamic features are used. @@ -396,7 +411,7 @@ use PhpParser\NodeVisitor\NameResolver; $inDir = '/some/path'; $outDir = '/some/other/path'; -$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); +$parser = (new ParserFactory())->createForNewestSupportedVersion(); $traverser = new NodeTraverser; $prettyPrinter = new PrettyPrinter\Standard; @@ -432,7 +447,7 @@ foreach ($files as $file) { } ``` -Now lets start with the main code, the `NodeVisitor\NamespaceConverter`. One thing it needs to do +Now lets start with the main code, the `NamespaceConverter`. One thing it needs to do is convert `A\\B` style names to `A_B` style ones. ```php @@ -487,7 +502,7 @@ The last thing we need to do is remove the `namespace` and `use` statements: ```php use PhpParser\Node; use PhpParser\Node\Stmt; -use PhpParser\NodeTraverser; +use PhpParser\NodeVisitor; class NodeVisitor_NamespaceConverter extends \PhpParser\NodeVisitorAbstract { @@ -507,7 +522,7 @@ class NodeVisitor_NamespaceConverter extends \PhpParser\NodeVisitorAbstract return $node->stmts; } elseif ($node instanceof Stmt\Use_) { // remove use nodes altogether - return NodeTraverser::REMOVE_NODE; + return NodeVisitor::REMOVE_NODE; } } } diff --git a/doc/README.md b/doc/README.md index 3b8cd76563..0b4149f851 100644 --- a/doc/README.md +++ b/doc/README.md @@ -27,9 +27,8 @@ Component documentation * [AST builders](component/AST_builders.markdown) * Fluent builders for AST nodes * [Lexer](component/Lexer.markdown) - * Lexer options - * Token and file positions for nodes - * Custom attributes + * Emulation + * Tokens, positions and attributes * [Error handling](component/Error_handling.markdown) * Column information for errors * Error recovery (parsing of syntactically incorrect code) @@ -39,7 +38,7 @@ Component documentation * [JSON representation](component/JSON_representation.markdown) * JSON encoding and decoding of ASTs * [Performance](component/Performance.markdown) - * Disabling XDebug + * Disabling Xdebug * Reusing objects * Garbage collection impact * [Frequently asked questions](component/FAQ.markdown) diff --git a/doc/component/AST_builders.markdown b/doc/component/AST_builders.markdown index 60ae0192df..fc3533af6e 100644 --- a/doc/component/AST_builders.markdown +++ b/doc/component/AST_builders.markdown @@ -15,9 +15,10 @@ accessed through `getNode()`. Fluent builders are available for the following syntactic elements: * namespaces and use statements - * classes, interfaces and traits + * classes, interfaces, traits and enums * methods, functions and parameters - * properties + * properties, class constants and enum cases + * trait uses and trait use adaptations Here is an example: @@ -95,13 +96,13 @@ abstract class SomeOtherClass extends SomeClass implements A\Few, \Interfaces AnotherTrait::func insteadof SecondTrait; } protected $someProperty; - private $anotherProperty = array(1, 2, 3); + private $anotherProperty = [1, 2, 3]; /** * This method does something. * * @param SomeClass And takes a parameter */ - public abstract function someMethod(SomeClass $someParam) : bool; + abstract public function someMethod(SomeClass $someParam): bool; protected function anotherMethod($someParam = 'test') { print $someParam; @@ -133,6 +134,8 @@ nodes. The following methods are currently available: * `propertyFetch($var, $name)`: Creates a property fetch node. Converts `$name` to an `Identifier` node. * `concat(...$exprs)`: Create a tree of `BinaryOp\Concat` nodes for the given expressions. + * `attribute($name, $args)`: Create a `Attribute` node. Converts `$name` to a `Name` node and + normalizes arguments. These methods may be expanded on an as-needed basis. Please open an issue or PR if a common operation is missing. diff --git a/doc/component/Constant_expression_evaluation.markdown b/doc/component/Constant_expression_evaluation.markdown index 9ab4f5c395..1a42a5272e 100644 --- a/doc/component/Constant_expression_evaluation.markdown +++ b/doc/component/Constant_expression_evaluation.markdown @@ -19,9 +19,9 @@ PHP-Parser supports evaluation of such constant expressions through the `ConstEx use PhpParser\{ConstExprEvaluator, ConstExprEvaluationException}; -$evalutator = new ConstExprEvaluator(); +$evaluator = new ConstExprEvaluator(); try { - $value = $evalutator->evaluateSilently($someExpr); + $value = $evaluator->evaluateSilently($someExpr); } catch (ConstExprEvaluationException $e) { // Either the expression contains unsupported expression types, // or an error occurred during evaluation @@ -45,7 +45,7 @@ use PhpParser\Node\{Expr, Scalar}; $evaluator = new ConstExprEvaluator(); // 10 / 0 -$expr = new Expr\BinaryOp\Div(new Scalar\LNumber(10), new Scalar\LNumber(0)); +$expr = new Expr\BinaryOp\Div(new Scalar\Int_(10), new Scalar\Int_(0)); var_dump($evaluator->evaluateDirectly($expr)); // float(INF) // Warning: Division by zero @@ -69,6 +69,8 @@ expressions, apart from the following: * `Scalar\MagicConst\*` * `Expr\ConstFetch` (only null/false/true are handled) * `Expr\ClassConstFetch` + * `Expr\New_` (since PHP 8.1) + * `Expr\PropertyFetch` (since PHP 8.2) Handling these expression types requires non-local information, such as which global constants are defined. By default, the evaluator will throw a `ConstExprEvaluationException` when it encounters @@ -83,7 +85,7 @@ specifying an evaluation fallback function: use PhpParser\{ConstExprEvaluator, ConstExprEvaluationException}; use PhpParser\Node\Expr; -$evalutator = new ConstExprEvaluator(function(Expr $expr) { +$evaluator = new ConstExprEvaluator(function(Expr $expr) { if ($expr instanceof Expr\ConstFetch) { return fetchConstantSomehow($expr); } @@ -96,7 +98,7 @@ $evalutator = new ConstExprEvaluator(function(Expr $expr) { }); try { - $evalutator->evaluateSilently($someExpr); + $evaluator->evaluateSilently($someExpr); } catch (ConstExprEvaluationException $e) { // Handle exception } @@ -112,4 +114,4 @@ class Test { const A = self::B; const B = self::A; } -``` \ No newline at end of file +``` diff --git a/doc/component/Error_handling.markdown b/doc/component/Error_handling.markdown index fc088130ea..597bf0094d 100644 --- a/doc/component/Error_handling.markdown +++ b/doc/component/Error_handling.markdown @@ -4,29 +4,12 @@ Error handling Errors during parsing or analysis are represented using the `PhpParser\Error` exception class. In addition to an error message, an error can also store additional information about the location the error occurred at. -How much location information is available depends on the origin of the error and how many lexer attributes have been -enabled. At a minimum the start line of the error is usually available. +How much location information is available depends on the origin of the error. At a minimum the start line of the error +is usually available. Column information ------------------ -In order to receive information about not only the line, but also the column span an error occurred at, the file -position attributes in the lexer need to be enabled: - -```php -$lexer = new PhpParser\Lexer(array( - 'usedAttributes' => array('comments', 'startLine', 'endLine', 'startFilePos', 'endFilePos'), -)); -$parser = (new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::PREFER_PHP7, $lexer); - -try { - $stmts = $parser->parse($code); - // ... -} catch (PhpParser\Error $e) { - // ... -} -``` - Before using column information, its availability needs to be checked with `$e->hasColumnInfo()`, as the precise location of an error cannot always be determined. The methods for retrieving column information also have to be passed the source code of the parsed file. An example for printing an error: @@ -56,7 +39,7 @@ To instead collect all encountered errors into an array, while trying to continu an instance of `ErrorHandler\Collecting` can be passed to the `Parser::parse()` method. A usage example: ```php -$parser = (new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::ONLY_PHP7); +$parser = (new PhpParser\ParserFactory())->createForHostVersion(); $errorHandler = new PhpParser\ErrorHandler\Collecting; $stmts = $parser->parse($code, $errorHandler); @@ -72,4 +55,6 @@ if (null !== $stmts) { } ``` +The partial AST may contain `Expr\Error` nodes that indicate that an error occurred while parsing an expression. + The `NameResolver` visitor also accepts an `ErrorHandler` as a constructor argument. diff --git a/doc/component/FAQ.markdown b/doc/component/FAQ.markdown index 1a70a48c68..2ef13f6707 100644 --- a/doc/component/FAQ.markdown +++ b/doc/component/FAQ.markdown @@ -16,10 +16,9 @@ use PhpParser\ParserFactory; $code = '...'; -$traverser = new NodeTraverser; -$traverser->addVisitor(new ParentConnectingVisitor); +$traverser = new NodeTraverser(new ParentConnectingVisitor); -$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); +$parser = (new ParserFactory())->createForHostVersion(); $ast = $parser->parse($code); $ast = $traverser->traverse($ast); ``` @@ -39,10 +38,9 @@ use PhpParser\ParserFactory; $code = '...'; -$traverser = new NodeTraverser; -$traverser->addVisitor(new NodeConnectingVisitor); +$traverser = new NodeTraverser(new NodeConnectingVisitor); -$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); +$parser = (new ParserFactory())->createForHostVersion(); $ast = $parser->parse($code); $ast = $traverser->traverse($ast); ``` @@ -53,3 +51,17 @@ obtained through `$node->getAttribute('next')`. `ParentConnectingVisitor` and `NodeConnectingVisitor` should not be used at the same time. The latter includes the functionality of the former. + + +How can I limit the impact of cyclic references in the AST? +----- + +NodeConnectingVisitor adds a parent reference, which introduces a cycle. This means that the AST can now only be collected by the cycle garbage collector. +This in turn can lead to performance and/or memory issues. + +To break the cyclic references between AST nodes `NodeConnectingVisitor` supports a boolean `$weakReferences` constructor parameter. +When set to `true`, all attributes added by `NodeConnectingVisitor` will be wrapped into a `WeakReference` object. + +After enabling this parameter, the parent node can be obtained through `$node->getAttribute('weak_parent')`, +the previous node can be obtained through `$node->getAttribute('weak_previous')`, and the next node can be +obtained through `$node->getAttribute('weak_next')`. \ No newline at end of file diff --git a/doc/component/JSON_representation.markdown b/doc/component/JSON_representation.markdown index 47c3429c07..46684ebd1e 100644 --- a/doc/component/JSON_representation.markdown +++ b/doc/component/JSON_representation.markdown @@ -18,7 +18,7 @@ function printLine($msg) { } CODE; -$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); +$parser = (new ParserFactory())->createForHostVersion(); try { $stmts = $parser->parse($code); @@ -35,78 +35,86 @@ This will result in the following output (which includes attributes): [ { "nodeType": "Stmt_Function", + "attributes": { + "startLine": 4, + "comments": [ + { + "nodeType": "Comment_Doc", + "text": "\/** @param string $msg *\/", + "line": 3, + "filePos": 7, + "tokenPos": 2, + "endLine": 3, + "endFilePos": 31, + "endTokenPos": 2 + } + ], + "endLine": 6 + }, "byRef": false, "name": { "nodeType": "Identifier", - "name": "printLine", "attributes": { "startLine": 4, "endLine": 4 - } + }, + "name": "printLine" }, "params": [ { "nodeType": "Param", + "attributes": { + "startLine": 4, + "endLine": 4 + }, "type": null, "byRef": false, "variadic": false, "var": { "nodeType": "Expr_Variable", - "name": "msg", "attributes": { "startLine": 4, "endLine": 4 - } + }, + "name": "msg" }, "default": null, - "attributes": { - "startLine": 4, - "endLine": 4 - } + "flags": 0, + "attrGroups": [] } ], "returnType": null, "stmts": [ { "nodeType": "Stmt_Echo", + "attributes": { + "startLine": 5, + "endLine": 5 + }, "exprs": [ { "nodeType": "Expr_Variable", - "name": "msg", "attributes": { "startLine": 5, "endLine": 5 - } + }, + "name": "msg" }, { "nodeType": "Scalar_String", - "value": "\n", "attributes": { "startLine": 5, "endLine": 5, - "kind": 2 - } + "kind": 2, + "rawValue": "\"\\n\"" + }, + "value": "\n" } - ], - "attributes": { - "startLine": 5, - "endLine": 5 - } + ] } ], - "attributes": { - "startLine": 4, - "comments": [ - { - "nodeType": "Comment_Doc", - "text": "\/** @param string $msg *\/", - "line": 3, - "filePos": 9, - "tokenPos": 2 - } - ], - "endLine": 6 - } + "attrGroups": [], + "namespacedName": null } ] ``` diff --git a/doc/component/Lexer.markdown b/doc/component/Lexer.markdown index be26e381e5..1b8e4ce041 100644 --- a/doc/component/Lexer.markdown +++ b/doc/component/Lexer.markdown @@ -1,57 +1,96 @@ Lexer component documentation ============================= -The lexer is responsible for providing tokens to the parser. The project comes with two lexers: `PhpParser\Lexer` and -`PhpParser\Lexer\Emulative`. The latter is an extension of the former, which adds the ability to emulate tokens of -newer PHP versions and thus allows parsing of new code on older versions. +The lexer is responsible for providing tokens to the parser. Typical use of the library does not require direct +interaction with the lexer, as an appropriate lexer is created by `PhpParser\ParserFactory`. The tokens produced +by the lexer can then be retrieved using `PhpParser\Parser::getTokens()`. -This documentation discusses options available for the default lexers and explains how lexers can be extended. +Emulation +--------- -Lexer options -------------- +While this library implements a custom parser, it relies on PHP's `ext/tokenizer` extension to perform lexing. However, +this extension only supports lexing code for the PHP version you are running on, while this library also wants to support +parsing newer code. For that reason, the lexer performs additional "emulation" in three layers: -The two default lexers accept an `$options` array in the constructor. Currently only the `'usedAttributes'` option is -supported, which allows you to specify which attributes will be added to the AST nodes. The attributes can then be -accessed using `$node->getAttribute()`, `$node->setAttribute()`, `$node->hasAttribute()` and `$node->getAttributes()` -methods. A sample options array: +First, PhpParser uses the `PhpToken` based representation introduced in PHP 8.0, rather than the array-based tokens from +previous versions. The `PhpParser\Token` class either extends `PhpToken` (on PHP 8.0) or a polyfill implementation. The +polyfill implementation will also perform two emulations that are required by the parser and cannot be disabled: + + * Single-line comments use the PHP 8.0 representation that does not include a trailing newline. The newline will be + part of a following `T_WHITESPACE` token. + * Namespaced names use the PHP 8.0 representation using `T_NAME_FULLY_QUALIFIED`, `T_NAME_QUALIFIED` and + `T_NAME_RELATIVE` tokens, rather than the previous representation using a sequence of `T_STRING` and `T_NS_SEPARATOR`. + This means that certain code that is legal on older versions (namespaced names including whitespace, such as `A \ B`) + will not be accepted by the parser. + +Second, the `PhpParser\Lexer` base class will convert `&` tokens into the PHP 8.1 representation of either +`T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG` or `T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG`. This is required by the parser +and cannot be disabled. + +Finally, `PhpParser\Lexer\Emulative` performs other, optional emulations. This lexer is parameterized by `PhpVersion` +and will try to emulate `ext/tokenizer` output for that version. This is done using separate `TokenEmulator`s for each +emulated feature. + +Emulation is usually used to support newer PHP versions, but there is also very limited support for reverse emulation to +older PHP versions, which can make keywords from newer versions non-reserved. + +Tokens, positions and attributes +-------------------------------- + +The `Lexer::tokenize()` method returns an array of `PhpParser\Token`s. The most important parts of the interface can be +summarized as follows: ```php -$lexer = new PhpParser\Lexer(array( - 'usedAttributes' => array( - 'comments', 'startLine', 'endLine' - ) -)); +class Token { + /** @var int Token ID, either T_* or ord($char) for single-character tokens. */ + public int $id; + /** @var string The textual content of the token. */ + public string $text; + /** @var int The 1-based starting line of the token (or -1 if unknown). */ + public int $line; + /** @var int The 0-based starting position of the token (or -1 if unknown). */ + public int $pos; + + /** @param int|string|(int|string)[] $kind Token ID or text (or array of them) */ + public function is($kind): bool; +} ``` -The attributes used in this example match the default behavior of the lexer. The following attributes are supported: +Unlike PHP's own `PhpToken::tokenize()` output, the token array is terminated by a sentinel token with ID 0. + +The lexer is normally invoked implicitly by the parser. In that case, the tokens for the last parse can be retrieved +using `Parser::getTokens()`. - * `comments`: Array of `PhpParser\Comment` or `PhpParser\Comment\Doc` instances, representing all comments that occurred - between the previous non-discarded token and the current one. Use of this attribute is required for the - `$node->getComments()` and `$node->getDocComment()` methods to work. The attribute is also needed if you wish the pretty - printer to retain comments present in the original code. - * `startLine`: Line in which the node starts. This attribute is required for the `$node->getLine()` to work. It is also - required if syntax errors should contain line number information. - * `endLine`: Line in which the node ends. Required for `$node->getEndLine()`. - * `startTokenPos`: Offset into the token array of the first token in the node. Required for `$node->getStartTokenPos()`. - * `endTokenPos`: Offset into the token array of the last token in the node. Required for `$node->getEndTokenPos()`. - * `startFilePos`: Offset into the code string of the first character that is part of the node. Required for `$node->getStartFilePos()`. - * `endFilePos`: Offset into the code string of the last character that is part of the node. Required for `$node->getEndFilePos()`. +Nodes in the AST produced by the parser always corresponds to some range of tokens. The parser adds a number of +positioning attributes to allow mapping nodes back to lines, tokens or file offsets: + + * `startLine`: Line in which the node starts. Used by `$node->getStartLine()`. + * `endLine`: Line in which the node ends. Used by `$node->getEndLine()`. + * `startTokenPos`: Offset into the token array of the first token in the node. Used by `$node->getStartTokenPos()`. + * `endTokenPos`: Offset into the token array of the last token in the node. Used by `$node->getEndTokenPos()`. + * `startFilePos`: Offset into the code string of the first character that is part of the node. Used by `$node->getStartFilePos()`. + * `endFilePos`: Offset into the code string of the last character that is part of the node. Used by `$node->getEndFilePos()`. + +Note that `start`/`end` here are closed rather than half-open ranges. This means that a node consisting of a single +token will have `startTokenPos == endTokenPos` rather than `startTokenPos + 1 == endTokenPos`. This also means that a +zero-length node will have `startTokenPos -1 == endTokenPos`. ### Using token positions > **Note:** The example in this section is outdated in that this information is directly available in the AST: While > `$property->isPublic()` does not distinguish between `public` and `var`, directly checking `$property->flags` for > the `$property->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0` allows making this distinction without resorting to -> tokens. However the general idea behind the example still applies in other cases. +> tokens. However, the general idea behind the example still applies in other cases. The token offset information is useful if you wish to examine the exact formatting used for a node. For example the AST does not distinguish whether a property was declared using `public` or using `var`, but you can retrieve this information based on the token position: ```php +/** @param PhpParser\Token[] $tokens */ function isDeclaredUsingVar(array $tokens, PhpParser\Node\Stmt\Property $prop) { - $i = $prop->getAttribute('startTokenPos'); - return $tokens[$i][0] === T_VAR; + $i = $prop->getStartTokenPos(); + return $tokens[$i]->id === T_VAR; } ``` @@ -72,88 +111,16 @@ class MyNodeVisitor extends PhpParser\NodeVisitorAbstract { } } -$lexer = new PhpParser\Lexer(array( - 'usedAttributes' => array( - 'comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos' - ) -)); -$parser = (new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::ONLY_PHP7, $lexer); +$parser = (new PhpParser\ParserFactory())->createForHostVersion($lexerOptions); $visitor = new MyNodeVisitor(); -$traverser = new PhpParser\NodeTraverser(); -$traverser->addVisitor($visitor); +$traverser = new PhpParser\NodeTraverser($visitor); try { $stmts = $parser->parse($code); - $visitor->setTokens($lexer->getTokens()); + $visitor->setTokens($parser->getTokens()); $stmts = $traverser->traverse($stmts); } catch (PhpParser\Error $e) { echo 'Parse Error: ', $e->getMessage(); } ``` - -The same approach can also be used to perform specific modifications in the code, without changing the formatting in -other places (which is the case when using the pretty printer). - -Lexer extension ---------------- - -A lexer has to define the following public interface: - -```php -function startLexing(string $code, ErrorHandler $errorHandler = null): void; -function getTokens(): array; -function handleHaltCompiler(): string; -function getNextToken(string &$value = null, array &$startAttributes = null, array &$endAttributes = null): int; -``` - -The `startLexing()` method is invoked whenever the `parse()` method of the parser is called and is passed the source -code that is to be lexed (including the opening tag). It can be used to reset state or preprocess the source code or tokens. The -passed `ErrorHandler` should be used to report lexing errors. - -The `getTokens()` method returns the current token array, in the usual `token_get_all()` format. This method is not -used by the parser (which uses `getNextToken()`), but is useful in combination with the token position attributes. - -The `handleHaltCompiler()` method is called whenever a `T_HALT_COMPILER` token is encountered. It has to return the -remaining string after the construct (not including `();`). - -The `getNextToken()` method returns the ID of the next token (as defined by the `Parser::T_*` constants). If no more -tokens are available it must return `0`, which is the ID of the `EOF` token. Furthermore the string content of the -token should be written into the by-reference `$value` parameter (which will then be available as `$n` in the parser). - -### Attribute handling - -The other two by-ref variables `$startAttributes` and `$endAttributes` define which attributes will eventually be -assigned to the generated nodes: The parser will take the `$startAttributes` from the first token which is part of the -node and the `$endAttributes` from the last token that is part of the node. - -E.g. if the tokens `T_FUNCTION T_STRING ... '{' ... '}'` constitute a node, then the `$startAttributes` from the -`T_FUNCTION` token will be taken and the `$endAttributes` from the `'}'` token. - -An application of custom attributes is storing the exact original formatting of literals: While the parser does retain -some information about the formatting of integers (like decimal vs. hexadecimal) or strings (like used quote type), it -does not preserve the exact original formatting (e.g. leading zeros for integers or escape sequences in strings). This -can be remedied by storing the original value in an attribute: - -```php -use PhpParser\Lexer; -use PhpParser\Parser\Tokens; - -class KeepOriginalValueLexer extends Lexer // or Lexer\Emulative -{ - public function getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null) { - $tokenId = parent::getNextToken($value, $startAttributes, $endAttributes); - - if ($tokenId == Tokens::T_CONSTANT_ENCAPSED_STRING // non-interpolated string - || $tokenId == Tokens::T_ENCAPSED_AND_WHITESPACE // interpolated string - || $tokenId == Tokens::T_LNUMBER // integer - || $tokenId == Tokens::T_DNUMBER // floating point number - ) { - // could also use $startAttributes, doesn't really matter here - $endAttributes['originalValue'] = $value; - } - - return $tokenId; - } -} -``` diff --git a/doc/component/Name_resolution.markdown b/doc/component/Name_resolution.markdown index 2a7eb603a9..c7416d5898 100644 --- a/doc/component/Name_resolution.markdown +++ b/doc/component/Name_resolution.markdown @@ -10,7 +10,7 @@ visitor (NameResolver) based on it. The NameResolver visitor ------------------------ -The `NameResolver` visitor can (and for nearly all uses of the AST, is) be applied to resolve names +The `NameResolver` visitor can (and for nearly all uses of the AST, should) be applied to resolve names to their fully-qualified form, to the degree that this is possible. ```php @@ -24,7 +24,7 @@ $stmts = $nodeTraverser->traverse($stmts); In the default configuration, the name resolver will perform three actions: - * Declarations of functions, classes, interfaces, traits and global constants will have a + * Declarations of functions, classes, interfaces, traits, enums and global constants will have a `namespacedName` property added, which contains the function/class/etc name including the namespace prefix. For historic reasons this is a **property** rather than an attribute. * Names will be replaced by fully qualified resolved names, which are instances of @@ -32,7 +32,7 @@ In the default configuration, the name resolver will perform three actions: * Unqualified function and constant names inside a namespace cannot be statically resolved. Inside a namespace `Foo`, a call to `strlen()` may either refer to the namespaced `\Foo\strlen()`, or the global `\strlen()`. Because PHP-Parser does not have the necessary context to decide this, - such names are left unresolved. Additionally a `namespacedName` **attribute** is added to the + such names are left unresolved. Additionally, a `namespacedName` **attribute** is added to the name node. The name resolver accepts an option array as the second argument, with the following default values: @@ -47,13 +47,13 @@ $nameResolver = new PhpParser\NodeVisitor\NameResolver(null, [ If the `preserveOriginalNames` option is enabled, then the resolved (fully qualified) name will have an `originalName` attribute, which contains the unresolved name. -If the `replaceNodes` option is disabled, then names will no longer be resolved in-place. Instead a +If the `replaceNodes` option is disabled, then names will no longer be resolved in-place. Instead, a `resolvedName` attribute will be added to each name, which contains the resolved (fully qualified) name. Once again, if an unqualified function or constant name cannot be resolved, then the `resolvedName` attribute will not be present, and instead a `namespacedName` attribute is added. The `replaceNodes` attribute is useful if you wish to perform modifications on the AST, as you -probably do not wish the resoluting code to have fully resolved names as a side-effect. +probably do not wish the resulting code to have fully resolved names as a side-effect. The NameContext --------------- @@ -75,7 +75,7 @@ class NameContext { } ``` -The `$type` parameters accept on of the `Stmt\Use_::TYPE_*` constants, which represent the three +The `$type` parameters accept one of the `Stmt\Use_::TYPE_*` constants, which represent the three basic symbol types in PHP (functions, constants and everything else). Next to name resolution, the `NameContext` also supports the reverse operation of finding a short @@ -84,4 +84,4 @@ representation of a name given the current name resolution environment. The name context is intended to be used for name resolution operations outside the AST itself, such as class names inside doc comments. A visitor running in parallel with the name resolver can access the name context using `$nameResolver->getNameContext()`. Alternatively a visitor can use an -independent context and explicitly feed `Namespace` and `Use` nodes to it. \ No newline at end of file +independent context and explicitly feed `Namespace` and `Use` nodes to it. diff --git a/doc/component/Performance.markdown b/doc/component/Performance.markdown index 4281ce8cbe..350b13637a 100644 --- a/doc/component/Performance.markdown +++ b/doc/component/Performance.markdown @@ -8,20 +8,20 @@ described in the following. Xdebug ------ -Running PHP with XDebug adds a lot of overhead, especially for code that performs many method calls. -Just by loading XDebug (without enabling profiling or other more intrusive XDebug features), you +Running PHP with Xdebug adds a lot of overhead, especially for code that performs many method calls. +Just by loading Xdebug (without enabling profiling or other more intrusive Xdebug features), you can expect that code using PHP-Parser will be approximately *five times slower*. -As such, you should make sure that XDebug is not loaded when using this library. Note that setting -the `xdebug.default_enable=0` ini option does *not* disable XDebug. The *only* way to disable -XDebug is to not load the extension in the first place. +As such, you should make sure that Xdebug is not loaded when using this library. Note that setting +the `xdebug.default_enable=0` ini option does *not* disable Xdebug. The *only* way to disable +Xdebug is to not load the extension in the first place. -If you are building a command-line utility for use by developers (who often have XDebug enabled), -you may want to consider automatically restarting PHP with XDebug unloaded. The +If you are building a command-line utility for use by developers (who often have Xdebug enabled), +you may want to consider automatically restarting PHP with Xdebug unloaded. The [composer/xdebug-handler](https://github.com/composer/xdebug-handler) package can be used to do this. -If you do run with XDebug, you may need to increase the `xdebug.max_nesting_level` option to a +If you do run with Xdebug, you may need to increase the `xdebug.max_nesting_level` option to a higher level, such as 3000. While the parser itself is recursion free, most other code working on the AST uses recursion and will generate an error if the value of this option is too low. @@ -40,26 +40,5 @@ parse multiple files. When possible, objects should be reused rather than being newly instantiated for every use. Some objects have expensive initialization procedures, which will be unnecessarily repeated if the object -is not reused. (Currently two objects with particularly expensive setup are lexers and pretty +is not reused. (Currently two objects with particularly expensive setup are parsers and pretty printers, though the details might change between versions of this library.) - -Garbage collection ------------------- - -A limitation in PHP's cyclic garbage collector may lead to major performance degradation when the -active working set exceeds 10000 objects (or arrays). Especially when parsing very large files this -limit is significantly exceeded and PHP will spend the majority of time performing unnecessary -garbage collection attempts. - -Without GC, parsing time is roughly linear in the input size. With GC, this degenerates to quadratic -runtime for large files. While the specifics may differ, as a rough guideline you may expect a 2.5x -GC overhead for 500KB files and a 5x overhead for 1MB files. - -Because this a limitation in PHP's implementation, there is no easy way to work around this. If -possible, you should avoid parsing very large files, as they will impact overall execution time -disproportionally (and are usually generated anyway). - -Of course, you can also try to (temporarily) disable GC. By design the AST generated by PHP-Parser -is cycle-free, so the AST itself will never cause leaks with GC disabled. However, other code -(including for example the parser object itself) may hold cycles, so disabling of GC should be -approached with care. \ No newline at end of file diff --git a/doc/component/Pretty_printing.markdown b/doc/component/Pretty_printing.markdown index d6198e315f..f7b9501609 100644 --- a/doc/component/Pretty_printing.markdown +++ b/doc/component/Pretty_printing.markdown @@ -31,10 +31,30 @@ expression. Customizing the formatting -------------------------- -Apart from an `shortArraySyntax` option, the default pretty printer does not provide any -functionality to customize the formatting of the generated code. The pretty printer does respect a -number of `kind` attributes used by some notes (e.g., whether an integer should be printed as -decimal, hexadecimal, etc), but there are no options to control brace placement or similar. +The pretty printer respects a number of `kind` attributes used by some nodes (e.g., whether an +integer should be printed as decimal, hexadecimal, etc). Additionally, it supports three options: + +* `phpVersion` (defaults to 7.4) allows opting into formatting that is not supported by older PHP + versions. +* `newline` (defaults to `"\n"`) can be set to `"\r\n"` in order to produce Windows newlines. +* `indent` (defaults to four spaces `" "`) can be set to any number of spaces or a single tab. +* `shortArraySyntax` determines the used array syntax if the `kind` attribute is not set. This is + a legacy option, and `phpVersion` should be used to control this behavior instead. + +The behaviors controlled by `phpVersion` (defaults to PHP 7.4) are: + +* For PHP >= 7.0, short array syntax `[]` will be used by default. This does not affect nodes that + specify an explicit array syntax using the `kind` attribute. +* For PHP >= 7.0, parentheses around `yield` expressions will only be printed when necessary. +* For PHP >= 7.1, the short array syntax `[]` will be used for destructuring by default (instead of + `list()`). This does not affect nodes that specify and explicit syntax using the `kind` attribute. +* For PHP >= 7.3, a newline is no longer forced after heredoc/nowdoc strings, as the requirement + for this has been removed with the introduction of flexible heredoc/nowdoc strings. +* For PHP >= 7.3, heredoc/nowdoc strings are indented just like regular code. This was allowed with + the introduction of flexible heredoc/nowdoc strings. + +The default pretty printer does not provide functionality for fine-grained customization of code +formatting. If you want to make minor changes to the formatting, the easiest way is to extend the pretty printer and override the methods responsible for the node types you are interested in. @@ -46,51 +66,37 @@ default pretty printer with an existing library for code reformatting, such as Formatting-preserving pretty printing ------------------------------------- -> **Note:** This functionality is **experimental** and not yet complete. - For automated code refactoring, migration and similar, you will usually only want to modify a small portion of the code and leave the remainder alone. The basic pretty printer is not suitable for this, because it will also reformat parts of the code which have not been modified. -Since PHP-Parser 4.0, an experimental formatting-preserving pretty-printing mode is available, which +Since PHP-Parser 4.0, a formatting-preserving pretty-printing mode is available, which attempts to preserve the formatting of code (those AST nodes that have not changed) and only reformat code which has been modified or newly inserted. Use of the formatting-preservation functionality requires some additional preparatory steps: ```php -use PhpParser\{Lexer, NodeTraverser, NodeVisitor, Parser, PrettyPrinter}; - -$lexer = new Lexer\Emulative([ - 'usedAttributes' => [ - 'comments', - 'startLine', 'endLine', - 'startTokenPos', 'endTokenPos', - ], -]); -$parser = new Parser\Php7($lexer); - -$traverser = new NodeTraverser(); -$traverser->addVisitor(new NodeVisitor\CloningVisitor()); - -$printer = new PrettyPrinter\Standard(); +use PhpParser\{NodeTraverser, NodeVisitor, ParserFactory, PrettyPrinter}; +$parser = (new ParserFactory())->createForHostVersion(); $oldStmts = $parser->parse($code); -$oldTokens = $lexer->getTokens(); +$oldTokens = $parser->getTokens(); +// Run CloningVisitor before making changes to the AST. +$traverser = new NodeTraverser(new NodeVisitor\CloningVisitor()); $newStmts = $traverser->traverse($oldStmts); // MODIFY $newStmts HERE +$printer = new PrettyPrinter\Standard(); $newCode = $printer->printFormatPreserving($newStmts, $oldStmts, $oldTokens); ``` If you make use of the name resolution functionality, you will likely want to disable the -`replaceNodes` option. This will add resolved names as attributes, instead of directlying modifying +`replaceNodes` option. This will add resolved names as attributes, instead of directly modifying the AST and causing spurious changes to the pretty printed code. For more information, see the [name resolution documentation](Name_resolution.markdown). -This functionality is experimental and not yet fully implemented. It should not provide incorrect -code, but it may sometimes reformat more code than necessary. Open issues are tracked in -[issue #344](https://github.com/nikic/PHP-Parser/issues/344). If you encounter problems while using -this functionality, please open an issue, so we know what to prioritize. +The formatting-preservation works on a best-effort basis and may sometimes reformat more code than +necessary. If you encounter problems while using this functionality, please open an issue. diff --git a/doc/component/Walking_the_AST.markdown b/doc/component/Walking_the_AST.markdown index 81c4d3c0de..675d79794d 100644 --- a/doc/component/Walking_the_AST.markdown +++ b/doc/component/Walking_the_AST.markdown @@ -11,7 +11,7 @@ use PhpParser\{Node, NodeTraverser, NodeVisitorAbstract}; $traverser = new NodeTraverser; $traverser->addVisitor(new class extends NodeVisitorAbstract { public function leaveNode(Node $node) { - if ($node instanceof Node\Scalar\LNumber) { + if ($node instanceof Node\Scalar\Int_) { return new Node\Scalar\String_((string) $node->value); } } @@ -21,6 +21,18 @@ $stmts = ...; $modifiedStmts = $traverser->traverse($stmts); ``` +Visitors can be either passed to the `NodeTraverser` constructor, or added using `addVisitor()`: + +```php +$traverser = new NodeTraverser($visitor1, $visitor2, $visitor3); + +// Equivalent to: +$traverser = new NodeTraverser(); +$traverser->addVisitor($visitor1); +$traverser->addVisitor($visitor2); +$traverser->addVisitor($visitor3); +``` + Node visitors ------------- @@ -47,20 +59,19 @@ For example, if we have the following excerpt of an AST ``` Expr_FuncCall( - name: Name( - parts: array( - 0: printLine - ) - ) - args: array( - 0: Arg( - value: Scalar_String( - value: Hello World!!! - ) - byRef: false - unpack: false - ) - ) + name: Name( + name: printLine + ) + args: array( + 0: Arg( + name: null + value: Scalar_String( + value: Hello World!!! + ) + byRef: false + unpack: false + ) + ) ) ``` @@ -129,14 +140,13 @@ Now `$a && $b` will be replaced by `!($a && $b)`. Then the traverser will go int only) child of `!($a && $b)`, which is `$a && $b`. The transformation applies again and we end up with `!!($a && $b)`. This will continue until PHP hits the memory limit. -Finally, two special replacement types are supported only by leaveNode. The first is removal of a -node: +Finally, there are three special replacement types. The first is removal of a node: ```php public function leaveNode(Node $node) { if ($node instanceof Node\Stmt\Return_) { // Remove all return statements - return NodeTraverser::REMOVE_NODE; + return NodeVisitor::REMOVE_NODE; } } ``` @@ -156,7 +166,7 @@ public function leaveNode(Node $node) { && $node->expr->name instanceof Node\Name && $node->expr->name->toString() === 'var_dump' ) { - return NodeTraverser::REMOVE_NODE; + return NodeVisitor::REMOVE_NODE; } } ``` @@ -165,8 +175,22 @@ This example will remove all calls to `var_dump()` which occur as expression sta that `var_dump($a);` will be removed, but `if (var_dump($a))` will not be removed (and there is no obvious way in which it can be removed). -Next to removing nodes, it is also possible to replace one node with multiple nodes. Again, this -only works inside leaveNode and only if the parent structure is an array. +Another way to remove nodes is to replace them with `null`. For example, all `else` statements could +be removed as follows: + +```php +public function leaveNode(Node $node) { + if ($node instanceof Node\Stmt\Else_) { + return NodeVisitor::REPLACE_WITH_NULL; + } +} +``` + +This is only safe to do if the subnode the node is stored in is nullable. `Node\Stmt\Else_` only +occurs inside `Node\Stmt\If_::$else`, which is nullable, so this particular replacement is safe. + +Next to removing nodes, it is also possible to replace one node with multiple nodes. This +only works if the parent structure is an array. ```php public function leaveNode(Node $node) { @@ -193,12 +217,12 @@ anonymous classes), you know that once you've seen a class declaration, there is checking all it's child nodes, because PHP does not allow nesting classes. In this case, you can instruct the traverser to not recurse into the class node: -``` +```php private $classes = []; public function enterNode(Node $node) { if ($node instanceof Node\Stmt\Class_) { $this->classes[] = $node; - return NodeTraverser::DONT_TRAVERSE_CHILDREN; + return NodeVisitor::DONT_TRAVERSE_CHILDREN; } } ``` @@ -211,14 +235,14 @@ after finding it. For example, if you are looking for the node of a class with a discounting exotic cases like conditionally defining a class two times), you can stop traversal once you found it: -``` +```php private $class = null; public function enterNode(Node $node) { if ($node instanceof Node\Stmt\Class_ && $node->namespacedName->toString() === 'Foo\Bar\Baz' ) { $this->class = $node; - return NodeTraverser::STOP_TRAVERSAL; + return NodeVisitor::STOP_TRAVERSAL; } } ``` @@ -251,18 +275,19 @@ Stmt_Return( the following method calls will be performed: -``` +```php $visitorA->enterNode(Stmt_Return) $visitorB->enterNode(Stmt_Return) $visitorA->enterNode(Expr_Variable) $visitorB->enterNode(Expr_Variable) -$visitorA->leaveNode(Expr_Variable) $visitorB->leaveNode(Expr_Variable) -$visitorA->leaveNode(Stmt_Return) +$visitorA->leaveNode(Expr_Variable) $visitorB->leaveNode(Stmt_Return) +$visitorA->leaveNode(Stmt_Return) ``` -That is, when visiting a node, enterNode and leaveNode will always be called for all visitors. +That is, when visiting a node, `enterNode()` and `leaveNode()` will always be called for all +visitors, with the `leaveNode()` calls happening in the reverse order of the `enterNode()` calls. Running multiple visitors in parallel improves performance, as the AST only has to be traversed once. However, it is not always possible to write visitors in a way that allows interleaved execution. In this case, you can always fall back to performing multiple traversals: @@ -287,6 +312,7 @@ special enterNode/leaveNode return values: * If a visitor returns a replacement node, subsequent visitors will be passed the replacement node, not the original one. * If a visitor returns `REMOVE_NODE`, subsequent visitors will not see this node. + * If a visitor returns `REPLACE_WITH_NULL`, subsequent visitors will not see this node. * If a visitor returns an array of replacement nodes, subsequent visitors will see neither the node that was replaced, nor the replacement nodes. @@ -333,5 +359,6 @@ be accessed: From parents to children. However, it can often be convenient to op reverse direction: When working on a node, you might want to check if the parent node satisfies a certain property. -PHP-Parser does not add parent (or sibling) references to nodes by itself, but you can easily -emulate this with a visitor. See the [FAQ](FAQ.markdown) for more information. +PHP-Parser does not add parent (or sibling) references to nodes by default, but you can enable them +using the `ParentConnectingVisitor` or `NodeConnectingVisitor`. See the [FAQ](FAQ.markdown) for +more information. diff --git a/grammar/README.md b/grammar/README.md index 4bae11d826..bbb9bb4078 100644 --- a/grammar/README.md +++ b/grammar/README.md @@ -1,11 +1,8 @@ What do all those files mean? ============================= - * `php5.y`: PHP 5 grammar written in a pseudo language - * `php7.y`: PHP 7 grammar written in a pseudo language - * `tokens.y`: Tokens definition shared between PHP 5 and PHP 7 grammars + * `php.y`: PHP 5-8 grammar written in a pseudo language * `parser.template`: A `kmyacc` parser prototype file for PHP - * `tokens.template`: A `kmyacc` prototype file for the `Tokens` class * `rebuildParsers.php`: Preprocesses the grammar and builds the parser using `kmyacc` .phpy pseudo language diff --git a/grammar/parser.template b/grammar/parser.template index 6166607c9e..339cecced3 100644 --- a/grammar/parser.template +++ b/grammar/parser.template @@ -1,13 +1,14 @@ -semValue -#semval($,%t) $this->semValue +#semval($) $self->semValue +#semval($,%t) $self->semValue #semval(%n) $stackPos-(%l-%n) #semval(%n,%t) $stackPos-(%l-%n) namespace PhpParser\Parser; use PhpParser\Error; +use PhpParser\Modifiers; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Name; @@ -17,88 +18,90 @@ use PhpParser\Node\Stmt; /* This is an automatically GENERATED file, which should not be manually edited. * Instead edit one of the following: - * * the grammar files grammar/php5.y or grammar/php7.y + * * the grammar file grammar/php.y * * the skeleton file grammar/parser.template * * the preprocessing script grammar/rebuildParsers.php */ class #(-p) extends \PhpParser\ParserAbstract { - protected $tokenToSymbolMapSize = #(YYMAXLEX); - protected $actionTableSize = #(YYLAST); - protected $gotoTableSize = #(YYGLAST); +#tokenval + public const %s = %n; +#endtokenval - protected $invalidSymbol = #(YYBADCH); - protected $errorSymbol = #(YYINTERRTOK); - protected $defaultAction = #(YYDEFAULT); - protected $unexpectedTokenRule = #(YYUNEXPECTED); + protected int $tokenToSymbolMapSize = #(YYMAXLEX); + protected int $actionTableSize = #(YYLAST); + protected int $gotoTableSize = #(YYGLAST); - protected $YY2TBLSTATE = #(YY2TBLSTATE); - protected $numNonLeafStates = #(YYNLSTATES); + protected int $invalidSymbol = #(YYBADCH); + protected int $errorSymbol = #(YYINTERRTOK); + protected int $defaultAction = #(YYDEFAULT); + protected int $unexpectedTokenRule = #(YYUNEXPECTED); - protected $symbolToName = array( + protected int $YY2TBLSTATE = #(YY2TBLSTATE); + protected int $numNonLeafStates = #(YYNLSTATES); + + protected array $symbolToName = array( #listvar terminals ); - protected $tokenToSymbol = array( + protected array $tokenToSymbol = array( #listvar yytranslate ); - protected $action = array( + protected array $action = array( #listvar yyaction ); - protected $actionCheck = array( + protected array $actionCheck = array( #listvar yycheck ); - protected $actionBase = array( + protected array $actionBase = array( #listvar yybase ); - protected $actionDefault = array( + protected array $actionDefault = array( #listvar yydefault ); - protected $goto = array( + protected array $goto = array( #listvar yygoto ); - protected $gotoCheck = array( + protected array $gotoCheck = array( #listvar yygcheck ); - protected $gotoBase = array( + protected array $gotoBase = array( #listvar yygbase ); - protected $gotoDefault = array( + protected array $gotoDefault = array( #listvar yygdefault ); - protected $ruleToNonTerminal = array( + protected array $ruleToNonTerminal = array( #listvar yylhs ); - protected $ruleToLength = array( + protected array $ruleToLength = array( #listvar yylen ); #if -t - protected $productions = array( + protected array $productions = array( #production-strings; ); #endif - protected function initReduceCallbacks() { + protected function initReduceCallbacks(): void { $this->reduceCallbacks = [ #reduce - %n => function ($stackPos) { + %n => static function ($self, $stackPos) { %b }, #noact - %n => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, + %n => null, #endreduce ]; } diff --git a/grammar/php7.y b/grammar/php.y similarity index 63% rename from grammar/php7.y rename to grammar/php.y index 4ca244d8a6..44c76f8b0f 100644 --- a/grammar/php7.y +++ b/grammar/php.y @@ -1,7 +1,131 @@ %pure_parser %expect 2 -%tokens +%right T_VOID_CAST +%right T_THROW +%left T_INCLUDE T_INCLUDE_ONCE T_EVAL T_REQUIRE T_REQUIRE_ONCE +%left ',' +%left T_LOGICAL_OR +%left T_LOGICAL_XOR +%left T_LOGICAL_AND +%right T_PRINT +%right T_YIELD +%right T_DOUBLE_ARROW +%right T_YIELD_FROM +%left '=' T_PLUS_EQUAL T_MINUS_EQUAL T_MUL_EQUAL T_DIV_EQUAL T_CONCAT_EQUAL T_MOD_EQUAL T_AND_EQUAL T_OR_EQUAL T_XOR_EQUAL T_SL_EQUAL T_SR_EQUAL T_POW_EQUAL T_COALESCE_EQUAL +%left '?' ':' +%right T_COALESCE +%left T_BOOLEAN_OR +%left T_BOOLEAN_AND +%left '|' +%left '^' +%left T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG +%nonassoc T_IS_EQUAL T_IS_NOT_EQUAL T_IS_IDENTICAL T_IS_NOT_IDENTICAL T_SPACESHIP +%nonassoc '<' T_IS_SMALLER_OR_EQUAL '>' T_IS_GREATER_OR_EQUAL +#if PHP7 +%left T_SL T_SR +%left '+' '-' '.' +#endif +#if PHP8 +%left T_PIPE +%left '.' +%left T_SL T_SR +%left '+' '-' +#endif +%left '*' '/' '%' +%right '!' +%nonassoc T_INSTANCEOF +%right '~' T_INC T_DEC T_INT_CAST T_DOUBLE_CAST T_STRING_CAST T_ARRAY_CAST T_OBJECT_CAST T_BOOL_CAST T_UNSET_CAST '@' +%right T_POW +%right '[' +%nonassoc T_NEW T_CLONE +%token T_EXIT +%token T_IF +%left T_ELSEIF +%left T_ELSE +%left T_ENDIF +%token T_LNUMBER +%token T_DNUMBER +%token T_STRING +%token T_STRING_VARNAME +%token T_VARIABLE +%token T_NUM_STRING +%token T_INLINE_HTML +%token T_ENCAPSED_AND_WHITESPACE +%token T_CONSTANT_ENCAPSED_STRING +%token T_ECHO +%token T_DO +%token T_WHILE +%token T_ENDWHILE +%token T_FOR +%token T_ENDFOR +%token T_FOREACH +%token T_ENDFOREACH +%token T_DECLARE +%token T_ENDDECLARE +%token T_AS +%token T_SWITCH +%token T_MATCH +%token T_ENDSWITCH +%token T_CASE +%token T_DEFAULT +%token T_BREAK +%token T_CONTINUE +%token T_GOTO +%token T_FUNCTION +%token T_FN +%token T_CONST +%token T_RETURN +%token T_TRY +%token T_CATCH +%token T_FINALLY +%token T_THROW +%token T_USE +%token T_INSTEADOF +%token T_GLOBAL +%token T_STATIC T_ABSTRACT T_FINAL T_PRIVATE T_PROTECTED T_PUBLIC T_READONLY +%token T_PUBLIC_SET +%token T_PROTECTED_SET +%token T_PRIVATE_SET +%token T_VAR +%token T_UNSET +%token T_ISSET +%token T_EMPTY +%token T_HALT_COMPILER +%token T_CLASS +%token T_TRAIT +%token T_INTERFACE +%token T_ENUM +%token T_EXTENDS +%token T_IMPLEMENTS +%token T_OBJECT_OPERATOR +%token T_NULLSAFE_OBJECT_OPERATOR +%token T_DOUBLE_ARROW +%token T_LIST +%token T_ARRAY +%token T_CALLABLE +%token T_CLASS_C +%token T_TRAIT_C +%token T_METHOD_C +%token T_FUNC_C +%token T_PROPERTY_C +%token T_LINE +%token T_FILE +%token T_START_HEREDOC +%token T_END_HEREDOC +%token T_DOLLAR_OPEN_CURLY_BRACES +%token T_CURLY_OPEN +%token T_PAAMAYIM_NEKUDOTAYIM +%token T_NAMESPACE +%token T_NS_C +%token T_DIR +%token T_NS_SEPARATOR +%token T_ELLIPSIS +%token T_NAME_FULLY_QUALIFIED +%token T_NAME_QUALIFIED +%token T_NAME_RELATIVE +%token T_ATTRIBUTE +%token T_ENUM %% @@ -16,32 +140,38 @@ top_statement_list_ex: top_statement_list: top_statement_list_ex - { makeZeroLengthNop($nop, $this->lookaheadStartAttributes); + { makeZeroLengthNop($nop); if ($nop !== null) { $1[] = $nop; } $$ = $1; } ; +ampersand: + T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG + | T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG +; + reserved_non_modifiers: T_INCLUDE | T_INCLUDE_ONCE | T_EVAL | T_REQUIRE | T_REQUIRE_ONCE | T_LOGICAL_OR | T_LOGICAL_XOR | T_LOGICAL_AND - | T_INSTANCEOF | T_NEW | T_CLONE | T_EXIT | T_IF | T_ELSEIF | T_ELSE | T_ENDIF | T_ECHO | T_DO | T_WHILE + | T_INSTANCEOF | T_NEW | T_CLONE | T_EXIT | T_IF | T_ELSEIF | T_ELSE | T_ENDIF | T_DO | T_WHILE | T_ENDWHILE | T_FOR | T_ENDFOR | T_FOREACH | T_ENDFOREACH | T_DECLARE | T_ENDDECLARE | T_AS | T_TRY | T_CATCH | 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_FN - | T_MATCH + | T_CLASS_C | T_TRAIT_C | T_FUNC_C | T_METHOD_C | T_LINE | T_FILE | T_DIR | T_NS_C | T_FN + | T_MATCH | T_ENUM + | T_ECHO { $$ = $1; if ($$ === "emitError(new Error('Cannot use "lexer->handleHaltCompiler()]; } + statement + | function_declaration_statement + | class_declaration_statement + | T_HALT_COMPILER '(' ')' ';' + { $$ = Stmt\HaltCompiler[$this->handleHaltCompiler()]; } | T_NAMESPACE namespace_declaration_name semi { $$ = Stmt\Namespace_[$2, null]; $$->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON); @@ -128,8 +258,11 @@ top_statement: $this->checkNamespace($$); } | T_USE use_declarations semi { $$ = Stmt\Use_[$2, Stmt\Use_::TYPE_NORMAL]; } | T_USE use_type use_declarations semi { $$ = Stmt\Use_[$3, $2]; } - | group_use_declaration semi { $$ = $1; } - | T_CONST constant_declaration_list semi { $$ = Stmt\Const_[$2]; } + | group_use_declaration + | T_CONST constant_declaration_list semi { $$ = new Stmt\Const_($2, attributes(), []); } + | attributes T_CONST constant_declaration_list semi + { $$ = new Stmt\Const_($3, attributes(), $1); + $this->checkConstantAttributes($$); } ; use_type: @@ -138,14 +271,14 @@ use_type: ; group_use_declaration: - T_USE use_type legacy_namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations '}' + T_USE use_type legacy_namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations '}' semi { $$ = Stmt\GroupUse[$3, $6, $2]; } - | T_USE legacy_namespace_name T_NS_SEPARATOR '{' inline_use_declarations '}' + | T_USE legacy_namespace_name T_NS_SEPARATOR '{' inline_use_declarations '}' semi { $$ = Stmt\GroupUse[$2, $5, Stmt\Use_::TYPE_UNKNOWN]; } ; unprefixed_use_declarations: - non_empty_unprefixed_use_declarations optional_comma { $$ = $1; } + non_empty_unprefixed_use_declarations optional_comma ; non_empty_unprefixed_use_declarations: @@ -155,7 +288,7 @@ non_empty_unprefixed_use_declarations: ; use_declarations: - non_empty_use_declarations no_comma { $$ = $1; } + non_empty_use_declarations no_comma ; non_empty_use_declarations: @@ -164,7 +297,7 @@ non_empty_use_declarations: ; inline_use_declarations: - non_empty_inline_use_declarations optional_comma { $$ = $1; } + non_empty_inline_use_declarations optional_comma ; non_empty_inline_use_declarations: @@ -175,16 +308,16 @@ non_empty_inline_use_declarations: unprefixed_use_declaration: namespace_name - { $$ = Stmt\UseUse[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); } - | namespace_name T_AS identifier - { $$ = Stmt\UseUse[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); } + { $$ = Node\UseItem[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); } + | namespace_name T_AS identifier_not_reserved + { $$ = Node\UseItem[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); } ; use_declaration: legacy_namespace_name - { $$ = Stmt\UseUse[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); } - | legacy_namespace_name T_AS identifier - { $$ = Stmt\UseUse[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); } + { $$ = Node\UseItem[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); } + | legacy_namespace_name T_AS identifier_not_reserved + { $$ = Node\UseItem[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); } ; inline_use_declaration: @@ -193,7 +326,7 @@ inline_use_declaration: ; constant_declaration_list: - non_empty_constant_declaration_list no_comma { $$ = $1; } + non_empty_constant_declaration_list no_comma ; non_empty_constant_declaration_list: @@ -203,11 +336,11 @@ non_empty_constant_declaration_list: ; constant_declaration: - identifier '=' expr { $$ = Node\Const_[$1, $3]; } + identifier_not_reserved '=' expr { $$ = Node\Const_[$1, $3]; } ; class_const_list: - non_empty_class_const_list no_comma { $$ = $1; } + non_empty_class_const_list no_comma ; non_empty_class_const_list: @@ -216,7 +349,10 @@ non_empty_class_const_list: ; class_const: - identifier_ex '=' expr { $$ = Node\Const_[$1, $3]; } + T_STRING '=' expr + { $$ = Node\Const_[new Node\Identifier($1, stackAttributes(#1)), $3]; } + | semi_reserved '=' expr + { $$ = Node\Const_[new Node\Identifier($1, stackAttributes(#1)), $3]; } ; inner_statement_list_ex: @@ -226,34 +362,26 @@ inner_statement_list_ex: inner_statement_list: inner_statement_list_ex - { makeZeroLengthNop($nop, $this->lookaheadStartAttributes); + { makeZeroLengthNop($nop); if ($nop !== null) { $1[] = $nop; } $$ = $1; } ; inner_statement: - statement { $$ = $1; } - | function_declaration_statement { $$ = $1; } - | class_declaration_statement { $$ = $1; } + statement + | function_declaration_statement + | class_declaration_statement | T_HALT_COMPILER { throw new Error('__HALT_COMPILER() can only be used from the outermost scope', attributes()); } ; non_empty_statement: - '{' inner_statement_list '}' - { - if ($2) { - $$ = $2; prependLeadingComments($$); - } else { - makeNop($$, $this->startAttributeStack[#1], $this->endAttributes); - if (null === $$) { $$ = array(); } - } - } - | T_IF '(' expr ')' statement elseif_list else_single - { $$ = Stmt\If_[$3, ['stmts' => toArray($5), 'elseifs' => $6, 'else' => $7]]; } + '{' inner_statement_list '}' { $$ = Stmt\Block[$2]; } + | T_IF '(' expr ')' blocklike_statement elseif_list else_single + { $$ = Stmt\If_[$3, ['stmts' => $5, 'elseifs' => $6, 'else' => $7]]; } | T_IF '(' expr ')' ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';' { $$ = Stmt\If_[$3, ['stmts' => $6, 'elseifs' => $7, 'else' => $8]]; } | T_WHILE '(' expr ')' while_statement { $$ = Stmt\While_[$3, $5]; } - | T_DO statement T_WHILE '(' expr ')' ';' { $$ = Stmt\Do_ [$5, toArray($2)]; } + | T_DO blocklike_statement T_WHILE '(' expr ')' ';' { $$ = Stmt\Do_ [$5, $2]; } | T_FOR '(' for_expr ';' for_expr ';' for_expr ')' for_statement { $$ = Stmt\For_[['init' => $3, 'cond' => $5, 'loop' => $7, 'stmts' => $9]]; } | T_SWITCH '(' expr ')' switch_case_list { $$ = Stmt\Switch_[$3, $5]; } @@ -263,17 +391,11 @@ non_empty_statement: | T_GLOBAL global_var_list semi { $$ = Stmt\Global_[$2]; } | T_STATIC static_var_list semi { $$ = Stmt\Static_[$2]; } | T_ECHO expr_list_forbid_comma semi { $$ = Stmt\Echo_[$2]; } - | T_INLINE_HTML { $$ = Stmt\InlineHTML[$1]; } - | expr semi { - $e = $1; - if ($e instanceof Expr\Throw_) { - // For backwards-compatibility reasons, convert throw in statement position into - // Stmt\Throw_ rather than Stmt\Expression(Expr\Throw_). - $$ = Stmt\Throw_[$e->expr]; - } else { - $$ = Stmt\Expression[$e]; - } + | T_INLINE_HTML { + $$ = Stmt\InlineHTML[$1]; + $$->setAttribute('hasLeadingNewline', $this->inlineHtmlHasLeadingNewline(#1)); } + | expr semi { $$ = Stmt\Expression[$1]; } | T_UNSET '(' variables_list ')' semi { $$ = Stmt\Unset_[$3]; } | T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement { $$ = Stmt\Foreach_[$3, $5[0], ['keyVar' => null, 'byRef' => $5[1], 'stmts' => $7]]; } @@ -284,16 +406,18 @@ non_empty_statement: | T_DECLARE '(' declare_list ')' declare_statement { $$ = Stmt\Declare_[$3, $5]; } | T_TRY '{' inner_statement_list '}' catches optional_finally { $$ = Stmt\TryCatch[$3, $5, $6]; $this->checkTryCatch($$); } - | T_GOTO identifier semi { $$ = Stmt\Goto_[$2]; } - | identifier ':' { $$ = Stmt\Label[$1]; } - | error { $$ = array(); /* means: no statement */ } + | T_GOTO identifier_not_reserved semi { $$ = Stmt\Goto_[$2]; } + | identifier_not_reserved ':' { $$ = Stmt\Label[$1]; } + | error { $$ = null; /* means: no statement */ } ; statement: - non_empty_statement { $$ = $1; } - | ';' - { makeNop($$, $this->startAttributeStack[#1], $this->endAttributes); - if ($$ === null) $$ = array(); /* means: no statement */ } + non_empty_statement + | ';' { makeNop($$); } +; + +blocklike_statement: + statement { toBlock($1); } ; catches: @@ -317,7 +441,7 @@ optional_finally: ; variables_list: - non_empty_variables_list optional_comma { $$ = $1; } + non_empty_variables_list optional_comma ; non_empty_variables_list: @@ -327,7 +451,12 @@ non_empty_variables_list: optional_ref: /* empty */ { $$ = false; } - | '&' { $$ = true; } + | ampersand { $$ = true; } +; + +optional_arg_ref: + /* empty */ { $$ = false; } + | T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG { $$ = true; } ; optional_ellipsis: @@ -340,28 +469,60 @@ block_or_error: | error { $$ = []; } ; +fn_identifier: + identifier_not_reserved + | T_READONLY { $$ = Node\Identifier[$1]; } + | T_EXIT { $$ = Node\Identifier[$1]; } + | T_CLONE { $$ = Node\Identifier[$1]; } +; + function_declaration_statement: - T_FUNCTION optional_ref identifier '(' parameter_list ')' optional_return_type block_or_error + T_FUNCTION optional_ref fn_identifier '(' parameter_list ')' optional_return_type block_or_error { $$ = Stmt\Function_[$3, ['byRef' => $2, 'params' => $5, 'returnType' => $7, 'stmts' => $8, 'attrGroups' => []]]; } - | attributes T_FUNCTION optional_ref identifier '(' parameter_list ')' optional_return_type block_or_error + | attributes T_FUNCTION optional_ref fn_identifier '(' parameter_list ')' optional_return_type block_or_error { $$ = Stmt\Function_[$4, ['byRef' => $3, 'params' => $6, 'returnType' => $8, 'stmts' => $9, 'attrGroups' => $1]]; } ; class_declaration_statement: - optional_attributes class_entry_type identifier extends_from implements_list '{' class_statement_list '}' + class_entry_type identifier_not_reserved extends_from implements_list '{' class_statement_list '}' + { $$ = Stmt\Class_[$2, ['type' => $1, 'extends' => $3, 'implements' => $4, 'stmts' => $6, 'attrGroups' => []]]; + $this->checkClass($$, #2); } + | attributes class_entry_type identifier_not_reserved extends_from implements_list '{' class_statement_list '}' { $$ = Stmt\Class_[$3, ['type' => $2, 'extends' => $4, 'implements' => $5, 'stmts' => $7, 'attrGroups' => $1]]; $this->checkClass($$, #3); } - | optional_attributes T_INTERFACE identifier interface_extends_list '{' class_statement_list '}' + | optional_attributes T_INTERFACE identifier_not_reserved interface_extends_list '{' class_statement_list '}' { $$ = Stmt\Interface_[$3, ['extends' => $4, 'stmts' => $6, 'attrGroups' => $1]]; $this->checkInterface($$, #3); } - | optional_attributes T_TRAIT identifier '{' class_statement_list '}' + | optional_attributes T_TRAIT identifier_not_reserved '{' class_statement_list '}' { $$ = Stmt\Trait_[$3, ['stmts' => $5, 'attrGroups' => $1]]; } + | optional_attributes T_ENUM identifier_not_reserved enum_scalar_type implements_list '{' class_statement_list '}' + { $$ = Stmt\Enum_[$3, ['scalarType' => $4, 'implements' => $5, 'stmts' => $7, 'attrGroups' => $1]]; + $this->checkEnum($$, #3); } +; + +enum_scalar_type: + /* empty */ { $$ = null; } + | ':' type { $$ = $2; } + +enum_case_expr: + /* empty */ { $$ = null; } + | '=' expr { $$ = $2; } ; class_entry_type: T_CLASS { $$ = 0; } - | T_ABSTRACT T_CLASS { $$ = Stmt\Class_::MODIFIER_ABSTRACT; } - | T_FINAL T_CLASS { $$ = Stmt\Class_::MODIFIER_FINAL; } + | class_modifiers T_CLASS +; + +class_modifiers: + class_modifier + | class_modifiers class_modifier { $this->checkClassModifier($1, $2, #2); $$ = $1 | $2; } +; + +class_modifier: + T_ABSTRACT { $$ = Modifiers::ABSTRACT; } + | T_FINAL { $$ = Modifiers::FINAL; } + | T_READONLY { $$ = Modifiers::READONLY; } ; extends_from: @@ -380,7 +541,7 @@ implements_list: ; class_name_list: - non_empty_class_name_list no_comma { $$ = $1; } + non_empty_class_name_list no_comma ; non_empty_class_name_list: @@ -389,23 +550,23 @@ non_empty_class_name_list: ; for_statement: - statement { $$ = toArray($1); } + blocklike_statement | ':' inner_statement_list T_ENDFOR ';' { $$ = $2; } ; foreach_statement: - statement { $$ = toArray($1); } + blocklike_statement | ':' inner_statement_list T_ENDFOREACH ';' { $$ = $2; } ; declare_statement: - non_empty_statement { $$ = toArray($1); } + non_empty_statement { toBlock($1); } | ';' { $$ = null; } | ':' inner_statement_list T_ENDDECLARE ';' { $$ = $2; } ; declare_list: - non_empty_declare_list no_comma { $$ = $1; } + non_empty_declare_list no_comma ; non_empty_declare_list: @@ -414,7 +575,7 @@ non_empty_declare_list: ; declare_list_element: - identifier '=' expr { $$ = Stmt\DeclareDeclare[$1, $3]; } + identifier_not_reserved '=' expr { $$ = Node\DeclareItem[$1, $3]; } ; switch_case_list: @@ -445,7 +606,7 @@ match: match_arm_list: /* empty */ { $$ = []; } - | non_empty_match_arm_list optional_comma { $$ = $1; } + | non_empty_match_arm_list optional_comma ; non_empty_match_arm_list: @@ -459,7 +620,7 @@ match_arm: ; while_statement: - statement { $$ = toArray($1); } + blocklike_statement { $$ = $1; } | ':' inner_statement_list T_ENDWHILE ';' { $$ = $2; } ; @@ -469,7 +630,7 @@ elseif_list: ; elseif: - T_ELSEIF '(' expr ')' statement { $$ = Stmt\ElseIf_[$3, toArray($5)]; } + T_ELSEIF '(' expr ')' blocklike_statement { $$ = Stmt\ElseIf_[$3, $5]; } ; new_elseif_list: @@ -478,28 +639,31 @@ new_elseif_list: ; new_elseif: - T_ELSEIF '(' expr ')' ':' inner_statement_list { $$ = Stmt\ElseIf_[$3, $6]; } + T_ELSEIF '(' expr ')' ':' inner_statement_list + { $$ = Stmt\ElseIf_[$3, $6]; $this->fixupAlternativeElse($$); } ; else_single: /* empty */ { $$ = null; } - | T_ELSE statement { $$ = Stmt\Else_[toArray($2)]; } + | T_ELSE blocklike_statement { $$ = Stmt\Else_[$2]; } ; new_else_single: /* empty */ { $$ = null; } - | T_ELSE ':' inner_statement_list { $$ = Stmt\Else_[$3]; } + | T_ELSE ':' inner_statement_list + { $$ = Stmt\Else_[$3]; $this->fixupAlternativeElse($$); } ; foreach_variable: variable { $$ = array($1, false); } - | '&' variable { $$ = array($2, true); } + | ampersand variable { $$ = array($2, true); } | list_expr { $$ = array($1, false); } - | array_short_syntax { $$ = array($1, false); } + | array_short_syntax + { $$ = array($this->fixupArrayDestructuring($1), false); } ; parameter_list: - non_empty_parameter_list optional_comma { $$ = $1; } + non_empty_parameter_list optional_comma | /* empty */ { $$ = array(); } ; @@ -508,32 +672,48 @@ non_empty_parameter_list: | non_empty_parameter_list ',' parameter { push($1, $3); } ; -optional_visibility_modifier: +optional_property_modifiers: /* empty */ { $$ = 0; } - | T_PUBLIC { $$ = Stmt\Class_::MODIFIER_PUBLIC; } - | T_PROTECTED { $$ = Stmt\Class_::MODIFIER_PROTECTED; } - | T_PRIVATE { $$ = Stmt\Class_::MODIFIER_PRIVATE; } + | optional_property_modifiers property_modifier + { $this->checkModifier($1, $2, #2); $$ = $1 | $2; } +; + +property_modifier: + T_PUBLIC { $$ = Modifiers::PUBLIC; } + | T_PROTECTED { $$ = Modifiers::PROTECTED; } + | T_PRIVATE { $$ = Modifiers::PRIVATE; } + | T_PUBLIC_SET { $$ = Modifiers::PUBLIC_SET; } + | T_PROTECTED_SET { $$ = Modifiers::PROTECTED_SET; } + | T_PRIVATE_SET { $$ = Modifiers::PRIVATE_SET; } + | T_READONLY { $$ = Modifiers::READONLY; } + | T_FINAL { $$ = Modifiers::FINAL; } ; parameter: - optional_attributes optional_visibility_modifier optional_type_without_static optional_ref optional_ellipsis plain_variable - { $$ = new Node\Param($6, null, $3, $4, $5, attributes(), $2, $1); - $this->checkParam($$); } - | optional_attributes optional_visibility_modifier optional_type_without_static optional_ref optional_ellipsis plain_variable '=' expr - { $$ = new Node\Param($6, $8, $3, $4, $5, attributes(), $2, $1); - $this->checkParam($$); } - | optional_attributes optional_visibility_modifier optional_type_without_static optional_ref optional_ellipsis error + optional_attributes optional_property_modifiers optional_type_without_static + optional_arg_ref optional_ellipsis plain_variable optional_property_hook_list + { $$ = new Node\Param($6, null, $3, $4, $5, attributes(), $2, $1, $7); + $this->checkParam($$); + $this->addPropertyNameToHooks($$); } + | optional_attributes optional_property_modifiers optional_type_without_static + optional_arg_ref optional_ellipsis plain_variable '=' expr optional_property_hook_list + { $$ = new Node\Param($6, $8, $3, $4, $5, attributes(), $2, $1, $9); + $this->checkParam($$); + $this->addPropertyNameToHooks($$); } + | optional_attributes optional_property_modifiers optional_type_without_static + optional_arg_ref optional_ellipsis error { $$ = new Node\Param(Expr\Error[], null, $3, $4, $5, attributes(), $2, $1); } ; type_expr: - type { $$ = $1; } + type | '?' type { $$ = Node\NullableType[$2]; } | union_type { $$ = Node\UnionType[$1]; } + | intersection_type ; type: - type_without_static { $$ = $1; } + type_without_static | T_STATIC { $$ = Node\Name['static']; } ; @@ -543,25 +723,57 @@ type_without_static: | T_CALLABLE { $$ = Node\Identifier['callable']; } ; +union_type_element: + type + | '(' intersection_type ')' { $$ = $2; } +; + union_type: - type '|' type { init($1, $3); } - | union_type '|' type { push($1, $3); } + union_type_element '|' union_type_element { init($1, $3); } + | union_type '|' union_type_element { push($1, $3); } +; + +union_type_without_static_element: + type_without_static + | '(' intersection_type_without_static ')' { $$ = $2; } ; union_type_without_static: - type_without_static '|' type_without_static { init($1, $3); } - | union_type_without_static '|' type_without_static { push($1, $3); } + union_type_without_static_element '|' union_type_without_static_element { init($1, $3); } + | union_type_without_static '|' union_type_without_static_element { push($1, $3); } +; + +intersection_type_list: + type T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type { init($1, $3); } + | intersection_type_list T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type + { push($1, $3); } +; + +intersection_type: + intersection_type_list { $$ = Node\IntersectionType[$1]; } +; + +intersection_type_without_static_list: + type_without_static T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type_without_static + { init($1, $3); } + | intersection_type_without_static_list T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG type_without_static + { push($1, $3); } +; + +intersection_type_without_static: + intersection_type_without_static_list { $$ = Node\IntersectionType[$1]; } ; type_expr_without_static: - type_without_static { $$ = $1; } + type_without_static | '?' type_without_static { $$ = Node\NullableType[$2]; } | union_type_without_static { $$ = Node\UnionType[$1]; } + | intersection_type_without_static ; optional_type_without_static: /* empty */ { $$ = null; } - | type_expr_without_static { $$ = $1; } + | type_expr_without_static ; optional_return_type: @@ -573,6 +785,27 @@ optional_return_type: argument_list: '(' ')' { $$ = array(); } | '(' non_empty_argument_list optional_comma ')' { $$ = $2; } + | '(' variadic_placeholder ')' { init($2); } +; + +clone_argument_list: + '(' ')' { $$ = array(); } + | '(' non_empty_clone_argument_list optional_comma ')' { $$ = $2; } + | '(' expr ',' ')' { init(Node\Arg[$2, false, false]); } + | '(' variadic_placeholder ')' { init($2); } +; + +non_empty_clone_argument_list: + expr ',' argument + { init(new Node\Arg($1, false, false, stackAttributes(#1)), $3); } + | argument_no_expr + { init($1); } + | non_empty_clone_argument_list ',' argument + { push($1, $3); } +; + +variadic_placeholder: + T_ELLIPSIS { $$ = Node\VariadicPlaceholder[]; } ; non_empty_argument_list: @@ -580,16 +813,20 @@ non_empty_argument_list: | non_empty_argument_list ',' argument { push($1, $3); } ; -argument: - expr { $$ = Node\Arg[$1, false, false]; } - | '&' variable { $$ = Node\Arg[$2, true, false]; } +argument_no_expr: + ampersand variable { $$ = Node\Arg[$2, true, false]; } | T_ELLIPSIS expr { $$ = Node\Arg[$2, false, true]; } - | identifier_ex ':' expr + | identifier_maybe_reserved ':' expr { $$ = new Node\Arg($3, false, false, attributes(), $1); } ; +argument: + expr { $$ = Node\Arg[$1, false, false]; } + | argument_no_expr { $$ = $1; } +; + global_var_list: - non_empty_global_var_list no_comma { $$ = $1; } + non_empty_global_var_list no_comma ; non_empty_global_var_list: @@ -598,11 +835,11 @@ non_empty_global_var_list: ; global_var: - simple_variable { $$ = $1; } + simple_variable ; static_var_list: - non_empty_static_var_list no_comma { $$ = $1; } + non_empty_static_var_list no_comma ; non_empty_static_var_list: @@ -611,32 +848,44 @@ non_empty_static_var_list: ; static_var: - plain_variable { $$ = Stmt\StaticVar[$1, null]; } - | plain_variable '=' expr { $$ = Stmt\StaticVar[$1, $3]; } + plain_variable { $$ = Node\StaticVar[$1, null]; } + | plain_variable '=' expr { $$ = Node\StaticVar[$1, $3]; } ; class_statement_list_ex: - class_statement_list_ex class_statement { if ($2 !== null) { push($1, $2); } } + class_statement_list_ex class_statement { if ($2 !== null) { push($1, $2); } else { $$ = $1; } } | /* empty */ { init(); } ; class_statement_list: class_statement_list_ex - { makeZeroLengthNop($nop, $this->lookaheadStartAttributes); + { makeZeroLengthNop($nop); if ($nop !== null) { $1[] = $nop; } $$ = $1; } ; class_statement: optional_attributes variable_modifiers optional_type_without_static property_declaration_list semi - { $$ = new Stmt\Property($2, $4, attributes(), $3, $1); - $this->checkProperty($$, #2); } + { $$ = new Stmt\Property($2, $4, attributes(), $3, $1); } +#if PHP8 + | optional_attributes variable_modifiers optional_type_without_static property_declaration_list '{' property_hook_list '}' + { $$ = new Stmt\Property($2, $4, attributes(), $3, $1, $6); + $this->checkPropertyHooksForMultiProperty($$, #5); + $this->checkEmptyPropertyHookList($6, #5); + $this->addPropertyNameToHooks($$); } +#endif | optional_attributes method_modifiers T_CONST class_const_list semi { $$ = new Stmt\ClassConst($4, $2, attributes(), $1); $this->checkClassConst($$, #2); } - | optional_attributes method_modifiers T_FUNCTION optional_ref identifier_ex '(' parameter_list ')' optional_return_type method_body + | optional_attributes method_modifiers T_CONST type_expr class_const_list semi + { $$ = new Stmt\ClassConst($5, $2, attributes(), $1, $4); + $this->checkClassConst($$, #2); } + | optional_attributes method_modifiers T_FUNCTION optional_ref identifier_maybe_reserved '(' parameter_list ')' + optional_return_type method_body { $$ = Stmt\ClassMethod[$5, ['type' => $2, 'byRef' => $4, 'params' => $7, 'returnType' => $9, 'stmts' => $10, 'attrGroups' => $1]]; $this->checkClassMethod($$, #2); } | T_USE class_name_list trait_adaptations { $$ = Stmt\TraitUse[$2, $3]; } + | optional_attributes T_CASE identifier_maybe_reserved enum_case_expr semi + { $$ = Stmt\EnumCase[$3, $4, $1]; } | error { $$ = null; /* will be skipped */ } ; @@ -653,55 +902,59 @@ trait_adaptation_list: trait_adaptation: trait_method_reference_fully_qualified T_INSTEADOF class_name_list ';' { $$ = Stmt\TraitUseAdaptation\Precedence[$1[0], $1[1], $3]; } - | trait_method_reference T_AS member_modifier identifier_ex ';' + | trait_method_reference T_AS member_modifier identifier_maybe_reserved ';' { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, $4]; } | trait_method_reference T_AS member_modifier ';' { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, null]; } - | trait_method_reference T_AS identifier ';' + | trait_method_reference T_AS identifier_not_reserved ';' { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; } | trait_method_reference T_AS reserved_non_modifiers_identifier ';' { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; } ; trait_method_reference_fully_qualified: - name T_PAAMAYIM_NEKUDOTAYIM identifier_ex { $$ = array($1, $3); } + name T_PAAMAYIM_NEKUDOTAYIM identifier_maybe_reserved { $$ = array($1, $3); } ; trait_method_reference: - trait_method_reference_fully_qualified { $$ = $1; } - | identifier_ex { $$ = array(null, $1); } + trait_method_reference_fully_qualified + | identifier_maybe_reserved { $$ = array(null, $1); } ; method_body: ';' /* abstract method */ { $$ = null; } - | block_or_error { $$ = $1; } + | block_or_error ; variable_modifiers: - non_empty_member_modifiers { $$ = $1; } + non_empty_member_modifiers | T_VAR { $$ = 0; } ; method_modifiers: /* empty */ { $$ = 0; } - | non_empty_member_modifiers { $$ = $1; } + | non_empty_member_modifiers ; non_empty_member_modifiers: - member_modifier { $$ = $1; } + member_modifier | non_empty_member_modifiers member_modifier { $this->checkModifier($1, $2, #2); $$ = $1 | $2; } ; member_modifier: - T_PUBLIC { $$ = Stmt\Class_::MODIFIER_PUBLIC; } - | T_PROTECTED { $$ = Stmt\Class_::MODIFIER_PROTECTED; } - | T_PRIVATE { $$ = Stmt\Class_::MODIFIER_PRIVATE; } - | T_STATIC { $$ = Stmt\Class_::MODIFIER_STATIC; } - | T_ABSTRACT { $$ = Stmt\Class_::MODIFIER_ABSTRACT; } - | T_FINAL { $$ = Stmt\Class_::MODIFIER_FINAL; } + T_PUBLIC { $$ = Modifiers::PUBLIC; } + | T_PROTECTED { $$ = Modifiers::PROTECTED; } + | T_PRIVATE { $$ = Modifiers::PRIVATE; } + | T_PUBLIC_SET { $$ = Modifiers::PUBLIC_SET; } + | T_PROTECTED_SET { $$ = Modifiers::PROTECTED_SET; } + | T_PRIVATE_SET { $$ = Modifiers::PRIVATE_SET; } + | T_STATIC { $$ = Modifiers::STATIC; } + | T_ABSTRACT { $$ = Modifiers::ABSTRACT; } + | T_FINAL { $$ = Modifiers::FINAL; } + | T_READONLY { $$ = Modifiers::READONLY; } ; property_declaration_list: - non_empty_property_declaration_list no_comma { $$ = $1; } + non_empty_property_declaration_list no_comma ; non_empty_property_declaration_list: @@ -715,16 +968,49 @@ property_decl_name: ; property_declaration: - property_decl_name { $$ = Stmt\PropertyProperty[$1, null]; } - | property_decl_name '=' expr { $$ = Stmt\PropertyProperty[$1, $3]; } + property_decl_name { $$ = Node\PropertyItem[$1, null]; } + | property_decl_name '=' expr { $$ = Node\PropertyItem[$1, $3]; } +; + +property_hook_list: + /* empty */ { $$ = []; } + | property_hook_list property_hook { push($1, $2); } +; + +optional_property_hook_list: + /* empty */ { $$ = []; } +#if PHP8 + | '{' property_hook_list '}' { $$ = $2; $this->checkEmptyPropertyHookList($2, #1); } +#endif +; + +property_hook: + optional_attributes property_hook_modifiers optional_ref identifier_not_reserved property_hook_body + { $$ = Node\PropertyHook[$4, $5, ['flags' => $2, 'byRef' => $3, 'params' => [], 'attrGroups' => $1]]; + $this->checkPropertyHook($$, null); } + | optional_attributes property_hook_modifiers optional_ref identifier_not_reserved '(' parameter_list ')' property_hook_body + { $$ = Node\PropertyHook[$4, $8, ['flags' => $2, 'byRef' => $3, 'params' => $6, 'attrGroups' => $1]]; + $this->checkPropertyHook($$, #5); } +; + +property_hook_body: + ';' { $$ = null; } + | '{' inner_statement_list '}' { $$ = $2; } + | T_DOUBLE_ARROW expr ';' { $$ = $2; } +; + +property_hook_modifiers: + /* empty */ { $$ = 0; } + | property_hook_modifiers member_modifier + { $this->checkPropertyHookModifiers($1, $2, #2); $$ = $1 | $2; } ; expr_list_forbid_comma: - non_empty_expr_list no_comma { $$ = $1; } + non_empty_expr_list no_comma ; expr_list_allow_comma: - non_empty_expr_list optional_comma { $$ = $1; } + non_empty_expr_list optional_comma ; non_empty_expr_list: @@ -734,17 +1020,25 @@ non_empty_expr_list: for_expr: /* empty */ { $$ = array(); } - | expr_list_forbid_comma { $$ = $1; } + | expr_list_forbid_comma ; expr: - variable { $$ = $1; } + variable | list_expr '=' expr { $$ = Expr\Assign[$1, $3]; } - | array_short_syntax '=' expr { $$ = Expr\Assign[$1, $3]; } + | array_short_syntax '=' expr + { $$ = Expr\Assign[$this->fixupArrayDestructuring($1), $3]; } | variable '=' expr { $$ = Expr\Assign[$1, $3]; } - | variable '=' '&' variable { $$ = Expr\AssignRef[$1, $4]; } - | new_expr { $$ = $1; } - | match { $$ = $1; } + | variable '=' ampersand variable { $$ = Expr\AssignRef[$1, $4]; } + | variable '=' ampersand new_expr + { $$ = Expr\AssignRef[$1, $4]; + if (!$this->phpVersion->allowsAssignNewByReference()) { + $this->emitError(new Error('Cannot assign new by reference', attributes())); + } + } + | new_expr + | match + | T_CLONE clone_argument_list { $$ = Expr\FuncCall[new Node\Name($1, stackAttributes(#1)), $2]; } | T_CLONE expr { $$ = Expr\Clone_[$2]; } | variable T_PLUS_EQUAL expr { $$ = Expr\AssignOp\Plus [$1, $3]; } | variable T_MINUS_EQUAL expr { $$ = Expr\AssignOp\Minus [$1, $3]; } @@ -769,7 +1063,8 @@ expr: | expr T_LOGICAL_AND expr { $$ = Expr\BinaryOp\LogicalAnd[$1, $3]; } | expr T_LOGICAL_XOR expr { $$ = Expr\BinaryOp\LogicalXor[$1, $3]; } | expr '|' expr { $$ = Expr\BinaryOp\BitwiseOr [$1, $3]; } - | expr '&' expr { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; } + | expr T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG expr { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; } + | expr T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG expr { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; } | expr '^' expr { $$ = Expr\BinaryOp\BitwiseXor[$1, $3]; } | expr '.' expr { $$ = Expr\BinaryOp\Concat [$1, $3]; } | expr '+' expr { $$ = Expr\BinaryOp\Plus [$1, $3]; } @@ -793,6 +1088,9 @@ expr: | expr T_IS_SMALLER_OR_EQUAL expr { $$ = Expr\BinaryOp\SmallerOrEqual[$1, $3]; } | expr '>' expr { $$ = Expr\BinaryOp\Greater [$1, $3]; } | expr T_IS_GREATER_OR_EQUAL expr { $$ = Expr\BinaryOp\GreaterOrEqual[$1, $3]; } +#if PHP8 + | expr T_PIPE expr { $$ = Expr\BinaryOp\Pipe[$1, $3]; } +#endif | expr T_INSTANCEOF class_name_reference { $$ = Expr\Instanceof_[$1, $3]; } | '(' expr ')' { $$ = $2; } | expr '?' expr ':' expr { $$ = Expr\Ternary[$1, $3, $5]; } @@ -805,22 +1103,30 @@ expr: | T_EVAL '(' expr ')' { $$ = Expr\Eval_[$3]; } | T_REQUIRE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_REQUIRE]; } | T_REQUIRE_ONCE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_REQUIRE_ONCE]; } - | T_INT_CAST expr { $$ = Expr\Cast\Int_ [$2]; } + | T_INT_CAST expr + { $attrs = attributes(); + $attrs['kind'] = $this->getIntCastKind($1); + $$ = new Expr\Cast\Int_($2, $attrs); } | T_DOUBLE_CAST expr { $attrs = attributes(); $attrs['kind'] = $this->getFloatCastKind($1); $$ = new Expr\Cast\Double($2, $attrs); } - | T_STRING_CAST expr { $$ = Expr\Cast\String_ [$2]; } + | T_STRING_CAST expr + { $attrs = attributes(); + $attrs['kind'] = $this->getStringCastKind($1); + $$ = new Expr\Cast\String_($2, $attrs); } | T_ARRAY_CAST expr { $$ = Expr\Cast\Array_ [$2]; } | T_OBJECT_CAST expr { $$ = Expr\Cast\Object_ [$2]; } - | T_BOOL_CAST expr { $$ = Expr\Cast\Bool_ [$2]; } - | T_UNSET_CAST expr { $$ = Expr\Cast\Unset_ [$2]; } - | T_EXIT exit_expr + | T_BOOL_CAST expr { $attrs = attributes(); - $attrs['kind'] = strtolower($1) === 'exit' ? Expr\Exit_::KIND_EXIT : Expr\Exit_::KIND_DIE; - $$ = new Expr\Exit_($2, $attrs); } + $attrs['kind'] = $this->getBoolCastKind($1); + $$ = new Expr\Cast\Bool_($2, $attrs); } + | T_UNSET_CAST expr { $$ = Expr\Cast\Unset_ [$2]; } + | T_VOID_CAST expr { $$ = Expr\Cast\Void_ [$2]; } + | T_EXIT ctor_arguments + { $$ = $this->createExitExpr($1, #1, $2, attributes()); } | '@' expr { $$ = Expr\ErrorSuppress[$2]; } - | scalar { $$ = $1; } + | scalar | '`' backticks_expr '`' { $$ = Expr\ShellExec[$2]; } | T_PRINT expr { $$ = Expr\Print_[$2]; } | T_YIELD { $$ = Expr\Yield_[null, null]; } @@ -829,18 +1135,18 @@ expr: | T_YIELD_FROM expr { $$ = Expr\YieldFrom[$2]; } | T_THROW expr { $$ = Expr\Throw_[$2]; } - | T_FN optional_ref '(' parameter_list ')' optional_return_type T_DOUBLE_ARROW expr + | T_FN optional_ref '(' parameter_list ')' optional_return_type T_DOUBLE_ARROW expr %prec T_THROW { $$ = Expr\ArrowFunction[['static' => false, 'byRef' => $2, 'params' => $4, 'returnType' => $6, 'expr' => $8, 'attrGroups' => []]]; } - | T_STATIC T_FN optional_ref '(' parameter_list ')' optional_return_type T_DOUBLE_ARROW expr + | T_STATIC T_FN optional_ref '(' parameter_list ')' optional_return_type T_DOUBLE_ARROW expr %prec T_THROW { $$ = Expr\ArrowFunction[['static' => true, 'byRef' => $3, 'params' => $5, 'returnType' => $7, 'expr' => $9, 'attrGroups' => []]]; } | 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, 'attrGroups' => []]]; } | T_STATIC T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type block_or_error { $$ = Expr\Closure[['static' => true, 'byRef' => $3, 'params' => $5, 'uses' => $7, 'returnType' => $8, 'stmts' => $9, 'attrGroups' => []]]; } - | attributes T_FN optional_ref '(' parameter_list ')' optional_return_type T_DOUBLE_ARROW expr + | attributes T_FN optional_ref '(' parameter_list ')' optional_return_type T_DOUBLE_ARROW expr %prec T_THROW { $$ = Expr\ArrowFunction[['static' => false, 'byRef' => $3, 'params' => $5, 'returnType' => $7, 'expr' => $9, 'attrGroups' => $1]]; } - | attributes T_STATIC T_FN optional_ref '(' parameter_list ')' optional_return_type T_DOUBLE_ARROW expr + | attributes T_STATIC T_FN optional_ref '(' parameter_list ')' optional_return_type T_DOUBLE_ARROW expr %prec T_THROW { $$ = Expr\ArrowFunction[['static' => true, 'byRef' => $4, 'params' => $6, 'returnType' => $8, 'expr' => $10, 'attrGroups' => $1]]; } | attributes T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type block_or_error { $$ = Expr\Closure[['static' => false, 'byRef' => $3, 'params' => $5, 'uses' => $7, 'returnType' => $8, 'stmts' => $9, 'attrGroups' => $1]]; } @@ -849,24 +1155,33 @@ expr: ; anonymous_class: - optional_attributes T_CLASS ctor_arguments extends_from implements_list '{' class_statement_list '}' - { $$ = array(Stmt\Class_[null, ['type' => 0, 'extends' => $4, 'implements' => $5, 'stmts' => $7, 'attrGroups' => $1]], $3); + optional_attributes class_entry_type ctor_arguments extends_from implements_list '{' class_statement_list '}' + { $$ = array(Stmt\Class_[null, ['type' => $2, 'extends' => $4, 'implements' => $5, 'stmts' => $7, 'attrGroups' => $1]], $3); $this->checkClass($$[0], -1); } ; -new_expr: - T_NEW class_name_reference ctor_arguments { $$ = Expr\New_[$2, $3]; } +new_dereferenceable: + T_NEW class_name_reference argument_list { $$ = Expr\New_[$2, $3]; } | T_NEW anonymous_class { list($class, $ctorArgs) = $2; $$ = Expr\New_[$class, $ctorArgs]; } ; +new_non_dereferenceable: + T_NEW class_name_reference { $$ = Expr\New_[$2, []]; } +; + +new_expr: + new_dereferenceable + | new_non_dereferenceable +; + lexical_vars: /* empty */ { $$ = array(); } | T_USE '(' lexical_var_list ')' { $$ = $3; } ; lexical_var_list: - non_empty_lexical_var_list optional_comma { $$ = $1; } + non_empty_lexical_var_list optional_comma ; non_empty_lexical_var_list: @@ -875,11 +1190,16 @@ non_empty_lexical_var_list: ; lexical_var: - optional_ref plain_variable { $$ = Expr\ClosureUse[$2, $1]; } + optional_ref plain_variable { $$ = Node\ClosureUse[$2, $1]; } +; + +name_readonly: + T_READONLY { $$ = Name[$1]; } ; function_call: name argument_list { $$ = Expr\FuncCall[$1, $2]; } + | name_readonly argument_list { $$ = Expr\FuncCall[$1, $2]; } | callable_expr argument_list { $$ = Expr\FuncCall[$1, $2]; } | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM member_name argument_list { $$ = Expr\StaticCall[$1, $3, $4]; } @@ -887,7 +1207,7 @@ function_call: class_name: T_STATIC { $$ = Name[$1]; } - | name { $$ = $1; } + | name ; name: @@ -898,32 +1218,27 @@ name: ; class_name_reference: - class_name { $$ = $1; } - | new_variable { $$ = $1; } + class_name + | new_variable | '(' expr ')' { $$ = $2; } | error { $$ = Expr\Error[]; $this->errorState = 2; } ; class_name_or_var: - class_name { $$ = $1; } - | fully_dereferencable { $$ = $1; } -; - -exit_expr: - /* empty */ { $$ = null; } - | '(' optional_expr ')' { $$ = $2; } + class_name + | fully_dereferenceable ; backticks_expr: /* empty */ { $$ = array(); } - | T_ENCAPSED_AND_WHITESPACE - { $$ = array(Scalar\EncapsedStringPart[Scalar\String_::parseEscapeSequences($1, '`')]); } - | encaps_list { parseEncapsed($1, '`', true); $$ = $1; } + | encaps_string_part + { $$ = array($1); parseEncapsed($$, '`', $this->phpVersion->supportsUnicodeEscapes()); } + | encaps_list { parseEncapsed($1, '`', $this->phpVersion->supportsUnicodeEscapes()); $$ = $1; } ; ctor_arguments: /* empty */ { $$ = array(); } - | argument_list { $$ = $1; } + | argument_list ; constant: @@ -936,11 +1251,14 @@ constant: | T_METHOD_C { $$ = Scalar\MagicConst\Method[]; } | T_FUNC_C { $$ = Scalar\MagicConst\Function_[]; } | T_NS_C { $$ = Scalar\MagicConst\Namespace_[]; } + | T_PROPERTY_C { $$ = Scalar\MagicConst\Property[]; } ; class_constant: - class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex + class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_maybe_reserved { $$ = Expr\ClassConstFetch[$1, $3]; } + | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' + { $$ = Expr\ClassConstFetch[$1, $4]; } /* We interpret an isolated FOO:: as an unfinished class constant fetch. It could also be an unfinished static property fetch or unfinished scoped call. */ | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM error @@ -953,25 +1271,27 @@ array_short_syntax: $$ = new Expr\Array_($2, $attrs); } ; -dereferencable_scalar: +dereferenceable_scalar: T_ARRAY '(' array_pair_list ')' { $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_LONG; - $$ = new Expr\Array_($3, $attrs); } - | array_short_syntax { $$ = $1; } + $$ = new Expr\Array_($3, $attrs); + $this->createdArrays->offsetSet($$); } + | array_short_syntax + { $$ = $1; $this->createdArrays->offsetSet($$); } | T_CONSTANT_ENCAPSED_STRING - { $attrs = attributes(); $attrs['kind'] = strKind($1); - $$ = new Scalar\String_(Scalar\String_::parse($1), $attrs); } + { $$ = Scalar\String_::fromString($1, attributes(), $this->phpVersion->supportsUnicodeEscapes()); } | '"' encaps_list '"' { $attrs = attributes(); $attrs['kind'] = Scalar\String_::KIND_DOUBLE_QUOTED; - parseEncapsed($2, '"', true); $$ = new Scalar\Encapsed($2, $attrs); } + parseEncapsed($2, '"', $this->phpVersion->supportsUnicodeEscapes()); $$ = new Scalar\InterpolatedString($2, $attrs); } ; scalar: - T_LNUMBER { $$ = $this->parseLNumber($1, attributes()); } - | T_DNUMBER { $$ = Scalar\DNumber[Scalar\DNumber::parse($1)]; } - | dereferencable_scalar { $$ = $1; } - | constant { $$ = $1; } - | class_constant { $$ = $1; } + T_LNUMBER + { $$ = $this->parseLNumber($1, attributes(), $this->phpVersion->allowsInvalidOctals()); } + | T_DNUMBER { $$ = Scalar\Float_::fromString($1, attributes()); } + | dereferenceable_scalar + | constant + | class_constant | T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC { $$ = $this->parseDocString($1, $2, $3, attributes(), stackAttributes(#3), true); } | T_START_HEREDOC T_END_HEREDOC @@ -982,54 +1302,58 @@ scalar: optional_expr: /* empty */ { $$ = null; } - | expr { $$ = $1; } + | expr ; -fully_dereferencable: - variable { $$ = $1; } +fully_dereferenceable: + variable | '(' expr ')' { $$ = $2; } - | dereferencable_scalar { $$ = $1; } - | class_constant { $$ = $1; } + | dereferenceable_scalar + | class_constant + | new_dereferenceable ; -array_object_dereferencable: - fully_dereferencable { $$ = $1; } - | constant { $$ = $1; } +array_object_dereferenceable: + fully_dereferenceable + | constant ; callable_expr: - callable_variable { $$ = $1; } + callable_variable | '(' expr ')' { $$ = $2; } - | dereferencable_scalar { $$ = $1; } + | dereferenceable_scalar + | new_dereferenceable ; callable_variable: - simple_variable { $$ = $1; } - | array_object_dereferencable '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } - | array_object_dereferencable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; } - | function_call { $$ = $1; } - | array_object_dereferencable T_OBJECT_OPERATOR property_name argument_list + simple_variable + | array_object_dereferenceable '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } +#if PHP7 + | array_object_dereferenceable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; } +#endif + | function_call + | array_object_dereferenceable T_OBJECT_OPERATOR property_name argument_list { $$ = Expr\MethodCall[$1, $3, $4]; } - | array_object_dereferencable T_NULLSAFE_OBJECT_OPERATOR property_name argument_list + | array_object_dereferenceable T_NULLSAFE_OBJECT_OPERATOR property_name argument_list { $$ = Expr\NullsafeMethodCall[$1, $3, $4]; } ; optional_plain_variable: /* empty */ { $$ = null; } - | plain_variable { $$ = $1; } + | plain_variable ; variable: - callable_variable { $$ = $1; } - | static_member { $$ = $1; } - | array_object_dereferencable T_OBJECT_OPERATOR property_name + callable_variable + | static_member + | array_object_dereferenceable T_OBJECT_OPERATOR property_name { $$ = Expr\PropertyFetch[$1, $3]; } - | array_object_dereferencable T_NULLSAFE_OBJECT_OPERATOR property_name + | array_object_dereferenceable T_NULLSAFE_OBJECT_OPERATOR property_name { $$ = Expr\NullsafePropertyFetch[$1, $3]; } ; simple_variable: - plain_variable { $$ = $1; } + plain_variable | '$' '{' expr '}' { $$ = Expr\Variable[$3]; } | '$' simple_variable { $$ = Expr\Variable[$2]; } | '$' error { $$ = Expr\Variable[Expr\Error[]]; $this->errorState = 2; } @@ -1046,9 +1370,11 @@ static_member: ; new_variable: - simple_variable { $$ = $1; } + simple_variable | new_variable '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } +#if PHP7 | new_variable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; } +#endif | new_variable T_OBJECT_OPERATOR property_name { $$ = Expr\PropertyFetch[$1, $3]; } | new_variable T_NULLSAFE_OBJECT_OPERATOR property_name { $$ = Expr\NullsafePropertyFetch[$1, $3]; } | class_name T_PAAMAYIM_NEKUDOTAYIM static_member_prop_name @@ -1058,25 +1384,27 @@ new_variable: ; member_name: - identifier_ex { $$ = $1; } + identifier_maybe_reserved | '{' expr '}' { $$ = $2; } - | simple_variable { $$ = $1; } + | simple_variable ; property_name: - identifier { $$ = $1; } + identifier_not_reserved | '{' expr '}' { $$ = $2; } - | simple_variable { $$ = $1; } + | simple_variable | error { $$ = Expr\Error[]; $this->errorState = 2; } ; list_expr: - T_LIST '(' inner_array_pair_list ')' { $$ = Expr\List_[$3]; } + T_LIST '(' inner_array_pair_list ')' + { $$ = Expr\List_[$3]; $$->setAttribute('kind', Expr\List_::KIND_LIST); + $this->postprocessList($$); } ; array_pair_list: inner_array_pair_list - { $$ = $1; $end = count($$)-1; if ($$[$end] === null) array_pop($$); } + { $$ = $1; $end = count($$)-1; if ($$[$end]->value instanceof Expr\Error) array_pop($$); } ; comma_or_error: @@ -1091,14 +1419,18 @@ inner_array_pair_list: ; array_pair: - expr { $$ = Expr\ArrayItem[$1, null, false]; } - | '&' variable { $$ = Expr\ArrayItem[$2, null, true]; } - | list_expr { $$ = Expr\ArrayItem[$1, null, false]; } - | expr T_DOUBLE_ARROW expr { $$ = Expr\ArrayItem[$3, $1, false]; } - | expr T_DOUBLE_ARROW '&' variable { $$ = Expr\ArrayItem[$4, $1, true]; } - | expr T_DOUBLE_ARROW list_expr { $$ = Expr\ArrayItem[$3, $1, false]; } - | T_ELLIPSIS expr { $$ = Expr\ArrayItem[$2, null, false, attributes(), true]; } - | /* empty */ { $$ = null; } + expr { $$ = Node\ArrayItem[$1, null, false]; } + | ampersand variable { $$ = Node\ArrayItem[$2, null, true]; } + | list_expr { $$ = Node\ArrayItem[$1, null, false]; } + | expr T_DOUBLE_ARROW expr { $$ = Node\ArrayItem[$3, $1, false]; } + | expr T_DOUBLE_ARROW ampersand variable { $$ = Node\ArrayItem[$4, $1, true]; } + | expr T_DOUBLE_ARROW list_expr { $$ = Node\ArrayItem[$3, $1, false]; } + | T_ELLIPSIS expr { $$ = new Node\ArrayItem($2, null, false, attributes(), true); } + | /* empty */ + { /* Create an Error node now to remember the position. We'll later either report an error, + or convert this into a null element, depending on whether this is a creation or destructuring context. */ + $attrs = $this->createEmptyElemAttributes($this->tokenPos); + $$ = new Node\ArrayItem(new Expr\Error($attrs), null, false, $attrs); } ; encaps_list: @@ -1109,7 +1441,8 @@ encaps_list: ; encaps_string_part: - T_ENCAPSED_AND_WHITESPACE { $$ = Scalar\EncapsedStringPart[$1]; } + T_ENCAPSED_AND_WHITESPACE + { $attrs = attributes(); $attrs['rawValue'] = $1; $$ = new Node\InterpolatedStringPart($1, $attrs); } ; encaps_str_varname: @@ -1117,10 +1450,12 @@ encaps_str_varname: ; encaps_var: - plain_variable { $$ = $1; } + plain_variable | plain_variable '[' encaps_var_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } - | plain_variable T_OBJECT_OPERATOR identifier { $$ = Expr\PropertyFetch[$1, $3]; } - | plain_variable T_NULLSAFE_OBJECT_OPERATOR identifier { $$ = Expr\NullsafePropertyFetch[$1, $3]; } + | plain_variable T_OBJECT_OPERATOR identifier_not_reserved + { $$ = Expr\PropertyFetch[$1, $3]; } + | plain_variable T_NULLSAFE_OBJECT_OPERATOR identifier_not_reserved + { $$ = Expr\NullsafePropertyFetch[$1, $3]; } | T_DOLLAR_OPEN_CURLY_BRACES expr '}' { $$ = Expr\Variable[$2]; } | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}' { $$ = Expr\Variable[$2]; } | T_DOLLAR_OPEN_CURLY_BRACES encaps_str_varname '[' expr ']' '}' @@ -1132,7 +1467,7 @@ encaps_var_offset: T_STRING { $$ = Scalar\String_[$1]; } | T_NUM_STRING { $$ = $this->parseNumString($1, attributes()); } | '-' T_NUM_STRING { $$ = $this->parseNumString('-' . $2, attributes()); } - | plain_variable { $$ = $1; } + | plain_variable ; %% diff --git a/grammar/php5.y b/grammar/php5.y deleted file mode 100644 index c7d245dc78..0000000000 --- a/grammar/php5.y +++ /dev/null @@ -1,1026 +0,0 @@ -%pure_parser -%expect 6 - -%tokens - -%% - -start: - top_statement_list { $$ = $this->handleNamespaces($1); } -; - -top_statement_list_ex: - top_statement_list_ex top_statement { pushNormalizing($1, $2); } - | /* empty */ { init(); } -; - -top_statement_list: - top_statement_list_ex - { makeZeroLengthNop($nop, $this->lookaheadStartAttributes); - if ($nop !== null) { $1[] = $nop; } $$ = $1; } -; - -reserved_non_modifiers: - T_INCLUDE | T_INCLUDE_ONCE | T_EVAL | T_REQUIRE | T_REQUIRE_ONCE | T_LOGICAL_OR | T_LOGICAL_XOR | T_LOGICAL_AND - | T_INSTANCEOF | T_NEW | T_CLONE | T_EXIT | T_IF | T_ELSEIF | T_ELSE | T_ENDIF | T_ECHO | T_DO | T_WHILE - | T_ENDWHILE | T_FOR | T_ENDFOR | T_FOREACH | T_ENDFOREACH | T_DECLARE | T_ENDDECLARE | T_AS | T_TRY | T_CATCH - | 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_FN - | T_MATCH -; - -semi_reserved: - reserved_non_modifiers - | T_STATIC | T_ABSTRACT | T_FINAL | T_PRIVATE | T_PROTECTED | T_PUBLIC -; - -identifier_ex: - T_STRING { $$ = Node\Identifier[$1]; } - | semi_reserved { $$ = Node\Identifier[$1]; } -; - -identifier: - T_STRING { $$ = Node\Identifier[$1]; } -; - -reserved_non_modifiers_identifier: - reserved_non_modifiers { $$ = Node\Identifier[$1]; } -; - -namespace_name: - T_STRING { $$ = Name[$1]; } - | T_NAME_QUALIFIED { $$ = Name[$1]; } -; - -legacy_namespace_name: - namespace_name { $$ = $1; } - | T_NAME_FULLY_QUALIFIED { $$ = Name[substr($1, 1)]; } -; - -plain_variable: - T_VARIABLE { $$ = Expr\Variable[parseVar($1)]; } -; - -top_statement: - statement { $$ = $1; } - | function_declaration_statement { $$ = $1; } - | class_declaration_statement { $$ = $1; } - | T_HALT_COMPILER - { $$ = Stmt\HaltCompiler[$this->lexer->handleHaltCompiler()]; } - | T_NAMESPACE namespace_name ';' - { $$ = Stmt\Namespace_[$2, null]; - $$->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON); - $this->checkNamespace($$); } - | T_NAMESPACE namespace_name '{' top_statement_list '}' - { $$ = Stmt\Namespace_[$2, $4]; - $$->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); - $this->checkNamespace($$); } - | T_NAMESPACE '{' top_statement_list '}' - { $$ = Stmt\Namespace_[null, $3]; - $$->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); - $this->checkNamespace($$); } - | T_USE use_declarations ';' { $$ = Stmt\Use_[$2, Stmt\Use_::TYPE_NORMAL]; } - | T_USE use_type use_declarations ';' { $$ = Stmt\Use_[$3, $2]; } - | group_use_declaration ';' { $$ = $1; } - | T_CONST constant_declaration_list ';' { $$ = Stmt\Const_[$2]; } -; - -use_type: - T_FUNCTION { $$ = Stmt\Use_::TYPE_FUNCTION; } - | T_CONST { $$ = Stmt\Use_::TYPE_CONSTANT; } -; - -group_use_declaration: - T_USE use_type legacy_namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations '}' - { $$ = Stmt\GroupUse[$3, $6, $2]; } - | T_USE legacy_namespace_name T_NS_SEPARATOR '{' inline_use_declarations '}' - { $$ = Stmt\GroupUse[$2, $5, Stmt\Use_::TYPE_UNKNOWN]; } -; - -unprefixed_use_declarations: - unprefixed_use_declarations ',' unprefixed_use_declaration - { push($1, $3); } - | unprefixed_use_declaration { init($1); } -; - -use_declarations: - use_declarations ',' use_declaration { push($1, $3); } - | use_declaration { init($1); } -; - -inline_use_declarations: - inline_use_declarations ',' inline_use_declaration { push($1, $3); } - | inline_use_declaration { init($1); } -; - -unprefixed_use_declaration: - namespace_name - { $$ = Stmt\UseUse[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); } - | namespace_name T_AS identifier - { $$ = Stmt\UseUse[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); } -; - -use_declaration: - legacy_namespace_name - { $$ = Stmt\UseUse[$1, null, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #1); } - | legacy_namespace_name T_AS identifier - { $$ = Stmt\UseUse[$1, $3, Stmt\Use_::TYPE_UNKNOWN]; $this->checkUseUse($$, #3); } -; - -inline_use_declaration: - unprefixed_use_declaration { $$ = $1; $$->type = Stmt\Use_::TYPE_NORMAL; } - | use_type unprefixed_use_declaration { $$ = $2; $$->type = $1; } -; - -constant_declaration_list: - constant_declaration_list ',' constant_declaration { push($1, $3); } - | constant_declaration { init($1); } -; - -constant_declaration: - identifier '=' static_scalar { $$ = Node\Const_[$1, $3]; } -; - -class_const_list: - class_const_list ',' class_const { push($1, $3); } - | class_const { init($1); } -; - -class_const: - identifier_ex '=' static_scalar { $$ = Node\Const_[$1, $3]; } -; - -inner_statement_list_ex: - inner_statement_list_ex inner_statement { pushNormalizing($1, $2); } - | /* empty */ { init(); } -; - -inner_statement_list: - inner_statement_list_ex - { makeZeroLengthNop($nop, $this->lookaheadStartAttributes); - if ($nop !== null) { $1[] = $nop; } $$ = $1; } -; - -inner_statement: - statement { $$ = $1; } - | function_declaration_statement { $$ = $1; } - | class_declaration_statement { $$ = $1; } - | T_HALT_COMPILER - { throw new Error('__HALT_COMPILER() can only be used from the outermost scope', attributes()); } -; - -non_empty_statement: - '{' inner_statement_list '}' - { - if ($2) { - $$ = $2; prependLeadingComments($$); - } else { - makeNop($$, $this->startAttributeStack[#1], $this->endAttributes); - if (null === $$) { $$ = array(); } - } - } - | T_IF parentheses_expr statement elseif_list else_single - { $$ = Stmt\If_[$2, ['stmts' => toArray($3), 'elseifs' => $4, 'else' => $5]]; } - | T_IF parentheses_expr ':' inner_statement_list new_elseif_list new_else_single T_ENDIF ';' - { $$ = Stmt\If_[$2, ['stmts' => $4, 'elseifs' => $5, 'else' => $6]]; } - | T_WHILE parentheses_expr while_statement { $$ = Stmt\While_[$2, $3]; } - | T_DO statement T_WHILE parentheses_expr ';' { $$ = Stmt\Do_ [$4, toArray($2)]; } - | T_FOR '(' for_expr ';' for_expr ';' for_expr ')' for_statement - { $$ = Stmt\For_[['init' => $3, 'cond' => $5, 'loop' => $7, 'stmts' => $9]]; } - | T_SWITCH parentheses_expr switch_case_list { $$ = Stmt\Switch_[$2, $3]; } - | 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]; } - | yield_expr ';' { $$ = Stmt\Expression[$1]; } - | expr ';' { $$ = Stmt\Expression[$1]; } - | T_UNSET '(' variables_list ')' ';' { $$ = Stmt\Unset_[$3]; } - | T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement - { $$ = Stmt\Foreach_[$3, $5[0], ['keyVar' => null, 'byRef' => $5[1], 'stmts' => $7]]; } - | T_FOREACH '(' expr T_AS variable T_DOUBLE_ARROW foreach_variable ')' foreach_statement - { $$ = Stmt\Foreach_[$3, $7[0], ['keyVar' => $5, 'byRef' => $7[1], 'stmts' => $9]]; } - | T_DECLARE '(' declare_list ')' declare_statement { $$ = Stmt\Declare_[$3, $5]; } - | T_TRY '{' inner_statement_list '}' catches optional_finally - { $$ = Stmt\TryCatch[$3, $5, $6]; $this->checkTryCatch($$); } - | T_THROW expr ';' { $$ = Stmt\Throw_[$2]; } - | T_GOTO identifier ';' { $$ = Stmt\Goto_[$2]; } - | identifier ':' { $$ = Stmt\Label[$1]; } - | expr error { $$ = Stmt\Expression[$1]; } - | error { $$ = array(); /* means: no statement */ } -; - -statement: - non_empty_statement { $$ = $1; } - | ';' - { makeNop($$, $this->startAttributeStack[#1], $this->endAttributes); - if ($$ === null) $$ = array(); /* means: no statement */ } -; - -catches: - /* empty */ { init(); } - | catches catch { push($1, $2); } -; - -catch: - T_CATCH '(' name plain_variable ')' '{' inner_statement_list '}' - { $$ = Stmt\Catch_[array($3), $4, $7]; } -; - -optional_finally: - /* empty */ { $$ = null; } - | T_FINALLY '{' inner_statement_list '}' { $$ = Stmt\Finally_[$3]; } -; - -variables_list: - variable { init($1); } - | variables_list ',' variable { push($1, $3); } -; - -optional_ref: - /* empty */ { $$ = false; } - | '&' { $$ = true; } -; - -optional_ellipsis: - /* empty */ { $$ = false; } - | T_ELLIPSIS { $$ = true; } -; - -function_declaration_statement: - T_FUNCTION optional_ref identifier '(' parameter_list ')' optional_return_type '{' inner_statement_list '}' - { $$ = Stmt\Function_[$3, ['byRef' => $2, 'params' => $5, 'returnType' => $7, 'stmts' => $9]]; } -; - -class_declaration_statement: - class_entry_type identifier extends_from implements_list '{' class_statement_list '}' - { $$ = Stmt\Class_[$2, ['type' => $1, 'extends' => $3, 'implements' => $4, 'stmts' => $6]]; - $this->checkClass($$, #2); } - | T_INTERFACE identifier interface_extends_list '{' class_statement_list '}' - { $$ = Stmt\Interface_[$2, ['extends' => $3, 'stmts' => $5]]; - $this->checkInterface($$, #2); } - | T_TRAIT identifier '{' class_statement_list '}' - { $$ = Stmt\Trait_[$2, ['stmts' => $4]]; } -; - -class_entry_type: - T_CLASS { $$ = 0; } - | T_ABSTRACT T_CLASS { $$ = Stmt\Class_::MODIFIER_ABSTRACT; } - | T_FINAL T_CLASS { $$ = Stmt\Class_::MODIFIER_FINAL; } -; - -extends_from: - /* empty */ { $$ = null; } - | T_EXTENDS class_name { $$ = $2; } -; - -interface_extends_list: - /* empty */ { $$ = array(); } - | T_EXTENDS class_name_list { $$ = $2; } -; - -implements_list: - /* empty */ { $$ = array(); } - | T_IMPLEMENTS class_name_list { $$ = $2; } -; - -class_name_list: - class_name { init($1); } - | class_name_list ',' class_name { push($1, $3); } -; - -for_statement: - statement { $$ = toArray($1); } - | ':' inner_statement_list T_ENDFOR ';' { $$ = $2; } -; - -foreach_statement: - statement { $$ = toArray($1); } - | ':' inner_statement_list T_ENDFOREACH ';' { $$ = $2; } -; - -declare_statement: - non_empty_statement { $$ = toArray($1); } - | ';' { $$ = null; } - | ':' inner_statement_list T_ENDDECLARE ';' { $$ = $2; } -; - -declare_list: - declare_list_element { init($1); } - | declare_list ',' declare_list_element { push($1, $3); } -; - -declare_list_element: - identifier '=' static_scalar { $$ = Stmt\DeclareDeclare[$1, $3]; } -; - -switch_case_list: - '{' case_list '}' { $$ = $2; } - | '{' ';' case_list '}' { $$ = $3; } - | ':' case_list T_ENDSWITCH ';' { $$ = $2; } - | ':' ';' case_list T_ENDSWITCH ';' { $$ = $3; } -; - -case_list: - /* empty */ { init(); } - | case_list case { push($1, $2); } -; - -case: - T_CASE expr case_separator inner_statement_list_ex { $$ = Stmt\Case_[$2, $4]; } - | T_DEFAULT case_separator inner_statement_list_ex { $$ = Stmt\Case_[null, $3]; } -; - -case_separator: - ':' - | ';' -; - -while_statement: - statement { $$ = toArray($1); } - | ':' inner_statement_list T_ENDWHILE ';' { $$ = $2; } -; - -elseif_list: - /* empty */ { init(); } - | elseif_list elseif { push($1, $2); } -; - -elseif: - T_ELSEIF parentheses_expr statement { $$ = Stmt\ElseIf_[$2, toArray($3)]; } -; - -new_elseif_list: - /* empty */ { init(); } - | new_elseif_list new_elseif { push($1, $2); } -; - -new_elseif: - T_ELSEIF parentheses_expr ':' inner_statement_list { $$ = Stmt\ElseIf_[$2, $4]; } -; - -else_single: - /* empty */ { $$ = null; } - | T_ELSE statement { $$ = Stmt\Else_[toArray($2)]; } -; - -new_else_single: - /* empty */ { $$ = null; } - | T_ELSE ':' inner_statement_list { $$ = Stmt\Else_[$3]; } -; - -foreach_variable: - variable { $$ = array($1, false); } - | '&' variable { $$ = array($2, true); } - | list_expr { $$ = array($1, false); } -; - -parameter_list: - non_empty_parameter_list { $$ = $1; } - | /* empty */ { $$ = array(); } -; - -non_empty_parameter_list: - parameter { init($1); } - | non_empty_parameter_list ',' parameter { push($1, $3); } -; - -parameter: - optional_param_type optional_ref optional_ellipsis plain_variable - { $$ = Node\Param[$4, null, $1, $2, $3]; $this->checkParam($$); } - | optional_param_type optional_ref optional_ellipsis plain_variable '=' static_scalar - { $$ = Node\Param[$4, $6, $1, $2, $3]; $this->checkParam($$); } -; - -type: - name { $$ = $1; } - | T_ARRAY { $$ = Node\Identifier['array']; } - | T_CALLABLE { $$ = Node\Identifier['callable']; } -; - -optional_param_type: - /* empty */ { $$ = null; } - | type { $$ = $1; } -; - -optional_return_type: - /* empty */ { $$ = null; } - | ':' type { $$ = $2; } -; - -argument_list: - '(' ')' { $$ = array(); } - | '(' non_empty_argument_list ')' { $$ = $2; } - | '(' yield_expr ')' { $$ = array(Node\Arg[$2, false, false]); } -; - -non_empty_argument_list: - argument { init($1); } - | non_empty_argument_list ',' argument { push($1, $3); } -; - -argument: - expr { $$ = Node\Arg[$1, false, false]; } - | '&' variable { $$ = Node\Arg[$2, true, false]; } - | T_ELLIPSIS expr { $$ = Node\Arg[$2, false, true]; } -; - -global_var_list: - global_var_list ',' global_var { push($1, $3); } - | global_var { init($1); } -; - -global_var: - plain_variable { $$ = $1; } - | '$' variable { $$ = Expr\Variable[$2]; } - | '$' '{' expr '}' { $$ = Expr\Variable[$3]; } -; - -static_var_list: - static_var_list ',' static_var { push($1, $3); } - | static_var { init($1); } -; - -static_var: - plain_variable { $$ = Stmt\StaticVar[$1, null]; } - | plain_variable '=' static_scalar { $$ = Stmt\StaticVar[$1, $3]; } -; - -class_statement_list_ex: - class_statement_list_ex class_statement { if ($2 !== null) { push($1, $2); } } - | /* empty */ { init(); } -; - -class_statement_list: - class_statement_list_ex - { makeZeroLengthNop($nop, $this->lookaheadStartAttributes); - if ($nop !== null) { $1[] = $nop; } $$ = $1; } -; - -class_statement: - variable_modifiers property_declaration_list ';' - { $$ = Stmt\Property[$1, $2]; $this->checkProperty($$, #1); } - | T_CONST class_const_list ';' { $$ = Stmt\ClassConst[$2, 0]; } - | method_modifiers T_FUNCTION optional_ref identifier_ex '(' parameter_list ')' optional_return_type method_body - { $$ = Stmt\ClassMethod[$4, ['type' => $1, 'byRef' => $3, 'params' => $6, 'returnType' => $8, 'stmts' => $9]]; - $this->checkClassMethod($$, #1); } - | T_USE class_name_list trait_adaptations { $$ = Stmt\TraitUse[$2, $3]; } -; - -trait_adaptations: - ';' { $$ = array(); } - | '{' trait_adaptation_list '}' { $$ = $2; } -; - -trait_adaptation_list: - /* empty */ { init(); } - | trait_adaptation_list trait_adaptation { push($1, $2); } -; - -trait_adaptation: - trait_method_reference_fully_qualified T_INSTEADOF class_name_list ';' - { $$ = Stmt\TraitUseAdaptation\Precedence[$1[0], $1[1], $3]; } - | trait_method_reference T_AS member_modifier identifier_ex ';' - { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, $4]; } - | trait_method_reference T_AS member_modifier ';' - { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], $3, null]; } - | trait_method_reference T_AS identifier ';' - { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; } - | trait_method_reference T_AS reserved_non_modifiers_identifier ';' - { $$ = Stmt\TraitUseAdaptation\Alias[$1[0], $1[1], null, $3]; } -; - -trait_method_reference_fully_qualified: - name T_PAAMAYIM_NEKUDOTAYIM identifier_ex { $$ = array($1, $3); } -; -trait_method_reference: - trait_method_reference_fully_qualified { $$ = $1; } - | identifier_ex { $$ = array(null, $1); } -; - -method_body: - ';' /* abstract method */ { $$ = null; } - | '{' inner_statement_list '}' { $$ = $2; } -; - -variable_modifiers: - non_empty_member_modifiers { $$ = $1; } - | T_VAR { $$ = 0; } -; - -method_modifiers: - /* empty */ { $$ = 0; } - | non_empty_member_modifiers { $$ = $1; } -; - -non_empty_member_modifiers: - member_modifier { $$ = $1; } - | non_empty_member_modifiers member_modifier { $this->checkModifier($1, $2, #2); $$ = $1 | $2; } -; - -member_modifier: - T_PUBLIC { $$ = Stmt\Class_::MODIFIER_PUBLIC; } - | T_PROTECTED { $$ = Stmt\Class_::MODIFIER_PROTECTED; } - | T_PRIVATE { $$ = Stmt\Class_::MODIFIER_PRIVATE; } - | T_STATIC { $$ = Stmt\Class_::MODIFIER_STATIC; } - | T_ABSTRACT { $$ = Stmt\Class_::MODIFIER_ABSTRACT; } - | T_FINAL { $$ = Stmt\Class_::MODIFIER_FINAL; } -; - -property_declaration_list: - property_declaration { init($1); } - | property_declaration_list ',' property_declaration { push($1, $3); } -; - -property_decl_name: - T_VARIABLE { $$ = Node\VarLikeIdentifier[parseVar($1)]; } -; - -property_declaration: - property_decl_name { $$ = Stmt\PropertyProperty[$1, null]; } - | property_decl_name '=' static_scalar { $$ = Stmt\PropertyProperty[$1, $3]; } -; - -expr_list: - expr_list ',' expr { push($1, $3); } - | expr { init($1); } -; - -for_expr: - /* empty */ { $$ = array(); } - | expr_list { $$ = $1; } -; - -expr: - variable { $$ = $1; } - | list_expr '=' expr { $$ = Expr\Assign[$1, $3]; } - | variable '=' expr { $$ = Expr\Assign[$1, $3]; } - | variable '=' '&' variable { $$ = Expr\AssignRef[$1, $4]; } - | variable '=' '&' new_expr { $$ = Expr\AssignRef[$1, $4]; } - | new_expr { $$ = $1; } - | T_CLONE expr { $$ = Expr\Clone_[$2]; } - | variable T_PLUS_EQUAL expr { $$ = Expr\AssignOp\Plus [$1, $3]; } - | variable T_MINUS_EQUAL expr { $$ = Expr\AssignOp\Minus [$1, $3]; } - | variable T_MUL_EQUAL expr { $$ = Expr\AssignOp\Mul [$1, $3]; } - | variable T_DIV_EQUAL expr { $$ = Expr\AssignOp\Div [$1, $3]; } - | variable T_CONCAT_EQUAL expr { $$ = Expr\AssignOp\Concat [$1, $3]; } - | variable T_MOD_EQUAL expr { $$ = Expr\AssignOp\Mod [$1, $3]; } - | variable T_AND_EQUAL expr { $$ = Expr\AssignOp\BitwiseAnd[$1, $3]; } - | variable T_OR_EQUAL expr { $$ = Expr\AssignOp\BitwiseOr [$1, $3]; } - | variable T_XOR_EQUAL expr { $$ = Expr\AssignOp\BitwiseXor[$1, $3]; } - | variable T_SL_EQUAL expr { $$ = Expr\AssignOp\ShiftLeft [$1, $3]; } - | variable T_SR_EQUAL expr { $$ = Expr\AssignOp\ShiftRight[$1, $3]; } - | variable T_POW_EQUAL expr { $$ = Expr\AssignOp\Pow [$1, $3]; } - | variable T_COALESCE_EQUAL expr { $$ = Expr\AssignOp\Coalesce [$1, $3]; } - | variable T_INC { $$ = Expr\PostInc[$1]; } - | T_INC variable { $$ = Expr\PreInc [$2]; } - | variable T_DEC { $$ = Expr\PostDec[$1]; } - | T_DEC variable { $$ = Expr\PreDec [$2]; } - | expr T_BOOLEAN_OR expr { $$ = Expr\BinaryOp\BooleanOr [$1, $3]; } - | expr T_BOOLEAN_AND expr { $$ = Expr\BinaryOp\BooleanAnd[$1, $3]; } - | expr T_LOGICAL_OR expr { $$ = Expr\BinaryOp\LogicalOr [$1, $3]; } - | expr T_LOGICAL_AND expr { $$ = Expr\BinaryOp\LogicalAnd[$1, $3]; } - | expr T_LOGICAL_XOR expr { $$ = Expr\BinaryOp\LogicalXor[$1, $3]; } - | expr '|' expr { $$ = Expr\BinaryOp\BitwiseOr [$1, $3]; } - | expr '&' expr { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; } - | expr '^' expr { $$ = Expr\BinaryOp\BitwiseXor[$1, $3]; } - | expr '.' expr { $$ = Expr\BinaryOp\Concat [$1, $3]; } - | expr '+' expr { $$ = Expr\BinaryOp\Plus [$1, $3]; } - | expr '-' expr { $$ = Expr\BinaryOp\Minus [$1, $3]; } - | expr '*' expr { $$ = Expr\BinaryOp\Mul [$1, $3]; } - | expr '/' expr { $$ = Expr\BinaryOp\Div [$1, $3]; } - | expr '%' expr { $$ = Expr\BinaryOp\Mod [$1, $3]; } - | expr T_SL expr { $$ = Expr\BinaryOp\ShiftLeft [$1, $3]; } - | expr T_SR expr { $$ = Expr\BinaryOp\ShiftRight[$1, $3]; } - | expr T_POW expr { $$ = Expr\BinaryOp\Pow [$1, $3]; } - | '+' expr %prec T_INC { $$ = Expr\UnaryPlus [$2]; } - | '-' expr %prec T_INC { $$ = Expr\UnaryMinus[$2]; } - | '!' expr { $$ = Expr\BooleanNot[$2]; } - | '~' expr { $$ = Expr\BitwiseNot[$2]; } - | expr T_IS_IDENTICAL expr { $$ = Expr\BinaryOp\Identical [$1, $3]; } - | expr T_IS_NOT_IDENTICAL expr { $$ = Expr\BinaryOp\NotIdentical [$1, $3]; } - | expr T_IS_EQUAL expr { $$ = Expr\BinaryOp\Equal [$1, $3]; } - | expr T_IS_NOT_EQUAL expr { $$ = Expr\BinaryOp\NotEqual [$1, $3]; } - | expr T_SPACESHIP expr { $$ = Expr\BinaryOp\Spaceship [$1, $3]; } - | expr '<' expr { $$ = Expr\BinaryOp\Smaller [$1, $3]; } - | expr T_IS_SMALLER_OR_EQUAL expr { $$ = Expr\BinaryOp\SmallerOrEqual[$1, $3]; } - | expr '>' expr { $$ = Expr\BinaryOp\Greater [$1, $3]; } - | expr T_IS_GREATER_OR_EQUAL expr { $$ = Expr\BinaryOp\GreaterOrEqual[$1, $3]; } - | expr T_INSTANCEOF class_name_reference { $$ = Expr\Instanceof_[$1, $3]; } - | parentheses_expr { $$ = $1; } - /* we need a separate '(' new_expr ')' rule to avoid problems caused by a s/r conflict */ - | '(' new_expr ')' { $$ = $2; } - | expr '?' expr ':' expr { $$ = Expr\Ternary[$1, $3, $5]; } - | expr '?' ':' expr { $$ = Expr\Ternary[$1, null, $4]; } - | expr T_COALESCE expr { $$ = Expr\BinaryOp\Coalesce[$1, $3]; } - | T_ISSET '(' variables_list ')' { $$ = Expr\Isset_[$3]; } - | T_EMPTY '(' expr ')' { $$ = Expr\Empty_[$3]; } - | T_INCLUDE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE]; } - | T_INCLUDE_ONCE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_INCLUDE_ONCE]; } - | T_EVAL parentheses_expr { $$ = Expr\Eval_[$2]; } - | T_REQUIRE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_REQUIRE]; } - | T_REQUIRE_ONCE expr { $$ = Expr\Include_[$2, Expr\Include_::TYPE_REQUIRE_ONCE]; } - | T_INT_CAST expr { $$ = Expr\Cast\Int_ [$2]; } - | T_DOUBLE_CAST expr - { $attrs = attributes(); - $attrs['kind'] = $this->getFloatCastKind($1); - $$ = new Expr\Cast\Double($2, $attrs); } - | T_STRING_CAST expr { $$ = Expr\Cast\String_ [$2]; } - | T_ARRAY_CAST expr { $$ = Expr\Cast\Array_ [$2]; } - | T_OBJECT_CAST expr { $$ = Expr\Cast\Object_ [$2]; } - | T_BOOL_CAST expr { $$ = Expr\Cast\Bool_ [$2]; } - | T_UNSET_CAST expr { $$ = Expr\Cast\Unset_ [$2]; } - | T_EXIT exit_expr - { $attrs = attributes(); - $attrs['kind'] = strtolower($1) === 'exit' ? Expr\Exit_::KIND_EXIT : Expr\Exit_::KIND_DIE; - $$ = new Expr\Exit_($2, $attrs); } - | '@' expr { $$ = Expr\ErrorSuppress[$2]; } - | scalar { $$ = $1; } - | array_expr { $$ = $1; } - | scalar_dereference { $$ = $1; } - | '`' backticks_expr '`' { $$ = Expr\ShellExec[$2]; } - | T_PRINT expr { $$ = Expr\Print_[$2]; } - | T_YIELD { $$ = Expr\Yield_[null, null]; } - | T_YIELD_FROM expr { $$ = Expr\YieldFrom[$2]; } - | T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type - '{' inner_statement_list '}' - { $$ = Expr\Closure[['static' => false, 'byRef' => $2, 'params' => $4, 'uses' => $6, 'returnType' => $7, 'stmts' => $9]]; } - | T_STATIC T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars optional_return_type - '{' inner_statement_list '}' - { $$ = Expr\Closure[['static' => true, 'byRef' => $3, 'params' => $5, 'uses' => $7, 'returnType' => $8, 'stmts' => $10]]; } -; - -parentheses_expr: - '(' expr ')' { $$ = $2; } - | '(' yield_expr ')' { $$ = $2; } -; - -yield_expr: - T_YIELD expr { $$ = Expr\Yield_[$2, null]; } - | T_YIELD expr T_DOUBLE_ARROW expr { $$ = Expr\Yield_[$4, $2]; } -; - -array_expr: - T_ARRAY '(' array_pair_list ')' - { $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_LONG; - $$ = new Expr\Array_($3, $attrs); } - | '[' array_pair_list ']' - { $attrs = attributes(); $attrs['kind'] = Expr\Array_::KIND_SHORT; - $$ = new Expr\Array_($2, $attrs); } -; - -scalar_dereference: - array_expr '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } - | T_CONSTANT_ENCAPSED_STRING '[' dim_offset ']' - { $attrs = attributes(); $attrs['kind'] = strKind($1); - $$ = Expr\ArrayDimFetch[new Scalar\String_(Scalar\String_::parse($1), $attrs), $3]; } - | constant '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } - | scalar_dereference '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } - /* alternative array syntax missing intentionally */ -; - -anonymous_class: - T_CLASS ctor_arguments extends_from implements_list '{' class_statement_list '}' - { $$ = array(Stmt\Class_[null, ['type' => 0, 'extends' => $3, 'implements' => $4, 'stmts' => $6]], $2); - $this->checkClass($$[0], -1); } -; - -new_expr: - T_NEW class_name_reference ctor_arguments { $$ = Expr\New_[$2, $3]; } - | T_NEW anonymous_class - { list($class, $ctorArgs) = $2; $$ = Expr\New_[$class, $ctorArgs]; } -; - -lexical_vars: - /* empty */ { $$ = array(); } - | T_USE '(' lexical_var_list ')' { $$ = $3; } -; - -lexical_var_list: - lexical_var { init($1); } - | lexical_var_list ',' lexical_var { push($1, $3); } -; - -lexical_var: - optional_ref plain_variable { $$ = Expr\ClosureUse[$2, $1]; } -; - -function_call: - name argument_list { $$ = Expr\FuncCall[$1, $2]; } - | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex argument_list - { $$ = Expr\StaticCall[$1, $3, $4]; } - | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '{' expr '}' argument_list - { $$ = Expr\StaticCall[$1, $4, $6]; } - | static_property argument_list - { $$ = $this->fixupPhp5StaticPropCall($1, $2, attributes()); } - | variable_without_objects argument_list - { $$ = Expr\FuncCall[$1, $2]; } - | function_call '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } - /* alternative array syntax missing intentionally */ -; - -class_name: - T_STATIC { $$ = Name[$1]; } - | name { $$ = $1; } -; - -name: - T_STRING { $$ = Name[$1]; } - | T_NAME_QUALIFIED { $$ = Name[$1]; } - | T_NAME_FULLY_QUALIFIED { $$ = Name\FullyQualified[substr($1, 1)]; } - | T_NAME_RELATIVE { $$ = Name\Relative[substr($1, 10)]; } -; - -class_name_reference: - class_name { $$ = $1; } - | dynamic_class_name_reference { $$ = $1; } -; - -dynamic_class_name_reference: - object_access_for_dcnr { $$ = $1; } - | base_variable { $$ = $1; } -; - -class_name_or_var: - class_name { $$ = $1; } - | reference_variable { $$ = $1; } -; - -object_access_for_dcnr: - base_variable T_OBJECT_OPERATOR object_property - { $$ = Expr\PropertyFetch[$1, $3]; } - | object_access_for_dcnr T_OBJECT_OPERATOR object_property - { $$ = Expr\PropertyFetch[$1, $3]; } - | object_access_for_dcnr '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } - | object_access_for_dcnr '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; } -; - -exit_expr: - /* empty */ { $$ = null; } - | '(' ')' { $$ = null; } - | parentheses_expr { $$ = $1; } -; - -backticks_expr: - /* empty */ { $$ = array(); } - | T_ENCAPSED_AND_WHITESPACE - { $$ = array(Scalar\EncapsedStringPart[Scalar\String_::parseEscapeSequences($1, '`', false)]); } - | encaps_list { parseEncapsed($1, '`', false); $$ = $1; } -; - -ctor_arguments: - /* empty */ { $$ = array(); } - | argument_list { $$ = $1; } -; - -common_scalar: - T_LNUMBER { $$ = $this->parseLNumber($1, attributes(), true); } - | T_DNUMBER { $$ = Scalar\DNumber[Scalar\DNumber::parse($1)]; } - | T_CONSTANT_ENCAPSED_STRING - { $attrs = attributes(); $attrs['kind'] = strKind($1); - $$ = new Scalar\String_(Scalar\String_::parse($1, false), $attrs); } - | T_LINE { $$ = Scalar\MagicConst\Line[]; } - | T_FILE { $$ = Scalar\MagicConst\File[]; } - | T_DIR { $$ = Scalar\MagicConst\Dir[]; } - | T_CLASS_C { $$ = Scalar\MagicConst\Class_[]; } - | T_TRAIT_C { $$ = Scalar\MagicConst\Trait_[]; } - | T_METHOD_C { $$ = Scalar\MagicConst\Method[]; } - | T_FUNC_C { $$ = Scalar\MagicConst\Function_[]; } - | T_NS_C { $$ = Scalar\MagicConst\Namespace_[]; } - | T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC - { $$ = $this->parseDocString($1, $2, $3, attributes(), stackAttributes(#3), false); } - | T_START_HEREDOC T_END_HEREDOC - { $$ = $this->parseDocString($1, '', $2, attributes(), stackAttributes(#2), false); } -; - -static_scalar: - common_scalar { $$ = $1; } - | class_name T_PAAMAYIM_NEKUDOTAYIM identifier_ex { $$ = Expr\ClassConstFetch[$1, $3]; } - | name { $$ = Expr\ConstFetch[$1]; } - | T_ARRAY '(' static_array_pair_list ')' { $$ = Expr\Array_[$3]; } - | '[' static_array_pair_list ']' { $$ = Expr\Array_[$2]; } - | static_operation { $$ = $1; } -; - -static_operation: - static_scalar T_BOOLEAN_OR static_scalar { $$ = Expr\BinaryOp\BooleanOr [$1, $3]; } - | static_scalar T_BOOLEAN_AND static_scalar { $$ = Expr\BinaryOp\BooleanAnd[$1, $3]; } - | static_scalar T_LOGICAL_OR static_scalar { $$ = Expr\BinaryOp\LogicalOr [$1, $3]; } - | static_scalar T_LOGICAL_AND static_scalar { $$ = Expr\BinaryOp\LogicalAnd[$1, $3]; } - | static_scalar T_LOGICAL_XOR static_scalar { $$ = Expr\BinaryOp\LogicalXor[$1, $3]; } - | static_scalar '|' static_scalar { $$ = Expr\BinaryOp\BitwiseOr [$1, $3]; } - | static_scalar '&' static_scalar { $$ = Expr\BinaryOp\BitwiseAnd[$1, $3]; } - | static_scalar '^' static_scalar { $$ = Expr\BinaryOp\BitwiseXor[$1, $3]; } - | static_scalar '.' static_scalar { $$ = Expr\BinaryOp\Concat [$1, $3]; } - | static_scalar '+' static_scalar { $$ = Expr\BinaryOp\Plus [$1, $3]; } - | static_scalar '-' static_scalar { $$ = Expr\BinaryOp\Minus [$1, $3]; } - | static_scalar '*' static_scalar { $$ = Expr\BinaryOp\Mul [$1, $3]; } - | static_scalar '/' static_scalar { $$ = Expr\BinaryOp\Div [$1, $3]; } - | static_scalar '%' static_scalar { $$ = Expr\BinaryOp\Mod [$1, $3]; } - | static_scalar T_SL static_scalar { $$ = Expr\BinaryOp\ShiftLeft [$1, $3]; } - | static_scalar T_SR static_scalar { $$ = Expr\BinaryOp\ShiftRight[$1, $3]; } - | static_scalar T_POW static_scalar { $$ = Expr\BinaryOp\Pow [$1, $3]; } - | '+' static_scalar %prec T_INC { $$ = Expr\UnaryPlus [$2]; } - | '-' static_scalar %prec T_INC { $$ = Expr\UnaryMinus[$2]; } - | '!' static_scalar { $$ = Expr\BooleanNot[$2]; } - | '~' static_scalar { $$ = Expr\BitwiseNot[$2]; } - | static_scalar T_IS_IDENTICAL static_scalar { $$ = Expr\BinaryOp\Identical [$1, $3]; } - | static_scalar T_IS_NOT_IDENTICAL static_scalar { $$ = Expr\BinaryOp\NotIdentical [$1, $3]; } - | static_scalar T_IS_EQUAL static_scalar { $$ = Expr\BinaryOp\Equal [$1, $3]; } - | static_scalar T_IS_NOT_EQUAL static_scalar { $$ = Expr\BinaryOp\NotEqual [$1, $3]; } - | static_scalar '<' static_scalar { $$ = Expr\BinaryOp\Smaller [$1, $3]; } - | static_scalar T_IS_SMALLER_OR_EQUAL static_scalar { $$ = Expr\BinaryOp\SmallerOrEqual[$1, $3]; } - | static_scalar '>' static_scalar { $$ = Expr\BinaryOp\Greater [$1, $3]; } - | static_scalar T_IS_GREATER_OR_EQUAL static_scalar { $$ = Expr\BinaryOp\GreaterOrEqual[$1, $3]; } - | static_scalar '?' static_scalar ':' static_scalar { $$ = Expr\Ternary[$1, $3, $5]; } - | static_scalar '?' ':' static_scalar { $$ = Expr\Ternary[$1, null, $4]; } - | static_scalar '[' static_scalar ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } - | '(' static_scalar ')' { $$ = $2; } -; - -constant: - name { $$ = Expr\ConstFetch[$1]; } - | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM identifier_ex - { $$ = Expr\ClassConstFetch[$1, $3]; } -; - -scalar: - common_scalar { $$ = $1; } - | constant { $$ = $1; } - | '"' encaps_list '"' - { $attrs = attributes(); $attrs['kind'] = Scalar\String_::KIND_DOUBLE_QUOTED; - parseEncapsed($2, '"', true); $$ = new Scalar\Encapsed($2, $attrs); } - | T_START_HEREDOC encaps_list T_END_HEREDOC - { $$ = $this->parseDocString($1, $2, $3, attributes(), stackAttributes(#3), true); } -; - -static_array_pair_list: - /* empty */ { $$ = array(); } - | non_empty_static_array_pair_list optional_comma { $$ = $1; } -; - -optional_comma: - /* empty */ - | ',' -; - -non_empty_static_array_pair_list: - non_empty_static_array_pair_list ',' static_array_pair { push($1, $3); } - | static_array_pair { init($1); } -; - -static_array_pair: - static_scalar T_DOUBLE_ARROW static_scalar { $$ = Expr\ArrayItem[$3, $1, false]; } - | static_scalar { $$ = Expr\ArrayItem[$1, null, false]; } -; - -variable: - object_access { $$ = $1; } - | base_variable { $$ = $1; } - | function_call { $$ = $1; } - | new_expr_array_deref { $$ = $1; } -; - -new_expr_array_deref: - '(' new_expr ')' '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$2, $5]; } - | new_expr_array_deref '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } - /* alternative array syntax missing intentionally */ -; - -object_access: - variable_or_new_expr T_OBJECT_OPERATOR object_property - { $$ = Expr\PropertyFetch[$1, $3]; } - | variable_or_new_expr T_OBJECT_OPERATOR object_property argument_list - { $$ = Expr\MethodCall[$1, $3, $4]; } - | object_access argument_list { $$ = Expr\FuncCall[$1, $2]; } - | object_access '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } - | object_access '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; } -; - -variable_or_new_expr: - variable { $$ = $1; } - | '(' new_expr ')' { $$ = $2; } -; - -variable_without_objects: - reference_variable { $$ = $1; } - | '$' variable_without_objects { $$ = Expr\Variable[$2]; } -; - -base_variable: - variable_without_objects { $$ = $1; } - | static_property { $$ = $1; } -; - -static_property: - class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '$' reference_variable - { $$ = Expr\StaticPropertyFetch[$1, $4]; } - | static_property_with_arrays { $$ = $1; } -; - -static_property_simple_name: - T_VARIABLE - { $var = parseVar($1); $$ = \is_string($var) ? Node\VarLikeIdentifier[$var] : $var; } -; - -static_property_with_arrays: - class_name_or_var T_PAAMAYIM_NEKUDOTAYIM static_property_simple_name - { $$ = Expr\StaticPropertyFetch[$1, $3]; } - | class_name_or_var T_PAAMAYIM_NEKUDOTAYIM '$' '{' expr '}' - { $$ = Expr\StaticPropertyFetch[$1, $5]; } - | static_property_with_arrays '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } - | static_property_with_arrays '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; } -; - -reference_variable: - reference_variable '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } - | reference_variable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; } - | plain_variable { $$ = $1; } - | '$' '{' expr '}' { $$ = Expr\Variable[$3]; } -; - -dim_offset: - /* empty */ { $$ = null; } - | expr { $$ = $1; } -; - -object_property: - identifier { $$ = $1; } - | '{' expr '}' { $$ = $2; } - | variable_without_objects { $$ = $1; } - | error { $$ = Expr\Error[]; $this->errorState = 2; } -; - -list_expr: - T_LIST '(' list_expr_elements ')' { $$ = Expr\List_[$3]; } -; - -list_expr_elements: - list_expr_elements ',' list_expr_element { push($1, $3); } - | list_expr_element { init($1); } -; - -list_expr_element: - variable { $$ = Expr\ArrayItem[$1, null, false]; } - | list_expr { $$ = Expr\ArrayItem[$1, null, false]; } - | /* empty */ { $$ = null; } -; - -array_pair_list: - /* empty */ { $$ = array(); } - | non_empty_array_pair_list optional_comma { $$ = $1; } -; - -non_empty_array_pair_list: - non_empty_array_pair_list ',' array_pair { push($1, $3); } - | array_pair { init($1); } -; - -array_pair: - expr T_DOUBLE_ARROW expr { $$ = Expr\ArrayItem[$3, $1, false]; } - | 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: - encaps_list encaps_var { push($1, $2); } - | encaps_list encaps_string_part { push($1, $2); } - | encaps_var { init($1); } - | encaps_string_part encaps_var { init($1, $2); } -; - -encaps_string_part: - T_ENCAPSED_AND_WHITESPACE { $$ = Scalar\EncapsedStringPart[$1]; } -; - -encaps_str_varname: - T_STRING_VARNAME { $$ = Expr\Variable[$1]; } -; - -encaps_var: - plain_variable { $$ = $1; } - | plain_variable '[' encaps_var_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } - | plain_variable T_OBJECT_OPERATOR identifier { $$ = Expr\PropertyFetch[$1, $3]; } - | T_DOLLAR_OPEN_CURLY_BRACES expr '}' { $$ = Expr\Variable[$2]; } - | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}' { $$ = Expr\Variable[$2]; } - | T_DOLLAR_OPEN_CURLY_BRACES encaps_str_varname '[' expr ']' '}' - { $$ = Expr\ArrayDimFetch[$2, $4]; } - | T_CURLY_OPEN variable '}' { $$ = $2; } -; - -encaps_var_offset: - T_STRING { $$ = Scalar\String_[$1]; } - | T_NUM_STRING { $$ = $this->parseNumString($1, attributes()); } - | plain_variable { $$ = $1; } -; - -%% diff --git a/grammar/phpyLang.php b/grammar/phpyLang.php new file mode 100644 index 0000000000..ac51e2c85d --- /dev/null +++ b/grammar/phpyLang.php @@ -0,0 +1,171 @@ +\'[^\\\\\']*+(?:\\\\.[^\\\\\']*+)*+\') + (?"[^\\\\"]*+(?:\\\\.[^\\\\"]*+)*+") + (?(?&singleQuotedString)|(?&doubleQuotedString)) + (?/\*[^*]*+(?:\*(?!/)[^*]*+)*+\*/) + (?\{[^\'"/{}]*+(?:(?:(?&string)|(?&comment)|(?&code)|/)[^\'"/{}]*+)*+}) +)'; + +const PARAMS = '\[(?[^[\]]*+(?:\[(?¶ms)\][^[\]]*+)*+)\]'; +const ARGS = '\((?[^()]*+(?:\((?&args)\)[^()]*+)*+)\)'; + +/////////////////////////////// +/// Preprocessing functions /// +/////////////////////////////// + +function preprocessGrammar($code) { + $code = resolveNodes($code); + $code = resolveMacros($code); + $code = resolveStackAccess($code); + $code = str_replace('$this', '$self', $code); + + return $code; +} + +function resolveNodes($code) { + return preg_replace_callback( + '~\b(?[A-Z][a-zA-Z_\\\\]++)\s*' . PARAMS . '~', + function ($matches) { + // recurse + $matches['params'] = resolveNodes($matches['params']); + + $params = magicSplit( + '(?:' . PARAMS . '|' . ARGS . ')(*SKIP)(*FAIL)|,', + $matches['params'] + ); + + $paramCode = ''; + foreach ($params as $param) { + $paramCode .= $param . ', '; + } + + return 'new ' . $matches['name'] . '(' . $paramCode . 'attributes())'; + }, + $code + ); +} + +function resolveMacros($code) { + return preg_replace_callback( + '~\b(?)(?!array\()(?[a-z][A-Za-z]++)' . ARGS . '~', + function ($matches) { + // recurse + $matches['args'] = resolveMacros($matches['args']); + + $name = $matches['name']; + $args = magicSplit( + '(?:' . PARAMS . '|' . ARGS . ')(*SKIP)(*FAIL)|,', + $matches['args'] + ); + + if ('attributes' === $name) { + assertArgs(0, $args, $name); + return '$this->getAttributes($this->tokenStartStack[#1], $this->tokenEndStack[$stackPos])'; + } + + if ('stackAttributes' === $name) { + assertArgs(1, $args, $name); + return '$this->getAttributes($this->tokenStartStack[' . $args[0] . '], ' + . ' $this->tokenEndStack[' . $args[0] . '])'; + } + + if ('init' === $name) { + return '$$ = array(' . implode(', ', $args) . ')'; + } + + if ('push' === $name) { + assertArgs(2, $args, $name); + + return $args[0] . '[] = ' . $args[1] . '; $$ = ' . $args[0]; + } + + if ('pushNormalizing' === $name) { + assertArgs(2, $args, $name); + + return 'if (' . $args[1] . ' !== null) { ' . $args[0] . '[] = ' . $args[1] . '; } $$ = ' . $args[0] . ';'; + } + + if ('toBlock' == $name) { + assertArgs(1, $args, $name); + + return 'if (' . $args[0] . ' instanceof Stmt\Block) { $$ = ' . $args[0] . '->stmts; } ' + . 'else if (' . $args[0] . ' === null) { $$ = []; } ' + . 'else { $$ = [' . $args[0] . ']; }'; + } + + if ('parseVar' === $name) { + assertArgs(1, $args, $name); + + return 'substr(' . $args[0] . ', 1)'; + } + + if ('parseEncapsed' === $name) { + assertArgs(3, $args, $name); + + return 'foreach (' . $args[0] . ' as $s) { if ($s instanceof Node\InterpolatedStringPart) {' + . ' $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, ' . $args[1] . ', ' . $args[2] . '); } }'; + } + + if ('makeNop' === $name) { + assertArgs(1, $args, $name); + + return $args[0] . ' = $this->maybeCreateNop($this->tokenStartStack[#1], $this->tokenEndStack[$stackPos])'; + } + + if ('makeZeroLengthNop' == $name) { + assertArgs(1, $args, $name); + + return $args[0] . ' = $this->maybeCreateZeroLengthNop($this->tokenPos);'; + } + + return $matches[0]; + }, + $code + ); +} + +function assertArgs($num, $args, $name) { + if ($num != count($args)) { + die('Wrong argument count for ' . $name . '().'); + } +} + +function resolveStackAccess($code) { + $code = preg_replace('/\$\d+/', '$this->semStack[$0]', $code); + $code = preg_replace('/#(\d+)/', '$$1', $code); + return $code; +} + +function removeTrailingWhitespace($code) { + $lines = explode("\n", $code); + $lines = array_map('rtrim', $lines); + return implode("\n", $lines); +} + +////////////////////////////// +/// Regex helper functions /// +////////////////////////////// + +function regex($regex) { + return '~' . LIB . '(?:' . str_replace('~', '\~', $regex) . ')~'; +} + +function magicSplit($regex, $string) { + $pieces = preg_split(regex('(?:(?&string)|(?&comment)|(?&code))(*SKIP)(*FAIL)|' . $regex), $string); + + foreach ($pieces as &$piece) { + $piece = trim($piece); + } + + if ($pieces === ['']) { + return []; + } + + return $pieces; +} diff --git a/grammar/rebuildParsers.php b/grammar/rebuildParsers.php index 88a53f1334..a3ff9249c3 100644 --- a/grammar/rebuildParsers.php +++ b/grammar/rebuildParsers.php @@ -1,17 +1,17 @@ - 'Php5', - __DIR__ . '/php7.y' => 'Php7', +require __DIR__ . '/phpyLang.php'; + +$parserToDefines = [ + 'Php7' => ['PHP7' => true], + 'Php8' => ['PHP8' => true], ]; -$tokensFile = __DIR__ . '/tokens.y'; -$tokensTemplate = __DIR__ . '/tokens.template'; +$grammarFile = __DIR__ . '/php.y'; $skeletonFile = __DIR__ . '/parser.template'; $tmpGrammarFile = __DIR__ . '/tmp_parser.phpy'; $tmpResultFile = __DIR__ . '/tmp_parser.php'; $resultDir = __DIR__ . '/../lib/PhpParser/Parser'; -$tokensResultsFile = $resultDir . '/Tokens.php'; $kmyacc = getenv('KMYACC'); if (!$kmyacc) { @@ -23,36 +23,16 @@ $optionDebug = isset($options['--debug']); $optionKeepTmpGrammar = isset($options['--keep-tmp-grammar']); -/////////////////////////////// -/// Utility regex constants /// -/////////////////////////////// - -const LIB = '(?(DEFINE) - (?\'[^\\\\\']*+(?:\\\\.[^\\\\\']*+)*+\') - (?"[^\\\\"]*+(?:\\\\.[^\\\\"]*+)*+") - (?(?&singleQuotedString)|(?&doubleQuotedString)) - (?/\*[^*]*+(?:\*(?!/)[^*]*+)*+\*/) - (?\{[^\'"/{}]*+(?:(?:(?&string)|(?&comment)|(?&code)|/)[^\'"/{}]*+)*+}) -)'; - -const PARAMS = '\[(?[^[\]]*+(?:\[(?¶ms)\][^[\]]*+)*+)\]'; -const ARGS = '\((?[^()]*+(?:\((?&args)\)[^()]*+)*+)\)'; - /////////////////// /// Main script /// /////////////////// -$tokens = file_get_contents($tokensFile); - -foreach ($grammarFileToName as $grammarFile => $name) { +foreach ($parserToDefines as $name => $defines) { echo "Building temporary $name grammar file.\n"; $grammarCode = file_get_contents($grammarFile); - $grammarCode = str_replace('%tokens', $tokens, $grammarCode); - - $grammarCode = resolveNodes($grammarCode); - $grammarCode = resolveMacros($grammarCode); - $grammarCode = resolveStackAccess($grammarCode); + $grammarCode = replaceIfBlocks($grammarCode, $defines); + $grammarCode = preprocessGrammar($grammarCode); file_put_contents($tmpGrammarFile, $grammarCode); @@ -68,160 +48,14 @@ file_put_contents("$resultDir/$name.php", $resultCode); unlink($tmpResultFile); - echo "Building token definition.\n"; - $output = execCmd("$kmyacc -m $tokensTemplate $tmpGrammarFile"); - rename($tmpResultFile, $tokensResultsFile); - if (!$optionKeepTmpGrammar) { unlink($tmpGrammarFile); } } -/////////////////////////////// -/// Preprocessing functions /// -/////////////////////////////// - -function resolveNodes($code) { - return preg_replace_callback( - '~\b(?[A-Z][a-zA-Z_\\\\]++)\s*' . PARAMS . '~', - function($matches) { - // recurse - $matches['params'] = resolveNodes($matches['params']); - - $params = magicSplit( - '(?:' . PARAMS . '|' . ARGS . ')(*SKIP)(*FAIL)|,', - $matches['params'] - ); - - $paramCode = ''; - foreach ($params as $param) { - $paramCode .= $param . ', '; - } - - return 'new ' . $matches['name'] . '(' . $paramCode . 'attributes())'; - }, - $code - ); -} - -function resolveMacros($code) { - return preg_replace_callback( - '~\b(?)(?!array\()(?[a-z][A-Za-z]++)' . ARGS . '~', - function($matches) { - // recurse - $matches['args'] = resolveMacros($matches['args']); - - $name = $matches['name']; - $args = magicSplit( - '(?:' . PARAMS . '|' . ARGS . ')(*SKIP)(*FAIL)|,', - $matches['args'] - ); - - if ('attributes' === $name) { - assertArgs(0, $args, $name); - return '$this->startAttributeStack[#1] + $this->endAttributes'; - } - - if ('stackAttributes' === $name) { - assertArgs(1, $args, $name); - return '$this->startAttributeStack[' . $args[0] . ']' - . ' + $this->endAttributeStack[' . $args[0] . ']'; - } - - if ('init' === $name) { - return '$$ = array(' . implode(', ', $args) . ')'; - } - - if ('push' === $name) { - assertArgs(2, $args, $name); - - return $args[0] . '[] = ' . $args[1] . '; $$ = ' . $args[0]; - } - - if ('pushNormalizing' === $name) { - assertArgs(2, $args, $name); - - return 'if (is_array(' . $args[1] . ')) { $$ = array_merge(' . $args[0] . ', ' . $args[1] . '); }' - . ' else { ' . $args[0] . '[] = ' . $args[1] . '; $$ = ' . $args[0] . '; }'; - } - - if ('toArray' == $name) { - assertArgs(1, $args, $name); - - return 'is_array(' . $args[0] . ') ? ' . $args[0] . ' : array(' . $args[0] . ')'; - } - - if ('parseVar' === $name) { - assertArgs(1, $args, $name); - - return 'substr(' . $args[0] . ', 1)'; - } - - if ('parseEncapsed' === $name) { - assertArgs(3, $args, $name); - - return 'foreach (' . $args[0] . ' as $s) { if ($s instanceof Node\Scalar\EncapsedStringPart) {' - . ' $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, ' . $args[1] . ', ' . $args[2] . '); } }'; - } - - if ('makeNop' === $name) { - assertArgs(3, $args, $name); - - return '$startAttributes = ' . $args[1] . ';' - . ' if (isset($startAttributes[\'comments\']))' - . ' { ' . $args[0] . ' = new Stmt\Nop($startAttributes + ' . $args[2] . '); }' - . ' 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->createCommentNopAttributes($startAttributes[\'comments\'])); }' - . ' else { ' . $args[0] . ' = null; }'; - } - - if ('strKind' === $name) { - assertArgs(1, $args, $name); - - return '(' . $args[0] . '[0] === "\'" || (' . $args[0] . '[1] === "\'" && ' - . '(' . $args[0] . '[0] === \'b\' || ' . $args[0] . '[0] === \'B\')) ' - . '? Scalar\String_::KIND_SINGLE_QUOTED : Scalar\String_::KIND_DOUBLE_QUOTED)'; - } - - if ('prependLeadingComments' === $name) { - assertArgs(1, $args, $name); - - return '$attrs = $this->startAttributeStack[#1]; $stmts = ' . $args[0] . '; ' - . 'if (!empty($attrs[\'comments\'])) {' - . '$stmts[0]->setAttribute(\'comments\', ' - . 'array_merge($attrs[\'comments\'], $stmts[0]->getAttribute(\'comments\', []))); }'; - } - - return $matches[0]; - }, - $code - ); -} - -function assertArgs($num, $args, $name) { - if ($num != count($args)) { - die('Wrong argument count for ' . $name . '().'); - } -} - -function resolveStackAccess($code) { - $code = preg_replace('/\$\d+/', '$this->semStack[$0]', $code); - $code = preg_replace('/#(\d+)/', '$$1', $code); - return $code; -} - -function removeTrailingWhitespace($code) { - $lines = explode("\n", $code); - $lines = array_map('rtrim', $lines); - return implode("\n", $lines); -} +//////////////////////////////// +/// Utility helper functions /// +//////////////////////////////// function ensureDirExists($dir) { if (!is_dir($dir)) { @@ -230,7 +64,7 @@ function ensureDirExists($dir) { } function execCmd($cmd) { - $output = trim(shell_exec("$cmd 2>&1")); + $output = trim(shell_exec("$cmd 2>&1") ?? ''); if ($output !== "") { echo "> " . $cmd . "\n"; echo $output; @@ -238,24 +72,9 @@ function execCmd($cmd) { return $output; } -////////////////////////////// -/// Regex helper functions /// -////////////////////////////// - -function regex($regex) { - return '~' . LIB . '(?:' . str_replace('~', '\~', $regex) . ')~'; -} - -function magicSplit($regex, $string) { - $pieces = preg_split(regex('(?:(?&string)|(?&comment)|(?&code))(*SKIP)(*FAIL)|' . $regex), $string); - - foreach ($pieces as &$piece) { - $piece = trim($piece); - } - - if ($pieces === ['']) { - return []; - } - - return $pieces; +function replaceIfBlocks(string $code, array $defines): string { + return preg_replace_callback('/\n#if\s+(\w+)\n(.*?)\n#endif/s', function ($matches) use ($defines) { + $value = $defines[$matches[1]] ?? false; + return $value ? $matches[2] : ''; + }, $code); } diff --git a/grammar/tokens.template b/grammar/tokens.template deleted file mode 100644 index ba4e4901c0..0000000000 --- a/grammar/tokens.template +++ /dev/null @@ -1,17 +0,0 @@ -semValue -#semval($,%t) $this->semValue -#semval(%n) $this->stackPos-(%l-%n) -#semval(%n,%t) $this->stackPos-(%l-%n) - -namespace PhpParser\Parser; -#include; - -/* GENERATED file based on grammar/tokens.y */ -final class Tokens -{ -#tokenval - const %s = %n; -#endtokenval -} diff --git a/grammar/tokens.y b/grammar/tokens.y deleted file mode 100644 index d2c2b7205d..0000000000 --- a/grammar/tokens.y +++ /dev/null @@ -1,114 +0,0 @@ -/* We currently rely on the token ID mapping to be the same between PHP 5 and PHP 7 - so the same lexer can be used for - * both. This is enforced by sharing this token file. */ - -%right T_THROW -%left T_INCLUDE T_INCLUDE_ONCE T_EVAL T_REQUIRE T_REQUIRE_ONCE -%left ',' -%left T_LOGICAL_OR -%left T_LOGICAL_XOR -%left T_LOGICAL_AND -%right T_PRINT -%right T_YIELD -%right T_DOUBLE_ARROW -%right T_YIELD_FROM -%left '=' T_PLUS_EQUAL T_MINUS_EQUAL T_MUL_EQUAL T_DIV_EQUAL T_CONCAT_EQUAL T_MOD_EQUAL T_AND_EQUAL T_OR_EQUAL T_XOR_EQUAL T_SL_EQUAL T_SR_EQUAL T_POW_EQUAL T_COALESCE_EQUAL -%left '?' ':' -%right T_COALESCE -%left T_BOOLEAN_OR -%left T_BOOLEAN_AND -%left '|' -%left '^' -%left '&' -%nonassoc T_IS_EQUAL T_IS_NOT_EQUAL T_IS_IDENTICAL T_IS_NOT_IDENTICAL T_SPACESHIP -%nonassoc '<' T_IS_SMALLER_OR_EQUAL '>' T_IS_GREATER_OR_EQUAL -%left T_SL T_SR -%left '+' '-' '.' -%left '*' '/' '%' -%right '!' -%nonassoc T_INSTANCEOF -%right '~' T_INC T_DEC T_INT_CAST T_DOUBLE_CAST T_STRING_CAST T_ARRAY_CAST T_OBJECT_CAST T_BOOL_CAST T_UNSET_CAST '@' -%right T_POW -%right '[' -%nonassoc T_NEW T_CLONE -%token T_EXIT -%token T_IF -%left T_ELSEIF -%left T_ELSE -%left T_ENDIF -%token T_LNUMBER -%token T_DNUMBER -%token T_STRING -%token T_STRING_VARNAME -%token T_VARIABLE -%token T_NUM_STRING -%token T_INLINE_HTML -%token T_ENCAPSED_AND_WHITESPACE -%token T_CONSTANT_ENCAPSED_STRING -%token T_ECHO -%token T_DO -%token T_WHILE -%token T_ENDWHILE -%token T_FOR -%token T_ENDFOR -%token T_FOREACH -%token T_ENDFOREACH -%token T_DECLARE -%token T_ENDDECLARE -%token T_AS -%token T_SWITCH -%token T_MATCH -%token T_ENDSWITCH -%token T_CASE -%token T_DEFAULT -%token T_BREAK -%token T_CONTINUE -%token T_GOTO -%token T_FUNCTION -%token T_FN -%token T_CONST -%token T_RETURN -%token T_TRY -%token T_CATCH -%token T_FINALLY -%token T_THROW -%token T_USE -%token T_INSTEADOF -%token T_GLOBAL -%right T_STATIC T_ABSTRACT T_FINAL T_PRIVATE T_PROTECTED T_PUBLIC -%token T_VAR -%token T_UNSET -%token T_ISSET -%token T_EMPTY -%token T_HALT_COMPILER -%token T_CLASS -%token T_TRAIT -%token T_INTERFACE -%token T_EXTENDS -%token T_IMPLEMENTS -%token T_OBJECT_OPERATOR -%token T_NULLSAFE_OBJECT_OPERATOR -%token T_DOUBLE_ARROW -%token T_LIST -%token T_ARRAY -%token T_CALLABLE -%token T_CLASS_C -%token T_TRAIT_C -%token T_METHOD_C -%token T_FUNC_C -%token T_LINE -%token T_FILE -%token T_START_HEREDOC -%token T_END_HEREDOC -%token T_DOLLAR_OPEN_CURLY_BRACES -%token T_CURLY_OPEN -%token T_PAAMAYIM_NEKUDOTAYIM -%token T_NAMESPACE -%token T_NS_C -%token T_DIR -%token T_NS_SEPARATOR -%token T_ELLIPSIS -%token T_NAME_FULLY_QUALIFIED -%token T_NAME_QUALIFIED -%token T_NAME_RELATIVE -%token T_ATTRIBUTE -%token T_ENUM \ No newline at end of file diff --git a/lib/PhpParser/Builder.php b/lib/PhpParser/Builder.php index 26d8921efc..d6aa124c02 100644 --- a/lib/PhpParser/Builder.php +++ b/lib/PhpParser/Builder.php @@ -2,12 +2,11 @@ namespace PhpParser; -interface Builder -{ +interface Builder { /** * Returns the built node. * * @return Node The built node */ - public function getNode() : Node; + public function getNode(): Node; } diff --git a/lib/PhpParser/Builder/ClassConst.php b/lib/PhpParser/Builder/ClassConst.php index 442307e808..138fa638c1 100644 --- a/lib/PhpParser/Builder/ClassConst.php +++ b/lib/PhpParser/Builder/ClassConst.php @@ -6,21 +6,29 @@ use PhpParser; use PhpParser\BuilderHelpers; +use PhpParser\Modifiers; +use PhpParser\Node; use PhpParser\Node\Const_; use PhpParser\Node\Identifier; use PhpParser\Node\Stmt; -class ClassConst implements PhpParser\Builder -{ - protected $flags = 0; - protected $attributes = []; - protected $constants = []; +class ClassConst implements PhpParser\Builder { + protected int $flags = 0; + /** @var array */ + protected array $attributes = []; + /** @var list */ + protected array $constants = []; + + /** @var list */ + protected array $attributeGroups = []; + /** @var Identifier|Node\Name|Node\ComplexType|null */ + protected ?Node $type = null; /** * Creates a class constant builder * - * @param string|Identifier $name Name - * @param Node\Expr|bool|null|int|float|string|array $value Value + * @param string|Identifier $name Name + * @param Node\Expr|bool|null|int|float|string|array|\UnitEnum $value Value */ public function __construct($name, $value) { $this->constants = [new Const_($name, BuilderHelpers::normalizeValue($value))]; @@ -29,8 +37,8 @@ public function __construct($name, $value) { /** * Add another constant to const group * - * @param string|Identifier $name Name - * @param Node\Expr|bool|null|int|float|string|array $value Value + * @param string|Identifier $name Name + * @param Node\Expr|bool|null|int|float|string|array|\UnitEnum $value Value * * @return $this The builder instance (for fluid interface) */ @@ -46,7 +54,7 @@ public function addConst($name, $value) { * @return $this The builder instance (for fluid interface) */ public function makePublic() { - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PUBLIC); + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PUBLIC); return $this; } @@ -57,7 +65,7 @@ public function makePublic() { * @return $this The builder instance (for fluid interface) */ public function makeProtected() { - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PROTECTED); + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PROTECTED); return $this; } @@ -68,7 +76,18 @@ public function makeProtected() { * @return $this The builder instance (for fluid interface) */ public function makePrivate() { - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PRIVATE); + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PRIVATE); + + return $this; + } + + /** + * Makes the constant final. + * + * @return $this The builder instance (for fluid interface) + */ + public function makeFinal() { + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::FINAL); return $this; } @@ -88,6 +107,32 @@ public function setDocComment($docComment) { return $this; } + /** + * Adds an attribute group. + * + * @param Node\Attribute|Node\AttributeGroup $attribute + * + * @return $this The builder instance (for fluid interface) + */ + public function addAttribute($attribute) { + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); + + return $this; + } + + /** + * Sets the constant type. + * + * @param string|Node\Name|Identifier|Node\ComplexType $type + * + * @return $this + */ + public function setType($type) { + $this->type = BuilderHelpers::normalizeType($type); + + return $this; + } + /** * Returns the built class node. * @@ -97,7 +142,9 @@ public function getNode(): PhpParser\Node { return new Stmt\ClassConst( $this->constants, $this->flags, - $this->attributes + $this->attributes, + $this->attributeGroups, + $this->type ); } } diff --git a/lib/PhpParser/Builder/Class_.php b/lib/PhpParser/Builder/Class_.php index c2f2468914..6f394315ec 100644 --- a/lib/PhpParser/Builder/Class_.php +++ b/lib/PhpParser/Builder/Class_.php @@ -4,21 +4,27 @@ use PhpParser; use PhpParser\BuilderHelpers; +use PhpParser\Modifiers; +use PhpParser\Node; use PhpParser\Node\Name; use PhpParser\Node\Stmt; -class Class_ extends Declaration -{ - protected $name; - - protected $extends = null; - protected $implements = []; - protected $flags = 0; - - protected $uses = []; - protected $constants = []; - protected $properties = []; - protected $methods = []; +class Class_ extends Declaration { + protected string $name; + protected ?Name $extends = null; + /** @var list */ + protected array $implements = []; + protected int $flags = 0; + /** @var list */ + protected array $uses = []; + /** @var list */ + protected array $constants = []; + /** @var list */ + protected array $properties = []; + /** @var list */ + protected array $methods = []; + /** @var list */ + protected array $attributeGroups = []; /** * Creates a class builder. @@ -63,7 +69,7 @@ public function implement(...$interfaces) { * @return $this The builder instance (for fluid interface) */ public function makeAbstract() { - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_ABSTRACT); + $this->flags = BuilderHelpers::addClassModifier($this->flags, Modifiers::ABSTRACT); return $this; } @@ -74,7 +80,18 @@ public function makeAbstract() { * @return $this The builder instance (for fluid interface) */ public function makeFinal() { - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_FINAL); + $this->flags = BuilderHelpers::addClassModifier($this->flags, Modifiers::FINAL); + + return $this; + } + + /** + * Makes the class readonly. + * + * @return $this The builder instance (for fluid interface) + */ + public function makeReadonly() { + $this->flags = BuilderHelpers::addClassModifier($this->flags, Modifiers::READONLY); return $this; } @@ -89,19 +106,30 @@ public function makeFinal() { public function addStmt($stmt) { $stmt = BuilderHelpers::normalizeNode($stmt); - $targets = [ - Stmt\TraitUse::class => &$this->uses, - Stmt\ClassConst::class => &$this->constants, - Stmt\Property::class => &$this->properties, - Stmt\ClassMethod::class => &$this->methods, - ]; - - $class = \get_class($stmt); - if (!isset($targets[$class])) { + if ($stmt instanceof Stmt\Property) { + $this->properties[] = $stmt; + } elseif ($stmt instanceof Stmt\ClassMethod) { + $this->methods[] = $stmt; + } elseif ($stmt instanceof Stmt\TraitUse) { + $this->uses[] = $stmt; + } elseif ($stmt instanceof Stmt\ClassConst) { + $this->constants[] = $stmt; + } else { throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); } - $targets[$class][] = $stmt; + return $this; + } + + /** + * Adds an attribute group. + * + * @param Node\Attribute|Node\AttributeGroup $attribute + * + * @return $this The builder instance (for fluid interface) + */ + public function addAttribute($attribute) { + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); return $this; } @@ -111,12 +139,13 @@ public function addStmt($stmt) { * * @return Stmt\Class_ The built class node */ - public function getNode() : PhpParser\Node { + public function getNode(): PhpParser\Node { return new Stmt\Class_($this->name, [ 'flags' => $this->flags, 'extends' => $this->extends, 'implements' => $this->implements, 'stmts' => array_merge($this->uses, $this->constants, $this->properties, $this->methods), + 'attrGroups' => $this->attributeGroups, ], $this->attributes); } } diff --git a/lib/PhpParser/Builder/Declaration.php b/lib/PhpParser/Builder/Declaration.php index 830949928a..488b72131f 100644 --- a/lib/PhpParser/Builder/Declaration.php +++ b/lib/PhpParser/Builder/Declaration.php @@ -5,16 +5,23 @@ use PhpParser; use PhpParser\BuilderHelpers; -abstract class Declaration implements PhpParser\Builder -{ - protected $attributes = []; +abstract class Declaration implements PhpParser\Builder { + /** @var array */ + protected array $attributes = []; + /** + * Adds a statement. + * + * @param PhpParser\Node\Stmt|PhpParser\Builder $stmt The statement to add + * + * @return $this The builder instance (for fluid interface) + */ abstract public function addStmt($stmt); /** * Adds multiple statements. * - * @param array $stmts The statements to add + * @param (PhpParser\Node\Stmt|PhpParser\Builder)[] $stmts The statements to add * * @return $this The builder instance (for fluid interface) */ diff --git a/lib/PhpParser/Builder/EnumCase.php b/lib/PhpParser/Builder/EnumCase.php new file mode 100644 index 0000000000..c766321ba3 --- /dev/null +++ b/lib/PhpParser/Builder/EnumCase.php @@ -0,0 +1,86 @@ + */ + protected array $attributes = []; + + /** @var list */ + protected array $attributeGroups = []; + + /** + * Creates an enum case builder. + * + * @param string|Identifier $name Name + */ + public function __construct($name) { + $this->name = $name; + } + + /** + * Sets the value. + * + * @param Node\Expr|string|int $value + * + * @return $this + */ + public function setValue($value) { + $this->value = BuilderHelpers::normalizeValue($value); + + return $this; + } + + /** + * Sets doc comment for the constant. + * + * @param PhpParser\Comment\Doc|string $docComment Doc comment to set + * + * @return $this The builder instance (for fluid interface) + */ + public function setDocComment($docComment) { + $this->attributes = [ + 'comments' => [BuilderHelpers::normalizeDocComment($docComment)] + ]; + + return $this; + } + + /** + * Adds an attribute group. + * + * @param Node\Attribute|Node\AttributeGroup $attribute + * + * @return $this The builder instance (for fluid interface) + */ + public function addAttribute($attribute) { + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); + + return $this; + } + + /** + * Returns the built enum case node. + * + * @return Stmt\EnumCase The built constant node + */ + public function getNode(): PhpParser\Node { + return new Stmt\EnumCase( + $this->name, + $this->value, + $this->attributeGroups, + $this->attributes + ); + } +} diff --git a/lib/PhpParser/Builder/Enum_.php b/lib/PhpParser/Builder/Enum_.php new file mode 100644 index 0000000000..c00df03f5b --- /dev/null +++ b/lib/PhpParser/Builder/Enum_.php @@ -0,0 +1,116 @@ + */ + protected array $implements = []; + /** @var list */ + protected array $uses = []; + /** @var list */ + protected array $enumCases = []; + /** @var list */ + protected array $constants = []; + /** @var list */ + protected array $methods = []; + /** @var list */ + protected array $attributeGroups = []; + + /** + * Creates an enum builder. + * + * @param string $name Name of the enum + */ + public function __construct(string $name) { + $this->name = $name; + } + + /** + * Sets the scalar type. + * + * @param string|Identifier $scalarType + * + * @return $this + */ + public function setScalarType($scalarType) { + $this->scalarType = BuilderHelpers::normalizeType($scalarType); + + return $this; + } + + /** + * Implements one or more interfaces. + * + * @param Name|string ...$interfaces Names of interfaces to implement + * + * @return $this The builder instance (for fluid interface) + */ + public function implement(...$interfaces) { + foreach ($interfaces as $interface) { + $this->implements[] = BuilderHelpers::normalizeName($interface); + } + + return $this; + } + + /** + * Adds a statement. + * + * @param Stmt|PhpParser\Builder $stmt The statement to add + * + * @return $this The builder instance (for fluid interface) + */ + public function addStmt($stmt) { + $stmt = BuilderHelpers::normalizeNode($stmt); + + if ($stmt instanceof Stmt\EnumCase) { + $this->enumCases[] = $stmt; + } elseif ($stmt instanceof Stmt\ClassMethod) { + $this->methods[] = $stmt; + } elseif ($stmt instanceof Stmt\TraitUse) { + $this->uses[] = $stmt; + } elseif ($stmt instanceof Stmt\ClassConst) { + $this->constants[] = $stmt; + } else { + throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); + } + + return $this; + } + + /** + * Adds an attribute group. + * + * @param Node\Attribute|Node\AttributeGroup $attribute + * + * @return $this The builder instance (for fluid interface) + */ + public function addAttribute($attribute) { + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); + + return $this; + } + + /** + * Returns the built class node. + * + * @return Stmt\Enum_ The built enum node + */ + public function getNode(): PhpParser\Node { + return new Stmt\Enum_($this->name, [ + 'scalarType' => $this->scalarType, + 'implements' => $this->implements, + 'stmts' => array_merge($this->uses, $this->enumCases, $this->constants, $this->methods), + 'attrGroups' => $this->attributeGroups, + ], $this->attributes); + } +} diff --git a/lib/PhpParser/Builder/FunctionLike.php b/lib/PhpParser/Builder/FunctionLike.php index 8e7db399d3..ff79cb6b4a 100644 --- a/lib/PhpParser/Builder/FunctionLike.php +++ b/lib/PhpParser/Builder/FunctionLike.php @@ -5,13 +5,13 @@ use PhpParser\BuilderHelpers; use PhpParser\Node; -abstract class FunctionLike extends Declaration -{ - protected $returnByRef = false; - protected $params = []; +abstract class FunctionLike extends Declaration { + protected bool $returnByRef = false; + /** @var Node\Param[] */ + protected array $params = []; - /** @var string|Node\Name|Node\NullableType|null */ - protected $returnType = null; + /** @var Node\Identifier|Node\Name|Node\ComplexType|null */ + protected ?Node $returnType = null; /** * Make the function return by reference. @@ -46,7 +46,7 @@ public function addParam($param) { /** * Adds multiple parameters. * - * @param array $params The parameters to add + * @param (Node\Param|Param)[] $params The parameters to add * * @return $this The builder instance (for fluid interface) */ @@ -61,8 +61,7 @@ public function addParams(array $params) { /** * Sets the return type for PHP 7. * - * @param string|Node\Name|Node\NullableType $type One of array, callable, string, int, float, - * bool, iterable, or a class/interface name. + * @param string|Node\Name|Node\Identifier|Node\ComplexType $type * * @return $this The builder instance (for fluid interface) */ diff --git a/lib/PhpParser/Builder/Function_.php b/lib/PhpParser/Builder/Function_.php index 56eda2a812..48f5f69319 100644 --- a/lib/PhpParser/Builder/Function_.php +++ b/lib/PhpParser/Builder/Function_.php @@ -7,10 +7,13 @@ use PhpParser\Node; use PhpParser\Node\Stmt; -class Function_ extends FunctionLike -{ - protected $name; - protected $stmts = []; +class Function_ extends FunctionLike { + protected string $name; + /** @var list */ + protected array $stmts = []; + + /** @var list */ + protected array $attributeGroups = []; /** * Creates a function builder. @@ -34,17 +37,31 @@ public function addStmt($stmt) { return $this; } + /** + * Adds an attribute group. + * + * @param Node\Attribute|Node\AttributeGroup $attribute + * + * @return $this The builder instance (for fluid interface) + */ + public function addAttribute($attribute) { + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); + + return $this; + } + /** * Returns the built function node. * * @return Stmt\Function_ The built function node */ - public function getNode() : Node { + public function getNode(): Node { return new Stmt\Function_($this->name, [ 'byRef' => $this->returnByRef, 'params' => $this->params, 'returnType' => $this->returnType, 'stmts' => $this->stmts, + 'attrGroups' => $this->attributeGroups, ], $this->attributes); } } diff --git a/lib/PhpParser/Builder/Interface_.php b/lib/PhpParser/Builder/Interface_.php index 87e5b93ee1..13dd3f7f9b 100644 --- a/lib/PhpParser/Builder/Interface_.php +++ b/lib/PhpParser/Builder/Interface_.php @@ -4,15 +4,20 @@ use PhpParser; use PhpParser\BuilderHelpers; +use PhpParser\Node; use PhpParser\Node\Name; use PhpParser\Node\Stmt; -class Interface_ extends Declaration -{ - protected $name; - protected $extends = []; - protected $constants = []; - protected $methods = []; +class Interface_ extends Declaration { + protected string $name; + /** @var list */ + protected array $extends = []; + /** @var list */ + protected array $constants = []; + /** @var list */ + protected array $methods = []; + /** @var list */ + protected array $attributeGroups = []; /** * Creates an interface builder. @@ -61,15 +66,29 @@ public function addStmt($stmt) { return $this; } + /** + * Adds an attribute group. + * + * @param Node\Attribute|Node\AttributeGroup $attribute + * + * @return $this The builder instance (for fluid interface) + */ + public function addAttribute($attribute) { + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); + + return $this; + } + /** * Returns the built interface node. * * @return Stmt\Interface_ The built interface node */ - public function getNode() : PhpParser\Node { + public function getNode(): PhpParser\Node { return new Stmt\Interface_($this->name, [ 'extends' => $this->extends, 'stmts' => array_merge($this->constants, $this->methods), + 'attrGroups' => $this->attributeGroups, ], $this->attributes); } } diff --git a/lib/PhpParser/Builder/Method.php b/lib/PhpParser/Builder/Method.php index a3e8676592..8358dbe38f 100644 --- a/lib/PhpParser/Builder/Method.php +++ b/lib/PhpParser/Builder/Method.php @@ -4,16 +4,20 @@ use PhpParser; use PhpParser\BuilderHelpers; +use PhpParser\Modifiers; use PhpParser\Node; use PhpParser\Node\Stmt; -class Method extends FunctionLike -{ - protected $name; - protected $flags = 0; +class Method extends FunctionLike { + protected string $name; - /** @var array|null */ - protected $stmts = []; + protected int $flags = 0; + + /** @var list|null */ + protected ?array $stmts = []; + + /** @var list */ + protected array $attributeGroups = []; /** * Creates a method builder. @@ -30,7 +34,7 @@ public function __construct(string $name) { * @return $this The builder instance (for fluid interface) */ public function makePublic() { - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PUBLIC); + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PUBLIC); return $this; } @@ -41,7 +45,7 @@ public function makePublic() { * @return $this The builder instance (for fluid interface) */ public function makeProtected() { - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PROTECTED); + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PROTECTED); return $this; } @@ -52,7 +56,7 @@ public function makeProtected() { * @return $this The builder instance (for fluid interface) */ public function makePrivate() { - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PRIVATE); + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PRIVATE); return $this; } @@ -63,7 +67,7 @@ public function makePrivate() { * @return $this The builder instance (for fluid interface) */ public function makeStatic() { - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_STATIC); + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::STATIC); return $this; } @@ -78,7 +82,7 @@ public function makeAbstract() { throw new \LogicException('Cannot make method with statements abstract'); } - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_ABSTRACT); + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::ABSTRACT); $this->stmts = null; // abstract methods don't have statements return $this; @@ -90,7 +94,7 @@ public function makeAbstract() { * @return $this The builder instance (for fluid interface) */ public function makeFinal() { - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_FINAL); + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::FINAL); return $this; } @@ -112,18 +116,32 @@ public function addStmt($stmt) { return $this; } + /** + * Adds an attribute group. + * + * @param Node\Attribute|Node\AttributeGroup $attribute + * + * @return $this The builder instance (for fluid interface) + */ + public function addAttribute($attribute) { + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); + + return $this; + } + /** * Returns the built method node. * * @return Stmt\ClassMethod The built method node */ - public function getNode() : Node { + public function getNode(): Node { return new Stmt\ClassMethod($this->name, [ 'flags' => $this->flags, 'byRef' => $this->returnByRef, 'params' => $this->params, 'returnType' => $this->returnType, 'stmts' => $this->stmts, + 'attrGroups' => $this->attributeGroups, ], $this->attributes); } } diff --git a/lib/PhpParser/Builder/Namespace_.php b/lib/PhpParser/Builder/Namespace_.php index 1c751e163a..80fe6f8464 100644 --- a/lib/PhpParser/Builder/Namespace_.php +++ b/lib/PhpParser/Builder/Namespace_.php @@ -7,10 +7,10 @@ use PhpParser\Node; use PhpParser\Node\Stmt; -class Namespace_ extends Declaration -{ - private $name; - private $stmts = []; +class Namespace_ extends Declaration { + private ?Node\Name $name; + /** @var Stmt[] */ + private array $stmts = []; /** * Creates a namespace builder. @@ -39,7 +39,7 @@ public function addStmt($stmt) { * * @return Stmt\Namespace_ The built node */ - public function getNode() : Node { + public function getNode(): Node { return new Stmt\Namespace_($this->name, $this->stmts, $this->attributes); } } diff --git a/lib/PhpParser/Builder/Param.php b/lib/PhpParser/Builder/Param.php index c6491786e3..324a32b05f 100644 --- a/lib/PhpParser/Builder/Param.php +++ b/lib/PhpParser/Builder/Param.php @@ -4,20 +4,19 @@ use PhpParser; use PhpParser\BuilderHelpers; +use PhpParser\Modifiers; use PhpParser\Node; -class Param implements PhpParser\Builder -{ - protected $name; - - protected $default = null; - - /** @var Node\Identifier|Node\Name|Node\NullableType|null */ - protected $type = null; - - protected $byRef = false; - - protected $variadic = false; +class Param implements PhpParser\Builder { + protected string $name; + protected ?Node\Expr $default = null; + /** @var Node\Identifier|Node\Name|Node\ComplexType|null */ + protected ?Node $type = null; + protected bool $byRef = false; + protected int $flags = 0; + protected bool $variadic = false; + /** @var list */ + protected array $attributeGroups = []; /** * Creates a parameter builder. @@ -44,7 +43,7 @@ public function setDefault($value) { /** * Sets type for the parameter. * - * @param string|Node\Name|Node\NullableType|Node\UnionType $type Parameter type + * @param string|Node\Name|Node\Identifier|Node\ComplexType $type Parameter type * * @return $this The builder instance (for fluid interface) */ @@ -58,36 +57,102 @@ public function setType($type) { } /** - * Sets type for the parameter. + * Make the parameter accept the value by reference. * - * @param string|Node\Name|Node\NullableType|Node\UnionType $type Parameter type + * @return $this The builder instance (for fluid interface) + */ + public function makeByRef() { + $this->byRef = true; + + return $this; + } + + /** + * Make the parameter variadic * * @return $this The builder instance (for fluid interface) + */ + public function makeVariadic() { + $this->variadic = true; + + return $this; + } + + /** + * Makes the (promoted) parameter public. * - * @deprecated Use setType() instead + * @return $this The builder instance (for fluid interface) */ - public function setTypeHint($type) { - return $this->setType($type); + public function makePublic() { + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PUBLIC); + + return $this; } /** - * Make the parameter accept the value by reference. + * Makes the (promoted) parameter protected. * * @return $this The builder instance (for fluid interface) */ - public function makeByRef() { - $this->byRef = true; + public function makeProtected() { + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PROTECTED); return $this; } /** - * Make the parameter variadic + * Makes the (promoted) parameter private. * * @return $this The builder instance (for fluid interface) */ - public function makeVariadic() { - $this->variadic = true; + public function makePrivate() { + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PRIVATE); + + return $this; + } + + /** + * Makes the (promoted) parameter readonly. + * + * @return $this The builder instance (for fluid interface) + */ + public function makeReadonly() { + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::READONLY); + + return $this; + } + + /** + * Gives the promoted property private(set) visibility. + * + * @return $this The builder instance (for fluid interface) + */ + public function makePrivateSet() { + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PRIVATE_SET); + + return $this; + } + + /** + * Gives the promoted property protected(set) visibility. + * + * @return $this The builder instance (for fluid interface) + */ + public function makeProtectedSet() { + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PROTECTED_SET); + + return $this; + } + + /** + * Adds an attribute group. + * + * @param Node\Attribute|Node\AttributeGroup $attribute + * + * @return $this The builder instance (for fluid interface) + */ + public function addAttribute($attribute) { + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); return $this; } @@ -97,10 +162,10 @@ public function makeVariadic() { * * @return Node\Param The built parameter node */ - public function getNode() : Node { + public function getNode(): Node { return new Node\Param( new Node\Expr\Variable($this->name), - $this->default, $this->type, $this->byRef, $this->variadic + $this->default, $this->type, $this->byRef, $this->variadic, [], $this->flags, $this->attributeGroups ); } } diff --git a/lib/PhpParser/Builder/Property.php b/lib/PhpParser/Builder/Property.php index 1f3bdb2723..c80fe481bd 100644 --- a/lib/PhpParser/Builder/Property.php +++ b/lib/PhpParser/Builder/Property.php @@ -4,21 +4,27 @@ use PhpParser; use PhpParser\BuilderHelpers; +use PhpParser\Modifiers; +use PhpParser\Node; use PhpParser\Node\Identifier; use PhpParser\Node\Name; -use PhpParser\Node\NullableType; use PhpParser\Node\Stmt; +use PhpParser\Node\ComplexType; -class Property implements PhpParser\Builder -{ - protected $name; +class Property implements PhpParser\Builder { + protected string $name; - protected $flags = 0; - protected $default = null; - protected $attributes = []; + protected int $flags = 0; - /** @var null|Identifier|Name|NullableType */ - protected $type; + protected ?Node\Expr $default = null; + /** @var array */ + protected array $attributes = []; + /** @var null|Identifier|Name|ComplexType */ + protected ?Node $type = null; + /** @var list */ + protected array $attributeGroups = []; + /** @var list */ + protected array $hooks = []; /** * Creates a property builder. @@ -35,7 +41,7 @@ public function __construct(string $name) { * @return $this The builder instance (for fluid interface) */ public function makePublic() { - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PUBLIC); + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PUBLIC); return $this; } @@ -46,7 +52,7 @@ public function makePublic() { * @return $this The builder instance (for fluid interface) */ public function makeProtected() { - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PROTECTED); + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PROTECTED); return $this; } @@ -57,7 +63,7 @@ public function makeProtected() { * @return $this The builder instance (for fluid interface) */ public function makePrivate() { - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_PRIVATE); + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PRIVATE); return $this; } @@ -68,7 +74,62 @@ public function makePrivate() { * @return $this The builder instance (for fluid interface) */ public function makeStatic() { - $this->flags = BuilderHelpers::addModifier($this->flags, Stmt\Class_::MODIFIER_STATIC); + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::STATIC); + + return $this; + } + + /** + * Makes the property readonly. + * + * @return $this The builder instance (for fluid interface) + */ + public function makeReadonly() { + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::READONLY); + + return $this; + } + + /** + * Makes the property abstract. Requires at least one property hook to be specified as well. + * + * @return $this The builder instance (for fluid interface) + */ + public function makeAbstract() { + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::ABSTRACT); + + return $this; + } + + /** + * Makes the property final. + * + * @return $this The builder instance (for fluid interface) + */ + public function makeFinal() { + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::FINAL); + + return $this; + } + + /** + * Gives the property private(set) visibility. + * + * @return $this The builder instance (for fluid interface) + */ + public function makePrivateSet() { + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PRIVATE_SET); + + return $this; + } + + /** + * Gives the property protected(set) visibility. + * + * @return $this The builder instance (for fluid interface) + */ + public function makeProtectedSet() { + $this->flags = BuilderHelpers::addModifier($this->flags, Modifiers::PROTECTED_SET); return $this; } @@ -104,7 +165,7 @@ public function setDocComment($docComment) { /** * Sets the property type for PHP 7.4+. * - * @param string|Name|NullableType|Identifier $type + * @param string|Name|Identifier|ComplexType $type * * @return $this */ @@ -114,19 +175,49 @@ public function setType($type) { return $this; } + /** + * Adds an attribute group. + * + * @param Node\Attribute|Node\AttributeGroup $attribute + * + * @return $this The builder instance (for fluid interface) + */ + public function addAttribute($attribute) { + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); + + return $this; + } + + /** + * Adds a property hook. + * + * @return $this The builder instance (for fluid interface) + */ + public function addHook(Node\PropertyHook $hook) { + $this->hooks[] = $hook; + + return $this; + } + /** * Returns the built class node. * * @return Stmt\Property The built property node */ - public function getNode() : PhpParser\Node { + public function getNode(): PhpParser\Node { + if ($this->flags & Modifiers::ABSTRACT && !$this->hooks) { + throw new PhpParser\Error('Only hooked properties may be declared abstract'); + } + return new Stmt\Property( - $this->flags !== 0 ? $this->flags : Stmt\Class_::MODIFIER_PUBLIC, + $this->flags !== 0 ? $this->flags : Modifiers::PUBLIC, [ - new Stmt\PropertyProperty($this->name, $this->default) + new Node\PropertyItem($this->name, $this->default) ], $this->attributes, - $this->type + $this->type, + $this->attributeGroups, + $this->hooks ); } } diff --git a/lib/PhpParser/Builder/TraitUse.php b/lib/PhpParser/Builder/TraitUse.php index 311e8cd7b6..cf21c821ab 100644 --- a/lib/PhpParser/Builder/TraitUse.php +++ b/lib/PhpParser/Builder/TraitUse.php @@ -7,10 +7,11 @@ use PhpParser\Node; use PhpParser\Node\Stmt; -class TraitUse implements Builder -{ - protected $traits = []; - protected $adaptations = []; +class TraitUse implements Builder { + /** @var Node\Name[] */ + protected array $traits = []; + /** @var Stmt\TraitUseAdaptation[] */ + protected array $adaptations = []; /** * Creates a trait use builder. @@ -58,7 +59,7 @@ public function with($adaptation) { * * @return Node The built node */ - public function getNode() : Node { + public function getNode(): Node { return new Stmt\TraitUse($this->traits, $this->adaptations); } } diff --git a/lib/PhpParser/Builder/TraitUseAdaptation.php b/lib/PhpParser/Builder/TraitUseAdaptation.php index eb6c0b622d..fee09583a6 100644 --- a/lib/PhpParser/Builder/TraitUseAdaptation.php +++ b/lib/PhpParser/Builder/TraitUseAdaptation.php @@ -4,43 +4,40 @@ use PhpParser\Builder; use PhpParser\BuilderHelpers; +use PhpParser\Modifiers; use PhpParser\Node; use PhpParser\Node\Stmt; -class TraitUseAdaptation implements Builder -{ - const TYPE_UNDEFINED = 0; - const TYPE_ALIAS = 1; - const TYPE_PRECEDENCE = 2; +class TraitUseAdaptation implements Builder { + private const TYPE_UNDEFINED = 0; + private const TYPE_ALIAS = 1; + private const TYPE_PRECEDENCE = 2; - /** @var int Type of building adaptation */ - protected $type; - - protected $trait; - protected $method; - - protected $modifier = null; - protected $alias = null; - - protected $insteadof = []; + protected int $type; + protected ?Node\Name $trait; + protected Node\Identifier $method; + protected ?int $modifier = null; + protected ?Node\Identifier $alias = null; + /** @var Node\Name[] */ + protected array $insteadof = []; /** * Creates a trait use adaptation builder. * - * @param Node\Name|string|null $trait Name of adaptated trait - * @param Node\Identifier|string $method Name of adaptated method + * @param Node\Name|string|null $trait Name of adapted trait + * @param Node\Identifier|string $method Name of adapted method */ public function __construct($trait, $method) { $this->type = self::TYPE_UNDEFINED; - $this->trait = is_null($trait)? null: BuilderHelpers::normalizeName($trait); + $this->trait = is_null($trait) ? null : BuilderHelpers::normalizeName($trait); $this->method = BuilderHelpers::normalizeIdentifier($method); } /** * Sets alias of method. * - * @param Node\Identifier|string $alias Alias for adaptated method + * @param Node\Identifier|string $alias Alias for adapted method * * @return $this The builder instance (for fluid interface) */ @@ -53,37 +50,37 @@ public function as($alias) { throw new \LogicException('Cannot set alias for not alias adaptation buider'); } - $this->alias = $alias; + $this->alias = BuilderHelpers::normalizeIdentifier($alias); return $this; } /** - * Sets adaptated method public. + * Sets adapted method public. * * @return $this The builder instance (for fluid interface) */ public function makePublic() { - $this->setModifier(Stmt\Class_::MODIFIER_PUBLIC); + $this->setModifier(Modifiers::PUBLIC); return $this; } /** - * Sets adaptated method protected. + * Sets adapted method protected. * * @return $this The builder instance (for fluid interface) */ public function makeProtected() { - $this->setModifier(Stmt\Class_::MODIFIER_PROTECTED); + $this->setModifier(Modifiers::PROTECTED); return $this; } /** - * Sets adaptated method private. + * Sets adapted method private. * * @return $this The builder instance (for fluid interface) */ public function makePrivate() { - $this->setModifier(Stmt\Class_::MODIFIER_PRIVATE); + $this->setModifier(Modifiers::PRIVATE); return $this; } @@ -114,7 +111,7 @@ public function insteadof(...$traits) { return $this; } - protected function setModifier(int $modifier) { + protected function setModifier(int $modifier): void { if ($this->type === self::TYPE_UNDEFINED) { $this->type = self::TYPE_ALIAS; } @@ -135,7 +132,7 @@ protected function setModifier(int $modifier) { * * @return Node The built node */ - public function getNode() : Node { + public function getNode(): Node { switch ($this->type) { case self::TYPE_ALIAS: return new Stmt\TraitUseAdaptation\Alias($this->trait, $this->method, $this->modifier, $this->alias); diff --git a/lib/PhpParser/Builder/Trait_.php b/lib/PhpParser/Builder/Trait_.php index a836d40c60..ffa1bd5cca 100644 --- a/lib/PhpParser/Builder/Trait_.php +++ b/lib/PhpParser/Builder/Trait_.php @@ -4,14 +4,21 @@ use PhpParser; use PhpParser\BuilderHelpers; +use PhpParser\Node; use PhpParser\Node\Stmt; -class Trait_ extends Declaration -{ - protected $name; - protected $uses = []; - protected $properties = []; - protected $methods = []; +class Trait_ extends Declaration { + protected string $name; + /** @var list */ + protected array $uses = []; + /** @var list */ + protected array $constants = []; + /** @var list */ + protected array $properties = []; + /** @var list */ + protected array $methods = []; + /** @var list */ + protected array $attributeGroups = []; /** * Creates an interface builder. @@ -38,6 +45,8 @@ public function addStmt($stmt) { $this->methods[] = $stmt; } elseif ($stmt instanceof Stmt\TraitUse) { $this->uses[] = $stmt; + } elseif ($stmt instanceof Stmt\ClassConst) { + $this->constants[] = $stmt; } else { throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); } @@ -45,15 +54,29 @@ public function addStmt($stmt) { return $this; } + /** + * Adds an attribute group. + * + * @param Node\Attribute|Node\AttributeGroup $attribute + * + * @return $this The builder instance (for fluid interface) + */ + public function addAttribute($attribute) { + $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); + + return $this; + } + /** * Returns the built trait node. * * @return Stmt\Trait_ The built interface node */ - public function getNode() : PhpParser\Node { + public function getNode(): PhpParser\Node { return new Stmt\Trait_( $this->name, [ - 'stmts' => array_merge($this->uses, $this->properties, $this->methods) + 'stmts' => array_merge($this->uses, $this->constants, $this->properties, $this->methods), + 'attrGroups' => $this->attributeGroups, ], $this->attributes ); } diff --git a/lib/PhpParser/Builder/Use_.php b/lib/PhpParser/Builder/Use_.php index 4bd3d12df0..b82cf1396a 100644 --- a/lib/PhpParser/Builder/Use_.php +++ b/lib/PhpParser/Builder/Use_.php @@ -7,17 +7,17 @@ use PhpParser\Node; use PhpParser\Node\Stmt; -class Use_ implements Builder -{ - protected $name; - protected $type; - protected $alias = null; +class Use_ implements Builder { + protected Node\Name $name; + /** @var Stmt\Use_::TYPE_* */ + protected int $type; + protected ?string $alias = null; /** * Creates a name use (alias) builder. * * @param Node\Name|string $name Name of the entity (namespace, class, function, constant) to alias - * @param int $type One of the Stmt\Use_::TYPE_* constants + * @param Stmt\Use_::TYPE_* $type One of the Stmt\Use_::TYPE_* constants */ public function __construct($name, int $type) { $this->name = BuilderHelpers::normalizeName($name); @@ -41,9 +41,9 @@ public function as(string $alias) { * * @return Stmt\Use_ The built node */ - public function getNode() : Node { + public function getNode(): Node { return new Stmt\Use_([ - new Stmt\UseUse($this->name, $this->alias) + new Node\UseItem($this->name, $this->alias) ], $this->type); } } diff --git a/lib/PhpParser/BuilderFactory.php b/lib/PhpParser/BuilderFactory.php index cc8c48bd9e..07642f92fa 100644 --- a/lib/PhpParser/BuilderFactory.php +++ b/lib/PhpParser/BuilderFactory.php @@ -10,8 +10,20 @@ use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\Use_; -class BuilderFactory -{ +class BuilderFactory { + /** + * Creates an attribute node. + * + * @param string|Name $name Name of the attribute + * @param array $args Attribute named arguments + */ + public function attribute($name, array $args = []): Node\Attribute { + return new Node\Attribute( + BuilderHelpers::normalizeName($name), + $this->args($args) + ); + } + /** * Creates a namespace builder. * @@ -19,7 +31,7 @@ class BuilderFactory * * @return Builder\Namespace_ The created namespace builder */ - public function namespace($name) : Builder\Namespace_ { + public function namespace($name): Builder\Namespace_ { return new Builder\Namespace_($name); } @@ -30,7 +42,7 @@ public function namespace($name) : Builder\Namespace_ { * * @return Builder\Class_ The created class builder */ - public function class(string $name) : Builder\Class_ { + public function class(string $name): Builder\Class_ { return new Builder\Class_($name); } @@ -41,7 +53,7 @@ public function class(string $name) : Builder\Class_ { * * @return Builder\Interface_ The created interface builder */ - public function interface(string $name) : Builder\Interface_ { + public function interface(string $name): Builder\Interface_ { return new Builder\Interface_($name); } @@ -52,30 +64,41 @@ public function interface(string $name) : Builder\Interface_ { * * @return Builder\Trait_ The created trait builder */ - public function trait(string $name) : Builder\Trait_ { + public function trait(string $name): Builder\Trait_ { return new Builder\Trait_($name); } + /** + * Creates an enum builder. + * + * @param string $name Name of the enum + * + * @return Builder\Enum_ The created enum builder + */ + public function enum(string $name): Builder\Enum_ { + return new Builder\Enum_($name); + } + /** * Creates a trait use builder. * * @param Node\Name|string ...$traits Trait names * - * @return Builder\TraitUse The create trait use builder + * @return Builder\TraitUse The created trait use builder */ - public function useTrait(...$traits) : Builder\TraitUse { + public function useTrait(...$traits): Builder\TraitUse { return new Builder\TraitUse(...$traits); } /** * Creates a trait use adaptation builder. * - * @param Node\Name|string|null $trait Trait name + * @param Node\Name|string|null $trait Trait name * @param Node\Identifier|string $method Method name * - * @return Builder\TraitUseAdaptation The create trait use adaptation builder + * @return Builder\TraitUseAdaptation The created trait use adaptation builder */ - public function traitUseAdaptation($trait, $method = null) : Builder\TraitUseAdaptation { + public function traitUseAdaptation($trait, $method = null): Builder\TraitUseAdaptation { if ($method === null) { $method = $trait; $trait = null; @@ -91,7 +114,7 @@ public function traitUseAdaptation($trait, $method = null) : Builder\TraitUseAda * * @return Builder\Method The created method builder */ - public function method(string $name) : Builder\Method { + public function method(string $name): Builder\Method { return new Builder\Method($name); } @@ -102,7 +125,7 @@ public function method(string $name) : Builder\Method { * * @return Builder\Param The created parameter builder */ - public function param(string $name) : Builder\Param { + public function param(string $name): Builder\Param { return new Builder\Param($name); } @@ -113,7 +136,7 @@ public function param(string $name) : Builder\Param { * * @return Builder\Property The created property builder */ - public function property(string $name) : Builder\Property { + public function property(string $name): Builder\Property { return new Builder\Property($name); } @@ -124,7 +147,7 @@ public function property(string $name) : Builder\Property { * * @return Builder\Function_ The created function builder */ - public function function(string $name) : Builder\Function_ { + public function function(string $name): Builder\Function_ { return new Builder\Function_($name); } @@ -135,7 +158,7 @@ public function function(string $name) : Builder\Function_ { * * @return Builder\Use_ The created use builder */ - public function use($name) : Builder\Use_ { + public function use($name): Builder\Use_ { return new Builder\Use_($name, Use_::TYPE_NORMAL); } @@ -146,7 +169,7 @@ public function use($name) : Builder\Use_ { * * @return Builder\Use_ The created use function builder */ - public function useFunction($name) : Builder\Use_ { + public function useFunction($name): Builder\Use_ { return new Builder\Use_($name, Use_::TYPE_FUNCTION); } @@ -157,30 +180,39 @@ public function useFunction($name) : Builder\Use_ { * * @return Builder\Use_ The created use const builder */ - public function useConst($name) : Builder\Use_ { + public function useConst($name): Builder\Use_ { return new Builder\Use_($name, Use_::TYPE_CONSTANT); } /** * Creates a class constant builder. * - * @param string|Identifier $name Name + * @param string|Identifier $name Name * @param Node\Expr|bool|null|int|float|string|array $value Value * * @return Builder\ClassConst The created use const builder */ - public function classConst($name, $value) : Builder\ClassConst { + public function classConst($name, $value): Builder\ClassConst { return new Builder\ClassConst($name, $value); } /** - * Creates node a for a literal value. + * Creates an enum case builder. + * + * @param string|Identifier $name Name * - * @param Expr|bool|null|int|float|string|array $value $value + * @return Builder\EnumCase The created use const builder + */ + public function enumCase($name): Builder\EnumCase { + return new Builder\EnumCase($name); + } + + /** + * Creates node a for a literal value. * - * @return Expr + * @param Expr|bool|null|int|float|string|array|\UnitEnum $value $value */ - public function val($value) : Expr { + public function val($value): Expr { return BuilderHelpers::normalizeValue($value); } @@ -188,10 +220,8 @@ public function val($value) : Expr { * Creates variable node. * * @param string|Expr $name Name - * - * @return Expr\Variable */ - public function var($name) : Expr\Variable { + public function var($name): Expr\Variable { if (!\is_string($name) && !$name instanceof Expr) { throw new \LogicException('Variable name must be string or Expr'); } @@ -206,16 +236,18 @@ public function var($name) : Expr\Variable { * * @param array $args List of arguments to normalize * - * @return Arg[] + * @return list */ - public function args(array $args) : array { + public function args(array $args): array { $normalizedArgs = []; - foreach ($args as $arg) { - if ($arg instanceof Arg) { - $normalizedArgs[] = $arg; - } else { - $normalizedArgs[] = new Arg(BuilderHelpers::normalizeValue($arg)); + foreach ($args as $key => $arg) { + if (!($arg instanceof Arg)) { + $arg = new Arg(BuilderHelpers::normalizeValue($arg)); + } + if (\is_string($key)) { + $arg->name = BuilderHelpers::normalizeIdentifier($key); } + $normalizedArgs[] = $arg; } return $normalizedArgs; } @@ -224,11 +256,9 @@ public function args(array $args) : array { * Creates a function call node. * * @param string|Name|Expr $name Function name - * @param array $args Function arguments - * - * @return Expr\FuncCall + * @param array $args Function arguments */ - public function funcCall($name, array $args = []) : Expr\FuncCall { + public function funcCall($name, array $args = []): Expr\FuncCall { return new Expr\FuncCall( BuilderHelpers::normalizeNameOrExpr($name), $this->args($args) @@ -238,13 +268,11 @@ public function funcCall($name, array $args = []) : Expr\FuncCall { /** * Creates a method call node. * - * @param Expr $var Variable the method is called on + * @param Expr $var Variable the method is called on * @param string|Identifier|Expr $name Method name - * @param array $args Method arguments - * - * @return Expr\MethodCall + * @param array $args Method arguments */ - public function methodCall(Expr $var, $name, array $args = []) : Expr\MethodCall { + public function methodCall(Expr $var, $name, array $args = []): Expr\MethodCall { return new Expr\MethodCall( $var, BuilderHelpers::normalizeIdentifierOrExpr($name), @@ -255,13 +283,11 @@ public function methodCall(Expr $var, $name, array $args = []) : Expr\MethodCall /** * Creates a static method call node. * - * @param string|Name|Expr $class Class name - * @param string|Identifier|Expr $name Method name - * @param array $args Method arguments - * - * @return Expr\StaticCall + * @param string|Name|Expr $class Class name + * @param string|Identifier|Expr $name Method name + * @param array $args Method arguments */ - public function staticCall($class, $name, array $args = []) : Expr\StaticCall { + public function staticCall($class, $name, array $args = []): Expr\StaticCall { return new Expr\StaticCall( BuilderHelpers::normalizeNameOrExpr($class), BuilderHelpers::normalizeIdentifierOrExpr($name), @@ -273,11 +299,9 @@ public function staticCall($class, $name, array $args = []) : Expr\StaticCall { * Creates an object creation node. * * @param string|Name|Expr $class Class name - * @param array $args Constructor arguments - * - * @return Expr\New_ + * @param array $args Constructor arguments */ - public function new($class, array $args = []) : Expr\New_ { + public function new($class, array $args = []): Expr\New_ { return new Expr\New_( BuilderHelpers::normalizeNameOrExpr($class), $this->args($args) @@ -288,37 +312,31 @@ public function new($class, array $args = []) : Expr\New_ { * Creates a constant fetch node. * * @param string|Name $name Constant name - * - * @return Expr\ConstFetch */ - public function constFetch($name) : Expr\ConstFetch { + public function constFetch($name): Expr\ConstFetch { return new Expr\ConstFetch(BuilderHelpers::normalizeName($name)); } - + /** * Creates a property fetch node. * - * @param Expr $var Variable holding object + * @param Expr $var Variable holding object * @param string|Identifier|Expr $name Property name - * - * @return Expr\PropertyFetch */ - public function propertyFetch(Expr $var, $name) : Expr\PropertyFetch { + public function propertyFetch(Expr $var, $name): Expr\PropertyFetch { return new Expr\PropertyFetch($var, BuilderHelpers::normalizeIdentifierOrExpr($name)); } /** * Creates a class constant fetch node. * - * @param string|Name|Expr $class Class name - * @param string|Identifier $name Constant name - * - * @return Expr\ClassConstFetch + * @param string|Name|Expr $class Class name + * @param string|Identifier|Expr $name Constant name */ public function classConstFetch($class, $name): Expr\ClassConstFetch { return new Expr\ClassConstFetch( BuilderHelpers::normalizeNameOrExpr($class), - BuilderHelpers::normalizeIdentifier($name) + BuilderHelpers::normalizeIdentifierOrExpr($name) ); } @@ -326,10 +344,8 @@ public function classConstFetch($class, $name): Expr\ClassConstFetch { * Creates nested Concat nodes from a list of expressions. * * @param Expr|string ...$exprs Expressions or literal strings - * - * @return Concat */ - public function concat(...$exprs) : Concat { + public function concat(...$exprs): Concat { $numExprs = count($exprs); if ($numExprs < 2) { throw new \LogicException('Expected at least two expressions'); @@ -344,9 +360,8 @@ public function concat(...$exprs) : Concat { /** * @param string|Expr $expr - * @return Expr */ - private function normalizeStringExpr($expr) : Expr { + private function normalizeStringExpr($expr): Expr { if ($expr instanceof Expr) { return $expr; } diff --git a/lib/PhpParser/BuilderHelpers.php b/lib/PhpParser/BuilderHelpers.php index 180bf35d0e..f29a69153d 100644 --- a/lib/PhpParser/BuilderHelpers.php +++ b/lib/PhpParser/BuilderHelpers.php @@ -2,21 +2,21 @@ namespace PhpParser; +use PhpParser\Node\ComplexType; use PhpParser\Node\Expr; use PhpParser\Node\Identifier; use PhpParser\Node\Name; +use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\NullableType; use PhpParser\Node\Scalar; use PhpParser\Node\Stmt; -use PhpParser\Node\UnionType; /** * This class defines helpers used in the implementation of builders. Don't use it directly. * * @internal */ -final class BuilderHelpers -{ +final class BuilderHelpers { /** * Normalizes a node: Converts builder objects to nodes. * @@ -24,10 +24,12 @@ final class BuilderHelpers * * @return Node The normalized node */ - public static function normalizeNode($node) : Node { + public static function normalizeNode($node): Node { if ($node instanceof Builder) { return $node->getNode(); - } elseif ($node instanceof Node) { + } + + if ($node instanceof Node) { return $node; } @@ -43,7 +45,7 @@ public static function normalizeNode($node) : Node { * * @return Stmt The normalized statement node */ - public static function normalizeStmt($node) : Stmt { + public static function normalizeStmt($node): Stmt { $node = self::normalizeNode($node); if ($node instanceof Stmt) { return $node; @@ -63,7 +65,7 @@ public static function normalizeStmt($node) : Stmt { * * @return Identifier The normalized identifier */ - public static function normalizeIdentifier($name) : Identifier { + public static function normalizeIdentifier($name): Identifier { if ($name instanceof Identifier) { return $name; } @@ -101,8 +103,28 @@ public static function normalizeIdentifierOrExpr($name) { * * @return Name The normalized name */ - public static function normalizeName($name) : Name { - return self::normalizeNameCommon($name, false); + public static function normalizeName($name): Name { + if ($name instanceof Name) { + return $name; + } + + if (is_string($name)) { + if (!$name) { + throw new \LogicException('Name cannot be empty'); + } + + if ($name[0] === '\\') { + return new Name\FullyQualified(substr($name, 1)); + } + + if (0 === strpos($name, 'namespace\\')) { + return new Name\Relative(substr($name, strlen('namespace\\'))); + } + + return new Name($name); + } + + throw new \LogicException('Name must be a string or an instance of Node\Name'); } /** @@ -113,44 +135,17 @@ public static function normalizeName($name) : Name { * @return Name|Expr The normalized name or expression */ public static function normalizeNameOrExpr($name) { - return self::normalizeNameCommon($name, true); - } - - /** - * Normalizes a name: Converts string names to Name nodes, optionally allowing expressions. - * - * @param Expr|Name|string $name The name to normalize - * @param bool $allowExpr Whether to also allow expressions - * - * @return Name|Expr The normalized name, or expression (if allowed) - */ - private static function normalizeNameCommon($name, bool $allowExpr) { - if ($name instanceof Name) { + if ($name instanceof Expr) { return $name; - } elseif (is_string($name)) { - if (!$name) { - throw new \LogicException('Name cannot be empty'); - } - - if ($name[0] === '\\') { - return new Name\FullyQualified(substr($name, 1)); - } elseif (0 === strpos($name, 'namespace\\')) { - return new Name\Relative(substr($name, strlen('namespace\\'))); - } else { - return new Name($name); - } } - if ($allowExpr) { - if ($name instanceof Expr) { - return $name; - } + if (!is_string($name) && !($name instanceof Name)) { throw new \LogicException( 'Name must be a string or an instance of Node\Name or Node\Expr' ); - } else { - throw new \LogicException('Name must be a string or an instance of Node\Name'); } + + return self::normalizeName($name); } /** @@ -159,18 +154,18 @@ private static function normalizeNameCommon($name, bool $allowExpr) { * In particular, builtin types become Identifiers, custom types become Names and nullables * are wrapped in NullableType nodes. * - * @param string|Name|Identifier|NullableType|UnionType $type The type to normalize + * @param string|Name|Identifier|ComplexType $type The type to normalize * - * @return Name|Identifier|NullableType|UnionType The normalized type + * @return Name|Identifier|ComplexType The normalized type */ public static function normalizeType($type) { if (!is_string($type)) { if ( !$type instanceof Name && !$type instanceof Identifier && - !$type instanceof NullableType && !$type instanceof UnionType + !$type instanceof ComplexType ) { throw new \LogicException( - 'Type must be a string, or an instance of Name, Identifier, NullableType or UnionType' + 'Type must be a string, or an instance of Name, Identifier or ComplexType' ); } return $type; @@ -183,7 +178,20 @@ public static function normalizeType($type) { } $builtinTypes = [ - 'array', 'callable', 'string', 'int', 'float', 'bool', 'iterable', 'void', 'object', 'mixed' + 'array', + 'callable', + 'bool', + 'int', + 'float', + 'string', + 'iterable', + 'void', + 'object', + 'null', + 'false', + 'mixed', + 'never', + 'true', ]; $lowerType = strtolower($type); @@ -193,12 +201,11 @@ public static function normalizeType($type) { $type = self::normalizeName($type); } - if ($nullable && (string) $type === 'void') { - throw new \LogicException('void type cannot be nullable'); - } - - if ($nullable && (string) $type === 'mixed') { - throw new \LogicException('mixed type cannot be nullable'); + $notNullableTypes = [ + 'void', 'mixed', 'never', + ]; + if ($nullable && in_array((string) $type, $notNullableTypes)) { + throw new \LogicException(sprintf('%s type cannot be nullable', $type)); } return $nullable ? new NullableType($type) : $type; @@ -208,39 +215,51 @@ public static function normalizeType($type) { * Normalizes a value: Converts nulls, booleans, integers, * floats, strings and arrays into their respective nodes * - * @param Node\Expr|bool|null|int|float|string|array $value The value to normalize + * @param Node\Expr|bool|null|int|float|string|array|\UnitEnum $value The value to normalize * * @return Expr The normalized value */ - public static function normalizeValue($value) : Expr { + public static function normalizeValue($value): Expr { if ($value instanceof Node\Expr) { return $value; - } elseif (is_null($value)) { + } + + if (is_null($value)) { return new Expr\ConstFetch( new Name('null') ); - } elseif (is_bool($value)) { + } + + if (is_bool($value)) { return new Expr\ConstFetch( new Name($value ? 'true' : 'false') ); - } elseif (is_int($value)) { - return new Scalar\LNumber($value); - } elseif (is_float($value)) { - return new Scalar\DNumber($value); - } elseif (is_string($value)) { + } + + if (is_int($value)) { + return new Scalar\Int_($value); + } + + if (is_float($value)) { + return new Scalar\Float_($value); + } + + if (is_string($value)) { return new Scalar\String_($value); - } elseif (is_array($value)) { + } + + if (is_array($value)) { $items = []; $lastKey = -1; foreach ($value as $itemKey => $itemValue) { // for consecutive, numeric keys don't generate keys if (null !== $lastKey && ++$lastKey === $itemKey) { - $items[] = new Expr\ArrayItem( + $items[] = new Node\ArrayItem( self::normalizeValue($itemValue) ); } else { $lastKey = null; - $items[] = new Expr\ArrayItem( + $items[] = new Node\ArrayItem( self::normalizeValue($itemValue), self::normalizeValue($itemKey) ); @@ -248,9 +267,13 @@ public static function normalizeValue($value) : Expr { } return new Expr\Array_($items); - } else { - throw new \LogicException('Invalid value'); } + + if ($value instanceof \UnitEnum) { + return new Expr\ClassConstFetch(new FullyQualified(\get_class($value)), new Identifier($value->name)); + } + + throw new \LogicException('Invalid value'); } /** @@ -260,26 +283,56 @@ public static function normalizeValue($value) : Expr { * * @return Comment\Doc The normalized doc comment */ - public static function normalizeDocComment($docComment) : Comment\Doc { + public static function normalizeDocComment($docComment): Comment\Doc { if ($docComment instanceof Comment\Doc) { return $docComment; - } elseif (is_string($docComment)) { + } + + if (is_string($docComment)) { return new Comment\Doc($docComment); - } else { - throw new \LogicException('Doc comment must be a string or an instance of PhpParser\Comment\Doc'); } + + throw new \LogicException('Doc comment must be a string or an instance of PhpParser\Comment\Doc'); + } + + /** + * Normalizes a attribute: Converts attribute to the Attribute Group if needed. + * + * @param Node\Attribute|Node\AttributeGroup $attribute + * + * @return Node\AttributeGroup The Attribute Group + */ + public static function normalizeAttribute($attribute): Node\AttributeGroup { + if ($attribute instanceof Node\AttributeGroup) { + return $attribute; + } + + if (!($attribute instanceof Node\Attribute)) { + throw new \LogicException('Attribute must be an instance of PhpParser\Node\Attribute or PhpParser\Node\AttributeGroup'); + } + + return new Node\AttributeGroup([$attribute]); } /** * Adds a modifier and returns new modifier bitmask. * * @param int $modifiers Existing modifiers - * @param int $modifier Modifier to set + * @param int $modifier Modifier to set * * @return int New modifiers */ - public static function addModifier(int $modifiers, int $modifier) : int { - Stmt\Class_::verifyModifier($modifiers, $modifier); + public static function addModifier(int $modifiers, int $modifier): int { + Modifiers::verifyModifier($modifiers, $modifier); return $modifiers | $modifier; } + + /** + * Adds a modifier and returns new modifier bitmask. + * @return int New modifiers + */ + public static function addClassModifier(int $existingModifiers, int $modifierToSet): int { + Modifiers::verifyClassModifier($existingModifiers, $modifierToSet); + return $existingModifiers | $modifierToSet; + } } diff --git a/lib/PhpParser/Comment.php b/lib/PhpParser/Comment.php index 61e98d3dca..01b341e438 100644 --- a/lib/PhpParser/Comment.php +++ b/lib/PhpParser/Comment.php @@ -2,23 +2,22 @@ namespace PhpParser; -class Comment implements \JsonSerializable -{ - protected $text; - protected $startLine; - protected $startFilePos; - protected $startTokenPos; - protected $endLine; - protected $endFilePos; - protected $endTokenPos; +class Comment implements \JsonSerializable { + protected string $text; + protected int $startLine; + protected int $startFilePos; + protected int $startTokenPos; + protected int $endLine; + protected int $endFilePos; + protected int $endTokenPos; /** * Constructs a comment node. * - * @param string $text Comment text (including comment delimiters like /*) - * @param int $startLine Line number the comment started on - * @param int $startFilePos File offset the comment started on - * @param int $startTokenPos Token offset the comment started on + * @param string $text Comment text (including comment delimiters like /*) + * @param int $startLine Line number the comment started on + * @param int $startFilePos File offset the comment started on + * @param int $startTokenPos Token offset the comment started on */ public function __construct( string $text, @@ -39,7 +38,7 @@ public function __construct( * * @return string The comment text (including comment delimiters like /*) */ - public function getText() : string { + public function getText(): string { return $this->text; } @@ -47,8 +46,9 @@ public function getText() : string { * Gets the line number the comment started on. * * @return int Line number (or -1 if not available) + * @phpstan-return -1|positive-int */ - public function getStartLine() : int { + public function getStartLine(): int { return $this->startLine; } @@ -57,7 +57,7 @@ public function getStartLine() : int { * * @return int File offset (or -1 if not available) */ - public function getStartFilePos() : int { + public function getStartFilePos(): int { return $this->startFilePos; } @@ -66,7 +66,7 @@ public function getStartFilePos() : int { * * @return int Token offset (or -1 if not available) */ - public function getStartTokenPos() : int { + public function getStartTokenPos(): int { return $this->startTokenPos; } @@ -74,8 +74,9 @@ public function getStartTokenPos() : int { * Gets the line number the comment ends on. * * @return int Line number (or -1 if not available) + * @phpstan-return -1|positive-int */ - public function getEndLine() : int { + public function getEndLine(): int { return $this->endLine; } @@ -84,7 +85,7 @@ public function getEndLine() : int { * * @return int File offset (or -1 if not available) */ - public function getEndFilePos() : int { + public function getEndFilePos(): int { return $this->endFilePos; } @@ -93,49 +94,16 @@ public function getEndFilePos() : int { * * @return int Token offset (or -1 if not available) */ - public function getEndTokenPos() : int { + public function getEndTokenPos(): int { return $this->endTokenPos; } - /** - * Gets the line number the comment started on. - * - * @deprecated Use getStartLine() instead - * - * @return int Line number - */ - public function getLine() : int { - return $this->startLine; - } - - /** - * Gets the file offset the comment started on. - * - * @deprecated Use getStartFilePos() instead - * - * @return int File offset - */ - public function getFilePos() : int { - return $this->startFilePos; - } - - /** - * Gets the token offset the comment started on. - * - * @deprecated Use getStartTokenPos() instead - * - * @return int Token offset - */ - public function getTokenPos() : int { - return $this->startTokenPos; - } - /** * Gets the comment text. * * @return string The comment text (including comment delimiters like /*) */ - public function __toString() : string { + public function __toString(): string { return $this->text; } @@ -144,18 +112,19 @@ public function __toString() : string { * * "Reformatted" here means that we try to clean up the whitespace at the * starts of the lines. This is necessary because we receive the comments - * without trailing whitespace on the first line, but with trailing whitespace + * without leading whitespace on the first line, but with leading whitespace * on all subsequent lines. * - * @return mixed|string + * Additionally, this normalizes CRLF newlines to LF newlines. */ - public function getReformattedText() { - $text = trim($this->text); + public function getReformattedText(): string { + $text = str_replace("\r\n", "\n", $this->text); $newlinePos = strpos($text, "\n"); if (false === $newlinePos) { // Single line comments don't need further processing return $text; - } elseif (preg_match('((*BSR_ANYCRLF)(*ANYCRLF)^.*(?:\R\s+\*.*)+$)', $text)) { + } + if (preg_match('(^.*(?:\n\s+\*.*)+$)', $text)) { // Multi line comment of the type // // /* @@ -164,8 +133,9 @@ public function getReformattedText() { // */ // // is handled by replacing the whitespace sequences before the * by a single space - return preg_replace('(^\s+\*)m', ' *', $this->text); - } elseif (preg_match('(^/\*\*?\s*[\r\n])', $text) && preg_match('(\n(\s*)\*/$)', $text, $matches)) { + return preg_replace('(^\s+\*)m', ' *', $text); + } + if (preg_match('(^/\*\*?\s*\n)', $text) && preg_match('(\n(\s*)\*/$)', $text, $matches)) { // Multi line comment of the type // // /* @@ -177,7 +147,8 @@ public function getReformattedText() { // */ on all lines. So if the last line is " */", then " " is removed at the // start of all lines. return preg_replace('(^' . preg_quote($matches[1]) . ')m', '', $text); - } elseif (preg_match('(^/\*\*?\s*(?!\s))', $text, $matches)) { + } + if (preg_match('(^/\*\*?\s*(?!\s))', $text, $matches)) { // Multi line comment of the type // // /* Some text. @@ -204,9 +175,9 @@ public function getReformattedText() { * @param string $str String to check * @return int Length in characters. Tabs count as single characters. */ - private function getShortestWhitespacePrefixLen(string $str) : int { + private function getShortestWhitespacePrefixLen(string $str): int { $lines = explode("\n", $str); - $shortestPrefixLen = \INF; + $shortestPrefixLen = \PHP_INT_MAX; foreach ($lines as $line) { preg_match('(^\s*)', $line, $matches); $prefixLen = strlen($matches[0]); @@ -218,10 +189,9 @@ private function getShortestWhitespacePrefixLen(string $str) : int { } /** - * @return array - * @psalm-return array{nodeType:string, text:mixed, line:mixed, filePos:mixed} + * @return array{nodeType:string, text:mixed, line:mixed, filePos:mixed} */ - public function jsonSerialize() : array { + public function jsonSerialize(): array { // Technically not a node, but we make it look like one anyway $type = $this instanceof Comment\Doc ? 'Comment_Doc' : 'Comment'; return [ diff --git a/lib/PhpParser/Comment/Doc.php b/lib/PhpParser/Comment/Doc.php index a9db6128f4..bb3e9146af 100644 --- a/lib/PhpParser/Comment/Doc.php +++ b/lib/PhpParser/Comment/Doc.php @@ -2,6 +2,5 @@ namespace PhpParser\Comment; -class Doc extends \PhpParser\Comment -{ +class Doc extends \PhpParser\Comment { } diff --git a/lib/PhpParser/ConstExprEvaluationException.php b/lib/PhpParser/ConstExprEvaluationException.php index 49c92d5950..7964058a6e 100644 --- a/lib/PhpParser/ConstExprEvaluationException.php +++ b/lib/PhpParser/ConstExprEvaluationException.php @@ -1,6 +1,6 @@ -fallbackEvaluator = $fallbackEvaluator ?? function(Expr $expr) { + public function __construct(?callable $fallbackEvaluator = null) { + $this->fallbackEvaluator = $fallbackEvaluator ?? function (Expr $expr) { throw new ConstExprEvaluationException( "Expression of type {$expr->getType()} cannot be evaluated" ); @@ -62,7 +64,7 @@ public function __construct(callable $fallbackEvaluator = null) { * @throws ConstExprEvaluationException if the expression cannot be evaluated or an error occurred */ public function evaluateSilently(Expr $expr) { - set_error_handler(function($num, $str, $file, $line) { + set_error_handler(function ($num, $str, $file, $line) { throw new \ErrorException($str, 0, $num, $file, $line); }); @@ -100,9 +102,10 @@ public function evaluateDirectly(Expr $expr) { return $this->evaluate($expr); } + /** @return mixed */ private function evaluate(Expr $expr) { - if ($expr instanceof Scalar\LNumber - || $expr instanceof Scalar\DNumber + if ($expr instanceof Scalar\Int_ + || $expr instanceof Scalar\Float_ || $expr instanceof Scalar\String_ ) { return $expr->value; @@ -145,11 +148,13 @@ private function evaluate(Expr $expr) { return ($this->fallbackEvaluator)($expr); } - private function evaluateArray(Expr\Array_ $expr) { + private function evaluateArray(Expr\Array_ $expr): array { $array = []; foreach ($expr->items as $item) { if (null !== $item->key) { $array[$this->evaluate($item->key)] = $this->evaluate($item->value); + } elseif ($item->unpack) { + $array = array_merge($array, $this->evaluate($item->value)); } else { $array[] = $this->evaluate($item->value); } @@ -157,6 +162,7 @@ private function evaluateArray(Expr\Array_ $expr) { return $array; } + /** @return mixed */ private function evaluateTernary(Expr\Ternary $expr) { if (null === $expr->if) { return $this->evaluate($expr->cond) ?: $this->evaluate($expr->else); @@ -167,6 +173,7 @@ private function evaluateTernary(Expr\Ternary $expr) { : $this->evaluate($expr->else); } + /** @return mixed */ private function evaluateBinaryOp(Expr\BinaryOp $expr) { if ($expr instanceof Expr\BinaryOp\Coalesce && $expr->left instanceof Expr\ArrayDimFetch @@ -208,11 +215,15 @@ private function evaluateBinaryOp(Expr\BinaryOp $expr) { case '<': return $this->evaluate($l) < $this->evaluate($r); case '<=': return $this->evaluate($l) <= $this->evaluate($r); case '<=>': return $this->evaluate($l) <=> $this->evaluate($r); + case '|>': + $lval = $this->evaluate($l); + return $this->evaluate($r)($lval); } throw new \Exception('Should not happen'); } + /** @return mixed */ private function evaluateConstFetch(Expr\ConstFetch $expr) { $name = $expr->name->toLowerString(); switch ($name) { diff --git a/lib/PhpParser/Error.php b/lib/PhpParser/Error.php index d1fb959d19..f81f0c4202 100644 --- a/lib/PhpParser/Error.php +++ b/lib/PhpParser/Error.php @@ -2,25 +2,20 @@ namespace PhpParser; -class Error extends \RuntimeException -{ - protected $rawMessage; - protected $attributes; +class Error extends \RuntimeException { + protected string $rawMessage; + /** @var array */ + protected array $attributes; /** * Creates an Exception signifying a parse error. * - * @param string $message Error message - * @param array|int $attributes Attributes of node/token where error occurred - * (or start line of error -- deprecated) + * @param string $message Error message + * @param array $attributes Attributes of node/token where error occurred */ - public function __construct(string $message, $attributes = []) { + public function __construct(string $message, array $attributes = []) { $this->rawMessage = $message; - if (is_array($attributes)) { - $this->attributes = $attributes; - } else { - $this->attributes = ['startLine' => $attributes]; - } + $this->attributes = $attributes; $this->updateMessage(); } @@ -29,7 +24,7 @@ public function __construct(string $message, $attributes = []) { * * @return string Error message */ - public function getRawMessage() : string { + public function getRawMessage(): string { return $this->rawMessage; } @@ -37,8 +32,9 @@ public function getRawMessage() : string { * Gets the line the error starts in. * * @return int Error start line + * @phpstan-return -1|positive-int */ - public function getStartLine() : int { + public function getStartLine(): int { return $this->attributes['startLine'] ?? -1; } @@ -46,26 +42,27 @@ public function getStartLine() : int { * Gets the line the error ends in. * * @return int Error end line + * @phpstan-return -1|positive-int */ - public function getEndLine() : int { + public function getEndLine(): int { return $this->attributes['endLine'] ?? -1; } /** * Gets the attributes of the node/token the error occurred at. * - * @return array + * @return array */ - public function getAttributes() : array { + public function getAttributes(): array { return $this->attributes; } /** * Sets the attributes of the node/token the error occurred at. * - * @param array $attributes + * @param array $attributes */ - public function setAttributes(array $attributes) { + public function setAttributes(array $attributes): void { $this->attributes = $attributes; $this->updateMessage(); } @@ -75,7 +72,7 @@ public function setAttributes(array $attributes) { * * @param string $message Error message */ - public function setRawMessage(string $message) { + public function setRawMessage(string $message): void { $this->rawMessage = $message; $this->updateMessage(); } @@ -85,7 +82,7 @@ public function setRawMessage(string $message) { * * @param int $line Error start line */ - public function setStartLine(int $line) { + public function setStartLine(int $line): void { $this->attributes['startLine'] = $line; $this->updateMessage(); } @@ -94,10 +91,8 @@ public function setStartLine(int $line) { * Returns whether the error has start and end column information. * * For column information enable the startFilePos and endFilePos in the lexer options. - * - * @return bool */ - public function hasColumnInfo() : bool { + public function hasColumnInfo(): bool { return isset($this->attributes['startFilePos'], $this->attributes['endFilePos']); } @@ -105,9 +100,8 @@ public function hasColumnInfo() : bool { * Gets the start column (1-based) into the line where the error started. * * @param string $code Source code of the file - * @return int */ - public function getStartColumn(string $code) : int { + public function getStartColumn(string $code): int { if (!$this->hasColumnInfo()) { throw new \RuntimeException('Error does not have column information'); } @@ -119,9 +113,8 @@ public function getStartColumn(string $code) : int { * Gets the end column (1-based) into the line where the error ended. * * @param string $code Source code of the file - * @return int */ - public function getEndColumn(string $code) : int { + public function getEndColumn(string $code): int { if (!$this->hasColumnInfo()) { throw new \RuntimeException('Error does not have column information'); } @@ -136,7 +129,7 @@ public function getEndColumn(string $code) : int { * * @return string Formatted message */ - public function getMessageWithColumnInfo(string $code) : string { + public function getMessageWithColumnInfo(string $code): string { return sprintf( '%s from %d:%d to %d:%d', $this->getRawMessage(), $this->getStartLine(), $this->getStartColumn($code), @@ -148,11 +141,11 @@ public function getMessageWithColumnInfo(string $code) : string { * Converts a file offset into a column. * * @param string $code Source code that $pos indexes into - * @param int $pos 0-based position in $code + * @param int $pos 0-based position in $code * * @return int 1-based column (relative to start of line) */ - private function toColumn(string $code, int $pos) : int { + private function toColumn(string $code, int $pos): int { if ($pos > strlen($code)) { throw new \RuntimeException('Invalid position information'); } @@ -168,7 +161,7 @@ private function toColumn(string $code, int $pos) : int { /** * Updates the exception message after a change to rawMessage or rawLine. */ - protected function updateMessage() { + protected function updateMessage(): void { $this->message = $this->rawMessage; if (-1 === $this->getStartLine()) { diff --git a/lib/PhpParser/ErrorHandler.php b/lib/PhpParser/ErrorHandler.php index d620e74536..51ad730c4e 100644 --- a/lib/PhpParser/ErrorHandler.php +++ b/lib/PhpParser/ErrorHandler.php @@ -2,12 +2,11 @@ namespace PhpParser; -interface ErrorHandler -{ +interface ErrorHandler { /** * Handle an error generated during lexing, parsing or some other operation. * * @param Error $error The error that needs to be handled */ - public function handleError(Error $error); + public function handleError(Error $error): void; } diff --git a/lib/PhpParser/ErrorHandler/Collecting.php b/lib/PhpParser/ErrorHandler/Collecting.php index 784b61b143..eee634924a 100644 --- a/lib/PhpParser/ErrorHandler/Collecting.php +++ b/lib/PhpParser/ErrorHandler/Collecting.php @@ -10,12 +10,11 @@ * * This allows graceful handling of errors. */ -class Collecting implements ErrorHandler -{ +class Collecting implements ErrorHandler { /** @var Error[] Collected errors */ - private $errors = []; + private array $errors = []; - public function handleError(Error $error) { + public function handleError(Error $error): void { $this->errors[] = $error; } @@ -24,23 +23,21 @@ public function handleError(Error $error) { * * @return Error[] */ - public function getErrors() : array { + public function getErrors(): array { return $this->errors; } /** * Check whether there are any errors. - * - * @return bool */ - public function hasErrors() : bool { + public function hasErrors(): bool { return !empty($this->errors); } /** * Reset/clear collected errors. */ - public function clearErrors() { + public function clearErrors(): void { $this->errors = []; } } diff --git a/lib/PhpParser/ErrorHandler/Throwing.php b/lib/PhpParser/ErrorHandler/Throwing.php index aeee989b1a..dff33dd021 100644 --- a/lib/PhpParser/ErrorHandler/Throwing.php +++ b/lib/PhpParser/ErrorHandler/Throwing.php @@ -10,9 +10,8 @@ * * This is the default strategy used by all components. */ -class Throwing implements ErrorHandler -{ - public function handleError(Error $error) { +class Throwing implements ErrorHandler { + public function handleError(Error $error): void { throw $error; } } diff --git a/lib/PhpParser/Internal/DiffElem.php b/lib/PhpParser/Internal/DiffElem.php index a38b57ba93..7433b5d32a 100644 --- a/lib/PhpParser/Internal/DiffElem.php +++ b/lib/PhpParser/Internal/DiffElem.php @@ -5,20 +5,24 @@ /** * @internal */ -class DiffElem -{ - const TYPE_KEEP = 0; - const TYPE_REMOVE = 1; - const TYPE_ADD = 2; - const TYPE_REPLACE = 3; +class DiffElem { + public const TYPE_KEEP = 0; + public const TYPE_REMOVE = 1; + public const TYPE_ADD = 2; + public const TYPE_REPLACE = 3; /** @var int One of the TYPE_* constants */ - public $type; + public int $type; /** @var mixed Is null for add operations */ public $old; /** @var mixed Is null for remove operations */ public $new; + /** + * @param int $type One of the TYPE_* constants + * @param mixed $old Is null for add operations + * @param mixed $new Is null for remove operations + */ public function __construct(int $type, $old, $new) { $this->type = $type; $this->old = $old; diff --git a/lib/PhpParser/Internal/Differ.php b/lib/PhpParser/Internal/Differ.php index 7f218c74fe..253e17574c 100644 --- a/lib/PhpParser/Internal/Differ.php +++ b/lib/PhpParser/Internal/Differ.php @@ -8,16 +8,17 @@ * Myers, Eugene W. "An O (ND) difference algorithm and its variations." * Algorithmica 1.1 (1986): 251-266. * + * @template T * @internal */ -class Differ -{ +class Differ { + /** @var callable(T, T): bool */ private $isEqual; /** * Create differ over the given equality relation. * - * @param callable $isEqual Equality relation with signature function($a, $b) : bool + * @param callable(T, T): bool $isEqual Equality relation */ public function __construct(callable $isEqual) { $this->isEqual = $isEqual; @@ -26,12 +27,14 @@ public function __construct(callable $isEqual) { /** * Calculate diff (edit script) from $old to $new. * - * @param array $old Original array - * @param array $new New array + * @param T[] $old Original array + * @param T[] $new New array * * @return DiffElem[] Diff (edit script) */ - public function diff(array $old, array $new) { + public function diff(array $old, array $new): array { + $old = \array_values($old); + $new = \array_values($new); list($trace, $x, $y) = $this->calculateTrace($old, $new); return $this->extractDiff($trace, $x, $y, $old, $new); } @@ -42,32 +45,37 @@ public function diff(array $old, array $new) { * If a sequence of remove operations is followed by the same number of add operations, these * will be coalesced into replace operations. * - * @param array $old Original array - * @param array $new New array + * @param T[] $old Original array + * @param T[] $new New array * * @return DiffElem[] Diff (edit script), including replace operations */ - public function diffWithReplacements(array $old, array $new) { + public function diffWithReplacements(array $old, array $new): array { return $this->coalesceReplacements($this->diff($old, $new)); } - private function calculateTrace(array $a, array $b) { - $n = \count($a); - $m = \count($b); + /** + * @param T[] $old + * @param T[] $new + * @return array{array>, int, int} + */ + private function calculateTrace(array $old, array $new): array { + $n = \count($old); + $m = \count($new); $max = $n + $m; $v = [1 => 0]; $trace = []; for ($d = 0; $d <= $max; $d++) { $trace[] = $v; for ($k = -$d; $k <= $d; $k += 2) { - if ($k === -$d || ($k !== $d && $v[$k-1] < $v[$k+1])) { - $x = $v[$k+1]; + if ($k === -$d || ($k !== $d && $v[$k - 1] < $v[$k + 1])) { + $x = $v[$k + 1]; } else { - $x = $v[$k-1] + 1; + $x = $v[$k - 1] + 1; } $y = $x - $k; - while ($x < $n && $y < $m && ($this->isEqual)($a[$x], $b[$y])) { + while ($x < $n && $y < $m && ($this->isEqual)($old[$x], $new[$y])) { $x++; $y++; } @@ -81,13 +89,19 @@ private function calculateTrace(array $a, array $b) { throw new \Exception('Should not happen'); } - private function extractDiff(array $trace, int $x, int $y, array $a, array $b) { + /** + * @param array> $trace + * @param T[] $old + * @param T[] $new + * @return DiffElem[] + */ + private function extractDiff(array $trace, int $x, int $y, array $old, array $new): array { $result = []; for ($d = \count($trace) - 1; $d >= 0; $d--) { $v = $trace[$d]; $k = $x - $y; - if ($k === -$d || ($k !== $d && $v[$k-1] < $v[$k+1])) { + if ($k === -$d || ($k !== $d && $v[$k - 1] < $v[$k + 1])) { $prevK = $k + 1; } else { $prevK = $k - 1; @@ -97,7 +111,7 @@ private function extractDiff(array $trace, int $x, int $y, array $a, array $b) { $prevY = $prevX - $prevK; while ($x > $prevX && $y > $prevY) { - $result[] = new DiffElem(DiffElem::TYPE_KEEP, $a[$x-1], $b[$y-1]); + $result[] = new DiffElem(DiffElem::TYPE_KEEP, $old[$x - 1], $new[$y - 1]); $x--; $y--; } @@ -107,12 +121,12 @@ private function extractDiff(array $trace, int $x, int $y, array $a, array $b) { } while ($x > $prevX) { - $result[] = new DiffElem(DiffElem::TYPE_REMOVE, $a[$x-1], null); + $result[] = new DiffElem(DiffElem::TYPE_REMOVE, $old[$x - 1], null); $x--; } while ($y > $prevY) { - $result[] = new DiffElem(DiffElem::TYPE_ADD, null, $b[$y-1]); + $result[] = new DiffElem(DiffElem::TYPE_ADD, null, $new[$y - 1]); $y--; } } @@ -125,7 +139,7 @@ private function extractDiff(array $trace, int $x, int $y, array $a, array $b) { * @param DiffElem[] $diff * @return DiffElem[] */ - private function coalesceReplacements(array $diff) { + private function coalesceReplacements(array $diff): array { $newDiff = []; $c = \count($diff); for ($i = 0; $i < $c; $i++) { diff --git a/lib/PhpParser/Internal/PrintableNewAnonClassNode.php b/lib/PhpParser/Internal/PrintableNewAnonClassNode.php index 3eeac04a41..b30a99a14b 100644 --- a/lib/PhpParser/Internal/PrintableNewAnonClassNode.php +++ b/lib/PhpParser/Internal/PrintableNewAnonClassNode.php @@ -15,47 +15,57 @@ * * @internal */ -class PrintableNewAnonClassNode extends Expr -{ +class PrintableNewAnonClassNode extends Expr { /** @var Node\AttributeGroup[] PHP attribute groups */ - public $attrGroups; - /** @var Node\Arg[] Arguments */ - public $args; + public array $attrGroups; + /** @var int Modifiers */ + public int $flags; + /** @var (Node\Arg|Node\VariadicPlaceholder)[] Arguments */ + public array $args; /** @var null|Node\Name Name of extended class */ - public $extends; + public ?Node\Name $extends; /** @var Node\Name[] Names of implemented interfaces */ - public $implements; + public array $implements; /** @var Node\Stmt[] Statements */ - public $stmts; + public array $stmts; + /** + * @param Node\AttributeGroup[] $attrGroups PHP attribute groups + * @param (Node\Arg|Node\VariadicPlaceholder)[] $args Arguments + * @param Node\Name|null $extends Name of extended class + * @param Node\Name[] $implements Names of implemented interfaces + * @param Node\Stmt[] $stmts Statements + * @param array $attributes Attributes + */ public function __construct( - array $attrGroups, array $args, Node\Name $extends = null, array $implements, + array $attrGroups, int $flags, array $args, ?Node\Name $extends, array $implements, array $stmts, array $attributes ) { parent::__construct($attributes); $this->attrGroups = $attrGroups; + $this->flags = $flags; $this->args = $args; $this->extends = $extends; $this->implements = $implements; $this->stmts = $stmts; } - public static function fromNewNode(Expr\New_ $newNode) { + public static function fromNewNode(Expr\New_ $newNode): self { $class = $newNode->class; assert($class instanceof Node\Stmt\Class_); // We don't assert that $class->name is null here, to allow consumers to assign unique names // to anonymous classes for their own purposes. We simplify ignore the name here. return new self( - $class->attrGroups, $newNode->args, $class->extends, $class->implements, + $class->attrGroups, $class->flags, $newNode->args, $class->extends, $class->implements, $class->stmts, $newNode->getAttributes() ); } - public function getType() : string { + public function getType(): string { return 'Expr_PrintableNewAnonClass'; } - public function getSubNodeNames() : array { - return ['attrGroups', 'args', 'extends', 'implements', 'stmts']; + public function getSubNodeNames(): array { + return ['attrGroups', 'flags', 'args', 'extends', 'implements', 'stmts']; } } diff --git a/lib/PhpParser/Internal/TokenPolyfill.php b/lib/PhpParser/Internal/TokenPolyfill.php new file mode 100644 index 0000000000..36022d09a0 --- /dev/null +++ b/lib/PhpParser/Internal/TokenPolyfill.php @@ -0,0 +1,237 @@ += 80000) { + class TokenPolyfill extends \PhpToken { + } + return; +} + +/** + * This is a polyfill for the PhpToken class introduced in PHP 8.0. We do not actually polyfill + * PhpToken, because composer might end up picking a different polyfill implementation, which does + * not meet our requirements. + * + * @internal + */ +class TokenPolyfill { + /** @var int The ID of the token. Either a T_* constant of a character code < 256. */ + public int $id; + /** @var string The textual content of the token. */ + public string $text; + /** @var int The 1-based starting line of the token (or -1 if unknown). */ + public int $line; + /** @var int The 0-based starting position of the token (or -1 if unknown). */ + public int $pos; + + /** @var array Tokens ignored by the PHP parser. */ + private const IGNORABLE_TOKENS = [ + \T_WHITESPACE => true, + \T_COMMENT => true, + \T_DOC_COMMENT => true, + \T_OPEN_TAG => true, + ]; + + /** @var array Tokens that may be part of a T_NAME_* identifier. */ + private static array $identifierTokens; + + /** + * Create a Token with the given ID and text, as well optional line and position information. + */ + final public function __construct(int $id, string $text, int $line = -1, int $pos = -1) { + $this->id = $id; + $this->text = $text; + $this->line = $line; + $this->pos = $pos; + } + + /** + * Get the name of the token. For single-char tokens this will be the token character. + * Otherwise it will be a T_* style name, or null if the token ID is unknown. + */ + public function getTokenName(): ?string { + if ($this->id < 256) { + return \chr($this->id); + } + + $name = token_name($this->id); + return $name === 'UNKNOWN' ? null : $name; + } + + /** + * Check whether the token is of the given kind. The kind may be either an integer that matches + * the token ID, a string that matches the token text, or an array of integers/strings. In the + * latter case, the function returns true if any of the kinds in the array match. + * + * @param int|string|(int|string)[] $kind + */ + public function is($kind): bool { + if (\is_int($kind)) { + return $this->id === $kind; + } + if (\is_string($kind)) { + return $this->text === $kind; + } + if (\is_array($kind)) { + foreach ($kind as $entry) { + if (\is_int($entry)) { + if ($this->id === $entry) { + return true; + } + } elseif (\is_string($entry)) { + if ($this->text === $entry) { + return true; + } + } else { + throw new \TypeError( + 'Argument #1 ($kind) must only have elements of type string|int, ' . + gettype($entry) . ' given'); + } + } + return false; + } + throw new \TypeError( + 'Argument #1 ($kind) must be of type string|int|array, ' .gettype($kind) . ' given'); + } + + /** + * Check whether this token would be ignored by the PHP parser. Returns true for T_WHITESPACE, + * T_COMMENT, T_DOC_COMMENT and T_OPEN_TAG, and false for everything else. + */ + public function isIgnorable(): bool { + return isset(self::IGNORABLE_TOKENS[$this->id]); + } + + /** + * Return the textual content of the token. + */ + public function __toString(): string { + return $this->text; + } + + /** + * Tokenize the given source code and return an array of tokens. + * + * This performs certain canonicalizations to match the PHP 8.0 token format: + * * Bad characters are represented using T_BAD_CHARACTER rather than omitted. + * * T_COMMENT does not include trailing newlines, instead the newline is part of a following + * T_WHITESPACE token. + * * Namespaced names are represented using T_NAME_* tokens. + * + * @return static[] + */ + public static function tokenize(string $code, int $flags = 0): array { + self::init(); + + $tokens = []; + $line = 1; + $pos = 0; + $origTokens = \token_get_all($code, $flags); + + $numTokens = \count($origTokens); + for ($i = 0; $i < $numTokens; $i++) { + $token = $origTokens[$i]; + if (\is_string($token)) { + if (\strlen($token) === 2) { + // b" and B" are tokenized as single-char tokens, even though they aren't. + $tokens[] = new static(\ord('"'), $token, $line, $pos); + $pos += 2; + } else { + $tokens[] = new static(\ord($token), $token, $line, $pos); + $pos++; + } + } else { + $id = $token[0]; + $text = $token[1]; + + // Emulate PHP 8.0 comment format, which does not include trailing whitespace anymore. + if ($id === \T_COMMENT && \substr($text, 0, 2) !== '/*' && + \preg_match('/(\r\n|\n|\r)$/D', $text, $matches) + ) { + $trailingNewline = $matches[0]; + $text = \substr($text, 0, -\strlen($trailingNewline)); + $tokens[] = new static($id, $text, $line, $pos); + $pos += \strlen($text); + + if ($i + 1 < $numTokens && $origTokens[$i + 1][0] === \T_WHITESPACE) { + // Move trailing newline into following T_WHITESPACE token, if it already exists. + $origTokens[$i + 1][1] = $trailingNewline . $origTokens[$i + 1][1]; + $origTokens[$i + 1][2]--; + } else { + // Otherwise, we need to create a new T_WHITESPACE token. + $tokens[] = new static(\T_WHITESPACE, $trailingNewline, $line, $pos); + $line++; + $pos += \strlen($trailingNewline); + } + continue; + } + + // Emulate PHP 8.0 T_NAME_* tokens, by combining sequences of T_NS_SEPARATOR and + // T_STRING into a single token. + if (($id === \T_NS_SEPARATOR || isset(self::$identifierTokens[$id]))) { + $newText = $text; + $lastWasSeparator = $id === \T_NS_SEPARATOR; + for ($j = $i + 1; $j < $numTokens; $j++) { + if ($lastWasSeparator) { + if (!isset(self::$identifierTokens[$origTokens[$j][0]])) { + break; + } + $lastWasSeparator = false; + } else { + if ($origTokens[$j][0] !== \T_NS_SEPARATOR) { + break; + } + $lastWasSeparator = true; + } + $newText .= $origTokens[$j][1]; + } + if ($lastWasSeparator) { + // Trailing separator is not part of the name. + $j--; + $newText = \substr($newText, 0, -1); + } + if ($j > $i + 1) { + if ($id === \T_NS_SEPARATOR) { + $id = \T_NAME_FULLY_QUALIFIED; + } elseif ($id === \T_NAMESPACE) { + $id = \T_NAME_RELATIVE; + } else { + $id = \T_NAME_QUALIFIED; + } + $tokens[] = new static($id, $newText, $line, $pos); + $pos += \strlen($newText); + $i = $j - 1; + continue; + } + } + + $tokens[] = new static($id, $text, $line, $pos); + $line += \substr_count($text, "\n"); + $pos += \strlen($text); + } + } + return $tokens; + } + + /** Initialize private static state needed by tokenize(). */ + private static function init(): void { + if (isset(self::$identifierTokens)) { + return; + } + + // Based on semi_reserved production. + self::$identifierTokens = \array_fill_keys([ + \T_STRING, + \T_STATIC, \T_ABSTRACT, \T_FINAL, \T_PRIVATE, \T_PROTECTED, \T_PUBLIC, \T_READONLY, + \T_INCLUDE, \T_INCLUDE_ONCE, \T_EVAL, \T_REQUIRE, \T_REQUIRE_ONCE, \T_LOGICAL_OR, \T_LOGICAL_XOR, \T_LOGICAL_AND, + \T_INSTANCEOF, \T_NEW, \T_CLONE, \T_EXIT, \T_IF, \T_ELSEIF, \T_ELSE, \T_ENDIF, \T_ECHO, \T_DO, \T_WHILE, + \T_ENDWHILE, \T_FOR, \T_ENDFOR, \T_FOREACH, \T_ENDFOREACH, \T_DECLARE, \T_ENDDECLARE, \T_AS, \T_TRY, \T_CATCH, + \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_FN, + \T_MATCH, + ], true); + } +} diff --git a/lib/PhpParser/Internal/TokenStream.php b/lib/PhpParser/Internal/TokenStream.php index 84c0175ec5..cdbe2bdcc9 100644 --- a/lib/PhpParser/Internal/TokenStream.php +++ b/lib/PhpParser/Internal/TokenStream.php @@ -2,37 +2,36 @@ namespace PhpParser\Internal; +use PhpParser\Token; + /** * Provides operations on token streams, for use by pretty printer. * * @internal */ -class TokenStream -{ - /** @var array Tokens (in token_get_all format) */ - private $tokens; +class TokenStream { + /** @var Token[] Tokens (in PhpToken::tokenize() format) */ + private array $tokens; /** @var int[] Map from position to indentation */ - private $indentMap; + private array $indentMap; /** * Create token stream instance. * - * @param array $tokens Tokens in token_get_all() format + * @param Token[] $tokens Tokens in PhpToken::tokenize() format */ - public function __construct(array $tokens) { + public function __construct(array $tokens, int $tabWidth) { $this->tokens = $tokens; - $this->indentMap = $this->calcIndentMap(); + $this->indentMap = $this->calcIndentMap($tabWidth); } /** * Whether the given position is immediately surrounded by parenthesis. * * @param int $startPos Start position - * @param int $endPos End position - * - * @return bool + * @param int $endPos End position */ - public function haveParens(int $startPos, int $endPos) : bool { + public function haveParens(int $startPos, int $endPos): bool { return $this->haveTokenImmediatelyBefore($startPos, '(') && $this->haveTokenImmediatelyAfter($endPos, ')'); } @@ -41,11 +40,9 @@ public function haveParens(int $startPos, int $endPos) : bool { * Whether the given position is immediately surrounded by braces. * * @param int $startPos Start position - * @param int $endPos End position - * - * @return bool + * @param int $endPos End position */ - public function haveBraces(int $startPos, int $endPos) : bool { + public function haveBraces(int $startPos, int $endPos): bool { return ($this->haveTokenImmediatelyBefore($startPos, '{') || $this->haveTokenImmediatelyBefore($startPos, T_CURLY_OPEN)) && $this->haveTokenImmediatelyAfter($endPos, '}'); @@ -56,21 +53,20 @@ public function haveBraces(int $startPos, int $endPos) : bool { * * During this check whitespace and comments are skipped. * - * @param int $pos Position before which the token should occur + * @param int $pos Position before which the token should occur * @param int|string $expectedTokenType Token to check for * * @return bool Whether the expected token was found */ - public function haveTokenImmediatelyBefore(int $pos, $expectedTokenType) : bool { + public function haveTokenImmediatelyBefore(int $pos, $expectedTokenType): bool { $tokens = $this->tokens; $pos--; for (; $pos >= 0; $pos--) { - $tokenType = $tokens[$pos][0]; - if ($tokenType === $expectedTokenType) { + $token = $tokens[$pos]; + if ($token->is($expectedTokenType)) { return true; } - if ($tokenType !== \T_WHITESPACE - && $tokenType !== \T_COMMENT && $tokenType !== \T_DOC_COMMENT) { + if (!$token->isIgnorable()) { break; } } @@ -82,28 +78,28 @@ public function haveTokenImmediatelyBefore(int $pos, $expectedTokenType) : bool * * During this check whitespace and comments are skipped. * - * @param int $pos Position after which the token should occur + * @param int $pos Position after which the token should occur * @param int|string $expectedTokenType Token to check for * * @return bool Whether the expected token was found */ - public function haveTokenImmediatelyAfter(int $pos, $expectedTokenType) : bool { + public function haveTokenImmediatelyAfter(int $pos, $expectedTokenType): bool { $tokens = $this->tokens; $pos++; - for (; $pos < \count($tokens); $pos++) { - $tokenType = $tokens[$pos][0]; - if ($tokenType === $expectedTokenType) { + for ($c = \count($tokens); $pos < $c; $pos++) { + $token = $tokens[$pos]; + if ($token->is($expectedTokenType)) { return true; } - if ($tokenType !== \T_WHITESPACE - && $tokenType !== \T_COMMENT && $tokenType !== \T_DOC_COMMENT) { + if (!$token->isIgnorable()) { break; } } return false; } - public function skipLeft(int $pos, $skipTokenType) { + /** @param int|string|(int|string)[] $skipTokenType */ + public function skipLeft(int $pos, $skipTokenType): int { $tokens = $this->tokens; $pos = $this->skipLeftWhitespace($pos); @@ -111,7 +107,7 @@ public function skipLeft(int $pos, $skipTokenType) { return $pos; } - if ($tokens[$pos][0] !== $skipTokenType) { + if (!$tokens[$pos]->is($skipTokenType)) { // Shouldn't happen. The skip token MUST be there throw new \Exception('Encountered unexpected token'); } @@ -120,7 +116,8 @@ public function skipLeft(int $pos, $skipTokenType) { return $this->skipLeftWhitespace($pos); } - public function skipRight(int $pos, $skipTokenType) { + /** @param int|string|(int|string)[] $skipTokenType */ + public function skipRight(int $pos, $skipTokenType): int { $tokens = $this->tokens; $pos = $this->skipRightWhitespace($pos); @@ -128,7 +125,7 @@ public function skipRight(int $pos, $skipTokenType) { return $pos; } - if ($tokens[$pos][0] !== $skipTokenType) { + if (!$tokens[$pos]->is($skipTokenType)) { // Shouldn't happen. The skip token MUST be there throw new \Exception('Encountered unexpected token'); } @@ -143,11 +140,10 @@ public function skipRight(int $pos, $skipTokenType) { * @param int $pos Token position * @return int Non-whitespace token position */ - public function skipLeftWhitespace(int $pos) { + public function skipLeftWhitespace(int $pos): int { $tokens = $this->tokens; for (; $pos >= 0; $pos--) { - $type = $tokens[$pos][0]; - if ($type !== \T_WHITESPACE && $type !== \T_COMMENT && $type !== \T_DOC_COMMENT) { + if (!$tokens[$pos]->isIgnorable()) { break; } } @@ -160,22 +156,21 @@ public function skipLeftWhitespace(int $pos) { * @param int $pos Token position * @return int Non-whitespace token position */ - public function skipRightWhitespace(int $pos) { + public function skipRightWhitespace(int $pos): int { $tokens = $this->tokens; for ($count = \count($tokens); $pos < $count; $pos++) { - $type = $tokens[$pos][0]; - if ($type !== \T_WHITESPACE && $type !== \T_COMMENT && $type !== \T_DOC_COMMENT) { + if (!$tokens[$pos]->isIgnorable()) { break; } } return $pos; } - public function findRight(int $pos, $findTokenType) { + /** @param int|string|(int|string)[] $findTokenType */ + public function findRight(int $pos, $findTokenType): int { $tokens = $this->tokens; for ($count = \count($tokens); $pos < $count; $pos++) { - $type = $tokens[$pos][0]; - if ($type === $findTokenType) { + if ($tokens[$pos]->is($findTokenType)) { return $pos; } } @@ -190,20 +185,19 @@ public function findRight(int $pos, $findTokenType) { * @param int|string $tokenType Token type to look for * @return bool Whether the token occurs in the given range */ - public function haveTokenInRange(int $startPos, int $endPos, $tokenType) { + public function haveTokenInRange(int $startPos, int $endPos, $tokenType): bool { $tokens = $this->tokens; for ($pos = $startPos; $pos < $endPos; $pos++) { - if ($tokens[$pos][0] === $tokenType) { + if ($tokens[$pos]->is($tokenType)) { return true; } } return false; } - public function haveBracesInRange(int $startPos, int $endPos) { - return $this->haveTokenInRange($startPos, $endPos, '{') - || $this->haveTokenInRange($startPos, $endPos, T_CURLY_OPEN) - || $this->haveTokenInRange($startPos, $endPos, '}'); + public function haveTagInRange(int $startPos, int $endPos): bool { + return $this->haveTokenInRange($startPos, $endPos, \T_OPEN_TAG) + || $this->haveTokenInRange($startPos, $endPos, \T_CLOSE_TAG); } /** @@ -213,41 +207,37 @@ public function haveBracesInRange(int $startPos, int $endPos) { * * @return int Indentation depth (in spaces) */ - public function getIndentationBefore(int $pos) : int { + public function getIndentationBefore(int $pos): int { return $this->indentMap[$pos]; } /** * Get the code corresponding to a token offset range, optionally adjusted for indentation. * - * @param int $from Token start position (inclusive) - * @param int $to Token end position (exclusive) + * @param int $from Token start position (inclusive) + * @param int $to Token end position (exclusive) * @param int $indent By how much the code should be indented (can be negative as well) * * @return string Code corresponding to token range, adjusted for indentation */ - public function getTokenCode(int $from, int $to, int $indent) : string { + public function getTokenCode(int $from, int $to, int $indent): string { $tokens = $this->tokens; $result = ''; for ($pos = $from; $pos < $to; $pos++) { $token = $tokens[$pos]; - if (\is_array($token)) { - $type = $token[0]; - $content = $token[1]; - if ($type === \T_CONSTANT_ENCAPSED_STRING || $type === \T_ENCAPSED_AND_WHITESPACE) { - $result .= $content; + $id = $token->id; + $text = $token->text; + if ($id === \T_CONSTANT_ENCAPSED_STRING || $id === \T_ENCAPSED_AND_WHITESPACE) { + $result .= $text; + } else { + // TODO Handle non-space indentation + if ($indent < 0) { + $result .= str_replace("\n" . str_repeat(" ", -$indent), "\n", $text); + } elseif ($indent > 0) { + $result .= str_replace("\n", "\n" . str_repeat(" ", $indent), $text); } else { - // TODO Handle non-space indentation - if ($indent < 0) { - $result .= str_replace("\n" . str_repeat(" ", -$indent), "\n", $content); - } elseif ($indent > 0) { - $result .= str_replace("\n", "\n" . str_repeat(" ", $indent), $content); - } else { - $result .= $content; - } + $result .= $text; } - } else { - $result .= $token; } } return $result; @@ -258,17 +248,21 @@ public function getTokenCode(int $from, int $to, int $indent) : string { * * @return int[] Token position to indentation map */ - private function calcIndentMap() { + private function calcIndentMap(int $tabWidth): array { $indentMap = []; $indent = 0; - foreach ($this->tokens as $token) { + foreach ($this->tokens as $i => $token) { $indentMap[] = $indent; - if ($token[0] === \T_WHITESPACE) { - $content = $token[1]; + if ($token->id === \T_WHITESPACE) { + $content = $token->text; $newlinePos = \strrpos($content, "\n"); if (false !== $newlinePos) { - $indent = \strlen($content) - $newlinePos - 1; + $indent = $this->getIndent(\substr($content, $newlinePos + 1), $tabWidth); + } elseif ($i === 1 && $this->tokens[0]->id === \T_OPEN_TAG && + $this->tokens[0]->text[\strlen($this->tokens[0]->text) - 1] === "\n") { + // Special case: Newline at the end of opening tag followed by whitespace. + $indent = $this->getIndent($content, $tabWidth); } } } @@ -278,4 +272,11 @@ private function calcIndentMap() { return $indentMap; } + + private function getIndent(string $ws, int $tabWidth): int { + $spaces = \substr_count($ws, " "); + $tabs = \substr_count($ws, "\t"); + assert(\strlen($ws) === $spaces + $tabs); + return $spaces + $tabs * $tabWidth; + } } diff --git a/lib/PhpParser/JsonDecoder.php b/lib/PhpParser/JsonDecoder.php index 47d2003d4b..7be41426ef 100644 --- a/lib/PhpParser/JsonDecoder.php +++ b/lib/PhpParser/JsonDecoder.php @@ -2,11 +2,11 @@ namespace PhpParser; -class JsonDecoder -{ - /** @var \ReflectionClass[] Node type to reflection class map */ - private $reflectionClassCache; +class JsonDecoder { + /** @var \ReflectionClass[] Node type to reflection class map */ + private array $reflectionClassCache; + /** @return mixed */ public function decode(string $json) { $value = json_decode($json, true); if (json_last_error()) { @@ -16,6 +16,10 @@ public function decode(string $json) { return $this->decodeRecursive($value); } + /** + * @param mixed $value + * @return mixed + */ private function decodeRecursive($value) { if (\is_array($value)) { if (isset($value['nodeType'])) { @@ -29,7 +33,7 @@ private function decodeRecursive($value) { return $value; } - private function decodeArray(array $array) : array { + private function decodeArray(array $array): array { $decodedArray = []; foreach ($array as $key => $value) { $decodedArray[$key] = $this->decodeRecursive($value); @@ -37,14 +41,13 @@ private function decodeArray(array $array) : array { return $decodedArray; } - private function decodeNode(array $value) : Node { + private function decodeNode(array $value): Node { $nodeType = $value['nodeType']; if (!\is_string($nodeType)) { throw new \RuntimeException('Node type must be a string'); } $reflectionClass = $this->reflectionClassFromNodeType($nodeType); - /** @var Node $node */ $node = $reflectionClass->newInstanceWithoutConstructor(); if (isset($value['attributes'])) { @@ -66,7 +69,7 @@ private function decodeNode(array $value) : Node { return $node; } - private function decodeComment(array $value) : Comment { + private function decodeComment(array $value): Comment { $className = $value['nodeType'] === 'Comment' ? Comment::class : Comment\Doc::class; if (!isset($value['text'])) { throw new \RuntimeException('Comment must have text'); @@ -79,7 +82,8 @@ private function decodeComment(array $value) : Comment { ); } - private function reflectionClassFromNodeType(string $nodeType) : \ReflectionClass { + /** @return \ReflectionClass */ + private function reflectionClassFromNodeType(string $nodeType): \ReflectionClass { if (!isset($this->reflectionClassCache[$nodeType])) { $className = $this->classNameFromNodeType($nodeType); $this->reflectionClassCache[$nodeType] = new \ReflectionClass($className); @@ -87,7 +91,8 @@ private function reflectionClassFromNodeType(string $nodeType) : \ReflectionClas return $this->reflectionClassCache[$nodeType]; } - private function classNameFromNodeType(string $nodeType) : string { + /** @return class-string */ + private function classNameFromNodeType(string $nodeType): string { $className = 'PhpParser\\Node\\' . strtr($nodeType, '_', '\\'); if (class_exists($className)) { return $className; diff --git a/lib/PhpParser/Lexer.php b/lib/PhpParser/Lexer.php index 1826c615fb..5e2ece9617 100644 --- a/lib/PhpParser/Lexer.php +++ b/lib/PhpParser/Lexer.php @@ -2,535 +2,115 @@ namespace PhpParser; -use PhpParser\Parser\Tokens; - -class Lexer -{ - protected $code; - protected $tokens; - protected $pos; - protected $line; - protected $filePos; - protected $prevCloseTagHasNewline; - - protected $tokenMap; - protected $dropTokens; - protected $identifierTokens; - - private $attributeStartLineUsed; - private $attributeEndLineUsed; - private $attributeStartTokenPosUsed; - private $attributeEndTokenPosUsed; - private $attributeStartFilePosUsed; - private $attributeEndFilePosUsed; - private $attributeCommentsUsed; +require __DIR__ . '/compatibility_tokens.php'; +class Lexer { /** - * Creates a Lexer. + * Tokenize the provided source code. * - * @param array $options Options array. Currently only the 'usedAttributes' option is supported, - * which is an array of attributes to add to the AST nodes. Possible - * attributes are: 'comments', 'startLine', 'endLine', 'startTokenPos', - * 'endTokenPos', 'startFilePos', 'endFilePos'. The option defaults to the - * first three. For more info see getNextToken() docs. - */ - public function __construct(array $options = []) { - // Create Map from internal tokens to PhpParser tokens. - $this->defineCompatibilityTokens(); - $this->tokenMap = $this->createTokenMap(); - $this->identifierTokens = $this->createIdentifierTokenMap(); - - // map of tokens to drop while lexing (the map is only used for isset lookup, - // that's why the value is simply set to 1; the value is never actually used.) - $this->dropTokens = array_fill_keys( - [\T_WHITESPACE, \T_OPEN_TAG, \T_COMMENT, \T_DOC_COMMENT, \T_BAD_CHARACTER], 1 - ); - - $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']); - } - - /** - * Initializes the lexer for lexing the provided source code. + * The token array is in the same format as provided by the PhpToken::tokenize() method in + * PHP 8.0. The tokens are instances of PhpParser\Token, to abstract over a polyfill + * implementation in earlier PHP version. * - * This function does not throw if lexing errors occur. Instead, errors may be retrieved using - * the getErrors() method. + * The token array is terminated by a sentinel token with token ID 0. + * The token array does not discard any tokens (i.e. whitespace and comments are included). + * The token position attributes are against this token array. * - * @param string $code The source code to lex + * @param string $code The source code to tokenize. * @param ErrorHandler|null $errorHandler Error handler to use for lexing errors. Defaults to - * ErrorHandler\Throwing + * ErrorHandler\Throwing. + * @return Token[] Tokens */ - public function startLexing(string $code, ErrorHandler $errorHandler = null) { + public function tokenize(string $code, ?ErrorHandler $errorHandler = null): array { if (null === $errorHandler) { $errorHandler = new ErrorHandler\Throwing(); } - $this->code = $code; // keep the code around for __halt_compiler() handling - $this->pos = -1; - $this->line = 1; - $this->filePos = 0; - - // If inline HTML occurs without preceding code, treat it as if it had a leading newline. - // This ensures proper composability, because having a newline is the "safe" assumption. - $this->prevCloseTagHasNewline = true; - $scream = ini_set('xdebug.scream', '0'); - $this->tokens = @token_get_all($code); - $this->postprocessTokens($errorHandler); + $tokens = @Token::tokenize($code); + $this->postprocessTokens($tokens, $errorHandler); if (false !== $scream) { ini_set('xdebug.scream', $scream); } - } - private function handleInvalidCharacterRange($start, $end, $line, ErrorHandler $errorHandler) { - $tokens = []; - for ($i = $start; $i < $end; $i++) { - $chr = $this->code[$i]; - if ($chr === "\0") { - // PHP cuts error message after null byte, so need special case - $errorMsg = 'Unexpected null byte'; - } else { - $errorMsg = sprintf( - 'Unexpected character "%s" (ASCII %d)', $chr, ord($chr) - ); - } - - $tokens[] = [\T_BAD_CHARACTER, $chr, $line]; - $errorHandler->handleError(new Error($errorMsg, [ - 'startLine' => $line, - 'endLine' => $line, - 'startFilePos' => $i, - 'endFilePos' => $i, - ])); - } return $tokens; } - /** - * Check whether comment token is unterminated. - * - * @return bool - */ - private function isUnterminatedComment($token) : bool { - return ($token[0] === \T_COMMENT || $token[0] === \T_DOC_COMMENT) - && substr($token[1], 0, 2) === '/*' - && substr($token[1], -2) !== '*/'; - } - - protected function postprocessTokens(ErrorHandler $errorHandler) { - // PHP's error handling for token_get_all() is rather bad, so if we want detailed - // error information we need to compute it ourselves. Invalid character errors are - // detected by finding "gaps" in the token array. Unterminated comments are detected - // by checking if a trailing comment has a "*/" at the end. - // - // Additionally, we canonicalize to the PHP 8 comment format here, which does not include - // the trailing whitespace anymore. - // - // We also canonicalize to the PHP 8 T_NAME_* tokens. - - $filePos = 0; - $line = 1; - $numTokens = \count($this->tokens); - for ($i = 0; $i < $numTokens; $i++) { - $token = $this->tokens[$i]; - - // Since PHP 7.4 invalid characters are represented by a T_BAD_CHARACTER token. - // In this case we only need to emit an error. - if ($token[0] === \T_BAD_CHARACTER) { - $this->handleInvalidCharacterRange($filePos, $filePos + 1, $line, $errorHandler); - } - - if ($token[0] === \T_COMMENT && substr($token[1], 0, 2) !== '/*' - && preg_match('/(\r\n|\n|\r)$/D', $token[1], $matches)) { - $trailingNewline = $matches[0]; - $token[1] = substr($token[1], 0, -strlen($trailingNewline)); - $this->tokens[$i] = $token; - if (isset($this->tokens[$i + 1]) && $this->tokens[$i + 1][0] === \T_WHITESPACE) { - // Move trailing newline into following T_WHITESPACE token, if it already exists. - $this->tokens[$i + 1][1] = $trailingNewline . $this->tokens[$i + 1][1]; - $this->tokens[$i + 1][2]--; - } else { - // Otherwise, we need to create a new T_WHITESPACE token. - array_splice($this->tokens, $i + 1, 0, [ - [\T_WHITESPACE, $trailingNewline, $line], - ]); - $numTokens++; - } - } - - // Emulate PHP 8 T_NAME_* tokens, by combining sequences of T_NS_SEPARATOR and T_STRING - // into a single token. - if (\is_array($token) - && ($token[0] === \T_NS_SEPARATOR || isset($this->identifierTokens[$token[0]]))) { - $lastWasSeparator = $token[0] === \T_NS_SEPARATOR; - $text = $token[1]; - for ($j = $i + 1; isset($this->tokens[$j]); $j++) { - if ($lastWasSeparator) { - if (!isset($this->identifierTokens[$this->tokens[$j][0]])) { - break; - } - $lastWasSeparator = false; - } else { - if ($this->tokens[$j][0] !== \T_NS_SEPARATOR) { - break; - } - $lastWasSeparator = true; - } - $text .= $this->tokens[$j][1]; - } - if ($lastWasSeparator) { - // Trailing separator is not part of the name. - $j--; - $text = substr($text, 0, -1); - } - if ($j > $i + 1) { - if ($token[0] === \T_NS_SEPARATOR) { - $type = \T_NAME_FULLY_QUALIFIED; - } else if ($token[0] === \T_NAMESPACE) { - $type = \T_NAME_RELATIVE; - } else { - $type = \T_NAME_QUALIFIED; - } - $token = [$type, $text, $line]; - array_splice($this->tokens, $i, $j - $i, [$token]); - $numTokens -= $j - $i - 1; - } - } - - $tokenValue = \is_string($token) ? $token : $token[1]; - $tokenLen = \strlen($tokenValue); - - if (substr($this->code, $filePos, $tokenLen) !== $tokenValue) { - // Something is missing, must be an invalid character - $nextFilePos = strpos($this->code, $tokenValue, $filePos); - $badCharTokens = $this->handleInvalidCharacterRange( - $filePos, $nextFilePos, $line, $errorHandler); - $filePos = (int) $nextFilePos; - - array_splice($this->tokens, $i, 0, $badCharTokens); - $numTokens += \count($badCharTokens); - $i += \count($badCharTokens); - } - - $filePos += $tokenLen; - $line += substr_count($tokenValue, "\n"); - } - - if ($filePos !== \strlen($this->code)) { - if (substr($this->code, $filePos, 2) === '/*') { - // Unlike PHP, HHVM will drop unterminated comments entirely - $comment = substr($this->code, $filePos); - $errorHandler->handleError(new Error('Unterminated comment', [ - 'startLine' => $line, - 'endLine' => $line + substr_count($comment, "\n"), - 'startFilePos' => $filePos, - 'endFilePos' => $filePos + \strlen($comment), - ])); - - // Emulate the PHP behavior - $isDocComment = isset($comment[3]) && $comment[3] === '*'; - $this->tokens[] = [$isDocComment ? \T_DOC_COMMENT : \T_COMMENT, $comment, $line]; - } else { - // Invalid characters at the end of the input - $badCharTokens = $this->handleInvalidCharacterRange( - $filePos, \strlen($this->code), $line, $errorHandler); - $this->tokens = array_merge($this->tokens, $badCharTokens); - } - return; + private function handleInvalidCharacter(Token $token, ErrorHandler $errorHandler): void { + $chr = $token->text; + if ($chr === "\0") { + // PHP cuts error message after null byte, so need special case + $errorMsg = 'Unexpected null byte'; + } else { + $errorMsg = sprintf( + 'Unexpected character "%s" (ASCII %d)', $chr, ord($chr) + ); } - if (count($this->tokens) > 0) { - // Check for unterminated comment - $lastToken = $this->tokens[count($this->tokens) - 1]; - if ($this->isUnterminatedComment($lastToken)) { - $errorHandler->handleError(new Error('Unterminated comment', [ - 'startLine' => $line - substr_count($lastToken[1], "\n"), - 'endLine' => $line, - 'startFilePos' => $filePos - \strlen($lastToken[1]), - 'endFilePos' => $filePos, - ])); - } - } + $errorHandler->handleError(new Error($errorMsg, [ + 'startLine' => $token->line, + 'endLine' => $token->line, + 'startFilePos' => $token->pos, + 'endFilePos' => $token->pos, + ])); } - /** - * Fetches the next token. - * - * The available attributes are determined by the 'usedAttributes' option, which can - * be specified in the constructor. The following attributes are supported: - * - * * 'comments' => Array of PhpParser\Comment or PhpParser\Comment\Doc instances, - * representing all comments that occurred between the previous - * non-discarded token and the current one. - * * 'startLine' => Line in which the node starts. - * * 'endLine' => Line in which the node ends. - * * 'startTokenPos' => Offset into the token array of the first token in the node. - * * 'endTokenPos' => Offset into the token array of the last token in the node. - * * 'startFilePos' => Offset into the code string of the first character that is part of the node. - * * 'endFilePos' => Offset into the code string of the last character that is part of the node. - * - * @param mixed $value Variable to store token content in - * @param mixed $startAttributes Variable to store start attributes in - * @param mixed $endAttributes Variable to store end attributes in - * - * @return int Token id - */ - public function getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null) : int { - $startAttributes = []; - $endAttributes = []; - - while (1) { - if (isset($this->tokens[++$this->pos])) { - $token = $this->tokens[$this->pos]; - } else { - // EOF token with ID 0 - $token = "\0"; - } - - if ($this->attributeStartLineUsed) { - $startAttributes['startLine'] = $this->line; - } - if ($this->attributeStartTokenPosUsed) { - $startAttributes['startTokenPos'] = $this->pos; - } - if ($this->attributeStartFilePosUsed) { - $startAttributes['startFilePos'] = $this->filePos; - } - - if (\is_string($token)) { - $value = $token; - if (isset($token[1])) { - // bug in token_get_all - $this->filePos += 2; - $id = ord('"'); - } else { - $this->filePos += 1; - $id = ord($token); - } - } elseif (!isset($this->dropTokens[$token[0]])) { - $value = $token[1]; - $id = $this->tokenMap[$token[0]]; - if (\T_CLOSE_TAG === $token[0]) { - $this->prevCloseTagHasNewline = false !== strpos($token[1], "\n"); - } elseif (\T_INLINE_HTML === $token[0]) { - $startAttributes['hasLeadingNewline'] = $this->prevCloseTagHasNewline; - } - - $this->line += substr_count($value, "\n"); - $this->filePos += \strlen($value); - } else { - $origLine = $this->line; - $origFilePos = $this->filePos; - $this->line += substr_count($token[1], "\n"); - $this->filePos += \strlen($token[1]); - - if (\T_COMMENT === $token[0] || \T_DOC_COMMENT === $token[0]) { - if ($this->attributeCommentsUsed) { - $comment = \T_DOC_COMMENT === $token[0] - ? new Comment\Doc($token[1], - $origLine, $origFilePos, $this->pos, - $this->line, $this->filePos - 1, $this->pos) - : new Comment($token[1], - $origLine, $origFilePos, $this->pos, - $this->line, $this->filePos - 1, $this->pos); - $startAttributes['comments'][] = $comment; - } - } - continue; - } - - if ($this->attributeEndLineUsed) { - $endAttributes['endLine'] = $this->line; - } - if ($this->attributeEndTokenPosUsed) { - $endAttributes['endTokenPos'] = $this->pos; - } - if ($this->attributeEndFilePosUsed) { - $endAttributes['endFilePos'] = $this->filePos - 1; - } - - return $id; - } - - throw new \RuntimeException('Reached end of lexer loop'); + private function isUnterminatedComment(Token $token): bool { + return $token->is([\T_COMMENT, \T_DOC_COMMENT]) + && substr($token->text, 0, 2) === '/*' + && substr($token->text, -2) !== '*/'; } /** - * Returns the token array for current code. - * - * The token array is in the same format as provided by the - * token_get_all() function and does not discard tokens (i.e. - * whitespace and comments are included). The token position - * attributes are against this token array. - * - * @return array Array of tokens in token_get_all() format - */ - public function getTokens() : array { - return $this->tokens; - } - - /** - * Handles __halt_compiler() by returning the text after it. - * - * @return string Remaining text + * @param list $tokens */ - public function handleHaltCompiler() : string { - // text after T_HALT_COMPILER, still including (); - $textAfter = substr($this->code, $this->filePos); - - // ensure that it is followed by (); - // this simplifies the situation, by not allowing any comments - // in between of the tokens. - if (!preg_match('~^\s*\(\s*\)\s*(?:;|\?>\r?\n?)~', $textAfter, $matches)) { - throw new Error('__HALT_COMPILER must be followed by "();"'); - } - - // prevent the lexer from returning any further tokens - $this->pos = count($this->tokens); - - // return with (); removed - return substr($textAfter, strlen($matches[0])); - } - - private function defineCompatibilityTokens() { - static $compatTokensDefined = false; - if ($compatTokensDefined) { + protected function postprocessTokens(array &$tokens, ErrorHandler $errorHandler): void { + // This function reports errors (bad characters and unterminated comments) in the token + // array, and performs certain canonicalizations: + // * Use PHP 8.1 T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG and + // T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG tokens used to disambiguate intersection types. + // * Add a sentinel token with ID 0. + + $numTokens = \count($tokens); + if ($numTokens === 0) { + // Empty input edge case: Just add the sentinel token. + $tokens[] = new Token(0, "\0", 1, 0); return; } - $compatTokens = [ - // PHP 7.4 - 'T_BAD_CHARACTER', - 'T_FN', - 'T_COALESCE_EQUAL', - // PHP 8.0 - 'T_NAME_QUALIFIED', - 'T_NAME_FULLY_QUALIFIED', - 'T_NAME_RELATIVE', - 'T_MATCH', - 'T_NULLSAFE_OBJECT_OPERATOR', - 'T_ATTRIBUTE', - // PHP 8.1 - 'T_ENUM', - ]; - - // PHP-Parser might be used together with another library that also emulates some or all - // of these tokens. Perform a sanity-check that all already defined tokens have been - // assigned a unique ID. - $usedTokenIds = []; - foreach ($compatTokens as $token) { - if (\defined($token)) { - $tokenId = \constant($token); - $clashingToken = $usedTokenIds[$tokenId] ?? null; - if ($clashingToken !== null) { - throw new \Error(sprintf( - 'Token %s has same ID as token %s, ' . - 'you may be using a library with broken token emulation', - $token, $clashingToken - )); - } - $usedTokenIds[$tokenId] = $token; - } - } - - // Now define any tokens that have not yet been emulated. Try to assign IDs from -1 - // downwards, but skip any IDs that may already be in use. - $newTokenId = -1; - foreach ($compatTokens as $token) { - if (!\defined($token)) { - while (isset($usedTokenIds[$newTokenId])) { - $newTokenId--; - } - \define($token, $newTokenId); - $newTokenId--; + for ($i = 0; $i < $numTokens; $i++) { + $token = $tokens[$i]; + if ($token->id === \T_BAD_CHARACTER) { + $this->handleInvalidCharacter($token, $errorHandler); } - } - - $compatTokensDefined = true; - } - /** - * Creates the token map. - * - * The token map maps the PHP internal token identifiers - * to the identifiers used by the Parser. Additionally it - * maps T_OPEN_TAG_WITH_ECHO to T_ECHO and T_CLOSE_TAG to ';'. - * - * @return array The token map - */ - protected function createTokenMap() : array { - $tokenMap = []; - - // 256 is the minimum possible token number, as everything below - // it is an ASCII value - for ($i = 256; $i < 1000; ++$i) { - if (\T_DOUBLE_COLON === $i) { - // T_DOUBLE_COLON is equivalent to T_PAAMAYIM_NEKUDOTAYIM - $tokenMap[$i] = Tokens::T_PAAMAYIM_NEKUDOTAYIM; - } elseif(\T_OPEN_TAG_WITH_ECHO === $i) { - // T_OPEN_TAG_WITH_ECHO with dropped T_OPEN_TAG results in T_ECHO - $tokenMap[$i] = Tokens::T_ECHO; - } elseif(\T_CLOSE_TAG === $i) { - // T_CLOSE_TAG is equivalent to ';' - $tokenMap[$i] = ord(';'); - } elseif ('UNKNOWN' !== $name = token_name($i)) { - if ('T_HASHBANG' === $name) { - // HHVM uses a special token for #! hashbang lines - $tokenMap[$i] = Tokens::T_INLINE_HTML; - } elseif (defined($name = Tokens::class . '::' . $name)) { - // Other tokens can be mapped directly - $tokenMap[$i] = constant($name); + if ($token->id === \ord('&')) { + $next = $i + 1; + while (isset($tokens[$next]) && $tokens[$next]->id === \T_WHITESPACE) { + $next++; } + $followedByVarOrVarArg = isset($tokens[$next]) && + $tokens[$next]->is([\T_VARIABLE, \T_ELLIPSIS]); + $token->id = $followedByVarOrVarArg + ? \T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG + : \T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG; } } - // HHVM uses a special token for numbers that overflow to double - if (defined('T_ONUMBER')) { - $tokenMap[\T_ONUMBER] = Tokens::T_DNUMBER; - } - // HHVM also has a separate token for the __COMPILER_HALT_OFFSET__ constant - if (defined('T_COMPILER_HALT_OFFSET')) { - $tokenMap[\T_COMPILER_HALT_OFFSET] = Tokens::T_STRING; + // Check for unterminated comment + $lastToken = $tokens[$numTokens - 1]; + if ($this->isUnterminatedComment($lastToken)) { + $errorHandler->handleError(new Error('Unterminated comment', [ + 'startLine' => $lastToken->line, + 'endLine' => $lastToken->getEndLine(), + 'startFilePos' => $lastToken->pos, + 'endFilePos' => $lastToken->getEndPos(), + ])); } - // Assign tokens for which we define compatibility constants, as token_name() does not know them. - $tokenMap[\T_FN] = Tokens::T_FN; - $tokenMap[\T_COALESCE_EQUAL] = Tokens::T_COALESCE_EQUAL; - $tokenMap[\T_NAME_QUALIFIED] = Tokens::T_NAME_QUALIFIED; - $tokenMap[\T_NAME_FULLY_QUALIFIED] = Tokens::T_NAME_FULLY_QUALIFIED; - $tokenMap[\T_NAME_RELATIVE] = Tokens::T_NAME_RELATIVE; - $tokenMap[\T_MATCH] = Tokens::T_MATCH; - $tokenMap[\T_NULLSAFE_OBJECT_OPERATOR] = Tokens::T_NULLSAFE_OBJECT_OPERATOR; - $tokenMap[\T_ATTRIBUTE] = Tokens::T_ATTRIBUTE; - $tokenMap[\T_ENUM] = Tokens::T_ENUM; - - return $tokenMap; - } - - private function createIdentifierTokenMap(): array { - // Based on semi_reserved production. - return array_fill_keys([ - \T_STRING, - \T_STATIC, \T_ABSTRACT, \T_FINAL, \T_PRIVATE, \T_PROTECTED, \T_PUBLIC, - \T_INCLUDE, \T_INCLUDE_ONCE, \T_EVAL, \T_REQUIRE, \T_REQUIRE_ONCE, \T_LOGICAL_OR, \T_LOGICAL_XOR, \T_LOGICAL_AND, - \T_INSTANCEOF, \T_NEW, \T_CLONE, \T_EXIT, \T_IF, \T_ELSEIF, \T_ELSE, \T_ENDIF, \T_ECHO, \T_DO, \T_WHILE, - \T_ENDWHILE, \T_FOR, \T_ENDFOR, \T_FOREACH, \T_ENDFOREACH, \T_DECLARE, \T_ENDDECLARE, \T_AS, \T_TRY, \T_CATCH, - \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_FN, - \T_MATCH, - ], true); + // Add sentinel token. + $tokens[] = new Token(0, "\0", $lastToken->getEndLine(), $lastToken->getEndPos()); } } diff --git a/lib/PhpParser/Lexer/Emulative.php b/lib/PhpParser/Lexer/Emulative.php index 6d517f40a3..3185e808ea 100644 --- a/lib/PhpParser/Lexer/Emulative.php +++ b/lib/PhpParser/Lexer/Emulative.php @@ -5,54 +5,52 @@ use PhpParser\Error; use PhpParser\ErrorHandler; use PhpParser\Lexer; +use PhpParser\Lexer\TokenEmulator\AsymmetricVisibilityTokenEmulator; use PhpParser\Lexer\TokenEmulator\AttributeEmulator; use PhpParser\Lexer\TokenEmulator\EnumTokenEmulator; -use PhpParser\Lexer\TokenEmulator\CoaleseEqualTokenEmulator; -use PhpParser\Lexer\TokenEmulator\FlexibleDocStringEmulator; -use PhpParser\Lexer\TokenEmulator\FnTokenEmulator; +use PhpParser\Lexer\TokenEmulator\ExplicitOctalEmulator; use PhpParser\Lexer\TokenEmulator\MatchTokenEmulator; use PhpParser\Lexer\TokenEmulator\NullsafeTokenEmulator; -use PhpParser\Lexer\TokenEmulator\NumericLiteralSeparatorEmulator; +use PhpParser\Lexer\TokenEmulator\PipeOperatorEmulator; +use PhpParser\Lexer\TokenEmulator\PropertyTokenEmulator; +use PhpParser\Lexer\TokenEmulator\ReadonlyFunctionTokenEmulator; +use PhpParser\Lexer\TokenEmulator\ReadonlyTokenEmulator; use PhpParser\Lexer\TokenEmulator\ReverseEmulator; use PhpParser\Lexer\TokenEmulator\TokenEmulator; +use PhpParser\Lexer\TokenEmulator\VoidCastEmulator; +use PhpParser\PhpVersion; +use PhpParser\Token; -class Emulative extends Lexer -{ - const PHP_7_3 = '7.3dev'; - const PHP_7_4 = '7.4dev'; - const PHP_8_0 = '8.0dev'; - const PHP_8_1 = '8.1dev'; +class Emulative extends Lexer { + /** @var array{int, string, string}[] Patches used to reverse changes introduced in the code */ + private array $patches = []; - /** @var mixed[] Patches used to reverse changes introduced in the code */ - private $patches = []; + /** @var list */ + private array $emulators = []; - /** @var TokenEmulator[] */ - private $emulators = []; + private PhpVersion $targetPhpVersion; - /** @var string */ - private $targetPhpVersion; + private PhpVersion $hostPhpVersion; /** - * @param mixed[] $options Lexer options. In addition to the usual options, - * accepts a 'phpVersion' string that specifies the - * version to emulated. Defaults to newest supported. + * @param PhpVersion|null $phpVersion PHP version to emulate. Defaults to newest supported. */ - public function __construct(array $options = []) - { - $this->targetPhpVersion = $options['phpVersion'] ?? Emulative::PHP_8_1; - unset($options['phpVersion']); - - parent::__construct($options); + public function __construct(?PhpVersion $phpVersion = null) { + $this->targetPhpVersion = $phpVersion ?? PhpVersion::getNewestSupported(); + $this->hostPhpVersion = PhpVersion::getHostVersion(); $emulators = [ - new FlexibleDocStringEmulator(), - new FnTokenEmulator(), new MatchTokenEmulator(), - new CoaleseEqualTokenEmulator(), - new NumericLiteralSeparatorEmulator(), new NullsafeTokenEmulator(), new AttributeEmulator(), new EnumTokenEmulator(), + new ReadonlyTokenEmulator(), + new ExplicitOctalEmulator(), + new ReadonlyFunctionTokenEmulator(), + new PropertyTokenEmulator(), + new AsymmetricVisibilityTokenEmulator(), + new PipeOperatorEmulator(), + new VoidCastEmulator(), ]; // Collect emulators that are relevant for the PHP version we're running @@ -61,21 +59,24 @@ public function __construct(array $options = []) $emulatorPhpVersion = $emulator->getPhpVersion(); if ($this->isForwardEmulationNeeded($emulatorPhpVersion)) { $this->emulators[] = $emulator; - } else if ($this->isReverseEmulationNeeded($emulatorPhpVersion)) { + } elseif ($this->isReverseEmulationNeeded($emulatorPhpVersion)) { $this->emulators[] = new ReverseEmulator($emulator); } } } - public function startLexing(string $code, ErrorHandler $errorHandler = null) { - $emulators = array_filter($this->emulators, function($emulator) use($code) { + public function tokenize(string $code, ?ErrorHandler $errorHandler = null): array { + $emulators = array_filter($this->emulators, function ($emulator) use ($code) { return $emulator->isEmulationNeeded($code); }); if (empty($emulators)) { // Nothing to emulate, yay - parent::startLexing($code, $errorHandler); - return; + return parent::tokenize($code, $errorHandler); + } + + if ($errorHandler === null) { + $errorHandler = new ErrorHandler\Throwing(); } $this->patches = []; @@ -84,9 +85,9 @@ public function startLexing(string $code, ErrorHandler $errorHandler = null) { } $collector = new ErrorHandler\Collecting(); - parent::startLexing($code, $collector); + $tokens = parent::tokenize($code, $collector); $this->sortPatches(); - $this->fixupTokens(); + $tokens = $this->fixupTokens($tokens); $errors = $collector->getErrors(); if (!empty($errors)) { @@ -97,90 +98,80 @@ public function startLexing(string $code, ErrorHandler $errorHandler = null) { } foreach ($emulators as $emulator) { - $this->tokens = $emulator->emulate($code, $this->tokens); + $tokens = $emulator->emulate($code, $tokens); } + + return $tokens; } - private function isForwardEmulationNeeded(string $emulatorPhpVersion): bool { - return version_compare(\PHP_VERSION, $emulatorPhpVersion, '<') - && version_compare($this->targetPhpVersion, $emulatorPhpVersion, '>='); + private function isForwardEmulationNeeded(PhpVersion $emulatorPhpVersion): bool { + return $this->hostPhpVersion->older($emulatorPhpVersion) + && $this->targetPhpVersion->newerOrEqual($emulatorPhpVersion); } - private function isReverseEmulationNeeded(string $emulatorPhpVersion): bool { - return version_compare(\PHP_VERSION, $emulatorPhpVersion, '>=') - && version_compare($this->targetPhpVersion, $emulatorPhpVersion, '<'); + private function isReverseEmulationNeeded(PhpVersion $emulatorPhpVersion): bool { + return $this->hostPhpVersion->newerOrEqual($emulatorPhpVersion) + && $this->targetPhpVersion->older($emulatorPhpVersion); } - private function sortPatches() - { + private function sortPatches(): void { // Patches may be contributed by different emulators. // Make sure they are sorted by increasing patch position. - usort($this->patches, function($p1, $p2) { + usort($this->patches, function ($p1, $p2) { return $p1[0] <=> $p2[0]; }); } - private function fixupTokens() - { + /** + * @param list $tokens + * @return list + */ + private function fixupTokens(array $tokens): array { if (\count($this->patches) === 0) { - return; + return $tokens; } // Load first patch $patchIdx = 0; - list($patchPos, $patchType, $patchText) = $this->patches[$patchIdx]; // We use a manual loop over the tokens, because we modify the array on the fly - $pos = 0; - for ($i = 0, $c = \count($this->tokens); $i < $c; $i++) { - $token = $this->tokens[$i]; - if (\is_string($token)) { - if ($patchPos === $pos) { - // Only support replacement for string tokens. - assert($patchType === 'replace'); - $this->tokens[$i] = $patchText; - - // Fetch the next patch - $patchIdx++; - if ($patchIdx >= \count($this->patches)) { - // No more patches, we're done - return; - } - list($patchPos, $patchType, $patchText) = $this->patches[$patchIdx]; - } - - $pos += \strlen($token); - continue; - } - - $len = \strlen($token[1]); - $posDelta = 0; + $posDelta = 0; + $lineDelta = 0; + for ($i = 0, $c = \count($tokens); $i < $c; $i++) { + $token = $tokens[$i]; + $pos = $token->pos; + $token->pos += $posDelta; + $token->line += $lineDelta; + $localPosDelta = 0; + $len = \strlen($token->text); while ($patchPos >= $pos && $patchPos < $pos + $len) { $patchTextLen = \strlen($patchText); if ($patchType === 'remove') { if ($patchPos === $pos && $patchTextLen === $len) { // Remove token entirely - array_splice($this->tokens, $i, 1, []); + array_splice($tokens, $i, 1, []); $i--; $c--; } else { // Remove from token string - $this->tokens[$i][1] = substr_replace( - $token[1], '', $patchPos - $pos + $posDelta, $patchTextLen + $token->text = substr_replace( + $token->text, '', $patchPos - $pos + $localPosDelta, $patchTextLen ); - $posDelta -= $patchTextLen; + $localPosDelta -= $patchTextLen; } + $lineDelta -= \substr_count($patchText, "\n"); } elseif ($patchType === 'add') { // Insert into the token string - $this->tokens[$i][1] = substr_replace( - $token[1], $patchText, $patchPos - $pos + $posDelta, 0 + $token->text = substr_replace( + $token->text, $patchText, $patchPos - $pos + $localPosDelta, 0 ); - $posDelta += $patchTextLen; - } else if ($patchType === 'replace') { + $localPosDelta += $patchTextLen; + $lineDelta += \substr_count($patchText, "\n"); + } elseif ($patchType === 'replace') { // Replace inside the token string - $this->tokens[$i][1] = substr_replace( - $token[1], $patchText, $patchPos - $pos + $posDelta, $patchTextLen + $token->text = substr_replace( + $token->text, $patchText, $patchPos - $pos + $localPosDelta, $patchTextLen ); } else { assert(false); @@ -189,22 +180,17 @@ private function fixupTokens() // Fetch the next patch $patchIdx++; if ($patchIdx >= \count($this->patches)) { - // No more patches, we're done - return; + // No more patches. However, we still need to adjust position. + $patchPos = \PHP_INT_MAX; + break; } list($patchPos, $patchType, $patchText) = $this->patches[$patchIdx]; - - // Multiple patches may apply to the same token. Reload the current one to check - // If the new patch applies - $token = $this->tokens[$i]; } - $pos += $len; + $posDelta += $localPosDelta; } - - // A patch did not apply - assert(false); + return $tokens; } /** @@ -212,7 +198,7 @@ private function fixupTokens() * * @param Error[] $errors */ - private function fixupErrors(array $errors) { + private function fixupErrors(array $errors): void { foreach ($errors as $error) { $attrs = $error->getAttributes(); @@ -228,7 +214,7 @@ private function fixupErrors(array $errors) { if ($patchType === 'add') { $posDelta += strlen($patchText); $lineDelta += substr_count($patchText, "\n"); - } else if ($patchType === 'remove') { + } elseif ($patchType === 'remove') { $posDelta -= strlen($patchText); $lineDelta -= substr_count($patchText, "\n"); } diff --git a/lib/PhpParser/Lexer/TokenEmulator/AsymmetricVisibilityTokenEmulator.php b/lib/PhpParser/Lexer/TokenEmulator/AsymmetricVisibilityTokenEmulator.php new file mode 100644 index 0000000000..084bb75dcc --- /dev/null +++ b/lib/PhpParser/Lexer/TokenEmulator/AsymmetricVisibilityTokenEmulator.php @@ -0,0 +1,93 @@ + \T_PUBLIC_SET, + \T_PROTECTED => \T_PROTECTED_SET, + \T_PRIVATE => \T_PRIVATE_SET, + ]; + for ($i = 0, $c = count($tokens); $i < $c; ++$i) { + $token = $tokens[$i]; + if (isset($map[$token->id]) && $i + 3 < $c && $tokens[$i + 1]->text === '(' && + $tokens[$i + 2]->id === \T_STRING && \strtolower($tokens[$i + 2]->text) === 'set' && + $tokens[$i + 3]->text === ')' && + $this->isKeywordContext($tokens, $i) + ) { + array_splice($tokens, $i, 4, [ + new Token( + $map[$token->id], $token->text . '(' . $tokens[$i + 2]->text . ')', + $token->line, $token->pos), + ]); + $c -= 3; + } + } + + return $tokens; + } + + public function reverseEmulate(string $code, array $tokens): array { + $reverseMap = [ + \T_PUBLIC_SET => \T_PUBLIC, + \T_PROTECTED_SET => \T_PROTECTED, + \T_PRIVATE_SET => \T_PRIVATE, + ]; + for ($i = 0, $c = count($tokens); $i < $c; ++$i) { + $token = $tokens[$i]; + if (isset($reverseMap[$token->id]) && + \preg_match('/(public|protected|private)\((set)\)/i', $token->text, $matches) + ) { + [, $modifier, $set] = $matches; + $modifierLen = \strlen($modifier); + array_splice($tokens, $i, 1, [ + new Token($reverseMap[$token->id], $modifier, $token->line, $token->pos), + new Token(\ord('('), '(', $token->line, $token->pos + $modifierLen), + new Token(\T_STRING, $set, $token->line, $token->pos + $modifierLen + 1), + new Token(\ord(')'), ')', $token->line, $token->pos + $modifierLen + 4), + ]); + $i += 3; + $c += 3; + } + } + + return $tokens; + } + + /** @param Token[] $tokens */ + protected function isKeywordContext(array $tokens, int $pos): bool { + $prevToken = $this->getPreviousNonSpaceToken($tokens, $pos); + if ($prevToken === null) { + return false; + } + return $prevToken->id !== \T_OBJECT_OPERATOR + && $prevToken->id !== \T_NULLSAFE_OBJECT_OPERATOR; + } + + /** @param Token[] $tokens */ + private function getPreviousNonSpaceToken(array $tokens, int $start): ?Token { + for ($i = $start - 1; $i >= 0; --$i) { + if ($tokens[$i]->id === T_WHITESPACE) { + continue; + } + + return $tokens[$i]; + } + + return null; + } +} diff --git a/lib/PhpParser/Lexer/TokenEmulator/AttributeEmulator.php b/lib/PhpParser/Lexer/TokenEmulator/AttributeEmulator.php index 6776a51975..2c12f33ae6 100644 --- a/lib/PhpParser/Lexer/TokenEmulator/AttributeEmulator.php +++ b/lib/PhpParser/Lexer/TokenEmulator/AttributeEmulator.php @@ -2,43 +2,36 @@ namespace PhpParser\Lexer\TokenEmulator; -use PhpParser\Lexer\Emulative; +use PhpParser\PhpVersion; +use PhpParser\Token; -final class AttributeEmulator extends TokenEmulator -{ - public function getPhpVersion(): string - { - return Emulative::PHP_8_0; +final class AttributeEmulator extends TokenEmulator { + public function getPhpVersion(): PhpVersion { + return PhpVersion::fromComponents(8, 0); } - public function isEmulationNeeded(string $code) : bool - { + public function isEmulationNeeded(string $code): bool { return strpos($code, '#[') !== false; } - public function emulate(string $code, array $tokens): array - { + 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 ($tokens[$i] === '#' && isset($tokens[$i + 1]) && $tokens[$i + 1] === '[') { + $token = $tokens[$i]; + if ($token->text === '#' && isset($tokens[$i + 1]) && $tokens[$i + 1]->text === '[') { array_splice($tokens, $i, 2, [ - [\T_ATTRIBUTE, '#[', $line] + new Token(\T_ATTRIBUTE, '#[', $token->line, $token->pos), ]); $c--; continue; } - if (\is_array($tokens[$i])) { - $line += substr_count($tokens[$i][1], "\n"); - } } return $tokens; } - public function reverseEmulate(string $code, array $tokens): array - { + public function reverseEmulate(string $code, array $tokens): array { // TODO return $tokens; } diff --git a/lib/PhpParser/Lexer/TokenEmulator/CoaleseEqualTokenEmulator.php b/lib/PhpParser/Lexer/TokenEmulator/CoaleseEqualTokenEmulator.php deleted file mode 100644 index d91da92143..0000000000 --- a/lib/PhpParser/Lexer/TokenEmulator/CoaleseEqualTokenEmulator.php +++ /dev/null @@ -1,47 +0,0 @@ -id === \T_WHITESPACE + && $tokens[$pos + 2]->id === \T_STRING; } -} \ No newline at end of file +} diff --git a/lib/PhpParser/Lexer/TokenEmulator/ExplicitOctalEmulator.php b/lib/PhpParser/Lexer/TokenEmulator/ExplicitOctalEmulator.php new file mode 100644 index 0000000000..9cadf420c0 --- /dev/null +++ b/lib/PhpParser/Lexer/TokenEmulator/ExplicitOctalEmulator.php @@ -0,0 +1,45 @@ +id == \T_LNUMBER && $token->text === '0' && + isset($tokens[$i + 1]) && $tokens[$i + 1]->id == \T_STRING && + preg_match('/[oO][0-7]+(?:_[0-7]+)*/', $tokens[$i + 1]->text) + ) { + $tokenKind = $this->resolveIntegerOrFloatToken($tokens[$i + 1]->text); + array_splice($tokens, $i, 2, [ + new Token($tokenKind, '0' . $tokens[$i + 1]->text, $token->line, $token->pos), + ]); + $c--; + } + } + return $tokens; + } + + private function resolveIntegerOrFloatToken(string $str): int { + $str = substr($str, 1); + $str = str_replace('_', '', $str); + $num = octdec($str); + return is_float($num) ? \T_DNUMBER : \T_LNUMBER; + } + + public function reverseEmulate(string $code, array $tokens): array { + // Explicit octals were not legal code previously, don't bother. + return $tokens; + } +} diff --git a/lib/PhpParser/Lexer/TokenEmulator/FlexibleDocStringEmulator.php b/lib/PhpParser/Lexer/TokenEmulator/FlexibleDocStringEmulator.php deleted file mode 100644 index c15d6271fc..0000000000 --- a/lib/PhpParser/Lexer/TokenEmulator/FlexibleDocStringEmulator.php +++ /dev/null @@ -1,76 +0,0 @@ -\h*)\2(?![a-zA-Z0-9_\x80-\xff])(?(?:;?[\r\n])?)/x -REGEX; - - public function getPhpVersion(): string - { - return Emulative::PHP_7_3; - } - - public function isEmulationNeeded(string $code) : bool - { - return strpos($code, '<<<') !== false; - } - - public function emulate(string $code, array $tokens): array - { - // Handled by preprocessing + fixup. - return $tokens; - } - - public function reverseEmulate(string $code, array $tokens): array - { - // Not supported. - return $tokens; - } - - public function preprocessCode(string $code, array &$patches): string { - if (!preg_match_all(self::FLEXIBLE_DOC_STRING_REGEX, $code, $matches, PREG_SET_ORDER|PREG_OFFSET_CAPTURE)) { - // No heredoc/nowdoc found - return $code; - } - - // Keep track of how much we need to adjust string offsets due to the modifications we - // already made - $posDelta = 0; - foreach ($matches as $match) { - $indentation = $match['indentation'][0]; - $indentationStart = $match['indentation'][1]; - - $separator = $match['separator'][0]; - $separatorStart = $match['separator'][1]; - - if ($indentation === '' && $separator !== '') { - // Ordinary heredoc/nowdoc - continue; - } - - if ($indentation !== '') { - // Remove indentation - $indentationLen = strlen($indentation); - $code = substr_replace($code, '', $indentationStart + $posDelta, $indentationLen); - $patches[] = [$indentationStart + $posDelta, 'add', $indentation]; - $posDelta -= $indentationLen; - } - - if ($separator === '') { - // Insert newline as separator - $code = substr_replace($code, "\n", $separatorStart + $posDelta, 0); - $patches[] = [$separatorStart + $posDelta, 'remove', "\n"]; - $posDelta += 1; - } - } - - return $code; - } -} diff --git a/lib/PhpParser/Lexer/TokenEmulator/FnTokenEmulator.php b/lib/PhpParser/Lexer/TokenEmulator/FnTokenEmulator.php deleted file mode 100644 index eb7e49634a..0000000000 --- a/lib/PhpParser/Lexer/TokenEmulator/FnTokenEmulator.php +++ /dev/null @@ -1,23 +0,0 @@ -getKeywordString()) !== false; } - protected function isKeywordContext(array $tokens, int $pos): bool - { - $previousNonSpaceToken = $this->getPreviousNonSpaceToken($tokens, $pos); - return $previousNonSpaceToken === null || $previousNonSpaceToken[0] !== \T_OBJECT_OPERATOR; + /** @param Token[] $tokens */ + protected function isKeywordContext(array $tokens, int $pos): bool { + $prevToken = $this->getPreviousNonSpaceToken($tokens, $pos); + if ($prevToken === null) { + return false; + } + return $prevToken->id !== \T_OBJECT_OPERATOR + && $prevToken->id !== \T_NULLSAFE_OBJECT_OPERATOR; } - public function emulate(string $code, array $tokens): array - { + public function emulate(string $code, array $tokens): array { $keywordString = $this->getKeywordString(); foreach ($tokens as $i => $token) { - if ($token[0] === T_STRING && strtolower($token[1]) === $keywordString + if ($token->id === T_STRING && strtolower($token->text) === $keywordString && $this->isKeywordContext($tokens, $i)) { - $tokens[$i][0] = $this->getKeywordToken(); + $token->id = $this->getKeywordToken(); } } return $tokens; } - /** - * @param mixed[] $tokens - * @return mixed[]|null - */ - private function getPreviousNonSpaceToken(array $tokens, int $start) - { + /** @param Token[] $tokens */ + private function getPreviousNonSpaceToken(array $tokens, int $start): ?Token { for ($i = $start - 1; $i >= 0; --$i) { - if ($tokens[$i][0] === T_WHITESPACE) { + if ($tokens[$i]->id === T_WHITESPACE) { continue; } @@ -48,12 +47,11 @@ private function getPreviousNonSpaceToken(array $tokens, int $start) return null; } - public function reverseEmulate(string $code, array $tokens): array - { + public function reverseEmulate(string $code, array $tokens): array { $keywordToken = $this->getKeywordToken(); - foreach ($tokens as $i => $token) { - if ($token[0] === $keywordToken) { - $tokens[$i][0] = \T_STRING; + foreach ($tokens as $token) { + if ($token->id === $keywordToken) { + $token->id = \T_STRING; } } diff --git a/lib/PhpParser/Lexer/TokenEmulator/MatchTokenEmulator.php b/lib/PhpParser/Lexer/TokenEmulator/MatchTokenEmulator.php index 902a46dfcb..0fa5fbc2f2 100644 --- a/lib/PhpParser/Lexer/TokenEmulator/MatchTokenEmulator.php +++ b/lib/PhpParser/Lexer/TokenEmulator/MatchTokenEmulator.php @@ -2,22 +2,18 @@ namespace PhpParser\Lexer\TokenEmulator; -use PhpParser\Lexer\Emulative; +use PhpParser\PhpVersion; -final class MatchTokenEmulator extends KeywordEmulator -{ - public function getPhpVersion(): string - { - return Emulative::PHP_8_0; +final class MatchTokenEmulator extends KeywordEmulator { + public function getPhpVersion(): PhpVersion { + return PhpVersion::fromComponents(8, 0); } - public function getKeywordString(): string - { + public function getKeywordString(): string { return 'match'; } - public function getKeywordToken(): int - { + public function getKeywordToken(): int { return \T_MATCH; } } diff --git a/lib/PhpParser/Lexer/TokenEmulator/NullsafeTokenEmulator.php b/lib/PhpParser/Lexer/TokenEmulator/NullsafeTokenEmulator.php index 1a29c676e4..cede96f0f7 100644 --- a/lib/PhpParser/Lexer/TokenEmulator/NullsafeTokenEmulator.php +++ b/lib/PhpParser/Lexer/TokenEmulator/NullsafeTokenEmulator.php @@ -2,65 +2,58 @@ namespace PhpParser\Lexer\TokenEmulator; -use PhpParser\Lexer\Emulative; +use PhpParser\PhpVersion; +use PhpParser\Token; -final class NullsafeTokenEmulator extends TokenEmulator -{ - public function getPhpVersion(): string - { - return Emulative::PHP_8_0; +final class NullsafeTokenEmulator extends TokenEmulator { + public function getPhpVersion(): PhpVersion { + return PhpVersion::fromComponents(8, 0); } - public function isEmulationNeeded(string $code): bool - { + public function isEmulationNeeded(string $code): bool { return strpos($code, '?->') !== false; } - public function emulate(string $code, array $tokens): array - { + 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 ($tokens[$i] === '?' && isset($tokens[$i + 1]) && $tokens[$i + 1][0] === \T_OBJECT_OPERATOR) { + $token = $tokens[$i]; + if ($token->text === '?' && isset($tokens[$i + 1]) && $tokens[$i + 1]->id === \T_OBJECT_OPERATOR) { array_splice($tokens, $i, 2, [ - [\T_NULLSAFE_OBJECT_OPERATOR, '?->', $line] + new Token(\T_NULLSAFE_OBJECT_OPERATOR, '?->', $token->line, $token->pos), ]); $c--; continue; } // Handle ?-> inside encapsed string. - if ($tokens[$i][0] === \T_ENCAPSED_AND_WHITESPACE && isset($tokens[$i - 1]) - && $tokens[$i - 1][0] === \T_VARIABLE - && preg_match('/^\?->([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/', $tokens[$i][1], $matches) + if ($token->id === \T_ENCAPSED_AND_WHITESPACE && isset($tokens[$i - 1]) + && $tokens[$i - 1]->id === \T_VARIABLE + && preg_match('/^\?->([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/', $token->text, $matches) ) { $replacement = [ - [\T_NULLSAFE_OBJECT_OPERATOR, '?->', $line], - [\T_STRING, $matches[1], $line], + new Token(\T_NULLSAFE_OBJECT_OPERATOR, '?->', $token->line, $token->pos), + new Token(\T_STRING, $matches[1], $token->line, $token->pos + 3), ]; - if (\strlen($matches[0]) !== \strlen($tokens[$i][1])) { - $replacement[] = [ + $matchLen = \strlen($matches[0]); + if ($matchLen !== \strlen($token->text)) { + $replacement[] = new Token( \T_ENCAPSED_AND_WHITESPACE, - \substr($tokens[$i][1], \strlen($matches[0])), - $line - ]; + \substr($token->text, $matchLen), + $token->line, $token->pos + $matchLen + ); } array_splice($tokens, $i, 1, $replacement); $c += \count($replacement) - 1; continue; } - - if (\is_array($tokens[$i])) { - $line += substr_count($tokens[$i][1], "\n"); - } } return $tokens; } - public function reverseEmulate(string $code, array $tokens): array - { + public function reverseEmulate(string $code, array $tokens): array { // ?-> was not valid code previously, don't bother. return $tokens; } diff --git a/lib/PhpParser/Lexer/TokenEmulator/NumericLiteralSeparatorEmulator.php b/lib/PhpParser/Lexer/TokenEmulator/NumericLiteralSeparatorEmulator.php deleted file mode 100644 index cdf793e46e..0000000000 --- a/lib/PhpParser/Lexer/TokenEmulator/NumericLiteralSeparatorEmulator.php +++ /dev/null @@ -1,105 +0,0 @@ -resolveIntegerOrFloatToken($match); - $newTokens = [[$tokenKind, $match, $token[2]]]; - - $numTokens = 1; - $len = $tokenLen; - while ($matchLen > $len) { - $nextToken = $tokens[$i + $numTokens]; - $nextTokenText = \is_array($nextToken) ? $nextToken[1] : $nextToken; - $nextTokenLen = \strlen($nextTokenText); - - $numTokens++; - if ($matchLen < $len + $nextTokenLen) { - // Split trailing characters into a partial token. - assert(is_array($nextToken), "Partial token should be an array token"); - $partialText = substr($nextTokenText, $matchLen - $len); - $newTokens[] = [$nextToken[0], $partialText, $nextToken[2]]; - break; - } - - $len += $nextTokenLen; - } - - array_splice($tokens, $i, $numTokens, $newTokens); - $c -= $numTokens - \count($newTokens); - $codeOffset += $matchLen; - } - - return $tokens; - } - - private function resolveIntegerOrFloatToken(string $str): int - { - $str = str_replace('_', '', $str); - - if (stripos($str, '0b') === 0) { - $num = bindec($str); - } elseif (stripos($str, '0x') === 0) { - $num = hexdec($str); - } elseif (stripos($str, '0') === 0 && ctype_digit($str)) { - $num = octdec($str); - } else { - $num = +$str; - } - - return is_float($num) ? T_DNUMBER : T_LNUMBER; - } - - public function reverseEmulate(string $code, array $tokens): array - { - // Numeric separators were not legal code previously, don't bother. - return $tokens; - } -} diff --git a/lib/PhpParser/Lexer/TokenEmulator/PipeOperatorEmulator.php b/lib/PhpParser/Lexer/TokenEmulator/PipeOperatorEmulator.php new file mode 100644 index 0000000000..b561692395 --- /dev/null +++ b/lib/PhpParser/Lexer/TokenEmulator/PipeOperatorEmulator.php @@ -0,0 +1,45 @@ +') !== false; + } + + public function emulate(string $code, array $tokens): array { + for ($i = 0, $c = count($tokens); $i < $c; ++$i) { + $token = $tokens[$i]; + if ($token->text === '|' && isset($tokens[$i + 1]) && $tokens[$i + 1]->text === '>') { + array_splice($tokens, $i, 2, [ + new Token(\T_PIPE, '|>', $token->line, $token->pos), + ]); + $c--; + } + } + return $tokens; + } + + public function reverseEmulate(string $code, array $tokens): array { + for ($i = 0, $c = count($tokens); $i < $c; ++$i) { + $token = $tokens[$i]; + if ($token->id === \T_PIPE) { + array_splice($tokens, $i, 1, [ + new Token(\ord('|'), '|', $token->line, $token->pos), + new Token(\ord('>'), '>', $token->line, $token->pos + 1), + ]); + $i++; + $c++; + } + } + return $tokens; + } +} diff --git a/lib/PhpParser/Lexer/TokenEmulator/PropertyTokenEmulator.php b/lib/PhpParser/Lexer/TokenEmulator/PropertyTokenEmulator.php new file mode 100644 index 0000000000..71b7fc232d --- /dev/null +++ b/lib/PhpParser/Lexer/TokenEmulator/PropertyTokenEmulator.php @@ -0,0 +1,19 @@ +text === '(' || + ($tokens[$pos + 1]->id === \T_WHITESPACE && + isset($tokens[$pos + 2]) && + $tokens[$pos + 2]->text === '('))); + } +} diff --git a/lib/PhpParser/Lexer/TokenEmulator/ReverseEmulator.php b/lib/PhpParser/Lexer/TokenEmulator/ReverseEmulator.php index 90093f66b2..851b5c4acf 100644 --- a/lib/PhpParser/Lexer/TokenEmulator/ReverseEmulator.php +++ b/lib/PhpParser/Lexer/TokenEmulator/ReverseEmulator.php @@ -2,19 +2,20 @@ namespace PhpParser\Lexer\TokenEmulator; +use PhpParser\PhpVersion; + /** * Reverses emulation direction of the inner emulator. */ -final class ReverseEmulator extends TokenEmulator -{ +final class ReverseEmulator extends TokenEmulator { /** @var TokenEmulator Inner emulator */ - private $emulator; + private TokenEmulator $emulator; public function __construct(TokenEmulator $emulator) { $this->emulator = $emulator; } - public function getPhpVersion(): string { + public function getPhpVersion(): PhpVersion { return $this->emulator->getPhpVersion(); } @@ -33,4 +34,4 @@ public function reverseEmulate(string $code, array $tokens): array { public function preprocessCode(string $code, array &$patches): string { return $code; } -} \ No newline at end of file +} diff --git a/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php b/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php index a020bc0ff4..fec2f19f44 100644 --- a/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php +++ b/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php @@ -2,23 +2,28 @@ namespace PhpParser\Lexer\TokenEmulator; +use PhpParser\PhpVersion; +use PhpParser\Token; + /** @internal */ -abstract class TokenEmulator -{ - abstract public function getPhpVersion(): string; +abstract class TokenEmulator { + abstract public function getPhpVersion(): PhpVersion; abstract public function isEmulationNeeded(string $code): bool; /** - * @return array Modified Tokens + * @param Token[] $tokens Original tokens + * @return Token[] Modified Tokens */ abstract public function emulate(string $code, array $tokens): array; /** - * @return array Modified Tokens + * @param Token[] $tokens Original tokens + * @return Token[] Modified Tokens */ abstract public function reverseEmulate(string $code, array $tokens): array; + /** @param array{int, string, string}[] $patches */ public function preprocessCode(string $code, array &$patches): string { return $code; } diff --git a/lib/PhpParser/Lexer/TokenEmulator/VoidCastEmulator.php b/lib/PhpParser/Lexer/TokenEmulator/VoidCastEmulator.php new file mode 100644 index 0000000000..b6dcacf667 --- /dev/null +++ b/lib/PhpParser/Lexer/TokenEmulator/VoidCastEmulator.php @@ -0,0 +1,98 @@ +text !== '(') { + continue; + } + + $numTokens = 1; + $text = '('; + $j = $i + 1; + if ($j < $c && $tokens[$j]->id === \T_WHITESPACE && preg_match('/[ \t]+/', $tokens[$j]->text)) { + $text .= $tokens[$j]->text; + $numTokens++; + $j++; + } + + if ($j >= $c || $tokens[$j]->id !== \T_STRING || \strtolower($tokens[$j]->text) !== 'void') { + continue; + } + + $text .= $tokens[$j]->text; + $numTokens++; + $k = $j + 1; + if ($k < $c && $tokens[$k]->id === \T_WHITESPACE && preg_match('/[ \t]+/', $tokens[$k]->text)) { + $text .= $tokens[$k]->text; + $numTokens++; + $k++; + } + + if ($k >= $c || $tokens[$k]->text !== ')') { + continue; + } + + $text .= ')'; + $numTokens++; + array_splice($tokens, $i, $numTokens, [ + new Token(\T_VOID_CAST, $text, $token->line, $token->pos), + ]); + $c -= $numTokens - 1; + } + return $tokens; + } + + public function reverseEmulate(string $code, array $tokens): array { + for ($i = 0, $c = count($tokens); $i < $c; ++$i) { + $token = $tokens[$i]; + if ($token->id !== \T_VOID_CAST) { + continue; + } + + if (!preg_match('/^\(([ \t]*)(void)([ \t]*)\)$/i', $token->text, $match)) { + throw new \LogicException('Unexpected T_VOID_CAST contents'); + } + + $newTokens = []; + $pos = $token->pos; + + $newTokens[] = new Token(\ord('('), '(', $token->line, $pos); + $pos++; + + if ($match[1] !== '') { + $newTokens[] = new Token(\T_WHITESPACE, $match[1], $token->line, $pos); + $pos += \strlen($match[1]); + } + + $newTokens[] = new Token(\T_STRING, $match[2], $token->line, $pos); + $pos += \strlen($match[2]); + + if ($match[3] !== '') { + $newTokens[] = new Token(\T_WHITESPACE, $match[3], $token->line, $pos); + $pos += \strlen($match[3]); + } + + $newTokens[] = new Token(\ord(')'), ')', $token->line, $pos); + + array_splice($tokens, $i, 1, $newTokens); + $i += \count($newTokens) - 1; + $c += \count($newTokens) - 1; + } + return $tokens; + } +} diff --git a/lib/PhpParser/Modifiers.php b/lib/PhpParser/Modifiers.php new file mode 100644 index 0000000000..0f0f22d6bb --- /dev/null +++ b/lib/PhpParser/Modifiers.php @@ -0,0 +1,85 @@ + 'public', + self::PROTECTED => 'protected', + self::PRIVATE => 'private', + self::STATIC => 'static', + self::ABSTRACT => 'abstract', + self::FINAL => 'final', + self::READONLY => 'readonly', + self::PUBLIC_SET => 'public(set)', + self::PROTECTED_SET => 'protected(set)', + self::PRIVATE_SET => 'private(set)', + ]; + + public static function toString(int $modifier): string { + if (!isset(self::TO_STRING_MAP[$modifier])) { + throw new \InvalidArgumentException("Unknown modifier $modifier"); + } + return self::TO_STRING_MAP[$modifier]; + } + + private static function isValidModifier(int $modifier): bool { + $isPow2 = ($modifier & ($modifier - 1)) == 0 && $modifier != 0; + return $isPow2 && $modifier <= self::PRIVATE_SET; + } + + /** + * @internal + */ + public static function verifyClassModifier(int $a, int $b): void { + assert(self::isValidModifier($b)); + if (($a & $b) != 0) { + throw new Error( + 'Multiple ' . self::toString($b) . ' modifiers are not allowed'); + } + + if ($a & 48 && $b & 48) { + throw new Error('Cannot use the final modifier on an abstract class'); + } + } + + /** + * @internal + */ + public static function verifyModifier(int $a, int $b): void { + assert(self::isValidModifier($b)); + if (($a & Modifiers::VISIBILITY_MASK && $b & Modifiers::VISIBILITY_MASK) || + ($a & Modifiers::VISIBILITY_SET_MASK && $b & Modifiers::VISIBILITY_SET_MASK) + ) { + throw new Error('Multiple access type modifiers are not allowed'); + } + + if (($a & $b) != 0) { + throw new Error( + 'Multiple ' . self::toString($b) . ' modifiers are not allowed'); + } + + if ($a & 48 && $b & 48) { + throw new Error('Cannot use the final modifier on an abstract class member'); + } + } +} diff --git a/lib/PhpParser/NameContext.php b/lib/PhpParser/NameContext.php index 777a4afdee..2265ecce82 100644 --- a/lib/PhpParser/NameContext.php +++ b/lib/PhpParser/NameContext.php @@ -6,19 +6,18 @@ use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt; -class NameContext -{ +class NameContext { /** @var null|Name Current namespace */ - protected $namespace; + protected ?Name $namespace; /** @var Name[][] Map of format [aliasType => [aliasName => originalName]] */ - protected $aliases = []; + protected array $aliases = []; /** @var Name[][] Same as $aliases but preserving original case */ - protected $origAliases = []; + protected array $origAliases = []; /** @var ErrorHandler Error handler */ - protected $errorHandler; + protected ErrorHandler $errorHandler; /** * Create a name context. @@ -36,7 +35,7 @@ public function __construct(ErrorHandler $errorHandler) { * * @param Name|null $namespace Null is the global namespace */ - public function startNamespace(Name $namespace = null) { + public function startNamespace(?Name $namespace = null): void { $this->namespace = $namespace; $this->origAliases = $this->aliases = [ Stmt\Use_::TYPE_NORMAL => [], @@ -48,12 +47,12 @@ public function startNamespace(Name $namespace = null) { /** * Add an alias / import. * - * @param Name $name Original name - * @param string $aliasName Aliased name - * @param int $type One of Stmt\Use_::TYPE_* - * @param array $errorAttrs Attributes to use to report an error + * @param Name $name Original name + * @param string $aliasName Aliased name + * @param Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_* + * @param array $errorAttrs Attributes to use to report an error */ - public function addAlias(Name $name, string $aliasName, int $type, array $errorAttrs = []) { + public function addAlias(Name $name, string $aliasName, int $type, array $errorAttrs = []): void { // Constant names are case sensitive, everything else case insensitive if ($type === Stmt\Use_::TYPE_CONSTANT) { $aliasLookupName = $aliasName; @@ -87,7 +86,7 @@ public function addAlias(Name $name, string $aliasName, int $type, array $errorA * * @return null|Name Namespace (or null if global namespace) */ - public function getNamespace() { + public function getNamespace(): ?Name { return $this->namespace; } @@ -95,11 +94,11 @@ public function getNamespace() { * Get resolved name. * * @param Name $name Name to resolve - * @param int $type One of Stmt\Use_::TYPE_{FUNCTION|CONSTANT} + * @param Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_{FUNCTION|CONSTANT} * * @return null|Name Resolved name, or null if static resolution is not possible */ - public function getResolvedName(Name $name, int $type) { + public function getResolvedName(Name $name, int $type): ?Name { // don't resolve special class names if ($type === Stmt\Use_::TYPE_NORMAL && $name->isSpecialClassName()) { if (!$name->isUnqualified()) { @@ -142,7 +141,7 @@ public function getResolvedName(Name $name, int $type) { * * @return Name Resolved name */ - public function getResolvedClassName(Name $name) : Name { + public function getResolvedClassName(Name $name): Name { return $this->getResolvedName($name, Stmt\Use_::TYPE_NORMAL); } @@ -150,11 +149,11 @@ public function getResolvedClassName(Name $name) : Name { * Get possible ways of writing a fully qualified name (e.g., by making use of aliases). * * @param string $name Fully-qualified name (without leading namespace separator) - * @param int $type One of Stmt\Use_::TYPE_* + * @param Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_* * * @return Name[] Possible representations of the name */ - public function getPossibleNames(string $name, int $type) : array { + public function getPossibleNames(string $name, int $type): array { $lcName = strtolower($name); if ($type === Stmt\Use_::TYPE_NORMAL) { @@ -186,7 +185,7 @@ public function getPossibleNames(string $name, int $type) : array { // Check for relevant type-specific use statements foreach ($this->origAliases[$type] as $alias => $orig) { if ($type === Stmt\Use_::TYPE_CONSTANT) { - // Constants are are complicated-sensitive + // Constants are complicated-sensitive $normalizedOrig = $this->normalizeConstName($orig->toString()); if ($normalizedOrig === $this->normalizeConstName($name)) { $possibleNames[] = new Name($alias); @@ -206,11 +205,11 @@ public function getPossibleNames(string $name, int $type) : array { * Get shortest representation of this fully-qualified name. * * @param string $name Fully-qualified name (without leading namespace separator) - * @param int $type One of Stmt\Use_::TYPE_* + * @param Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_* * * @return Name Shortest representation */ - public function getShortName(string $name, int $type) : Name { + public function getShortName(string $name, int $type): Name { $possibleNames = $this->getPossibleNames($name, $type); // Find shortest name @@ -224,10 +223,10 @@ public function getShortName(string $name, int $type) : Name { } } - return $shortestName; + return $shortestName; } - private function resolveAlias(Name $name, $type) { + private function resolveAlias(Name $name, int $type): ?FullyQualified { $firstPart = $name->getFirst(); if ($name->isQualified()) { @@ -250,7 +249,7 @@ private function resolveAlias(Name $name, $type) { return null; } - private function getNamespaceRelativeName(string $name, string $lcName, int $type) { + private function getNamespaceRelativeName(string $name, string $lcName, int $type): ?Name { if (null === $this->namespace) { return new Name($name); } @@ -271,7 +270,7 @@ private function getNamespaceRelativeName(string $name, string $lcName, int $typ return null; } - private function normalizeConstName(string $name) { + private function normalizeConstName(string $name): string { $nsSep = strrpos($name, '\\'); if (false === $nsSep) { return $name; diff --git a/lib/PhpParser/Node.php b/lib/PhpParser/Node.php index befb256504..fd2a9b7247 100644 --- a/lib/PhpParser/Node.php +++ b/lib/PhpParser/Node.php @@ -2,28 +2,31 @@ namespace PhpParser; -interface Node -{ +interface Node { /** * Gets the type of the node. * + * @psalm-return non-empty-string * @return string Type of the node */ - public function getType() : string; + public function getType(): string; /** * Gets the names of the sub nodes. * - * @return array Names of sub nodes + * @return string[] Names of sub nodes */ - public function getSubNodeNames() : array; + public function getSubNodeNames(): array; /** * Gets line the node started in (alias of getStartLine). * * @return int Start line (or -1 if not available) + * @phpstan-return -1|positive-int + * + * @deprecated Use getStartLine() instead */ - public function getLine() : int; + public function getLine(): int; /** * Gets line the node started in. @@ -31,8 +34,9 @@ public function getLine() : int; * Requires the 'startLine' attribute to be enabled in the lexer (enabled by default). * * @return int Start line (or -1 if not available) + * @phpstan-return -1|positive-int */ - public function getStartLine() : int; + public function getStartLine(): int; /** * Gets the line the node ended in. @@ -40,8 +44,9 @@ public function getStartLine() : int; * Requires the 'endLine' attribute to be enabled in the lexer (enabled by default). * * @return int End line (or -1 if not available) + * @phpstan-return -1|positive-int */ - public function getEndLine() : int; + public function getEndLine(): int; /** * Gets the token offset of the first token that is part of this node. @@ -52,7 +57,7 @@ public function getEndLine() : int; * * @return int Token start position (or -1 if not available) */ - public function getStartTokenPos() : int; + public function getStartTokenPos(): int; /** * Gets the token offset of the last token that is part of this node. @@ -63,7 +68,7 @@ public function getStartTokenPos() : int; * * @return int Token end position (or -1 if not available) */ - public function getEndTokenPos() : int; + public function getEndTokenPos(): int; /** * Gets the file offset of the first character that is part of this node. @@ -72,7 +77,7 @@ public function getEndTokenPos() : int; * * @return int File start position (or -1 if not available) */ - public function getStartFilePos() : int; + public function getStartFilePos(): int; /** * Gets the file offset of the last character that is part of this node. @@ -81,7 +86,7 @@ public function getStartFilePos() : int; * * @return int File end position (or -1 if not available) */ - public function getEndFilePos() : int; + public function getEndFilePos(): int; /** * Gets all comments directly preceding this node. @@ -90,14 +95,14 @@ public function getEndFilePos() : int; * * @return Comment[] */ - public function getComments() : array; + public function getComments(): array; /** * Gets the doc comment of the node. * * @return null|Comment\Doc Doc comment object or null */ - public function getDocComment(); + public function getDocComment(): ?Comment\Doc; /** * Sets the doc comment of the node. @@ -106,30 +111,24 @@ public function getDocComment(); * * @param Comment\Doc $docComment Doc comment to set */ - public function setDocComment(Comment\Doc $docComment); + public function setDocComment(Comment\Doc $docComment): void; /** * Sets an attribute on a node. * - * @param string $key - * @param mixed $value + * @param mixed $value */ - public function setAttribute(string $key, $value); + public function setAttribute(string $key, $value): void; /** * Returns whether an attribute exists. - * - * @param string $key - * - * @return bool */ - public function hasAttribute(string $key) : bool; + public function hasAttribute(string $key): bool; /** * Returns the value of an attribute. * - * @param string $key - * @param mixed $default + * @param mixed $default * * @return mixed */ @@ -138,14 +137,14 @@ public function getAttribute(string $key, $default = null); /** * Returns all the attributes of this node. * - * @return array + * @return array */ - public function getAttributes() : array; + public function getAttributes(): array; /** * Replaces all the attributes of this node. * - * @param array $attributes + * @param array $attributes */ - public function setAttributes(array $attributes); + public function setAttributes(array $attributes): void; } diff --git a/lib/PhpParser/Node/Arg.php b/lib/PhpParser/Node/Arg.php index b25b0904a2..6680efac98 100644 --- a/lib/PhpParser/Node/Arg.php +++ b/lib/PhpParser/Node/Arg.php @@ -4,29 +4,28 @@ use PhpParser\NodeAbstract; -class Arg extends NodeAbstract -{ +class Arg extends NodeAbstract { /** @var Identifier|null Parameter name (for named parameters) */ - public $name; + public ?Identifier $name; /** @var Expr Value to pass */ - public $value; + public Expr $value; /** @var bool Whether to pass by ref */ - public $byRef; + public bool $byRef; /** @var bool Whether to unpack the argument */ - public $unpack; + public bool $unpack; /** * Constructs a function call argument node. * - * @param Expr $value Value to pass - * @param bool $byRef Whether to pass by ref - * @param bool $unpack Whether to unpack the argument - * @param array $attributes Additional attributes + * @param Expr $value Value to pass + * @param bool $byRef Whether to pass by ref + * @param bool $unpack Whether to unpack the argument + * @param array $attributes Additional attributes * @param Identifier|null $name Parameter name (for named parameters) */ public function __construct( Expr $value, bool $byRef = false, bool $unpack = false, array $attributes = [], - Identifier $name = null + ?Identifier $name = null ) { $this->attributes = $attributes; $this->name = $name; @@ -35,11 +34,11 @@ public function __construct( $this->unpack = $unpack; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['name', 'value', 'byRef', 'unpack']; } - - public function getType() : string { + + public function getType(): string { return 'Arg'; } } diff --git a/lib/PhpParser/Node/ArrayItem.php b/lib/PhpParser/Node/ArrayItem.php new file mode 100644 index 0000000000..fa1cff5276 --- /dev/null +++ b/lib/PhpParser/Node/ArrayItem.php @@ -0,0 +1,43 @@ + $attributes Additional 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', 'unpack']; + } + + public function getType(): string { + return 'ArrayItem'; + } +} + +// @deprecated compatibility alias +class_alias(ArrayItem::class, Expr\ArrayItem::class); diff --git a/lib/PhpParser/Node/Attribute.php b/lib/PhpParser/Node/Attribute.php index c96f66e514..9d892436af 100644 --- a/lib/PhpParser/Node/Attribute.php +++ b/lib/PhpParser/Node/Attribute.php @@ -5,18 +5,17 @@ use PhpParser\Node; use PhpParser\NodeAbstract; -class Attribute extends NodeAbstract -{ +class Attribute extends NodeAbstract { /** @var Name Attribute name */ - public $name; + public Name $name; - /** @var Arg[] Attribute arguments */ - public $args; + /** @var list Attribute arguments */ + public array $args; /** - * @param Node\Name $name Attribute name - * @param Arg[] $args Attribute arguments - * @param array $attributes Additional node attributes + * @param Node\Name $name Attribute name + * @param list $args Attribute arguments + * @param array $attributes Additional node attributes */ public function __construct(Name $name, array $args = [], array $attributes = []) { $this->attributes = $attributes; @@ -24,11 +23,11 @@ public function __construct(Name $name, array $args = [], array $attributes = [] $this->args = $args; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['name', 'args']; } - public function getType() : string { + public function getType(): string { return 'Attribute'; } } diff --git a/lib/PhpParser/Node/AttributeGroup.php b/lib/PhpParser/Node/AttributeGroup.php index 613bfc4134..b9eb588d01 100644 --- a/lib/PhpParser/Node/AttributeGroup.php +++ b/lib/PhpParser/Node/AttributeGroup.php @@ -2,28 +2,26 @@ namespace PhpParser\Node; -use PhpParser\Node; use PhpParser\NodeAbstract; -class AttributeGroup extends NodeAbstract -{ +class AttributeGroup extends NodeAbstract { /** @var Attribute[] Attributes */ - public $attrs; + public array $attrs; /** * @param Attribute[] $attrs PHP attributes - * @param array $attributes Additional node attributes + * @param array $attributes Additional node attributes */ public function __construct(array $attrs, array $attributes = []) { $this->attributes = $attributes; $this->attrs = $attrs; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['attrs']; } - public function getType() : string { + public function getType(): string { return 'AttributeGroup'; } } diff --git a/lib/PhpParser/Node/ClosureUse.php b/lib/PhpParser/Node/ClosureUse.php new file mode 100644 index 0000000000..e313280b6c --- /dev/null +++ b/lib/PhpParser/Node/ClosureUse.php @@ -0,0 +1,36 @@ + $attributes Additional attributes + */ + public function __construct(Expr\Variable $var, bool $byRef = false, array $attributes = []) { + $this->attributes = $attributes; + $this->var = $var; + $this->byRef = $byRef; + } + + public function getSubNodeNames(): array { + return ['var', 'byRef']; + } + + public function getType(): string { + return 'ClosureUse'; + } +} + +// @deprecated compatibility alias +class_alias(ClosureUse::class, Expr\ClosureUse::class); diff --git a/lib/PhpParser/Node/ComplexType.php b/lib/PhpParser/Node/ComplexType.php new file mode 100644 index 0000000000..05a5e5eef4 --- /dev/null +++ b/lib/PhpParser/Node/ComplexType.php @@ -0,0 +1,13 @@ + $attributes Additional attributes */ public function __construct($name, Expr $value, array $attributes = []) { $this->attributes = $attributes; @@ -27,11 +26,11 @@ public function __construct($name, Expr $value, array $attributes = []) { $this->value = $value; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['name', 'value']; } - - public function getType() : string { + + public function getType(): string { return 'Const'; } } diff --git a/lib/PhpParser/Node/DeclareItem.php b/lib/PhpParser/Node/DeclareItem.php new file mode 100644 index 0000000000..55c1fe4f19 --- /dev/null +++ b/lib/PhpParser/Node/DeclareItem.php @@ -0,0 +1,37 @@ +value pair node. + * + * @param string|Node\Identifier $key Key + * @param Node\Expr $value Value + * @param array $attributes Additional attributes + */ + public function __construct($key, Node\Expr $value, array $attributes = []) { + $this->attributes = $attributes; + $this->key = \is_string($key) ? new Node\Identifier($key) : $key; + $this->value = $value; + } + + public function getSubNodeNames(): array { + return ['key', 'value']; + } + + public function getType(): string { + return 'DeclareItem'; + } +} + +// @deprecated compatibility alias +class_alias(DeclareItem::class, Stmt\DeclareDeclare::class); diff --git a/lib/PhpParser/Node/Expr.php b/lib/PhpParser/Node/Expr.php index 6cf4df2233..8b7dbb6ca8 100644 --- a/lib/PhpParser/Node/Expr.php +++ b/lib/PhpParser/Node/Expr.php @@ -4,6 +4,5 @@ use PhpParser\NodeAbstract; -abstract class Expr extends NodeAbstract -{ +abstract class Expr extends NodeAbstract { } diff --git a/lib/PhpParser/Node/Expr/ArrayDimFetch.php b/lib/PhpParser/Node/Expr/ArrayDimFetch.php index 71694478e9..24427bbc35 100644 --- a/lib/PhpParser/Node/Expr/ArrayDimFetch.php +++ b/lib/PhpParser/Node/Expr/ArrayDimFetch.php @@ -4,31 +4,30 @@ use PhpParser\Node\Expr; -class ArrayDimFetch extends Expr -{ +class ArrayDimFetch extends Expr { /** @var Expr Variable */ - public $var; + public Expr $var; /** @var null|Expr Array index / dim */ - public $dim; + public ?Expr $dim; /** * Constructs an array index fetch node. * - * @param Expr $var Variable - * @param null|Expr $dim Array index / dim - * @param array $attributes Additional attributes + * @param Expr $var Variable + * @param null|Expr $dim Array index / dim + * @param array $attributes Additional attributes */ - public function __construct(Expr $var, Expr $dim = null, array $attributes = []) { + public function __construct(Expr $var, ?Expr $dim = null, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; $this->dim = $dim; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['var', 'dim']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_ArrayDimFetch'; } } diff --git a/lib/PhpParser/Node/Expr/ArrayItem.php b/lib/PhpParser/Node/Expr/ArrayItem.php index 1b078f8218..be9d0708d1 100644 --- a/lib/PhpParser/Node/Expr/ArrayItem.php +++ b/lib/PhpParser/Node/Expr/ArrayItem.php @@ -2,40 +2,10 @@ namespace PhpParser\Node\Expr; -use PhpParser\Node\Expr; +require __DIR__ . '/../ArrayItem.php'; -class ArrayItem extends Expr -{ - /** @var null|Expr Key */ - public $key; - /** @var Expr Value */ - 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. - * - * @param Expr $value Value - * @param null|Expr $key Key - * @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 = [], 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', 'unpack']; - } - - public function getType() : string { - return 'Expr_ArrayItem'; +if (false) { + // For classmap-authoritative support. + class ArrayItem extends \PhpParser\Node\ArrayItem { } } diff --git a/lib/PhpParser/Node/Expr/Array_.php b/lib/PhpParser/Node/Expr/Array_.php index e6eaa2834d..3c8c9c2fcf 100644 --- a/lib/PhpParser/Node/Expr/Array_.php +++ b/lib/PhpParser/Node/Expr/Array_.php @@ -2,33 +2,33 @@ namespace PhpParser\Node\Expr; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr; -class Array_ extends Expr -{ +class Array_ extends Expr { // For use in "kind" attribute - const KIND_LONG = 1; // array() syntax - const KIND_SHORT = 2; // [] syntax + public const KIND_LONG = 1; // array() syntax + public const KIND_SHORT = 2; // [] syntax - /** @var (ArrayItem|null)[] Items */ - public $items; + /** @var ArrayItem[] Items */ + public array $items; /** * Constructs an array node. * - * @param (ArrayItem|null)[] $items Items of the array - * @param array $attributes Additional attributes + * @param ArrayItem[] $items Items of the array + * @param array $attributes Additional attributes */ public function __construct(array $items = [], array $attributes = []) { $this->attributes = $attributes; $this->items = $items; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['items']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_Array'; } } diff --git a/lib/PhpParser/Node/Expr/ArrowFunction.php b/lib/PhpParser/Node/Expr/ArrowFunction.php index d293f0ae41..0e98ce9f6b 100644 --- a/lib/PhpParser/Node/Expr/ArrowFunction.php +++ b/lib/PhpParser/Node/Expr/ArrowFunction.php @@ -6,55 +6,60 @@ use PhpParser\Node\Expr; use PhpParser\Node\FunctionLike; -class ArrowFunction extends Expr implements FunctionLike -{ - /** @var bool */ - public $static; +class ArrowFunction extends Expr implements FunctionLike { + /** @var bool Whether the closure is static */ + public bool $static; - /** @var bool */ - public $byRef; + /** @var bool Whether to return by reference */ + public bool $byRef; /** @var Node\Param[] */ - public $params = []; + public array $params = []; - /** @var null|Node\Identifier|Node\Name|Node\NullableType|Node\UnionType */ - public $returnType; + /** @var null|Node\Identifier|Node\Name|Node\ComplexType */ + public ?Node $returnType; - /** @var Expr */ - public $expr; + /** @var Expr Expression body */ + public Expr $expr; /** @var Node\AttributeGroup[] */ - public $attrGroups; + public array $attrGroups; /** - * @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 - * 'attrGroups' => array() : PHP attribute groups - * @param array $attributes Additional attributes + * @param array{ + * expr: Expr, + * static?: bool, + * byRef?: bool, + * params?: Node\Param[], + * returnType?: null|Node\Identifier|Node\Name|Node\ComplexType, + * attrGroups?: Node\AttributeGroup[] + * } $subNodes Array of the following subnodes: + * 'expr' : Expression body + * 'static' => false : Whether the closure is static + * 'byRef' => false : Whether to return by reference + * 'params' => array() : Parameters + * 'returnType' => null : Return type + * 'attrGroups' => array() : PHP attribute groups + * @param array $attributes Additional attributes */ - public function __construct(array $subNodes = [], array $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; + $this->returnType = $subNodes['returnType'] ?? null; + $this->expr = $subNodes['expr']; $this->attrGroups = $subNodes['attrGroups'] ?? []; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['attrGroups', 'static', 'byRef', 'params', 'returnType', 'expr']; } - public function returnsByRef() : bool { + public function returnsByRef(): bool { return $this->byRef; } - public function getParams() : array { + public function getParams(): array { return $this->params; } @@ -62,18 +67,18 @@ public function getReturnType() { return $this->returnType; } - public function getAttrGroups() : array { + public function getAttrGroups(): array { return $this->attrGroups; } /** * @return Node\Stmt\Return_[] */ - public function getStmts() : array { + public function getStmts(): array { return [new Node\Stmt\Return_($this->expr)]; } - public function getType() : string { + public function getType(): string { return 'Expr_ArrowFunction'; } } diff --git a/lib/PhpParser/Node/Expr/Assign.php b/lib/PhpParser/Node/Expr/Assign.php index cf9e6e82b4..dcbf84dd41 100644 --- a/lib/PhpParser/Node/Expr/Assign.php +++ b/lib/PhpParser/Node/Expr/Assign.php @@ -4,19 +4,18 @@ use PhpParser\Node\Expr; -class Assign extends Expr -{ +class Assign extends Expr { /** @var Expr Variable */ - public $var; + public Expr $var; /** @var Expr Expression */ - public $expr; + public Expr $expr; /** * Constructs an assignment node. * - * @param Expr $var Variable - * @param Expr $expr Expression - * @param array $attributes Additional attributes + * @param Expr $var Variable + * @param Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Expr $var, Expr $expr, array $attributes = []) { $this->attributes = $attributes; @@ -24,11 +23,11 @@ public function __construct(Expr $var, Expr $expr, array $attributes = []) { $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['var', 'expr']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_Assign'; } } diff --git a/lib/PhpParser/Node/Expr/AssignOp.php b/lib/PhpParser/Node/Expr/AssignOp.php index bce8604f14..5209a64b1f 100644 --- a/lib/PhpParser/Node/Expr/AssignOp.php +++ b/lib/PhpParser/Node/Expr/AssignOp.php @@ -4,19 +4,18 @@ use PhpParser\Node\Expr; -abstract class AssignOp extends Expr -{ +abstract class AssignOp extends Expr { /** @var Expr Variable */ - public $var; + public Expr $var; /** @var Expr Expression */ - public $expr; + public Expr $expr; /** * Constructs a compound assignment operation node. * - * @param Expr $var Variable - * @param Expr $expr Expression - * @param array $attributes Additional attributes + * @param Expr $var Variable + * @param Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Expr $var, Expr $expr, array $attributes = []) { $this->attributes = $attributes; @@ -24,7 +23,7 @@ public function __construct(Expr $var, Expr $expr, array $attributes = []) { $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['var', 'expr']; } } diff --git a/lib/PhpParser/Node/Expr/AssignOp/BitwiseAnd.php b/lib/PhpParser/Node/Expr/AssignOp/BitwiseAnd.php index 420284cdc1..4f3623fb6d 100644 --- a/lib/PhpParser/Node/Expr/AssignOp/BitwiseAnd.php +++ b/lib/PhpParser/Node/Expr/AssignOp/BitwiseAnd.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\AssignOp; -class BitwiseAnd extends AssignOp -{ - public function getType() : string { +class BitwiseAnd extends AssignOp { + public function getType(): string { return 'Expr_AssignOp_BitwiseAnd'; } } diff --git a/lib/PhpParser/Node/Expr/AssignOp/BitwiseOr.php b/lib/PhpParser/Node/Expr/AssignOp/BitwiseOr.php index 481ad3bbce..23efe10716 100644 --- a/lib/PhpParser/Node/Expr/AssignOp/BitwiseOr.php +++ b/lib/PhpParser/Node/Expr/AssignOp/BitwiseOr.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\AssignOp; -class BitwiseOr extends AssignOp -{ - public function getType() : string { +class BitwiseOr extends AssignOp { + public function getType(): string { return 'Expr_AssignOp_BitwiseOr'; } } diff --git a/lib/PhpParser/Node/Expr/AssignOp/BitwiseXor.php b/lib/PhpParser/Node/Expr/AssignOp/BitwiseXor.php index f41d4c8e73..24be7303f6 100644 --- a/lib/PhpParser/Node/Expr/AssignOp/BitwiseXor.php +++ b/lib/PhpParser/Node/Expr/AssignOp/BitwiseXor.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\AssignOp; -class BitwiseXor extends AssignOp -{ - public function getType() : string { +class BitwiseXor extends AssignOp { + public function getType(): string { return 'Expr_AssignOp_BitwiseXor'; } } diff --git a/lib/PhpParser/Node/Expr/AssignOp/Coalesce.php b/lib/PhpParser/Node/Expr/AssignOp/Coalesce.php index c0e9b316cf..b78ea901ab 100644 --- a/lib/PhpParser/Node/Expr/AssignOp/Coalesce.php +++ b/lib/PhpParser/Node/Expr/AssignOp/Coalesce.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\AssignOp; -class Coalesce extends AssignOp -{ - public function getType() : string { +class Coalesce extends AssignOp { + public function getType(): string { return 'Expr_AssignOp_Coalesce'; } } diff --git a/lib/PhpParser/Node/Expr/AssignOp/Concat.php b/lib/PhpParser/Node/Expr/AssignOp/Concat.php index ac16820785..f419e2ea06 100644 --- a/lib/PhpParser/Node/Expr/AssignOp/Concat.php +++ b/lib/PhpParser/Node/Expr/AssignOp/Concat.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\AssignOp; -class Concat extends AssignOp -{ - public function getType() : string { +class Concat extends AssignOp { + public function getType(): string { return 'Expr_AssignOp_Concat'; } } diff --git a/lib/PhpParser/Node/Expr/AssignOp/Div.php b/lib/PhpParser/Node/Expr/AssignOp/Div.php index f1fcfc09ad..98b0472745 100644 --- a/lib/PhpParser/Node/Expr/AssignOp/Div.php +++ b/lib/PhpParser/Node/Expr/AssignOp/Div.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\AssignOp; -class Div extends AssignOp -{ - public function getType() : string { +class Div extends AssignOp { + public function getType(): string { return 'Expr_AssignOp_Div'; } } diff --git a/lib/PhpParser/Node/Expr/AssignOp/Minus.php b/lib/PhpParser/Node/Expr/AssignOp/Minus.php index 82ef4517b7..2076599304 100644 --- a/lib/PhpParser/Node/Expr/AssignOp/Minus.php +++ b/lib/PhpParser/Node/Expr/AssignOp/Minus.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\AssignOp; -class Minus extends AssignOp -{ - public function getType() : string { +class Minus extends AssignOp { + public function getType(): string { return 'Expr_AssignOp_Minus'; } } diff --git a/lib/PhpParser/Node/Expr/AssignOp/Mod.php b/lib/PhpParser/Node/Expr/AssignOp/Mod.php index be3b4a0adb..526430e2ff 100644 --- a/lib/PhpParser/Node/Expr/AssignOp/Mod.php +++ b/lib/PhpParser/Node/Expr/AssignOp/Mod.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\AssignOp; -class Mod extends AssignOp -{ - public function getType() : string { +class Mod extends AssignOp { + public function getType(): string { return 'Expr_AssignOp_Mod'; } } diff --git a/lib/PhpParser/Node/Expr/AssignOp/Mul.php b/lib/PhpParser/Node/Expr/AssignOp/Mul.php index 5c196c3bcb..81241ac9af 100644 --- a/lib/PhpParser/Node/Expr/AssignOp/Mul.php +++ b/lib/PhpParser/Node/Expr/AssignOp/Mul.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\AssignOp; -class Mul extends AssignOp -{ - public function getType() : string { +class Mul extends AssignOp { + public function getType(): string { return 'Expr_AssignOp_Mul'; } } diff --git a/lib/PhpParser/Node/Expr/AssignOp/Plus.php b/lib/PhpParser/Node/Expr/AssignOp/Plus.php index dd101c61cb..0bca8cc17f 100644 --- a/lib/PhpParser/Node/Expr/AssignOp/Plus.php +++ b/lib/PhpParser/Node/Expr/AssignOp/Plus.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\AssignOp; -class Plus extends AssignOp -{ - public function getType() : string { +class Plus extends AssignOp { + public function getType(): string { return 'Expr_AssignOp_Plus'; } } diff --git a/lib/PhpParser/Node/Expr/AssignOp/Pow.php b/lib/PhpParser/Node/Expr/AssignOp/Pow.php index 5e1307d1da..4e3279c428 100644 --- a/lib/PhpParser/Node/Expr/AssignOp/Pow.php +++ b/lib/PhpParser/Node/Expr/AssignOp/Pow.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\AssignOp; -class Pow extends AssignOp -{ - public function getType() : string { +class Pow extends AssignOp { + public function getType(): string { return 'Expr_AssignOp_Pow'; } } diff --git a/lib/PhpParser/Node/Expr/AssignOp/ShiftLeft.php b/lib/PhpParser/Node/Expr/AssignOp/ShiftLeft.php index b8f88269b6..7a5dd60c66 100644 --- a/lib/PhpParser/Node/Expr/AssignOp/ShiftLeft.php +++ b/lib/PhpParser/Node/Expr/AssignOp/ShiftLeft.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\AssignOp; -class ShiftLeft extends AssignOp -{ - public function getType() : string { +class ShiftLeft extends AssignOp { + public function getType(): string { return 'Expr_AssignOp_ShiftLeft'; } } diff --git a/lib/PhpParser/Node/Expr/AssignOp/ShiftRight.php b/lib/PhpParser/Node/Expr/AssignOp/ShiftRight.php index e0cc67b7ff..4f270864dd 100644 --- a/lib/PhpParser/Node/Expr/AssignOp/ShiftRight.php +++ b/lib/PhpParser/Node/Expr/AssignOp/ShiftRight.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\AssignOp; -class ShiftRight extends AssignOp -{ - public function getType() : string { +class ShiftRight extends AssignOp { + public function getType(): string { return 'Expr_AssignOp_ShiftRight'; } } diff --git a/lib/PhpParser/Node/Expr/AssignRef.php b/lib/PhpParser/Node/Expr/AssignRef.php index de3c644c3c..9714650a54 100644 --- a/lib/PhpParser/Node/Expr/AssignRef.php +++ b/lib/PhpParser/Node/Expr/AssignRef.php @@ -4,19 +4,18 @@ use PhpParser\Node\Expr; -class AssignRef extends Expr -{ +class AssignRef extends Expr { /** @var Expr Variable reference is assigned to */ - public $var; + public Expr $var; /** @var Expr Variable which is referenced */ - public $expr; + public Expr $expr; /** * Constructs an assignment node. * - * @param Expr $var Variable - * @param Expr $expr Expression - * @param array $attributes Additional attributes + * @param Expr $var Variable + * @param Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Expr $var, Expr $expr, array $attributes = []) { $this->attributes = $attributes; @@ -24,11 +23,11 @@ public function __construct(Expr $var, Expr $expr, array $attributes = []) { $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['var', 'expr']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_AssignRef'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp.php b/lib/PhpParser/Node/Expr/BinaryOp.php index d9c582b0d2..1b92bd4f50 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp.php +++ b/lib/PhpParser/Node/Expr/BinaryOp.php @@ -4,19 +4,18 @@ use PhpParser\Node\Expr; -abstract class BinaryOp extends Expr -{ +abstract class BinaryOp extends Expr { /** @var Expr The left hand side expression */ - public $left; + public Expr $left; /** @var Expr The right hand side expression */ - public $right; + public Expr $right; /** * Constructs a binary operator node. * - * @param Expr $left The left hand side expression - * @param Expr $right The right hand side expression - * @param array $attributes Additional attributes + * @param Expr $left The left hand side expression + * @param Expr $right The right hand side expression + * @param array $attributes Additional attributes */ public function __construct(Expr $left, Expr $right, array $attributes = []) { $this->attributes = $attributes; @@ -24,7 +23,7 @@ public function __construct(Expr $left, Expr $right, array $attributes = []) { $this->right = $right; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['left', 'right']; } @@ -33,8 +32,6 @@ public function getSubNodeNames() : array { * * In the case there are multiple possible sigils for an operator, this method does not * necessarily return the one used in the parsed code. - * - * @return string */ - abstract public function getOperatorSigil() : string; + abstract public function getOperatorSigil(): string; } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/BitwiseAnd.php b/lib/PhpParser/Node/Expr/BinaryOp/BitwiseAnd.php index d907393bfa..5930c5413c 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/BitwiseAnd.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/BitwiseAnd.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class BitwiseAnd extends BinaryOp -{ - public function getOperatorSigil() : string { +class BitwiseAnd extends BinaryOp { + public function getOperatorSigil(): string { return '&'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_BitwiseAnd'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/BitwiseOr.php b/lib/PhpParser/Node/Expr/BinaryOp/BitwiseOr.php index d92069f321..adcefd0e2c 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/BitwiseOr.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/BitwiseOr.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class BitwiseOr extends BinaryOp -{ - public function getOperatorSigil() : string { +class BitwiseOr extends BinaryOp { + public function getOperatorSigil(): string { return '|'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_BitwiseOr'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/BitwiseXor.php b/lib/PhpParser/Node/Expr/BinaryOp/BitwiseXor.php index 40fa94f887..92bca60946 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/BitwiseXor.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/BitwiseXor.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class BitwiseXor extends BinaryOp -{ - public function getOperatorSigil() : string { +class BitwiseXor extends BinaryOp { + public function getOperatorSigil(): string { return '^'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_BitwiseXor'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/BooleanAnd.php b/lib/PhpParser/Node/Expr/BinaryOp/BooleanAnd.php index 4c3c9e9b1e..82a6b5a270 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/BooleanAnd.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/BooleanAnd.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class BooleanAnd extends BinaryOp -{ - public function getOperatorSigil() : string { +class BooleanAnd extends BinaryOp { + public function getOperatorSigil(): string { return '&&'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_BooleanAnd'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/BooleanOr.php b/lib/PhpParser/Node/Expr/BinaryOp/BooleanOr.php index 5ad417279a..739edafafc 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/BooleanOr.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/BooleanOr.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class BooleanOr extends BinaryOp -{ - public function getOperatorSigil() : string { +class BooleanOr extends BinaryOp { + public function getOperatorSigil(): string { return '||'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_BooleanOr'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/Coalesce.php b/lib/PhpParser/Node/Expr/BinaryOp/Coalesce.php index b8cf6f4599..ab75a23e48 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/Coalesce.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/Coalesce.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class Coalesce extends BinaryOp -{ - public function getOperatorSigil() : string { +class Coalesce extends BinaryOp { + public function getOperatorSigil(): string { return '??'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_Coalesce'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/Concat.php b/lib/PhpParser/Node/Expr/BinaryOp/Concat.php index 9a8d9873c0..a730f57604 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/Concat.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/Concat.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class Concat extends BinaryOp -{ - public function getOperatorSigil() : string { +class Concat extends BinaryOp { + public function getOperatorSigil(): string { return '.'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_Concat'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/Div.php b/lib/PhpParser/Node/Expr/BinaryOp/Div.php index d38df0db4d..ba1f629d30 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/Div.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/Div.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class Div extends BinaryOp -{ - public function getOperatorSigil() : string { +class Div extends BinaryOp { + public function getOperatorSigil(): string { return '/'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_Div'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/Equal.php b/lib/PhpParser/Node/Expr/BinaryOp/Equal.php index e7b11dc824..28bde8122d 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/Equal.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/Equal.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class Equal extends BinaryOp -{ - public function getOperatorSigil() : string { +class Equal extends BinaryOp { + public function getOperatorSigil(): string { return '=='; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_Equal'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/Greater.php b/lib/PhpParser/Node/Expr/BinaryOp/Greater.php index da01f7a100..6215c50b82 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/Greater.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/Greater.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class Greater extends BinaryOp -{ - public function getOperatorSigil() : string { +class Greater extends BinaryOp { + public function getOperatorSigil(): string { return '>'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_Greater'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/GreaterOrEqual.php b/lib/PhpParser/Node/Expr/BinaryOp/GreaterOrEqual.php index d677502cf5..4d440b100c 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/GreaterOrEqual.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/GreaterOrEqual.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class GreaterOrEqual extends BinaryOp -{ - public function getOperatorSigil() : string { +class GreaterOrEqual extends BinaryOp { + public function getOperatorSigil(): string { return '>='; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_GreaterOrEqual'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/Identical.php b/lib/PhpParser/Node/Expr/BinaryOp/Identical.php index 3d96285c64..e25d17cd99 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/Identical.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/Identical.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class Identical extends BinaryOp -{ - public function getOperatorSigil() : string { +class Identical extends BinaryOp { + public function getOperatorSigil(): string { return '==='; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_Identical'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/LogicalAnd.php b/lib/PhpParser/Node/Expr/BinaryOp/LogicalAnd.php index 2a3afd548f..9b9ea1f6e4 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/LogicalAnd.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/LogicalAnd.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class LogicalAnd extends BinaryOp -{ - public function getOperatorSigil() : string { +class LogicalAnd extends BinaryOp { + public function getOperatorSigil(): string { return 'and'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_LogicalAnd'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/LogicalOr.php b/lib/PhpParser/Node/Expr/BinaryOp/LogicalOr.php index 21507dba63..a6235ee76d 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/LogicalOr.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/LogicalOr.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class LogicalOr extends BinaryOp -{ - public function getOperatorSigil() : string { +class LogicalOr extends BinaryOp { + public function getOperatorSigil(): string { return 'or'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_LogicalOr'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/LogicalXor.php b/lib/PhpParser/Node/Expr/BinaryOp/LogicalXor.php index 261c6a9100..7ff2fdb0a1 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/LogicalXor.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/LogicalXor.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class LogicalXor extends BinaryOp -{ - public function getOperatorSigil() : string { +class LogicalXor extends BinaryOp { + public function getOperatorSigil(): string { return 'xor'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_LogicalXor'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/Minus.php b/lib/PhpParser/Node/Expr/BinaryOp/Minus.php index 54b3c6e905..8924c55e1e 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/Minus.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/Minus.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class Minus extends BinaryOp -{ - public function getOperatorSigil() : string { +class Minus extends BinaryOp { + public function getOperatorSigil(): string { return '-'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_Minus'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/Mod.php b/lib/PhpParser/Node/Expr/BinaryOp/Mod.php index 1034040401..56619de1bd 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/Mod.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/Mod.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class Mod extends BinaryOp -{ - public function getOperatorSigil() : string { +class Mod extends BinaryOp { + public function getOperatorSigil(): string { return '%'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_Mod'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/Mul.php b/lib/PhpParser/Node/Expr/BinaryOp/Mul.php index b82d0b2fcb..98745fbe2f 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/Mul.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/Mul.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class Mul extends BinaryOp -{ - public function getOperatorSigil() : string { +class Mul extends BinaryOp { + public function getOperatorSigil(): string { return '*'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_Mul'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/NotEqual.php b/lib/PhpParser/Node/Expr/BinaryOp/NotEqual.php index 51075da563..72d03c4590 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/NotEqual.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/NotEqual.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class NotEqual extends BinaryOp -{ - public function getOperatorSigil() : string { +class NotEqual extends BinaryOp { + public function getOperatorSigil(): string { return '!='; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_NotEqual'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/NotIdentical.php b/lib/PhpParser/Node/Expr/BinaryOp/NotIdentical.php index fa4050e058..e9befd80f3 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/NotIdentical.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/NotIdentical.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class NotIdentical extends BinaryOp -{ - public function getOperatorSigil() : string { +class NotIdentical extends BinaryOp { + public function getOperatorSigil(): string { return '!=='; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_NotIdentical'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/Pipe.php b/lib/PhpParser/Node/Expr/BinaryOp/Pipe.php new file mode 100644 index 0000000000..8dd8890bd2 --- /dev/null +++ b/lib/PhpParser/Node/Expr/BinaryOp/Pipe.php @@ -0,0 +1,15 @@ +'; + } + + public function getType(): string { + return 'Expr_BinaryOp_Pipe'; + } +} diff --git a/lib/PhpParser/Node/Expr/BinaryOp/Plus.php b/lib/PhpParser/Node/Expr/BinaryOp/Plus.php index 62f0229985..fe34b84c9a 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/Plus.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/Plus.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class Plus extends BinaryOp -{ - public function getOperatorSigil() : string { +class Plus extends BinaryOp { + public function getOperatorSigil(): string { return '+'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_Plus'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/Pow.php b/lib/PhpParser/Node/Expr/BinaryOp/Pow.php index 572a1e8e43..e4e641cb72 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/Pow.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/Pow.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class Pow extends BinaryOp -{ - public function getOperatorSigil() : string { +class Pow extends BinaryOp { + public function getOperatorSigil(): string { return '**'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_Pow'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/ShiftLeft.php b/lib/PhpParser/Node/Expr/BinaryOp/ShiftLeft.php index 4e70b4ef0b..22c6260f55 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/ShiftLeft.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/ShiftLeft.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class ShiftLeft extends BinaryOp -{ - public function getOperatorSigil() : string { +class ShiftLeft extends BinaryOp { + public function getOperatorSigil(): string { return '<<'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_ShiftLeft'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/ShiftRight.php b/lib/PhpParser/Node/Expr/BinaryOp/ShiftRight.php index 45acbd0461..cd42644af2 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/ShiftRight.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/ShiftRight.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class ShiftRight extends BinaryOp -{ - public function getOperatorSigil() : string { +class ShiftRight extends BinaryOp { + public function getOperatorSigil(): string { return '>>'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_ShiftRight'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/Smaller.php b/lib/PhpParser/Node/Expr/BinaryOp/Smaller.php index 3cb8e7e0d1..01e9b2310d 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/Smaller.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/Smaller.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class Smaller extends BinaryOp -{ - public function getOperatorSigil() : string { +class Smaller extends BinaryOp { + public function getOperatorSigil(): string { return '<'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_Smaller'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/SmallerOrEqual.php b/lib/PhpParser/Node/Expr/BinaryOp/SmallerOrEqual.php index 83e8e214d0..2c88f3836d 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/SmallerOrEqual.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/SmallerOrEqual.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class SmallerOrEqual extends BinaryOp -{ - public function getOperatorSigil() : string { +class SmallerOrEqual extends BinaryOp { + public function getOperatorSigil(): string { return '<='; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_SmallerOrEqual'; } } diff --git a/lib/PhpParser/Node/Expr/BinaryOp/Spaceship.php b/lib/PhpParser/Node/Expr/BinaryOp/Spaceship.php index 8c6d787f6a..974ec7dd37 100644 --- a/lib/PhpParser/Node/Expr/BinaryOp/Spaceship.php +++ b/lib/PhpParser/Node/Expr/BinaryOp/Spaceship.php @@ -4,13 +4,12 @@ use PhpParser\Node\Expr\BinaryOp; -class Spaceship extends BinaryOp -{ - public function getOperatorSigil() : string { +class Spaceship extends BinaryOp { + public function getOperatorSigil(): string { return '<=>'; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BinaryOp_Spaceship'; } } diff --git a/lib/PhpParser/Node/Expr/BitwiseNot.php b/lib/PhpParser/Node/Expr/BitwiseNot.php index ed44984bea..b7175a7ae5 100644 --- a/lib/PhpParser/Node/Expr/BitwiseNot.php +++ b/lib/PhpParser/Node/Expr/BitwiseNot.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class BitwiseNot extends Expr -{ +class BitwiseNot extends Expr { /** @var Expr Expression */ - public $expr; + public Expr $expr; /** * Constructs a bitwise not node. * - * @param Expr $expr Expression - * @param array $attributes Additional attributes + * @param Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BitwiseNot'; } } diff --git a/lib/PhpParser/Node/Expr/BooleanNot.php b/lib/PhpParser/Node/Expr/BooleanNot.php index bf27e9f657..c66d23326d 100644 --- a/lib/PhpParser/Node/Expr/BooleanNot.php +++ b/lib/PhpParser/Node/Expr/BooleanNot.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class BooleanNot extends Expr -{ +class BooleanNot extends Expr { /** @var Expr Expression */ - public $expr; + public Expr $expr; /** * Constructs a boolean not node. * - * @param Expr $expr Expression - * @param array $attributes Additional attributes + * @param Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_BooleanNot'; } } diff --git a/lib/PhpParser/Node/Expr/CallLike.php b/lib/PhpParser/Node/Expr/CallLike.php new file mode 100644 index 0000000000..86e781c102 --- /dev/null +++ b/lib/PhpParser/Node/Expr/CallLike.php @@ -0,0 +1,60 @@ + + */ + abstract public function getRawArgs(): array; + + /** + * Returns whether this call expression is actually a first class callable. + */ + public function isFirstClassCallable(): bool { + $rawArgs = $this->getRawArgs(); + return count($rawArgs) === 1 && current($rawArgs) instanceof VariadicPlaceholder; + } + + /** + * Assert that this is not a first-class callable and return only ordinary Args. + * + * @return Arg[] + */ + public function getArgs(): array { + assert(!$this->isFirstClassCallable()); + return $this->getRawArgs(); + } + + /** + * Retrieves a specific argument from the raw arguments. + * + * Returns the named argument that matches the given `$name`, or the + * positional (unnamed) argument that exists at the given `$position`, + * otherwise, returns `null` for first-class callables or if no match is found. + */ + public function getArg(string $name, int $position): ?Arg { + if ($this->isFirstClassCallable()) { + return null; + } + foreach ($this->getRawArgs() as $i => $arg) { + if ($arg->unpack) { + continue; + } + if ( + ($arg->name !== null && $arg->name->toString() === $name) + || ($arg->name === null && $i === $position) + ) { + return $arg; + } + } + return null; + } +} diff --git a/lib/PhpParser/Node/Expr/Cast.php b/lib/PhpParser/Node/Expr/Cast.php index 36769d4fc6..c2751de470 100644 --- a/lib/PhpParser/Node/Expr/Cast.php +++ b/lib/PhpParser/Node/Expr/Cast.php @@ -4,23 +4,22 @@ use PhpParser\Node\Expr; -abstract class Cast extends Expr -{ +abstract class Cast extends Expr { /** @var Expr Expression */ - public $expr; + public Expr $expr; /** * Constructs a cast node. * - * @param Expr $expr Expression - * @param array $attributes Additional attributes + * @param Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr']; } } diff --git a/lib/PhpParser/Node/Expr/Cast/Array_.php b/lib/PhpParser/Node/Expr/Cast/Array_.php index 57cc473b62..471cb824a0 100644 --- a/lib/PhpParser/Node/Expr/Cast/Array_.php +++ b/lib/PhpParser/Node/Expr/Cast/Array_.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\Cast; -class Array_ extends Cast -{ - public function getType() : string { +class Array_ extends Cast { + public function getType(): string { return 'Expr_Cast_Array'; } } diff --git a/lib/PhpParser/Node/Expr/Cast/Bool_.php b/lib/PhpParser/Node/Expr/Cast/Bool_.php index 04eb4af584..ca02586dd1 100644 --- a/lib/PhpParser/Node/Expr/Cast/Bool_.php +++ b/lib/PhpParser/Node/Expr/Cast/Bool_.php @@ -4,9 +4,12 @@ use PhpParser\Node\Expr\Cast; -class Bool_ extends Cast -{ - public function getType() : string { +class Bool_ extends Cast { + // For use in "kind" attribute + public const KIND_BOOL = 1; // "bool" syntax + public const KIND_BOOLEAN = 2; // "boolean" syntax + + public function getType(): string { return 'Expr_Cast_Bool'; } } diff --git a/lib/PhpParser/Node/Expr/Cast/Double.php b/lib/PhpParser/Node/Expr/Cast/Double.php index 891ba5f870..e7f5cd9b92 100644 --- a/lib/PhpParser/Node/Expr/Cast/Double.php +++ b/lib/PhpParser/Node/Expr/Cast/Double.php @@ -4,14 +4,13 @@ use PhpParser\Node\Expr\Cast; -class Double extends Cast -{ +class Double extends Cast { // For use in "kind" attribute - const KIND_DOUBLE = 1; // "double" syntax - const KIND_FLOAT = 2; // "float" syntax - const KIND_REAL = 3; // "real" syntax + public const KIND_DOUBLE = 1; // "double" syntax + public const KIND_FLOAT = 2; // "float" syntax + public const KIND_REAL = 3; // "real" syntax - public function getType() : string { + public function getType(): string { return 'Expr_Cast_Double'; } } diff --git a/lib/PhpParser/Node/Expr/Cast/Int_.php b/lib/PhpParser/Node/Expr/Cast/Int_.php index 01ed594bd0..7e5d4a36a2 100644 --- a/lib/PhpParser/Node/Expr/Cast/Int_.php +++ b/lib/PhpParser/Node/Expr/Cast/Int_.php @@ -4,9 +4,12 @@ use PhpParser\Node\Expr\Cast; -class Int_ extends Cast -{ - public function getType() : string { +class Int_ extends Cast { + // For use in "kind" attribute + public const KIND_INT = 1; // "int" syntax + public const KIND_INTEGER = 2; // "integer" syntax + + public function getType(): string { return 'Expr_Cast_Int'; } } diff --git a/lib/PhpParser/Node/Expr/Cast/Object_.php b/lib/PhpParser/Node/Expr/Cast/Object_.php index 163752be89..dffa9e54ad 100644 --- a/lib/PhpParser/Node/Expr/Cast/Object_.php +++ b/lib/PhpParser/Node/Expr/Cast/Object_.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\Cast; -class Object_ extends Cast -{ - public function getType() : string { +class Object_ extends Cast { + public function getType(): string { return 'Expr_Cast_Object'; } } diff --git a/lib/PhpParser/Node/Expr/Cast/String_.php b/lib/PhpParser/Node/Expr/Cast/String_.php index b3d99270ac..a8f8c25486 100644 --- a/lib/PhpParser/Node/Expr/Cast/String_.php +++ b/lib/PhpParser/Node/Expr/Cast/String_.php @@ -4,9 +4,12 @@ use PhpParser\Node\Expr\Cast; -class String_ extends Cast -{ - public function getType() : string { +class String_ extends Cast { + // For use in "kind" attribute + public const KIND_STRING = 1; // "string" syntax + public const KIND_BINARY = 2; // "binary" syntax + + public function getType(): string { return 'Expr_Cast_String'; } } diff --git a/lib/PhpParser/Node/Expr/Cast/Unset_.php b/lib/PhpParser/Node/Expr/Cast/Unset_.php index accda3e4ff..cb709a43e3 100644 --- a/lib/PhpParser/Node/Expr/Cast/Unset_.php +++ b/lib/PhpParser/Node/Expr/Cast/Unset_.php @@ -4,9 +4,8 @@ use PhpParser\Node\Expr\Cast; -class Unset_ extends Cast -{ - public function getType() : string { +class Unset_ extends Cast { + public function getType(): string { return 'Expr_Cast_Unset'; } } diff --git a/lib/PhpParser/Node/Expr/Cast/Void_.php b/lib/PhpParser/Node/Expr/Cast/Void_.php new file mode 100644 index 0000000000..bc9c23fc00 --- /dev/null +++ b/lib/PhpParser/Node/Expr/Cast/Void_.php @@ -0,0 +1,11 @@ + $attributes Additional attributes */ - public function __construct($class, $name, array $attributes = []) { + public function __construct(Node $class, $name, array $attributes = []) { $this->attributes = $attributes; $this->class = $class; $this->name = \is_string($name) ? new Identifier($name) : $name; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['class', 'name']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_ClassConstFetch'; } } diff --git a/lib/PhpParser/Node/Expr/Clone_.php b/lib/PhpParser/Node/Expr/Clone_.php index db216b8f84..d85bc9ab42 100644 --- a/lib/PhpParser/Node/Expr/Clone_.php +++ b/lib/PhpParser/Node/Expr/Clone_.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class Clone_ extends Expr -{ +class Clone_ extends Expr { /** @var Expr Expression */ - public $expr; + public Expr $expr; /** * Constructs a clone node. * - * @param Expr $expr Expression - * @param array $attributes Additional attributes + * @param Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_Clone'; } } diff --git a/lib/PhpParser/Node/Expr/Closure.php b/lib/PhpParser/Node/Expr/Closure.php index 56e621f252..0680446f34 100644 --- a/lib/PhpParser/Node/Expr/Closure.php +++ b/lib/PhpParser/Node/Expr/Closure.php @@ -3,38 +3,46 @@ namespace PhpParser\Node\Expr; use PhpParser\Node; +use PhpParser\Node\ClosureUse; use PhpParser\Node\Expr; use PhpParser\Node\FunctionLike; -class Closure extends Expr implements FunctionLike -{ +class Closure extends Expr implements FunctionLike { /** @var bool Whether the closure is static */ - public $static; + public bool $static; /** @var bool Whether to return by reference */ - public $byRef; + public bool $byRef; /** @var Node\Param[] Parameters */ - public $params; + public array $params; /** @var ClosureUse[] use()s */ - public $uses; - /** @var null|Node\Identifier|Node\Name|Node\NullableType|Node\UnionType Return type */ - public $returnType; + public array $uses; + /** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */ + public ?Node $returnType; /** @var Node\Stmt[] Statements */ - public $stmts; + public array $stmts; /** @var Node\AttributeGroup[] PHP attribute groups */ - public $attrGroups; + public array $attrGroups; /** * Constructs a lambda function node. * - * @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 - * 'uses' => array(): use()s - * 'returnType' => null : Return type - * 'stmts' => array(): Statements - * 'attrGroups' => array(): PHP attributes groups - * @param array $attributes Additional attributes + * @param array{ + * static?: bool, + * byRef?: bool, + * params?: Node\Param[], + * uses?: ClosureUse[], + * returnType?: null|Node\Identifier|Node\Name|Node\ComplexType, + * stmts?: Node\Stmt[], + * attrGroups?: Node\AttributeGroup[], + * } $subNodes Array of the following optional subnodes: + * 'static' => false : Whether the closure is static + * 'byRef' => false : Whether to return by reference + * 'params' => array(): Parameters + * 'uses' => array(): use()s + * 'returnType' => null : Return type + * 'stmts' => array(): Statements + * 'attrGroups' => array(): PHP attributes groups + * @param array $attributes Additional attributes */ public function __construct(array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; @@ -42,21 +50,20 @@ public function __construct(array $subNodes = [], array $attributes = []) { $this->byRef = $subNodes['byRef'] ?? false; $this->params = $subNodes['params'] ?? []; $this->uses = $subNodes['uses'] ?? []; - $returnType = $subNodes['returnType'] ?? null; - $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType; + $this->returnType = $subNodes['returnType'] ?? null; $this->stmts = $subNodes['stmts'] ?? []; $this->attrGroups = $subNodes['attrGroups'] ?? []; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['attrGroups', 'static', 'byRef', 'params', 'uses', 'returnType', 'stmts']; } - public function returnsByRef() : bool { + public function returnsByRef(): bool { return $this->byRef; } - public function getParams() : array { + public function getParams(): array { return $this->params; } @@ -65,15 +72,15 @@ public function getReturnType() { } /** @return Node\Stmt[] */ - public function getStmts() : array { + public function getStmts(): array { return $this->stmts; } - public function getAttrGroups() : array { + public function getAttrGroups(): array { return $this->attrGroups; } - public function getType() : string { + public function getType(): string { return 'Expr_Closure'; } } diff --git a/lib/PhpParser/Node/Expr/ClosureUse.php b/lib/PhpParser/Node/Expr/ClosureUse.php index 2b8a096666..b395617202 100644 --- a/lib/PhpParser/Node/Expr/ClosureUse.php +++ b/lib/PhpParser/Node/Expr/ClosureUse.php @@ -2,33 +2,10 @@ namespace PhpParser\Node\Expr; -use PhpParser\Node\Expr; +require __DIR__ . '/../ClosureUse.php'; -class ClosureUse extends Expr -{ - /** @var Expr\Variable Variable to use */ - public $var; - /** @var bool Whether to use by reference */ - public $byRef; - - /** - * Constructs a closure use node. - * - * @param Expr\Variable $var Variable to use - * @param bool $byRef Whether to use by reference - * @param array $attributes Additional attributes - */ - public function __construct(Expr\Variable $var, bool $byRef = false, array $attributes = []) { - $this->attributes = $attributes; - $this->var = $var; - $this->byRef = $byRef; - } - - public function getSubNodeNames() : array { - return ['var', 'byRef']; - } - - public function getType() : string { - return 'Expr_ClosureUse'; +if (false) { + // For classmap-authoritative support. + class ClosureUse extends \PhpParser\Node\ClosureUse { } } diff --git a/lib/PhpParser/Node/Expr/ConstFetch.php b/lib/PhpParser/Node/Expr/ConstFetch.php index 14ebd16bd8..47191c5f33 100644 --- a/lib/PhpParser/Node/Expr/ConstFetch.php +++ b/lib/PhpParser/Node/Expr/ConstFetch.php @@ -5,27 +5,26 @@ use PhpParser\Node\Expr; use PhpParser\Node\Name; -class ConstFetch extends Expr -{ +class ConstFetch extends Expr { /** @var Name Constant name */ - public $name; + public Name $name; /** * Constructs a const fetch node. * - * @param Name $name Constant name - * @param array $attributes Additional attributes + * @param Name $name Constant name + * @param array $attributes Additional attributes */ public function __construct(Name $name, array $attributes = []) { $this->attributes = $attributes; $this->name = $name; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['name']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_ConstFetch'; } } diff --git a/lib/PhpParser/Node/Expr/Empty_.php b/lib/PhpParser/Node/Expr/Empty_.php index 4042ec93ca..d2f30506ba 100644 --- a/lib/PhpParser/Node/Expr/Empty_.php +++ b/lib/PhpParser/Node/Expr/Empty_.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class Empty_ extends Expr -{ +class Empty_ extends Expr { /** @var Expr Expression */ - public $expr; + public Expr $expr; /** * Constructs an empty() node. * - * @param Expr $expr Expression - * @param array $attributes Additional attributes + * @param Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_Empty'; } } diff --git a/lib/PhpParser/Node/Expr/Error.php b/lib/PhpParser/Node/Expr/Error.php index 1637f3aeae..43010ac45d 100644 --- a/lib/PhpParser/Node/Expr/Error.php +++ b/lib/PhpParser/Node/Expr/Error.php @@ -10,22 +10,21 @@ * An error node may be placed at a position where an expression is required, but an error occurred. * Error nodes will not be present if the parser is run in throwOnError mode (the default). */ -class Error extends Expr -{ +class Error extends Expr { /** * Constructs an error node. * - * @param array $attributes Additional attributes + * @param array $attributes Additional attributes */ public function __construct(array $attributes = []) { $this->attributes = $attributes; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return []; } - - public function getType() : string { + + public function getType(): string { return 'Expr_Error'; } } diff --git a/lib/PhpParser/Node/Expr/ErrorSuppress.php b/lib/PhpParser/Node/Expr/ErrorSuppress.php index c44ff6f931..32625a2335 100644 --- a/lib/PhpParser/Node/Expr/ErrorSuppress.php +++ b/lib/PhpParser/Node/Expr/ErrorSuppress.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class ErrorSuppress extends Expr -{ +class ErrorSuppress extends Expr { /** @var Expr Expression */ - public $expr; + public Expr $expr; /** * Constructs an error suppress node. * - * @param Expr $expr Expression - * @param array $attributes Additional attributes + * @param Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_ErrorSuppress'; } } diff --git a/lib/PhpParser/Node/Expr/Eval_.php b/lib/PhpParser/Node/Expr/Eval_.php index 8568547438..5120b1b4f3 100644 --- a/lib/PhpParser/Node/Expr/Eval_.php +++ b/lib/PhpParser/Node/Expr/Eval_.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class Eval_ extends Expr -{ +class Eval_ extends Expr { /** @var Expr Expression */ - public $expr; + public Expr $expr; /** * Constructs an eval() node. * - * @param Expr $expr Expression - * @param array $attributes Additional attributes + * @param Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_Eval'; } } diff --git a/lib/PhpParser/Node/Expr/Exit_.php b/lib/PhpParser/Node/Expr/Exit_.php index b88a8f7e6f..cf00246699 100644 --- a/lib/PhpParser/Node/Expr/Exit_.php +++ b/lib/PhpParser/Node/Expr/Exit_.php @@ -4,31 +4,30 @@ use PhpParser\Node\Expr; -class Exit_ extends Expr -{ +class Exit_ extends Expr { /* For use in "kind" attribute */ - const KIND_EXIT = 1; - const KIND_DIE = 2; + public const KIND_EXIT = 1; + public const KIND_DIE = 2; /** @var null|Expr Expression */ - public $expr; + public ?Expr $expr; /** * Constructs an exit() node. * - * @param null|Expr $expr Expression - * @param array $attributes Additional attributes + * @param null|Expr $expr Expression + * @param array $attributes Additional attributes */ - public function __construct(Expr $expr = null, array $attributes = []) { + public function __construct(?Expr $expr = null, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_Exit'; } } diff --git a/lib/PhpParser/Node/Expr/FuncCall.php b/lib/PhpParser/Node/Expr/FuncCall.php index 1e8afa5596..0b85840d8e 100644 --- a/lib/PhpParser/Node/Expr/FuncCall.php +++ b/lib/PhpParser/Node/Expr/FuncCall.php @@ -5,31 +5,34 @@ use PhpParser\Node; use PhpParser\Node\Expr; -class FuncCall extends Expr -{ +class FuncCall extends CallLike { /** @var Node\Name|Expr Function name */ - public $name; - /** @var Node\Arg[] Arguments */ - public $args; + public Node $name; + /** @var array Arguments */ + public array $args; /** * Constructs a function call node. * - * @param Node\Name|Expr $name Function name - * @param Node\Arg[] $args Arguments - * @param array $attributes Additional attributes + * @param Node\Name|Expr $name Function name + * @param array $args Arguments + * @param array $attributes Additional attributes */ - public function __construct($name, array $args = [], array $attributes = []) { + public function __construct(Node $name, array $args = [], array $attributes = []) { $this->attributes = $attributes; $this->name = $name; $this->args = $args; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['name', 'args']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_FuncCall'; } + + public function getRawArgs(): array { + return $this->args; + } } diff --git a/lib/PhpParser/Node/Expr/Include_.php b/lib/PhpParser/Node/Expr/Include_.php index 07ce5968e4..e1187b194f 100644 --- a/lib/PhpParser/Node/Expr/Include_.php +++ b/lib/PhpParser/Node/Expr/Include_.php @@ -4,24 +4,23 @@ use PhpParser\Node\Expr; -class Include_ extends Expr -{ - const TYPE_INCLUDE = 1; - const TYPE_INCLUDE_ONCE = 2; - const TYPE_REQUIRE = 3; - const TYPE_REQUIRE_ONCE = 4; +class Include_ extends Expr { + public const TYPE_INCLUDE = 1; + public const TYPE_INCLUDE_ONCE = 2; + public const TYPE_REQUIRE = 3; + public const TYPE_REQUIRE_ONCE = 4; /** @var Expr Expression */ - public $expr; + public Expr $expr; /** @var int Type of include */ - public $type; + public int $type; /** * Constructs an include node. * - * @param Expr $expr Expression - * @param int $type Type of include - * @param array $attributes Additional attributes + * @param Expr $expr Expression + * @param int $type Type of include + * @param array $attributes Additional attributes */ public function __construct(Expr $expr, int $type, array $attributes = []) { $this->attributes = $attributes; @@ -29,11 +28,11 @@ public function __construct(Expr $expr, int $type, array $attributes = []) { $this->type = $type; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr', 'type']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_Include'; } } diff --git a/lib/PhpParser/Node/Expr/Instanceof_.php b/lib/PhpParser/Node/Expr/Instanceof_.php index 9000d47bb1..a2783cb3af 100644 --- a/lib/PhpParser/Node/Expr/Instanceof_.php +++ b/lib/PhpParser/Node/Expr/Instanceof_.php @@ -2,34 +2,34 @@ namespace PhpParser\Node\Expr; +use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Name; -class Instanceof_ extends Expr -{ +class Instanceof_ extends Expr { /** @var Expr Expression */ - public $expr; + public Expr $expr; /** @var Name|Expr Class name */ - public $class; + public Node $class; /** * Constructs an instanceof check node. * - * @param Expr $expr Expression - * @param Name|Expr $class Class name - * @param array $attributes Additional attributes + * @param Expr $expr Expression + * @param Name|Expr $class Class name + * @param array $attributes Additional attributes */ - public function __construct(Expr $expr, $class, array $attributes = []) { + public function __construct(Expr $expr, Node $class, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; $this->class = $class; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr', 'class']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_Instanceof'; } } diff --git a/lib/PhpParser/Node/Expr/Isset_.php b/lib/PhpParser/Node/Expr/Isset_.php index 76b7387587..4f80fff723 100644 --- a/lib/PhpParser/Node/Expr/Isset_.php +++ b/lib/PhpParser/Node/Expr/Isset_.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class Isset_ extends Expr -{ +class Isset_ extends Expr { /** @var Expr[] Variables */ - public $vars; + public array $vars; /** * Constructs an array node. * - * @param Expr[] $vars Variables - * @param array $attributes Additional attributes + * @param Expr[] $vars Variables + * @param array $attributes Additional attributes */ public function __construct(array $vars, array $attributes = []) { $this->attributes = $attributes; $this->vars = $vars; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['vars']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_Isset'; } } diff --git a/lib/PhpParser/Node/Expr/List_.php b/lib/PhpParser/Node/Expr/List_.php index c27a27b957..496b7b3853 100644 --- a/lib/PhpParser/Node/Expr/List_.php +++ b/lib/PhpParser/Node/Expr/List_.php @@ -2,29 +2,33 @@ namespace PhpParser\Node\Expr; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr; -class List_ extends Expr -{ +class List_ extends Expr { + // For use in "kind" attribute + public const KIND_LIST = 1; // list() syntax + public const KIND_ARRAY = 2; // [] syntax + /** @var (ArrayItem|null)[] List of items to assign to */ - public $items; + public array $items; /** * Constructs a list() destructuring node. * - * @param (ArrayItem|null)[] $items List of items to assign to - * @param array $attributes Additional attributes + * @param (ArrayItem|null)[] $items List of items to assign to + * @param array $attributes Additional attributes */ public function __construct(array $items, array $attributes = []) { $this->attributes = $attributes; $this->items = $items; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['items']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_List'; } } diff --git a/lib/PhpParser/Node/Expr/Match_.php b/lib/PhpParser/Node/Expr/Match_.php index 2455a30264..cd028a2da7 100644 --- a/lib/PhpParser/Node/Expr/Match_.php +++ b/lib/PhpParser/Node/Expr/Match_.php @@ -5,15 +5,16 @@ use PhpParser\Node; use PhpParser\Node\MatchArm; -class Match_ extends Node\Expr -{ - /** @var Node\Expr */ - public $cond; +class Match_ extends Node\Expr { + /** @var Node\Expr Condition */ + public Node\Expr $cond; /** @var MatchArm[] */ - public $arms; + public array $arms; /** + * @param Node\Expr $cond Condition * @param MatchArm[] $arms + * @param array $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $arms = [], array $attributes = []) { $this->attributes = $attributes; @@ -21,11 +22,11 @@ public function __construct(Node\Expr $cond, array $arms = [], array $attributes $this->arms = $arms; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['cond', 'arms']; } - public function getType() : string { + public function getType(): string { return 'Expr_Match'; } } diff --git a/lib/PhpParser/Node/Expr/MethodCall.php b/lib/PhpParser/Node/Expr/MethodCall.php index bd81bb43f6..2703c75d88 100644 --- a/lib/PhpParser/Node/Expr/MethodCall.php +++ b/lib/PhpParser/Node/Expr/MethodCall.php @@ -2,26 +2,27 @@ namespace PhpParser\Node\Expr; +use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr; use PhpParser\Node\Identifier; +use PhpParser\Node\VariadicPlaceholder; -class MethodCall extends Expr -{ +class MethodCall extends CallLike { /** @var Expr Variable holding object */ - public $var; + public Expr $var; /** @var Identifier|Expr Method name */ - public $name; - /** @var Arg[] Arguments */ - public $args; + public Node $name; + /** @var array Arguments */ + public array $args; /** * Constructs a function call node. * - * @param Expr $var Variable holding object - * @param string|Identifier|Expr $name Method name - * @param Arg[] $args Arguments - * @param array $attributes Additional attributes + * @param Expr $var Variable holding object + * @param string|Identifier|Expr $name Method name + * @param array $args Arguments + * @param array $attributes Additional attributes */ public function __construct(Expr $var, $name, array $args = [], array $attributes = []) { $this->attributes = $attributes; @@ -30,11 +31,15 @@ public function __construct(Expr $var, $name, array $args = [], array $attribute $this->args = $args; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['var', 'name', 'args']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_MethodCall'; } + + public function getRawArgs(): array { + return $this->args; + } } diff --git a/lib/PhpParser/Node/Expr/New_.php b/lib/PhpParser/Node/Expr/New_.php index c86f0c6015..eedaaa1e3b 100644 --- a/lib/PhpParser/Node/Expr/New_.php +++ b/lib/PhpParser/Node/Expr/New_.php @@ -3,33 +3,38 @@ namespace PhpParser\Node\Expr; use PhpParser\Node; +use PhpParser\Node\Arg; use PhpParser\Node\Expr; +use PhpParser\Node\VariadicPlaceholder; -class New_ extends Expr -{ +class New_ extends CallLike { /** @var Node\Name|Expr|Node\Stmt\Class_ Class name */ - public $class; - /** @var Node\Arg[] Arguments */ - public $args; + public Node $class; + /** @var array Arguments */ + public array $args; /** * Constructs a function call node. * - * @param Node\Name|Expr|Node\Stmt\Class_ $class Class name (or class node for anonymous classes) - * @param Node\Arg[] $args Arguments - * @param array $attributes Additional attributes + * @param Node\Name|Expr|Node\Stmt\Class_ $class Class name (or class node for anonymous classes) + * @param array $args Arguments + * @param array $attributes Additional attributes */ - public function __construct($class, array $args = [], array $attributes = []) { + public function __construct(Node $class, array $args = [], array $attributes = []) { $this->attributes = $attributes; $this->class = $class; $this->args = $args; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['class', 'args']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_New'; } + + public function getRawArgs(): array { + return $this->args; + } } diff --git a/lib/PhpParser/Node/Expr/NullsafeMethodCall.php b/lib/PhpParser/Node/Expr/NullsafeMethodCall.php index 361e446227..a151f71528 100644 --- a/lib/PhpParser/Node/Expr/NullsafeMethodCall.php +++ b/lib/PhpParser/Node/Expr/NullsafeMethodCall.php @@ -2,26 +2,27 @@ namespace PhpParser\Node\Expr; +use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr; use PhpParser\Node\Identifier; +use PhpParser\Node\VariadicPlaceholder; -class NullsafeMethodCall extends Expr -{ +class NullsafeMethodCall extends CallLike { /** @var Expr Variable holding object */ - public $var; + public Expr $var; /** @var Identifier|Expr Method name */ - public $name; - /** @var Arg[] Arguments */ - public $args; + public Node $name; + /** @var array Arguments */ + public array $args; /** * Constructs a nullsafe method call node. * - * @param Expr $var Variable holding object - * @param string|Identifier|Expr $name Method name - * @param Arg[] $args Arguments - * @param array $attributes Additional attributes + * @param Expr $var Variable holding object + * @param string|Identifier|Expr $name Method name + * @param array $args Arguments + * @param array $attributes Additional attributes */ public function __construct(Expr $var, $name, array $args = [], array $attributes = []) { $this->attributes = $attributes; @@ -30,11 +31,15 @@ public function __construct(Expr $var, $name, array $args = [], array $attribute $this->args = $args; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['var', 'name', 'args']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_NullsafeMethodCall'; } + + public function getRawArgs(): array { + return $this->args; + } } diff --git a/lib/PhpParser/Node/Expr/NullsafePropertyFetch.php b/lib/PhpParser/Node/Expr/NullsafePropertyFetch.php index 9317eb3b91..6f73a16d76 100644 --- a/lib/PhpParser/Node/Expr/NullsafePropertyFetch.php +++ b/lib/PhpParser/Node/Expr/NullsafePropertyFetch.php @@ -2,22 +2,22 @@ namespace PhpParser\Node\Expr; +use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Identifier; -class NullsafePropertyFetch extends Expr -{ +class NullsafePropertyFetch extends Expr { /** @var Expr Variable holding object */ - public $var; + public Expr $var; /** @var Identifier|Expr Property name */ - public $name; + public Node $name; /** * Constructs a nullsafe property fetch node. * - * @param Expr $var Variable holding object - * @param string|Identifier|Expr $name Property name - * @param array $attributes Additional attributes + * @param Expr $var Variable holding object + * @param string|Identifier|Expr $name Property name + * @param array $attributes Additional attributes */ public function __construct(Expr $var, $name, array $attributes = []) { $this->attributes = $attributes; @@ -25,11 +25,11 @@ public function __construct(Expr $var, $name, array $attributes = []) { $this->name = \is_string($name) ? new Identifier($name) : $name; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['var', 'name']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_NullsafePropertyFetch'; } } diff --git a/lib/PhpParser/Node/Expr/PostDec.php b/lib/PhpParser/Node/Expr/PostDec.php index 94d6c296d8..3dca8fdc5a 100644 --- a/lib/PhpParser/Node/Expr/PostDec.php +++ b/lib/PhpParser/Node/Expr/PostDec.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class PostDec extends Expr -{ +class PostDec extends Expr { /** @var Expr Variable */ - public $var; + public Expr $var; /** * Constructs a post decrement node. * - * @param Expr $var Variable - * @param array $attributes Additional attributes + * @param Expr $var Variable + * @param array $attributes Additional attributes */ public function __construct(Expr $var, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['var']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_PostDec'; } } diff --git a/lib/PhpParser/Node/Expr/PostInc.php b/lib/PhpParser/Node/Expr/PostInc.php index 005c443a2d..bc990c3030 100644 --- a/lib/PhpParser/Node/Expr/PostInc.php +++ b/lib/PhpParser/Node/Expr/PostInc.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class PostInc extends Expr -{ +class PostInc extends Expr { /** @var Expr Variable */ - public $var; + public Expr $var; /** * Constructs a post increment node. * - * @param Expr $var Variable - * @param array $attributes Additional attributes + * @param Expr $var Variable + * @param array $attributes Additional attributes */ public function __construct(Expr $var, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['var']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_PostInc'; } } diff --git a/lib/PhpParser/Node/Expr/PreDec.php b/lib/PhpParser/Node/Expr/PreDec.php index a5ca685a8a..2f16873016 100644 --- a/lib/PhpParser/Node/Expr/PreDec.php +++ b/lib/PhpParser/Node/Expr/PreDec.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class PreDec extends Expr -{ +class PreDec extends Expr { /** @var Expr Variable */ - public $var; + public Expr $var; /** * Constructs a pre decrement node. * - * @param Expr $var Variable - * @param array $attributes Additional attributes + * @param Expr $var Variable + * @param array $attributes Additional attributes */ public function __construct(Expr $var, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['var']; } - public function getType() : string { + public function getType(): string { return 'Expr_PreDec'; } } diff --git a/lib/PhpParser/Node/Expr/PreInc.php b/lib/PhpParser/Node/Expr/PreInc.php index 0986c44748..fd455f55b9 100644 --- a/lib/PhpParser/Node/Expr/PreInc.php +++ b/lib/PhpParser/Node/Expr/PreInc.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class PreInc extends Expr -{ +class PreInc extends Expr { /** @var Expr Variable */ - public $var; + public Expr $var; /** * Constructs a pre increment node. * - * @param Expr $var Variable - * @param array $attributes Additional attributes + * @param Expr $var Variable + * @param array $attributes Additional attributes */ public function __construct(Expr $var, array $attributes = []) { $this->attributes = $attributes; $this->var = $var; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['var']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_PreInc'; } } diff --git a/lib/PhpParser/Node/Expr/Print_.php b/lib/PhpParser/Node/Expr/Print_.php index 2d43c2ac82..605747604d 100644 --- a/lib/PhpParser/Node/Expr/Print_.php +++ b/lib/PhpParser/Node/Expr/Print_.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class Print_ extends Expr -{ +class Print_ extends Expr { /** @var Expr Expression */ - public $expr; + public Expr $expr; /** * Constructs an print() node. * - * @param Expr $expr Expression - * @param array $attributes Additional attributes + * @param Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_Print'; } } diff --git a/lib/PhpParser/Node/Expr/PropertyFetch.php b/lib/PhpParser/Node/Expr/PropertyFetch.php index 4281f31ccf..8c416a8c40 100644 --- a/lib/PhpParser/Node/Expr/PropertyFetch.php +++ b/lib/PhpParser/Node/Expr/PropertyFetch.php @@ -2,22 +2,22 @@ namespace PhpParser\Node\Expr; +use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Identifier; -class PropertyFetch extends Expr -{ +class PropertyFetch extends Expr { /** @var Expr Variable holding object */ - public $var; + public Expr $var; /** @var Identifier|Expr Property name */ - public $name; + public Node $name; /** * Constructs a function call node. * - * @param Expr $var Variable holding object - * @param string|Identifier|Expr $name Property name - * @param array $attributes Additional attributes + * @param Expr $var Variable holding object + * @param string|Identifier|Expr $name Property name + * @param array $attributes Additional attributes */ public function __construct(Expr $var, $name, array $attributes = []) { $this->attributes = $attributes; @@ -25,11 +25,11 @@ public function __construct(Expr $var, $name, array $attributes = []) { $this->name = \is_string($name) ? new Identifier($name) : $name; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['var', 'name']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_PropertyFetch'; } } diff --git a/lib/PhpParser/Node/Expr/ShellExec.php b/lib/PhpParser/Node/Expr/ShellExec.php index 537a7cc809..e400351277 100644 --- a/lib/PhpParser/Node/Expr/ShellExec.php +++ b/lib/PhpParser/Node/Expr/ShellExec.php @@ -3,28 +3,28 @@ namespace PhpParser\Node\Expr; use PhpParser\Node\Expr; +use PhpParser\Node\InterpolatedStringPart; -class ShellExec extends Expr -{ - /** @var array Encapsed string array */ - public $parts; +class ShellExec extends Expr { + /** @var (Expr|InterpolatedStringPart)[] Interpolated string array */ + public array $parts; /** * Constructs a shell exec (backtick) node. * - * @param array $parts Encapsed string array - * @param array $attributes Additional attributes + * @param (Expr|InterpolatedStringPart)[] $parts Interpolated string array + * @param array $attributes Additional attributes */ public function __construct(array $parts, array $attributes = []) { $this->attributes = $attributes; $this->parts = $parts; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['parts']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_ShellExec'; } } diff --git a/lib/PhpParser/Node/Expr/StaticCall.php b/lib/PhpParser/Node/Expr/StaticCall.php index 9883f5af51..707f34b669 100644 --- a/lib/PhpParser/Node/Expr/StaticCall.php +++ b/lib/PhpParser/Node/Expr/StaticCall.php @@ -3,38 +3,43 @@ namespace PhpParser\Node\Expr; use PhpParser\Node; +use PhpParser\Node\Arg; use PhpParser\Node\Expr; use PhpParser\Node\Identifier; +use PhpParser\Node\VariadicPlaceholder; -class StaticCall extends Expr -{ +class StaticCall extends CallLike { /** @var Node\Name|Expr Class name */ - public $class; + public Node $class; /** @var Identifier|Expr Method name */ - public $name; - /** @var Node\Arg[] Arguments */ - public $args; + public Node $name; + /** @var array Arguments */ + public array $args; /** * Constructs a static method call node. * - * @param Node\Name|Expr $class Class name - * @param string|Identifier|Expr $name Method name - * @param Node\Arg[] $args Arguments - * @param array $attributes Additional attributes + * @param Node\Name|Expr $class Class name + * @param string|Identifier|Expr $name Method name + * @param array $args Arguments + * @param array $attributes Additional attributes */ - public function __construct($class, $name, array $args = [], array $attributes = []) { + public function __construct(Node $class, $name, array $args = [], array $attributes = []) { $this->attributes = $attributes; $this->class = $class; $this->name = \is_string($name) ? new Identifier($name) : $name; $this->args = $args; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['class', 'name', 'args']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_StaticCall'; } + + public function getRawArgs(): array { + return $this->args; + } } diff --git a/lib/PhpParser/Node/Expr/StaticPropertyFetch.php b/lib/PhpParser/Node/Expr/StaticPropertyFetch.php index 1ee1a25e50..4836a65b23 100644 --- a/lib/PhpParser/Node/Expr/StaticPropertyFetch.php +++ b/lib/PhpParser/Node/Expr/StaticPropertyFetch.php @@ -2,35 +2,35 @@ namespace PhpParser\Node\Expr; +use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Name; use PhpParser\Node\VarLikeIdentifier; -class StaticPropertyFetch extends Expr -{ +class StaticPropertyFetch extends Expr { /** @var Name|Expr Class name */ - public $class; + public Node $class; /** @var VarLikeIdentifier|Expr Property name */ - public $name; + public Node $name; /** * Constructs a static property fetch node. * - * @param Name|Expr $class Class name - * @param string|VarLikeIdentifier|Expr $name Property name - * @param array $attributes Additional attributes + * @param Name|Expr $class Class name + * @param string|VarLikeIdentifier|Expr $name Property name + * @param array $attributes Additional attributes */ - public function __construct($class, $name, array $attributes = []) { + public function __construct(Node $class, $name, array $attributes = []) { $this->attributes = $attributes; $this->class = $class; $this->name = \is_string($name) ? new VarLikeIdentifier($name) : $name; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['class', 'name']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_StaticPropertyFetch'; } } diff --git a/lib/PhpParser/Node/Expr/Ternary.php b/lib/PhpParser/Node/Expr/Ternary.php index 9316f47d4d..d4837e6402 100644 --- a/lib/PhpParser/Node/Expr/Ternary.php +++ b/lib/PhpParser/Node/Expr/Ternary.php @@ -4,35 +4,34 @@ use PhpParser\Node\Expr; -class Ternary extends Expr -{ +class Ternary extends Expr { /** @var Expr Condition */ - public $cond; + public Expr $cond; /** @var null|Expr Expression for true */ - public $if; + public ?Expr $if; /** @var Expr Expression for false */ - public $else; + public Expr $else; /** * Constructs a ternary operator node. * - * @param Expr $cond Condition - * @param null|Expr $if Expression for true - * @param Expr $else Expression for false - * @param array $attributes Additional attributes + * @param Expr $cond Condition + * @param null|Expr $if Expression for true + * @param Expr $else Expression for false + * @param array $attributes Additional attributes */ - public function __construct(Expr $cond, $if, Expr $else, array $attributes = []) { + public function __construct(Expr $cond, ?Expr $if, Expr $else, array $attributes = []) { $this->attributes = $attributes; $this->cond = $cond; $this->if = $if; $this->else = $else; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['cond', 'if', 'else']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_Ternary'; } } diff --git a/lib/PhpParser/Node/Expr/Throw_.php b/lib/PhpParser/Node/Expr/Throw_.php index 5c97f0e2b4..ee49f835fb 100644 --- a/lib/PhpParser/Node/Expr/Throw_.php +++ b/lib/PhpParser/Node/Expr/Throw_.php @@ -4,27 +4,26 @@ use PhpParser\Node; -class Throw_ extends Node\Expr -{ +class Throw_ extends Node\Expr { /** @var Node\Expr Expression */ - public $expr; + public Node\Expr $expr; /** * Constructs a throw expression node. * - * @param Node\Expr $expr Expression - * @param array $attributes Additional attributes + * @param Node\Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Node\Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr']; } - public function getType() : string { + public function getType(): string { return 'Expr_Throw'; } } diff --git a/lib/PhpParser/Node/Expr/UnaryMinus.php b/lib/PhpParser/Node/Expr/UnaryMinus.php index ce8808bc64..cd06f74bab 100644 --- a/lib/PhpParser/Node/Expr/UnaryMinus.php +++ b/lib/PhpParser/Node/Expr/UnaryMinus.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class UnaryMinus extends Expr -{ +class UnaryMinus extends Expr { /** @var Expr Expression */ - public $expr; + public Expr $expr; /** * Constructs a unary minus node. * - * @param Expr $expr Expression - * @param array $attributes Additional attributes + * @param Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_UnaryMinus'; } } diff --git a/lib/PhpParser/Node/Expr/UnaryPlus.php b/lib/PhpParser/Node/Expr/UnaryPlus.php index d23047e54e..1b44f7b3e7 100644 --- a/lib/PhpParser/Node/Expr/UnaryPlus.php +++ b/lib/PhpParser/Node/Expr/UnaryPlus.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class UnaryPlus extends Expr -{ +class UnaryPlus extends Expr { /** @var Expr Expression */ - public $expr; + public Expr $expr; /** * Constructs a unary plus node. * - * @param Expr $expr Expression - * @param array $attributes Additional attributes + * @param Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_UnaryPlus'; } } diff --git a/lib/PhpParser/Node/Expr/Variable.php b/lib/PhpParser/Node/Expr/Variable.php index b47d38e934..bab74920a1 100644 --- a/lib/PhpParser/Node/Expr/Variable.php +++ b/lib/PhpParser/Node/Expr/Variable.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class Variable extends Expr -{ +class Variable extends Expr { /** @var string|Expr Name */ public $name; /** * Constructs a variable node. * - * @param string|Expr $name Name - * @param array $attributes Additional attributes + * @param string|Expr $name Name + * @param array $attributes Additional attributes */ public function __construct($name, array $attributes = []) { $this->attributes = $attributes; $this->name = $name; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['name']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_Variable'; } } diff --git a/lib/PhpParser/Node/Expr/YieldFrom.php b/lib/PhpParser/Node/Expr/YieldFrom.php index a3efce618c..5cff88f869 100644 --- a/lib/PhpParser/Node/Expr/YieldFrom.php +++ b/lib/PhpParser/Node/Expr/YieldFrom.php @@ -4,27 +4,26 @@ use PhpParser\Node\Expr; -class YieldFrom extends Expr -{ +class YieldFrom extends Expr { /** @var Expr Expression to yield from */ - public $expr; + public Expr $expr; /** * Constructs an "yield from" node. * - * @param Expr $expr Expression - * @param array $attributes Additional attributes + * @param Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_YieldFrom'; } } diff --git a/lib/PhpParser/Node/Expr/Yield_.php b/lib/PhpParser/Node/Expr/Yield_.php index aef8fc333d..bd81e69b31 100644 --- a/lib/PhpParser/Node/Expr/Yield_.php +++ b/lib/PhpParser/Node/Expr/Yield_.php @@ -4,31 +4,30 @@ use PhpParser\Node\Expr; -class Yield_ extends Expr -{ +class Yield_ extends Expr { /** @var null|Expr Key expression */ - public $key; + public ?Expr $key; /** @var null|Expr Value expression */ - public $value; + public ?Expr $value; /** * Constructs a yield expression node. * - * @param null|Expr $value Value expression - * @param null|Expr $key Key expression - * @param array $attributes Additional attributes + * @param null|Expr $value Value expression + * @param null|Expr $key Key expression + * @param array $attributes Additional attributes */ - public function __construct(Expr $value = null, Expr $key = null, array $attributes = []) { + public function __construct(?Expr $value = null, ?Expr $key = null, array $attributes = []) { $this->attributes = $attributes; $this->key = $key; $this->value = $value; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['key', 'value']; } - - public function getType() : string { + + public function getType(): string { return 'Expr_Yield'; } } diff --git a/lib/PhpParser/Node/FunctionLike.php b/lib/PhpParser/Node/FunctionLike.php index bbcf53e55f..58f653a89f 100644 --- a/lib/PhpParser/Node/FunctionLike.php +++ b/lib/PhpParser/Node/FunctionLike.php @@ -4,26 +4,23 @@ use PhpParser\Node; -interface FunctionLike extends Node -{ +interface FunctionLike extends Node { /** * Whether to return by reference - * - * @return bool */ - public function returnsByRef() : bool; + public function returnsByRef(): bool; /** * List of parameters * * @return Param[] */ - public function getParams() : array; + public function getParams(): array; /** * Get the declared return type or null * - * @return null|Identifier|Name|NullableType|UnionType + * @return null|Identifier|Name|ComplexType */ public function getReturnType(); @@ -32,12 +29,12 @@ public function getReturnType(); * * @return Stmt[]|null */ - public function getStmts(); + public function getStmts(): ?array; /** * Get PHP attribute groups. * * @return AttributeGroup[] */ - public function getAttrGroups() : array; + public function getAttrGroups(): array; } diff --git a/lib/PhpParser/Node/Identifier.php b/lib/PhpParser/Node/Identifier.php index 2f262db0aa..21473fad18 100644 --- a/lib/PhpParser/Node/Identifier.php +++ b/lib/PhpParser/Node/Identifier.php @@ -7,12 +7,15 @@ /** * Represents a non-namespaced name. Namespaced names are represented using Name nodes. */ -class Identifier extends NodeAbstract -{ - /** @var string Identifier as string */ - public $name; +class Identifier extends NodeAbstract { + /** + * @psalm-var non-empty-string + * @var string Identifier as string + */ + public string $name; - private static $specialClassNames = [ + /** @var array */ + private static array $specialClassNames = [ 'self' => true, 'parent' => true, 'static' => true, @@ -21,33 +24,39 @@ class Identifier extends NodeAbstract /** * Constructs an identifier node. * - * @param string $name Identifier as string - * @param array $attributes Additional attributes + * @param string $name Identifier as string + * @param array $attributes Additional attributes */ public function __construct(string $name, array $attributes = []) { + if ($name === '') { + throw new \InvalidArgumentException('Identifier name cannot be empty'); + } + $this->attributes = $attributes; $this->name = $name; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['name']; } /** * Get identifier as string. * + * @psalm-return non-empty-string * @return string Identifier as string. */ - public function toString() : string { + public function toString(): string { return $this->name; } /** * Get lowercased identifier as string. * + * @psalm-return non-empty-string&lowercase-string * @return string Lowercased identifier as string */ - public function toLowerString() : string { + public function toLowerString(): string { return strtolower($this->name); } @@ -56,20 +65,21 @@ public function toLowerString() : string { * * @return bool Whether identifier is a special class name */ - public function isSpecialClassName() : bool { + public function isSpecialClassName(): bool { return isset(self::$specialClassNames[strtolower($this->name)]); } /** * Get identifier as string. * + * @psalm-return non-empty-string * @return string Identifier as string */ - public function __toString() : string { + public function __toString(): string { return $this->name; } - - public function getType() : string { + + public function getType(): string { return 'Identifier'; } } diff --git a/lib/PhpParser/Node/InterpolatedStringPart.php b/lib/PhpParser/Node/InterpolatedStringPart.php new file mode 100644 index 0000000000..576dac46f5 --- /dev/null +++ b/lib/PhpParser/Node/InterpolatedStringPart.php @@ -0,0 +1,32 @@ + $attributes Additional attributes + */ + public function __construct(string $value, array $attributes = []) { + $this->attributes = $attributes; + $this->value = $value; + } + + public function getSubNodeNames(): array { + return ['value']; + } + + public function getType(): string { + return 'InterpolatedStringPart'; + } +} + +// @deprecated compatibility alias +class_alias(InterpolatedStringPart::class, Scalar\EncapsedStringPart::class); diff --git a/lib/PhpParser/Node/IntersectionType.php b/lib/PhpParser/Node/IntersectionType.php new file mode 100644 index 0000000000..3b39cf105b --- /dev/null +++ b/lib/PhpParser/Node/IntersectionType.php @@ -0,0 +1,27 @@ + $attributes Additional attributes + */ + public function __construct(array $types, array $attributes = []) { + $this->attributes = $attributes; + $this->types = $types; + } + + public function getSubNodeNames(): array { + return ['types']; + } + + public function getType(): string { + return 'IntersectionType'; + } +} diff --git a/lib/PhpParser/Node/MatchArm.php b/lib/PhpParser/Node/MatchArm.php index 2ae1c86b85..192216dfb3 100644 --- a/lib/PhpParser/Node/MatchArm.php +++ b/lib/PhpParser/Node/MatchArm.php @@ -5,27 +5,25 @@ use PhpParser\Node; use PhpParser\NodeAbstract; -class MatchArm extends NodeAbstract -{ - /** @var null|Node\Expr[] */ - public $conds; - /** @var Node\Expr */ - public $body; +class MatchArm extends NodeAbstract { + /** @var null|list */ + public ?array $conds; + public Expr $body; /** - * @param null|Node\Expr[] $conds + * @param null|list $conds */ - public function __construct($conds, Node\Expr $body, array $attributes = []) { + public function __construct(?array $conds, Node\Expr $body, array $attributes = []) { $this->conds = $conds; $this->body = $body; $this->attributes = $attributes; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['conds', 'body']; } - public function getType() : string { + public function getType(): string { return 'MatchArm'; } } diff --git a/lib/PhpParser/Node/Name.php b/lib/PhpParser/Node/Name.php index 6b1cc9f8ed..932080b544 100644 --- a/lib/PhpParser/Node/Name.php +++ b/lib/PhpParser/Node/Name.php @@ -4,12 +4,15 @@ use PhpParser\NodeAbstract; -class Name extends NodeAbstract -{ - /** @var string[] Parts of the name */ - public $parts; +class Name extends NodeAbstract { + /** + * @psalm-var non-empty-string + * @var string Name as string + */ + public string $name; - private static $specialClassNames = [ + /** @var array */ + private static array $specialClassNames = [ 'self' => true, 'parent' => true, 'static' => true, @@ -18,16 +21,26 @@ class Name extends NodeAbstract /** * Constructs a name node. * - * @param string|string[]|self $name Name as string, part array or Name instance (copy ctor) - * @param array $attributes Additional attributes + * @param string|string[]|self $name Name as string, part array or Name instance (copy ctor) + * @param array $attributes Additional attributes */ - public function __construct($name, array $attributes = []) { + final public function __construct($name, array $attributes = []) { $this->attributes = $attributes; - $this->parts = self::prepareName($name); + $this->name = self::prepareName($name); } - public function getSubNodeNames() : array { - return ['parts']; + public function getSubNodeNames(): array { + return ['name']; + } + + /** + * Get parts of name (split by the namespace separator). + * + * @psalm-return non-empty-list + * @return string[] Parts of name + */ + public function getParts(): array { + return \explode('\\', $this->name); } /** @@ -35,8 +48,11 @@ public function getSubNodeNames() : array { * * @return string First part of the name */ - public function getFirst() : string { - return $this->parts[0]; + public function getFirst(): string { + if (false !== $pos = \strpos($this->name, '\\')) { + return \substr($this->name, 0, $pos); + } + return $this->name; } /** @@ -44,8 +60,11 @@ public function getFirst() : string { * * @return string Last part of the name */ - public function getLast() : string { - return $this->parts[count($this->parts) - 1]; + public function getLast(): string { + if (false !== $pos = \strrpos($this->name, '\\')) { + return \substr($this->name, $pos + 1); + } + return $this->name; } /** @@ -53,8 +72,8 @@ public function getLast() : string { * * @return bool Whether the name is unqualified */ - public function isUnqualified() : bool { - return 1 === count($this->parts); + public function isUnqualified(): bool { + return false === \strpos($this->name, '\\'); } /** @@ -62,8 +81,8 @@ public function isUnqualified() : bool { * * @return bool Whether the name is qualified */ - public function isQualified() : bool { - return 1 < count($this->parts); + public function isQualified(): bool { + return false !== \strpos($this->name, '\\'); } /** @@ -71,7 +90,7 @@ public function isQualified() : bool { * * @return bool Whether the name is fully qualified */ - public function isFullyQualified() : bool { + public function isFullyQualified(): bool { return false; } @@ -80,7 +99,7 @@ public function isFullyQualified() : bool { * * @return bool Whether the name is relative */ - public function isRelative() : bool { + public function isRelative(): bool { return false; } @@ -88,19 +107,21 @@ public function isRelative() : bool { * Returns a string representation of the name itself, without taking the name type into * account (e.g., not including a leading backslash for fully qualified names). * + * @psalm-return non-empty-string * @return string String representation */ - public function toString() : string { - return implode('\\', $this->parts); + public function toString(): string { + return $this->name; } /** * Returns a string representation of the name as it would occur in code (e.g., including * leading backslash for fully qualified names. * + * @psalm-return non-empty-string * @return string String representation */ - public function toCodeString() : string { + public function toCodeString(): string { return $this->toString(); } @@ -108,10 +129,11 @@ public function toCodeString() : string { * Returns lowercased string representation of the name, without taking the name type into * account (e.g., no leading backslash for fully qualified names). * + * @psalm-return non-empty-string&lowercase-string * @return string Lowercased string representation */ - public function toLowerString() : string { - return strtolower(implode('\\', $this->parts)); + public function toLowerString(): string { + return strtolower($this->name); } /** @@ -119,19 +141,19 @@ public function toLowerString() : string { * * @return bool Whether identifier is a special class name */ - public function isSpecialClassName() : bool { - return count($this->parts) === 1 - && isset(self::$specialClassNames[strtolower($this->parts[0])]); + public function isSpecialClassName(): bool { + return isset(self::$specialClassNames[strtolower($this->name)]); } /** * Returns a string representation of the name by imploding the namespace parts with the * namespace separator. * + * @psalm-return non-empty-string * @return string String representation */ - public function __toString() : string { - return implode('\\', $this->parts); + public function __toString(): string { + return $this->name; } /** @@ -145,13 +167,22 @@ public function __toString() : string { * * Offset and length have the same meaning as in array_slice(). * - * @param int $offset Offset to start the slice at (may be negative) + * @param int $offset Offset to start the slice at (may be negative) * @param int|null $length Length of the slice (may be negative) * * @return static|null Sliced name */ - public function slice(int $offset, int $length = null) { - $numParts = count($this->parts); + public function slice(int $offset, ?int $length = null) { + if ($offset === 1 && $length === null) { + // Short-circuit the common case. + if (false !== $pos = \strpos($this->name, '\\')) { + return new static(\substr($this->name, $pos + 1)); + } + return null; + } + + $parts = \explode('\\', $this->name); + $numParts = \count($parts); $realOffset = $offset < 0 ? $offset + $numParts : $offset; if ($realOffset < 0 || $realOffset > $numParts) { @@ -162,7 +193,7 @@ public function slice(int $offset, int $length = null) { $realLength = $numParts - $realOffset; } else { $realLength = $length < 0 ? $length + $numParts - $realOffset : $length; - if ($realLength < 0 || $realLength > $numParts) { + if ($realLength < 0 || $realLength > $numParts - $realOffset) { throw new \OutOfBoundsException(sprintf('Length %d is out of bounds', $length)); } } @@ -172,7 +203,7 @@ public function slice(int $offset, int $length = null) { return null; } - return new static(array_slice($this->parts, $realOffset, $realLength), $this->attributes); + return new static(array_slice($parts, $realOffset, $realLength), $this->attributes); } /** @@ -186,49 +217,54 @@ public function slice(int $offset, int $length = null) { * Name::concat($namespace, $shortName) * where $namespace is a Name node or null will work as expected. * - * @param string|string[]|self|null $name1 The first name - * @param string|string[]|self|null $name2 The second name - * @param array $attributes Attributes to assign to concatenated name + * @param string|string[]|self|null $name1 The first name + * @param string|string[]|self|null $name2 The second name + * @param array $attributes Attributes to assign to concatenated name * * @return static|null Concatenated name */ public static function concat($name1, $name2, array $attributes = []) { if (null === $name1 && null === $name2) { return null; - } elseif (null === $name1) { - return new static(self::prepareName($name2), $attributes); - } elseif (null === $name2) { - return new static(self::prepareName($name1), $attributes); + } + if (null === $name1) { + return new static($name2, $attributes); + } + if (null === $name2) { + return new static($name1, $attributes); } else { return new static( - array_merge(self::prepareName($name1), self::prepareName($name2)), $attributes + self::prepareName($name1) . '\\' . self::prepareName($name2), $attributes ); } } /** * Prepares a (string, array or Name node) name for use in name changing methods by converting - * it to an array. + * it to a string. * * @param string|string[]|self $name Name to prepare * - * @return string[] Prepared name + * @psalm-return non-empty-string + * @return string Prepared name */ - private static function prepareName($name) : array { + private static function prepareName($name): string { if (\is_string($name)) { if ('' === $name) { throw new \InvalidArgumentException('Name cannot be empty'); } - return explode('\\', $name); - } elseif (\is_array($name)) { + return $name; + } + if (\is_array($name)) { if (empty($name)) { throw new \InvalidArgumentException('Name cannot be empty'); } - return $name; - } elseif ($name instanceof self) { - return $name->parts; + return implode('\\', $name); + } + if ($name instanceof self) { + return $name->name; } throw new \InvalidArgumentException( @@ -236,7 +272,7 @@ private static function prepareName($name) : array { ); } - public function getType() : string { + public function getType(): string { return 'Name'; } } diff --git a/lib/PhpParser/Node/Name/FullyQualified.php b/lib/PhpParser/Node/Name/FullyQualified.php index 1df93a56b6..21183786ba 100644 --- a/lib/PhpParser/Node/Name/FullyQualified.php +++ b/lib/PhpParser/Node/Name/FullyQualified.php @@ -2,14 +2,13 @@ namespace PhpParser\Node\Name; -class FullyQualified extends \PhpParser\Node\Name -{ +class FullyQualified extends \PhpParser\Node\Name { /** * Checks whether the name is unqualified. (E.g. Name) * * @return bool Whether the name is unqualified */ - public function isUnqualified() : bool { + public function isUnqualified(): bool { return false; } @@ -18,7 +17,7 @@ public function isUnqualified() : bool { * * @return bool Whether the name is qualified */ - public function isQualified() : bool { + public function isQualified(): bool { return false; } @@ -27,7 +26,7 @@ public function isQualified() : bool { * * @return bool Whether the name is fully qualified */ - public function isFullyQualified() : bool { + public function isFullyQualified(): bool { return true; } @@ -36,15 +35,15 @@ public function isFullyQualified() : bool { * * @return bool Whether the name is relative */ - public function isRelative() : bool { + public function isRelative(): bool { return false; } - public function toCodeString() : string { + public function toCodeString(): string { return '\\' . $this->toString(); } - - public function getType() : string { + + public function getType(): string { return 'Name_FullyQualified'; } } diff --git a/lib/PhpParser/Node/Name/Relative.php b/lib/PhpParser/Node/Name/Relative.php index 57bf7af2b2..0226a4e485 100644 --- a/lib/PhpParser/Node/Name/Relative.php +++ b/lib/PhpParser/Node/Name/Relative.php @@ -2,14 +2,13 @@ namespace PhpParser\Node\Name; -class Relative extends \PhpParser\Node\Name -{ +class Relative extends \PhpParser\Node\Name { /** * Checks whether the name is unqualified. (E.g. Name) * * @return bool Whether the name is unqualified */ - public function isUnqualified() : bool { + public function isUnqualified(): bool { return false; } @@ -18,7 +17,7 @@ public function isUnqualified() : bool { * * @return bool Whether the name is qualified */ - public function isQualified() : bool { + public function isQualified(): bool { return false; } @@ -27,7 +26,7 @@ public function isQualified() : bool { * * @return bool Whether the name is fully qualified */ - public function isFullyQualified() : bool { + public function isFullyQualified(): bool { return false; } @@ -36,15 +35,15 @@ public function isFullyQualified() : bool { * * @return bool Whether the name is relative */ - public function isRelative() : bool { + public function isRelative(): bool { return true; } - public function toCodeString() : string { + public function toCodeString(): string { return 'namespace\\' . $this->toString(); } - - public function getType() : string { + + public function getType(): string { return 'Name_Relative'; } } diff --git a/lib/PhpParser/Node/NullableType.php b/lib/PhpParser/Node/NullableType.php index 36463657e9..b99acd1351 100644 --- a/lib/PhpParser/Node/NullableType.php +++ b/lib/PhpParser/Node/NullableType.php @@ -2,29 +2,28 @@ namespace PhpParser\Node; -use PhpParser\NodeAbstract; +use PhpParser\Node; -class NullableType extends NodeAbstract -{ +class NullableType extends ComplexType { /** @var Identifier|Name Type */ - public $type; + public Node $type; /** * Constructs a nullable type (wrapping another type). * - * @param string|Identifier|Name $type Type - * @param array $attributes Additional attributes + * @param Identifier|Name $type Type + * @param array $attributes Additional attributes */ - public function __construct($type, array $attributes = []) { + public function __construct(Node $type, array $attributes = []) { $this->attributes = $attributes; - $this->type = \is_string($type) ? new Identifier($type) : $type; + $this->type = $type; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['type']; } - - public function getType() : string { + + public function getType(): string { return 'NullableType'; } } diff --git a/lib/PhpParser/Node/Param.php b/lib/PhpParser/Node/Param.php index 315b5f24f6..6634930bd5 100644 --- a/lib/PhpParser/Node/Param.php +++ b/lib/PhpParser/Node/Param.php @@ -2,59 +2,118 @@ namespace PhpParser\Node; +use PhpParser\Modifiers; +use PhpParser\Node; use PhpParser\NodeAbstract; -class Param extends NodeAbstract -{ - /** @var null|Identifier|Name|NullableType|UnionType Type declaration */ - public $type; +class Param extends NodeAbstract { + /** @var null|Identifier|Name|ComplexType Type declaration */ + public ?Node $type; /** @var bool Whether parameter is passed by reference */ - public $byRef; + public bool $byRef; /** @var bool Whether this is a variadic argument */ - public $variadic; + public bool $variadic; /** @var Expr\Variable|Expr\Error Parameter variable */ - public $var; + public Expr $var; /** @var null|Expr Default value */ - public $default; - /** @var int */ - public $flags; + public ?Expr $default; + /** @var int Optional visibility flags */ + public int $flags; /** @var AttributeGroup[] PHP attribute groups */ - public $attrGroups; + public array $attrGroups; + /** @var PropertyHook[] Property hooks for promoted properties */ + public array $hooks; /** * Constructs a parameter node. * - * @param Expr\Variable|Expr\Error $var Parameter variable - * @param null|Expr $default Default value - * @param null|string|Identifier|Name|NullableType|UnionType $type Type declaration - * @param bool $byRef Whether is passed by reference - * @param bool $variadic Whether this is a variadic argument - * @param array $attributes Additional attributes - * @param int $flags Optional visibility flags - * @param AttributeGroup[] $attrGroups PHP attribute groups + * @param Expr\Variable|Expr\Error $var Parameter variable + * @param null|Expr $default Default value + * @param null|Identifier|Name|ComplexType $type Type declaration + * @param bool $byRef Whether is passed by reference + * @param bool $variadic Whether this is a variadic argument + * @param array $attributes Additional attributes + * @param int $flags Optional visibility flags + * @param list $attrGroups PHP attribute groups + * @param PropertyHook[] $hooks Property hooks for promoted properties */ public function __construct( - $var, Expr $default = null, $type = null, + Expr $var, ?Expr $default = null, ?Node $type = null, bool $byRef = false, bool $variadic = false, array $attributes = [], int $flags = 0, - array $attrGroups = [] + array $attrGroups = [], + array $hooks = [] ) { $this->attributes = $attributes; - $this->type = \is_string($type) ? new Identifier($type) : $type; + $this->type = $type; $this->byRef = $byRef; $this->variadic = $variadic; $this->var = $var; $this->default = $default; $this->flags = $flags; $this->attrGroups = $attrGroups; + $this->hooks = $hooks; } - public function getSubNodeNames() : array { - return ['attrGroups', 'flags', 'type', 'byRef', 'variadic', 'var', 'default']; + public function getSubNodeNames(): array { + return ['attrGroups', 'flags', 'type', 'byRef', 'variadic', 'var', 'default', 'hooks']; } - public function getType() : string { + public function getType(): string { return 'Param'; } + + /** + * Whether this parameter uses constructor property promotion. + */ + public function isPromoted(): bool { + return $this->flags !== 0 || $this->hooks !== []; + } + + public function isPublic(): bool { + $public = (bool) ($this->flags & Modifiers::PUBLIC); + if ($public) { + return true; + } + + if (!$this->isPromoted()) { + return false; + } + + return ($this->flags & Modifiers::VISIBILITY_MASK) === 0; + } + + public function isProtected(): bool { + return (bool) ($this->flags & Modifiers::PROTECTED); + } + + public function isPrivate(): bool { + return (bool) ($this->flags & Modifiers::PRIVATE); + } + + public function isReadonly(): bool { + return (bool) ($this->flags & Modifiers::READONLY); + } + + /** + * Whether the promoted property has explicit public(set) visibility. + */ + public function isPublicSet(): bool { + return (bool) ($this->flags & Modifiers::PUBLIC_SET); + } + + /** + * Whether the promoted property has explicit protected(set) visibility. + */ + public function isProtectedSet(): bool { + return (bool) ($this->flags & Modifiers::PROTECTED_SET); + } + + /** + * Whether the promoted property has explicit private(set) visibility. + */ + public function isPrivateSet(): bool { + return (bool) ($this->flags & Modifiers::PRIVATE_SET); + } } diff --git a/lib/PhpParser/Node/PropertyHook.php b/lib/PhpParser/Node/PropertyHook.php new file mode 100644 index 0000000000..349b9cef4a --- /dev/null +++ b/lib/PhpParser/Node/PropertyHook.php @@ -0,0 +1,105 @@ + 0 : Flags + * 'byRef' => false : Whether hook returns by reference + * 'params' => array(): Parameters + * 'attrGroups' => array(): PHP attribute groups + * @param array $attributes Additional attributes + */ + public function __construct($name, $body, array $subNodes = [], array $attributes = []) { + $this->attributes = $attributes; + $this->name = \is_string($name) ? new Identifier($name) : $name; + $this->body = $body; + $this->flags = $subNodes['flags'] ?? 0; + $this->byRef = $subNodes['byRef'] ?? false; + $this->params = $subNodes['params'] ?? []; + $this->attrGroups = $subNodes['attrGroups'] ?? []; + } + + public function returnsByRef(): bool { + return $this->byRef; + } + + public function getParams(): array { + return $this->params; + } + + public function getReturnType() { + return null; + } + + /** + * Whether the property hook is final. + */ + public function isFinal(): bool { + return (bool) ($this->flags & Modifiers::FINAL); + } + + public function getStmts(): ?array { + if ($this->body instanceof Expr) { + $name = $this->name->toLowerString(); + if ($name === 'get') { + return [new Return_($this->body)]; + } + if ($name === 'set') { + if (!$this->hasAttribute('propertyName')) { + throw new \LogicException( + 'Can only use getStmts() on a "set" hook if the "propertyName" attribute is set'); + } + + $propName = $this->getAttribute('propertyName'); + $prop = new PropertyFetch(new Variable('this'), (string) $propName); + return [new Expression(new Assign($prop, $this->body))]; + } + throw new \LogicException('Unknown property hook "' . $name . '"'); + } + return $this->body; + } + + public function getAttrGroups(): array { + return $this->attrGroups; + } + + public function getType(): string { + return 'PropertyHook'; + } + + public function getSubNodeNames(): array { + return ['attrGroups', 'flags', 'byRef', 'name', 'params', 'body']; + } +} diff --git a/lib/PhpParser/Node/PropertyItem.php b/lib/PhpParser/Node/PropertyItem.php new file mode 100644 index 0000000000..101611e6bc --- /dev/null +++ b/lib/PhpParser/Node/PropertyItem.php @@ -0,0 +1,37 @@ + $attributes Additional attributes + */ + public function __construct($name, ?Node\Expr $default = null, array $attributes = []) { + $this->attributes = $attributes; + $this->name = \is_string($name) ? new Node\VarLikeIdentifier($name) : $name; + $this->default = $default; + } + + public function getSubNodeNames(): array { + return ['name', 'default']; + } + + public function getType(): string { + return 'PropertyItem'; + } +} + +// @deprecated compatibility alias +class_alias(PropertyItem::class, Stmt\PropertyProperty::class); diff --git a/lib/PhpParser/Node/Scalar.php b/lib/PhpParser/Node/Scalar.php index 8117909b65..3df2572169 100644 --- a/lib/PhpParser/Node/Scalar.php +++ b/lib/PhpParser/Node/Scalar.php @@ -2,6 +2,5 @@ namespace PhpParser\Node; -abstract class Scalar extends Expr -{ +abstract class Scalar extends Expr { } diff --git a/lib/PhpParser/Node/Scalar/DNumber.php b/lib/PhpParser/Node/Scalar/DNumber.php index 29ce0dd401..aaafc5fece 100644 --- a/lib/PhpParser/Node/Scalar/DNumber.php +++ b/lib/PhpParser/Node/Scalar/DNumber.php @@ -2,69 +2,10 @@ namespace PhpParser\Node\Scalar; -use PhpParser\Node\Scalar; +require __DIR__ . '/Float_.php'; -class DNumber extends Scalar -{ - /** @var float Number value */ - public $value; - - /** - * Constructs a float number scalar node. - * - * @param float $value Value of the number - * @param array $attributes Additional attributes - */ - public function __construct(float $value, array $attributes = []) { - $this->attributes = $attributes; - $this->value = $value; - } - - public function getSubNodeNames() : array { - return ['value']; - } - - /** - * @internal - * - * Parses a DNUMBER token like PHP would. - * - * @param string $str A string number - * - * @return float The parsed number - */ - public static function parse(string $str) : float { - $str = str_replace('_', '', $str); - - // if string contains any of .eE just cast it to float - if (false !== strpbrk($str, '.eE')) { - return (float) $str; - } - - // otherwise it's an integer notation that overflowed into a float - // if it starts with 0 it's one of the special integer notations - if ('0' === $str[0]) { - // hex - if ('x' === $str[1] || 'X' === $str[1]) { - return hexdec($str); - } - - // bin - if ('b' === $str[1] || 'B' === $str[1]) { - return bindec($str); - } - - // oct - // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit (8 or 9) - // so that only the digits before that are used - return octdec(substr($str, 0, strcspn($str, '89'))); - } - - // dec - return (float) $str; - } - - public function getType() : string { - return 'Scalar_DNumber'; +if (false) { + // For classmap-authoritative support. + class DNumber extends Float_ { } } diff --git a/lib/PhpParser/Node/Scalar/Encapsed.php b/lib/PhpParser/Node/Scalar/Encapsed.php index fa5d2e2681..a97545e7bd 100644 --- a/lib/PhpParser/Node/Scalar/Encapsed.php +++ b/lib/PhpParser/Node/Scalar/Encapsed.php @@ -2,30 +2,10 @@ namespace PhpParser\Node\Scalar; -use PhpParser\Node\Expr; -use PhpParser\Node\Scalar; +require __DIR__ . '/InterpolatedString.php'; -class Encapsed extends Scalar -{ - /** @var Expr[] list of string parts */ - public $parts; - - /** - * Constructs an encapsed string node. - * - * @param Expr[] $parts Encaps list - * @param array $attributes Additional attributes - */ - public function __construct(array $parts, array $attributes = []) { - $this->attributes = $attributes; - $this->parts = $parts; - } - - public function getSubNodeNames() : array { - return ['parts']; - } - - public function getType() : string { - return 'Scalar_Encapsed'; +if (false) { + // For classmap-authoritative support. + class Encapsed extends InterpolatedString { } } diff --git a/lib/PhpParser/Node/Scalar/EncapsedStringPart.php b/lib/PhpParser/Node/Scalar/EncapsedStringPart.php index bb3194c1d7..7ef5fb0c09 100644 --- a/lib/PhpParser/Node/Scalar/EncapsedStringPart.php +++ b/lib/PhpParser/Node/Scalar/EncapsedStringPart.php @@ -2,29 +2,12 @@ namespace PhpParser\Node\Scalar; -use PhpParser\Node\Scalar; +use PhpParser\Node\InterpolatedStringPart; -class EncapsedStringPart extends Scalar -{ - /** @var string String value */ - public $value; +require __DIR__ . '/../InterpolatedStringPart.php'; - /** - * Constructs a node representing a string part of an encapsed string. - * - * @param string $value String value - * @param array $attributes Additional attributes - */ - public function __construct(string $value, array $attributes = []) { - $this->attributes = $attributes; - $this->value = $value; - } - - public function getSubNodeNames() : array { - return ['value']; - } - - public function getType() : string { - return 'Scalar_EncapsedStringPart'; +if (false) { + // For classmap-authoritative support. + class EncapsedStringPart extends InterpolatedStringPart { } } diff --git a/lib/PhpParser/Node/Scalar/Float_.php b/lib/PhpParser/Node/Scalar/Float_.php new file mode 100644 index 0000000000..5af1319237 --- /dev/null +++ b/lib/PhpParser/Node/Scalar/Float_.php @@ -0,0 +1,78 @@ + $attributes Additional attributes + */ + public function __construct(float $value, array $attributes = []) { + $this->attributes = $attributes; + $this->value = $value; + } + + public function getSubNodeNames(): array { + return ['value']; + } + + /** + * @param mixed[] $attributes + */ + public static function fromString(string $str, array $attributes = []): Float_ { + $attributes['rawValue'] = $str; + $float = self::parse($str); + + return new Float_($float, $attributes); + } + + /** + * @internal + * + * Parses a DNUMBER token like PHP would. + * + * @param string $str A string number + * + * @return float The parsed number + */ + public static function parse(string $str): float { + $str = str_replace('_', '', $str); + + // Check whether this is one of the special integer notations. + if ('0' === $str[0]) { + // hex + if ('x' === $str[1] || 'X' === $str[1]) { + return hexdec($str); + } + + // bin + if ('b' === $str[1] || 'B' === $str[1]) { + return bindec($str); + } + + // oct, but only if the string does not contain any of '.eE'. + if (false === strpbrk($str, '.eE')) { + // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit + // (8 or 9) so that only the digits before that are used. + return octdec(substr($str, 0, strcspn($str, '89'))); + } + } + + // dec + return (float) $str; + } + + public function getType(): string { + return 'Scalar_Float'; + } +} + +// @deprecated compatibility alias +class_alias(Float_::class, DNumber::class); diff --git a/lib/PhpParser/Node/Scalar/Int_.php b/lib/PhpParser/Node/Scalar/Int_.php new file mode 100644 index 0000000000..bcc257a6a1 --- /dev/null +++ b/lib/PhpParser/Node/Scalar/Int_.php @@ -0,0 +1,82 @@ + $attributes Additional attributes + */ + public function __construct(int $value, array $attributes = []) { + $this->attributes = $attributes; + $this->value = $value; + } + + public function getSubNodeNames(): array { + return ['value']; + } + + /** + * Constructs an Int node from a string number literal. + * + * @param string $str String number literal (decimal, octal, hex or binary) + * @param array $attributes Additional attributes + * @param bool $allowInvalidOctal Whether to allow invalid octal numbers (PHP 5) + * + * @return Int_ The constructed LNumber, including kind attribute + */ + public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false): Int_ { + $attributes['rawValue'] = $str; + + $str = str_replace('_', '', $str); + + if ('0' !== $str[0] || '0' === $str) { + $attributes['kind'] = Int_::KIND_DEC; + return new Int_((int) $str, $attributes); + } + + if ('x' === $str[1] || 'X' === $str[1]) { + $attributes['kind'] = Int_::KIND_HEX; + return new Int_(hexdec($str), $attributes); + } + + if ('b' === $str[1] || 'B' === $str[1]) { + $attributes['kind'] = Int_::KIND_BIN; + return new Int_(bindec($str), $attributes); + } + + if (!$allowInvalidOctal && strpbrk($str, '89')) { + throw new Error('Invalid numeric literal', $attributes); + } + + // Strip optional explicit octal prefix. + if ('o' === $str[1] || 'O' === $str[1]) { + $str = substr($str, 2); + } + + // use intval instead of octdec to get proper cutting behavior with malformed numbers + $attributes['kind'] = Int_::KIND_OCT; + return new Int_(intval($str, 8), $attributes); + } + + public function getType(): string { + return 'Scalar_Int'; + } +} + +// @deprecated compatibility alias +class_alias(Int_::class, LNumber::class); diff --git a/lib/PhpParser/Node/Scalar/InterpolatedString.php b/lib/PhpParser/Node/Scalar/InterpolatedString.php new file mode 100644 index 0000000000..9336dfe4da --- /dev/null +++ b/lib/PhpParser/Node/Scalar/InterpolatedString.php @@ -0,0 +1,34 @@ + $attributes Additional attributes + */ + public function __construct(array $parts, array $attributes = []) { + $this->attributes = $attributes; + $this->parts = $parts; + } + + public function getSubNodeNames(): array { + return ['parts']; + } + + public function getType(): string { + return 'Scalar_InterpolatedString'; + } +} + +// @deprecated compatibility alias +class_alias(InterpolatedString::class, Encapsed::class); diff --git a/lib/PhpParser/Node/Scalar/LNumber.php b/lib/PhpParser/Node/Scalar/LNumber.php index b33943547e..0d1287105d 100644 --- a/lib/PhpParser/Node/Scalar/LNumber.php +++ b/lib/PhpParser/Node/Scalar/LNumber.php @@ -2,72 +2,10 @@ namespace PhpParser\Node\Scalar; -use PhpParser\Error; -use PhpParser\Node\Scalar; +require __DIR__ . '/Int_.php'; -class LNumber extends Scalar -{ - /* For use in "kind" attribute */ - const KIND_BIN = 2; - const KIND_OCT = 8; - const KIND_DEC = 10; - const KIND_HEX = 16; - - /** @var int Number value */ - public $value; - - /** - * Constructs an integer number scalar node. - * - * @param int $value Value of the number - * @param array $attributes Additional attributes - */ - public function __construct(int $value, array $attributes = []) { - $this->attributes = $attributes; - $this->value = $value; - } - - public function getSubNodeNames() : array { - return ['value']; - } - - /** - * Constructs an LNumber node from a string number literal. - * - * @param string $str String number literal (decimal, octal, hex or binary) - * @param array $attributes Additional attributes - * @param bool $allowInvalidOctal Whether to allow invalid octal numbers (PHP 5) - * - * @return LNumber The constructed LNumber, including kind attribute - */ - public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false) : LNumber { - $str = str_replace('_', '', $str); - - if ('0' !== $str[0] || '0' === $str) { - $attributes['kind'] = LNumber::KIND_DEC; - return new LNumber((int) $str, $attributes); - } - - if ('x' === $str[1] || 'X' === $str[1]) { - $attributes['kind'] = LNumber::KIND_HEX; - return new LNumber(hexdec($str), $attributes); - } - - if ('b' === $str[1] || 'B' === $str[1]) { - $attributes['kind'] = LNumber::KIND_BIN; - return new LNumber(bindec($str), $attributes); - } - - if (!$allowInvalidOctal && strpbrk($str, '89')) { - throw new Error('Invalid numeric literal', $attributes); - } - - // use intval instead of octdec to get proper cutting behavior with malformed numbers - $attributes['kind'] = LNumber::KIND_OCT; - return new LNumber(intval($str, 8), $attributes); - } - - public function getType() : string { - return 'Scalar_LNumber'; +if (false) { + // For classmap-authoritative support. + class LNumber extends Int_ { } } diff --git a/lib/PhpParser/Node/Scalar/MagicConst.php b/lib/PhpParser/Node/Scalar/MagicConst.php index 941f0c7620..1da9b391cb 100644 --- a/lib/PhpParser/Node/Scalar/MagicConst.php +++ b/lib/PhpParser/Node/Scalar/MagicConst.php @@ -4,18 +4,17 @@ use PhpParser\Node\Scalar; -abstract class MagicConst extends Scalar -{ +abstract class MagicConst extends Scalar { /** * Constructs a magic constant node. * - * @param array $attributes Additional attributes + * @param array $attributes Additional attributes */ public function __construct(array $attributes = []) { $this->attributes = $attributes; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return []; } @@ -24,5 +23,5 @@ public function getSubNodeNames() : array { * * @return string Name of magic constant */ - abstract public function getName() : string; + abstract public function getName(): string; } diff --git a/lib/PhpParser/Node/Scalar/MagicConst/Class_.php b/lib/PhpParser/Node/Scalar/MagicConst/Class_.php index 244328476d..732ed140f1 100644 --- a/lib/PhpParser/Node/Scalar/MagicConst/Class_.php +++ b/lib/PhpParser/Node/Scalar/MagicConst/Class_.php @@ -4,13 +4,12 @@ use PhpParser\Node\Scalar\MagicConst; -class Class_ extends MagicConst -{ - public function getName() : string { +class Class_ extends MagicConst { + public function getName(): string { return '__CLASS__'; } - - public function getType() : string { + + public function getType(): string { return 'Scalar_MagicConst_Class'; } } diff --git a/lib/PhpParser/Node/Scalar/MagicConst/Dir.php b/lib/PhpParser/Node/Scalar/MagicConst/Dir.php index 2b618473e3..64daa713bb 100644 --- a/lib/PhpParser/Node/Scalar/MagicConst/Dir.php +++ b/lib/PhpParser/Node/Scalar/MagicConst/Dir.php @@ -4,13 +4,12 @@ use PhpParser\Node\Scalar\MagicConst; -class Dir extends MagicConst -{ - public function getName() : string { +class Dir extends MagicConst { + public function getName(): string { return '__DIR__'; } - - public function getType() : string { + + public function getType(): string { return 'Scalar_MagicConst_Dir'; } } diff --git a/lib/PhpParser/Node/Scalar/MagicConst/File.php b/lib/PhpParser/Node/Scalar/MagicConst/File.php index 3422db0692..91041f0f99 100644 --- a/lib/PhpParser/Node/Scalar/MagicConst/File.php +++ b/lib/PhpParser/Node/Scalar/MagicConst/File.php @@ -4,13 +4,12 @@ use PhpParser\Node\Scalar\MagicConst; -class File extends MagicConst -{ - public function getName() : string { +class File extends MagicConst { + public function getName(): string { return '__FILE__'; } - - public function getType() : string { + + public function getType(): string { return 'Scalar_MagicConst_File'; } } diff --git a/lib/PhpParser/Node/Scalar/MagicConst/Function_.php b/lib/PhpParser/Node/Scalar/MagicConst/Function_.php index 1db65a1513..c242d2d95d 100644 --- a/lib/PhpParser/Node/Scalar/MagicConst/Function_.php +++ b/lib/PhpParser/Node/Scalar/MagicConst/Function_.php @@ -4,13 +4,12 @@ use PhpParser\Node\Scalar\MagicConst; -class Function_ extends MagicConst -{ - public function getName() : string { +class Function_ extends MagicConst { + public function getName(): string { return '__FUNCTION__'; } - - public function getType() : string { + + public function getType(): string { return 'Scalar_MagicConst_Function'; } } diff --git a/lib/PhpParser/Node/Scalar/MagicConst/Line.php b/lib/PhpParser/Node/Scalar/MagicConst/Line.php index 25d3de57c1..58d8ce39da 100644 --- a/lib/PhpParser/Node/Scalar/MagicConst/Line.php +++ b/lib/PhpParser/Node/Scalar/MagicConst/Line.php @@ -4,13 +4,12 @@ use PhpParser\Node\Scalar\MagicConst; -class Line extends MagicConst -{ - public function getName() : string { +class Line extends MagicConst { + public function getName(): string { return '__LINE__'; } - - public function getType() : string { + + public function getType(): string { return 'Scalar_MagicConst_Line'; } } diff --git a/lib/PhpParser/Node/Scalar/MagicConst/Method.php b/lib/PhpParser/Node/Scalar/MagicConst/Method.php index d168d56f10..47f341f10a 100644 --- a/lib/PhpParser/Node/Scalar/MagicConst/Method.php +++ b/lib/PhpParser/Node/Scalar/MagicConst/Method.php @@ -4,13 +4,12 @@ use PhpParser\Node\Scalar\MagicConst; -class Method extends MagicConst -{ - public function getName() : string { +class Method extends MagicConst { + public function getName(): string { return '__METHOD__'; } - - public function getType() : string { + + public function getType(): string { return 'Scalar_MagicConst_Method'; } } diff --git a/lib/PhpParser/Node/Scalar/MagicConst/Namespace_.php b/lib/PhpParser/Node/Scalar/MagicConst/Namespace_.php index 4fabb751af..e9f8c0eae4 100644 --- a/lib/PhpParser/Node/Scalar/MagicConst/Namespace_.php +++ b/lib/PhpParser/Node/Scalar/MagicConst/Namespace_.php @@ -4,13 +4,12 @@ use PhpParser\Node\Scalar\MagicConst; -class Namespace_ extends MagicConst -{ - public function getName() : string { +class Namespace_ extends MagicConst { + public function getName(): string { return '__NAMESPACE__'; } - - public function getType() : string { + + public function getType(): string { return 'Scalar_MagicConst_Namespace'; } } diff --git a/lib/PhpParser/Node/Scalar/MagicConst/Property.php b/lib/PhpParser/Node/Scalar/MagicConst/Property.php new file mode 100644 index 0000000000..6c0c968fce --- /dev/null +++ b/lib/PhpParser/Node/Scalar/MagicConst/Property.php @@ -0,0 +1,15 @@ + Escaped character to its decoded value */ + protected static array $replacements = [ '\\' => '\\', '$' => '$', 'n' => "\n", @@ -30,18 +30,34 @@ class String_ extends Scalar /** * Constructs a string scalar node. * - * @param string $value Value of the string - * @param array $attributes Additional attributes + * @param string $value Value of the string + * @param array $attributes Additional attributes */ public function __construct(string $value, array $attributes = []) { $this->attributes = $attributes; $this->value = $value; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['value']; } + /** + * @param array $attributes + * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes + */ + public static function fromString(string $str, array $attributes = [], bool $parseUnicodeEscape = true): self { + $attributes['kind'] = ($str[0] === "'" || ($str[1] === "'" && ($str[0] === 'b' || $str[0] === 'B'))) + ? Scalar\String_::KIND_SINGLE_QUOTED + : Scalar\String_::KIND_DOUBLE_QUOTED; + + $attributes['rawValue'] = $str; + + $string = self::parse($str, $parseUnicodeEscape); + + return new self($string, $attributes); + } + /** * @internal * @@ -52,7 +68,7 @@ public function getSubNodeNames() : array { * * @return string The parsed string */ - public static function parse(string $str, bool $parseUnicodeEscape = true) : string { + public static function parse(string $str, bool $parseUnicodeEscape = true): string { $bLength = 0; if ('b' === $str[0] || 'B' === $str[0]) { $bLength = 1; @@ -76,13 +92,13 @@ public static function parse(string $str, bool $parseUnicodeEscape = true) : str * * Parses escape sequences in strings (all string types apart from single quoted). * - * @param string $str String without quotes + * @param string $str String without quotes * @param null|string $quote Quote type * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes * * @return string String with escape sequences parsed */ - public static function parseEscapeSequences(string $str, $quote, bool $parseUnicodeEscape = true) : string { + public static function parseEscapeSequences(string $str, ?string $quote, bool $parseUnicodeEscape = true): string { if (null !== $quote) { $str = str_replace('\\' . $quote, $quote, $str); } @@ -94,15 +110,19 @@ public static function parseEscapeSequences(string $str, $quote, bool $parseUnic return preg_replace_callback( '~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}' . $extra . ')~', - function($matches) { + function ($matches) { $str = $matches[1]; if (isset(self::$replacements[$str])) { return self::$replacements[$str]; - } elseif ('x' === $str[0] || 'X' === $str[0]) { + } + if ('x' === $str[0] || 'X' === $str[0]) { return chr(hexdec(substr($str, 1))); - } elseif ('u' === $str[0]) { - return self::codePointToUtf8(hexdec($matches[2])); + } + if ('u' === $str[0]) { + $dec = hexdec($matches[2]); + // If it overflowed to float, treat as INT_MAX, it will throw an error anyway. + return self::codePointToUtf8(\is_int($dec) ? $dec : \PHP_INT_MAX); } else { return chr(octdec($str)); } @@ -118,24 +138,24 @@ function($matches) { * * @return string UTF-8 representation of code point */ - private static function codePointToUtf8(int $num) : string { + private static function codePointToUtf8(int $num): string { if ($num <= 0x7F) { return chr($num); } if ($num <= 0x7FF) { - return chr(($num>>6) + 0xC0) . chr(($num&0x3F) + 0x80); + return chr(($num >> 6) + 0xC0) . chr(($num & 0x3F) + 0x80); } if ($num <= 0xFFFF) { - return chr(($num>>12) + 0xE0) . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); + return chr(($num >> 12) + 0xE0) . chr((($num >> 6) & 0x3F) + 0x80) . chr(($num & 0x3F) + 0x80); } if ($num <= 0x1FFFFF) { - return chr(($num>>18) + 0xF0) . chr((($num>>12)&0x3F) + 0x80) - . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); + return chr(($num >> 18) + 0xF0) . chr((($num >> 12) & 0x3F) + 0x80) + . chr((($num >> 6) & 0x3F) + 0x80) . chr(($num & 0x3F) + 0x80); } throw new Error('Invalid UTF-8 codepoint escape sequence: Codepoint too large'); } - public function getType() : string { + public function getType(): string { return 'Scalar_String'; } } diff --git a/lib/PhpParser/Node/StaticVar.php b/lib/PhpParser/Node/StaticVar.php new file mode 100644 index 0000000000..517c0edddd --- /dev/null +++ b/lib/PhpParser/Node/StaticVar.php @@ -0,0 +1,39 @@ + $attributes Additional attributes + */ + public function __construct( + Expr\Variable $var, ?Node\Expr $default = null, array $attributes = [] + ) { + $this->attributes = $attributes; + $this->var = $var; + $this->default = $default; + } + + public function getSubNodeNames(): array { + return ['var', 'default']; + } + + public function getType(): string { + return 'StaticVar'; + } +} + +// @deprecated compatibility alias +class_alias(StaticVar::class, Stmt\StaticVar::class); diff --git a/lib/PhpParser/Node/Stmt.php b/lib/PhpParser/Node/Stmt.php index 69d33e5796..481d31a939 100644 --- a/lib/PhpParser/Node/Stmt.php +++ b/lib/PhpParser/Node/Stmt.php @@ -4,6 +4,5 @@ use PhpParser\NodeAbstract; -abstract class Stmt extends NodeAbstract -{ +abstract class Stmt extends NodeAbstract { } diff --git a/lib/PhpParser/Node/Stmt/Block.php b/lib/PhpParser/Node/Stmt/Block.php new file mode 100644 index 0000000000..073df2086f --- /dev/null +++ b/lib/PhpParser/Node/Stmt/Block.php @@ -0,0 +1,29 @@ + $attributes Additional attributes + */ + public function __construct(array $stmts, array $attributes = []) { + $this->attributes = $attributes; + $this->stmts = $stmts; + } + + public function getType(): string { + return 'Stmt_Block'; + } + + public function getSubNodeNames(): array { + return ['stmts']; + } +} diff --git a/lib/PhpParser/Node/Stmt/Break_.php b/lib/PhpParser/Node/Stmt/Break_.php index 6adc5a6c6f..d2bcc5eb2d 100644 --- a/lib/PhpParser/Node/Stmt/Break_.php +++ b/lib/PhpParser/Node/Stmt/Break_.php @@ -4,27 +4,26 @@ use PhpParser\Node; -class Break_ extends Node\Stmt -{ +class Break_ extends Node\Stmt { /** @var null|Node\Expr Number of loops to break */ - public $num; + public ?Node\Expr $num; /** * Constructs a break node. * - * @param null|Node\Expr $num Number of loops to break - * @param array $attributes Additional attributes + * @param null|Node\Expr $num Number of loops to break + * @param array $attributes Additional attributes */ - public function __construct(Node\Expr $num = null, array $attributes = []) { + public function __construct(?Node\Expr $num = null, array $attributes = []) { $this->attributes = $attributes; $this->num = $num; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['num']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Break'; } } diff --git a/lib/PhpParser/Node/Stmt/Case_.php b/lib/PhpParser/Node/Stmt/Case_.php index 2bf044c900..a06ca1832e 100644 --- a/lib/PhpParser/Node/Stmt/Case_.php +++ b/lib/PhpParser/Node/Stmt/Case_.php @@ -4,31 +4,30 @@ use PhpParser\Node; -class Case_ extends Node\Stmt -{ +class Case_ extends Node\Stmt { /** @var null|Node\Expr Condition (null for default) */ - public $cond; + public ?Node\Expr $cond; /** @var Node\Stmt[] Statements */ - public $stmts; + public array $stmts; /** * Constructs a case node. * - * @param null|Node\Expr $cond Condition (null for default) - * @param Node\Stmt[] $stmts Statements - * @param array $attributes Additional attributes + * @param null|Node\Expr $cond Condition (null for default) + * @param Node\Stmt[] $stmts Statements + * @param array $attributes Additional attributes */ - public function __construct($cond, array $stmts = [], array $attributes = []) { + public function __construct(?Node\Expr $cond, array $stmts = [], array $attributes = []) { $this->attributes = $attributes; $this->cond = $cond; $this->stmts = $stmts; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['cond', 'stmts']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Case'; } } diff --git a/lib/PhpParser/Node/Stmt/Catch_.php b/lib/PhpParser/Node/Stmt/Catch_.php index 9b9c094782..e8d39c9cce 100644 --- a/lib/PhpParser/Node/Stmt/Catch_.php +++ b/lib/PhpParser/Node/Stmt/Catch_.php @@ -5,25 +5,24 @@ use PhpParser\Node; use PhpParser\Node\Expr; -class Catch_ extends Node\Stmt -{ +class Catch_ extends Node\Stmt { /** @var Node\Name[] Types of exceptions to catch */ - public $types; + public array $types; /** @var Expr\Variable|null Variable for exception */ - public $var; + public ?Expr\Variable $var; /** @var Node\Stmt[] Statements */ - public $stmts; + public array $stmts; /** * Constructs a catch node. * - * @param Node\Name[] $types Types of exceptions to catch - * @param Expr\Variable|null $var Variable for exception - * @param Node\Stmt[] $stmts Statements - * @param array $attributes Additional attributes + * @param Node\Name[] $types Types of exceptions to catch + * @param Expr\Variable|null $var Variable for exception + * @param Node\Stmt[] $stmts Statements + * @param array $attributes Additional attributes */ public function __construct( - array $types, Expr\Variable $var = null, array $stmts = [], array $attributes = [] + array $types, ?Expr\Variable $var = null, array $stmts = [], array $attributes = [] ) { $this->attributes = $attributes; $this->types = $types; @@ -31,11 +30,11 @@ public function __construct( $this->stmts = $stmts; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['types', 'var', 'stmts']; } - public function getType() : string { + public function getType(): string { return 'Stmt_Catch'; } } diff --git a/lib/PhpParser/Node/Stmt/ClassConst.php b/lib/PhpParser/Node/Stmt/ClassConst.php index c459acb152..9bdce1f1db 100644 --- a/lib/PhpParser/Node/Stmt/ClassConst.php +++ b/lib/PhpParser/Node/Stmt/ClassConst.php @@ -2,70 +2,76 @@ namespace PhpParser\Node\Stmt; +use PhpParser\Modifiers; use PhpParser\Node; -class ClassConst extends Node\Stmt -{ +class ClassConst extends Node\Stmt { /** @var int Modifiers */ - public $flags; + public int $flags; /** @var Node\Const_[] Constant declarations */ - public $consts; - /** @var Node\AttributeGroup[] */ - public $attrGroups; + public array $consts; + /** @var Node\AttributeGroup[] PHP attribute groups */ + public array $attrGroups; + /** @var Node\Identifier|Node\Name|Node\ComplexType|null Type declaration */ + public ?Node $type; /** * Constructs a class const list node. * - * @param Node\Const_[] $consts Constant declarations - * @param int $flags Modifiers - * @param array $attributes Additional attributes - * @param Node\AttributeGroup[] $attrGroups PHP attribute groups + * @param Node\Const_[] $consts Constant declarations + * @param int $flags Modifiers + * @param array $attributes Additional attributes + * @param list $attrGroups PHP attribute groups + * @param null|Node\Identifier|Node\Name|Node\ComplexType $type Type declaration */ public function __construct( array $consts, int $flags = 0, array $attributes = [], - array $attrGroups = [] + array $attrGroups = [], + ?Node $type = null ) { $this->attributes = $attributes; $this->flags = $flags; $this->consts = $consts; $this->attrGroups = $attrGroups; + $this->type = $type; } - public function getSubNodeNames() : array { - return ['attrGroups', 'flags', 'consts']; + public function getSubNodeNames(): array { + return ['attrGroups', 'flags', 'type', 'consts']; } /** * Whether constant is explicitly or implicitly public. - * - * @return bool */ - public function isPublic() : bool { - return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0 - || ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0; + public function isPublic(): bool { + return ($this->flags & Modifiers::PUBLIC) !== 0 + || ($this->flags & Modifiers::VISIBILITY_MASK) === 0; } /** * Whether constant is protected. - * - * @return bool */ - public function isProtected() : bool { - return (bool) ($this->flags & Class_::MODIFIER_PROTECTED); + public function isProtected(): bool { + return (bool) ($this->flags & Modifiers::PROTECTED); } /** * Whether constant is private. - * - * @return bool */ - public function isPrivate() : bool { - return (bool) ($this->flags & Class_::MODIFIER_PRIVATE); + public function isPrivate(): bool { + return (bool) ($this->flags & Modifiers::PRIVATE); + } + + /** + * Whether constant is final. + */ + public function isFinal(): bool { + return (bool) ($this->flags & Modifiers::FINAL); } - public function getType() : string { + public function getType(): string { return 'Stmt_ClassConst'; } } diff --git a/lib/PhpParser/Node/Stmt/ClassLike.php b/lib/PhpParser/Node/Stmt/ClassLike.php index 840c4f67ec..e652177c44 100644 --- a/lib/PhpParser/Node/Stmt/ClassLike.php +++ b/lib/PhpParser/Node/Stmt/ClassLike.php @@ -3,23 +3,23 @@ namespace PhpParser\Node\Stmt; use PhpParser\Node; +use PhpParser\Node\PropertyItem; -/** - * @property Node\Name $namespacedName Namespaced name (if using NameResolver) - */ -abstract class ClassLike extends Node\Stmt -{ +abstract class ClassLike extends Node\Stmt { /** @var Node\Identifier|null Name */ - public $name; + public ?Node\Identifier $name; /** @var Node\Stmt[] Statements */ - public $stmts; + public array $stmts; /** @var Node\AttributeGroup[] PHP attribute groups */ - public $attrGroups; + public array $attrGroups; + + /** @var Node\Name|null Namespaced name (if using NameResolver) */ + public ?Node\Name $namespacedName; /** - * @return TraitUse[] + * @return list */ - public function getTraitUses() : array { + public function getTraitUses(): array { $traitUses = []; foreach ($this->stmts as $stmt) { if ($stmt instanceof TraitUse) { @@ -30,9 +30,9 @@ public function getTraitUses() : array { } /** - * @return ClassConst[] + * @return list */ - public function getConstants() : array { + public function getConstants(): array { $constants = []; foreach ($this->stmts as $stmt) { if ($stmt instanceof ClassConst) { @@ -43,9 +43,9 @@ public function getConstants() : array { } /** - * @return Property[] + * @return list */ - public function getProperties() : array { + public function getProperties(): array { $properties = []; foreach ($this->stmts as $stmt) { if ($stmt instanceof Property) { @@ -62,11 +62,11 @@ public function getProperties() : array { * * @return Property|null Property node or null if the property does not exist */ - public function getProperty(string $name) { + public function getProperty(string $name): ?Property { foreach ($this->stmts as $stmt) { if ($stmt instanceof Property) { foreach ($stmt->props as $prop) { - if ($prop instanceof PropertyProperty && $name === $prop->name->toString()) { + if ($prop instanceof PropertyItem && $name === $prop->name->toString()) { return $stmt; } } @@ -78,9 +78,9 @@ public function getProperty(string $name) { /** * Gets all methods defined directly in this class/interface/trait * - * @return ClassMethod[] + * @return list */ - public function getMethods() : array { + public function getMethods(): array { $methods = []; foreach ($this->stmts as $stmt) { if ($stmt instanceof ClassMethod) { @@ -97,7 +97,7 @@ public function getMethods() : array { * * @return ClassMethod|null Method node or null if the method does not exist */ - public function getMethod(string $name) { + public function getMethod(string $name): ?ClassMethod { $lowerName = strtolower($name); foreach ($this->stmts as $stmt) { if ($stmt instanceof ClassMethod && $lowerName === $stmt->name->toLowerString()) { diff --git a/lib/PhpParser/Node/Stmt/ClassMethod.php b/lib/PhpParser/Node/Stmt/ClassMethod.php index 92157fab26..59c0519ea6 100644 --- a/lib/PhpParser/Node/Stmt/ClassMethod.php +++ b/lib/PhpParser/Node/Stmt/ClassMethod.php @@ -2,56 +2,66 @@ namespace PhpParser\Node\Stmt; +use PhpParser\Modifiers; use PhpParser\Node; use PhpParser\Node\FunctionLike; -class ClassMethod extends Node\Stmt implements FunctionLike -{ +class ClassMethod extends Node\Stmt implements FunctionLike { /** @var int Flags */ - public $flags; + public int $flags; /** @var bool Whether to return by reference */ - public $byRef; + public bool $byRef; /** @var Node\Identifier Name */ - public $name; + public Node\Identifier $name; /** @var Node\Param[] Parameters */ - public $params; - /** @var null|Node\Identifier|Node\Name|Node\NullableType|Node\UnionType Return type */ - public $returnType; + public array $params; + /** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */ + public ?Node $returnType; /** @var Node\Stmt[]|null Statements */ - public $stmts; + public ?array $stmts; /** @var Node\AttributeGroup[] PHP attribute groups */ - public $attrGroups; - - private static $magicNames = [ - '__construct' => true, - '__destruct' => true, - '__call' => true, - '__callstatic' => true, - '__get' => true, - '__set' => true, - '__isset' => true, - '__unset' => true, - '__sleep' => true, - '__wakeup' => true, - '__tostring' => true, - '__set_state' => true, - '__clone' => true, - '__invoke' => true, - '__debuginfo' => true, + public array $attrGroups; + + /** @var array */ + private static array $magicNames = [ + '__construct' => true, + '__destruct' => true, + '__call' => true, + '__callstatic' => true, + '__get' => true, + '__set' => true, + '__isset' => true, + '__unset' => true, + '__sleep' => true, + '__wakeup' => true, + '__tostring' => true, + '__set_state' => true, + '__clone' => true, + '__invoke' => true, + '__debuginfo' => true, + '__serialize' => true, + '__unserialize' => true, ]; /** * Constructs a class method node. * * @param string|Node\Identifier $name Name - * @param array $subNodes Array of the following optional subnodes: - * 'flags => MODIFIER_PUBLIC: Flags - * 'byRef' => false : Whether to return by reference - * 'params' => array() : Parameters - * 'returnType' => null : Return type - * 'stmts' => array() : Statements - * 'attrGroups' => array() : PHP attribute groups - * @param array $attributes Additional attributes + * @param array{ + * flags?: int, + * byRef?: bool, + * params?: Node\Param[], + * returnType?: null|Node\Identifier|Node\Name|Node\ComplexType, + * stmts?: Node\Stmt[]|null, + * attrGroups?: Node\AttributeGroup[], + * } $subNodes Array of the following optional subnodes: + * 'flags => 0 : Flags + * 'byRef' => false : Whether to return by reference + * 'params' => array() : Parameters + * 'returnType' => null : Return type + * 'stmts' => array() : Statements + * 'attrGroups' => array() : PHP attribute groups + * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; @@ -59,21 +69,20 @@ public function __construct($name, array $subNodes = [], array $attributes = []) $this->byRef = $subNodes['byRef'] ?? false; $this->name = \is_string($name) ? new Node\Identifier($name) : $name; $this->params = $subNodes['params'] ?? []; - $returnType = $subNodes['returnType'] ?? null; - $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType; + $this->returnType = $subNodes['returnType'] ?? null; $this->stmts = array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : []; $this->attrGroups = $subNodes['attrGroups'] ?? []; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['attrGroups', 'flags', 'byRef', 'name', 'params', 'returnType', 'stmts']; } - public function returnsByRef() : bool { + public function returnsByRef(): bool { return $this->byRef; } - public function getParams() : array { + public function getParams(): array { return $this->params; } @@ -81,79 +90,65 @@ public function getReturnType() { return $this->returnType; } - public function getStmts() { + public function getStmts(): ?array { return $this->stmts; } - public function getAttrGroups() : array { + public function getAttrGroups(): array { return $this->attrGroups; } /** * Whether the method is explicitly or implicitly public. - * - * @return bool */ - public function isPublic() : bool { - return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0 - || ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0; + public function isPublic(): bool { + return ($this->flags & Modifiers::PUBLIC) !== 0 + || ($this->flags & Modifiers::VISIBILITY_MASK) === 0; } /** * Whether the method is protected. - * - * @return bool */ - public function isProtected() : bool { - return (bool) ($this->flags & Class_::MODIFIER_PROTECTED); + public function isProtected(): bool { + return (bool) ($this->flags & Modifiers::PROTECTED); } /** * Whether the method is private. - * - * @return bool */ - public function isPrivate() : bool { - return (bool) ($this->flags & Class_::MODIFIER_PRIVATE); + public function isPrivate(): bool { + return (bool) ($this->flags & Modifiers::PRIVATE); } /** * Whether the method is abstract. - * - * @return bool */ - public function isAbstract() : bool { - return (bool) ($this->flags & Class_::MODIFIER_ABSTRACT); + public function isAbstract(): bool { + return (bool) ($this->flags & Modifiers::ABSTRACT); } /** * Whether the method is final. - * - * @return bool */ - public function isFinal() : bool { - return (bool) ($this->flags & Class_::MODIFIER_FINAL); + public function isFinal(): bool { + return (bool) ($this->flags & Modifiers::FINAL); } /** * Whether the method is static. - * - * @return bool */ - public function isStatic() : bool { - return (bool) ($this->flags & Class_::MODIFIER_STATIC); + public function isStatic(): bool { + return (bool) ($this->flags & Modifiers::STATIC); } /** * Whether the method is magic. - * - * @return bool */ - public function isMagic() : bool { + public function isMagic(): bool { return isset(self::$magicNames[$this->name->toLowerString()]); } - public function getType() : string { + public function getType(): string { return 'Stmt_ClassMethod'; } } diff --git a/lib/PhpParser/Node/Stmt/Class_.php b/lib/PhpParser/Node/Stmt/Class_.php index ace266f74b..3f492b7bb3 100644 --- a/lib/PhpParser/Node/Stmt/Class_.php +++ b/lib/PhpParser/Node/Stmt/Class_.php @@ -2,38 +2,52 @@ namespace PhpParser\Node\Stmt; -use PhpParser\Error; +use PhpParser\Modifiers; use PhpParser\Node; -class Class_ extends ClassLike -{ - const MODIFIER_PUBLIC = 1; - const MODIFIER_PROTECTED = 2; - const MODIFIER_PRIVATE = 4; - const MODIFIER_STATIC = 8; - const MODIFIER_ABSTRACT = 16; - const MODIFIER_FINAL = 32; - - const VISIBILITY_MODIFIER_MASK = 7; // 1 | 2 | 4 - - /** @var int Type */ - public $flags; +class Class_ extends ClassLike { + /** @deprecated Use Modifiers::PUBLIC instead */ + public const MODIFIER_PUBLIC = 1; + /** @deprecated Use Modifiers::PROTECTED instead */ + public const MODIFIER_PROTECTED = 2; + /** @deprecated Use Modifiers::PRIVATE instead */ + public const MODIFIER_PRIVATE = 4; + /** @deprecated Use Modifiers::STATIC instead */ + public const MODIFIER_STATIC = 8; + /** @deprecated Use Modifiers::ABSTRACT instead */ + public const MODIFIER_ABSTRACT = 16; + /** @deprecated Use Modifiers::FINAL instead */ + public const MODIFIER_FINAL = 32; + /** @deprecated Use Modifiers::READONLY instead */ + public const MODIFIER_READONLY = 64; + + /** @deprecated Use Modifiers::VISIBILITY_MASK instead */ + public const VISIBILITY_MODIFIER_MASK = 7; // 1 | 2 | 4 + + /** @var int Modifiers */ + public int $flags; /** @var null|Node\Name Name of extended class */ - public $extends; + public ?Node\Name $extends; /** @var Node\Name[] Names of implemented interfaces */ - public $implements; + public array $implements; /** * Constructs a class node. * * @param string|Node\Identifier|null $name Name - * @param array $subNodes Array of the following optional subnodes: - * 'flags' => 0 : Flags - * 'extends' => null : Name of extended class - * 'implements' => array(): Names of implemented interfaces - * 'stmts' => array(): Statements - * '$attrGroups' => array(): PHP attribute groups - * @param array $attributes Additional attributes + * @param array{ + * flags?: int, + * extends?: Node\Name|null, + * implements?: Node\Name[], + * stmts?: Node\Stmt[], + * attrGroups?: Node\AttributeGroup[], + * } $subNodes Array of the following optional subnodes: + * 'flags' => 0 : Flags + * 'extends' => null : Name of extended class + * 'implements' => array(): Names of implemented interfaces + * 'stmts' => array(): Statements + * 'attrGroups' => array(): PHP attribute groups + * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; @@ -45,63 +59,36 @@ public function __construct($name, array $subNodes = [], array $attributes = []) $this->attrGroups = $subNodes['attrGroups'] ?? []; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['attrGroups', 'flags', 'name', 'extends', 'implements', 'stmts']; } /** * Whether the class is explicitly abstract. - * - * @return bool */ - public function isAbstract() : bool { - return (bool) ($this->flags & self::MODIFIER_ABSTRACT); + public function isAbstract(): bool { + return (bool) ($this->flags & Modifiers::ABSTRACT); } /** * Whether the class is final. - * - * @return bool */ - public function isFinal() : bool { - return (bool) ($this->flags & self::MODIFIER_FINAL); + public function isFinal(): bool { + return (bool) ($this->flags & Modifiers::FINAL); } - /** - * Whether the class is anonymous. - * - * @return bool - */ - public function isAnonymous() : bool { - return null === $this->name; + public function isReadonly(): bool { + return (bool) ($this->flags & Modifiers::READONLY); } /** - * @internal + * Whether the class is anonymous. */ - public static function verifyModifier($a, $b) { - if ($a & self::VISIBILITY_MODIFIER_MASK && $b & self::VISIBILITY_MODIFIER_MASK) { - throw new Error('Multiple access type modifiers are not allowed'); - } - - if ($a & self::MODIFIER_ABSTRACT && $b & self::MODIFIER_ABSTRACT) { - throw new Error('Multiple abstract modifiers are not allowed'); - } - - if ($a & self::MODIFIER_STATIC && $b & self::MODIFIER_STATIC) { - throw new Error('Multiple static modifiers are not allowed'); - } - - if ($a & self::MODIFIER_FINAL && $b & self::MODIFIER_FINAL) { - throw new Error('Multiple final modifiers are not allowed'); - } - - if ($a & 48 && $b & 48) { - throw new Error('Cannot use the final modifier on an abstract class member'); - } + public function isAnonymous(): bool { + return null === $this->name; } - public function getType() : string { + public function getType(): string { return 'Stmt_Class'; } } diff --git a/lib/PhpParser/Node/Stmt/Const_.php b/lib/PhpParser/Node/Stmt/Const_.php index e6316345ee..c54d6780e6 100644 --- a/lib/PhpParser/Node/Stmt/Const_.php +++ b/lib/PhpParser/Node/Stmt/Const_.php @@ -4,27 +4,34 @@ use PhpParser\Node; -class Const_ extends Node\Stmt -{ +class Const_ extends Node\Stmt { /** @var Node\Const_[] Constant declarations */ - public $consts; + public array $consts; + /** @var Node\AttributeGroup[] PHP attribute groups */ + public array $attrGroups; /** * Constructs a const list node. * - * @param Node\Const_[] $consts Constant declarations - * @param array $attributes Additional attributes + * @param Node\Const_[] $consts Constant declarations + * @param array $attributes Additional attributes + * @param list $attrGroups PHP attribute groups */ - public function __construct(array $consts, array $attributes = []) { + public function __construct( + array $consts, + array $attributes = [], + array $attrGroups = [] + ) { $this->attributes = $attributes; + $this->attrGroups = $attrGroups; $this->consts = $consts; } - public function getSubNodeNames() : array { - return ['consts']; + public function getSubNodeNames(): array { + return ['attrGroups', 'consts']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Const'; } } diff --git a/lib/PhpParser/Node/Stmt/Continue_.php b/lib/PhpParser/Node/Stmt/Continue_.php index 24882683b3..54e979ddaa 100644 --- a/lib/PhpParser/Node/Stmt/Continue_.php +++ b/lib/PhpParser/Node/Stmt/Continue_.php @@ -4,27 +4,26 @@ use PhpParser\Node; -class Continue_ extends Node\Stmt -{ +class Continue_ extends Node\Stmt { /** @var null|Node\Expr Number of loops to continue */ - public $num; + public ?Node\Expr $num; /** * Constructs a continue node. * - * @param null|Node\Expr $num Number of loops to continue - * @param array $attributes Additional attributes + * @param null|Node\Expr $num Number of loops to continue + * @param array $attributes Additional attributes */ - public function __construct(Node\Expr $num = null, array $attributes = []) { + public function __construct(?Node\Expr $num = null, array $attributes = []) { $this->attributes = $attributes; $this->num = $num; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['num']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Continue'; } } diff --git a/lib/PhpParser/Node/Stmt/DeclareDeclare.php b/lib/PhpParser/Node/Stmt/DeclareDeclare.php index ac07f30c78..1a3c3616d4 100644 --- a/lib/PhpParser/Node/Stmt/DeclareDeclare.php +++ b/lib/PhpParser/Node/Stmt/DeclareDeclare.php @@ -2,33 +2,12 @@ namespace PhpParser\Node\Stmt; -use PhpParser\Node; +use PhpParser\Node\DeclareItem; -class DeclareDeclare extends Node\Stmt -{ - /** @var Node\Identifier Key */ - public $key; - /** @var Node\Expr Value */ - public $value; +require __DIR__ . '/../DeclareItem.php'; - /** - * Constructs a declare key=>value pair node. - * - * @param string|Node\Identifier $key Key - * @param Node\Expr $value Value - * @param array $attributes Additional attributes - */ - public function __construct($key, Node\Expr $value, array $attributes = []) { - $this->attributes = $attributes; - $this->key = \is_string($key) ? new Node\Identifier($key) : $key; - $this->value = $value; - } - - public function getSubNodeNames() : array { - return ['key', 'value']; - } - - public function getType() : string { - return 'Stmt_DeclareDeclare'; +if (false) { + // For classmap-authoritative support. + class DeclareDeclare extends DeclareItem { } } diff --git a/lib/PhpParser/Node/Stmt/Declare_.php b/lib/PhpParser/Node/Stmt/Declare_.php index f46ff0bafd..3c0547bdf2 100644 --- a/lib/PhpParser/Node/Stmt/Declare_.php +++ b/lib/PhpParser/Node/Stmt/Declare_.php @@ -3,32 +3,32 @@ namespace PhpParser\Node\Stmt; use PhpParser\Node; +use PhpParser\Node\DeclareItem; -class Declare_ extends Node\Stmt -{ - /** @var DeclareDeclare[] List of declares */ - public $declares; +class Declare_ extends Node\Stmt { + /** @var DeclareItem[] List of declares */ + public array $declares; /** @var Node\Stmt[]|null Statements */ - public $stmts; + public ?array $stmts; /** * Constructs a declare node. * - * @param DeclareDeclare[] $declares List of declares - * @param Node\Stmt[]|null $stmts Statements - * @param array $attributes Additional attributes + * @param DeclareItem[] $declares List of declares + * @param Node\Stmt[]|null $stmts Statements + * @param array $attributes Additional attributes */ - public function __construct(array $declares, array $stmts = null, array $attributes = []) { + public function __construct(array $declares, ?array $stmts = null, array $attributes = []) { $this->attributes = $attributes; $this->declares = $declares; $this->stmts = $stmts; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['declares', 'stmts']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Declare'; } } diff --git a/lib/PhpParser/Node/Stmt/Do_.php b/lib/PhpParser/Node/Stmt/Do_.php index 78e90da03a..6124442881 100644 --- a/lib/PhpParser/Node/Stmt/Do_.php +++ b/lib/PhpParser/Node/Stmt/Do_.php @@ -4,19 +4,18 @@ use PhpParser\Node; -class Do_ extends Node\Stmt -{ +class Do_ extends Node\Stmt { /** @var Node\Stmt[] Statements */ - public $stmts; + public array $stmts; /** @var Node\Expr Condition */ - public $cond; + public Node\Expr $cond; /** * Constructs a do while node. * - * @param Node\Expr $cond Condition - * @param Node\Stmt[] $stmts Statements - * @param array $attributes Additional attributes + * @param Node\Expr $cond Condition + * @param Node\Stmt[] $stmts Statements + * @param array $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $stmts = [], array $attributes = []) { $this->attributes = $attributes; @@ -24,11 +23,11 @@ public function __construct(Node\Expr $cond, array $stmts = [], array $attribute $this->stmts = $stmts; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['stmts', 'cond']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Do'; } } diff --git a/lib/PhpParser/Node/Stmt/Echo_.php b/lib/PhpParser/Node/Stmt/Echo_.php index 7cc50d5d6e..4d42452353 100644 --- a/lib/PhpParser/Node/Stmt/Echo_.php +++ b/lib/PhpParser/Node/Stmt/Echo_.php @@ -4,27 +4,26 @@ use PhpParser\Node; -class Echo_ extends Node\Stmt -{ +class Echo_ extends Node\Stmt { /** @var Node\Expr[] Expressions */ - public $exprs; + public array $exprs; /** * Constructs an echo node. * - * @param Node\Expr[] $exprs Expressions - * @param array $attributes Additional attributes + * @param Node\Expr[] $exprs Expressions + * @param array $attributes Additional attributes */ public function __construct(array $exprs, array $attributes = []) { $this->attributes = $attributes; $this->exprs = $exprs; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['exprs']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Echo'; } } diff --git a/lib/PhpParser/Node/Stmt/ElseIf_.php b/lib/PhpParser/Node/Stmt/ElseIf_.php index eef1ece324..b26d59ce5f 100644 --- a/lib/PhpParser/Node/Stmt/ElseIf_.php +++ b/lib/PhpParser/Node/Stmt/ElseIf_.php @@ -4,19 +4,18 @@ use PhpParser\Node; -class ElseIf_ extends Node\Stmt -{ +class ElseIf_ extends Node\Stmt { /** @var Node\Expr Condition */ - public $cond; + public Node\Expr $cond; /** @var Node\Stmt[] Statements */ - public $stmts; + public array $stmts; /** * Constructs an elseif node. * - * @param Node\Expr $cond Condition - * @param Node\Stmt[] $stmts Statements - * @param array $attributes Additional attributes + * @param Node\Expr $cond Condition + * @param Node\Stmt[] $stmts Statements + * @param array $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $stmts = [], array $attributes = []) { $this->attributes = $attributes; @@ -24,11 +23,11 @@ public function __construct(Node\Expr $cond, array $stmts = [], array $attribute $this->stmts = $stmts; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['cond', 'stmts']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_ElseIf'; } } diff --git a/lib/PhpParser/Node/Stmt/Else_.php b/lib/PhpParser/Node/Stmt/Else_.php index 0e61778e26..3d2b066ec9 100644 --- a/lib/PhpParser/Node/Stmt/Else_.php +++ b/lib/PhpParser/Node/Stmt/Else_.php @@ -4,27 +4,26 @@ use PhpParser\Node; -class Else_ extends Node\Stmt -{ +class Else_ extends Node\Stmt { /** @var Node\Stmt[] Statements */ - public $stmts; + public array $stmts; /** * Constructs an else node. * - * @param Node\Stmt[] $stmts Statements - * @param array $attributes Additional attributes + * @param Node\Stmt[] $stmts Statements + * @param array $attributes Additional attributes */ public function __construct(array $stmts = [], array $attributes = []) { $this->attributes = $attributes; $this->stmts = $stmts; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['stmts']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Else'; } } diff --git a/lib/PhpParser/Node/Stmt/EnumCase.php b/lib/PhpParser/Node/Stmt/EnumCase.php new file mode 100644 index 0000000000..c071a0af13 --- /dev/null +++ b/lib/PhpParser/Node/Stmt/EnumCase.php @@ -0,0 +1,36 @@ + $attrGroups PHP attribute groups + * @param array $attributes Additional attributes + */ + public function __construct($name, ?Node\Expr $expr = null, array $attrGroups = [], array $attributes = []) { + parent::__construct($attributes); + $this->name = \is_string($name) ? new Node\Identifier($name) : $name; + $this->expr = $expr; + $this->attrGroups = $attrGroups; + } + + public function getSubNodeNames(): array { + return ['attrGroups', 'name', 'expr']; + } + + public function getType(): string { + return 'Stmt_EnumCase'; + } +} diff --git a/lib/PhpParser/Node/Stmt/Enum_.php b/lib/PhpParser/Node/Stmt/Enum_.php new file mode 100644 index 0000000000..7eea6a6991 --- /dev/null +++ b/lib/PhpParser/Node/Stmt/Enum_.php @@ -0,0 +1,44 @@ + null : Scalar type + * 'implements' => array() : Names of implemented interfaces + * 'stmts' => array() : Statements + * 'attrGroups' => array() : PHP attribute groups + * @param array $attributes Additional attributes + */ + public function __construct($name, array $subNodes = [], array $attributes = []) { + $this->name = \is_string($name) ? new Node\Identifier($name) : $name; + $this->scalarType = $subNodes['scalarType'] ?? null; + $this->implements = $subNodes['implements'] ?? []; + $this->stmts = $subNodes['stmts'] ?? []; + $this->attrGroups = $subNodes['attrGroups'] ?? []; + + parent::__construct($attributes); + } + + public function getSubNodeNames(): array { + return ['attrGroups', 'name', 'scalarType', 'implements', 'stmts']; + } + + public function getType(): string { + return 'Stmt_Enum'; + } +} diff --git a/lib/PhpParser/Node/Stmt/Expression.php b/lib/PhpParser/Node/Stmt/Expression.php index 99d1687ded..89751fa2dc 100644 --- a/lib/PhpParser/Node/Stmt/Expression.php +++ b/lib/PhpParser/Node/Stmt/Expression.php @@ -7,27 +7,26 @@ /** * Represents statements of type "expr;" */ -class Expression extends Node\Stmt -{ +class Expression extends Node\Stmt { /** @var Node\Expr Expression */ - public $expr; + public Node\Expr $expr; /** * Constructs an expression statement. * - * @param Node\Expr $expr Expression - * @param array $attributes Additional attributes + * @param Node\Expr $expr Expression + * @param array $attributes Additional attributes */ public function __construct(Node\Expr $expr, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Expression'; } } diff --git a/lib/PhpParser/Node/Stmt/Finally_.php b/lib/PhpParser/Node/Stmt/Finally_.php index d55b8b6872..69ecf25373 100644 --- a/lib/PhpParser/Node/Stmt/Finally_.php +++ b/lib/PhpParser/Node/Stmt/Finally_.php @@ -4,27 +4,26 @@ use PhpParser\Node; -class Finally_ extends Node\Stmt -{ +class Finally_ extends Node\Stmt { /** @var Node\Stmt[] Statements */ - public $stmts; + public array $stmts; /** * Constructs a finally node. * - * @param Node\Stmt[] $stmts Statements - * @param array $attributes Additional attributes + * @param Node\Stmt[] $stmts Statements + * @param array $attributes Additional attributes */ public function __construct(array $stmts = [], array $attributes = []) { $this->attributes = $attributes; $this->stmts = $stmts; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['stmts']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Finally'; } } diff --git a/lib/PhpParser/Node/Stmt/For_.php b/lib/PhpParser/Node/Stmt/For_.php index 1323d37cf3..6f2fbb9e3a 100644 --- a/lib/PhpParser/Node/Stmt/For_.php +++ b/lib/PhpParser/Node/Stmt/For_.php @@ -4,26 +4,30 @@ use PhpParser\Node; -class For_ extends Node\Stmt -{ +class For_ extends Node\Stmt { /** @var Node\Expr[] Init expressions */ - public $init; + public array $init; /** @var Node\Expr[] Loop conditions */ - public $cond; + public array $cond; /** @var Node\Expr[] Loop expressions */ - public $loop; + public array $loop; /** @var Node\Stmt[] Statements */ - public $stmts; + public array $stmts; /** * Constructs a for loop node. * - * @param array $subNodes Array of the following optional subnodes: - * 'init' => array(): Init expressions - * 'cond' => array(): Loop conditions - * 'loop' => array(): Loop expressions - * 'stmts' => array(): Statements - * @param array $attributes Additional attributes + * @param array{ + * init?: Node\Expr[], + * cond?: Node\Expr[], + * loop?: Node\Expr[], + * stmts?: Node\Stmt[], + * } $subNodes Array of the following optional subnodes: + * 'init' => array(): Init expressions + * 'cond' => array(): Loop conditions + * 'loop' => array(): Loop expressions + * 'stmts' => array(): Statements + * @param array $attributes Additional attributes */ public function __construct(array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; @@ -33,11 +37,11 @@ public function __construct(array $subNodes = [], array $attributes = []) { $this->stmts = $subNodes['stmts'] ?? []; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['init', 'cond', 'loop', 'stmts']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_For'; } } diff --git a/lib/PhpParser/Node/Stmt/Foreach_.php b/lib/PhpParser/Node/Stmt/Foreach_.php index 0556a7ce5f..c5d9a8b132 100644 --- a/lib/PhpParser/Node/Stmt/Foreach_.php +++ b/lib/PhpParser/Node/Stmt/Foreach_.php @@ -4,29 +4,32 @@ use PhpParser\Node; -class Foreach_ extends Node\Stmt -{ +class Foreach_ extends Node\Stmt { /** @var Node\Expr Expression to iterate */ - public $expr; + public Node\Expr $expr; /** @var null|Node\Expr Variable to assign key to */ - public $keyVar; + public ?Node\Expr $keyVar; /** @var bool Whether to assign value by reference */ - public $byRef; + public bool $byRef; /** @var Node\Expr Variable to assign value to */ - public $valueVar; + public Node\Expr $valueVar; /** @var Node\Stmt[] Statements */ - public $stmts; + public array $stmts; /** * Constructs a foreach node. * - * @param Node\Expr $expr Expression to iterate - * @param Node\Expr $valueVar Variable to assign value to - * @param array $subNodes Array of the following optional subnodes: - * 'keyVar' => null : Variable to assign key to - * 'byRef' => false : Whether to assign value by reference - * 'stmts' => array(): Statements - * @param array $attributes Additional attributes + * @param Node\Expr $expr Expression to iterate + * @param Node\Expr $valueVar Variable to assign value to + * @param array{ + * keyVar?: Node\Expr|null, + * byRef?: bool, + * stmts?: Node\Stmt[], + * } $subNodes Array of the following optional subnodes: + * 'keyVar' => null : Variable to assign key to + * 'byRef' => false : Whether to assign value by reference + * 'stmts' => array(): Statements + * @param array $attributes Additional attributes */ public function __construct(Node\Expr $expr, Node\Expr $valueVar, array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; @@ -37,11 +40,11 @@ public function __construct(Node\Expr $expr, Node\Expr $valueVar, array $subNode $this->stmts = $subNodes['stmts'] ?? []; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr', 'keyVar', 'byRef', 'valueVar', 'stmts']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Foreach'; } } diff --git a/lib/PhpParser/Node/Stmt/Function_.php b/lib/PhpParser/Node/Stmt/Function_.php index f08481fae1..2111bab749 100644 --- a/lib/PhpParser/Node/Stmt/Function_.php +++ b/lib/PhpParser/Node/Stmt/Function_.php @@ -5,56 +5,60 @@ use PhpParser\Node; use PhpParser\Node\FunctionLike; -/** - * @property Node\Name $namespacedName Namespaced name (if using NameResolver) - */ -class Function_ extends Node\Stmt implements FunctionLike -{ +class Function_ extends Node\Stmt implements FunctionLike { /** @var bool Whether function returns by reference */ - public $byRef; + public bool $byRef; /** @var Node\Identifier Name */ - public $name; + public Node\Identifier $name; /** @var Node\Param[] Parameters */ - public $params; - /** @var null|Node\Identifier|Node\Name|Node\NullableType|Node\UnionType Return type */ - public $returnType; + public array $params; + /** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */ + public ?Node $returnType; /** @var Node\Stmt[] Statements */ - public $stmts; + public array $stmts; /** @var Node\AttributeGroup[] PHP attribute groups */ - public $attrGroups; + public array $attrGroups; + + /** @var Node\Name|null Namespaced name (if using NameResolver) */ + public ?Node\Name $namespacedName; /** * Constructs a function node. * * @param string|Node\Identifier $name Name - * @param array $subNodes Array of the following optional subnodes: - * 'byRef' => false : Whether to return by reference - * 'params' => array(): Parameters - * 'returnType' => null : Return type - * 'stmts' => array(): Statements - * 'attrGroups' => array(): PHP attribute groups - * @param array $attributes Additional attributes + * @param array{ + * byRef?: bool, + * params?: Node\Param[], + * returnType?: null|Node\Identifier|Node\Name|Node\ComplexType, + * stmts?: Node\Stmt[], + * attrGroups?: Node\AttributeGroup[], + * } $subNodes Array of the following optional subnodes: + * 'byRef' => false : Whether to return by reference + * 'params' => array(): Parameters + * 'returnType' => null : Return type + * 'stmts' => array(): Statements + * 'attrGroups' => array(): PHP attribute groups + * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; $this->byRef = $subNodes['byRef'] ?? false; $this->name = \is_string($name) ? new Node\Identifier($name) : $name; $this->params = $subNodes['params'] ?? []; - $returnType = $subNodes['returnType'] ?? null; - $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType; + $this->returnType = $subNodes['returnType'] ?? null; $this->stmts = $subNodes['stmts'] ?? []; $this->attrGroups = $subNodes['attrGroups'] ?? []; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['attrGroups', 'byRef', 'name', 'params', 'returnType', 'stmts']; } - public function returnsByRef() : bool { + public function returnsByRef(): bool { return $this->byRef; } - public function getParams() : array { + public function getParams(): array { return $this->params; } @@ -62,16 +66,16 @@ public function getReturnType() { return $this->returnType; } - public function getAttrGroups() : array { + public function getAttrGroups(): array { return $this->attrGroups; } /** @return Node\Stmt[] */ - public function getStmts() : array { + public function getStmts(): array { return $this->stmts; } - public function getType() : string { + public function getType(): string { return 'Stmt_Function'; } } diff --git a/lib/PhpParser/Node/Stmt/Global_.php b/lib/PhpParser/Node/Stmt/Global_.php index a0022ad932..d3ab12fc24 100644 --- a/lib/PhpParser/Node/Stmt/Global_.php +++ b/lib/PhpParser/Node/Stmt/Global_.php @@ -4,27 +4,26 @@ use PhpParser\Node; -class Global_ extends Node\Stmt -{ +class Global_ extends Node\Stmt { /** @var Node\Expr[] Variables */ - public $vars; + public array $vars; /** * Constructs a global variables list node. * - * @param Node\Expr[] $vars Variables to unset - * @param array $attributes Additional attributes + * @param Node\Expr[] $vars Variables to unset + * @param array $attributes Additional attributes */ public function __construct(array $vars, array $attributes = []) { $this->attributes = $attributes; $this->vars = $vars; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['vars']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Global'; } } diff --git a/lib/PhpParser/Node/Stmt/Goto_.php b/lib/PhpParser/Node/Stmt/Goto_.php index 24a57f7807..26a0d01eae 100644 --- a/lib/PhpParser/Node/Stmt/Goto_.php +++ b/lib/PhpParser/Node/Stmt/Goto_.php @@ -5,27 +5,26 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Stmt; -class Goto_ extends Stmt -{ +class Goto_ extends Stmt { /** @var Identifier Name of label to jump to */ - public $name; + public Identifier $name; /** * Constructs a goto node. * - * @param string|Identifier $name Name of label to jump to - * @param array $attributes Additional attributes + * @param string|Identifier $name Name of label to jump to + * @param array $attributes Additional attributes */ public function __construct($name, array $attributes = []) { $this->attributes = $attributes; $this->name = \is_string($name) ? new Identifier($name) : $name; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['name']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Goto'; } } diff --git a/lib/PhpParser/Node/Stmt/GroupUse.php b/lib/PhpParser/Node/Stmt/GroupUse.php index 24520d2233..0ec8e9d42b 100644 --- a/lib/PhpParser/Node/Stmt/GroupUse.php +++ b/lib/PhpParser/Node/Stmt/GroupUse.php @@ -4,23 +4,25 @@ use PhpParser\Node\Name; use PhpParser\Node\Stmt; +use PhpParser\Node\UseItem; -class GroupUse extends Stmt -{ - /** @var int Type of group use */ - public $type; +class GroupUse extends Stmt { + /** + * @var Use_::TYPE_* Type of group use + */ + public int $type; /** @var Name Prefix for uses */ - public $prefix; - /** @var UseUse[] Uses */ - public $uses; + public Name $prefix; + /** @var UseItem[] Uses */ + public array $uses; /** * Constructs a group use node. * - * @param Name $prefix Prefix for uses - * @param UseUse[] $uses Uses - * @param int $type Type of group use - * @param array $attributes Additional attributes + * @param Name $prefix Prefix for uses + * @param UseItem[] $uses Uses + * @param Use_::TYPE_* $type Type of group use + * @param array $attributes Additional attributes */ public function __construct(Name $prefix, array $uses, int $type = Use_::TYPE_NORMAL, array $attributes = []) { $this->attributes = $attributes; @@ -29,11 +31,11 @@ public function __construct(Name $prefix, array $uses, int $type = Use_::TYPE_NO $this->uses = $uses; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['type', 'prefix', 'uses']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_GroupUse'; } } diff --git a/lib/PhpParser/Node/Stmt/HaltCompiler.php b/lib/PhpParser/Node/Stmt/HaltCompiler.php index 8e624e0f1f..665bacdee2 100644 --- a/lib/PhpParser/Node/Stmt/HaltCompiler.php +++ b/lib/PhpParser/Node/Stmt/HaltCompiler.php @@ -4,27 +4,26 @@ use PhpParser\Node\Stmt; -class HaltCompiler extends Stmt -{ +class HaltCompiler extends Stmt { /** @var string Remaining text after halt compiler statement. */ - public $remaining; + public string $remaining; /** * Constructs a __halt_compiler node. * - * @param string $remaining Remaining text after halt compiler statement. - * @param array $attributes Additional attributes + * @param string $remaining Remaining text after halt compiler statement. + * @param array $attributes Additional attributes */ public function __construct(string $remaining, array $attributes = []) { $this->attributes = $attributes; $this->remaining = $remaining; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['remaining']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_HaltCompiler'; } } diff --git a/lib/PhpParser/Node/Stmt/If_.php b/lib/PhpParser/Node/Stmt/If_.php index a1bae4bf89..544390ff5e 100644 --- a/lib/PhpParser/Node/Stmt/If_.php +++ b/lib/PhpParser/Node/Stmt/If_.php @@ -4,26 +4,29 @@ use PhpParser\Node; -class If_ extends Node\Stmt -{ +class If_ extends Node\Stmt { /** @var Node\Expr Condition expression */ - public $cond; + public Node\Expr $cond; /** @var Node\Stmt[] Statements */ - public $stmts; + public array $stmts; /** @var ElseIf_[] Elseif clauses */ - public $elseifs; + public array $elseifs; /** @var null|Else_ Else clause */ - public $else; + public ?Else_ $else; /** * Constructs an if node. * - * @param Node\Expr $cond Condition - * @param array $subNodes Array of the following optional subnodes: - * 'stmts' => array(): Statements - * 'elseifs' => array(): Elseif clauses - * 'else' => null : Else clause - * @param array $attributes Additional attributes + * @param Node\Expr $cond Condition + * @param array{ + * stmts?: Node\Stmt[], + * elseifs?: ElseIf_[], + * else?: Else_|null, + * } $subNodes Array of the following optional subnodes: + * 'stmts' => array(): Statements + * 'elseifs' => array(): Elseif clauses + * 'else' => null : Else clause + * @param array $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; @@ -33,11 +36,11 @@ public function __construct(Node\Expr $cond, array $subNodes = [], array $attrib $this->else = $subNodes['else'] ?? null; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['cond', 'stmts', 'elseifs', 'else']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_If'; } } diff --git a/lib/PhpParser/Node/Stmt/InlineHTML.php b/lib/PhpParser/Node/Stmt/InlineHTML.php index 0711d2842c..0515d02054 100644 --- a/lib/PhpParser/Node/Stmt/InlineHTML.php +++ b/lib/PhpParser/Node/Stmt/InlineHTML.php @@ -4,27 +4,26 @@ use PhpParser\Node\Stmt; -class InlineHTML extends Stmt -{ +class InlineHTML extends Stmt { /** @var string String */ - public $value; + public string $value; /** * Constructs an inline HTML node. * - * @param string $value String - * @param array $attributes Additional attributes + * @param string $value String + * @param array $attributes Additional attributes */ public function __construct(string $value, array $attributes = []) { $this->attributes = $attributes; $this->value = $value; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['value']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_InlineHTML'; } } diff --git a/lib/PhpParser/Node/Stmt/Interface_.php b/lib/PhpParser/Node/Stmt/Interface_.php index 4d587dd484..9359064f8e 100644 --- a/lib/PhpParser/Node/Stmt/Interface_.php +++ b/lib/PhpParser/Node/Stmt/Interface_.php @@ -4,20 +4,23 @@ use PhpParser\Node; -class Interface_ extends ClassLike -{ +class Interface_ extends ClassLike { /** @var Node\Name[] Extended interfaces */ - public $extends; + public array $extends; /** * Constructs a class node. * * @param string|Node\Identifier $name Name - * @param array $subNodes Array of the following optional subnodes: - * 'extends' => array(): Name of extended interfaces - * 'stmts' => array(): Statements - * 'attrGroups' => array(): PHP attribute groups - * @param array $attributes Additional attributes + * @param array{ + * extends?: Node\Name[], + * stmts?: Node\Stmt[], + * attrGroups?: Node\AttributeGroup[], + * } $subNodes Array of the following optional subnodes: + * 'extends' => array(): Name of extended interfaces + * 'stmts' => array(): Statements + * 'attrGroups' => array(): PHP attribute groups + * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; @@ -27,11 +30,11 @@ public function __construct($name, array $subNodes = [], array $attributes = []) $this->attrGroups = $subNodes['attrGroups'] ?? []; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['attrGroups', 'name', 'extends', 'stmts']; } - public function getType() : string { + public function getType(): string { return 'Stmt_Interface'; } } diff --git a/lib/PhpParser/Node/Stmt/Label.php b/lib/PhpParser/Node/Stmt/Label.php index 3edcb3be7e..658468d2f6 100644 --- a/lib/PhpParser/Node/Stmt/Label.php +++ b/lib/PhpParser/Node/Stmt/Label.php @@ -5,27 +5,26 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Stmt; -class Label extends Stmt -{ +class Label extends Stmt { /** @var Identifier Name */ - public $name; + public Identifier $name; /** * Constructs a label node. * - * @param string|Identifier $name Name - * @param array $attributes Additional attributes + * @param string|Identifier $name Name + * @param array $attributes Additional attributes */ public function __construct($name, array $attributes = []) { $this->attributes = $attributes; $this->name = \is_string($name) ? new Identifier($name) : $name; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['name']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Label'; } } diff --git a/lib/PhpParser/Node/Stmt/Namespace_.php b/lib/PhpParser/Node/Stmt/Namespace_.php index c63204577c..f5b59ad6e3 100644 --- a/lib/PhpParser/Node/Stmt/Namespace_.php +++ b/lib/PhpParser/Node/Stmt/Namespace_.php @@ -4,35 +4,34 @@ use PhpParser\Node; -class Namespace_ extends Node\Stmt -{ +class Namespace_ extends Node\Stmt { /* For use in the "kind" attribute */ - const KIND_SEMICOLON = 1; - const KIND_BRACED = 2; + public const KIND_SEMICOLON = 1; + public const KIND_BRACED = 2; /** @var null|Node\Name Name */ - public $name; + public ?Node\Name $name; /** @var Node\Stmt[] Statements */ public $stmts; /** * Constructs a namespace node. * - * @param null|Node\Name $name Name - * @param null|Node\Stmt[] $stmts Statements - * @param array $attributes Additional attributes + * @param null|Node\Name $name Name + * @param null|Node\Stmt[] $stmts Statements + * @param array $attributes Additional attributes */ - public function __construct(Node\Name $name = null, $stmts = [], array $attributes = []) { + public function __construct(?Node\Name $name = null, ?array $stmts = [], array $attributes = []) { $this->attributes = $attributes; $this->name = $name; $this->stmts = $stmts; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['name', 'stmts']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Namespace'; } } diff --git a/lib/PhpParser/Node/Stmt/Nop.php b/lib/PhpParser/Node/Stmt/Nop.php index f86f8df7d3..3acfa46fb0 100644 --- a/lib/PhpParser/Node/Stmt/Nop.php +++ b/lib/PhpParser/Node/Stmt/Nop.php @@ -5,13 +5,12 @@ use PhpParser\Node; /** Nop/empty statement (;). */ -class Nop extends Node\Stmt -{ - public function getSubNodeNames() : array { +class Nop extends Node\Stmt { + public function getSubNodeNames(): array { return []; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Nop'; } } diff --git a/lib/PhpParser/Node/Stmt/Property.php b/lib/PhpParser/Node/Stmt/Property.php index 324345b85f..03e45a9526 100644 --- a/lib/PhpParser/Node/Stmt/Property.php +++ b/lib/PhpParser/Node/Stmt/Property.php @@ -2,82 +2,120 @@ namespace PhpParser\Node\Stmt; +use PhpParser\Modifiers; use PhpParser\Node; +use PhpParser\Node\ComplexType; use PhpParser\Node\Identifier; use PhpParser\Node\Name; -use PhpParser\Node\NullableType; -use PhpParser\Node\UnionType; +use PhpParser\Node\PropertyItem; -class Property extends Node\Stmt -{ +class Property extends Node\Stmt { /** @var int Modifiers */ - public $flags; - /** @var PropertyProperty[] Properties */ - public $props; - /** @var null|Identifier|Name|NullableType|UnionType Type declaration */ - public $type; + public int $flags; + /** @var PropertyItem[] Properties */ + public array $props; + /** @var null|Identifier|Name|ComplexType Type declaration */ + public ?Node $type; /** @var Node\AttributeGroup[] PHP attribute groups */ - public $attrGroups; + public array $attrGroups; + /** @var Node\PropertyHook[] Property hooks */ + public array $hooks; /** * Constructs a class property list node. * - * @param int $flags Modifiers - * @param PropertyProperty[] $props Properties - * @param array $attributes Additional attributes - * @param null|string|Identifier|Name|NullableType|UnionType $type Type declaration - * @param Node\AttributeGroup[] $attrGroups PHP attribute groups + * @param int $flags Modifiers + * @param PropertyItem[] $props Properties + * @param array $attributes Additional attributes + * @param null|Identifier|Name|ComplexType $type Type declaration + * @param Node\AttributeGroup[] $attrGroups PHP attribute groups + * @param Node\PropertyHook[] $hooks Property hooks */ - public function __construct(int $flags, array $props, array $attributes = [], $type = null, array $attrGroups = []) { + public function __construct(int $flags, array $props, array $attributes = [], ?Node $type = null, array $attrGroups = [], array $hooks = []) { $this->attributes = $attributes; $this->flags = $flags; $this->props = $props; - $this->type = \is_string($type) ? new Identifier($type) : $type; + $this->type = $type; $this->attrGroups = $attrGroups; + $this->hooks = $hooks; } - public function getSubNodeNames() : array { - return ['attrGroups', 'flags', 'type', 'props']; + public function getSubNodeNames(): array { + return ['attrGroups', 'flags', 'type', 'props', 'hooks']; } /** * Whether the property is explicitly or implicitly public. - * - * @return bool */ - public function isPublic() : bool { - return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0 - || ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0; + public function isPublic(): bool { + return ($this->flags & Modifiers::PUBLIC) !== 0 + || ($this->flags & Modifiers::VISIBILITY_MASK) === 0; } /** * Whether the property is protected. - * - * @return bool */ - public function isProtected() : bool { - return (bool) ($this->flags & Class_::MODIFIER_PROTECTED); + public function isProtected(): bool { + return (bool) ($this->flags & Modifiers::PROTECTED); } /** * Whether the property is private. - * - * @return bool */ - public function isPrivate() : bool { - return (bool) ($this->flags & Class_::MODIFIER_PRIVATE); + public function isPrivate(): bool { + return (bool) ($this->flags & Modifiers::PRIVATE); } /** * Whether the property is static. - * - * @return bool */ - public function isStatic() : bool { - return (bool) ($this->flags & Class_::MODIFIER_STATIC); + public function isStatic(): bool { + return (bool) ($this->flags & Modifiers::STATIC); + } + + /** + * Whether the property is readonly. + */ + public function isReadonly(): bool { + return (bool) ($this->flags & Modifiers::READONLY); + } + + /** + * Whether the property is abstract. + */ + public function isAbstract(): bool { + return (bool) ($this->flags & Modifiers::ABSTRACT); + } + + /** + * Whether the property is final. + */ + public function isFinal(): bool { + return (bool) ($this->flags & Modifiers::FINAL); + } + + /** + * Whether the property has explicit public(set) visibility. + */ + public function isPublicSet(): bool { + return (bool) ($this->flags & Modifiers::PUBLIC_SET); + } + + /** + * Whether the property has explicit protected(set) visibility. + */ + public function isProtectedSet(): bool { + return (bool) ($this->flags & Modifiers::PROTECTED_SET); + } + + /** + * Whether the property has explicit private(set) visibility. + */ + public function isPrivateSet(): bool { + return (bool) ($this->flags & Modifiers::PRIVATE_SET); } - public function getType() : string { + public function getType(): string { return 'Stmt_Property'; } } diff --git a/lib/PhpParser/Node/Stmt/PropertyProperty.php b/lib/PhpParser/Node/Stmt/PropertyProperty.php index 205731e20e..fe7c99736b 100644 --- a/lib/PhpParser/Node/Stmt/PropertyProperty.php +++ b/lib/PhpParser/Node/Stmt/PropertyProperty.php @@ -2,33 +2,12 @@ namespace PhpParser\Node\Stmt; -use PhpParser\Node; +use PhpParser\Node\PropertyItem; -class PropertyProperty extends Node\Stmt -{ - /** @var Node\VarLikeIdentifier Name */ - public $name; - /** @var null|Node\Expr Default */ - public $default; +require __DIR__ . '/../PropertyItem.php'; - /** - * Constructs a class property node. - * - * @param string|Node\VarLikeIdentifier $name Name - * @param null|Node\Expr $default Default value - * @param array $attributes Additional attributes - */ - public function __construct($name, Node\Expr $default = null, array $attributes = []) { - $this->attributes = $attributes; - $this->name = \is_string($name) ? new Node\VarLikeIdentifier($name) : $name; - $this->default = $default; - } - - public function getSubNodeNames() : array { - return ['name', 'default']; - } - - public function getType() : string { - return 'Stmt_PropertyProperty'; +if (false) { + // For classmap-authoritative support. + class PropertyProperty extends PropertyItem { } } diff --git a/lib/PhpParser/Node/Stmt/Return_.php b/lib/PhpParser/Node/Stmt/Return_.php index efc578c58f..9c44cca85c 100644 --- a/lib/PhpParser/Node/Stmt/Return_.php +++ b/lib/PhpParser/Node/Stmt/Return_.php @@ -4,27 +4,26 @@ use PhpParser\Node; -class Return_ extends Node\Stmt -{ +class Return_ extends Node\Stmt { /** @var null|Node\Expr Expression */ - public $expr; + public ?Node\Expr $expr; /** * Constructs a return node. * - * @param null|Node\Expr $expr Expression - * @param array $attributes Additional attributes + * @param null|Node\Expr $expr Expression + * @param array $attributes Additional attributes */ - public function __construct(Node\Expr $expr = null, array $attributes = []) { + public function __construct(?Node\Expr $expr = null, array $attributes = []) { $this->attributes = $attributes; $this->expr = $expr; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['expr']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Return'; } } diff --git a/lib/PhpParser/Node/Stmt/StaticVar.php b/lib/PhpParser/Node/Stmt/StaticVar.php index 29584560d3..6775b9597f 100644 --- a/lib/PhpParser/Node/Stmt/StaticVar.php +++ b/lib/PhpParser/Node/Stmt/StaticVar.php @@ -2,36 +2,10 @@ namespace PhpParser\Node\Stmt; -use PhpParser\Node; -use PhpParser\Node\Expr; +require __DIR__ . '/../StaticVar.php'; -class StaticVar extends Node\Stmt -{ - /** @var Expr\Variable Variable */ - public $var; - /** @var null|Node\Expr Default value */ - public $default; - - /** - * Constructs a static variable node. - * - * @param Expr\Variable $var Name - * @param null|Node\Expr $default Default value - * @param array $attributes Additional attributes - */ - public function __construct( - Expr\Variable $var, Node\Expr $default = null, array $attributes = [] - ) { - $this->attributes = $attributes; - $this->var = $var; - $this->default = $default; - } - - public function getSubNodeNames() : array { - return ['var', 'default']; - } - - public function getType() : string { - return 'Stmt_StaticVar'; +if (false) { + // For classmap-authoritative support. + class StaticVar extends \PhpParser\Node\StaticVar { } } diff --git a/lib/PhpParser/Node/Stmt/Static_.php b/lib/PhpParser/Node/Stmt/Static_.php index 464898ffa6..a84de106ac 100644 --- a/lib/PhpParser/Node/Stmt/Static_.php +++ b/lib/PhpParser/Node/Stmt/Static_.php @@ -2,29 +2,29 @@ namespace PhpParser\Node\Stmt; +use PhpParser\Node\StaticVar; use PhpParser\Node\Stmt; -class Static_ extends Stmt -{ +class Static_ extends Stmt { /** @var StaticVar[] Variable definitions */ - public $vars; + public array $vars; /** * Constructs a static variables list node. * - * @param StaticVar[] $vars Variable definitions - * @param array $attributes Additional attributes + * @param StaticVar[] $vars Variable definitions + * @param array $attributes Additional attributes */ public function __construct(array $vars, array $attributes = []) { $this->attributes = $attributes; $this->vars = $vars; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['vars']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Static'; } } diff --git a/lib/PhpParser/Node/Stmt/Switch_.php b/lib/PhpParser/Node/Stmt/Switch_.php index 2c8dae0221..21e5efa569 100644 --- a/lib/PhpParser/Node/Stmt/Switch_.php +++ b/lib/PhpParser/Node/Stmt/Switch_.php @@ -4,19 +4,18 @@ use PhpParser\Node; -class Switch_ extends Node\Stmt -{ +class Switch_ extends Node\Stmt { /** @var Node\Expr Condition */ - public $cond; + public Node\Expr $cond; /** @var Case_[] Case list */ - public $cases; + public array $cases; /** * Constructs a case node. * - * @param Node\Expr $cond Condition - * @param Case_[] $cases Case list - * @param array $attributes Additional attributes + * @param Node\Expr $cond Condition + * @param Case_[] $cases Case list + * @param array $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $cases, array $attributes = []) { $this->attributes = $attributes; @@ -24,11 +23,11 @@ public function __construct(Node\Expr $cond, array $cases, array $attributes = [ $this->cases = $cases; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['cond', 'cases']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Switch'; } } diff --git a/lib/PhpParser/Node/Stmt/Throw_.php b/lib/PhpParser/Node/Stmt/Throw_.php deleted file mode 100644 index a34e2b3624..0000000000 --- a/lib/PhpParser/Node/Stmt/Throw_.php +++ /dev/null @@ -1,30 +0,0 @@ -attributes = $attributes; - $this->expr = $expr; - } - - public function getSubNodeNames() : array { - return ['expr']; - } - - public function getType() : string { - return 'Stmt_Throw'; - } -} diff --git a/lib/PhpParser/Node/Stmt/TraitUse.php b/lib/PhpParser/Node/Stmt/TraitUse.php index 9e97053b40..7705a57057 100644 --- a/lib/PhpParser/Node/Stmt/TraitUse.php +++ b/lib/PhpParser/Node/Stmt/TraitUse.php @@ -4,19 +4,18 @@ use PhpParser\Node; -class TraitUse extends Node\Stmt -{ +class TraitUse extends Node\Stmt { /** @var Node\Name[] Traits */ - public $traits; + public array $traits; /** @var TraitUseAdaptation[] Adaptations */ - public $adaptations; + public array $adaptations; /** * Constructs a trait use node. * - * @param Node\Name[] $traits Traits + * @param Node\Name[] $traits Traits * @param TraitUseAdaptation[] $adaptations Adaptations - * @param array $attributes Additional attributes + * @param array $attributes Additional attributes */ public function __construct(array $traits, array $adaptations = [], array $attributes = []) { $this->attributes = $attributes; @@ -24,11 +23,11 @@ public function __construct(array $traits, array $adaptations = [], array $attri $this->adaptations = $adaptations; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['traits', 'adaptations']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_TraitUse'; } } diff --git a/lib/PhpParser/Node/Stmt/TraitUseAdaptation.php b/lib/PhpParser/Node/Stmt/TraitUseAdaptation.php index 8bdd2c041f..987bc88ed0 100644 --- a/lib/PhpParser/Node/Stmt/TraitUseAdaptation.php +++ b/lib/PhpParser/Node/Stmt/TraitUseAdaptation.php @@ -4,10 +4,9 @@ use PhpParser\Node; -abstract class TraitUseAdaptation extends Node\Stmt -{ +abstract class TraitUseAdaptation extends Node\Stmt { /** @var Node\Name|null Trait name */ - public $trait; + public ?Node\Name $trait; /** @var Node\Identifier Method name */ - public $method; + public Node\Identifier $method; } diff --git a/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Alias.php b/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Alias.php index a3bccbd10c..449671e771 100644 --- a/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Alias.php +++ b/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Alias.php @@ -4,23 +4,22 @@ use PhpParser\Node; -class Alias extends Node\Stmt\TraitUseAdaptation -{ +class Alias extends Node\Stmt\TraitUseAdaptation { /** @var null|int New modifier */ - public $newModifier; + public ?int $newModifier; /** @var null|Node\Identifier New name */ - public $newName; + public ?Node\Identifier $newName; /** * Constructs a trait use precedence adaptation node. * - * @param null|Node\Name $trait Trait name - * @param string|Node\Identifier $method Method name - * @param null|int $newModifier New modifier - * @param null|string|Node\Identifier $newName New name - * @param array $attributes Additional attributes + * @param null|Node\Name $trait Trait name + * @param string|Node\Identifier $method Method name + * @param null|int $newModifier New modifier + * @param null|string|Node\Identifier $newName New name + * @param array $attributes Additional attributes */ - public function __construct($trait, $method, $newModifier, $newName, array $attributes = []) { + public function __construct(?Node\Name $trait, $method, ?int $newModifier, $newName, array $attributes = []) { $this->attributes = $attributes; $this->trait = $trait; $this->method = \is_string($method) ? new Node\Identifier($method) : $method; @@ -28,11 +27,11 @@ public function __construct($trait, $method, $newModifier, $newName, array $attr $this->newName = \is_string($newName) ? new Node\Identifier($newName) : $newName; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['trait', 'method', 'newModifier', 'newName']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_TraitUseAdaptation_Alias'; } } diff --git a/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Precedence.php b/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Precedence.php index 80385f64e3..7bc4083769 100644 --- a/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Precedence.php +++ b/lib/PhpParser/Node/Stmt/TraitUseAdaptation/Precedence.php @@ -4,18 +4,17 @@ use PhpParser\Node; -class Precedence extends Node\Stmt\TraitUseAdaptation -{ +class Precedence extends Node\Stmt\TraitUseAdaptation { /** @var Node\Name[] Overwritten traits */ - public $insteadof; + public array $insteadof; /** * Constructs a trait use precedence adaptation node. * - * @param Node\Name $trait Trait name - * @param string|Node\Identifier $method Method name - * @param Node\Name[] $insteadof Overwritten traits - * @param array $attributes Additional attributes + * @param Node\Name $trait Trait name + * @param string|Node\Identifier $method Method name + * @param Node\Name[] $insteadof Overwritten traits + * @param array $attributes Additional attributes */ public function __construct(Node\Name $trait, $method, array $insteadof, array $attributes = []) { $this->attributes = $attributes; @@ -24,11 +23,11 @@ public function __construct(Node\Name $trait, $method, array $insteadof, array $ $this->insteadof = $insteadof; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['trait', 'method', 'insteadof']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_TraitUseAdaptation_Precedence'; } } diff --git a/lib/PhpParser/Node/Stmt/Trait_.php b/lib/PhpParser/Node/Stmt/Trait_.php index 0cec203ac7..5f2b33070a 100644 --- a/lib/PhpParser/Node/Stmt/Trait_.php +++ b/lib/PhpParser/Node/Stmt/Trait_.php @@ -4,16 +4,18 @@ use PhpParser\Node; -class Trait_ extends ClassLike -{ +class Trait_ extends ClassLike { /** * Constructs a trait node. * * @param string|Node\Identifier $name Name - * @param array $subNodes Array of the following optional subnodes: - * 'stmts' => array(): Statements - * 'attrGroups' => array(): PHP attribute groups - * @param array $attributes Additional attributes + * @param array{ + * stmts?: Node\Stmt[], + * attrGroups?: Node\AttributeGroup[], + * } $subNodes Array of the following optional subnodes: + * 'stmts' => array(): Statements + * 'attrGroups' => array(): PHP attribute groups + * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { $this->attributes = $attributes; @@ -22,11 +24,11 @@ public function __construct($name, array $subNodes = [], array $attributes = []) $this->attrGroups = $subNodes['attrGroups'] ?? []; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['attrGroups', 'name', 'stmts']; } - public function getType() : string { + public function getType(): string { return 'Stmt_Trait'; } } diff --git a/lib/PhpParser/Node/Stmt/TryCatch.php b/lib/PhpParser/Node/Stmt/TryCatch.php index 7fc158c570..6414c46c94 100644 --- a/lib/PhpParser/Node/Stmt/TryCatch.php +++ b/lib/PhpParser/Node/Stmt/TryCatch.php @@ -4,35 +4,34 @@ use PhpParser\Node; -class TryCatch extends Node\Stmt -{ +class TryCatch extends Node\Stmt { /** @var Node\Stmt[] Statements */ - public $stmts; + public array $stmts; /** @var Catch_[] Catches */ - public $catches; + public array $catches; /** @var null|Finally_ Optional finally node */ - public $finally; + public ?Finally_ $finally; /** * Constructs a try catch node. * - * @param Node\Stmt[] $stmts Statements - * @param Catch_[] $catches Catches - * @param null|Finally_ $finally Optional finally node - * @param array $attributes Additional attributes + * @param Node\Stmt[] $stmts Statements + * @param Catch_[] $catches Catches + * @param null|Finally_ $finally Optional finally node + * @param array $attributes Additional attributes */ - public function __construct(array $stmts, array $catches, Finally_ $finally = null, array $attributes = []) { + public function __construct(array $stmts, array $catches, ?Finally_ $finally = null, array $attributes = []) { $this->attributes = $attributes; $this->stmts = $stmts; $this->catches = $catches; $this->finally = $finally; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['stmts', 'catches', 'finally']; } - public function getType() : string { + public function getType(): string { return 'Stmt_TryCatch'; } } diff --git a/lib/PhpParser/Node/Stmt/Unset_.php b/lib/PhpParser/Node/Stmt/Unset_.php index 310e427aa2..c211beb0c5 100644 --- a/lib/PhpParser/Node/Stmt/Unset_.php +++ b/lib/PhpParser/Node/Stmt/Unset_.php @@ -4,27 +4,26 @@ use PhpParser\Node; -class Unset_ extends Node\Stmt -{ +class Unset_ extends Node\Stmt { /** @var Node\Expr[] Variables to unset */ - public $vars; + public array $vars; /** * Constructs an unset node. * - * @param Node\Expr[] $vars Variables to unset - * @param array $attributes Additional attributes + * @param Node\Expr[] $vars Variables to unset + * @param array $attributes Additional attributes */ public function __construct(array $vars, array $attributes = []) { $this->attributes = $attributes; $this->vars = $vars; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['vars']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Unset'; } } diff --git a/lib/PhpParser/Node/Stmt/UseUse.php b/lib/PhpParser/Node/Stmt/UseUse.php index 32bd7847da..b14fbd6ea1 100644 --- a/lib/PhpParser/Node/Stmt/UseUse.php +++ b/lib/PhpParser/Node/Stmt/UseUse.php @@ -2,51 +2,12 @@ namespace PhpParser\Node\Stmt; -use PhpParser\Node; -use PhpParser\Node\Identifier; +use PhpParser\Node\UseItem; -class UseUse extends Node\Stmt -{ - /** @var int One of the Stmt\Use_::TYPE_* constants. Will only differ from TYPE_UNKNOWN for mixed group uses */ - public $type; - /** @var Node\Name Namespace, class, function or constant to alias */ - public $name; - /** @var Identifier|null Alias */ - public $alias; +require __DIR__ . '/../UseItem.php'; - /** - * Constructs an alias (use) node. - * - * @param Node\Name $name Namespace/Class to alias - * @param null|string|Identifier $alias Alias - * @param int $type Type of the use element (for mixed group use only) - * @param array $attributes Additional attributes - */ - public function __construct(Node\Name $name, $alias = null, int $type = Use_::TYPE_UNKNOWN, array $attributes = []) { - $this->attributes = $attributes; - $this->type = $type; - $this->name = $name; - $this->alias = \is_string($alias) ? new Identifier($alias) : $alias; - } - - public function getSubNodeNames() : array { - return ['type', 'name', 'alias']; - } - - /** - * Get alias. If not explicitly given this is the last component of the used name. - * - * @return Identifier - */ - public function getAlias() : Identifier { - if (null !== $this->alias) { - return $this->alias; - } - - return new Identifier($this->name->getLast()); - } - - public function getType() : string { - return 'Stmt_UseUse'; +if (false) { + // For classmap-authoritative support. + class UseUse extends UseItem { } } diff --git a/lib/PhpParser/Node/Stmt/Use_.php b/lib/PhpParser/Node/Stmt/Use_.php index 8753da313d..5b2d864832 100644 --- a/lib/PhpParser/Node/Stmt/Use_.php +++ b/lib/PhpParser/Node/Stmt/Use_.php @@ -3,33 +3,33 @@ namespace PhpParser\Node\Stmt; use PhpParser\Node\Stmt; +use PhpParser\Node\UseItem; -class Use_ extends Stmt -{ +class Use_ extends Stmt { /** * Unknown type. Both Stmt\Use_ / Stmt\GroupUse and Stmt\UseUse have a $type property, one of them will always be * TYPE_UNKNOWN while the other has one of the three other possible types. For normal use statements the type on the * Stmt\UseUse is unknown. It's only the other way around for mixed group use declarations. */ - const TYPE_UNKNOWN = 0; + public const TYPE_UNKNOWN = 0; /** Class or namespace import */ - const TYPE_NORMAL = 1; + public const TYPE_NORMAL = 1; /** Function import */ - const TYPE_FUNCTION = 2; + public const TYPE_FUNCTION = 2; /** Constant import */ - const TYPE_CONSTANT = 3; + public const TYPE_CONSTANT = 3; - /** @var int Type of alias */ - public $type; - /** @var UseUse[] Aliases */ - public $uses; + /** @var self::TYPE_* Type of alias */ + public int $type; + /** @var UseItem[] Aliases */ + public array $uses; /** * Constructs an alias (use) list node. * - * @param UseUse[] $uses Aliases - * @param int $type Type of alias - * @param array $attributes Additional attributes + * @param UseItem[] $uses Aliases + * @param Stmt\Use_::TYPE_* $type Type of alias + * @param array $attributes Additional attributes */ public function __construct(array $uses, int $type = self::TYPE_NORMAL, array $attributes = []) { $this->attributes = $attributes; @@ -37,11 +37,11 @@ public function __construct(array $uses, int $type = self::TYPE_NORMAL, array $a $this->uses = $uses; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['type', 'uses']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_Use'; } } diff --git a/lib/PhpParser/Node/Stmt/While_.php b/lib/PhpParser/Node/Stmt/While_.php index f41034f8c2..2f7aed2343 100644 --- a/lib/PhpParser/Node/Stmt/While_.php +++ b/lib/PhpParser/Node/Stmt/While_.php @@ -4,19 +4,18 @@ use PhpParser\Node; -class While_ extends Node\Stmt -{ +class While_ extends Node\Stmt { /** @var Node\Expr Condition */ - public $cond; + public Node\Expr $cond; /** @var Node\Stmt[] Statements */ - public $stmts; + public array $stmts; /** * Constructs a while node. * - * @param Node\Expr $cond Condition - * @param Node\Stmt[] $stmts Statements - * @param array $attributes Additional attributes + * @param Node\Expr $cond Condition + * @param Node\Stmt[] $stmts Statements + * @param array $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $stmts = [], array $attributes = []) { $this->attributes = $attributes; @@ -24,11 +23,11 @@ public function __construct(Node\Expr $cond, array $stmts = [], array $attribute $this->stmts = $stmts; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['cond', 'stmts']; } - - public function getType() : string { + + public function getType(): string { return 'Stmt_While'; } } diff --git a/lib/PhpParser/Node/UnionType.php b/lib/PhpParser/Node/UnionType.php index c8f45235d6..bad88d2b8b 100644 --- a/lib/PhpParser/Node/UnionType.php +++ b/lib/PhpParser/Node/UnionType.php @@ -2,29 +2,26 @@ namespace PhpParser\Node; -use PhpParser\NodeAbstract; - -class UnionType extends NodeAbstract -{ - /** @var (Identifier|Name)[] Types */ - public $types; +class UnionType extends ComplexType { + /** @var (Identifier|Name|IntersectionType)[] Types */ + public array $types; /** * Constructs a union type. * - * @param (Identifier|Name)[] $types Types - * @param array $attributes Additional attributes + * @param (Identifier|Name|IntersectionType)[] $types Types + * @param array $attributes Additional attributes */ public function __construct(array $types, array $attributes = []) { $this->attributes = $attributes; $this->types = $types; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['types']; } - - public function getType() : string { + + public function getType(): string { return 'UnionType'; } } diff --git a/lib/PhpParser/Node/UseItem.php b/lib/PhpParser/Node/UseItem.php new file mode 100644 index 0000000000..a7d9fc447c --- /dev/null +++ b/lib/PhpParser/Node/UseItem.php @@ -0,0 +1,55 @@ + $attributes Additional attributes + */ + public function __construct(Node\Name $name, $alias = null, int $type = Use_::TYPE_UNKNOWN, array $attributes = []) { + $this->attributes = $attributes; + $this->type = $type; + $this->name = $name; + $this->alias = \is_string($alias) ? new Identifier($alias) : $alias; + } + + public function getSubNodeNames(): array { + return ['type', 'name', 'alias']; + } + + /** + * Get alias. If not explicitly given this is the last component of the used name. + */ + public function getAlias(): Identifier { + if (null !== $this->alias) { + return $this->alias; + } + + return new Identifier($this->name->getLast()); + } + + public function getType(): string { + return 'UseItem'; + } +} + +// @deprecated compatibility alias +class_alias(UseItem::class, Stmt\UseUse::class); diff --git a/lib/PhpParser/Node/VarLikeIdentifier.php b/lib/PhpParser/Node/VarLikeIdentifier.php index a30807a6d5..9baa6fe0bb 100644 --- a/lib/PhpParser/Node/VarLikeIdentifier.php +++ b/lib/PhpParser/Node/VarLikeIdentifier.php @@ -9,9 +9,8 @@ * Examples: Names in property declarations are formatted as variables. Names in static property * lookups are also formatted as variables. */ -class VarLikeIdentifier extends Identifier -{ - public function getType() : string { +class VarLikeIdentifier extends Identifier { + public function getType(): string { return 'VarLikeIdentifier'; } } diff --git a/lib/PhpParser/Node/VariadicPlaceholder.php b/lib/PhpParser/Node/VariadicPlaceholder.php new file mode 100644 index 0000000000..48c4f338c0 --- /dev/null +++ b/lib/PhpParser/Node/VariadicPlaceholder.php @@ -0,0 +1,27 @@ + $attributes Additional attributes + */ + public function __construct(array $attributes = []) { + $this->attributes = $attributes; + } + + public function getType(): string { + return 'VariadicPlaceholder'; + } + + public function getSubNodeNames(): array { + return []; + } +} diff --git a/lib/PhpParser/NodeAbstract.php b/lib/PhpParser/NodeAbstract.php index 04514da116..a6a50aea0f 100644 --- a/lib/PhpParser/NodeAbstract.php +++ b/lib/PhpParser/NodeAbstract.php @@ -2,14 +2,14 @@ namespace PhpParser; -abstract class NodeAbstract implements Node, \JsonSerializable -{ - protected $attributes; +abstract class NodeAbstract implements Node, \JsonSerializable { + /** @var array Attributes */ + protected array $attributes; /** * Creates a Node. * - * @param array $attributes Array of attributes + * @param array $attributes Array of attributes */ public function __construct(array $attributes = []) { $this->attributes = $attributes; @@ -19,8 +19,9 @@ public function __construct(array $attributes = []) { * Gets line the node started in (alias of getStartLine). * * @return int Start line (or -1 if not available) + * @phpstan-return -1|positive-int */ - public function getLine() : int { + public function getLine(): int { return $this->attributes['startLine'] ?? -1; } @@ -30,8 +31,9 @@ public function getLine() : int { * Requires the 'startLine' attribute to be enabled in the lexer (enabled by default). * * @return int Start line (or -1 if not available) + * @phpstan-return -1|positive-int */ - public function getStartLine() : int { + public function getStartLine(): int { return $this->attributes['startLine'] ?? -1; } @@ -41,8 +43,9 @@ public function getStartLine() : int { * Requires the 'endLine' attribute to be enabled in the lexer (enabled by default). * * @return int End line (or -1 if not available) + * @phpstan-return -1|positive-int */ - public function getEndLine() : int { + public function getEndLine(): int { return $this->attributes['endLine'] ?? -1; } @@ -55,7 +58,7 @@ public function getEndLine() : int { * * @return int Token start position (or -1 if not available) */ - public function getStartTokenPos() : int { + public function getStartTokenPos(): int { return $this->attributes['startTokenPos'] ?? -1; } @@ -68,7 +71,7 @@ public function getStartTokenPos() : int { * * @return int Token end position (or -1 if not available) */ - public function getEndTokenPos() : int { + public function getEndTokenPos(): int { return $this->attributes['endTokenPos'] ?? -1; } @@ -79,7 +82,7 @@ public function getEndTokenPos() : int { * * @return int File start position (or -1 if not available) */ - public function getStartFilePos() : int { + public function getStartFilePos(): int { return $this->attributes['startFilePos'] ?? -1; } @@ -90,7 +93,7 @@ public function getStartFilePos() : int { * * @return int File end position (or -1 if not available) */ - public function getEndFilePos() : int { + public function getEndFilePos(): int { return $this->attributes['endFilePos'] ?? -1; } @@ -101,7 +104,7 @@ public function getEndFilePos() : int { * * @return Comment[] */ - public function getComments() : array { + public function getComments(): array { return $this->attributes['comments'] ?? []; } @@ -110,7 +113,7 @@ public function getComments() : array { * * @return null|Comment\Doc Doc comment object or null */ - public function getDocComment() { + public function getDocComment(): ?Comment\Doc { $comments = $this->getComments(); for ($i = count($comments) - 1; $i >= 0; $i--) { $comment = $comments[$i]; @@ -129,7 +132,7 @@ public function getDocComment() { * * @param Comment\Doc $docComment Doc comment to set */ - public function setDocComment(Comment\Doc $docComment) { + public function setDocComment(Comment\Doc $docComment): void { $comments = $this->getComments(); for ($i = count($comments) - 1; $i >= 0; $i--) { if ($comments[$i] instanceof Comment\Doc) { @@ -145,11 +148,11 @@ public function setDocComment(Comment\Doc $docComment) { $this->setAttribute('comments', $comments); } - public function setAttribute(string $key, $value) { + public function setAttribute(string $key, $value): void { $this->attributes[$key] = $value; } - public function hasAttribute(string $key) : bool { + public function hasAttribute(string $key): bool { return array_key_exists($key, $this->attributes); } @@ -161,18 +164,18 @@ public function getAttribute(string $key, $default = null) { return $default; } - public function getAttributes() : array { + public function getAttributes(): array { return $this->attributes; } - public function setAttributes(array $attributes) { + public function setAttributes(array $attributes): void { $this->attributes = $attributes; } /** - * @return array + * @return array */ - public function jsonSerialize() : array { + public function jsonSerialize(): array { return ['nodeType' => $this->getType()] + get_object_vars($this); } } diff --git a/lib/PhpParser/NodeDumper.php b/lib/PhpParser/NodeDumper.php index 197ebc144c..7d62d038dc 100644 --- a/lib/PhpParser/NodeDumper.php +++ b/lib/PhpParser/NodeDumper.php @@ -2,17 +2,33 @@ namespace PhpParser; +use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\Include_; -use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Expr\List_; +use PhpParser\Node\Scalar\Int_; +use PhpParser\Node\Scalar\InterpolatedString; +use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\GroupUse; use PhpParser\Node\Stmt\Use_; -use PhpParser\Node\Stmt\UseUse; +use PhpParser\Node\UseItem; -class NodeDumper -{ - private $dumpComments; - private $dumpPositions; - private $code; +class NodeDumper { + private bool $dumpComments; + private bool $dumpPositions; + private bool $dumpOtherAttributes; + private ?string $code; + private string $res; + private string $nl; + + private const IGNORE_ATTRIBUTES = [ + 'comments' => true, + 'startLine' => true, + 'endLine' => true, + 'startFilePos' => true, + 'endFilePos' => true, + 'startTokenPos' => true, + 'endTokenPos' => true, + ]; /** * Constructs a NodeDumper. @@ -21,147 +37,227 @@ class NodeDumper * * bool dumpComments: Whether comments should be dumped. * * bool dumpPositions: Whether line/offset information should be dumped. To dump offset * information, the code needs to be passed to dump(). + * * bool dumpOtherAttributes: Whether non-comment, non-position attributes should be dumped. * * @param array $options Options (see description) */ public function __construct(array $options = []) { $this->dumpComments = !empty($options['dumpComments']); $this->dumpPositions = !empty($options['dumpPositions']); + $this->dumpOtherAttributes = !empty($options['dumpOtherAttributes']); } /** * Dumps a node or array. * - * @param array|Node $node Node or array to dump + * @param array|Node $node Node or array to dump * @param string|null $code Code corresponding to dumped AST. This only needs to be passed if * the dumpPositions option is enabled and the dumping of node offsets * is desired. * * @return string Dumped value */ - public function dump($node, string $code = null) : string { + public function dump($node, ?string $code = null): string { $this->code = $code; - return $this->dumpRecursive($node); + $this->res = ''; + $this->nl = "\n"; + $this->dumpRecursive($node, false); + return $this->res; } - protected function dumpRecursive($node) { + /** @param mixed $node */ + protected function dumpRecursive($node, bool $indent = true): void { + if ($indent) { + $this->nl .= " "; + } if ($node instanceof Node) { - $r = $node->getType(); + $this->res .= $node->getType(); if ($this->dumpPositions && null !== $p = $this->dumpPosition($node)) { - $r .= $p; + $this->res .= $p; } - $r .= '('; + $this->res .= '('; foreach ($node->getSubNodeNames() as $key) { - $r .= "\n " . $key . ': '; + $this->res .= "$this->nl " . $key . ': '; $value = $node->$key; - if (null === $value) { - $r .= 'null'; - } elseif (false === $value) { - $r .= 'false'; - } elseif (true === $value) { - $r .= 'true'; - } elseif (is_scalar($value)) { + if (\is_int($value)) { if ('flags' === $key || 'newModifier' === $key) { - $r .= $this->dumpFlags($value); - } elseif ('type' === $key && $node instanceof Include_) { - $r .= $this->dumpIncludeType($value); - } elseif ('type' === $key - && ($node instanceof Use_ || $node instanceof UseUse || $node instanceof GroupUse)) { - $r .= $this->dumpUseType($value); - } else { - $r .= $value; + $this->res .= $this->dumpFlags($value); + continue; + } + if ('type' === $key && $node instanceof Include_) { + $this->res .= $this->dumpIncludeType($value); + continue; + } + if ('type' === $key + && ($node instanceof Use_ || $node instanceof UseItem || $node instanceof GroupUse)) { + $this->res .= $this->dumpUseType($value); + continue; } - } else { - $r .= str_replace("\n", "\n ", $this->dumpRecursive($value)); } + $this->dumpRecursive($value); } if ($this->dumpComments && $comments = $node->getComments()) { - $r .= "\n comments: " . str_replace("\n", "\n ", $this->dumpRecursive($comments)); + $this->res .= "$this->nl comments: "; + $this->dumpRecursive($comments); } - } elseif (is_array($node)) { - $r = 'array('; - foreach ($node as $key => $value) { - $r .= "\n " . $key . ': '; - - if (null === $value) { - $r .= 'null'; - } elseif (false === $value) { - $r .= 'false'; - } elseif (true === $value) { - $r .= 'true'; - } elseif (is_scalar($value)) { - $r .= $value; - } else { - $r .= str_replace("\n", "\n ", $this->dumpRecursive($value)); + if ($this->dumpOtherAttributes) { + foreach ($node->getAttributes() as $key => $value) { + if (isset(self::IGNORE_ATTRIBUTES[$key])) { + continue; + } + + $this->res .= "$this->nl $key: "; + if (\is_int($value)) { + if ('kind' === $key) { + if ($node instanceof Int_) { + $this->res .= $this->dumpIntKind($value); + continue; + } + if ($node instanceof String_ || $node instanceof InterpolatedString) { + $this->res .= $this->dumpStringKind($value); + continue; + } + if ($node instanceof Array_) { + $this->res .= $this->dumpArrayKind($value); + continue; + } + if ($node instanceof List_) { + $this->res .= $this->dumpListKind($value); + continue; + } + } + } + $this->dumpRecursive($value); } } + $this->res .= "$this->nl)"; + } elseif (\is_array($node)) { + $this->res .= 'array('; + foreach ($node as $key => $value) { + $this->res .= "$this->nl " . $key . ': '; + $this->dumpRecursive($value); + } + $this->res .= "$this->nl)"; } elseif ($node instanceof Comment) { - return $node->getReformattedText(); + $this->res .= \str_replace("\n", $this->nl, $node->getReformattedText()); + } elseif (\is_string($node)) { + $this->res .= \str_replace("\n", $this->nl, $node); + } elseif (\is_int($node) || \is_float($node)) { + $this->res .= $node; + } elseif (null === $node) { + $this->res .= 'null'; + } elseif (false === $node) { + $this->res .= 'false'; + } elseif (true === $node) { + $this->res .= 'true'; } else { throw new \InvalidArgumentException('Can only dump nodes and arrays.'); } - - return $r . "\n)"; + if ($indent) { + $this->nl = \substr($this->nl, 0, -4); + } } - protected function dumpFlags($flags) { + protected function dumpFlags(int $flags): string { $strs = []; - if ($flags & Class_::MODIFIER_PUBLIC) { - $strs[] = 'MODIFIER_PUBLIC'; + if ($flags & Modifiers::PUBLIC) { + $strs[] = 'PUBLIC'; + } + if ($flags & Modifiers::PROTECTED) { + $strs[] = 'PROTECTED'; + } + if ($flags & Modifiers::PRIVATE) { + $strs[] = 'PRIVATE'; + } + if ($flags & Modifiers::ABSTRACT) { + $strs[] = 'ABSTRACT'; } - if ($flags & Class_::MODIFIER_PROTECTED) { - $strs[] = 'MODIFIER_PROTECTED'; + if ($flags & Modifiers::STATIC) { + $strs[] = 'STATIC'; } - if ($flags & Class_::MODIFIER_PRIVATE) { - $strs[] = 'MODIFIER_PRIVATE'; + if ($flags & Modifiers::FINAL) { + $strs[] = 'FINAL'; } - if ($flags & Class_::MODIFIER_ABSTRACT) { - $strs[] = 'MODIFIER_ABSTRACT'; + if ($flags & Modifiers::READONLY) { + $strs[] = 'READONLY'; } - if ($flags & Class_::MODIFIER_STATIC) { - $strs[] = 'MODIFIER_STATIC'; + if ($flags & Modifiers::PUBLIC_SET) { + $strs[] = 'PUBLIC_SET'; } - if ($flags & Class_::MODIFIER_FINAL) { - $strs[] = 'MODIFIER_FINAL'; + if ($flags & Modifiers::PROTECTED_SET) { + $strs[] = 'PROTECTED_SET'; + } + if ($flags & Modifiers::PRIVATE_SET) { + $strs[] = 'PRIVATE_SET'; } if ($strs) { return implode(' | ', $strs) . ' (' . $flags . ')'; } else { - return $flags; + return (string) $flags; + } + } + + /** @param array $map */ + private function dumpEnum(int $value, array $map): string { + if (!isset($map[$value])) { + return (string) $value; } + return $map[$value] . ' (' . $value . ')'; } - protected function dumpIncludeType($type) { - $map = [ + private function dumpIncludeType(int $type): string { + return $this->dumpEnum($type, [ Include_::TYPE_INCLUDE => 'TYPE_INCLUDE', Include_::TYPE_INCLUDE_ONCE => 'TYPE_INCLUDE_ONCE', Include_::TYPE_REQUIRE => 'TYPE_REQUIRE', Include_::TYPE_REQUIRE_ONCE => 'TYPE_REQUIRE_ONCE', - ]; - - if (!isset($map[$type])) { - return $type; - } - return $map[$type] . ' (' . $type . ')'; + ]); } - protected function dumpUseType($type) { - $map = [ + private function dumpUseType(int $type): string { + return $this->dumpEnum($type, [ Use_::TYPE_UNKNOWN => 'TYPE_UNKNOWN', Use_::TYPE_NORMAL => 'TYPE_NORMAL', Use_::TYPE_FUNCTION => 'TYPE_FUNCTION', Use_::TYPE_CONSTANT => 'TYPE_CONSTANT', - ]; + ]); + } - if (!isset($map[$type])) { - return $type; - } - return $map[$type] . ' (' . $type . ')'; + private function dumpIntKind(int $kind): string { + return $this->dumpEnum($kind, [ + Int_::KIND_BIN => 'KIND_BIN', + Int_::KIND_OCT => 'KIND_OCT', + Int_::KIND_DEC => 'KIND_DEC', + Int_::KIND_HEX => 'KIND_HEX', + ]); + } + + private function dumpStringKind(int $kind): string { + return $this->dumpEnum($kind, [ + String_::KIND_SINGLE_QUOTED => 'KIND_SINGLE_QUOTED', + String_::KIND_DOUBLE_QUOTED => 'KIND_DOUBLE_QUOTED', + String_::KIND_HEREDOC => 'KIND_HEREDOC', + String_::KIND_NOWDOC => 'KIND_NOWDOC', + ]); + } + + private function dumpArrayKind(int $kind): string { + return $this->dumpEnum($kind, [ + Array_::KIND_LONG => 'KIND_LONG', + Array_::KIND_SHORT => 'KIND_SHORT', + ]); + } + + private function dumpListKind(int $kind): string { + return $this->dumpEnum($kind, [ + List_::KIND_LIST => 'KIND_LIST', + List_::KIND_ARRAY => 'KIND_ARRAY', + ]); } /** @@ -171,7 +267,7 @@ protected function dumpUseType($type) { * * @return string|null Dump of position, or null if position information not available */ - protected function dumpPosition(Node $node) { + protected function dumpPosition(Node $node): ?string { if (!$node->hasAttribute('startLine') || !$node->hasAttribute('endLine')) { return null; } @@ -188,7 +284,7 @@ protected function dumpPosition(Node $node) { } // Copied from Error class - private function toColumn($code, $pos) { + private function toColumn(string $code, int $pos): int { if ($pos > strlen($code)) { throw new \RuntimeException('Invalid position information'); } diff --git a/lib/PhpParser/NodeFinder.php b/lib/PhpParser/NodeFinder.php index 2e7cfdad4d..96c8452633 100644 --- a/lib/PhpParser/NodeFinder.php +++ b/lib/PhpParser/NodeFinder.php @@ -5,25 +5,27 @@ use PhpParser\NodeVisitor\FindingVisitor; use PhpParser\NodeVisitor\FirstFindingVisitor; -class NodeFinder -{ +class NodeFinder { /** * Find all nodes satisfying a filter callback. * - * @param Node|Node[] $nodes Single node or array of nodes to search in - * @param callable $filter Filter callback: function(Node $node) : bool + * @param Node|Node[] $nodes Single node or array of nodes to search in + * @param callable $filter Filter callback: function(Node $node) : bool * * @return Node[] Found nodes satisfying the filter callback */ - public function find($nodes, callable $filter) : array { + public function find($nodes, callable $filter): array { + if ($nodes === []) { + return []; + } + if (!is_array($nodes)) { $nodes = [$nodes]; } $visitor = new FindingVisitor($filter); - $traverser = new NodeTraverser; - $traverser->addVisitor($visitor); + $traverser = new NodeTraverser($visitor); $traverser->traverse($nodes); return $visitor->getFoundNodes(); @@ -31,13 +33,15 @@ public function find($nodes, callable $filter) : array { /** * Find all nodes that are instances of a certain class. + + * @template TNode as Node * * @param Node|Node[] $nodes Single node or array of nodes to search in - * @param string $class Class name + * @param class-string $class Class name * - * @return Node[] Found nodes (all instances of $class) + * @return TNode[] Found nodes (all instances of $class) */ - public function findInstanceOf($nodes, string $class) : array { + public function findInstanceOf($nodes, string $class): array { return $this->find($nodes, function ($node) use ($class) { return $node instanceof $class; }); @@ -46,20 +50,23 @@ public function findInstanceOf($nodes, string $class) : array { /** * Find first node satisfying a filter callback. * - * @param Node|Node[] $nodes Single node or array of nodes to search in - * @param callable $filter Filter callback: function(Node $node) : bool + * @param Node|Node[] $nodes Single node or array of nodes to search in + * @param callable $filter Filter callback: function(Node $node) : bool * * @return null|Node Found node (or null if none found) */ - public function findFirst($nodes, callable $filter) { + public function findFirst($nodes, callable $filter): ?Node { + if ($nodes === []) { + return null; + } + if (!is_array($nodes)) { $nodes = [$nodes]; } $visitor = new FirstFindingVisitor($filter); - $traverser = new NodeTraverser; - $traverser->addVisitor($visitor); + $traverser = new NodeTraverser($visitor); $traverser->traverse($nodes); return $visitor->getFoundNode(); @@ -68,12 +75,14 @@ public function findFirst($nodes, callable $filter) { /** * Find first node that is an instance of a certain class. * - * @param Node|Node[] $nodes Single node or array of nodes to search in - * @param string $class Class name + * @template TNode as Node + * + * @param Node|Node[] $nodes Single node or array of nodes to search in + * @param class-string $class Class name * - * @return null|Node Found node, which is an instance of $class (or null if none found) + * @return null|TNode Found node, which is an instance of $class (or null if none found) */ - public function findFirstInstanceOf($nodes, string $class) { + public function findFirstInstanceOf($nodes, string $class): ?Node { return $this->findFirst($nodes, function ($node) use ($class) { return $node instanceof $class; }); diff --git a/lib/PhpParser/NodeTraverser.php b/lib/PhpParser/NodeTraverser.php index 97d45bdaaa..bb3d6ddbfa 100644 --- a/lib/PhpParser/NodeTraverser.php +++ b/lib/PhpParser/NodeTraverser.php @@ -2,51 +2,40 @@ namespace PhpParser; -class NodeTraverser implements NodeTraverserInterface -{ +class NodeTraverser implements NodeTraverserInterface { /** - * If NodeVisitor::enterNode() returns DONT_TRAVERSE_CHILDREN, child nodes - * of the current node will not be traversed for any visitors. - * - * For subsequent visitors enterNode() will still be called on the current - * node and leaveNode() will also be invoked for the current node. + * @deprecated Use NodeVisitor::DONT_TRAVERSE_CHILDREN instead. */ - const DONT_TRAVERSE_CHILDREN = 1; + public const DONT_TRAVERSE_CHILDREN = NodeVisitor::DONT_TRAVERSE_CHILDREN; /** - * If NodeVisitor::enterNode() or NodeVisitor::leaveNode() returns - * STOP_TRAVERSAL, traversal is aborted. - * - * The afterTraverse() method will still be invoked. + * @deprecated Use NodeVisitor::STOP_TRAVERSAL instead. */ - const STOP_TRAVERSAL = 2; + public const STOP_TRAVERSAL = NodeVisitor::STOP_TRAVERSAL; /** - * If NodeVisitor::leaveNode() returns REMOVE_NODE for a node that occurs - * in an array, it will be removed from the array. - * - * For subsequent visitors leaveNode() will still be invoked for the - * removed node. + * @deprecated Use NodeVisitor::REMOVE_NODE instead. */ - const REMOVE_NODE = 3; + public const REMOVE_NODE = NodeVisitor::REMOVE_NODE; /** - * If NodeVisitor::enterNode() returns DONT_TRAVERSE_CURRENT_AND_CHILDREN, child nodes - * of the current node will not be traversed for any visitors. - * - * For subsequent visitors enterNode() will not be called as well. - * leaveNode() will be invoked for visitors that has enterNode() method invoked. + * @deprecated Use NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN instead. */ - const DONT_TRAVERSE_CURRENT_AND_CHILDREN = 4; + public const DONT_TRAVERSE_CURRENT_AND_CHILDREN = NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN; - /** @var NodeVisitor[] Visitors */ - protected $visitors = []; + /** @var list Visitors */ + protected array $visitors = []; /** @var bool Whether traversal should be stopped */ - protected $stopTraversal; + protected bool $stopTraversal; - public function __construct() { - // for BC + /** + * Create a traverser with the given visitors. + * + * @param NodeVisitor ...$visitors Node visitors + */ + public function __construct(NodeVisitor ...$visitors) { + $this->visitors = $visitors; } /** @@ -54,21 +43,17 @@ public function __construct() { * * @param NodeVisitor $visitor Visitor to add */ - public function addVisitor(NodeVisitor $visitor) { + public function addVisitor(NodeVisitor $visitor): void { $this->visitors[] = $visitor; } /** * Removes an added visitor. - * - * @param NodeVisitor $visitor */ - public function removeVisitor(NodeVisitor $visitor) { - foreach ($this->visitors as $index => $storedVisitor) { - if ($storedVisitor === $visitor) { - unset($this->visitors[$index]); - break; - } + public function removeVisitor(NodeVisitor $visitor): void { + $index = array_search($visitor, $this->visitors); + if ($index !== false) { + array_splice($this->visitors, $index, 1, []); } } @@ -79,7 +64,7 @@ public function removeVisitor(NodeVisitor $visitor) { * * @return Node[] Traversed array of nodes */ - public function traverse(array $nodes) : array { + public function traverse(array $nodes): array { $this->stopTraversal = false; foreach ($this->visitors as $visitor) { @@ -90,7 +75,8 @@ public function traverse(array $nodes) : array { $nodes = $this->traverseArray($nodes); - foreach ($this->visitors as $visitor) { + for ($i = \count($this->visitors) - 1; $i >= 0; --$i) { + $visitor = $this->visitors[$i]; if (null !== $return = $visitor->afterTraverse($nodes)) { $nodes = $return; } @@ -103,82 +89,86 @@ public function traverse(array $nodes) : array { * Recursively traverse a node. * * @param Node $node Node to traverse. - * - * @return Node Result of traversal (may be original node or new one) */ - protected function traverseNode(Node $node) : Node { + protected function traverseNode(Node $node): void { foreach ($node->getSubNodeNames() as $name) { - $subNode =& $node->$name; + $subNode = $node->$name; if (\is_array($subNode)) { - $subNode = $this->traverseArray($subNode); + $node->$name = $this->traverseArray($subNode); if ($this->stopTraversal) { break; } - } elseif ($subNode instanceof Node) { - $traverseChildren = true; - $breakVisitorIndex = null; - - foreach ($this->visitors as $visitorIndex => $visitor) { - $return = $visitor->enterNode($subNode); - if (null !== $return) { - if ($return instanceof Node) { - $this->ensureReplacementReasonable($subNode, $return); - $subNode = $return; - } elseif (self::DONT_TRAVERSE_CHILDREN === $return) { - $traverseChildren = false; - } elseif (self::DONT_TRAVERSE_CURRENT_AND_CHILDREN === $return) { - $traverseChildren = false; - $breakVisitorIndex = $visitorIndex; - break; - } elseif (self::STOP_TRAVERSAL === $return) { - $this->stopTraversal = true; - break 2; - } else { - throw new \LogicException( - 'enterNode() returned invalid value of type ' . gettype($return) - ); - } - } - } - if ($traverseChildren) { - $subNode = $this->traverseNode($subNode); - if ($this->stopTraversal) { + continue; + } + + if (!$subNode instanceof Node) { + continue; + } + + $traverseChildren = true; + $visitorIndex = -1; + + foreach ($this->visitors as $visitorIndex => $visitor) { + $return = $visitor->enterNode($subNode); + if (null !== $return) { + if ($return instanceof Node) { + $this->ensureReplacementReasonable($subNode, $return); + $subNode = $node->$name = $return; + } elseif (NodeVisitor::DONT_TRAVERSE_CHILDREN === $return) { + $traverseChildren = false; + } elseif (NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN === $return) { + $traverseChildren = false; break; + } elseif (NodeVisitor::STOP_TRAVERSAL === $return) { + $this->stopTraversal = true; + break 2; + } elseif (NodeVisitor::REPLACE_WITH_NULL === $return) { + $node->$name = null; + continue 2; + } else { + throw new \LogicException( + 'enterNode() returned invalid value of type ' . gettype($return) + ); } } + } - foreach ($this->visitors as $visitorIndex => $visitor) { - $return = $visitor->leaveNode($subNode); - - if (null !== $return) { - if ($return instanceof Node) { - $this->ensureReplacementReasonable($subNode, $return); - $subNode = $return; - } elseif (self::STOP_TRAVERSAL === $return) { - $this->stopTraversal = true; - break 2; - } elseif (\is_array($return)) { - throw new \LogicException( - 'leaveNode() may only return an array ' . - 'if the parent structure is an array' - ); - } else { - throw new \LogicException( - 'leaveNode() returned invalid value of type ' . gettype($return) - ); - } - } + if ($traverseChildren) { + $this->traverseNode($subNode); + if ($this->stopTraversal) { + break; + } + } - if ($breakVisitorIndex === $visitorIndex) { + for (; $visitorIndex >= 0; --$visitorIndex) { + $visitor = $this->visitors[$visitorIndex]; + $return = $visitor->leaveNode($subNode); + + if (null !== $return) { + if ($return instanceof Node) { + $this->ensureReplacementReasonable($subNode, $return); + $subNode = $node->$name = $return; + } elseif (NodeVisitor::STOP_TRAVERSAL === $return) { + $this->stopTraversal = true; + break 2; + } elseif (NodeVisitor::REPLACE_WITH_NULL === $return) { + $node->$name = null; break; + } elseif (\is_array($return)) { + throw new \LogicException( + 'leaveNode() may only return an array ' . + 'if the parent structure is an array' + ); + } else { + throw new \LogicException( + 'leaveNode() returned invalid value of type ' . gettype($return) + ); } } } } - - return $node; } /** @@ -188,78 +178,84 @@ protected function traverseNode(Node $node) : Node { * * @return array Result of traversal (may be original array or changed one) */ - protected function traverseArray(array $nodes) : array { + protected function traverseArray(array $nodes): array { $doNodes = []; - foreach ($nodes as $i => &$node) { - if ($node instanceof Node) { - $traverseChildren = true; - $breakVisitorIndex = null; - - foreach ($this->visitors as $visitorIndex => $visitor) { - $return = $visitor->enterNode($node); - if (null !== $return) { - if ($return instanceof Node) { - $this->ensureReplacementReasonable($node, $return); - $node = $return; - } elseif (self::DONT_TRAVERSE_CHILDREN === $return) { - $traverseChildren = false; - } elseif (self::DONT_TRAVERSE_CURRENT_AND_CHILDREN === $return) { - $traverseChildren = false; - $breakVisitorIndex = $visitorIndex; - break; - } elseif (self::STOP_TRAVERSAL === $return) { - $this->stopTraversal = true; - break 2; - } else { - throw new \LogicException( - 'enterNode() returned invalid value of type ' . gettype($return) - ); - } - } + foreach ($nodes as $i => $node) { + if (!$node instanceof Node) { + if (\is_array($node)) { + throw new \LogicException('Invalid node structure: Contains nested arrays'); } + continue; + } - if ($traverseChildren) { - $node = $this->traverseNode($node); - if ($this->stopTraversal) { + $traverseChildren = true; + $visitorIndex = -1; + + foreach ($this->visitors as $visitorIndex => $visitor) { + $return = $visitor->enterNode($node); + if (null !== $return) { + if ($return instanceof Node) { + $this->ensureReplacementReasonable($node, $return); + $nodes[$i] = $node = $return; + } elseif (\is_array($return)) { + $doNodes[] = [$i, $return]; + continue 2; + } elseif (NodeVisitor::REMOVE_NODE === $return) { + $doNodes[] = [$i, []]; + continue 2; + } elseif (NodeVisitor::DONT_TRAVERSE_CHILDREN === $return) { + $traverseChildren = false; + } elseif (NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN === $return) { + $traverseChildren = false; break; + } elseif (NodeVisitor::STOP_TRAVERSAL === $return) { + $this->stopTraversal = true; + break 2; + } elseif (NodeVisitor::REPLACE_WITH_NULL === $return) { + throw new \LogicException( + 'REPLACE_WITH_NULL can not be used if the parent structure is an array'); + } else { + throw new \LogicException( + 'enterNode() returned invalid value of type ' . gettype($return) + ); } } + } - foreach ($this->visitors as $visitorIndex => $visitor) { - $return = $visitor->leaveNode($node); - - if (null !== $return) { - if ($return instanceof Node) { - $this->ensureReplacementReasonable($node, $return); - $node = $return; - } elseif (\is_array($return)) { - $doNodes[] = [$i, $return]; - break; - } elseif (self::REMOVE_NODE === $return) { - $doNodes[] = [$i, []]; - break; - } elseif (self::STOP_TRAVERSAL === $return) { - $this->stopTraversal = true; - break 2; - } elseif (false === $return) { - throw new \LogicException( - 'bool(false) return from leaveNode() no longer supported. ' . - 'Return NodeTraverser::REMOVE_NODE instead' - ); - } else { - throw new \LogicException( - 'leaveNode() returned invalid value of type ' . gettype($return) - ); - } - } + if ($traverseChildren) { + $this->traverseNode($node); + if ($this->stopTraversal) { + break; + } + } - if ($breakVisitorIndex === $visitorIndex) { + for (; $visitorIndex >= 0; --$visitorIndex) { + $visitor = $this->visitors[$visitorIndex]; + $return = $visitor->leaveNode($node); + + if (null !== $return) { + if ($return instanceof Node) { + $this->ensureReplacementReasonable($node, $return); + $nodes[$i] = $node = $return; + } elseif (\is_array($return)) { + $doNodes[] = [$i, $return]; + break; + } elseif (NodeVisitor::REMOVE_NODE === $return) { + $doNodes[] = [$i, []]; break; + } elseif (NodeVisitor::STOP_TRAVERSAL === $return) { + $this->stopTraversal = true; + break 2; + } elseif (NodeVisitor::REPLACE_WITH_NULL === $return) { + throw new \LogicException( + 'REPLACE_WITH_NULL can not be used if the parent structure is an array'); + } else { + throw new \LogicException( + 'leaveNode() returned invalid value of type ' . gettype($return) + ); } } - } elseif (\is_array($node)) { - throw new \LogicException('Invalid node structure: Contains nested arrays'); } } @@ -272,7 +268,7 @@ protected function traverseArray(array $nodes) : array { return $nodes; } - private function ensureReplacementReasonable($old, $new) { + private function ensureReplacementReasonable(Node $old, Node $new): void { if ($old instanceof Node\Stmt && $new instanceof Node\Expr) { throw new \LogicException( "Trying to replace statement ({$old->getType()}) " . diff --git a/lib/PhpParser/NodeTraverserInterface.php b/lib/PhpParser/NodeTraverserInterface.php index 77ff3d27f6..c3992b3dc4 100644 --- a/lib/PhpParser/NodeTraverserInterface.php +++ b/lib/PhpParser/NodeTraverserInterface.php @@ -2,21 +2,18 @@ namespace PhpParser; -interface NodeTraverserInterface -{ +interface NodeTraverserInterface { /** * Adds a visitor. * * @param NodeVisitor $visitor Visitor to add */ - public function addVisitor(NodeVisitor $visitor); + public function addVisitor(NodeVisitor $visitor): void; /** * Removes an added visitor. - * - * @param NodeVisitor $visitor */ - public function removeVisitor(NodeVisitor $visitor); + public function removeVisitor(NodeVisitor $visitor): void; /** * Traverses an array of nodes using the registered visitors. @@ -25,5 +22,5 @@ public function removeVisitor(NodeVisitor $visitor); * * @return Node[] Traversed array of nodes */ - public function traverse(array $nodes) : array; + public function traverse(array $nodes): array; } diff --git a/lib/PhpParser/NodeVisitor.php b/lib/PhpParser/NodeVisitor.php index f1f7f3e3e3..0ec4f7beb2 100644 --- a/lib/PhpParser/NodeVisitor.php +++ b/lib/PhpParser/NodeVisitor.php @@ -2,8 +2,49 @@ namespace PhpParser; -interface NodeVisitor -{ +interface NodeVisitor { + /** + * If NodeVisitor::enterNode() returns DONT_TRAVERSE_CHILDREN, child nodes + * of the current node will not be traversed for any visitors. + * + * For subsequent visitors enterNode() will still be called on the current + * node and leaveNode() will also be invoked for the current node. + */ + public const DONT_TRAVERSE_CHILDREN = 1; + + /** + * If NodeVisitor::enterNode() or NodeVisitor::leaveNode() returns + * STOP_TRAVERSAL, traversal is aborted. + * + * The afterTraverse() method will still be invoked. + */ + public const STOP_TRAVERSAL = 2; + + /** + * If NodeVisitor::leaveNode() returns REMOVE_NODE for a node that occurs + * in an array, it will be removed from the array. + * + * For subsequent visitors leaveNode() will still be invoked for the + * removed node. + */ + public const REMOVE_NODE = 3; + + /** + * If NodeVisitor::enterNode() returns DONT_TRAVERSE_CURRENT_AND_CHILDREN, child nodes + * of the current node will not be traversed for any visitors. + * + * For subsequent visitors enterNode() will not be called as well. + * leaveNode() will be invoked for visitors that has enterNode() method invoked. + */ + public const DONT_TRAVERSE_CURRENT_AND_CHILDREN = 4; + + /** + * If NodeVisitor::enterNode() or NodeVisitor::leaveNode() returns REPLACE_WITH_NULL, + * the node will be replaced with null. This is not a legal return value if the node is part + * of an array, rather than another node. + */ + public const REPLACE_WITH_NULL = 5; + /** * Called once before traversal. * @@ -23,16 +64,25 @@ public function beforeTraverse(array $nodes); * Return value semantics: * * null * => $node stays as-is - * * NodeTraverser::DONT_TRAVERSE_CHILDREN + * * array (of Nodes) + * => The return value is merged into the parent array (at the position of the $node) + * * NodeVisitor::REMOVE_NODE + * => $node is removed from the parent array + * * NodeVisitor::REPLACE_WITH_NULL + * => $node is replaced with null + * * NodeVisitor::DONT_TRAVERSE_CHILDREN * => Children of $node are not traversed. $node stays as-is - * * NodeTraverser::STOP_TRAVERSAL + * * NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN + * => Further visitors for the current node are skipped, and its children are not + * traversed. $node stays as-is. + * * NodeVisitor::STOP_TRAVERSAL * => Traversal is aborted. $node stays as-is * * otherwise * => $node is set to the return value * * @param Node $node Node * - * @return null|int|Node Replacement node (or special return value) + * @return null|int|Node|Node[] Replacement node (or special return value) */ public function enterNode(Node $node); @@ -42,9 +92,11 @@ public function enterNode(Node $node); * Return value semantics: * * null * => $node stays as-is - * * NodeTraverser::REMOVE_NODE + * * NodeVisitor::REMOVE_NODE * => $node is removed from the parent array - * * NodeTraverser::STOP_TRAVERSAL + * * NodeVisitor::REPLACE_WITH_NULL + * => $node is replaced with null + * * NodeVisitor::STOP_TRAVERSAL * => Traversal is aborted. $node stays as-is * * array (of Nodes) * => The return value is merged into the parent array (at the position of the $node) diff --git a/lib/PhpParser/NodeVisitor/CloningVisitor.php b/lib/PhpParser/NodeVisitor/CloningVisitor.php index a85fa493b0..cba924998a 100644 --- a/lib/PhpParser/NodeVisitor/CloningVisitor.php +++ b/lib/PhpParser/NodeVisitor/CloningVisitor.php @@ -10,8 +10,7 @@ * * This visitor is required to perform format-preserving pretty prints. */ -class CloningVisitor extends NodeVisitorAbstract -{ +class CloningVisitor extends NodeVisitorAbstract { public function enterNode(Node $origNode) { $node = clone $origNode; $node->setAttribute('origNode', $origNode); diff --git a/lib/PhpParser/NodeVisitor/CommentAnnotatingVisitor.php b/lib/PhpParser/NodeVisitor/CommentAnnotatingVisitor.php new file mode 100644 index 0000000000..5e2aed313f --- /dev/null +++ b/lib/PhpParser/NodeVisitor/CommentAnnotatingVisitor.php @@ -0,0 +1,82 @@ + Token positions of comments */ + private array $commentPositions = []; + + /** + * Create a comment annotation visitor. + * + * @param Token[] $tokens Token array + */ + public function __construct(array $tokens) { + $this->tokens = $tokens; + + // Collect positions of comments. We use this to avoid traversing parts of the AST where + // there are no comments. + foreach ($tokens as $i => $token) { + if ($token->id === \T_COMMENT || $token->id === \T_DOC_COMMENT) { + $this->commentPositions[] = $i; + } + } + } + + public function enterNode(Node $node) { + $nextCommentPos = current($this->commentPositions); + if ($nextCommentPos === false) { + // No more comments. + return self::STOP_TRAVERSAL; + } + + $oldPos = $this->pos; + $this->pos = $pos = $node->getStartTokenPos(); + if ($nextCommentPos > $oldPos && $nextCommentPos < $pos) { + $comments = []; + while (--$pos >= $oldPos) { + $token = $this->tokens[$pos]; + if ($token->id === \T_DOC_COMMENT) { + $comments[] = new Comment\Doc( + $token->text, $token->line, $token->pos, $pos, + $token->getEndLine(), $token->getEndPos() - 1, $pos); + continue; + } + if ($token->id === \T_COMMENT) { + $comments[] = new Comment( + $token->text, $token->line, $token->pos, $pos, + $token->getEndLine(), $token->getEndPos() - 1, $pos); + continue; + } + if ($token->id !== \T_WHITESPACE) { + break; + } + } + if (!empty($comments)) { + $node->setAttribute('comments', array_reverse($comments)); + } + + do { + $nextCommentPos = next($this->commentPositions); + } while ($nextCommentPos !== false && $nextCommentPos < $this->pos); + } + + $endPos = $node->getEndTokenPos(); + if ($nextCommentPos > $endPos) { + // Skip children if there are no comments located inside this node. + $this->pos = $endPos; + return self::DONT_TRAVERSE_CHILDREN; + } + + return null; + } +} diff --git a/lib/PhpParser/NodeVisitor/FindingVisitor.php b/lib/PhpParser/NodeVisitor/FindingVisitor.php index 9531edbce7..65a1bd3f1b 100644 --- a/lib/PhpParser/NodeVisitor/FindingVisitor.php +++ b/lib/PhpParser/NodeVisitor/FindingVisitor.php @@ -9,12 +9,11 @@ * This visitor can be used to find and collect all nodes satisfying some criterion determined by * a filter callback. */ -class FindingVisitor extends NodeVisitorAbstract -{ +class FindingVisitor extends NodeVisitorAbstract { /** @var callable Filter callback */ protected $filterCallback; - /** @var Node[] Found nodes */ - protected $foundNodes; + /** @var list Found nodes */ + protected array $foundNodes; public function __construct(callable $filterCallback) { $this->filterCallback = $filterCallback; @@ -25,13 +24,13 @@ public function __construct(callable $filterCallback) { * * Nodes are returned in pre-order. * - * @return Node[] Found nodes + * @return list Found nodes */ - public function getFoundNodes() : array { + public function getFoundNodes(): array { return $this->foundNodes; } - public function beforeTraverse(array $nodes) { + public function beforeTraverse(array $nodes): ?array { $this->foundNodes = []; return null; diff --git a/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php b/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php index 596a7d7fd5..05deed597a 100644 --- a/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php +++ b/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php @@ -3,19 +3,18 @@ namespace PhpParser\NodeVisitor; use PhpParser\Node; -use PhpParser\NodeTraverser; +use PhpParser\NodeVisitor; use PhpParser\NodeVisitorAbstract; /** * This visitor can be used to find the first node satisfying some criterion determined by * a filter callback. */ -class FirstFindingVisitor extends NodeVisitorAbstract -{ +class FirstFindingVisitor extends NodeVisitorAbstract { /** @var callable Filter callback */ protected $filterCallback; /** @var null|Node Found node */ - protected $foundNode; + protected ?Node $foundNode; public function __construct(callable $filterCallback) { $this->filterCallback = $filterCallback; @@ -28,11 +27,11 @@ public function __construct(callable $filterCallback) { * * @return null|Node Found node (or null if not found) */ - public function getFoundNode() { + public function getFoundNode(): ?Node { return $this->foundNode; } - public function beforeTraverse(array $nodes) { + public function beforeTraverse(array $nodes): ?array { $this->foundNode = null; return null; @@ -42,7 +41,7 @@ public function enterNode(Node $node) { $filterCallback = $this->filterCallback; if ($filterCallback($node)) { $this->foundNode = $node; - return NodeTraverser::STOP_TRAVERSAL; + return NodeVisitor::STOP_TRAVERSAL; } return null; diff --git a/lib/PhpParser/NodeVisitor/NameResolver.php b/lib/PhpParser/NodeVisitor/NameResolver.php index c55532a5ea..e0066f2d09 100644 --- a/lib/PhpParser/NodeVisitor/NameResolver.php +++ b/lib/PhpParser/NodeVisitor/NameResolver.php @@ -11,16 +11,15 @@ use PhpParser\Node\Stmt; use PhpParser\NodeVisitorAbstract; -class NameResolver extends NodeVisitorAbstract -{ +class NameResolver extends NodeVisitorAbstract { /** @var NameContext Naming context */ - protected $nameContext; + protected NameContext $nameContext; /** @var bool Whether to preserve original names */ - protected $preserveOriginalNames; + protected bool $preserveOriginalNames; /** @var bool Whether to replace resolved nodes in place, or to add resolvedNode attributes */ - protected $replaceNodes; + protected bool $replaceNodes; /** * Constructs a name resolution visitor. @@ -33,24 +32,22 @@ class NameResolver extends NodeVisitorAbstract * namespacedName attribute, as usual.) * * @param ErrorHandler|null $errorHandler Error handler - * @param array $options Options + * @param array{preserveOriginalNames?: bool, replaceNodes?: bool} $options Options */ - public function __construct(ErrorHandler $errorHandler = null, array $options = []) { - $this->nameContext = new NameContext($errorHandler ?? new ErrorHandler\Throwing); + public function __construct(?ErrorHandler $errorHandler = null, array $options = []) { + $this->nameContext = new NameContext($errorHandler ?? new ErrorHandler\Throwing()); $this->preserveOriginalNames = $options['preserveOriginalNames'] ?? false; $this->replaceNodes = $options['replaceNodes'] ?? true; } /** * Get name resolution context. - * - * @return NameContext */ - public function getNameContext() : NameContext { + public function getNameContext(): NameContext { return $this->nameContext; } - public function beforeTraverse(array $nodes) { + public function beforeTraverse(array $nodes): ?array { $this->nameContext->startNamespace(); return null; } @@ -78,12 +75,21 @@ public function enterNode(Node $node) { $this->resolveAttrGroups($node); if (null !== $node->name) { $this->addNamespacedName($node); + } else { + $node->namespacedName = null; } } elseif ($node instanceof Stmt\Interface_) { foreach ($node->extends as &$interface) { $interface = $this->resolveClassName($interface); } + $this->resolveAttrGroups($node); + $this->addNamespacedName($node); + } elseif ($node instanceof Stmt\Enum_) { + foreach ($node->implements as &$interface) { + $interface = $this->resolveClassName($interface); + } + $this->resolveAttrGroups($node); $this->addNamespacedName($node); } elseif ($node instanceof Stmt\Trait_) { @@ -104,11 +110,23 @@ public function enterNode(Node $node) { $node->type = $this->resolveType($node->type); } $this->resolveAttrGroups($node); + } elseif ($node instanceof Node\PropertyHook) { + foreach ($node->params as $param) { + $param->type = $this->resolveType($param->type); + $this->resolveAttrGroups($param); + } + $this->resolveAttrGroups($node); } elseif ($node instanceof Stmt\Const_) { foreach ($node->consts as $const) { $this->addNamespacedName($const); } - } else if ($node instanceof Stmt\ClassConst) { + $this->resolveAttrGroups($node); + } elseif ($node instanceof Stmt\ClassConst) { + if (null !== $node->type) { + $node->type = $this->resolveType($node->type); + } + $this->resolveAttrGroups($node); + } elseif ($node instanceof Stmt\EnumCase) { $this->resolveAttrGroups($node); } elseif ($node instanceof Expr\StaticCall || $node instanceof Expr\StaticPropertyFetch @@ -150,7 +168,8 @@ public function enterNode(Node $node) { return null; } - private function addAlias(Stmt\UseUse $use, $type, Name $prefix = null) { + /** @param Stmt\Use_::TYPE_* $type */ + private function addAlias(Node\UseItem $use, int $type, ?Name $prefix = null): void { // Add prefix for group uses $name = $prefix ? Name::concat($prefix, $use->name) : $use->name; // Type is determined either by individual element or whole use declaration @@ -161,8 +180,8 @@ private function addAlias(Stmt\UseUse $use, $type, Name $prefix = null) { ); } - /** @param Stmt\Function_|Stmt\ClassMethod|Expr\Closure $node */ - private function resolveSignature($node) { + /** @param Stmt\Function_|Stmt\ClassMethod|Expr\Closure|Expr\ArrowFunction $node */ + private function resolveSignature($node): void { foreach ($node->params as $param) { $param->type = $this->resolveType($param->type); $this->resolveAttrGroups($param); @@ -170,7 +189,12 @@ private function resolveSignature($node) { $node->returnType = $this->resolveType($node->returnType); } - private function resolveType($node) { + /** + * @template T of Node\Identifier|Name|Node\ComplexType|null + * @param T $node + * @return T + */ + private function resolveType(?Node $node): ?Node { if ($node instanceof Name) { return $this->resolveClassName($node); } @@ -178,7 +202,7 @@ private function resolveType($node) { $node->type = $this->resolveType($node->type); return $node; } - if ($node instanceof Node\UnionType) { + if ($node instanceof Node\UnionType || $node instanceof Node\IntersectionType) { foreach ($node->types as &$type) { $type = $this->resolveType($type); } @@ -191,11 +215,11 @@ private function resolveType($node) { * Resolve name, according to name resolver options. * * @param Name $name Function or constant name to resolve - * @param int $type One of Stmt\Use_::TYPE_* + * @param Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_* * * @return Name Resolved name, or original name with attribute */ - protected function resolveName(Name $name, int $type) : Name { + protected function resolveName(Name $name, int $type): Name { if (!$this->replaceNodes) { $resolvedName = $this->nameContext->getResolvedName($name, $type); if (null !== $resolvedName) { @@ -226,17 +250,16 @@ protected function resolveName(Name $name, int $type) : Name { return $name; } - protected function resolveClassName(Name $name) { + protected function resolveClassName(Name $name): Name { return $this->resolveName($name, Stmt\Use_::TYPE_NORMAL); } - protected function addNamespacedName(Node $node) { + protected function addNamespacedName(Node $node): void { $node->namespacedName = Name::concat( $this->nameContext->getNamespace(), (string) $node->name); } - protected function resolveAttrGroups(Node $node) - { + protected function resolveAttrGroups(Node $node): void { foreach ($node->attrGroups as $attrGroup) { foreach ($attrGroup->attrs as $attr) { $attr->name = $this->resolveClassName($attr->name); diff --git a/lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php b/lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php index ea372e5b99..70e051e2d9 100644 --- a/lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php +++ b/lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php @@ -9,23 +9,30 @@ * Visitor that connects a child node to its parent node * as well as its sibling nodes. * - * On the child node, the parent node can be accessed through + * With $weakReferences=false on the child node, the parent node can be accessed through * $node->getAttribute('parent'), the previous * node can be accessed through $node->getAttribute('previous'), * and the next node can be accessed through $node->getAttribute('next'). + * + * With $weakReferences=true attribute names are prefixed by "weak_", e.g. "weak_parent". */ -final class NodeConnectingVisitor extends NodeVisitorAbstract -{ +final class NodeConnectingVisitor extends NodeVisitorAbstract { /** * @var Node[] */ - private $stack = []; + private array $stack = []; /** * @var ?Node */ private $previous; + private bool $weakReferences; + + public function __construct(bool $weakReferences = false) { + $this->weakReferences = $weakReferences; + } + public function beforeTraverse(array $nodes) { $this->stack = []; $this->previous = null; @@ -33,12 +40,26 @@ public function beforeTraverse(array $nodes) { public function enterNode(Node $node) { if (!empty($this->stack)) { - $node->setAttribute('parent', $this->stack[count($this->stack) - 1]); + $parent = $this->stack[count($this->stack) - 1]; + if ($this->weakReferences) { + $node->setAttribute('weak_parent', \WeakReference::create($parent)); + } else { + $node->setAttribute('parent', $parent); + } } - if ($this->previous !== null && $this->previous->getAttribute('parent') === $node->getAttribute('parent')) { - $node->setAttribute('previous', $this->previous); - $this->previous->setAttribute('next', $node); + if ($this->previous !== null) { + if ( + $this->weakReferences + ) { + if ($this->previous->getAttribute('weak_parent') === $node->getAttribute('weak_parent')) { + $node->setAttribute('weak_previous', \WeakReference::create($this->previous)); + $this->previous->setAttribute('weak_next', \WeakReference::create($node)); + } + } elseif ($this->previous->getAttribute('parent') === $node->getAttribute('parent')) { + $node->setAttribute('previous', $this->previous); + $this->previous->setAttribute('next', $node); + } } $this->stack[] = $node; diff --git a/lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php b/lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php index b98d2bfa6f..abf6e37d2e 100644 --- a/lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php +++ b/lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php @@ -2,40 +2,50 @@ namespace PhpParser\NodeVisitor; -use function array_pop; -use function count; use PhpParser\Node; use PhpParser\NodeVisitorAbstract; +use function array_pop; +use function count; + /** * Visitor that connects a child node to its parent node. * - * On the child node, the parent node can be accessed through + * With $weakReferences=false on the child node, the parent node can be accessed through * $node->getAttribute('parent'). + * + * With $weakReferences=true the attribute name is "weak_parent" instead. */ -final class ParentConnectingVisitor extends NodeVisitorAbstract -{ +final class ParentConnectingVisitor extends NodeVisitorAbstract { /** * @var Node[] */ - private $stack = []; + private array $stack = []; + + private bool $weakReferences; + + public function __construct(bool $weakReferences = false) { + $this->weakReferences = $weakReferences; + } - public function beforeTraverse(array $nodes) - { + public function beforeTraverse(array $nodes) { $this->stack = []; } - public function enterNode(Node $node) - { + public function enterNode(Node $node) { if (!empty($this->stack)) { - $node->setAttribute('parent', $this->stack[count($this->stack) - 1]); + $parent = $this->stack[count($this->stack) - 1]; + if ($this->weakReferences) { + $node->setAttribute('weak_parent', \WeakReference::create($parent)); + } else { + $node->setAttribute('parent', $parent); + } } $this->stack[] = $node; } - public function leaveNode(Node $node) - { + public function leaveNode(Node $node) { array_pop($this->stack); } } diff --git a/lib/PhpParser/NodeVisitorAbstract.php b/lib/PhpParser/NodeVisitorAbstract.php index d378d67096..6fb15cca4d 100644 --- a/lib/PhpParser/NodeVisitorAbstract.php +++ b/lib/PhpParser/NodeVisitorAbstract.php @@ -5,8 +5,7 @@ /** * @codeCoverageIgnore */ -class NodeVisitorAbstract implements NodeVisitor -{ +abstract class NodeVisitorAbstract implements NodeVisitor { public function beforeTraverse(array $nodes) { return null; } diff --git a/lib/PhpParser/Parser.php b/lib/PhpParser/Parser.php index 8956c76718..68954afea7 100644 --- a/lib/PhpParser/Parser.php +++ b/lib/PhpParser/Parser.php @@ -2,8 +2,7 @@ namespace PhpParser; -interface Parser -{ +interface Parser { /** * Parses PHP code into a node tree. * @@ -14,5 +13,12 @@ interface Parser * @return Node\Stmt[]|null Array of statements (or null non-throwing error handler is used and * the parser was unable to recover from an error). */ - public function parse(string $code, ErrorHandler $errorHandler = null); + public function parse(string $code, ?ErrorHandler $errorHandler = null): ?array; + + /** + * Return tokens for the last parse. + * + * @return Token[] + */ + public function getTokens(): array; } diff --git a/lib/PhpParser/Parser/Multiple.php b/lib/PhpParser/Parser/Multiple.php deleted file mode 100644 index 77fd1f3fbb..0000000000 --- a/lib/PhpParser/Parser/Multiple.php +++ /dev/null @@ -1,55 +0,0 @@ -parsers = $parsers; - } - - public function parse(string $code, ErrorHandler $errorHandler = null) { - if (null === $errorHandler) { - $errorHandler = new ErrorHandler\Throwing; - } - - list($firstStmts, $firstError) = $this->tryParse($this->parsers[0], $errorHandler, $code); - if ($firstError === null) { - return $firstStmts; - } - - for ($i = 1, $c = count($this->parsers); $i < $c; ++$i) { - list($stmts, $error) = $this->tryParse($this->parsers[$i], $errorHandler, $code); - if ($error === null) { - return $stmts; - } - } - - throw $firstError; - } - - private function tryParse(Parser $parser, ErrorHandler $errorHandler, $code) { - $stmts = null; - $error = null; - try { - $stmts = $parser->parse($code, $errorHandler); - } catch (Error $error) {} - return [$stmts, $error]; - } -} diff --git a/lib/PhpParser/Parser/Php5.php b/lib/PhpParser/Parser/Php5.php deleted file mode 100644 index 331adb6791..0000000000 --- a/lib/PhpParser/Parser/Php5.php +++ /dev/null @@ -1,2630 +0,0 @@ -'", - "T_IS_GREATER_OR_EQUAL", - "T_SL", - "T_SR", - "'+'", - "'-'", - "'.'", - "'*'", - "'/'", - "'%'", - "'!'", - "T_INSTANCEOF", - "'~'", - "T_INC", - "T_DEC", - "T_INT_CAST", - "T_DOUBLE_CAST", - "T_STRING_CAST", - "T_ARRAY_CAST", - "T_OBJECT_CAST", - "T_BOOL_CAST", - "T_UNSET_CAST", - "'@'", - "T_POW", - "'['", - "T_NEW", - "T_CLONE", - "T_EXIT", - "T_IF", - "T_ELSEIF", - "T_ELSE", - "T_ENDIF", - "T_LNUMBER", - "T_DNUMBER", - "T_STRING", - "T_STRING_VARNAME", - "T_VARIABLE", - "T_NUM_STRING", - "T_INLINE_HTML", - "T_ENCAPSED_AND_WHITESPACE", - "T_CONSTANT_ENCAPSED_STRING", - "T_ECHO", - "T_DO", - "T_WHILE", - "T_ENDWHILE", - "T_FOR", - "T_ENDFOR", - "T_FOREACH", - "T_ENDFOREACH", - "T_DECLARE", - "T_ENDDECLARE", - "T_AS", - "T_SWITCH", - "T_MATCH", - "T_ENDSWITCH", - "T_CASE", - "T_DEFAULT", - "T_BREAK", - "T_CONTINUE", - "T_GOTO", - "T_FUNCTION", - "T_FN", - "T_CONST", - "T_RETURN", - "T_TRY", - "T_CATCH", - "T_FINALLY", - "T_USE", - "T_INSTEADOF", - "T_GLOBAL", - "T_STATIC", - "T_ABSTRACT", - "T_FINAL", - "T_PRIVATE", - "T_PROTECTED", - "T_PUBLIC", - "T_VAR", - "T_UNSET", - "T_ISSET", - "T_EMPTY", - "T_HALT_COMPILER", - "T_CLASS", - "T_TRAIT", - "T_INTERFACE", - "T_EXTENDS", - "T_IMPLEMENTS", - "T_OBJECT_OPERATOR", - "T_LIST", - "T_ARRAY", - "T_CALLABLE", - "T_CLASS_C", - "T_TRAIT_C", - "T_METHOD_C", - "T_FUNC_C", - "T_LINE", - "T_FILE", - "T_START_HEREDOC", - "T_END_HEREDOC", - "T_DOLLAR_OPEN_CURLY_BRACES", - "T_CURLY_OPEN", - "T_PAAMAYIM_NEKUDOTAYIM", - "T_NAMESPACE", - "T_NS_C", - "T_DIR", - "T_NS_SEPARATOR", - "T_ELLIPSIS", - "T_NAME_FULLY_QUALIFIED", - "T_NAME_QUALIFIED", - "T_NAME_RELATIVE", - "';'", - "'{'", - "'}'", - "'('", - "')'", - "'$'", - "'`'", - "']'", - "'\"'", - "T_NULLSAFE_OBJECT_OPERATOR", - "T_ATTRIBUTE", - "T_ENUM" - ); - - protected $tokenToSymbol = array( - 0, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 55, 162, 166, 159, 54, 37, 166, - 157, 158, 52, 49, 8, 50, 51, 53, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 31, 154, - 43, 16, 45, 30, 67, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 69, 166, 161, 36, 166, 160, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 155, 35, 156, 57, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, - 166, 166, 166, 166, 166, 166, 1, 2, 3, 4, - 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 32, 33, 34, 38, 39, 40, 41, - 42, 44, 46, 47, 48, 56, 58, 59, 60, 61, - 62, 63, 64, 65, 66, 68, 70, 71, 72, 73, - 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, - 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, - 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, - 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, - 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, - 124, 125, 126, 127, 128, 129, 130, 131, 163, 132, - 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, - 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, - 153, 164, 165 - ); - - protected $action = array( - 693, 663, 664, 665, 666, 667, 282, 668, 669, 670, - 706, 707, 221, 222, 223, 224, 225, 226, 227, 228, - 229, 0, 230, 231, 232, 233, 234, 235, 236, 237, - 238, 239, 240, 241,-32766,-32766,-32766,-32766,-32766,-32766, - -32766,-32766,-32767,-32767,-32767,-32767, 27, 242, 243,-32766, - -32766,-32766,-32766,-32766, 671,-32766, 333,-32766,-32766,-32766, - -32766,-32766,-32766,-32767,-32767,-32767,-32767,-32767, 672, 673, - 674, 675, 676, 677, 678, 1034, 816, 740, 941, 942, - 943, 940, 939, 938, 679, 680, 681, 682, 683, 684, - 685, 686, 687, 688, 689, 709, 732, 710, 711, 712, - 713, 701, 702, 703, 731, 704, 705, 690, 691, 692, - 694, 695, 696, 734, 735, 736, 737, 738, 739, 697, - 698, 699, 700, 730, 721, 719, 720, 716, 717, 437, - 708, 714, 715, 722, 723, 725, 724, 726, 727, 55, - 56, 417, 57, 58, 718, 729, 728, 28, 59, 60, - -220, 61,-32766,-32766,-32766,-32766,-32766,-32766,-32766,-32766, - -32766, 36,-32767,-32767,-32767,-32767, 1034, 35, 106, 107, - 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, - 118,-32766,-32766,-32766,-32766, 62, 63, 1034, 125, 285, - 292, 64, 748, 65, 290, 291, 66, 67, 68, 69, - 70, 71, 72, 73, 763, 25, 298, 74, 409, 973, - 975, 294, 294, 1086, 1087, 1064, 796, 748, 218, 219, - 220, 465,-32766,-32766,-32766, 742, 864, 817, 54, 807, - 9,-32766,-32766,-32766, 760, 320, 761, 410, 10, 202, - 246, 428, 209,-32766, 933,-32766,-32766,-32766,-32766,-32766, - -32766, 488,-32766, 438,-32766,-32766,-32766,-32766,-32766, 473, - 474, 941, 942, 943, 940, 939, 938,-32766, 475, 476, - 337, 1092, 1093, 1094, 1095, 1089, 1090, 315, 1214, -255, - 747, 1215, -505, 1096, 1091, 888, 889, 1066, 1065, 1067, - 218, 219, 220, 41, 414, 337, 330, 895, 332, 418, - -126, -126, -126, 75, 52, 464, -4, 817, 54, 805, - -224, 202, 40, 21, 419, -126, 466, -126, 467, -126, - 468, -126, 359, 420, 128, 128, 748, 1171, 31, 32, - 421, 422, 1034, 894, 33, 469,-32766,-32766,-32766, 1186, - 351, 352, 470, 471,-32766,-32766,-32766, 309, 472, 865, - 323, 788, 835, 423, 424,-32767,-32767,-32767,-32767, 97, - 98, 99, 100, 101, 615,-32766, 313,-32766,-32766,-32766, - -32766, 354, 1185, 1171, 218, 219, 220, 475, 748, 418, - 819, 629, -126, 297, 915, 464, 817, 54,-32766, 805, - 124, 748, 40, 21, 419, 202, 466, 48, 467, 534, - 468, 129, 429, 420, 337, 341, 888, 889, 31, 32, - 421, 422, 416, 405, 33, 469,-32766,-32766, 311, 298, - 351, 352, 470, 471,-32766,-32766,-32766, 748, 472, 412, - 748, 752, 835, 423, 424, 338, 1066, 1065, 1067, 219, - 220, 919, 1136, 296, 20,-32766, 576,-32766,-32766,-32766, - 742, 341, 342, 413, 429, 1064, 337, 512, 418, 202, - 819, 629, -4, 1034, 464, 817, 54, 49, 805, 337, - 762, 40, 21, 419, 51, 466, 1034, 467, 475, 468, - 340, 748, 420, 120, -205, -205, -205, 31, 32, 421, - 422, 1062,-32766, 33, 469,-32766,-32766,-32766, 744, 351, - 352, 470, 471, 429, 1098, 337, 429, 472, 337, 1034, - 788, 835, 423, 424, 415, 1098,-32766, 802,-32766,-32766, - 102, 103, 104, 1137, 303, 202, 130, 1066, 1065, 1067, - 337, 123, 239, 240, 241, 748, 105, 418, 1205, 819, - 629, -205, 440, 464,-32766,-32766,-32766, 805, 242, 243, - 40, 21, 419, 121, 466, 126, 467, 429, 468, 337, - 122, 420, 1052, -204, -204, -204, 31, 32, 421, 422, - 1034, 745, 33, 469, 220, 759, 817, 54, 351, 352, - 470, 471, 218, 219, 220, 119, 472, 244, 127, 788, - 835, 423, 424, 202,-32766,-32766,-32766, 30, 293, 803, - 79, 80, 81, 202, 798, 210, 632, 99, 100, 101, - 236, 237, 238, 817, 54,-32766, 211, 800, 819, 629, - -204, 34, 1034, 82, 83, 84, 85, 86, 87, 88, - 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, - 99, 100, 101, 102, 103, 104, 286, 303, 418, 1034, - 817, 54,-32766,-32766, 464, 218, 219, 220, 805, 105, - 914, 40, 21, 419, 78, 466, 212, 467, 337, 468, - 133, 247, 420, 295, 567, 248, 202, 31, 32, 421, - 633, 242, 243, 33, 469, 418, 249, 817, 54, 351, - 352, 464, 760, -84, 761, 805, 310, 472, 40, 21, - 419,-32766, 466, 640, 467, 643, 468, 447, 22, 420, - 815, 452, 584, 132, 31, 32, 421, 637, 134, 364, - 33, 469, 418, 303, 817, 54, 351, 352, 464, 819, - 629, 828, 805, 43, 472, 40, 21, 419, 44, 466, - 45, 467, 46, 468, 591, 592, 420, 753, 635, 930, - 649, 31, 32, 421, 641, 918, 657, 33, 469, 418, - 105, 817, 54, 351, 352, 464, 819, 629, 47, 805, - 50, 472, 40, 21, 419, 53, 466, 131, 467, 298, - 468, 599, 742, 420,-32766, -274, 516, 570, 31, 32, - 421, 646, 748, 946, 33, 469, 418, 589, 436,-32766, - 351, 352, 464, 819, 629, 623, 805, 836, 472, 40, - 21, 419, 611, 466, -82, 467, 603, 468, 11, 573, - 420, 439, 456, 281, 318, 31, 32, 421, 588, 432, - 321, 33, 469, 418, -414, 458, 322, 351, 352, 464, - 851, 629, 837, 805, -505, 472, 40, 21, 419, 654, - 466, 38, 467, 24, 468, 0, 0, 420, 319, 0, - -405, 0, 31, 32, 421, 245, 312, 314, 33, 469, - -506, 0, 0, 1097, 351, 352, 1143, 819, 629, 0, - 0, 527, 472, 213, 214, 6, 7, 12, 14, 215, - 363, 216, -415, 558, 789, -221, 830, 0, 0, 747, - 0, 0, 0, 207, 39, 652, 653, 758, 806, 814, - 793, 1086, 1087, 808, 819, 629, 213, 214, 867, 1088, - 858, 859, 215, 791, 216, 852, 849, 847, 925, 926, - 923, 813, 797, 799, 801, 804, 207, 922, 756, 757, - 924, 287, 78, 331, 1086, 1087, 353, 630, 634, 636, - 638, 639, 1088, 642, 644, 645, 647, 648, 631, 1142, - 1211, 1213, 755, 834, 754, 833, 1212, 554, 832, 1092, - 1093, 1094, 1095, 1089, 1090, 388, 1048, 824, 1036, 831, - 1037, 1096, 1091, 822, 931, 856, 857, 451, 1210, 1179, - 0, 217, 1177, 1162, 1175, 1077, 906, 1183, 1173, 0, - 554, 26, 1092, 1093, 1094, 1095, 1089, 1090, 388, 29, - 37, 42, 76, 77, 1096, 1091, 208, 284, 288, 289, - 304, 305, 306, 307, 217, 335, 406, 408, 0, -220, - 16, 17, 18, 383, 448, 455, 457, 462, 548, 620, - 1039, 1042, 896, 1102, 1038, 1014, 559, 1013, 1079, 0, - 0, -424, 1032, 0, 1043, 1045, 1044, 1047, 1046, 1061, - 1176, 1161, 1157, 1174, 1076, 1208, 1103, 1156, 595 - ); - - protected $actionCheck = array( - 2, 3, 4, 5, 6, 7, 14, 9, 10, 11, - 12, 13, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 0, 43, 44, 45, 46, 47, 48, 49, 50, - 51, 52, 53, 54, 9, 10, 11, 33, 34, 35, - 36, 37, 38, 39, 40, 41, 8, 68, 69, 33, - 34, 35, 36, 37, 56, 30, 8, 32, 33, 34, - 35, 36, 37, 38, 39, 40, 41, 42, 70, 71, - 72, 73, 74, 75, 76, 13, 1, 79, 115, 116, - 117, 118, 119, 120, 86, 87, 88, 89, 90, 91, - 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, - 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, - 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, - 122, 123, 124, 125, 126, 127, 128, 129, 130, 31, - 132, 133, 134, 135, 136, 137, 138, 139, 140, 3, - 4, 5, 6, 7, 146, 147, 148, 8, 12, 13, - 158, 15, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 14, 43, 44, 45, 46, 13, 16, 17, 18, - 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, - 29, 33, 34, 35, 36, 49, 50, 13, 8, 8, - 37, 55, 81, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 156, 69, 70, 71, 72, 58, - 59, 37, 37, 77, 78, 79, 154, 81, 9, 10, - 11, 85, 9, 10, 11, 79, 31, 1, 2, 154, - 107, 9, 10, 11, 105, 112, 107, 126, 8, 30, - 31, 105, 8, 30, 121, 32, 33, 34, 35, 36, - 37, 115, 30, 155, 32, 33, 34, 35, 36, 123, - 124, 115, 116, 117, 118, 119, 120, 115, 132, 133, - 159, 135, 136, 137, 138, 139, 140, 141, 79, 156, - 151, 82, 131, 147, 148, 133, 134, 151, 152, 153, - 9, 10, 11, 157, 8, 159, 160, 158, 162, 73, - 74, 75, 76, 150, 69, 79, 0, 1, 2, 83, - 158, 30, 86, 87, 88, 89, 90, 91, 92, 93, - 94, 95, 8, 97, 150, 150, 81, 81, 102, 103, - 104, 105, 13, 158, 108, 109, 9, 10, 11, 158, - 114, 115, 116, 117, 9, 10, 11, 8, 122, 154, - 8, 125, 126, 127, 128, 43, 44, 45, 46, 47, - 48, 49, 50, 51, 79, 30, 131, 32, 33, 34, - 35, 8, 1, 81, 9, 10, 11, 132, 81, 73, - 154, 155, 156, 37, 154, 79, 1, 2, 115, 83, - 155, 81, 86, 87, 88, 30, 90, 69, 92, 80, - 94, 155, 157, 97, 159, 159, 133, 134, 102, 103, - 104, 105, 8, 107, 108, 109, 9, 10, 112, 70, - 114, 115, 116, 117, 9, 10, 11, 81, 122, 8, - 81, 125, 126, 127, 128, 8, 151, 152, 153, 10, - 11, 156, 161, 8, 158, 30, 84, 32, 33, 34, - 79, 159, 146, 8, 157, 79, 159, 84, 73, 30, - 154, 155, 156, 13, 79, 1, 2, 69, 83, 159, - 156, 86, 87, 88, 69, 90, 13, 92, 132, 94, - 69, 81, 97, 155, 99, 100, 101, 102, 103, 104, - 105, 115, 9, 108, 109, 9, 10, 11, 79, 114, - 115, 116, 117, 157, 142, 159, 157, 122, 159, 13, - 125, 126, 127, 128, 8, 142, 30, 154, 32, 33, - 52, 53, 54, 158, 56, 30, 155, 151, 152, 153, - 159, 14, 52, 53, 54, 81, 68, 73, 84, 154, - 155, 156, 131, 79, 33, 34, 35, 83, 68, 69, - 86, 87, 88, 155, 90, 155, 92, 157, 94, 159, - 155, 97, 158, 99, 100, 101, 102, 103, 104, 105, - 13, 152, 108, 109, 11, 154, 1, 2, 114, 115, - 116, 117, 9, 10, 11, 16, 122, 14, 31, 125, - 126, 127, 128, 30, 9, 10, 11, 143, 144, 154, - 9, 10, 11, 30, 154, 16, 31, 49, 50, 51, - 49, 50, 51, 1, 2, 30, 16, 154, 154, 155, - 156, 30, 13, 32, 33, 34, 35, 36, 37, 38, - 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, - 49, 50, 51, 52, 53, 54, 37, 56, 73, 13, - 1, 2, 33, 34, 79, 9, 10, 11, 83, 68, - 154, 86, 87, 88, 155, 90, 16, 92, 159, 94, - 155, 16, 97, 37, 159, 16, 30, 102, 103, 104, - 31, 68, 69, 108, 109, 73, 16, 1, 2, 114, - 115, 79, 105, 31, 107, 83, 31, 122, 86, 87, - 88, 33, 90, 31, 92, 31, 94, 74, 75, 97, - 31, 74, 75, 31, 102, 103, 104, 31, 100, 101, - 108, 109, 73, 56, 1, 2, 114, 115, 79, 154, - 155, 37, 83, 69, 122, 86, 87, 88, 69, 90, - 69, 92, 69, 94, 110, 111, 97, 154, 155, 154, - 155, 102, 103, 104, 31, 154, 155, 108, 109, 73, - 68, 1, 2, 114, 115, 79, 154, 155, 69, 83, - 69, 122, 86, 87, 88, 69, 90, 69, 92, 70, - 94, 76, 79, 97, 84, 81, 84, 89, 102, 103, - 104, 31, 81, 81, 108, 109, 73, 112, 88, 115, - 114, 115, 79, 154, 155, 91, 83, 126, 122, 86, - 87, 88, 93, 90, 96, 92, 95, 94, 96, 99, - 97, 96, 96, 96, 129, 102, 103, 104, 99, 105, - 113, 108, 109, 73, 145, 105, 129, 114, 115, 79, - 154, 155, 126, 83, 131, 122, 86, 87, 88, 156, - 90, 154, 92, 157, 94, -1, -1, 97, 130, -1, - 145, -1, 102, 103, 104, 31, 131, 131, 108, 109, - 131, -1, -1, 142, 114, 115, 142, 154, 155, -1, - -1, 149, 122, 49, 50, 145, 145, 145, 145, 55, - 145, 57, 145, 149, 156, 158, 150, -1, -1, 151, - -1, -1, -1, 69, 154, 154, 154, 154, 154, 154, - 154, 77, 78, 154, 154, 155, 49, 50, 154, 85, - 154, 154, 55, 154, 57, 154, 154, 154, 154, 154, - 154, 154, 154, 154, 154, 154, 69, 154, 154, 154, - 154, 159, 155, 155, 77, 78, 155, 155, 155, 155, - 155, 155, 85, 155, 155, 155, 155, 155, 155, 162, - 156, 156, 156, 156, 156, 156, 156, 133, 156, 135, - 136, 137, 138, 139, 140, 141, 156, 156, 156, 156, - 156, 147, 148, 156, 156, 156, 156, 156, 156, 156, - -1, 157, 156, 156, 156, 156, 156, 156, 156, -1, - 133, 157, 135, 136, 137, 138, 139, 140, 141, 157, - 157, 157, 157, 157, 147, 148, 157, 157, 157, 157, - 157, 157, 157, 157, 157, 157, 157, 157, -1, 158, - 158, 158, 158, 158, 158, 158, 158, 158, 158, 158, - 158, 158, 158, 158, 158, 158, 158, 158, 158, -1, - -1, 160, 160, -1, 161, 161, 161, 161, 161, 161, - 161, 161, 161, 161, 161, 161, 161, 161, 161 - ); - - protected $actionBase = array( - 0, 226, 306, 385, 464, 285, 246, 246, 786, -2, - -2, 146, -2, -2, -2, 649, 723, 760, 723, 575, - 686, 612, 612, 612, 175, 153, 153, 153, 174, 890, - 319, 62, 450, 463, 557, 609, 636, 496, 496, 496, - 496, 136, 136, 496, 496, 496, 496, 496, 496, 496, - 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, - 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, - 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, - 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, - 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, - 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, - 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, - 496, 496, 496, 496, 496, 496, 496, 496, 496, 496, - 496, 496, 496, 496, 496, 195, 75, 777, 517, 147, - 778, 779, 780, 886, 727, 887, 832, 833, 682, 836, - 837, 838, 839, 840, 831, 841, 907, 842, 591, 591, - 591, 591, 591, 591, 591, 591, 591, 591, 591, 591, - 483, 573, 365, 209, 281, 407, 646, 646, 646, 646, - 646, 646, 646, 327, 327, 327, 327, 327, 327, 327, - 327, 327, 327, 327, 327, 327, 327, 327, 327, 327, - 327, 429, 834, 585, 585, 585, 563, 867, 867, 867, - 867, 867, 867, 867, 867, 867, 867, 867, 867, 867, - 867, 867, 867, 867, 867, 867, 867, 867, 867, 867, - 867, 867, 867, 867, 867, 867, 867, 867, 867, 867, - 867, 867, 867, 867, 867, 867, 867, 867, 867, 867, - 495, 486, -21, -21, 415, 668, 335, 619, 222, 511, - 213, 25, 25, 25, 25, 25, 148, 16, 4, 4, - 4, 4, 151, 312, 312, 312, 312, 119, 119, 119, - 119, 346, 346, 123, 245, 245, 349, 400, 297, 297, - 297, 297, 297, 297, 297, 297, 297, 297, 111, 558, - 558, 561, 561, 310, 152, 152, 152, 152, 704, 273, - 273, 129, 371, 371, 371, 373, 734, 797, 376, 376, - 376, 376, 376, 376, 468, 468, 468, 480, 480, 480, - 702, 587, 454, 587, 454, 684, 748, 509, 748, 700, - 199, 515, 803, 398, 720, 829, 729, 830, 601, 747, - 235, 782, 724, 419, 782, 633, 637, 634, 419, 419, - 715, 98, 863, 292, 195, 595, 405, 667, 781, 421, - 732, 784, 363, 445, 411, 593, 328, 286, 744, 785, - 888, 889, 181, 739, 667, 667, 667, 139, 362, 328, - -8, 613, 613, 613, 613, 48, 613, 613, 613, 613, - 314, 230, 506, 404, 783, 703, 703, 712, 694, 852, - 696, 696, 703, 711, 703, 712, 694, 854, 854, 854, - 854, 703, 694, 703, 703, 703, 696, 696, 694, 709, - 696, 38, 694, 695, 707, 707, 854, 751, 752, 703, - 703, 728, 696, 696, 696, 728, 694, 854, 685, 746, - 234, 696, 854, 665, 711, 665, 703, 685, 694, 665, - 711, 711, 665, 21, 662, 664, 853, 855, 869, 792, - 681, 716, 861, 862, 856, 860, 844, 679, 753, 754, - 569, 669, 671, 673, 699, 740, 701, 735, 724, 692, - 692, 692, 713, 741, 713, 692, 692, 692, 692, 692, - 692, 692, 692, 893, 689, 745, 736, 710, 755, 589, - 600, 793, 731, 738, 882, 875, 891, 892, 863, 880, - 713, 894, 697, 180, 650, 864, 693, 788, 713, 865, - 713, 794, 713, 883, 804, 708, 805, 806, 692, 884, - 895, 896, 897, 898, 899, 900, 901, 902, 706, 903, - 756, 698, 876, 339, 859, 715, 742, 725, 791, 759, - 807, 342, 904, 808, 713, 713, 795, 787, 713, 796, - 764, 750, 872, 766, 877, 905, 731, 726, 878, 713, - 730, 809, 906, 342, 672, 705, 737, 721, 767, 870, - 885, 868, 798, 655, 659, 810, 812, 820, 674, 769, - 873, 874, 871, 771, 799, 670, 800, 719, 821, 801, - 866, 772, 822, 823, 881, 718, 743, 717, 722, 714, - 802, 824, 879, 773, 774, 775, 827, 776, 828, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 136, - 136, 136, 136, -2, -2, -2, -2, 0, 0, -2, - 0, 0, 0, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 0, - 0, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, - 136, 136, 136, 591, 591, 591, 591, 591, 591, 591, - 591, 591, 591, 591, 591, 591, 591, 591, 591, 591, - 591, 591, 591, 591, 591, 591, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 591, -21, - -21, -21, -21, 591, -21, -21, -21, -21, -21, -21, - -21, 591, 591, 591, 591, 591, 591, 591, 591, 591, - 591, 591, 591, 591, 591, 591, 591, 591, 591, -21, - 376, 591, 591, 591, -21, 376, 376, 376, 376, 376, - 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, - 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, - 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, - 376, 376, 376, 376, 376, 376, 376, 376, -21, 591, - 0, 0, 591, -21, 591, -21, 591, -21, 591, 591, - 591, 591, 591, 591, -21, -21, -21, -21, -21, -21, - 0, 468, 468, 468, 468, -21, -21, -21, -21, 376, - 376, -37, 376, 376, 376, 376, 376, 376, 376, 376, - 376, 376, 376, 376, 376, 376, 376, 468, 468, 480, - 480, 376, 376, 376, 376, 376, -37, 376, 376, 419, - 711, 711, 711, 454, 454, 454, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 454, 419, - 0, 419, 0, 376, 419, 711, 419, 454, 711, 711, - 419, 696, 618, 618, 618, 618, 342, 328, 0, 711, - 711, 0, 711, 0, 0, 0, 0, 0, 696, 0, - 703, 0, 0, 0, 0, 692, 180, 0, 725, 427, - 0, 0, 0, 0, 0, 0, 725, 427, 435, 435, - 0, 706, 692, 692, 692, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 342 - ); - - protected $actionDefault = array( - 3,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 32767,32767,32767,32767,32767, 534, 534, 489,32767,32767, - 32767,32767,32767,32767,32767,32767,32767, 293, 293, 293, - 32767,32767,32767, 522, 522, 522, 522, 522, 522, 522, - 522, 522, 522, 522,32767,32767,32767,32767,32767,32767, - 376,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 32767,32767,32767,32767,32767,32767,32767,32767, 382, 539, - 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 32767,32767,32767,32767,32767,32767,32767,32767, 357, 358, - 360, 361, 292, 542, 523, 241, 383, 538, 291, 243, - 321, 493,32767,32767,32767, 323, 120, 252, 197, 492, - 123, 290, 228, 375, 377, 322, 297, 302, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, - 296, 449,32767, 354, 353, 352, 451, 486, 486, 489, - 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 450, 319, 477, 476, 320, 447, 324, 448, 326, 452, - 325, 342, 343, 340, 341, 344, 454, 453, 470, 471, - 468, 469, 295, 345, 346, 347, 348, 472, 473, 474, - 475,32767,32767, 276, 533, 533,32767,32767,32767,32767, - 32767,32767,32767,32767,32767,32767,32767,32767,32767, 333, - 334, 461, 462,32767, 232, 232, 232, 232, 277, 232, - 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 32767,32767,32767,32767, 328, 329, 327, 456, 457, 455, - 423,32767,32767,32767, 425,32767,32767,32767,32767,32767, - 32767,32767,32767, 494,32767,32767,32767,32767,32767, 507, - 412,32767, 404,32767,32767, 216, 218, 165,32767,32767, - 480,32767,32767,32767,32767,32767, 512, 338,32767,32767, - 114,32767,32767,32767, 549,32767, 507,32767, 114,32767, - 32767,32767,32767, 351, 330, 331, 332,32767,32767, 511, - 505, 464, 465, 466, 467,32767, 458, 459, 460, 463, - 32767,32767,32767,32767,32767,32767,32767,32767, 169, 420, - 426, 426,32767,32767,32767,32767, 169,32767,32767,32767, - 32767,32767, 169,32767,32767,32767, 510, 509, 169,32767, - 405, 488, 169, 182, 180, 180,32767, 202, 202,32767, - 32767, 184, 481, 500,32767, 184, 169,32767, 393, 171, - 488,32767,32767, 234,32767, 234,32767, 393, 169, 234, - 32767,32767, 234,32767, 406, 430,32767,32767,32767,32767, - 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, - 32767, 372, 373, 483, 496,32767, 497,32767, 404, 336, - 337, 339, 316,32767, 318, 362, 363, 364, 365, 366, - 367, 368, 370,32767, 410,32767, 413,32767,32767,32767, - 251,32767, 547,32767,32767, 300, 547,32767,32767,32767, - 541,32767,32767, 294,32767,32767,32767,32767, 247,32767, - 167,32767, 531,32767, 548,32767, 505,32767, 335,32767, - 32767,32767,32767,32767,32767,32767,32767,32767, 506,32767, - 32767,32767,32767, 223,32767, 443,32767, 114,32767,32767, - 32767, 183,32767,32767, 298, 242,32767,32767, 540,32767, - 32767,32767,32767,32767,32767,32767,32767, 112,32767, 168, - 32767,32767,32767, 185,32767,32767, 505,32767,32767,32767, - 32767,32767,32767,32767, 289,32767,32767,32767,32767,32767, - 32767,32767, 505,32767,32767, 227,32767,32767,32767,32767, - 32767,32767,32767,32767,32767, 406,32767, 270,32767,32767, - 32767,32767,32767,32767,32767,32767,32767,32767,32767, 125, - 125, 3, 125, 125, 254, 3, 254, 125, 254, 254, - 125, 125, 125, 125, 125, 125, 125, 125, 125, 125, - 210, 213, 202, 202, 162, 125, 125, 262 - ); - - protected $goto = array( - 165, 139, 139, 139, 165, 143, 146, 140, 141, 142, - 148, 186, 167, 162, 162, 162, 162, 143, 143, 164, - 164, 164, 164, 164, 164, 164, 164, 164, 164, 164, - 137, 158, 159, 160, 161, 183, 138, 184, 489, 490, - 367, 491, 495, 496, 497, 498, 499, 500, 501, 502, - 959, 163, 144, 145, 147, 170, 175, 185, 203, 251, - 254, 256, 258, 260, 261, 262, 263, 264, 265, 273, - 274, 275, 276, 299, 300, 324, 325, 326, 384, 385, - 386, 538, 187, 188, 189, 190, 191, 192, 193, 194, - 195, 196, 197, 198, 199, 200, 149, 150, 151, 166, - 152, 168, 153, 204, 169, 154, 155, 156, 205, 157, - 135, 616, 556, 574, 578, 622, 624, 556, 556, 556, - 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, - 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, - 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, - 556, 556, 556, 556, 556, 556, 556, 556, 556, 556, - 1099, 515, 345, 571, 600, 1099, 1099, 1099, 1099, 1099, - 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, - 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, - 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, - 1099, 1099, 1099, 1099, 1099, 1099, 1099, 1099, 504, 1202, - 1202, 1075, 1074, 504, 540, 541, 542, 543, 544, 545, - 546, 547, 549, 582, 3, 4, 173, 1202, 844, 844, - 844, 844, 839, 845, 176, 177, 178, 391, 392, 393, - 394, 172, 201, 206, 250, 255, 257, 259, 266, 267, - 268, 269, 270, 271, 277, 278, 279, 280, 301, 302, - 327, 328, 329, 396, 397, 398, 399, 174, 179, 252, - 253, 180, 181, 182, 493, 493, 750, 493, 493, 493, - 493, 493, 493, 493, 493, 493, 493, 493, 493, 493, - 493, 505, 929, 442, 444, 627, 505, 751, 779, 1100, - 610, 927, 880, 880, 765, 1190, 1190, 1168, 555, 775, - 764, 743, 1168, 555, 555, 555, 555, 555, 555, 555, - 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, - 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, - 555, 555, 555, 555, 555, 555, 555, 555, 555, 555, - 555, 555, 555, 555, 555, 555, 390, 602, 746, 532, - 532, 564, 528, 530, 530, 492, 494, 520, 536, 565, - 568, 579, 586, 810, 606, 506, 346, 347, 609, 850, - 506, 365, 537, 746, 533, 746, 563, 430, 430, 375, - 430, 430, 430, 430, 430, 430, 430, 430, 430, 430, - 430, 430, 430, 430, 1063, 581, 957, 596, 597, 1063, - 887, 887, 887, 887, 1160, 887, 887, 1182, 1182, 1182, - 376, 376, 376, 749, 1063, 1063, 1063, 1063, 1063, 1063, - 334, 1056, 317, 374, 374, 374, 866, 848, 846, 848, - 650, 461, 507, 875, 870, 376, 1194, 368, 374, 389, - 374, 898, 374, 1080, 583, 348, 404, 374, 1216, 590, - 601, 1017, 19, 15, 361, 1148, 1187, 525, 936, 904, - 510, 526, 904, 651, 551, 381, 1201, 1201, 587, 1007, - 550, 877, 607, 608, 873, 612, 613, 619, 621, 626, - 628, 23, 884, 937, 1201, 336, 598, 1059, 1060, 1204, - 378, 1056, 557, 539, 893, 768, 766, 379, 514, 902, - 509, 524, 655, 1057, 1159, 1057, 776, 509, 1167, 524, - 514, 514, 1058, 1167, 1049, 907, 508, 1054, 511, 433, - 434, 510, 1184, 1184, 1184, 854, 445, 945, 569, 1145, - 459, 362, 0, 0, 773, 1209, 0, 518, 0, 519, - 0, 529, 0, 0, 0, 0, 0, 1166, 0, 0, - 0, 771, 0, 0, 0, 449, 0, 0, 0, 0, - 0, 0, 605, 0, 0, 0, 0, 13, 1055, 614 - ); - - protected $gotoCheck = array( - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 56, 66, 59, 59, 59, 8, 66, 66, 66, - 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, - 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, - 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, - 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, - 124, 99, 69, 39, 39, 124, 124, 124, 124, 124, - 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, - 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, - 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, - 124, 124, 124, 124, 124, 124, 124, 124, 66, 140, - 140, 122, 122, 66, 108, 108, 108, 108, 108, 108, - 108, 108, 108, 108, 29, 29, 26, 140, 66, 66, - 66, 66, 66, 66, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, - 26, 26, 26, 26, 115, 115, 14, 115, 115, 115, - 115, 115, 115, 115, 115, 115, 115, 115, 115, 115, - 115, 115, 7, 7, 7, 7, 115, 15, 28, 7, - 7, 7, 74, 74, 22, 74, 74, 116, 56, 22, - 22, 5, 116, 56, 56, 56, 56, 56, 56, 56, - 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, - 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, - 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, - 56, 56, 56, 56, 56, 56, 50, 50, 10, 50, - 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 50, 49, 60, 120, 69, 69, 60, 32, - 120, 60, 2, 10, 107, 10, 2, 56, 56, 10, - 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, - 56, 56, 56, 56, 56, 64, 99, 64, 64, 56, - 56, 56, 56, 56, 79, 56, 56, 8, 8, 8, - 121, 121, 121, 13, 56, 56, 56, 56, 56, 56, - 123, 79, 123, 12, 12, 12, 13, 13, 13, 13, - 13, 56, 13, 13, 13, 121, 138, 45, 12, 121, - 12, 81, 12, 33, 67, 67, 67, 12, 12, 125, - 48, 33, 33, 33, 33, 129, 136, 8, 95, 12, - 12, 31, 12, 31, 31, 47, 139, 139, 31, 100, - 33, 31, 31, 31, 31, 31, 31, 31, 31, 31, - 31, 33, 76, 95, 139, 17, 33, 79, 79, 139, - 11, 79, 11, 46, 78, 24, 23, 16, 46, 82, - 8, 8, 71, 79, 79, 79, 25, 8, 117, 8, - 46, 46, 79, 117, 111, 83, 8, 113, 8, 8, - 8, 12, 117, 117, 117, 68, 62, 97, 63, 128, - 106, 57, -1, -1, 8, 8, -1, 57, -1, 99, - -1, 57, -1, -1, -1, -1, -1, 117, -1, -1, - -1, 8, -1, -1, -1, 57, -1, -1, -1, -1, - -1, -1, 12, -1, -1, -1, -1, 57, 12, 12 - ); - - protected $gotoBase = array( - 0, 0, -249, 0, 0, 300, 0, 287, 105, 0, - 47, 164, 118, 421, 274, 295, 171, 184, 0, 0, - 0, 0, -49, 168, 172, 104, 24, 0, 288, -431, - 0, -159, 359, 44, 0, 0, 0, 0, 0, 125, - 0, 0, -24, 0, 0, 407, 479, 186, 178, 355, - 75, 0, 0, 0, 0, 0, 106, 119, 0, -192, - -81, 0, 101, 93, -231, 0, -90, 135, 121, -276, - 0, 148, 0, 0, 21, 0, 183, 0, 194, 71, - 0, 423, 155, 112, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 185, 0, 122, 0, 120, - 176, 0, 0, 0, 0, 0, 83, 358, 170, 0, - 0, 113, 0, 111, 0, -7, 9, 220, 0, 0, - 77, 108, -102, 100, -42, 251, 0, 0, 89, 256, - 0, 0, 0, 0, 0, 0, 181, 0, 419, 160, - -107, 0, 0 - ); - - protected $gotoDefault = array( - -32768, 463, 659, 2, 660, 733, 741, 593, 477, 625, - 577, 370, 1178, 785, 786, 787, 371, 358, 478, 369, - 400, 395, 774, 767, 769, 777, 171, 401, 780, 1, - 782, 513, 818, 1008, 355, 790, 356, 585, 792, 522, - 794, 795, 136, 372, 373, 523, 479, 380, 572, 809, - 272, 377, 811, 357, 812, 821, 360, 460, 454, 552, - 604, 425, 441, 566, 560, 531, 1072, 561, 853, 344, - 861, 656, 869, 872, 480, 553, 883, 446, 891, 1085, - 387, 897, 903, 908, 283, 911, 407, 402, 580, 916, - 917, 5, 921, 617, 618, 8, 308, 944, 594, 958, - 411, 1027, 1029, 481, 482, 517, 453, 503, 521, 483, - 1050, 435, 403, 1053, 484, 485, 426, 427, 1069, 350, - 1153, 349, 443, 316, 1140, 575, 1104, 450, 1193, 1149, - 343, 486, 487, 366, 1172, 382, 1188, 431, 1195, 1203, - 339, 535, 562 - ); - - protected $ruleToNonTerminal = array( - 0, 1, 3, 3, 2, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, - 6, 6, 7, 7, 8, 9, 10, 10, 11, 11, - 12, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 17, 17, 18, 18, 20, 20, 16, 16, - 21, 21, 22, 22, 23, 23, 24, 24, 19, 19, - 25, 27, 27, 28, 29, 29, 31, 30, 30, 30, - 30, 32, 32, 32, 32, 32, 32, 32, 32, 32, - 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, - 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, - 13, 13, 53, 53, 55, 54, 54, 47, 47, 57, - 57, 58, 58, 14, 15, 15, 15, 61, 61, 61, - 62, 62, 65, 65, 63, 63, 67, 67, 40, 40, - 49, 49, 52, 52, 52, 51, 51, 68, 41, 41, - 41, 41, 69, 69, 70, 70, 71, 71, 38, 38, - 34, 34, 72, 36, 36, 73, 35, 35, 37, 37, - 48, 48, 48, 59, 59, 75, 75, 76, 76, 78, - 78, 78, 77, 77, 60, 60, 79, 79, 79, 80, - 80, 81, 81, 81, 43, 43, 82, 82, 82, 44, - 44, 83, 83, 84, 84, 64, 85, 85, 85, 85, - 90, 90, 91, 91, 92, 92, 92, 92, 92, 93, - 94, 94, 89, 89, 86, 86, 88, 88, 96, 96, - 95, 95, 95, 95, 95, 95, 87, 87, 98, 97, - 97, 45, 45, 39, 39, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, - 33, 33, 46, 46, 103, 103, 104, 104, 104, 104, - 110, 99, 99, 106, 106, 112, 112, 113, 114, 114, - 114, 114, 114, 114, 66, 66, 56, 56, 56, 56, - 100, 100, 118, 118, 115, 115, 119, 119, 119, 119, - 101, 101, 101, 105, 105, 105, 111, 111, 124, 124, - 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, - 124, 26, 26, 26, 26, 26, 26, 126, 126, 126, - 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, - 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, - 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, - 109, 109, 102, 102, 102, 102, 125, 125, 128, 128, - 127, 127, 129, 129, 50, 50, 50, 50, 131, 131, - 130, 130, 130, 130, 130, 132, 132, 117, 117, 120, - 120, 116, 116, 134, 133, 133, 133, 133, 121, 121, - 121, 121, 108, 108, 122, 122, 122, 122, 74, 135, - 135, 136, 136, 136, 107, 107, 137, 137, 138, 138, - 138, 138, 138, 123, 123, 123, 123, 140, 141, 139, - 139, 139, 139, 139, 139, 139, 142, 142, 142 - ); - - protected $ruleToLength = array( - 1, 1, 2, 0, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 3, 5, 4, 3, 4, - 2, 3, 1, 1, 7, 6, 3, 1, 3, 1, - 3, 1, 1, 3, 1, 3, 1, 2, 3, 1, - 3, 3, 1, 3, 2, 0, 1, 1, 1, 1, - 1, 3, 5, 8, 3, 5, 9, 3, 2, 3, - 2, 3, 2, 3, 3, 3, 3, 1, 2, 2, - 5, 7, 9, 5, 6, 3, 3, 2, 2, 1, - 1, 1, 0, 2, 8, 0, 4, 1, 3, 0, - 1, 0, 1, 10, 7, 6, 5, 1, 2, 2, - 0, 2, 0, 2, 0, 2, 1, 3, 1, 4, - 1, 4, 1, 1, 4, 1, 3, 3, 3, 4, - 4, 5, 0, 2, 4, 3, 1, 1, 1, 4, - 0, 2, 3, 0, 2, 4, 0, 2, 0, 3, - 1, 2, 1, 1, 0, 1, 3, 4, 6, 1, - 1, 1, 0, 1, 0, 2, 2, 3, 3, 1, - 3, 1, 2, 2, 3, 1, 1, 2, 4, 3, - 1, 1, 3, 2, 0, 1, 3, 3, 9, 3, - 1, 3, 0, 2, 4, 5, 4, 4, 4, 3, - 1, 1, 1, 3, 1, 1, 0, 1, 1, 2, - 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, - 3, 3, 1, 0, 1, 1, 3, 3, 4, 4, - 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 2, 2, 2, 2, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 1, 3, 5, 4, 3, 4, 4, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 1, 1, 1, 3, 2, 1, 2, 10, 11, - 3, 3, 2, 4, 4, 3, 4, 4, 4, 4, - 7, 3, 2, 0, 4, 1, 3, 2, 2, 4, - 6, 2, 2, 4, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 3, 3, 4, 4, - 0, 2, 1, 0, 1, 1, 0, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, - 2, 1, 3, 1, 4, 3, 1, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 2, 2, 2, 2, 3, 3, - 3, 3, 3, 3, 3, 3, 5, 4, 4, 3, - 1, 3, 1, 1, 3, 3, 0, 2, 0, 1, - 3, 1, 3, 1, 1, 1, 1, 1, 6, 4, - 3, 4, 2, 4, 4, 1, 3, 1, 2, 1, - 1, 4, 1, 1, 3, 6, 4, 4, 4, 4, - 1, 4, 0, 1, 1, 3, 1, 1, 4, 3, - 1, 1, 1, 0, 0, 2, 3, 1, 3, 1, - 4, 2, 2, 2, 2, 1, 2, 1, 1, 1, - 4, 3, 3, 3, 6, 3, 1, 1, 1 - ); - - protected function initReduceCallbacks() { - $this->reduceCallbacks = [ - 0 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 1 => function ($stackPos) { - $this->semValue = $this->handleNamespaces($this->semStack[$stackPos-(1-1)]); - }, - 2 => function ($stackPos) { - if (is_array($this->semStack[$stackPos-(2-2)])) { $this->semValue = array_merge($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)]); } else { $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; }; - }, - 3 => function ($stackPos) { - $this->semValue = array(); - }, - 4 => function ($stackPos) { - $startAttributes = $this->lookaheadStartAttributes; if (isset($startAttributes['comments'])) { $nop = new Stmt\Nop($this->createCommentNopAttributes($startAttributes['comments'])); } else { $nop = null; }; - if ($nop !== null) { $this->semStack[$stackPos-(1-1)][] = $nop; } $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 5 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 6 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 7 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 8 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 9 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 10 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 11 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 12 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 13 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 14 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 15 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 16 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 17 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 18 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 19 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 20 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 21 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 22 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 23 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 24 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 25 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 26 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 27 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 28 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 29 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 30 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 31 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 32 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 33 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 34 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 35 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 36 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 37 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 38 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 39 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 40 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 41 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 42 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 43 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 44 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 45 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 46 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 47 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 48 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 49 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 50 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 51 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 52 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 53 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 54 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 55 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 56 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 57 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 58 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 59 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 60 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 61 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 62 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 63 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 64 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 65 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 66 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 67 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 68 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 69 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 70 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 71 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 72 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 73 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 74 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 75 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 76 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 77 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 78 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 79 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 80 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 81 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 82 => function ($stackPos) { - $this->semValue = new Node\Identifier($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 83 => function ($stackPos) { - $this->semValue = new Node\Identifier($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 84 => function ($stackPos) { - $this->semValue = new Node\Identifier($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 85 => function ($stackPos) { - $this->semValue = new Node\Identifier($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 86 => function ($stackPos) { - $this->semValue = new Name($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 87 => function ($stackPos) { - $this->semValue = new Name($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 88 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 89 => function ($stackPos) { - $this->semValue = new Name(substr($this->semStack[$stackPos-(1-1)], 1), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 90 => function ($stackPos) { - $this->semValue = new Expr\Variable(substr($this->semStack[$stackPos-(1-1)], 1), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 91 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 92 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 93 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 94 => function ($stackPos) { - $this->semValue = new Stmt\HaltCompiler($this->lexer->handleHaltCompiler(), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 95 => function ($stackPos) { - $this->semValue = new Stmt\Namespace_($this->semStack[$stackPos-(3-2)], null, $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - $this->semValue->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON); - $this->checkNamespace($this->semValue); - }, - 96 => function ($stackPos) { - $this->semValue = new Stmt\Namespace_($this->semStack[$stackPos-(5-2)], $this->semStack[$stackPos-(5-4)], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); - $this->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); - $this->checkNamespace($this->semValue); - }, - 97 => function ($stackPos) { - $this->semValue = new Stmt\Namespace_(null, $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - $this->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); - $this->checkNamespace($this->semValue); - }, - 98 => function ($stackPos) { - $this->semValue = new Stmt\Use_($this->semStack[$stackPos-(3-2)], Stmt\Use_::TYPE_NORMAL, $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 99 => function ($stackPos) { - $this->semValue = new Stmt\Use_($this->semStack[$stackPos-(4-3)], $this->semStack[$stackPos-(4-2)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 100 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; - }, - 101 => function ($stackPos) { - $this->semValue = new Stmt\Const_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 102 => function ($stackPos) { - $this->semValue = Stmt\Use_::TYPE_FUNCTION; - }, - 103 => function ($stackPos) { - $this->semValue = Stmt\Use_::TYPE_CONSTANT; - }, - 104 => function ($stackPos) { - $this->semValue = new Stmt\GroupUse($this->semStack[$stackPos-(7-3)], $this->semStack[$stackPos-(7-6)], $this->semStack[$stackPos-(7-2)], $this->startAttributeStack[$stackPos-(7-1)] + $this->endAttributes); - }, - 105 => function ($stackPos) { - $this->semValue = new Stmt\GroupUse($this->semStack[$stackPos-(6-2)], $this->semStack[$stackPos-(6-5)], Stmt\Use_::TYPE_UNKNOWN, $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes); - }, - 106 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 107 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 108 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 109 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 110 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 111 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 112 => function ($stackPos) { - $this->semValue = new Stmt\UseUse($this->semStack[$stackPos-(1-1)], null, Stmt\Use_::TYPE_UNKNOWN, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); $this->checkUseUse($this->semValue, $stackPos-(1-1)); - }, - 113 => function ($stackPos) { - $this->semValue = new Stmt\UseUse($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], Stmt\Use_::TYPE_UNKNOWN, $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); $this->checkUseUse($this->semValue, $stackPos-(3-3)); - }, - 114 => function ($stackPos) { - $this->semValue = new Stmt\UseUse($this->semStack[$stackPos-(1-1)], null, Stmt\Use_::TYPE_UNKNOWN, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); $this->checkUseUse($this->semValue, $stackPos-(1-1)); - }, - 115 => function ($stackPos) { - $this->semValue = new Stmt\UseUse($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], Stmt\Use_::TYPE_UNKNOWN, $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); $this->checkUseUse($this->semValue, $stackPos-(3-3)); - }, - 116 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; $this->semValue->type = Stmt\Use_::TYPE_NORMAL; - }, - 117 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-2)]; $this->semValue->type = $this->semStack[$stackPos-(2-1)]; - }, - 118 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 119 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 120 => function ($stackPos) { - $this->semValue = new Node\Const_($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 121 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 122 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 123 => function ($stackPos) { - $this->semValue = new Node\Const_($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 124 => function ($stackPos) { - if (is_array($this->semStack[$stackPos-(2-2)])) { $this->semValue = array_merge($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)]); } else { $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; }; - }, - 125 => function ($stackPos) { - $this->semValue = array(); - }, - 126 => function ($stackPos) { - $startAttributes = $this->lookaheadStartAttributes; if (isset($startAttributes['comments'])) { $nop = new Stmt\Nop($this->createCommentNopAttributes($startAttributes['comments'])); } else { $nop = null; }; - if ($nop !== null) { $this->semStack[$stackPos-(1-1)][] = $nop; } $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 127 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 128 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 129 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 130 => function ($stackPos) { - throw new Error('__HALT_COMPILER() can only be used from the outermost scope', $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 131 => function ($stackPos) { - - if ($this->semStack[$stackPos-(3-2)]) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; $attrs = $this->startAttributeStack[$stackPos-(3-1)]; $stmts = $this->semValue; if (!empty($attrs['comments'])) {$stmts[0]->setAttribute('comments', array_merge($attrs['comments'], $stmts[0]->getAttribute('comments', []))); }; - } else { - $startAttributes = $this->startAttributeStack[$stackPos-(3-1)]; if (isset($startAttributes['comments'])) { $this->semValue = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $this->semValue = null; }; - if (null === $this->semValue) { $this->semValue = array(); } - } - - }, - 132 => function ($stackPos) { - $this->semValue = new Stmt\If_($this->semStack[$stackPos-(5-2)], ['stmts' => is_array($this->semStack[$stackPos-(5-3)]) ? $this->semStack[$stackPos-(5-3)] : array($this->semStack[$stackPos-(5-3)]), 'elseifs' => $this->semStack[$stackPos-(5-4)], 'else' => $this->semStack[$stackPos-(5-5)]], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); - }, - 133 => function ($stackPos) { - $this->semValue = new Stmt\If_($this->semStack[$stackPos-(8-2)], ['stmts' => $this->semStack[$stackPos-(8-4)], 'elseifs' => $this->semStack[$stackPos-(8-5)], 'else' => $this->semStack[$stackPos-(8-6)]], $this->startAttributeStack[$stackPos-(8-1)] + $this->endAttributes); - }, - 134 => function ($stackPos) { - $this->semValue = new Stmt\While_($this->semStack[$stackPos-(3-2)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 135 => function ($stackPos) { - $this->semValue = new Stmt\Do_($this->semStack[$stackPos-(5-4)], is_array($this->semStack[$stackPos-(5-2)]) ? $this->semStack[$stackPos-(5-2)] : array($this->semStack[$stackPos-(5-2)]), $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); - }, - 136 => function ($stackPos) { - $this->semValue = new Stmt\For_(['init' => $this->semStack[$stackPos-(9-3)], 'cond' => $this->semStack[$stackPos-(9-5)], 'loop' => $this->semStack[$stackPos-(9-7)], 'stmts' => $this->semStack[$stackPos-(9-9)]], $this->startAttributeStack[$stackPos-(9-1)] + $this->endAttributes); - }, - 137 => function ($stackPos) { - $this->semValue = new Stmt\Switch_($this->semStack[$stackPos-(3-2)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 138 => function ($stackPos) { - $this->semValue = new Stmt\Break_(null, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 139 => function ($stackPos) { - $this->semValue = new Stmt\Break_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 140 => function ($stackPos) { - $this->semValue = new Stmt\Continue_(null, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 141 => function ($stackPos) { - $this->semValue = new Stmt\Continue_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 142 => function ($stackPos) { - $this->semValue = new Stmt\Return_(null, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 143 => function ($stackPos) { - $this->semValue = new Stmt\Return_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 144 => function ($stackPos) { - $this->semValue = new Stmt\Global_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 145 => function ($stackPos) { - $this->semValue = new Stmt\Static_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 146 => function ($stackPos) { - $this->semValue = new Stmt\Echo_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 147 => function ($stackPos) { - $this->semValue = new Stmt\InlineHTML($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 148 => function ($stackPos) { - $this->semValue = new Stmt\Expression($this->semStack[$stackPos-(2-1)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 149 => function ($stackPos) { - $this->semValue = new Stmt\Expression($this->semStack[$stackPos-(2-1)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 150 => function ($stackPos) { - $this->semValue = new Stmt\Unset_($this->semStack[$stackPos-(5-3)], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); - }, - 151 => function ($stackPos) { - $this->semValue = new Stmt\Foreach_($this->semStack[$stackPos-(7-3)], $this->semStack[$stackPos-(7-5)][0], ['keyVar' => null, 'byRef' => $this->semStack[$stackPos-(7-5)][1], 'stmts' => $this->semStack[$stackPos-(7-7)]], $this->startAttributeStack[$stackPos-(7-1)] + $this->endAttributes); - }, - 152 => function ($stackPos) { - $this->semValue = new Stmt\Foreach_($this->semStack[$stackPos-(9-3)], $this->semStack[$stackPos-(9-7)][0], ['keyVar' => $this->semStack[$stackPos-(9-5)], 'byRef' => $this->semStack[$stackPos-(9-7)][1], 'stmts' => $this->semStack[$stackPos-(9-9)]], $this->startAttributeStack[$stackPos-(9-1)] + $this->endAttributes); - }, - 153 => function ($stackPos) { - $this->semValue = new Stmt\Declare_($this->semStack[$stackPos-(5-3)], $this->semStack[$stackPos-(5-5)], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); - }, - 154 => function ($stackPos) { - $this->semValue = new Stmt\TryCatch($this->semStack[$stackPos-(6-3)], $this->semStack[$stackPos-(6-5)], $this->semStack[$stackPos-(6-6)], $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes); $this->checkTryCatch($this->semValue); - }, - 155 => function ($stackPos) { - $this->semValue = new Stmt\Throw_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 156 => function ($stackPos) { - $this->semValue = new Stmt\Goto_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 157 => function ($stackPos) { - $this->semValue = new Stmt\Label($this->semStack[$stackPos-(2-1)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 158 => function ($stackPos) { - $this->semValue = new Stmt\Expression($this->semStack[$stackPos-(2-1)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 159 => function ($stackPos) { - $this->semValue = array(); /* means: no statement */ - }, - 160 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 161 => function ($stackPos) { - $startAttributes = $this->startAttributeStack[$stackPos-(1-1)]; if (isset($startAttributes['comments'])) { $this->semValue = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $this->semValue = null; }; - if ($this->semValue === null) $this->semValue = array(); /* means: no statement */ - }, - 162 => function ($stackPos) { - $this->semValue = array(); - }, - 163 => function ($stackPos) { - $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; - }, - 164 => function ($stackPos) { - $this->semValue = new Stmt\Catch_(array($this->semStack[$stackPos-(8-3)]), $this->semStack[$stackPos-(8-4)], $this->semStack[$stackPos-(8-7)], $this->startAttributeStack[$stackPos-(8-1)] + $this->endAttributes); - }, - 165 => function ($stackPos) { - $this->semValue = null; - }, - 166 => function ($stackPos) { - $this->semValue = new Stmt\Finally_($this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 167 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 168 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 169 => function ($stackPos) { - $this->semValue = false; - }, - 170 => function ($stackPos) { - $this->semValue = true; - }, - 171 => function ($stackPos) { - $this->semValue = false; - }, - 172 => function ($stackPos) { - $this->semValue = true; - }, - 173 => function ($stackPos) { - $this->semValue = new Stmt\Function_($this->semStack[$stackPos-(10-3)], ['byRef' => $this->semStack[$stackPos-(10-2)], 'params' => $this->semStack[$stackPos-(10-5)], 'returnType' => $this->semStack[$stackPos-(10-7)], 'stmts' => $this->semStack[$stackPos-(10-9)]], $this->startAttributeStack[$stackPos-(10-1)] + $this->endAttributes); - }, - 174 => function ($stackPos) { - $this->semValue = new Stmt\Class_($this->semStack[$stackPos-(7-2)], ['type' => $this->semStack[$stackPos-(7-1)], 'extends' => $this->semStack[$stackPos-(7-3)], 'implements' => $this->semStack[$stackPos-(7-4)], 'stmts' => $this->semStack[$stackPos-(7-6)]], $this->startAttributeStack[$stackPos-(7-1)] + $this->endAttributes); - $this->checkClass($this->semValue, $stackPos-(7-2)); - }, - 175 => function ($stackPos) { - $this->semValue = new Stmt\Interface_($this->semStack[$stackPos-(6-2)], ['extends' => $this->semStack[$stackPos-(6-3)], 'stmts' => $this->semStack[$stackPos-(6-5)]], $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes); - $this->checkInterface($this->semValue, $stackPos-(6-2)); - }, - 176 => function ($stackPos) { - $this->semValue = new Stmt\Trait_($this->semStack[$stackPos-(5-2)], ['stmts' => $this->semStack[$stackPos-(5-4)]], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); - }, - 177 => function ($stackPos) { - $this->semValue = 0; - }, - 178 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_ABSTRACT; - }, - 179 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_FINAL; - }, - 180 => function ($stackPos) { - $this->semValue = null; - }, - 181 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-2)]; - }, - 182 => function ($stackPos) { - $this->semValue = array(); - }, - 183 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-2)]; - }, - 184 => function ($stackPos) { - $this->semValue = array(); - }, - 185 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-2)]; - }, - 186 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 187 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 188 => function ($stackPos) { - $this->semValue = is_array($this->semStack[$stackPos-(1-1)]) ? $this->semStack[$stackPos-(1-1)] : array($this->semStack[$stackPos-(1-1)]); - }, - 189 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(4-2)]; - }, - 190 => function ($stackPos) { - $this->semValue = is_array($this->semStack[$stackPos-(1-1)]) ? $this->semStack[$stackPos-(1-1)] : array($this->semStack[$stackPos-(1-1)]); - }, - 191 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(4-2)]; - }, - 192 => function ($stackPos) { - $this->semValue = is_array($this->semStack[$stackPos-(1-1)]) ? $this->semStack[$stackPos-(1-1)] : array($this->semStack[$stackPos-(1-1)]); - }, - 193 => function ($stackPos) { - $this->semValue = null; - }, - 194 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(4-2)]; - }, - 195 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 196 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 197 => function ($stackPos) { - $this->semValue = new Stmt\DeclareDeclare($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 198 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; - }, - 199 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(4-3)]; - }, - 200 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(4-2)]; - }, - 201 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(5-3)]; - }, - 202 => function ($stackPos) { - $this->semValue = array(); - }, - 203 => function ($stackPos) { - $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; - }, - 204 => function ($stackPos) { - $this->semValue = new Stmt\Case_($this->semStack[$stackPos-(4-2)], $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 205 => function ($stackPos) { - $this->semValue = new Stmt\Case_(null, $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 206 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 207 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 208 => function ($stackPos) { - $this->semValue = is_array($this->semStack[$stackPos-(1-1)]) ? $this->semStack[$stackPos-(1-1)] : array($this->semStack[$stackPos-(1-1)]); - }, - 209 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(4-2)]; - }, - 210 => function ($stackPos) { - $this->semValue = array(); - }, - 211 => function ($stackPos) { - $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; - }, - 212 => function ($stackPos) { - $this->semValue = new Stmt\ElseIf_($this->semStack[$stackPos-(3-2)], is_array($this->semStack[$stackPos-(3-3)]) ? $this->semStack[$stackPos-(3-3)] : array($this->semStack[$stackPos-(3-3)]), $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 213 => function ($stackPos) { - $this->semValue = array(); - }, - 214 => function ($stackPos) { - $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; - }, - 215 => function ($stackPos) { - $this->semValue = new Stmt\ElseIf_($this->semStack[$stackPos-(4-2)], $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 216 => function ($stackPos) { - $this->semValue = null; - }, - 217 => function ($stackPos) { - $this->semValue = new Stmt\Else_(is_array($this->semStack[$stackPos-(2-2)]) ? $this->semStack[$stackPos-(2-2)] : array($this->semStack[$stackPos-(2-2)]), $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 218 => function ($stackPos) { - $this->semValue = null; - }, - 219 => function ($stackPos) { - $this->semValue = new Stmt\Else_($this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 220 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)], false); - }, - 221 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(2-2)], true); - }, - 222 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)], false); - }, - 223 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 224 => function ($stackPos) { - $this->semValue = array(); - }, - 225 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 226 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 227 => function ($stackPos) { - $this->semValue = new Node\Param($this->semStack[$stackPos-(4-4)], null, $this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-2)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); $this->checkParam($this->semValue); - }, - 228 => function ($stackPos) { - $this->semValue = new Node\Param($this->semStack[$stackPos-(6-4)], $this->semStack[$stackPos-(6-6)], $this->semStack[$stackPos-(6-1)], $this->semStack[$stackPos-(6-2)], $this->semStack[$stackPos-(6-3)], $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes); $this->checkParam($this->semValue); - }, - 229 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 230 => function ($stackPos) { - $this->semValue = new Node\Identifier('array', $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 231 => function ($stackPos) { - $this->semValue = new Node\Identifier('callable', $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 232 => function ($stackPos) { - $this->semValue = null; - }, - 233 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 234 => function ($stackPos) { - $this->semValue = null; - }, - 235 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-2)]; - }, - 236 => function ($stackPos) { - $this->semValue = array(); - }, - 237 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; - }, - 238 => function ($stackPos) { - $this->semValue = array(new Node\Arg($this->semStack[$stackPos-(3-2)], false, false, $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes)); - }, - 239 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 240 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 241 => function ($stackPos) { - $this->semValue = new Node\Arg($this->semStack[$stackPos-(1-1)], false, false, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 242 => function ($stackPos) { - $this->semValue = new Node\Arg($this->semStack[$stackPos-(2-2)], true, false, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 243 => function ($stackPos) { - $this->semValue = new Node\Arg($this->semStack[$stackPos-(2-2)], false, true, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 244 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 245 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 246 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 247 => function ($stackPos) { - $this->semValue = new Expr\Variable($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 248 => function ($stackPos) { - $this->semValue = new Expr\Variable($this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 249 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 250 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 251 => function ($stackPos) { - $this->semValue = new Stmt\StaticVar($this->semStack[$stackPos-(1-1)], null, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 252 => function ($stackPos) { - $this->semValue = new Stmt\StaticVar($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 253 => function ($stackPos) { - if ($this->semStack[$stackPos-(2-2)] !== null) { $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; } - }, - 254 => function ($stackPos) { - $this->semValue = array(); - }, - 255 => function ($stackPos) { - $startAttributes = $this->lookaheadStartAttributes; if (isset($startAttributes['comments'])) { $nop = new Stmt\Nop($this->createCommentNopAttributes($startAttributes['comments'])); } else { $nop = null; }; - if ($nop !== null) { $this->semStack[$stackPos-(1-1)][] = $nop; } $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 256 => function ($stackPos) { - $this->semValue = new Stmt\Property($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); $this->checkProperty($this->semValue, $stackPos-(3-1)); - }, - 257 => function ($stackPos) { - $this->semValue = new Stmt\ClassConst($this->semStack[$stackPos-(3-2)], 0, $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 258 => function ($stackPos) { - $this->semValue = new Stmt\ClassMethod($this->semStack[$stackPos-(9-4)], ['type' => $this->semStack[$stackPos-(9-1)], 'byRef' => $this->semStack[$stackPos-(9-3)], 'params' => $this->semStack[$stackPos-(9-6)], 'returnType' => $this->semStack[$stackPos-(9-8)], 'stmts' => $this->semStack[$stackPos-(9-9)]], $this->startAttributeStack[$stackPos-(9-1)] + $this->endAttributes); - $this->checkClassMethod($this->semValue, $stackPos-(9-1)); - }, - 259 => function ($stackPos) { - $this->semValue = new Stmt\TraitUse($this->semStack[$stackPos-(3-2)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 260 => function ($stackPos) { - $this->semValue = array(); - }, - 261 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; - }, - 262 => function ($stackPos) { - $this->semValue = array(); - }, - 263 => function ($stackPos) { - $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; - }, - 264 => function ($stackPos) { - $this->semValue = new Stmt\TraitUseAdaptation\Precedence($this->semStack[$stackPos-(4-1)][0], $this->semStack[$stackPos-(4-1)][1], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 265 => function ($stackPos) { - $this->semValue = new Stmt\TraitUseAdaptation\Alias($this->semStack[$stackPos-(5-1)][0], $this->semStack[$stackPos-(5-1)][1], $this->semStack[$stackPos-(5-3)], $this->semStack[$stackPos-(5-4)], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); - }, - 266 => function ($stackPos) { - $this->semValue = new Stmt\TraitUseAdaptation\Alias($this->semStack[$stackPos-(4-1)][0], $this->semStack[$stackPos-(4-1)][1], $this->semStack[$stackPos-(4-3)], null, $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 267 => function ($stackPos) { - $this->semValue = new Stmt\TraitUseAdaptation\Alias($this->semStack[$stackPos-(4-1)][0], $this->semStack[$stackPos-(4-1)][1], null, $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 268 => function ($stackPos) { - $this->semValue = new Stmt\TraitUseAdaptation\Alias($this->semStack[$stackPos-(4-1)][0], $this->semStack[$stackPos-(4-1)][1], null, $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 269 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)]); - }, - 270 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 271 => function ($stackPos) { - $this->semValue = array(null, $this->semStack[$stackPos-(1-1)]); - }, - 272 => function ($stackPos) { - $this->semValue = null; - }, - 273 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; - }, - 274 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 275 => function ($stackPos) { - $this->semValue = 0; - }, - 276 => function ($stackPos) { - $this->semValue = 0; - }, - 277 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 278 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 279 => function ($stackPos) { - $this->checkModifier($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $this->semValue = $this->semStack[$stackPos-(2-1)] | $this->semStack[$stackPos-(2-2)]; - }, - 280 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_PUBLIC; - }, - 281 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_PROTECTED; - }, - 282 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_PRIVATE; - }, - 283 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_STATIC; - }, - 284 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_ABSTRACT; - }, - 285 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_FINAL; - }, - 286 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 287 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 288 => function ($stackPos) { - $this->semValue = new Node\VarLikeIdentifier(substr($this->semStack[$stackPos-(1-1)], 1), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 289 => function ($stackPos) { - $this->semValue = new Stmt\PropertyProperty($this->semStack[$stackPos-(1-1)], null, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 290 => function ($stackPos) { - $this->semValue = new Stmt\PropertyProperty($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 291 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 292 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 293 => function ($stackPos) { - $this->semValue = array(); - }, - 294 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 295 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 296 => function ($stackPos) { - $this->semValue = new Expr\Assign($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 297 => function ($stackPos) { - $this->semValue = new Expr\Assign($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 298 => function ($stackPos) { - $this->semValue = new Expr\AssignRef($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 299 => function ($stackPos) { - $this->semValue = new Expr\AssignRef($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 300 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 301 => function ($stackPos) { - $this->semValue = new Expr\Clone_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 302 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Plus($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 303 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Minus($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 304 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Mul($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 305 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Div($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 306 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Concat($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 307 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Mod($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 308 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\BitwiseAnd($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 309 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\BitwiseOr($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 310 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\BitwiseXor($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 311 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\ShiftLeft($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 312 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\ShiftRight($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 313 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Pow($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 314 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Coalesce($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 315 => function ($stackPos) { - $this->semValue = new Expr\PostInc($this->semStack[$stackPos-(2-1)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 316 => function ($stackPos) { - $this->semValue = new Expr\PreInc($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 317 => function ($stackPos) { - $this->semValue = new Expr\PostDec($this->semStack[$stackPos-(2-1)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 318 => function ($stackPos) { - $this->semValue = new Expr\PreDec($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 319 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\BooleanOr($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 320 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\BooleanAnd($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 321 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\LogicalOr($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 322 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\LogicalAnd($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 323 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\LogicalXor($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 324 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\BitwiseOr($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 325 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\BitwiseAnd($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 326 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\BitwiseXor($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 327 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Concat($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 328 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Plus($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 329 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Minus($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 330 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Mul($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 331 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Div($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 332 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Mod($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 333 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\ShiftLeft($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 334 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\ShiftRight($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 335 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Pow($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 336 => function ($stackPos) { - $this->semValue = new Expr\UnaryPlus($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 337 => function ($stackPos) { - $this->semValue = new Expr\UnaryMinus($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 338 => function ($stackPos) { - $this->semValue = new Expr\BooleanNot($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 339 => function ($stackPos) { - $this->semValue = new Expr\BitwiseNot($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 340 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Identical($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 341 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\NotIdentical($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 342 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Equal($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 343 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\NotEqual($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 344 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Spaceship($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 345 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Smaller($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 346 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\SmallerOrEqual($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 347 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Greater($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 348 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\GreaterOrEqual($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 349 => function ($stackPos) { - $this->semValue = new Expr\Instanceof_($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 350 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 351 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; - }, - 352 => function ($stackPos) { - $this->semValue = new Expr\Ternary($this->semStack[$stackPos-(5-1)], $this->semStack[$stackPos-(5-3)], $this->semStack[$stackPos-(5-5)], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); - }, - 353 => function ($stackPos) { - $this->semValue = new Expr\Ternary($this->semStack[$stackPos-(4-1)], null, $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 354 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Coalesce($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 355 => function ($stackPos) { - $this->semValue = new Expr\Isset_($this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 356 => function ($stackPos) { - $this->semValue = new Expr\Empty_($this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 357 => function ($stackPos) { - $this->semValue = new Expr\Include_($this->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_INCLUDE, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 358 => function ($stackPos) { - $this->semValue = new Expr\Include_($this->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_INCLUDE_ONCE, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 359 => function ($stackPos) { - $this->semValue = new Expr\Eval_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 360 => function ($stackPos) { - $this->semValue = new Expr\Include_($this->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_REQUIRE, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 361 => function ($stackPos) { - $this->semValue = new Expr\Include_($this->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_REQUIRE_ONCE, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 362 => function ($stackPos) { - $this->semValue = new Expr\Cast\Int_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 363 => function ($stackPos) { - $attrs = $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes; - $attrs['kind'] = $this->getFloatCastKind($this->semStack[$stackPos-(2-1)]); - $this->semValue = new Expr\Cast\Double($this->semStack[$stackPos-(2-2)], $attrs); - }, - 364 => function ($stackPos) { - $this->semValue = new Expr\Cast\String_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 365 => function ($stackPos) { - $this->semValue = new Expr\Cast\Array_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 366 => function ($stackPos) { - $this->semValue = new Expr\Cast\Object_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 367 => function ($stackPos) { - $this->semValue = new Expr\Cast\Bool_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 368 => function ($stackPos) { - $this->semValue = new Expr\Cast\Unset_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 369 => function ($stackPos) { - $attrs = $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes; - $attrs['kind'] = strtolower($this->semStack[$stackPos-(2-1)]) === 'exit' ? Expr\Exit_::KIND_EXIT : Expr\Exit_::KIND_DIE; - $this->semValue = new Expr\Exit_($this->semStack[$stackPos-(2-2)], $attrs); - }, - 370 => function ($stackPos) { - $this->semValue = new Expr\ErrorSuppress($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 371 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 372 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 373 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 374 => function ($stackPos) { - $this->semValue = new Expr\ShellExec($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 375 => function ($stackPos) { - $this->semValue = new Expr\Print_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 376 => function ($stackPos) { - $this->semValue = new Expr\Yield_(null, null, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 377 => function ($stackPos) { - $this->semValue = new Expr\YieldFrom($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 378 => function ($stackPos) { - $this->semValue = new Expr\Closure(['static' => false, 'byRef' => $this->semStack[$stackPos-(10-2)], 'params' => $this->semStack[$stackPos-(10-4)], 'uses' => $this->semStack[$stackPos-(10-6)], 'returnType' => $this->semStack[$stackPos-(10-7)], 'stmts' => $this->semStack[$stackPos-(10-9)]], $this->startAttributeStack[$stackPos-(10-1)] + $this->endAttributes); - }, - 379 => function ($stackPos) { - $this->semValue = new Expr\Closure(['static' => true, 'byRef' => $this->semStack[$stackPos-(11-3)], 'params' => $this->semStack[$stackPos-(11-5)], 'uses' => $this->semStack[$stackPos-(11-7)], 'returnType' => $this->semStack[$stackPos-(11-8)], 'stmts' => $this->semStack[$stackPos-(11-10)]], $this->startAttributeStack[$stackPos-(11-1)] + $this->endAttributes); - }, - 380 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; - }, - 381 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; - }, - 382 => function ($stackPos) { - $this->semValue = new Expr\Yield_($this->semStack[$stackPos-(2-2)], null, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 383 => function ($stackPos) { - $this->semValue = new Expr\Yield_($this->semStack[$stackPos-(4-4)], $this->semStack[$stackPos-(4-2)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 384 => function ($stackPos) { - $attrs = $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes; $attrs['kind'] = Expr\Array_::KIND_LONG; - $this->semValue = new Expr\Array_($this->semStack[$stackPos-(4-3)], $attrs); - }, - 385 => function ($stackPos) { - $attrs = $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes; $attrs['kind'] = Expr\Array_::KIND_SHORT; - $this->semValue = new Expr\Array_($this->semStack[$stackPos-(3-2)], $attrs); - }, - 386 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 387 => function ($stackPos) { - $attrs = $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes; $attrs['kind'] = ($this->semStack[$stackPos-(4-1)][0] === "'" || ($this->semStack[$stackPos-(4-1)][1] === "'" && ($this->semStack[$stackPos-(4-1)][0] === 'b' || $this->semStack[$stackPos-(4-1)][0] === 'B')) ? Scalar\String_::KIND_SINGLE_QUOTED : Scalar\String_::KIND_DOUBLE_QUOTED); - $this->semValue = new Expr\ArrayDimFetch(new Scalar\String_(Scalar\String_::parse($this->semStack[$stackPos-(4-1)]), $attrs), $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 388 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 389 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 390 => function ($stackPos) { - $this->semValue = array(new Stmt\Class_(null, ['type' => 0, 'extends' => $this->semStack[$stackPos-(7-3)], 'implements' => $this->semStack[$stackPos-(7-4)], 'stmts' => $this->semStack[$stackPos-(7-6)]], $this->startAttributeStack[$stackPos-(7-1)] + $this->endAttributes), $this->semStack[$stackPos-(7-2)]); - $this->checkClass($this->semValue[0], -1); - }, - 391 => function ($stackPos) { - $this->semValue = new Expr\New_($this->semStack[$stackPos-(3-2)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 392 => function ($stackPos) { - list($class, $ctorArgs) = $this->semStack[$stackPos-(2-2)]; $this->semValue = new Expr\New_($class, $ctorArgs, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 393 => function ($stackPos) { - $this->semValue = array(); - }, - 394 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(4-3)]; - }, - 395 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 396 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 397 => function ($stackPos) { - $this->semValue = new Expr\ClosureUse($this->semStack[$stackPos-(2-2)], $this->semStack[$stackPos-(2-1)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 398 => function ($stackPos) { - $this->semValue = new Expr\FuncCall($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 399 => function ($stackPos) { - $this->semValue = new Expr\StaticCall($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 400 => function ($stackPos) { - $this->semValue = new Expr\StaticCall($this->semStack[$stackPos-(6-1)], $this->semStack[$stackPos-(6-4)], $this->semStack[$stackPos-(6-6)], $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes); - }, - 401 => function ($stackPos) { - $this->semValue = $this->fixupPhp5StaticPropCall($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 402 => function ($stackPos) { - $this->semValue = new Expr\FuncCall($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 403 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 404 => function ($stackPos) { - $this->semValue = new Name($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 405 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 406 => function ($stackPos) { - $this->semValue = new Name($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 407 => function ($stackPos) { - $this->semValue = new Name($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 408 => function ($stackPos) { - $this->semValue = new Name\FullyQualified(substr($this->semStack[$stackPos-(1-1)], 1), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 409 => function ($stackPos) { - $this->semValue = new Name\Relative(substr($this->semStack[$stackPos-(1-1)], 10), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 410 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 411 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 412 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 413 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 414 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 415 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 416 => function ($stackPos) { - $this->semValue = new Expr\PropertyFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 417 => function ($stackPos) { - $this->semValue = new Expr\PropertyFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 418 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 419 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 420 => function ($stackPos) { - $this->semValue = null; - }, - 421 => function ($stackPos) { - $this->semValue = null; - }, - 422 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 423 => function ($stackPos) { - $this->semValue = array(); - }, - 424 => function ($stackPos) { - $this->semValue = array(new Scalar\EncapsedStringPart(Scalar\String_::parseEscapeSequences($this->semStack[$stackPos-(1-1)], '`', false), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes)); - }, - 425 => function ($stackPos) { - foreach ($this->semStack[$stackPos-(1-1)] as $s) { if ($s instanceof Node\Scalar\EncapsedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '`', false); } }; $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 426 => function ($stackPos) { - $this->semValue = array(); - }, - 427 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 428 => function ($stackPos) { - $this->semValue = $this->parseLNumber($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes, true); - }, - 429 => function ($stackPos) { - $this->semValue = new Scalar\DNumber(Scalar\DNumber::parse($this->semStack[$stackPos-(1-1)]), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 430 => function ($stackPos) { - $attrs = $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes; $attrs['kind'] = ($this->semStack[$stackPos-(1-1)][0] === "'" || ($this->semStack[$stackPos-(1-1)][1] === "'" && ($this->semStack[$stackPos-(1-1)][0] === 'b' || $this->semStack[$stackPos-(1-1)][0] === 'B')) ? Scalar\String_::KIND_SINGLE_QUOTED : Scalar\String_::KIND_DOUBLE_QUOTED); - $this->semValue = new Scalar\String_(Scalar\String_::parse($this->semStack[$stackPos-(1-1)], false), $attrs); - }, - 431 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\Line($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 432 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\File($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 433 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\Dir($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 434 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\Class_($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 435 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\Trait_($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 436 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\Method($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 437 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\Function_($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 438 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\Namespace_($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 439 => function ($stackPos) { - $this->semValue = $this->parseDocString($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-2)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes, $this->startAttributeStack[$stackPos-(3-3)] + $this->endAttributeStack[$stackPos-(3-3)], false); - }, - 440 => function ($stackPos) { - $this->semValue = $this->parseDocString($this->semStack[$stackPos-(2-1)], '', $this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes, $this->startAttributeStack[$stackPos-(2-2)] + $this->endAttributeStack[$stackPos-(2-2)], false); - }, - 441 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 442 => function ($stackPos) { - $this->semValue = new Expr\ClassConstFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 443 => function ($stackPos) { - $this->semValue = new Expr\ConstFetch($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 444 => function ($stackPos) { - $this->semValue = new Expr\Array_($this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 445 => function ($stackPos) { - $this->semValue = new Expr\Array_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 446 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 447 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\BooleanOr($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 448 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\BooleanAnd($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 449 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\LogicalOr($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 450 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\LogicalAnd($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 451 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\LogicalXor($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 452 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\BitwiseOr($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 453 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\BitwiseAnd($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 454 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\BitwiseXor($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 455 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Concat($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 456 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Plus($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 457 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Minus($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 458 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Mul($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 459 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Div($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 460 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Mod($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 461 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\ShiftLeft($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 462 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\ShiftRight($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 463 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Pow($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 464 => function ($stackPos) { - $this->semValue = new Expr\UnaryPlus($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 465 => function ($stackPos) { - $this->semValue = new Expr\UnaryMinus($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 466 => function ($stackPos) { - $this->semValue = new Expr\BooleanNot($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 467 => function ($stackPos) { - $this->semValue = new Expr\BitwiseNot($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 468 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Identical($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 469 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\NotIdentical($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 470 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Equal($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 471 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\NotEqual($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 472 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Smaller($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 473 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\SmallerOrEqual($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 474 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Greater($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 475 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\GreaterOrEqual($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 476 => function ($stackPos) { - $this->semValue = new Expr\Ternary($this->semStack[$stackPos-(5-1)], $this->semStack[$stackPos-(5-3)], $this->semStack[$stackPos-(5-5)], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); - }, - 477 => function ($stackPos) { - $this->semValue = new Expr\Ternary($this->semStack[$stackPos-(4-1)], null, $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 478 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 479 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; - }, - 480 => function ($stackPos) { - $this->semValue = new Expr\ConstFetch($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 481 => function ($stackPos) { - $this->semValue = new Expr\ClassConstFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 482 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 483 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 484 => function ($stackPos) { - $attrs = $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes; $attrs['kind'] = Scalar\String_::KIND_DOUBLE_QUOTED; - foreach ($this->semStack[$stackPos-(3-2)] as $s) { if ($s instanceof Node\Scalar\EncapsedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '"', true); } }; $this->semValue = new Scalar\Encapsed($this->semStack[$stackPos-(3-2)], $attrs); - }, - 485 => function ($stackPos) { - $this->semValue = $this->parseDocString($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-2)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes, $this->startAttributeStack[$stackPos-(3-3)] + $this->endAttributeStack[$stackPos-(3-3)], true); - }, - 486 => function ($stackPos) { - $this->semValue = array(); - }, - 487 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; - }, - 488 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 489 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 490 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 491 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 492 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(3-3)], $this->semStack[$stackPos-(3-1)], false, $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 493 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(1-1)], null, false, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 494 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 495 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 496 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 497 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 498 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(6-2)], $this->semStack[$stackPos-(6-5)], $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes); - }, - 499 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 500 => function ($stackPos) { - $this->semValue = new Expr\PropertyFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 501 => function ($stackPos) { - $this->semValue = new Expr\MethodCall($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 502 => function ($stackPos) { - $this->semValue = new Expr\FuncCall($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 503 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 504 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 505 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 506 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; - }, - 507 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 508 => function ($stackPos) { - $this->semValue = new Expr\Variable($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 509 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 510 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 511 => function ($stackPos) { - $this->semValue = new Expr\StaticPropertyFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 512 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 513 => function ($stackPos) { - $var = substr($this->semStack[$stackPos-(1-1)], 1); $this->semValue = \is_string($var) ? new Node\VarLikeIdentifier($var, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes) : $var; - }, - 514 => function ($stackPos) { - $this->semValue = new Expr\StaticPropertyFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 515 => function ($stackPos) { - $this->semValue = new Expr\StaticPropertyFetch($this->semStack[$stackPos-(6-1)], $this->semStack[$stackPos-(6-5)], $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes); - }, - 516 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 517 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 518 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 519 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 520 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 521 => function ($stackPos) { - $this->semValue = new Expr\Variable($this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 522 => function ($stackPos) { - $this->semValue = null; - }, - 523 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 524 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 525 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; - }, - 526 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 527 => function ($stackPos) { - $this->semValue = new Expr\Error($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); $this->errorState = 2; - }, - 528 => function ($stackPos) { - $this->semValue = new Expr\List_($this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 529 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 530 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 531 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(1-1)], null, false, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 532 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(1-1)], null, false, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 533 => function ($stackPos) { - $this->semValue = null; - }, - 534 => function ($stackPos) { - $this->semValue = array(); - }, - 535 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; - }, - 536 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; - }, - 537 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 538 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(3-3)], $this->semStack[$stackPos-(3-1)], false, $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 539 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(1-1)], null, false, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 540 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(4-4)], $this->semStack[$stackPos-(4-1)], true, $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 541 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(2-2)], null, true, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 542 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(2-2)], null, false, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes, true, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - }, - 543 => function ($stackPos) { - $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; - }, - 544 => function ($stackPos) { - $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; - }, - 545 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); - }, - 546 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)]); - }, - 547 => function ($stackPos) { - $this->semValue = new Scalar\EncapsedStringPart($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 548 => function ($stackPos) { - $this->semValue = new Expr\Variable($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 549 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 550 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - }, - 551 => function ($stackPos) { - $this->semValue = new Expr\PropertyFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 552 => function ($stackPos) { - $this->semValue = new Expr\Variable($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 553 => function ($stackPos) { - $this->semValue = new Expr\Variable($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 554 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(6-2)], $this->semStack[$stackPos-(6-4)], $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes); - }, - 555 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; - }, - 556 => function ($stackPos) { - $this->semValue = new Scalar\String_($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 557 => function ($stackPos) { - $this->semValue = $this->parseNumString($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 558 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - ]; - } -} diff --git a/lib/PhpParser/Parser/Php7.php b/lib/PhpParser/Parser/Php7.php index 3d09a65804..7784e8806c 100644 --- a/lib/PhpParser/Parser/Php7.php +++ b/lib/PhpParser/Parser/Php7.php @@ -1,8 +1,9 @@ -reduceCallbacks = [ - 0 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 1 => function ($stackPos) { - $this->semValue = $this->handleNamespaces($this->semStack[$stackPos-(1-1)]); - }, - 2 => function ($stackPos) { - if (is_array($this->semStack[$stackPos-(2-2)])) { $this->semValue = array_merge($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)]); } else { $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; }; - }, - 3 => function ($stackPos) { - $this->semValue = array(); - }, - 4 => function ($stackPos) { - $startAttributes = $this->lookaheadStartAttributes; if (isset($startAttributes['comments'])) { $nop = new Stmt\Nop($this->createCommentNopAttributes($startAttributes['comments'])); } else { $nop = null; }; - if ($nop !== null) { $this->semStack[$stackPos-(1-1)][] = $nop; } $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 5 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 6 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 7 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 8 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 9 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 10 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 11 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 12 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 13 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 14 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 15 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 16 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 17 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 18 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 19 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 20 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 21 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 22 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 23 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 24 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 25 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 26 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 27 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 28 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 29 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 30 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 31 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 32 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 33 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 34 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 35 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 36 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 37 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 38 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 39 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 40 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 41 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 42 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 43 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 44 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 45 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 46 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 47 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 48 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 49 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 50 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 51 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 52 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 53 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 54 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 55 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 56 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 57 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 58 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 59 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 60 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 61 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 62 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 63 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 64 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 65 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 66 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 67 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 68 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 69 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 70 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 71 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 72 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 73 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 74 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 75 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 76 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 77 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 78 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 79 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 80 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 81 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; - }, - 82 => function ($stackPos) { - $this->semValue = new Node\Identifier($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 83 => function ($stackPos) { - $this->semValue = new Node\Identifier($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 84 => function ($stackPos) { - $this->semValue = new Node\Identifier($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 85 => function ($stackPos) { - $this->semValue = new Node\Identifier($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 86 => function ($stackPos) { - $this->semValue = new Name($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 87 => function ($stackPos) { - $this->semValue = new Name($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 88 => function ($stackPos) { - $this->semValue = new Name($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 89 => function ($stackPos) { - $this->semValue = new Name($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 90 => function ($stackPos) { - $this->semValue = new Name($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 91 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; - }, - 92 => function ($stackPos) { - $this->semValue = new Name(substr($this->semStack[$stackPos-(1-1)], 1), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 93 => function ($stackPos) { - $this->semValue = new Expr\Variable(substr($this->semStack[$stackPos-(1-1)], 1), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 94 => function ($stackPos) { + 0 => null, + 1 => static function ($self, $stackPos) { + $self->semValue = $self->handleNamespaces($self->semStack[$stackPos-(1-1)]); + }, + 2 => static function ($self, $stackPos) { + if ($self->semStack[$stackPos-(2-2)] !== null) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; } $self->semValue = $self->semStack[$stackPos-(2-1)];; + }, + 3 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 4 => static function ($self, $stackPos) { + $nop = $self->maybeCreateZeroLengthNop($self->tokenPos);; + if ($nop !== null) { $self->semStack[$stackPos-(1-1)][] = $nop; } $self->semValue = $self->semStack[$stackPos-(1-1)]; + }, + 5 => null, + 6 => null, + 7 => null, + 8 => null, + 9 => null, + 10 => null, + 11 => null, + 12 => null, + 13 => null, + 14 => null, + 15 => null, + 16 => null, + 17 => null, + 18 => null, + 19 => null, + 20 => null, + 21 => null, + 22 => null, + 23 => null, + 24 => null, + 25 => null, + 26 => null, + 27 => null, + 28 => null, + 29 => null, + 30 => null, + 31 => null, + 32 => null, + 33 => null, + 34 => null, + 35 => null, + 36 => null, + 37 => null, + 38 => null, + 39 => null, + 40 => null, + 41 => null, + 42 => null, + 43 => null, + 44 => null, + 45 => null, + 46 => null, + 47 => null, + 48 => null, + 49 => null, + 50 => null, + 51 => null, + 52 => null, + 53 => null, + 54 => null, + 55 => null, + 56 => null, + 57 => null, + 58 => null, + 59 => null, + 60 => null, + 61 => null, + 62 => null, + 63 => null, + 64 => null, + 65 => null, + 66 => null, + 67 => null, + 68 => null, + 69 => null, + 70 => null, + 71 => null, + 72 => null, + 73 => null, + 74 => null, + 75 => null, + 76 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(1-1)]; if ($self->semValue === "emitError(new Error('Cannot use "getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]))); + }, + 77 => null, + 78 => null, + 79 => null, + 80 => null, + 81 => null, + 82 => null, + 83 => null, + 84 => null, + 85 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 86 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 87 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 88 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 89 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 90 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 91 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 92 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 93 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 94 => null, + 95 => static function ($self, $stackPos) { + $self->semValue = new Name(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 96 => static function ($self, $stackPos) { + $self->semValue = new Expr\Variable(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 97 => static function ($self, $stackPos) { /* nothing */ }, - 95 => function ($stackPos) { + 98 => static function ($self, $stackPos) { /* nothing */ }, - 96 => function ($stackPos) { + 99 => static function ($self, $stackPos) { /* nothing */ }, - 97 => function ($stackPos) { - $this->emitError(new Error('A trailing comma is not allowed here', $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes)); - }, - 98 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; + 100 => static function ($self, $stackPos) { + $self->emitError(new Error('A trailing comma is not allowed here', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]))); }, - 99 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; + 101 => null, + 102 => null, + 103 => static function ($self, $stackPos) { + $self->semValue = new Node\Attribute($self->semStack[$stackPos-(1-1)], [], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 100 => function ($stackPos) { - $this->semValue = new Node\Attribute($this->semStack[$stackPos-(1-1)], [], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 104 => static function ($self, $stackPos) { + $self->semValue = new Node\Attribute($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 101 => function ($stackPos) { - $this->semValue = new Node\Attribute($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 105 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 102 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 106 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 103 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 107 => static function ($self, $stackPos) { + $self->semValue = new Node\AttributeGroup($self->semStack[$stackPos-(4-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 104 => function ($stackPos) { - $this->semValue = new Node\AttributeGroup($this->semStack[$stackPos-(4-2)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 108 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 105 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 109 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, - 106 => function ($stackPos) { - $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; + 110 => static function ($self, $stackPos) { + $self->semValue = []; }, - 107 => function ($stackPos) { - $this->semValue = []; + 111 => null, + 112 => null, + 113 => null, + 114 => null, + 115 => static function ($self, $stackPos) { + $self->semValue = new Stmt\HaltCompiler($self->handleHaltCompiler(), $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 108 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 116 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Namespace_($self->semStack[$stackPos-(3-2)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + $self->semValue->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON); + $self->checkNamespace($self->semValue); }, - 109 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 117 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Namespace_($self->semStack[$stackPos-(5-2)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); + $self->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); + $self->checkNamespace($self->semValue); }, - 110 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 118 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Namespace_(null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + $self->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); + $self->checkNamespace($self->semValue); }, - 111 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 119 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Use_($self->semStack[$stackPos-(3-2)], Stmt\Use_::TYPE_NORMAL, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 112 => function ($stackPos) { - $this->semValue = new Stmt\HaltCompiler($this->lexer->handleHaltCompiler(), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 120 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Use_($self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 113 => function ($stackPos) { - $this->semValue = new Stmt\Namespace_($this->semStack[$stackPos-(3-2)], null, $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - $this->semValue->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON); - $this->checkNamespace($this->semValue); + 121 => null, + 122 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Const_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), []); }, - 114 => function ($stackPos) { - $this->semValue = new Stmt\Namespace_($this->semStack[$stackPos-(5-2)], $this->semStack[$stackPos-(5-4)], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); - $this->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); - $this->checkNamespace($this->semValue); + 123 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Const_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(4-1)]); + $self->checkConstantAttributes($self->semValue); }, - 115 => function ($stackPos) { - $this->semValue = new Stmt\Namespace_(null, $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); - $this->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); - $this->checkNamespace($this->semValue); + 124 => static function ($self, $stackPos) { + $self->semValue = Stmt\Use_::TYPE_FUNCTION; }, - 116 => function ($stackPos) { - $this->semValue = new Stmt\Use_($this->semStack[$stackPos-(3-2)], Stmt\Use_::TYPE_NORMAL, $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 125 => static function ($self, $stackPos) { + $self->semValue = Stmt\Use_::TYPE_CONSTANT; }, - 117 => function ($stackPos) { - $this->semValue = new Stmt\Use_($this->semStack[$stackPos-(4-3)], $this->semStack[$stackPos-(4-2)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 126 => static function ($self, $stackPos) { + $self->semValue = new Stmt\GroupUse($self->semStack[$stackPos-(8-3)], $self->semStack[$stackPos-(8-6)], $self->semStack[$stackPos-(8-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); }, - 118 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 127 => static function ($self, $stackPos) { + $self->semValue = new Stmt\GroupUse($self->semStack[$stackPos-(7-2)], $self->semStack[$stackPos-(7-5)], Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); }, - 119 => function ($stackPos) { - $this->semValue = new Stmt\Const_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 128 => null, + 129 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 120 => function ($stackPos) { - $this->semValue = Stmt\Use_::TYPE_FUNCTION; + 130 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 121 => function ($stackPos) { - $this->semValue = Stmt\Use_::TYPE_CONSTANT; + 131 => null, + 132 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 122 => function ($stackPos) { - $this->semValue = new Stmt\GroupUse($this->semStack[$stackPos-(7-3)], $this->semStack[$stackPos-(7-6)], $this->semStack[$stackPos-(7-2)], $this->startAttributeStack[$stackPos-(7-1)] + $this->endAttributes); + 133 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 123 => function ($stackPos) { - $this->semValue = new Stmt\GroupUse($this->semStack[$stackPos-(6-2)], $this->semStack[$stackPos-(6-5)], Stmt\Use_::TYPE_UNKNOWN, $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes); + 134 => null, + 135 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 124 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 136 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 125 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 137 => static function ($self, $stackPos) { + $self->semValue = new Node\UseItem($self->semStack[$stackPos-(1-1)], null, Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(1-1)); }, - 126 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 138 => static function ($self, $stackPos) { + $self->semValue = new Node\UseItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(3-3)); }, - 127 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 139 => static function ($self, $stackPos) { + $self->semValue = new Node\UseItem($self->semStack[$stackPos-(1-1)], null, Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(1-1)); }, - 128 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 140 => static function ($self, $stackPos) { + $self->semValue = new Node\UseItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(3-3)); }, - 129 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 141 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(1-1)]; $self->semValue->type = Stmt\Use_::TYPE_NORMAL; }, - 130 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 142 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(2-2)]; $self->semValue->type = $self->semStack[$stackPos-(2-1)]; }, - 131 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 143 => null, + 144 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 132 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 145 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 133 => function ($stackPos) { - $this->semValue = new Stmt\UseUse($this->semStack[$stackPos-(1-1)], null, Stmt\Use_::TYPE_UNKNOWN, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); $this->checkUseUse($this->semValue, $stackPos-(1-1)); + 146 => static function ($self, $stackPos) { + $self->semValue = new Node\Const_($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 134 => function ($stackPos) { - $this->semValue = new Stmt\UseUse($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], Stmt\Use_::TYPE_UNKNOWN, $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); $this->checkUseUse($this->semValue, $stackPos-(3-3)); + 147 => null, + 148 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 135 => function ($stackPos) { - $this->semValue = new Stmt\UseUse($this->semStack[$stackPos-(1-1)], null, Stmt\Use_::TYPE_UNKNOWN, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); $this->checkUseUse($this->semValue, $stackPos-(1-1)); + 149 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 136 => function ($stackPos) { - $this->semValue = new Stmt\UseUse($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], Stmt\Use_::TYPE_UNKNOWN, $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); $this->checkUseUse($this->semValue, $stackPos-(3-3)); + 150 => static function ($self, $stackPos) { + $self->semValue = new Node\Const_(new Node\Identifier($self->semStack[$stackPos-(3-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos-(3-1)])), $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 137 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; $this->semValue->type = Stmt\Use_::TYPE_NORMAL; + 151 => static function ($self, $stackPos) { + $self->semValue = new Node\Const_(new Node\Identifier($self->semStack[$stackPos-(3-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos-(3-1)])), $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 138 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-2)]; $this->semValue->type = $this->semStack[$stackPos-(2-1)]; + 152 => static function ($self, $stackPos) { + if ($self->semStack[$stackPos-(2-2)] !== null) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; } $self->semValue = $self->semStack[$stackPos-(2-1)];; }, - 139 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 153 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 140 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 154 => static function ($self, $stackPos) { + $nop = $self->maybeCreateZeroLengthNop($self->tokenPos);; + if ($nop !== null) { $self->semStack[$stackPos-(1-1)][] = $nop; } $self->semValue = $self->semStack[$stackPos-(1-1)]; }, - 141 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 155 => null, + 156 => null, + 157 => null, + 158 => static function ($self, $stackPos) { + throw new Error('__HALT_COMPILER() can only be used from the outermost scope', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 142 => function ($stackPos) { - $this->semValue = new Node\Const_($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 159 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Block($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 143 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 160 => static function ($self, $stackPos) { + $self->semValue = new Stmt\If_($self->semStack[$stackPos-(7-3)], ['stmts' => $self->semStack[$stackPos-(7-5)], 'elseifs' => $self->semStack[$stackPos-(7-6)], 'else' => $self->semStack[$stackPos-(7-7)]], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); }, - 144 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 161 => static function ($self, $stackPos) { + $self->semValue = new Stmt\If_($self->semStack[$stackPos-(10-3)], ['stmts' => $self->semStack[$stackPos-(10-6)], 'elseifs' => $self->semStack[$stackPos-(10-7)], 'else' => $self->semStack[$stackPos-(10-8)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); }, - 145 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 162 => static function ($self, $stackPos) { + $self->semValue = new Stmt\While_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, - 146 => function ($stackPos) { - $this->semValue = new Node\Const_($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 163 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Do_($self->semStack[$stackPos-(7-5)], $self->semStack[$stackPos-(7-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); }, - 147 => function ($stackPos) { - if (is_array($this->semStack[$stackPos-(2-2)])) { $this->semValue = array_merge($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)]); } else { $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; }; + 164 => static function ($self, $stackPos) { + $self->semValue = new Stmt\For_(['init' => $self->semStack[$stackPos-(9-3)], 'cond' => $self->semStack[$stackPos-(9-5)], 'loop' => $self->semStack[$stackPos-(9-7)], 'stmts' => $self->semStack[$stackPos-(9-9)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, - 148 => function ($stackPos) { - $this->semValue = array(); + 165 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Switch_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, - 149 => function ($stackPos) { - $startAttributes = $this->lookaheadStartAttributes; if (isset($startAttributes['comments'])) { $nop = new Stmt\Nop($this->createCommentNopAttributes($startAttributes['comments'])); } else { $nop = null; }; - if ($nop !== null) { $this->semStack[$stackPos-(1-1)][] = $nop; } $this->semValue = $this->semStack[$stackPos-(1-1)]; + 166 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Break_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 150 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 167 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Continue_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 151 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 168 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Return_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 152 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 169 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Global_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 153 => function ($stackPos) { - throw new Error('__HALT_COMPILER() can only be used from the outermost scope', $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 170 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Static_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 154 => function ($stackPos) { - - if ($this->semStack[$stackPos-(3-2)]) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; $attrs = $this->startAttributeStack[$stackPos-(3-1)]; $stmts = $this->semValue; if (!empty($attrs['comments'])) {$stmts[0]->setAttribute('comments', array_merge($attrs['comments'], $stmts[0]->getAttribute('comments', []))); }; - } else { - $startAttributes = $this->startAttributeStack[$stackPos-(3-1)]; if (isset($startAttributes['comments'])) { $this->semValue = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $this->semValue = null; }; - if (null === $this->semValue) { $this->semValue = array(); } - } - - }, - 155 => function ($stackPos) { - $this->semValue = new Stmt\If_($this->semStack[$stackPos-(7-3)], ['stmts' => is_array($this->semStack[$stackPos-(7-5)]) ? $this->semStack[$stackPos-(7-5)] : array($this->semStack[$stackPos-(7-5)]), 'elseifs' => $this->semStack[$stackPos-(7-6)], 'else' => $this->semStack[$stackPos-(7-7)]], $this->startAttributeStack[$stackPos-(7-1)] + $this->endAttributes); - }, - 156 => function ($stackPos) { - $this->semValue = new Stmt\If_($this->semStack[$stackPos-(10-3)], ['stmts' => $this->semStack[$stackPos-(10-6)], 'elseifs' => $this->semStack[$stackPos-(10-7)], 'else' => $this->semStack[$stackPos-(10-8)]], $this->startAttributeStack[$stackPos-(10-1)] + $this->endAttributes); - }, - 157 => function ($stackPos) { - $this->semValue = new Stmt\While_($this->semStack[$stackPos-(5-3)], $this->semStack[$stackPos-(5-5)], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); - }, - 158 => function ($stackPos) { - $this->semValue = new Stmt\Do_($this->semStack[$stackPos-(7-5)], is_array($this->semStack[$stackPos-(7-2)]) ? $this->semStack[$stackPos-(7-2)] : array($this->semStack[$stackPos-(7-2)]), $this->startAttributeStack[$stackPos-(7-1)] + $this->endAttributes); - }, - 159 => function ($stackPos) { - $this->semValue = new Stmt\For_(['init' => $this->semStack[$stackPos-(9-3)], 'cond' => $this->semStack[$stackPos-(9-5)], 'loop' => $this->semStack[$stackPos-(9-7)], 'stmts' => $this->semStack[$stackPos-(9-9)]], $this->startAttributeStack[$stackPos-(9-1)] + $this->endAttributes); - }, - 160 => function ($stackPos) { - $this->semValue = new Stmt\Switch_($this->semStack[$stackPos-(5-3)], $this->semStack[$stackPos-(5-5)], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); + 171 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Echo_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 161 => function ($stackPos) { - $this->semValue = new Stmt\Break_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 162 => function ($stackPos) { - $this->semValue = new Stmt\Continue_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 163 => function ($stackPos) { - $this->semValue = new Stmt\Return_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 164 => function ($stackPos) { - $this->semValue = new Stmt\Global_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 165 => function ($stackPos) { - $this->semValue = new Stmt\Static_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 166 => function ($stackPos) { - $this->semValue = new Stmt\Echo_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); - }, - 167 => function ($stackPos) { - $this->semValue = new Stmt\InlineHTML($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); - }, - 168 => function ($stackPos) { + 172 => static function ($self, $stackPos) { - $e = $this->semStack[$stackPos-(2-1)]; - if ($e instanceof Expr\Throw_) { - // For backwards-compatibility reasons, convert throw in statement position into - // Stmt\Throw_ rather than Stmt\Expression(Expr\Throw_). - $this->semValue = new Stmt\Throw_($e->expr, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - } else { - $this->semValue = new Stmt\Expression($e, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); - } + $self->semValue = new Stmt\InlineHTML($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + $self->semValue->setAttribute('hasLeadingNewline', $self->inlineHtmlHasLeadingNewline($stackPos-(1-1))); }, - 169 => function ($stackPos) { - $this->semValue = new Stmt\Unset_($this->semStack[$stackPos-(5-3)], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); + 173 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Expression($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 170 => function ($stackPos) { - $this->semValue = new Stmt\Foreach_($this->semStack[$stackPos-(7-3)], $this->semStack[$stackPos-(7-5)][0], ['keyVar' => null, 'byRef' => $this->semStack[$stackPos-(7-5)][1], 'stmts' => $this->semStack[$stackPos-(7-7)]], $this->startAttributeStack[$stackPos-(7-1)] + $this->endAttributes); + 174 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Unset_($self->semStack[$stackPos-(5-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, - 171 => function ($stackPos) { - $this->semValue = new Stmt\Foreach_($this->semStack[$stackPos-(9-3)], $this->semStack[$stackPos-(9-7)][0], ['keyVar' => $this->semStack[$stackPos-(9-5)], 'byRef' => $this->semStack[$stackPos-(9-7)][1], 'stmts' => $this->semStack[$stackPos-(9-9)]], $this->startAttributeStack[$stackPos-(9-1)] + $this->endAttributes); + 175 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Foreach_($self->semStack[$stackPos-(7-3)], $self->semStack[$stackPos-(7-5)][0], ['keyVar' => null, 'byRef' => $self->semStack[$stackPos-(7-5)][1], 'stmts' => $self->semStack[$stackPos-(7-7)]], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); }, - 172 => function ($stackPos) { - $this->semValue = new Stmt\Foreach_($this->semStack[$stackPos-(6-3)], new Expr\Error($this->startAttributeStack[$stackPos-(6-4)] + $this->endAttributeStack[$stackPos-(6-4)]), ['stmts' => $this->semStack[$stackPos-(6-6)]], $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes); + 176 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Foreach_($self->semStack[$stackPos-(9-3)], $self->semStack[$stackPos-(9-7)][0], ['keyVar' => $self->semStack[$stackPos-(9-5)], 'byRef' => $self->semStack[$stackPos-(9-7)][1], 'stmts' => $self->semStack[$stackPos-(9-9)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, - 173 => function ($stackPos) { - $this->semValue = new Stmt\Declare_($this->semStack[$stackPos-(5-3)], $this->semStack[$stackPos-(5-5)], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); + 177 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Foreach_($self->semStack[$stackPos-(6-3)], new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(6-4)], $self->tokenEndStack[$stackPos-(6-4)])), ['stmts' => $self->semStack[$stackPos-(6-6)]], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); }, - 174 => function ($stackPos) { - $this->semValue = new Stmt\TryCatch($this->semStack[$stackPos-(6-3)], $this->semStack[$stackPos-(6-5)], $this->semStack[$stackPos-(6-6)], $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes); $this->checkTryCatch($this->semValue); + 178 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Declare_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, - 175 => function ($stackPos) { - $this->semValue = new Stmt\Goto_($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 179 => static function ($self, $stackPos) { + $self->semValue = new Stmt\TryCatch($self->semStack[$stackPos-(6-3)], $self->semStack[$stackPos-(6-5)], $self->semStack[$stackPos-(6-6)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); $self->checkTryCatch($self->semValue); }, - 176 => function ($stackPos) { - $this->semValue = new Stmt\Label($this->semStack[$stackPos-(2-1)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 180 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Goto_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 177 => function ($stackPos) { - $this->semValue = array(); /* means: no statement */ + 181 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Label($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 178 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 182 => static function ($self, $stackPos) { + $self->semValue = null; /* means: no statement */ }, - 179 => function ($stackPos) { - $startAttributes = $this->startAttributeStack[$stackPos-(1-1)]; if (isset($startAttributes['comments'])) { $this->semValue = new Stmt\Nop($startAttributes + $this->endAttributes); } else { $this->semValue = null; }; - if ($this->semValue === null) $this->semValue = array(); /* means: no statement */ + 183 => null, + 184 => static function ($self, $stackPos) { + $self->semValue = $self->maybeCreateNop($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]); }, - 180 => function ($stackPos) { - $this->semValue = array(); + 185 => static function ($self, $stackPos) { + if ($self->semStack[$stackPos-(1-1)] instanceof Stmt\Block) { $self->semValue = $self->semStack[$stackPos-(1-1)]->stmts; } else if ($self->semStack[$stackPos-(1-1)] === null) { $self->semValue = []; } else { $self->semValue = [$self->semStack[$stackPos-(1-1)]]; }; }, - 181 => function ($stackPos) { - $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; + 186 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 182 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 187 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, - 183 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 188 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 184 => function ($stackPos) { - $this->semValue = new Stmt\Catch_($this->semStack[$stackPos-(8-3)], $this->semStack[$stackPos-(8-4)], $this->semStack[$stackPos-(8-7)], $this->startAttributeStack[$stackPos-(8-1)] + $this->endAttributes); + 189 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 185 => function ($stackPos) { - $this->semValue = null; + 190 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Catch_($self->semStack[$stackPos-(8-3)], $self->semStack[$stackPos-(8-4)], $self->semStack[$stackPos-(8-7)], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); }, - 186 => function ($stackPos) { - $this->semValue = new Stmt\Finally_($this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 191 => static function ($self, $stackPos) { + $self->semValue = null; }, - 187 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 192 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Finally_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 188 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 193 => null, + 194 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 189 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 195 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 190 => function ($stackPos) { - $this->semValue = false; + 196 => static function ($self, $stackPos) { + $self->semValue = false; }, - 191 => function ($stackPos) { - $this->semValue = true; + 197 => static function ($self, $stackPos) { + $self->semValue = true; }, - 192 => function ($stackPos) { - $this->semValue = false; + 198 => static function ($self, $stackPos) { + $self->semValue = false; }, - 193 => function ($stackPos) { - $this->semValue = true; + 199 => static function ($self, $stackPos) { + $self->semValue = true; }, - 194 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; + 200 => static function ($self, $stackPos) { + $self->semValue = false; }, - 195 => function ($stackPos) { - $this->semValue = []; + 201 => static function ($self, $stackPos) { + $self->semValue = true; }, - 196 => function ($stackPos) { - $this->semValue = new Stmt\Function_($this->semStack[$stackPos-(8-3)], ['byRef' => $this->semStack[$stackPos-(8-2)], 'params' => $this->semStack[$stackPos-(8-5)], 'returnType' => $this->semStack[$stackPos-(8-7)], 'stmts' => $this->semStack[$stackPos-(8-8)], 'attrGroups' => []], $this->startAttributeStack[$stackPos-(8-1)] + $this->endAttributes); + 202 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; }, - 197 => function ($stackPos) { - $this->semValue = new Stmt\Function_($this->semStack[$stackPos-(9-4)], ['byRef' => $this->semStack[$stackPos-(9-3)], 'params' => $this->semStack[$stackPos-(9-6)], 'returnType' => $this->semStack[$stackPos-(9-8)], 'stmts' => $this->semStack[$stackPos-(9-9)], 'attrGroups' => $this->semStack[$stackPos-(9-1)]], $this->startAttributeStack[$stackPos-(9-1)] + $this->endAttributes); + 203 => static function ($self, $stackPos) { + $self->semValue = []; }, - 198 => function ($stackPos) { - $this->semValue = new Stmt\Class_($this->semStack[$stackPos-(8-3)], ['type' => $this->semStack[$stackPos-(8-2)], 'extends' => $this->semStack[$stackPos-(8-4)], 'implements' => $this->semStack[$stackPos-(8-5)], 'stmts' => $this->semStack[$stackPos-(8-7)], 'attrGroups' => $this->semStack[$stackPos-(8-1)]], $this->startAttributeStack[$stackPos-(8-1)] + $this->endAttributes); - $this->checkClass($this->semValue, $stackPos-(8-3)); + 204 => null, + 205 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 199 => function ($stackPos) { - $this->semValue = new Stmt\Interface_($this->semStack[$stackPos-(7-3)], ['extends' => $this->semStack[$stackPos-(7-4)], 'stmts' => $this->semStack[$stackPos-(7-6)], 'attrGroups' => $this->semStack[$stackPos-(7-1)]], $this->startAttributeStack[$stackPos-(7-1)] + $this->endAttributes); - $this->checkInterface($this->semValue, $stackPos-(7-3)); + 206 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 200 => function ($stackPos) { - $this->semValue = new Stmt\Trait_($this->semStack[$stackPos-(6-3)], ['stmts' => $this->semStack[$stackPos-(6-5)], 'attrGroups' => $this->semStack[$stackPos-(6-1)]], $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes); + 207 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 201 => function ($stackPos) { - $this->semValue = 0; + 208 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Function_($self->semStack[$stackPos-(8-3)], ['byRef' => $self->semStack[$stackPos-(8-2)], 'params' => $self->semStack[$stackPos-(8-5)], 'returnType' => $self->semStack[$stackPos-(8-7)], 'stmts' => $self->semStack[$stackPos-(8-8)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); }, - 202 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_ABSTRACT; + 209 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Function_($self->semStack[$stackPos-(9-4)], ['byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-6)], 'returnType' => $self->semStack[$stackPos-(9-8)], 'stmts' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => $self->semStack[$stackPos-(9-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, - 203 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_FINAL; + 210 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Class_($self->semStack[$stackPos-(7-2)], ['type' => $self->semStack[$stackPos-(7-1)], 'extends' => $self->semStack[$stackPos-(7-3)], 'implements' => $self->semStack[$stackPos-(7-4)], 'stmts' => $self->semStack[$stackPos-(7-6)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); + $self->checkClass($self->semValue, $stackPos-(7-2)); }, - 204 => function ($stackPos) { - $this->semValue = null; + 211 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Class_($self->semStack[$stackPos-(8-3)], ['type' => $self->semStack[$stackPos-(8-2)], 'extends' => $self->semStack[$stackPos-(8-4)], 'implements' => $self->semStack[$stackPos-(8-5)], 'stmts' => $self->semStack[$stackPos-(8-7)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); + $self->checkClass($self->semValue, $stackPos-(8-3)); }, - 205 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-2)]; + 212 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Interface_($self->semStack[$stackPos-(7-3)], ['extends' => $self->semStack[$stackPos-(7-4)], 'stmts' => $self->semStack[$stackPos-(7-6)], 'attrGroups' => $self->semStack[$stackPos-(7-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); + $self->checkInterface($self->semValue, $stackPos-(7-3)); }, - 206 => function ($stackPos) { - $this->semValue = array(); + 213 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Trait_($self->semStack[$stackPos-(6-3)], ['stmts' => $self->semStack[$stackPos-(6-5)], 'attrGroups' => $self->semStack[$stackPos-(6-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); }, - 207 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-2)]; + 214 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Enum_($self->semStack[$stackPos-(8-3)], ['scalarType' => $self->semStack[$stackPos-(8-4)], 'implements' => $self->semStack[$stackPos-(8-5)], 'stmts' => $self->semStack[$stackPos-(8-7)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); + $self->checkEnum($self->semValue, $stackPos-(8-3)); }, - 208 => function ($stackPos) { - $this->semValue = array(); + 215 => static function ($self, $stackPos) { + $self->semValue = null; }, - 209 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-2)]; + 216 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(2-2)]; }, - 210 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 217 => static function ($self, $stackPos) { + $self->semValue = null; }, - 211 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 218 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(2-2)]; }, - 212 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 219 => static function ($self, $stackPos) { + $self->semValue = 0; }, - 213 => function ($stackPos) { - $this->semValue = is_array($this->semStack[$stackPos-(1-1)]) ? $this->semStack[$stackPos-(1-1)] : array($this->semStack[$stackPos-(1-1)]); + 220 => null, + 221 => null, + 222 => static function ($self, $stackPos) { + $self->checkClassModifier($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; }, - 214 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(4-2)]; + 223 => static function ($self, $stackPos) { + $self->semValue = Modifiers::ABSTRACT; }, - 215 => function ($stackPos) { - $this->semValue = is_array($this->semStack[$stackPos-(1-1)]) ? $this->semStack[$stackPos-(1-1)] : array($this->semStack[$stackPos-(1-1)]); + 224 => static function ($self, $stackPos) { + $self->semValue = Modifiers::FINAL; }, - 216 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(4-2)]; + 225 => static function ($self, $stackPos) { + $self->semValue = Modifiers::READONLY; }, - 217 => function ($stackPos) { - $this->semValue = is_array($this->semStack[$stackPos-(1-1)]) ? $this->semStack[$stackPos-(1-1)] : array($this->semStack[$stackPos-(1-1)]); + 226 => static function ($self, $stackPos) { + $self->semValue = null; }, - 218 => function ($stackPos) { - $this->semValue = null; + 227 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(2-2)]; }, - 219 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(4-2)]; + 228 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 220 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 229 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(2-2)]; }, - 221 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 230 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 222 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 231 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(2-2)]; }, - 223 => function ($stackPos) { - $this->semValue = new Stmt\DeclareDeclare($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 232 => null, + 233 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 224 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; + 234 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 225 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(4-3)]; + 235 => null, + 236 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-2)]; }, - 226 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(4-2)]; + 237 => null, + 238 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-2)]; }, - 227 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(5-3)]; + 239 => static function ($self, $stackPos) { + if ($self->semStack[$stackPos-(1-1)] instanceof Stmt\Block) { $self->semValue = $self->semStack[$stackPos-(1-1)]->stmts; } else if ($self->semStack[$stackPos-(1-1)] === null) { $self->semValue = []; } else { $self->semValue = [$self->semStack[$stackPos-(1-1)]]; }; }, - 228 => function ($stackPos) { - $this->semValue = array(); + 240 => static function ($self, $stackPos) { + $self->semValue = null; }, - 229 => function ($stackPos) { - $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; + 241 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-2)]; }, - 230 => function ($stackPos) { - $this->semValue = new Stmt\Case_($this->semStack[$stackPos-(4-2)], $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 242 => null, + 243 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 231 => function ($stackPos) { - $this->semValue = new Stmt\Case_(null, $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 244 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 232 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; + 245 => static function ($self, $stackPos) { + $self->semValue = new Node\DeclareItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 233 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; + 246 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; }, - 234 => function ($stackPos) { - $this->semValue = new Expr\Match_($this->semStack[$stackPos-(7-3)], $this->semStack[$stackPos-(7-6)], $this->startAttributeStack[$stackPos-(7-1)] + $this->endAttributes); + 247 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-3)]; }, - 235 => function ($stackPos) { - $this->semValue = []; + 248 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-2)]; }, - 236 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 249 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(5-3)]; }, - 237 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 250 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 238 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 251 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, - 239 => function ($stackPos) { - $this->semValue = new Node\MatchArm($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 252 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Case_($self->semStack[$stackPos-(4-2)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 240 => function ($stackPos) { - $this->semValue = new Node\MatchArm(null, $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 253 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Case_(null, $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 241 => function ($stackPos) { - $this->semValue = is_array($this->semStack[$stackPos-(1-1)]) ? $this->semStack[$stackPos-(1-1)] : array($this->semStack[$stackPos-(1-1)]); + 254 => null, + 255 => null, + 256 => static function ($self, $stackPos) { + $self->semValue = new Expr\Match_($self->semStack[$stackPos-(7-3)], $self->semStack[$stackPos-(7-6)], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); }, - 242 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(4-2)]; + 257 => static function ($self, $stackPos) { + $self->semValue = []; }, - 243 => function ($stackPos) { - $this->semValue = array(); + 258 => null, + 259 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 244 => function ($stackPos) { - $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; + 260 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 245 => function ($stackPos) { - $this->semValue = new Stmt\ElseIf_($this->semStack[$stackPos-(5-3)], is_array($this->semStack[$stackPos-(5-5)]) ? $this->semStack[$stackPos-(5-5)] : array($this->semStack[$stackPos-(5-5)]), $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); + 261 => static function ($self, $stackPos) { + $self->semValue = new Node\MatchArm($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 246 => function ($stackPos) { - $this->semValue = array(); + 262 => static function ($self, $stackPos) { + $self->semValue = new Node\MatchArm(null, $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 247 => function ($stackPos) { - $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; + 263 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(1-1)]; }, - 248 => function ($stackPos) { - $this->semValue = new Stmt\ElseIf_($this->semStack[$stackPos-(6-3)], $this->semStack[$stackPos-(6-6)], $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes); + 264 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-2)]; }, - 249 => function ($stackPos) { - $this->semValue = null; + 265 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 250 => function ($stackPos) { - $this->semValue = new Stmt\Else_(is_array($this->semStack[$stackPos-(2-2)]) ? $this->semStack[$stackPos-(2-2)] : array($this->semStack[$stackPos-(2-2)]), $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 266 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, - 251 => function ($stackPos) { - $this->semValue = null; + 267 => static function ($self, $stackPos) { + $self->semValue = new Stmt\ElseIf_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, - 252 => function ($stackPos) { - $this->semValue = new Stmt\Else_($this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 268 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 253 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)], false); + 269 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, - 254 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(2-2)], true); + 270 => static function ($self, $stackPos) { + $self->semValue = new Stmt\ElseIf_($self->semStack[$stackPos-(6-3)], $self->semStack[$stackPos-(6-6)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); $self->fixupAlternativeElse($self->semValue); }, - 255 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)], false); + 271 => static function ($self, $stackPos) { + $self->semValue = null; }, - 256 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)], false); + 272 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Else_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 257 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 273 => static function ($self, $stackPos) { + $self->semValue = null; }, - 258 => function ($stackPos) { - $this->semValue = array(); + 274 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Else_($self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->fixupAlternativeElse($self->semValue); }, - 259 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 275 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)], false); }, - 260 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 276 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(2-2)], true); }, - 261 => function ($stackPos) { - $this->semValue = 0; + 277 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)], false); }, - 262 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_PUBLIC; + 278 => static function ($self, $stackPos) { + $self->semValue = array($self->fixupArrayDestructuring($self->semStack[$stackPos-(1-1)]), false); }, - 263 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_PROTECTED; + 279 => null, + 280 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 264 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_PRIVATE; + 281 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 265 => function ($stackPos) { - $this->semValue = new Node\Param($this->semStack[$stackPos-(6-6)], null, $this->semStack[$stackPos-(6-3)], $this->semStack[$stackPos-(6-4)], $this->semStack[$stackPos-(6-5)], $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes, $this->semStack[$stackPos-(6-2)], $this->semStack[$stackPos-(6-1)]); - $this->checkParam($this->semValue); + 282 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 266 => function ($stackPos) { - $this->semValue = new Node\Param($this->semStack[$stackPos-(8-6)], $this->semStack[$stackPos-(8-8)], $this->semStack[$stackPos-(8-3)], $this->semStack[$stackPos-(8-4)], $this->semStack[$stackPos-(8-5)], $this->startAttributeStack[$stackPos-(8-1)] + $this->endAttributes, $this->semStack[$stackPos-(8-2)], $this->semStack[$stackPos-(8-1)]); - $this->checkParam($this->semValue); + 283 => static function ($self, $stackPos) { + $self->semValue = 0; }, - 267 => function ($stackPos) { - $this->semValue = new Node\Param(new Expr\Error($this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes), null, $this->semStack[$stackPos-(6-3)], $this->semStack[$stackPos-(6-4)], $this->semStack[$stackPos-(6-5)], $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes, $this->semStack[$stackPos-(6-2)], $this->semStack[$stackPos-(6-1)]); + 284 => static function ($self, $stackPos) { + $self->checkModifier($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; }, - 268 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 285 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PUBLIC; }, - 269 => function ($stackPos) { - $this->semValue = new Node\NullableType($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 286 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PROTECTED; }, - 270 => function ($stackPos) { - $this->semValue = new Node\UnionType($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 287 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PRIVATE; }, - 271 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 288 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PUBLIC_SET; }, - 272 => function ($stackPos) { - $this->semValue = new Node\Name('static', $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 289 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PROTECTED_SET; }, - 273 => function ($stackPos) { - $this->semValue = $this->handleBuiltinTypes($this->semStack[$stackPos-(1-1)]); + 290 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PRIVATE_SET; }, - 274 => function ($stackPos) { - $this->semValue = new Node\Identifier('array', $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 291 => static function ($self, $stackPos) { + $self->semValue = Modifiers::READONLY; }, - 275 => function ($stackPos) { - $this->semValue = new Node\Identifier('callable', $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 292 => static function ($self, $stackPos) { + $self->semValue = Modifiers::FINAL; }, - 276 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)]); + 293 => static function ($self, $stackPos) { + $self->semValue = new Node\Param($self->semStack[$stackPos-(7-6)], null, $self->semStack[$stackPos-(7-3)], $self->semStack[$stackPos-(7-4)], $self->semStack[$stackPos-(7-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(7-2)], $self->semStack[$stackPos-(7-1)], $self->semStack[$stackPos-(7-7)]); + $self->checkParam($self->semValue); + $self->addPropertyNameToHooks($self->semValue); }, - 277 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 294 => static function ($self, $stackPos) { + $self->semValue = new Node\Param($self->semStack[$stackPos-(9-6)], $self->semStack[$stackPos-(9-8)], $self->semStack[$stackPos-(9-3)], $self->semStack[$stackPos-(9-4)], $self->semStack[$stackPos-(9-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(9-2)], $self->semStack[$stackPos-(9-1)], $self->semStack[$stackPos-(9-9)]); + $self->checkParam($self->semValue); + $self->addPropertyNameToHooks($self->semValue); }, - 278 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)]); + 295 => static function ($self, $stackPos) { + $self->semValue = new Node\Param(new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])), null, $self->semStack[$stackPos-(6-3)], $self->semStack[$stackPos-(6-4)], $self->semStack[$stackPos-(6-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(6-2)], $self->semStack[$stackPos-(6-1)]); }, - 279 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 296 => null, + 297 => static function ($self, $stackPos) { + $self->semValue = new Node\NullableType($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 280 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 298 => static function ($self, $stackPos) { + $self->semValue = new Node\UnionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 281 => function ($stackPos) { - $this->semValue = new Node\NullableType($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 299 => null, + 300 => null, + 301 => static function ($self, $stackPos) { + $self->semValue = new Node\Name('static', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 282 => function ($stackPos) { - $this->semValue = new Node\UnionType($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 302 => static function ($self, $stackPos) { + $self->semValue = $self->handleBuiltinTypes($self->semStack[$stackPos-(1-1)]); }, - 283 => function ($stackPos) { - $this->semValue = null; + 303 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier('array', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 284 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 304 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier('callable', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 285 => function ($stackPos) { - $this->semValue = null; + 305 => null, + 306 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; }, - 286 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-2)]; + 307 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); }, - 287 => function ($stackPos) { - $this->semValue = null; + 308 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 288 => function ($stackPos) { - $this->semValue = array(); + 309 => null, + 310 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; }, - 289 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(4-2)]; + 311 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); }, - 290 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 312 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 291 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 313 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); }, - 292 => function ($stackPos) { - $this->semValue = new Node\Arg($this->semStack[$stackPos-(1-1)], false, false, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 314 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 293 => function ($stackPos) { - $this->semValue = new Node\Arg($this->semStack[$stackPos-(2-2)], true, false, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 315 => static function ($self, $stackPos) { + $self->semValue = new Node\IntersectionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 294 => function ($stackPos) { - $this->semValue = new Node\Arg($this->semStack[$stackPos-(2-2)], false, true, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 316 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); }, - 295 => function ($stackPos) { - $this->semValue = new Node\Arg($this->semStack[$stackPos-(3-3)], false, false, $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes, $this->semStack[$stackPos-(3-1)]); + 317 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 296 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 318 => static function ($self, $stackPos) { + $self->semValue = new Node\IntersectionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 297 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 319 => null, + 320 => static function ($self, $stackPos) { + $self->semValue = new Node\NullableType($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 298 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 321 => static function ($self, $stackPos) { + $self->semValue = new Node\UnionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 299 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 322 => null, + 323 => static function ($self, $stackPos) { + $self->semValue = null; }, - 300 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 324 => null, + 325 => static function ($self, $stackPos) { + $self->semValue = null; }, - 301 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 326 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(2-2)]; }, - 302 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 327 => static function ($self, $stackPos) { + $self->semValue = null; }, - 303 => function ($stackPos) { - $this->semValue = new Stmt\StaticVar($this->semStack[$stackPos-(1-1)], null, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 328 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 304 => function ($stackPos) { - $this->semValue = new Stmt\StaticVar($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 329 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-2)]; }, - 305 => function ($stackPos) { - if ($this->semStack[$stackPos-(2-2)] !== null) { $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; } + 330 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(3-2)]); }, - 306 => function ($stackPos) { - $this->semValue = array(); + 331 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 307 => function ($stackPos) { - $startAttributes = $this->lookaheadStartAttributes; if (isset($startAttributes['comments'])) { $nop = new Stmt\Nop($this->createCommentNopAttributes($startAttributes['comments'])); } else { $nop = null; }; - if ($nop !== null) { $this->semStack[$stackPos-(1-1)][] = $nop; } $this->semValue = $this->semStack[$stackPos-(1-1)]; + 332 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-2)]; }, - 308 => function ($stackPos) { - $this->semValue = new Stmt\Property($this->semStack[$stackPos-(5-2)], $this->semStack[$stackPos-(5-4)], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes, $this->semStack[$stackPos-(5-3)], $this->semStack[$stackPos-(5-1)]); - $this->checkProperty($this->semValue, $stackPos-(5-2)); + 333 => static function ($self, $stackPos) { + $self->semValue = array(new Node\Arg($self->semStack[$stackPos-(4-2)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]))); }, - 309 => function ($stackPos) { - $this->semValue = new Stmt\ClassConst($this->semStack[$stackPos-(5-4)], $this->semStack[$stackPos-(5-2)], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes, $this->semStack[$stackPos-(5-1)]); - $this->checkClassConst($this->semValue, $stackPos-(5-2)); + 334 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(3-2)]); }, - 310 => function ($stackPos) { - $this->semValue = new Stmt\ClassMethod($this->semStack[$stackPos-(10-5)], ['type' => $this->semStack[$stackPos-(10-2)], 'byRef' => $this->semStack[$stackPos-(10-4)], 'params' => $this->semStack[$stackPos-(10-7)], 'returnType' => $this->semStack[$stackPos-(10-9)], 'stmts' => $this->semStack[$stackPos-(10-10)], 'attrGroups' => $this->semStack[$stackPos-(10-1)]], $this->startAttributeStack[$stackPos-(10-1)] + $this->endAttributes); - $this->checkClassMethod($this->semValue, $stackPos-(10-2)); + 335 => static function ($self, $stackPos) { + $self->semValue = array(new Node\Arg($self->semStack[$stackPos-(3-1)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos-(3-1)])), $self->semStack[$stackPos-(3-3)]); }, - 311 => function ($stackPos) { - $this->semValue = new Stmt\TraitUse($this->semStack[$stackPos-(3-2)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 336 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 312 => function ($stackPos) { - $this->semValue = null; /* will be skipped */ + 337 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 313 => function ($stackPos) { - $this->semValue = array(); + 338 => static function ($self, $stackPos) { + $self->semValue = new Node\VariadicPlaceholder($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 314 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; + 339 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 315 => function ($stackPos) { - $this->semValue = array(); + 340 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 316 => function ($stackPos) { - $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; + 341 => static function ($self, $stackPos) { + $self->semValue = new Node\Arg($self->semStack[$stackPos-(2-2)], true, false, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 317 => function ($stackPos) { - $this->semValue = new Stmt\TraitUseAdaptation\Precedence($this->semStack[$stackPos-(4-1)][0], $this->semStack[$stackPos-(4-1)][1], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 342 => static function ($self, $stackPos) { + $self->semValue = new Node\Arg($self->semStack[$stackPos-(2-2)], false, true, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 318 => function ($stackPos) { - $this->semValue = new Stmt\TraitUseAdaptation\Alias($this->semStack[$stackPos-(5-1)][0], $this->semStack[$stackPos-(5-1)][1], $this->semStack[$stackPos-(5-3)], $this->semStack[$stackPos-(5-4)], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); + 343 => static function ($self, $stackPos) { + $self->semValue = new Node\Arg($self->semStack[$stackPos-(3-3)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(3-1)]); }, - 319 => function ($stackPos) { - $this->semValue = new Stmt\TraitUseAdaptation\Alias($this->semStack[$stackPos-(4-1)][0], $this->semStack[$stackPos-(4-1)][1], $this->semStack[$stackPos-(4-3)], null, $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 344 => static function ($self, $stackPos) { + $self->semValue = new Node\Arg($self->semStack[$stackPos-(1-1)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 320 => function ($stackPos) { - $this->semValue = new Stmt\TraitUseAdaptation\Alias($this->semStack[$stackPos-(4-1)][0], $this->semStack[$stackPos-(4-1)][1], null, $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 345 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(1-1)]; }, - 321 => function ($stackPos) { - $this->semValue = new Stmt\TraitUseAdaptation\Alias($this->semStack[$stackPos-(4-1)][0], $this->semStack[$stackPos-(4-1)][1], null, $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 346 => null, + 347 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 322 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)]); + 348 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 323 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 349 => null, + 350 => null, + 351 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 324 => function ($stackPos) { - $this->semValue = array(null, $this->semStack[$stackPos-(1-1)]); + 352 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 325 => function ($stackPos) { - $this->semValue = null; + 353 => static function ($self, $stackPos) { + $self->semValue = new Node\StaticVar($self->semStack[$stackPos-(1-1)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 326 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 354 => static function ($self, $stackPos) { + $self->semValue = new Node\StaticVar($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 327 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 355 => static function ($self, $stackPos) { + if ($self->semStack[$stackPos-(2-2)] !== null) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; } else { $self->semValue = $self->semStack[$stackPos-(2-1)]; } }, - 328 => function ($stackPos) { - $this->semValue = 0; + 356 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 329 => function ($stackPos) { - $this->semValue = 0; + 357 => static function ($self, $stackPos) { + $nop = $self->maybeCreateZeroLengthNop($self->tokenPos);; + if ($nop !== null) { $self->semStack[$stackPos-(1-1)][] = $nop; } $self->semValue = $self->semStack[$stackPos-(1-1)]; }, - 330 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 358 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Property($self->semStack[$stackPos-(5-2)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-1)]); }, - 331 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 359 => static function ($self, $stackPos) { + $self->semValue = new Stmt\ClassConst($self->semStack[$stackPos-(5-4)], $self->semStack[$stackPos-(5-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(5-1)]); + $self->checkClassConst($self->semValue, $stackPos-(5-2)); }, - 332 => function ($stackPos) { - $this->checkModifier($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $this->semValue = $this->semStack[$stackPos-(2-1)] | $this->semStack[$stackPos-(2-2)]; + 360 => static function ($self, $stackPos) { + $self->semValue = new Stmt\ClassConst($self->semStack[$stackPos-(6-5)], $self->semStack[$stackPos-(6-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(6-1)], $self->semStack[$stackPos-(6-4)]); + $self->checkClassConst($self->semValue, $stackPos-(6-2)); }, - 333 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_PUBLIC; + 361 => static function ($self, $stackPos) { + $self->semValue = new Stmt\ClassMethod($self->semStack[$stackPos-(10-5)], ['type' => $self->semStack[$stackPos-(10-2)], 'byRef' => $self->semStack[$stackPos-(10-4)], 'params' => $self->semStack[$stackPos-(10-7)], 'returnType' => $self->semStack[$stackPos-(10-9)], 'stmts' => $self->semStack[$stackPos-(10-10)], 'attrGroups' => $self->semStack[$stackPos-(10-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); + $self->checkClassMethod($self->semValue, $stackPos-(10-2)); }, - 334 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_PROTECTED; + 362 => static function ($self, $stackPos) { + $self->semValue = new Stmt\TraitUse($self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 335 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_PRIVATE; + 363 => static function ($self, $stackPos) { + $self->semValue = new Stmt\EnumCase($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-4)], $self->semStack[$stackPos-(5-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, - 336 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_STATIC; + 364 => static function ($self, $stackPos) { + $self->semValue = null; /* will be skipped */ }, - 337 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_ABSTRACT; + 365 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 338 => function ($stackPos) { - $this->semValue = Stmt\Class_::MODIFIER_FINAL; + 366 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; }, - 339 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 367 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 340 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 368 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, - 341 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 369 => static function ($self, $stackPos) { + $self->semValue = new Stmt\TraitUseAdaptation\Precedence($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 342 => function ($stackPos) { - $this->semValue = new Node\VarLikeIdentifier(substr($this->semStack[$stackPos-(1-1)], 1), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 370 => static function ($self, $stackPos) { + $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(5-1)][0], $self->semStack[$stackPos-(5-1)][1], $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, - 343 => function ($stackPos) { - $this->semValue = new Stmt\PropertyProperty($this->semStack[$stackPos-(1-1)], null, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 371 => static function ($self, $stackPos) { + $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 344 => function ($stackPos) { - $this->semValue = new Stmt\PropertyProperty($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 372 => static function ($self, $stackPos) { + $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 345 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 373 => static function ($self, $stackPos) { + $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 346 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 374 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); }, - 347 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 375 => null, + 376 => static function ($self, $stackPos) { + $self->semValue = array(null, $self->semStack[$stackPos-(1-1)]); }, - 348 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 377 => static function ($self, $stackPos) { + $self->semValue = null; }, - 349 => function ($stackPos) { - $this->semValue = array(); + 378 => null, + 379 => null, + 380 => static function ($self, $stackPos) { + $self->semValue = 0; }, - 350 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 381 => static function ($self, $stackPos) { + $self->semValue = 0; }, - 351 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 382 => null, + 383 => null, + 384 => static function ($self, $stackPos) { + $self->checkModifier($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; }, - 352 => function ($stackPos) { - $this->semValue = new Expr\Assign($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 385 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PUBLIC; }, - 353 => function ($stackPos) { - $this->semValue = new Expr\Assign($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 386 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PROTECTED; }, - 354 => function ($stackPos) { - $this->semValue = new Expr\Assign($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 387 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PRIVATE; }, - 355 => function ($stackPos) { - $this->semValue = new Expr\AssignRef($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 388 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PUBLIC_SET; }, - 356 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 389 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PROTECTED_SET; }, - 357 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 390 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PRIVATE_SET; }, - 358 => function ($stackPos) { - $this->semValue = new Expr\Clone_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 391 => static function ($self, $stackPos) { + $self->semValue = Modifiers::STATIC; }, - 359 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Plus($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 392 => static function ($self, $stackPos) { + $self->semValue = Modifiers::ABSTRACT; }, - 360 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Minus($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 393 => static function ($self, $stackPos) { + $self->semValue = Modifiers::FINAL; }, - 361 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Mul($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 394 => static function ($self, $stackPos) { + $self->semValue = Modifiers::READONLY; }, - 362 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Div($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 395 => null, + 396 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 363 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Concat($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 397 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 364 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Mod($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 398 => static function ($self, $stackPos) { + $self->semValue = new Node\VarLikeIdentifier(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 365 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\BitwiseAnd($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 399 => static function ($self, $stackPos) { + $self->semValue = new Node\PropertyItem($self->semStack[$stackPos-(1-1)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 366 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\BitwiseOr($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 400 => static function ($self, $stackPos) { + $self->semValue = new Node\PropertyItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 367 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\BitwiseXor($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 401 => static function ($self, $stackPos) { + $self->semValue = []; }, - 368 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\ShiftLeft($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 402 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, - 369 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\ShiftRight($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 403 => static function ($self, $stackPos) { + $self->semValue = []; }, - 370 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Pow($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 404 => static function ($self, $stackPos) { + $self->semValue = new Node\PropertyHook($self->semStack[$stackPos-(5-4)], $self->semStack[$stackPos-(5-5)], ['flags' => $self->semStack[$stackPos-(5-2)], 'byRef' => $self->semStack[$stackPos-(5-3)], 'params' => [], 'attrGroups' => $self->semStack[$stackPos-(5-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); + $self->checkPropertyHook($self->semValue, null); }, - 371 => function ($stackPos) { - $this->semValue = new Expr\AssignOp\Coalesce($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 405 => static function ($self, $stackPos) { + $self->semValue = new Node\PropertyHook($self->semStack[$stackPos-(8-4)], $self->semStack[$stackPos-(8-8)], ['flags' => $self->semStack[$stackPos-(8-2)], 'byRef' => $self->semStack[$stackPos-(8-3)], 'params' => $self->semStack[$stackPos-(8-6)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); + $self->checkPropertyHook($self->semValue, $stackPos-(8-5)); }, - 372 => function ($stackPos) { - $this->semValue = new Expr\PostInc($this->semStack[$stackPos-(2-1)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 406 => static function ($self, $stackPos) { + $self->semValue = null; }, - 373 => function ($stackPos) { - $this->semValue = new Expr\PreInc($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 407 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; }, - 374 => function ($stackPos) { - $this->semValue = new Expr\PostDec($this->semStack[$stackPos-(2-1)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 408 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; }, - 375 => function ($stackPos) { - $this->semValue = new Expr\PreDec($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 409 => static function ($self, $stackPos) { + $self->semValue = 0; }, - 376 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\BooleanOr($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 410 => static function ($self, $stackPos) { + $self->checkPropertyHookModifiers($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; }, - 377 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\BooleanAnd($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 411 => null, + 412 => null, + 413 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 378 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\LogicalOr($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 414 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 379 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\LogicalAnd($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 415 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 380 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\LogicalXor($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 416 => null, + 417 => null, + 418 => static function ($self, $stackPos) { + $self->semValue = new Expr\Assign($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 381 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\BitwiseOr($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 419 => static function ($self, $stackPos) { + $self->semValue = new Expr\Assign($self->fixupArrayDestructuring($self->semStack[$stackPos-(3-1)]), $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 382 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\BitwiseAnd($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 420 => static function ($self, $stackPos) { + $self->semValue = new Expr\Assign($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 383 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\BitwiseXor($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 421 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignRef($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 384 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Concat($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 422 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignRef($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + if (!$self->phpVersion->allowsAssignNewByReference()) { + $self->emitError(new Error('Cannot assign new by reference', $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]))); + } + }, - 385 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Plus($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 423 => null, + 424 => null, + 425 => static function ($self, $stackPos) { + $self->semValue = new Expr\FuncCall(new Node\Name($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos-(2-1)])), $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 386 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Minus($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 426 => static function ($self, $stackPos) { + $self->semValue = new Expr\Clone_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 387 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Mul($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 427 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Plus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 388 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Div($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 428 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Minus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 389 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Mod($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 429 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Mul($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 390 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\ShiftLeft($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 430 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Div($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 391 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\ShiftRight($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 431 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Concat($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 392 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Pow($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 432 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Mod($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 393 => function ($stackPos) { - $this->semValue = new Expr\UnaryPlus($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 433 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\BitwiseAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 394 => function ($stackPos) { - $this->semValue = new Expr\UnaryMinus($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 434 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\BitwiseOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 395 => function ($stackPos) { - $this->semValue = new Expr\BooleanNot($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 435 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\BitwiseXor($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 396 => function ($stackPos) { - $this->semValue = new Expr\BitwiseNot($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 436 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\ShiftLeft($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 397 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Identical($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 437 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\ShiftRight($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 398 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\NotIdentical($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 438 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Pow($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 399 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Equal($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 439 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Coalesce($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 400 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\NotEqual($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 440 => static function ($self, $stackPos) { + $self->semValue = new Expr\PostInc($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 401 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Spaceship($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 441 => static function ($self, $stackPos) { + $self->semValue = new Expr\PreInc($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 402 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Smaller($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 442 => static function ($self, $stackPos) { + $self->semValue = new Expr\PostDec($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 403 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\SmallerOrEqual($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 443 => static function ($self, $stackPos) { + $self->semValue = new Expr\PreDec($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 404 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Greater($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 444 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\BooleanOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 405 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\GreaterOrEqual($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 445 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\BooleanAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 406 => function ($stackPos) { - $this->semValue = new Expr\Instanceof_($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 446 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\LogicalOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 407 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; + 447 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\LogicalAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 408 => function ($stackPos) { - $this->semValue = new Expr\Ternary($this->semStack[$stackPos-(5-1)], $this->semStack[$stackPos-(5-3)], $this->semStack[$stackPos-(5-5)], $this->startAttributeStack[$stackPos-(5-1)] + $this->endAttributes); + 448 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\LogicalXor($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 409 => function ($stackPos) { - $this->semValue = new Expr\Ternary($this->semStack[$stackPos-(4-1)], null, $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 449 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\BitwiseOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 410 => function ($stackPos) { - $this->semValue = new Expr\BinaryOp\Coalesce($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 450 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\BitwiseAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 411 => function ($stackPos) { - $this->semValue = new Expr\Isset_($this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 451 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\BitwiseAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 412 => function ($stackPos) { - $this->semValue = new Expr\Empty_($this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 452 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\BitwiseXor($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 413 => function ($stackPos) { - $this->semValue = new Expr\Include_($this->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_INCLUDE, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 453 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Concat($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 414 => function ($stackPos) { - $this->semValue = new Expr\Include_($this->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_INCLUDE_ONCE, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 454 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Plus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 415 => function ($stackPos) { - $this->semValue = new Expr\Eval_($this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 455 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Minus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 416 => function ($stackPos) { - $this->semValue = new Expr\Include_($this->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_REQUIRE, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 456 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Mul($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 417 => function ($stackPos) { - $this->semValue = new Expr\Include_($this->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_REQUIRE_ONCE, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 457 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Div($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 418 => function ($stackPos) { - $this->semValue = new Expr\Cast\Int_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 458 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Mod($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 419 => function ($stackPos) { - $attrs = $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes; - $attrs['kind'] = $this->getFloatCastKind($this->semStack[$stackPos-(2-1)]); - $this->semValue = new Expr\Cast\Double($this->semStack[$stackPos-(2-2)], $attrs); + 459 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\ShiftLeft($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 420 => function ($stackPos) { - $this->semValue = new Expr\Cast\String_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 460 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\ShiftRight($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 421 => function ($stackPos) { - $this->semValue = new Expr\Cast\Array_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 461 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Pow($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 422 => function ($stackPos) { - $this->semValue = new Expr\Cast\Object_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 462 => static function ($self, $stackPos) { + $self->semValue = new Expr\UnaryPlus($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 423 => function ($stackPos) { - $this->semValue = new Expr\Cast\Bool_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 463 => static function ($self, $stackPos) { + $self->semValue = new Expr\UnaryMinus($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 424 => function ($stackPos) { - $this->semValue = new Expr\Cast\Unset_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 464 => static function ($self, $stackPos) { + $self->semValue = new Expr\BooleanNot($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 425 => function ($stackPos) { - $attrs = $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes; - $attrs['kind'] = strtolower($this->semStack[$stackPos-(2-1)]) === 'exit' ? Expr\Exit_::KIND_EXIT : Expr\Exit_::KIND_DIE; - $this->semValue = new Expr\Exit_($this->semStack[$stackPos-(2-2)], $attrs); + 465 => static function ($self, $stackPos) { + $self->semValue = new Expr\BitwiseNot($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 426 => function ($stackPos) { - $this->semValue = new Expr\ErrorSuppress($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 466 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Identical($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 427 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 467 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\NotIdentical($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 428 => function ($stackPos) { - $this->semValue = new Expr\ShellExec($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 468 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Equal($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 429 => function ($stackPos) { - $this->semValue = new Expr\Print_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 469 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\NotEqual($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 430 => function ($stackPos) { - $this->semValue = new Expr\Yield_(null, null, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 470 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Spaceship($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 431 => function ($stackPos) { - $this->semValue = new Expr\Yield_($this->semStack[$stackPos-(2-2)], null, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 471 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Smaller($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 432 => function ($stackPos) { - $this->semValue = new Expr\Yield_($this->semStack[$stackPos-(4-4)], $this->semStack[$stackPos-(4-2)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 472 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\SmallerOrEqual($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 433 => function ($stackPos) { - $this->semValue = new Expr\YieldFrom($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 473 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Greater($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 434 => function ($stackPos) { - $this->semValue = new Expr\Throw_($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 474 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\GreaterOrEqual($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 435 => function ($stackPos) { - $this->semValue = new Expr\ArrowFunction(['static' => false, 'byRef' => $this->semStack[$stackPos-(8-2)], 'params' => $this->semStack[$stackPos-(8-4)], 'returnType' => $this->semStack[$stackPos-(8-6)], 'expr' => $this->semStack[$stackPos-(8-8)], 'attrGroups' => []], $this->startAttributeStack[$stackPos-(8-1)] + $this->endAttributes); + 475 => static function ($self, $stackPos) { + $self->semValue = new Expr\Instanceof_($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 436 => function ($stackPos) { - $this->semValue = new Expr\ArrowFunction(['static' => true, 'byRef' => $this->semStack[$stackPos-(9-3)], 'params' => $this->semStack[$stackPos-(9-5)], 'returnType' => $this->semStack[$stackPos-(9-7)], 'expr' => $this->semStack[$stackPos-(9-9)], 'attrGroups' => []], $this->startAttributeStack[$stackPos-(9-1)] + $this->endAttributes); + 476 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; }, - 437 => function ($stackPos) { - $this->semValue = new Expr\Closure(['static' => false, 'byRef' => $this->semStack[$stackPos-(8-2)], 'params' => $this->semStack[$stackPos-(8-4)], 'uses' => $this->semStack[$stackPos-(8-6)], 'returnType' => $this->semStack[$stackPos-(8-7)], 'stmts' => $this->semStack[$stackPos-(8-8)], 'attrGroups' => []], $this->startAttributeStack[$stackPos-(8-1)] + $this->endAttributes); + 477 => static function ($self, $stackPos) { + $self->semValue = new Expr\Ternary($self->semStack[$stackPos-(5-1)], $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, - 438 => function ($stackPos) { - $this->semValue = new Expr\Closure(['static' => true, 'byRef' => $this->semStack[$stackPos-(9-3)], 'params' => $this->semStack[$stackPos-(9-5)], 'uses' => $this->semStack[$stackPos-(9-7)], 'returnType' => $this->semStack[$stackPos-(9-8)], 'stmts' => $this->semStack[$stackPos-(9-9)], 'attrGroups' => []], $this->startAttributeStack[$stackPos-(9-1)] + $this->endAttributes); + 478 => static function ($self, $stackPos) { + $self->semValue = new Expr\Ternary($self->semStack[$stackPos-(4-1)], null, $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 439 => function ($stackPos) { - $this->semValue = new Expr\ArrowFunction(['static' => false, 'byRef' => $this->semStack[$stackPos-(9-3)], 'params' => $this->semStack[$stackPos-(9-5)], 'returnType' => $this->semStack[$stackPos-(9-7)], 'expr' => $this->semStack[$stackPos-(9-9)], 'attrGroups' => $this->semStack[$stackPos-(9-1)]], $this->startAttributeStack[$stackPos-(9-1)] + $this->endAttributes); + 479 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Coalesce($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 440 => function ($stackPos) { - $this->semValue = new Expr\ArrowFunction(['static' => true, 'byRef' => $this->semStack[$stackPos-(10-4)], 'params' => $this->semStack[$stackPos-(10-6)], 'returnType' => $this->semStack[$stackPos-(10-8)], 'expr' => $this->semStack[$stackPos-(10-10)], 'attrGroups' => $this->semStack[$stackPos-(10-1)]], $this->startAttributeStack[$stackPos-(10-1)] + $this->endAttributes); + 480 => static function ($self, $stackPos) { + $self->semValue = new Expr\Isset_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 441 => function ($stackPos) { - $this->semValue = new Expr\Closure(['static' => false, 'byRef' => $this->semStack[$stackPos-(9-3)], 'params' => $this->semStack[$stackPos-(9-5)], 'uses' => $this->semStack[$stackPos-(9-7)], 'returnType' => $this->semStack[$stackPos-(9-8)], 'stmts' => $this->semStack[$stackPos-(9-9)], 'attrGroups' => $this->semStack[$stackPos-(9-1)]], $this->startAttributeStack[$stackPos-(9-1)] + $this->endAttributes); + 481 => static function ($self, $stackPos) { + $self->semValue = new Expr\Empty_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 442 => function ($stackPos) { - $this->semValue = new Expr\Closure(['static' => true, 'byRef' => $this->semStack[$stackPos-(10-4)], 'params' => $this->semStack[$stackPos-(10-6)], 'uses' => $this->semStack[$stackPos-(10-8)], 'returnType' => $this->semStack[$stackPos-(10-9)], 'stmts' => $this->semStack[$stackPos-(10-10)], 'attrGroups' => $this->semStack[$stackPos-(10-1)]], $this->startAttributeStack[$stackPos-(10-1)] + $this->endAttributes); + 482 => static function ($self, $stackPos) { + $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_INCLUDE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 443 => function ($stackPos) { - $this->semValue = array(new Stmt\Class_(null, ['type' => 0, 'extends' => $this->semStack[$stackPos-(8-4)], 'implements' => $this->semStack[$stackPos-(8-5)], 'stmts' => $this->semStack[$stackPos-(8-7)], 'attrGroups' => $this->semStack[$stackPos-(8-1)]], $this->startAttributeStack[$stackPos-(8-1)] + $this->endAttributes), $this->semStack[$stackPos-(8-3)]); - $this->checkClass($this->semValue[0], -1); + 483 => static function ($self, $stackPos) { + $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_INCLUDE_ONCE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 444 => function ($stackPos) { - $this->semValue = new Expr\New_($this->semStack[$stackPos-(3-2)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 484 => static function ($self, $stackPos) { + $self->semValue = new Expr\Eval_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 445 => function ($stackPos) { - list($class, $ctorArgs) = $this->semStack[$stackPos-(2-2)]; $this->semValue = new Expr\New_($class, $ctorArgs, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 485 => static function ($self, $stackPos) { + $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_REQUIRE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 446 => function ($stackPos) { - $this->semValue = array(); + 486 => static function ($self, $stackPos) { + $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_REQUIRE_ONCE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 447 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(4-3)]; + 487 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); + $attrs['kind'] = $self->getIntCastKind($self->semStack[$stackPos-(2-1)]); + $self->semValue = new Expr\Cast\Int_($self->semStack[$stackPos-(2-2)], $attrs); }, - 448 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(2-1)]; + 488 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); + $attrs['kind'] = $self->getFloatCastKind($self->semStack[$stackPos-(2-1)]); + $self->semValue = new Expr\Cast\Double($self->semStack[$stackPos-(2-2)], $attrs); }, - 449 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 489 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); + $attrs['kind'] = $self->getStringCastKind($self->semStack[$stackPos-(2-1)]); + $self->semValue = new Expr\Cast\String_($self->semStack[$stackPos-(2-2)], $attrs); }, - 450 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 490 => static function ($self, $stackPos) { + $self->semValue = new Expr\Cast\Array_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 451 => function ($stackPos) { - $this->semValue = new Expr\ClosureUse($this->semStack[$stackPos-(2-2)], $this->semStack[$stackPos-(2-1)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 491 => static function ($self, $stackPos) { + $self->semValue = new Expr\Cast\Object_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 452 => function ($stackPos) { - $this->semValue = new Expr\FuncCall($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 492 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); + $attrs['kind'] = $self->getBoolCastKind($self->semStack[$stackPos-(2-1)]); + $self->semValue = new Expr\Cast\Bool_($self->semStack[$stackPos-(2-2)], $attrs); }, - 453 => function ($stackPos) { - $this->semValue = new Expr\FuncCall($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 493 => static function ($self, $stackPos) { + $self->semValue = new Expr\Cast\Unset_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 454 => function ($stackPos) { - $this->semValue = new Expr\StaticCall($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 494 => static function ($self, $stackPos) { + $self->semValue = new Expr\Cast\Void_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 455 => function ($stackPos) { - $this->semValue = new Name($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 495 => static function ($self, $stackPos) { + $self->semValue = $self->createExitExpr($self->semStack[$stackPos-(2-1)], $stackPos-(2-1), $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 456 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 496 => static function ($self, $stackPos) { + $self->semValue = new Expr\ErrorSuppress($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 457 => function ($stackPos) { - $this->semValue = new Name($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 497 => null, + 498 => static function ($self, $stackPos) { + $self->semValue = new Expr\ShellExec($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 458 => function ($stackPos) { - $this->semValue = new Name($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 499 => static function ($self, $stackPos) { + $self->semValue = new Expr\Print_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 459 => function ($stackPos) { - $this->semValue = new Name\FullyQualified(substr($this->semStack[$stackPos-(1-1)], 1), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 500 => static function ($self, $stackPos) { + $self->semValue = new Expr\Yield_(null, null, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 460 => function ($stackPos) { - $this->semValue = new Name\Relative(substr($this->semStack[$stackPos-(1-1)], 10), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 501 => static function ($self, $stackPos) { + $self->semValue = new Expr\Yield_($self->semStack[$stackPos-(2-2)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 461 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 502 => static function ($self, $stackPos) { + $self->semValue = new Expr\Yield_($self->semStack[$stackPos-(4-4)], $self->semStack[$stackPos-(4-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 462 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 503 => static function ($self, $stackPos) { + $self->semValue = new Expr\YieldFrom($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 463 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; + 504 => static function ($self, $stackPos) { + $self->semValue = new Expr\Throw_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 464 => function ($stackPos) { - $this->semValue = new Expr\Error($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); $this->errorState = 2; + 505 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrowFunction(['static' => false, 'byRef' => $self->semStack[$stackPos-(8-2)], 'params' => $self->semStack[$stackPos-(8-4)], 'returnType' => $self->semStack[$stackPos-(8-6)], 'expr' => $self->semStack[$stackPos-(8-8)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); }, - 465 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 506 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrowFunction(['static' => true, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'returnType' => $self->semStack[$stackPos-(9-7)], 'expr' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, - 466 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 507 => static function ($self, $stackPos) { + $self->semValue = new Expr\Closure(['static' => false, 'byRef' => $self->semStack[$stackPos-(8-2)], 'params' => $self->semStack[$stackPos-(8-4)], 'uses' => $self->semStack[$stackPos-(8-6)], 'returnType' => $self->semStack[$stackPos-(8-7)], 'stmts' => $self->semStack[$stackPos-(8-8)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); }, - 467 => function ($stackPos) { - $this->semValue = null; + 508 => static function ($self, $stackPos) { + $self->semValue = new Expr\Closure(['static' => true, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'uses' => $self->semStack[$stackPos-(9-7)], 'returnType' => $self->semStack[$stackPos-(9-8)], 'stmts' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, - 468 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; + 509 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrowFunction(['static' => false, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'returnType' => $self->semStack[$stackPos-(9-7)], 'expr' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => $self->semStack[$stackPos-(9-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, - 469 => function ($stackPos) { - $this->semValue = array(); + 510 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrowFunction(['static' => true, 'byRef' => $self->semStack[$stackPos-(10-4)], 'params' => $self->semStack[$stackPos-(10-6)], 'returnType' => $self->semStack[$stackPos-(10-8)], 'expr' => $self->semStack[$stackPos-(10-10)], 'attrGroups' => $self->semStack[$stackPos-(10-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); }, - 470 => function ($stackPos) { - $this->semValue = array(new Scalar\EncapsedStringPart(Scalar\String_::parseEscapeSequences($this->semStack[$stackPos-(1-1)], '`'), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes)); + 511 => static function ($self, $stackPos) { + $self->semValue = new Expr\Closure(['static' => false, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'uses' => $self->semStack[$stackPos-(9-7)], 'returnType' => $self->semStack[$stackPos-(9-8)], 'stmts' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => $self->semStack[$stackPos-(9-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); }, - 471 => function ($stackPos) { - foreach ($this->semStack[$stackPos-(1-1)] as $s) { if ($s instanceof Node\Scalar\EncapsedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '`', true); } }; $this->semValue = $this->semStack[$stackPos-(1-1)]; + 512 => static function ($self, $stackPos) { + $self->semValue = new Expr\Closure(['static' => true, 'byRef' => $self->semStack[$stackPos-(10-4)], 'params' => $self->semStack[$stackPos-(10-6)], 'uses' => $self->semStack[$stackPos-(10-8)], 'returnType' => $self->semStack[$stackPos-(10-9)], 'stmts' => $self->semStack[$stackPos-(10-10)], 'attrGroups' => $self->semStack[$stackPos-(10-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); }, - 472 => function ($stackPos) { - $this->semValue = array(); + 513 => static function ($self, $stackPos) { + $self->semValue = array(new Stmt\Class_(null, ['type' => $self->semStack[$stackPos-(8-2)], 'extends' => $self->semStack[$stackPos-(8-4)], 'implements' => $self->semStack[$stackPos-(8-5)], 'stmts' => $self->semStack[$stackPos-(8-7)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])), $self->semStack[$stackPos-(8-3)]); + $self->checkClass($self->semValue[0], -1); }, - 473 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 514 => static function ($self, $stackPos) { + $self->semValue = new Expr\New_($self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 474 => function ($stackPos) { - $this->semValue = new Expr\ConstFetch($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 515 => static function ($self, $stackPos) { + list($class, $ctorArgs) = $self->semStack[$stackPos-(2-2)]; $self->semValue = new Expr\New_($class, $ctorArgs, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 475 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\Line($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 516 => static function ($self, $stackPos) { + $self->semValue = new Expr\New_($self->semStack[$stackPos-(2-2)], [], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 476 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\File($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 517 => null, + 518 => null, + 519 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 477 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\Dir($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 520 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-3)]; }, - 478 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\Class_($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 521 => null, + 522 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 479 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\Trait_($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 523 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 480 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\Method($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 524 => static function ($self, $stackPos) { + $self->semValue = new Node\ClosureUse($self->semStack[$stackPos-(2-2)], $self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 481 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\Function_($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 525 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 482 => function ($stackPos) { - $this->semValue = new Scalar\MagicConst\Namespace_($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 526 => static function ($self, $stackPos) { + $self->semValue = new Expr\FuncCall($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 483 => function ($stackPos) { - $this->semValue = new Expr\ClassConstFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 527 => static function ($self, $stackPos) { + $self->semValue = new Expr\FuncCall($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 484 => function ($stackPos) { - $this->semValue = new Expr\ClassConstFetch($this->semStack[$stackPos-(3-1)], new Expr\Error($this->startAttributeStack[$stackPos-(3-3)] + $this->endAttributeStack[$stackPos-(3-3)]), $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); $this->errorState = 2; + 528 => static function ($self, $stackPos) { + $self->semValue = new Expr\FuncCall($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 485 => function ($stackPos) { - $attrs = $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes; $attrs['kind'] = Expr\Array_::KIND_SHORT; - $this->semValue = new Expr\Array_($this->semStack[$stackPos-(3-2)], $attrs); + 529 => static function ($self, $stackPos) { + $self->semValue = new Expr\StaticCall($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 486 => function ($stackPos) { - $attrs = $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes; $attrs['kind'] = Expr\Array_::KIND_LONG; - $this->semValue = new Expr\Array_($this->semStack[$stackPos-(4-3)], $attrs); + 530 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 487 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 531 => null, + 532 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 488 => function ($stackPos) { - $attrs = $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes; $attrs['kind'] = ($this->semStack[$stackPos-(1-1)][0] === "'" || ($this->semStack[$stackPos-(1-1)][1] === "'" && ($this->semStack[$stackPos-(1-1)][0] === 'b' || $this->semStack[$stackPos-(1-1)][0] === 'B')) ? Scalar\String_::KIND_SINGLE_QUOTED : Scalar\String_::KIND_DOUBLE_QUOTED); - $this->semValue = new Scalar\String_(Scalar\String_::parse($this->semStack[$stackPos-(1-1)]), $attrs); + 533 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 489 => function ($stackPos) { - $attrs = $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes; $attrs['kind'] = Scalar\String_::KIND_DOUBLE_QUOTED; - foreach ($this->semStack[$stackPos-(3-2)] as $s) { if ($s instanceof Node\Scalar\EncapsedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '"', true); } }; $this->semValue = new Scalar\Encapsed($this->semStack[$stackPos-(3-2)], $attrs); + 534 => static function ($self, $stackPos) { + $self->semValue = new Name\FullyQualified(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 490 => function ($stackPos) { - $this->semValue = $this->parseLNumber($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 535 => static function ($self, $stackPos) { + $self->semValue = new Name\Relative(substr($self->semStack[$stackPos-(1-1)], 10), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 491 => function ($stackPos) { - $this->semValue = new Scalar\DNumber(Scalar\DNumber::parse($this->semStack[$stackPos-(1-1)]), $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 536 => null, + 537 => null, + 538 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; }, - 492 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 539 => static function ($self, $stackPos) { + $self->semValue = new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; }, - 493 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 540 => null, + 541 => null, + 542 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 494 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 543 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); foreach ($self->semValue as $s) { if ($s instanceof Node\InterpolatedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '`', $self->phpVersion->supportsUnicodeEscapes()); } }; }, - 495 => function ($stackPos) { - $this->semValue = $this->parseDocString($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-2)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes, $this->startAttributeStack[$stackPos-(3-3)] + $this->endAttributeStack[$stackPos-(3-3)], true); + 544 => static function ($self, $stackPos) { + foreach ($self->semStack[$stackPos-(1-1)] as $s) { if ($s instanceof Node\InterpolatedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '`', $self->phpVersion->supportsUnicodeEscapes()); } }; $self->semValue = $self->semStack[$stackPos-(1-1)]; }, - 496 => function ($stackPos) { - $this->semValue = $this->parseDocString($this->semStack[$stackPos-(2-1)], '', $this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes, $this->startAttributeStack[$stackPos-(2-2)] + $this->endAttributeStack[$stackPos-(2-2)], true); + 545 => static function ($self, $stackPos) { + $self->semValue = array(); }, - 497 => function ($stackPos) { - $this->semValue = $this->parseDocString($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-2)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes, $this->startAttributeStack[$stackPos-(3-3)] + $this->endAttributeStack[$stackPos-(3-3)], true); + 546 => null, + 547 => static function ($self, $stackPos) { + $self->semValue = new Expr\ConstFetch($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 498 => function ($stackPos) { - $this->semValue = null; + 548 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Line($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 499 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 549 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\File($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 500 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 550 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Dir($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 501 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; + 551 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Class_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 502 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 552 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Trait_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 503 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 553 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Method($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 504 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 554 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Function_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 505 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 555 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Namespace_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 506 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 556 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Property($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 507 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; + 557 => static function ($self, $stackPos) { + $self->semValue = new Expr\ClassConstFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 508 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 558 => static function ($self, $stackPos) { + $self->semValue = new Expr\ClassConstFetch($self->semStack[$stackPos-(5-1)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); }, - 509 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 559 => static function ($self, $stackPos) { + $self->semValue = new Expr\ClassConstFetch($self->semStack[$stackPos-(3-1)], new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(3-3)], $self->tokenEndStack[$stackPos-(3-3)])), $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; }, - 510 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 560 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = Expr\Array_::KIND_SHORT; + $self->semValue = new Expr\Array_($self->semStack[$stackPos-(3-2)], $attrs); }, - 511 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 561 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = Expr\Array_::KIND_LONG; + $self->semValue = new Expr\Array_($self->semStack[$stackPos-(4-3)], $attrs); + $self->createdArrays->offsetSet($self->semValue); }, - 512 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 562 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(1-1)]; $self->createdArrays->offsetSet($self->semValue); }, - 513 => function ($stackPos) { - $this->semValue = new Expr\MethodCall($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 563 => static function ($self, $stackPos) { + $self->semValue = Scalar\String_::fromString($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]), $self->phpVersion->supportsUnicodeEscapes()); }, - 514 => function ($stackPos) { - $this->semValue = new Expr\NullsafeMethodCall($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->semStack[$stackPos-(4-4)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 564 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = Scalar\String_::KIND_DOUBLE_QUOTED; + foreach ($self->semStack[$stackPos-(3-2)] as $s) { if ($s instanceof Node\InterpolatedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '"', $self->phpVersion->supportsUnicodeEscapes()); } }; $self->semValue = new Scalar\InterpolatedString($self->semStack[$stackPos-(3-2)], $attrs); }, - 515 => function ($stackPos) { - $this->semValue = null; + 565 => static function ($self, $stackPos) { + $self->semValue = $self->parseLNumber($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]), $self->phpVersion->allowsInvalidOctals()); }, - 516 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 566 => static function ($self, $stackPos) { + $self->semValue = Scalar\Float_::fromString($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 517 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 567 => null, + 568 => null, + 569 => null, + 570 => static function ($self, $stackPos) { + $self->semValue = $self->parseDocString($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), $self->getAttributes($self->tokenStartStack[$stackPos-(3-3)], $self->tokenEndStack[$stackPos-(3-3)]), true); }, - 518 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 571 => static function ($self, $stackPos) { + $self->semValue = $self->parseDocString($self->semStack[$stackPos-(2-1)], '', $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]), $self->getAttributes($self->tokenStartStack[$stackPos-(2-2)], $self->tokenEndStack[$stackPos-(2-2)]), true); }, - 519 => function ($stackPos) { - $this->semValue = new Expr\PropertyFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 572 => static function ($self, $stackPos) { + $self->semValue = $self->parseDocString($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), $self->getAttributes($self->tokenStartStack[$stackPos-(3-3)], $self->tokenEndStack[$stackPos-(3-3)]), true); }, - 520 => function ($stackPos) { - $this->semValue = new Expr\NullsafePropertyFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 573 => static function ($self, $stackPos) { + $self->semValue = null; }, - 521 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 574 => null, + 575 => null, + 576 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; }, - 522 => function ($stackPos) { - $this->semValue = new Expr\Variable($this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 577 => null, + 578 => null, + 579 => null, + 580 => null, + 581 => null, + 582 => null, + 583 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; }, - 523 => function ($stackPos) { - $this->semValue = new Expr\Variable($this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 584 => null, + 585 => null, + 586 => null, + 587 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 524 => function ($stackPos) { - $this->semValue = new Expr\Variable(new Expr\Error($this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes), $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); $this->errorState = 2; + 588 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 525 => function ($stackPos) { - $var = $this->semStack[$stackPos-(1-1)]->name; $this->semValue = \is_string($var) ? new Node\VarLikeIdentifier($var, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes) : $var; + 589 => null, + 590 => static function ($self, $stackPos) { + $self->semValue = new Expr\MethodCall($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 526 => function ($stackPos) { - $this->semValue = new Expr\StaticPropertyFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 591 => static function ($self, $stackPos) { + $self->semValue = new Expr\NullsafeMethodCall($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 527 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 592 => static function ($self, $stackPos) { + $self->semValue = null; }, - 528 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 593 => null, + 594 => null, + 595 => null, + 596 => static function ($self, $stackPos) { + $self->semValue = new Expr\PropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 529 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 597 => static function ($self, $stackPos) { + $self->semValue = new Expr\NullsafePropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 530 => function ($stackPos) { - $this->semValue = new Expr\PropertyFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 598 => null, + 599 => static function ($self, $stackPos) { + $self->semValue = new Expr\Variable($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 531 => function ($stackPos) { - $this->semValue = new Expr\NullsafePropertyFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 600 => static function ($self, $stackPos) { + $self->semValue = new Expr\Variable($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 532 => function ($stackPos) { - $this->semValue = new Expr\StaticPropertyFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 601 => static function ($self, $stackPos) { + $self->semValue = new Expr\Variable(new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])), $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; }, - 533 => function ($stackPos) { - $this->semValue = new Expr\StaticPropertyFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 602 => static function ($self, $stackPos) { + $var = $self->semStack[$stackPos-(1-1)]->name; $self->semValue = \is_string($var) ? new Node\VarLikeIdentifier($var, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])) : $var; }, - 534 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 603 => static function ($self, $stackPos) { + $self->semValue = new Expr\StaticPropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 535 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; + 604 => null, + 605 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 536 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 606 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 537 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 607 => static function ($self, $stackPos) { + $self->semValue = new Expr\PropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 538 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; + 608 => static function ($self, $stackPos) { + $self->semValue = new Expr\NullsafePropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 539 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 609 => static function ($self, $stackPos) { + $self->semValue = new Expr\StaticPropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 540 => function ($stackPos) { - $this->semValue = new Expr\Error($this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); $this->errorState = 2; + 610 => static function ($self, $stackPos) { + $self->semValue = new Expr\StaticPropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 541 => function ($stackPos) { - $this->semValue = new Expr\List_($this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 611 => null, + 612 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; }, - 542 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; $end = count($this->semValue)-1; if ($this->semValue[$end] === null) array_pop($this->semValue); + 613 => null, + 614 => null, + 615 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; }, - 543 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos]; + 616 => null, + 617 => static function ($self, $stackPos) { + $self->semValue = new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; }, - 544 => function ($stackPos) { - /* do nothing -- prevent default action of $$=$this->semStack[$1]. See $551. */ + 618 => static function ($self, $stackPos) { + $self->semValue = new Expr\List_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); $self->semValue->setAttribute('kind', Expr\List_::KIND_LIST); + $self->postprocessList($self->semValue); }, - 545 => function ($stackPos) { - $this->semStack[$stackPos-(3-1)][] = $this->semStack[$stackPos-(3-3)]; $this->semValue = $this->semStack[$stackPos-(3-1)]; + 619 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(1-1)]; $end = count($self->semValue)-1; if ($self->semValue[$end]->value instanceof Expr\Error) array_pop($self->semValue); }, - 546 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 620 => null, + 621 => static function ($self, $stackPos) { + /* do nothing -- prevent default action of $$=$self->semStack[$1]. See $551. */ }, - 547 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(1-1)], null, false, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 622 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; }, - 548 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(2-2)], null, true, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 623 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 549 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(1-1)], null, false, $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 624 => static function ($self, $stackPos) { + $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(1-1)], null, false, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 550 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(3-3)], $this->semStack[$stackPos-(3-1)], false, $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 625 => static function ($self, $stackPos) { + $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(2-2)], null, true, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, - 551 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(4-4)], $this->semStack[$stackPos-(4-1)], true, $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 626 => static function ($self, $stackPos) { + $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(1-1)], null, false, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 552 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(3-3)], $this->semStack[$stackPos-(3-1)], false, $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 627 => static function ($self, $stackPos) { + $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(3-3)], $self->semStack[$stackPos-(3-1)], false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 553 => function ($stackPos) { - $this->semValue = new Expr\ArrayItem($this->semStack[$stackPos-(2-2)], null, false, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes, true, $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 628 => static function ($self, $stackPos) { + $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(4-4)], $self->semStack[$stackPos-(4-1)], true, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 554 => function ($stackPos) { - $this->semValue = null; + 629 => static function ($self, $stackPos) { + $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(3-3)], $self->semStack[$stackPos-(3-1)], false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 555 => function ($stackPos) { - $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; + 630 => static function ($self, $stackPos) { + $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(2-2)], null, false, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]), true); }, - 556 => function ($stackPos) { - $this->semStack[$stackPos-(2-1)][] = $this->semStack[$stackPos-(2-2)]; $this->semValue = $this->semStack[$stackPos-(2-1)]; + 631 => static function ($self, $stackPos) { + /* Create an Error node now to remember the position. We'll later either report an error, + or convert this into a null element, depending on whether this is a creation or destructuring context. */ + $attrs = $self->createEmptyElemAttributes($self->tokenPos); + $self->semValue = new Node\ArrayItem(new Expr\Error($attrs), null, false, $attrs); }, - 557 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(1-1)]); + 632 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, - 558 => function ($stackPos) { - $this->semValue = array($this->semStack[$stackPos-(2-1)], $this->semStack[$stackPos-(2-2)]); + 633 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; }, - 559 => function ($stackPos) { - $this->semValue = new Scalar\EncapsedStringPart($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 634 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); }, - 560 => function ($stackPos) { - $this->semValue = new Expr\Variable($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 635 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)]); }, - 561 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 636 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]); $attrs['rawValue'] = $self->semStack[$stackPos-(1-1)]; $self->semValue = new Node\InterpolatedStringPart($self->semStack[$stackPos-(1-1)], $attrs); }, - 562 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(4-1)], $this->semStack[$stackPos-(4-3)], $this->startAttributeStack[$stackPos-(4-1)] + $this->endAttributes); + 637 => static function ($self, $stackPos) { + $self->semValue = new Expr\Variable($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 563 => function ($stackPos) { - $this->semValue = new Expr\PropertyFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 638 => null, + 639 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); }, - 564 => function ($stackPos) { - $this->semValue = new Expr\NullsafePropertyFetch($this->semStack[$stackPos-(3-1)], $this->semStack[$stackPos-(3-3)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 640 => static function ($self, $stackPos) { + $self->semValue = new Expr\PropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 565 => function ($stackPos) { - $this->semValue = new Expr\Variable($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 641 => static function ($self, $stackPos) { + $self->semValue = new Expr\NullsafePropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 566 => function ($stackPos) { - $this->semValue = new Expr\Variable($this->semStack[$stackPos-(3-2)], $this->startAttributeStack[$stackPos-(3-1)] + $this->endAttributes); + 642 => static function ($self, $stackPos) { + $self->semValue = new Expr\Variable($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 567 => function ($stackPos) { - $this->semValue = new Expr\ArrayDimFetch($this->semStack[$stackPos-(6-2)], $this->semStack[$stackPos-(6-4)], $this->startAttributeStack[$stackPos-(6-1)] + $this->endAttributes); + 643 => static function ($self, $stackPos) { + $self->semValue = new Expr\Variable($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); }, - 568 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(3-2)]; + 644 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(6-2)], $self->semStack[$stackPos-(6-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); }, - 569 => function ($stackPos) { - $this->semValue = new Scalar\String_($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 645 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; }, - 570 => function ($stackPos) { - $this->semValue = $this->parseNumString($this->semStack[$stackPos-(1-1)], $this->startAttributeStack[$stackPos-(1-1)] + $this->endAttributes); + 646 => static function ($self, $stackPos) { + $self->semValue = new Scalar\String_($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 571 => function ($stackPos) { - $this->semValue = $this->parseNumString('-' . $this->semStack[$stackPos-(2-2)], $this->startAttributeStack[$stackPos-(2-1)] + $this->endAttributes); + 647 => static function ($self, $stackPos) { + $self->semValue = $self->parseNumString($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); }, - 572 => function ($stackPos) { - $this->semValue = $this->semStack[$stackPos-(1-1)]; + 648 => static function ($self, $stackPos) { + $self->semValue = $self->parseNumString('-' . $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); }, + 649 => null, ]; } } diff --git a/lib/PhpParser/Parser/Php8.php b/lib/PhpParser/Parser/Php8.php new file mode 100644 index 0000000000..7a15cef564 --- /dev/null +++ b/lib/PhpParser/Parser/Php8.php @@ -0,0 +1,2909 @@ +'", + "T_IS_GREATER_OR_EQUAL", + "T_PIPE", + "'.'", + "T_SL", + "T_SR", + "'+'", + "'-'", + "'*'", + "'/'", + "'%'", + "'!'", + "T_INSTANCEOF", + "'~'", + "T_INC", + "T_DEC", + "T_INT_CAST", + "T_DOUBLE_CAST", + "T_STRING_CAST", + "T_ARRAY_CAST", + "T_OBJECT_CAST", + "T_BOOL_CAST", + "T_UNSET_CAST", + "'@'", + "T_POW", + "'['", + "T_NEW", + "T_CLONE", + "T_EXIT", + "T_IF", + "T_ELSEIF", + "T_ELSE", + "T_ENDIF", + "T_LNUMBER", + "T_DNUMBER", + "T_STRING", + "T_STRING_VARNAME", + "T_VARIABLE", + "T_NUM_STRING", + "T_INLINE_HTML", + "T_ENCAPSED_AND_WHITESPACE", + "T_CONSTANT_ENCAPSED_STRING", + "T_ECHO", + "T_DO", + "T_WHILE", + "T_ENDWHILE", + "T_FOR", + "T_ENDFOR", + "T_FOREACH", + "T_ENDFOREACH", + "T_DECLARE", + "T_ENDDECLARE", + "T_AS", + "T_SWITCH", + "T_MATCH", + "T_ENDSWITCH", + "T_CASE", + "T_DEFAULT", + "T_BREAK", + "T_CONTINUE", + "T_GOTO", + "T_FUNCTION", + "T_FN", + "T_CONST", + "T_RETURN", + "T_TRY", + "T_CATCH", + "T_FINALLY", + "T_USE", + "T_INSTEADOF", + "T_GLOBAL", + "T_STATIC", + "T_ABSTRACT", + "T_FINAL", + "T_PRIVATE", + "T_PROTECTED", + "T_PUBLIC", + "T_READONLY", + "T_PUBLIC_SET", + "T_PROTECTED_SET", + "T_PRIVATE_SET", + "T_VAR", + "T_UNSET", + "T_ISSET", + "T_EMPTY", + "T_HALT_COMPILER", + "T_CLASS", + "T_TRAIT", + "T_INTERFACE", + "T_ENUM", + "T_EXTENDS", + "T_IMPLEMENTS", + "T_OBJECT_OPERATOR", + "T_NULLSAFE_OBJECT_OPERATOR", + "T_LIST", + "T_ARRAY", + "T_CALLABLE", + "T_CLASS_C", + "T_TRAIT_C", + "T_METHOD_C", + "T_FUNC_C", + "T_PROPERTY_C", + "T_LINE", + "T_FILE", + "T_START_HEREDOC", + "T_END_HEREDOC", + "T_DOLLAR_OPEN_CURLY_BRACES", + "T_CURLY_OPEN", + "T_PAAMAYIM_NEKUDOTAYIM", + "T_NAMESPACE", + "T_NS_C", + "T_DIR", + "T_NS_SEPARATOR", + "T_ELLIPSIS", + "T_NAME_FULLY_QUALIFIED", + "T_NAME_QUALIFIED", + "T_NAME_RELATIVE", + "T_ATTRIBUTE", + "';'", + "']'", + "'('", + "')'", + "'{'", + "'}'", + "'`'", + "'\"'", + "'$'" + ); + + protected array $tokenToSymbol = array( + 0, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 58, 172, 174, 173, 57, 174, 174, + 167, 168, 55, 53, 9, 54, 50, 56, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 32, 165, + 45, 17, 47, 31, 70, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 72, 174, 166, 37, 174, 171, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 169, 36, 170, 60, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, + 174, 174, 174, 174, 174, 174, 1, 2, 3, 4, + 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, + 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, + 27, 28, 29, 30, 33, 34, 35, 38, 39, 40, + 41, 42, 43, 44, 46, 48, 49, 51, 52, 59, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 71, + 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, + 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, + 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, + 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, + 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, + 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, + 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, + 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, + 163, 164 + ); + + protected array $action = array( + 132, 133, 134, 582, 135, 136, 162, 779, 780, 781, + 137, 41, 863,-32766, 970, 1404, -584, 974, 973, 1302, + 0, 395, 396, 455, 246, 854,-32766,-32766,-32766,-32766, + -32766, 440,-32766, 27,-32766, 773, 772,-32766,-32766,-32766, + -32766, 508,-32766,-32766,-32766,-32766,-32766,-32766,-32766,-32766, + 131,-32766,-32766,-32766,-32766, 437, 782, 859, 1148,-32766, + 949,-32766,-32766,-32766,-32766,-32766,-32766, 972, 1385, 300, + 271, 53, 398, 786, 787, 788, 789, 305, 865, 441, + -341, 39, 254, -584, -584, -195, 843, 790, 791, 792, + 793, 794, 795, 796, 797, 798, 799, 819, 583, 820, + 821, 822, 823, 811, 812, 353, 354, 814, 815, 800, + 801, 802, 804, 805, 806, 368, 846, 847, 848, 849, + 850, 584, 1062, -194, 856, 807, 808, 585, 586, 3, + 831, 829, 830, 842, 826, 827, 4, 860, 587, 588, + 825, 589, 590, 591, 592, 939, 593, 594, 5, 854, + -32766,-32766,-32766, 828, 595, 596,-32766, 138, 764, 132, + 133, 134, 582, 135, 136, 1098, 779, 780, 781, 137, + 41,-32766,-32766,-32766,-32766,-32766,-32766, -275, 1302, 613, + 153, 1071, 749, 990, 991,-32766,-32766,-32766, 992,-32766, + 891,-32766, 892,-32766, 773, 772,-32766, 986, 1309, 397, + 396,-32766,-32766,-32766, 858, 299, 630,-32766,-32766, 440, + 502, 736,-32766,-32766, 437, 782,-32767,-32767,-32767,-32767, + 106, 107, 108, 109, 951,-32766, 1021, 29, 734, 271, + 53, 398, 786, 787, 788, 789, 144, 1071, 441, -341, + 332, 38, 864, 862, -195, 843, 790, 791, 792, 793, + 794, 795, 796, 797, 798, 799, 819, 583, 820, 821, + 822, 823, 811, 812, 353, 354, 814, 815, 800, 801, + 802, 804, 805, 806, 368, 846, 847, 848, 849, 850, + 584, 863, -194, 139, 807, 808, 585, 586, 323, 831, + 829, 830, 842, 826, 827, 1370, 148, 587, 588, 825, + 589, 590, 591, 592, 245, 593, 594, 395, 396,-32766, + -32766,-32766, 828, 595, 596, -85, 138, 440, 132, 133, + 134, 582, 135, 136, 1095, 779, 780, 781, 137, 41, + -32766,-32766,-32766,-32766,-32766, 51, 578, 1302, 257,-32766, + 636, 107, 108, 109,-32766,-32766,-32766, 503,-32766, 316, + -32766,-32766,-32766, 773, 772,-32766, -383, 166, -383, 1022, + -32766,-32766,-32766, 305, 79, 1133,-32766,-32766, 1414, 762, + 332, 1415,-32766, 437, 782,-32766, 1071, 110, 111, 112, + 113, 114, -85, 283,-32766, 477, 478, 479, 271, 53, + 398, 786, 787, 788, 789, 115, 407, 441, 10,-32766, + 299, 1341, 306, 307, 843, 790, 791, 792, 793, 794, + 795, 796, 797, 798, 799, 819, 583, 820, 821, 822, + 823, 811, 812, 353, 354, 814, 815, 800, 801, 802, + 804, 805, 806, 368, 846, 847, 848, 849, 850, 584, + 320, 1068, -582, 807, 808, 585, 586, 1389, 831, 829, + 830, 842, 826, 827, 329, 1388, 587, 588, 825, 589, + 590, 591, 592, 86, 593, 594, 1071, 332,-32766,-32766, + -32766, 828, 595, 596, 349, 151, -581, 132, 133, 134, + 582, 135, 136, 1100, 779, 780, 781, 137, 41,-32766, + 290,-32766,-32766,-32766,-32766,-32766,-32766,-32766,-32767,-32767, + -32767,-32767,-32767,-32766,-32766,-32766, 891, 1175, 892, -582, + -582, 754, 773, 772, 1159, 1160, 1161, 1155, 1154, 1153, + 1162, 1156, 1157, 1158,-32766, -582,-32766,-32766,-32766,-32766, + -32766,-32766,-32766, 782,-32766,-32766,-32766, -588, -78,-32766, + -32766,-32766, 350, -581, -581,-32766,-32766, 271, 53, 398, + 786, 787, 788, 789, 383,-32766, 441,-32766,-32766, -581, + -32766, 773, 772, 843, 790, 791, 792, 793, 794, 795, + 796, 797, 798, 799, 819, 583, 820, 821, 822, 823, + 811, 812, 353, 354, 814, 815, 800, 801, 802, 804, + 805, 806, 368, 846, 847, 848, 849, 850, 584, -620, + 1068, -620, 807, 808, 585, 586, 389, 831, 829, 830, + 842, 826, 827, 441, 405, 587, 588, 825, 589, 590, + 591, 592, 333, 593, 594, 1071, 87, 88, 89, 459, + 828, 595, 596, 460, 151, 803, 774, 775, 776, 777, + 778, 854, 779, 780, 781, 816, 817, 40, 461, 90, + 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, + 111, 112, 113, 114, 462, 283, 1329, 1159, 1160, 1161, + 1155, 1154, 1153, 1162, 1156, 1157, 1158, 115, 869, 488, + 489, 782, 1304, 1303, 1305, 108, 109, 1132, 154,-32766, + -32766, 1134, 679, 23, 156, 783, 784, 785, 786, 787, + 788, 789, 698, 699, 852, 152, 423, -580, 393, 394, + 157, 843, 790, 791, 792, 793, 794, 795, 796, 797, + 798, 799, 819, 841, 820, 821, 822, 823, 811, 812, + 813, 840, 814, 815, 800, 801, 802, 804, 805, 806, + 845, 846, 847, 848, 849, 850, 851, 1094, -578, 863, + 807, 808, 809, 810, -58, 831, 829, 830, 842, 826, + 827, 399, 400, 818, 824, 825, 832, 833, 835, 834, + 294, 836, 837, 158, -580, -580, 160, 294, 828, 839, + 838, 54, 55, 56, 57, 534, 58, 59, 36, -110, + -580, -57, 60, 61, -110, 62, -110, 670, 671, 129, + 130, 312, -587, 140, -110, -110, -110, -110, -110, -110, + -110, -110, -110, -110, -110, -578, -578, 141, 147, 949, + 161, 712, -87, 163, 164, 165, -84, 949, -78, -73, + -72, -578, 63, 64, 143, -309, -71, 65, 332, 66, + 251, 252, 67, 68, 69, 70, 71, 72, 73, 74, + 739, 31, 276, 47, 457, 535, -357, 713, 740, 1335, + 1336, 536, -70, 863, 1068, -69, -68, 1333, 45, 22, + 537, 949, 538, -67, 539, -66, 540, 52, -65, 541, + 542, 714, 715, -46, 48, 49, 463, 392, 391, 1071, + 50, 543, -18, 145, 281, 1302, 381, 348, 291, 750, + 1304, 1303, 1305, 1295, 939, 753, 290, 948, 545, 546, + 547, 150, 939, 290, -305, 295, 288, 289, 292, 293, + 549, 550, 338, 1321, 1322, 1323, 1324, 1326, 1318, 1319, + 304, 1300, 296, 301, 302, 283, 1325, 1320, 773, 772, + 1304, 1303, 1305, 305, 308, 309, 75, -154, -154, -154, + 327, 328, 332, 966, 854, 1070, 939, 149, 115, 1416, + 388, 680, -154, 708, -154, 725, -154, 13, -154, 668, + 723, 313, 31, 277, 1304, 1303, 1305, 863, 390,-32766, + 600, 1166, 987, 951, 863, 310, 701, 734, 1333, 990, + 991, 951,-32766, 686, 544, 734, 949, 685, 606, 1340, + 485, 513, 925, 986, -110, -110, -110, 35, 116, 117, + 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, + 128, 702, 949, 634, 1295, 773, 772, 741, -579, 305, + -614, 1334, 0, 0, 0, 951, 311, 949, 0, 734, + -154, 549, 550, 319, 1321, 1322, 1323, 1324, 1326, 1318, + 1319, 1209, 1211, 744, 0, 1342, 0, 1325, 1320, -544, + -534, 0, -578,-32766, -4, 949, 11, 77, 751, 1302, + 30, 387, 328, 332, 862, 43,-32766,-32766,-32766, -613, + -32766, 939,-32766, 968,-32766, 44, 759,-32766, 1330, 773, + 772, 760,-32766,-32766,-32766, -579, -579, 882,-32766,-32766, + 930, 1031, 1008, 1015,-32766, 437, 1005, 939, 1016, 928, + 1003, -579, 1137, 1140, 1141, 1138,-32766, 1177, 1139, 1145, + 37, 874, 939, -586, 1357, 1374, 1407,-32766, 673, -578, + -578, -612, -588, 1302, -587, -586, -585, 31, 276, -528, + -32766,-32766,-32766, 1,-32766, -578,-32766, 78,-32766, 863, + 939,-32766, 32, 1333, -278, 33,-32766,-32766,-32766, 42, + 1007, 46,-32766,-32766, 734, 76, 80, 81,-32766, 437, + 82, 83, 390, 84, 453, 31, 277, 85, 146, 303, + -32766, 155, 159, 990, 991, 249, 951, 863, 544, 1295, + 734, 1333, 334, 369, 370, 371, 548, 986, -110, -110, + -110, 951, 372, 326, 373, 734, 374, 550, 375, 1321, + 1322, 1323, 1324, 1326, 1318, 1319, 376, 377, 422, 378, + 21, -50, 1325, 1320, 379, 382, 454, 1295, 577, 951, + 380, 384, 77, 734, -4, -276, -275, 328, 332, 15, + 16, 17, 18, 20, 363, 550, 421, 1321, 1322, 1323, + 1324, 1326, 1318, 1319, 142, 504, 505, 512, 515, 516, + 1325, 1320, 949, 517, 518,-32766, 522, 523, 524, 531, + 77, 1302, 611, 718, 1101, 328, 332, 1097,-32766,-32766, + -32766, 1250,-32766, 1331,-32766, 949,-32766, 1099, 1096,-32766, + 1077, 1290, 1309, 1073,-32766,-32766,-32766, -280,-32766, -102, + -32766,-32766, 14, 19, 1302, 24,-32766, 437, 323, 420, + 625,-32766,-32766,-32766, 631,-32766, 659,-32766,-32766,-32766, + 724, 1254,-32766, -16, 1308, 1251, 1386,-32766,-32766,-32766, + 735,-32766, 738,-32766,-32766, 742, 743, 1302, 745,-32766, + 437, 746, 747, 748,-32766,-32766,-32766, 939,-32766, 300, + -32766,-32766,-32766, 752, 1309,-32766, 764, 737, 332, 765, + -32766,-32766,-32766, -253, -253, -253,-32766,-32766, 426, 390, + 939, 756,-32766, 437, 926, 863, 1411, 1413, 885, 884, + 990, 991, 980, 1023,-32766, 544, -252, -252, -252, 1412, + 979, 977, 390, 925, 986, -110, -110, -110, 978, 981, + 1283, 959, 969, 990, 991, 957, 1176, 1172, 544, 1126, + -110, -110, 1013, 1014, 657, -110, 925, 986, -110, -110, + -110, 1410, 2, 1368, -110, 1268, 951, 1383, 0, 0, + 734, -253, 0,-32766, 0, 0,-32766, 863, 1059, 1054, + 1053, 1052, 1058, 1055, 1056, 1057, 0, 0, 0, 951, + 0, 0, 0, 734, -252, 305, 0, 0, 79, 0, + 0, 1071, 0, 0, 332, 0, 0, 0, 0, 0, + 0, 0, -110, -110, 0, 0, 0, -110, 0, 0, + 0, 0, 0, 0, 0, 299, -110, 0, 0, 0, + 0, 0, 0, 0, 0,-32766, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 305, 0, 0, + 79, 0, 0, 0, 0, 0, 332 + ); + + protected array $actionCheck = array( + 3, 4, 5, 6, 7, 8, 17, 10, 11, 12, + 13, 14, 84, 76, 1, 87, 72, 74, 75, 82, + 0, 108, 109, 110, 15, 82, 89, 90, 91, 10, + 93, 118, 95, 103, 97, 38, 39, 100, 10, 11, + 12, 104, 105, 106, 107, 10, 11, 12, 111, 112, + 15, 10, 11, 12, 117, 118, 59, 82, 128, 31, + 1, 33, 34, 35, 36, 37, 129, 124, 1, 31, + 73, 74, 75, 76, 77, 78, 79, 164, 1, 82, + 9, 153, 154, 139, 140, 9, 89, 90, 91, 92, + 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, + 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, + 123, 124, 1, 9, 82, 128, 129, 130, 131, 9, + 133, 134, 135, 136, 137, 138, 9, 162, 141, 142, + 143, 144, 145, 146, 147, 86, 149, 150, 9, 82, + 10, 11, 12, 156, 157, 158, 118, 160, 169, 3, + 4, 5, 6, 7, 8, 168, 10, 11, 12, 13, + 14, 31, 76, 33, 34, 35, 36, 168, 82, 83, + 15, 143, 169, 119, 120, 89, 90, 91, 124, 93, + 108, 95, 110, 97, 38, 39, 100, 133, 1, 108, + 109, 105, 106, 107, 162, 167, 1, 111, 112, 118, + 32, 169, 118, 117, 118, 59, 45, 46, 47, 48, + 49, 50, 51, 52, 165, 129, 32, 9, 169, 73, + 74, 75, 76, 77, 78, 79, 169, 143, 82, 168, + 173, 9, 165, 161, 168, 89, 90, 91, 92, 93, + 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, + 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, + 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, + 124, 84, 168, 9, 128, 129, 130, 131, 168, 133, + 134, 135, 136, 137, 138, 1, 9, 141, 142, 143, + 144, 145, 146, 147, 99, 149, 150, 108, 109, 10, + 11, 12, 156, 157, 158, 32, 160, 118, 3, 4, + 5, 6, 7, 8, 168, 10, 11, 12, 13, 14, + 31, 76, 33, 34, 35, 72, 87, 82, 9, 142, + 54, 50, 51, 52, 89, 90, 91, 169, 93, 9, + 95, 118, 97, 38, 39, 100, 108, 15, 110, 165, + 105, 106, 107, 164, 167, 165, 111, 112, 82, 169, + 173, 85, 117, 118, 59, 118, 143, 53, 54, 55, + 56, 57, 99, 59, 129, 134, 135, 136, 73, 74, + 75, 76, 77, 78, 79, 71, 108, 82, 110, 142, + 167, 152, 139, 140, 89, 90, 91, 92, 93, 94, + 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, + 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, + 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, + 9, 118, 72, 128, 129, 130, 131, 1, 133, 134, + 135, 136, 137, 138, 9, 9, 141, 142, 143, 144, + 145, 146, 147, 169, 149, 150, 143, 173, 10, 11, + 12, 156, 157, 158, 9, 160, 72, 3, 4, 5, + 6, 7, 8, 168, 10, 11, 12, 13, 14, 31, + 167, 33, 34, 35, 36, 37, 38, 39, 40, 41, + 42, 43, 44, 10, 11, 12, 108, 165, 110, 139, + 140, 169, 38, 39, 118, 119, 120, 121, 122, 123, + 124, 125, 126, 127, 31, 155, 33, 34, 35, 36, + 37, 38, 39, 59, 10, 11, 12, 167, 17, 10, + 11, 12, 9, 139, 140, 10, 11, 73, 74, 75, + 76, 77, 78, 79, 9, 31, 82, 33, 34, 155, + 31, 38, 39, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, 119, 120, 121, 122, 123, 124, 166, + 118, 168, 128, 129, 130, 131, 9, 133, 134, 135, + 136, 137, 138, 82, 9, 141, 142, 143, 144, 145, + 146, 147, 72, 149, 150, 143, 10, 11, 12, 9, + 156, 157, 158, 9, 160, 3, 4, 5, 6, 7, + 8, 82, 10, 11, 12, 13, 14, 31, 9, 33, + 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, + 54, 55, 56, 57, 9, 59, 1, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 127, 71, 9, 139, + 140, 59, 161, 162, 163, 51, 52, 1, 15, 53, + 54, 170, 77, 78, 15, 73, 74, 75, 76, 77, + 78, 79, 77, 78, 82, 103, 104, 72, 108, 109, + 15, 89, 90, 91, 92, 93, 94, 95, 96, 97, + 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, + 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, + 118, 119, 120, 121, 122, 123, 124, 1, 72, 84, + 128, 129, 130, 131, 17, 133, 134, 135, 136, 137, + 138, 108, 109, 141, 142, 143, 144, 145, 146, 147, + 31, 149, 150, 15, 139, 140, 15, 31, 156, 157, + 158, 2, 3, 4, 5, 6, 7, 8, 15, 103, + 155, 17, 13, 14, 108, 16, 110, 113, 114, 17, + 17, 115, 167, 17, 118, 119, 120, 121, 122, 123, + 124, 125, 126, 127, 128, 139, 140, 17, 17, 1, + 17, 82, 32, 17, 17, 17, 32, 1, 32, 32, + 32, 155, 53, 54, 169, 36, 32, 58, 173, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 32, 72, 73, 74, 75, 76, 170, 118, 32, 80, + 81, 82, 32, 84, 118, 32, 32, 88, 89, 90, + 91, 1, 93, 32, 95, 32, 97, 72, 32, 100, + 101, 142, 143, 32, 105, 106, 107, 108, 109, 143, + 111, 112, 32, 32, 32, 82, 117, 118, 32, 32, + 161, 162, 163, 124, 86, 32, 167, 32, 129, 130, + 131, 32, 86, 167, 36, 38, 36, 36, 36, 36, + 141, 142, 36, 144, 145, 146, 147, 148, 149, 150, + 151, 118, 38, 38, 38, 59, 157, 158, 38, 39, + 161, 162, 163, 164, 139, 140, 167, 77, 78, 79, + 171, 172, 173, 39, 82, 142, 86, 72, 71, 85, + 155, 92, 92, 79, 94, 94, 96, 99, 98, 115, + 82, 116, 72, 73, 161, 162, 163, 84, 108, 87, + 91, 84, 133, 165, 84, 137, 96, 169, 88, 119, + 120, 165, 142, 102, 124, 169, 1, 98, 159, 152, + 99, 99, 132, 133, 134, 135, 136, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 102, 1, 159, 124, 38, 39, 32, 72, 164, + 167, 172, -1, -1, -1, 165, 138, 1, -1, 169, + 170, 141, 142, 137, 144, 145, 146, 147, 148, 149, + 150, 61, 62, 32, -1, 152, -1, 157, 158, 155, + 155, -1, 72, 76, 0, 1, 155, 167, 32, 82, + 155, 155, 172, 173, 161, 165, 89, 90, 91, 167, + 93, 86, 95, 160, 97, 165, 165, 100, 166, 38, + 39, 165, 105, 106, 107, 139, 140, 165, 111, 112, + 165, 165, 165, 165, 117, 118, 165, 86, 165, 165, + 165, 155, 165, 165, 165, 165, 129, 165, 165, 165, + 169, 166, 86, 167, 166, 166, 166, 76, 166, 139, + 140, 167, 167, 82, 167, 167, 167, 72, 73, 167, + 89, 90, 91, 167, 93, 155, 95, 160, 97, 84, + 86, 100, 167, 88, 168, 167, 105, 106, 107, 167, + 165, 167, 111, 112, 169, 167, 167, 167, 117, 118, + 167, 167, 108, 167, 110, 72, 73, 167, 167, 115, + 129, 167, 167, 119, 120, 167, 165, 84, 124, 124, + 169, 88, 167, 167, 167, 167, 132, 133, 134, 135, + 136, 165, 167, 169, 167, 169, 167, 142, 167, 144, + 145, 146, 147, 148, 149, 150, 167, 167, 170, 167, + 156, 32, 157, 158, 167, 167, 167, 124, 167, 165, + 167, 169, 167, 169, 170, 168, 168, 172, 173, 168, + 168, 168, 168, 168, 168, 142, 168, 144, 145, 146, + 147, 148, 149, 150, 32, 168, 168, 168, 168, 168, + 157, 158, 1, 168, 168, 76, 168, 168, 168, 168, + 167, 82, 168, 168, 168, 172, 173, 168, 89, 90, + 91, 168, 93, 168, 95, 1, 97, 168, 168, 100, + 168, 168, 1, 168, 105, 106, 107, 168, 76, 168, + 111, 112, 168, 168, 82, 168, 117, 118, 168, 168, + 168, 89, 90, 91, 168, 93, 168, 95, 129, 97, + 168, 168, 100, 32, 168, 168, 168, 105, 106, 107, + 169, 76, 169, 111, 112, 169, 169, 82, 169, 117, + 118, 169, 169, 169, 89, 90, 91, 86, 93, 31, + 95, 129, 97, 169, 1, 100, 169, 169, 173, 169, + 105, 106, 107, 102, 103, 104, 111, 112, 170, 108, + 86, 170, 117, 118, 170, 84, 170, 170, 170, 170, + 119, 120, 170, 170, 129, 124, 102, 103, 104, 170, + 170, 170, 108, 132, 133, 134, 135, 136, 170, 170, + 170, 170, 170, 119, 120, 170, 170, 170, 124, 170, + 119, 120, 170, 170, 170, 124, 132, 133, 134, 135, + 136, 170, 167, 170, 133, 171, 165, 170, -1, -1, + 169, 170, -1, 142, -1, -1, 118, 84, 120, 121, + 122, 123, 124, 125, 126, 127, -1, -1, -1, 165, + -1, -1, -1, 169, 170, 164, -1, -1, 167, -1, + -1, 143, -1, -1, 173, -1, -1, -1, -1, -1, + -1, -1, 119, 120, -1, -1, -1, 124, -1, -1, + -1, -1, -1, -1, -1, 167, 133, -1, -1, -1, + -1, -1, -1, -1, -1, 142, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 164, -1, -1, + 167, -1, -1, -1, -1, -1, 173 + ); + + protected array $actionBase = array( + 0, 156, -3, 315, 474, 474, 880, 1074, 1271, 1294, + 749, 675, 531, 559, 836, 1031, 1031, 1046, 1031, 828, + 1005, 42, 59, 59, 59, 963, 898, 632, 632, 898, + 632, 997, 997, 997, 997, 1061, 1061, -63, -63, 96, + 1232, 1199, 255, 255, 255, 255, 255, 1265, 255, 255, + 255, 255, 255, 1265, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 77, 194, 120, + 205, 1197, 783, 1150, 1163, 1152, 1166, 1145, 1144, 1151, + 1156, 1167, 1261, 1263, 889, 1254, 1267, 1158, 972, 1147, + 1162, 962, 616, 616, 616, 616, 616, 616, 616, 616, + 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, + 616, 616, 616, 616, 616, 616, 616, 616, 616, 19, + 35, 535, 41, 41, 41, 41, 41, 41, 41, 41, + 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, + 41, 41, 529, 529, 529, 910, 910, 524, 299, 1113, + 1075, 1113, 1113, 1113, 1113, 1113, 1113, 1113, 1113, 140, + 28, 1000, 493, 493, 458, 458, 458, 458, 458, 696, + 1328, 1301, 171, 171, 171, 171, 1363, 1363, -70, 523, + 248, 756, 291, 197, -87, 644, 38, 199, 323, 323, + 482, 482, 233, 233, 482, 482, 482, 324, 324, 94, + 94, 94, 94, 82, 249, 860, 67, 67, 67, 67, + 860, 860, 860, 860, 913, 869, 860, 1036, 1049, 860, + 860, 370, 645, 966, 646, 646, 398, -72, -72, 398, + 64, -72, 294, 286, 257, 859, 91, 433, 257, 1073, + 404, 686, 686, 815, 686, 686, 686, 923, 610, 923, + 1141, 902, 902, 861, 807, 964, 1198, 1168, 901, 1252, + 929, 1253, 1200, 342, 251, -56, 263, 550, 806, 1139, + 1139, 1139, 1139, 1139, 1139, 1139, 1139, 1139, 1139, 1139, + 1139, 1195, 523, 1141, -25, 1247, 1249, 1195, 1195, 1195, + 523, 523, 523, 523, 523, 523, 523, 523, 870, 523, + 523, 694, -25, 625, 635, -25, 896, 523, 915, 77, + 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, + 178, 77, 77, 194, 13, 13, 77, 200, 121, 13, + 13, 13, -11, 13, 77, 77, 77, 610, 886, 849, + 663, 283, 874, 114, 886, 886, 886, 71, 9, 76, + 809, 888, 288, 882, 882, 882, 907, 986, 986, 882, + 903, 882, 907, 882, 882, 986, 986, 875, 986, 274, + 620, 465, 597, 624, 986, 340, 882, 882, 882, 882, + 916, 986, 127, 139, 639, 882, 329, 287, 882, 882, + 916, 858, 876, 908, 986, 986, 986, 916, 545, 908, + 908, 908, 931, 936, 864, 872, 445, 431, 679, 232, + 924, 872, 872, 882, 605, 864, 872, 864, 872, 933, + 872, 872, 872, 864, 872, 903, 533, 872, 813, 665, + 218, 872, 882, 20, 1008, 1009, 800, 1010, 1002, 1013, + 1069, 1014, 1016, 1171, 982, 1028, 1004, 1020, 1071, 998, + 995, 885, 792, 793, 921, 914, 979, 897, 897, 897, + 975, 977, 897, 897, 897, 897, 897, 897, 897, 897, + 792, 932, 926, 899, 1037, 796, 810, 1114, 857, 1214, + 1264, 1036, 1008, 1016, 804, 1004, 1020, 998, 995, 856, + 853, 844, 851, 843, 840, 808, 814, 871, 1116, 1119, + 1021, 920, 811, 1085, 1038, 1211, 1044, 1045, 1047, 1088, + 1123, 942, 1125, 1216, 895, 1217, 1218, 965, 1051, 1173, + 897, 974, 873, 968, 1049, 978, 792, 969, 1129, 1130, + 1081, 961, 1097, 1098, 1072, 911, 884, 970, 1219, 1059, + 1060, 1062, 1176, 1177, 930, 1082, 996, 1099, 912, 1058, + 1100, 1101, 1105, 1106, 1179, 1222, 1182, 922, 1183, 945, + 879, 1077, 909, 1223, 165, 892, 893, 906, 1068, 683, + 1035, 1184, 1208, 1229, 1108, 1109, 1110, 1230, 1231, 1024, + 946, 1083, 900, 1084, 1078, 947, 948, 689, 905, 1132, + 890, 891, 904, 705, 768, 1238, 1239, 1240, 1025, 877, + 894, 951, 953, 1133, 887, 1135, 1241, 771, 954, 1242, + 1115, 816, 817, 521, 784, 747, 818, 881, 1194, 925, + 865, 878, 1067, 817, 883, 955, 1245, 957, 958, 959, + 1111, 960, 1086, 1246, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 789, 789, + 789, 789, 789, 789, 789, 789, 789, 632, 632, 632, + 632, 789, 789, 789, 789, 789, 789, 789, 632, 789, + 789, 789, 632, 632, 0, 0, 632, 0, 789, 789, + 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, + 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, + 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, + 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, + 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, + 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, + 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, + 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, + 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, + 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, + 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, + 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, + 789, 789, 789, 789, 789, 789, 789, 789, 789, 789, + 789, 789, 789, 789, 616, 616, 616, 616, 616, 616, + 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, + 616, 616, 616, 616, 616, 616, 616, 616, 616, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 616, 616, 616, 616, + 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, + 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, + 616, 616, 823, 823, 616, 616, 823, 823, 823, 823, + 823, 823, 823, 823, 823, 823, 616, 616, 0, 616, + 616, 616, 616, 616, 616, 616, 875, 823, 823, 324, + 324, 324, 324, 823, 823, 396, 396, 396, 823, 324, + 823, 64, 324, 823, 64, 823, 823, 823, 823, 823, + 823, 823, 823, 823, 0, 0, 823, 823, 823, 823, + -25, -72, 823, 903, 903, 903, 903, 823, 823, 823, + 823, -72, -72, 823, -57, -57, 823, 823, 0, 0, + 0, 324, 324, -25, 0, 0, -25, 0, 0, 903, + 903, 823, 64, 875, 446, 823, 342, 0, 0, 0, + 0, 0, 0, 0, -25, 903, -25, 523, -72, -72, + 523, 523, 13, 77, 446, 612, 612, 612, 612, 77, + 0, 0, 0, 0, 0, 610, 875, 875, 875, 875, + 875, 875, 875, 875, 875, 875, 875, 875, 903, 0, + 875, 0, 875, 875, 903, 903, 903, 0, 0, 0, + 0, 0, 0, 0, 0, 986, 0, 0, 0, 0, + 0, 0, 0, 903, 0, 986, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 903, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 897, 911, 0, 0, 911, + 0, 897, 897, 897, 0, 0, 0, 905, 887 + ); + + protected array $actionDefault = array( + 3,32767,32767,32767, 102, 102,32767,32767,32767,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767, 100, + 32767, 632, 632, 632, 632,32767,32767, 257, 102,32767, + 32767, 503, 417, 417, 417,32767,32767,32767, 576, 576, + 576, 576, 576, 17,32767,32767,32767,32767,32767,32767, + 32767, 503,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767, 36, 7, 8, 10, 11, 49, 338, 100, + 32767,32767,32767,32767,32767,32767,32767,32767, 102,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767, 404, 625,32767,32767,32767,32767,32767,32767,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767, 497, 507, 485, 486, 488, 489, 416, 577, + 631, 344, 628, 342, 415, 146, 354, 343, 245, 261, + 508, 262, 509, 512, 513, 218, 401, 150, 151, 448, + 504, 450, 502, 506, 449, 422, 429, 430, 431, 432, + 433, 434, 435, 436, 437, 438, 439, 440, 441, 420, + 421, 505, 482, 481, 480,32767,32767, 446, 447,32767, + 32767,32767,32767,32767,32767,32767,32767, 102,32767, 451, + 454, 419, 452, 453, 470, 471, 468, 469, 472,32767, + 323,32767, 473, 474, 475, 476,32767,32767, 382, 196, + 380,32767, 477,32767, 111, 455, 323, 111,32767,32767, + 32767,32767,32767,32767,32767,32767,32767, 461, 462,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767,32767,32767,32767,32767, 102,32767,32767,32767, + 100, 520, 570, 479, 456, 457,32767, 545,32767, 102, + 32767, 547,32767,32767,32767,32767,32767,32767,32767,32767, + 572, 443, 445, 540, 626, 423, 629,32767, 533, 100, + 196,32767, 546, 196, 196,32767,32767,32767,32767,32767, + 32767,32767,32767,32767,32767, 571,32767, 639, 533, 110, + 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, + 110,32767, 196, 110,32767, 110, 110,32767,32767, 100, + 196, 196, 196, 196, 196, 196, 196, 196, 548, 196, + 196, 191,32767, 271, 273, 102, 594, 196, 550,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767, 404,32767,32767,32767,32767, 533, 466, 139, + 32767, 535, 139, 578, 458, 459, 460, 578, 578, 578, + 319, 296,32767,32767,32767,32767,32767, 548, 548, 100, + 100, 100, 100,32767,32767,32767,32767, 111, 519, 99, + 99, 99, 99, 99, 103, 101,32767,32767,32767,32767, + 226,32767, 101, 101, 99,32767, 101, 101,32767,32767, + 226, 228, 215, 230,32767, 598, 599, 226, 101, 230, + 230, 230, 250, 250, 522, 325, 101, 99, 101, 101, + 198, 325, 325,32767, 101, 522, 325, 522, 325, 200, + 325, 325, 325, 522, 325,32767, 101, 325, 217, 99, + 99, 325,32767,32767,32767,32767, 535,32767,32767,32767, + 32767,32767,32767,32767, 225,32767,32767,32767,32767,32767, + 32767,32767,32767, 565,32767, 583, 596, 464, 465, 467, + 582, 580, 490, 491, 492, 493, 494, 495, 496, 499, + 627,32767, 539,32767,32767,32767, 353,32767, 637,32767, + 32767,32767, 9, 74, 528, 42, 43, 51, 57, 554, + 555, 556, 557, 551, 552, 558, 553,32767,32767,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767,32767, 638,32767, 578,32767,32767,32767,32767, + 463, 560, 604,32767,32767, 579, 630,32767,32767,32767, + 32767,32767,32767,32767,32767, 139,32767,32767,32767,32767, + 32767,32767,32767,32767,32767,32767, 565,32767, 137,32767, + 32767,32767,32767,32767,32767,32767,32767, 561,32767,32767, + 32767, 578,32767,32767,32767,32767, 321, 318,32767,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767,32767,32767, 578,32767,32767,32767,32767,32767, + 298,32767, 315,32767,32767,32767,32767,32767,32767,32767, + 32767,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767, 400, 535, 301, 303, 304,32767,32767,32767,32767, + 376,32767,32767,32767,32767,32767,32767,32767,32767,32767, + 32767,32767,32767,32767, 153, 153, 3, 3, 356, 153, + 153, 153, 356, 356, 153, 356, 356, 356, 153, 153, + 153, 153, 153, 153, 153, 283, 186, 265, 268, 250, + 250, 153, 368, 153, 402, 402, 411 + ); + + protected array $goto = array( + 201, 169, 201, 201, 201, 1069, 598, 719, 448, 684, + 644, 681, 443, 345, 341, 342, 344, 615, 447, 346, + 449, 661, 481, 728, 570, 570, 570, 570, 1245, 626, + 172, 172, 172, 172, 225, 202, 198, 198, 182, 184, + 220, 198, 198, 198, 198, 198, 1195, 199, 199, 199, + 199, 199, 1195, 192, 193, 194, 195, 196, 197, 222, + 220, 223, 557, 558, 438, 559, 562, 563, 564, 565, + 566, 567, 568, 569, 173, 174, 175, 200, 176, 177, + 178, 170, 179, 180, 181, 183, 219, 221, 224, 242, + 247, 248, 259, 260, 262, 263, 264, 265, 266, 267, + 268, 272, 273, 274, 275, 282, 285, 297, 298, 324, + 325, 444, 445, 446, 620, 226, 227, 228, 229, 230, + 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, + 241, 193, 194, 195, 196, 197, 222, 203, 204, 205, + 206, 243, 185, 186, 207, 187, 208, 204, 188, 244, + 203, 168, 209, 210, 189, 211, 212, 213, 190, 214, + 215, 171, 216, 217, 218, 191, 287, 284, 287, 287, + 883, 255, 255, 255, 255, 255, 1125, 605, 487, 487, + 622, 758, 660, 662, 1103, 359, 682, 487, 1075, 1074, + 706, 709, 1041, 717, 726, 1037, 733, 922, 879, 922, + 922, 253, 253, 253, 253, 250, 256, 646, 646, 1078, + 1079, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, 1332, + 1332, 880, 351, 938, 933, 934, 947, 889, 935, 886, + 936, 937, 887, 890, 476, 941, 894, 476, 1044, 1044, + 893, 364, 364, 364, 364, 352, 351, 532, 1131, 1127, + 1128, 1351, 1351, 331, 315, 1351, 1351, 1351, 1351, 1351, + 1351, 1351, 1351, 1351, 1351, 1069, 1301, 1072, 1072, 704, + 983, 1301, 1301, 1064, 1080, 1081, 1069, 942, 1301, 943, + 458, 1069, 881, 1069, 1069, 1069, 1069, 1069, 1069, 1069, + 1069, 1069, 897, 855, 1069, 1069, 1069, 1069, 677, 678, + 1301, 695, 696, 697, 1006, 1301, 1301, 1301, 1301, 450, + 909, 1301, 436, 896, 1301, 1301, 1382, 1382, 1382, 1382, + 915, 581, 574, 499, 612, 450, 367, 971, 971, 955, + 501, 1076, 1076, 956, 1400, 1400, 367, 367, 688, 1087, + 1083, 1084, 572, 411, 414, 623, 627, 572, 572, 367, + 367, 1400, 357, 367, 572, 1417, 1377, 1378, 317, 574, + 581, 607, 608, 318, 618, 624, 1390, 640, 641, 1027, + 576, 1403, 1403, 367, 367, 28, 474, 520, 442, 521, + 635, 1000, 1000, 1000, 1000, 527, 409, 474, 1348, 1348, + 994, 1001, 1348, 1348, 1348, 1348, 1348, 1348, 1348, 1348, + 1348, 1348, 633, 647, 650, 651, 652, 653, 674, 675, + 676, 730, 732, 561, 561, 258, 258, 561, 561, 561, + 561, 561, 561, 561, 561, 561, 561, 610, 1362, 467, + 683, 467, 876, 616, 638, 876, 467, 467, 1191, 861, + 1373, 360, 361, 1093, 456, 1373, 1373, 560, 560, 705, + 432, 560, 1373, 560, 560, 560, 560, 560, 560, 560, + 560, 1277, 975, 575, 602, 575, 1278, 1281, 976, 575, + 1282, 602, 689, 412, 480, 1384, 1384, 1384, 1384, 347, + 873, 716, 576, 861, 876, 861, 490, 619, 491, 492, + 639, 8, 857, 9, 902, 907, 989, 716, 1408, 1409, + 716, 1369, 418, 1296, 278, 899, 330, 1174, 424, 425, + 1292, 330, 330, 693, 1049, 694, 1114, 429, 430, 431, + 761, 707, 1060, 905, 433, 1102, 1104, 1107, 355, 467, + 467, 467, 467, 467, 467, 467, 467, 467, 467, 467, + 467, 419, 339, 467, 911, 467, 467, 1294, 628, 629, + 1116, 497, 960, 1181, 621, 1144, 1371, 1371, 1116, 1118, + 1297, 1298, 1011, 1284, 1046, 1151, 1179, 1152, 731, 871, + 528, 722, 901, 1142, 687, 1025, 1284, 496, 1375, 1376, + 895, 910, 898, 1113, 1117, 998, 427, 727, 1165, 1299, + 1359, 1360, 1291, 1030, 386, 1009, 1002, 0, 757, 0, + 0, 573, 1039, 1034, 654, 656, 658, 0, 0, 0, + 0, 0, 0, 0, 0, 876, 0, 0, 999, 0, + 766, 766, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1163, 914 + ); + + protected array $gotoCheck = array( + 42, 42, 42, 42, 42, 73, 127, 73, 66, 66, + 56, 56, 66, 66, 66, 66, 66, 66, 66, 66, + 66, 66, 159, 9, 107, 107, 107, 107, 159, 107, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 23, 23, 23, 23, + 15, 5, 5, 5, 5, 5, 15, 48, 157, 157, + 134, 48, 48, 48, 131, 97, 48, 157, 119, 119, + 48, 48, 48, 48, 48, 48, 48, 25, 25, 25, + 25, 5, 5, 5, 5, 5, 5, 108, 108, 120, + 120, 108, 108, 108, 108, 108, 108, 108, 108, 108, + 108, 26, 177, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 83, 15, 15, 83, 107, 107, + 15, 24, 24, 24, 24, 177, 177, 76, 15, 15, + 15, 179, 179, 178, 178, 179, 179, 179, 179, 179, + 179, 179, 179, 179, 179, 73, 73, 89, 89, 89, + 89, 73, 73, 89, 89, 89, 73, 65, 73, 65, + 83, 73, 27, 73, 73, 73, 73, 73, 73, 73, + 73, 73, 35, 6, 73, 73, 73, 73, 86, 86, + 73, 86, 86, 86, 49, 73, 73, 73, 73, 118, + 35, 73, 43, 35, 73, 73, 9, 9, 9, 9, + 45, 76, 76, 84, 181, 118, 14, 9, 9, 73, + 84, 118, 118, 73, 191, 191, 14, 14, 118, 118, + 118, 118, 19, 59, 59, 59, 59, 19, 19, 14, + 14, 191, 188, 14, 19, 14, 187, 187, 76, 76, + 76, 76, 76, 76, 76, 76, 190, 76, 76, 103, + 14, 191, 191, 14, 14, 76, 19, 163, 13, 163, + 13, 19, 19, 19, 19, 163, 62, 19, 180, 180, + 19, 19, 180, 180, 180, 180, 180, 180, 180, 180, + 180, 180, 81, 81, 81, 81, 81, 81, 81, 81, + 81, 81, 81, 182, 182, 5, 5, 182, 182, 182, + 182, 182, 182, 182, 182, 182, 182, 104, 14, 23, + 64, 23, 22, 2, 2, 22, 23, 23, 158, 12, + 134, 97, 97, 115, 113, 134, 134, 165, 165, 117, + 14, 165, 134, 165, 165, 165, 165, 165, 165, 165, + 165, 79, 79, 9, 9, 9, 79, 79, 79, 9, + 79, 9, 121, 9, 9, 134, 134, 134, 134, 29, + 18, 7, 14, 12, 22, 12, 9, 9, 9, 9, + 80, 46, 7, 46, 39, 9, 92, 7, 9, 9, + 7, 134, 28, 20, 24, 37, 24, 156, 82, 82, + 169, 24, 24, 82, 110, 82, 133, 82, 82, 82, + 99, 82, 114, 9, 82, 130, 130, 130, 82, 23, + 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, + 23, 31, 9, 23, 41, 23, 23, 14, 17, 17, + 134, 160, 17, 17, 8, 8, 134, 134, 134, 136, + 20, 20, 96, 20, 17, 149, 149, 149, 8, 20, + 8, 8, 17, 8, 17, 17, 20, 185, 185, 185, + 17, 16, 16, 16, 16, 93, 93, 93, 152, 20, + 20, 20, 17, 50, 141, 16, 50, -1, 50, -1, + -1, 50, 50, 50, 85, 85, 85, -1, -1, -1, + -1, -1, -1, -1, -1, 22, -1, -1, 16, -1, + 24, 24, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 16, 16 + ); + + protected array $gotoBase = array( + 0, 0, -303, 0, 0, 170, 280, 471, 543, 10, + 0, 0, 136, 31, 22, -186, 111, 66, 164, 71, + 95, 0, 148, 160, 235, 191, 214, 275, 155, 176, + 0, 86, 0, 0, 0, -92, 0, 156, 0, 165, + 0, 85, -1, 286, 0, 291, -270, 0, -558, 284, + 579, 0, 0, 0, 0, 0, -33, 0, 0, 294, + 0, 0, 341, 0, 184, 261, -237, 0, 0, 0, + 0, 0, 0, -5, 0, 0, -32, 0, 0, 37, + 172, 32, -3, -50, -167, 105, -444, 0, 0, -21, + 0, 0, 161, 274, 0, 0, 101, -318, 0, 97, + 0, 0, 0, 331, 381, 0, 0, -7, -38, 0, + 131, 0, 0, 158, 90, 162, 0, 159, 39, -100, + -83, 173, 0, 0, 0, 0, 0, 4, 0, 0, + 522, 182, 0, 127, 169, 0, 99, 0, 0, 0, + 0, -171, 0, 0, 0, 0, 0, 0, 0, 287, + 0, 0, 126, 0, 0, 0, 144, 141, 188, -255, + 93, 0, 0, -138, 0, 202, 0, 0, 0, 128, + 0, 0, 0, 0, 0, 0, 0, -82, -74, 6, + 143, 292, 168, 0, 0, 270, 0, -31, 319, 0, + 332, 20, 0, 0 + ); + + protected array $gotoDefault = array( + -32768, 533, 768, 7, 769, 964, 844, 853, 597, 551, + 729, 356, 648, 439, 1367, 940, 1180, 617, 872, 1310, + 1316, 475, 875, 336, 755, 952, 923, 924, 415, 402, + 888, 413, 672, 649, 514, 908, 471, 900, 506, 903, + 470, 912, 167, 435, 530, 916, 6, 919, 579, 950, + 1004, 403, 927, 404, 700, 929, 601, 931, 932, 410, + 416, 417, 1185, 609, 645, 944, 261, 603, 945, 401, + 946, 954, 406, 408, 710, 486, 525, 519, 428, 1146, + 604, 632, 669, 464, 493, 643, 655, 642, 500, 451, + 434, 335, 988, 996, 507, 484, 1010, 358, 1018, 763, + 1193, 663, 509, 1026, 664, 1033, 1036, 552, 553, 498, + 1048, 270, 1051, 510, 1061, 26, 690, 1066, 1067, 691, + 665, 1089, 666, 692, 667, 1091, 483, 599, 1194, 482, + 1106, 1112, 472, 1115, 1356, 473, 1119, 269, 1122, 286, + 362, 385, 452, 1129, 1130, 12, 1136, 720, 721, 25, + 280, 529, 1164, 711, 1170, 279, 1173, 469, 1192, 468, + 1265, 1267, 580, 511, 1285, 321, 1288, 703, 526, 1293, + 465, 1358, 466, 554, 494, 343, 555, 1401, 314, 365, + 340, 571, 322, 366, 556, 495, 1364, 1372, 337, 34, + 1391, 1402, 614, 637 + ); + + protected array $ruleToNonTerminal = array( + 0, 1, 3, 3, 2, 5, 5, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, + 7, 7, 7, 7, 7, 8, 8, 9, 10, 11, + 11, 11, 12, 12, 13, 13, 14, 15, 15, 16, + 16, 17, 17, 18, 18, 21, 21, 22, 23, 23, + 24, 24, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 29, 29, 30, 30, 32, 34, + 34, 28, 36, 36, 33, 38, 38, 35, 35, 37, + 37, 39, 39, 31, 40, 40, 41, 43, 44, 44, + 45, 45, 46, 46, 48, 47, 47, 47, 47, 49, + 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, + 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, + 49, 49, 49, 25, 25, 50, 69, 69, 72, 72, + 71, 70, 70, 63, 75, 75, 76, 76, 77, 77, + 78, 78, 79, 79, 80, 80, 80, 80, 26, 26, + 27, 27, 27, 27, 27, 88, 88, 90, 90, 83, + 83, 91, 91, 92, 92, 92, 84, 84, 87, 87, + 85, 85, 93, 94, 94, 57, 57, 65, 65, 68, + 68, 68, 67, 95, 95, 96, 58, 58, 58, 58, + 97, 97, 98, 98, 99, 99, 100, 101, 101, 102, + 102, 103, 103, 55, 55, 51, 51, 105, 53, 53, + 106, 52, 52, 54, 54, 64, 64, 64, 64, 81, + 81, 109, 109, 111, 111, 112, 112, 112, 112, 112, + 112, 112, 112, 110, 110, 110, 115, 115, 115, 115, + 89, 89, 118, 118, 118, 119, 119, 116, 116, 120, + 120, 122, 122, 123, 123, 117, 124, 124, 121, 125, + 125, 125, 125, 113, 113, 82, 82, 82, 20, 20, + 20, 128, 128, 128, 128, 129, 129, 129, 127, 126, + 126, 131, 131, 131, 130, 130, 60, 132, 132, 133, + 61, 135, 135, 136, 136, 137, 137, 86, 138, 138, + 138, 138, 138, 138, 138, 138, 144, 144, 145, 145, + 146, 146, 146, 146, 146, 147, 148, 148, 143, 143, + 139, 139, 142, 142, 150, 150, 149, 149, 149, 149, + 149, 149, 149, 149, 149, 149, 140, 151, 151, 153, + 152, 152, 141, 141, 114, 114, 154, 154, 156, 156, + 156, 155, 155, 62, 104, 157, 157, 56, 56, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, + 42, 42, 42, 42, 42, 42, 164, 165, 165, 166, + 158, 158, 163, 163, 167, 168, 168, 169, 170, 171, + 171, 171, 171, 19, 19, 73, 73, 73, 73, 159, + 159, 159, 159, 173, 173, 162, 162, 162, 160, 160, + 179, 179, 179, 179, 179, 179, 179, 179, 179, 179, + 180, 180, 180, 108, 182, 182, 182, 182, 161, 161, + 161, 161, 161, 161, 161, 161, 59, 59, 176, 176, + 176, 176, 176, 183, 183, 172, 172, 172, 172, 184, + 184, 184, 184, 184, 74, 74, 66, 66, 66, 66, + 134, 134, 134, 134, 187, 186, 175, 175, 175, 175, + 175, 175, 174, 174, 174, 185, 185, 185, 185, 107, + 181, 189, 189, 188, 188, 190, 190, 190, 190, 190, + 190, 190, 190, 178, 178, 178, 178, 177, 192, 191, + 191, 191, 191, 191, 191, 191, 191, 193, 193, 193, + 193 + ); + + protected array $ruleToLength = array( + 1, 1, 2, 0, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, + 1, 0, 1, 1, 2, 1, 3, 4, 1, 2, + 0, 1, 1, 1, 1, 4, 3, 5, 4, 3, + 4, 1, 3, 4, 1, 1, 8, 7, 2, 3, + 1, 2, 3, 1, 2, 3, 1, 1, 3, 1, + 3, 1, 2, 2, 3, 1, 3, 2, 3, 1, + 3, 3, 2, 0, 1, 1, 1, 1, 1, 3, + 7, 10, 5, 7, 9, 5, 3, 3, 3, 3, + 3, 3, 1, 2, 5, 7, 9, 6, 5, 6, + 3, 2, 1, 1, 1, 1, 0, 2, 1, 3, + 8, 0, 4, 2, 1, 3, 0, 1, 0, 1, + 0, 1, 3, 1, 1, 1, 1, 1, 8, 9, + 7, 8, 7, 6, 8, 0, 2, 0, 2, 1, + 2, 1, 2, 1, 1, 1, 0, 2, 0, 2, + 0, 2, 2, 1, 3, 1, 4, 1, 4, 1, + 1, 4, 2, 1, 3, 3, 3, 4, 4, 5, + 0, 2, 4, 3, 1, 1, 7, 0, 2, 1, + 3, 3, 4, 1, 4, 0, 2, 5, 0, 2, + 6, 0, 2, 0, 3, 1, 2, 1, 1, 2, + 0, 1, 3, 0, 2, 1, 1, 1, 1, 1, + 1, 1, 1, 7, 9, 6, 1, 2, 1, 1, + 1, 1, 1, 1, 1, 1, 3, 3, 3, 1, + 3, 3, 3, 3, 3, 1, 3, 3, 1, 1, + 2, 1, 1, 0, 1, 0, 2, 2, 2, 4, + 3, 2, 4, 4, 3, 3, 1, 3, 1, 1, + 3, 2, 2, 3, 1, 1, 2, 3, 1, 1, + 2, 3, 1, 1, 3, 2, 0, 1, 5, 7, + 5, 6, 10, 3, 5, 1, 1, 3, 0, 2, + 4, 5, 4, 4, 4, 3, 1, 1, 1, 1, + 1, 1, 0, 1, 1, 2, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 2, 1, 3, 1, + 1, 3, 0, 2, 0, 3, 5, 8, 1, 3, + 3, 0, 2, 2, 2, 3, 1, 0, 1, 1, + 3, 3, 3, 4, 4, 1, 1, 2, 2, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 2, 2, 2, 2, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 5, 4, 3, 4, 4, 2, 2, 4, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 1, 3, 2, 1, 2, 4, 2, 2, 8, 9, + 8, 9, 9, 10, 9, 10, 8, 3, 2, 2, + 1, 1, 0, 4, 2, 1, 3, 2, 1, 2, + 2, 2, 4, 1, 1, 1, 1, 1, 1, 1, + 1, 3, 1, 1, 1, 0, 1, 1, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 3, 5, 3, 3, 4, 1, 1, 3, 1, 1, + 1, 1, 1, 3, 2, 3, 0, 1, 1, 3, + 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, + 4, 1, 4, 4, 0, 1, 1, 1, 3, 3, + 1, 4, 2, 2, 1, 3, 1, 4, 3, 3, + 3, 3, 1, 3, 1, 1, 3, 1, 1, 4, + 1, 1, 1, 3, 1, 1, 2, 1, 3, 4, + 3, 2, 0, 2, 2, 1, 2, 1, 1, 1, + 4, 3, 3, 3, 3, 6, 3, 1, 1, 2, + 1 + ); + + protected function initReduceCallbacks(): void { + $this->reduceCallbacks = [ + 0 => null, + 1 => static function ($self, $stackPos) { + $self->semValue = $self->handleNamespaces($self->semStack[$stackPos-(1-1)]); + }, + 2 => static function ($self, $stackPos) { + if ($self->semStack[$stackPos-(2-2)] !== null) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; } $self->semValue = $self->semStack[$stackPos-(2-1)];; + }, + 3 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 4 => static function ($self, $stackPos) { + $nop = $self->maybeCreateZeroLengthNop($self->tokenPos);; + if ($nop !== null) { $self->semStack[$stackPos-(1-1)][] = $nop; } $self->semValue = $self->semStack[$stackPos-(1-1)]; + }, + 5 => null, + 6 => null, + 7 => null, + 8 => null, + 9 => null, + 10 => null, + 11 => null, + 12 => null, + 13 => null, + 14 => null, + 15 => null, + 16 => null, + 17 => null, + 18 => null, + 19 => null, + 20 => null, + 21 => null, + 22 => null, + 23 => null, + 24 => null, + 25 => null, + 26 => null, + 27 => null, + 28 => null, + 29 => null, + 30 => null, + 31 => null, + 32 => null, + 33 => null, + 34 => null, + 35 => null, + 36 => null, + 37 => null, + 38 => null, + 39 => null, + 40 => null, + 41 => null, + 42 => null, + 43 => null, + 44 => null, + 45 => null, + 46 => null, + 47 => null, + 48 => null, + 49 => null, + 50 => null, + 51 => null, + 52 => null, + 53 => null, + 54 => null, + 55 => null, + 56 => null, + 57 => null, + 58 => null, + 59 => null, + 60 => null, + 61 => null, + 62 => null, + 63 => null, + 64 => null, + 65 => null, + 66 => null, + 67 => null, + 68 => null, + 69 => null, + 70 => null, + 71 => null, + 72 => null, + 73 => null, + 74 => null, + 75 => null, + 76 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(1-1)]; if ($self->semValue === "emitError(new Error('Cannot use "getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]))); + }, + 77 => null, + 78 => null, + 79 => null, + 80 => null, + 81 => null, + 82 => null, + 83 => null, + 84 => null, + 85 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 86 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 87 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 88 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 89 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 90 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 91 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 92 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 93 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 94 => null, + 95 => static function ($self, $stackPos) { + $self->semValue = new Name(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 96 => static function ($self, $stackPos) { + $self->semValue = new Expr\Variable(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 97 => static function ($self, $stackPos) { + /* nothing */ + }, + 98 => static function ($self, $stackPos) { + /* nothing */ + }, + 99 => static function ($self, $stackPos) { + /* nothing */ + }, + 100 => static function ($self, $stackPos) { + $self->emitError(new Error('A trailing comma is not allowed here', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]))); + }, + 101 => null, + 102 => null, + 103 => static function ($self, $stackPos) { + $self->semValue = new Node\Attribute($self->semStack[$stackPos-(1-1)], [], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 104 => static function ($self, $stackPos) { + $self->semValue = new Node\Attribute($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 105 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 106 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 107 => static function ($self, $stackPos) { + $self->semValue = new Node\AttributeGroup($self->semStack[$stackPos-(4-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 108 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 109 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; + }, + 110 => static function ($self, $stackPos) { + $self->semValue = []; + }, + 111 => null, + 112 => null, + 113 => null, + 114 => null, + 115 => static function ($self, $stackPos) { + $self->semValue = new Stmt\HaltCompiler($self->handleHaltCompiler(), $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 116 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Namespace_($self->semStack[$stackPos-(3-2)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + $self->semValue->setAttribute('kind', Stmt\Namespace_::KIND_SEMICOLON); + $self->checkNamespace($self->semValue); + }, + 117 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Namespace_($self->semStack[$stackPos-(5-2)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); + $self->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); + $self->checkNamespace($self->semValue); + }, + 118 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Namespace_(null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + $self->semValue->setAttribute('kind', Stmt\Namespace_::KIND_BRACED); + $self->checkNamespace($self->semValue); + }, + 119 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Use_($self->semStack[$stackPos-(3-2)], Stmt\Use_::TYPE_NORMAL, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 120 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Use_($self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 121 => null, + 122 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Const_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), []); + }, + 123 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Const_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(4-1)]); + $self->checkConstantAttributes($self->semValue); + }, + 124 => static function ($self, $stackPos) { + $self->semValue = Stmt\Use_::TYPE_FUNCTION; + }, + 125 => static function ($self, $stackPos) { + $self->semValue = Stmt\Use_::TYPE_CONSTANT; + }, + 126 => static function ($self, $stackPos) { + $self->semValue = new Stmt\GroupUse($self->semStack[$stackPos-(8-3)], $self->semStack[$stackPos-(8-6)], $self->semStack[$stackPos-(8-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); + }, + 127 => static function ($self, $stackPos) { + $self->semValue = new Stmt\GroupUse($self->semStack[$stackPos-(7-2)], $self->semStack[$stackPos-(7-5)], Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); + }, + 128 => null, + 129 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 130 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 131 => null, + 132 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 133 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 134 => null, + 135 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 136 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 137 => static function ($self, $stackPos) { + $self->semValue = new Node\UseItem($self->semStack[$stackPos-(1-1)], null, Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(1-1)); + }, + 138 => static function ($self, $stackPos) { + $self->semValue = new Node\UseItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(3-3)); + }, + 139 => static function ($self, $stackPos) { + $self->semValue = new Node\UseItem($self->semStack[$stackPos-(1-1)], null, Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(1-1)); + }, + 140 => static function ($self, $stackPos) { + $self->semValue = new Node\UseItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], Stmt\Use_::TYPE_UNKNOWN, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->checkUseUse($self->semValue, $stackPos-(3-3)); + }, + 141 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(1-1)]; $self->semValue->type = Stmt\Use_::TYPE_NORMAL; + }, + 142 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(2-2)]; $self->semValue->type = $self->semStack[$stackPos-(2-1)]; + }, + 143 => null, + 144 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 145 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 146 => static function ($self, $stackPos) { + $self->semValue = new Node\Const_($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 147 => null, + 148 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 149 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 150 => static function ($self, $stackPos) { + $self->semValue = new Node\Const_(new Node\Identifier($self->semStack[$stackPos-(3-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos-(3-1)])), $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 151 => static function ($self, $stackPos) { + $self->semValue = new Node\Const_(new Node\Identifier($self->semStack[$stackPos-(3-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos-(3-1)])), $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 152 => static function ($self, $stackPos) { + if ($self->semStack[$stackPos-(2-2)] !== null) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; } $self->semValue = $self->semStack[$stackPos-(2-1)];; + }, + 153 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 154 => static function ($self, $stackPos) { + $nop = $self->maybeCreateZeroLengthNop($self->tokenPos);; + if ($nop !== null) { $self->semStack[$stackPos-(1-1)][] = $nop; } $self->semValue = $self->semStack[$stackPos-(1-1)]; + }, + 155 => null, + 156 => null, + 157 => null, + 158 => static function ($self, $stackPos) { + throw new Error('__HALT_COMPILER() can only be used from the outermost scope', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 159 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Block($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 160 => static function ($self, $stackPos) { + $self->semValue = new Stmt\If_($self->semStack[$stackPos-(7-3)], ['stmts' => $self->semStack[$stackPos-(7-5)], 'elseifs' => $self->semStack[$stackPos-(7-6)], 'else' => $self->semStack[$stackPos-(7-7)]], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); + }, + 161 => static function ($self, $stackPos) { + $self->semValue = new Stmt\If_($self->semStack[$stackPos-(10-3)], ['stmts' => $self->semStack[$stackPos-(10-6)], 'elseifs' => $self->semStack[$stackPos-(10-7)], 'else' => $self->semStack[$stackPos-(10-8)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); + }, + 162 => static function ($self, $stackPos) { + $self->semValue = new Stmt\While_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); + }, + 163 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Do_($self->semStack[$stackPos-(7-5)], $self->semStack[$stackPos-(7-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); + }, + 164 => static function ($self, $stackPos) { + $self->semValue = new Stmt\For_(['init' => $self->semStack[$stackPos-(9-3)], 'cond' => $self->semStack[$stackPos-(9-5)], 'loop' => $self->semStack[$stackPos-(9-7)], 'stmts' => $self->semStack[$stackPos-(9-9)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); + }, + 165 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Switch_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); + }, + 166 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Break_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 167 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Continue_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 168 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Return_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 169 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Global_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 170 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Static_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 171 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Echo_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 172 => static function ($self, $stackPos) { + + $self->semValue = new Stmt\InlineHTML($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + $self->semValue->setAttribute('hasLeadingNewline', $self->inlineHtmlHasLeadingNewline($stackPos-(1-1))); + + }, + 173 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Expression($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 174 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Unset_($self->semStack[$stackPos-(5-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); + }, + 175 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Foreach_($self->semStack[$stackPos-(7-3)], $self->semStack[$stackPos-(7-5)][0], ['keyVar' => null, 'byRef' => $self->semStack[$stackPos-(7-5)][1], 'stmts' => $self->semStack[$stackPos-(7-7)]], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); + }, + 176 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Foreach_($self->semStack[$stackPos-(9-3)], $self->semStack[$stackPos-(9-7)][0], ['keyVar' => $self->semStack[$stackPos-(9-5)], 'byRef' => $self->semStack[$stackPos-(9-7)][1], 'stmts' => $self->semStack[$stackPos-(9-9)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); + }, + 177 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Foreach_($self->semStack[$stackPos-(6-3)], new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(6-4)], $self->tokenEndStack[$stackPos-(6-4)])), ['stmts' => $self->semStack[$stackPos-(6-6)]], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); + }, + 178 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Declare_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); + }, + 179 => static function ($self, $stackPos) { + $self->semValue = new Stmt\TryCatch($self->semStack[$stackPos-(6-3)], $self->semStack[$stackPos-(6-5)], $self->semStack[$stackPos-(6-6)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); $self->checkTryCatch($self->semValue); + }, + 180 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Goto_($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 181 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Label($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 182 => static function ($self, $stackPos) { + $self->semValue = null; /* means: no statement */ + }, + 183 => null, + 184 => static function ($self, $stackPos) { + $self->semValue = $self->maybeCreateNop($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]); + }, + 185 => static function ($self, $stackPos) { + if ($self->semStack[$stackPos-(1-1)] instanceof Stmt\Block) { $self->semValue = $self->semStack[$stackPos-(1-1)]->stmts; } else if ($self->semStack[$stackPos-(1-1)] === null) { $self->semValue = []; } else { $self->semValue = [$self->semStack[$stackPos-(1-1)]]; }; + }, + 186 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 187 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; + }, + 188 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 189 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 190 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Catch_($self->semStack[$stackPos-(8-3)], $self->semStack[$stackPos-(8-4)], $self->semStack[$stackPos-(8-7)], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); + }, + 191 => static function ($self, $stackPos) { + $self->semValue = null; + }, + 192 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Finally_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 193 => null, + 194 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 195 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 196 => static function ($self, $stackPos) { + $self->semValue = false; + }, + 197 => static function ($self, $stackPos) { + $self->semValue = true; + }, + 198 => static function ($self, $stackPos) { + $self->semValue = false; + }, + 199 => static function ($self, $stackPos) { + $self->semValue = true; + }, + 200 => static function ($self, $stackPos) { + $self->semValue = false; + }, + 201 => static function ($self, $stackPos) { + $self->semValue = true; + }, + 202 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; + }, + 203 => static function ($self, $stackPos) { + $self->semValue = []; + }, + 204 => null, + 205 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 206 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 207 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 208 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Function_($self->semStack[$stackPos-(8-3)], ['byRef' => $self->semStack[$stackPos-(8-2)], 'params' => $self->semStack[$stackPos-(8-5)], 'returnType' => $self->semStack[$stackPos-(8-7)], 'stmts' => $self->semStack[$stackPos-(8-8)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); + }, + 209 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Function_($self->semStack[$stackPos-(9-4)], ['byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-6)], 'returnType' => $self->semStack[$stackPos-(9-8)], 'stmts' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => $self->semStack[$stackPos-(9-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); + }, + 210 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Class_($self->semStack[$stackPos-(7-2)], ['type' => $self->semStack[$stackPos-(7-1)], 'extends' => $self->semStack[$stackPos-(7-3)], 'implements' => $self->semStack[$stackPos-(7-4)], 'stmts' => $self->semStack[$stackPos-(7-6)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); + $self->checkClass($self->semValue, $stackPos-(7-2)); + }, + 211 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Class_($self->semStack[$stackPos-(8-3)], ['type' => $self->semStack[$stackPos-(8-2)], 'extends' => $self->semStack[$stackPos-(8-4)], 'implements' => $self->semStack[$stackPos-(8-5)], 'stmts' => $self->semStack[$stackPos-(8-7)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); + $self->checkClass($self->semValue, $stackPos-(8-3)); + }, + 212 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Interface_($self->semStack[$stackPos-(7-3)], ['extends' => $self->semStack[$stackPos-(7-4)], 'stmts' => $self->semStack[$stackPos-(7-6)], 'attrGroups' => $self->semStack[$stackPos-(7-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); + $self->checkInterface($self->semValue, $stackPos-(7-3)); + }, + 213 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Trait_($self->semStack[$stackPos-(6-3)], ['stmts' => $self->semStack[$stackPos-(6-5)], 'attrGroups' => $self->semStack[$stackPos-(6-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); + }, + 214 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Enum_($self->semStack[$stackPos-(8-3)], ['scalarType' => $self->semStack[$stackPos-(8-4)], 'implements' => $self->semStack[$stackPos-(8-5)], 'stmts' => $self->semStack[$stackPos-(8-7)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); + $self->checkEnum($self->semValue, $stackPos-(8-3)); + }, + 215 => static function ($self, $stackPos) { + $self->semValue = null; + }, + 216 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(2-2)]; + }, + 217 => static function ($self, $stackPos) { + $self->semValue = null; + }, + 218 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(2-2)]; + }, + 219 => static function ($self, $stackPos) { + $self->semValue = 0; + }, + 220 => null, + 221 => null, + 222 => static function ($self, $stackPos) { + $self->checkClassModifier($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; + }, + 223 => static function ($self, $stackPos) { + $self->semValue = Modifiers::ABSTRACT; + }, + 224 => static function ($self, $stackPos) { + $self->semValue = Modifiers::FINAL; + }, + 225 => static function ($self, $stackPos) { + $self->semValue = Modifiers::READONLY; + }, + 226 => static function ($self, $stackPos) { + $self->semValue = null; + }, + 227 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(2-2)]; + }, + 228 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 229 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(2-2)]; + }, + 230 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 231 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(2-2)]; + }, + 232 => null, + 233 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 234 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 235 => null, + 236 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-2)]; + }, + 237 => null, + 238 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-2)]; + }, + 239 => static function ($self, $stackPos) { + if ($self->semStack[$stackPos-(1-1)] instanceof Stmt\Block) { $self->semValue = $self->semStack[$stackPos-(1-1)]->stmts; } else if ($self->semStack[$stackPos-(1-1)] === null) { $self->semValue = []; } else { $self->semValue = [$self->semStack[$stackPos-(1-1)]]; }; + }, + 240 => static function ($self, $stackPos) { + $self->semValue = null; + }, + 241 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-2)]; + }, + 242 => null, + 243 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 244 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 245 => static function ($self, $stackPos) { + $self->semValue = new Node\DeclareItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 246 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; + }, + 247 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-3)]; + }, + 248 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-2)]; + }, + 249 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(5-3)]; + }, + 250 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 251 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; + }, + 252 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Case_($self->semStack[$stackPos-(4-2)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 253 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Case_(null, $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 254 => null, + 255 => null, + 256 => static function ($self, $stackPos) { + $self->semValue = new Expr\Match_($self->semStack[$stackPos-(7-3)], $self->semStack[$stackPos-(7-6)], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos])); + }, + 257 => static function ($self, $stackPos) { + $self->semValue = []; + }, + 258 => null, + 259 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 260 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 261 => static function ($self, $stackPos) { + $self->semValue = new Node\MatchArm($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 262 => static function ($self, $stackPos) { + $self->semValue = new Node\MatchArm(null, $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 263 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(1-1)]; + }, + 264 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-2)]; + }, + 265 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 266 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; + }, + 267 => static function ($self, $stackPos) { + $self->semValue = new Stmt\ElseIf_($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); + }, + 268 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 269 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; + }, + 270 => static function ($self, $stackPos) { + $self->semValue = new Stmt\ElseIf_($self->semStack[$stackPos-(6-3)], $self->semStack[$stackPos-(6-6)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); $self->fixupAlternativeElse($self->semValue); + }, + 271 => static function ($self, $stackPos) { + $self->semValue = null; + }, + 272 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Else_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 273 => static function ($self, $stackPos) { + $self->semValue = null; + }, + 274 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Else_($self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->fixupAlternativeElse($self->semValue); + }, + 275 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)], false); + }, + 276 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(2-2)], true); + }, + 277 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)], false); + }, + 278 => static function ($self, $stackPos) { + $self->semValue = array($self->fixupArrayDestructuring($self->semStack[$stackPos-(1-1)]), false); + }, + 279 => null, + 280 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 281 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 282 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 283 => static function ($self, $stackPos) { + $self->semValue = 0; + }, + 284 => static function ($self, $stackPos) { + $self->checkModifier($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; + }, + 285 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PUBLIC; + }, + 286 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PROTECTED; + }, + 287 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PRIVATE; + }, + 288 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PUBLIC_SET; + }, + 289 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PROTECTED_SET; + }, + 290 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PRIVATE_SET; + }, + 291 => static function ($self, $stackPos) { + $self->semValue = Modifiers::READONLY; + }, + 292 => static function ($self, $stackPos) { + $self->semValue = Modifiers::FINAL; + }, + 293 => static function ($self, $stackPos) { + $self->semValue = new Node\Param($self->semStack[$stackPos-(7-6)], null, $self->semStack[$stackPos-(7-3)], $self->semStack[$stackPos-(7-4)], $self->semStack[$stackPos-(7-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(7-2)], $self->semStack[$stackPos-(7-1)], $self->semStack[$stackPos-(7-7)]); + $self->checkParam($self->semValue); + $self->addPropertyNameToHooks($self->semValue); + }, + 294 => static function ($self, $stackPos) { + $self->semValue = new Node\Param($self->semStack[$stackPos-(9-6)], $self->semStack[$stackPos-(9-8)], $self->semStack[$stackPos-(9-3)], $self->semStack[$stackPos-(9-4)], $self->semStack[$stackPos-(9-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(9-2)], $self->semStack[$stackPos-(9-1)], $self->semStack[$stackPos-(9-9)]); + $self->checkParam($self->semValue); + $self->addPropertyNameToHooks($self->semValue); + }, + 295 => static function ($self, $stackPos) { + $self->semValue = new Node\Param(new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])), null, $self->semStack[$stackPos-(6-3)], $self->semStack[$stackPos-(6-4)], $self->semStack[$stackPos-(6-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(6-2)], $self->semStack[$stackPos-(6-1)]); + }, + 296 => null, + 297 => static function ($self, $stackPos) { + $self->semValue = new Node\NullableType($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 298 => static function ($self, $stackPos) { + $self->semValue = new Node\UnionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 299 => null, + 300 => null, + 301 => static function ($self, $stackPos) { + $self->semValue = new Node\Name('static', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 302 => static function ($self, $stackPos) { + $self->semValue = $self->handleBuiltinTypes($self->semStack[$stackPos-(1-1)]); + }, + 303 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier('array', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 304 => static function ($self, $stackPos) { + $self->semValue = new Node\Identifier('callable', $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 305 => null, + 306 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; + }, + 307 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); + }, + 308 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 309 => null, + 310 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; + }, + 311 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); + }, + 312 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 313 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); + }, + 314 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 315 => static function ($self, $stackPos) { + $self->semValue = new Node\IntersectionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 316 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); + }, + 317 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 318 => static function ($self, $stackPos) { + $self->semValue = new Node\IntersectionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 319 => null, + 320 => static function ($self, $stackPos) { + $self->semValue = new Node\NullableType($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 321 => static function ($self, $stackPos) { + $self->semValue = new Node\UnionType($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 322 => null, + 323 => static function ($self, $stackPos) { + $self->semValue = null; + }, + 324 => null, + 325 => static function ($self, $stackPos) { + $self->semValue = null; + }, + 326 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(2-2)]; + }, + 327 => static function ($self, $stackPos) { + $self->semValue = null; + }, + 328 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 329 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-2)]; + }, + 330 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(3-2)]); + }, + 331 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 332 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-2)]; + }, + 333 => static function ($self, $stackPos) { + $self->semValue = array(new Node\Arg($self->semStack[$stackPos-(4-2)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]))); + }, + 334 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(3-2)]); + }, + 335 => static function ($self, $stackPos) { + $self->semValue = array(new Node\Arg($self->semStack[$stackPos-(3-1)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos-(3-1)])), $self->semStack[$stackPos-(3-3)]); + }, + 336 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 337 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 338 => static function ($self, $stackPos) { + $self->semValue = new Node\VariadicPlaceholder($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 339 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 340 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 341 => static function ($self, $stackPos) { + $self->semValue = new Node\Arg($self->semStack[$stackPos-(2-2)], true, false, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 342 => static function ($self, $stackPos) { + $self->semValue = new Node\Arg($self->semStack[$stackPos-(2-2)], false, true, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 343 => static function ($self, $stackPos) { + $self->semValue = new Node\Arg($self->semStack[$stackPos-(3-3)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(3-1)]); + }, + 344 => static function ($self, $stackPos) { + $self->semValue = new Node\Arg($self->semStack[$stackPos-(1-1)], false, false, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 345 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(1-1)]; + }, + 346 => null, + 347 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 348 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 349 => null, + 350 => null, + 351 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 352 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 353 => static function ($self, $stackPos) { + $self->semValue = new Node\StaticVar($self->semStack[$stackPos-(1-1)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 354 => static function ($self, $stackPos) { + $self->semValue = new Node\StaticVar($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 355 => static function ($self, $stackPos) { + if ($self->semStack[$stackPos-(2-2)] !== null) { $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; } else { $self->semValue = $self->semStack[$stackPos-(2-1)]; } + }, + 356 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 357 => static function ($self, $stackPos) { + $nop = $self->maybeCreateZeroLengthNop($self->tokenPos);; + if ($nop !== null) { $self->semStack[$stackPos-(1-1)][] = $nop; } $self->semValue = $self->semStack[$stackPos-(1-1)]; + }, + 358 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Property($self->semStack[$stackPos-(5-2)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-1)]); + }, + 359 => static function ($self, $stackPos) { + $self->semValue = new Stmt\Property($self->semStack[$stackPos-(7-2)], $self->semStack[$stackPos-(7-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(7-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(7-3)], $self->semStack[$stackPos-(7-1)], $self->semStack[$stackPos-(7-6)]); + $self->checkPropertyHooksForMultiProperty($self->semValue, $stackPos-(7-5)); + $self->checkEmptyPropertyHookList($self->semStack[$stackPos-(7-6)], $stackPos-(7-5)); + $self->addPropertyNameToHooks($self->semValue); + }, + 360 => static function ($self, $stackPos) { + $self->semValue = new Stmt\ClassConst($self->semStack[$stackPos-(5-4)], $self->semStack[$stackPos-(5-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(5-1)]); + $self->checkClassConst($self->semValue, $stackPos-(5-2)); + }, + 361 => static function ($self, $stackPos) { + $self->semValue = new Stmt\ClassConst($self->semStack[$stackPos-(6-5)], $self->semStack[$stackPos-(6-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos]), $self->semStack[$stackPos-(6-1)], $self->semStack[$stackPos-(6-4)]); + $self->checkClassConst($self->semValue, $stackPos-(6-2)); + }, + 362 => static function ($self, $stackPos) { + $self->semValue = new Stmt\ClassMethod($self->semStack[$stackPos-(10-5)], ['type' => $self->semStack[$stackPos-(10-2)], 'byRef' => $self->semStack[$stackPos-(10-4)], 'params' => $self->semStack[$stackPos-(10-7)], 'returnType' => $self->semStack[$stackPos-(10-9)], 'stmts' => $self->semStack[$stackPos-(10-10)], 'attrGroups' => $self->semStack[$stackPos-(10-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); + $self->checkClassMethod($self->semValue, $stackPos-(10-2)); + }, + 363 => static function ($self, $stackPos) { + $self->semValue = new Stmt\TraitUse($self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 364 => static function ($self, $stackPos) { + $self->semValue = new Stmt\EnumCase($self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-4)], $self->semStack[$stackPos-(5-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); + }, + 365 => static function ($self, $stackPos) { + $self->semValue = null; /* will be skipped */ + }, + 366 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 367 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; + }, + 368 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 369 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; + }, + 370 => static function ($self, $stackPos) { + $self->semValue = new Stmt\TraitUseAdaptation\Precedence($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 371 => static function ($self, $stackPos) { + $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(5-1)][0], $self->semStack[$stackPos-(5-1)][1], $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); + }, + 372 => static function ($self, $stackPos) { + $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 373 => static function ($self, $stackPos) { + $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 374 => static function ($self, $stackPos) { + $self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 375 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); + }, + 376 => null, + 377 => static function ($self, $stackPos) { + $self->semValue = array(null, $self->semStack[$stackPos-(1-1)]); + }, + 378 => static function ($self, $stackPos) { + $self->semValue = null; + }, + 379 => null, + 380 => null, + 381 => static function ($self, $stackPos) { + $self->semValue = 0; + }, + 382 => static function ($self, $stackPos) { + $self->semValue = 0; + }, + 383 => null, + 384 => null, + 385 => static function ($self, $stackPos) { + $self->checkModifier($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; + }, + 386 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PUBLIC; + }, + 387 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PROTECTED; + }, + 388 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PRIVATE; + }, + 389 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PUBLIC_SET; + }, + 390 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PROTECTED_SET; + }, + 391 => static function ($self, $stackPos) { + $self->semValue = Modifiers::PRIVATE_SET; + }, + 392 => static function ($self, $stackPos) { + $self->semValue = Modifiers::STATIC; + }, + 393 => static function ($self, $stackPos) { + $self->semValue = Modifiers::ABSTRACT; + }, + 394 => static function ($self, $stackPos) { + $self->semValue = Modifiers::FINAL; + }, + 395 => static function ($self, $stackPos) { + $self->semValue = Modifiers::READONLY; + }, + 396 => null, + 397 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 398 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 399 => static function ($self, $stackPos) { + $self->semValue = new Node\VarLikeIdentifier(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 400 => static function ($self, $stackPos) { + $self->semValue = new Node\PropertyItem($self->semStack[$stackPos-(1-1)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 401 => static function ($self, $stackPos) { + $self->semValue = new Node\PropertyItem($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 402 => static function ($self, $stackPos) { + $self->semValue = []; + }, + 403 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; + }, + 404 => static function ($self, $stackPos) { + $self->semValue = []; + }, + 405 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; $self->checkEmptyPropertyHookList($self->semStack[$stackPos-(3-2)], $stackPos-(3-1)); + }, + 406 => static function ($self, $stackPos) { + $self->semValue = new Node\PropertyHook($self->semStack[$stackPos-(5-4)], $self->semStack[$stackPos-(5-5)], ['flags' => $self->semStack[$stackPos-(5-2)], 'byRef' => $self->semStack[$stackPos-(5-3)], 'params' => [], 'attrGroups' => $self->semStack[$stackPos-(5-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); + $self->checkPropertyHook($self->semValue, null); + }, + 407 => static function ($self, $stackPos) { + $self->semValue = new Node\PropertyHook($self->semStack[$stackPos-(8-4)], $self->semStack[$stackPos-(8-8)], ['flags' => $self->semStack[$stackPos-(8-2)], 'byRef' => $self->semStack[$stackPos-(8-3)], 'params' => $self->semStack[$stackPos-(8-6)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); + $self->checkPropertyHook($self->semValue, $stackPos-(8-5)); + }, + 408 => static function ($self, $stackPos) { + $self->semValue = null; + }, + 409 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; + }, + 410 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; + }, + 411 => static function ($self, $stackPos) { + $self->semValue = 0; + }, + 412 => static function ($self, $stackPos) { + $self->checkPropertyHookModifiers($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $stackPos-(2-2)); $self->semValue = $self->semStack[$stackPos-(2-1)] | $self->semStack[$stackPos-(2-2)]; + }, + 413 => null, + 414 => null, + 415 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 416 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 417 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 418 => null, + 419 => null, + 420 => static function ($self, $stackPos) { + $self->semValue = new Expr\Assign($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 421 => static function ($self, $stackPos) { + $self->semValue = new Expr\Assign($self->fixupArrayDestructuring($self->semStack[$stackPos-(3-1)]), $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 422 => static function ($self, $stackPos) { + $self->semValue = new Expr\Assign($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 423 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignRef($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 424 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignRef($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + if (!$self->phpVersion->allowsAssignNewByReference()) { + $self->emitError(new Error('Cannot assign new by reference', $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]))); + } + + }, + 425 => null, + 426 => null, + 427 => static function ($self, $stackPos) { + $self->semValue = new Expr\FuncCall(new Node\Name($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos-(2-1)])), $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 428 => static function ($self, $stackPos) { + $self->semValue = new Expr\Clone_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 429 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Plus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 430 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Minus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 431 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Mul($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 432 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Div($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 433 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Concat($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 434 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Mod($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 435 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\BitwiseAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 436 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\BitwiseOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 437 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\BitwiseXor($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 438 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\ShiftLeft($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 439 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\ShiftRight($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 440 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Pow($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 441 => static function ($self, $stackPos) { + $self->semValue = new Expr\AssignOp\Coalesce($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 442 => static function ($self, $stackPos) { + $self->semValue = new Expr\PostInc($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 443 => static function ($self, $stackPos) { + $self->semValue = new Expr\PreInc($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 444 => static function ($self, $stackPos) { + $self->semValue = new Expr\PostDec($self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 445 => static function ($self, $stackPos) { + $self->semValue = new Expr\PreDec($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 446 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\BooleanOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 447 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\BooleanAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 448 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\LogicalOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 449 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\LogicalAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 450 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\LogicalXor($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 451 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\BitwiseOr($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 452 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\BitwiseAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 453 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\BitwiseAnd($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 454 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\BitwiseXor($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 455 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Concat($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 456 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Plus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 457 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Minus($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 458 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Mul($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 459 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Div($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 460 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Mod($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 461 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\ShiftLeft($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 462 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\ShiftRight($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 463 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Pow($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 464 => static function ($self, $stackPos) { + $self->semValue = new Expr\UnaryPlus($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 465 => static function ($self, $stackPos) { + $self->semValue = new Expr\UnaryMinus($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 466 => static function ($self, $stackPos) { + $self->semValue = new Expr\BooleanNot($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 467 => static function ($self, $stackPos) { + $self->semValue = new Expr\BitwiseNot($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 468 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Identical($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 469 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\NotIdentical($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 470 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Equal($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 471 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\NotEqual($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 472 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Spaceship($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 473 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Smaller($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 474 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\SmallerOrEqual($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 475 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Greater($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 476 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\GreaterOrEqual($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 477 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Pipe($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 478 => static function ($self, $stackPos) { + $self->semValue = new Expr\Instanceof_($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 479 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; + }, + 480 => static function ($self, $stackPos) { + $self->semValue = new Expr\Ternary($self->semStack[$stackPos-(5-1)], $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-5)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); + }, + 481 => static function ($self, $stackPos) { + $self->semValue = new Expr\Ternary($self->semStack[$stackPos-(4-1)], null, $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 482 => static function ($self, $stackPos) { + $self->semValue = new Expr\BinaryOp\Coalesce($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 483 => static function ($self, $stackPos) { + $self->semValue = new Expr\Isset_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 484 => static function ($self, $stackPos) { + $self->semValue = new Expr\Empty_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 485 => static function ($self, $stackPos) { + $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_INCLUDE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 486 => static function ($self, $stackPos) { + $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_INCLUDE_ONCE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 487 => static function ($self, $stackPos) { + $self->semValue = new Expr\Eval_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 488 => static function ($self, $stackPos) { + $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_REQUIRE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 489 => static function ($self, $stackPos) { + $self->semValue = new Expr\Include_($self->semStack[$stackPos-(2-2)], Expr\Include_::TYPE_REQUIRE_ONCE, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 490 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); + $attrs['kind'] = $self->getIntCastKind($self->semStack[$stackPos-(2-1)]); + $self->semValue = new Expr\Cast\Int_($self->semStack[$stackPos-(2-2)], $attrs); + }, + 491 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); + $attrs['kind'] = $self->getFloatCastKind($self->semStack[$stackPos-(2-1)]); + $self->semValue = new Expr\Cast\Double($self->semStack[$stackPos-(2-2)], $attrs); + }, + 492 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); + $attrs['kind'] = $self->getStringCastKind($self->semStack[$stackPos-(2-1)]); + $self->semValue = new Expr\Cast\String_($self->semStack[$stackPos-(2-2)], $attrs); + }, + 493 => static function ($self, $stackPos) { + $self->semValue = new Expr\Cast\Array_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 494 => static function ($self, $stackPos) { + $self->semValue = new Expr\Cast\Object_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 495 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]); + $attrs['kind'] = $self->getBoolCastKind($self->semStack[$stackPos-(2-1)]); + $self->semValue = new Expr\Cast\Bool_($self->semStack[$stackPos-(2-2)], $attrs); + }, + 496 => static function ($self, $stackPos) { + $self->semValue = new Expr\Cast\Unset_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 497 => static function ($self, $stackPos) { + $self->semValue = new Expr\Cast\Void_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 498 => static function ($self, $stackPos) { + $self->semValue = $self->createExitExpr($self->semStack[$stackPos-(2-1)], $stackPos-(2-1), $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 499 => static function ($self, $stackPos) { + $self->semValue = new Expr\ErrorSuppress($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 500 => null, + 501 => static function ($self, $stackPos) { + $self->semValue = new Expr\ShellExec($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 502 => static function ($self, $stackPos) { + $self->semValue = new Expr\Print_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 503 => static function ($self, $stackPos) { + $self->semValue = new Expr\Yield_(null, null, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 504 => static function ($self, $stackPos) { + $self->semValue = new Expr\Yield_($self->semStack[$stackPos-(2-2)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 505 => static function ($self, $stackPos) { + $self->semValue = new Expr\Yield_($self->semStack[$stackPos-(4-4)], $self->semStack[$stackPos-(4-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 506 => static function ($self, $stackPos) { + $self->semValue = new Expr\YieldFrom($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 507 => static function ($self, $stackPos) { + $self->semValue = new Expr\Throw_($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 508 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrowFunction(['static' => false, 'byRef' => $self->semStack[$stackPos-(8-2)], 'params' => $self->semStack[$stackPos-(8-4)], 'returnType' => $self->semStack[$stackPos-(8-6)], 'expr' => $self->semStack[$stackPos-(8-8)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); + }, + 509 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrowFunction(['static' => true, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'returnType' => $self->semStack[$stackPos-(9-7)], 'expr' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); + }, + 510 => static function ($self, $stackPos) { + $self->semValue = new Expr\Closure(['static' => false, 'byRef' => $self->semStack[$stackPos-(8-2)], 'params' => $self->semStack[$stackPos-(8-4)], 'uses' => $self->semStack[$stackPos-(8-6)], 'returnType' => $self->semStack[$stackPos-(8-7)], 'stmts' => $self->semStack[$stackPos-(8-8)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])); + }, + 511 => static function ($self, $stackPos) { + $self->semValue = new Expr\Closure(['static' => true, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'uses' => $self->semStack[$stackPos-(9-7)], 'returnType' => $self->semStack[$stackPos-(9-8)], 'stmts' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => []], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); + }, + 512 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrowFunction(['static' => false, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'returnType' => $self->semStack[$stackPos-(9-7)], 'expr' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => $self->semStack[$stackPos-(9-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); + }, + 513 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrowFunction(['static' => true, 'byRef' => $self->semStack[$stackPos-(10-4)], 'params' => $self->semStack[$stackPos-(10-6)], 'returnType' => $self->semStack[$stackPos-(10-8)], 'expr' => $self->semStack[$stackPos-(10-10)], 'attrGroups' => $self->semStack[$stackPos-(10-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); + }, + 514 => static function ($self, $stackPos) { + $self->semValue = new Expr\Closure(['static' => false, 'byRef' => $self->semStack[$stackPos-(9-3)], 'params' => $self->semStack[$stackPos-(9-5)], 'uses' => $self->semStack[$stackPos-(9-7)], 'returnType' => $self->semStack[$stackPos-(9-8)], 'stmts' => $self->semStack[$stackPos-(9-9)], 'attrGroups' => $self->semStack[$stackPos-(9-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(9-1)], $self->tokenEndStack[$stackPos])); + }, + 515 => static function ($self, $stackPos) { + $self->semValue = new Expr\Closure(['static' => true, 'byRef' => $self->semStack[$stackPos-(10-4)], 'params' => $self->semStack[$stackPos-(10-6)], 'uses' => $self->semStack[$stackPos-(10-8)], 'returnType' => $self->semStack[$stackPos-(10-9)], 'stmts' => $self->semStack[$stackPos-(10-10)], 'attrGroups' => $self->semStack[$stackPos-(10-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(10-1)], $self->tokenEndStack[$stackPos])); + }, + 516 => static function ($self, $stackPos) { + $self->semValue = array(new Stmt\Class_(null, ['type' => $self->semStack[$stackPos-(8-2)], 'extends' => $self->semStack[$stackPos-(8-4)], 'implements' => $self->semStack[$stackPos-(8-5)], 'stmts' => $self->semStack[$stackPos-(8-7)], 'attrGroups' => $self->semStack[$stackPos-(8-1)]], $self->getAttributes($self->tokenStartStack[$stackPos-(8-1)], $self->tokenEndStack[$stackPos])), $self->semStack[$stackPos-(8-3)]); + $self->checkClass($self->semValue[0], -1); + }, + 517 => static function ($self, $stackPos) { + $self->semValue = new Expr\New_($self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 518 => static function ($self, $stackPos) { + list($class, $ctorArgs) = $self->semStack[$stackPos-(2-2)]; $self->semValue = new Expr\New_($class, $ctorArgs, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 519 => static function ($self, $stackPos) { + $self->semValue = new Expr\New_($self->semStack[$stackPos-(2-2)], [], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 520 => null, + 521 => null, + 522 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 523 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(4-3)]; + }, + 524 => null, + 525 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 526 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 527 => static function ($self, $stackPos) { + $self->semValue = new Node\ClosureUse($self->semStack[$stackPos-(2-2)], $self->semStack[$stackPos-(2-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 528 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 529 => static function ($self, $stackPos) { + $self->semValue = new Expr\FuncCall($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 530 => static function ($self, $stackPos) { + $self->semValue = new Expr\FuncCall($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 531 => static function ($self, $stackPos) { + $self->semValue = new Expr\FuncCall($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 532 => static function ($self, $stackPos) { + $self->semValue = new Expr\StaticCall($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 533 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 534 => null, + 535 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 536 => static function ($self, $stackPos) { + $self->semValue = new Name($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 537 => static function ($self, $stackPos) { + $self->semValue = new Name\FullyQualified(substr($self->semStack[$stackPos-(1-1)], 1), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 538 => static function ($self, $stackPos) { + $self->semValue = new Name\Relative(substr($self->semStack[$stackPos-(1-1)], 10), $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 539 => null, + 540 => null, + 541 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; + }, + 542 => static function ($self, $stackPos) { + $self->semValue = new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; + }, + 543 => null, + 544 => null, + 545 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 546 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); foreach ($self->semValue as $s) { if ($s instanceof Node\InterpolatedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '`', $self->phpVersion->supportsUnicodeEscapes()); } }; + }, + 547 => static function ($self, $stackPos) { + foreach ($self->semStack[$stackPos-(1-1)] as $s) { if ($s instanceof Node\InterpolatedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '`', $self->phpVersion->supportsUnicodeEscapes()); } }; $self->semValue = $self->semStack[$stackPos-(1-1)]; + }, + 548 => static function ($self, $stackPos) { + $self->semValue = array(); + }, + 549 => null, + 550 => static function ($self, $stackPos) { + $self->semValue = new Expr\ConstFetch($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 551 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Line($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 552 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\File($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 553 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Dir($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 554 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Class_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 555 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Trait_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 556 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Method($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 557 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Function_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 558 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Namespace_($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 559 => static function ($self, $stackPos) { + $self->semValue = new Scalar\MagicConst\Property($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 560 => static function ($self, $stackPos) { + $self->semValue = new Expr\ClassConstFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 561 => static function ($self, $stackPos) { + $self->semValue = new Expr\ClassConstFetch($self->semStack[$stackPos-(5-1)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos])); + }, + 562 => static function ($self, $stackPos) { + $self->semValue = new Expr\ClassConstFetch($self->semStack[$stackPos-(3-1)], new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(3-3)], $self->tokenEndStack[$stackPos-(3-3)])), $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; + }, + 563 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = Expr\Array_::KIND_SHORT; + $self->semValue = new Expr\Array_($self->semStack[$stackPos-(3-2)], $attrs); + }, + 564 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = Expr\Array_::KIND_LONG; + $self->semValue = new Expr\Array_($self->semStack[$stackPos-(4-3)], $attrs); + $self->createdArrays->offsetSet($self->semValue); + }, + 565 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(1-1)]; $self->createdArrays->offsetSet($self->semValue); + }, + 566 => static function ($self, $stackPos) { + $self->semValue = Scalar\String_::fromString($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]), $self->phpVersion->supportsUnicodeEscapes()); + }, + 567 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]); $attrs['kind'] = Scalar\String_::KIND_DOUBLE_QUOTED; + foreach ($self->semStack[$stackPos-(3-2)] as $s) { if ($s instanceof Node\InterpolatedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, '"', $self->phpVersion->supportsUnicodeEscapes()); } }; $self->semValue = new Scalar\InterpolatedString($self->semStack[$stackPos-(3-2)], $attrs); + }, + 568 => static function ($self, $stackPos) { + $self->semValue = $self->parseLNumber($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]), $self->phpVersion->allowsInvalidOctals()); + }, + 569 => static function ($self, $stackPos) { + $self->semValue = Scalar\Float_::fromString($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 570 => null, + 571 => null, + 572 => null, + 573 => static function ($self, $stackPos) { + $self->semValue = $self->parseDocString($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), $self->getAttributes($self->tokenStartStack[$stackPos-(3-3)], $self->tokenEndStack[$stackPos-(3-3)]), true); + }, + 574 => static function ($self, $stackPos) { + $self->semValue = $self->parseDocString($self->semStack[$stackPos-(2-1)], '', $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]), $self->getAttributes($self->tokenStartStack[$stackPos-(2-2)], $self->tokenEndStack[$stackPos-(2-2)]), true); + }, + 575 => static function ($self, $stackPos) { + $self->semValue = $self->parseDocString($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-2)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos]), $self->getAttributes($self->tokenStartStack[$stackPos-(3-3)], $self->tokenEndStack[$stackPos-(3-3)]), true); + }, + 576 => static function ($self, $stackPos) { + $self->semValue = null; + }, + 577 => null, + 578 => null, + 579 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; + }, + 580 => null, + 581 => null, + 582 => null, + 583 => null, + 584 => null, + 585 => null, + 586 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; + }, + 587 => null, + 588 => null, + 589 => null, + 590 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 591 => null, + 592 => static function ($self, $stackPos) { + $self->semValue = new Expr\MethodCall($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 593 => static function ($self, $stackPos) { + $self->semValue = new Expr\NullsafeMethodCall($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->semStack[$stackPos-(4-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 594 => static function ($self, $stackPos) { + $self->semValue = null; + }, + 595 => null, + 596 => null, + 597 => null, + 598 => static function ($self, $stackPos) { + $self->semValue = new Expr\PropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 599 => static function ($self, $stackPos) { + $self->semValue = new Expr\NullsafePropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 600 => null, + 601 => static function ($self, $stackPos) { + $self->semValue = new Expr\Variable($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 602 => static function ($self, $stackPos) { + $self->semValue = new Expr\Variable($self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 603 => static function ($self, $stackPos) { + $self->semValue = new Expr\Variable(new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])), $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; + }, + 604 => static function ($self, $stackPos) { + $var = $self->semStack[$stackPos-(1-1)]->name; $self->semValue = \is_string($var) ? new Node\VarLikeIdentifier($var, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])) : $var; + }, + 605 => static function ($self, $stackPos) { + $self->semValue = new Expr\StaticPropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 606 => null, + 607 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 608 => static function ($self, $stackPos) { + $self->semValue = new Expr\PropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 609 => static function ($self, $stackPos) { + $self->semValue = new Expr\NullsafePropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 610 => static function ($self, $stackPos) { + $self->semValue = new Expr\StaticPropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 611 => static function ($self, $stackPos) { + $self->semValue = new Expr\StaticPropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 612 => null, + 613 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; + }, + 614 => null, + 615 => null, + 616 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; + }, + 617 => null, + 618 => static function ($self, $stackPos) { + $self->semValue = new Expr\Error($self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); $self->errorState = 2; + }, + 619 => static function ($self, $stackPos) { + $self->semValue = new Expr\List_($self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); $self->semValue->setAttribute('kind', Expr\List_::KIND_LIST); + $self->postprocessList($self->semValue); + }, + 620 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(1-1)]; $end = count($self->semValue)-1; if ($self->semValue[$end]->value instanceof Expr\Error) array_pop($self->semValue); + }, + 621 => null, + 622 => static function ($self, $stackPos) { + /* do nothing -- prevent default action of $$=$self->semStack[$1]. See $551. */ + }, + 623 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(3-1)][] = $self->semStack[$stackPos-(3-3)]; $self->semValue = $self->semStack[$stackPos-(3-1)]; + }, + 624 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 625 => static function ($self, $stackPos) { + $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(1-1)], null, false, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 626 => static function ($self, $stackPos) { + $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(2-2)], null, true, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 627 => static function ($self, $stackPos) { + $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(1-1)], null, false, $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 628 => static function ($self, $stackPos) { + $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(3-3)], $self->semStack[$stackPos-(3-1)], false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 629 => static function ($self, $stackPos) { + $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(4-4)], $self->semStack[$stackPos-(4-1)], true, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 630 => static function ($self, $stackPos) { + $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(3-3)], $self->semStack[$stackPos-(3-1)], false, $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 631 => static function ($self, $stackPos) { + $self->semValue = new Node\ArrayItem($self->semStack[$stackPos-(2-2)], null, false, $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos]), true); + }, + 632 => static function ($self, $stackPos) { + /* Create an Error node now to remember the position. We'll later either report an error, + or convert this into a null element, depending on whether this is a creation or destructuring context. */ + $attrs = $self->createEmptyElemAttributes($self->tokenPos); + $self->semValue = new Node\ArrayItem(new Expr\Error($attrs), null, false, $attrs); + }, + 633 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; + }, + 634 => static function ($self, $stackPos) { + $self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)]; + }, + 635 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(1-1)]); + }, + 636 => static function ($self, $stackPos) { + $self->semValue = array($self->semStack[$stackPos-(2-1)], $self->semStack[$stackPos-(2-2)]); + }, + 637 => static function ($self, $stackPos) { + $attrs = $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos]); $attrs['rawValue'] = $self->semStack[$stackPos-(1-1)]; $self->semValue = new Node\InterpolatedStringPart($self->semStack[$stackPos-(1-1)], $attrs); + }, + 638 => static function ($self, $stackPos) { + $self->semValue = new Expr\Variable($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 639 => null, + 640 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(4-1)], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos])); + }, + 641 => static function ($self, $stackPos) { + $self->semValue = new Expr\PropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 642 => static function ($self, $stackPos) { + $self->semValue = new Expr\NullsafePropertyFetch($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 643 => static function ($self, $stackPos) { + $self->semValue = new Expr\Variable($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 644 => static function ($self, $stackPos) { + $self->semValue = new Expr\Variable($self->semStack[$stackPos-(3-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(3-1)], $self->tokenEndStack[$stackPos])); + }, + 645 => static function ($self, $stackPos) { + $self->semValue = new Expr\ArrayDimFetch($self->semStack[$stackPos-(6-2)], $self->semStack[$stackPos-(6-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(6-1)], $self->tokenEndStack[$stackPos])); + }, + 646 => static function ($self, $stackPos) { + $self->semValue = $self->semStack[$stackPos-(3-2)]; + }, + 647 => static function ($self, $stackPos) { + $self->semValue = new Scalar\String_($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 648 => static function ($self, $stackPos) { + $self->semValue = $self->parseNumString($self->semStack[$stackPos-(1-1)], $self->getAttributes($self->tokenStartStack[$stackPos-(1-1)], $self->tokenEndStack[$stackPos])); + }, + 649 => static function ($self, $stackPos) { + $self->semValue = $self->parseNumString('-' . $self->semStack[$stackPos-(2-2)], $self->getAttributes($self->tokenStartStack[$stackPos-(2-1)], $self->tokenEndStack[$stackPos])); + }, + 650 => null, + ]; + } +} diff --git a/lib/PhpParser/Parser/Tokens.php b/lib/PhpParser/Parser/Tokens.php deleted file mode 100644 index 07cab217a8..0000000000 --- a/lib/PhpParser/Parser/Tokens.php +++ /dev/null @@ -1,145 +0,0 @@ - Map of PHP token IDs to drop */ + protected array $dropTokens; + /** @var int[] Map of external symbols (static::T_*) to internal symbols */ + protected array $tokenToSymbol; /** @var string[] Map of symbols to their names */ - protected $symbolToName; - /** @var array Names of the production rules (only necessary for debugging) */ - protected $productions; + protected array $symbolToName; + /** @var array Names of the production rules (only necessary for debugging) */ + protected array $productions; /** @var int[] Map of states to a displacement into the $action table. The corresponding action for this * state/symbol pair is $action[$actionBase[$state] + $symbol]. If $actionBase[$state] is 0, the - action is defaulted, i.e. $actionDefault[$state] should be used instead. */ - protected $actionBase; + * action is defaulted, i.e. $actionDefault[$state] should be used instead. */ + protected array $actionBase; /** @var int[] Table of actions. Indexed according to $actionBase comment. */ - protected $action; + protected array $action; /** @var int[] Table indexed analogously to $action. If $actionCheck[$actionBase[$state] + $symbol] != $symbol * then the action is defaulted, i.e. $actionDefault[$state] should be used instead. */ - protected $actionCheck; + protected array $actionCheck; /** @var int[] Map of states to their default action */ - protected $actionDefault; + protected array $actionDefault; /** @var callable[] Semantic action callbacks */ - protected $reduceCallbacks; + protected array $reduceCallbacks; /** @var int[] Map of non-terminals to a displacement into the $goto table. The corresponding goto state for this * non-terminal/state pair is $goto[$gotoBase[$nonTerminal] + $state] (unless defaulted) */ - protected $gotoBase; + protected array $gotoBase; /** @var int[] Table of states to goto after reduction. Indexed according to $gotoBase comment. */ - protected $goto; + protected array $goto; /** @var int[] Table indexed analogously to $goto. If $gotoCheck[$gotoBase[$nonTerminal] + $state] != $nonTerminal * then the goto state is defaulted, i.e. $gotoDefault[$nonTerminal] should be used. */ - protected $gotoCheck; + protected array $gotoCheck; /** @var int[] Map of non-terminals to the default state to goto after their reduction */ - protected $gotoDefault; + protected array $gotoDefault; /** @var int[] Map of rules to the non-terminal on their left-hand side, i.e. the non-terminal to use for * determining the state to goto after reduction. */ - protected $ruleToNonTerminal; + protected array $ruleToNonTerminal; /** @var int[] Map of rules to the length of their right-hand side, which is the number of elements that have to * be popped from the stack(s) on reduction. */ - protected $ruleToLength; + protected array $ruleToLength; /* * The following members are part of the parser state: */ - /** @var Lexer Lexer that is used when parsing */ - protected $lexer; /** @var mixed Temporary value containing the result of last semantic action (reduction) */ protected $semValue; - /** @var array Semantic value stack (contains values of tokens and semantic action results) */ - protected $semStack; - /** @var array[] Start attribute stack */ - protected $startAttributeStack; - /** @var array[] End attribute stack */ - protected $endAttributeStack; - /** @var array End attributes of last *shifted* token */ - protected $endAttributes; - /** @var array Start attributes of last *read* token */ - protected $lookaheadStartAttributes; + /** @var mixed[] Semantic value stack (contains values of tokens and semantic action results) */ + protected array $semStack; + /** @var int[] Token start position stack */ + protected array $tokenStartStack; + /** @var int[] Token end position stack */ + protected array $tokenEndStack; /** @var ErrorHandler Error handler */ - protected $errorHandler; + protected ErrorHandler $errorHandler; /** @var int Error state, used to avoid error floods */ - protected $errorState; + protected int $errorState; + + /** @var \SplObjectStorage|null Array nodes created during parsing, for postprocessing of empty elements. */ + protected ?\SplObjectStorage $createdArrays; + + /** @var Token[] Tokens for the current parse */ + protected array $tokens; + /** @var int Current position in token array */ + protected int $tokenPos; /** * Initialize $reduceCallbacks map. */ - abstract protected function initReduceCallbacks(); + abstract protected function initReduceCallbacks(): void; /** * Creates a parser instance. * - * Options: Currently none. + * Options: + * * phpVersion: ?PhpVersion, * * @param Lexer $lexer A lexer - * @param array $options Options array. + * @param PhpVersion $phpVersion PHP version to target, defaults to latest supported. This + * option is best-effort: Even if specified, parsing will generally assume the latest + * supported version and only adjust behavior in minor ways, for example by omitting + * errors in older versions and interpreting type hints as a name or identifier depending + * on version. */ - public function __construct(Lexer $lexer, array $options = []) { + public function __construct(Lexer $lexer, ?PhpVersion $phpVersion = null) { $this->lexer = $lexer; - - if (isset($options['throwOnError'])) { - throw new \LogicException( - '"throwOnError" is no longer supported, use "errorHandler" instead'); - } + $this->phpVersion = $phpVersion ?? PhpVersion::getNewestSupported(); $this->initReduceCallbacks(); + $this->phpTokenToSymbol = $this->createTokenMap(); + $this->dropTokens = array_fill_keys( + [\T_WHITESPACE, \T_OPEN_TAG, \T_COMMENT, \T_DOC_COMMENT, \T_BAD_CHARACTER], true + ); } /** @@ -151,36 +179,55 @@ public function __construct(Lexer $lexer, array $options = []) { * @return Node\Stmt[]|null Array of statements (or null non-throwing error handler is used and * the parser was unable to recover from an error). */ - public function parse(string $code, ErrorHandler $errorHandler = null) { - $this->errorHandler = $errorHandler ?: new ErrorHandler\Throwing; + public function parse(string $code, ?ErrorHandler $errorHandler = null): ?array { + $this->errorHandler = $errorHandler ?: new ErrorHandler\Throwing(); + $this->createdArrays = new \SplObjectStorage(); - $this->lexer->startLexing($code, $this->errorHandler); + $this->tokens = $this->lexer->tokenize($code, $this->errorHandler); $result = $this->doParse(); + // Report errors for any empty elements used inside arrays. This is delayed until after the main parse, + // because we don't know a priori whether a given array expression will be used in a destructuring context + // or not. + foreach ($this->createdArrays as $node) { + foreach ($node->items as $item) { + if ($item->value instanceof Expr\Error) { + $this->errorHandler->handleError( + new Error('Cannot use empty array elements in arrays', $item->getAttributes())); + } + } + } + // Clear out some of the interior state, so we don't hold onto unnecessary // memory between uses of the parser - $this->startAttributeStack = []; - $this->endAttributeStack = []; + $this->tokenStartStack = []; + $this->tokenEndStack = []; $this->semStack = []; $this->semValue = null; + $this->createdArrays = null; + + if ($result !== null) { + $traverser = new NodeTraverser(new CommentAnnotatingVisitor($this->tokens)); + $traverser->traverse($result); + } return $result; } - protected function doParse() { + public function getTokens(): array { + return $this->tokens; + } + + /** @return Stmt[]|null */ + protected function doParse(): ?array { // We start off with no lookahead-token $symbol = self::SYMBOL_NONE; - - // The attributes for a node are taken from the first and last token of the node. - // From the first token only the startAttributes are taken and from the last only - // the endAttributes. Both are merged using the array union operator (+). - $startAttributes = []; - $endAttributes = []; - $this->endAttributes = $endAttributes; + $tokenValue = null; + $this->tokenPos = -1; // Keep stack of start and end attributes - $this->startAttributeStack = []; - $this->endAttributeStack = [$endAttributes]; + $this->tokenStartStack = []; + $this->tokenEndStack = [0]; // Start off in the initial state and keep a stack of previous states $state = 0; @@ -201,26 +248,20 @@ protected function doParse() { $rule = $this->actionDefault[$state]; } else { if ($symbol === self::SYMBOL_NONE) { - // Fetch the next token id from the lexer and fetch additional info by-ref. - // The end attributes are fetched into a temporary variable and only set once the token is really - // shifted (not during read). Otherwise you would sometimes get off-by-one errors, when a rule is - // reduced after a token was read but not yet shifted. - $tokenId = $this->lexer->getNextToken($tokenValue, $startAttributes, $endAttributes); - - // map the lexer token id to the internally used symbols - $symbol = $tokenId >= 0 && $tokenId < $this->tokenToSymbolMapSize - ? $this->tokenToSymbol[$tokenId] - : $this->invalidSymbol; - - if ($symbol === $this->invalidSymbol) { + do { + $token = $this->tokens[++$this->tokenPos]; + $tokenId = $token->id; + } while (isset($this->dropTokens[$tokenId])); + + // Map the lexer token id to the internally used symbols. + $tokenValue = $token->text; + if (!isset($this->phpTokenToSymbol[$tokenId])) { throw new \RangeException(sprintf( 'The lexer returned an invalid token (id=%d, value=%s)', $tokenId, $tokenValue )); } - - // Allow productions to access the start attributes of the lookahead token. - $this->lookaheadStartAttributes = $startAttributes; + $symbol = $this->phpTokenToSymbol[$tokenId]; //$this->traceRead($symbol); } @@ -245,9 +286,8 @@ protected function doParse() { ++$stackPos; $stateStack[$stackPos] = $state = $action; $this->semStack[$stackPos] = $tokenValue; - $this->startAttributeStack[$stackPos] = $startAttributes; - $this->endAttributeStack[$stackPos] = $endAttributes; - $this->endAttributes = $endAttributes; + $this->tokenStartStack[$stackPos] = $this->tokenPos; + $this->tokenEndStack[$stackPos] = $this->tokenPos; $symbol = self::SYMBOL_NONE; if ($this->errorState) { @@ -273,15 +313,22 @@ protected function doParse() { /* accept */ //$this->traceAccept(); return $this->semValue; - } elseif ($rule !== $this->unexpectedTokenRule) { + } + if ($rule !== $this->unexpectedTokenRule) { /* reduce */ //$this->traceReduce($rule); + $ruleLength = $this->ruleToLength[$rule]; try { - $this->reduceCallbacks[$rule]($stackPos); + $callback = $this->reduceCallbacks[$rule]; + if ($callback !== null) { + $callback($this, $stackPos); + } elseif ($ruleLength > 0) { + $this->semValue = $this->semStack[$stackPos - $ruleLength + 1]; + } } catch (Error $e) { - if (-1 === $e->getStartLine() && isset($startAttributes['startLine'])) { - $e->setStartLine($startAttributes['startLine']); + if (-1 === $e->getStartLine()) { + $e->setStartLine($this->tokens[$this->tokenPos]->line); } $this->emitError($e); @@ -290,8 +337,7 @@ protected function doParse() { } /* Goto - shift nonterminal */ - $lastEndAttributes = $this->endAttributeStack[$stackPos]; - $ruleLength = $this->ruleToLength[$rule]; + $lastTokenEnd = $this->tokenEndStack[$stackPos]; $stackPos -= $ruleLength; $nonTerminal = $this->ruleToNonTerminal[$rule]; $idx = $this->gotoBase[$nonTerminal] + $stateStack[$stackPos]; @@ -304,18 +350,19 @@ protected function doParse() { ++$stackPos; $stateStack[$stackPos] = $state; $this->semStack[$stackPos] = $this->semValue; - $this->endAttributeStack[$stackPos] = $lastEndAttributes; + $this->tokenEndStack[$stackPos] = $lastTokenEnd; if ($ruleLength === 0) { // Empty productions use the start attributes of the lookahead token. - $this->startAttributeStack[$stackPos] = $this->lookaheadStartAttributes; + $this->tokenStartStack[$stackPos] = $this->tokenPos; } } else { /* error */ switch ($this->errorState) { case 0: $msg = $this->getErrorMessage($symbol, $state); - $this->emitError(new Error($msg, $startAttributes + $endAttributes)); + $this->emitError(new Error($msg, $this->getAttributesForToken($this->tokenPos))); // Break missing intentionally + // no break case 1: case 2: $this->errorState = 3; @@ -342,9 +389,8 @@ protected function doParse() { // We treat the error symbol as being empty, so we reset the end attributes // to the end attributes of the last non-error symbol - $this->startAttributeStack[$stackPos] = $this->lookaheadStartAttributes; - $this->endAttributeStack[$stackPos] = $this->endAttributeStack[$stackPos - 1]; - $this->endAttributes = $this->endAttributeStack[$stackPos - 1]; + $this->tokenStartStack[$stackPos] = $this->tokenPos; + $this->tokenEndStack[$stackPos] = $this->tokenEndStack[$stackPos - 1]; break; case 3: @@ -367,11 +413,9 @@ protected function doParse() { $rule = $state - $this->numNonLeafStates; } } - - throw new \RuntimeException('Reached end of parser loop'); } - protected function emitError(Error $error) { + protected function emitError(Error $error): void { $this->errorHandler->handleError($error); } @@ -379,11 +423,11 @@ protected function emitError(Error $error) { * Format error message including expected tokens. * * @param int $symbol Unexpected symbol - * @param int $state State at time of error + * @param int $state State at time of error * * @return string Formatted error message */ - protected function getErrorMessage(int $symbol, int $state) : string { + protected function getErrorMessage(int $symbol, int $state): string { $expectedString = ''; if ($expected = $this->getExpectedTokens($state)) { $expectedString = ', expecting ' . implode(' or ', $expected); @@ -399,7 +443,7 @@ protected function getErrorMessage(int $symbol, int $state) : string { * * @return string[] Expected tokens. If too many, an empty array is returned. */ - protected function getExpectedTokens(int $state) : array { + protected function getExpectedTokens(int $state): array { $expected = []; $base = $this->actionBase[$state]; @@ -427,37 +471,79 @@ protected function getExpectedTokens(int $state) : array { return $expected; } + /** + * Get attributes for a node with the given start and end token positions. + * + * @param int $tokenStartPos Token position the node starts at + * @param int $tokenEndPos Token position the node ends at + * @return array Attributes + */ + protected function getAttributes(int $tokenStartPos, int $tokenEndPos): array { + $startToken = $this->tokens[$tokenStartPos]; + $afterEndToken = $this->tokens[$tokenEndPos + 1]; + return [ + 'startLine' => $startToken->line, + 'startTokenPos' => $tokenStartPos, + 'startFilePos' => $startToken->pos, + 'endLine' => $afterEndToken->line, + 'endTokenPos' => $tokenEndPos, + 'endFilePos' => $afterEndToken->pos - 1, + ]; + } + + /** + * Get attributes for a single token at the given token position. + * + * @return array Attributes + */ + protected function getAttributesForToken(int $tokenPos): array { + if ($tokenPos < \count($this->tokens) - 1) { + return $this->getAttributes($tokenPos, $tokenPos); + } + + // Get attributes for the sentinel token. + $token = $this->tokens[$tokenPos]; + return [ + 'startLine' => $token->line, + 'startTokenPos' => $tokenPos, + 'startFilePos' => $token->pos, + 'endLine' => $token->line, + 'endTokenPos' => $tokenPos, + 'endFilePos' => $token->pos, + ]; + } + /* * Tracing functions used for debugging the parser. */ /* - protected function traceNewState($state, $symbol) { + protected function traceNewState($state, $symbol): void { echo '% State ' . $state . ', Lookahead ' . ($symbol == self::SYMBOL_NONE ? '--none--' : $this->symbolToName[$symbol]) . "\n"; } - protected function traceRead($symbol) { + protected function traceRead($symbol): void { echo '% Reading ' . $this->symbolToName[$symbol] . "\n"; } - protected function traceShift($symbol) { + protected function traceShift($symbol): void { echo '% Shift ' . $this->symbolToName[$symbol] . "\n"; } - protected function traceAccept() { + protected function traceAccept(): void { echo "% Accepted.\n"; } - protected function traceReduce($n) { + protected function traceReduce($n): void { echo '% Reduce by (' . $n . ') ' . $this->productions[$n] . "\n"; } - protected function tracePop($state) { + protected function tracePop($state): void { echo '% Recovering, uncovered state ' . $state . "\n"; } - protected function traceDiscard($symbol) { + protected function traceDiscard($symbol): void { echo '% Discard ' . $this->symbolToName[$symbol] . "\n"; } */ @@ -472,13 +558,14 @@ protected function traceDiscard($symbol) { * @param Node\Stmt[] $stmts * @return Node\Stmt[] */ - protected function handleNamespaces(array $stmts) : array { + protected function handleNamespaces(array $stmts): array { $hasErrored = false; $style = $this->getNamespacingStyle($stmts); if (null === $style) { // not namespaced, nothing to do return $stmts; - } elseif ('brace' === $style) { + } + if ('brace' === $style) { // For braced namespaces we only have to check that there are no invalid statements between the namespaces $afterFirstNamespace = false; foreach ($stmts as $stmt) { @@ -496,7 +583,7 @@ protected function handleNamespaces(array $stmts) : array { } else { // For semicolon namespaces we have to move the statements after a namespace declaration into ->stmts $resultStmts = []; - $targetStmts =& $resultStmts; + $targetStmts = &$resultStmts; $lastNs = null; foreach ($stmts as $stmt) { if ($stmt instanceof Node\Stmt\Namespace_) { @@ -505,12 +592,12 @@ protected function handleNamespaces(array $stmts) : array { } if ($stmt->stmts === null) { $stmt->stmts = []; - $targetStmts =& $stmt->stmts; + $targetStmts = &$stmt->stmts; $resultStmts[] = $stmt; } else { // This handles the invalid case of mixed style namespaces $resultStmts[] = $stmt; - $targetStmts =& $resultStmts; + $targetStmts = &$resultStmts; } $lastNs = $stmt; } elseif ($stmt instanceof Node\Stmt\HaltCompiler) { @@ -527,7 +614,7 @@ protected function handleNamespaces(array $stmts) : array { } } - private function fixupNamespaceAttributes(Node\Stmt\Namespace_ $stmt) { + private function fixupNamespaceAttributes(Node\Stmt\Namespace_ $stmt): void { // We moved the statements into the namespace node, as such the end of the namespace node // needs to be extended to the end of the statements. if (empty($stmt->stmts)) { @@ -545,6 +632,22 @@ private function fixupNamespaceAttributes(Node\Stmt\Namespace_ $stmt) { } } + /** @return array */ + private function getNamespaceErrorAttributes(Namespace_ $node): array { + $attrs = $node->getAttributes(); + // Adjust end attributes to only cover the "namespace" keyword, not the whole namespace. + if (isset($attrs['startLine'])) { + $attrs['endLine'] = $attrs['startLine']; + } + if (isset($attrs['startTokenPos'])) { + $attrs['endTokenPos'] = $attrs['startTokenPos']; + } + if (isset($attrs['startFilePos'])) { + $attrs['endFilePos'] = $attrs['startFilePos'] + \strlen('namespace') - 1; + } + return $attrs; + } + /** * Determine namespacing style (semicolon or brace) * @@ -552,7 +655,7 @@ private function fixupNamespaceAttributes(Node\Stmt\Namespace_ $stmt) { * * @return null|string One of "semicolon", "brace" or null (no namespaces) */ - private function getNamespacingStyle(array $stmts) { + private function getNamespacingStyle(array $stmts): ?string { $style = null; $hasNotAllowedStmts = false; foreach ($stmts as $i => $stmt) { @@ -563,13 +666,13 @@ private function getNamespacingStyle(array $stmts) { if ($hasNotAllowedStmts) { $this->emitError(new Error( 'Namespace declaration statement has to be the very first statement in the script', - $stmt->getLine() // Avoid marking the entire namespace as an error + $this->getNamespaceErrorAttributes($stmt) )); } } elseif ($style !== $currentStyle) { $this->emitError(new Error( 'Cannot mix bracketed namespace declarations with unbracketed namespace declarations', - $stmt->getLine() // Avoid marking the entire namespace as an error + $this->getNamespaceErrorAttributes($stmt) )); // Treat like semicolon style for namespace normalization return 'semicolon'; @@ -595,81 +698,14 @@ private function getNamespacingStyle(array $stmts) { return $style; } - /** - * Fix up parsing of static property calls in PHP 5. - * - * In PHP 5 A::$b[c][d] and A::$b[c][d]() have very different interpretation. The former is - * interpreted as (A::$b)[c][d], while the latter is the same as A::{$b[c][d]}(). We parse the - * latter as the former initially and this method fixes the AST into the correct form when we - * encounter the "()". - * - * @param Node\Expr\StaticPropertyFetch|Node\Expr\ArrayDimFetch $prop - * @param Node\Arg[] $args - * @param array $attributes - * - * @return Expr\StaticCall - */ - protected function fixupPhp5StaticPropCall($prop, array $args, array $attributes) : Expr\StaticCall { - if ($prop instanceof Node\Expr\StaticPropertyFetch) { - $name = $prop->name instanceof VarLikeIdentifier - ? $prop->name->toString() : $prop->name; - $var = new Expr\Variable($name, $prop->name->getAttributes()); - return new Expr\StaticCall($prop->class, $var, $args, $attributes); - } elseif ($prop instanceof Node\Expr\ArrayDimFetch) { - $tmp = $prop; - while ($tmp->var instanceof Node\Expr\ArrayDimFetch) { - $tmp = $tmp->var; - } - - /** @var Expr\StaticPropertyFetch $staticProp */ - $staticProp = $tmp->var; - - // Set start attributes to attributes of innermost node - $tmp = $prop; - $this->fixupStartAttributes($tmp, $staticProp->name); - while ($tmp->var instanceof Node\Expr\ArrayDimFetch) { - $tmp = $tmp->var; - $this->fixupStartAttributes($tmp, $staticProp->name); - } - - $name = $staticProp->name instanceof VarLikeIdentifier - ? $staticProp->name->toString() : $staticProp->name; - $tmp->var = new Expr\Variable($name, $staticProp->name->getAttributes()); - return new Expr\StaticCall($staticProp->class, $prop, $args, $attributes); - } else { - throw new \Exception; - } - } - - protected function fixupStartAttributes(Node $to, Node $from) { - $startAttributes = ['startLine', 'startFilePos', 'startTokenPos']; - foreach ($startAttributes as $startAttribute) { - if ($from->hasAttribute($startAttribute)) { - $to->setAttribute($startAttribute, $from->getAttribute($startAttribute)); - } - } - } - + /** @return Name|Identifier */ protected function handleBuiltinTypes(Name $name) { - $builtinTypes = [ - 'bool' => true, - 'int' => true, - 'float' => true, - 'string' => true, - 'iterable' => true, - 'void' => true, - 'object' => true, - 'null' => true, - 'false' => true, - 'mixed' => true, - ]; - if (!$name->isUnqualified()) { return $name; } $lowerName = $name->toLowerString(); - if (!isset($builtinTypes[$lowerName])) { + if (!$this->phpVersion->supportsBuiltinType($lowerName)) { return $name; } @@ -679,16 +715,15 @@ protected function handleBuiltinTypes(Name $name) { /** * Get combined start and end attributes at a stack location * - * @param int $pos Stack location + * @param int $stackPos Stack location * - * @return array Combined start and end attributes + * @return array Combined start and end attributes */ - protected function getAttributesAt(int $pos) : array { - return $this->startAttributeStack[$pos] + $this->endAttributeStack[$pos]; + protected function getAttributesAt(int $stackPos): array { + return $this->getAttributes($this->tokenStartStack[$stackPos], $this->tokenEndStack[$stackPos]); } - protected function getFloatCastKind(string $cast): int - { + protected function getFloatCastKind(string $cast): int { $cast = strtolower($cast); if (strpos($cast, 'float') !== false) { return Double::KIND_FLOAT; @@ -701,23 +736,51 @@ protected function getFloatCastKind(string $cast): int return Double::KIND_DOUBLE; } - protected function parseLNumber($str, $attributes, $allowInvalidOctal = false) { + protected function getIntCastKind(string $cast): int { + $cast = strtolower($cast); + if (strpos($cast, 'integer') !== false) { + return Expr\Cast\Int_::KIND_INTEGER; + } + + return Expr\Cast\Int_::KIND_INT; + } + + protected function getBoolCastKind(string $cast): int { + $cast = strtolower($cast); + if (strpos($cast, 'boolean') !== false) { + return Expr\Cast\Bool_::KIND_BOOLEAN; + } + + return Expr\Cast\Bool_::KIND_BOOL; + } + + protected function getStringCastKind(string $cast): int { + $cast = strtolower($cast); + if (strpos($cast, 'binary') !== false) { + return Expr\Cast\String_::KIND_BINARY; + } + + return Expr\Cast\String_::KIND_STRING; + } + + /** @param array $attributes */ + protected function parseLNumber(string $str, array $attributes, bool $allowInvalidOctal = false): Int_ { try { - return LNumber::fromString($str, $attributes, $allowInvalidOctal); + return Int_::fromString($str, $attributes, $allowInvalidOctal); } catch (Error $error) { $this->emitError($error); // Use dummy value - return new LNumber(0, $attributes); + return new Int_(0, $attributes); } } /** * Parse a T_NUM_STRING token into either an integer or string node. * - * @param string $str Number string - * @param array $attributes Attributes + * @param string $str Number string + * @param array $attributes Attributes * - * @return LNumber|String_ Integer or string node. + * @return Int_|String_ Integer or string node. */ protected function parseNumString(string $str, array $attributes) { if (!preg_match('/^(?:0|-?[1-9][0-9]*)$/', $str)) { @@ -729,13 +792,14 @@ protected function parseNumString(string $str, array $attributes) { return new String_($str, $attributes); } - return new LNumber($num, $attributes); + return new Int_($num, $attributes); } + /** @param array $attributes */ protected function stripIndentation( string $string, int $indentLen, string $indentChar, bool $newlineAtStart, bool $newlineAtEnd, array $attributes - ) { + ): string { if ($indentLen === 0) { return $string; } @@ -764,10 +828,15 @@ function ($matches) use ($indentLen, $indentChar, $attributes) { ); } + /** + * @param string|(Expr|InterpolatedStringPart)[] $contents + * @param array $attributes + * @param array $endTokenAttributes + */ protected function parseDocString( string $startToken, $contents, string $endToken, array $attributes, array $endTokenAttributes, bool $parseUnicodeEscape - ) { + ): Expr { $kind = strpos($startToken, "'") === false ? String_::KIND_HEREDOC : String_::KIND_NOWDOC; @@ -801,6 +870,7 @@ protected function parseDocString( if (\is_string($contents)) { if ($contents === '') { + $attributes['rawValue'] = $contents; return new String_('', $attributes); } @@ -808,6 +878,7 @@ protected function parseDocString( $contents, $indentLen, $indentChar, true, true, $attributes ); $contents = preg_replace('~(\r\n|\n|\r)\z~', '', $contents); + $attributes['rawValue'] = $contents; if ($kind === String_::KIND_HEREDOC) { $contents = String_::parseEscapeSequences($contents, null, $parseUnicodeEscape); @@ -816,7 +887,7 @@ protected function parseDocString( return new String_($contents, $attributes); } else { assert(count($contents) > 0); - if (!$contents[0] instanceof Node\Scalar\EncapsedStringPart) { + if (!$contents[0] instanceof Node\InterpolatedStringPart) { // If there is no leading encapsed string part, pretend there is an empty one $this->stripIndentation( '', $indentLen, $indentChar, true, false, $contents[0]->getAttributes() @@ -825,65 +896,175 @@ protected function parseDocString( $newContents = []; foreach ($contents as $i => $part) { - if ($part instanceof Node\Scalar\EncapsedStringPart) { + if ($part instanceof Node\InterpolatedStringPart) { $isLast = $i === \count($contents) - 1; $part->value = $this->stripIndentation( $part->value, $indentLen, $indentChar, $i === 0, $isLast, $part->getAttributes() ); - $part->value = String_::parseEscapeSequences($part->value, null, $parseUnicodeEscape); if ($isLast) { $part->value = preg_replace('~(\r\n|\n|\r)\z~', '', $part->value); } + $part->setAttribute('rawValue', $part->value); + $part->value = String_::parseEscapeSequences($part->value, null, $parseUnicodeEscape); if ('' === $part->value) { continue; } } $newContents[] = $part; } - return new Encapsed($newContents, $attributes); + return new InterpolatedString($newContents, $attributes); + } + } + + protected function createCommentFromToken(Token $token, int $tokenPos): Comment { + assert($token->id === \T_COMMENT || $token->id == \T_DOC_COMMENT); + return \T_DOC_COMMENT === $token->id + ? new Comment\Doc($token->text, $token->line, $token->pos, $tokenPos, + $token->getEndLine(), $token->getEndPos() - 1, $tokenPos) + : new Comment($token->text, $token->line, $token->pos, $tokenPos, + $token->getEndLine(), $token->getEndPos() - 1, $tokenPos); + } + + /** + * Get last comment before the given token position, if any + */ + protected function getCommentBeforeToken(int $tokenPos): ?Comment { + while (--$tokenPos >= 0) { + $token = $this->tokens[$tokenPos]; + if (!isset($this->dropTokens[$token->id])) { + break; + } + + if ($token->id === \T_COMMENT || $token->id === \T_DOC_COMMENT) { + return $this->createCommentFromToken($token, $tokenPos); + } } + return null; } /** - * Create attributes for a zero-length common-capturing nop. - * - * @param Comment[] $comments - * @return array + * Create a zero-length nop to capture preceding comments, if any. */ - protected function createCommentNopAttributes(array $comments) { - $comment = $comments[count($comments) - 1]; + protected function maybeCreateZeroLengthNop(int $tokenPos): ?Nop { + $comment = $this->getCommentBeforeToken($tokenPos); + if ($comment === null) { + return null; + } + $commentEndLine = $comment->getEndLine(); $commentEndFilePos = $comment->getEndFilePos(); $commentEndTokenPos = $comment->getEndTokenPos(); + $attributes = [ + 'startLine' => $commentEndLine, + 'endLine' => $commentEndLine, + 'startFilePos' => $commentEndFilePos + 1, + 'endFilePos' => $commentEndFilePos, + 'startTokenPos' => $commentEndTokenPos + 1, + 'endTokenPos' => $commentEndTokenPos, + ]; + return new Nop($attributes); + } + + protected function maybeCreateNop(int $tokenStartPos, int $tokenEndPos): ?Nop { + if ($this->getCommentBeforeToken($tokenStartPos) === null) { + return null; + } + return new Nop($this->getAttributes($tokenStartPos, $tokenEndPos)); + } + + protected function handleHaltCompiler(): string { + // Prevent the lexer from returning any further tokens. + $nextToken = $this->tokens[$this->tokenPos + 1]; + $this->tokenPos = \count($this->tokens) - 2; + + // Return text after __halt_compiler. + return $nextToken->id === \T_INLINE_HTML ? $nextToken->text : ''; + } + + protected function inlineHtmlHasLeadingNewline(int $stackPos): bool { + $tokenPos = $this->tokenStartStack[$stackPos]; + $token = $this->tokens[$tokenPos]; + assert($token->id == \T_INLINE_HTML); + if ($tokenPos > 0) { + $prevToken = $this->tokens[$tokenPos - 1]; + assert($prevToken->id == \T_CLOSE_TAG); + return false !== strpos($prevToken->text, "\n") + || false !== strpos($prevToken->text, "\r"); + } + return true; + } + + /** + * @return array + */ + protected function createEmptyElemAttributes(int $tokenPos): array { + return $this->getAttributesForToken($tokenPos); + } + + protected function fixupArrayDestructuring(Array_ $node): Expr\List_ { + $this->createdArrays->offsetUnset($node); + return new Expr\List_(array_map(function (Node\ArrayItem $item) { + if ($item->value instanceof Expr\Error) { + // We used Error as a placeholder for empty elements, which are legal for destructuring. + return null; + } + if ($item->value instanceof Array_) { + return new Node\ArrayItem( + $this->fixupArrayDestructuring($item->value), + $item->key, $item->byRef, $item->getAttributes()); + } + return $item; + }, $node->items), ['kind' => Expr\List_::KIND_ARRAY] + $node->getAttributes()); + } - $attributes = ['comments' => $comments]; - if (-1 !== $commentEndLine) { - $attributes['startLine'] = $commentEndLine; - $attributes['endLine'] = $commentEndLine; + protected function postprocessList(Expr\List_ $node): void { + foreach ($node->items as $i => $item) { + if ($item->value instanceof Expr\Error) { + // We used Error as a placeholder for empty elements, which are legal for destructuring. + $node->items[$i] = null; + } } - if (-1 !== $commentEndFilePos) { - $attributes['startFilePos'] = $commentEndFilePos + 1; - $attributes['endFilePos'] = $commentEndFilePos; + } + + /** @param ElseIf_|Else_ $node */ + protected function fixupAlternativeElse($node): void { + // Make sure a trailing nop statement carrying comments is part of the node. + $numStmts = \count($node->stmts); + if ($numStmts !== 0 && $node->stmts[$numStmts - 1] instanceof Nop) { + $nopAttrs = $node->stmts[$numStmts - 1]->getAttributes(); + if (isset($nopAttrs['endLine'])) { + $node->setAttribute('endLine', $nopAttrs['endLine']); + } + if (isset($nopAttrs['endFilePos'])) { + $node->setAttribute('endFilePos', $nopAttrs['endFilePos']); + } + if (isset($nopAttrs['endTokenPos'])) { + $node->setAttribute('endTokenPos', $nopAttrs['endTokenPos']); + } } - if (-1 !== $commentEndTokenPos) { - $attributes['startTokenPos'] = $commentEndTokenPos + 1; - $attributes['endTokenPos'] = $commentEndTokenPos; + } + + protected function checkClassModifier(int $a, int $b, int $modifierPos): void { + try { + Modifiers::verifyClassModifier($a, $b); + } catch (Error $error) { + $error->setAttributes($this->getAttributesAt($modifierPos)); + $this->emitError($error); } - return $attributes; } - protected function checkModifier($a, $b, $modifierPos) { + protected function checkModifier(int $a, int $b, int $modifierPos): void { // Jumping through some hoops here because verifyModifier() is also used elsewhere try { - Class_::verifyModifier($a, $b); + Modifiers::verifyModifier($a, $b); } catch (Error $error) { $error->setAttributes($this->getAttributesAt($modifierPos)); $this->emitError($error); } } - protected function checkParam(Param $node) { + protected function checkParam(Param $node): void { if ($node->variadic && null !== $node->default) { $this->emitError(new Error( 'Variadic parameter cannot have a default value', @@ -892,7 +1073,7 @@ protected function checkParam(Param $node) { } } - protected function checkTryCatch(TryCatch $node) { + protected function checkTryCatch(TryCatch $node): void { if (empty($node->catches) && null === $node->finally) { $this->emitError(new Error( 'Cannot use try without catch or finally', $node->getAttributes() @@ -900,7 +1081,7 @@ protected function checkTryCatch(TryCatch $node) { } } - protected function checkNamespace(Namespace_ $node) { + protected function checkNamespace(Namespace_ $node): void { if (null !== $node->stmts) { foreach ($node->stmts as $stmt) { if ($stmt instanceof Namespace_) { @@ -912,22 +1093,18 @@ protected function checkNamespace(Namespace_ $node) { } } - protected function checkClass(Class_ $node, $namePos) { - if (null !== $node->name && $node->name->isSpecialClassName()) { + private function checkClassName(?Identifier $name, int $namePos): void { + if (null !== $name && $name->isSpecialClassName()) { $this->emitError(new Error( - sprintf('Cannot use \'%s\' as class name as it is reserved', $node->name), + sprintf('Cannot use \'%s\' as class name as it is reserved', $name), $this->getAttributesAt($namePos) )); } + } - if ($node->extends && $node->extends->isSpecialClassName()) { - $this->emitError(new Error( - sprintf('Cannot use \'%s\' as class name as it is reserved', $node->extends), - $node->extends->getAttributes() - )); - } - - foreach ($node->implements as $interface) { + /** @param Name[] $interfaces */ + private function checkImplementedInterfaces(array $interfaces): void { + foreach ($interfaces as $interface) { if ($interface->isSpecialClassName()) { $this->emitError(new Error( sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface), @@ -937,26 +1114,31 @@ protected function checkClass(Class_ $node, $namePos) { } } - protected function checkInterface(Interface_ $node, $namePos) { - if (null !== $node->name && $node->name->isSpecialClassName()) { + protected function checkClass(Class_ $node, int $namePos): void { + $this->checkClassName($node->name, $namePos); + + if ($node->extends && $node->extends->isSpecialClassName()) { $this->emitError(new Error( - sprintf('Cannot use \'%s\' as class name as it is reserved', $node->name), - $this->getAttributesAt($namePos) + sprintf('Cannot use \'%s\' as class name as it is reserved', $node->extends), + $node->extends->getAttributes() )); } - foreach ($node->extends as $interface) { - if ($interface->isSpecialClassName()) { - $this->emitError(new Error( - sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface), - $interface->getAttributes() - )); - } - } + $this->checkImplementedInterfaces($node->implements); + } + + protected function checkInterface(Interface_ $node, int $namePos): void { + $this->checkClassName($node->name, $namePos); + $this->checkImplementedInterfaces($node->extends); + } + + protected function checkEnum(Enum_ $node, int $namePos): void { + $this->checkClassName($node->name, $namePos); + $this->checkImplementedInterfaces($node->implements); } - protected function checkClassMethod(ClassMethod $node, $modifierPos) { - if ($node->flags & Class_::MODIFIER_STATIC) { + protected function checkClassMethod(ClassMethod $node, int $modifierPos): void { + if ($node->flags & Modifiers::STATIC) { switch ($node->name->toLowerString()) { case '__construct': $this->emitError(new Error( @@ -975,39 +1157,25 @@ protected function checkClassMethod(ClassMethod $node, $modifierPos) { break; } } - } - protected function checkClassConst(ClassConst $node, $modifierPos) { - if ($node->flags & Class_::MODIFIER_STATIC) { - $this->emitError(new Error( - "Cannot use 'static' as constant modifier", - $this->getAttributesAt($modifierPos))); - } - if ($node->flags & Class_::MODIFIER_ABSTRACT) { + if ($node->flags & Modifiers::READONLY) { $this->emitError(new Error( - "Cannot use 'abstract' as constant modifier", - $this->getAttributesAt($modifierPos))); - } - if ($node->flags & Class_::MODIFIER_FINAL) { - $this->emitError(new Error( - "Cannot use 'final' as constant modifier", + sprintf('Method %s() cannot be readonly', $node->name), $this->getAttributesAt($modifierPos))); } } - protected function checkProperty(Property $node, $modifierPos) { - if ($node->flags & Class_::MODIFIER_ABSTRACT) { - $this->emitError(new Error('Properties cannot be declared abstract', - $this->getAttributesAt($modifierPos))); - } - - if ($node->flags & Class_::MODIFIER_FINAL) { - $this->emitError(new Error('Properties cannot be declared final', - $this->getAttributesAt($modifierPos))); + protected function checkClassConst(ClassConst $node, int $modifierPos): void { + foreach ([Modifiers::STATIC, Modifiers::ABSTRACT, Modifiers::READONLY] as $modifier) { + if ($node->flags & $modifier) { + $this->emitError(new Error( + "Cannot use '" . Modifiers::toString($modifier) . "' as constant modifier", + $this->getAttributesAt($modifierPos))); + } } } - protected function checkUseUse(UseUse $node, $namePos) { + protected function checkUseUse(UseItem $node, int $namePos): void { if ($node->alias && $node->alias->isSpecialClassName()) { $this->emitError(new Error( sprintf( @@ -1018,4 +1186,136 @@ protected function checkUseUse(UseUse $node, $namePos) { )); } } + + protected function checkPropertyHooksForMultiProperty(Property $property, int $hookPos): void { + if (count($property->props) > 1) { + $this->emitError(new Error( + 'Cannot use hooks when declaring multiple properties', $this->getAttributesAt($hookPos))); + } + } + + /** @param PropertyHook[] $hooks */ + protected function checkEmptyPropertyHookList(array $hooks, int $hookPos): void { + if (empty($hooks)) { + $this->emitError(new Error( + 'Property hook list cannot be empty', $this->getAttributesAt($hookPos))); + } + } + + protected function checkPropertyHook(PropertyHook $hook, ?int $paramListPos): void { + $name = $hook->name->toLowerString(); + if ($name !== 'get' && $name !== 'set') { + $this->emitError(new Error( + 'Unknown hook "' . $hook->name . '", expected "get" or "set"', + $hook->name->getAttributes())); + } + if ($name === 'get' && $paramListPos !== null) { + $this->emitError(new Error( + 'get hook must not have a parameter list', $this->getAttributesAt($paramListPos))); + } + } + + protected function checkPropertyHookModifiers(int $a, int $b, int $modifierPos): void { + try { + Modifiers::verifyModifier($a, $b); + } catch (Error $error) { + $error->setAttributes($this->getAttributesAt($modifierPos)); + $this->emitError($error); + } + + if ($b != Modifiers::FINAL) { + $this->emitError(new Error( + 'Cannot use the ' . Modifiers::toString($b) . ' modifier on a property hook', + $this->getAttributesAt($modifierPos))); + } + } + + protected function checkConstantAttributes(Const_ $node): void { + if ($node->attrGroups !== [] && count($node->consts) > 1) { + $this->emitError(new Error( + 'Cannot use attributes on multiple constants at once', $node->getAttributes())); + } + } + + /** + * @param Property|Param $node + */ + protected function addPropertyNameToHooks(Node $node): void { + if ($node instanceof Property) { + $name = $node->props[0]->name->toString(); + } else { + $name = $node->var->name; + } + foreach ($node->hooks as $hook) { + $hook->setAttribute('propertyName', $name); + } + } + + /** @param array $args */ + private function isSimpleExit(array $args): bool { + if (\count($args) === 0) { + return true; + } + if (\count($args) === 1) { + $arg = $args[0]; + return $arg instanceof Arg && $arg->name === null && + $arg->byRef === false && $arg->unpack === false; + } + return false; + } + + /** + * @param array $args + * @param array $attrs + */ + protected function createExitExpr(string $name, int $namePos, array $args, array $attrs): Expr { + if ($this->isSimpleExit($args)) { + // Create Exit node for backwards compatibility. + $attrs['kind'] = strtolower($name) === 'exit' ? Expr\Exit_::KIND_EXIT : Expr\Exit_::KIND_DIE; + return new Expr\Exit_(\count($args) === 1 ? $args[0]->value : null, $attrs); + } + return new Expr\FuncCall(new Name($name, $this->getAttributesAt($namePos)), $args, $attrs); + } + + /** + * Creates the token map. + * + * The token map maps the PHP internal token identifiers + * to the identifiers used by the Parser. Additionally it + * maps T_OPEN_TAG_WITH_ECHO to T_ECHO and T_CLOSE_TAG to ';'. + * + * @return array The token map + */ + protected function createTokenMap(): array { + $tokenMap = []; + + // Single-char tokens use an identity mapping. + for ($i = 0; $i < 256; ++$i) { + $tokenMap[$i] = $i; + } + + foreach ($this->symbolToName as $name) { + if ($name[0] === 'T') { + $tokenMap[\constant($name)] = constant(static::class . '::' . $name); + } + } + + // T_OPEN_TAG_WITH_ECHO with dropped T_OPEN_TAG results in T_ECHO + $tokenMap[\T_OPEN_TAG_WITH_ECHO] = static::T_ECHO; + // T_CLOSE_TAG is equivalent to ';' + $tokenMap[\T_CLOSE_TAG] = ord(';'); + + // We have created a map from PHP token IDs to external symbol IDs. + // Now map them to the internal symbol ID. + $fullTokenMap = []; + foreach ($tokenMap as $phpToken => $extSymbol) { + $intSymbol = $this->tokenToSymbol[$extSymbol]; + if ($intSymbol === $this->invalidSymbol) { + continue; + } + $fullTokenMap[$phpToken] = $intSymbol; + } + + return $fullTokenMap; + } } diff --git a/lib/PhpParser/ParserFactory.php b/lib/PhpParser/ParserFactory.php index f041e7ffe3..3a7586ea29 100644 --- a/lib/PhpParser/ParserFactory.php +++ b/lib/PhpParser/ParserFactory.php @@ -2,43 +2,41 @@ namespace PhpParser; -class ParserFactory -{ - const PREFER_PHP7 = 1; - const PREFER_PHP5 = 2; - const ONLY_PHP7 = 3; - const ONLY_PHP5 = 4; +use PhpParser\Parser\Php7; +use PhpParser\Parser\Php8; +class ParserFactory { /** - * Creates a Parser instance, according to the provided kind. - * - * @param int $kind One of ::PREFER_PHP7, ::PREFER_PHP5, ::ONLY_PHP7 or ::ONLY_PHP5 - * @param Lexer|null $lexer Lexer to use. Defaults to emulative lexer when not specified - * @param array $parserOptions Parser options. See ParserAbstract::__construct() argument - * - * @return Parser The parser instance + * Create a parser targeting the given version on a best-effort basis. The parser will generally + * accept code for the newest supported version, but will try to accommodate code that becomes + * invalid in newer versions or changes in interpretation. */ - public function create(int $kind, Lexer $lexer = null, array $parserOptions = []) : Parser { - if (null === $lexer) { - $lexer = new Lexer\Emulative(); + public function createForVersion(PhpVersion $version): Parser { + if ($version->isHostVersion()) { + $lexer = new Lexer(); + } else { + $lexer = new Lexer\Emulative($version); } - switch ($kind) { - case self::PREFER_PHP7: - return new Parser\Multiple([ - new Parser\Php7($lexer, $parserOptions), new Parser\Php5($lexer, $parserOptions) - ]); - case self::PREFER_PHP5: - return new Parser\Multiple([ - new Parser\Php5($lexer, $parserOptions), new Parser\Php7($lexer, $parserOptions) - ]); - case self::ONLY_PHP7: - return new Parser\Php7($lexer, $parserOptions); - case self::ONLY_PHP5: - return new Parser\Php5($lexer, $parserOptions); - default: - throw new \LogicException( - 'Kind must be one of ::PREFER_PHP7, ::PREFER_PHP5, ::ONLY_PHP7 or ::ONLY_PHP5' - ); + if ($version->id >= 80000) { + return new Php8($lexer, $version); } + return new Php7($lexer, $version); + } + + /** + * Create a parser targeting the newest version supported by this library. Code for older + * versions will be accepted if there have been no relevant backwards-compatibility breaks in + * PHP. + */ + public function createForNewestSupportedVersion(): Parser { + return $this->createForVersion(PhpVersion::getNewestSupported()); + } + + /** + * Create a parser targeting the host PHP version, that is the PHP version we're currently + * running on. This parser will not use any token emulation. + */ + public function createForHostVersion(): Parser { + return $this->createForVersion(PhpVersion::getHostVersion()); } } diff --git a/lib/PhpParser/PhpVersion.php b/lib/PhpParser/PhpVersion.php new file mode 100644 index 0000000000..077d7cdc42 --- /dev/null +++ b/lib/PhpParser/PhpVersion.php @@ -0,0 +1,171 @@ + 50100, + 'callable' => 50400, + 'bool' => 70000, + 'int' => 70000, + 'float' => 70000, + 'string' => 70000, + 'iterable' => 70100, + 'void' => 70100, + 'object' => 70200, + 'null' => 80000, + 'false' => 80000, + 'mixed' => 80000, + 'never' => 80100, + 'true' => 80200, + ]; + + private function __construct(int $id) { + $this->id = $id; + } + + /** + * Create a PhpVersion object from major and minor version components. + */ + public static function fromComponents(int $major, int $minor): self { + return new self($major * 10000 + $minor * 100); + } + + /** + * Get the newest PHP version supported by this library. Support for this version may be partial, + * if it is still under development. + */ + public static function getNewestSupported(): self { + return self::fromComponents(8, 5); + } + + /** + * Get the host PHP version, that is the PHP version we're currently running on. + */ + public static function getHostVersion(): self { + return self::fromComponents(\PHP_MAJOR_VERSION, \PHP_MINOR_VERSION); + } + + /** + * Parse the version from a string like "8.1". + */ + public static function fromString(string $version): self { + if (!preg_match('/^(\d+)\.(\d+)/', $version, $matches)) { + throw new \LogicException("Invalid PHP version \"$version\""); + } + return self::fromComponents((int) $matches[1], (int) $matches[2]); + } + + /** + * Check whether two versions are the same. + */ + public function equals(PhpVersion $other): bool { + return $this->id === $other->id; + } + + /** + * Check whether this version is greater than or equal to the argument. + */ + public function newerOrEqual(PhpVersion $other): bool { + return $this->id >= $other->id; + } + + /** + * Check whether this version is older than the argument. + */ + public function older(PhpVersion $other): bool { + return $this->id < $other->id; + } + + /** + * Check whether this is the host PHP version. + */ + public function isHostVersion(): bool { + return $this->equals(self::getHostVersion()); + } + + /** + * Check whether this PHP version supports the given builtin type. Type name must be lowercase. + */ + public function supportsBuiltinType(string $type): bool { + $minVersion = self::BUILTIN_TYPE_VERSIONS[$type] ?? null; + return $minVersion !== null && $this->id >= $minVersion; + } + + /** + * Whether this version supports [] array literals. + */ + public function supportsShortArraySyntax(): bool { + return $this->id >= 50400; + } + + /** + * Whether this version supports [] for destructuring. + */ + public function supportsShortArrayDestructuring(): bool { + return $this->id >= 70100; + } + + /** + * Whether this version supports flexible heredoc/nowdoc. + */ + public function supportsFlexibleHeredoc(): bool { + return $this->id >= 70300; + } + + /** + * Whether this version supports trailing commas in parameter lists. + */ + public function supportsTrailingCommaInParamList(): bool { + return $this->id >= 80000; + } + + /** + * Whether this version allows "$var =& new Obj". + */ + public function allowsAssignNewByReference(): bool { + return $this->id < 70000; + } + + /** + * Whether this version allows invalid octals like "08". + */ + public function allowsInvalidOctals(): bool { + return $this->id < 70000; + } + + /** + * Whether this version allows DEL (\x7f) to occur in identifiers. + */ + public function allowsDelInIdentifiers(): bool { + return $this->id < 70100; + } + + /** + * Whether this version supports yield in expression context without parentheses. + */ + public function supportsYieldWithoutParentheses(): bool { + return $this->id >= 70000; + } + + /** + * Whether this version supports unicode escape sequences in strings. + */ + public function supportsUnicodeEscapes(): bool { + return $this->id >= 70000; + } + + /* + * Whether this version supports attributes. + */ + public function supportsAttributes(): bool { + return $this->id >= 80000; + } +} diff --git a/lib/PhpParser/PrettyPrinter.php b/lib/PhpParser/PrettyPrinter.php new file mode 100644 index 0000000000..892c686e53 --- /dev/null +++ b/lib/PhpParser/PrettyPrinter.php @@ -0,0 +1,51 @@ +pAttrGroups($node->attrGroups, true) + protected function pParam(Node\Param $node): string { + return $this->pAttrGroups($node->attrGroups, $this->phpVersion->supportsAttributes()) . $this->pModifiers($node->flags) . ($node->type ? $this->p($node->type) . ' ' : '') . ($node->byRef ? '&' : '') . ($node->variadic ? '...' : '') . $this->p($node->var) - . ($node->default ? ' = ' . $this->p($node->default) : ''); + . ($node->default ? ' = ' . $this->p($node->default) : '') + . ($node->hooks ? ' {' . $this->pStmts($node->hooks) . $this->nl . '}' : ''); } - protected function pArg(Node\Arg $node) { + protected function pArg(Node\Arg $node): string { return ($node->name ? $node->name->toString() . ': ' : '') . ($node->byRef ? '&' : '') . ($node->unpack ? '...' : '') . $this->p($node->value); } - protected function pConst(Node\Const_ $node) { + protected function pVariadicPlaceholder(Node\VariadicPlaceholder $node): string { + return '...'; + } + + protected function pConst(Node\Const_ $node): string { return $node->name . ' = ' . $this->p($node->value); } - protected function pNullableType(Node\NullableType $node) { + protected function pNullableType(Node\NullableType $node): string { return '?' . $this->p($node->type); } - protected function pUnionType(Node\UnionType $node) { - return $this->pImplode($node->types, '|'); + protected function pUnionType(Node\UnionType $node): string { + $types = []; + foreach ($node->types as $typeNode) { + if ($typeNode instanceof Node\IntersectionType) { + $types[] = '('. $this->p($typeNode) . ')'; + continue; + } + $types[] = $this->p($typeNode); + } + return implode('|', $types); } - protected function pIdentifier(Node\Identifier $node) { + protected function pIntersectionType(Node\IntersectionType $node): string { + return $this->pImplode($node->types, '&'); + } + + protected function pIdentifier(Node\Identifier $node): string { return $node->name; } - protected function pVarLikeIdentifier(Node\VarLikeIdentifier $node) { + protected function pVarLikeIdentifier(Node\VarLikeIdentifier $node): string { return '$' . $node->name; } - protected function pAttribute(Node\Attribute $node) { + protected function pAttribute(Node\Attribute $node): string { return $this->p($node->name) . ($node->args ? '(' . $this->pCommaSeparated($node->args) . ')' : ''); } - protected function pAttributeGroup(Node\AttributeGroup $node) { + protected function pAttributeGroup(Node\AttributeGroup $node): string { return '#[' . $this->pCommaSeparated($node->attrs) . ']'; } // Names - protected function pName(Name $node) { - return implode('\\', $node->parts); + protected function pName(Name $node): string { + return $node->name; } - protected function pName_FullyQualified(Name\FullyQualified $node) { - return '\\' . implode('\\', $node->parts); + protected function pName_FullyQualified(Name\FullyQualified $node): string { + return '\\' . $node->name; } - protected function pName_Relative(Name\Relative $node) { - return 'namespace\\' . implode('\\', $node->parts); + protected function pName_Relative(Name\Relative $node): string { + return 'namespace\\' . $node->name; } // Magic Constants - protected function pScalar_MagicConst_Class(MagicConst\Class_ $node) { + protected function pScalar_MagicConst_Class(MagicConst\Class_ $node): string { return '__CLASS__'; } - protected function pScalar_MagicConst_Dir(MagicConst\Dir $node) { + protected function pScalar_MagicConst_Dir(MagicConst\Dir $node): string { return '__DIR__'; } - protected function pScalar_MagicConst_File(MagicConst\File $node) { + protected function pScalar_MagicConst_File(MagicConst\File $node): string { return '__FILE__'; } - protected function pScalar_MagicConst_Function(MagicConst\Function_ $node) { + protected function pScalar_MagicConst_Function(MagicConst\Function_ $node): string { return '__FUNCTION__'; } - protected function pScalar_MagicConst_Line(MagicConst\Line $node) { + protected function pScalar_MagicConst_Line(MagicConst\Line $node): string { return '__LINE__'; } - protected function pScalar_MagicConst_Method(MagicConst\Method $node) { + protected function pScalar_MagicConst_Method(MagicConst\Method $node): string { return '__METHOD__'; } - protected function pScalar_MagicConst_Namespace(MagicConst\Namespace_ $node) { + protected function pScalar_MagicConst_Namespace(MagicConst\Namespace_ $node): string { return '__NAMESPACE__'; } - protected function pScalar_MagicConst_Trait(MagicConst\Trait_ $node) { + protected function pScalar_MagicConst_Trait(MagicConst\Trait_ $node): string { return '__TRAIT__'; } + protected function pScalar_MagicConst_Property(MagicConst\Property $node): string { + return '__PROPERTY__'; + } + // Scalars - protected function pScalar_String(Scalar\String_ $node) { + private function indentString(string $str): string { + return str_replace("\n", $this->nl, $str); + } + + protected function pScalar_String(Scalar\String_ $node): string { $kind = $node->getAttribute('kind', Scalar\String_::KIND_SINGLE_QUOTED); switch ($kind) { case Scalar\String_::KIND_NOWDOC: $label = $node->getAttribute('docLabel'); if ($label && !$this->containsEndLabel($node->value, $label)) { + $shouldIdent = $this->phpVersion->supportsFlexibleHeredoc(); + $nl = $shouldIdent ? $this->nl : $this->newline; if ($node->value === '') { - return "<<<'$label'\n$label" . $this->docStringEndToken; + return "<<<'$label'$nl$label{$this->docStringEndToken}"; } - return "<<<'$label'\n$node->value\n$label" - . $this->docStringEndToken; + // Make sure trailing \r is not combined with following \n into CRLF. + if ($node->value[strlen($node->value) - 1] !== "\r") { + $value = $shouldIdent ? $this->indentString($node->value) : $node->value; + return "<<<'$label'$nl$value$nl$label{$this->docStringEndToken}"; + } } /* break missing intentionally */ + // no break case Scalar\String_::KIND_SINGLE_QUOTED: return $this->pSingleQuotedString($node->value); case Scalar\String_::KIND_HEREDOC: $label = $node->getAttribute('docLabel'); - if ($label && !$this->containsEndLabel($node->value, $label)) { - if ($node->value === '') { - return "<<<$label\n$label" . $this->docStringEndToken; + $escaped = $this->escapeString($node->value, null); + if ($label && !$this->containsEndLabel($escaped, $label)) { + $nl = $this->phpVersion->supportsFlexibleHeredoc() ? $this->nl : $this->newline; + if ($escaped === '') { + return "<<<$label$nl$label{$this->docStringEndToken}"; } - $escaped = $this->escapeString($node->value, null); - return "<<<$label\n" . $escaped . "\n$label" - . $this->docStringEndToken; + return "<<<$label$nl$escaped$nl$label{$this->docStringEndToken}"; } - /* break missing intentionally */ + /* break missing intentionally */ + // no break case Scalar\String_::KIND_DOUBLE_QUOTED: return '"' . $this->escapeString($node->value, '"') . '"'; } throw new \Exception('Invalid string kind'); } - protected function pScalar_Encapsed(Scalar\Encapsed $node) { + protected function pScalar_InterpolatedString(Scalar\InterpolatedString $node): string { if ($node->getAttribute('kind') === Scalar\String_::KIND_HEREDOC) { $label = $node->getAttribute('docLabel'); if ($label && !$this->encapsedContainsEndLabel($node->parts, $label)) { + $nl = $this->phpVersion->supportsFlexibleHeredoc() ? $this->nl : $this->newline; if (count($node->parts) === 1 - && $node->parts[0] instanceof Scalar\EncapsedStringPart + && $node->parts[0] instanceof Node\InterpolatedStringPart && $node->parts[0]->value === '' ) { - return "<<<$label\n$label" . $this->docStringEndToken; + return "<<<$label$nl$label{$this->docStringEndToken}"; } - return "<<<$label\n" . $this->pEncapsList($node->parts, null) . "\n$label" - . $this->docStringEndToken; + return "<<<$label$nl" . $this->pEncapsList($node->parts, null) + . "$nl$label{$this->docStringEndToken}"; } } return '"' . $this->pEncapsList($node->parts, '"') . '"'; } - protected function pScalar_LNumber(Scalar\LNumber $node) { - if ($node->value === -\PHP_INT_MAX-1) { + protected function pScalar_Int(Scalar\Int_ $node): string { + if ($node->value === -\PHP_INT_MAX - 1) { // PHP_INT_MIN cannot be represented as a literal, // because the sign is not part of the literal return '(-' . \PHP_INT_MAX . '-1)'; } - $kind = $node->getAttribute('kind', Scalar\LNumber::KIND_DEC); - if (Scalar\LNumber::KIND_DEC === $kind) { + $kind = $node->getAttribute('kind', Scalar\Int_::KIND_DEC); + if (Scalar\Int_::KIND_DEC === $kind) { return (string) $node->value; } @@ -184,22 +216,23 @@ protected function pScalar_LNumber(Scalar\LNumber $node) { $str = (string) $node->value; } switch ($kind) { - case Scalar\LNumber::KIND_BIN: + case Scalar\Int_::KIND_BIN: return $sign . '0b' . base_convert($str, 10, 2); - case Scalar\LNumber::KIND_OCT: + case Scalar\Int_::KIND_OCT: return $sign . '0' . base_convert($str, 10, 8); - case Scalar\LNumber::KIND_HEX: + case Scalar\Int_::KIND_HEX: return $sign . '0x' . base_convert($str, 10, 16); } throw new \Exception('Invalid number kind'); } - protected function pScalar_DNumber(Scalar\DNumber $node) { + protected function pScalar_Float(Scalar\Float_ $node): string { if (!is_finite($node->value)) { if ($node->value === \INF) { - return '\INF'; - } elseif ($node->value === -\INF) { - return '-\INF'; + return '1.0E+1000'; + } + if ($node->value === -\INF) { + return '-1.0E+1000'; } else { return '\NAN'; } @@ -207,7 +240,7 @@ protected function pScalar_DNumber(Scalar\DNumber $node) { // Try to find a short full-precision representation $stringValue = sprintf('%.16G', $node->value); - if ($node->value !== (double) $stringValue) { + if ($node->value !== (float) $stringValue) { $stringValue = sprintf('%.17G', $node->value); } @@ -220,300 +253,297 @@ protected function pScalar_DNumber(Scalar\DNumber $node) { return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue . '.0' : $stringValue; } - protected function pScalar_EncapsedStringPart(Scalar\EncapsedStringPart $node) { - throw new \LogicException('Cannot directly print EncapsedStringPart'); - } - // Assignments - protected function pExpr_Assign(Expr\Assign $node) { - return $this->pInfixOp(Expr\Assign::class, $node->var, ' = ', $node->expr); + protected function pExpr_Assign(Expr\Assign $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Expr\Assign::class, $this->p($node->var) . ' = ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_AssignRef(Expr\AssignRef $node) { - return $this->pInfixOp(Expr\AssignRef::class, $node->var, ' =& ', $node->expr); + protected function pExpr_AssignRef(Expr\AssignRef $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Expr\AssignRef::class, $this->p($node->var) . ' =& ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_AssignOp_Plus(AssignOp\Plus $node) { - return $this->pInfixOp(AssignOp\Plus::class, $node->var, ' += ', $node->expr); + protected function pExpr_AssignOp_Plus(AssignOp\Plus $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(AssignOp\Plus::class, $this->p($node->var) . ' += ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_AssignOp_Minus(AssignOp\Minus $node) { - return $this->pInfixOp(AssignOp\Minus::class, $node->var, ' -= ', $node->expr); + protected function pExpr_AssignOp_Minus(AssignOp\Minus $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(AssignOp\Minus::class, $this->p($node->var) . ' -= ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_AssignOp_Mul(AssignOp\Mul $node) { - return $this->pInfixOp(AssignOp\Mul::class, $node->var, ' *= ', $node->expr); + protected function pExpr_AssignOp_Mul(AssignOp\Mul $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(AssignOp\Mul::class, $this->p($node->var) . ' *= ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_AssignOp_Div(AssignOp\Div $node) { - return $this->pInfixOp(AssignOp\Div::class, $node->var, ' /= ', $node->expr); + protected function pExpr_AssignOp_Div(AssignOp\Div $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(AssignOp\Div::class, $this->p($node->var) . ' /= ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_AssignOp_Concat(AssignOp\Concat $node) { - return $this->pInfixOp(AssignOp\Concat::class, $node->var, ' .= ', $node->expr); + protected function pExpr_AssignOp_Concat(AssignOp\Concat $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(AssignOp\Concat::class, $this->p($node->var) . ' .= ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_AssignOp_Mod(AssignOp\Mod $node) { - return $this->pInfixOp(AssignOp\Mod::class, $node->var, ' %= ', $node->expr); + protected function pExpr_AssignOp_Mod(AssignOp\Mod $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(AssignOp\Mod::class, $this->p($node->var) . ' %= ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_AssignOp_BitwiseAnd(AssignOp\BitwiseAnd $node) { - return $this->pInfixOp(AssignOp\BitwiseAnd::class, $node->var, ' &= ', $node->expr); + protected function pExpr_AssignOp_BitwiseAnd(AssignOp\BitwiseAnd $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(AssignOp\BitwiseAnd::class, $this->p($node->var) . ' &= ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_AssignOp_BitwiseOr(AssignOp\BitwiseOr $node) { - return $this->pInfixOp(AssignOp\BitwiseOr::class, $node->var, ' |= ', $node->expr); + protected function pExpr_AssignOp_BitwiseOr(AssignOp\BitwiseOr $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(AssignOp\BitwiseOr::class, $this->p($node->var) . ' |= ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_AssignOp_BitwiseXor(AssignOp\BitwiseXor $node) { - return $this->pInfixOp(AssignOp\BitwiseXor::class, $node->var, ' ^= ', $node->expr); + protected function pExpr_AssignOp_BitwiseXor(AssignOp\BitwiseXor $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(AssignOp\BitwiseXor::class, $this->p($node->var) . ' ^= ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_AssignOp_ShiftLeft(AssignOp\ShiftLeft $node) { - return $this->pInfixOp(AssignOp\ShiftLeft::class, $node->var, ' <<= ', $node->expr); + protected function pExpr_AssignOp_ShiftLeft(AssignOp\ShiftLeft $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(AssignOp\ShiftLeft::class, $this->p($node->var) . ' <<= ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_AssignOp_ShiftRight(AssignOp\ShiftRight $node) { - return $this->pInfixOp(AssignOp\ShiftRight::class, $node->var, ' >>= ', $node->expr); + protected function pExpr_AssignOp_ShiftRight(AssignOp\ShiftRight $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(AssignOp\ShiftRight::class, $this->p($node->var) . ' >>= ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_AssignOp_Pow(AssignOp\Pow $node) { - return $this->pInfixOp(AssignOp\Pow::class, $node->var, ' **= ', $node->expr); + protected function pExpr_AssignOp_Pow(AssignOp\Pow $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(AssignOp\Pow::class, $this->p($node->var) . ' **= ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_AssignOp_Coalesce(AssignOp\Coalesce $node) { - return $this->pInfixOp(AssignOp\Coalesce::class, $node->var, ' ??= ', $node->expr); + protected function pExpr_AssignOp_Coalesce(AssignOp\Coalesce $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(AssignOp\Coalesce::class, $this->p($node->var) . ' ??= ', $node->expr, $precedence, $lhsPrecedence); } // Binary expressions - protected function pExpr_BinaryOp_Plus(BinaryOp\Plus $node) { - return $this->pInfixOp(BinaryOp\Plus::class, $node->left, ' + ', $node->right); + protected function pExpr_BinaryOp_Plus(BinaryOp\Plus $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\Plus::class, $node->left, ' + ', $node->right, $precedence, $lhsPrecedence); + } + + protected function pExpr_BinaryOp_Minus(BinaryOp\Minus $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\Minus::class, $node->left, ' - ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_Minus(BinaryOp\Minus $node) { - return $this->pInfixOp(BinaryOp\Minus::class, $node->left, ' - ', $node->right); + protected function pExpr_BinaryOp_Mul(BinaryOp\Mul $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\Mul::class, $node->left, ' * ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_Mul(BinaryOp\Mul $node) { - return $this->pInfixOp(BinaryOp\Mul::class, $node->left, ' * ', $node->right); + protected function pExpr_BinaryOp_Div(BinaryOp\Div $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\Div::class, $node->left, ' / ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_Div(BinaryOp\Div $node) { - return $this->pInfixOp(BinaryOp\Div::class, $node->left, ' / ', $node->right); + protected function pExpr_BinaryOp_Concat(BinaryOp\Concat $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\Concat::class, $node->left, ' . ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_Concat(BinaryOp\Concat $node) { - return $this->pInfixOp(BinaryOp\Concat::class, $node->left, ' . ', $node->right); + protected function pExpr_BinaryOp_Mod(BinaryOp\Mod $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\Mod::class, $node->left, ' % ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_Mod(BinaryOp\Mod $node) { - return $this->pInfixOp(BinaryOp\Mod::class, $node->left, ' % ', $node->right); + protected function pExpr_BinaryOp_BooleanAnd(BinaryOp\BooleanAnd $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\BooleanAnd::class, $node->left, ' && ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_BooleanAnd(BinaryOp\BooleanAnd $node) { - return $this->pInfixOp(BinaryOp\BooleanAnd::class, $node->left, ' && ', $node->right); + protected function pExpr_BinaryOp_BooleanOr(BinaryOp\BooleanOr $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\BooleanOr::class, $node->left, ' || ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_BooleanOr(BinaryOp\BooleanOr $node) { - return $this->pInfixOp(BinaryOp\BooleanOr::class, $node->left, ' || ', $node->right); + protected function pExpr_BinaryOp_BitwiseAnd(BinaryOp\BitwiseAnd $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\BitwiseAnd::class, $node->left, ' & ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_BitwiseAnd(BinaryOp\BitwiseAnd $node) { - return $this->pInfixOp(BinaryOp\BitwiseAnd::class, $node->left, ' & ', $node->right); + protected function pExpr_BinaryOp_BitwiseOr(BinaryOp\BitwiseOr $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\BitwiseOr::class, $node->left, ' | ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_BitwiseOr(BinaryOp\BitwiseOr $node) { - return $this->pInfixOp(BinaryOp\BitwiseOr::class, $node->left, ' | ', $node->right); + protected function pExpr_BinaryOp_BitwiseXor(BinaryOp\BitwiseXor $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\BitwiseXor::class, $node->left, ' ^ ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_BitwiseXor(BinaryOp\BitwiseXor $node) { - return $this->pInfixOp(BinaryOp\BitwiseXor::class, $node->left, ' ^ ', $node->right); + protected function pExpr_BinaryOp_ShiftLeft(BinaryOp\ShiftLeft $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\ShiftLeft::class, $node->left, ' << ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_ShiftLeft(BinaryOp\ShiftLeft $node) { - return $this->pInfixOp(BinaryOp\ShiftLeft::class, $node->left, ' << ', $node->right); + protected function pExpr_BinaryOp_ShiftRight(BinaryOp\ShiftRight $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\ShiftRight::class, $node->left, ' >> ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_ShiftRight(BinaryOp\ShiftRight $node) { - return $this->pInfixOp(BinaryOp\ShiftRight::class, $node->left, ' >> ', $node->right); + protected function pExpr_BinaryOp_Pow(BinaryOp\Pow $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\Pow::class, $node->left, ' ** ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_Pow(BinaryOp\Pow $node) { - return $this->pInfixOp(BinaryOp\Pow::class, $node->left, ' ** ', $node->right); + protected function pExpr_BinaryOp_LogicalAnd(BinaryOp\LogicalAnd $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\LogicalAnd::class, $node->left, ' and ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_LogicalAnd(BinaryOp\LogicalAnd $node) { - return $this->pInfixOp(BinaryOp\LogicalAnd::class, $node->left, ' and ', $node->right); + protected function pExpr_BinaryOp_LogicalOr(BinaryOp\LogicalOr $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\LogicalOr::class, $node->left, ' or ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_LogicalOr(BinaryOp\LogicalOr $node) { - return $this->pInfixOp(BinaryOp\LogicalOr::class, $node->left, ' or ', $node->right); + protected function pExpr_BinaryOp_LogicalXor(BinaryOp\LogicalXor $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\LogicalXor::class, $node->left, ' xor ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_LogicalXor(BinaryOp\LogicalXor $node) { - return $this->pInfixOp(BinaryOp\LogicalXor::class, $node->left, ' xor ', $node->right); + protected function pExpr_BinaryOp_Equal(BinaryOp\Equal $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\Equal::class, $node->left, ' == ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_Equal(BinaryOp\Equal $node) { - return $this->pInfixOp(BinaryOp\Equal::class, $node->left, ' == ', $node->right); + protected function pExpr_BinaryOp_NotEqual(BinaryOp\NotEqual $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\NotEqual::class, $node->left, ' != ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_NotEqual(BinaryOp\NotEqual $node) { - return $this->pInfixOp(BinaryOp\NotEqual::class, $node->left, ' != ', $node->right); + protected function pExpr_BinaryOp_Identical(BinaryOp\Identical $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\Identical::class, $node->left, ' === ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_Identical(BinaryOp\Identical $node) { - return $this->pInfixOp(BinaryOp\Identical::class, $node->left, ' === ', $node->right); + protected function pExpr_BinaryOp_NotIdentical(BinaryOp\NotIdentical $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\NotIdentical::class, $node->left, ' !== ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_NotIdentical(BinaryOp\NotIdentical $node) { - return $this->pInfixOp(BinaryOp\NotIdentical::class, $node->left, ' !== ', $node->right); + protected function pExpr_BinaryOp_Spaceship(BinaryOp\Spaceship $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\Spaceship::class, $node->left, ' <=> ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_Spaceship(BinaryOp\Spaceship $node) { - return $this->pInfixOp(BinaryOp\Spaceship::class, $node->left, ' <=> ', $node->right); + protected function pExpr_BinaryOp_Greater(BinaryOp\Greater $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\Greater::class, $node->left, ' > ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_Greater(BinaryOp\Greater $node) { - return $this->pInfixOp(BinaryOp\Greater::class, $node->left, ' > ', $node->right); + protected function pExpr_BinaryOp_GreaterOrEqual(BinaryOp\GreaterOrEqual $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\GreaterOrEqual::class, $node->left, ' >= ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_GreaterOrEqual(BinaryOp\GreaterOrEqual $node) { - return $this->pInfixOp(BinaryOp\GreaterOrEqual::class, $node->left, ' >= ', $node->right); + protected function pExpr_BinaryOp_Smaller(BinaryOp\Smaller $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\Smaller::class, $node->left, ' < ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_Smaller(BinaryOp\Smaller $node) { - return $this->pInfixOp(BinaryOp\Smaller::class, $node->left, ' < ', $node->right); + protected function pExpr_BinaryOp_SmallerOrEqual(BinaryOp\SmallerOrEqual $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\SmallerOrEqual::class, $node->left, ' <= ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_SmallerOrEqual(BinaryOp\SmallerOrEqual $node) { - return $this->pInfixOp(BinaryOp\SmallerOrEqual::class, $node->left, ' <= ', $node->right); + protected function pExpr_BinaryOp_Coalesce(BinaryOp\Coalesce $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\Coalesce::class, $node->left, ' ?? ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_BinaryOp_Coalesce(BinaryOp\Coalesce $node) { - return $this->pInfixOp(BinaryOp\Coalesce::class, $node->left, ' ?? ', $node->right); + protected function pExpr_BinaryOp_Pipe(BinaryOp\Pipe $node, int $precedence, int $lhsPrecedence): string { + return $this->pInfixOp(BinaryOp\Pipe::class, $node->left, ' |> ', $node->right, $precedence, $lhsPrecedence); } - protected function pExpr_Instanceof(Expr\Instanceof_ $node) { - list($precedence, $associativity) = $this->precedenceMap[Expr\Instanceof_::class]; - return $this->pPrec($node->expr, $precedence, $associativity, -1) - . ' instanceof ' - . $this->pNewVariable($node->class); + protected function pExpr_Instanceof(Expr\Instanceof_ $node, int $precedence, int $lhsPrecedence): string { + return $this->pPostfixOp( + Expr\Instanceof_::class, $node->expr, + ' instanceof ' . $this->pNewOperand($node->class), + $precedence, $lhsPrecedence); } // Unary expressions - protected function pExpr_BooleanNot(Expr\BooleanNot $node) { - return $this->pPrefixOp(Expr\BooleanNot::class, '!', $node->expr); + protected function pExpr_BooleanNot(Expr\BooleanNot $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Expr\BooleanNot::class, '!', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_BitwiseNot(Expr\BitwiseNot $node) { - return $this->pPrefixOp(Expr\BitwiseNot::class, '~', $node->expr); + protected function pExpr_BitwiseNot(Expr\BitwiseNot $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Expr\BitwiseNot::class, '~', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_UnaryMinus(Expr\UnaryMinus $node) { - if ($node->expr instanceof Expr\UnaryMinus || $node->expr instanceof Expr\PreDec) { - // Enforce -(-$expr) instead of --$expr - return '-(' . $this->p($node->expr) . ')'; - } - return $this->pPrefixOp(Expr\UnaryMinus::class, '-', $node->expr); + protected function pExpr_UnaryMinus(Expr\UnaryMinus $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Expr\UnaryMinus::class, '-', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_UnaryPlus(Expr\UnaryPlus $node) { - if ($node->expr instanceof Expr\UnaryPlus || $node->expr instanceof Expr\PreInc) { - // Enforce +(+$expr) instead of ++$expr - return '+(' . $this->p($node->expr) . ')'; - } - return $this->pPrefixOp(Expr\UnaryPlus::class, '+', $node->expr); + protected function pExpr_UnaryPlus(Expr\UnaryPlus $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Expr\UnaryPlus::class, '+', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_PreInc(Expr\PreInc $node) { - return $this->pPrefixOp(Expr\PreInc::class, '++', $node->var); + protected function pExpr_PreInc(Expr\PreInc $node): string { + return '++' . $this->p($node->var); } - protected function pExpr_PreDec(Expr\PreDec $node) { - return $this->pPrefixOp(Expr\PreDec::class, '--', $node->var); + protected function pExpr_PreDec(Expr\PreDec $node): string { + return '--' . $this->p($node->var); } - protected function pExpr_PostInc(Expr\PostInc $node) { - return $this->pPostfixOp(Expr\PostInc::class, $node->var, '++'); + protected function pExpr_PostInc(Expr\PostInc $node): string { + return $this->p($node->var) . '++'; } - protected function pExpr_PostDec(Expr\PostDec $node) { - return $this->pPostfixOp(Expr\PostDec::class, $node->var, '--'); + protected function pExpr_PostDec(Expr\PostDec $node): string { + return $this->p($node->var) . '--'; } - protected function pExpr_ErrorSuppress(Expr\ErrorSuppress $node) { - return $this->pPrefixOp(Expr\ErrorSuppress::class, '@', $node->expr); + protected function pExpr_ErrorSuppress(Expr\ErrorSuppress $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Expr\ErrorSuppress::class, '@', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_YieldFrom(Expr\YieldFrom $node) { - return $this->pPrefixOp(Expr\YieldFrom::class, 'yield from ', $node->expr); + protected function pExpr_YieldFrom(Expr\YieldFrom $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Expr\YieldFrom::class, 'yield from ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_Print(Expr\Print_ $node) { - return $this->pPrefixOp(Expr\Print_::class, 'print ', $node->expr); + protected function pExpr_Print(Expr\Print_ $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Expr\Print_::class, 'print ', $node->expr, $precedence, $lhsPrecedence); } // Casts - protected function pExpr_Cast_Int(Cast\Int_ $node) { - return $this->pPrefixOp(Cast\Int_::class, '(int) ', $node->expr); + protected function pExpr_Cast_Int(Cast\Int_ $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Cast\Int_::class, '(int) ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_Cast_Double(Cast\Double $node) { + protected function pExpr_Cast_Double(Cast\Double $node, int $precedence, int $lhsPrecedence): string { $kind = $node->getAttribute('kind', Cast\Double::KIND_DOUBLE); if ($kind === Cast\Double::KIND_DOUBLE) { $cast = '(double)'; } elseif ($kind === Cast\Double::KIND_FLOAT) { $cast = '(float)'; - } elseif ($kind === Cast\Double::KIND_REAL) { + } else { + assert($kind === Cast\Double::KIND_REAL); $cast = '(real)'; } - return $this->pPrefixOp(Cast\Double::class, $cast . ' ', $node->expr); + return $this->pPrefixOp(Cast\Double::class, $cast . ' ', $node->expr, $precedence, $lhsPrecedence); + } + + protected function pExpr_Cast_String(Cast\String_ $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Cast\String_::class, '(string) ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_Cast_String(Cast\String_ $node) { - return $this->pPrefixOp(Cast\String_::class, '(string) ', $node->expr); + protected function pExpr_Cast_Array(Cast\Array_ $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Cast\Array_::class, '(array) ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_Cast_Array(Cast\Array_ $node) { - return $this->pPrefixOp(Cast\Array_::class, '(array) ', $node->expr); + protected function pExpr_Cast_Object(Cast\Object_ $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Cast\Object_::class, '(object) ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_Cast_Object(Cast\Object_ $node) { - return $this->pPrefixOp(Cast\Object_::class, '(object) ', $node->expr); + protected function pExpr_Cast_Bool(Cast\Bool_ $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Cast\Bool_::class, '(bool) ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_Cast_Bool(Cast\Bool_ $node) { - return $this->pPrefixOp(Cast\Bool_::class, '(bool) ', $node->expr); + protected function pExpr_Cast_Unset(Cast\Unset_ $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Cast\Unset_::class, '(unset) ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_Cast_Unset(Cast\Unset_ $node) { - return $this->pPrefixOp(Cast\Unset_::class, '(unset) ', $node->expr); + protected function pExpr_Cast_Void(Cast\Void_ $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Cast\Void_::class, '(void) ', $node->expr, $precedence, $lhsPrecedence); } // Function calls and similar constructs - protected function pExpr_FuncCall(Expr\FuncCall $node) { + protected function pExpr_FuncCall(Expr\FuncCall $node): string { return $this->pCallLhs($node->name) . '(' . $this->pMaybeMultiline($node->args) . ')'; } - protected function pExpr_MethodCall(Expr\MethodCall $node) { + protected function pExpr_MethodCall(Expr\MethodCall $node): string { return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name) . '(' . $this->pMaybeMultiline($node->args) . ')'; } - protected function pExpr_NullsafeMethodCall(Expr\NullsafeMethodCall $node) { + protected function pExpr_NullsafeMethodCall(Expr\NullsafeMethodCall $node): string { return $this->pDereferenceLhs($node->var) . '?->' . $this->pObjectProperty($node->name) . '(' . $this->pMaybeMultiline($node->args) . ')'; } - protected function pExpr_StaticCall(Expr\StaticCall $node) { - return $this->pDereferenceLhs($node->class) . '::' + protected function pExpr_StaticCall(Expr\StaticCall $node): string { + return $this->pStaticDereferenceLhs($node->class) . '::' . ($node->name instanceof Expr ? ($node->name instanceof Expr\Variable ? $this->p($node->name) @@ -522,19 +552,19 @@ protected function pExpr_StaticCall(Expr\StaticCall $node) { . '(' . $this->pMaybeMultiline($node->args) . ')'; } - protected function pExpr_Empty(Expr\Empty_ $node) { + protected function pExpr_Empty(Expr\Empty_ $node): string { return 'empty(' . $this->p($node->expr) . ')'; } - protected function pExpr_Isset(Expr\Isset_ $node) { + protected function pExpr_Isset(Expr\Isset_ $node): string { return 'isset(' . $this->pCommaSeparated($node->vars) . ')'; } - protected function pExpr_Eval(Expr\Eval_ $node) { + protected function pExpr_Eval(Expr\Eval_ $node): string { return 'eval(' . $this->p($node->expr) . ')'; } - protected function pExpr_Include(Expr\Include_ $node) { + protected function pExpr_Include(Expr\Include_ $node, int $precedence, int $lhsPrecedence): string { static $map = [ Expr\Include_::TYPE_INCLUDE => 'include', Expr\Include_::TYPE_INCLUDE_ONCE => 'include_once', @@ -542,20 +572,26 @@ protected function pExpr_Include(Expr\Include_ $node) { Expr\Include_::TYPE_REQUIRE_ONCE => 'require_once', ]; - return $map[$node->type] . ' ' . $this->p($node->expr); + return $this->pPrefixOp(Expr\Include_::class, $map[$node->type] . ' ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_List(Expr\List_ $node) { - return 'list(' . $this->pCommaSeparated($node->items) . ')'; + protected function pExpr_List(Expr\List_ $node): string { + $syntax = $node->getAttribute('kind', + $this->phpVersion->supportsShortArrayDestructuring() ? Expr\List_::KIND_ARRAY : Expr\List_::KIND_LIST); + if ($syntax === Expr\List_::KIND_ARRAY) { + return '[' . $this->pMaybeMultiline($node->items, true) . ']'; + } else { + return 'list(' . $this->pMaybeMultiline($node->items, true) . ')'; + } } // Other - protected function pExpr_Error(Expr\Error $node) { + protected function pExpr_Error(Expr\Error $node): string { throw new \LogicException('Cannot pretty-print AST with Error nodes'); } - protected function pExpr_Variable(Expr\Variable $node) { + protected function pExpr_Variable(Expr\Variable $node): string { if ($node->name instanceof Expr) { return '${' . $this->p($node->name) . '}'; } else { @@ -563,9 +599,9 @@ protected function pExpr_Variable(Expr\Variable $node) { } } - protected function pExpr_Array(Expr\Array_ $node) { + protected function pExpr_Array(Expr\Array_ $node): string { $syntax = $node->getAttribute('kind', - $this->options['shortArraySyntax'] ? Expr\Array_::KIND_SHORT : Expr\Array_::KIND_LONG); + $this->shortArraySyntax ? Expr\Array_::KIND_SHORT : Expr\Array_::KIND_LONG); if ($syntax === Expr\Array_::KIND_SHORT) { return '[' . $this->pMaybeMultiline($node->items, true) . ']'; } else { @@ -573,124 +609,152 @@ protected function pExpr_Array(Expr\Array_ $node) { } } - protected function pExpr_ArrayItem(Expr\ArrayItem $node) { - return (null !== $node->key ? $this->p($node->key) . ' => ' : '') + protected function pKey(?Node $node): string { + if ($node === null) { + return ''; + } + + // => is not really an operator and does not typically participate in precedence resolution. + // However, there is an exception if yield expressions with keys are involved: + // [yield $a => $b] is interpreted as [(yield $a => $b)], so we need to ensure that + // [(yield $a) => $b] is printed with parentheses. We approximate this by lowering the LHS + // precedence to that of yield (which will also print unnecessary parentheses for rare low + // precedence unary operators like include). + $yieldPrecedence = $this->precedenceMap[Expr\Yield_::class][0]; + return $this->p($node, self::MAX_PRECEDENCE, $yieldPrecedence) . ' => '; + } + + protected function pArrayItem(Node\ArrayItem $node): string { + return $this->pKey($node->key) . ($node->byRef ? '&' : '') . ($node->unpack ? '...' : '') . $this->p($node->value); } - protected function pExpr_ArrayDimFetch(Expr\ArrayDimFetch $node) { + protected function pExpr_ArrayDimFetch(Expr\ArrayDimFetch $node): string { return $this->pDereferenceLhs($node->var) . '[' . (null !== $node->dim ? $this->p($node->dim) : '') . ']'; } - protected function pExpr_ConstFetch(Expr\ConstFetch $node) { + protected function pExpr_ConstFetch(Expr\ConstFetch $node): string { return $this->p($node->name); } - protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node) { - return $this->pDereferenceLhs($node->class) . '::' . $this->p($node->name); + protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node): string { + return $this->pStaticDereferenceLhs($node->class) . '::' . $this->pObjectProperty($node->name); } - protected function pExpr_PropertyFetch(Expr\PropertyFetch $node) { + protected function pExpr_PropertyFetch(Expr\PropertyFetch $node): string { return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name); } - protected function pExpr_NullsafePropertyFetch(Expr\NullsafePropertyFetch $node) { + protected function pExpr_NullsafePropertyFetch(Expr\NullsafePropertyFetch $node): string { return $this->pDereferenceLhs($node->var) . '?->' . $this->pObjectProperty($node->name); } - protected function pExpr_StaticPropertyFetch(Expr\StaticPropertyFetch $node) { - return $this->pDereferenceLhs($node->class) . '::$' . $this->pObjectProperty($node->name); + protected function pExpr_StaticPropertyFetch(Expr\StaticPropertyFetch $node): string { + return $this->pStaticDereferenceLhs($node->class) . '::$' . $this->pObjectProperty($node->name); } - protected function pExpr_ShellExec(Expr\ShellExec $node) { + protected function pExpr_ShellExec(Expr\ShellExec $node): string { return '`' . $this->pEncapsList($node->parts, '`') . '`'; } - protected function pExpr_Closure(Expr\Closure $node) { + protected function pExpr_Closure(Expr\Closure $node): string { return $this->pAttrGroups($node->attrGroups, true) - . ($node->static ? 'static ' : '') + . $this->pStatic($node->static) . 'function ' . ($node->byRef ? '&' : '') - . '(' . $this->pCommaSeparated($node->params) . ')' - . (!empty($node->uses) ? ' use(' . $this->pCommaSeparated($node->uses) . ')' : '') - . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '') + . '(' . $this->pParams($node->params) . ')' + . (!empty($node->uses) ? ' use (' . $this->pCommaSeparated($node->uses) . ')' : '') + . (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '') . ' {' . $this->pStmts($node->stmts) . $this->nl . '}'; } - protected function pExpr_Match(Expr\Match_ $node) { + protected function pExpr_Match(Expr\Match_ $node): string { return 'match (' . $this->p($node->cond) . ') {' . $this->pCommaSeparatedMultiline($node->arms, true) . $this->nl . '}'; } - protected function pMatchArm(Node\MatchArm $node) { - return ($node->conds ? $this->pCommaSeparated($node->conds) : 'default') - . ' => ' . $this->p($node->body); + protected function pMatchArm(Node\MatchArm $node): string { + $result = ''; + if ($node->conds) { + for ($i = 0, $c = \count($node->conds); $i + 1 < $c; $i++) { + $result .= $this->p($node->conds[$i]) . ', '; + } + $result .= $this->pKey($node->conds[$i]); + } else { + $result = 'default => '; + } + return $result . $this->p($node->body); } - protected function pExpr_ArrowFunction(Expr\ArrowFunction $node) { - return $this->pAttrGroups($node->attrGroups, true) - . ($node->static ? 'static ' : '') + protected function pExpr_ArrowFunction(Expr\ArrowFunction $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp( + Expr\ArrowFunction::class, + $this->pAttrGroups($node->attrGroups, true) + . $this->pStatic($node->static) . 'fn' . ($node->byRef ? '&' : '') - . '(' . $this->pCommaSeparated($node->params) . ')' + . '(' . $this->pParams($node->params) . ')' . (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '') - . ' => ' - . $this->p($node->expr); + . ' => ', + $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_ClosureUse(Expr\ClosureUse $node) { + protected function pClosureUse(Node\ClosureUse $node): string { return ($node->byRef ? '&' : '') . $this->p($node->var); } - protected function pExpr_New(Expr\New_ $node) { + protected function pExpr_New(Expr\New_ $node): string { if ($node->class instanceof Stmt\Class_) { $args = $node->args ? '(' . $this->pMaybeMultiline($node->args) . ')' : ''; return 'new ' . $this->pClassCommon($node->class, $args); } - return 'new ' . $this->pNewVariable($node->class) + return 'new ' . $this->pNewOperand($node->class) . '(' . $this->pMaybeMultiline($node->args) . ')'; } - protected function pExpr_Clone(Expr\Clone_ $node) { - return 'clone ' . $this->p($node->expr); + protected function pExpr_Clone(Expr\Clone_ $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Expr\Clone_::class, 'clone ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_Ternary(Expr\Ternary $node) { + protected function pExpr_Ternary(Expr\Ternary $node, int $precedence, int $lhsPrecedence): string { // a bit of cheating: we treat the ternary as a binary op where the ?...: part is the operator. // this is okay because the part between ? and : never needs parentheses. return $this->pInfixOp(Expr\Ternary::class, - $node->cond, ' ?' . (null !== $node->if ? ' ' . $this->p($node->if) . ' ' : '') . ': ', $node->else + $node->cond, ' ?' . (null !== $node->if ? ' ' . $this->p($node->if) . ' ' : '') . ': ', $node->else, + $precedence, $lhsPrecedence ); } - protected function pExpr_Exit(Expr\Exit_ $node) { + protected function pExpr_Exit(Expr\Exit_ $node): string { $kind = $node->getAttribute('kind', Expr\Exit_::KIND_DIE); return ($kind === Expr\Exit_::KIND_EXIT ? 'exit' : 'die') . (null !== $node->expr ? '(' . $this->p($node->expr) . ')' : ''); } - protected function pExpr_Throw(Expr\Throw_ $node) { - return 'throw ' . $this->p($node->expr); + protected function pExpr_Throw(Expr\Throw_ $node, int $precedence, int $lhsPrecedence): string { + return $this->pPrefixOp(Expr\Throw_::class, 'throw ', $node->expr, $precedence, $lhsPrecedence); } - protected function pExpr_Yield(Expr\Yield_ $node) { + protected function pExpr_Yield(Expr\Yield_ $node, int $precedence, int $lhsPrecedence): string { if ($node->value === null) { - return 'yield'; + $opPrecedence = $this->precedenceMap[Expr\Yield_::class][0]; + return $opPrecedence >= $lhsPrecedence ? '(yield)' : 'yield'; } else { - // this is a bit ugly, but currently there is no way to detect whether the parentheses are necessary - return '(yield ' - . ($node->key !== null ? $this->p($node->key) . ' => ' : '') - . $this->p($node->value) - . ')'; + if (!$this->phpVersion->supportsYieldWithoutParentheses()) { + return '(yield ' . $this->pKey($node->key) . $this->p($node->value) . ')'; + } + return $this->pPrefixOp( + Expr\Yield_::class, 'yield ' . $this->pKey($node->key), + $node->value, $precedence, $lhsPrecedence); } } // Declarations - protected function pStmt_Namespace(Stmt\Namespace_ $node) { + protected function pStmt_Namespace(Stmt\Namespace_ $node): string { if ($this->canUseSemicolonNamespaces) { return 'namespace ' . $this->p($node->name) . ';' . $this->nl . $this->pStmts($node->stmts, false); @@ -700,132 +764,165 @@ protected function pStmt_Namespace(Stmt\Namespace_ $node) { } } - protected function pStmt_Use(Stmt\Use_ $node) { + protected function pStmt_Use(Stmt\Use_ $node): string { return 'use ' . $this->pUseType($node->type) . $this->pCommaSeparated($node->uses) . ';'; } - protected function pStmt_GroupUse(Stmt\GroupUse $node) { + protected function pStmt_GroupUse(Stmt\GroupUse $node): string { return 'use ' . $this->pUseType($node->type) . $this->pName($node->prefix) . '\{' . $this->pCommaSeparated($node->uses) . '};'; } - protected function pStmt_UseUse(Stmt\UseUse $node) { + protected function pUseItem(Node\UseItem $node): string { return $this->pUseType($node->type) . $this->p($node->name) . (null !== $node->alias ? ' as ' . $node->alias : ''); } - protected function pUseType($type) { + protected function pUseType(int $type): string { return $type === Stmt\Use_::TYPE_FUNCTION ? 'function ' : ($type === Stmt\Use_::TYPE_CONSTANT ? 'const ' : ''); } - protected function pStmt_Interface(Stmt\Interface_ $node) { + protected function pStmt_Interface(Stmt\Interface_ $node): string { return $this->pAttrGroups($node->attrGroups) . 'interface ' . $node->name . (!empty($node->extends) ? ' extends ' . $this->pCommaSeparated($node->extends) : '') . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } - protected function pStmt_Class(Stmt\Class_ $node) { + protected function pStmt_Enum(Stmt\Enum_ $node): string { + return $this->pAttrGroups($node->attrGroups) + . 'enum ' . $node->name + . ($node->scalarType ? ' : ' . $this->p($node->scalarType) : '') + . (!empty($node->implements) ? ' implements ' . $this->pCommaSeparated($node->implements) : '') + . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; + } + + protected function pStmt_Class(Stmt\Class_ $node): string { return $this->pClassCommon($node, ' ' . $node->name); } - protected function pStmt_Trait(Stmt\Trait_ $node) { + protected function pStmt_Trait(Stmt\Trait_ $node): string { return $this->pAttrGroups($node->attrGroups) . 'trait ' . $node->name . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } - protected function pStmt_TraitUse(Stmt\TraitUse $node) { + protected function pStmt_EnumCase(Stmt\EnumCase $node): string { + return $this->pAttrGroups($node->attrGroups) + . 'case ' . $node->name + . ($node->expr ? ' = ' . $this->p($node->expr) : '') + . ';'; + } + + protected function pStmt_TraitUse(Stmt\TraitUse $node): string { return 'use ' . $this->pCommaSeparated($node->traits) . (empty($node->adaptations) ? ';' : ' {' . $this->pStmts($node->adaptations) . $this->nl . '}'); } - protected function pStmt_TraitUseAdaptation_Precedence(Stmt\TraitUseAdaptation\Precedence $node) { + protected function pStmt_TraitUseAdaptation_Precedence(Stmt\TraitUseAdaptation\Precedence $node): string { return $this->p($node->trait) . '::' . $node->method . ' insteadof ' . $this->pCommaSeparated($node->insteadof) . ';'; } - protected function pStmt_TraitUseAdaptation_Alias(Stmt\TraitUseAdaptation\Alias $node) { + protected function pStmt_TraitUseAdaptation_Alias(Stmt\TraitUseAdaptation\Alias $node): string { return (null !== $node->trait ? $this->p($node->trait) . '::' : '') . $node->method . ' as' . (null !== $node->newModifier ? ' ' . rtrim($this->pModifiers($node->newModifier), ' ') : '') - . (null !== $node->newName ? ' ' . $node->newName : '') + . (null !== $node->newName ? ' ' . $node->newName : '') . ';'; } - protected function pStmt_Property(Stmt\Property $node) { + protected function pStmt_Property(Stmt\Property $node): string { return $this->pAttrGroups($node->attrGroups) . (0 === $node->flags ? 'var ' : $this->pModifiers($node->flags)) . ($node->type ? $this->p($node->type) . ' ' : '') - . $this->pCommaSeparated($node->props) . ';'; + . $this->pCommaSeparated($node->props) + . ($node->hooks ? ' {' . $this->pStmts($node->hooks) . $this->nl . '}' : ';'); } - protected function pStmt_PropertyProperty(Stmt\PropertyProperty $node) { + protected function pPropertyItem(Node\PropertyItem $node): string { return '$' . $node->name . (null !== $node->default ? ' = ' . $this->p($node->default) : ''); } - protected function pStmt_ClassMethod(Stmt\ClassMethod $node) { + protected function pPropertyHook(Node\PropertyHook $node): string { + return $this->pAttrGroups($node->attrGroups) + . $this->pModifiers($node->flags) + . ($node->byRef ? '&' : '') . $node->name + . ($node->params ? '(' . $this->pParams($node->params) . ')' : '') + . (\is_array($node->body) ? ' {' . $this->pStmts($node->body) . $this->nl . '}' + : ($node->body !== null ? ' => ' . $this->p($node->body) : '') . ';'); + } + + protected function pStmt_ClassMethod(Stmt\ClassMethod $node): string { return $this->pAttrGroups($node->attrGroups) . $this->pModifiers($node->flags) . 'function ' . ($node->byRef ? '&' : '') . $node->name - . '(' . $this->pMaybeMultiline($node->params) . ')' - . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '') + . '(' . $this->pParams($node->params) . ')' + . (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '') . (null !== $node->stmts ? $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}' : ';'); } - protected function pStmt_ClassConst(Stmt\ClassConst $node) { + protected function pStmt_ClassConst(Stmt\ClassConst $node): string { return $this->pAttrGroups($node->attrGroups) . $this->pModifiers($node->flags) - . 'const ' . $this->pCommaSeparated($node->consts) . ';'; + . 'const ' + . (null !== $node->type ? $this->p($node->type) . ' ' : '') + . $this->pCommaSeparated($node->consts) . ';'; } - protected function pStmt_Function(Stmt\Function_ $node) { + protected function pStmt_Function(Stmt\Function_ $node): string { return $this->pAttrGroups($node->attrGroups) . 'function ' . ($node->byRef ? '&' : '') . $node->name - . '(' . $this->pCommaSeparated($node->params) . ')' - . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '') + . '(' . $this->pParams($node->params) . ')' + . (null !== $node->returnType ? ': ' . $this->p($node->returnType) : '') . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } - protected function pStmt_Const(Stmt\Const_ $node) { - return 'const ' . $this->pCommaSeparated($node->consts) . ';'; + protected function pStmt_Const(Stmt\Const_ $node): string { + return $this->pAttrGroups($node->attrGroups) + . 'const ' + . $this->pCommaSeparated($node->consts) . ';'; } - protected function pStmt_Declare(Stmt\Declare_ $node) { + protected function pStmt_Declare(Stmt\Declare_ $node): string { return 'declare (' . $this->pCommaSeparated($node->declares) . ')' . (null !== $node->stmts ? ' {' . $this->pStmts($node->stmts) . $this->nl . '}' : ';'); } - protected function pStmt_DeclareDeclare(Stmt\DeclareDeclare $node) { + protected function pDeclareItem(Node\DeclareItem $node): string { return $node->key . '=' . $this->p($node->value); } // Control flow - protected function pStmt_If(Stmt\If_ $node) { + protected function pStmt_If(Stmt\If_ $node): string { return 'if (' . $this->p($node->cond) . ') {' . $this->pStmts($node->stmts) . $this->nl . '}' . ($node->elseifs ? ' ' . $this->pImplode($node->elseifs, ' ') : '') . (null !== $node->else ? ' ' . $this->p($node->else) : ''); } - protected function pStmt_ElseIf(Stmt\ElseIf_ $node) { + protected function pStmt_ElseIf(Stmt\ElseIf_ $node): string { return 'elseif (' . $this->p($node->cond) . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; } - protected function pStmt_Else(Stmt\Else_ $node) { + protected function pStmt_Else(Stmt\Else_ $node): string { + if (\count($node->stmts) === 1 && $node->stmts[0] instanceof Stmt\If_) { + // Print as "else if" rather than "else { if }" + return 'else ' . $this->p($node->stmts[0]); + } return 'else {' . $this->pStmts($node->stmts) . $this->nl . '}'; } - protected function pStmt_For(Stmt\For_ $node) { + protected function pStmt_For(Stmt\For_ $node): string { return 'for (' . $this->pCommaSeparated($node->init) . ';' . (!empty($node->cond) ? ' ' : '') . $this->pCommaSeparated($node->cond) . ';' . (!empty($node->loop) ? ' ' : '') @@ -833,116 +930,116 @@ protected function pStmt_For(Stmt\For_ $node) { . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; } - protected function pStmt_Foreach(Stmt\Foreach_ $node) { + protected function pStmt_Foreach(Stmt\Foreach_ $node): string { return 'foreach (' . $this->p($node->expr) . ' as ' . (null !== $node->keyVar ? $this->p($node->keyVar) . ' => ' : '') . ($node->byRef ? '&' : '') . $this->p($node->valueVar) . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; } - protected function pStmt_While(Stmt\While_ $node) { + protected function pStmt_While(Stmt\While_ $node): string { return 'while (' . $this->p($node->cond) . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; } - protected function pStmt_Do(Stmt\Do_ $node) { + protected function pStmt_Do(Stmt\Do_ $node): string { return 'do {' . $this->pStmts($node->stmts) . $this->nl . '} while (' . $this->p($node->cond) . ');'; } - protected function pStmt_Switch(Stmt\Switch_ $node) { + protected function pStmt_Switch(Stmt\Switch_ $node): string { return 'switch (' . $this->p($node->cond) . ') {' . $this->pStmts($node->cases) . $this->nl . '}'; } - protected function pStmt_Case(Stmt\Case_ $node) { + protected function pStmt_Case(Stmt\Case_ $node): string { return (null !== $node->cond ? 'case ' . $this->p($node->cond) : 'default') . ':' . $this->pStmts($node->stmts); } - protected function pStmt_TryCatch(Stmt\TryCatch $node) { + protected function pStmt_TryCatch(Stmt\TryCatch $node): string { return 'try {' . $this->pStmts($node->stmts) . $this->nl . '}' . ($node->catches ? ' ' . $this->pImplode($node->catches, ' ') : '') . ($node->finally !== null ? ' ' . $this->p($node->finally) : ''); } - protected function pStmt_Catch(Stmt\Catch_ $node) { + protected function pStmt_Catch(Stmt\Catch_ $node): string { return 'catch (' . $this->pImplode($node->types, '|') . ($node->var !== null ? ' ' . $this->p($node->var) : '') . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; } - protected function pStmt_Finally(Stmt\Finally_ $node) { + protected function pStmt_Finally(Stmt\Finally_ $node): string { return 'finally {' . $this->pStmts($node->stmts) . $this->nl . '}'; } - protected function pStmt_Break(Stmt\Break_ $node) { + protected function pStmt_Break(Stmt\Break_ $node): string { return 'break' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';'; } - protected function pStmt_Continue(Stmt\Continue_ $node) { + protected function pStmt_Continue(Stmt\Continue_ $node): string { return 'continue' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';'; } - protected function pStmt_Return(Stmt\Return_ $node) { + protected function pStmt_Return(Stmt\Return_ $node): string { return 'return' . (null !== $node->expr ? ' ' . $this->p($node->expr) : '') . ';'; } - protected function pStmt_Throw(Stmt\Throw_ $node) { - return 'throw ' . $this->p($node->expr) . ';'; - } - - protected function pStmt_Label(Stmt\Label $node) { + protected function pStmt_Label(Stmt\Label $node): string { return $node->name . ':'; } - protected function pStmt_Goto(Stmt\Goto_ $node) { + protected function pStmt_Goto(Stmt\Goto_ $node): string { return 'goto ' . $node->name . ';'; } // Other - protected function pStmt_Expression(Stmt\Expression $node) { + protected function pStmt_Expression(Stmt\Expression $node): string { return $this->p($node->expr) . ';'; } - protected function pStmt_Echo(Stmt\Echo_ $node) { + protected function pStmt_Echo(Stmt\Echo_ $node): string { return 'echo ' . $this->pCommaSeparated($node->exprs) . ';'; } - protected function pStmt_Static(Stmt\Static_ $node) { + protected function pStmt_Static(Stmt\Static_ $node): string { return 'static ' . $this->pCommaSeparated($node->vars) . ';'; } - protected function pStmt_Global(Stmt\Global_ $node) { + protected function pStmt_Global(Stmt\Global_ $node): string { return 'global ' . $this->pCommaSeparated($node->vars) . ';'; } - protected function pStmt_StaticVar(Stmt\StaticVar $node) { + protected function pStaticVar(Node\StaticVar $node): string { return $this->p($node->var) . (null !== $node->default ? ' = ' . $this->p($node->default) : ''); } - protected function pStmt_Unset(Stmt\Unset_ $node) { + protected function pStmt_Unset(Stmt\Unset_ $node): string { return 'unset(' . $this->pCommaSeparated($node->vars) . ');'; } - protected function pStmt_InlineHTML(Stmt\InlineHTML $node) { - $newline = $node->getAttribute('hasLeadingNewline', true) ? "\n" : ''; + protected function pStmt_InlineHTML(Stmt\InlineHTML $node): string { + $newline = $node->getAttribute('hasLeadingNewline', true) ? $this->newline : ''; return '?>' . $newline . $node->value . 'remaining; } - protected function pStmt_Nop(Stmt\Nop $node) { + protected function pStmt_Nop(Stmt\Nop $node): string { return ''; } + protected function pStmt_Block(Stmt\Block $node): string { + return '{' . $this->pStmts($node->stmts) . $this->nl . '}'; + } + // Helpers - protected function pClassCommon(Stmt\Class_ $node, $afterClassToken) { + protected function pClassCommon(Stmt\Class_ $node, string $afterClassToken): string { return $this->pAttrGroups($node->attrGroups, $node->name === null) . $this->pModifiers($node->flags) . 'class' . $afterClassToken @@ -951,18 +1048,20 @@ protected function pClassCommon(Stmt\Class_ $node, $afterClassToken) { . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } - protected function pObjectProperty($node) { + protected function pObjectProperty(Node $node): string { if ($node instanceof Expr) { return '{' . $this->p($node) . '}'; } else { - return $node; + assert($node instanceof Node\Identifier); + return $node->name; } } - protected function pEncapsList(array $encapsList, $quote) { + /** @param (Expr|Node\InterpolatedStringPart)[] $encapsList */ + protected function pEncapsList(array $encapsList, ?string $quote): string { $return = ''; foreach ($encapsList as $element) { - if ($element instanceof Scalar\EncapsedStringPart) { + if ($element instanceof Node\InterpolatedStringPart) { $return .= $this->escapeString($element->value, $quote); } else { $return .= '{' . $this->p($element) . '}'; @@ -972,42 +1071,64 @@ protected function pEncapsList(array $encapsList, $quote) { return $return; } - protected function pSingleQuotedString(string $string) { - return '\'' . addcslashes($string, '\'\\') . '\''; + protected function pSingleQuotedString(string $string): string { + // It is idiomatic to only escape backslashes when necessary, i.e. when followed by ', \ or + // the end of the string ('Foo\Bar' instead of 'Foo\\Bar'). However, we also don't want to + // produce an odd number of backslashes, so '\\\\a' should not get rendered as '\\\a', even + // though that would be legal. + $regex = '/\'|\\\\(?=[\'\\\\]|$)|(?<=\\\\)\\\\/'; + return '\'' . preg_replace($regex, '\\\\$0', $string) . '\''; } - protected function escapeString($string, $quote) { + protected function escapeString(string $string, ?string $quote): string { if (null === $quote) { // For doc strings, don't escape newlines $escaped = addcslashes($string, "\t\f\v$\\"); + // But do escape isolated \r. Combined with the terminating newline, it might get + // interpreted as \r\n and dropped from the string contents. + $escaped = preg_replace('/\r(?!\n)/', '\\r', $escaped); + if ($this->phpVersion->supportsFlexibleHeredoc()) { + $escaped = $this->indentString($escaped); + } } else { $escaped = addcslashes($string, "\n\r\t\f\v$" . $quote . "\\"); } - // Escape other control characters - return preg_replace_callback('/([\0-\10\16-\37])(?=([0-7]?))/', function ($matches) { - $oct = decoct(ord($matches[1])); - if ($matches[2] !== '') { - // If there is a trailing digit, use the full three character form - return '\\' . str_pad($oct, 3, '0', \STR_PAD_LEFT); - } - return '\\' . $oct; + // Escape control characters and non-UTF-8 characters. + // Regex based on https://stackoverflow.com/a/11709412/385378. + $regex = '/( + [\x00-\x08\x0E-\x1F] # Control characters + | [\xC0-\xC1] # Invalid UTF-8 Bytes + | [\xF5-\xFF] # Invalid UTF-8 Bytes + | \xE0(?=[\x80-\x9F]) # Overlong encoding of prior code point + | \xF0(?=[\x80-\x8F]) # Overlong encoding of prior code point + | [\xC2-\xDF](?![\x80-\xBF]) # Invalid UTF-8 Sequence Start + | [\xE0-\xEF](?![\x80-\xBF]{2}) # Invalid UTF-8 Sequence Start + | [\xF0-\xF4](?![\x80-\xBF]{3}) # Invalid UTF-8 Sequence Start + | (?<=[\x00-\x7F\xF5-\xFF])[\x80-\xBF] # Invalid UTF-8 Sequence Middle + | (? $part) { - $atStart = $i === 0; - $atEnd = $i === count($parts) - 1; - if ($part instanceof Scalar\EncapsedStringPart - && $this->containsEndLabel($part->value, $label, $atStart, $atEnd) + if ($part instanceof Node\InterpolatedStringPart + && $this->containsEndLabel($this->escapeString($part->value, null), $label, $i === 0) ) { return true; } @@ -1015,32 +1136,42 @@ protected function encapsedContainsEndLabel(array $parts, $label) { return false; } - protected function pDereferenceLhs(Node $node) { + protected function pDereferenceLhs(Node $node): string { if (!$this->dereferenceLhsRequiresParens($node)) { return $this->p($node); - } else { + } else { return '(' . $this->p($node) . ')'; } } - protected function pCallLhs(Node $node) { + protected function pStaticDereferenceLhs(Node $node): string { + if (!$this->staticDereferenceLhsRequiresParens($node)) { + return $this->p($node); + } else { + return '(' . $this->p($node) . ')'; + } + } + + protected function pCallLhs(Node $node): string { if (!$this->callLhsRequiresParens($node)) { return $this->p($node); - } else { + } else { return '(' . $this->p($node) . ')'; } } - protected function pNewVariable(Node $node) { - // TODO: This is not fully accurate. - return $this->pDereferenceLhs($node); + protected function pNewOperand(Node $node): string { + if (!$this->newOperandRequiresParens($node)) { + return $this->p($node); + } else { + return '(' . $this->p($node) . ')'; + } } /** * @param Node[] $nodes - * @return bool */ - protected function hasNodeWithComments(array $nodes) { + protected function hasNodeWithComments(array $nodes): bool { foreach ($nodes as $node) { if ($node && $node->getComments()) { return true; @@ -1049,7 +1180,8 @@ protected function hasNodeWithComments(array $nodes) { return false; } - protected function pMaybeMultiline(array $nodes, bool $trailingComma = false) { + /** @param Node[] $nodes */ + protected function pMaybeMultiline(array $nodes, bool $trailingComma = false): string { if (!$this->hasNodeWithComments($nodes)) { return $this->pCommaSeparated($nodes); } else { @@ -1057,6 +1189,28 @@ protected function pMaybeMultiline(array $nodes, bool $trailingComma = false) { } } + /** @param Node\Param[] $params + */ + private function hasParamWithAttributes(array $params): bool { + foreach ($params as $param) { + if ($param->attrGroups) { + return true; + } + } + return false; + } + + /** @param Node\Param[] $params */ + protected function pParams(array $params): string { + if ($this->hasNodeWithComments($params) || + ($this->hasParamWithAttributes($params) && !$this->phpVersion->supportsAttributes()) + ) { + return $this->pCommaSeparatedMultiline($params, $this->phpVersion->supportsTrailingCommaInParamList()) . $this->nl; + } + return $this->pCommaSeparated($params); + } + + /** @param Node\AttributeGroup[] $nodes */ protected function pAttrGroups(array $nodes, bool $inline = false): string { $result = ''; $sep = $inline ? ' ' : $this->nl; diff --git a/lib/PhpParser/PrettyPrinterAbstract.php b/lib/PhpParser/PrettyPrinterAbstract.php index 804026eff6..ac8bda29ee 100644 --- a/lib/PhpParser/PrettyPrinterAbstract.php +++ b/lib/PhpParser/PrettyPrinterAbstract.php @@ -3,160 +3,226 @@ namespace PhpParser; use PhpParser\Internal\DiffElem; +use PhpParser\Internal\Differ; use PhpParser\Internal\PrintableNewAnonClassNode; use PhpParser\Internal\TokenStream; +use PhpParser\Node\AttributeGroup; use PhpParser\Node\Expr; use PhpParser\Node\Expr\AssignOp; use PhpParser\Node\Expr\BinaryOp; use PhpParser\Node\Expr\Cast; +use PhpParser\Node\IntersectionType; +use PhpParser\Node\MatchArm; +use PhpParser\Node\Param; +use PhpParser\Node\PropertyHook; use PhpParser\Node\Scalar; use PhpParser\Node\Stmt; - -abstract class PrettyPrinterAbstract -{ - const FIXUP_PREC_LEFT = 0; // LHS operand affected by precedence - const FIXUP_PREC_RIGHT = 1; // RHS operand affected by precedence - const FIXUP_CALL_LHS = 2; // LHS of call - const FIXUP_DEREF_LHS = 3; // LHS of dereferencing operation - const FIXUP_BRACED_NAME = 4; // Name operand that may require bracing - const FIXUP_VAR_BRACED_NAME = 5; // Name operand that may require ${} bracing - const FIXUP_ENCAPSED = 6; // Encapsed string part - - protected $precedenceMap = [ - // [precedence, associativity] - // where for precedence -1 is %left, 0 is %nonassoc and 1 is %right - BinaryOp\Pow::class => [ 0, 1], - Expr\BitwiseNot::class => [ 10, 1], - Expr\PreInc::class => [ 10, 1], - Expr\PreDec::class => [ 10, 1], - Expr\PostInc::class => [ 10, -1], - Expr\PostDec::class => [ 10, -1], - Expr\UnaryPlus::class => [ 10, 1], - Expr\UnaryMinus::class => [ 10, 1], - Cast\Int_::class => [ 10, 1], - Cast\Double::class => [ 10, 1], - Cast\String_::class => [ 10, 1], - Cast\Array_::class => [ 10, 1], - Cast\Object_::class => [ 10, 1], - Cast\Bool_::class => [ 10, 1], - Cast\Unset_::class => [ 10, 1], - Expr\ErrorSuppress::class => [ 10, 1], - Expr\Instanceof_::class => [ 20, 0], - Expr\BooleanNot::class => [ 30, 1], - BinaryOp\Mul::class => [ 40, -1], - BinaryOp\Div::class => [ 40, -1], - BinaryOp\Mod::class => [ 40, -1], - BinaryOp\Plus::class => [ 50, -1], - BinaryOp\Minus::class => [ 50, -1], - BinaryOp\Concat::class => [ 50, -1], - BinaryOp\ShiftLeft::class => [ 60, -1], - BinaryOp\ShiftRight::class => [ 60, -1], - BinaryOp\Smaller::class => [ 70, 0], - BinaryOp\SmallerOrEqual::class => [ 70, 0], - BinaryOp\Greater::class => [ 70, 0], - BinaryOp\GreaterOrEqual::class => [ 70, 0], - BinaryOp\Equal::class => [ 80, 0], - BinaryOp\NotEqual::class => [ 80, 0], - BinaryOp\Identical::class => [ 80, 0], - BinaryOp\NotIdentical::class => [ 80, 0], - BinaryOp\Spaceship::class => [ 80, 0], - BinaryOp\BitwiseAnd::class => [ 90, -1], - BinaryOp\BitwiseXor::class => [100, -1], - BinaryOp\BitwiseOr::class => [110, -1], - BinaryOp\BooleanAnd::class => [120, -1], - BinaryOp\BooleanOr::class => [130, -1], - BinaryOp\Coalesce::class => [140, 1], - Expr\Ternary::class => [150, 0], - // parser uses %left for assignments, but they really behave as %right - Expr\Assign::class => [160, 1], - Expr\AssignRef::class => [160, 1], - AssignOp\Plus::class => [160, 1], - AssignOp\Minus::class => [160, 1], - AssignOp\Mul::class => [160, 1], - AssignOp\Div::class => [160, 1], - AssignOp\Concat::class => [160, 1], - AssignOp\Mod::class => [160, 1], - AssignOp\BitwiseAnd::class => [160, 1], - AssignOp\BitwiseOr::class => [160, 1], - AssignOp\BitwiseXor::class => [160, 1], - AssignOp\ShiftLeft::class => [160, 1], - AssignOp\ShiftRight::class => [160, 1], - AssignOp\Pow::class => [160, 1], - AssignOp\Coalesce::class => [160, 1], - Expr\YieldFrom::class => [165, 1], - Expr\Print_::class => [168, 1], - BinaryOp\LogicalAnd::class => [170, -1], - BinaryOp\LogicalXor::class => [180, -1], - BinaryOp\LogicalOr::class => [190, -1], - Expr\Include_::class => [200, -1], +use PhpParser\Node\UnionType; + +abstract class PrettyPrinterAbstract implements PrettyPrinter { + protected const FIXUP_PREC_LEFT = 0; // LHS operand affected by precedence + protected const FIXUP_PREC_RIGHT = 1; // RHS operand affected by precedence + protected const FIXUP_PREC_UNARY = 2; // Only operand affected by precedence + protected const FIXUP_CALL_LHS = 3; // LHS of call + protected const FIXUP_DEREF_LHS = 4; // LHS of dereferencing operation + protected const FIXUP_STATIC_DEREF_LHS = 5; // LHS of static dereferencing operation + protected const FIXUP_BRACED_NAME = 6; // Name operand that may require bracing + protected const FIXUP_VAR_BRACED_NAME = 7; // Name operand that may require ${} bracing + protected const FIXUP_ENCAPSED = 8; // Encapsed string part + protected const FIXUP_NEW = 9; // New/instanceof operand + + protected const MAX_PRECEDENCE = 1000; + + /** @var array */ + protected array $precedenceMap = [ + // [precedence, precedenceLHS, precedenceRHS] + // Where the latter two are the precedences to use for the LHS and RHS of a binary operator, + // where 1 is added to one of the sides depending on associativity. This information is not + // used for unary operators and set to -1. + Expr\Clone_::class => [-10, 0, 1], + BinaryOp\Pow::class => [ 0, 0, 1], + Expr\BitwiseNot::class => [ 10, -1, -1], + Expr\UnaryPlus::class => [ 10, -1, -1], + Expr\UnaryMinus::class => [ 10, -1, -1], + Cast\Int_::class => [ 10, -1, -1], + Cast\Double::class => [ 10, -1, -1], + Cast\String_::class => [ 10, -1, -1], + Cast\Array_::class => [ 10, -1, -1], + Cast\Object_::class => [ 10, -1, -1], + Cast\Bool_::class => [ 10, -1, -1], + Cast\Unset_::class => [ 10, -1, -1], + Expr\ErrorSuppress::class => [ 10, -1, -1], + Expr\Instanceof_::class => [ 20, -1, -1], + Expr\BooleanNot::class => [ 30, -1, -1], + BinaryOp\Mul::class => [ 40, 41, 40], + BinaryOp\Div::class => [ 40, 41, 40], + BinaryOp\Mod::class => [ 40, 41, 40], + BinaryOp\Plus::class => [ 50, 51, 50], + BinaryOp\Minus::class => [ 50, 51, 50], + // FIXME: This precedence is incorrect for PHP 8. + BinaryOp\Concat::class => [ 50, 51, 50], + BinaryOp\ShiftLeft::class => [ 60, 61, 60], + BinaryOp\ShiftRight::class => [ 60, 61, 60], + BinaryOp\Pipe::class => [ 65, 66, 65], + BinaryOp\Smaller::class => [ 70, 70, 70], + BinaryOp\SmallerOrEqual::class => [ 70, 70, 70], + BinaryOp\Greater::class => [ 70, 70, 70], + BinaryOp\GreaterOrEqual::class => [ 70, 70, 70], + BinaryOp\Equal::class => [ 80, 80, 80], + BinaryOp\NotEqual::class => [ 80, 80, 80], + BinaryOp\Identical::class => [ 80, 80, 80], + BinaryOp\NotIdentical::class => [ 80, 80, 80], + BinaryOp\Spaceship::class => [ 80, 80, 80], + BinaryOp\BitwiseAnd::class => [ 90, 91, 90], + BinaryOp\BitwiseXor::class => [100, 101, 100], + BinaryOp\BitwiseOr::class => [110, 111, 110], + BinaryOp\BooleanAnd::class => [120, 121, 120], + BinaryOp\BooleanOr::class => [130, 131, 130], + BinaryOp\Coalesce::class => [140, 140, 141], + Expr\Ternary::class => [150, 150, 150], + Expr\Assign::class => [160, -1, -1], + Expr\AssignRef::class => [160, -1, -1], + AssignOp\Plus::class => [160, -1, -1], + AssignOp\Minus::class => [160, -1, -1], + AssignOp\Mul::class => [160, -1, -1], + AssignOp\Div::class => [160, -1, -1], + AssignOp\Concat::class => [160, -1, -1], + AssignOp\Mod::class => [160, -1, -1], + AssignOp\BitwiseAnd::class => [160, -1, -1], + AssignOp\BitwiseOr::class => [160, -1, -1], + AssignOp\BitwiseXor::class => [160, -1, -1], + AssignOp\ShiftLeft::class => [160, -1, -1], + AssignOp\ShiftRight::class => [160, -1, -1], + AssignOp\Pow::class => [160, -1, -1], + AssignOp\Coalesce::class => [160, -1, -1], + Expr\YieldFrom::class => [170, -1, -1], + Expr\Yield_::class => [175, -1, -1], + Expr\Print_::class => [180, -1, -1], + BinaryOp\LogicalAnd::class => [190, 191, 190], + BinaryOp\LogicalXor::class => [200, 201, 200], + BinaryOp\LogicalOr::class => [210, 211, 210], + Expr\Include_::class => [220, -1, -1], + Expr\ArrowFunction::class => [230, -1, -1], + Expr\Throw_::class => [240, -1, -1], + Expr\Cast\Void_::class => [250, -1, -1], ]; /** @var int Current indentation level. */ - protected $indentLevel; + protected int $indentLevel; + /** @var string String for single level of indentation */ + private string $indent; + /** @var int Width in spaces to indent by. */ + private int $indentWidth; + /** @var bool Whether to use tab indentation. */ + private bool $useTabs; + /** @var int Width in spaces of one tab. */ + private int $tabWidth = 4; + + /** @var string Newline style. Does not include current indentation. */ + protected string $newline; /** @var string Newline including current indentation. */ - protected $nl; - /** @var string Token placed at end of doc string to ensure it is followed by a newline. */ - protected $docStringEndToken; + protected string $nl; + /** @var string|null Token placed at end of doc string to ensure it is followed by a newline. + * Null if flexible doc strings are used. */ + protected ?string $docStringEndToken; /** @var bool Whether semicolon namespaces can be used (i.e. no global namespace is used) */ - protected $canUseSemicolonNamespaces; - /** @var array Pretty printer options */ - protected $options; - - /** @var TokenStream Original tokens for use in format-preserving pretty print */ - protected $origTokens; - /** @var Internal\Differ Differ for node lists */ - protected $nodeListDiffer; - /** @var bool[] Map determining whether a certain character is a label character */ - protected $labelCharMap; + protected bool $canUseSemicolonNamespaces; + /** @var bool Whether to use short array syntax if the node specifies no preference */ + protected bool $shortArraySyntax; + /** @var PhpVersion PHP version to target */ + protected PhpVersion $phpVersion; + + /** @var TokenStream|null Original tokens for use in format-preserving pretty print */ + protected ?TokenStream $origTokens; + /** @var Internal\Differ Differ for node lists */ + protected Differ $nodeListDiffer; + /** @var array Map determining whether a certain character is a label character */ + protected array $labelCharMap; + /** + * @var array> Map from token classes and subnode names to FIXUP_* constants. + * This is used during format-preserving prints to place additional parens/braces if necessary. + */ + protected array $fixupMap; /** - * @var int[][] Map from token classes and subnode names to FIXUP_* constants. This is used - * during format-preserving prints to place additional parens/braces if necessary. + * @var array Map from "{$node->getType()}->{$subNode}" + * to ['left' => $l, 'right' => $r], where $l and $r specify the token type that needs to be stripped + * when removing this node. */ - protected $fixupMap; + protected array $removalMap; /** - * @var int[][] Map from "{$node->getType()}->{$subNode}" to ['left' => $l, 'right' => $r], - * where $l and $r specify the token type that needs to be stripped when removing - * this node. + * @var array Map from + * "{$node->getType()}->{$subNode}" to [$find, $beforeToken, $extraLeft, $extraRight]. + * $find is an optional token after which the insertion occurs. $extraLeft/Right + * are optionally added before/after the main insertions. */ - protected $removalMap; + protected array $insertionMap; /** - * @var mixed[] Map from "{$node->getType()}->{$subNode}" to [$find, $beforeToken, $extraLeft, $extraRight]. - * $find is an optional token after which the insertion occurs. $extraLeft/Right - * are optionally added before/after the main insertions. + * @var array Map From "{$class}->{$subNode}" to string that should be inserted + * between elements of this list subnode. */ - protected $insertionMap; + protected array $listInsertionMap; + /** - * @var string[] Map From "{$node->getType()}->{$subNode}" to string that should be inserted - * between elements of this list subnode. + * @var array */ - protected $listInsertionMap; - protected $emptyListInsertionMap; - /** @var int[] Map from "{$node->getType()}->{$subNode}" to token before which the modifiers - * should be reprinted. */ - protected $modifierChangeMap; + protected array $emptyListInsertionMap; + /** @var array Map from "{$class}->{$subNode}" to [$printFn, $token] + * where $printFn is the function to print the modifiers and $token is the token before which + * the modifiers should be reprinted. */ + protected array $modifierChangeMap; /** * Creates a pretty printer instance using the given options. * * Supported options: - * * bool $shortArraySyntax = false: Whether to use [] instead of array() as the default array - * syntax, if the node does not specify a format. + * * PhpVersion $phpVersion: The PHP version to target (default to PHP 7.4). This option + * controls compatibility of the generated code with older PHP + * versions in cases where a simple stylistic choice exists (e.g. + * array() vs []). It is safe to pretty-print an AST for a newer + * PHP version while specifying an older target (but the result will + * of course not be compatible with the older version in that case). + * * string $newline: The newline style to use. Should be "\n" (default) or "\r\n". + * * string $indent: The indentation to use. Should either be all spaces or a single + * tab. Defaults to four spaces (" "). + * * bool $shortArraySyntax: Whether to use [] instead of array() as the default array + * syntax, if the node does not specify a format. Defaults to whether + * the phpVersion support short array syntax. * - * @param array $options Dictionary of formatting options + * @param array{ + * phpVersion?: PhpVersion, newline?: string, indent?: string, shortArraySyntax?: bool + * } $options Dictionary of formatting options */ public function __construct(array $options = []) { - $this->docStringEndToken = '_DOC_STRING_END_' . mt_rand(); + $this->phpVersion = $options['phpVersion'] ?? PhpVersion::fromComponents(7, 4); - $defaultOptions = ['shortArraySyntax' => false]; - $this->options = $options + $defaultOptions; + $this->newline = $options['newline'] ?? "\n"; + if ($this->newline !== "\n" && $this->newline != "\r\n") { + throw new \LogicException('Option "newline" must be one of "\n" or "\r\n"'); + } + + $this->shortArraySyntax = + $options['shortArraySyntax'] ?? $this->phpVersion->supportsShortArraySyntax(); + $this->docStringEndToken = + $this->phpVersion->supportsFlexibleHeredoc() ? null : '_DOC_STRING_END_' . mt_rand(); + + $this->indent = $indent = $options['indent'] ?? ' '; + if ($indent === "\t") { + $this->useTabs = true; + $this->indentWidth = $this->tabWidth; + } elseif ($indent === \str_repeat(' ', \strlen($indent))) { + $this->useTabs = false; + $this->indentWidth = \strlen($indent); + } else { + throw new \LogicException('Option "indent" must either be all spaces or a single tab'); + } } /** * Reset pretty printing state. */ - protected function resetState() { + protected function resetState(): void { $this->indentLevel = 0; - $this->nl = "\n"; + $this->nl = $this->newline; $this->origTokens = null; } @@ -165,26 +231,31 @@ protected function resetState() { * * @param int $level Level in number of spaces */ - protected function setIndentLevel(int $level) { + protected function setIndentLevel(int $level): void { $this->indentLevel = $level; - $this->nl = "\n" . \str_repeat(' ', $level); + if ($this->useTabs) { + $tabs = \intdiv($level, $this->tabWidth); + $spaces = $level % $this->tabWidth; + $this->nl = $this->newline . \str_repeat("\t", $tabs) . \str_repeat(' ', $spaces); + } else { + $this->nl = $this->newline . \str_repeat(' ', $level); + } } /** * Increase indentation level. */ - protected function indent() { - $this->indentLevel += 4; - $this->nl .= ' '; + protected function indent(): void { + $this->indentLevel += $this->indentWidth; + $this->nl .= $this->indent; } /** * Decrease indentation level. */ - protected function outdent() { - assert($this->indentLevel >= 4); - $this->indentLevel -= 4; - $this->nl = "\n" . str_repeat(' ', $this->indentLevel); + protected function outdent(): void { + assert($this->indentLevel >= $this->indentWidth); + $this->setIndentLevel($this->indentLevel - $this->indentWidth); } /** @@ -194,7 +265,7 @@ protected function outdent() { * * @return string Pretty printed statements */ - public function prettyPrint(array $stmts) : string { + public function prettyPrint(array $stmts): string { $this->resetState(); $this->preprocessNodes($stmts); @@ -208,7 +279,7 @@ public function prettyPrint(array $stmts) : string { * * @return string Pretty printed node */ - public function prettyPrintExpr(Expr $node) : string { + public function prettyPrintExpr(Expr $node): string { $this->resetState(); return $this->handleMagicTokens($this->p($node)); } @@ -220,15 +291,15 @@ public function prettyPrintExpr(Expr $node) : string { * * @return string Pretty printed statements */ - public function prettyPrintFile(array $stmts) : string { + public function prettyPrintFile(array $stmts): string { if (!$stmts) { - return "newline . $this->newline; } - $p = "prettyPrint($stmts); + $p = "newline . $this->newline . $this->prettyPrint($stmts); if ($stmts[0] instanceof Stmt\InlineHTML) { - $p = preg_replace('/^<\?php\s+\?>\n?/', '', $p); + $p = preg_replace('/^<\?php\s+\?>\r?\n?/', '', $p); } if ($stmts[count($stmts) - 1] instanceof Stmt\InlineHTML) { $p = preg_replace('/<\?php$/', '', rtrim($p)); @@ -242,7 +313,7 @@ public function prettyPrintFile(array $stmts) : string { * * @param Node[] $nodes Array of nodes */ - protected function preprocessNodes(array $nodes) { + protected function preprocessNodes(array $nodes): void { /* We can use semicolon-namespaces unless there is a global namespace declaration */ $this->canUseSemicolonNamespaces = true; foreach ($nodes as $node) { @@ -254,15 +325,17 @@ protected function preprocessNodes(array $nodes) { } /** - * Handles (and removes) no-indent and doc-string-end tokens. - * - * @param string $str - * @return string + * Handles (and removes) doc-string-end tokens. */ - protected function handleMagicTokens(string $str) : string { - // Replace doc-string-end tokens with nothing or a newline - $str = str_replace($this->docStringEndToken . ";\n", ";\n", $str); - $str = str_replace($this->docStringEndToken, "\n", $str); + protected function handleMagicTokens(string $str): string { + if ($this->docStringEndToken !== null) { + // Replace doc-string-end tokens with nothing or a newline + $str = str_replace( + $this->docStringEndToken . ';' . $this->newline, + ';' . $this->newline, + $str); + $str = str_replace($this->docStringEndToken, $this->newline, $str); + } return $str; } @@ -270,12 +343,12 @@ protected function handleMagicTokens(string $str) : string { /** * Pretty prints an array of nodes (statements) and indents them optionally. * - * @param Node[] $nodes Array of nodes - * @param bool $indent Whether to indent the printed nodes + * @param Node[] $nodes Array of nodes + * @param bool $indent Whether to indent the printed nodes * * @return string Pretty printed statements */ - protected function pStmts(array $nodes, bool $indent = true) : string { + protected function pStmts(array $nodes, bool $indent = true): string { if ($indent) { $this->indent(); } @@ -303,84 +376,96 @@ protected function pStmts(array $nodes, bool $indent = true) : string { /** * Pretty-print an infix operation while taking precedence into account. * - * @param string $class Node class of operator - * @param Node $leftNode Left-hand side node + * @param string $class Node class of operator + * @param Node $leftNode Left-hand side node * @param string $operatorString String representation of the operator - * @param Node $rightNode Right-hand side node + * @param Node $rightNode Right-hand side node + * @param int $precedence Precedence of parent operator + * @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator * * @return string Pretty printed infix operation */ - protected function pInfixOp(string $class, Node $leftNode, string $operatorString, Node $rightNode) : string { - list($precedence, $associativity) = $this->precedenceMap[$class]; - - return $this->pPrec($leftNode, $precedence, $associativity, -1) - . $operatorString - . $this->pPrec($rightNode, $precedence, $associativity, 1); + protected function pInfixOp( + string $class, Node $leftNode, string $operatorString, Node $rightNode, + int $precedence, int $lhsPrecedence + ): string { + list($opPrecedence, $newPrecedenceLHS, $newPrecedenceRHS) = $this->precedenceMap[$class]; + $prefix = ''; + $suffix = ''; + if ($opPrecedence >= $precedence) { + $prefix = '('; + $suffix = ')'; + $lhsPrecedence = self::MAX_PRECEDENCE; + } + return $prefix . $this->p($leftNode, $newPrecedenceLHS, $newPrecedenceLHS) + . $operatorString . $this->p($rightNode, $newPrecedenceRHS, $lhsPrecedence) . $suffix; } /** * Pretty-print a prefix operation while taking precedence into account. * - * @param string $class Node class of operator + * @param string $class Node class of operator * @param string $operatorString String representation of the operator - * @param Node $node Node + * @param Node $node Node + * @param int $precedence Precedence of parent operator + * @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator * * @return string Pretty printed prefix operation */ - protected function pPrefixOp(string $class, string $operatorString, Node $node) : string { - list($precedence, $associativity) = $this->precedenceMap[$class]; - return $operatorString . $this->pPrec($node, $precedence, $associativity, 1); + protected function pPrefixOp(string $class, string $operatorString, Node $node, int $precedence, int $lhsPrecedence): string { + $opPrecedence = $this->precedenceMap[$class][0]; + $prefix = ''; + $suffix = ''; + if ($opPrecedence >= $lhsPrecedence) { + $prefix = '('; + $suffix = ')'; + $lhsPrecedence = self::MAX_PRECEDENCE; + } + $printedArg = $this->p($node, $opPrecedence, $lhsPrecedence); + if (($operatorString === '+' && $printedArg[0] === '+') || + ($operatorString === '-' && $printedArg[0] === '-') + ) { + // Avoid printing +(+$a) as ++$a and similar. + $printedArg = '(' . $printedArg . ')'; + } + return $prefix . $operatorString . $printedArg . $suffix; } /** * Pretty-print a postfix operation while taking precedence into account. * - * @param string $class Node class of operator + * @param string $class Node class of operator * @param string $operatorString String representation of the operator - * @param Node $node Node + * @param Node $node Node + * @param int $precedence Precedence of parent operator + * @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator * * @return string Pretty printed postfix operation */ - protected function pPostfixOp(string $class, Node $node, string $operatorString) : string { - list($precedence, $associativity) = $this->precedenceMap[$class]; - return $this->pPrec($node, $precedence, $associativity, -1) . $operatorString; - } - - /** - * Prints an expression node with the least amount of parentheses necessary to preserve the meaning. - * - * @param Node $node Node to pretty print - * @param int $parentPrecedence Precedence of the parent operator - * @param int $parentAssociativity Associativity of parent operator - * (-1 is left, 0 is nonassoc, 1 is right) - * @param int $childPosition Position of the node relative to the operator - * (-1 is left, 1 is right) - * - * @return string The pretty printed node - */ - protected function pPrec(Node $node, int $parentPrecedence, int $parentAssociativity, int $childPosition) : string { - $class = \get_class($node); - if (isset($this->precedenceMap[$class])) { - $childPrecedence = $this->precedenceMap[$class][0]; - if ($childPrecedence > $parentPrecedence - || ($parentPrecedence === $childPrecedence && $parentAssociativity !== $childPosition) - ) { - return '(' . $this->p($node) . ')'; - } + protected function pPostfixOp(string $class, Node $node, string $operatorString, int $precedence, int $lhsPrecedence): string { + $opPrecedence = $this->precedenceMap[$class][0]; + $prefix = ''; + $suffix = ''; + if ($opPrecedence >= $precedence) { + $prefix = '('; + $suffix = ')'; + $lhsPrecedence = self::MAX_PRECEDENCE; } - - return $this->p($node); + if ($opPrecedence < $lhsPrecedence) { + $lhsPrecedence = $opPrecedence; + } + return $prefix . $this->p($node, $opPrecedence, $lhsPrecedence) . $operatorString . $suffix; } /** * Pretty prints an array of nodes and implodes the printed values. * * @param Node[] $nodes Array of Nodes to be printed - * @param string $glue Character to implode with + * @param string $glue Character to implode with * - * @return string Imploded pretty printed nodes + * @return string Imploded pretty printed nodes> $pre */ - protected function pImplode(array $nodes, string $glue = '') : string { + protected function pImplode(array $nodes, string $glue = ''): string { $pNodes = []; foreach ($nodes as $node) { if (null === $node) { @@ -400,7 +485,7 @@ protected function pImplode(array $nodes, string $glue = '') : string { * * @return string Comma separated pretty printed nodes */ - protected function pCommaSeparated(array $nodes) : string { + protected function pCommaSeparated(array $nodes): string { return $this->pImplode($nodes, ', '); } @@ -409,12 +494,12 @@ protected function pCommaSeparated(array $nodes) : string { * * The result includes a leading newline and one level of indentation (same as pStmts). * - * @param Node[] $nodes Array of Nodes to be printed - * @param bool $trailingComma Whether to use a trailing comma + * @param Node[] $nodes Array of Nodes to be printed + * @param bool $trailingComma Whether to use a trailing comma * * @return string Comma separated pretty printed nodes in multiline style */ - protected function pCommaSeparatedMultiline(array $nodes, bool $trailingComma) : string { + protected function pCommaSeparatedMultiline(array $nodes, bool $trailingComma): string { $this->indent(); $result = ''; @@ -446,7 +531,7 @@ protected function pCommaSeparatedMultiline(array $nodes, bool $trailingComma) : * * @return string Reformatted text of comments */ - protected function pComments(array $comments) : string { + protected function pComments(array $comments): string { $formattedComments = []; foreach ($comments as $comment) { @@ -467,13 +552,11 @@ protected function pComments(array $comments) : string { * * The CloningVisitor must be run on the AST prior to modification. * * The original tokens must be provided, using the getTokens() method on the lexer. * - * @param Node[] $stmts Modified AST with links to original AST - * @param Node[] $origStmts Original AST with token offset information - * @param array $origTokens Tokens of the original code - * - * @return string + * @param Node[] $stmts Modified AST with links to original AST + * @param Node[] $origStmts Original AST with token offset information + * @param Token[] $origTokens Tokens of the original code */ - public function printFormatPreserving(array $stmts, array $origStmts, array $origTokens) : string { + public function printFormatPreserving(array $stmts, array $origStmts, array $origTokens): string { $this->initializeNodeListDiffer(); $this->initializeLabelCharMap(); $this->initializeFixupMap(); @@ -484,25 +567,25 @@ public function printFormatPreserving(array $stmts, array $origStmts, array $ori $this->initializeModifierChangeMap(); $this->resetState(); - $this->origTokens = new TokenStream($origTokens); + $this->origTokens = new TokenStream($origTokens, $this->tabWidth); $this->preprocessNodes($stmts); $pos = 0; $result = $this->pArray($stmts, $origStmts, $pos, 0, 'File', 'stmts', null); if (null !== $result) { - $result .= $this->origTokens->getTokenCode($pos, count($origTokens), 0); + $result .= $this->origTokens->getTokenCode($pos, count($origTokens) - 1, 0); } else { // Fallback // TODO Add pStmts($stmts, false); + $result = "newline . $this->pStmts($stmts, false); } - return ltrim($this->handleMagicTokens($result)); + return $this->handleMagicTokens($result); } - protected function pFallback(Node $node) { - return $this->{'p' . $node->getType()}($node); + protected function pFallback(Node $node, int $precedence, int $lhsPrecedence): string { + return $this->{'p' . $node->getType()}($node, $precedence, $lhsPrecedence); } /** @@ -511,20 +594,25 @@ protected function pFallback(Node $node) { * This method also handles formatting preservation for nodes. * * @param Node $node Node to be pretty printed + * @param int $precedence Precedence of parent operator + * @param int $lhsPrecedence Precedence for unary operator on LHS of binary operator * @param bool $parentFormatPreserved Whether parent node has preserved formatting * * @return string Pretty printed node */ - protected function p(Node $node, $parentFormatPreserved = false) : string { + protected function p( + Node $node, int $precedence = self::MAX_PRECEDENCE, int $lhsPrecedence = self::MAX_PRECEDENCE, + bool $parentFormatPreserved = false + ): string { // No orig tokens means this is a normal pretty print without preservation of formatting if (!$this->origTokens) { - return $this->{'p' . $node->getType()}($node); + return $this->{'p' . $node->getType()}($node, $precedence, $lhsPrecedence); } - /** @var Node $origNode */ + /** @var Node|null $origNode */ $origNode = $node->getAttribute('origNode'); if (null === $origNode) { - return $this->pFallback($node); + return $this->pFallback($node, $precedence, $lhsPrecedence); } $class = \get_class($node); @@ -537,15 +625,17 @@ protected function p(Node $node, $parentFormatPreserved = false) : string { $fallbackNode = $node; if ($node instanceof Expr\New_ && $node->class instanceof Stmt\Class_) { // Normalize node structure of anonymous classes + assert($origNode instanceof Expr\New_); $node = PrintableNewAnonClassNode::fromNewNode($node); $origNode = PrintableNewAnonClassNode::fromNewNode($origNode); + $class = PrintableNewAnonClassNode::class; } // InlineHTML node does not contain closing and opening PHP tags. If the parent formatting // is not preserved, then we need to use the fallback code to make sure the tags are // printed. if ($node instanceof Stmt\InlineHTML && !$parentFormatPreserved) { - return $this->pFallback($fallbackNode); + return $this->pFallback($fallbackNode, $precedence, $lhsPrecedence); } $indentAdjustment = $this->indentLevel - $this->origTokens->getIndentationBefore($startPos); @@ -570,34 +660,27 @@ protected function p(Node $node, $parentFormatPreserved = false) : string { if (is_array($subNode) && is_array($origSubNode)) { // Array subnode changed, we might be able to reconstruct it $listResult = $this->pArray( - $subNode, $origSubNode, $pos, $indentAdjustment, $type, $subNodeName, + $subNode, $origSubNode, $pos, $indentAdjustment, $class, $subNodeName, $fixupInfo[$subNodeName] ?? null ); if (null === $listResult) { - return $this->pFallback($fallbackNode); + return $this->pFallback($fallbackNode, $precedence, $lhsPrecedence); } $result .= $listResult; continue; } - if (is_int($subNode) && is_int($origSubNode)) { - // Check if this is a modifier change - $key = $type . '->' . $subNodeName; - if (!isset($this->modifierChangeMap[$key])) { - return $this->pFallback($fallbackNode); - } - - $findToken = $this->modifierChangeMap[$key]; - $result .= $this->pModifiers($subNode); - $pos = $this->origTokens->findRight($pos, $findToken); - continue; + // Check if this is a modifier change + $key = $class . '->' . $subNodeName; + if (!isset($this->modifierChangeMap[$key])) { + return $this->pFallback($fallbackNode, $precedence, $lhsPrecedence); } - // If a non-node, non-array subnode changed, we don't be able to do a partial - // reconstructions, as we don't have enough offset information. Pretty print the - // whole node instead. - return $this->pFallback($fallbackNode); + [$printFn, $findToken] = $this->modifierChangeMap[$key]; + $result .= $this->$printFn($subNode); + $pos = $this->origTokens->findRight($pos, $findToken); + continue; } $extraLeft = ''; @@ -615,7 +698,7 @@ protected function p(Node $node, $parentFormatPreserved = false) : string { // A node has been inserted, check if we have insertion information for it $key = $type . '->' . $subNodeName; if (!isset($this->insertionMap[$key])) { - return $this->pFallback($fallbackNode); + return $this->pFallback($fallbackNode, $precedence, $lhsPrecedence); } list($findToken, $beforeToken, $extraLeft, $extraRight) = $this->insertionMap[$key]; @@ -637,7 +720,7 @@ protected function p(Node $node, $parentFormatPreserved = false) : string { // A node has been removed, check if we have removal information for it $key = $type . '->' . $subNodeName; if (!isset($this->removalMap[$key])) { - return $this->pFallback($fallbackNode); + return $this->pFallback($fallbackNode, $precedence, $lhsPrecedence); } // Adjust positions to account for additional tokens that must be skipped @@ -656,7 +739,7 @@ protected function p(Node $node, $parentFormatPreserved = false) : string { $result .= $extraLeft; $origIndentLevel = $this->indentLevel; - $this->setIndentLevel($this->origTokens->getIndentationBefore($subStartPos) + $indentAdjustment); + $this->setIndentLevel(max($this->origTokens->getIndentationBefore($subStartPos) + $indentAdjustment, 0)); // If it's the same node that was previously in this position, it certainly doesn't // need fixup. It's important to check this here, because our fixup checks are more @@ -667,7 +750,7 @@ protected function p(Node $node, $parentFormatPreserved = false) : string { $fixup = $fixupInfo[$subNodeName]; $res = $this->pFixup($fixup, $subNode, $class, $subStartPos, $subEndPos); } else { - $res = $this->p($subNode, true); + $res = $this->p($subNode, self::MAX_PRECEDENCE, self::MAX_PRECEDENCE, true); } $this->safeAppend($result, $res); @@ -686,23 +769,23 @@ protected function p(Node $node, $parentFormatPreserved = false) : string { /** * Perform a format-preserving pretty print of an array. * - * @param array $nodes New nodes - * @param array $origNodes Original nodes - * @param int $pos Current token position (updated by reference) - * @param int $indentAdjustment Adjustment for indentation - * @param string $parentNodeType Type of the containing node. - * @param string $subNodeName Name of array subnode. - * @param null|int $fixup Fixup information for array item nodes + * @param Node[] $nodes New nodes + * @param Node[] $origNodes Original nodes + * @param int $pos Current token position (updated by reference) + * @param int $indentAdjustment Adjustment for indentation + * @param string $parentNodeClass Class of the containing node. + * @param string $subNodeName Name of array subnode. + * @param null|int $fixup Fixup information for array item nodes * * @return null|string Result of pretty print or null if cannot preserve formatting */ protected function pArray( - array $nodes, array $origNodes, int &$pos, int $indentAdjustment, - string $parentNodeType, string $subNodeName, $fixup - ) { + array $nodes, array $origNodes, int &$pos, int $indentAdjustment, + string $parentNodeClass, string $subNodeName, ?int $fixup + ): ?string { $diff = $this->nodeListDiffer->diffWithReplacements($origNodes, $nodes); - $mapKey = $parentNodeType . '->' . $subNodeName; + $mapKey = $parentNodeClass . '->' . $subNodeName; $insertStr = $this->listInsertionMap[$mapKey] ?? null; $isStmtList = $subNodeName === 'stmts'; @@ -733,9 +816,9 @@ protected function pArray( $result = ''; foreach ($diff as $i => $diffElem) { $diffType = $diffElem->type; - /** @var Node|null $arrItem */ + /** @var Node|string|null $arrItem */ $arrItem = $diffElem->new; - /** @var Node|null $origArrItem */ + /** @var Node|string|null $origArrItem */ $origArrItem = $diffElem->old; if ($diffType === DiffElem::TYPE_KEEP || $diffType === DiffElem::TYPE_REPLACE) { @@ -759,7 +842,7 @@ protected function pArray( \assert($itemStartPos >= 0 && $itemEndPos >= 0 && $itemStartPos >= $pos); $origIndentLevel = $this->indentLevel; - $lastElemIndentLevel = $this->origTokens->getIndentationBefore($itemStartPos) + $indentAdjustment; + $lastElemIndentLevel = max($this->origTokens->getIndentationBefore($itemStartPos) + $indentAdjustment, 0); $this->setIndentLevel($lastElemIndentLevel); $comments = $arrItem->getComments(); @@ -774,8 +857,8 @@ protected function pArray( } if ($skipRemovedNode) { - if ($isStmtList && $this->origTokens->haveBracesInRange($pos, $itemStartPos)) { - // We'd remove the brace of a code block. + if ($isStmtList && $this->origTokens->haveTagInRange($pos, $itemStartPos)) { + // We'd remove an opening/closing PHP tag. // TODO: Preserve formatting. $this->setIndentLevel($origIndentLevel); return null; @@ -795,7 +878,7 @@ protected function pArray( } } - $this->safeAppend($result, $this->p($delayedAddNode, true)); + $this->safeAppend($result, $this->p($delayedAddNode, self::MAX_PRECEDENCE, self::MAX_PRECEDENCE, true)); if ($insertNewline) { $result .= $insertStr . $this->nl; @@ -824,7 +907,18 @@ protected function pArray( return null; } - if ($insertStr === ', ' && $this->isMultiline($origNodes)) { + if (!$arrItem instanceof Node) { + // We only support list insertion of nodes. + return null; + } + + // We go multiline if the original code was multiline, + // or if it's an array item with a comment above it. + // Match always uses multiline formatting. + if ($insertStr === ', ' && + ($this->isMultiline($origNodes) || $arrItem->getComments() || + $parentNodeClass === Expr\Match_::class) + ) { $insertStr = ','; $insertNewline = true; } @@ -842,11 +936,11 @@ protected function pArray( $this->setIndentLevel($lastElemIndentLevel); if ($insertNewline) { + $result .= $insertStr . $this->nl; $comments = $arrItem->getComments(); if ($comments) { - $result .= $this->nl . $this->pComments($comments); + $result .= $this->pComments($comments) . $this->nl; } - $result .= $insertStr . $this->nl; } else { $result .= $insertStr; } @@ -873,8 +967,8 @@ protected function pArray( $pos, $itemStartPos, $indentAdjustment); $skipRemovedNode = true; } else { - if ($isStmtList && $this->origTokens->haveBracesInRange($pos, $itemStartPos)) { - // We'd remove the brace of a code block. + if ($isStmtList && $this->origTokens->haveTagInRange($pos, $itemStartPos)) { + // We'd remove an opening/closing PHP tag. // TODO: Preserve formatting. return null; } @@ -889,7 +983,7 @@ protected function pArray( if (null !== $fixup && $arrItem->getAttribute('origNode') !== $origArrItem) { $res = $this->pFixup($fixup, $arrItem, null, $itemStartPos, $itemEndPos); } else { - $res = $this->p($arrItem, true); + $res = $this->p($arrItem, self::MAX_PRECEDENCE, self::MAX_PRECEDENCE, true); } $this->safeAppend($result, $res); @@ -919,11 +1013,14 @@ protected function pArray( foreach ($delayedAdd as $delayedAddNode) { if (!$first) { $result .= $insertStr; + if ($insertNewline) { + $result .= $this->nl; + } } - $result .= $this->p($delayedAddNode, true); + $result .= $this->p($delayedAddNode, self::MAX_PRECEDENCE, self::MAX_PRECEDENCE, true); $first = false; } - $result .= $extraRight; + $result .= $extraRight === "\n" ? $this->nl : $extraRight; } return $result; @@ -936,22 +1033,33 @@ protected function pArray( * are required to preserve program semantics in a certain context (e.g. to maintain precedence * or because only certain expressions are allowed in certain places). * - * @param int $fixup Fixup type - * @param Node $subNode Subnode to print + * @param int $fixup Fixup type + * @param Node $subNode Subnode to print * @param string|null $parentClass Class of parent node - * @param int $subStartPos Original start pos of subnode - * @param int $subEndPos Original end pos of subnode + * @param int $subStartPos Original start pos of subnode + * @param int $subEndPos Original end pos of subnode * * @return string Result of fixed-up print of subnode */ - protected function pFixup(int $fixup, Node $subNode, $parentClass, int $subStartPos, int $subEndPos) : string { + protected function pFixup(int $fixup, Node $subNode, ?string $parentClass, int $subStartPos, int $subEndPos): string { switch ($fixup) { case self::FIXUP_PREC_LEFT: + // We use a conservative approximation where lhsPrecedence == precedence. + if (!$this->origTokens->haveParens($subStartPos, $subEndPos)) { + $precedence = $this->precedenceMap[$parentClass][1]; + return $this->p($subNode, $precedence, $precedence); + } + break; case self::FIXUP_PREC_RIGHT: if (!$this->origTokens->haveParens($subStartPos, $subEndPos)) { - list($precedence, $associativity) = $this->precedenceMap[$parentClass]; - return $this->pPrec($subNode, $precedence, $associativity, - $fixup === self::FIXUP_PREC_LEFT ? -1 : 1); + $precedence = $this->precedenceMap[$parentClass][2]; + return $this->p($subNode, $precedence, $precedence); + } + break; + case self::FIXUP_PREC_UNARY: + if (!$this->origTokens->haveParens($subStartPos, $subEndPos)) { + $precedence = $this->precedenceMap[$parentClass][0]; + return $this->p($subNode, $precedence, $precedence); } break; case self::FIXUP_CALL_LHS: @@ -968,6 +1076,19 @@ protected function pFixup(int $fixup, Node $subNode, $parentClass, int $subStart return '(' . $this->p($subNode) . ')'; } break; + case self::FIXUP_STATIC_DEREF_LHS: + if ($this->staticDereferenceLhsRequiresParens($subNode) + && !$this->origTokens->haveParens($subStartPos, $subEndPos) + ) { + return '(' . $this->p($subNode) . ')'; + } + break; + case self::FIXUP_NEW: + if ($this->newOperandRequiresParens($subNode) + && !$this->origTokens->haveParens($subStartPos, $subEndPos)) { + return '(' . $this->p($subNode) . ')'; + } + break; case self::FIXUP_BRACED_NAME: case self::FIXUP_VAR_BRACED_NAME: if ($subNode instanceof Expr @@ -978,7 +1099,7 @@ protected function pFixup(int $fixup, Node $subNode, $parentClass, int $subStart } break; case self::FIXUP_ENCAPSED: - if (!$subNode instanceof Scalar\EncapsedStringPart + if (!$subNode instanceof Node\InterpolatedStringPart && !$this->origTokens->haveBraces($subStartPos, $subEndPos) ) { return '{' . $this->p($subNode) . '}'; @@ -997,11 +1118,8 @@ protected function pFixup(int $fixup, Node $subNode, $parentClass, int $subStart * * Example: "echo" and "$x" result in "echo$x", but "echo" and "x" result in "echo x". * Without safeAppend the result would be "echox", which does not preserve semantics. - * - * @param string $str - * @param string $append */ - protected function safeAppend(string &$str, string $append) { + protected function safeAppend(string &$str, string $append): void { if ($str === "") { $str = $append; return; @@ -1026,7 +1144,7 @@ protected function safeAppend(string &$str, string $append) { * * @return bool Whether parentheses are required */ - protected function callLhsRequiresParens(Node $node) : bool { + protected function callLhsRequiresParens(Node $node): bool { return !($node instanceof Node\Name || $node instanceof Expr\Variable || $node instanceof Expr\ArrayDimFetch @@ -1038,13 +1156,26 @@ protected function callLhsRequiresParens(Node $node) : bool { } /** - * Determines whether the LHS of a dereferencing operation must be wrapped in parenthesis. + * Determines whether the LHS of an array/object operation must be wrapped in parentheses. + * + * @param Node $node LHS of dereferencing operation + * + * @return bool Whether parentheses are required + */ + protected function dereferenceLhsRequiresParens(Node $node): bool { + // A constant can occur on the LHS of an array/object deref, but not a static deref. + return $this->staticDereferenceLhsRequiresParens($node) + && !$node instanceof Expr\ConstFetch; + } + + /** + * Determines whether the LHS of a static operation must be wrapped in parentheses. * * @param Node $node LHS of dereferencing operation * * @return bool Whether parentheses are required */ - protected function dereferenceLhsRequiresParens(Node $node) : bool { + protected function staticDereferenceLhsRequiresParens(Node $node): bool { return !($node instanceof Expr\Variable || $node instanceof Node\Name || $node instanceof Expr\ArrayDimFetch @@ -1057,10 +1188,31 @@ protected function dereferenceLhsRequiresParens(Node $node) : bool { || $node instanceof Expr\StaticCall || $node instanceof Expr\Array_ || $node instanceof Scalar\String_ - || $node instanceof Expr\ConstFetch || $node instanceof Expr\ClassConstFetch); } + /** + * Determines whether an expression used in "new" or "instanceof" requires parentheses. + * + * @param Node $node New or instanceof operand + * + * @return bool Whether parentheses are required + */ + protected function newOperandRequiresParens(Node $node): bool { + if ($node instanceof Node\Name || $node instanceof Expr\Variable) { + return false; + } + if ($node instanceof Expr\ArrayDimFetch || $node instanceof Expr\PropertyFetch || + $node instanceof Expr\NullsafePropertyFetch + ) { + return $this->newOperandRequiresParens($node->var); + } + if ($node instanceof Expr\StaticPropertyFetch) { + return $this->newOperandRequiresParens($node->class); + } + return true; + } + /** * Print modifiers, including trailing whitespace. * @@ -1068,13 +1220,21 @@ protected function dereferenceLhsRequiresParens(Node $node) : bool { * * @return string Printed modifiers */ - protected function pModifiers(int $modifiers) { - return ($modifiers & Stmt\Class_::MODIFIER_PUBLIC ? 'public ' : '') - . ($modifiers & Stmt\Class_::MODIFIER_PROTECTED ? 'protected ' : '') - . ($modifiers & Stmt\Class_::MODIFIER_PRIVATE ? 'private ' : '') - . ($modifiers & Stmt\Class_::MODIFIER_STATIC ? 'static ' : '') - . ($modifiers & Stmt\Class_::MODIFIER_ABSTRACT ? 'abstract ' : '') - . ($modifiers & Stmt\Class_::MODIFIER_FINAL ? 'final ' : ''); + protected function pModifiers(int $modifiers): string { + return ($modifiers & Modifiers::FINAL ? 'final ' : '') + . ($modifiers & Modifiers::ABSTRACT ? 'abstract ' : '') + . ($modifiers & Modifiers::PUBLIC ? 'public ' : '') + . ($modifiers & Modifiers::PROTECTED ? 'protected ' : '') + . ($modifiers & Modifiers::PRIVATE ? 'private ' : '') + . ($modifiers & Modifiers::PUBLIC_SET ? 'public(set) ' : '') + . ($modifiers & Modifiers::PROTECTED_SET ? 'protected(set) ' : '') + . ($modifiers & Modifiers::PRIVATE_SET ? 'private(set) ' : '') + . ($modifiers & Modifiers::STATIC ? 'static ' : '') + . ($modifiers & Modifiers::READONLY ? 'readonly ' : ''); + } + + protected function pStatic(bool $static): string { + return $static ? 'static ' : ''; } /** @@ -1084,7 +1244,7 @@ protected function pModifiers(int $modifiers) { * * @return bool Whether multiline formatting is used */ - protected function isMultiline(array $nodes) : bool { + protected function isMultiline(array $nodes): bool { if (\count($nodes) < 2) { return false; } @@ -1116,14 +1276,19 @@ protected function isMultiline(array $nodes) : bool { * * The label char map determines whether a certain character may occur in a label. */ - protected function initializeLabelCharMap() { - if ($this->labelCharMap) return; + protected function initializeLabelCharMap(): void { + if (isset($this->labelCharMap)) { + return; + } $this->labelCharMap = []; for ($i = 0; $i < 256; $i++) { - // Since PHP 7.1 The lower range is 0x80. However, we also want to support code for - // older versions. - $this->labelCharMap[chr($i)] = $i >= 0x7f || ctype_alnum($i); + $chr = chr($i); + $this->labelCharMap[$chr] = $i >= 0x80 || ctype_alnum($chr); + } + + if ($this->phpVersion->allowsDelInIdentifiers()) { + $this->labelCharMap["\x7f"] = true; } } @@ -1132,8 +1297,10 @@ protected function initializeLabelCharMap() { * * The node list differ is used to determine differences between two array subnodes. */ - protected function initializeNodeListDiffer() { - if ($this->nodeListDiffer) return; + protected function initializeNodeListDiffer(): void { + if (isset($this->nodeListDiffer)) { + return; + } $this->nodeListDiffer = new Internal\Differ(function ($a, $b) { if ($a instanceof Node && $b instanceof Node) { @@ -1150,28 +1317,30 @@ protected function initializeNodeListDiffer() { * The fixup map is used to determine whether a certain subnode of a certain node may require * some kind of "fixup" operation, e.g. the addition of parenthesis or braces. */ - protected function initializeFixupMap() { - if ($this->fixupMap) return; + protected function initializeFixupMap(): void { + if (isset($this->fixupMap)) { + return; + } $this->fixupMap = [ - Expr\PreInc::class => ['var' => self::FIXUP_PREC_RIGHT], - Expr\PreDec::class => ['var' => self::FIXUP_PREC_RIGHT], - Expr\PostInc::class => ['var' => self::FIXUP_PREC_LEFT], - Expr\PostDec::class => ['var' => self::FIXUP_PREC_LEFT], Expr\Instanceof_::class => [ - 'expr' => self::FIXUP_PREC_LEFT, - 'class' => self::FIXUP_PREC_RIGHT, // TODO: FIXUP_NEW_VARIABLE + 'expr' => self::FIXUP_PREC_UNARY, + 'class' => self::FIXUP_NEW, ], Expr\Ternary::class => [ 'cond' => self::FIXUP_PREC_LEFT, 'else' => self::FIXUP_PREC_RIGHT, ], + Expr\Yield_::class => ['value' => self::FIXUP_PREC_UNARY], Expr\FuncCall::class => ['name' => self::FIXUP_CALL_LHS], - Expr\StaticCall::class => ['class' => self::FIXUP_DEREF_LHS], + Expr\StaticCall::class => ['class' => self::FIXUP_STATIC_DEREF_LHS], Expr\ArrayDimFetch::class => ['var' => self::FIXUP_DEREF_LHS], - Expr\ClassConstFetch::class => ['var' => self::FIXUP_DEREF_LHS], - Expr\New_::class => ['class' => self::FIXUP_DEREF_LHS], // TODO: FIXUP_NEW_VARIABLE + Expr\ClassConstFetch::class => [ + 'class' => self::FIXUP_STATIC_DEREF_LHS, + 'name' => self::FIXUP_BRACED_NAME, + ], + Expr\New_::class => ['class' => self::FIXUP_NEW], Expr\MethodCall::class => [ 'var' => self::FIXUP_DEREF_LHS, 'name' => self::FIXUP_BRACED_NAME, @@ -1181,7 +1350,7 @@ protected function initializeFixupMap() { 'name' => self::FIXUP_BRACED_NAME, ], Expr\StaticPropertyFetch::class => [ - 'class' => self::FIXUP_DEREF_LHS, + 'class' => self::FIXUP_STATIC_DEREF_LHS, 'name' => self::FIXUP_VAR_BRACED_NAME, ], Expr\PropertyFetch::class => [ @@ -1192,7 +1361,7 @@ protected function initializeFixupMap() { 'var' => self::FIXUP_DEREF_LHS, 'name' => self::FIXUP_BRACED_NAME, ], - Scalar\Encapsed::class => [ + Scalar\InterpolatedString::class => [ 'parts' => self::FIXUP_ENCAPSED, ], ]; @@ -1206,7 +1375,7 @@ protected function initializeFixupMap() { BinaryOp\NotIdentical::class, BinaryOp\Spaceship::class, BinaryOp\BitwiseAnd::class, BinaryOp\BitwiseXor::class, BinaryOp\BitwiseOr::class, BinaryOp\BooleanAnd::class, BinaryOp\BooleanOr::class, BinaryOp\Coalesce::class, BinaryOp\LogicalAnd::class, - BinaryOp\LogicalXor::class, BinaryOp\LogicalOr::class, + BinaryOp\LogicalXor::class, BinaryOp\LogicalOr::class, BinaryOp\Pipe::class, ]; foreach ($binaryOps as $binaryOp) { $this->fixupMap[$binaryOp] = [ @@ -1215,38 +1384,32 @@ protected function initializeFixupMap() { ]; } - $assignOps = [ - Expr\Assign::class, Expr\AssignRef::class, AssignOp\Plus::class, AssignOp\Minus::class, - AssignOp\Mul::class, AssignOp\Div::class, AssignOp\Concat::class, AssignOp\Mod::class, - AssignOp\BitwiseAnd::class, AssignOp\BitwiseOr::class, AssignOp\BitwiseXor::class, - AssignOp\ShiftLeft::class, AssignOp\ShiftRight::class, AssignOp\Pow::class, AssignOp\Coalesce::class - ]; - foreach ($assignOps as $assignOp) { - $this->fixupMap[$assignOp] = [ - 'var' => self::FIXUP_PREC_LEFT, - 'expr' => self::FIXUP_PREC_RIGHT, - ]; - } - $prefixOps = [ - Expr\BitwiseNot::class, Expr\BooleanNot::class, Expr\UnaryPlus::class, Expr\UnaryMinus::class, + Expr\Clone_::class, Expr\BitwiseNot::class, Expr\BooleanNot::class, Expr\UnaryPlus::class, Expr\UnaryMinus::class, Cast\Int_::class, Cast\Double::class, Cast\String_::class, Cast\Array_::class, Cast\Object_::class, Cast\Bool_::class, Cast\Unset_::class, Expr\ErrorSuppress::class, Expr\YieldFrom::class, Expr\Print_::class, Expr\Include_::class, + Expr\Assign::class, Expr\AssignRef::class, AssignOp\Plus::class, AssignOp\Minus::class, + AssignOp\Mul::class, AssignOp\Div::class, AssignOp\Concat::class, AssignOp\Mod::class, + AssignOp\BitwiseAnd::class, AssignOp\BitwiseOr::class, AssignOp\BitwiseXor::class, + AssignOp\ShiftLeft::class, AssignOp\ShiftRight::class, AssignOp\Pow::class, AssignOp\Coalesce::class, + Expr\ArrowFunction::class, Expr\Throw_::class, ]; foreach ($prefixOps as $prefixOp) { - $this->fixupMap[$prefixOp] = ['expr' => self::FIXUP_PREC_RIGHT]; + $this->fixupMap[$prefixOp] = ['expr' => self::FIXUP_PREC_UNARY]; } } /** * Lazily initializes the removal map. * - * The removal map is used to determine which additional tokens should be returned when a + * The removal map is used to determine which additional tokens should be removed when a * certain node is replaced by null. */ - protected function initializeRemovalMap() { - if ($this->removalMap) return; + protected function initializeRemovalMap(): void { + if (isset($this->removalMap)) { + return; + } $stripBoth = ['left' => \T_WHITESPACE, 'right' => \T_WHITESPACE]; $stripLeft = ['left' => \T_WHITESPACE]; @@ -1256,7 +1419,7 @@ protected function initializeRemovalMap() { $stripEquals = ['left' => '=']; $this->removalMap = [ 'Expr_ArrayDimFetch->dim' => $stripBoth, - 'Expr_ArrayItem->key' => $stripDoubleArrow, + 'ArrayItem->key' => $stripDoubleArrow, 'Expr_ArrowFunction->returnType' => $stripColon, 'Expr_Closure->returnType' => $stripColon, 'Expr_Exit->expr' => $stripBoth, @@ -1267,8 +1430,11 @@ protected function initializeRemovalMap() { 'Param->default' => $stripEquals, 'Stmt_Break->num' => $stripBoth, 'Stmt_Catch->var' => $stripLeft, + 'Stmt_ClassConst->type' => $stripRight, 'Stmt_ClassMethod->returnType' => $stripColon, 'Stmt_Class->extends' => ['left' => \T_EXTENDS], + 'Stmt_Enum->scalarType' => $stripColon, + 'Stmt_EnumCase->expr' => $stripEquals, 'Expr_PrintableNewAnonClass->extends' => ['left' => \T_EXTENDS], 'Stmt_Continue->num' => $stripBoth, 'Stmt_Foreach->keyVar' => $stripDoubleArrow, @@ -1276,7 +1442,7 @@ protected function initializeRemovalMap() { 'Stmt_If->else' => $stripLeft, 'Stmt_Namespace->name' => $stripLeft, 'Stmt_Property->type' => $stripRight, - 'Stmt_PropertyProperty->default' => $stripEquals, + 'PropertyItem->default' => $stripEquals, 'Stmt_Return->expr' => $stripBoth, 'Stmt_StaticVar->default' => $stripEquals, 'Stmt_TraitUseAdaptation_Alias->newName' => $stripLeft, @@ -1288,16 +1454,18 @@ protected function initializeRemovalMap() { ]; } - protected function initializeInsertionMap() { - if ($this->insertionMap) return; + protected function initializeInsertionMap(): void { + if (isset($this->insertionMap)) { + return; + } // TODO: "yield" where both key and value are inserted doesn't work // [$find, $beforeToken, $extraLeft, $extraRight] $this->insertionMap = [ 'Expr_ArrayDimFetch->dim' => ['[', false, null, null], - 'Expr_ArrayItem->key' => [null, false, null, ' => '], - 'Expr_ArrowFunction->returnType' => [')', false, ' : ', null], - 'Expr_Closure->returnType' => [')', false, ' : ', null], + 'ArrayItem->key' => [null, false, null, ' => '], + 'Expr_ArrowFunction->returnType' => [')', false, ': ', null], + 'Expr_Closure->returnType' => [')', false, ': ', null], 'Expr_Ternary->if' => ['?', false, ' ', ' '], 'Expr_Yield->key' => [\T_YIELD, false, null, ' => '], 'Expr_Yield->value' => [\T_YIELD, false, ' ', null], @@ -1305,16 +1473,19 @@ protected function initializeInsertionMap() { 'Param->default' => [null, false, ' = ', null], 'Stmt_Break->num' => [\T_BREAK, false, ' ', null], 'Stmt_Catch->var' => [null, false, ' ', null], - 'Stmt_ClassMethod->returnType' => [')', false, ' : ', null], + 'Stmt_ClassMethod->returnType' => [')', false, ': ', null], + 'Stmt_ClassConst->type' => [\T_CONST, false, ' ', null], 'Stmt_Class->extends' => [null, false, ' extends ', null], - 'Expr_PrintableNewAnonClass->extends' => [null, ' extends ', null], + 'Stmt_Enum->scalarType' => [null, false, ' : ', null], + 'Stmt_EnumCase->expr' => [null, false, ' = ', null], + 'Expr_PrintableNewAnonClass->extends' => [null, false, ' extends ', null], 'Stmt_Continue->num' => [\T_CONTINUE, false, ' ', null], 'Stmt_Foreach->keyVar' => [\T_AS, false, null, ' => '], - 'Stmt_Function->returnType' => [')', false, ' : ', null], + 'Stmt_Function->returnType' => [')', false, ': ', null], 'Stmt_If->else' => [null, false, ' ', null], 'Stmt_Namespace->name' => [\T_NAMESPACE, false, ' ', null], 'Stmt_Property->type' => [\T_VARIABLE, true, null, ' '], - 'Stmt_PropertyProperty->default' => [null, false, ' = ', null], + 'PropertyItem->default' => [null, false, ' = ', null], 'Stmt_Return->expr' => [\T_RETURN, false, ' ', null], 'Stmt_StaticVar->default' => [null, false, ' = ', null], //'Stmt_TraitUseAdaptation_Alias->newName' => [T_AS, false, ' ', null], // TODO @@ -1328,116 +1499,146 @@ protected function initializeInsertionMap() { ]; } - protected function initializeListInsertionMap() { - if ($this->listInsertionMap) return; + protected function initializeListInsertionMap(): void { + if (isset($this->listInsertionMap)) { + return; + } $this->listInsertionMap = [ // special //'Expr_ShellExec->parts' => '', // TODO These need to be treated more carefully - //'Scalar_Encapsed->parts' => '', - 'Stmt_Catch->types' => '|', - 'UnionType->types' => '|', - 'Stmt_If->elseifs' => ' ', - 'Stmt_TryCatch->catches' => ' ', + //'Scalar_InterpolatedString->parts' => '', + Stmt\Catch_::class . '->types' => '|', + UnionType::class . '->types' => '|', + IntersectionType::class . '->types' => '&', + Stmt\If_::class . '->elseifs' => ' ', + Stmt\TryCatch::class . '->catches' => ' ', // comma-separated lists - 'Expr_Array->items' => ', ', - 'Expr_ArrowFunction->params' => ', ', - 'Expr_Closure->params' => ', ', - 'Expr_Closure->uses' => ', ', - 'Expr_FuncCall->args' => ', ', - 'Expr_Isset->vars' => ', ', - 'Expr_List->items' => ', ', - 'Expr_MethodCall->args' => ', ', - 'Expr_NullsafeMethodCall->args' => ', ', - 'Expr_New->args' => ', ', - 'Expr_PrintableNewAnonClass->args' => ', ', - 'Expr_StaticCall->args' => ', ', - 'Stmt_ClassConst->consts' => ', ', - 'Stmt_ClassMethod->params' => ', ', - 'Stmt_Class->implements' => ', ', - 'Expr_PrintableNewAnonClass->implements' => ', ', - 'Stmt_Const->consts' => ', ', - 'Stmt_Declare->declares' => ', ', - 'Stmt_Echo->exprs' => ', ', - 'Stmt_For->init' => ', ', - 'Stmt_For->cond' => ', ', - 'Stmt_For->loop' => ', ', - 'Stmt_Function->params' => ', ', - 'Stmt_Global->vars' => ', ', - 'Stmt_GroupUse->uses' => ', ', - 'Stmt_Interface->extends' => ', ', - 'Stmt_Match->arms' => ', ', - 'Stmt_Property->props' => ', ', - 'Stmt_StaticVar->vars' => ', ', - 'Stmt_TraitUse->traits' => ', ', - 'Stmt_TraitUseAdaptation_Precedence->insteadof' => ', ', - 'Stmt_Unset->vars' => ', ', - 'Stmt_Use->uses' => ', ', - 'MatchArm->conds' => ', ', - 'AttributeGroup->attrs' => ', ', + Expr\Array_::class . '->items' => ', ', + Expr\ArrowFunction::class . '->params' => ', ', + Expr\Closure::class . '->params' => ', ', + Expr\Closure::class . '->uses' => ', ', + Expr\FuncCall::class . '->args' => ', ', + Expr\Isset_::class . '->vars' => ', ', + Expr\List_::class . '->items' => ', ', + Expr\MethodCall::class . '->args' => ', ', + Expr\NullsafeMethodCall::class . '->args' => ', ', + Expr\New_::class . '->args' => ', ', + PrintableNewAnonClassNode::class . '->args' => ', ', + Expr\StaticCall::class . '->args' => ', ', + Stmt\ClassConst::class . '->consts' => ', ', + Stmt\ClassMethod::class . '->params' => ', ', + Stmt\Class_::class . '->implements' => ', ', + Stmt\Enum_::class . '->implements' => ', ', + PrintableNewAnonClassNode::class . '->implements' => ', ', + Stmt\Const_::class . '->consts' => ', ', + Stmt\Declare_::class . '->declares' => ', ', + Stmt\Echo_::class . '->exprs' => ', ', + Stmt\For_::class . '->init' => ', ', + Stmt\For_::class . '->cond' => ', ', + Stmt\For_::class . '->loop' => ', ', + Stmt\Function_::class . '->params' => ', ', + Stmt\Global_::class . '->vars' => ', ', + Stmt\GroupUse::class . '->uses' => ', ', + Stmt\Interface_::class . '->extends' => ', ', + Expr\Match_::class . '->arms' => ', ', + Stmt\Property::class . '->props' => ', ', + Stmt\StaticVar::class . '->vars' => ', ', + Stmt\TraitUse::class . '->traits' => ', ', + Stmt\TraitUseAdaptation\Precedence::class . '->insteadof' => ', ', + Stmt\Unset_::class . '->vars' => ', ', + Stmt\UseUse::class . '->uses' => ', ', + MatchArm::class . '->conds' => ', ', + AttributeGroup::class . '->attrs' => ', ', + PropertyHook::class . '->params' => ', ', // statement lists - 'Expr_Closure->stmts' => "\n", - 'Stmt_Case->stmts' => "\n", - 'Stmt_Catch->stmts' => "\n", - 'Stmt_Class->stmts' => "\n", - 'Expr_PrintableNewAnonClass->stmts' => "\n", - 'Stmt_Interface->stmts' => "\n", - 'Stmt_Trait->stmts' => "\n", - 'Stmt_ClassMethod->stmts' => "\n", - 'Stmt_Declare->stmts' => "\n", - 'Stmt_Do->stmts' => "\n", - 'Stmt_ElseIf->stmts' => "\n", - 'Stmt_Else->stmts' => "\n", - 'Stmt_Finally->stmts' => "\n", - 'Stmt_Foreach->stmts' => "\n", - 'Stmt_For->stmts' => "\n", - 'Stmt_Function->stmts' => "\n", - 'Stmt_If->stmts' => "\n", - 'Stmt_Namespace->stmts' => "\n", - 'Stmt_Class->attrGroups' => "\n", - 'Stmt_Interface->attrGroups' => "\n", - 'Stmt_Trait->attrGroups' => "\n", - 'Stmt_Function->attrGroups' => "\n", - 'Stmt_ClassMethod->attrGroups' => "\n", - 'Stmt_ClassConst->attrGroups' => "\n", - 'Stmt_Property->attrGroups' => "\n", - 'Expr_PrintableNewAnonClass->attrGroups' => ' ', - 'Expr_Closure->attrGroups' => ' ', - 'Expr_ArrowFunction->attrGroups' => ' ', - 'Param->attrGroups' => ' ', - 'Stmt_Switch->cases' => "\n", - 'Stmt_TraitUse->adaptations' => "\n", - 'Stmt_TryCatch->stmts' => "\n", - 'Stmt_While->stmts' => "\n", + Expr\Closure::class . '->stmts' => "\n", + Stmt\Case_::class . '->stmts' => "\n", + Stmt\Catch_::class . '->stmts' => "\n", + Stmt\Class_::class . '->stmts' => "\n", + Stmt\Enum_::class . '->stmts' => "\n", + PrintableNewAnonClassNode::class . '->stmts' => "\n", + Stmt\Interface_::class . '->stmts' => "\n", + Stmt\Trait_::class . '->stmts' => "\n", + Stmt\ClassMethod::class . '->stmts' => "\n", + Stmt\Declare_::class . '->stmts' => "\n", + Stmt\Do_::class . '->stmts' => "\n", + Stmt\ElseIf_::class . '->stmts' => "\n", + Stmt\Else_::class . '->stmts' => "\n", + Stmt\Finally_::class . '->stmts' => "\n", + Stmt\Foreach_::class . '->stmts' => "\n", + Stmt\For_::class . '->stmts' => "\n", + Stmt\Function_::class . '->stmts' => "\n", + Stmt\If_::class . '->stmts' => "\n", + Stmt\Namespace_::class . '->stmts' => "\n", + Stmt\Block::class . '->stmts' => "\n", + + // Attribute groups + Stmt\Class_::class . '->attrGroups' => "\n", + Stmt\Enum_::class . '->attrGroups' => "\n", + Stmt\EnumCase::class . '->attrGroups' => "\n", + Stmt\Interface_::class . '->attrGroups' => "\n", + Stmt\Trait_::class . '->attrGroups' => "\n", + Stmt\Function_::class . '->attrGroups' => "\n", + Stmt\ClassMethod::class . '->attrGroups' => "\n", + Stmt\ClassConst::class . '->attrGroups' => "\n", + Stmt\Property::class . '->attrGroups' => "\n", + PrintableNewAnonClassNode::class . '->attrGroups' => ' ', + Expr\Closure::class . '->attrGroups' => ' ', + Expr\ArrowFunction::class . '->attrGroups' => ' ', + Param::class . '->attrGroups' => ' ', + PropertyHook::class . '->attrGroups' => ' ', + + Stmt\Switch_::class . '->cases' => "\n", + Stmt\TraitUse::class . '->adaptations' => "\n", + Stmt\TryCatch::class . '->stmts' => "\n", + Stmt\While_::class . '->stmts' => "\n", + PropertyHook::class . '->body' => "\n", + Stmt\Property::class . '->hooks' => "\n", + Param::class . '->hooks' => "\n", // dummy for top-level context 'File->stmts' => "\n", ]; } - protected function initializeEmptyListInsertionMap() { - if ($this->emptyListInsertionMap) return; + protected function initializeEmptyListInsertionMap(): void { + if (isset($this->emptyListInsertionMap)) { + return; + } // TODO Insertion into empty statement lists. // [$find, $extraLeft, $extraRight] $this->emptyListInsertionMap = [ - 'Expr_ArrowFunction->params' => ['(', '', ''], - 'Expr_Closure->uses' => [')', ' use(', ')'], - 'Expr_Closure->params' => ['(', '', ''], - 'Expr_FuncCall->args' => ['(', '', ''], - 'Expr_MethodCall->args' => ['(', '', ''], - 'Expr_NullsafeMethodCall->args' => ['(', '', ''], - 'Expr_New->args' => ['(', '', ''], - 'Expr_PrintableNewAnonClass->args' => ['(', '', ''], - 'Expr_PrintableNewAnonClass->implements' => [null, ' implements ', ''], - 'Expr_StaticCall->args' => ['(', '', ''], - 'Stmt_Class->implements' => [null, ' implements ', ''], - 'Stmt_ClassMethod->params' => ['(', '', ''], - 'Stmt_Interface->extends' => [null, ' extends ', ''], - 'Stmt_Function->params' => ['(', '', ''], + Expr\ArrowFunction::class . '->params' => ['(', '', ''], + Expr\Closure::class . '->uses' => [')', ' use (', ')'], + Expr\Closure::class . '->params' => ['(', '', ''], + Expr\FuncCall::class . '->args' => ['(', '', ''], + Expr\MethodCall::class . '->args' => ['(', '', ''], + Expr\NullsafeMethodCall::class . '->args' => ['(', '', ''], + Expr\New_::class . '->args' => ['(', '', ''], + PrintableNewAnonClassNode::class . '->args' => ['(', '', ''], + PrintableNewAnonClassNode::class . '->implements' => [null, ' implements ', ''], + Expr\StaticCall::class . '->args' => ['(', '', ''], + Stmt\Class_::class . '->implements' => [null, ' implements ', ''], + Stmt\Enum_::class . '->implements' => [null, ' implements ', ''], + Stmt\ClassMethod::class . '->params' => ['(', '', ''], + Stmt\Interface_::class . '->extends' => [null, ' extends ', ''], + Stmt\Function_::class . '->params' => ['(', '', ''], + Stmt\Interface_::class . '->attrGroups' => [null, '', "\n"], + Stmt\Class_::class . '->attrGroups' => [null, '', "\n"], + Stmt\ClassConst::class . '->attrGroups' => [null, '', "\n"], + Stmt\ClassMethod::class . '->attrGroups' => [null, '', "\n"], + Stmt\Function_::class . '->attrGroups' => [null, '', "\n"], + Stmt\Property::class . '->attrGroups' => [null, '', "\n"], + Stmt\Trait_::class . '->attrGroups' => [null, '', "\n"], + Expr\ArrowFunction::class . '->attrGroups' => [null, '', ' '], + Expr\Closure::class . '->attrGroups' => [null, '', ' '], + Stmt\Const_::class . '->attrGroups' => [null, '', "\n"], + PrintableNewAnonClassNode::class . '->attrGroups' => [\T_NEW, ' ', ''], /* These cannot be empty to start with: * Expr_Isset->vars @@ -1469,22 +1670,28 @@ protected function initializeEmptyListInsertionMap() { ]; } - protected function initializeModifierChangeMap() { - if ($this->modifierChangeMap) return; + protected function initializeModifierChangeMap(): void { + if (isset($this->modifierChangeMap)) { + return; + } $this->modifierChangeMap = [ - 'Stmt_ClassConst->flags' => \T_CONST, - 'Stmt_ClassMethod->flags' => \T_FUNCTION, - 'Stmt_Class->flags' => \T_CLASS, - 'Stmt_Property->flags' => \T_VARIABLE, - 'Param->flags' => \T_VARIABLE, - //'Stmt_TraitUseAdaptation_Alias->newModifier' => 0, // TODO + Stmt\ClassConst::class . '->flags' => ['pModifiers', \T_CONST], + Stmt\ClassMethod::class . '->flags' => ['pModifiers', \T_FUNCTION], + Stmt\Class_::class . '->flags' => ['pModifiers', \T_CLASS], + Stmt\Property::class . '->flags' => ['pModifiers', \T_VARIABLE], + PrintableNewAnonClassNode::class . '->flags' => ['pModifiers', \T_CLASS], + Param::class . '->flags' => ['pModifiers', \T_VARIABLE], + PropertyHook::class . '->flags' => ['pModifiers', \T_STRING], + Expr\Closure::class . '->static' => ['pStatic', \T_FUNCTION], + Expr\ArrowFunction::class . '->static' => ['pStatic', \T_FN], + //Stmt\TraitUseAdaptation\Alias::class . '->newModifier' => 0, // TODO ]; // List of integer subnodes that are not modifiers: // Expr_Include->type // Stmt_GroupUse->type // Stmt_Use->type - // Stmt_UseUse->type + // UseItem->type } } diff --git a/lib/PhpParser/Token.php b/lib/PhpParser/Token.php new file mode 100644 index 0000000000..6683310f16 --- /dev/null +++ b/lib/PhpParser/Token.php @@ -0,0 +1,18 @@ +pos + \strlen($this->text); + } + + /** Get 1-based end line number of the token. */ + public function getEndLine(): int { + return $this->line + \substr_count($this->text, "\n"); + } +} diff --git a/lib/PhpParser/compatibility_tokens.php b/lib/PhpParser/compatibility_tokens.php new file mode 100644 index 0000000000..ced038d47f --- /dev/null +++ b/lib/PhpParser/compatibility_tokens.php @@ -0,0 +1,71 @@ +\|null but return statement is missing\.$#' + identifier: return.missing + count: 1 + path: lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php + + - + message: '#^Method PhpParser\\NodeVisitor\\NodeConnectingVisitor\:\:enterNode\(\) should return array\\|int\|PhpParser\\Node\|null but return statement is missing\.$#' + identifier: return.missing + count: 1 + path: lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php + + - + message: '#^Method PhpParser\\NodeVisitor\\NodeConnectingVisitor\:\:leaveNode\(\) should return array\\|int\|PhpParser\\Node\|null but return statement is missing\.$#' + identifier: return.missing + count: 1 + path: lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php + + - + message: '#^Method PhpParser\\NodeVisitor\\ParentConnectingVisitor\:\:beforeTraverse\(\) should return array\\|null but return statement is missing\.$#' + identifier: return.missing + count: 1 + path: lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php + + - + message: '#^Method PhpParser\\NodeVisitor\\ParentConnectingVisitor\:\:enterNode\(\) should return array\\|int\|PhpParser\\Node\|null but return statement is missing\.$#' + identifier: return.missing + count: 1 + path: lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php + + - + message: '#^Method PhpParser\\NodeVisitor\\ParentConnectingVisitor\:\:leaveNode\(\) should return array\\|int\|PhpParser\\Node\|null but return statement is missing\.$#' + identifier: return.missing + count: 1 + path: lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php + + - + message: '#^Access to undefined constant static\(PhpParser\\ParserAbstract\)\:\:T_ECHO\.$#' + identifier: classConstant.notFound + count: 1 + path: lib/PhpParser/ParserAbstract.php + + - + message: '#^Unary operation "\+" on string results in an error\.$#' + identifier: unaryOp.invalid + count: 1 + path: lib/PhpParser/ParserAbstract.php + + - + message: '#^Variable \$action might not be defined\.$#' + identifier: variable.undefined + count: 1 + path: lib/PhpParser/ParserAbstract.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000000..af91012549 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,8 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: 6 + paths: + - lib + treatPhpDocTypesAsCertain: false diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5271264cbf..daf6142cad 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,6 +4,7 @@ xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" backupGlobals="false" colors="true" + convertDeprecationsToExceptions="true" beStrictAboutTestsThatDoNotTestAnything="false" bootstrap="./test/bootstrap.php"> @@ -12,9 +13,9 @@ - - + + ./lib/PhpParser/ - - + + diff --git a/test/PhpParser/Builder/ClassConstTest.php b/test/PhpParser/Builder/ClassConstTest.php index 0e88e073e7..ac6590b417 100644 --- a/test/PhpParser/Builder/ClassConstTest.php +++ b/test/PhpParser/Builder/ClassConstTest.php @@ -3,20 +3,24 @@ namespace PhpParser\Builder; use PhpParser\Comment; +use PhpParser\Modifiers; +use PhpParser\Node\Arg; +use PhpParser\Node\Attribute; +use PhpParser\Node\AttributeGroup; use PhpParser\Node\Const_; use PhpParser\Node\Expr; +use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PhpParser\Node\Scalar; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Stmt; -class ClassConstTest extends \PHPUnit\Framework\TestCase -{ +class ClassConstTest extends \PHPUnit\Framework\TestCase { public function createClassConstBuilder($name, $value) { return new ClassConst($name, $value); } - public function testModifiers() { + public function testModifiers(): void { $node = $this->createClassConstBuilder("TEST", 1) ->makePrivate() ->getNode() @@ -25,9 +29,9 @@ public function testModifiers() { $this->assertEquals( new Stmt\ClassConst( [ - new Const_("TEST", new LNumber(1)) + new Const_("TEST", new Int_(1)) ], - Stmt\Class_::MODIFIER_PRIVATE + Modifiers::PRIVATE ), $node ); @@ -40,9 +44,9 @@ public function testModifiers() { $this->assertEquals( new Stmt\ClassConst( [ - new Const_("TEST", new LNumber(1) ) + new Const_("TEST", new Int_(1)) ], - Stmt\Class_::MODIFIER_PROTECTED + Modifiers::PROTECTED ), $node ); @@ -55,16 +59,31 @@ public function testModifiers() { $this->assertEquals( new Stmt\ClassConst( [ - new Const_("TEST", new LNumber(1) ) + new Const_("TEST", new Int_(1)) ], - Stmt\Class_::MODIFIER_PUBLIC + Modifiers::PUBLIC + ), + $node + ); + + $node = $this->createClassConstBuilder("TEST", 1) + ->makeFinal() + ->getNode() + ; + + $this->assertEquals( + new Stmt\ClassConst( + [ + new Const_("TEST", new Int_(1)) + ], + Modifiers::FINAL ), $node ); } - public function testDocComment() { - $node = $this->createClassConstBuilder('TEST',1) + public function testDocComment(): void { + $node = $this->createClassConstBuilder('TEST', 1) ->setDocComment('/** Test */') ->makePublic() ->getNode(); @@ -72,9 +91,9 @@ public function testDocComment() { $this->assertEquals( new Stmt\ClassConst( [ - new Const_("TEST", new LNumber(1) ) + new Const_("TEST", new Int_(1)) ], - Stmt\Class_::MODIFIER_PUBLIC, + Modifiers::PUBLIC, [ 'comments' => [new Comment\Doc('/** Test */')] ] @@ -83,26 +102,62 @@ public function testDocComment() { ); } - public function testAddConst() { - $node = $this->createClassConstBuilder('FIRST_TEST',1) - ->addConst("SECOND_TEST",2) + public function testAddConst(): void { + $node = $this->createClassConstBuilder('FIRST_TEST', 1) + ->addConst("SECOND_TEST", 2) ->getNode(); $this->assertEquals( new Stmt\ClassConst( [ - new Const_("FIRST_TEST", new LNumber(1)), - new Const_("SECOND_TEST", new LNumber(2)) + new Const_("FIRST_TEST", new Int_(1)), + new Const_("SECOND_TEST", new Int_(2)) ] ), $node ); } + public function testAddAttribute(): void { + $attribute = new Attribute( + new Name('Attr'), + [new Arg(new Int_(1), false, false, [], new Identifier('name'))] + ); + $attributeGroup = new AttributeGroup([$attribute]); + + $node = $this->createClassConstBuilder('ATTR_GROUP', 1) + ->addAttribute($attributeGroup) + ->getNode(); + + $this->assertEquals( + new Stmt\ClassConst( + [ + new Const_("ATTR_GROUP", new Int_(1)) + ], + 0, + [], + [$attributeGroup] + ), + $node + ); + } + + public function testType(): void { + $node = $this->createClassConstBuilder('TYPE', 1) + ->setType('int') + ->getNode(); + $this->assertEquals( + new Stmt\ClassConst( + [new Const_('TYPE', new Int_(1))], + 0, [], [], new Identifier('int')), + $node + ); + } + /** * @dataProvider provideTestDefaultValues */ - public function testValues($value, $expectedValueNode) { + public function testValues($value, $expectedValueNode): void { $node = $this->createClassConstBuilder('TEST', $value) ->getNode() ; @@ -110,7 +165,7 @@ public function testValues($value, $expectedValueNode) { $this->assertEquals($expectedValueNode, $node->consts[0]->value); } - public function provideTestDefaultValues() { + public static function provideTestDefaultValues() { return [ [ null, @@ -126,11 +181,11 @@ public function provideTestDefaultValues() { ], [ 31415, - new Scalar\LNumber(31415) + new Scalar\Int_(31415) ], [ 3.1415, - new Scalar\DNumber(3.1415) + new Scalar\Float_(3.1415) ], [ 'Hallo World', @@ -139,27 +194,27 @@ public function provideTestDefaultValues() { [ [1, 2, 3], new Expr\Array_([ - new Expr\ArrayItem(new Scalar\LNumber(1)), - new Expr\ArrayItem(new Scalar\LNumber(2)), - new Expr\ArrayItem(new Scalar\LNumber(3)), + new \PhpParser\Node\ArrayItem(new Scalar\Int_(1)), + new \PhpParser\Node\ArrayItem(new Scalar\Int_(2)), + new \PhpParser\Node\ArrayItem(new Scalar\Int_(3)), ]) ], [ ['foo' => 'bar', 'bar' => 'foo'], new Expr\Array_([ - new Expr\ArrayItem( + new \PhpParser\Node\ArrayItem( new Scalar\String_('bar'), new Scalar\String_('foo') ), - new Expr\ArrayItem( + new \PhpParser\Node\ArrayItem( new Scalar\String_('foo'), new Scalar\String_('bar') ), ]) ], [ - new Scalar\MagicConst\Dir, - new Scalar\MagicConst\Dir + new Scalar\MagicConst\Dir(), + new Scalar\MagicConst\Dir() ] ]; } diff --git a/test/PhpParser/Builder/ClassTest.php b/test/PhpParser/Builder/ClassTest.php index 2cfa787231..69866b7b79 100644 --- a/test/PhpParser/Builder/ClassTest.php +++ b/test/PhpParser/Builder/ClassTest.php @@ -3,17 +3,22 @@ namespace PhpParser\Builder; use PhpParser\Comment; +use PhpParser\Modifiers; use PhpParser\Node; +use PhpParser\Node\Arg; +use PhpParser\Node\Attribute; +use PhpParser\Node\AttributeGroup; +use PhpParser\Node\Identifier; use PhpParser\Node\Name; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Stmt; -class ClassTest extends \PHPUnit\Framework\TestCase -{ +class ClassTest extends \PHPUnit\Framework\TestCase { protected function createClassBuilder($class) { return new Class_($class); } - public function testExtendsImplements() { + public function testExtendsImplements(): void { $node = $this->createClassBuilder('SomeLogger') ->extend('BaseLogger') ->implement('Namespaced\Logger', new Name('SomeInterface')) @@ -35,7 +40,7 @@ public function testExtendsImplements() { ); } - public function testAbstract() { + public function testAbstract(): void { $node = $this->createClassBuilder('Test') ->makeAbstract() ->getNode() @@ -43,13 +48,13 @@ public function testAbstract() { $this->assertEquals( new Stmt\Class_('Test', [ - 'flags' => Stmt\Class_::MODIFIER_ABSTRACT + 'flags' => Modifiers::ABSTRACT ]), $node ); } - public function testFinal() { + public function testFinal(): void { $node = $this->createClassBuilder('Test') ->makeFinal() ->getNode() @@ -57,17 +62,31 @@ public function testFinal() { $this->assertEquals( new Stmt\Class_('Test', [ - 'flags' => Stmt\Class_::MODIFIER_FINAL + 'flags' => Modifiers::FINAL ]), $node ); } - public function testStatementOrder() { + public function testReadonly(): void { + $node = $this->createClassBuilder('Test') + ->makeReadonly() + ->getNode() + ; + + $this->assertEquals( + new Stmt\Class_('Test', [ + 'flags' => Modifiers::READONLY + ]), + $node + ); + } + + public function testStatementOrder(): void { $method = new Stmt\ClassMethod('testMethod'); $property = new Stmt\Property( - Stmt\Class_::MODIFIER_PUBLIC, - [new Stmt\PropertyProperty('testProperty')] + Modifiers::PUBLIC, + [new Node\PropertyItem('testProperty')] ); $const = new Stmt\ClassConst([ new Node\Const_('TEST_CONST', new Node\Scalar\String_('ABC')) @@ -89,7 +108,7 @@ public function testStatementOrder() { ); } - public function testDocComment() { + public function testDocComment(): void { $docComment = <<<'DOC' /** * Test @@ -122,7 +141,28 @@ public function testDocComment() { ); } - public function testInvalidStmtError() { + public function testAddAttribute(): void { + $attribute = new Attribute( + new Name('Attr'), + [new Arg(new Int_(1), false, false, [], new Identifier('name'))] + ); + $attributeGroup = new AttributeGroup([$attribute]); + + $class = $this->createClassBuilder('ATTR_GROUP') + ->addAttribute($attributeGroup) + ->getNode(); + + $this->assertEquals( + new Stmt\Class_('ATTR_GROUP', [ + 'attrGroups' => [ + $attributeGroup, + ] + ], []), + $class + ); + } + + public function testInvalidStmtError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Unexpected node of type "Stmt_Echo"'); $this->createClassBuilder('Test') @@ -130,21 +170,21 @@ public function testInvalidStmtError() { ; } - public function testInvalidDocComment() { + public function testInvalidDocComment(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Doc comment must be a string or an instance of PhpParser\Comment\Doc'); $this->createClassBuilder('Test') ->setDocComment(new Comment('Test')); } - public function testEmptyName() { + public function testEmptyName(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Name cannot be empty'); $this->createClassBuilder('Test') ->extend(''); } - public function testInvalidName() { + public function testInvalidName(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Name must be a string or an instance of Node\Name'); $this->createClassBuilder('Test') diff --git a/test/PhpParser/Builder/EnumCaseTest.php b/test/PhpParser/Builder/EnumCaseTest.php new file mode 100644 index 0000000000..04c032c118 --- /dev/null +++ b/test/PhpParser/Builder/EnumCaseTest.php @@ -0,0 +1,83 @@ +createEnumCaseBuilder('TEST') + ->setDocComment('/** Test */') + ->getNode(); + + $this->assertEquals( + new Stmt\EnumCase( + "TEST", + null, + [], + [ + 'comments' => [new Comment\Doc('/** Test */')] + ] + ), + $node + ); + } + + public function testAddAttribute(): void { + $attribute = new Attribute( + new Name('Attr'), + [new Arg(new Int_(1), false, false, [], new Identifier('name'))] + ); + $attributeGroup = new AttributeGroup([$attribute]); + + $node = $this->createEnumCaseBuilder('ATTR_GROUP') + ->addAttribute($attributeGroup) + ->getNode(); + + $this->assertEquals( + new Stmt\EnumCase( + "ATTR_GROUP", + null, + [$attributeGroup] + ), + $node + ); + } + + /** + * @dataProvider provideTestDefaultValues + */ + public function testValues($value, $expectedValueNode): void { + $node = $this->createEnumCaseBuilder('TEST') + ->setValue($value) + ->getNode() + ; + + $this->assertEquals($expectedValueNode, $node->expr); + } + + public static function provideTestDefaultValues() { + return [ + [ + 31415, + new Scalar\Int_(31415) + ], + [ + 'Hallo World', + new Scalar\String_('Hallo World') + ], + ]; + } +} diff --git a/test/PhpParser/Builder/EnumTest.php b/test/PhpParser/Builder/EnumTest.php new file mode 100644 index 0000000000..f62392a26c --- /dev/null +++ b/test/PhpParser/Builder/EnumTest.php @@ -0,0 +1,158 @@ +createEnumBuilder('SomeEnum') + ->implement('Namespaced\SomeInterface', new Name('OtherInterface')) + ->getNode() + ; + + $this->assertEquals( + new Stmt\Enum_('SomeEnum', [ + 'implements' => [ + new Name('Namespaced\SomeInterface'), + new Name('OtherInterface'), + ], + ]), + $node + ); + } + + public function testSetScalarType(): void { + $node = $this->createEnumBuilder('Test') + ->setScalarType('int') + ->getNode() + ; + + $this->assertEquals( + new Stmt\Enum_('Test', [ + 'scalarType' => new Identifier('int'), + ]), + $node + ); + } + + public function testStatementOrder(): void { + $method = new Stmt\ClassMethod('testMethod'); + $enumCase = new Stmt\EnumCase( + 'TEST_ENUM_CASE' + ); + $const = new Stmt\ClassConst([ + new Node\Const_('TEST_CONST', new Node\Scalar\String_('ABC')) + ]); + $use = new Stmt\TraitUse([new Name('SomeTrait')]); + + $node = $this->createEnumBuilder('Test') + ->addStmt($method) + ->addStmt($enumCase) + ->addStmts([$const, $use]) + ->getNode() + ; + + $this->assertEquals( + new Stmt\Enum_('Test', [ + 'stmts' => [$use, $enumCase, $const, $method] + ]), + $node + ); + } + + public function testDocComment(): void { + $docComment = <<<'DOC' +/** + * Test + */ +DOC; + $enum = $this->createEnumBuilder('Test') + ->setDocComment($docComment) + ->getNode(); + + $this->assertEquals( + new Stmt\Enum_('Test', [], [ + 'comments' => [ + new Comment\Doc($docComment) + ] + ]), + $enum + ); + + $enum = $this->createEnumBuilder('Test') + ->setDocComment(new Comment\Doc($docComment)) + ->getNode(); + + $this->assertEquals( + new Stmt\Enum_('Test', [], [ + 'comments' => [ + new Comment\Doc($docComment) + ] + ]), + $enum + ); + } + + public function testAddAttribute(): void { + $attribute = new Attribute( + new Name('Attr'), + [new Arg(new Int_(1), false, false, [], new Identifier('name'))] + ); + $attributeGroup = new AttributeGroup([$attribute]); + + $enum = $this->createEnumBuilder('ATTR_GROUP') + ->addAttribute($attributeGroup) + ->getNode(); + + $this->assertEquals( + new Stmt\Enum_('ATTR_GROUP', [ + 'attrGroups' => [ + $attributeGroup, + ] + ], []), + $enum + ); + } + + public function testInvalidStmtError(): void { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Unexpected node of type "PropertyItem"'); + $this->createEnumBuilder('Test') + ->addStmt(new Node\PropertyItem('property')) + ; + } + + public function testInvalidDocComment(): void { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Doc comment must be a string or an instance of PhpParser\Comment\Doc'); + $this->createEnumBuilder('Test') + ->setDocComment(new Comment('Test')); + } + + public function testEmptyName(): void { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Name cannot be empty'); + $this->createEnumBuilder('Test') + ->implement(''); + } + + public function testInvalidName(): void { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Name must be a string or an instance of Node\Name'); + $this->createEnumBuilder('Test') + ->implement(['Foo']); + } +} diff --git a/test/PhpParser/Builder/FunctionTest.php b/test/PhpParser/Builder/FunctionTest.php index c17045b83f..1b60112731 100644 --- a/test/PhpParser/Builder/FunctionTest.php +++ b/test/PhpParser/Builder/FunctionTest.php @@ -4,18 +4,23 @@ use PhpParser\Comment; use PhpParser\Node; +use PhpParser\Node\Arg; +use PhpParser\Node\Attribute; +use PhpParser\Node\AttributeGroup; use PhpParser\Node\Expr\Print_; use PhpParser\Node\Expr\Variable; +use PhpParser\Node\Identifier; +use PhpParser\Node\Name; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt; -class FunctionTest extends \PHPUnit\Framework\TestCase -{ +class FunctionTest extends \PHPUnit\Framework\TestCase { public function createFunctionBuilder($name) { return new Function_($name); } - public function testReturnByRef() { + public function testReturnByRef(): void { $node = $this->createFunctionBuilder('test') ->makeReturnByRef() ->getNode() @@ -29,7 +34,7 @@ public function testReturnByRef() { ); } - public function testParams() { + public function testParams(): void { $param1 = new Node\Param(new Variable('test1')); $param2 = new Node\Param(new Variable('test2')); $param3 = new Node\Param(new Variable('test3')); @@ -48,7 +53,7 @@ public function testParams() { ); } - public function testStmts() { + public function testStmts(): void { $stmt1 = new Print_(new String_('test1')); $stmt2 = new Print_(new String_('test2')); $stmt3 = new Print_(new String_('test3')); @@ -71,7 +76,7 @@ public function testStmts() { ); } - public function testDocComment() { + public function testDocComment(): void { $node = $this->createFunctionBuilder('test') ->setDocComment('/** Test */') ->getNode(); @@ -81,23 +86,39 @@ public function testDocComment() { ]), $node); } - public function testReturnType() { + public function testAddAttribute(): void { + $attribute = new Attribute( + new Name('Attr'), + [new Arg(new Int_(1), false, false, [], new Identifier('name'))] + ); + $attributeGroup = new AttributeGroup([$attribute]); + + $node = $this->createFunctionBuilder('attrGroup') + ->addAttribute($attributeGroup) + ->getNode(); + + $this->assertEquals(new Stmt\Function_('attrGroup', [ + 'attrGroups' => [$attributeGroup], + ], []), $node); + } + + public function testReturnType(): void { $node = $this->createFunctionBuilder('test') ->setReturnType('void') ->getNode(); $this->assertEquals(new Stmt\Function_('test', [ - 'returnType' => 'void' + 'returnType' => new Identifier('void'), ], []), $node); } - public function testInvalidNullableVoidType() { + public function testInvalidNullableVoidType(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('void type cannot be nullable'); $this->createFunctionBuilder('test')->setReturnType('?void'); } - public function testInvalidParamError() { + public function testInvalidParamError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected parameter node, got "Name"'); $this->createFunctionBuilder('test') @@ -105,7 +126,7 @@ public function testInvalidParamError() { ; } - public function testAddNonStmt() { + public function testAddNonStmt(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected statement or expression node'); $this->createFunctionBuilder('test') diff --git a/test/PhpParser/Builder/InterfaceTest.php b/test/PhpParser/Builder/InterfaceTest.php index 63ce6b9859..75f2ed7d27 100644 --- a/test/PhpParser/Builder/InterfaceTest.php +++ b/test/PhpParser/Builder/InterfaceTest.php @@ -4,27 +4,32 @@ use PhpParser\Comment; use PhpParser\Node; -use PhpParser\Node\Scalar\DNumber; +use PhpParser\Node\Arg; +use PhpParser\Node\Attribute; +use PhpParser\Node\AttributeGroup; +use PhpParser\Node\Identifier; +use PhpParser\Node\Name; +use PhpParser\Node\Scalar\Float_; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Stmt; -class InterfaceTest extends \PHPUnit\Framework\TestCase -{ +class InterfaceTest extends \PHPUnit\Framework\TestCase { protected function createInterfaceBuilder() { return new Interface_('Contract'); } private function dump($node) { - $pp = new \PhpParser\PrettyPrinter\Standard; + $pp = new \PhpParser\PrettyPrinter\Standard(); return $pp->prettyPrint([$node]); } - public function testEmpty() { + public function testEmpty(): void { $contract = $this->createInterfaceBuilder()->getNode(); $this->assertInstanceOf(Stmt\Interface_::class, $contract); $this->assertEquals(new Node\Identifier('Contract'), $contract->name); } - public function testExtending() { + public function testExtending(): void { $contract = $this->createInterfaceBuilder() ->extend('Space\Root1', 'Root2')->getNode(); $this->assertEquals( @@ -37,23 +42,23 @@ public function testExtending() { ); } - public function testAddMethod() { + public function testAddMethod(): void { $method = new Stmt\ClassMethod('doSomething'); $contract = $this->createInterfaceBuilder()->addStmt($method)->getNode(); $this->assertSame([$method], $contract->stmts); } - public function testAddConst() { + public function testAddConst(): void { $const = new Stmt\ClassConst([ - new Node\Const_('SPEED_OF_LIGHT', new DNumber(299792458.0)) + new Node\Const_('SPEED_OF_LIGHT', new Float_(299792458.0)) ]); $contract = $this->createInterfaceBuilder()->addStmt($const)->getNode(); $this->assertSame(299792458.0, $contract->stmts[0]->consts[0]->value->value); } - public function testOrder() { + public function testOrder(): void { $const = new Stmt\ClassConst([ - new Node\Const_('SPEED_OF_LIGHT', new DNumber(299792458)) + new Node\Const_('SPEED_OF_LIGHT', new Float_(299792458)) ]); $method = new Stmt\ClassMethod('doSomething'); $contract = $this->createInterfaceBuilder() @@ -66,7 +71,7 @@ public function testOrder() { $this->assertInstanceOf(Stmt\ClassMethod::class, $contract->stmts[1]); } - public function testDocComment() { + public function testDocComment(): void { $node = $this->createInterfaceBuilder() ->setDocComment('/** Test */') ->getNode(); @@ -76,15 +81,31 @@ public function testDocComment() { ]), $node); } - public function testInvalidStmtError() { + public function testAddAttribute(): void { + $attribute = new Attribute( + new Name('Attr'), + [new Arg(new Int_(1), false, false, [], new Identifier('name'))] + ); + $attributeGroup = new AttributeGroup([$attribute]); + + $node = $this->createInterfaceBuilder() + ->addAttribute($attributeGroup) + ->getNode(); + + $this->assertEquals(new Stmt\Interface_('Contract', [ + 'attrGroups' => [$attributeGroup], + ], []), $node); + } + + public function testInvalidStmtError(): void { $this->expectException(\LogicException::class); - $this->expectExceptionMessage('Unexpected node of type "Stmt_PropertyProperty"'); - $this->createInterfaceBuilder()->addStmt(new Stmt\PropertyProperty('invalid')); + $this->expectExceptionMessage('Unexpected node of type "PropertyItem"'); + $this->createInterfaceBuilder()->addStmt(new Node\PropertyItem('invalid')); } - public function testFullFunctional() { + public function testFullFunctional(): void { $const = new Stmt\ClassConst([ - new Node\Const_('SPEED_OF_LIGHT', new DNumber(299792458)) + new Node\Const_('SPEED_OF_LIGHT', new Float_(299792458)) ]); $method = new Stmt\ClassMethod('doSomething'); $contract = $this->createInterfaceBuilder() diff --git a/test/PhpParser/Builder/MethodTest.php b/test/PhpParser/Builder/MethodTest.php index 529f035497..a5ff8f7c80 100644 --- a/test/PhpParser/Builder/MethodTest.php +++ b/test/PhpParser/Builder/MethodTest.php @@ -3,19 +3,25 @@ namespace PhpParser\Builder; use PhpParser\Comment; +use PhpParser\Modifiers; use PhpParser\Node; +use PhpParser\Node\Arg; +use PhpParser\Node\Attribute; +use PhpParser\Node\AttributeGroup; use PhpParser\Node\Expr\Print_; use PhpParser\Node\Expr\Variable; +use PhpParser\Node\Identifier; +use PhpParser\Node\Name; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt; -class MethodTest extends \PHPUnit\Framework\TestCase -{ +class MethodTest extends \PHPUnit\Framework\TestCase { public function createMethodBuilder($name) { return new Method($name); } - public function testModifiers() { + public function testModifiers(): void { $node = $this->createMethodBuilder('test') ->makePublic() ->makeAbstract() @@ -25,9 +31,7 @@ public function testModifiers() { $this->assertEquals( new Stmt\ClassMethod('test', [ - 'flags' => Stmt\Class_::MODIFIER_PUBLIC - | Stmt\Class_::MODIFIER_ABSTRACT - | Stmt\Class_::MODIFIER_STATIC, + 'flags' => Modifiers::PUBLIC | Modifiers::ABSTRACT | Modifiers::STATIC, 'stmts' => null, ]), $node @@ -41,8 +45,7 @@ public function testModifiers() { $this->assertEquals( new Stmt\ClassMethod('test', [ - 'flags' => Stmt\Class_::MODIFIER_PROTECTED - | Stmt\Class_::MODIFIER_FINAL + 'flags' => Modifiers::PROTECTED | Modifiers::FINAL ]), $node ); @@ -54,13 +57,13 @@ public function testModifiers() { $this->assertEquals( new Stmt\ClassMethod('test', [ - 'type' => Stmt\Class_::MODIFIER_PRIVATE + 'type' => Modifiers::PRIVATE ]), $node ); } - public function testReturnByRef() { + public function testReturnByRef(): void { $node = $this->createMethodBuilder('test') ->makeReturnByRef() ->getNode() @@ -74,7 +77,7 @@ public function testReturnByRef() { ); } - public function testParams() { + public function testParams(): void { $param1 = new Node\Param(new Variable('test1')); $param2 = new Node\Param(new Variable('test2')); $param3 = new Node\Param(new Variable('test3')); @@ -93,7 +96,7 @@ public function testParams() { ); } - public function testStmts() { + public function testStmts(): void { $stmt1 = new Print_(new String_('test1')); $stmt2 = new Print_(new String_('test2')); $stmt3 = new Print_(new String_('test3')); @@ -115,7 +118,7 @@ public function testStmts() { $node ); } - public function testDocComment() { + public function testDocComment(): void { $node = $this->createMethodBuilder('test') ->setDocComment('/** Test */') ->getNode(); @@ -125,16 +128,32 @@ public function testDocComment() { ]), $node); } - public function testReturnType() { + public function testAddAttribute(): void { + $attribute = new Attribute( + new Name('Attr'), + [new Arg(new Int_(1), false, false, [], new Identifier('name'))] + ); + $attributeGroup = new AttributeGroup([$attribute]); + + $node = $this->createMethodBuilder('attributeGroup') + ->addAttribute($attributeGroup) + ->getNode(); + + $this->assertEquals(new Stmt\ClassMethod('attributeGroup', [ + 'attrGroups' => [$attributeGroup], + ], []), $node); + } + + public function testReturnType(): void { $node = $this->createMethodBuilder('test') ->setReturnType('bool') ->getNode(); $this->assertEquals(new Stmt\ClassMethod('test', [ - 'returnType' => 'bool' + 'returnType' => new Identifier('bool'), ], []), $node); } - public function testAddStmtToAbstractMethodError() { + public function testAddStmtToAbstractMethodError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot add statements to an abstract method'); $this->createMethodBuilder('test') @@ -143,7 +162,7 @@ public function testAddStmtToAbstractMethodError() { ; } - public function testMakeMethodWithStmtsAbstractError() { + public function testMakeMethodWithStmtsAbstractError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot make method with statements abstract'); $this->createMethodBuilder('test') @@ -152,7 +171,7 @@ public function testMakeMethodWithStmtsAbstractError() { ; } - public function testInvalidParamError() { + public function testInvalidParamError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected parameter node, got "Name"'); $this->createMethodBuilder('test') diff --git a/test/PhpParser/Builder/NamespaceTest.php b/test/PhpParser/Builder/NamespaceTest.php index 689001bcbe..2cce107f47 100644 --- a/test/PhpParser/Builder/NamespaceTest.php +++ b/test/PhpParser/Builder/NamespaceTest.php @@ -6,13 +6,12 @@ use PhpParser\Node; use PhpParser\Node\Stmt; -class NamespaceTest extends \PHPUnit\Framework\TestCase -{ +class NamespaceTest extends \PHPUnit\Framework\TestCase { protected function createNamespaceBuilder($fqn) { return new Namespace_($fqn); } - public function testCreation() { + public function testCreation(): void { $stmt1 = new Stmt\Class_('SomeClass'); $stmt2 = new Stmt\Interface_('SomeInterface'); $stmt3 = new Stmt\Function_('someFunction'); diff --git a/test/PhpParser/Builder/ParamTest.php b/test/PhpParser/Builder/ParamTest.php index 781fffa6f3..56eee0a726 100644 --- a/test/PhpParser/Builder/ParamTest.php +++ b/test/PhpParser/Builder/ParamTest.php @@ -2,12 +2,18 @@ namespace PhpParser\Builder; +use PhpParser\Modifiers; use PhpParser\Node; +use PhpParser\Node\Arg; +use PhpParser\Node\Attribute; +use PhpParser\Node\AttributeGroup; use PhpParser\Node\Expr; +use PhpParser\Node\Identifier; +use PhpParser\Node\Name; use PhpParser\Node\Scalar; +use PhpParser\Node\Scalar\Int_; -class ParamTest extends \PHPUnit\Framework\TestCase -{ +class ParamTest extends \PHPUnit\Framework\TestCase { public function createParamBuilder($name) { return new Param($name); } @@ -15,7 +21,7 @@ public function createParamBuilder($name) { /** * @dataProvider provideTestDefaultValues */ - public function testDefaultValues($value, $expectedValueNode) { + public function testDefaultValues($value, $expectedValueNode): void { $node = $this->createParamBuilder('test') ->setDefault($value) ->getNode() @@ -24,7 +30,7 @@ public function testDefaultValues($value, $expectedValueNode) { $this->assertEquals($expectedValueNode, $node->default); } - public function provideTestDefaultValues() { + public static function provideTestDefaultValues() { return [ [ null, @@ -40,11 +46,11 @@ public function provideTestDefaultValues() { ], [ 31415, - new Scalar\LNumber(31415) + new Scalar\Int_(31415) ], [ 3.1415, - new Scalar\DNumber(3.1415) + new Scalar\Float_(3.1415) ], [ 'Hallo World', @@ -53,27 +59,27 @@ public function provideTestDefaultValues() { [ [1, 2, 3], new Expr\Array_([ - new Expr\ArrayItem(new Scalar\LNumber(1)), - new Expr\ArrayItem(new Scalar\LNumber(2)), - new Expr\ArrayItem(new Scalar\LNumber(3)), + new Node\ArrayItem(new Scalar\Int_(1)), + new Node\ArrayItem(new Scalar\Int_(2)), + new Node\ArrayItem(new Scalar\Int_(3)), ]) ], [ ['foo' => 'bar', 'bar' => 'foo'], new Expr\Array_([ - new Expr\ArrayItem( + new Node\ArrayItem( new Scalar\String_('bar'), new Scalar\String_('foo') ), - new Expr\ArrayItem( + new Node\ArrayItem( new Scalar\String_('foo'), new Scalar\String_('bar') ), ]) ], [ - new Scalar\MagicConst\Dir, - new Scalar\MagicConst\Dir + new Scalar\MagicConst\Dir(), + new Scalar\MagicConst\Dir() ] ]; } @@ -83,9 +89,9 @@ public function provideTestDefaultValues() { * @dataProvider provideTestNullableTypes * @dataProvider provideTestUnionTypes */ - public function testTypes($typeHint, $expectedType) { + public function testTypes($typeHint, $expectedType): void { $node = $this->createParamBuilder('test') - ->setTypeHint($typeHint) + ->setType($typeHint) ->getNode() ; $type = $node->type; @@ -101,7 +107,7 @@ public function testTypes($typeHint, $expectedType) { $this->assertEquals($expectedType, $type); } - public function provideTestTypes() { + public static function provideTestTypes() { return [ ['array', new Node\Identifier('array')], ['callable', new Node\Identifier('callable')], @@ -121,7 +127,7 @@ public function provideTestTypes() { ]; } - public function provideTestNullableTypes() { + public static function provideTestNullableTypes() { return [ ['?array', new Node\NullableType(new Node\Identifier('array'))], ['?Some\Class', new Node\NullableType(new Node\Name('Some\Class'))], @@ -136,7 +142,7 @@ public function provideTestNullableTypes() { ]; } - public function provideTestUnionTypes() { + public static function provideTestUnionTypes() { return [ [ new Node\UnionType([ @@ -163,19 +169,19 @@ public function provideTestUnionTypes() { ]; } - public function testVoidTypeError() { + public function testVoidTypeError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Parameter type cannot be void'); $this->createParamBuilder('test')->setType('void'); } - public function testInvalidTypeError() { + public function testInvalidTypeError(): void { $this->expectException(\LogicException::class); - $this->expectExceptionMessage('Type must be a string, or an instance of Name, Identifier, NullableType or UnionType'); - $this->createParamBuilder('test')->setType(new \stdClass); + $this->expectExceptionMessage('Type must be a string, or an instance of Name, Identifier or ComplexType'); + $this->createParamBuilder('test')->setType(new \stdClass()); } - public function testByRef() { + public function testByRef(): void { $node = $this->createParamBuilder('test') ->makeByRef() ->getNode() @@ -187,7 +193,7 @@ public function testByRef() { ); } - public function testVariadic() { + public function testVariadic(): void { $node = $this->createParamBuilder('test') ->makeVariadic() ->getNode() @@ -198,4 +204,89 @@ public function testVariadic() { $node ); } + + public function testMakePublic(): void { + $node = $this->createParamBuilder('test') + ->makePublic() + ->getNode() + ; + + $this->assertEquals( + new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Modifiers::PUBLIC), + $node + ); + } + + public function testMakeProtected(): void { + $node = $this->createParamBuilder('test') + ->makeProtected() + ->getNode() + ; + + $this->assertEquals( + new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Modifiers::PROTECTED), + $node + ); + + $node = $this->createParamBuilder('test') + ->makeProtectedSet() + ->getNode() + ; + + $this->assertEquals( + new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Modifiers::PROTECTED_SET), + $node + ); + } + + public function testMakePrivate(): void { + $node = $this->createParamBuilder('test') + ->makePrivate() + ->getNode() + ; + + $this->assertEquals( + new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Modifiers::PRIVATE), + $node + ); + + $node = $this->createParamBuilder('test') + ->makePrivateSet() + ->getNode() + ; + + $this->assertEquals( + new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Modifiers::PRIVATE_SET), + $node + ); + } + + public function testMakeReadonly(): void { + $node = $this->createParamBuilder('test') + ->makeReadonly() + ->getNode() + ; + + $this->assertEquals( + new Node\Param(new Expr\Variable('test'), null, null, false, false, [], Modifiers::READONLY), + $node + ); + } + + public function testAddAttribute(): void { + $attribute = new Attribute( + new Name('Attr'), + [new Arg(new Int_(1), false, false, [], new Identifier('name'))] + ); + $attributeGroup = new AttributeGroup([$attribute]); + + $node = $this->createParamBuilder('attributeGroup') + ->addAttribute($attributeGroup) + ->getNode(); + + $this->assertEquals( + new Node\Param(new Expr\Variable('attributeGroup'), null, null, false, false, [], 0, [$attributeGroup]), + $node + ); + } } diff --git a/test/PhpParser/Builder/PropertyTest.php b/test/PhpParser/Builder/PropertyTest.php index a15cd43c76..0505327a7b 100644 --- a/test/PhpParser/Builder/PropertyTest.php +++ b/test/PhpParser/Builder/PropertyTest.php @@ -3,18 +3,26 @@ namespace PhpParser\Builder; use PhpParser\Comment; +use PhpParser\Error; +use PhpParser\Modifiers; +use PhpParser\Node\Arg; +use PhpParser\Node\Attribute; +use PhpParser\Node\AttributeGroup; use PhpParser\Node\Expr; +use PhpParser\Node\Identifier; use PhpParser\Node\Name; +use PhpParser\Node\PropertyHook; +use PhpParser\Node\PropertyItem; use PhpParser\Node\Scalar; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Stmt; -class PropertyTest extends \PHPUnit\Framework\TestCase -{ +class PropertyTest extends \PHPUnit\Framework\TestCase { public function createPropertyBuilder($name) { return new Property($name); } - public function testModifiers() { + public function testModifiers(): void { $node = $this->createPropertyBuilder('test') ->makePrivate() ->makeStatic() @@ -23,11 +31,8 @@ public function testModifiers() { $this->assertEquals( new Stmt\Property( - Stmt\Class_::MODIFIER_PRIVATE - | Stmt\Class_::MODIFIER_STATIC, - [ - new Stmt\PropertyProperty('test') - ] + Modifiers::PRIVATE | Modifiers::STATIC, + [new PropertyItem('test')] ), $node ); @@ -39,10 +44,8 @@ public function testModifiers() { $this->assertEquals( new Stmt\Property( - Stmt\Class_::MODIFIER_PROTECTED, - [ - new Stmt\PropertyProperty('test') - ] + Modifiers::PROTECTED, + [new PropertyItem('test')] ), $node ); @@ -54,24 +57,62 @@ public function testModifiers() { $this->assertEquals( new Stmt\Property( - Stmt\Class_::MODIFIER_PUBLIC, - [ - new Stmt\PropertyProperty('test') - ] + Modifiers::PUBLIC, + [new PropertyItem('test')] + ), + $node + ); + + $node = $this->createPropertyBuilder('test') + ->makeReadonly() + ->getNode() + ; + + $this->assertEquals( + new Stmt\Property( + Modifiers::READONLY, + [new PropertyItem('test')] ), $node ); + + $node = $this->createPropertyBuilder('test') + ->makeFinal() + ->getNode(); + $this->assertEquals( + new Stmt\Property(Modifiers::FINAL, [new PropertyItem('test')]), + $node); + + $node = $this->createPropertyBuilder('test') + ->makePrivateSet() + ->getNode(); + $this->assertEquals( + new Stmt\Property(Modifiers::PRIVATE_SET, [new PropertyItem('test')]), + $node); + + $node = $this->createPropertyBuilder('test') + ->makeProtectedSet() + ->getNode(); + $this->assertEquals( + new Stmt\Property(Modifiers::PROTECTED_SET, [new PropertyItem('test')]), + $node); + } + + public function testAbstractWithoutHook() { + $this->expectException(Error::class); + $this->expectExceptionMessage('Only hooked properties may be declared abstract'); + $this->createPropertyBuilder('test')->makeAbstract()->getNode(); } - public function testDocComment() { + public function testDocComment(): void { $node = $this->createPropertyBuilder('test') ->setDocComment('/** Test */') ->getNode(); $this->assertEquals(new Stmt\Property( - Stmt\Class_::MODIFIER_PUBLIC, + Modifiers::PUBLIC, [ - new Stmt\PropertyProperty('test') + new \PhpParser\Node\PropertyItem('test') ], [ 'comments' => [new Comment\Doc('/** Test */')] @@ -82,7 +123,7 @@ public function testDocComment() { /** * @dataProvider provideTestDefaultValues */ - public function testDefaultValues($value, $expectedValueNode) { + public function testDefaultValues($value, $expectedValueNode): void { $node = $this->createPropertyBuilder('test') ->setDefault($value) ->getNode() @@ -91,7 +132,50 @@ public function testDefaultValues($value, $expectedValueNode) { $this->assertEquals($expectedValueNode, $node->props[0]->default); } - public function provideTestDefaultValues() { + public function testAddAttribute(): void { + $attribute = new Attribute( + new Name('Attr'), + [new Arg(new Int_(1), false, false, [], new Identifier('name'))] + ); + $attributeGroup = new AttributeGroup([$attribute]); + + $node = $this->createPropertyBuilder('test') + ->addAttribute($attributeGroup) + ->getNode() + ; + + $this->assertEquals( + new Stmt\Property( + Modifiers::PUBLIC, + [ + new \PhpParser\Node\PropertyItem('test') + ], + [], + null, + [$attributeGroup] + ), + $node + ); + } + + public function testAddHook(): void { + $get = new PropertyHook('get', null); + $set = new PropertyHook('set', null); + $node = $this->createPropertyBuilder('test') + ->addHook($get) + ->addHook($set) + ->makeAbstract() + ->getNode(); + $this->assertEquals( + new Stmt\Property( + Modifiers::ABSTRACT, + [new PropertyItem('test')], + [], null, [], + [$get, $set]), + $node); + } + + public static function provideTestDefaultValues() { return [ [ null, @@ -107,11 +191,11 @@ public function provideTestDefaultValues() { ], [ 31415, - new Scalar\LNumber(31415) + new Scalar\Int_(31415) ], [ 3.1415, - new Scalar\DNumber(3.1415) + new Scalar\Float_(3.1415) ], [ 'Hallo World', @@ -120,27 +204,27 @@ public function provideTestDefaultValues() { [ [1, 2, 3], new Expr\Array_([ - new Expr\ArrayItem(new Scalar\LNumber(1)), - new Expr\ArrayItem(new Scalar\LNumber(2)), - new Expr\ArrayItem(new Scalar\LNumber(3)), + new \PhpParser\Node\ArrayItem(new Scalar\Int_(1)), + new \PhpParser\Node\ArrayItem(new Scalar\Int_(2)), + new \PhpParser\Node\ArrayItem(new Scalar\Int_(3)), ]) ], [ ['foo' => 'bar', 'bar' => 'foo'], new Expr\Array_([ - new Expr\ArrayItem( + new \PhpParser\Node\ArrayItem( new Scalar\String_('bar'), new Scalar\String_('foo') ), - new Expr\ArrayItem( + new \PhpParser\Node\ArrayItem( new Scalar\String_('foo'), new Scalar\String_('bar') ), ]) ], [ - new Scalar\MagicConst\Dir, - new Scalar\MagicConst\Dir + new Scalar\MagicConst\Dir(), + new Scalar\MagicConst\Dir() ] ]; } diff --git a/test/PhpParser/Builder/TraitTest.php b/test/PhpParser/Builder/TraitTest.php index 2f2bd6b959..ddb9f9d631 100644 --- a/test/PhpParser/Builder/TraitTest.php +++ b/test/PhpParser/Builder/TraitTest.php @@ -3,28 +3,34 @@ namespace PhpParser\Builder; use PhpParser\Comment; +use PhpParser\Modifiers; +use PhpParser\Node\Arg; +use PhpParser\Node\Attribute; +use PhpParser\Node\AttributeGroup; +use PhpParser\Node\Const_; +use PhpParser\Node\Identifier; use PhpParser\Node\Name; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Stmt; -use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassConst; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Property; -use PhpParser\Node\Stmt\PropertyProperty; +use PhpParser\Node\PropertyItem; use PhpParser\Node\Stmt\TraitUse; -class TraitTest extends \PHPUnit\Framework\TestCase -{ +class TraitTest extends \PHPUnit\Framework\TestCase { protected function createTraitBuilder($class) { return new Trait_($class); } - public function testStmtAddition() { + public function testStmtAddition(): void { $method1 = new Stmt\ClassMethod('test1'); $method2 = new Stmt\ClassMethod('test2'); $method3 = new Stmt\ClassMethod('test3'); - $prop = new Stmt\Property(Stmt\Class_::MODIFIER_PUBLIC, [ - new Stmt\PropertyProperty('test') + $prop = new Stmt\Property(Modifiers::PUBLIC, [ + new PropertyItem('test') ]); + $const = new ClassConst([new Const_('FOO', new Int_(0))]); $use = new Stmt\TraitUse([new Name('OtherTrait')]); $trait = $this->createTraitBuilder('TestTrait') ->setDocComment('/** Nice trait */') @@ -32,9 +38,10 @@ public function testStmtAddition() { ->addStmts([$method2, $method3]) ->addStmt($prop) ->addStmt($use) + ->addStmt($const) ->getNode(); $this->assertEquals(new Stmt\Trait_('TestTrait', [ - 'stmts' => [$use, $prop, $method1, $method2, $method3] + 'stmts' => [$use, $const, $prop, $method1, $method2, $method3] ], [ 'comments' => [ new Comment\Doc('/** Nice trait */') @@ -42,7 +49,7 @@ public function testStmtAddition() { ]), $trait); } - public function testInvalidStmtError() { + public function testInvalidStmtError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Unexpected node of type "Stmt_Echo"'); $this->createTraitBuilder('Test') @@ -50,7 +57,7 @@ public function testInvalidStmtError() { ; } - public function testGetMethods() { + public function testGetMethods(): void { $methods = [ new ClassMethod('foo'), new ClassMethod('bar'), @@ -70,11 +77,10 @@ public function testGetMethods() { $this->assertSame($methods, $trait->getMethods()); } - public function testGetProperties() - { + public function testGetProperties(): void { $properties = [ - new Property(Class_::MODIFIER_PUBLIC, [new PropertyProperty('foo')]), - new Property(Class_::MODIFIER_PUBLIC, [new PropertyProperty('bar')]), + new Property(Modifiers::PUBLIC, [new PropertyItem('foo')]), + new Property(Modifiers::PUBLIC, [new PropertyItem('bar')]), ]; $trait = new Stmt\Trait_('Foo', [ 'stmts' => [ @@ -88,4 +94,27 @@ public function testGetProperties() $this->assertSame($properties, $trait->getProperties()); } + + public function testAddAttribute(): void { + $attribute = new Attribute( + new Name('Attr'), + [new Arg(new Int_(1), false, false, [], new Identifier('name'))] + ); + $attributeGroup = new AttributeGroup([$attribute]); + + $node = $this->createTraitBuilder('AttributeGroup') + ->addAttribute($attributeGroup) + ->getNode() + ; + + $this->assertEquals( + new Stmt\Trait_( + 'AttributeGroup', + [ + 'attrGroups' => [$attributeGroup], + ] + ), + $node + ); + } } diff --git a/test/PhpParser/Builder/TraitUseAdaptationTest.php b/test/PhpParser/Builder/TraitUseAdaptationTest.php index 4961ccfac9..56ab75f185 100644 --- a/test/PhpParser/Builder/TraitUseAdaptationTest.php +++ b/test/PhpParser/Builder/TraitUseAdaptationTest.php @@ -2,17 +2,17 @@ namespace PhpParser\Builder; +use PhpParser\Modifiers; use PhpParser\Node\Name; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Class_; -class TraitUseAdaptationTest extends \PHPUnit\Framework\TestCase -{ +class TraitUseAdaptationTest extends \PHPUnit\Framework\TestCase { protected function createTraitUseAdaptationBuilder($trait, $method) { return new TraitUseAdaptation($trait, $method); } - public function testAsMake() { + public function testAsMake(): void { $builder = $this->createTraitUseAdaptationBuilder(null, 'foo'); $this->assertEquals( @@ -21,22 +21,22 @@ public function testAsMake() { ); $this->assertEquals( - new Stmt\TraitUseAdaptation\Alias(null, 'foo', Class_::MODIFIER_PUBLIC, null), + new Stmt\TraitUseAdaptation\Alias(null, 'foo', Modifiers::PUBLIC, null), (clone $builder)->makePublic()->getNode() ); $this->assertEquals( - new Stmt\TraitUseAdaptation\Alias(null, 'foo', Class_::MODIFIER_PROTECTED, null), + new Stmt\TraitUseAdaptation\Alias(null, 'foo', Modifiers::PROTECTED, null), (clone $builder)->makeProtected()->getNode() ); $this->assertEquals( - new Stmt\TraitUseAdaptation\Alias(null, 'foo', Class_::MODIFIER_PRIVATE, null), + new Stmt\TraitUseAdaptation\Alias(null, 'foo', Modifiers::PRIVATE, null), (clone $builder)->makePrivate()->getNode() ); } - public function testInsteadof() { + public function testInsteadof(): void { $node = $this->createTraitUseAdaptationBuilder('SomeTrait', 'foo') ->insteadof('AnotherTrait') ->getNode() @@ -52,7 +52,7 @@ public function testInsteadof() { ); } - public function testAsOnNotAlias() { + public function testAsOnNotAlias(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot set alias for not alias adaptation buider'); $this->createTraitUseAdaptationBuilder('Test', 'foo') @@ -61,7 +61,7 @@ public function testAsOnNotAlias() { ; } - public function testInsteadofOnNotPrecedence() { + public function testInsteadofOnNotPrecedence(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot add overwritten traits for not precedence adaptation buider'); $this->createTraitUseAdaptationBuilder('Test', 'foo') @@ -70,7 +70,7 @@ public function testInsteadofOnNotPrecedence() { ; } - public function testInsteadofWithoutTrait() { + public function testInsteadofWithoutTrait(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Precedence adaptation must have trait'); $this->createTraitUseAdaptationBuilder(null, 'foo') @@ -78,7 +78,7 @@ public function testInsteadofWithoutTrait() { ; } - public function testMakeOnNotAlias() { + public function testMakeOnNotAlias(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot set access modifier for not alias adaptation buider'); $this->createTraitUseAdaptationBuilder('Test', 'foo') @@ -87,7 +87,7 @@ public function testMakeOnNotAlias() { ; } - public function testMultipleMake() { + public function testMultipleMake(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Multiple access type modifiers are not allowed'); $this->createTraitUseAdaptationBuilder(null, 'foo') @@ -96,7 +96,7 @@ public function testMultipleMake() { ; } - public function testUndefinedType() { + public function testUndefinedType(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Type of adaptation is not defined'); $this->createTraitUseAdaptationBuilder(null, 'foo') diff --git a/test/PhpParser/Builder/TraitUseTest.php b/test/PhpParser/Builder/TraitUseTest.php index 8d20dfbd7c..8101b777cb 100644 --- a/test/PhpParser/Builder/TraitUseTest.php +++ b/test/PhpParser/Builder/TraitUseTest.php @@ -5,13 +5,12 @@ use PhpParser\Node\Name; use PhpParser\Node\Stmt; -class TraitUseTest extends \PHPUnit\Framework\TestCase -{ +class TraitUseTest extends \PHPUnit\Framework\TestCase { protected function createTraitUseBuilder(...$traits) { return new TraitUse(...$traits); } - public function testAnd() { + public function testAnd(): void { $node = $this->createTraitUseBuilder('SomeTrait') ->and('AnotherTrait') ->getNode() @@ -26,7 +25,7 @@ public function testAnd() { ); } - public function testWith() { + public function testWith(): void { $node = $this->createTraitUseBuilder('SomeTrait') ->with(new Stmt\TraitUseAdaptation\Alias(null, 'foo', null, 'bar')) ->with((new TraitUseAdaptation(null, 'test'))->as('baz')) @@ -42,7 +41,7 @@ public function testWith() { ); } - public function testInvalidAdaptationNode() { + public function testInvalidAdaptationNode(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Adaptation must have type TraitUseAdaptation'); $this->createTraitUseBuilder('Test') diff --git a/test/PhpParser/Builder/UseTest.php b/test/PhpParser/Builder/UseTest.php index f17da59b42..5e5601589b 100644 --- a/test/PhpParser/Builder/UseTest.php +++ b/test/PhpParser/Builder/UseTest.php @@ -6,31 +6,30 @@ use PhpParser\Node\Name; use PhpParser\Node\Stmt; -class UseTest extends \PHPUnit\Framework\TestCase -{ +class UseTest extends \PHPUnit\Framework\TestCase { protected function createUseBuilder($name, $type = Stmt\Use_::TYPE_NORMAL) { return new Builder\Use_($name, $type); } - public function testCreation() { + public function testCreation(): void { $node = $this->createUseBuilder('Foo\Bar')->getNode(); $this->assertEquals(new Stmt\Use_([ - new Stmt\UseUse(new Name('Foo\Bar'), null) + new \PhpParser\Node\UseItem(new Name('Foo\Bar'), null) ]), $node); $node = $this->createUseBuilder(new Name('Foo\Bar'))->as('XYZ')->getNode(); $this->assertEquals(new Stmt\Use_([ - new Stmt\UseUse(new Name('Foo\Bar'), 'XYZ') + new \PhpParser\Node\UseItem(new Name('Foo\Bar'), 'XYZ') ]), $node); $node = $this->createUseBuilder('foo\bar', Stmt\Use_::TYPE_FUNCTION)->as('foo')->getNode(); $this->assertEquals(new Stmt\Use_([ - new Stmt\UseUse(new Name('foo\bar'), 'foo') + new \PhpParser\Node\UseItem(new Name('foo\bar'), 'foo') ], Stmt\Use_::TYPE_FUNCTION), $node); $node = $this->createUseBuilder('foo\BAR', Stmt\Use_::TYPE_CONSTANT)->as('FOO')->getNode(); $this->assertEquals(new Stmt\Use_([ - new Stmt\UseUse(new Name('foo\BAR'), 'FOO') + new \PhpParser\Node\UseItem(new Name('foo\BAR'), 'FOO') ], Stmt\Use_::TYPE_CONSTANT), $node); } } diff --git a/test/PhpParser/BuilderFactoryTest.php b/test/PhpParser/BuilderFactoryTest.php index 1d0bfcfc4a..4f807c0fb3 100644 --- a/test/PhpParser/BuilderFactoryTest.php +++ b/test/PhpParser/BuilderFactoryTest.php @@ -3,29 +3,30 @@ namespace PhpParser; use PhpParser\Node\Arg; +use PhpParser\Node\Attribute; use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp\Concat; use PhpParser\Node\Identifier; use PhpParser\Node\Name; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\String_; -class BuilderFactoryTest extends \PHPUnit\Framework\TestCase -{ +class BuilderFactoryTest extends \PHPUnit\Framework\TestCase { /** * @dataProvider provideTestFactory */ - public function testFactory($methodName, $className) { - $factory = new BuilderFactory; + public function testFactory($methodName, $className): void { + $factory = new BuilderFactory(); $this->assertInstanceOf($className, $factory->$methodName('test')); } - public function provideTestFactory() { + public static function provideTestFactory() { return [ ['namespace', Builder\Namespace_::class], ['class', Builder\Class_::class], ['interface', Builder\Interface_::class], ['trait', Builder\Trait_::class], + ['enum', Builder\Enum_::class], ['method', Builder\Method::class], ['function', Builder\Function_::class], ['property', Builder\Property::class], @@ -33,15 +34,26 @@ public function provideTestFactory() { ['use', Builder\Use_::class], ['useFunction', Builder\Use_::class], ['useConst', Builder\Use_::class], + ['enumCase', Builder\EnumCase::class], ]; } - public function testFactoryClassConst() { - $factory = new BuilderFactory; - $this->assertInstanceOf(Builder\ClassConst::class, $factory->classConst('TEST',1)); + public function testFactoryClassConst(): void { + $factory = new BuilderFactory(); + $this->assertInstanceOf(Builder\ClassConst::class, $factory->classConst('TEST', 1)); + } + + public function testAttribute(): void { + $factory = new BuilderFactory(); + $this->assertEquals( + new Attribute(new Name('AttributeName'), [new Arg( + new String_('bar'), false, false, [], new Identifier('foo') + )]), + $factory->attribute('AttributeName', ['foo' => 'bar']) + ); } - public function testVal() { + public function testVal(): void { // This method is a wrapper around BuilderHelpers::normalizeValue(), // which is already tested elsewhere $factory = new BuilderFactory(); @@ -51,7 +63,7 @@ public function testVal() { ); } - public function testConcat() { + public function testConcat(): void { $factory = new BuilderFactory(); $varA = new Expr\Variable('a'); $varB = new Expr\Variable('b'); @@ -71,19 +83,19 @@ public function testConcat() { ); } - public function testConcatOneError() { + public function testConcatOneError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected at least two expressions'); (new BuilderFactory())->concat("a"); } - public function testConcatInvalidExpr() { + public function testConcatInvalidExpr(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected string or Expr'); (new BuilderFactory())->concat("a", 42); } - public function testArgs() { + public function testArgs(): void { $factory = new BuilderFactory(); $unpack = new Arg(new Expr\Variable('c'), false, true); $this->assertEquals( @@ -96,7 +108,18 @@ public function testArgs() { ); } - public function testCalls() { + public function testNamedArgs(): void { + $factory = new BuilderFactory(); + $this->assertEquals( + [ + new Arg(new String_('foo')), + new Arg(new String_('baz'), false, false, [], new Identifier('bar')), + ], + $factory->args(['foo', 'bar' => 'baz']) + ); + } + + public function testCalls(): void { $factory = new BuilderFactory(); // Simple function call @@ -118,7 +141,7 @@ public function testCalls() { new Expr\MethodCall( new Expr\Variable('obj'), new Identifier('method'), - [new Arg(new LNumber(42))] + [new Arg(new Int_(42))] ), $factory->methodCall(new Expr\Variable('obj'), 'method', [42]) ); @@ -172,7 +195,7 @@ public function testCalls() { ); } - public function testConstFetches() { + public function testConstFetches(): void { $factory = new BuilderFactory(); $this->assertEquals( new Expr\ConstFetch(new Name('FOO')), @@ -186,9 +209,13 @@ public function testConstFetches() { new Expr\ClassConstFetch(new Expr\Variable('foo'), new Identifier('BAR')), $factory->classConstFetch(new Expr\Variable('foo'), 'BAR') ); + $this->assertEquals( + new Expr\ClassConstFetch(new Name('Foo'), new Expr\Variable('foo')), + $factory->classConstFetch('Foo', $factory->var('foo')) + ); } - public function testVar() { + public function testVar(): void { $factory = new BuilderFactory(); $this->assertEquals( new Expr\Variable("foo"), @@ -200,7 +227,7 @@ public function testVar() { ); } - public function testPropertyFetch() { + public function testPropertyFetch(): void { $f = new BuilderFactory(); $this->assertEquals( new Expr\PropertyFetch(new Expr\Variable('foo'), 'bar'), @@ -216,32 +243,32 @@ public function testPropertyFetch() { ); } - public function testInvalidIdentifier() { + public function testInvalidIdentifier(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected string or instance of Node\Identifier'); - (new BuilderFactory())->classConstFetch('Foo', new Expr\Variable('foo')); + (new BuilderFactory())->classConstFetch('Foo', new Name('foo')); } - public function testInvalidIdentifierOrExpr() { + public function testInvalidIdentifierOrExpr(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Expected string or instance of Node\Identifier or Node\Expr'); (new BuilderFactory())->staticCall('Foo', new Name('bar')); } - public function testInvalidNameOrExpr() { + public function testInvalidNameOrExpr(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Name must be a string or an instance of Node\Name or Node\Expr'); (new BuilderFactory())->funcCall(new Node\Stmt\Return_()); } - public function testInvalidVar() { + public function testInvalidVar(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Variable name must be string or Expr'); (new BuilderFactory())->var(new Node\Stmt\Return_()); } - public function testIntegration() { - $factory = new BuilderFactory; + public function testIntegration(): void { + $factory = new BuilderFactory(); $node = $factory->namespace('Name\Space') ->addStmt($factory->use('Foo\Bar\SomeOtherClass')) ->addStmt($factory->use('Foo\Bar')->as('A')) @@ -251,6 +278,7 @@ public function testIntegration() { ->class('SomeClass') ->extend('SomeOtherClass') ->implement('A\Few', '\Interfaces') + ->addAttribute($factory->attribute('ClassAttribute', ['repository' => 'fqcn'])) ->makeAbstract() ->addStmt($factory->useTrait('FirstTrait')) @@ -261,7 +289,9 @@ public function testIntegration() { ->with($factory->traitUseAdaptation('AnotherTrait', 'baz')->as('test')) ->with($factory->traitUseAdaptation('AnotherTrait', 'func')->insteadof('SecondTrait'))) - ->addStmt($factory->method('firstMethod')) + ->addStmt($factory->method('firstMethod') + ->addAttribute($factory->attribute('Route', ['/index', 'name' => 'homepage'])) + ) ->addStmt($factory->method('someMethod') ->makePublic() @@ -275,16 +305,27 @@ public function testIntegration() { ->addStmt($factory->method('anotherMethod') ->makeProtected() - ->addParam($factory->param('someParam')->setDefault('test')) + ->addParam($factory->param('someParam') + ->setDefault('test') + ->addAttribute($factory->attribute('TaggedIterator', ['app.handlers'])) + ) ->addStmt(new Expr\Print_(new Expr\Variable('someParam')))) ->addStmt($factory->property('someProperty')->makeProtected()) ->addStmt($factory->property('anotherProperty') ->makePrivate() ->setDefault([1, 2, 3])) + ->addStmt($factory->property('integerProperty') + ->setType('int') + ->addAttribute($factory->attribute('Column', ['options' => ['unsigned' => true]])) + ->setDefault(1)) + ->addStmt($factory->classConst('CONST_WITH_ATTRIBUTE', 1) + ->makePublic() + ->addAttribute($factory->attribute('ConstAttribute')) + ) ->addStmt($factory->classConst("FIRST_CLASS_CONST", 1) - ->addConst("SECOND_CLASS_CONST",2) + ->addConst("SECOND_CLASS_CONST", 2) ->makePrivate())) ->getNode() ; @@ -298,6 +339,7 @@ public function testIntegration() { use Foo\Bar as A; use function strlen; use const PHP_VERSION; +#[ClassAttribute(repository: 'fqcn')] abstract class SomeClass extends SomeOtherClass implements A\Few, \Interfaces { use FirstTrait; @@ -306,9 +348,14 @@ abstract class SomeClass extends SomeOtherClass implements A\Few, \Interfaces AnotherTrait::baz as test; AnotherTrait::func insteadof SecondTrait; } + #[ConstAttribute] + public const CONST_WITH_ATTRIBUTE = 1; private const FIRST_CLASS_CONST = 1, SECOND_CLASS_CONST = 2; protected $someProperty; - private $anotherProperty = array(1, 2, 3); + private $anotherProperty = [1, 2, 3]; + #[Column(options: ['unsigned' => true])] + public int $integerProperty = 1; + #[Route('/index', name: 'homepage')] function firstMethod() { } @@ -317,8 +364,11 @@ function firstMethod() * * @param SomeClass And takes a parameter */ - public abstract function someMethod(SomeClass $someParam); - protected function anotherMethod($someParam = 'test') + abstract public function someMethod(SomeClass $someParam); + protected function anotherMethod( + #[TaggedIterator('app.handlers')] + $someParam = 'test' + ) { print $someParam; } diff --git a/test/PhpParser/BuilderHelpersTest.php b/test/PhpParser/BuilderHelpersTest.php new file mode 100644 index 0000000000..776f6e4515 --- /dev/null +++ b/test/PhpParser/BuilderHelpersTest.php @@ -0,0 +1,236 @@ +assertEquals($builder->getNode(), BuilderHelpers::normalizeNode($builder)); + + $attribute = new Node\Attribute(new Node\Name('Test')); + $this->assertSame($attribute, BuilderHelpers::normalizeNode($attribute)); + + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Expected node or builder object'); + BuilderHelpers::normalizeNode('test'); + } + + public function testNormalizeStmt(): void { + $stmt = new Node\Stmt\Class_('Class'); + $this->assertSame($stmt, BuilderHelpers::normalizeStmt($stmt)); + + $expr = new Expr\Variable('fn'); + $normalizedExpr = BuilderHelpers::normalizeStmt($expr); + $this->assertEquals(new Stmt\Expression($expr), $normalizedExpr); + $this->assertSame($expr, $normalizedExpr->expr); + + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Expected statement or expression node'); + BuilderHelpers::normalizeStmt(new Node\Attribute(new Node\Name('Test'))); + } + + public function testNormalizeStmtInvalidType(): void { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Expected node or builder object'); + BuilderHelpers::normalizeStmt('test'); + } + + public function testNormalizeIdentifier(): void { + $identifier = new Node\Identifier('fn'); + $this->assertSame($identifier, BuilderHelpers::normalizeIdentifier($identifier)); + $this->assertEquals($identifier, BuilderHelpers::normalizeIdentifier('fn')); + + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Expected string or instance of Node\Identifier'); + BuilderHelpers::normalizeIdentifier(1); + } + + public function testNormalizeIdentifierOrExpr(): void { + $identifier = new Node\Identifier('fn'); + $this->assertSame($identifier, BuilderHelpers::normalizeIdentifierOrExpr($identifier)); + + $expr = new Expr\Variable('fn'); + $this->assertSame($expr, BuilderHelpers::normalizeIdentifierOrExpr($expr)); + $this->assertEquals($identifier, BuilderHelpers::normalizeIdentifierOrExpr('fn')); + + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Expected string or instance of Node\Identifier'); + BuilderHelpers::normalizeIdentifierOrExpr(1); + } + + public function testNormalizeName(): void { + $name = new Node\Name('test'); + $this->assertSame($name, BuilderHelpers::normalizeName($name)); + $this->assertEquals( + new Node\Name\FullyQualified(['Namespace', 'Test']), + BuilderHelpers::normalizeName('\\Namespace\\Test') + ); + $this->assertEquals( + new Node\Name\Relative(['Test']), + BuilderHelpers::normalizeName('namespace\\Test') + ); + $this->assertEquals($name, BuilderHelpers::normalizeName('test')); + + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Name cannot be empty'); + BuilderHelpers::normalizeName(''); + } + + public function testNormalizeNameInvalidType(): void { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Name must be a string or an instance of Node\Name'); + BuilderHelpers::normalizeName(1); + } + + public function testNormalizeNameOrExpr(): void { + $expr = new Expr\Variable('fn'); + $this->assertSame($expr, BuilderHelpers::normalizeNameOrExpr($expr)); + + $name = new Node\Name('test'); + $this->assertSame($name, BuilderHelpers::normalizeNameOrExpr($name)); + $this->assertEquals( + new Node\Name\FullyQualified(['Namespace', 'Test']), + BuilderHelpers::normalizeNameOrExpr('\\Namespace\\Test') + ); + $this->assertEquals( + new Node\Name\Relative(['Test']), + BuilderHelpers::normalizeNameOrExpr('namespace\\Test') + ); + $this->assertEquals($name, BuilderHelpers::normalizeNameOrExpr('test')); + + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Name cannot be empty'); + BuilderHelpers::normalizeNameOrExpr(''); + } + + public function testNormalizeNameOrExpInvalidType(): void { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Name must be a string or an instance of Node\Name or Node\Expr'); + BuilderHelpers::normalizeNameOrExpr(1); + } + + public function testNormalizeType(): void { + $this->assertEquals(new Node\Identifier('array'), BuilderHelpers::normalizeType('array')); + $this->assertEquals(new Node\Identifier('callable'), BuilderHelpers::normalizeType('callable')); + $this->assertEquals(new Node\Identifier('string'), BuilderHelpers::normalizeType('string')); + $this->assertEquals(new Node\Identifier('int'), BuilderHelpers::normalizeType('int')); + $this->assertEquals(new Node\Identifier('float'), BuilderHelpers::normalizeType('float')); + $this->assertEquals(new Node\Identifier('bool'), BuilderHelpers::normalizeType('bool')); + $this->assertEquals(new Node\Identifier('iterable'), BuilderHelpers::normalizeType('iterable')); + $this->assertEquals(new Node\Identifier('void'), BuilderHelpers::normalizeType('void')); + $this->assertEquals(new Node\Identifier('object'), BuilderHelpers::normalizeType('object')); + $this->assertEquals(new Node\Identifier('null'), BuilderHelpers::normalizeType('null')); + $this->assertEquals(new Node\Identifier('false'), BuilderHelpers::normalizeType('false')); + $this->assertEquals(new Node\Identifier('mixed'), BuilderHelpers::normalizeType('mixed')); + $this->assertEquals(new Node\Identifier('never'), BuilderHelpers::normalizeType('never')); + $this->assertEquals(new Node\Identifier('true'), BuilderHelpers::normalizeType('true')); + + $intIdentifier = new Node\Identifier('int'); + $this->assertSame($intIdentifier, BuilderHelpers::normalizeType($intIdentifier)); + + $intName = new Node\Name('int'); + $this->assertSame($intName, BuilderHelpers::normalizeType($intName)); + + $intNullable = new Node\NullableType(new Identifier('int')); + $this->assertSame($intNullable, BuilderHelpers::normalizeType($intNullable)); + + $unionType = new Node\UnionType([new Node\Identifier('int'), new Node\Identifier('string')]); + $this->assertSame($unionType, BuilderHelpers::normalizeType($unionType)); + + $intersectionType = new Node\IntersectionType([new Node\Name('A'), new Node\Name('B')]); + $this->assertSame($intersectionType, BuilderHelpers::normalizeType($intersectionType)); + + $expectedNullable = new Node\NullableType($intIdentifier); + $nullable = BuilderHelpers::normalizeType('?int'); + $this->assertEquals($expectedNullable, $nullable); + $this->assertEquals($intIdentifier, $nullable->type); + + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Type must be a string, or an instance of Name, Identifier or ComplexType'); + BuilderHelpers::normalizeType(1); + } + + public function testNormalizeTypeNullableVoid(): void { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('void type cannot be nullable'); + BuilderHelpers::normalizeType('?void'); + } + + public function testNormalizeTypeNullableMixed(): void { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('mixed type cannot be nullable'); + BuilderHelpers::normalizeType('?mixed'); + } + + public function testNormalizeTypeNullableNever(): void { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('never type cannot be nullable'); + BuilderHelpers::normalizeType('?never'); + } + + public function testNormalizeValue(): void { + $expression = new Scalar\Int_(1); + $this->assertSame($expression, BuilderHelpers::normalizeValue($expression)); + + $this->assertEquals(new Expr\ConstFetch(new Node\Name('null')), BuilderHelpers::normalizeValue(null)); + $this->assertEquals(new Expr\ConstFetch(new Node\Name('true')), BuilderHelpers::normalizeValue(true)); + $this->assertEquals(new Expr\ConstFetch(new Node\Name('false')), BuilderHelpers::normalizeValue(false)); + $this->assertEquals(new Scalar\Int_(2), BuilderHelpers::normalizeValue(2)); + $this->assertEquals(new Scalar\Float_(2.5), BuilderHelpers::normalizeValue(2.5)); + $this->assertEquals(new Scalar\String_('text'), BuilderHelpers::normalizeValue('text')); + $this->assertEquals( + new Expr\Array_([ + new Node\ArrayItem(new Scalar\Int_(0)), + new Node\ArrayItem(new Scalar\Int_(1), new Scalar\String_('test')), + ]), + BuilderHelpers::normalizeValue([ + 0, + 'test' => 1, + ]) + ); + + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Invalid value'); + BuilderHelpers::normalizeValue(new \stdClass()); + } + + public function testNormalizeDocComment(): void { + $docComment = new Comment\Doc('Some doc comment'); + $this->assertSame($docComment, BuilderHelpers::normalizeDocComment($docComment)); + + $this->assertEquals($docComment, BuilderHelpers::normalizeDocComment('Some doc comment')); + + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Doc comment must be a string or an instance of PhpParser\Comment\Doc'); + BuilderHelpers::normalizeDocComment(1); + } + + public function testNormalizeAttribute(): void { + $attribute = new Node\Attribute(new Node\Name('Test')); + $attributeGroup = new Node\AttributeGroup([$attribute]); + + $this->assertEquals($attributeGroup, BuilderHelpers::normalizeAttribute($attribute)); + $this->assertSame($attributeGroup, BuilderHelpers::normalizeAttribute($attributeGroup)); + + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Attribute must be an instance of PhpParser\Node\Attribute or PhpParser\Node\AttributeGroup'); + BuilderHelpers::normalizeAttribute('test'); + } + + public function testNormalizeValueEnum() { + if (\PHP_VERSION_ID <= 80100) { + $this->markTestSkipped('Enums are supported since PHP 8.1'); + } + + include __DIR__ . '/../fixtures/Suit.php'; + + $this->assertEquals(new Expr\ClassConstFetch(new FullyQualified(\Suit::class), new Identifier('Hearts')), BuilderHelpers::normalizeValue(\Suit::Hearts)); + } +} diff --git a/test/PhpParser/CodeParsingTest.php b/test/PhpParser/CodeParsingTest.php index 24e93dd522..0c479a51be 100644 --- a/test/PhpParser/CodeParsingTest.php +++ b/test/PhpParser/CodeParsingTest.php @@ -5,56 +5,32 @@ use PhpParser\Node\Expr; use PhpParser\Node\Stmt; -class CodeParsingTest extends CodeTestAbstract -{ +class CodeParsingTest extends CodeTestAbstract { /** * @dataProvider provideTestParse */ - public function testParse($name, $code, $expected, $modeLine) { - if (null !== $modeLine) { - $modes = array_fill_keys(explode(',', $modeLine), true); - } else { - $modes = []; - } - - list($parser5, $parser7) = $this->createParsers($modes); - list($stmts5, $output5) = $this->getParseOutput($parser5, $code, $modes); - list($stmts7, $output7) = $this->getParseOutput($parser7, $code, $modes); - - if (isset($modes['php5'])) { - $this->assertSame($expected, $output5, $name); - $this->assertNotSame($expected, $output7, $name); - } elseif (isset($modes['php7'])) { - $this->assertNotSame($expected, $output5, $name); - $this->assertSame($expected, $output7, $name); - } else { - $this->assertSame($expected, $output5, $name); - $this->assertSame($expected, $output7, $name); - } + public function testParse($name, $code, $expected, $modeLine): void { + $modes = $this->parseModeLine($modeLine); + $parser = $this->createParser($modes['version'] ?? null); + list($stmts, $output) = $this->getParseOutput($parser, $code, $modes); - $this->checkAttributes($stmts5); - $this->checkAttributes($stmts7); + $this->assertSame($expected, $output, $name); + $this->checkAttributes($stmts); } - public function createParsers(array $modes) { - $lexer = new Lexer\Emulative(['usedAttributes' => [ - 'startLine', 'endLine', - 'startFilePos', 'endFilePos', - 'startTokenPos', 'endTokenPos', - 'comments' - ]]); - - return [ - new Parser\Php5($lexer), - new Parser\Php7($lexer), - ]; + public function createParser(?string $version): Parser { + $factory = new ParserFactory(); + $version = $version === null + ? PhpVersion::getNewestSupported() : PhpVersion::fromString($version); + return $factory->createForVersion($version); } // Must be public for updateTests.php public function getParseOutput(Parser $parser, $code, array $modes) { $dumpPositions = isset($modes['positions']); + $dumpOtherAttributes = isset($modes['attributes']); - $errors = new ErrorHandler\Collecting; + $errors = new ErrorHandler\Collecting(); $stmts = $parser->parse($code, $errors); $output = ''; @@ -63,15 +39,19 @@ public function getParseOutput(Parser $parser, $code, array $modes) { } if (null !== $stmts) { - $dumper = new NodeDumper(['dumpComments' => true, 'dumpPositions' => $dumpPositions]); + $dumper = new NodeDumper([ + 'dumpComments' => true, + 'dumpPositions' => $dumpPositions, + 'dumpOtherAttributes' => $dumpOtherAttributes, + ]); $output .= $dumper->dump($stmts, $code); } return [$stmts, canonicalize($output)]; } - public function provideTestParse() { - return $this->getTests(__DIR__ . '/../code/parser', 'test'); + public static function provideTestParse() { + return self::getTests(__DIR__ . '/../code/parser', 'test'); } private function formatErrorMessage(Error $e, $code) { @@ -82,14 +62,13 @@ private function formatErrorMessage(Error $e, $code) { return $e->getMessage(); } - private function checkAttributes($stmts) { + private function checkAttributes($stmts): void { if ($stmts === null) { return; } - $traverser = new NodeTraverser(); - $traverser->addVisitor(new class extends NodeVisitorAbstract { - public function enterNode(Node $node) { + $traverser = new NodeTraverser(new class () extends NodeVisitorAbstract { + public function enterNode(Node $node): void { $startLine = $node->getStartLine(); $endLine = $node->getEndLine(); $startFilePos = $node->getStartFilePos(); @@ -107,8 +86,11 @@ public function enterNode(Node $node) { $endFilePos < $startFilePos || $endTokenPos < $startTokenPos ) { - // Nops and error can have inverted order, if they are empty - if (!$node instanceof Stmt\Nop && !$node instanceof Expr\Error) { + // Nop and Error can have inverted order, if they are empty. + // This can also happen for a Param containing an Error. + if (!$node instanceof Stmt\Nop && !$node instanceof Expr\Error && + !$node instanceof Node\Param + ) { throw new \Exception('End < start on ' . $node->getType()); } } diff --git a/test/PhpParser/CodeTestAbstract.php b/test/PhpParser/CodeTestAbstract.php index f5f408755c..145f7dda2d 100644 --- a/test/PhpParser/CodeTestAbstract.php +++ b/test/PhpParser/CodeTestAbstract.php @@ -2,10 +2,9 @@ namespace PhpParser; -abstract class CodeTestAbstract extends \PHPUnit\Framework\TestCase -{ - protected function getTests($directory, $fileExtension, $chunksPerTest = 2) { - $parser = new CodeTestParser; +abstract class CodeTestAbstract extends \PHPUnit\Framework\TestCase { + protected static function getTests($directory, $fileExtension, $chunksPerTest = 2) { + $parser = new CodeTestParser(); $allTests = []; foreach (filesInDir($directory, $fileExtension) as $fileName => $fileContents) { list($name, $tests) = $parser->parseTest($fileContents, $chunksPerTest); @@ -23,4 +22,21 @@ protected function getTests($directory, $fileExtension, $chunksPerTest = 2) { return $allTests; } + + public function parseModeLine(?string $modeLine): array { + if ($modeLine === null) { + return []; + } + + $modes = []; + foreach (explode(',', $modeLine) as $mode) { + $kv = explode('=', $mode, 2); + if (isset($kv[1])) { + $modes[$kv[0]] = $kv[1]; + } else { + $modes[$kv[0]] = true; + } + } + return $modes; + } } diff --git a/test/PhpParser/CodeTestParser.php b/test/PhpParser/CodeTestParser.php index f63dc92653..9f8ed596f2 100644 --- a/test/PhpParser/CodeTestParser.php +++ b/test/PhpParser/CodeTestParser.php @@ -2,15 +2,14 @@ namespace PhpParser; -class CodeTestParser -{ +class CodeTestParser { public function parseTest($code, $chunksPerTest) { $code = canonicalize($code); // evaluate @@{expr}@@ expressions $code = preg_replace_callback( '/@@\{(.*?)\}@@/', - function($matches) { + function ($matches) { return eval('return ' . $matches[1] . ';'); }, $code @@ -25,7 +24,7 @@ function($matches) { // multiple sections possible with always two forming a pair $chunks = array_chunk($parts, $chunksPerTest); $tests = []; - foreach ($chunks as $i => $chunk) { + foreach ($chunks as $chunk) { $lastPart = array_pop($chunk); list($lastPart, $mode) = $this->extractMode($lastPart); $tests[] = [$mode, array_merge($chunk, [$lastPart])]; @@ -48,10 +47,10 @@ public function reconstructTest($name, array $tests) { } $result .= $lastPart; } - return $result; + return $result . "\n"; } - private function extractMode($expected) { + private function extractMode(string $expected): array { $firstNewLine = strpos($expected, "\n"); if (false === $firstNewLine) { $firstNewLine = strlen($expected); @@ -62,7 +61,7 @@ private function extractMode($expected) { return [$expected, null]; } - $expected = (string) substr($expected, $firstNewLine + 1); + $expected = substr($expected, $firstNewLine + 1); return [$expected, substr($firstLine, 2)]; } } diff --git a/test/PhpParser/CommentTest.php b/test/PhpParser/CommentTest.php index c51a26be8f..1d0f0ebd0f 100644 --- a/test/PhpParser/CommentTest.php +++ b/test/PhpParser/CommentTest.php @@ -2,17 +2,13 @@ namespace PhpParser; -class CommentTest extends \PHPUnit\Framework\TestCase -{ - public function testGetters() { +class CommentTest extends \PHPUnit\Framework\TestCase { + public function testGetters(): void { $comment = new Comment('/* Some comment */', 1, 10, 2, 1, 27, 2); $this->assertSame('/* Some comment */', $comment->getText()); $this->assertSame('/* Some comment */', (string) $comment); - $this->assertSame(1, $comment->getLine()); - $this->assertSame(10, $comment->getFilePos()); - $this->assertSame(2, $comment->getTokenPos()); $this->assertSame(1, $comment->getStartLine()); $this->assertSame(10, $comment->getStartFilePos()); $this->assertSame(2, $comment->getStartTokenPos()); @@ -24,57 +20,47 @@ public function testGetters() { /** * @dataProvider provideTestReformatting */ - public function testReformatting($commentText, $reformattedText) { + public function testReformatting($commentText, $reformattedText): void { $comment = new Comment($commentText); $this->assertSame($reformattedText, $comment->getReformattedText()); } - public function provideTestReformatting() { + public static function provideTestReformatting() { return [ - ['// Some text' . "\n", '// Some text'], + ['// Some text', '// Some text'], ['/* Some text */', '/* Some text */'], [ - '/** - * Some text. - * Some more text. - */', - '/** - * Some text. - * Some more text. - */' + "/**\n * Some text.\n * Some more text.\n */", + "/**\n * Some text.\n * Some more text.\n */" ], [ - '/* - Some text. - Some more text. - */', - '/* - Some text. - Some more text. -*/' + "/**\r\n * Some text.\r\n * Some more text.\r\n */", + "/**\n * Some text.\n * Some more text.\n */" ], [ - '/* Some text. - More text. - Even more text. */', - '/* Some text. - More text. - Even more text. */' + "/*\n Some text.\n Some more text.\n */", + "/*\n Some text.\n Some more text.\n*/" ], [ - '/* Some text. - More text. - Indented text. */', - '/* Some text. - More text. - Indented text. */', + "/*\r\n Some text.\r\n Some more text.\r\n */", + "/*\n Some text.\n Some more text.\n*/" + ], + [ + "/* Some text.\n More text.\n Even more text. */", + "/* Some text.\n More text.\n Even more text. */" + ], + [ + "/* Some text.\r\n More text.\r\n Even more text. */", + "/* Some text.\n More text.\n Even more text. */" + ], + [ + "/* Some text.\n More text.\n Indented text. */", + "/* Some text.\n More text.\n Indented text. */", ], // invalid comment -> no reformatting [ - 'hallo - world', - 'hallo - world', + "hello\n world", + "hello\n world", ], ]; } diff --git a/test/PhpParser/CompatibilityTest.php b/test/PhpParser/CompatibilityTest.php new file mode 100644 index 0000000000..9928e8d85f --- /dev/null +++ b/test/PhpParser/CompatibilityTest.php @@ -0,0 +1,67 @@ +assertTrue($node instanceof Expr\ClosureUse); + $node = new Node\ArrayItem($var); + $this->assertTrue($node instanceof Expr\ArrayItem); + $node = new Node\StaticVar($var); + $this->assertTrue($node instanceof Stmt\StaticVar); + $node = new Scalar\Float_(1.0); + $this->assertTrue($node instanceof Scalar\DNumber); + $node = new Scalar\Int_(1); + $this->assertTrue($node instanceof Scalar\LNumber); + $part = new InterpolatedStringPart('foo'); + $this->assertTrue($part instanceof Scalar\EncapsedStringPart); + $node = new Scalar\InterpolatedString([$part]); + $this->assertTrue($node instanceof Scalar\Encapsed); + $node = new Node\DeclareItem('strict_types', new Scalar\Int_(1)); + $this->assertTrue($node instanceof Stmt\DeclareDeclare); + $node = new Node\PropertyItem('x'); + $this->assertTrue($node instanceof Stmt\PropertyProperty); + $node = new Node\UseItem(new Name('X')); + $this->assertTrue($node instanceof Stmt\UseUse); + } + + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testAliases2(): void { + $var = new Expr\Variable('x'); + $node = new Node\Expr\ClosureUse($var); + $this->assertTrue($node instanceof Node\ClosureUse); + $node = new Node\Expr\ArrayItem($var); + $this->assertTrue($node instanceof Node\ArrayItem); + $node = new Node\Stmt\StaticVar($var); + $this->assertTrue($node instanceof Node\StaticVar); + $node = new Node\Scalar\DNumber(1.0); + $this->assertTrue($node instanceof Scalar\Float_); + $node = new Node\Scalar\LNumber(1); + $this->assertTrue($node instanceof Scalar\Int_); + $part = new Node\Scalar\EncapsedStringPart('foo'); + $this->assertTrue($part instanceof Node\InterpolatedStringPart); + $node = new Scalar\Encapsed([$part]); + $this->assertTrue($node instanceof Scalar\InterpolatedString); + $node = new Stmt\DeclareDeclare('strict_types', new Scalar\LNumber(1)); + $this->assertTrue($node instanceof Node\DeclareItem); + $node = new Stmt\PropertyProperty('x'); + $this->assertTrue($node instanceof Node\PropertyItem); + $node = new Stmt\UseUse(new Name('X')); + $this->assertTrue($node instanceof Node\UseItem); + } +} diff --git a/test/PhpParser/ConstExprEvaluatorTest.php b/test/PhpParser/ConstExprEvaluatorTest.php index 23ab18d3d1..513918e56d 100644 --- a/test/PhpParser/ConstExprEvaluatorTest.php +++ b/test/PhpParser/ConstExprEvaluatorTest.php @@ -5,23 +5,25 @@ use PhpParser\Node\Expr; use PhpParser\Node\Scalar; -class ConstExprEvaluatorTest extends \PHPUnit\Framework\TestCase -{ +class ConstExprEvaluatorTest extends \PHPUnit\Framework\TestCase { /** @dataProvider provideTestEvaluate */ - public function testEvaluate($exprString, $expected) { - $parser = new Parser\Php7(new Lexer()); + public function testEvaluate($exprString, $expected): void { + $parser = (new ParserFactory())->createForNewestSupportedVersion(); $expr = $parser->parse('expr; $evaluator = new ConstExprEvaluator(); $this->assertSame($expected, $evaluator->evaluateDirectly($expr)); } - public function provideTestEvaluate() { + public static function provideTestEvaluate() { return [ ['1', 1], ['1.0', 1.0], ['"foo"', "foo"], ['[0, 1]', [0, 1]], ['["foo" => "bar"]', ["foo" => "bar"]], + ['[...["bar"]]', ["bar"]], + ['[...["foo" => "bar"]]', ["foo" => "bar"]], + ['["a", "b" => "b", ...["b" => "bb", "c"]]', ["a", "b" => "bb", "c"]], ['NULL', null], ['False', false], ['true', true], @@ -69,25 +71,26 @@ public function provideTestEvaluate() { ['true || (1/0)', true], ['true or (1/0)', true], ['true xor false', true], + ['"foo" |> "strlen"', 3], ]; } - public function testEvaluateFails() { + public function testEvaluateFails(): void { $this->expectException(ConstExprEvaluationException::class); $this->expectExceptionMessage('Expression of type Expr_Variable cannot be evaluated'); $evaluator = new ConstExprEvaluator(); $evaluator->evaluateDirectly(new Expr\Variable('a')); } - public function testEvaluateFallback() { - $evaluator = new ConstExprEvaluator(function(Expr $expr) { + public function testEvaluateFallback(): void { + $evaluator = new ConstExprEvaluator(function (Expr $expr) { if ($expr instanceof Scalar\MagicConst\Line) { return 42; } throw new ConstExprEvaluationException(); }); $expr = new Expr\BinaryOp\Plus( - new Scalar\LNumber(8), + new Scalar\Int_(8), new Scalar\MagicConst\Line() ); $this->assertSame(50, $evaluator->evaluateDirectly($expr)); @@ -96,7 +99,7 @@ public function testEvaluateFallback() { /** * @dataProvider provideTestEvaluateSilently */ - public function testEvaluateSilently($expr, $exception, $msg) { + public function testEvaluateSilently($expr, $exception, $msg): void { $evaluator = new ConstExprEvaluator(); try { @@ -113,15 +116,15 @@ public function testEvaluateSilently($expr, $exception, $msg) { } } - public function provideTestEvaluateSilently() { + public static function provideTestEvaluateSilently() { return [ [ - new Expr\BinaryOp\Mod(new Scalar\LNumber(42), new Scalar\LNumber(0)), + new Expr\BinaryOp\Mod(new Scalar\Int_(42), new Scalar\Int_(0)), \Error::class, 'Modulo by zero' ], [ - new Expr\BinaryOp\Plus(new Scalar\LNumber(42), new Scalar\String_("1foo")), + new Expr\BinaryOp\Plus(new Scalar\Int_(42), new Scalar\String_("1foo")), \ErrorException::class, \PHP_VERSION_ID >= 80000 ? 'A non-numeric value encountered' diff --git a/test/PhpParser/ErrorHandler/CollectingTest.php b/test/PhpParser/ErrorHandler/CollectingTest.php index a20101a8b6..631b0b0ba4 100644 --- a/test/PhpParser/ErrorHandler/CollectingTest.php +++ b/test/PhpParser/ErrorHandler/CollectingTest.php @@ -4,9 +4,8 @@ use PhpParser\Error; -class CollectingTest extends \PHPUnit\Framework\TestCase -{ - public function testHandleError() { +class CollectingTest extends \PHPUnit\Framework\TestCase { + public function testHandleError(): void { $errorHandler = new Collecting(); $this->assertFalse($errorHandler->hasErrors()); $this->assertEmpty($errorHandler->getErrors()); diff --git a/test/PhpParser/ErrorHandler/ThrowingTest.php b/test/PhpParser/ErrorHandler/ThrowingTest.php index be641ec7a9..8442600a63 100644 --- a/test/PhpParser/ErrorHandler/ThrowingTest.php +++ b/test/PhpParser/ErrorHandler/ThrowingTest.php @@ -4,9 +4,8 @@ use PhpParser\Error; -class ThrowingTest extends \PHPUnit\Framework\TestCase -{ - public function testHandleError() { +class ThrowingTest extends \PHPUnit\Framework\TestCase { + public function testHandleError(): void { $this->expectException(Error::class); $this->expectExceptionMessage('Test'); $errorHandler = new Throwing(); diff --git a/test/PhpParser/ErrorTest.php b/test/PhpParser/ErrorTest.php index cc2d3fa5c8..b86412ee8b 100644 --- a/test/PhpParser/ErrorTest.php +++ b/test/PhpParser/ErrorTest.php @@ -2,8 +2,7 @@ namespace PhpParser; -class ErrorTest extends \PHPUnit\Framework\TestCase -{ +class ErrorTest extends \PHPUnit\Framework\TestCase { public function testConstruct() { $attributes = [ 'startLine' => 10, @@ -23,7 +22,7 @@ public function testConstruct() { /** * @depends testConstruct */ - public function testSetMessageAndLine(Error $error) { + public function testSetMessageAndLine(Error $error): void { $error->setRawMessage('Some other error'); $this->assertSame('Some other error', $error->getRawMessage()); @@ -32,7 +31,7 @@ public function testSetMessageAndLine(Error $error) { $this->assertSame('Some other error on line 15', $error->getMessage()); } - public function testUnknownLine() { + public function testUnknownLine(): void { $error = new Error('Some error'); $this->assertSame(-1, $error->getStartLine()); @@ -41,7 +40,7 @@ public function testUnknownLine() { } /** @dataProvider provideTestColumnInfo */ - public function testColumnInfo($code, $startPos, $endPos, $startColumn, $endColumn) { + public function testColumnInfo($code, $startPos, $endPos, $startColumn, $endColumn): void { $error = new Error('Some error', [ 'startFilePos' => $startPos, 'endFilePos' => $endPos, @@ -50,10 +49,9 @@ public function testColumnInfo($code, $startPos, $endPos, $startColumn, $endColu $this->assertTrue($error->hasColumnInfo()); $this->assertSame($startColumn, $error->getStartColumn($code)); $this->assertSame($endColumn, $error->getEndColumn($code)); - } - public function provideTestColumnInfo() { + public static function provideTestColumnInfo() { return [ // Error at "bar" [" 3]); $this->assertFalse($error->hasColumnInfo()); try { @@ -92,7 +90,7 @@ public function testNoColumnInfo() { } } - public function testInvalidPosInfo() { + public function testInvalidPosInfo(): void { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Invalid position information'); $error = new Error('Some error', [ diff --git a/test/PhpParser/Internal/DifferTest.php b/test/PhpParser/Internal/DifferTest.php index 6fac3fd365..a50ca6676d 100644 --- a/test/PhpParser/Internal/DifferTest.php +++ b/test/PhpParser/Internal/DifferTest.php @@ -2,8 +2,7 @@ namespace PhpParser\Internal; -class DifferTest extends \PHPUnit\Framework\TestCase -{ +class DifferTest extends \PHPUnit\Framework\TestCase { private function formatDiffString(array $diff) { $diffStr = ''; foreach ($diff as $diffElem) { @@ -29,13 +28,15 @@ private function formatDiffString(array $diff) { } /** @dataProvider provideTestDiff */ - public function testDiff($oldStr, $newStr, $expectedDiffStr) { - $differ = new Differ(function($a, $b) { return $a === $b; }); + public function testDiff($oldStr, $newStr, $expectedDiffStr): void { + $differ = new Differ(function ($a, $b) { + return $a === $b; + }); $diff = $differ->diff(str_split($oldStr), str_split($newStr)); $this->assertSame($expectedDiffStr, $this->formatDiffString($diff)); } - public function provideTestDiff() { + public static function provideTestDiff() { return [ ['abc', 'abc', 'abc'], ['abc', 'abcdef', 'abc+d+e+f'], @@ -48,13 +49,15 @@ public function provideTestDiff() { } /** @dataProvider provideTestDiffWithReplacements */ - public function testDiffWithReplacements($oldStr, $newStr, $expectedDiffStr) { - $differ = new Differ(function($a, $b) { return $a === $b; }); + public function testDiffWithReplacements($oldStr, $newStr, $expectedDiffStr): void { + $differ = new Differ(function ($a, $b) { + return $a === $b; + }); $diff = $differ->diffWithReplacements(str_split($oldStr), str_split($newStr)); $this->assertSame($expectedDiffStr, $this->formatDiffString($diff)); } - public function provideTestDiffWithReplacements() { + public static function provideTestDiffWithReplacements() { return [ ['abcde', 'axyze', 'a/bx/cy/dze'], ['abcde', 'xbcdy', '/axbcd/ey'], @@ -62,4 +65,15 @@ public function provideTestDiffWithReplacements() { ['abcde', 'axyzue', 'a-b-c-d+x+y+z+ue'], ]; } + + public function testNonContiguousIndices(): void { + $differ = new Differ(function ($a, $b) { + return $a === $b; + }); + $diff = $differ->diff([0 => 'a', 2 => 'b'], [0 => 'a', 3 => 'b']); + $this->assertEquals([ + new DiffElem(DiffElem::TYPE_KEEP, 'a', 'a'), + new DiffElem(DiffElem::TYPE_KEEP, 'b', 'b'), + ], $diff); + } } diff --git a/test/PhpParser/JsonDecoderTest.php b/test/PhpParser/JsonDecoderTest.php index d5cb05973e..9f1e837f18 100644 --- a/test/PhpParser/JsonDecoderTest.php +++ b/test/PhpParser/JsonDecoderTest.php @@ -2,9 +2,8 @@ namespace PhpParser; -class JsonDecoderTest extends \PHPUnit\Framework\TestCase -{ - public function testRoundTrip() { +class JsonDecoderTest extends \PHPUnit\Framework\TestCase { + public function testRoundTrip(): void { $code = <<<'PHP' expectException(\RuntimeException::class); $this->expectExceptionMessage($expectedMessage); $jsonDecoder->decode($json); } - public function provideTestDecodingError() { + public static function provideTestDecodingError() { return [ ['???', 'JSON decoding error: Syntax error'], ['{"nodeType":123}', 'Node type must be a string'], diff --git a/test/PhpParser/Lexer/EmulativeTest.php b/test/PhpParser/Lexer/EmulativeTest.php index a4eab67a89..2613289a30 100644 --- a/test/PhpParser/Lexer/EmulativeTest.php +++ b/test/PhpParser/Lexer/EmulativeTest.php @@ -5,136 +5,161 @@ use PhpParser\ErrorHandler; use PhpParser\Lexer; use PhpParser\LexerTest; -use PhpParser\Parser\Tokens; +use PhpParser\Parser\Php7; +use PhpParser\PhpVersion; +use PhpParser\Token; -class EmulativeTest extends LexerTest -{ - protected function getLexer(array $options = []) { - return new Emulative($options); +require __DIR__ . '/../../../lib/PhpParser/compatibility_tokens.php'; + +class EmulativeTest extends LexerTest { + protected function getLexer() { + return new Emulative(); } /** * @dataProvider provideTestReplaceKeywords */ - public function testReplaceKeywords($keyword, $expectedToken) { + public function testReplaceKeywords(string $keyword, int $expectedToken): void { $lexer = $this->getLexer(); - $lexer->startLexing('assertSame($expectedToken, $lexer->getNextToken()); - $this->assertSame(0, $lexer->getNextToken()); + $code = 'assertEquals([ + new Token(\T_OPEN_TAG, 'tokenize($code)); } /** * @dataProvider provideTestReplaceKeywords */ - public function testReplaceKeywordsUppercase($keyword, $expectedToken) { + public function testReplaceKeywordsUppercase(string $keyword, int $expectedToken): void { $lexer = $this->getLexer(); - $lexer->startLexing('assertSame($expectedToken, $lexer->getNextToken()); - $this->assertSame(0, $lexer->getNextToken()); + $this->assertEquals([ + new Token(\T_OPEN_TAG, 'tokenize($code)); } /** * @dataProvider provideTestReplaceKeywords */ - public function testNoReplaceKeywordsAfterObjectOperator(string $keyword) { + public function testNoReplaceKeywordsAfterObjectOperator(string $keyword): void { $lexer = $this->getLexer(); - $lexer->startLexing('' . $keyword); - - $this->assertSame(Tokens::T_OBJECT_OPERATOR, $lexer->getNextToken()); - $this->assertSame(Tokens::T_STRING, $lexer->getNextToken()); - $this->assertSame(0, $lexer->getNextToken()); + $code = '' . $keyword; + + $this->assertEquals([ + new Token(\T_OPEN_TAG, '', 1, 6), + new Token(\T_STRING, $keyword, 1, 8), + new Token(0, "\0", 1, \strlen($code)), + ], $lexer->tokenize($code)); } /** * @dataProvider provideTestReplaceKeywords */ - public function testNoReplaceKeywordsAfterObjectOperatorWithSpaces(string $keyword) { + public function testNoReplaceKeywordsAfterObjectOperatorWithSpaces(string $keyword): void { $lexer = $this->getLexer(); - $lexer->startLexing(' ' . $keyword); - - $this->assertSame(Tokens::T_OBJECT_OPERATOR, $lexer->getNextToken()); - $this->assertSame(Tokens::T_STRING, $lexer->getNextToken()); - $this->assertSame(0, $lexer->getNextToken()); + $code = ' ' . $keyword; + + $this->assertEquals([ + new Token(\T_OPEN_TAG, '', 1, 6), + new Token(\T_WHITESPACE, ' ', 1, 8), + new Token(\T_STRING, $keyword, 1, 12), + new Token(0, "\0", 1, \strlen($code)), + ], $lexer->tokenize($code)); } /** * @dataProvider provideTestReplaceKeywords */ - public function testNoReplaceKeywordsAfterNullsafeObjectOperator(string $keyword) { + public function testNoReplaceKeywordsAfterNullsafeObjectOperator(string $keyword): void { $lexer = $this->getLexer(); - $lexer->startLexing('' . $keyword); - - $this->assertSame(Tokens::T_NULLSAFE_OBJECT_OPERATOR, $lexer->getNextToken()); - $this->assertSame(Tokens::T_STRING, $lexer->getNextToken()); - $this->assertSame(0, $lexer->getNextToken()); + $code = '' . $keyword; + + $this->assertEquals([ + new Token(\T_OPEN_TAG, '', 1, 6), + new Token(\T_STRING, $keyword, 1, 9), + new Token(0, "\0", 1, \strlen($code)), + ], $lexer->tokenize($code)); } - public function provideTestReplaceKeywords() { + public static function provideTestReplaceKeywords() { return [ + // PHP 8.4 + ['__PROPERTY__', \T_PROPERTY_C], + // PHP 8.0 - ['match', Tokens::T_MATCH], + ['match', \T_MATCH], // PHP 7.4 - ['fn', Tokens::T_FN], + ['fn', \T_FN], // PHP 5.5 - ['finally', Tokens::T_FINALLY], - ['yield', Tokens::T_YIELD], + ['finally', \T_FINALLY], + ['yield', \T_YIELD], // PHP 5.4 - ['callable', Tokens::T_CALLABLE], - ['insteadof', Tokens::T_INSTEADOF], - ['trait', Tokens::T_TRAIT], - ['__TRAIT__', Tokens::T_TRAIT_C], + ['callable', \T_CALLABLE], + ['insteadof', \T_INSTEADOF], + ['trait', \T_TRAIT], + ['__TRAIT__', \T_TRAIT_C], // PHP 5.3 - ['__DIR__', Tokens::T_DIR], - ['goto', Tokens::T_GOTO], - ['namespace', Tokens::T_NAMESPACE], - ['__NAMESPACE__', Tokens::T_NS_C], + ['__DIR__', \T_DIR], + ['goto', \T_GOTO], + ['namespace', \T_NAMESPACE], + ['__NAMESPACE__', \T_NS_C], ]; } - private function assertSameTokens(array $expectedTokens, Lexer $lexer) { - $tokens = []; - while (0 !== $token = $lexer->getNextToken($text)) { - $tokens[] = [$token, $text]; + private function assertSameTokens(array $expectedTokens, array $tokens): void { + $reducedTokens = []; + foreach ($tokens as $token) { + if ($token->id === 0 || $token->isIgnorable()) { + continue; + } + $reducedTokens[] = [$token->id, $token->text]; } - $this->assertSame($expectedTokens, $tokens); + $this->assertSame($expectedTokens, $reducedTokens); } /** * @dataProvider provideTestLexNewFeatures */ - public function testLexNewFeatures($code, array $expectedTokens) { + public function testLexNewFeatures(string $code, array $expectedTokens): void { $lexer = $this->getLexer(); - $lexer->startLexing('assertSameTokens($expectedTokens, $lexer); + $this->assertSameTokens($expectedTokens, $lexer->tokenize('getLexer(); - $lexer->startLexing('assertSame(Tokens::T_CONSTANT_ENCAPSED_STRING, $lexer->getNextToken($text)); - $this->assertSame($stringifiedToken, $text); - $this->assertSame(0, $lexer->getNextToken()); + $this->assertEquals([ + new Token(\T_OPEN_TAG, 'tokenize($fullCode)); } /** * @dataProvider provideTestLexNewFeatures */ - public function testErrorAfterEmulation($code) { - $errorHandler = new ErrorHandler\Collecting; + public function testErrorAfterEmulation($code): void { + $errorHandler = new ErrorHandler\Collecting(); $lexer = $this->getLexer(); - $lexer->startLexing('tokenize('getErrors(); $this->assertCount(1, $errors); @@ -151,234 +176,345 @@ public function testErrorAfterEmulation($code) { $this->assertSame($expLine, $attrs['endLine']); } - public function provideTestLexNewFeatures() { + public static function provideTestLexNewFeatures() { return [ ['yield from', [ - [Tokens::T_YIELD_FROM, 'yield from'], + [\T_YIELD_FROM, 'yield from'], ]], ["yield\r\nfrom", [ - [Tokens::T_YIELD_FROM, "yield\r\nfrom"], + [\T_YIELD_FROM, "yield\r\nfrom"], ]], ['...', [ - [Tokens::T_ELLIPSIS, '...'], + [\T_ELLIPSIS, '...'], ]], ['**', [ - [Tokens::T_POW, '**'], + [\T_POW, '**'], ]], ['**=', [ - [Tokens::T_POW_EQUAL, '**='], + [\T_POW_EQUAL, '**='], ]], ['??', [ - [Tokens::T_COALESCE, '??'], + [\T_COALESCE, '??'], ]], ['<=>', [ - [Tokens::T_SPACESHIP, '<=>'], + [\T_SPACESHIP, '<=>'], ]], ['0b1010110', [ - [Tokens::T_LNUMBER, '0b1010110'], + [\T_LNUMBER, '0b1010110'], ]], ['0b1011010101001010110101010010101011010101010101101011001110111100', [ - [Tokens::T_DNUMBER, '0b1011010101001010110101010010101011010101010101101011001110111100'], + [\T_DNUMBER, '0b1011010101001010110101010010101011010101010101101011001110111100'], ]], ['\\', [ - [Tokens::T_NS_SEPARATOR, '\\'], + [\T_NS_SEPARATOR, '\\'], ]], ["<<<'NOWDOC'\nNOWDOC;\n", [ - [Tokens::T_START_HEREDOC, "<<<'NOWDOC'\n"], - [Tokens::T_END_HEREDOC, 'NOWDOC'], + [\T_START_HEREDOC, "<<<'NOWDOC'\n"], + [\T_END_HEREDOC, 'NOWDOC'], [ord(';'), ';'], ]], ["<<<'NOWDOC'\nFoobar\nNOWDOC;\n", [ - [Tokens::T_START_HEREDOC, "<<<'NOWDOC'\n"], - [Tokens::T_ENCAPSED_AND_WHITESPACE, "Foobar\n"], - [Tokens::T_END_HEREDOC, 'NOWDOC'], + [\T_START_HEREDOC, "<<<'NOWDOC'\n"], + [\T_ENCAPSED_AND_WHITESPACE, "Foobar\n"], + [\T_END_HEREDOC, 'NOWDOC'], [ord(';'), ';'], ]], // PHP 7.3: Flexible heredoc/nowdoc ["<<', [ - [Tokens::T_NULLSAFE_OBJECT_OPERATOR, '?->'], + [\T_NULLSAFE_OBJECT_OPERATOR, '?->'], ]], ['#[Attr]', [ - [Tokens::T_ATTRIBUTE, '#['], - [Tokens::T_STRING, 'Attr'], + [\T_ATTRIBUTE, '#['], + [\T_STRING, 'Attr'], [ord(']'), ']'], ]], ["#[\nAttr\n]", [ - [Tokens::T_ATTRIBUTE, '#['], - [Tokens::T_STRING, 'Attr'], + [\T_ATTRIBUTE, '#['], + [\T_STRING, 'Attr'], [ord(']'), ']'], ]], // Test interaction of two patch-based emulators ["<<public(set)', [ + [\T_OBJECT_OPERATOR, '->'], + [\T_STRING, 'public'], + [\ord('('), '('], + [\T_STRING, 'set'], + [\ord(')'), ')'], + ]], + ['?-> public(set)', [ + [\T_NULLSAFE_OBJECT_OPERATOR, '?->'], + [\T_STRING, 'public'], + [\ord('('), '('], + [\T_STRING, 'set'], + [\ord(')'), ')'], + ]], + + // PHP 8.5: Pipe operator + ['|>', [ + [\T_PIPE, '|>'] + ]], + + // PHP 8.5: Void cast + ['(void)', [ + [\T_VOID_CAST, '(void)'], + ]], + ["( \tvoid \t)", [ + [\T_VOID_CAST, "( \tvoid \t)"], + ]], + ['( vOiD)', [ + [\T_VOID_CAST, '( vOiD)'], + ]], + ["(void\n)", [ + [\ord('('), '('], + [\T_STRING, 'void'], + [\ord(')'), ')'], + ]], ]; } /** * @dataProvider provideTestTargetVersion */ - public function testTargetVersion(string $phpVersion, string $code, array $expectedTokens) { - $lexer = $this->getLexer(['phpVersion' => $phpVersion]); - $lexer->startLexing('assertSameTokens($expectedTokens, $lexer); + public function testTargetVersion(string $phpVersion, string $code, array $expectedTokens): void { + $lexer = new Emulative(PhpVersion::fromString($phpVersion)); + $this->assertSameTokens($expectedTokens, $lexer->tokenize('bar"', [ [ord('"'), '"'], - [Tokens::T_VARIABLE, '$foo'], - [Tokens::T_NULLSAFE_OBJECT_OPERATOR, '?->'], - [Tokens::T_STRING, 'bar'], + [\T_VARIABLE, '$foo'], + [\T_NULLSAFE_OBJECT_OPERATOR, '?->'], + [\T_STRING, 'bar'], [ord('"'), '"'], ]], ['8.0', '"$foo?->bar baz"', [ [ord('"'), '"'], - [Tokens::T_VARIABLE, '$foo'], - [Tokens::T_NULLSAFE_OBJECT_OPERATOR, '?->'], - [Tokens::T_STRING, 'bar'], - [Tokens::T_ENCAPSED_AND_WHITESPACE, ' baz'], + [\T_VARIABLE, '$foo'], + [\T_NULLSAFE_OBJECT_OPERATOR, '?->'], + [\T_STRING, 'bar'], + [\T_ENCAPSED_AND_WHITESPACE, ' baz'], [ord('"'), '"'], ]], + ['8.4', '__PROPERTY__', [[\T_PROPERTY_C, '__PROPERTY__']]], + ['8.3', '__PROPERTY__', [[\T_STRING, '__PROPERTY__']]], + ['8.4', '__property__', [[\T_PROPERTY_C, '__property__']]], + ['8.3', '__property__', [[\T_STRING, '__property__']]], + ['8.4', 'public(set)', [ + [\T_PUBLIC_SET, 'public(set)'], + ]], + ['8.3', 'public(set)', [ + [\T_PUBLIC, 'public'], + [\ord('('), '('], + [\T_STRING, 'set'], + [\ord(')'), ')'] + ]], + ['8.5', '|>', [ + [\T_PIPE, '|>'] + ]], + ['8.4', '|>', [ + [\ord('|'), '|'], + [\ord('>'), '>'], + ]], + ['8.5', '(void)', [ + [\T_VOID_CAST, '(void)'], + ]], + ['8.5', "( \tvoid \t)", [ + [\T_VOID_CAST, "( \tvoid \t)"], + ]], + ['8.4', '(void)', [ + [\ord('('), '('], + [\T_STRING, 'void'], + [\ord(')'), ')'], + ]], + ['8.4', "( \tVOID \t)", [ + [\ord('('), '('], + [\T_STRING, 'VOID'], + [\ord(')'), ')'], + ]], ]; } } diff --git a/test/PhpParser/LexerTest.php b/test/PhpParser/LexerTest.php index c15179646d..c70d83e22c 100644 --- a/test/PhpParser/LexerTest.php +++ b/test/PhpParser/LexerTest.php @@ -2,28 +2,25 @@ namespace PhpParser; -use PhpParser\Parser\Tokens; +require __DIR__ . '/../../lib/PhpParser/compatibility_tokens.php'; -class LexerTest extends \PHPUnit\Framework\TestCase -{ +class LexerTest extends \PHPUnit\Framework\TestCase { /* To allow overwriting in parent class */ - protected function getLexer(array $options = []) { - return new Lexer($options); + protected function getLexer() { + return new Lexer(); } /** * @dataProvider provideTestError */ - public function testError($code, $messages) { + public function testError($code, $messages): void { if (defined('HHVM_VERSION')) { $this->markTestSkipped('HHVM does not throw warnings from token_get_all()'); } $errorHandler = new ErrorHandler\Collecting(); - $lexer = $this->getLexer(['usedAttributes' => [ - 'comments', 'startLine', 'endLine', 'startFilePos', 'endFilePos' - ]]); - $lexer->startLexing($code, $errorHandler); + $lexer = $this->getLexer(); + $lexer->tokenize($code, $errorHandler); $errors = $errorHandler->getErrors(); $this->assertCount(count($messages), $errors); @@ -32,7 +29,7 @@ public function testError($code, $messages) { } } - public function provideTestError() { + public static function provideTestError() { return [ ["expectException(Error::class); + $this->expectExceptionMessage('Unterminated comment on line 1'); + $lexer = $this->getLexer(); + $lexer->tokenize("getLexer($options); - $lexer->startLexing($code); - while ($id = $lexer->getNextToken($value, $startAttributes, $endAttributes)) { - $token = array_shift($tokens); + public function testLex($code, $expectedTokens): void { + $lexer = $this->getLexer(); + $tokens = $lexer->tokenize($code); + foreach ($tokens as $token) { + if ($token->id === 0 || $token->isIgnorable()) { + continue; + } + + $expectedToken = array_shift($expectedTokens); - $this->assertSame($token[0], $id); - $this->assertSame($token[1], $value); - $this->assertEquals($token[2], $startAttributes); - $this->assertEquals($token[3], $endAttributes); + $this->assertSame($expectedToken[0], $token->id); + $this->assertSame($expectedToken[1], $token->text); } } - public function provideTestLex() { + public static function provideTestLex() { return [ - // tests conversion of closing PHP tag and drop of whitespace and opening tags - [ - 'plaintext', - [], - [ - [ - Tokens::T_STRING, 'tokens', - ['startLine' => 1], ['endLine' => 1] - ], - [ - ord(';'), '?>', - ['startLine' => 1], ['endLine' => 1] - ], - [ - Tokens::T_INLINE_HTML, 'plaintext', - ['startLine' => 1, 'hasLeadingNewline' => false], - ['endLine' => 1] - ], - ] - ], - // tests line numbers - [ - ' 2], ['endLine' => 2] - ], - [ - Tokens::T_STRING, 'token', - ['startLine' => 2], ['endLine' => 2] - ], - [ - ord('$'), '$', - [ - 'startLine' => 3, - 'comments' => [ - new Comment\Doc('/** doc' . "\n" . 'comment */', - 2, 14, 5, - 3, 31, 5), - ] - ], - ['endLine' => 3] - ], - ] - ], - // tests comment extraction - [ - ' 2, - 'comments' => [ - new Comment('/* comment */', - 1, 6, 1, 1, 18, 1), - new Comment('// comment', - 1, 20, 3, 1, 29, 3), - new Comment\Doc('/** docComment 1 */', - 2, 31, 5, 2, 49, 5), - new Comment\Doc('/** docComment 2 */', - 2, 50, 6, 2, 68, 6), - ], - ], - ['endLine' => 2] - ], - ] - ], - // tests differing start and end line - [ - ' 1], ['endLine' => 2] - ], - ] - ], - // tests exact file offsets - [ - ' ['startFilePos', 'endFilePos']], - [ - [ - Tokens::T_CONSTANT_ENCAPSED_STRING, '"a"', - ['startFilePos' => 6], ['endFilePos' => 8] - ], - [ - ord(';'), ';', - ['startFilePos' => 9], ['endFilePos' => 9] - ], - [ - Tokens::T_CONSTANT_ENCAPSED_STRING, '"b"', - ['startFilePos' => 18], ['endFilePos' => 20] - ], - [ - ord(';'), ';', - ['startFilePos' => 21], ['endFilePos' => 21] - ], - ] - ], - // tests token offsets - [ - ' ['startTokenPos', 'endTokenPos']], - [ - [ - Tokens::T_CONSTANT_ENCAPSED_STRING, '"a"', - ['startTokenPos' => 1], ['endTokenPos' => 1] - ], - [ - ord(';'), ';', - ['startTokenPos' => 2], ['endTokenPos' => 2] - ], - [ - Tokens::T_CONSTANT_ENCAPSED_STRING, '"b"', - ['startTokenPos' => 6], ['endTokenPos' => 6] - ], - [ - ord(';'), ';', - ['startTokenPos' => 7], ['endTokenPos' => 7] - ], - ] - ], - // tests all attributes being disabled - [ - ' []], - [ - [ - Tokens::T_VARIABLE, '$bar', - [], [] - ], - [ - ord(';'), ';', - [], [] - ] - ] - ], - // tests no tokens - [ - '', - [], - [] - ], // tests PHP 8 T_NAME_* emulation [ ' []], [ - [Tokens::T_NAME_QUALIFIED, 'Foo\Bar', [], []], - [Tokens::T_NAME_FULLY_QUALIFIED, '\Foo\Bar', [], []], - [Tokens::T_NAME_RELATIVE, 'namespace\Foo\Bar', [], []], - [Tokens::T_NAME_QUALIFIED, 'Foo\Bar', [], []], - [Tokens::T_NS_SEPARATOR, '\\', [], []], + [\T_NAME_QUALIFIED, 'Foo\Bar'], + [\T_NAME_FULLY_QUALIFIED, '\Foo\Bar'], + [\T_NAME_RELATIVE, 'namespace\Foo\Bar'], + [\T_NAME_QUALIFIED, 'Foo\Bar'], + [\T_NS_SEPARATOR, '\\'], ] ], // tests PHP 8 T_NAME_* emulation with reserved keywords [ ' []], [ - [Tokens::T_NAME_QUALIFIED, 'fn\use', [], []], - [Tokens::T_NAME_FULLY_QUALIFIED, '\fn\use', [], []], - [Tokens::T_NAME_RELATIVE, 'namespace\fn\use', [], []], - [Tokens::T_NAME_QUALIFIED, 'fn\use', [], []], - [Tokens::T_NS_SEPARATOR, '\\', [], []], + [\T_NAME_QUALIFIED, 'fn\use'], + [\T_NAME_FULLY_QUALIFIED, '\fn\use'], + [\T_NAME_RELATIVE, 'namespace\fn\use'], + [\T_NAME_QUALIFIED, 'fn\use'], + [\T_NS_SEPARATOR, '\\'], ] ], ]; } - /** - * @dataProvider provideTestHaltCompiler - */ - public function testHandleHaltCompiler($code, $remaining) { - $lexer = $this->getLexer(); - $lexer->startLexing($code); - - while (Tokens::T_HALT_COMPILER !== $lexer->getNextToken()); - - $this->assertSame($remaining, $lexer->handleHaltCompiler()); - $this->assertSame(0, $lexer->getNextToken()); - } - - public function provideTestHaltCompiler() { - return [ - ['Remaining Text', 'Remaining Text'], - //array('expectException(Error::class); - $this->expectExceptionMessage('__HALT_COMPILER must be followed by "();"'); - $lexer = $this->getLexer(); - $lexer->startLexing('getNextToken()); - $lexer->handleHaltCompiler(); - } - - public function testGetTokens() { + public function testGetTokens(): void { $code = 'getLexer(); - $lexer->startLexing($code); - $this->assertSame($expectedTokens, $lexer->getTokens()); + $this->assertEquals($expectedTokens, $lexer->tokenize($code)); } } diff --git a/test/PhpParser/ModifiersTest.php b/test/PhpParser/ModifiersTest.php new file mode 100644 index 0000000000..1b10e8e102 --- /dev/null +++ b/test/PhpParser/ModifiersTest.php @@ -0,0 +1,18 @@ +assertSame('public', Modifiers::toString(Modifiers::PUBLIC)); + } + + public function testToStringInvalid() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Unknown modifier 3'); + Modifiers::toString(Modifiers::PUBLIC | Modifiers::PROTECTED); + } +} diff --git a/test/PhpParser/NameContextTest.php b/test/PhpParser/NameContextTest.php index ee8458b67e..1c8295e767 100644 --- a/test/PhpParser/NameContextTest.php +++ b/test/PhpParser/NameContextTest.php @@ -5,12 +5,11 @@ use PhpParser\Node\Name; use PhpParser\Node\Stmt\Use_; -class NameContextTest extends \PHPUnit\Framework\TestCase -{ +class NameContextTest extends \PHPUnit\Framework\TestCase { /** * @dataProvider provideTestGetPossibleNames */ - public function testGetPossibleNames($type, $name, $expectedPossibleNames) { + public function testGetPossibleNames($type, $name, $expectedPossibleNames): void { $nameContext = new NameContext(new ErrorHandler\Throwing()); $nameContext->startNamespace(new Name('NS')); $nameContext->addAlias(new Name('Foo'), 'Foo', Use_::TYPE_NORMAL); @@ -33,7 +32,7 @@ public function testGetPossibleNames($type, $name, $expectedPossibleNames) { ); } - public function provideTestGetPossibleNames() { + public static function provideTestGetPossibleNames() { return [ [Use_::TYPE_NORMAL, 'Test', ['\Test']], [Use_::TYPE_NORMAL, 'Test\Namespaced', ['\Test\Namespaced']], diff --git a/test/PhpParser/Node/Expr/CallableLikeTest.php b/test/PhpParser/Node/Expr/CallableLikeTest.php new file mode 100644 index 0000000000..618c9723f9 --- /dev/null +++ b/test/PhpParser/Node/Expr/CallableLikeTest.php @@ -0,0 +1,98 @@ +assertSame($isFirstClassCallable, $node->isFirstClassCallable()); + if (!$isFirstClassCallable) { + $this->assertSame($node->getRawArgs(), $node->getArgs()); + } + } + + /** + * @dataProvider provideTestGetArg + */ + public function testGetArg(CallLike $node, ?Arg $expected): void { + $this->assertSame($expected, $node->getArg('bar', 1)); + } + + public static function provideTestIsFirstClassCallable() { + $normalArgs = [new Arg(new Int_(1))]; + $callableArgs = [new VariadicPlaceholder()]; + return [ + [new FuncCall(new Name('test'), $normalArgs), false], + [new FuncCall(new Name('test'), $callableArgs), true], + [new MethodCall(new Variable('this'), 'test', $normalArgs), false], + [new MethodCall(new Variable('this'), 'test', $callableArgs), true], + [new StaticCall(new Name('Test'), 'test', $normalArgs), false], + [new StaticCall(new Name('Test'), 'test', $callableArgs), true], + [new New_(new Name('Test'), $normalArgs), false], + [new NullsafeMethodCall(new Variable('this'), 'test', $normalArgs), false], + // This is not legal code, but accepted by the parser. + [new New_(new Name('Test'), $callableArgs), true], + [new NullsafeMethodCall(new Variable('this'), 'test', $callableArgs), true], + ]; + } + + public static function provideTestGetArg() { + $foo = new Arg(new Int_(1)); + $namedFoo = new Arg(new Int_(1), false, false, [], new Identifier('foo')); + $bar = new Arg(new Int_(2)); + $namedBar = new Arg(new Int_(2), false, false, [], new Identifier('bar')); + $unpack = new Arg(new Int_(3), false, true); + $callableArgs = [new VariadicPlaceholder()]; + return [ + [new FuncCall(new Name('test'), [$foo]), null], + [new FuncCall(new Name('test'), [$namedFoo]), null], + [new FuncCall(new Name('test'), [$foo, $bar]), $bar], + [new FuncCall(new Name('test'), [$namedBar]), $namedBar], + [new FuncCall(new Name('test'), [$namedFoo, $namedBar]), $namedBar], + [new FuncCall(new Name('test'), [$namedBar, $namedFoo]), $namedBar], + [new FuncCall(new Name('test'), [$namedFoo, $unpack]), null], + [new FuncCall(new Name('test'), $callableArgs), null], + [new MethodCall(new Variable('this'), 'test', [$foo]), null], + [new MethodCall(new Variable('this'), 'test', [$namedFoo]), null], + [new MethodCall(new Variable('this'), 'test', [$foo, $bar]), $bar], + [new MethodCall(new Variable('this'), 'test', [$namedBar]), $namedBar], + [new MethodCall(new Variable('this'), 'test', [$namedFoo, $namedBar]), $namedBar], + [new MethodCall(new Variable('this'), 'test', [$namedBar, $namedFoo]), $namedBar], + [new MethodCall(new Variable('this'), 'test', [$namedFoo, $unpack]), null], + [new MethodCall(new Variable('this'), 'test', $callableArgs), null], + [new StaticCall(new Name('Test'), 'test', [$foo]), null], + [new StaticCall(new Name('Test'), 'test', [$namedFoo]), null], + [new StaticCall(new Name('Test'), 'test', [$foo, $bar]), $bar], + [new StaticCall(new Name('Test'), 'test', [$namedBar]), $namedBar], + [new StaticCall(new Name('Test'), 'test', [$namedFoo, $namedBar]), $namedBar], + [new StaticCall(new Name('Test'), 'test', [$namedBar, $namedFoo]), $namedBar], + [new StaticCall(new Name('Test'), 'test', [$namedFoo, $unpack]), null], + [new StaticCall(new Name('Test'), 'test', $callableArgs), null], + [new New_(new Name('test'), [$foo]), null], + [new New_(new Name('test'), [$namedFoo]), null], + [new New_(new Name('test'), [$foo, $bar]), $bar], + [new New_(new Name('test'), [$namedBar]), $namedBar], + [new New_(new Name('test'), [$namedFoo, $namedBar]), $namedBar], + [new New_(new Name('test'), [$namedBar, $namedFoo]), $namedBar], + [new New_(new Name('test'), [$namedFoo, $unpack]), null], + [new NullsafeMethodCall(new Variable('this'), 'test', [$foo]), null], + [new NullsafeMethodCall(new Variable('this'), 'test', [$namedFoo]), null], + [new NullsafeMethodCall(new Variable('this'), 'test', [$foo, $bar]), $bar], + [new NullsafeMethodCall(new Variable('this'), 'test', [$namedBar]), $namedBar], + [new NullsafeMethodCall(new Variable('this'), 'test', [$namedFoo, $namedBar]), $namedBar], + [new NullsafeMethodCall(new Variable('this'), 'test', [$namedBar, $namedFoo]), $namedBar], + [new NullsafeMethodCall(new Variable('this'), 'test', [$namedFoo, $unpack]), null], + // This is not legal code, but accepted by the parser. + [new New_(new Name('Test'), $callableArgs), null], + [new NullsafeMethodCall(new Variable('this'), 'test', $callableArgs), null], + ]; + } +} diff --git a/test/PhpParser/Node/IdentifierTest.php b/test/PhpParser/Node/IdentifierTest.php index 2bd58fc8d0..fa3e066eb0 100644 --- a/test/PhpParser/Node/IdentifierTest.php +++ b/test/PhpParser/Node/IdentifierTest.php @@ -2,9 +2,13 @@ namespace PhpParser\Node; -class IdentifierTest extends \PHPUnit\Framework\TestCase -{ - public function testToString() { +class IdentifierTest extends \PHPUnit\Framework\TestCase { + public function testConstructorThrows(): void { + self::expectException(\InvalidArgumentException::class); + new Identifier(''); + } + + public function testToString(): void { $identifier = new Identifier('Foo'); $this->assertSame('Foo', (string) $identifier); @@ -13,12 +17,12 @@ public function testToString() { } /** @dataProvider provideTestIsSpecialClassName */ - public function testIsSpecialClassName($identifier, $expected) { + public function testIsSpecialClassName($identifier, $expected): void { $identifier = new Identifier($identifier); $this->assertSame($expected, $identifier->isSpecialClassName()); } - public function provideTestIsSpecialClassName() { + public static function provideTestIsSpecialClassName() { return [ ['self', true], ['PARENT', true], diff --git a/test/PhpParser/Node/NameTest.php b/test/PhpParser/Node/NameTest.php index 5e69ebba3c..eb25d04b1a 100644 --- a/test/PhpParser/Node/NameTest.php +++ b/test/PhpParser/Node/NameTest.php @@ -2,30 +2,31 @@ namespace PhpParser\Node; -class NameTest extends \PHPUnit\Framework\TestCase -{ - public function testConstruct() { +class NameTest extends \PHPUnit\Framework\TestCase { + public function testConstruct(): void { $name = new Name(['foo', 'bar']); - $this->assertSame(['foo', 'bar'], $name->parts); + $this->assertSame('foo\bar', $name->name); $name = new Name('foo\bar'); - $this->assertSame(['foo', 'bar'], $name->parts); + $this->assertSame('foo\bar', $name->name); $name = new Name($name); - $this->assertSame(['foo', 'bar'], $name->parts); + $this->assertSame('foo\bar', $name->name); } - public function testGet() { + public function testGet(): void { $name = new Name('foo'); $this->assertSame('foo', $name->getFirst()); $this->assertSame('foo', $name->getLast()); + $this->assertSame(['foo'], $name->getParts()); $name = new Name('foo\bar'); $this->assertSame('foo', $name->getFirst()); $this->assertSame('bar', $name->getLast()); + $this->assertSame(['foo', 'bar'], $name->getParts()); } - public function testToString() { + public function testToString(): void { $name = new Name('Foo\Bar'); $this->assertSame('Foo\Bar', (string) $name); @@ -33,7 +34,7 @@ public function testToString() { $this->assertSame('foo\bar', $name->toLowerString()); } - public function testSlice() { + public function testSlice(): void { $name = new Name('foo\bar\baz'); $this->assertEquals(new Name('foo\bar\baz'), $name->slice(0)); $this->assertEquals(new Name('bar\baz'), $name->slice(1)); @@ -49,31 +50,37 @@ public function testSlice() { $this->assertNull($name->slice(-2, -2)); } - public function testSliceOffsetTooLarge() { + public function testSliceOffsetTooLarge(): void { $this->expectException(\OutOfBoundsException::class); $this->expectExceptionMessage('Offset 4 is out of bounds'); (new Name('foo\bar\baz'))->slice(4); } - public function testSliceOffsetTooSmall() { + public function testSliceOffsetTooSmall(): void { $this->expectException(\OutOfBoundsException::class); $this->expectExceptionMessage('Offset -4 is out of bounds'); (new Name('foo\bar\baz'))->slice(-4); } - public function testSliceLengthTooLarge() { + public function testSliceLengthTooLarge(): void { $this->expectException(\OutOfBoundsException::class); $this->expectExceptionMessage('Length 4 is out of bounds'); (new Name('foo\bar\baz'))->slice(0, 4); } - public function testSliceLengthTooSmall() { + public function testSliceLengthTooSmall(): void { $this->expectException(\OutOfBoundsException::class); $this->expectExceptionMessage('Length -4 is out of bounds'); (new Name('foo\bar\baz'))->slice(0, -4); } - public function testConcat() { + public function testSliceLengthTooLargeWithOffset(): void { + $this->expectException(\OutOfBoundsException::class); + $this->expectExceptionMessage('Length 3 is out of bounds'); + (new Name('foo\bar\baz'))->slice(1, 3); + } + + public function testConcat(): void { $this->assertEquals(new Name('foo\bar\baz'), Name::concat('foo', 'bar\baz')); $this->assertEquals( new Name\FullyQualified('foo\bar'), @@ -91,7 +98,7 @@ public function testConcat() { $this->assertNull(Name::concat(null, null)); } - public function testNameTypes() { + public function testNameTypes(): void { $name = new Name('foo'); $this->assertTrue($name->isUnqualified()); $this->assertFalse($name->isQualified()); @@ -121,31 +128,31 @@ public function testNameTypes() { $this->assertSame('namespace\foo', $name->toCodeString()); } - public function testInvalidArg() { + public function testInvalidArg(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Expected string, array of parts or Name instance'); - Name::concat('foo', new \stdClass); + Name::concat('foo', new \stdClass()); } - public function testInvalidEmptyString() { + public function testInvalidEmptyString(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Name cannot be empty'); new Name(''); } - public function testInvalidEmptyArray() { + public function testInvalidEmptyArray(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Name cannot be empty'); new Name([]); } /** @dataProvider provideTestIsSpecialClassName */ - public function testIsSpecialClassName($name, $expected) { + public function testIsSpecialClassName($name, $expected): void { $name = new Name($name); $this->assertSame($expected, $name->isSpecialClassName()); } - public function provideTestIsSpecialClassName() { + public static function provideTestIsSpecialClassName() { return [ ['self', true], ['PARENT', true], diff --git a/test/PhpParser/Node/ParamTest.php b/test/PhpParser/Node/ParamTest.php new file mode 100644 index 0000000000..e4b670c317 --- /dev/null +++ b/test/PhpParser/Node/ParamTest.php @@ -0,0 +1,67 @@ +assertFalse($node->isPromoted()); + $this->assertFalse($node->isPrivate()); + $this->assertFalse($node->isProtected()); + $this->assertFalse($node->isPrivate()); + $this->assertFalse($node->isReadonly()); + $this->assertFalse($node->isPublicSet()); + $this->assertFalse($node->isProtectedSet()); + $this->assertFalse($node->isPrivateSet()); + } + + /** + * @dataProvider provideModifiers + */ + public function testModifiers(string $modifier): void { + $node = new Param(new Variable('foo')); + $node->flags = constant(Modifiers::class . '::' . strtoupper($modifier)); + $this->assertTrue($node->isPromoted()); + $this->assertTrue($node->{'is' . $modifier}()); + } + + public static function provideModifiers() { + return [ + ['public'], + ['protected'], + ['private'], + ['readonly'], + ]; + } + + public function testSetVisibility() { + $node = new Param(new Variable('foo')); + $node->flags = Modifiers::PRIVATE_SET; + $this->assertTrue($node->isPrivateSet()); + $this->assertTrue($node->isPublic()); + $node->flags = Modifiers::PROTECTED_SET; + $this->assertTrue($node->isProtectedSet()); + $this->assertTrue($node->isPublic()); + $node->flags = Modifiers::PUBLIC_SET; + $this->assertTrue($node->isPublicSet()); + $this->assertTrue($node->isPublic()); + } + + public function testPromotedPropertyWithoutVisibilityModifier(): void { + $node = new Param(new Variable('foo')); + $get = new PropertyHook('get', null); + $node->hooks[] = $get; + + $this->assertTrue($node->isPromoted()); + $this->assertTrue($node->isPublic()); + } + + public function testNonPromotedPropertyIsNotPublic(): void { + $node = new Param(new Variable('foo')); + $this->assertFalse($node->isPublic()); + } +} diff --git a/test/PhpParser/Node/PropertyHookTest.php b/test/PhpParser/Node/PropertyHookTest.php new file mode 100644 index 0000000000..8e5cf99fa8 --- /dev/null +++ b/test/PhpParser/Node/PropertyHookTest.php @@ -0,0 +1,89 @@ + constant(Modifiers::class . '::' . strtoupper($modifier)), + ] + ); + + $this->assertTrue($node->{'is' . $modifier}()); + } + + public function testNoModifiers(): void { + $node = new PropertyHook('get', null); + + $this->assertFalse($node->isFinal()); + } + + public static function provideModifiers() { + return [ + ['final'], + ]; + } + + public function testGetStmts(): void { + $expr = new Variable('test'); + $get = new PropertyHook('get', $expr); + $this->assertEquals([new Return_($expr)], $get->getStmts()); + + $set = new PropertyHook('set', $expr, [], ['propertyName' => 'abc']); + $this->assertEquals([ + new Expression(new Assign(new PropertyFetch(new Variable('this'), 'abc'), $expr)) + ], $set->getStmts()); + } + + public function testGetStmtsSetHookFromParser(): void { + $parser = (new ParserFactory())->createForNewestSupportedVersion(); + $prettyPrinter = new Standard(); + $stmts = $parser->parse(<<<'CODE' + 123; } + + public function __construct(public $prop2 { set => 456; }) {} + } + CODE); + + $hook1 = $stmts[0]->stmts[0]->hooks[0]; + $this->assertEquals('$this->prop1 = 123;', $prettyPrinter->prettyPrint($hook1->getStmts())); + + $hook2 = $stmts[0]->stmts[1]->params[0]->hooks[0]; + $this->assertEquals('$this->prop2 = 456;', $prettyPrinter->prettyPrint($hook2->getStmts())); + } + + public function testGetStmtsUnknownHook(): void { + $expr = new Variable('test'); + $hook = new PropertyHook('foobar', $expr); + + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Unknown property hook "foobar"'); + $hook->getStmts(); + } + + public function testGetStmtsSetHookWithoutPropertyName(): void { + $expr = new Variable('test'); + $set = new PropertyHook('set', $expr); + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Can only use getStmts() on a "set" hook if the "propertyName" attribute is set'); + $set->getStmts(); + } +} diff --git a/test/PhpParser/Node/Scalar/DNumberTest.php b/test/PhpParser/Node/Scalar/DNumberTest.php new file mode 100644 index 0000000000..2bd31c3367 --- /dev/null +++ b/test/PhpParser/Node/Scalar/DNumberTest.php @@ -0,0 +1,25 @@ +createForNewestSupportedVersion(); + $nodes = $parser->parse('assertInstanceOf(Echo_::class, $echo); + + /** @var Echo_ $echo */ + $dnumber = $echo->exprs[0]; + $this->assertInstanceOf(Float_::class, $dnumber); + + /** @var Float_ $dnumber */ + $this->assertSame(1234.56, $dnumber->value); + $this->assertSame('1_234.56', $dnumber->getAttribute('rawValue')); + } +} diff --git a/test/PhpParser/Node/Scalar/MagicConstTest.php b/test/PhpParser/Node/Scalar/MagicConstTest.php index c8ae433b00..825b1b171a 100644 --- a/test/PhpParser/Node/Scalar/MagicConstTest.php +++ b/test/PhpParser/Node/Scalar/MagicConstTest.php @@ -2,25 +2,24 @@ namespace PhpParser\Node\Scalar; -class MagicConstTest extends \PHPUnit\Framework\TestCase -{ +class MagicConstTest extends \PHPUnit\Framework\TestCase { /** * @dataProvider provideTestGetName */ - public function testGetName(MagicConst $magicConst, $name) { + public function testGetName(MagicConst $magicConst, $name): void { $this->assertSame($name, $magicConst->getName()); } - public function provideTestGetName() { + public static function provideTestGetName() { return [ - [new MagicConst\Class_, '__CLASS__'], - [new MagicConst\Dir, '__DIR__'], - [new MagicConst\File, '__FILE__'], - [new MagicConst\Function_, '__FUNCTION__'], - [new MagicConst\Line, '__LINE__'], - [new MagicConst\Method, '__METHOD__'], - [new MagicConst\Namespace_, '__NAMESPACE__'], - [new MagicConst\Trait_, '__TRAIT__'], + [new MagicConst\Class_(), '__CLASS__'], + [new MagicConst\Dir(), '__DIR__'], + [new MagicConst\File(), '__FILE__'], + [new MagicConst\Function_(), '__FUNCTION__'], + [new MagicConst\Line(), '__LINE__'], + [new MagicConst\Method(), '__METHOD__'], + [new MagicConst\Namespace_(), '__NAMESPACE__'], + [new MagicConst\Trait_(), '__TRAIT__'], ]; } } diff --git a/test/PhpParser/Node/Scalar/NumberTest.php b/test/PhpParser/Node/Scalar/NumberTest.php new file mode 100644 index 0000000000..27bfe5abcc --- /dev/null +++ b/test/PhpParser/Node/Scalar/NumberTest.php @@ -0,0 +1,24 @@ +createForNewestSupportedVersion(); + $nodes = $parser->parse('assertInstanceOf(Echo_::class, $echo); + + /** @var Echo_ $echo */ + $lnumber = $echo->exprs[0]; + $this->assertInstanceOf(Int_::class, $lnumber); + + /** @var Int_ $lnumber */ + $this->assertSame(1234, $lnumber->value); + $this->assertSame('1_234', $lnumber->getAttribute('rawValue')); + } +} diff --git a/test/PhpParser/Node/Scalar/StringTest.php b/test/PhpParser/Node/Scalar/StringTest.php index 814a7758fc..cb0968c2e5 100644 --- a/test/PhpParser/Node/Scalar/StringTest.php +++ b/test/PhpParser/Node/Scalar/StringTest.php @@ -2,12 +2,30 @@ namespace PhpParser\Node\Scalar; -class StringTest extends \PHPUnit\Framework\TestCase -{ +use PhpParser\Node\Stmt\Echo_; +use PhpParser\ParserFactory; + +class StringTest extends \PHPUnit\Framework\TestCase { + public function testRawValue(): void { + $parser = (new ParserFactory())->createForNewestSupportedVersion(); + $nodes = $parser->parse('assertInstanceOf(Echo_::class, $echo); + + /** @var Echo_ $echo */ + $string = $echo->exprs[0]; + $this->assertInstanceOf(String_::class, $string); + + /** @var String_ $string */ + $this->assertSame('sequence A', $string->value); + $this->assertSame('"sequence \\x41"', $string->getAttribute('rawValue')); + } + /** * @dataProvider provideTestParseEscapeSequences */ - public function testParseEscapeSequences($expected, $string, $quote) { + public function testParseEscapeSequences($expected, $string, $quote): void { $this->assertSame( $expected, String_::parseEscapeSequences($string, $quote) @@ -17,14 +35,14 @@ public function testParseEscapeSequences($expected, $string, $quote) { /** * @dataProvider provideTestParse */ - public function testCreate($expected, $string) { + public function testCreate($expected, $string): void { $this->assertSame( $expected, String_::parse($string) ); } - public function provideTestParseEscapeSequences() { + public static function provideTestParseEscapeSequences() { return [ ['"', '\\"', '"'], ['\\"', '\\"', '`'], @@ -39,7 +57,7 @@ public function provideTestParseEscapeSequences() { ]; } - public function provideTestParse() { + public static function provideTestParse() { $tests = [ ['A', '\'A\''], ['A', 'b\'A\''], @@ -49,7 +67,7 @@ public function provideTestParse() { ['\'', '\'\\\'\''], ]; - foreach ($this->provideTestParseEscapeSequences() as $i => $test) { + foreach (self::provideTestParseEscapeSequences() as $i => $test) { // skip second and third tests, they aren't for double quotes if ($i !== 1 && $i !== 2) { $tests[] = [$test[0], '"' . $test[1] . '"']; diff --git a/test/PhpParser/Node/Stmt/ClassConstTest.php b/test/PhpParser/Node/Stmt/ClassConstTest.php index 9a1b4697ca..7206ebf4c8 100644 --- a/test/PhpParser/Node/Stmt/ClassConstTest.php +++ b/test/PhpParser/Node/Stmt/ClassConstTest.php @@ -2,33 +2,36 @@ namespace PhpParser\Node\Stmt; -class ClassConstTest extends \PHPUnit\Framework\TestCase -{ +use PhpParser\Modifiers; + +class ClassConstTest extends \PHPUnit\Framework\TestCase { /** * @dataProvider provideModifiers */ - public function testModifiers($modifier) { + public function testModifiers($modifier): void { $node = new ClassConst( [], // invalid - constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier)) + constant(Modifiers::class . '::' . strtoupper($modifier)) ); $this->assertTrue($node->{'is' . $modifier}()); } - public function testNoModifiers() { + public function testNoModifiers(): void { $node = new ClassConst([], 0); $this->assertTrue($node->isPublic()); $this->assertFalse($node->isProtected()); $this->assertFalse($node->isPrivate()); + $this->assertFalse($node->isFinal()); } - public function provideModifiers() { + public static function provideModifiers() { return [ ['public'], ['protected'], ['private'], + ['final'], ]; } } diff --git a/test/PhpParser/Node/Stmt/ClassMethodTest.php b/test/PhpParser/Node/Stmt/ClassMethodTest.php index 51c5f1c2cf..17bb3ec508 100644 --- a/test/PhpParser/Node/Stmt/ClassMethodTest.php +++ b/test/PhpParser/Node/Stmt/ClassMethodTest.php @@ -2,24 +2,24 @@ namespace PhpParser\Node\Stmt; +use PhpParser\Modifiers; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Name; use PhpParser\Node\Param; -class ClassMethodTest extends \PHPUnit\Framework\TestCase -{ +class ClassMethodTest extends \PHPUnit\Framework\TestCase { /** * @dataProvider provideModifiers */ - public function testModifiers($modifier) { + public function testModifiers($modifier): void { $node = new ClassMethod('foo', [ - 'type' => constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier)) + 'type' => constant(Modifiers::class . '::' . strtoupper($modifier)) ]); $this->assertTrue($node->{'is' . $modifier}()); } - public function testNoModifiers() { + public function testNoModifiers(): void { $node = new ClassMethod('foo', ['type' => 0]); $this->assertTrue($node->isPublic()); @@ -31,7 +31,7 @@ public function testNoModifiers() { $this->assertFalse($node->isMagic()); } - public function provideModifiers() { + public static function provideModifiers() { return [ ['public'], ['protected'], @@ -49,16 +49,15 @@ public function provideModifiers() { * * @param string $modifier Node type modifier */ - public function testImplicitPublic(string $modifier) - { + public function testImplicitPublic(string $modifier): void { $node = new ClassMethod('foo', [ - 'type' => constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier)) + 'type' => constant(Modifiers::class . '::' . strtoupper($modifier)) ]); $this->assertTrue($node->isPublic(), 'Node should be implicitly public'); } - public function implicitPublicModifiers() { + public static function implicitPublicModifiers() { return [ ['abstract'], ['final'], @@ -71,12 +70,12 @@ public function implicitPublicModifiers() { * * @param string $name Node name */ - public function testMagic(string $name) { + public function testMagic(string $name): void { $node = new ClassMethod($name); $this->assertTrue($node->isMagic(), 'Method should be magic'); } - public function provideMagics() { + public static function provideMagics() { return [ ['__construct'], ['__DESTRUCT'], @@ -96,7 +95,7 @@ public function provideMagics() { ]; } - public function testFunctionLike() { + public function testFunctionLike(): void { $param = new Param(new Variable('a')); $type = new Name('Foo'); $return = new Return_(new Variable('a')); diff --git a/test/PhpParser/Node/Stmt/ClassTest.php b/test/PhpParser/Node/Stmt/ClassTest.php index da85e5b90d..3f701b69d4 100644 --- a/test/PhpParser/Node/Stmt/ClassTest.php +++ b/test/PhpParser/Node/Stmt/ClassTest.php @@ -2,27 +2,28 @@ namespace PhpParser\Node\Stmt; +use PhpParser\Modifiers; +use PhpParser\Node\PropertyItem; use PhpParser\Node\Scalar\String_; -class ClassTest extends \PHPUnit\Framework\TestCase -{ - public function testIsAbstract() { - $class = new Class_('Foo', ['type' => Class_::MODIFIER_ABSTRACT]); +class ClassTest extends \PHPUnit\Framework\TestCase { + public function testIsAbstract(): void { + $class = new Class_('Foo', ['type' => Modifiers::ABSTRACT]); $this->assertTrue($class->isAbstract()); $class = new Class_('Foo'); $this->assertFalse($class->isAbstract()); } - public function testIsFinal() { - $class = new Class_('Foo', ['type' => Class_::MODIFIER_FINAL]); + public function testIsFinal(): void { + $class = new Class_('Foo', ['type' => Modifiers::FINAL]); $this->assertTrue($class->isFinal()); $class = new Class_('Foo'); $this->assertFalse($class->isFinal()); } - public function testGetTraitUses() { + public function testGetTraitUses(): void { $traitUses = [ new TraitUse([new Trait_('foo')]), new TraitUse([new Trait_('bar')]), @@ -38,7 +39,7 @@ public function testGetTraitUses() { $this->assertSame($traitUses, $class->getTraitUses()); } - public function testGetMethods() { + public function testGetMethods(): void { $methods = [ new ClassMethod('foo'), new ClassMethod('bar'), @@ -58,7 +59,7 @@ public function testGetMethods() { $this->assertSame($methods, $class->getMethods()); } - public function testGetConstants() { + public function testGetConstants(): void { $constants = [ new ClassConst([new \PhpParser\Node\Const_('foo', new String_('foo_value'))]), new ClassConst([new \PhpParser\Node\Const_('bar', new String_('bar_value'))]), @@ -75,11 +76,10 @@ public function testGetConstants() { $this->assertSame($constants, $class->getConstants()); } - public function testGetProperties() - { + public function testGetProperties(): void { $properties = [ - new Property(Class_::MODIFIER_PUBLIC, [new PropertyProperty('foo')]), - new Property(Class_::MODIFIER_PUBLIC, [new PropertyProperty('bar')]), + new Property(Modifiers::PUBLIC, [new PropertyItem('foo')]), + new Property(Modifiers::PUBLIC, [new PropertyItem('bar')]), ]; $class = new Class_('Foo', [ 'stmts' => [ @@ -94,11 +94,11 @@ public function testGetProperties() $this->assertSame($properties, $class->getProperties()); } - public function testGetProperty() { + public function testGetProperty(): void { $properties = [ - $fooProp = new Property(Class_::MODIFIER_PUBLIC, [new PropertyProperty('foo1')]), - $barProp = new Property(Class_::MODIFIER_PUBLIC, [new PropertyProperty('BAR1')]), - $fooBarProp = new Property(Class_::MODIFIER_PUBLIC, [new PropertyProperty('foo2'), new PropertyProperty('bar2')]), + $fooProp = new Property(Modifiers::PUBLIC, [new PropertyItem('foo1')]), + $barProp = new Property(Modifiers::PUBLIC, [new PropertyItem('BAR1')]), + $fooBarProp = new Property(Modifiers::PUBLIC, [new PropertyItem('foo2'), new PropertyItem('bar2')]), ]; $class = new Class_('Foo', [ 'stmts' => [ @@ -119,7 +119,7 @@ public function testGetProperty() { $this->assertNull($class->getProperty('nonExisting')); } - public function testGetMethod() { + public function testGetMethod(): void { $methodConstruct = new ClassMethod('__CONSTRUCT'); $methodTest = new ClassMethod('test'); $class = new Class_('Foo', [ diff --git a/test/PhpParser/Node/Stmt/InterfaceTest.php b/test/PhpParser/Node/Stmt/InterfaceTest.php index 48c8e2bbeb..5bb4a7840d 100644 --- a/test/PhpParser/Node/Stmt/InterfaceTest.php +++ b/test/PhpParser/Node/Stmt/InterfaceTest.php @@ -5,9 +5,8 @@ use PhpParser\Node; use PhpParser\Node\Scalar\String_; -class InterfaceTest extends \PHPUnit\Framework\TestCase -{ - public function testGetMethods() { +class InterfaceTest extends \PHPUnit\Framework\TestCase { + public function testGetMethods(): void { $methods = [ new ClassMethod('foo'), new ClassMethod('bar'), @@ -25,7 +24,7 @@ public function testGetMethods() { $this->assertSame($methods, $interface->getMethods()); } - public function testGetConstants() { + public function testGetConstants(): void { $constants = [ new ClassConst([new \PhpParser\Node\Const_('foo', new String_('foo_value'))]), new ClassConst([new \PhpParser\Node\Const_('bar', new String_('bar_value'))]), diff --git a/test/PhpParser/Node/Stmt/PropertyTest.php b/test/PhpParser/Node/Stmt/PropertyTest.php index e5d69fba5d..4eb252e008 100644 --- a/test/PhpParser/Node/Stmt/PropertyTest.php +++ b/test/PhpParser/Node/Stmt/PropertyTest.php @@ -2,43 +2,69 @@ namespace PhpParser\Node\Stmt; -class PropertyTest extends \PHPUnit\Framework\TestCase -{ +use PhpParser\Modifiers; + +class PropertyTest extends \PHPUnit\Framework\TestCase { /** * @dataProvider provideModifiers */ - public function testModifiers($modifier) { + public function testModifiers($modifier): void { $node = new Property( - constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier)), + constant(Modifiers::class . '::' . strtoupper($modifier)), [] // invalid ); $this->assertTrue($node->{'is' . $modifier}()); } - public function testNoModifiers() { + public function testNoModifiers(): void { $node = new Property(0, []); $this->assertTrue($node->isPublic()); $this->assertFalse($node->isProtected()); $this->assertFalse($node->isPrivate()); $this->assertFalse($node->isStatic()); + $this->assertFalse($node->isReadonly()); + $this->assertFalse($node->isPublicSet()); + $this->assertFalse($node->isProtectedSet()); + $this->assertFalse($node->isPrivateSet()); } - public function testStaticImplicitlyPublic() { - $node = new Property(Class_::MODIFIER_STATIC, []); + public function testStaticImplicitlyPublic(): void { + $node = new Property(Modifiers::STATIC, []); $this->assertTrue($node->isPublic()); $this->assertFalse($node->isProtected()); $this->assertFalse($node->isPrivate()); $this->assertTrue($node->isStatic()); + $this->assertFalse($node->isReadonly()); } - public function provideModifiers() { + public static function provideModifiers() { return [ ['public'], ['protected'], ['private'], ['static'], + ['readonly'], ]; } + + public function testSetVisibility() { + $node = new Property(Modifiers::PRIVATE_SET, []); + $this->assertTrue($node->isPrivateSet()); + $node = new Property(Modifiers::PROTECTED_SET, []); + $this->assertTrue($node->isProtectedSet()); + $node = new Property(Modifiers::PUBLIC_SET, []); + $this->assertTrue($node->isPublicSet()); + } + + public function testIsFinal() { + $node = new Property(Modifiers::FINAL, []); + $this->assertTrue($node->isFinal()); + } + + public function testIsAbstract() { + $node = new Property(Modifiers::ABSTRACT, []); + $this->assertTrue($node->isAbstract()); + } } diff --git a/test/PhpParser/NodeAbstractTest.php b/test/PhpParser/NodeAbstractTest.php index 4c56e8f32b..cdd193a978 100644 --- a/test/PhpParser/NodeAbstractTest.php +++ b/test/PhpParser/NodeAbstractTest.php @@ -2,30 +2,30 @@ namespace PhpParser; -class DummyNode extends NodeAbstract -{ +class DummyNode extends NodeAbstract { public $subNode1; public $subNode2; + public $notSubNode; - public function __construct($subNode1, $subNode2, $attributes) { + public function __construct($subNode1, $subNode2, $notSubNode, $attributes) { parent::__construct($attributes); $this->subNode1 = $subNode1; $this->subNode2 = $subNode2; + $this->notSubNode = $notSubNode; } - public function getSubNodeNames() : array { + public function getSubNodeNames(): array { return ['subNode1', 'subNode2']; } // This method is only overwritten because the node is located in an unusual namespace - public function getType() : string { + public function getType(): string { return 'Dummy'; } } -class NodeAbstractTest extends \PHPUnit\Framework\TestCase -{ - public function provideNodes() { +class NodeAbstractTest extends \PHPUnit\Framework\TestCase { + public static function provideNodes() { $attributes = [ 'startLine' => 10, 'endLine' => 11, @@ -40,8 +40,7 @@ public function provideNodes() { ], ]; - $node = new DummyNode('value1', 'value2', $attributes); - $node->notSubNode = 'value3'; + $node = new DummyNode('value1', 'value2', 'value3', $attributes); return [ [$attributes, $node], @@ -64,9 +63,9 @@ public function testConstruct(array $attributes, Node $node) { $this->assertSame('/** doc comment */', $node->getDocComment()->getText()); $this->assertSame('value1', $node->subNode1); $this->assertSame('value2', $node->subNode2); - $this->assertObjectHasAttribute('subNode1', $node); - $this->assertObjectHasAttribute('subNode2', $node); - $this->assertObjectNotHasAttribute('subNode3', $node); + $this->assertTrue(isset($node->subNode1)); + $this->assertTrue(isset($node->subNode2)); + $this->assertTrue(!isset($node->subNode3)); $this->assertSame($attributes, $node->getAttributes()); $this->assertSame($attributes['comments'], $node->getComments()); @@ -76,7 +75,7 @@ public function testConstruct(array $attributes, Node $node) { /** * @dataProvider provideNodes */ - public function testGetDocComment(array $attributes, Node $node) { + public function testGetDocComment(array $attributes, Node $node): void { $this->assertSame('/** doc comment */', $node->getDocComment()->getText()); $comments = $node->getComments(); @@ -89,8 +88,8 @@ public function testGetDocComment(array $attributes, Node $node) { $this->assertNull($node->getDocComment()); } - public function testSetDocComment() { - $node = new DummyNode(null, null, []); + public function testSetDocComment(): void { + $node = new DummyNode(null, null, null, []); // Add doc comment to node without comments $docComment = new Comment\Doc('/** doc */'); @@ -120,25 +119,25 @@ public function testSetDocComment() { /** * @dataProvider provideNodes */ - public function testChange(array $attributes, Node $node) { + public function testChange(array $attributes, DummyNode $node): void { // direct modification - $node->subNode = 'newValue'; - $this->assertSame('newValue', $node->subNode); + $node->subNode1 = 'newValue'; + $this->assertSame('newValue', $node->subNode1); // indirect modification - $subNode =& $node->subNode; + $subNode = &$node->subNode1; $subNode = 'newNewValue'; - $this->assertSame('newNewValue', $node->subNode); + $this->assertSame('newNewValue', $node->subNode1); // removal - unset($node->subNode); - $this->assertObjectNotHasAttribute('subNode', $node); + unset($node->subNode1); + $this->assertFalse(isset($node->subNode1)); } /** * @dataProvider provideNodes */ - public function testIteration(array $attributes, Node $node) { + public function testIteration(array $attributes, Node $node): void { // Iteration is simple object iteration over properties, // not over subnodes $i = 0; @@ -153,14 +152,14 @@ public function testIteration(array $attributes, Node $node) { $this->assertSame('notSubNode', $key); $this->assertSame('value3', $value); } else { - throw new \Exception; + throw new \Exception(); } $i++; } $this->assertSame(3, $i); } - public function testAttributes() { + public function testAttributes(): void { /** @var $node Node */ $node = $this->getMockForAbstractClass(NodeAbstract::class); @@ -202,7 +201,7 @@ public function testAttributes() { ); } - public function testJsonSerialization() { + public function testJsonSerialization(): void { $code = <<<'PHP' =')) { + $expected = $expected81; + } $parser = new Parser\Php7(new Lexer()); $stmts = $parser->parse(canonicalize($code)); diff --git a/test/PhpParser/NodeDumperTest.php b/test/PhpParser/NodeDumperTest.php index 036c3d1ee5..f0e65cacdb 100644 --- a/test/PhpParser/NodeDumperTest.php +++ b/test/PhpParser/NodeDumperTest.php @@ -2,8 +2,7 @@ namespace PhpParser; -class NodeDumperTest extends \PHPUnit\Framework\TestCase -{ +class NodeDumperTest extends \PHPUnit\Framework\TestCase { private function canonicalize($string) { return str_replace("\r\n", "\n", $string); } @@ -11,13 +10,13 @@ private function canonicalize($string) { /** * @dataProvider provideTestDump */ - public function testDump($node, $dump) { - $dumper = new NodeDumper; + public function testDump($node, $dump): void { + $dumper = new NodeDumper(); $this->assertSame($this->canonicalize($dump), $this->canonicalize($dumper->dump($node))); } - public function provideTestDump() { + public static function provideTestDump() { return [ [ [], @@ -35,19 +34,16 @@ public function provideTestDump() { [ new Node\Name(['Hallo', 'World']), 'Name( - parts: array( - 0: Hallo - 1: World - ) + name: Hallo\World )' ], [ new Node\Expr\Array_([ - new Node\Expr\ArrayItem(new Node\Scalar\String_('Foo')) + new Node\ArrayItem(new Node\Scalar\String_('Foo')) ]), 'Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Scalar_String( value: Foo @@ -61,11 +57,8 @@ public function provideTestDump() { ]; } - public function testDumpWithPositions() { - $parser = (new ParserFactory)->create( - ParserFactory::ONLY_PHP7, - new Lexer(['usedAttributes' => ['startLine', 'endLine', 'startFilePos', 'endFilePos']]) - ); + public function testDumpWithPositions(): void { + $parser = (new ParserFactory())->createForHostVersion(); $dumper = new NodeDumper(['dumpPositions' => true]); $code = "assertSame($this->canonicalize($expected), $this->canonicalize($dump)); } - public function testError() { + public function testError(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Can only dump nodes and arrays.'); - $dumper = new NodeDumper; - $dumper->dump(new \stdClass); + $dumper = new NodeDumper(); + $dumper->dump(new \stdClass()); } } diff --git a/test/PhpParser/NodeFinderTest.php b/test/PhpParser/NodeFinderTest.php index 909738a738..2929c5f869 100644 --- a/test/PhpParser/NodeFinderTest.php +++ b/test/PhpParser/NodeFinderTest.php @@ -4,8 +4,7 @@ use PhpParser\Node\Expr; -class NodeFinderTest extends \PHPUnit\Framework\TestCase -{ +class NodeFinderTest extends \PHPUnit\Framework\TestCase { private function getStmtsAndVars() { $assign = new Expr\Assign(new Expr\Variable('a'), new Expr\BinaryOp\Concat( new Expr\Variable('b'), new Expr\Variable('c') @@ -15,42 +14,46 @@ private function getStmtsAndVars() { return [$stmts, $vars]; } - public function testFind() { - $finder = new NodeFinder; + public function testFind(): void { + $finder = new NodeFinder(); list($stmts, $vars) = $this->getStmtsAndVars(); - $varFilter = function(Node $node) { + $varFilter = function (Node $node) { return $node instanceof Expr\Variable; }; $this->assertSame($vars, $finder->find($stmts, $varFilter)); $this->assertSame($vars, $finder->find($stmts[0], $varFilter)); - $noneFilter = function () { return false; }; + $noneFilter = function () { + return false; + }; $this->assertSame([], $finder->find($stmts, $noneFilter)); } - public function testFindInstanceOf() { - $finder = new NodeFinder; + public function testFindInstanceOf(): void { + $finder = new NodeFinder(); list($stmts, $vars) = $this->getStmtsAndVars(); $this->assertSame($vars, $finder->findInstanceOf($stmts, Expr\Variable::class)); $this->assertSame($vars, $finder->findInstanceOf($stmts[0], Expr\Variable::class)); $this->assertSame([], $finder->findInstanceOf($stmts, Expr\BinaryOp\Mul::class)); } - public function testFindFirst() { - $finder = new NodeFinder; + public function testFindFirst(): void { + $finder = new NodeFinder(); list($stmts, $vars) = $this->getStmtsAndVars(); - $varFilter = function(Node $node) { + $varFilter = function (Node $node) { return $node instanceof Expr\Variable; }; $this->assertSame($vars[0], $finder->findFirst($stmts, $varFilter)); $this->assertSame($vars[0], $finder->findFirst($stmts[0], $varFilter)); - $noneFilter = function () { return false; }; + $noneFilter = function () { + return false; + }; $this->assertNull($finder->findFirst($stmts, $noneFilter)); } - public function testFindFirstInstanceOf() { - $finder = new NodeFinder; + public function testFindFirstInstanceOf(): void { + $finder = new NodeFinder(); list($stmts, $vars) = $this->getStmtsAndVars(); $this->assertSame($vars[0], $finder->findFirstInstanceOf($stmts, Expr\Variable::class)); $this->assertSame($vars[0], $finder->findFirstInstanceOf($stmts[0], Expr\Variable::class)); diff --git a/test/PhpParser/NodeTraverserTest.php b/test/PhpParser/NodeTraverserTest.php index 9880ae9de8..09ea8143f7 100644 --- a/test/PhpParser/NodeTraverserTest.php +++ b/test/PhpParser/NodeTraverserTest.php @@ -3,18 +3,20 @@ namespace PhpParser; use PhpParser\Node\Expr; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\String_; +use PhpParser\Node\Stmt\Else_; +use PhpParser\Node\Stmt\If_; -class NodeTraverserTest extends \PHPUnit\Framework\TestCase -{ - public function testNonModifying() { +class NodeTraverserTest extends \PHPUnit\Framework\TestCase { + public function testNonModifying(): void { $str1Node = new String_('Foo'); $str2Node = new String_('Bar'); $echoNode = new Node\Stmt\Echo_([$str1Node, $str2Node]); $stmts = [$echoNode]; $visitor = new NodeVisitorForTesting(); - $traverser = new NodeTraverser; + $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $this->assertEquals($stmts, $traverser->traverse($stmts)); @@ -30,13 +32,14 @@ public function testNonModifying() { ], $visitor->trace); } - public function testModifying() { + public function testModifying(): void { $str1Node = new String_('Foo'); $str2Node = new String_('Bar'); $printNode = new Expr\Print_($str1Node); - // first visitor changes the node, second verifies the change - $visitor1 = new NodeVisitorForTesting([ + // Visitor 2 performs changes, visitors 1 and 3 observe the changes. + $visitor1 = new NodeVisitorForTesting(); + $visitor2 = new NodeVisitorForTesting([ ['beforeTraverse', [], [$str1Node]], ['enterNode', $str1Node, $printNode], ['enterNode', $str1Node, $str2Node], @@ -44,39 +47,107 @@ public function testModifying() { ['leaveNode', $printNode, $str1Node], ['afterTraverse', [$str1Node], []], ]); - $visitor2 = new NodeVisitorForTesting(); + $visitor3 = new NodeVisitorForTesting(); - $traverser = new NodeTraverser; - $traverser->addVisitor($visitor1); - $traverser->addVisitor($visitor2); + $traverser = new NodeTraverser($visitor1, $visitor2, $visitor3); // as all operations are reversed we end where we start $this->assertEquals([], $traverser->traverse([])); $this->assertEquals([ - ['beforeTraverse', [$str1Node]], - ['enterNode', $printNode], - ['enterNode', $str2Node], + // Sees nodes before changes on entry. + ['beforeTraverse', []], + ['enterNode', $str1Node], + ['enterNode', $str1Node], + // Sees nodes after changes on leave. ['leaveNode', $str1Node], ['leaveNode', $str1Node], ['afterTraverse', []], + ], $visitor1->trace); + $this->assertEquals([ + // Sees nodes after changes on entry. + ['beforeTraverse', [$str1Node]], + ['enterNode', $printNode], + ['enterNode', $str2Node], + // Sees nodes before changes on leave. + ['leaveNode', $str2Node], + ['leaveNode', $printNode], + ['afterTraverse', [$str1Node]], + ], $visitor3->trace); + } + + public function testRemoveFromLeave(): void { + $str1Node = new String_('Foo'); + $str2Node = new String_('Bar'); + + $visitor = new NodeVisitorForTesting([ + ['leaveNode', $str1Node, NodeVisitor::REMOVE_NODE], + ]); + $visitor2 = new NodeVisitorForTesting(); + + $traverser = new NodeTraverser(); + $traverser->addVisitor($visitor2); + $traverser->addVisitor($visitor); + + $stmts = [$str1Node, $str2Node]; + $this->assertEquals([$str2Node], $traverser->traverse($stmts)); + $this->assertEquals([ + ['beforeTraverse', $stmts], + ['enterNode', $str1Node], + ['enterNode', $str2Node], + ['leaveNode', $str2Node], + ['afterTraverse', [$str2Node]], ], $visitor2->trace); } - public function testRemove() { + public function testRemoveFromEnter(): void { $str1Node = new String_('Foo'); $str2Node = new String_('Bar'); $visitor = new NodeVisitorForTesting([ - ['leaveNode', $str1Node, NodeTraverser::REMOVE_NODE], + ['enterNode', $str1Node, NodeVisitor::REMOVE_NODE], + ]); + $visitor2 = new NodeVisitorForTesting(); + + $traverser = new NodeTraverser(); + $traverser->addVisitor($visitor); + $traverser->addVisitor($visitor2); + + $stmts = [$str1Node, $str2Node]; + $this->assertEquals([$str2Node], $traverser->traverse($stmts)); + $this->assertEquals([ + ['beforeTraverse', $stmts], + ['enterNode', $str2Node], + ['leaveNode', $str2Node], + ['afterTraverse', [$str2Node]], + ], $visitor2->trace); + } + + public function testReturnArrayFromEnter(): void { + $str1Node = new String_('Str1'); + $str2Node = new String_('Str2'); + $str3Node = new String_('Str3'); + $str4Node = new String_('Str4'); + + $visitor = new NodeVisitorForTesting([ + ['enterNode', $str1Node, [$str3Node, $str4Node]], ]); + $visitor2 = new NodeVisitorForTesting(); - $traverser = new NodeTraverser; + $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); + $traverser->addVisitor($visitor2); - $this->assertEquals([$str2Node], $traverser->traverse([$str1Node, $str2Node])); + $stmts = [$str1Node, $str2Node]; + $this->assertEquals([$str3Node, $str4Node, $str2Node], $traverser->traverse($stmts)); + $this->assertEquals([ + ['beforeTraverse', $stmts], + ['enterNode', $str2Node], + ['leaveNode', $str2Node], + ['afterTraverse', [$str3Node, $str4Node, $str2Node]], + ], $visitor2->trace); } - public function testMerge() { + public function testMerge(): void { $strStart = new String_('Start'); $strMiddle = new String_('End'); $strEnd = new String_('Middle'); @@ -87,7 +158,7 @@ public function testMerge() { ['leaveNode', $strMiddle, [$strR1, $strR2]], ]); - $traverser = new NodeTraverser; + $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $this->assertEquals( @@ -96,17 +167,17 @@ public function testMerge() { ); } - public function testInvalidDeepArray() { + public function testInvalidDeepArray(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Invalid node structure: Contains nested arrays'); $strNode = new String_('Foo'); $stmts = [[[$strNode]]]; - $traverser = new NodeTraverser; + $traverser = new NodeTraverser(); $this->assertEquals($stmts, $traverser->traverse($stmts)); } - public function testDontTraverseChildren() { + public function testDontTraverseChildren(): void { $strNode = new String_('str'); $printNode = new Expr\Print_($strNode); $varNode = new Expr\Variable('foo'); @@ -115,10 +186,10 @@ public function testDontTraverseChildren() { $stmts = [$printNode, $negNode]; $visitor1 = new NodeVisitorForTesting([ - ['enterNode', $printNode, NodeTraverser::DONT_TRAVERSE_CHILDREN], + ['enterNode', $printNode, NodeVisitor::DONT_TRAVERSE_CHILDREN], ]); $visitor2 = new NodeVisitorForTesting([ - ['enterNode', $mulNode, NodeTraverser::DONT_TRAVERSE_CHILDREN], + ['enterNode', $mulNode, NodeVisitor::DONT_TRAVERSE_CHILDREN], ]); $expectedTrace = [ @@ -132,7 +203,7 @@ public function testDontTraverseChildren() { ['afterTraverse', $stmts], ]; - $traverser = new NodeTraverser; + $traverser = new NodeTraverser(); $traverser->addVisitor($visitor1); $traverser->addVisitor($visitor2); @@ -141,7 +212,7 @@ public function testDontTraverseChildren() { $this->assertEquals($expectedTrace, $visitor2->trace); } - public function testDontTraverseCurrentAndChildren() { + public function testDontTraverseCurrentAndChildren(): void { // print 'str'; -($foo * $foo); $strNode = new String_('str'); $printNode = new Expr\Print_($strNode); @@ -152,13 +223,13 @@ public function testDontTraverseCurrentAndChildren() { $stmts = [$printNode, $negNode]; $visitor1 = new NodeVisitorForTesting([ - ['enterNode', $printNode, NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN], - ['enterNode', $mulNode, NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN], + ['enterNode', $printNode, NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN], + ['enterNode', $mulNode, NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN], ['leaveNode', $mulNode, $divNode], ]); $visitor2 = new NodeVisitorForTesting(); - $traverser = new NodeTraverser; + $traverser = new NodeTraverser(); $traverser->addVisitor($visitor1); $traverser->addVisitor($visitor2); @@ -183,7 +254,7 @@ public function testDontTraverseCurrentAndChildren() { ], $visitor2->trace); } - public function testStopTraversal() { + public function testStopTraversal(): void { $varNode1 = new Expr\Variable('a'); $varNode2 = new Expr\Variable('b'); $varNode3 = new Expr\Variable('c'); @@ -193,9 +264,9 @@ public function testStopTraversal() { // From enterNode() with array parent $visitor = new NodeVisitorForTesting([ - ['enterNode', $mulNode, NodeTraverser::STOP_TRAVERSAL], + ['enterNode', $mulNode, NodeVisitor::STOP_TRAVERSAL], ]); - $traverser = new NodeTraverser; + $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $this->assertEquals($stmts, $traverser->traverse($stmts)); $this->assertEquals([ @@ -206,9 +277,9 @@ public function testStopTraversal() { // From enterNode with Node parent $visitor = new NodeVisitorForTesting([ - ['enterNode', $varNode1, NodeTraverser::STOP_TRAVERSAL], + ['enterNode', $varNode1, NodeVisitor::STOP_TRAVERSAL], ]); - $traverser = new NodeTraverser; + $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $this->assertEquals($stmts, $traverser->traverse($stmts)); $this->assertEquals([ @@ -220,9 +291,9 @@ public function testStopTraversal() { // From leaveNode with Node parent $visitor = new NodeVisitorForTesting([ - ['leaveNode', $varNode1, NodeTraverser::STOP_TRAVERSAL], + ['leaveNode', $varNode1, NodeVisitor::STOP_TRAVERSAL], ]); - $traverser = new NodeTraverser; + $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $this->assertEquals($stmts, $traverser->traverse($stmts)); $this->assertEquals([ @@ -235,9 +306,9 @@ public function testStopTraversal() { // From leaveNode with array parent $visitor = new NodeVisitorForTesting([ - ['leaveNode', $mulNode, NodeTraverser::STOP_TRAVERSAL], + ['leaveNode', $mulNode, NodeVisitor::STOP_TRAVERSAL], ]); - $traverser = new NodeTraverser; + $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $this->assertEquals($stmts, $traverser->traverse($stmts)); $this->assertEquals([ @@ -253,10 +324,10 @@ public function testStopTraversal() { // Check that pending array modifications are still carried out $visitor = new NodeVisitorForTesting([ - ['leaveNode', $mulNode, NodeTraverser::REMOVE_NODE], - ['enterNode', $printNode, NodeTraverser::STOP_TRAVERSAL], + ['leaveNode', $mulNode, NodeVisitor::REMOVE_NODE], + ['enterNode', $printNode, NodeVisitor::STOP_TRAVERSAL], ]); - $traverser = new NodeTraverser; + $traverser = new NodeTraverser(); $traverser->addVisitor($visitor); $this->assertEquals([$printNode], $traverser->traverse($stmts)); $this->assertEquals([ @@ -272,12 +343,50 @@ public function testStopTraversal() { ], $visitor->trace); } - public function testRemovingVisitor() { - $visitor1 = new class extends NodeVisitorAbstract {}; - $visitor2 = new class extends NodeVisitorAbstract {}; - $visitor3 = new class extends NodeVisitorAbstract {}; + public function testReplaceWithNull(): void { + $one = new Int_(1); + $else1 = new Else_(); + $else2 = new Else_(); + $if1 = new If_($one, ['else' => $else1]); + $if2 = new If_($one, ['else' => $else2]); + $stmts = [$if1, $if2]; + $visitor1 = new NodeVisitorForTesting([ + ['enterNode', $else1, NodeVisitor::REPLACE_WITH_NULL], + ['leaveNode', $else2, NodeVisitor::REPLACE_WITH_NULL], + ]); + $visitor2 = new NodeVisitorForTesting(); + $traverser = new NodeTraverser(); + $traverser->addVisitor($visitor1); + $traverser->addVisitor($visitor2); + $newStmts = $traverser->traverse($stmts); + $this->assertEquals([ + new If_($one), + new If_($one), + ], $newStmts); + $this->assertEquals([ + ['beforeTraverse', $stmts], + ['enterNode', $if1], + ['enterNode', $one], + // We never see the if1 Else node. + ['leaveNode', $one], + ['leaveNode', $if1], + ['enterNode', $if2], + ['enterNode', $one], + ['leaveNode', $one], + // We do see the if2 Else node, as it will only be replaced afterwards. + ['enterNode', $else2], + ['leaveNode', $else2], + ['leaveNode', $if2], + ['afterTraverse', $stmts], + ], $visitor2->trace); + } - $traverser = new NodeTraverser; + public function testRemovingVisitor(): void { + $visitor1 = new class () extends NodeVisitorAbstract {}; + $visitor2 = new class () extends NodeVisitorAbstract {}; + $visitor3 = new class () extends NodeVisitorAbstract {}; + + $traverser = new NodeTraverser(); $traverser->addVisitor($visitor1); $traverser->addVisitor($visitor2); $traverser->addVisitor($visitor3); @@ -291,14 +400,14 @@ public function testRemovingVisitor() { $traverser->removeVisitor($visitor2); - $postExpected = [0 => $visitor1, 2 => $visitor3]; + $postExpected = [$visitor1, $visitor3]; $this->assertSame($postExpected, $getVisitors()); } - public function testNoCloneNodes() { + public function testNoCloneNodes(): void { $stmts = [new Node\Stmt\Echo_([new String_('Foo'), new String_('Bar')])]; - $traverser = new NodeTraverser; + $traverser = new NodeTraverser(); $this->assertSame($stmts, $traverser->traverse($stmts)); } @@ -306,7 +415,7 @@ public function testNoCloneNodes() { /** * @dataProvider provideTestInvalidReturn */ - public function testInvalidReturn($stmts, $visitor, $message) { + public function testInvalidReturn($stmts, $visitor, $message): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage($message); @@ -315,8 +424,8 @@ public function testInvalidReturn($stmts, $visitor, $message) { $traverser->traverse($stmts); } - public function provideTestInvalidReturn() { - $num = new Node\Scalar\LNumber(42); + public static function provideTestInvalidReturn() { + $num = new Node\Scalar\Int_(42); $expr = new Node\Stmt\Expression($num); $stmts = [$expr]; @@ -333,17 +442,23 @@ public function provideTestInvalidReturn() { ['leaveNode', $expr, 'foobar'], ]); $visitor5 = new NodeVisitorForTesting([ - ['leaveNode', $num, [new Node\Scalar\DNumber(42.0)]], + ['leaveNode', $num, [new Node\Scalar\Float_(42.0)]], ]); $visitor6 = new NodeVisitorForTesting([ ['leaveNode', $expr, false], ]); $visitor7 = new NodeVisitorForTesting([ - ['enterNode', $expr, new Node\Scalar\LNumber(42)], + ['enterNode', $expr, new Node\Scalar\Int_(42)], ]); $visitor8 = new NodeVisitorForTesting([ ['enterNode', $num, new Node\Stmt\Return_()], ]); + $visitor9 = new NodeVisitorForTesting([ + ['enterNode', $expr, NodeVisitor::REPLACE_WITH_NULL], + ]); + $visitor10 = new NodeVisitorForTesting([ + ['leaveNode', $expr, NodeVisitor::REPLACE_WITH_NULL], + ]); return [ [$stmts, $visitor1, 'enterNode() returned invalid value of type string'], @@ -351,9 +466,11 @@ public function provideTestInvalidReturn() { [$stmts, $visitor3, 'leaveNode() returned invalid value of type string'], [$stmts, $visitor4, 'leaveNode() returned invalid value of type string'], [$stmts, $visitor5, 'leaveNode() may only return an array if the parent structure is an array'], - [$stmts, $visitor6, 'bool(false) return from leaveNode() no longer supported. Return NodeTraverser::REMOVE_NODE instead'], - [$stmts, $visitor7, 'Trying to replace statement (Stmt_Expression) with expression (Scalar_LNumber). Are you missing a Stmt_Expression wrapper?'], - [$stmts, $visitor8, 'Trying to replace expression (Scalar_LNumber) with statement (Stmt_Return)'], + [$stmts, $visitor6, 'leaveNode() returned invalid value of type bool'], + [$stmts, $visitor7, 'Trying to replace statement (Stmt_Expression) with expression (Scalar_Int). Are you missing a Stmt_Expression wrapper?'], + [$stmts, $visitor8, 'Trying to replace expression (Scalar_Int) with statement (Stmt_Return)'], + [$stmts, $visitor9, 'REPLACE_WITH_NULL can not be used if the parent structure is an array'], + [$stmts, $visitor10, 'REPLACE_WITH_NULL can not be used if the parent structure is an array'], ]; } } diff --git a/test/PhpParser/NodeVisitor/FindingVisitorTest.php b/test/PhpParser/NodeVisitor/FindingVisitorTest.php index 27cb6dd480..195074f1b0 100644 --- a/test/PhpParser/NodeVisitor/FindingVisitorTest.php +++ b/test/PhpParser/NodeVisitor/FindingVisitorTest.php @@ -6,11 +6,10 @@ use PhpParser\Node\Expr; use PhpParser\NodeTraverser; -class FindingVisitorTest extends \PHPUnit\Framework\TestCase -{ - public function testFindVariables() { +class FindingVisitorTest extends \PHPUnit\Framework\TestCase { + public function testFindVariables(): void { $traverser = new NodeTraverser(); - $visitor = new FindingVisitor(function(Node $node) { + $visitor = new FindingVisitor(function (Node $node) { return $node instanceof Node\Expr\Variable; }); $traverser->addVisitor($visitor); @@ -28,9 +27,9 @@ public function testFindVariables() { ], $visitor->getFoundNodes()); } - public function testFindAll() { + public function testFindAll(): void { $traverser = new NodeTraverser(); - $visitor = new FindingVisitor(function(Node $node) { + $visitor = new FindingVisitor(function (Node $node) { return true; // All nodes }); $traverser->addVisitor($visitor); diff --git a/test/PhpParser/NodeVisitor/FirstFindingVisitorTest.php b/test/PhpParser/NodeVisitor/FirstFindingVisitorTest.php index 9ae8932f92..2163d9d470 100644 --- a/test/PhpParser/NodeVisitor/FirstFindingVisitorTest.php +++ b/test/PhpParser/NodeVisitor/FirstFindingVisitorTest.php @@ -6,11 +6,10 @@ use PhpParser\Node\Expr; use PhpParser\NodeTraverser; -class FirstFindingVisitorTest extends \PHPUnit\Framework\TestCase -{ - public function testFindFirstVariable() { +class FirstFindingVisitorTest extends \PHPUnit\Framework\TestCase { + public function testFindFirstVariable(): void { $traverser = new NodeTraverser(); - $visitor = new FirstFindingVisitor(function(Node $node) { + $visitor = new FirstFindingVisitor(function (Node $node) { return $node instanceof Node\Expr\Variable; }); $traverser->addVisitor($visitor); @@ -22,9 +21,9 @@ public function testFindFirstVariable() { $this->assertSame($assign->var, $visitor->getFoundNode()); } - public function testFindNone() { + public function testFindNone(): void { $traverser = new NodeTraverser(); - $visitor = new FirstFindingVisitor(function(Node $node) { + $visitor = new FirstFindingVisitor(function (Node $node) { return $node instanceof Node\Expr\BinaryOp; }); $traverser->addVisitor($visitor); diff --git a/test/PhpParser/NodeVisitor/NameResolverTest.php b/test/PhpParser/NodeVisitor/NameResolverTest.php index a98b57cd00..a50a59525b 100644 --- a/test/PhpParser/NodeVisitor/NameResolverTest.php +++ b/test/PhpParser/NodeVisitor/NameResolverTest.php @@ -8,8 +8,7 @@ use PhpParser\Node\Name; use PhpParser\Node\Stmt; -class NameResolverTest extends \PHPUnit\Framework\TestCase -{ +class NameResolverTest extends \PHPUnit\Framework\TestCase { private function canonicalize($string) { return str_replace("\r\n", "\n", $string); } @@ -17,7 +16,7 @@ private function canonicalize($string) { /** * @covers \PhpParser\NodeVisitor\NameResolver */ - public function testResolveNames() { + public function testResolveNames(): void { $code = <<<'EOC' parseAndResolve($code); $this->assertSame( @@ -177,7 +176,7 @@ public function testResolveNames() { /** * @covers \PhpParser\NodeVisitor\NameResolver */ - public function testResolveLocations() { + public function testResolveLocations(): void { $code = <<<'EOC' $a; fn(?A $a): ?A => $a; +#[X] +const EXAMPLE = true; + A::b(); A::$b; A::B; @@ -256,35 +281,68 @@ class A extends \NS\B implements \NS\C, \NS\D public \NS\A|\NS\B|int $prop; #[\NS\X] const C = 1; + public const \NS\X A = \NS\X::Bar; + public const \NS\X\Foo B = \NS\X\Foo::Bar; + public const \X\Foo C = \X\Foo::Bar; + public \NS\Foo $foo { + #[\NS\X] + set( + #[\NS\X] + \NS\Bar $v + ) { + } + } + public function __construct(public \NS\Foo $bar { + #[\NS\X] + set( + #[\NS\X] + \NS\Bar $v + ) { + } + }) + { + } } #[\NS\X] interface A extends \NS\C, \NS\D { - public function a(\NS\A $a) : \NS\A; - public function b(\NS\A|\NS\B|int $a) : \NS\A|\NS\B|int; + public function a(\NS\A $a): \NS\A; + public function b(\NS\A|\NS\B|int $a): \NS\A|\NS\B|int; + public function c(\NS\A&\NS\B $a): \NS\A&\NS\B; +} +#[\NS\X] +enum E : int +{ + #[\NS\X] + case A = 1; } #[\NS\X] trait A { } #[\NS\X] -function f(#[\NS\X] \NS\A $a) : \NS\A +function f( + #[\NS\X] + \NS\A $a +): \NS\A { } -function f2(array $a) : array +function f2(array $a): array { } -function fn3(?\NS\A $a) : ?\NS\A +function fn3(?\NS\A $a): ?\NS\A { } -function fn4(?array $a) : ?array +function fn4(?array $a): ?array { } -#[\NS\X] function (\NS\A $a) : \NS\A { +#[\NS\X] function (\NS\A $a): \NS\A { }; #[\NS\X] fn(array $a): array => $a; fn(\NS\A $a): \NS\A => $a; fn(?\NS\A $a): ?\NS\A => $a; +#[\NS\X] +const EXAMPLE = true; \NS\A::b(); \NS\A::$b; \NS\A::B; @@ -299,7 +357,7 @@ function fn4(?array $a) : ?array } EOC; - $prettyPrinter = new PhpParser\PrettyPrinter\Standard; + $prettyPrinter = new PhpParser\PrettyPrinter\Standard(); $stmts = $this->parseAndResolve($code); $this->assertSame( @@ -308,29 +366,30 @@ function fn4(?array $a) : ?array ); } - public function testNoResolveSpecialName() { + public function testNoResolveSpecialName(): void { $stmts = [new Node\Expr\New_(new Name('self'))]; - $traverser = new PhpParser\NodeTraverser; - $traverser->addVisitor(new NameResolver); + $traverser = new PhpParser\NodeTraverser(); + $traverser->addVisitor(new NameResolver()); $this->assertEquals($stmts, $traverser->traverse($stmts)); } - public function testAddDeclarationNamespacedName() { + public function testAddDeclarationNamespacedName(): void { $nsStmts = [ new Stmt\Class_('A'), new Stmt\Interface_('B'), new Stmt\Function_('C'), new Stmt\Const_([ - new Node\Const_('D', new Node\Scalar\LNumber(42)) + new Node\Const_('D', new Node\Scalar\Int_(42)) ]), new Stmt\Trait_('E'), new Expr\New_(new Stmt\Class_(null)), + new Stmt\Enum_('F'), ]; - $traverser = new PhpParser\NodeTraverser; - $traverser->addVisitor(new NameResolver); + $traverser = new PhpParser\NodeTraverser(); + $traverser->addVisitor(new NameResolver()); $stmts = $traverser->traverse([new Stmt\Namespace_(new Name('NS'), $nsStmts)]); $this->assertSame('NS\\A', (string) $stmts[0]->stmts[0]->namespacedName); @@ -338,18 +397,20 @@ public function testAddDeclarationNamespacedName() { $this->assertSame('NS\\C', (string) $stmts[0]->stmts[2]->namespacedName); $this->assertSame('NS\\D', (string) $stmts[0]->stmts[3]->consts[0]->namespacedName); $this->assertSame('NS\\E', (string) $stmts[0]->stmts[4]->namespacedName); - $this->assertObjectNotHasAttribute('namespacedName', $stmts[0]->stmts[5]->class); + $this->assertNull($stmts[0]->stmts[5]->class->namespacedName); + $this->assertSame('NS\\F', (string) $stmts[0]->stmts[6]->namespacedName); $stmts = $traverser->traverse([new Stmt\Namespace_(null, $nsStmts)]); - $this->assertSame('A', (string) $stmts[0]->stmts[0]->namespacedName); - $this->assertSame('B', (string) $stmts[0]->stmts[1]->namespacedName); - $this->assertSame('C', (string) $stmts[0]->stmts[2]->namespacedName); - $this->assertSame('D', (string) $stmts[0]->stmts[3]->consts[0]->namespacedName); - $this->assertSame('E', (string) $stmts[0]->stmts[4]->namespacedName); - $this->assertObjectNotHasAttribute('namespacedName', $stmts[0]->stmts[5]->class); + $this->assertSame('A', (string) $stmts[0]->stmts[0]->namespacedName); + $this->assertSame('B', (string) $stmts[0]->stmts[1]->namespacedName); + $this->assertSame('C', (string) $stmts[0]->stmts[2]->namespacedName); + $this->assertSame('D', (string) $stmts[0]->stmts[3]->consts[0]->namespacedName); + $this->assertSame('E', (string) $stmts[0]->stmts[4]->namespacedName); + $this->assertNull($stmts[0]->stmts[5]->class->namespacedName); + $this->assertSame('F', (string) $stmts[0]->stmts[6]->namespacedName); } - public function testAddRuntimeResolvedNamespacedName() { + public function testAddRuntimeResolvedNamespacedName(): void { $stmts = [ new Stmt\Namespace_(new Name('NS'), [ new Expr\FuncCall(new Name('foo')), @@ -361,8 +422,8 @@ public function testAddRuntimeResolvedNamespacedName() { ]), ]; - $traverser = new PhpParser\NodeTraverser; - $traverser->addVisitor(new NameResolver); + $traverser = new PhpParser\NodeTraverser(); + $traverser->addVisitor(new NameResolver()); $stmts = $traverser->traverse($stmts); $this->assertSame('NS\\foo', (string) $stmts[0]->stmts[0]->name->getAttribute('namespacedName')); @@ -375,35 +436,35 @@ public function testAddRuntimeResolvedNamespacedName() { /** * @dataProvider provideTestError */ - public function testError(Node $stmt, $errorMsg) { + public function testError(Node $stmt, $errorMsg): void { $this->expectException(\PhpParser\Error::class); $this->expectExceptionMessage($errorMsg); - $traverser = new PhpParser\NodeTraverser; - $traverser->addVisitor(new NameResolver); + $traverser = new PhpParser\NodeTraverser(); + $traverser->addVisitor(new NameResolver()); $traverser->traverse([$stmt]); } - public function provideTestError() { + public static function provideTestError() { return [ [ new Stmt\Use_([ - new Stmt\UseUse(new Name('A\B'), 'B', 0, ['startLine' => 1]), - new Stmt\UseUse(new Name('C\D'), 'B', 0, ['startLine' => 2]), + new Node\UseItem(new Name('A\B'), 'B', 0, ['startLine' => 1]), + new Node\UseItem(new Name('C\D'), 'B', 0, ['startLine' => 2]), ], Stmt\Use_::TYPE_NORMAL), 'Cannot use C\D as B because the name is already in use on line 2' ], [ new Stmt\Use_([ - new Stmt\UseUse(new Name('a\b'), 'b', 0, ['startLine' => 1]), - new Stmt\UseUse(new Name('c\d'), 'B', 0, ['startLine' => 2]), + new Node\UseItem(new Name('a\b'), 'b', 0, ['startLine' => 1]), + new Node\UseItem(new Name('c\d'), 'B', 0, ['startLine' => 2]), ], Stmt\Use_::TYPE_FUNCTION), 'Cannot use function c\d as B because the name is already in use on line 2' ], [ new Stmt\Use_([ - new Stmt\UseUse(new Name('A\B'), 'B', 0, ['startLine' => 1]), - new Stmt\UseUse(new Name('C\D'), 'B', 0, ['startLine' => 2]), + new Node\UseItem(new Name('A\B'), 'B', 0, ['startLine' => 1]), + new Node\UseItem(new Name('C\D'), 'B', 0, ['startLine' => 2]), ], Stmt\Use_::TYPE_CONSTANT), 'Cannot use const C\D as B because the name is already in use on line 2' ], @@ -426,8 +487,7 @@ public function provideTestError() { ]; } - public function testClassNameIsCaseInsensitive() - { + public function testClassNameIsCaseInsensitive(): void { $source = <<<'EOC' parse($source); - $traverser = new PhpParser\NodeTraverser; - $traverser->addVisitor(new NameResolver); + $traverser = new PhpParser\NodeTraverser(); + $traverser->addVisitor(new NameResolver()); $stmts = $traverser->traverse($stmts); $stmt = $stmts[0]; $assign = $stmt->stmts[1]->expr; - $this->assertSame(['Bar', 'Baz'], $assign->expr->class->parts); + $this->assertSame('Bar\\Baz', $assign->expr->class->name); } - public function testSpecialClassNamesAreCaseInsensitive() { + public function testSpecialClassNamesAreCaseInsensitive(): void { $source = <<<'EOC' parse($source); - $traverser = new PhpParser\NodeTraverser; - $traverser->addVisitor(new NameResolver); + $traverser = new PhpParser\NodeTraverser(); + $traverser->addVisitor(new NameResolver()); $stmts = $traverser->traverse($stmts); $classStmt = $stmts[0]; @@ -479,8 +539,8 @@ public static function method() $this->assertSame('STATIC', (string) $methodStmt->stmts[2]->expr->class); } - public function testAddOriginalNames() { - $traverser = new PhpParser\NodeTraverser; + public function testAddOriginalNames(): void { + $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor(new NameResolver(null, ['preserveOriginalNames' => true])); $n1 = new Name('Bar'); @@ -498,8 +558,8 @@ public function testAddOriginalNames() { $this->assertSame($n2, $stmts[0]->stmts[1]->name->getAttribute('originalName')); } - public function testAttributeOnlyMode() { - $traverser = new PhpParser\NodeTraverser; + public function testAttributeOnlyMode(): void { + $traverser = new PhpParser\NodeTraverser(); $traverser->addVisitor(new NameResolver(null, ['replaceNodes' => false])); $n1 = new Name('Bar'); @@ -520,11 +580,10 @@ public function testAttributeOnlyMode() { new Name\FullyQualified('Foo\bar'), $n2->getAttribute('namespacedName')); } - private function parseAndResolve(string $code): array - { - $parser = new PhpParser\Parser\Php7(new PhpParser\Lexer\Emulative); - $traverser = new PhpParser\NodeTraverser; - $traverser->addVisitor(new NameResolver); + private function parseAndResolve(string $code): array { + $parser = new PhpParser\Parser\Php8(new PhpParser\Lexer\Emulative()); + $traverser = new PhpParser\NodeTraverser(); + $traverser->addVisitor(new NameResolver()); $stmts = $parser->parse($code); return $traverser->traverse($stmts); diff --git a/test/PhpParser/NodeVisitor/NodeConnectingVisitorTest.php b/test/PhpParser/NodeVisitor/NodeConnectingVisitorTest.php index b9b1bffe6e..c9ac5e898a 100644 --- a/test/PhpParser/NodeVisitor/NodeConnectingVisitorTest.php +++ b/test/PhpParser/NodeVisitor/NodeConnectingVisitorTest.php @@ -9,27 +9,49 @@ use PhpParser\NodeTraverser; use PhpParser\ParserFactory; -final class NodeConnectingVisitorTest extends \PHPUnit\Framework\TestCase -{ - public function testConnectsNodeToItsParentNodeAndItsSiblingNodes() - { - $ast = (new ParserFactory)->create(ParserFactory::PREFER_PHP7)->parse( +final class NodeConnectingVisitorTest extends \PHPUnit\Framework\TestCase { + public function testConnectsNodeToItsParentNodeAndItsSiblingNodes(): void { + $ast = (new ParserFactory())->createForNewestSupportedVersion()->parse( 'addVisitor(new NodeConnectingVisitor); + $traverser->addVisitor(new NodeConnectingVisitor()); $ast = $traverser->traverse($ast); - $node = (new NodeFinder)->findFirstInstanceof($ast, Else_::class); + $node = (new NodeFinder())->findFirstInstanceof($ast, Else_::class); $this->assertSame(If_::class, get_class($node->getAttribute('parent'))); $this->assertSame(ConstFetch::class, get_class($node->getAttribute('previous'))); - $node = (new NodeFinder)->findFirstInstanceof($ast, ConstFetch::class); + $node = (new NodeFinder())->findFirstInstanceof($ast, ConstFetch::class); $this->assertSame(Else_::class, get_class($node->getAttribute('next'))); } + + public function testWeakReferences(): void { + $ast = (new ParserFactory())->createForNewestSupportedVersion()->parse( + 'addVisitor(new NodeConnectingVisitor(true)); + + $ast = $traverser->traverse($ast); + + $node = (new NodeFinder())->findFirstInstanceof($ast, Else_::class); + + $this->assertInstanceOf(\WeakReference::class, $node->getAttribute('weak_parent')); + $this->assertSame(If_::class, get_class($node->getAttribute('weak_parent')->get())); + $this->assertInstanceOf(\WeakReference::class, $node->getAttribute('weak_previous')); + $this->assertSame(ConstFetch::class, get_class($node->getAttribute('weak_previous')->get())); + + $node = (new NodeFinder())->findFirstInstanceof($ast, ConstFetch::class); + + $this->assertInstanceOf(\WeakReference::class, $node->getAttribute('weak_next')); + $this->assertSame(Else_::class, get_class($node->getAttribute('weak_next')->get())); + } } diff --git a/test/PhpParser/NodeVisitor/ParentConnectingVisitorTest.php b/test/PhpParser/NodeVisitor/ParentConnectingVisitorTest.php index d1cc482013..059c2260ff 100644 --- a/test/PhpParser/NodeVisitor/ParentConnectingVisitorTest.php +++ b/test/PhpParser/NodeVisitor/ParentConnectingVisitorTest.php @@ -7,22 +7,38 @@ use PhpParser\NodeTraverser; use PhpParser\ParserFactory; -final class ParentConnectingVisitorTest extends \PHPUnit\Framework\TestCase -{ - public function testConnectsChildNodeToParentNode() - { - $ast = (new ParserFactory)->create(ParserFactory::PREFER_PHP7)->parse( +final class ParentConnectingVisitorTest extends \PHPUnit\Framework\TestCase { + public function testConnectsChildNodeToParentNode(): void { + $ast = (new ParserFactory())->createForNewestSupportedVersion()->parse( 'addVisitor(new ParentConnectingVisitor); + $traverser->addVisitor(new ParentConnectingVisitor()); $ast = $traverser->traverse($ast); - $node = (new NodeFinder)->findFirstInstanceof($ast, ClassMethod::class); + $node = (new NodeFinder())->findFirstInstanceof($ast, ClassMethod::class); $this->assertSame('C', $node->getAttribute('parent')->name->toString()); } + + public function testWeakReferences(): void { + $ast = (new ParserFactory())->createForNewestSupportedVersion()->parse( + 'addVisitor(new ParentConnectingVisitor(true)); + + $ast = $traverser->traverse($ast); + + $node = (new NodeFinder())->findFirstInstanceof($ast, ClassMethod::class); + + $weakReference = $node->getAttribute('weak_parent'); + $this->assertInstanceOf(\WeakReference::class, $weakReference); + $this->assertSame('C', $weakReference->get()->name->toString()); + } } diff --git a/test/PhpParser/NodeVisitorForTesting.php b/test/PhpParser/NodeVisitorForTesting.php index 1383aa34c3..4a30c59e64 100644 --- a/test/PhpParser/NodeVisitorForTesting.php +++ b/test/PhpParser/NodeVisitorForTesting.php @@ -1,4 +1,4 @@ -returnsPos = 0; } - public function beforeTraverse(array $nodes) { + public function beforeTraverse(array $nodes): ?array { return $this->traceEvent('beforeTraverse', $nodes); } @@ -24,7 +24,7 @@ public function leaveNode(Node $node) { return $this->traceEvent('leaveNode', $node); } - public function afterTraverse(array $nodes) { + public function afterTraverse(array $nodes): ?array { return $this->traceEvent('afterTraverse', $nodes); } @@ -45,4 +45,4 @@ public function __destruct() { throw new \Exception("Expected event did not occur"); } } -} \ No newline at end of file +} diff --git a/test/PhpParser/Parser/MultipleTest.php b/test/PhpParser/Parser/MultipleTest.php deleted file mode 100644 index 46d1b35dff..0000000000 --- a/test/PhpParser/Parser/MultipleTest.php +++ /dev/null @@ -1,99 +0,0 @@ - []]); - return new Multiple([new Php7($lexer), new Php5($lexer)]); - } - - private function getPrefer5() { - $lexer = new Lexer(['usedAttributes' => []]); - return new Multiple([new Php5($lexer), new Php7($lexer)]); - } - - /** @dataProvider provideTestParse */ - public function testParse($code, Multiple $parser, $expected) { - $this->assertEquals($expected, $parser->parse($code)); - } - - public function provideTestParse() { - return [ - [ - // PHP 7 only code - 'getPrefer5(), - [ - new Stmt\Class_('Test', ['stmts' => [ - new Stmt\ClassMethod('function') - ]]), - ] - ], - [ - // PHP 5 only code - 'b;', - $this->getPrefer7(), - [ - new Stmt\Global_([ - new Expr\Variable(new Expr\PropertyFetch(new Expr\Variable('a'), 'b')) - ]) - ] - ], - [ - // Different meaning (PHP 5) - 'getPrefer5(), - [ - new Stmt\Expression(new Expr\Variable( - new Expr\ArrayDimFetch(new Expr\Variable('a'), LNumber::fromString('0')) - )) - ] - ], - [ - // Different meaning (PHP 7) - 'getPrefer7(), - [ - new Stmt\Expression(new Expr\ArrayDimFetch( - new Expr\Variable(new Expr\Variable('a')), LNumber::fromString('0') - )) - ] - ], - ]; - } - - public function testThrownError() { - $this->expectException(Error::class); - $this->expectExceptionMessage('FAIL A'); - - $parserA = new class implements \PhpParser\Parser { - public function parse(string $code, ErrorHandler $errorHandler = null) { - throw new Error('FAIL A'); - } - }; - $parserB = new class implements \PhpParser\Parser { - public function parse(string $code, ErrorHandler $errorHandler = null) { - throw new Error('FAIL B'); - } - }; - - $parser = new Multiple([$parserA, $parserB]); - $parser->parse('dummy'); - } -} diff --git a/test/PhpParser/Parser/Php7Test.php b/test/PhpParser/Parser/Php7Test.php index 22a4c5190c..7b45cb14c6 100644 --- a/test/PhpParser/Parser/Php7Test.php +++ b/test/PhpParser/Parser/Php7Test.php @@ -3,9 +3,9 @@ namespace PhpParser\Parser; use PhpParser\Lexer; -use PhpParser\ParserTest; +use PhpParser\ParserTestAbstract; -class Php7Test extends ParserTest +class Php7Test extends ParserTestAbstract { protected function getParser(Lexer $lexer) { return new Php7($lexer); diff --git a/test/PhpParser/Parser/Php5Test.php b/test/PhpParser/Parser/Php8Test.php similarity index 56% rename from test/PhpParser/Parser/Php5Test.php rename to test/PhpParser/Parser/Php8Test.php index 4386b5129a..769e8b798f 100644 --- a/test/PhpParser/Parser/Php5Test.php +++ b/test/PhpParser/Parser/Php8Test.php @@ -3,11 +3,11 @@ namespace PhpParser\Parser; use PhpParser\Lexer; -use PhpParser\ParserTest; +use PhpParser\ParserTestAbstract; -class Php5Test extends ParserTest +class Php8Test extends ParserTestAbstract { protected function getParser(Lexer $lexer) { - return new Php5($lexer); + return new Php8($lexer); } } diff --git a/test/PhpParser/ParserFactoryTest.php b/test/PhpParser/ParserFactoryTest.php index d50981f2a1..7108d9e00a 100644 --- a/test/PhpParser/ParserFactoryTest.php +++ b/test/PhpParser/ParserFactoryTest.php @@ -5,32 +5,13 @@ /* This test is very weak, because PHPUnit's assertEquals assertion is way too slow dealing with the * large objects involved here. So we just do some basic instanceof tests instead. */ -class ParserFactoryTest extends \PHPUnit\Framework\TestCase -{ - /** @dataProvider provideTestCreate */ - public function testCreate($kind, $lexer, $expected) { - $this->assertInstanceOf($expected, (new ParserFactory)->create($kind, $lexer)); - } +use PhpParser\Parser\Php7; +use PhpParser\Parser\Php8; - public function provideTestCreate() { - $lexer = new Lexer(); - return [ - [ - ParserFactory::PREFER_PHP7, $lexer, - Parser\Multiple::class - ], - [ - ParserFactory::PREFER_PHP5, null, - Parser\Multiple::class - ], - [ - ParserFactory::ONLY_PHP7, null, - Parser\Php7::class - ], - [ - ParserFactory::ONLY_PHP5, $lexer, - Parser\Php5::class - ] - ]; +class ParserFactoryTest extends \PHPUnit\Framework\TestCase { + public function testCreate(): void { + $factory = new ParserFactory(); + $this->assertInstanceOf(Php8::class, $factory->createForNewestSupportedVersion()); + $this->assertInstanceOf(Parser::class, $factory->createForHostVersion()); } } diff --git a/test/PhpParser/ParserTest.php b/test/PhpParser/ParserTestAbstract.php similarity index 71% rename from test/PhpParser/ParserTest.php rename to test/PhpParser/ParserTestAbstract.php index 5080365fbb..9f083b2eee 100644 --- a/test/PhpParser/ParserTest.php +++ b/test/PhpParser/ParserTestAbstract.php @@ -7,39 +7,33 @@ use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt; -abstract class ParserTest extends \PHPUnit\Framework\TestCase -{ +abstract class ParserTestAbstract extends \PHPUnit\Framework\TestCase { /** @returns Parser */ abstract protected function getParser(Lexer $lexer); - public function testParserThrowsSyntaxError() { + public function testParserThrowsSyntaxError(): void { $this->expectException(Error::class); $this->expectExceptionMessage('Syntax error, unexpected EOF on line 1'); $parser = $this->getParser(new Lexer()); $parser->parse('expectException(Error::class); $this->expectExceptionMessage('Cannot use foo as self because \'self\' is a special class name on line 1'); $parser = $this->getParser(new Lexer()); $parser->parse('expectException(Error::class); $this->expectExceptionMessage('Unterminated comment on line 1'); $parser = $this->getParser(new Lexer()); $parser->parse(' [ - 'comments', 'startLine', 'endLine', - 'startTokenPos', 'endTokenPos', - ] - ]); + public function testAttributeAssignment(): void { + $lexer = new Lexer(); $code = <<<'EOC' 7, 'startTokenPos' => 3, 'endTokenPos' => 21, + 'startFilePos' => 25, + 'endFilePos' => 86, ], $fn->getAttributes()); $param = $fn->params[0]; @@ -76,6 +72,8 @@ function test($a) { 'endLine' => 3, 'startTokenPos' => 7, 'endTokenPos' => 7, + 'startFilePos' => 39, + 'endFilePos' => 40, ], $param->getAttributes()); /** @var Stmt\Echo_ $echo */ @@ -92,6 +90,8 @@ function test($a) { 'endLine' => 6, 'startTokenPos' => 16, 'endTokenPos' => 19, + 'startFilePos' => 77, + 'endFilePos' => 84, ], $echo->getAttributes()); /** @var \PhpParser\Node\Expr\Variable $var */ @@ -102,13 +102,15 @@ function test($a) { 'endLine' => 6, 'startTokenPos' => 18, 'endTokenPos' => 18, + 'startFilePos' => 82, + 'endFilePos' => 83, ], $var->getAttributes()); } - public function testInvalidToken() { + public function testInvalidToken(): void { $this->expectException(\RangeException::class); $this->expectExceptionMessage('The lexer returned an invalid token (id=999, value=foobar)'); - $lexer = new InvalidTokenLexer; + $lexer = new InvalidTokenLexer(); $parser = $this->getParser($lexer); $parser->parse('dummy'); } @@ -116,8 +118,8 @@ public function testInvalidToken() { /** * @dataProvider provideTestExtraAttributes */ - public function testExtraAttributes($code, $expectedAttributes) { - $parser = $this->getParser(new Lexer\Emulative); + public function testExtraAttributes($code, $expectedAttributes): void { + $parser = $this->getParser(new Lexer\Emulative()); $stmts = $parser->parse("expr : $stmts[0]; $attributes = $node->getAttributes(); @@ -126,15 +128,17 @@ public function testExtraAttributes($code, $expectedAttributes) { } } - public function provideTestExtraAttributes() { + public static function provideTestExtraAttributes() { return [ - ['0', ['kind' => Scalar\LNumber::KIND_DEC]], - ['9', ['kind' => Scalar\LNumber::KIND_DEC]], - ['07', ['kind' => Scalar\LNumber::KIND_OCT]], - ['0xf', ['kind' => Scalar\LNumber::KIND_HEX]], - ['0XF', ['kind' => Scalar\LNumber::KIND_HEX]], - ['0b1', ['kind' => Scalar\LNumber::KIND_BIN]], - ['0B1', ['kind' => Scalar\LNumber::KIND_BIN]], + ['0', ['kind' => Scalar\Int_::KIND_DEC]], + ['9', ['kind' => Scalar\Int_::KIND_DEC]], + ['07', ['kind' => Scalar\Int_::KIND_OCT]], + ['0xf', ['kind' => Scalar\Int_::KIND_HEX]], + ['0XF', ['kind' => Scalar\Int_::KIND_HEX]], + ['0b1', ['kind' => Scalar\Int_::KIND_BIN]], + ['0B1', ['kind' => Scalar\Int_::KIND_BIN]], + ['0o7', ['kind' => Scalar\Int_::KIND_OCT]], + ['0O7', ['kind' => Scalar\Int_::KIND_OCT]], ['[]', ['kind' => Expr\Array_::KIND_SHORT]], ['array()', ['kind' => Expr\Array_::KIND_LONG]], ["'foo'", ['kind' => String_::KIND_SINGLE_QUOTED]], @@ -175,12 +179,35 @@ public function provideTestExtraAttributes() { [" ( REAL ) 5.0", ['kind' => Expr\Cast\Double::KIND_REAL]], ]; } + + public function testListKindAttribute(): void { + $parser = $this->getParser(new Lexer\Emulative()); + $stmts = $parser->parse('assertSame($stmts[0]->expr->var->getAttribute('kind'), Expr\List_::KIND_LIST); + $this->assertSame($stmts[0]->expr->var->items[0]->value->getAttribute('kind'), Expr\List_::KIND_LIST); + $this->assertSame($stmts[1]->expr->var->getAttribute('kind'), Expr\List_::KIND_ARRAY); + $this->assertSame($stmts[1]->expr->var->items[0]->value->getAttribute('kind'), Expr\List_::KIND_ARRAY); + } + + public function testGetTokens(): void { + $lexer = new Lexer(); + $parser = $this->getParser($lexer); + $parser->parse('assertEquals([ + new Token(\T_OPEN_TAG, 'getTokens()); + } } -class InvalidTokenLexer extends Lexer -{ - public function getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null) : int { - $value = 'foobar'; - return 999; +class InvalidTokenLexer extends Lexer { + public function tokenize(string $code, ?ErrorHandler $errorHandler = null): array { + return [ + new Token(999, 'foobar', 42), + ]; } } diff --git a/test/PhpParser/PhpVersionTest.php b/test/PhpParser/PhpVersionTest.php new file mode 100644 index 0000000000..cacc0f41b8 --- /dev/null +++ b/test/PhpParser/PhpVersionTest.php @@ -0,0 +1,41 @@ +assertSame(80200, $version->id); + + $version = PhpVersion::fromString('8.2'); + $this->assertSame(80200, $version->id); + + $version = PhpVersion::fromString('8.2.14'); + $this->assertSame(80200, $version->id); + + $version = PhpVersion::fromString('8.2.14rc1'); + $this->assertSame(80200, $version->id); + } + + public function testInvalidVersion(): void { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Invalid PHP version "8"'); + PhpVersion::fromString('8'); + } + + public function testEquals(): void { + $php74 = PhpVersion::fromComponents(7, 4); + $php81 = PhpVersion::fromComponents(8, 1); + $php82 = PhpVersion::fromComponents(8, 2); + $this->assertTrue($php81->equals($php81)); + $this->assertFalse($php81->equals($php82)); + + $this->assertTrue($php81->older($php82)); + $this->assertFalse($php81->older($php81)); + $this->assertFalse($php81->older($php74)); + + $this->assertFalse($php81->newerOrEqual($php82)); + $this->assertTrue($php81->newerOrEqual($php81)); + $this->assertTrue($php81->newerOrEqual($php74)); + } +} diff --git a/test/PhpParser/PrettyPrinterTest.php b/test/PhpParser/PrettyPrinterTest.php index e5b8a1aeae..8e0e472179 100644 --- a/test/PhpParser/PrettyPrinterTest.php +++ b/test/PhpParser/PrettyPrinterTest.php @@ -4,80 +4,60 @@ use PhpParser\Node\Expr; use PhpParser\Node\Name; -use PhpParser\Node\Scalar\DNumber; -use PhpParser\Node\Scalar\Encapsed; -use PhpParser\Node\Scalar\EncapsedStringPart; -use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Scalar\Float_; +use PhpParser\Node\Scalar\InterpolatedString; +use PhpParser\Node\InterpolatedStringPart; +use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt; use PhpParser\PrettyPrinter\Standard; -class PrettyPrinterTest extends CodeTestAbstract -{ - protected function doTestPrettyPrintMethod($method, $name, $code, $expected, $modeLine) { - $lexer = new Lexer\Emulative; - $parser5 = new Parser\Php5($lexer); - $parser7 = new Parser\Php7($lexer); - - list($version, $options) = $this->parseModeLine($modeLine); - $prettyPrinter = new Standard($options); - - try { - $output5 = canonicalize($prettyPrinter->$method($parser5->parse($code))); - } catch (Error $e) { - $output5 = null; - if ('php7' !== $version) { - throw $e; - } - } - - try { - $output7 = canonicalize($prettyPrinter->$method($parser7->parse($code))); - } catch (Error $e) { - $output7 = null; - if ('php5' !== $version) { - throw $e; - } - } +class PrettyPrinterTest extends CodeTestAbstract { + /** @return array{0: Parser, 1: PrettyPrinter} */ + private function createParserAndPrinter(array $options): array { + $parserVersion = $options['parserVersion'] ?? $options['version'] ?? null; + $printerVersion = $options['version'] ?? null; + $indent = isset($options['indent']) ? json_decode($options['indent']) : null; + $factory = new ParserFactory(); + $parser = $factory->createForVersion($parserVersion !== null + ? PhpVersion::fromString($parserVersion) : PhpVersion::getNewestSupported()); + $prettyPrinter = new Standard([ + 'phpVersion' => $printerVersion !== null ? PhpVersion::fromString($printerVersion) : null, + 'indent' => $indent, + ]); + return [$parser, $prettyPrinter]; + } - if ('php5' === $version) { - $this->assertSame($expected, $output5, $name); - $this->assertNotSame($expected, $output7, $name); - } elseif ('php7' === $version) { - $this->assertSame($expected, $output7, $name); - $this->assertNotSame($expected, $output5, $name); - } else { - $this->assertSame($expected, $output5, $name); - $this->assertSame($expected, $output7, $name); - } + protected function doTestPrettyPrintMethod($method, $name, $code, $expected, $modeLine) { + [$parser, $prettyPrinter] = $this->createParserAndPrinter($this->parseModeLine($modeLine)); + $output = canonicalize($prettyPrinter->$method($parser->parse($code))); + $this->assertSame($expected, $output, $name); } /** * @dataProvider provideTestPrettyPrint - * @covers \PhpParser\PrettyPrinter\Standard */ - public function testPrettyPrint($name, $code, $expected, $mode) { + public function testPrettyPrint($name, $code, $expected, $mode): void { $this->doTestPrettyPrintMethod('prettyPrint', $name, $code, $expected, $mode); } /** * @dataProvider provideTestPrettyPrintFile - * @covers \PhpParser\PrettyPrinter\Standard */ - public function testPrettyPrintFile($name, $code, $expected, $mode) { + public function testPrettyPrintFile($name, $code, $expected, $mode): void { $this->doTestPrettyPrintMethod('prettyPrintFile', $name, $code, $expected, $mode); } - public function provideTestPrettyPrint() { - return $this->getTests(__DIR__ . '/../code/prettyPrinter', 'test'); + public static function provideTestPrettyPrint() { + return self::getTests(__DIR__ . '/../code/prettyPrinter', 'test'); } - public function provideTestPrettyPrintFile() { - return $this->getTests(__DIR__ . '/../code/prettyPrinter', 'file-test'); + public static function provideTestPrettyPrintFile() { + return self::getTests(__DIR__ . '/../code/prettyPrinter', 'file-test'); } - public function testPrettyPrintExpr() { - $prettyPrinter = new Standard; + public function testPrettyPrintExpr(): void { + $prettyPrinter = new Standard(); $expr = new Expr\BinaryOp\Mul( new Expr\BinaryOp\Plus(new Expr\Variable('a'), new Expr\Variable('b')), new Expr\Variable('c') @@ -90,25 +70,18 @@ public function testPrettyPrintExpr() { $this->assertEquals("function () {\n return 'a\nb';\n}", $prettyPrinter->prettyPrintExpr($expr)); } - public function testCommentBeforeInlineHTML() { - $prettyPrinter = new PrettyPrinter\Standard; + public function testCommentBeforeInlineHTML(): void { + $prettyPrinter = new PrettyPrinter\Standard(); $comment = new Comment\Doc("/**\n * This is a comment\n */"); $stmts = [new Stmt\InlineHTML('Hello World!', ['comments' => [$comment]])]; $expected = "\nHello World!"; $this->assertSame($expected, $prettyPrinter->prettyPrintFile($stmts)); } - private function parseModeLine($modeLine) { - $parts = explode(' ', (string) $modeLine, 2); - $version = $parts[0] ?? 'both'; - $options = isset($parts[1]) ? json_decode($parts[1], true) : []; - return [$version, $options]; - } - - public function testArraySyntaxDefault() { + public function testArraySyntaxDefault(): void { $prettyPrinter = new Standard(['shortArraySyntax' => true]); $expr = new Expr\Array_([ - new Expr\ArrayItem(new String_('val'), new String_('key')) + new Node\ArrayItem(new String_('val'), new String_('key')) ]); $expected = "['key' => 'val']"; $this->assertSame($expected, $prettyPrinter->prettyPrintExpr($expr)); @@ -117,13 +90,13 @@ public function testArraySyntaxDefault() { /** * @dataProvider provideTestKindAttributes */ - public function testKindAttributes($node, $expected) { - $prttyPrinter = new PrettyPrinter\Standard; + public function testKindAttributes($node, $expected): void { + $prttyPrinter = new PrettyPrinter\Standard(); $result = $prttyPrinter->prettyPrintExpr($node); $this->assertSame($expected, $result); } - public function provideTestKindAttributes() { + public static function provideTestKindAttributes() { $nowdoc = ['kind' => String_::KIND_NOWDOC, 'docLabel' => 'STR']; $heredoc = ['kind' => String_::KIND_HEREDOC, 'docLabel' => 'STR']; return [ @@ -139,98 +112,88 @@ public function provideTestKindAttributes() { [new String_("A\nB\nC", ['kind' => String_::KIND_NOWDOC, 'docLabel' => 'A']), "'A\nB\nC'"], [new String_("A\nB\nC", ['kind' => String_::KIND_NOWDOC, 'docLabel' => 'B']), "'A\nB\nC'"], [new String_("A\nB\nC", ['kind' => String_::KIND_NOWDOC, 'docLabel' => 'C']), "'A\nB\nC'"], - [new String_("STR;", ['kind' => String_::KIND_NOWDOC, 'docLabel' => 'STR']), "'STR;'"], + [new String_("STR;", $nowdoc), "'STR;'"], + [new String_("STR,", $nowdoc), "'STR,'"], + [new String_(" STR", $nowdoc), "' STR'"], + [new String_("\tSTR", $nowdoc), "'\tSTR'"], + [new String_("STR\x80", $heredoc), '"STR\x80"'], // Doc string if label not contained (or not in ending position) - [new String_("foo", $nowdoc), "<<<'STR'\nfoo\nSTR\n"], - [new String_("foo", $heredoc), "<<prettyPrintExpr($node); $this->assertSame($expected, $result); } - public function provideTestUnnaturalLiterals() { + public static function provideTestUnnaturalLiterals() { return [ - [new LNumber(-1), '-1'], - [new LNumber(-PHP_INT_MAX - 1), '(-' . PHP_INT_MAX . '-1)'], - [new LNumber(-1, ['kind' => LNumber::KIND_BIN]), '-0b1'], - [new LNumber(-1, ['kind' => LNumber::KIND_OCT]), '-01'], - [new LNumber(-1, ['kind' => LNumber::KIND_HEX]), '-0x1'], - [new DNumber(\INF), '\INF'], - [new DNumber(-\INF), '-\INF'], - [new DNumber(-\NAN), '\NAN'], + [new Int_(-1), '-1'], + [new Int_(-PHP_INT_MAX - 1), '(-' . PHP_INT_MAX . '-1)'], + [new Int_(-1, ['kind' => Int_::KIND_BIN]), '-0b1'], + [new Int_(-1, ['kind' => Int_::KIND_OCT]), '-01'], + [new Int_(-1, ['kind' => Int_::KIND_HEX]), '-0x1'], + [new Float_(\INF), '1.0E+1000'], + [new Float_(-\INF), '-1.0E+1000'], + [new Float_(-\NAN), '\NAN'], ]; } - public function testPrettyPrintWithError() { + public function testPrettyPrintWithError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot pretty-print AST with Error nodes'); $stmts = [new Stmt\Expression( new Expr\PropertyFetch(new Expr\Variable('a'), new Expr\Error()) )]; - $prettyPrinter = new PrettyPrinter\Standard; + $prettyPrinter = new PrettyPrinter\Standard(); $prettyPrinter->prettyPrint($stmts); } - public function testPrettyPrintWithErrorInClassConstFetch() { + public function testPrettyPrintWithErrorInClassConstFetch(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Cannot pretty-print AST with Error nodes'); $stmts = [new Stmt\Expression( new Expr\ClassConstFetch(new Name('Foo'), new Expr\Error()) )]; - $prettyPrinter = new PrettyPrinter\Standard; + $prettyPrinter = new PrettyPrinter\Standard(); $prettyPrinter->prettyPrint($stmts); } - public function testPrettyPrintEncapsedStringPart() { - $this->expectException(\LogicException::class); - $this->expectExceptionMessage('Cannot directly print EncapsedStringPart'); - $expr = new Node\Scalar\EncapsedStringPart('foo'); - $prettyPrinter = new PrettyPrinter\Standard; - $prettyPrinter->prettyPrintExpr($expr); - } - /** * @dataProvider provideTestFormatPreservingPrint - * @covers \PhpParser\PrettyPrinter\Standard */ - public function testFormatPreservingPrint($name, $code, $modification, $expected, $modeLine) { - $lexer = new Lexer\Emulative([ - 'usedAttributes' => [ - 'comments', - 'startLine', 'endLine', - 'startTokenPos', 'endTokenPos', - ], - ]); - - $parser = new Parser\Php7($lexer); - $traverser = new NodeTraverser(); - $traverser->addVisitor(new NodeVisitor\CloningVisitor()); - - $printer = new PrettyPrinter\Standard(); + public function testFormatPreservingPrint($name, $code, $modification, $expected, $modeLine): void { + [$parser, $printer] = $this->createParserAndPrinter($this->parseModeLine($modeLine)); + $traverser = new NodeTraverser(new NodeVisitor\CloningVisitor()); $oldStmts = $parser->parse($code); - $oldTokens = $lexer->getTokens(); + $oldTokens = $parser->getTokens(); $newStmts = $traverser->traverse($oldStmts); @@ -241,6 +204,7 @@ public function testFormatPreservingPrint($name, $code, $modification, $expected use PhpParser\Node\Expr; use PhpParser\Node\Scalar; use PhpParser\Node\Stmt; +use PhpParser\Modifiers; \$fn = function(&\$stmts) { $modification }; CODE ); @@ -250,38 +214,21 @@ public function testFormatPreservingPrint($name, $code, $modification, $expected $this->assertSame(canonicalize($expected), canonicalize($newCode), $name); } - public function provideTestFormatPreservingPrint() { - return $this->getTests(__DIR__ . '/../code/formatPreservation', 'test', 3); + public static function provideTestFormatPreservingPrint() { + return self::getTests(__DIR__ . '/../code/formatPreservation', 'test', 3); } /** * @dataProvider provideTestRoundTripPrint - * @covers \PhpParser\PrettyPrinter\Standard */ - public function testRoundTripPrint($name, $code, $expected, $modeLine) { + public function testRoundTripPrint($name, $code, $expected, $modeLine): void { /** * This test makes sure that the format-preserving pretty printer round-trips for all * the pretty printer tests (i.e. returns the input if no changes occurred). */ - list($version) = $this->parseModeLine($modeLine); - - $lexer = new Lexer\Emulative([ - 'usedAttributes' => [ - 'comments', - 'startLine', 'endLine', - 'startTokenPos', 'endTokenPos', - ], - ]); - - $parserClass = $version === 'php5' ? Parser\Php5::class : Parser\Php7::class; - /** @var Parser $parser */ - $parser = new $parserClass($lexer); - - $traverser = new NodeTraverser(); - $traverser->addVisitor(new NodeVisitor\CloningVisitor()); - - $printer = new PrettyPrinter\Standard(); + [$parser, $printer] = $this->createParserAndPrinter($this->parseModeLine($modeLine)); + $traverser = new NodeTraverser(new NodeVisitor\CloningVisitor()); try { $oldStmts = $parser->parse($code); @@ -290,7 +237,7 @@ public function testRoundTripPrint($name, $code, $expected, $modeLine) { return; } - $oldTokens = $lexer->getTokens(); + $oldTokens = $parser->getTokens(); $newStmts = $traverser->traverse($oldStmts); @@ -298,10 +245,64 @@ public function testRoundTripPrint($name, $code, $expected, $modeLine) { $this->assertSame(canonicalize($code), canonicalize($newCode), $name); } - public function provideTestRoundTripPrint() { + public static function provideTestRoundTripPrint() { return array_merge( - $this->getTests(__DIR__ . '/../code/prettyPrinter', 'test'), - $this->getTests(__DIR__ . '/../code/parser', 'test') + self::getTests(__DIR__ . '/../code/prettyPrinter', 'test'), + self::getTests(__DIR__ . '/../code/parser', 'test') ); } + + public function testWindowsNewline(): void { + $prettyPrinter = new Standard([ + 'newline' => "\r\n", + 'phpVersion' => PhpVersion::fromComponents(7, 2), + ]); + $stmts = [ + new Stmt\If_(new Int_(1), [ + 'stmts' => [ + new Stmt\Echo_([new String_('Hello')]), + new Stmt\Echo_([new String_('World')]), + ], + ]), + ]; + $code = $prettyPrinter->prettyPrint($stmts); + $this->assertSame("if (1) {\r\n echo 'Hello';\r\n echo 'World';\r\n}", $code); + $code = $prettyPrinter->prettyPrintFile($stmts); + $this->assertSame("prettyPrintFile($stmts); + $this->assertSame("Hello world", $code); + + $stmts = [ + new Stmt\Expression(new String_('Test', [ + 'kind' => String_::KIND_NOWDOC, + 'docLabel' => 'STR' + ])), + new Stmt\Expression(new String_('Test 2', [ + 'kind' => String_::KIND_HEREDOC, + 'docLabel' => 'STR' + ])), + new Stmt\Expression(new InterpolatedString([new InterpolatedStringPart('Test 3')], [ + 'kind' => String_::KIND_HEREDOC, + 'docLabel' => 'STR' + ])), + ]; + $code = $prettyPrinter->prettyPrint($stmts); + $this->assertSame( + "<<<'STR'\r\nTest\r\nSTR;\r\n<<expectException(\LogicException::class); + $this->expectExceptionMessage('Option "newline" must be one of "\n" or "\r\n"'); + new PrettyPrinter\Standard(['newline' => 'foo']); + } + + public function testInvalidIndent(): void { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Option "indent" must either be all spaces or a single tab'); + new PrettyPrinter\Standard(['indent' => "\t "]); + } } diff --git a/test/PhpParser/TokenTest.php b/test/PhpParser/TokenTest.php new file mode 100644 index 0000000000..c015d9fa0e --- /dev/null +++ b/test/PhpParser/TokenTest.php @@ -0,0 +1,47 @@ +assertSame(',', $token->getTokenName()); + $token = new Token(\T_WHITESPACE, ' '); + $this->assertSame('T_WHITESPACE', $token->getTokenName()); + } + + public function testIs(): void { + $token = new Token(\ord(','), ','); + $this->assertTrue($token->is(\ord(','))); + $this->assertFalse($token->is(\ord(';'))); + $this->assertTrue($token->is(',')); + $this->assertFalse($token->is(';')); + $this->assertTrue($token->is([\ord(','), \ord(';')])); + $this->assertFalse($token->is([\ord('!'), \ord(';')])); + $this->assertTrue($token->is([',', ';'])); + $this->assertFalse($token->is(['!', ';'])); + } + + /** @dataProvider provideTestIsIgnorable */ + public function testIsIgnorable(int $id, string $text, bool $isIgnorable): void { + $token = new Token($id, $text); + $this->assertSame($isIgnorable, $token->isIgnorable()); + } + + public static function provideTestIsIgnorable() { + return [ + [\T_STRING, 'foo', false], + [\T_WHITESPACE, ' ', true], + [\T_COMMENT, '// foo', true], + [\T_DOC_COMMENT, '/** foo */', true], + [\T_OPEN_TAG, 'assertSame(',', (string) $token); + $token = new Token(\T_STRING, 'foo'); + $this->assertSame('foo', (string) $token); + } +} diff --git a/test/bootstrap.php b/test/bootstrap.php index 0bfa9d0ad7..b6ef839653 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -1,4 +1,4 @@ - 'foo', + 'b' => 'bar', +]; +----- +$node = new Expr\ArrayItem(new Scalar\String_('baz'), new Scalar\String_('c')); +$node->setAttribute('comments', [new Comment\Doc(<<expr->expr; +$array->items[] = $node; +----- + 'foo', + 'b' => 'bar', + /** + * A doc comment + */ + 'c' => 'baz', +]; +----- + 'foo', + 'b' => 'bar', +]; +----- +$node = new Expr\ArrayItem(new Scalar\String_('baz'), new Scalar\String_('c')); +$node->setAttribute('comments', [new Comment("/* Block comment */")]); +$array = $stmts[0]->expr->expr; +$array->items[] = $node; +----- + 'foo', + 'b' => 'bar', + /* Block comment */ + 'c' => 'baz', +]; +----- + 'foo', + 'b' => 'bar', +]; +----- +$node = new Expr\ArrayItem(new Scalar\String_('baz'), new Scalar\String_('c')); +$node->setAttribute('comments', [new Comment("// Line comment")]); +$array = $stmts[0]->expr->expr; +$array->items[] = $node; +----- + 'foo', + 'b' => 'bar', + // Line comment + 'c' => 'baz', +]; +----- + 'foo', +]; +----- +$node = new Expr\ArrayItem(new Scalar\String_('bar'), new Scalar\String_('b')); +$node->setAttribute('comments', [new Comment("// Line comment")]); +$array = $stmts[0]->expr->expr; +$array->items[] = $node; +----- + 'foo', + // Line comment + 'b' => 'bar', +]; +----- +setAttribute('comments', [new Comment("// Line comment")]); +$array = $stmts[0]->expr->expr; +$array->items[] = $node; +----- + 'foo', +]; \ No newline at end of file diff --git a/test/code/formatPreservation/arrow_function.test b/test/code/formatPreservation/arrow_function.test index eeff36f7bb..0b81e1b2e6 100644 --- a/test/code/formatPreservation/arrow_function.test +++ b/test/code/formatPreservation/arrow_function.test @@ -69,14 +69,17 @@ static fn($a) : int => $a; ----- -// TODO: Format preserving currently not supported $stmts[0]->expr->static = true; $stmts[1]->expr->static = false; ----- $a; +static fn($a) +: int +=> $a; -fn($a): int => $a; +fn($a) +: int +=> $a; ----- 42; ----- -// TODO: Currently we lose formatting for this case. $attrGroup = new Node\AttributeGroup([ new Node\Attribute(new Node\Name('A'), []), ]); +$attrGroup2 = new Node\AttributeGroup([ + new Node\Attribute(new Node\Name('B'), []), +]); $stmts[0]->attrGroups[] = $attrGroup; +$stmts[0]->attrGroups[] = $attrGroup2; $stmts[0]->stmts[0]->attrGroups[] = $attrGroup; +$stmts[0]->stmts[0]->attrGroups[] = $attrGroup2; $stmts[0]->stmts[1]->attrGroups[] = $attrGroup; $stmts[0]->stmts[2]->attrGroups[] = $attrGroup; $stmts[1]->attrGroups[] = $attrGroup; @@ -119,39 +123,34 @@ $stmts[6]->expr->attrGroups[] = $attrGroup; ----- 42; +new #[A] class {}; +#[A] function() {}; +#[A] fn() + => 42; ----- stmts[0]->stmts[0]->setAttribute('comments', [new Comment("// I'm a new comment\n")]); +$stmts[0]->stmts[0]->stmts[0]->setAttribute('comments', [new Comment("// I'm a new comment")]); ----- expr->static = true; +----- +setDocComment(new Comment\Doc("/** foo */")); +----- +attrGroups[] = $attrGroup; +$stmts[1]->attrGroups[] = $attrGroup; +----- +attrGroups[0]->attrs[] = $attr; +$stmts[1]->attrGroups[0]->attrs[] = $attr; +----- + 42; @@ -107,4 +107,4 @@ Foo new class ($a, $b) -extends Foo {}; \ No newline at end of file +extends Foo {}; diff --git a/test/code/formatPreservation/enum.test b/test/code/formatPreservation/enum.test new file mode 100644 index 0000000000..c6abcbf74c --- /dev/null +++ b/test/code/formatPreservation/enum.test @@ -0,0 +1,100 @@ +Enum formatting preservation +----- +scalarType = null; +----- +stmts[0]->expr = null; +----- +scalarType = new Node\Identifier('int'); +----- +scalarType = new Node\Identifier('int'); +----- +stmts[0]->expr = new Scalar\LNumber(1); +----- +stmts[] = new Node\Stmt\EnumCase('C'); +----- +implements[] = new Node\Name('Z'); +----- +implements[] = new Node\Name('Y'); +----- + bar; $foo -> bar; self :: $foo; self :: $foo; +new Foo(); +$x instanceof Foo; +Foo :: bar; +Foo :: $bar; +Foo :: bar(); +Foo :: bar; ----- $stmts[0]->expr->name = new Expr\Variable('a'); $stmts[1]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b')); @@ -54,6 +60,12 @@ $stmts[5]->expr->name = new Expr\Variable('bar'); $stmts[6]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b')); $stmts[7]->expr->name = new Node\VarLikeIdentifier('bar'); $stmts[8]->expr->name = new Expr\BinaryOp\Concat(new Expr\Variable('a'), new Expr\Variable('b')); +$stmts[9]->expr->class = new Scalar\String_('Foo'); +$stmts[10]->expr->class = new Scalar\String_('Foo'); +$stmts[11]->expr->class = new Expr\ConstFetch(new Node\Name('FOO')); +$stmts[12]->expr->class = new Expr\ConstFetch(new Node\Name('FOO')); +$stmts[13]->expr->class = new Expr\ConstFetch(new Node\Name('FOO')); +$stmts[14]->expr->name = new Expr\Variable('bar'); ----- foo; $foo -> {$bar}; $foo -> {$a . $b}; self :: $bar; -self :: ${$a . $b}; \ No newline at end of file +self :: ${$a . $b}; +new ('Foo')(); +$x instanceof ('Foo'); +(FOO) :: bar; +(FOO) :: $bar; +(FOO) :: bar(); +Foo :: {$bar}; diff --git a/test/code/formatPreservation/group_use.test b/test/code/formatPreservation/group_use.test new file mode 100644 index 0000000000..39c87b6489 --- /dev/null +++ b/test/code/formatPreservation/group_use.test @@ -0,0 +1,9 @@ +Group use should include trailing semicolon +----- + $stmts]); +----- +!!indent=" " + $stmts]); +----- +!!indent="\t" +stmts[] = new Stmt\Expression(new Expr\Variable('y')); +----- +!!indent="\t" +expr; +$stmts[0]->expr = new Expr\StaticCall(new Node\Name\FullyQualified('Compat'), $call->name, $call->args); +----- +cond, $stmts[0]->stmts); +----- +stmts[1] = $stmts[0]->stmts[2]; ----- Barstmts[2]); +----- +BarBarstmts, 0, 1, []); +----- +BarBarstmts, 1, 1, []); +----- +expr = new Expr\Variable('x'); $stmts[10]->extends = new Node\Name\FullyQualified('Bar'); $stmts[10]->stmts[0]->returnType = new Node\Name('Y'); $stmts[10]->stmts[1]->props[0]->default = new Scalar\DNumber(42.0); +$stmts[10]->stmts[2]->type = new Node\Identifier('int'); $stmts[11]->keyVar = new Expr\Variable('z'); $stmts[12]->vars[0]->default = new Scalar\String_('abc'); $stmts[13]->finally = new Stmt\Finally_([]); @@ -99,7 +104,7 @@ function foo( int $x, array &$y = null -) : Foo +): Foo {} $foo @@ -107,11 +112,11 @@ $foo ]; [ - 'X' => $value + 'X' => & $value ]; function -() : Bar +(): Bar {}; $x @@ -134,12 +139,16 @@ class X extends \Bar { public - function y() : Y + function y(): Y {} private $x = 42.0 ; + + const int + X + = 1; } foreach ( @@ -191,4 +200,4 @@ try } catch (Exception $e) { -} \ No newline at end of file +} diff --git a/test/code/formatPreservation/listInsertion.test b/test/code/formatPreservation/listInsertion.test index 0795c9d919..7b33bcebeb 100644 --- a/test/code/formatPreservation/listInsertion.test +++ b/test/code/formatPreservation/listInsertion.test @@ -141,7 +141,7 @@ function test() { namespace Foo; ----- -$stmts[0]->name->parts[0] = 'Xyz'; +$stmts[0]->name->name = 'Xyz'; ----- returnType->types[] = new Node\Name('C'); +----- +expr->var->items, 1, 0, [null]); +----- +stmts[] = new Stmt\Expression(new Expr\Variable('c')); +----- +stmts[0]->traits[0]); +----- + 'one' @@ -10,11 +11,12 @@ $value = match (1) { $stmts[0]->expr->expr->arms[] = new Node\MatchArm(null, new Scalar\String_('two')); ----- 'one', - default => 'two', + default => 'two' }; ----- expr->expr->arms[0]->conds = null; // TODO: Preserve formatting? $value = match (1) { default => 'test', -}; \ No newline at end of file +}; diff --git a/test/code/formatPreservation/modifierChange.test b/test/code/formatPreservation/modifierChange.test index 08005bc738..af74aa2891 100644 --- a/test/code/formatPreservation/modifierChange.test +++ b/test/code/formatPreservation/modifierChange.test @@ -28,7 +28,7 @@ class Bar { protected $foo = 24; - public final function + final public function foo() {} } ----- @@ -54,4 +54,15 @@ function test( = 'z', public T3 $z = 'x', -) {} \ No newline at end of file +) {} +----- +expr->class->flags = Modifiers::READONLY; +$stmts[1]->expr->class->flags = 0; +----- + 42; + } +} +----- +$stmts[0]->stmts[0]->hooks[] = new Node\PropertyHook('set', new Scalar\Int_(123)); +----- + 42; + set => 123; + } +} +----- + 42; } + ) {} +} +----- +$stmts[0]->stmts[0]->params[0]->hooks[] = new Node\PropertyHook('set', new Scalar\Int_(123)); +----- + 42; + set => 123; } + ) {} +} +----- +stmts[0]->hooks[0]->body[] = new Stmt\Expression(new Expr\Variable('b')); +----- + 42; + } +} +----- +$stmts[0]->stmts[0]->hooks[0]->flags = Modifiers::FINAL; +----- + 42; + } +} +----- + 42; + } +} +----- +$stmts[0]->stmts[0]->hooks[0]->body = [new Stmt\Return_(new Scalar\Int_(24))]; +----- +stmts[0]->hooks[0]->body = new Scalar\Int_(24); +$stmts[0]->stmts[1]->hooks[0]->body = [new Stmt\Return_(new Scalar\Int_(24))]; +----- + 24; + } + public $prop2 { + &get { + return 24; + } + } +} diff --git a/test/code/formatPreservation/removalViaNull.test b/test/code/formatPreservation/removalViaNull.test index 35c40c81b8..a3679289db 100644 --- a/test/code/formatPreservation/removalViaNull.test +++ b/test/code/formatPreservation/removalViaNull.test @@ -35,6 +35,11 @@ Bar y ; } + + const + int + X + = 1; } $foo [ $bar ]; @@ -43,7 +48,7 @@ $foo ? $bar : $baz; [ $a => $b -, $c => $d]; +, $c => & $d]; yield $foo @@ -97,6 +102,7 @@ $stmts[2]->extends = null; $stmts[2]->stmts[0]->returnType = null; $stmts[2]->stmts[1]->props[0]->default = null; $stmts[2]->stmts[2]->adaptations[0]->newName = null; +$stmts[2]->stmts[3]->type = null; $stmts[3]->expr->dim = null; $stmts[4]->expr->expr = null; $stmts[5]->expr->if = null; @@ -141,6 +147,10 @@ Foo public ; } + + const + X + = 1; } $foo []; @@ -149,7 +159,7 @@ $foo ?: $baz; [ $a => $b -, $d]; +, & $d]; yield $bar; @@ -209,4 +219,4 @@ try } catch (Exception) { -} \ No newline at end of file +} diff --git a/test/code/parser/blockComments.test b/test/code/parser/blockComments.test index 8cfe166d74..4d259a4361 100644 --- a/test/code/parser/blockComments.test +++ b/test/code/parser/blockComments.test @@ -15,22 +15,33 @@ Comments on blocks {} ----- array( - 0: Stmt_Expression( - expr: Expr_Variable( - name: a - comments: array( - 0: // baz + 0: Stmt_Block( + stmts: array( + 0: Stmt_Block( + stmts: array( + 0: Stmt_Expression( + expr: Expr_Variable( + name: a + ) + comments: array( + 0: // baz + ) + ) + ) + comments: array( + 0: // bar + ) ) ) comments: array( 0: // foo - 1: // bar - 2: // baz ) ) - 1: Stmt_Nop( + 1: Stmt_Block( + stmts: array( + ) comments: array( 0: // empty ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/commentAtEndOfClass.test b/test/code/parser/commentAtEndOfClass.test index cc5393660b..e287451dad 100644 --- a/test/code/parser/commentAtEndOfClass.test +++ b/test/code/parser/commentAtEndOfClass.test @@ -21,16 +21,18 @@ array( 0: Stmt_Property( attrGroups: array( ) - flags: MODIFIER_PROTECTED (2) + flags: PROTECTED (2) type: null props: array( - 0: Stmt_PropertyProperty( + 0: PropertyItem( name: VarLikeIdentifier( name: a ) default: null ) ) + hooks: array( + ) ) 1: Stmt_Nop( comments: array( @@ -39,4 +41,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/comments.test b/test/code/parser/comments.test index 90b6b1f079..6c88c159f0 100644 --- a/test/code/parser/comments.test +++ b/test/code/parser/comments.test @@ -24,12 +24,6 @@ array( 0: Stmt_Expression( expr: Expr_Variable( name: var - comments: array( - 0: /** doc 1 */ - 1: /* foobar 1 */ - 2: // foo 1 - 3: // bar 1 - ) ) comments: array( 0: /** doc 1 */ @@ -93,7 +87,7 @@ if (42) {} ----- array( 0: Stmt_If( - cond: Scalar_LNumber( + cond: Scalar_Int( value: 42 ) stmts: array( @@ -105,4 +99,4 @@ array( 0: // comment ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/emptyFile.test b/test/code/parser/emptyFile.test new file mode 100644 index 0000000000..2f3acd0352 --- /dev/null +++ b/test/code/parser/emptyFile.test @@ -0,0 +1,6 @@ +Empty file +----- + +----- +array( +) diff --git a/test/code/parser/errorHandling/eofError.test b/test/code/parser/errorHandling/eofError.test index 012841def0..c342385617 100644 --- a/test/code/parser/errorHandling/eofError.test +++ b/test/code/parser/errorHandling/eofError.test @@ -7,9 +7,7 @@ array( 0: Stmt_Expression( expr: Expr_ConstFetch( name: Name( - parts: array( - 0: foo - ) + name: foo ) ) ) @@ -22,9 +20,7 @@ array( 0: Stmt_Expression( expr: Expr_ConstFetch( name: Name( - parts: array( - 0: foo - ) + name: foo ) ) ) @@ -33,4 +29,4 @@ array( 0: /* bar */ ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/errorHandling/lexerErrors.test b/test/code/parser/errorHandling/lexerErrors.test index 7ff27eb94b..2efcac65b1 100644 --- a/test/code/parser/errorHandling/lexerErrors.test +++ b/test/code/parser/errorHandling/lexerErrors.test @@ -13,7 +13,7 @@ array( var: Expr_Variable( name: a ) - expr: Scalar_LNumber( + expr: Scalar_Int( value: 42 ) ) @@ -40,7 +40,7 @@ array( var: Expr_Variable[3:1 - 3:2]( name: a ) - expr: Scalar_LNumber[3:6 - 3:7]( + expr: Scalar_Int[3:6 - 3:7]( value: 42 ) ) @@ -50,7 +50,7 @@ array( var: Expr_Variable[5:1 - 5:2]( name: b ) - expr: Scalar_LNumber[5:6 - 5:7]( + expr: Scalar_Int[5:6 - 5:7]( value: 24 ) ) @@ -71,7 +71,7 @@ array( var: Expr_Variable[3:1 - 3:2]( name: a ) - expr: Scalar_LNumber[3:6 - 3:7]( + expr: Scalar_Int[3:6 - 3:7]( value: 42 ) ) @@ -81,7 +81,7 @@ array( var: Expr_Variable[5:1 - 5:2]( name: b ) - expr: Scalar_LNumber[5:6 - 5:7]( + expr: Scalar_Int[5:6 - 5:7]( value: 24 ) ) @@ -105,7 +105,7 @@ array( var: Expr_Variable[3:1 - 3:2]( name: a ) - expr: Scalar_LNumber[3:6 - 3:6]( + expr: Scalar_Int[3:6 - 3:6]( value: 1 ) ) @@ -115,7 +115,7 @@ array( var: Expr_Variable[5:1 - 5:2]( name: b ) - expr: Scalar_LNumber[5:6 - 5:6]( + expr: Scalar_Int[5:6 - 5:6]( value: 2 ) ) @@ -125,7 +125,7 @@ array( var: Expr_Variable[7:1 - 7:2]( name: c ) - expr: Scalar_LNumber[7:6 - 7:6]( + expr: Scalar_Int[7:6 - 7:6]( value: 3 ) ) @@ -140,4 +140,4 @@ if ($b) { } ----- Unterminated comment from 5:5 to 6:2 -Syntax error, unexpected EOF from 6:2 to 6:2 \ No newline at end of file +Syntax error, unexpected EOF from 6:2 to 6:2 diff --git a/test/code/parser/errorHandling/recovery.test b/test/code/parser/errorHandling/recovery.test index 27f7cb4434..a56182d67d 100644 --- a/test/code/parser/errorHandling/recovery.test +++ b/test/code/parser/errorHandling/recovery.test @@ -13,9 +13,7 @@ array( 0: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: foo - ) + name: foo ) args: array( ) @@ -24,9 +22,7 @@ array( 1: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: bar - ) + name: bar ) args: array( ) @@ -35,9 +31,7 @@ array( 2: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: baz - ) + name: baz ) args: array( ) @@ -56,9 +50,7 @@ array( 0: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: foo - ) + name: foo ) args: array( ) @@ -67,9 +59,7 @@ array( 1: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: bar - ) + name: bar ) args: array( ) @@ -78,9 +68,7 @@ array( 2: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: baz - ) + name: baz ) args: array( ) @@ -99,9 +87,7 @@ array( 0: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: foo - ) + name: foo ) args: array( ) @@ -110,9 +96,7 @@ array( 1: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: bar - ) + name: bar ) args: array( ) @@ -121,9 +105,7 @@ array( 2: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: baz - ) + name: baz ) args: array( ) @@ -140,14 +122,12 @@ array( 0: Stmt_Expression( expr: Expr_ConstFetch( name: Name( - parts: array( - 0: abc - ) + name: abc ) ) ) 1: Stmt_Expression( - expr: Scalar_LNumber( + expr: Scalar_Int( value: 1 ) ) @@ -172,7 +152,7 @@ array( returnType: null stmts: array( 0: Stmt_Expression( - expr: Scalar_LNumber( + expr: Scalar_Int( value: 1 ) ) @@ -195,7 +175,7 @@ array( var: Expr_Variable( name: i ) - expr: Scalar_LNumber( + expr: Scalar_Int( value: 0 ) ) @@ -205,7 +185,7 @@ array( var: Expr_Variable( name: j ) - expr: Scalar_LNumber( + expr: Scalar_Int( value: 1 ) ) @@ -215,7 +195,7 @@ array( var: Expr_Variable( name: k ) - expr: Scalar_LNumber( + expr: Scalar_Int( value: 2 ) ) @@ -238,18 +218,22 @@ array( var: Expr_Variable( name: i ) - expr: Scalar_LNumber( + expr: Scalar_Int( value: 0 ) ) ) - 1: Stmt_Expression( - expr: Expr_Assign( - var: Expr_Variable( - name: j - ) - expr: Scalar_LNumber( - value: 1 + 1: Stmt_Block( + stmts: array( + 0: Stmt_Expression( + expr: Expr_Assign( + var: Expr_Variable( + name: j + ) + expr: Scalar_Int( + value: 1 + ) + ) ) ) ) @@ -258,7 +242,7 @@ array( var: Expr_Variable( name: k ) - expr: Scalar_LNumber( + expr: Scalar_Int( value: 2 ) ) @@ -339,9 +323,7 @@ array( 0: Stmt_Expression( expr: Expr_New( class: Name( - parts: array( - 0: T - ) + name: T ) args: array( ) @@ -352,7 +334,7 @@ array( $value $oopsAnotherValue ]; ----- -!!php7 Syntax error, unexpected T_VARIABLE, expecting ',' or ']' or ')' from 3:18 to 3:34 Syntax error, unexpected T_VARIABLE, expecting ',' or ']' or ')' from 6:12 to 6:28 Syntax error, unexpected T_VARIABLE, expecting ',' or ']' or ')' from 9:21 to 9:37 @@ -1278,7 +1242,7 @@ array( ) expr: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Expr_PropertyFetch( var: Expr_Variable( @@ -1291,7 +1255,7 @@ array( byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: null value: Expr_MethodCall( var: Expr_Variable( @@ -1317,7 +1281,7 @@ array( ) expr: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Expr_Variable( name: value @@ -1325,7 +1289,7 @@ array( byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: null value: Expr_Variable( name: oopsAnotherValue @@ -1344,7 +1308,7 @@ array( ) expr: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: Scalar_String( value: key ) @@ -1354,7 +1318,7 @@ array( byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: null value: Expr_Variable( name: oopsAnotherValue @@ -1374,7 +1338,6 @@ function foo() : return $a; } ----- -!!php7 Syntax error, unexpected '{' from 3:1 to 3:1 array( 0: Stmt_Function( @@ -1400,7 +1363,6 @@ array( b{'c'}; +$a->b(){'c'}; +A::$b{'c'}; +A{0}; +A::B{0}; +new $array{'className'}; +new $a->b{'c'}(); +----- +!!version=7.4 +array( + 0: Stmt_Expression( + expr: Expr_ArrayDimFetch( + var: Expr_Variable( + name: a + ) + dim: Scalar_String( + value: b + ) + ) + ) + 1: Stmt_Expression( + expr: Expr_FuncCall( + name: Expr_ArrayDimFetch( + var: Expr_Variable( + name: a + ) + dim: Scalar_String( + value: b + ) + ) + args: array( + ) + ) + ) + 2: Stmt_Expression( + expr: Expr_ArrayDimFetch( + var: Expr_PropertyFetch( + var: Expr_Variable( + name: a + ) + name: Identifier( + name: b + ) + ) + dim: Scalar_String( + value: c + ) + ) + ) + 3: Stmt_Expression( + expr: Expr_ArrayDimFetch( + var: Expr_MethodCall( + var: Expr_Variable( + name: a + ) + name: Identifier( + name: b + ) + args: array( + ) + ) + dim: Scalar_String( + value: c + ) + ) + ) + 4: Stmt_Expression( + expr: Expr_ArrayDimFetch( + var: Expr_StaticPropertyFetch( + class: Name( + name: A + ) + name: VarLikeIdentifier( + name: b + ) + ) + dim: Scalar_String( + value: c + ) + ) + ) + 5: Stmt_Expression( + expr: Expr_ArrayDimFetch( + var: Expr_ConstFetch( + name: Name( + name: A + ) + ) + dim: Scalar_Int( + value: 0 + ) + ) + ) + 6: Stmt_Expression( + expr: Expr_ArrayDimFetch( + var: Expr_ClassConstFetch( + class: Name( + name: A + ) + name: Identifier( + name: B + ) + ) + dim: Scalar_Int( + value: 0 + ) + ) + ) + 7: Stmt_Expression( + expr: Expr_New( + class: Expr_ArrayDimFetch( + var: Expr_Variable( + name: array + ) + dim: Scalar_String( + value: className + ) + ) + args: array( + ) + ) + ) + 8: Stmt_Expression( + expr: Expr_New( + class: Expr_ArrayDimFetch( + var: Expr_PropertyFetch( + var: Expr_Variable( + name: a + ) + name: Identifier( + name: b + ) + ) + dim: Scalar_String( + value: c + ) + ) + args: array( + ) + ) + ) +) +----- +b{'c'}; +$a->b(){'c'}; +A::$b{'c'}; +A{0}; +A::B{0}; +new $array{'className'}; +new $a->b{'c'}(); +----- +Syntax error, unexpected '{' from 3:3 to 3:3 +Syntax error, unexpected '{' from 4:3 to 4:3 +Syntax error, unexpected '{' from 5:6 to 5:6 +Syntax error, unexpected '{' from 6:8 to 6:8 +Syntax error, unexpected '{' from 7:6 to 7:6 +Syntax error, unexpected '{' from 8:2 to 8:2 +Syntax error, unexpected '{' from 9:5 to 9:5 +Syntax error, unexpected '{' from 10:11 to 10:11 +Syntax error, unexpected '{' from 11:10 to 11:10 +array( + 0: Stmt_Expression( + expr: Expr_Variable( + name: a + ) + ) + 1: Stmt_Block( + stmts: array( + 0: Stmt_Expression( + expr: Scalar_String( + value: b + ) + ) + ) + ) + 2: Stmt_Expression( + expr: Expr_Variable( + name: a + ) + ) + 3: Stmt_Block( + stmts: array( + 0: Stmt_Expression( + expr: Scalar_String( + value: b + ) + ) + ) + ) + 4: Stmt_Expression( + expr: Expr_PropertyFetch( + var: Expr_Variable( + name: a + ) + name: Identifier( + name: b + ) + ) + ) + 5: Stmt_Block( + stmts: array( + 0: Stmt_Expression( + expr: Scalar_String( + value: c + ) + ) + ) + ) + 6: Stmt_Expression( + expr: Expr_MethodCall( + var: Expr_Variable( + name: a + ) + name: Identifier( + name: b + ) + args: array( + ) + ) + ) + 7: Stmt_Block( + stmts: array( + 0: Stmt_Expression( + expr: Scalar_String( + value: c + ) + ) + ) + ) + 8: Stmt_Expression( + expr: Expr_StaticPropertyFetch( + class: Name( + name: A + ) + name: VarLikeIdentifier( + name: b + ) + ) + ) + 9: Stmt_Block( + stmts: array( + 0: Stmt_Expression( + expr: Scalar_String( + value: c + ) + ) + ) + ) + 10: Stmt_Expression( + expr: Expr_ConstFetch( + name: Name( + name: A + ) + ) + ) + 11: Stmt_Block( + stmts: array( + 0: Stmt_Expression( + expr: Scalar_Int( + value: 0 + ) + ) + ) + ) + 12: Stmt_Expression( + expr: Expr_ClassConstFetch( + class: Name( + name: A + ) + name: Identifier( + name: B + ) + ) + ) + 13: Stmt_Block( + stmts: array( + 0: Stmt_Expression( + expr: Scalar_Int( + value: 0 + ) + ) + ) + ) + 14: Stmt_Expression( + expr: Expr_New( + class: Expr_Variable( + name: array + ) + args: array( + ) + ) + ) + 15: Stmt_Block( + stmts: array( + 0: Stmt_Expression( + expr: Scalar_String( + value: className + ) + ) + ) + ) + 16: Stmt_Expression( + expr: Expr_New( + class: Expr_PropertyFetch( + var: Expr_Variable( + name: a + ) + name: Identifier( + name: b + ) + ) + args: array( + ) + ) + ) + 17: Stmt_Block( + stmts: array( + 0: Stmt_Expression( + expr: Scalar_String( + value: c + ) + ) + ) + ) +) diff --git a/test/code/parser/expr/arrayDef.test b/test/code/parser/expr/arrayDef.test index 0339a56761..88cbb5895d 100644 --- a/test/code/parser/expr/arrayDef.test +++ b/test/code/parser/expr/arrayDef.test @@ -23,7 +23,7 @@ array( 1: Stmt_Expression( expr: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Scalar_String( value: a @@ -37,7 +37,7 @@ array( 2: Stmt_Expression( expr: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Scalar_String( value: a @@ -51,7 +51,7 @@ array( 3: Stmt_Expression( expr: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Scalar_String( value: a @@ -59,7 +59,7 @@ array( byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: null value: Scalar_String( value: b @@ -73,7 +73,7 @@ array( 4: Stmt_Expression( expr: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Scalar_String( value: a @@ -81,7 +81,7 @@ array( byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: null value: Expr_Variable( name: b @@ -89,7 +89,7 @@ array( byRef: true unpack: false ) - 2: Expr_ArrayItem( + 2: ArrayItem( key: Scalar_String( value: c ) @@ -99,7 +99,7 @@ array( byRef: false unpack: false ) - 3: Expr_ArrayItem( + 3: ArrayItem( key: Scalar_String( value: e ) @@ -116,9 +116,6 @@ array( expr: Expr_Array( items: array( ) - comments: array( - 0: // short array syntax - ) ) comments: array( 0: // short array syntax @@ -127,25 +124,25 @@ array( 6: Stmt_Expression( expr: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null - value: Scalar_LNumber( + value: Scalar_Int( value: 1 ) byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: null - value: Scalar_LNumber( + value: Scalar_Int( value: 2 ) byRef: false unpack: false ) - 2: Expr_ArrayItem( + 2: ArrayItem( key: null - value: Scalar_LNumber( + value: Scalar_Int( value: 3 ) byRef: false @@ -157,7 +154,7 @@ array( 7: Stmt_Expression( expr: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: Scalar_String( value: a ) @@ -170,4 +167,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/arrayDestructuring.test b/test/code/parser/expr/arrayDestructuring.test index cfec0d13b1..9b0dfa5829 100644 --- a/test/code/parser/expr/arrayDestructuring.test +++ b/test/code/parser/expr/arrayDestructuring.test @@ -4,16 +4,15 @@ Array destructuring [$a, $b] = [$c, $d]; [, $a, , , $b, ,] = $foo; -[, [[$a]], $b] = $bar; +[, [[$a, , $x]], $b] = $bar; ['a' => $b, 'b' => $a] = $baz; ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_Assign( - var: Expr_Array( + var: Expr_List( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Expr_Variable( name: a @@ -21,7 +20,7 @@ array( byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: null value: Expr_Variable( name: b @@ -33,7 +32,7 @@ array( ) expr: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Expr_Variable( name: c @@ -41,7 +40,7 @@ array( byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: null value: Expr_Variable( name: d @@ -55,10 +54,10 @@ array( ) 1: Stmt_Expression( expr: Expr_Assign( - var: Expr_Array( + var: Expr_List( items: array( 0: null - 1: Expr_ArrayItem( + 1: ArrayItem( key: null value: Expr_Variable( name: a @@ -68,7 +67,7 @@ array( ) 2: null 3: null - 4: Expr_ArrayItem( + 4: ArrayItem( key: null value: Expr_Variable( name: b @@ -86,18 +85,18 @@ array( ) 2: Stmt_Expression( expr: Expr_Assign( - var: Expr_Array( + var: Expr_List( items: array( 0: null - 1: Expr_ArrayItem( + 1: ArrayItem( key: null - value: Expr_Array( + value: Expr_List( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null - value: Expr_Array( + value: Expr_List( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Expr_Variable( name: a @@ -105,6 +104,15 @@ array( byRef: false unpack: false ) + 1: null + 2: ArrayItem( + key: null + value: Expr_Variable( + name: x + ) + byRef: false + unpack: false + ) ) ) byRef: false @@ -115,7 +123,7 @@ array( byRef: false unpack: false ) - 2: Expr_ArrayItem( + 2: ArrayItem( key: null value: Expr_Variable( name: b @@ -132,9 +140,9 @@ array( ) 3: Stmt_Expression( expr: Expr_Assign( - var: Expr_Array( + var: Expr_List( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: Scalar_String( value: a ) @@ -144,7 +152,7 @@ array( byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: Scalar_String( value: b ) @@ -161,4 +169,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/arrayEmptyElemens.test b/test/code/parser/expr/arrayEmptyElemens.test new file mode 100644 index 0000000000..919c0ece6f --- /dev/null +++ b/test/code/parser/expr/arrayEmptyElemens.test @@ -0,0 +1,70 @@ +Array with empty elements +----- + $x; fn&($x) => $x; fn($x, ...$rest) => $rest; fn(): int => $x; + +fn($a, $b) => $a and $b; +fn($a, $b) => $a && $b; ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_ArrowFunction( @@ -30,6 +32,8 @@ array( name: a ) default: null + hooks: array( + ) ) ) returnType: null @@ -55,9 +59,11 @@ array( var: Expr_Variable( name: x ) - default: Scalar_LNumber( + default: Scalar_Int( value: 42 ) + hooks: array( + ) ) ) returnType: null @@ -84,6 +90,8 @@ array( name: x ) default: null + hooks: array( + ) ) ) returnType: null @@ -110,6 +118,8 @@ array( name: x ) default: null + hooks: array( + ) ) ) returnType: null @@ -136,6 +146,8 @@ array( name: x ) default: null + hooks: array( + ) ) 1: Param( attrGroups: array( @@ -148,6 +160,8 @@ array( name: rest ) default: null + hooks: array( + ) ) ) returnType: null @@ -172,4 +186,98 @@ array( ) ) ) -) \ No newline at end of file + 6: Stmt_Expression( + expr: Expr_ArrowFunction( + attrGroups: array( + ) + static: false + byRef: false + params: array( + 0: Param( + attrGroups: array( + ) + flags: 0 + type: null + byRef: false + variadic: false + var: Expr_Variable( + name: a + ) + default: null + hooks: array( + ) + ) + 1: Param( + attrGroups: array( + ) + flags: 0 + type: null + byRef: false + variadic: false + var: Expr_Variable( + name: b + ) + default: null + hooks: array( + ) + ) + ) + returnType: null + expr: Expr_BinaryOp_LogicalAnd( + left: Expr_Variable( + name: a + ) + right: Expr_Variable( + name: b + ) + ) + ) + ) + 7: Stmt_Expression( + expr: Expr_ArrowFunction( + attrGroups: array( + ) + static: false + byRef: false + params: array( + 0: Param( + attrGroups: array( + ) + flags: 0 + type: null + byRef: false + variadic: false + var: Expr_Variable( + name: a + ) + default: null + hooks: array( + ) + ) + 1: Param( + attrGroups: array( + ) + flags: 0 + type: null + byRef: false + variadic: false + var: Expr_Variable( + name: b + ) + default: null + hooks: array( + ) + ) + ) + returnType: null + expr: Expr_BinaryOp_BooleanAnd( + left: Expr_Variable( + name: a + ) + right: Expr_Variable( + name: b + ) + ) + ) + ) +) diff --git a/test/code/parser/expr/assign.test b/test/code/parser/expr/assign.test index 423f48af2f..4d34843af6 100644 --- a/test/code/parser/expr/assign.test +++ b/test/code/parser/expr/assign.test @@ -41,16 +41,10 @@ array( expr: Expr_Assign( var: Expr_Variable( name: a - comments: array( - 0: // simple assign - ) ) expr: Expr_Variable( name: b ) - comments: array( - 0: // simple assign - ) ) comments: array( 0: // simple assign @@ -60,16 +54,10 @@ array( expr: Expr_AssignOp_BitwiseAnd( var: Expr_Variable( name: a - comments: array( - 0: // combined assign - ) ) expr: Expr_Variable( name: b ) - comments: array( - 0: // combined assign - ) ) comments: array( 0: // combined assign @@ -199,9 +187,6 @@ array( expr: Expr_Assign( var: Expr_Variable( name: a - comments: array( - 0: // chained assign - ) ) expr: Expr_AssignOp_Mul( var: Expr_Variable( @@ -216,9 +201,6 @@ array( ) ) ) - comments: array( - 0: // chained assign - ) ) comments: array( 0: // chained assign @@ -228,16 +210,10 @@ array( expr: Expr_AssignRef( var: Expr_Variable( name: a - comments: array( - 0: // by ref assign - ) ) expr: Expr_Variable( name: b ) - comments: array( - 0: // by ref assign - ) ) comments: array( 0: // by ref assign @@ -247,7 +223,7 @@ array( expr: Expr_Assign( var: Expr_List( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Expr_Variable( name: a @@ -256,16 +232,10 @@ array( unpack: false ) ) - comments: array( - 0: // list() assign - ) ) expr: Expr_Variable( name: b ) - comments: array( - 0: // list() assign - ) ) comments: array( 0: // list() assign @@ -275,7 +245,7 @@ array( expr: Expr_Assign( var: Expr_List( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Expr_Variable( name: a @@ -284,7 +254,7 @@ array( unpack: false ) 1: null - 2: Expr_ArrayItem( + 2: ArrayItem( key: null value: Expr_Variable( name: b @@ -303,7 +273,7 @@ array( expr: Expr_Assign( var: Expr_List( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Expr_Variable( name: a @@ -311,12 +281,12 @@ array( byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: null value: Expr_List( items: array( 0: null - 1: Expr_ArrayItem( + 1: ArrayItem( key: null value: Expr_Variable( name: c @@ -329,7 +299,7 @@ array( byRef: false unpack: false ) - 2: Expr_ArrayItem( + 2: ArrayItem( key: null value: Expr_Variable( name: d @@ -349,9 +319,6 @@ array( var: Expr_Variable( name: a ) - comments: array( - 0: // inc/dec - ) ) comments: array( 0: // inc/dec @@ -378,4 +345,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/assignNewByRef.test b/test/code/parser/expr/assignNewByRef.test index a66d943a42..338d6507bf 100644 --- a/test/code/parser/expr/assignNewByRef.test +++ b/test/code/parser/expr/assignNewByRef.test @@ -3,7 +3,7 @@ Assigning new by reference (PHP 5 only) b['c'](); // array dereferencing @@ -19,18 +18,10 @@ array( 0: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: a - ) - comments: array( - 0: // function name variations - ) + name: a ) args: array( ) - comments: array( - 0: // function name variations - ) ) comments: array( 0: // function name variations @@ -95,20 +86,6 @@ array( ) ) 6: Stmt_Expression( - expr: Expr_FuncCall( - name: Expr_ArrayDimFetch( - var: Expr_Variable( - name: a - ) - dim: Scalar_String( - value: b - ) - ) - args: array( - ) - ) - ) - 7: Stmt_Expression( expr: Expr_FuncCall( name: Expr_ArrayDimFetch( var: Expr_PropertyFetch( @@ -127,32 +104,21 @@ array( ) ) ) - 8: Stmt_Expression( + 7: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_FuncCall( name: Name( - parts: array( - 0: a - ) - comments: array( - 0: // array dereferencing - ) + name: a ) args: array( ) - comments: array( - 0: // array dereferencing - ) ) dim: Scalar_String( value: b ) - comments: array( - 0: // array dereferencing - ) ) comments: array( 0: // array dereferencing ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/fetchAndCall/namedArgs.test b/test/code/parser/expr/fetchAndCall/namedArgs.test index f6a9a07f0e..7a27c6e92c 100644 --- a/test/code/parser/expr/fetchAndCall/namedArgs.test +++ b/test/code/parser/expr/fetchAndCall/namedArgs.test @@ -4,14 +4,11 @@ Named arguments foo(a: $b, c: $d); bar(class: 0); ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: foo - ) + name: foo ) args: array( 0: Arg( @@ -40,16 +37,14 @@ array( 1: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: bar - ) + name: bar ) args: array( 0: Arg( name: Identifier( name: class ) - value: Scalar_LNumber( + value: Scalar_Int( value: 0 ) byRef: false @@ -58,4 +53,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/fetchAndCall/newDeref.test b/test/code/parser/expr/fetchAndCall/newDeref.test index a4b7a7240b..bfed4374e1 100644 --- a/test/code/parser/expr/fetchAndCall/newDeref.test +++ b/test/code/parser/expr/fetchAndCall/newDeref.test @@ -12,9 +12,7 @@ array( expr: Expr_PropertyFetch( var: Expr_New( class: Name( - parts: array( - 0: A - ) + name: A ) args: array( ) @@ -28,9 +26,7 @@ array( expr: Expr_MethodCall( var: Expr_New( class: Name( - parts: array( - 0: A - ) + name: A ) args: array( ) @@ -46,9 +42,7 @@ array( expr: Expr_ArrayDimFetch( var: Expr_New( class: Name( - parts: array( - 0: A - ) + name: A ) args: array( ) @@ -63,9 +57,7 @@ array( var: Expr_ArrayDimFetch( var: Expr_New( class: Name( - parts: array( - 0: A - ) + name: A ) args: array( ) @@ -79,4 +71,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/fetchAndCall/objectAccess.test b/test/code/parser/expr/fetchAndCall/objectAccess.test index 2d1808b058..1e48031640 100644 --- a/test/code/parser/expr/fetchAndCall/objectAccess.test +++ b/test/code/parser/expr/fetchAndCall/objectAccess.test @@ -5,7 +5,6 @@ Object access // property fetch variations $a->b; $a->b['c']; -$a->b{'c'}; // method call variations $a->b(); @@ -15,24 +14,16 @@ $a->$b['c'](); // array dereferencing $a->b()['c']; -$a->b(){'c'}; // invalid PHP: drop Support? ----- -!!php5 array( 0: Stmt_Expression( expr: Expr_PropertyFetch( var: Expr_Variable( name: a - comments: array( - 0: // property fetch variations - ) ) name: Identifier( name: b ) - comments: array( - 0: // property fetch variations - ) ) comments: array( 0: // property fetch variations @@ -54,42 +45,21 @@ array( ) ) 2: Stmt_Expression( - expr: Expr_ArrayDimFetch( - var: Expr_PropertyFetch( - var: Expr_Variable( - name: a - ) - name: Identifier( - name: b - ) - ) - dim: Scalar_String( - value: c - ) - ) - ) - 3: Stmt_Expression( expr: Expr_MethodCall( var: Expr_Variable( name: a - comments: array( - 0: // method call variations - ) ) name: Identifier( name: b ) args: array( ) - comments: array( - 0: // method call variations - ) ) comments: array( 0: // method call variations ) ) - 4: Stmt_Expression( + 3: Stmt_Expression( expr: Expr_MethodCall( var: Expr_Variable( name: a @@ -101,7 +71,7 @@ array( ) ) ) - 5: Stmt_Expression( + 4: Stmt_Expression( expr: Expr_MethodCall( var: Expr_Variable( name: a @@ -113,14 +83,16 @@ array( ) ) ) - 6: Stmt_Expression( - expr: Expr_MethodCall( - var: Expr_Variable( - name: a - ) + 5: Stmt_Expression( + expr: Expr_FuncCall( name: Expr_ArrayDimFetch( - var: Expr_Variable( - name: b + var: Expr_PropertyFetch( + var: Expr_Variable( + name: a + ) + name: Expr_Variable( + name: b + ) ) dim: Scalar_String( value: c @@ -130,55 +102,24 @@ array( ) ) ) - 7: Stmt_Expression( + 6: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_MethodCall( var: Expr_Variable( name: a - comments: array( - 0: // array dereferencing - ) ) name: Identifier( name: b ) args: array( ) - comments: array( - 0: // array dereferencing - ) ) dim: Scalar_String( value: c ) - comments: array( - 0: // array dereferencing - ) ) comments: array( 0: // array dereferencing ) ) - 8: Stmt_Expression( - expr: Expr_ArrayDimFetch( - var: Expr_MethodCall( - var: Expr_Variable( - name: a - ) - name: Identifier( - name: b - ) - args: array( - ) - ) - dim: Scalar_String( - value: c - ) - ) - ) - 9: Stmt_Nop( - comments: array( - 0: // invalid PHP: drop Support? - ) - ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/fetchAndCall/simpleArrayAccess.test b/test/code/parser/expr/fetchAndCall/simpleArrayAccess.test index 133771b75d..cd0dcc50a4 100644 --- a/test/code/parser/expr/fetchAndCall/simpleArrayAccess.test +++ b/test/code/parser/expr/fetchAndCall/simpleArrayAccess.test @@ -5,7 +5,6 @@ Simple array access $a['b']; $a['b']['c']; $a[] = $b; -$a{'b'}; ${$a}['b']; ----- array( @@ -48,16 +47,6 @@ array( ) ) 3: Stmt_Expression( - expr: Expr_ArrayDimFetch( - var: Expr_Variable( - name: a - ) - dim: Scalar_String( - value: b - ) - ) - ) - 4: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_Variable( name: Expr_Variable( @@ -69,4 +58,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/fetchAndCall/staticCall.test b/test/code/parser/expr/fetchAndCall/staticCall.test index a34a3e4bcd..b88f19fce1 100644 --- a/test/code/parser/expr/fetchAndCall/staticCall.test +++ b/test/code/parser/expr/fetchAndCall/staticCall.test @@ -18,26 +18,17 @@ $a::b(); ${'a'}::b(); $a['b']::c(); ----- -!!php5 array( 0: Stmt_Expression( expr: Expr_StaticCall( class: Name( - parts: array( - 0: A - ) - comments: array( - 0: // method name variations - ) + name: A ) name: Identifier( name: b ) args: array( ) - comments: array( - 0: // method name variations - ) ) comments: array( 0: // method name variations @@ -46,9 +37,7 @@ array( 1: Stmt_Expression( expr: Expr_StaticCall( class: Name( - parts: array( - 0: A - ) + name: A ) name: Scalar_String( value: b @@ -60,9 +49,7 @@ array( 2: Stmt_Expression( expr: Expr_StaticCall( class: Name( - parts: array( - 0: A - ) + name: A ) name: Expr_Variable( name: b @@ -72,15 +59,15 @@ array( ) ) 3: Stmt_Expression( - expr: Expr_StaticCall( - class: Name( - parts: array( - 0: A - ) - ) + expr: Expr_FuncCall( name: Expr_ArrayDimFetch( - var: Expr_Variable( - name: b + var: Expr_StaticPropertyFetch( + class: Name( + name: A + ) + name: VarLikeIdentifier( + name: b + ) ) dim: Scalar_String( value: c @@ -91,16 +78,16 @@ array( ) ) 4: Stmt_Expression( - expr: Expr_StaticCall( - class: Name( - parts: array( - 0: A - ) - ) + expr: Expr_FuncCall( name: Expr_ArrayDimFetch( var: Expr_ArrayDimFetch( - var: Expr_Variable( - name: b + var: Expr_StaticPropertyFetch( + class: Name( + name: A + ) + name: VarLikeIdentifier( + name: b + ) ) dim: Scalar_String( value: c @@ -118,28 +105,17 @@ array( expr: Expr_ArrayDimFetch( var: Expr_StaticCall( class: Name( - parts: array( - 0: A - ) - comments: array( - 0: // array dereferencing - ) + name: A ) name: Identifier( name: b ) args: array( ) - comments: array( - 0: // array dereferencing - ) ) dim: Scalar_String( value: c ) - comments: array( - 0: // array dereferencing - ) ) comments: array( 0: // array dereferencing @@ -148,21 +124,13 @@ array( 6: Stmt_Expression( expr: Expr_StaticCall( class: Name( - parts: array( - 0: static - ) - comments: array( - 0: // class name variations - ) + name: static ) name: Identifier( name: b ) args: array( ) - comments: array( - 0: // class name variations - ) ) comments: array( 0: // class name variations @@ -211,4 +179,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/fetchAndCall/staticPropertyFetch.test b/test/code/parser/expr/fetchAndCall/staticPropertyFetch.test index a1de3c8c12..5256cf0991 100644 --- a/test/code/parser/expr/fetchAndCall/staticPropertyFetch.test +++ b/test/code/parser/expr/fetchAndCall/staticPropertyFetch.test @@ -9,7 +9,6 @@ A::${'b'}; // array access A::$b['c']; -A::$b{'c'}; // class name variations can be found in staticCall.test ----- @@ -17,19 +16,11 @@ array( 0: Stmt_Expression( expr: Expr_StaticPropertyFetch( class: Name( - parts: array( - 0: A - ) - comments: array( - 0: // property name variations - ) + name: A ) name: VarLikeIdentifier( name: b ) - comments: array( - 0: // property name variations - ) ) comments: array( 0: // property name variations @@ -38,9 +29,7 @@ array( 1: Stmt_Expression( expr: Expr_StaticPropertyFetch( class: Name( - parts: array( - 0: A - ) + name: A ) name: Expr_Variable( name: b @@ -50,9 +39,7 @@ array( 2: Stmt_Expression( expr: Expr_StaticPropertyFetch( class: Name( - parts: array( - 0: A - ) + name: A ) name: Scalar_String( value: b @@ -63,51 +50,23 @@ array( expr: Expr_ArrayDimFetch( var: Expr_StaticPropertyFetch( class: Name( - parts: array( - 0: A - ) - comments: array( - 0: // array access - ) + name: A ) name: VarLikeIdentifier( name: b ) - comments: array( - 0: // array access - ) ) dim: Scalar_String( value: c ) - comments: array( - 0: // array access - ) ) comments: array( 0: // array access ) ) - 4: Stmt_Expression( - expr: Expr_ArrayDimFetch( - var: Expr_StaticPropertyFetch( - class: Name( - parts: array( - 0: A - ) - ) - name: VarLikeIdentifier( - name: b - ) - ) - dim: Scalar_String( - value: c - ) - ) - ) - 5: Stmt_Nop( + 4: Stmt_Nop( comments: array( 0: // class name variations can be found in staticCall.test ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/firstClassCallables.test b/test/code/parser/expr/firstClassCallables.test new file mode 100644 index 0000000000..a3f628e371 --- /dev/null +++ b/test/code/parser/expr/firstClassCallables.test @@ -0,0 +1,109 @@ +First-class callables +----- +foo(...); +A::foo(...); + +// These are invalid, but accepted on the parser level. +new Foo(...); +$this?->foo(...); + +#[Foo(...)] +function foo() {} +----- +array( + 0: Stmt_Expression( + expr: Expr_FuncCall( + name: Name( + name: foo + ) + args: array( + 0: VariadicPlaceholder( + ) + ) + ) + ) + 1: Stmt_Expression( + expr: Expr_MethodCall( + var: Expr_Variable( + name: this + ) + name: Identifier( + name: foo + ) + args: array( + 0: VariadicPlaceholder( + ) + ) + ) + ) + 2: Stmt_Expression( + expr: Expr_StaticCall( + class: Name( + name: A + ) + name: Identifier( + name: foo + ) + args: array( + 0: VariadicPlaceholder( + ) + ) + ) + ) + 3: Stmt_Expression( + expr: Expr_New( + class: Name( + name: Foo + ) + args: array( + 0: VariadicPlaceholder( + ) + ) + ) + comments: array( + 0: // These are invalid, but accepted on the parser level. + ) + ) + 4: Stmt_Expression( + expr: Expr_NullsafeMethodCall( + var: Expr_Variable( + name: this + ) + name: Identifier( + name: foo + ) + args: array( + 0: VariadicPlaceholder( + ) + ) + ) + ) + 5: Stmt_Function( + attrGroups: array( + 0: AttributeGroup( + attrs: array( + 0: Attribute( + name: Name( + name: Foo + ) + args: array( + 0: VariadicPlaceholder( + ) + ) + ) + ) + ) + ) + byRef: false + name: Identifier( + name: foo + ) + params: array( + ) + returnType: null + stmts: array( + ) + ) +) diff --git a/test/code/parser/expr/includeAndEval.test b/test/code/parser/expr/includeAndEval.test index 0ab189081a..6d28e7c53d 100644 --- a/test/code/parser/expr/includeAndEval.test +++ b/test/code/parser/expr/includeAndEval.test @@ -47,4 +47,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/issetAndEmpty.test b/test/code/parser/expr/issetAndEmpty.test index 989b3a5547..94babbc0cb 100644 --- a/test/code/parser/expr/issetAndEmpty.test +++ b/test/code/parser/expr/issetAndEmpty.test @@ -44,9 +44,7 @@ array( expr: Expr_Empty( expr: Expr_FuncCall( name: Name( - parts: array( - 0: foo - ) + name: foo ) args: array( ) @@ -57,25 +55,25 @@ array( expr: Expr_Empty( expr: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null - value: Scalar_LNumber( + value: Scalar_Int( value: 1 ) byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: null - value: Scalar_LNumber( + value: Scalar_Int( value: 2 ) byRef: false unpack: false ) - 2: Expr_ArrayItem( + 2: ArrayItem( key: null - value: Scalar_LNumber( + value: Scalar_Int( value: 3 ) byRef: false @@ -85,4 +83,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/keywordsInNamespacedName.test b/test/code/parser/expr/keywordsInNamespacedName.test index 6ff1bdbb39..47279f1da4 100644 --- a/test/code/parser/expr/keywordsInNamespacedName.test +++ b/test/code/parser/expr/keywordsInNamespacedName.test @@ -11,59 +11,44 @@ fn\use(); namespace\fn\use(); private\protected\public\static\abstract\final(); ----- -!!php7 array( 0: Stmt_Namespace( name: Name( - parts: array( - 0: fn - ) + name: fn ) stmts: array( ) ) 1: Stmt_Namespace( name: Name( - parts: array( - 0: fn - 1: use - ) + name: fn\use ) stmts: array( ) ) 2: Stmt_Namespace( name: Name( - parts: array( - 0: self - ) + name: self ) stmts: array( ) ) 3: Stmt_Namespace( name: Name( - parts: array( - 0: parent - ) + name: parent ) stmts: array( ) ) 4: Stmt_Namespace( name: Name( - parts: array( - 0: static - ) + name: static ) stmts: array( 0: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: fn - 1: use - ) + name: fn\use ) args: array( ) @@ -72,10 +57,7 @@ array( 1: Stmt_Expression( expr: Expr_FuncCall( name: Name_FullyQualified( - parts: array( - 0: fn - 1: use - ) + name: fn\use ) args: array( ) @@ -84,10 +66,7 @@ array( 2: Stmt_Expression( expr: Expr_FuncCall( name: Name_Relative( - parts: array( - 0: fn - 1: use - ) + name: fn\use ) args: array( ) @@ -96,14 +75,7 @@ array( 3: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: private - 1: protected - 2: public - 3: static - 4: abstract - 5: final - ) + name: private\protected\public\static\abstract\final ) args: array( ) @@ -111,4 +83,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/listReferences.test b/test/code/parser/expr/listReferences.test index 436d45ffa3..fd333555e1 100644 --- a/test/code/parser/expr/listReferences.test +++ b/test/code/parser/expr/listReferences.test @@ -7,13 +7,12 @@ list('k' => &$v) = $x; [&$v] = $x; ['k' => &$v] = $x; ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_List( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Expr_Variable( name: v @@ -32,7 +31,7 @@ array( expr: Expr_Assign( var: Expr_List( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: Scalar_String( value: k ) @@ -51,9 +50,9 @@ array( ) 2: Stmt_Expression( expr: Expr_Assign( - var: Expr_Array( + var: Expr_List( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Expr_Variable( name: v @@ -70,9 +69,9 @@ array( ) 3: Stmt_Expression( expr: Expr_Assign( - var: Expr_Array( + var: Expr_List( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: Scalar_String( value: k ) @@ -89,4 +88,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/listWithKeys.test b/test/code/parser/expr/listWithKeys.test index e2eeedf0d9..aa07d45e25 100644 --- a/test/code/parser/expr/listWithKeys.test +++ b/test/code/parser/expr/listWithKeys.test @@ -5,13 +5,12 @@ List destructing with keys list('a' => $b) = ['a' => 'b']; list('a' => list($b => $c), 'd' => $e) = $x; ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_Assign( var: Expr_List( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: Scalar_String( value: a ) @@ -25,7 +24,7 @@ array( ) expr: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: Scalar_String( value: a ) @@ -43,13 +42,13 @@ array( expr: Expr_Assign( var: Expr_List( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: Scalar_String( value: a ) value: Expr_List( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: Expr_Variable( name: b ) @@ -64,7 +63,7 @@ array( byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: Scalar_String( value: d ) @@ -81,4 +80,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/logic.test b/test/code/parser/expr/logic.test index 6b434565f6..d1f61eab58 100644 --- a/test/code/parser/expr/logic.test +++ b/test/code/parser/expr/logic.test @@ -25,16 +25,10 @@ array( expr: Expr_BinaryOp_BooleanAnd( left: Expr_Variable( name: a - comments: array( - 0: // boolean ops - ) ) right: Expr_Variable( name: b ) - comments: array( - 0: // boolean ops - ) ) comments: array( 0: // boolean ops @@ -70,16 +64,10 @@ array( expr: Expr_BinaryOp_LogicalAnd( left: Expr_Variable( name: a - comments: array( - 0: // logical ops - ) ) right: Expr_Variable( name: b ) - comments: array( - 0: // logical ops - ) ) comments: array( 0: // logical ops @@ -110,16 +98,10 @@ array( left: Expr_BinaryOp_BooleanAnd( left: Expr_Variable( name: a - comments: array( - 0: // precedence - ) ) right: Expr_Variable( name: b ) - comments: array( - 0: // precedence - ) ) right: Expr_BinaryOp_BooleanAnd( left: Expr_Variable( @@ -129,9 +111,6 @@ array( name: d ) ) - comments: array( - 0: // precedence - ) ) comments: array( 0: // precedence @@ -187,4 +166,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/match.test b/test/code/parser/expr/match.test index 3d1ef58d6d..d16a72f8b3 100644 --- a/test/code/parser/expr/match.test +++ b/test/code/parser/expr/match.test @@ -7,18 +7,17 @@ echo match (1) { 1 => 'Bar', }; ----- -!!php7 array( 0: Stmt_Echo( exprs: array( 0: Expr_Match( - cond: Scalar_LNumber( + cond: Scalar_Int( value: 1 ) arms: array( 0: MatchArm( conds: array( - 0: Scalar_LNumber( + 0: Scalar_Int( value: 0 ) ) @@ -28,7 +27,7 @@ array( ) 1: MatchArm( conds: array( - 0: Scalar_LNumber( + 0: Scalar_Int( value: 1 ) ) @@ -49,7 +48,6 @@ $value = match (1) { 0, 1 => 'Foo', }; ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_Assign( @@ -57,19 +55,16 @@ array( name: value ) expr: Expr_Match( - cond: Scalar_LNumber( + cond: Scalar_Int( value: 1 ) arms: array( 0: MatchArm( conds: array( - 0: Scalar_LNumber( + 0: Scalar_Int( value: 0 - comments: array( - 0: // list of conditions - ) ) - 1: Scalar_LNumber( + 1: Scalar_Int( value: 1 ) ) @@ -92,7 +87,6 @@ $result = match ($operator) { BinaryOperator::ADD => $lhs + $rhs, }; ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_Assign( @@ -108,9 +102,7 @@ array( conds: array( 0: Expr_ClassConstFetch( class: Name( - parts: array( - 0: BinaryOperator - ) + name: BinaryOperator ) name: Identifier( name: ADD @@ -139,7 +131,6 @@ $value = match ($char) { default => 'default' }; ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_Assign( @@ -153,7 +144,7 @@ array( arms: array( 0: MatchArm( conds: array( - 0: Scalar_LNumber( + 0: Scalar_Int( value: 1 ) ) @@ -180,7 +171,6 @@ $value = match (1) { default, => 'Bar', }; ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_Assign( @@ -188,16 +178,16 @@ array( name: value ) expr: Expr_Match( - cond: Scalar_LNumber( + cond: Scalar_Int( value: 1 ) arms: array( 0: MatchArm( conds: array( - 0: Scalar_LNumber( + 0: Scalar_Int( value: 0 ) - 1: Scalar_LNumber( + 1: Scalar_Int( value: 1 ) ) @@ -215,4 +205,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/math.test b/test/code/parser/expr/math.test index 8399400c06..daf469b3e2 100644 --- a/test/code/parser/expr/math.test +++ b/test/code/parser/expr/math.test @@ -39,9 +39,6 @@ array( expr: Expr_Variable( name: a ) - comments: array( - 0: // unary ops - ) ) comments: array( 0: // unary ops @@ -65,16 +62,10 @@ array( expr: Expr_BinaryOp_BitwiseAnd( left: Expr_Variable( name: a - comments: array( - 0: // binary ops - ) ) right: Expr_Variable( name: b ) - comments: array( - 0: // binary ops - ) ) comments: array( 0: // binary ops @@ -195,23 +186,14 @@ array( left: Expr_BinaryOp_Mul( left: Expr_Variable( name: a - comments: array( - 0: // associativity - ) ) right: Expr_Variable( name: b ) - comments: array( - 0: // associativity - ) ) right: Expr_Variable( name: c ) - comments: array( - 0: // associativity - ) ) comments: array( 0: // associativity @@ -236,9 +218,6 @@ array( expr: Expr_BinaryOp_Plus( left: Expr_Variable( name: a - comments: array( - 0: // precedence - ) ) right: Expr_BinaryOp_Mul( left: Expr_Variable( @@ -248,9 +227,6 @@ array( name: c ) ) - comments: array( - 0: // precedence - ) ) comments: array( 0: // precedence @@ -275,9 +251,6 @@ array( expr: Expr_BinaryOp_Pow( left: Expr_Variable( name: a - comments: array( - 0: // pow is special - ) ) right: Expr_BinaryOp_Pow( left: Expr_Variable( @@ -287,9 +260,6 @@ array( name: c ) ) - comments: array( - 0: // pow is special - ) ) comments: array( 0: // pow is special @@ -310,4 +280,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/new.test b/test/code/parser/expr/new.test index 5c6a82a1ee..c962fda34a 100644 --- a/test/code/parser/expr/new.test +++ b/test/code/parser/expr/new.test @@ -13,7 +13,6 @@ new A::$b(); new $a->b(); new $a->b->c(); new $a->b['c'](); -new $a->b{'c'}(); // test regression introduces by new dereferencing syntax (new A); @@ -22,9 +21,7 @@ array( 0: Stmt_Expression( expr: Expr_New( class: Name( - parts: array( - 0: A - ) + name: A ) args: array( ) @@ -33,9 +30,7 @@ array( 1: Stmt_Expression( expr: Expr_New( class: Name( - parts: array( - 0: A - ) + name: A ) args: array( 0: Arg( @@ -56,9 +51,6 @@ array( ) args: array( ) - comments: array( - 0: // class name variations - ) ) comments: array( 0: // class name variations @@ -82,9 +74,7 @@ array( expr: Expr_New( class: Expr_StaticPropertyFetch( class: Name( - parts: array( - 0: A - ) + name: A ) name: VarLikeIdentifier( name: b @@ -106,9 +96,6 @@ array( ) args: array( ) - comments: array( - 0: // DNCR object access - ) ) comments: array( 0: // DNCR object access @@ -153,30 +140,9 @@ array( ) ) 8: Stmt_Expression( - expr: Expr_New( - class: Expr_ArrayDimFetch( - var: Expr_PropertyFetch( - var: Expr_Variable( - name: a - ) - name: Identifier( - name: b - ) - ) - dim: Scalar_String( - value: c - ) - ) - args: array( - ) - ) - ) - 9: Stmt_Expression( expr: Expr_New( class: Name( - parts: array( - 0: A - ) + name: A ) args: array( ) @@ -185,4 +151,4 @@ array( 0: // test regression introduces by new dereferencing syntax ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/newDeref.test b/test/code/parser/expr/newDeref.test new file mode 100644 index 0000000000..9845f689fc --- /dev/null +++ b/test/code/parser/expr/newDeref.test @@ -0,0 +1,280 @@ +New dereference without parentheses +----- +foo; +new A()->foo(); +new A()::FOO; +new A()::foo(); +new A()::$foo; +new A()[0]; +new A()(); + +new class {}->foo; +new class {}->foo(); +new class {}::FOO; +new class {}::foo(); +new class {}::$foo; +new class {}[0]; +new class {}(); +----- +array( + 0: Stmt_Expression( + expr: Expr_PropertyFetch( + var: Expr_New( + class: Name( + name: A + ) + args: array( + ) + ) + name: Identifier( + name: foo + ) + ) + ) + 1: Stmt_Expression( + expr: Expr_MethodCall( + var: Expr_New( + class: Name( + name: A + ) + args: array( + ) + ) + name: Identifier( + name: foo + ) + args: array( + ) + ) + ) + 2: Stmt_Expression( + expr: Expr_ClassConstFetch( + class: Expr_New( + class: Name( + name: A + ) + args: array( + ) + ) + name: Identifier( + name: FOO + ) + ) + ) + 3: Stmt_Expression( + expr: Expr_StaticCall( + class: Expr_New( + class: Name( + name: A + ) + args: array( + ) + ) + name: Identifier( + name: foo + ) + args: array( + ) + ) + ) + 4: Stmt_Expression( + expr: Expr_StaticPropertyFetch( + class: Expr_New( + class: Name( + name: A + ) + args: array( + ) + ) + name: VarLikeIdentifier( + name: foo + ) + ) + ) + 5: Stmt_Expression( + expr: Expr_ArrayDimFetch( + var: Expr_New( + class: Name( + name: A + ) + args: array( + ) + ) + dim: Scalar_Int( + value: 0 + ) + ) + ) + 6: Stmt_Expression( + expr: Expr_FuncCall( + name: Expr_New( + class: Name( + name: A + ) + args: array( + ) + ) + args: array( + ) + ) + ) + 7: Stmt_Expression( + expr: Expr_PropertyFetch( + var: Expr_New( + class: Stmt_Class( + attrGroups: array( + ) + flags: 0 + name: null + extends: null + implements: array( + ) + stmts: array( + ) + ) + args: array( + ) + ) + name: Identifier( + name: foo + ) + ) + ) + 8: Stmt_Expression( + expr: Expr_MethodCall( + var: Expr_New( + class: Stmt_Class( + attrGroups: array( + ) + flags: 0 + name: null + extends: null + implements: array( + ) + stmts: array( + ) + ) + args: array( + ) + ) + name: Identifier( + name: foo + ) + args: array( + ) + ) + ) + 9: Stmt_Expression( + expr: Expr_ClassConstFetch( + class: Expr_New( + class: Stmt_Class( + attrGroups: array( + ) + flags: 0 + name: null + extends: null + implements: array( + ) + stmts: array( + ) + ) + args: array( + ) + ) + name: Identifier( + name: FOO + ) + ) + ) + 10: Stmt_Expression( + expr: Expr_StaticCall( + class: Expr_New( + class: Stmt_Class( + attrGroups: array( + ) + flags: 0 + name: null + extends: null + implements: array( + ) + stmts: array( + ) + ) + args: array( + ) + ) + name: Identifier( + name: foo + ) + args: array( + ) + ) + ) + 11: Stmt_Expression( + expr: Expr_StaticPropertyFetch( + class: Expr_New( + class: Stmt_Class( + attrGroups: array( + ) + flags: 0 + name: null + extends: null + implements: array( + ) + stmts: array( + ) + ) + args: array( + ) + ) + name: VarLikeIdentifier( + name: foo + ) + ) + ) + 12: Stmt_Expression( + expr: Expr_ArrayDimFetch( + var: Expr_New( + class: Stmt_Class( + attrGroups: array( + ) + flags: 0 + name: null + extends: null + implements: array( + ) + stmts: array( + ) + ) + args: array( + ) + ) + dim: Scalar_Int( + value: 0 + ) + ) + ) + 13: Stmt_Expression( + expr: Expr_FuncCall( + name: Expr_New( + class: Stmt_Class( + attrGroups: array( + ) + flags: 0 + name: null + extends: null + implements: array( + ) + stmts: array( + ) + ) + args: array( + ) + ) + args: array( + ) + ) + ) +) diff --git a/test/code/parser/expr/newWithoutClass.test b/test/code/parser/expr/newWithoutClass.test index 318f9301f9..d06f880f4b 100644 --- a/test/code/parser/expr/newWithoutClass.test +++ b/test/code/parser/expr/newWithoutClass.test @@ -3,15 +3,6 @@ New without a class b; "{$a?->b}"; "$a?->b"; ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_NullsafePropertyFetch( @@ -55,7 +54,7 @@ array( ) ) 3: Stmt_Expression( - expr: Scalar_Encapsed( + expr: Scalar_InterpolatedString( parts: array( 0: Expr_NullsafePropertyFetch( var: Expr_Variable( @@ -69,7 +68,7 @@ array( ) ) 4: Stmt_Expression( - expr: Scalar_Encapsed( + expr: Scalar_InterpolatedString( parts: array( 0: Expr_NullsafePropertyFetch( var: Expr_Variable( @@ -82,4 +81,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/pipe.test b/test/code/parser/expr/pipe.test new file mode 100644 index 0000000000..19b011d879 --- /dev/null +++ b/test/code/parser/expr/pipe.test @@ -0,0 +1,75 @@ +Pipe operator +----- + $b |> $c; +$a . $b |> $c . $d; +$a |> $b == $c; +$c == $a |> $b; +----- +array( + 0: Stmt_Expression( + expr: Expr_BinaryOp_Pipe( + left: Expr_BinaryOp_Pipe( + left: Expr_Variable( + name: a + ) + right: Expr_Variable( + name: b + ) + ) + right: Expr_Variable( + name: c + ) + ) + ) + 1: Stmt_Expression( + expr: Expr_BinaryOp_Pipe( + left: Expr_BinaryOp_Concat( + left: Expr_Variable( + name: a + ) + right: Expr_Variable( + name: b + ) + ) + right: Expr_BinaryOp_Concat( + left: Expr_Variable( + name: c + ) + right: Expr_Variable( + name: d + ) + ) + ) + ) + 2: Stmt_Expression( + expr: Expr_BinaryOp_Equal( + left: Expr_BinaryOp_Pipe( + left: Expr_Variable( + name: a + ) + right: Expr_Variable( + name: b + ) + ) + right: Expr_Variable( + name: c + ) + ) + ) + 3: Stmt_Expression( + expr: Expr_BinaryOp_Equal( + left: Expr_Variable( + name: c + ) + right: Expr_BinaryOp_Pipe( + left: Expr_Variable( + name: a + ) + right: Expr_Variable( + name: b + ) + ) + ) + ) +) \ No newline at end of file diff --git a/test/code/parser/expr/print.test b/test/code/parser/expr/print.test index 84ed7775b1..98e45b56ea 100644 --- a/test/code/parser/expr/print.test +++ b/test/code/parser/expr/print.test @@ -11,4 +11,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/shellExec.test b/test/code/parser/expr/shellExec.test index 115d9f0a36..594bce6f96 100644 --- a/test/code/parser/expr/shellExec.test +++ b/test/code/parser/expr/shellExec.test @@ -17,7 +17,7 @@ array( 1: Stmt_Expression( expr: Expr_ShellExec( parts: array( - 0: Scalar_EncapsedStringPart( + 0: InterpolatedStringPart( value: test ) ) @@ -26,7 +26,7 @@ array( 2: Stmt_Expression( expr: Expr_ShellExec( parts: array( - 0: Scalar_EncapsedStringPart( + 0: InterpolatedStringPart( value: test ) 1: Expr_Variable( @@ -38,7 +38,7 @@ array( 3: Stmt_Expression( expr: Expr_ShellExec( parts: array( - 0: Scalar_EncapsedStringPart( + 0: InterpolatedStringPart( value: test ` ) ) @@ -47,10 +47,10 @@ array( 4: Stmt_Expression( expr: Expr_ShellExec( parts: array( - 0: Scalar_EncapsedStringPart( + 0: InterpolatedStringPart( value: test \" ) ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/ternaryAndCoalesce.test b/test/code/parser/expr/ternaryAndCoalesce.test index ea1010caa1..09be314da4 100644 --- a/test/code/parser/expr/ternaryAndCoalesce.test +++ b/test/code/parser/expr/ternaryAndCoalesce.test @@ -21,9 +21,6 @@ array( expr: Expr_Ternary( cond: Expr_Variable( name: a - comments: array( - 0: // ternary - ) ) if: Expr_Variable( name: b @@ -31,9 +28,6 @@ array( else: Expr_Variable( name: c ) - comments: array( - 0: // ternary - ) ) comments: array( 0: // ternary @@ -55,9 +49,6 @@ array( cond: Expr_Ternary( cond: Expr_Variable( name: a - comments: array( - 0: // precedence - ) ) if: Expr_Variable( name: b @@ -65,9 +56,6 @@ array( else: Expr_Variable( name: c ) - comments: array( - 0: // precedence - ) ) if: Expr_Variable( name: d @@ -75,9 +63,6 @@ array( else: Expr_Variable( name: e ) - comments: array( - 0: // precedence - ) ) comments: array( 0: // precedence @@ -108,16 +93,10 @@ array( expr: Expr_BinaryOp_Coalesce( left: Expr_Variable( name: a - comments: array( - 0: // null coalesce - ) ) right: Expr_Variable( name: b ) - comments: array( - 0: // null coalesce - ) ) comments: array( 0: // null coalesce @@ -171,4 +150,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/throw.test b/test/code/parser/expr/throw.test index f098461d13..a8597ffe9b 100644 --- a/test/code/parser/expr/throw.test +++ b/test/code/parser/expr/throw.test @@ -4,14 +4,11 @@ Throw expression test(throw $x); $a ?? throw new Exception; ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: test - ) + name: test ) args: array( 0: Arg( @@ -35,9 +32,7 @@ array( right: Expr_Throw( expr: Expr_New( class: Name( - parts: array( - 0: Exception - ) + name: Exception ) args: array( ) @@ -45,4 +40,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/trailingCommas.test b/test/code/parser/expr/trailingCommas.test index 4b15a13a6e..cbb5f99a4e 100644 --- a/test/code/parser/expr/trailingCommas.test +++ b/test/code/parser/expr/trailingCommas.test @@ -9,14 +9,11 @@ new Foo($a, $b, ); unset($a, $b, ); isset($a, $b, ); ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: foo - ) + name: foo ) args: array( 0: Arg( @@ -69,9 +66,7 @@ array( 2: Stmt_Expression( expr: Expr_StaticCall( class: Name( - parts: array( - 0: Foo - ) + name: Foo ) name: Identifier( name: bar @@ -99,9 +94,7 @@ array( 3: Stmt_Expression( expr: Expr_New( class: Name( - parts: array( - 0: Foo - ) + name: Foo ) args: array( 0: Arg( @@ -145,4 +138,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/uvs/constDeref.test b/test/code/parser/expr/uvs/constDeref.test index 996e846854..6674610bb8 100644 --- a/test/code/parser/expr/uvs/constDeref.test +++ b/test/code/parser/expr/uvs/constDeref.test @@ -6,11 +6,9 @@ A->length; A->length(); A[0]; A[0][1][2]; -A{0}; A::B[0]; A::B[0][1][2]; -A::B{0}; A::B->length; A::B->length(); A::B::C; @@ -21,15 +19,12 @@ __FUNCTION__[0]; __FUNCTION__->length; __FUNCIONT__->length(); ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_PropertyFetch( var: Expr_ConstFetch( name: Name( - parts: array( - 0: A - ) + name: A ) ) name: Identifier( @@ -41,9 +36,7 @@ array( expr: Expr_MethodCall( var: Expr_ConstFetch( name: Name( - parts: array( - 0: A - ) + name: A ) ) name: Identifier( @@ -57,12 +50,10 @@ array( expr: Expr_ArrayDimFetch( var: Expr_ConstFetch( name: Name( - parts: array( - 0: A - ) + name: A ) ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 0 ) ) @@ -73,106 +64,67 @@ array( var: Expr_ArrayDimFetch( var: Expr_ConstFetch( name: Name( - parts: array( - 0: A - ) + name: A ) ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 0 ) ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 1 ) ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 2 ) ) ) 4: Stmt_Expression( - expr: Expr_ArrayDimFetch( - var: Expr_ConstFetch( - name: Name( - parts: array( - 0: A - ) - ) - ) - dim: Scalar_LNumber( - value: 0 - ) - ) - ) - 5: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_ClassConstFetch( class: Name( - parts: array( - 0: A - ) + name: A ) name: Identifier( name: B ) ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 0 ) ) ) - 6: Stmt_Expression( + 5: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Expr_ArrayDimFetch( var: Expr_ArrayDimFetch( var: Expr_ClassConstFetch( class: Name( - parts: array( - 0: A - ) + name: A ) name: Identifier( name: B ) ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 0 ) ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 1 ) ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 2 ) ) ) - 7: Stmt_Expression( - expr: Expr_ArrayDimFetch( - var: Expr_ClassConstFetch( - class: Name( - parts: array( - 0: A - ) - ) - name: Identifier( - name: B - ) - ) - dim: Scalar_LNumber( - value: 0 - ) - ) - ) - 8: Stmt_Expression( + 6: Stmt_Expression( expr: Expr_PropertyFetch( var: Expr_ClassConstFetch( class: Name( - parts: array( - 0: A - ) + name: A ) name: Identifier( name: B @@ -183,13 +135,11 @@ array( ) ) ) - 9: Stmt_Expression( + 7: Stmt_Expression( expr: Expr_MethodCall( var: Expr_ClassConstFetch( class: Name( - parts: array( - 0: A - ) + name: A ) name: Identifier( name: B @@ -202,13 +152,11 @@ array( ) ) ) - 10: Stmt_Expression( + 8: Stmt_Expression( expr: Expr_ClassConstFetch( class: Expr_ClassConstFetch( class: Name( - parts: array( - 0: A - ) + name: A ) name: Identifier( name: B @@ -219,13 +167,11 @@ array( ) ) ) - 11: Stmt_Expression( + 9: Stmt_Expression( expr: Expr_StaticPropertyFetch( class: Expr_ClassConstFetch( class: Name( - parts: array( - 0: A - ) + name: A ) name: Identifier( name: B @@ -236,13 +182,11 @@ array( ) ) ) - 12: Stmt_Expression( + 10: Stmt_Expression( expr: Expr_StaticCall( class: Expr_ClassConstFetch( class: Name( - parts: array( - 0: A - ) + name: A ) name: Identifier( name: B @@ -255,16 +199,16 @@ array( ) ) ) - 13: Stmt_Expression( + 11: Stmt_Expression( expr: Expr_ArrayDimFetch( var: Scalar_MagicConst_Function( ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 0 ) ) ) - 14: Stmt_Expression( + 12: Stmt_Expression( expr: Expr_PropertyFetch( var: Scalar_MagicConst_Function( ) @@ -273,13 +217,11 @@ array( ) ) ) - 15: Stmt_Expression( + 13: Stmt_Expression( expr: Expr_MethodCall( var: Expr_ConstFetch( name: Name( - parts: array( - 0: __FUNCIONT__ - ) + name: __FUNCIONT__ ) ) name: Identifier( @@ -289,4 +231,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/uvs/globalNonSimpleVarError.test b/test/code/parser/expr/uvs/globalNonSimpleVarError.test index 5ae4f958e2..8b8fd40e09 100644 --- a/test/code/parser/expr/uvs/globalNonSimpleVarError.test +++ b/test/code/parser/expr/uvs/globalNonSimpleVarError.test @@ -3,7 +3,6 @@ Non-simple variables are forbidden in PHP 7 bar; ----- -!!php7 Syntax error, unexpected T_OBJECT_OPERATOR, expecting ';' from 2:13 to 2:14 array( 0: Stmt_Global( @@ -18,10 +17,8 @@ array( 1: Stmt_Expression( expr: Expr_ConstFetch( name: Name( - parts: array( - 0: bar - ) + name: bar ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/uvs/indirectCall.test b/test/code/parser/expr/uvs/indirectCall.test index 776e5c5289..d2cfa99aa2 100644 --- a/test/code/parser/expr/uvs/indirectCall.test +++ b/test/code/parser/expr/uvs/indirectCall.test @@ -15,15 +15,12 @@ id(['udef', 'id'])[1]()('var_dump')(5); ('i' . 'd')()('var_dump')(13); '\id'('var_dump')(14); ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_FuncCall( name: Expr_FuncCall( name: Name( - parts: array( - 0: id - ) + name: id ) args: array( 0: Arg( @@ -39,7 +36,7 @@ array( args: array( 0: Arg( name: null - value: Scalar_LNumber( + value: Scalar_Int( value: 1 ) byRef: false @@ -53,9 +50,7 @@ array( name: Expr_FuncCall( name: Expr_FuncCall( name: Name( - parts: array( - 0: id - ) + name: id ) args: array( 0: Arg( @@ -82,7 +77,7 @@ array( args: array( 0: Arg( name: null - value: Scalar_LNumber( + value: Scalar_Int( value: 2 ) byRef: false @@ -97,9 +92,7 @@ array( name: Expr_FuncCall( name: Expr_FuncCall( name: Name( - parts: array( - 0: id - ) + name: id ) args: array( ) @@ -121,7 +114,7 @@ array( args: array( 0: Arg( name: null - value: Scalar_LNumber( + value: Scalar_Int( value: 4 ) byRef: false @@ -137,16 +130,14 @@ array( name: Expr_ArrayDimFetch( var: Expr_FuncCall( name: Name( - parts: array( - 0: id - ) + name: id ) args: array( 0: Arg( name: null value: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Scalar_String( value: udef @@ -154,7 +145,7 @@ array( byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: null value: Scalar_String( value: id @@ -169,7 +160,7 @@ array( ) ) ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 1 ) ) @@ -190,7 +181,7 @@ array( args: array( 0: Arg( name: null - value: Scalar_LNumber( + value: Scalar_Int( value: 5 ) byRef: false @@ -220,6 +211,8 @@ array( name: x ) default: null + hooks: array( + ) ) ) uses: array( @@ -258,7 +251,7 @@ array( args: array( 0: Arg( name: null - value: Scalar_LNumber( + value: Scalar_Int( value: 8 ) byRef: false @@ -295,15 +288,15 @@ array( ) default: Expr_ConstFetch( name: Name( - parts: array( - 0: null - ) + name: null ) ) + hooks: array( + ) ) ) uses: array( - 0: Expr_ClosureUse( + 0: ClosureUse( var: Expr_Variable( name: f ) @@ -349,7 +342,7 @@ array( args: array( 0: Arg( name: null - value: Scalar_LNumber( + value: Scalar_Int( value: 9 ) byRef: false @@ -366,7 +359,7 @@ array( name: Expr_FuncCall( name: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Expr_Variable( name: obj @@ -374,7 +367,7 @@ array( byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: null value: Scalar_String( value: id @@ -423,7 +416,7 @@ array( args: array( 0: Arg( name: null - value: Scalar_LNumber( + value: Scalar_Int( value: 10 ) byRef: false @@ -468,7 +461,7 @@ array( args: array( 0: Arg( name: null - value: Scalar_LNumber( + value: Scalar_Int( value: 12 ) byRef: false @@ -506,7 +499,7 @@ array( args: array( 0: Arg( name: null - value: Scalar_LNumber( + value: Scalar_Int( value: 13 ) byRef: false @@ -535,7 +528,7 @@ array( args: array( 0: Arg( name: null - value: Scalar_LNumber( + value: Scalar_Int( value: 14 ) byRef: false @@ -544,4 +537,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/uvs/isset.test b/test/code/parser/expr/uvs/isset.test index 828fd9b1f5..fe20e98520 100644 --- a/test/code/parser/expr/uvs/isset.test +++ b/test/code/parser/expr/uvs/isset.test @@ -6,7 +6,6 @@ isset(([0, 1] + [])[0]); isset(['a' => 'b']->a); isset("str"->a); ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_Isset( @@ -15,17 +14,17 @@ array( var: Expr_BinaryOp_Plus( left: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null - value: Scalar_LNumber( + value: Scalar_Int( value: 0 ) byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: null - value: Scalar_LNumber( + value: Scalar_Int( value: 1 ) byRef: false @@ -38,7 +37,7 @@ array( ) ) ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 0 ) ) @@ -51,7 +50,7 @@ array( 0: Expr_PropertyFetch( var: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: Scalar_String( value: a ) @@ -84,4 +83,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/uvs/misc.test b/test/code/parser/expr/uvs/misc.test index f56c096310..5ef02d6dbb 100644 --- a/test/code/parser/expr/uvs/misc.test +++ b/test/code/parser/expr/uvs/misc.test @@ -8,7 +8,6 @@ Uniform variable syntax in PHP 7 (misc) (clone $obj)->b[0](1); [0, 1][0] = 1; ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_MethodCall( @@ -24,9 +23,9 @@ array( ) 1: Stmt_Expression( expr: Expr_ArrayDimFetch( - var: Scalar_Encapsed( + var: Scalar_InterpolatedString( parts: array( - 0: Scalar_EncapsedStringPart( + 0: InterpolatedStringPart( value: foo ) 1: Expr_Variable( @@ -34,16 +33,16 @@ array( ) ) ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 0 ) ) ) 2: Stmt_Expression( expr: Expr_MethodCall( - var: Scalar_Encapsed( + var: Scalar_InterpolatedString( parts: array( - 0: Scalar_EncapsedStringPart( + 0: InterpolatedStringPart( value: foo ) 1: Expr_Variable( @@ -71,14 +70,14 @@ array( name: b ) ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 0 ) ) args: array( 0: Arg( name: null - value: Scalar_LNumber( + value: Scalar_Int( value: 1 ) byRef: false @@ -92,17 +91,17 @@ array( var: Expr_ArrayDimFetch( var: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null - value: Scalar_LNumber( + value: Scalar_Int( value: 0 ) byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: null - value: Scalar_LNumber( + value: Scalar_Int( value: 1 ) byRef: false @@ -110,13 +109,13 @@ array( ) ) ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 0 ) ) - expr: Scalar_LNumber( + expr: Scalar_Int( value: 1 ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/uvs/new.test b/test/code/parser/expr/uvs/new.test index 5e1caf2fc2..403a15f85c 100644 --- a/test/code/parser/expr/uvs/new.test +++ b/test/code/parser/expr/uvs/new.test @@ -3,13 +3,11 @@ UVS new expressions className; new Test::$className; new $test::$className; new $weird[0]->foo::$className; ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_New( @@ -35,20 +33,6 @@ array( ) ) 2: Stmt_Expression( - expr: Expr_New( - class: Expr_ArrayDimFetch( - var: Expr_Variable( - name: array - ) - dim: Scalar_String( - value: className - ) - ) - args: array( - ) - ) - ) - 3: Stmt_Expression( expr: Expr_New( class: Expr_PropertyFetch( var: Expr_Variable( @@ -62,13 +46,11 @@ array( ) ) ) - 4: Stmt_Expression( + 3: Stmt_Expression( expr: Expr_New( class: Expr_StaticPropertyFetch( class: Name( - parts: array( - 0: Test - ) + name: Test ) name: VarLikeIdentifier( name: className @@ -78,7 +60,7 @@ array( ) ) ) - 5: Stmt_Expression( + 4: Stmt_Expression( expr: Expr_New( class: Expr_StaticPropertyFetch( class: Expr_Variable( @@ -92,7 +74,7 @@ array( ) ) ) - 6: Stmt_Expression( + 5: Stmt_Expression( expr: Expr_New( class: Expr_StaticPropertyFetch( class: Expr_PropertyFetch( @@ -100,7 +82,7 @@ array( var: Expr_Variable( name: weird ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 0 ) ) @@ -116,4 +98,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/uvs/newInstanceofExpr.test b/test/code/parser/expr/uvs/newInstanceofExpr.test index b778e4335f..0fe70746d4 100644 --- a/test/code/parser/expr/uvs/newInstanceofExpr.test +++ b/test/code/parser/expr/uvs/newInstanceofExpr.test @@ -6,7 +6,6 @@ new ('Foo' . $bar); new ('Foo' . $bar)($arg); $obj instanceof ('Foo' . $bar); ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_New( @@ -59,4 +58,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/uvs/staticProperty.test b/test/code/parser/expr/uvs/staticProperty.test index bf3547ca76..f912030115 100644 --- a/test/code/parser/expr/uvs/staticProperty.test +++ b/test/code/parser/expr/uvs/staticProperty.test @@ -10,14 +10,11 @@ A::$$b; A::$$c[1]; A::$A::$b; ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_StaticPropertyFetch( class: Name( - parts: array( - 0: A - ) + name: A ) name: VarLikeIdentifier( name: b @@ -65,7 +62,7 @@ array( var: Scalar_String( value: A ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 0 ) ) @@ -77,9 +74,7 @@ array( 5: Stmt_Expression( expr: Expr_StaticPropertyFetch( class: Name( - parts: array( - 0: A - ) + name: A ) name: Expr_Variable( name: b @@ -90,15 +85,13 @@ array( expr: Expr_ArrayDimFetch( var: Expr_StaticPropertyFetch( class: Name( - parts: array( - 0: A - ) + name: A ) name: Expr_Variable( name: c ) ) - dim: Scalar_LNumber( + dim: Scalar_Int( value: 1 ) ) @@ -107,9 +100,7 @@ array( expr: Expr_StaticPropertyFetch( class: Expr_StaticPropertyFetch( class: Name( - parts: array( - 0: A - ) + name: A ) name: VarLikeIdentifier( name: A @@ -120,4 +111,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/varVarPos.test b/test/code/parser/expr/varVarPos.test index 26c747f5ab..aefb8f5217 100644 --- a/test/code/parser/expr/varVarPos.test +++ b/test/code/parser/expr/varVarPos.test @@ -14,4 +14,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/expr/variable.test b/test/code/parser/expr/variable.test index c30326cc5e..f34e495c1d 100644 --- a/test/code/parser/expr/variable.test +++ b/test/code/parser/expr/variable.test @@ -9,7 +9,6 @@ $$a; $$$a; $$a['b']; ----- -!!php5 array( 0: Stmt_Expression( expr: Expr_Variable( @@ -27,9 +26,7 @@ array( expr: Expr_Variable( name: Expr_FuncCall( name: Name( - parts: array( - 0: foo - ) + name: foo ) args: array( ) @@ -53,15 +50,15 @@ array( ) ) 5: Stmt_Expression( - expr: Expr_Variable( - name: Expr_ArrayDimFetch( - var: Expr_Variable( + expr: Expr_ArrayDimFetch( + var: Expr_Variable( + name: Expr_Variable( name: a ) - dim: Scalar_String( - value: b - ) + ) + dim: Scalar_String( + value: b ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/formattingAttributes.test b/test/code/parser/formattingAttributes.test new file mode 100644 index 0000000000..065fb51c50 --- /dev/null +++ b/test/code/parser/formattingAttributes.test @@ -0,0 +1,358 @@ +Test formatting attributes +----- + float overflows - 1: // (all are actually the same number, just in different representations) - ) ) comments: array( 0: // various integer -> float overflows @@ -86,23 +83,28 @@ array( ) ) 11: Stmt_Expression( - expr: Scalar_DNumber( + expr: Scalar_Float( value: 1.844674407371E+19 ) ) 12: Stmt_Expression( - expr: Scalar_DNumber( - value: 1.844674407371E+19 + expr: Scalar_Float( + value: 1.7216961135462E+19 ) ) 13: Stmt_Expression( - expr: Scalar_DNumber( + expr: Scalar_Float( value: 1.844674407371E+19 ) ) 14: Stmt_Expression( - expr: Scalar_DNumber( + expr: Scalar_Float( + value: 1.844674407371E+19 + ) + ) + 15: Stmt_Expression( + expr: Scalar_Float( value: 1.844674407371E+19 ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/scalar/int.test b/test/code/parser/scalar/int.test index b65858dbbc..12081e93b6 100644 --- a/test/code/parser/scalar/int.test +++ b/test/code/parser/scalar/int.test @@ -14,48 +14,48 @@ Different integer syntaxes ----- array( 0: Stmt_Expression( - expr: Scalar_LNumber( + expr: Scalar_Int( value: 0 ) ) 1: Stmt_Expression( - expr: Scalar_LNumber( + expr: Scalar_Int( value: 1 ) ) 2: Stmt_Expression( - expr: Scalar_LNumber( + expr: Scalar_Int( value: @@{ PHP_INT_MAX }@@ ) ) 3: Stmt_Expression( - expr: Scalar_DNumber( + expr: Scalar_Float( value: @@{ PHP_INT_MAX + 1 }@@ ) ) 4: Stmt_Expression( - expr: Scalar_LNumber( + expr: Scalar_Int( value: 4095 ) ) 5: Stmt_Expression( - expr: Scalar_LNumber( + expr: Scalar_Int( value: 4095 ) ) 6: Stmt_Expression( - expr: Scalar_LNumber( + expr: Scalar_Int( value: 4095 ) ) 7: Stmt_Expression( - expr: Scalar_LNumber( + expr: Scalar_Int( value: 511 ) ) 8: Stmt_Expression( - expr: Scalar_LNumber( + expr: Scalar_Int( value: 3640 ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/scalar/invalidOctal.test b/test/code/parser/scalar/invalidOctal.test index cd0cbfba0f..c489abe713 100644 --- a/test/code/parser/scalar/invalidOctal.test +++ b/test/code/parser/scalar/invalidOctal.test @@ -3,11 +3,11 @@ Invalid octal literals 0; $a = #[A12] static function() {}; $b = #[A13] static fn() => 0; ----- -!!php7 array( 0: Stmt_Function( attrGroups: array( @@ -39,32 +38,26 @@ array( attrs: array( 0: Attribute( name: Name( - parts: array( - 0: A1 - ) + name: A1 ) args: array( ) ) 1: Attribute( name: Name( - parts: array( - 0: A2 - ) + name: A2 ) args: array( ) ) 2: Attribute( name: Name( - parts: array( - 0: A3 - ) + name: A3 ) args: array( 0: Arg( name: null - value: Scalar_LNumber( + value: Scalar_Int( value: 0 ) byRef: false @@ -74,16 +67,14 @@ array( ) 3: Attribute( name: Name( - parts: array( - 0: A4 - ) + name: A4 ) args: array( 0: Arg( name: Identifier( name: x ) - value: Scalar_LNumber( + value: Scalar_Int( value: 1 ) byRef: false @@ -110,9 +101,7 @@ array( attrs: array( 0: Attribute( name: Name( - parts: array( - 0: A5 - ) + name: A5 ) args: array( ) @@ -134,9 +123,7 @@ array( attrs: array( 0: Attribute( name: Name( - parts: array( - 0: A6 - ) + name: A6 ) args: array( ) @@ -144,7 +131,7 @@ array( ) ) ) - flags: MODIFIER_PUBLIC (1) + flags: PUBLIC (1) byRef: false name: Identifier( name: m @@ -156,9 +143,7 @@ array( attrs: array( 0: Attribute( name: Name( - parts: array( - 0: A7 - ) + name: A7 ) args: array( ) @@ -174,6 +159,8 @@ array( name: param ) default: null + hooks: array( + ) ) ) returnType: null @@ -186,9 +173,7 @@ array( attrs: array( 0: Attribute( name: Name( - parts: array( - 0: A14 - ) + name: A14 ) args: array( ) @@ -196,16 +181,18 @@ array( ) ) ) - flags: MODIFIER_PUBLIC (1) + flags: PUBLIC (1) type: null props: array( - 0: Stmt_PropertyProperty( + 0: PropertyItem( name: VarLikeIdentifier( name: prop ) default: null ) ) + hooks: array( + ) ) ) ) @@ -215,9 +202,7 @@ array( attrs: array( 0: Attribute( name: Name( - parts: array( - 0: A8 - ) + name: A8 ) args: array( ) @@ -239,9 +224,7 @@ array( attrs: array( 0: Attribute( name: Name( - parts: array( - 0: A9 - ) + name: A9 ) args: array( ) @@ -266,9 +249,7 @@ array( attrs: array( 0: Attribute( name: Name( - parts: array( - 0: A10 - ) + name: A10 ) args: array( ) @@ -299,9 +280,7 @@ array( attrs: array( 0: Attribute( name: Name( - parts: array( - 0: A11 - ) + name: A11 ) args: array( ) @@ -314,7 +293,7 @@ array( params: array( ) returnType: null - expr: Scalar_LNumber( + expr: Scalar_Int( value: 0 ) ) @@ -331,9 +310,7 @@ array( attrs: array( 0: Attribute( name: Name( - parts: array( - 0: A12 - ) + name: A12 ) args: array( ) @@ -364,9 +341,7 @@ array( attrs: array( 0: Attribute( name: Name( - parts: array( - 0: A13 - ) + name: A13 ) args: array( ) @@ -379,10 +354,10 @@ array( params: array( ) returnType: null - expr: Scalar_LNumber( + expr: Scalar_Int( value: 0 ) ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/stmt/blocklessStatement.test b/test/code/parser/stmt/blocklessStatement.test index abf586465b..79b62d81c7 100644 --- a/test/code/parser/stmt/blocklessStatement.test +++ b/test/code/parser/stmt/blocklessStatement.test @@ -110,7 +110,7 @@ array( ) 5: Stmt_Declare( declares: array( - 0: Stmt_DeclareDeclare( + 0: DeclareItem( key: Identifier( name: a ) @@ -127,4 +127,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/stmt/class/abstract.test b/test/code/parser/stmt/class/abstract.test index 8635be6000..8b81fd95d9 100644 --- a/test/code/parser/stmt/class/abstract.test +++ b/test/code/parser/stmt/class/abstract.test @@ -11,7 +11,7 @@ array( 0: Stmt_Class( attrGroups: array( ) - flags: MODIFIER_ABSTRACT (16) + flags: ABSTRACT (16) name: Identifier( name: A ) @@ -22,7 +22,7 @@ array( 0: Stmt_ClassMethod( attrGroups: array( ) - flags: MODIFIER_PUBLIC (1) + flags: PUBLIC (1) byRef: false name: Identifier( name: a @@ -36,7 +36,7 @@ array( 1: Stmt_ClassMethod( attrGroups: array( ) - flags: MODIFIER_PUBLIC | MODIFIER_ABSTRACT (17) + flags: PUBLIC | ABSTRACT (17) byRef: false name: Identifier( name: b @@ -48,4 +48,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/stmt/class/anonymous.test b/test/code/parser/stmt/class/anonymous.test index 923fce8400..6ac4c8a178 100644 --- a/test/code/parser/stmt/class/anonymous.test +++ b/test/code/parser/stmt/class/anonymous.test @@ -36,7 +36,7 @@ array( 0: Stmt_ClassMethod( attrGroups: array( ) - flags: MODIFIER_PUBLIC (1) + flags: PUBLIC (1) byRef: false name: Identifier( name: test @@ -61,20 +61,14 @@ array( flags: 0 name: null extends: Name( - parts: array( - 0: A - ) + name: A ) implements: array( 0: Name( - parts: array( - 0: B - ) + name: B ) 1: Name( - parts: array( - 0: C - ) + name: C ) ) stmts: array( @@ -98,16 +92,18 @@ array( 0: Stmt_Property( attrGroups: array( ) - flags: MODIFIER_PUBLIC (1) + flags: PUBLIC (1) type: null props: array( - 0: Stmt_PropertyProperty( + 0: PropertyItem( name: VarLikeIdentifier( name: foo ) default: null ) ) + hooks: array( + ) ) ) ) @@ -123,9 +119,7 @@ array( flags: 0 name: null extends: Name( - parts: array( - 0: A - ) + name: A ) implements: array( ) @@ -133,9 +127,7 @@ array( 0: Stmt_TraitUse( traits: array( 0: Name( - parts: array( - 0: T - ) + name: T ) ) adaptations: array( @@ -177,7 +169,7 @@ array( 0: Stmt_ClassMethod( attrGroups: array( ) - flags: MODIFIER_PUBLIC (1) + flags: PUBLIC (1) byRef: false name: Identifier( name: test @@ -194,9 +186,7 @@ array( flags: 0 name: null extends: Name( - parts: array( - 0: A - ) + name: A ) implements: array( ) @@ -205,6 +195,7 @@ array( attrGroups: array( ) flags: 0 + type: null consts: array( 0: Const( name: Identifier( @@ -234,4 +225,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/stmt/class/asymmetric_visibility.test b/test/code/parser/stmt/class/asymmetric_visibility.test new file mode 100644 index 0000000000..0877f1bfcd --- /dev/null +++ b/test/code/parser/stmt/class/asymmetric_visibility.test @@ -0,0 +1,191 @@ +Asymmetric visibility modifiers +----- + 42; + set => $value; + } + abstract $prop3 { + &get; + set; + } + public $prop4 { + final get { return 42; } + set(string $value) { } + } +} +----- +array( + 0: Stmt_Class( + attrGroups: array( + ) + flags: 0 + name: Identifier( + name: Test + ) + extends: null + implements: array( + ) + stmts: array( + 0: Stmt_Property( + attrGroups: array( + ) + flags: PUBLIC (1) + type: null + props: array( + 0: PropertyItem( + name: VarLikeIdentifier( + name: prop + ) + default: null + ) + ) + hooks: array( + 0: PropertyHook( + attrGroups: array( + ) + flags: 0 + byRef: false + name: Identifier( + name: get + ) + params: array( + ) + body: array( + 0: Stmt_Return( + expr: Scalar_Int( + value: 42 + ) + ) + ) + ) + 1: PropertyHook( + attrGroups: array( + ) + flags: 0 + byRef: false + name: Identifier( + name: set + ) + params: array( + ) + body: array( + 0: Stmt_Echo( + exprs: array( + 0: Expr_Variable( + name: value + ) + ) + ) + ) + ) + ) + ) + 1: Stmt_Property( + attrGroups: array( + ) + flags: PRIVATE (4) + type: null + props: array( + 0: PropertyItem( + name: VarLikeIdentifier( + name: prop2 + ) + default: null + ) + ) + hooks: array( + 0: PropertyHook( + attrGroups: array( + ) + flags: 0 + byRef: false + name: Identifier( + name: get + ) + params: array( + ) + body: Scalar_Int( + value: 42 + ) + ) + 1: PropertyHook( + attrGroups: array( + ) + flags: 0 + byRef: false + name: Identifier( + name: set + ) + params: array( + ) + body: Expr_Variable( + name: value + ) + ) + ) + ) + 2: Stmt_Property( + attrGroups: array( + ) + flags: ABSTRACT (16) + type: null + props: array( + 0: PropertyItem( + name: VarLikeIdentifier( + name: prop3 + ) + default: null + ) + ) + hooks: array( + 0: PropertyHook( + attrGroups: array( + ) + flags: 0 + byRef: true + name: Identifier( + name: get + ) + params: array( + ) + body: null + ) + 1: PropertyHook( + attrGroups: array( + ) + flags: 0 + byRef: false + name: Identifier( + name: set + ) + params: array( + ) + body: null + ) + ) + ) + 3: Stmt_Property( + attrGroups: array( + ) + flags: PUBLIC (1) + type: null + props: array( + 0: PropertyItem( + name: VarLikeIdentifier( + name: prop4 + ) + default: null + ) + ) + hooks: array( + 0: PropertyHook( + attrGroups: array( + ) + flags: FINAL (32) + byRef: false + name: Identifier( + name: get + ) + params: array( + ) + body: array( + 0: Stmt_Return( + expr: Scalar_Int( + value: 42 + ) + ) + ) + ) + 1: PropertyHook( + attrGroups: array( + ) + flags: 0 + byRef: false + name: Identifier( + name: set + ) + params: array( + 0: Param( + attrGroups: array( + ) + flags: 0 + type: Identifier( + name: string + ) + byRef: false + variadic: false + var: Expr_Variable( + name: value + ) + default: null + hooks: array( + ) + ) + ) + body: array( + ) + ) + ) + ) + ) + ) +) +----- + 42; + } +} +----- +get hook must not have a parameter list from 4:12 to 4:12 +array( + 0: Stmt_Class( + attrGroups: array( + ) + flags: 0 + name: Identifier( + name: Test + ) + extends: null + implements: array( + ) + stmts: array( + 0: Stmt_Property( + attrGroups: array( + ) + flags: PUBLIC (1) + type: null + props: array( + 0: PropertyItem( + name: VarLikeIdentifier( + name: prop + ) + default: null + ) + ) + hooks: array( + 0: PropertyHook( + attrGroups: array( + ) + flags: 0 + byRef: false + name: Identifier( + name: get + ) + params: array( + ) + body: Scalar_Int( + value: 42 + ) + ) + ) + ) + ) + ) +) +----- + bar; } +} +----- +Unknown hook "FOO", expected "get" or "set" from 3:20 to 3:22 +array( + 0: Stmt_Class( + attrGroups: array( + ) + flags: 0 + name: Identifier( + name: Test + ) + extends: null + implements: array( + ) + stmts: array( + 0: Stmt_Property( + attrGroups: array( + ) + flags: PUBLIC (1) + type: null + props: array( + 0: PropertyItem( + name: VarLikeIdentifier( + name: prop + ) + default: null + ) + ) + hooks: array( + 0: PropertyHook( + attrGroups: array( + ) + flags: 0 + byRef: false + name: Identifier( + name: FOO + ) + params: array( + ) + body: Expr_ConstFetch( + name: Name( + name: bar + ) + ) + ) + ) + ) + ) + ) +) +----- + $value; }, + public $g = 1 { get => 2; }, + final $i, ) {} } ----- -!!php7 array( 0: Stmt_Class( attrGroups: array( @@ -26,7 +29,7 @@ array( 0: Stmt_ClassMethod( attrGroups: array( ) - flags: MODIFIER_PUBLIC (1) + flags: PUBLIC (1) byRef: false name: Identifier( name: __construct @@ -35,7 +38,7 @@ array( 0: Param( attrGroups: array( ) - flags: MODIFIER_PUBLIC (1) + flags: PUBLIC (1) type: Identifier( name: float ) @@ -44,14 +47,16 @@ array( var: Expr_Variable( name: x ) - default: Scalar_DNumber( + default: Scalar_Float( value: 0 ) + hooks: array( + ) ) 1: Param( attrGroups: array( ) - flags: MODIFIER_PROTECTED (2) + flags: PROTECTED (2) type: Identifier( name: array ) @@ -64,11 +69,13 @@ array( items: array( ) ) + hooks: array( + ) ) 2: Param( attrGroups: array( ) - flags: MODIFIER_PRIVATE (4) + flags: PRIVATE (4) type: Identifier( name: string ) @@ -80,6 +87,98 @@ array( default: Scalar_String( value: hello ) + hooks: array( + ) + ) + 3: Param( + attrGroups: array( + ) + flags: PUBLIC | READONLY (65) + type: Identifier( + name: int + ) + byRef: false + variadic: false + var: Expr_Variable( + name: a + ) + default: Scalar_Int( + value: 0 + ) + hooks: array( + ) + ) + 4: Param( + attrGroups: array( + ) + flags: PUBLIC (1) + type: null + byRef: false + variadic: false + var: Expr_Variable( + name: h + ) + default: null + hooks: array( + 0: PropertyHook( + attrGroups: array( + ) + flags: 0 + byRef: false + name: Identifier( + name: set + ) + params: array( + ) + body: Expr_Variable( + name: value + ) + ) + ) + ) + 5: Param( + attrGroups: array( + ) + flags: PUBLIC (1) + type: null + byRef: false + variadic: false + var: Expr_Variable( + name: g + ) + default: Scalar_Int( + value: 1 + ) + hooks: array( + 0: PropertyHook( + attrGroups: array( + ) + flags: 0 + byRef: false + name: Identifier( + name: get + ) + params: array( + ) + body: Scalar_Int( + value: 2 + ) + ) + ) + ) + 6: Param( + attrGroups: array( + ) + flags: FINAL (32) + type: null + byRef: false + variadic: false + var: Expr_Variable( + name: i + ) + default: null + hooks: array( + ) ) ) returnType: null @@ -88,4 +187,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/stmt/class/readonly.test b/test/code/parser/stmt/class/readonly.test new file mode 100644 index 0000000000..fb2131e683 --- /dev/null +++ b/test/code/parser/stmt/class/readonly.test @@ -0,0 +1,43 @@ +Readonly class +----- + $foo, "bar" => $bar ]); +clone($x, $array); +clone($x, $array, $extraParameter, $trailingComma, ); +clone(object: $x, withProperties: [ "foo" => $foo, "bar" => $bar ]); +clone($x, withProperties: [ "foo" => $foo, "bar" => $bar ]); +clone(object: $x); +clone(object: $x, [ "foo" => $foo, "bar" => $bar ]); +clone(...["object" => $x, "withProperties" => [ "foo" => $foo, "bar" => $bar ]]); +clone(...); +----- +array( + 0: Stmt_Function( + attrGroups: array( + ) + byRef: false + name: Identifier( + name: clone + ) + params: array( + 0: Param( + attrGroups: array( + ) + flags: 0 + type: Identifier( + name: object + ) + byRef: false + variadic: false + var: Expr_Variable( + name: object + ) + default: null + hooks: array( + ) + ) + 1: Param( + attrGroups: array( + ) + flags: 0 + type: Identifier( + name: array + ) + byRef: false + variadic: false + var: Expr_Variable( + name: withProperties + ) + default: Expr_Array( + items: array( + ) + ) + hooks: array( + ) + ) + ) + returnType: Identifier( + name: object + ) + stmts: array( + ) + ) + 1: Stmt_Expression( + expr: Expr_Clone( + expr: Expr_Variable( + name: x + ) + ) + ) + 2: Stmt_Expression( + expr: Expr_Clone( + expr: Expr_Variable( + name: x + ) + ) + ) + 3: Stmt_Expression( + expr: Expr_FuncCall( + name: Name( + name: clone + ) + args: array( + 0: Arg( + name: null + value: Expr_Variable( + name: x + ) + byRef: false + unpack: false + ) + ) + ) + ) + 4: Stmt_Expression( + expr: Expr_FuncCall( + name: Name( + name: clone + ) + args: array( + 0: Arg( + name: null + value: Expr_Variable( + name: x + ) + byRef: false + unpack: false + ) + 1: Arg( + name: null + value: Expr_Array( + items: array( + 0: ArrayItem( + key: Scalar_String( + value: foo + ) + value: Expr_Variable( + name: foo + ) + byRef: false + unpack: false + ) + 1: ArrayItem( + key: Scalar_String( + value: bar + ) + value: Expr_Variable( + name: bar + ) + byRef: false + unpack: false + ) + ) + ) + byRef: false + unpack: false + ) + ) + ) + ) + 5: Stmt_Expression( + expr: Expr_FuncCall( + name: Name( + name: clone + ) + args: array( + 0: Arg( + name: null + value: Expr_Variable( + name: x + ) + byRef: false + unpack: false + ) + 1: Arg( + name: null + value: Expr_Variable( + name: array + ) + byRef: false + unpack: false + ) + ) + ) + ) + 6: Stmt_Expression( + expr: Expr_FuncCall( + name: Name( + name: clone + ) + args: array( + 0: Arg( + name: null + value: Expr_Variable( + name: x + ) + byRef: false + unpack: false + ) + 1: Arg( + name: null + value: Expr_Variable( + name: array + ) + byRef: false + unpack: false + ) + 2: Arg( + name: null + value: Expr_Variable( + name: extraParameter + ) + byRef: false + unpack: false + ) + 3: Arg( + name: null + value: Expr_Variable( + name: trailingComma + ) + byRef: false + unpack: false + ) + ) + ) + ) + 7: Stmt_Expression( + expr: Expr_FuncCall( + name: Name( + name: clone + ) + args: array( + 0: Arg( + name: Identifier( + name: object + ) + value: Expr_Variable( + name: x + ) + byRef: false + unpack: false + ) + 1: Arg( + name: Identifier( + name: withProperties + ) + value: Expr_Array( + items: array( + 0: ArrayItem( + key: Scalar_String( + value: foo + ) + value: Expr_Variable( + name: foo + ) + byRef: false + unpack: false + ) + 1: ArrayItem( + key: Scalar_String( + value: bar + ) + value: Expr_Variable( + name: bar + ) + byRef: false + unpack: false + ) + ) + ) + byRef: false + unpack: false + ) + ) + ) + ) + 8: Stmt_Expression( + expr: Expr_FuncCall( + name: Name( + name: clone + ) + args: array( + 0: Arg( + name: null + value: Expr_Variable( + name: x + ) + byRef: false + unpack: false + ) + 1: Arg( + name: Identifier( + name: withProperties + ) + value: Expr_Array( + items: array( + 0: ArrayItem( + key: Scalar_String( + value: foo + ) + value: Expr_Variable( + name: foo + ) + byRef: false + unpack: false + ) + 1: ArrayItem( + key: Scalar_String( + value: bar + ) + value: Expr_Variable( + name: bar + ) + byRef: false + unpack: false + ) + ) + ) + byRef: false + unpack: false + ) + ) + ) + ) + 9: Stmt_Expression( + expr: Expr_FuncCall( + name: Name( + name: clone + ) + args: array( + 0: Arg( + name: Identifier( + name: object + ) + value: Expr_Variable( + name: x + ) + byRef: false + unpack: false + ) + ) + ) + ) + 10: Stmt_Expression( + expr: Expr_FuncCall( + name: Name( + name: clone + ) + args: array( + 0: Arg( + name: Identifier( + name: object + ) + value: Expr_Variable( + name: x + ) + byRef: false + unpack: false + ) + 1: Arg( + name: null + value: Expr_Array( + items: array( + 0: ArrayItem( + key: Scalar_String( + value: foo + ) + value: Expr_Variable( + name: foo + ) + byRef: false + unpack: false + ) + 1: ArrayItem( + key: Scalar_String( + value: bar + ) + value: Expr_Variable( + name: bar + ) + byRef: false + unpack: false + ) + ) + ) + byRef: false + unpack: false + ) + ) + ) + ) + 11: Stmt_Expression( + expr: Expr_FuncCall( + name: Name( + name: clone + ) + args: array( + 0: Arg( + name: null + value: Expr_Array( + items: array( + 0: ArrayItem( + key: Scalar_String( + value: object + ) + value: Expr_Variable( + name: x + ) + byRef: false + unpack: false + ) + 1: ArrayItem( + key: Scalar_String( + value: withProperties + ) + value: Expr_Array( + items: array( + 0: ArrayItem( + key: Scalar_String( + value: foo + ) + value: Expr_Variable( + name: foo + ) + byRef: false + unpack: false + ) + 1: ArrayItem( + key: Scalar_String( + value: bar + ) + value: Expr_Variable( + name: bar + ) + byRef: false + unpack: false + ) + ) + ) + byRef: false + unpack: false + ) + ) + ) + byRef: false + unpack: true + ) + ) + ) + ) + 12: Stmt_Expression( + expr: Expr_FuncCall( + name: Name( + name: clone + ) + args: array( + 0: VariadicPlaceholder( + ) + ) + ) + ) +) diff --git a/test/code/parser/stmt/function/conditional.test b/test/code/parser/stmt/function/conditional.test index 42f5fa203b..50861ed564 100644 --- a/test/code/parser/stmt/function/conditional.test +++ b/test/code/parser/stmt/function/conditional.test @@ -10,9 +10,7 @@ array( 0: Stmt_If( cond: Expr_ConstFetch( name: Name( - parts: array( - 0: true - ) + name: true ) ) stmts: array( @@ -34,4 +32,4 @@ array( ) else: null ) -) \ No newline at end of file +) diff --git a/test/code/parser/stmt/function/defaultValues.test b/test/code/parser/stmt/function/defaultValues.test index 3db4208be0..9a243f70df 100644 --- a/test/code/parser/stmt/function/defaultValues.test +++ b/test/code/parser/stmt/function/defaultValues.test @@ -35,11 +35,11 @@ array( ) default: Expr_ConstFetch( name: Name( - parts: array( - 0: null - ) + name: null ) ) + hooks: array( + ) ) 1: Param( attrGroups: array( @@ -54,6 +54,8 @@ array( default: Scalar_String( value: foo ) + hooks: array( + ) ) 2: Param( attrGroups: array( @@ -67,14 +69,14 @@ array( ) default: Expr_ClassConstFetch( class: Name( - parts: array( - 0: A - ) + name: A ) name: Identifier( name: B ) ) + hooks: array( + ) ) 3: Param( attrGroups: array( @@ -87,10 +89,12 @@ array( name: f ) default: Expr_UnaryPlus( - expr: Scalar_LNumber( + expr: Scalar_Int( value: 1 ) ) + hooks: array( + ) ) 4: Param( attrGroups: array( @@ -103,10 +107,12 @@ array( name: g ) default: Expr_UnaryMinus( - expr: Scalar_DNumber( + expr: Scalar_Float( value: 1 ) ) + hooks: array( + ) ) 5: Param( attrGroups: array( @@ -122,6 +128,8 @@ array( items: array( ) ) + hooks: array( + ) ) 6: Param( attrGroups: array( @@ -137,6 +145,8 @@ array( items: array( ) ) + hooks: array( + ) ) 7: Param( attrGroups: array( @@ -150,7 +160,7 @@ array( ) default: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Scalar_String( value: foo @@ -160,6 +170,8 @@ array( ) ) ) + hooks: array( + ) ) 8: Param( attrGroups: array( @@ -173,7 +185,7 @@ array( ) default: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Scalar_String( value: foo @@ -181,7 +193,7 @@ array( byRef: false unpack: false ) - 1: Expr_ArrayItem( + 1: ArrayItem( key: Scalar_String( value: bar ) @@ -193,10 +205,12 @@ array( ) ) ) + hooks: array( + ) ) ) returnType: null stmts: array( ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/stmt/function/disjointNormalFormTypes.test b/test/code/parser/stmt/function/disjointNormalFormTypes.test new file mode 100644 index 0000000000..f515f96875 --- /dev/null +++ b/test/code/parser/stmt/function/disjointNormalFormTypes.test @@ -0,0 +1,170 @@ +DNF types +----- + $bar; ----- -!!php7 array( 0: Stmt_Expression( expr: Expr_ArrowFunction( @@ -121,6 +124,8 @@ array( name: foo ) default: null + hooks: array( + ) ) ) returnType: null @@ -129,4 +134,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/stmt/function/readonlyFunction.test b/test/code/parser/stmt/function/readonlyFunction.test new file mode 100644 index 0000000000..0ce05d7441 --- /dev/null +++ b/test/code/parser/stmt/function/readonlyFunction.test @@ -0,0 +1,30 @@ +readonly function +----- + (yield "k2") => "a" . "b"]); } ----- -!!php7 array( 0: Stmt_Function( attrGroups: array( @@ -86,16 +85,14 @@ array( 4: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: var_dump - ) + name: var_dump ) args: array( 0: Arg( name: null value: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Expr_Yield( key: Scalar_String( @@ -170,16 +167,14 @@ array( 7: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: var_dump - ) + name: var_dump ) args: array( 0: Arg( name: null value: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: null value: Expr_Yield( key: Scalar_String( @@ -213,16 +208,14 @@ array( 8: Stmt_Expression( expr: Expr_FuncCall( name: Name( - parts: array( - 0: var_dump - ) + name: var_dump ) args: array( 0: Arg( name: null value: Expr_Array( items: array( - 0: Expr_ArrayItem( + 0: ArrayItem( key: Expr_Yield( key: Scalar_String( value: k1 @@ -255,4 +248,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/stmt/generator/yieldUnaryPrecedence.test b/test/code/parser/stmt/generator/yieldUnaryPrecedence.test index ed78bca51e..172984f395 100644 --- a/test/code/parser/stmt/generator/yieldUnaryPrecedence.test +++ b/test/code/parser/stmt/generator/yieldUnaryPrecedence.test @@ -24,7 +24,7 @@ array( expr: Expr_Yield( key: null value: Expr_UnaryPlus( - expr: Scalar_LNumber( + expr: Scalar_Int( value: 1 ) ) @@ -34,7 +34,7 @@ array( expr: Expr_Yield( key: null value: Expr_UnaryMinus( - expr: Scalar_LNumber( + expr: Scalar_Int( value: 1 ) ) @@ -47,7 +47,7 @@ array( value: null ) right: Expr_UnaryMinus( - expr: Scalar_LNumber( + expr: Scalar_Int( value: 1 ) ) @@ -55,4 +55,4 @@ array( ) ) ) -) \ No newline at end of file +) diff --git a/test/code/parser/stmt/haltCompiler.test b/test/code/parser/stmt/haltCompiler.test index 112946ea7c..995e760597 100644 --- a/test/code/parser/stmt/haltCompiler.test +++ b/test/code/parser/stmt/haltCompiler.test @@ -43,9 +43,7 @@ __halt_compiler(); array( 0: Stmt_Namespace( name: Name( - parts: array( - 0: A - ) + name: A ) stmts: array( 0: Stmt_Expression( @@ -58,4 +56,4 @@ array( 1: Stmt_HaltCompiler( remaining: ) -) \ No newline at end of file +) diff --git a/test/code/parser/stmt/haltCompilerInvalidSyntax.test b/test/code/parser/stmt/haltCompilerInvalidSyntax.test index 381019a9bf..9b121ecbcc 100644 --- a/test/code/parser/stmt/haltCompilerInvalidSyntax.test +++ b/test/code/parser/stmt/haltCompilerInvalidSyntax.test @@ -3,4 +3,6 @@ Invalid __halt_compiler() syntax a = $a; } }; +new readonly class {}; ----- new class { @@ -25,3 +26,6 @@ new class($a) extends A $this->a = $a; } }; +new readonly class +{ +}; diff --git a/test/code/prettyPrinter/expr/arrayDestructuring.test b/test/code/prettyPrinter/expr/arrayDestructuring.test index bff1999e4e..56d23bb65c 100644 --- a/test/code/prettyPrinter/expr/arrayDestructuring.test +++ b/test/code/prettyPrinter/expr/arrayDestructuring.test @@ -7,7 +7,6 @@ Array destructuring [, [[$a]], $b] = $bar; ['a' => $b, 'b' => $a] = $baz; ----- -!!php7 [$a, $b] = [$c, $d]; [, $a, , , $b, ] = $foo; [, [[$a]], $b] = $bar; diff --git a/test/code/prettyPrinter/expr/arraySpread.test b/test/code/prettyPrinter/expr/arraySpread.test index 5e8393ff27..a3a1c121c8 100644 --- a/test/code/prettyPrinter/expr/arraySpread.test +++ b/test/code/prettyPrinter/expr/arraySpread.test @@ -4,5 +4,4 @@ Array spread [$a, $b] = [...$c, ...$d]; ----- -!!php7 [$a, $b] = [...$c, ...$d]; diff --git a/test/code/prettyPrinter/expr/arrow_function.test b/test/code/prettyPrinter/expr/arrow_function.test index fe8d8791b5..8b2656158a 100644 --- a/test/code/prettyPrinter/expr/arrow_function.test +++ b/test/code/prettyPrinter/expr/arrow_function.test @@ -8,11 +8,14 @@ fn(&$x) => $x; fn&($x) => $x; static fn($x, ...$rest) => $rest; fn(): int => $x; +fn($a, $b) => $a and $b; +fn($a, $b) => $a && $b; ----- -!!php7 fn($a) => $a; fn($x = 42) => $x; fn(&$x) => $x; fn&($x) => $x; static fn($x, ...$rest) => $rest; fn(): int => $x; +fn($a, $b) => $a and $b; +fn($a, $b) => $a && $b; \ No newline at end of file diff --git a/test/code/prettyPrinter/expr/cast.test b/test/code/prettyPrinter/expr/cast.test new file mode 100644 index 0000000000..b52d056a24 --- /dev/null +++ b/test/code/prettyPrinter/expr/cast.test @@ -0,0 +1,17 @@ +Casts +----- +foo(...); +A::foo(...); +----- +foo(...); +$this->foo(...); +A::foo(...); \ No newline at end of file diff --git a/test/code/prettyPrinter/expr/include.test b/test/code/prettyPrinter/expr/include.test index 3c40779876..ef8c9911ef 100644 --- a/test/code/prettyPrinter/expr/include.test +++ b/test/code/prettyPrinter/expr/include.test @@ -4,4 +4,4 @@ Include (include $foo) && (include $bar); ----- -(include $foo) && (include $bar); \ No newline at end of file +(include $foo) && include $bar; diff --git a/test/code/prettyPrinter/expr/literals.test b/test/code/prettyPrinter/expr/literals.test index f649b5d0cc..b5968a05ee 100644 --- a/test/code/prettyPrinter/expr/literals.test +++ b/test/code/prettyPrinter/expr/literals.test @@ -11,6 +11,7 @@ __CLASS__; __TRAIT__; __METHOD__; __NAMESPACE__; +__PROPERTY__; // not actually literals, but close null; @@ -47,6 +48,8 @@ b'; 'a\'b'; 'a\b'; 'a\\'; +'a\\\\b'; +'a\\\'b'; // strings (double quoted) "a"; @@ -92,6 +95,7 @@ __CLASS__; __TRAIT__; __METHOD__; __NAMESPACE__; +__PROPERTY__; // not actually literals, but close null; true; @@ -112,7 +116,7 @@ FALSE; 0.0; 1.0; 1.0E+100; -\INF; +1.0E+1000; 1.0E-100; 1.0E+84; 378282246310005.0; @@ -122,8 +126,10 @@ FALSE; 'a b'; 'a\'b'; -'a\\b'; +'a\b'; 'a\\'; +'a\\\\b'; +'a\\\'b'; // strings (double quoted) "a"; "a\nb"; @@ -155,4 +161,4 @@ b'; `foo`; `foo{$a}`; `foo{$a}bar`; -`\`\\'\\"`; \ No newline at end of file +`\`\\'\\"`; diff --git a/test/code/prettyPrinter/expr/match.test b/test/code/prettyPrinter/expr/match.test index f5f87a110f..0583d2356f 100644 --- a/test/code/prettyPrinter/expr/match.test +++ b/test/code/prettyPrinter/expr/match.test @@ -9,7 +9,6 @@ echo match (1) { default => 'Foo', }; ----- -!!php7 echo match (1) { 0, 1 => 'Foo', // Comment diff --git a/test/code/prettyPrinter/expr/namedArgs.test b/test/code/prettyPrinter/expr/namedArgs.test index 2e20d9b5c4..a2a021d4f1 100644 --- a/test/code/prettyPrinter/expr/namedArgs.test +++ b/test/code/prettyPrinter/expr/namedArgs.test @@ -4,6 +4,5 @@ Named arguments foo(a: $b, c: $d); bar(class: 0); ----- -!!php7 foo(a: $b, c: $d); bar(class: 0); \ No newline at end of file diff --git a/test/code/prettyPrinter/expr/newVariable.test b/test/code/prettyPrinter/expr/newVariable.test index d5283b3316..dae95d6854 100644 --- a/test/code/prettyPrinter/expr/newVariable.test +++ b/test/code/prettyPrinter/expr/newVariable.test @@ -2,10 +2,21 @@ Parentheses for complex new/instanceof expressions ----- y); +new ((x)::$y); $x instanceof ('a' . 'b'); $x instanceof ($y++); ----- -!!php7 new ('a' . 'b')(); +new (x)(); +new (foo())(); +new ('foo')(); +new (x[0])(); +new (x->y)(); +new ((x)::$y)(); $x instanceof ('a' . 'b'); -$x instanceof ($y++); \ No newline at end of file +$x instanceof ($y++); diff --git a/test/code/prettyPrinter/expr/nullsafe.test b/test/code/prettyPrinter/expr/nullsafe.test index de9adc9884..4487479b37 100644 --- a/test/code/prettyPrinter/expr/nullsafe.test +++ b/test/code/prettyPrinter/expr/nullsafe.test @@ -11,7 +11,6 @@ new $a?->b; "{$a?->b}"; "$a?->b"; ----- -!!php7 $a?->b; $a?->b($c); $a?->b?->c; diff --git a/test/code/prettyPrinter/expr/numbers.test b/test/code/prettyPrinter/expr/numbers.test index c85f36bd82..09ecf7d5a3 100644 --- a/test/code/prettyPrinter/expr/numbers.test +++ b/test/code/prettyPrinter/expr/numbers.test @@ -31,5 +31,5 @@ Number literals -42.5; 1.0E+42; -1.0E+42; -\INF; --\INF; \ No newline at end of file +1.0E+1000; +-1.0E+1000; diff --git a/test/code/prettyPrinter/expr/parentheses.test b/test/code/prettyPrinter/expr/parentheses.test index bda956e3d5..9674858abd 100644 --- a/test/code/prettyPrinter/expr/parentheses.test +++ b/test/code/prettyPrinter/expr/parentheses.test @@ -5,7 +5,7 @@ Pretty printer generates least-parentheses output echo 'abc' . 'cde' . 'fgh'; echo 'abc' . ('cde' . 'fgh'); -echo 'abc' . 1 + 2 . 'fgh'; +echo ('abc' . 1) + 2 . 'fgh'; echo 'abc' . (1 + 2) . 'fgh'; echo 1 * 2 + 3 / 4 % 5 . 6; @@ -19,6 +19,7 @@ $a = $b = $c = $d = ($f and true); $a ? $b : $c ? $d : $e ? $f : $g; $a ? $b : ($c ? $d : ($e ? $f : $g)); $a ? $b ? $c : $d : $f; +$a === $b ? $c : $d; $a ?? $b ?? $c; ($a ?? $b) ?? $c; @@ -37,17 +38,28 @@ yield from $a and yield from $b; yield from ($a and yield from $b); print ($a and print $b); +clone ($a + $b); +(throw $a) + $b; -(-$a); +(+$a); -(--$a); +(++$a); +-(--$a)**$b; ++(++$a)**$b; -// The following will currently add unnecessary parentheses, because the pretty printer is not aware that assignment -// and incdec only work on variables. !$a = $b; ++$a ** $b; $a ** $b++; +$a . ($b = $c) . $d; +!($a = $b) || $c; +(fn() => $a) || $b; +($a = $b and $c) + $d; +$a ** ($b instanceof $c); +($a = $b) instanceof $c; +[$a and $b => $c]; +// TODO: This prints redundant parentheses +[include $a => $c]; ----- echo 'abc' . 'cde' . 'fgh'; echo 'abc' . ('cde' . 'fgh'); @@ -62,6 +74,7 @@ $a = $b = $c = $d = ($f and true); (($a ? $b : $c) ? $d : $e) ? $f : $g; $a ? $b : ($c ? $d : ($e ? $f : $g)); $a ? $b ? $c : $d : $f; +$a === $b ? $c : $d; $a ?? $b ?? $c; ($a ?? $b) ?? $c; $a ?? ($b ? $c : $d); @@ -75,12 +88,23 @@ $a ** $b ** $c; yield from $a and yield from $b; yield from ($a and yield from $b); print ($a and print $b); +clone ($a + $b); +(throw $a) + $b; -(-$a); +(+$a); -(--$a); +(++$a); -// The following will currently add unnecessary parentheses, because the pretty printer is not aware that assignment -// and incdec only work on variables. -!($a = $b); -(++$a) ** $b; -$a ** ($b++); +-(--$a ** $b); ++(++$a ** $b); +!$a = $b; +++$a ** $b; +$a ** $b++; +$a . ($b = $c) . $d; +!($a = $b) || $c; +(fn() => $a) || $b; +($a = $b and $c) + $d; +$a ** ($b instanceof $c); +($a = $b) instanceof $c; +[$a and $b => $c]; +// TODO: This prints redundant parentheses +[(include $a) => $c]; diff --git a/test/code/prettyPrinter/expr/pipe.test b/test/code/prettyPrinter/expr/pipe.test new file mode 100644 index 0000000000..68b2195d36 --- /dev/null +++ b/test/code/prettyPrinter/expr/pipe.test @@ -0,0 +1,16 @@ +Pipe operator +----- + $b |> $c; +$a . $b |> $c . $d; +$a |> $b == $c; +$c == $a |> $b; +($a == $b) |> ($c == $d); +$a . ($b |> $c) . $d; +----- +$a |> $b |> $c; +$a . $b |> $c . $d; +$a |> $b == $c; +$c == $a |> $b; +($a == $b) |> ($c == $d); +$a . ($b |> $c) . $d; \ No newline at end of file diff --git a/test/code/prettyPrinter/expr/stringEscaping.test b/test/code/prettyPrinter/expr/stringEscaping.test index 5d114b814e..cd2e5b653c 100644 --- a/test/code/prettyPrinter/expr/stringEscaping.test +++ b/test/code/prettyPrinter/expr/stringEscaping.test @@ -5,6 +5,9 @@ Escape sequences in double-quoted strings "@@{ implode(range("\0", "\37")) }@@"; "\0000\0001"; "äöü"; +"\xc0\x80"; +"\xd0\x01"; +"\xf0\x80\x80"; <<b)(); (A::$b)(); ('a' . 'b')::X; +(A)::X; +(A)::$x; +(A)::x(); ----- -!!php7 (function () { })(); array('a', 'b')()(); @@ -22,4 +24,7 @@ $A::{$b[$c]}(); A::${$b}[$c](); ($a->b)(); (A::$b)(); -('a' . 'b')::X; \ No newline at end of file +('a' . 'b')::X; +(A)::X; +(A)::$x; +(A)::x(); diff --git a/test/code/prettyPrinter/expr/variables.test b/test/code/prettyPrinter/expr/variables.test index 4e0fa2e123..2b444b236c 100644 --- a/test/code/prettyPrinter/expr/variables.test +++ b/test/code/prettyPrinter/expr/variables.test @@ -35,9 +35,8 @@ $a::$b()[$c]; (new $$a)[$b]; (new $a->b)->c; -global $a, $$a, $$a[$b], $$a->b; +global $a, $$a; ----- -!!php5 $a; ${$a}; ${$a}; @@ -46,21 +45,21 @@ $a->b(); $a->b($c); $a->{$b}(); $a->{$b}(); -$a->{$b[$c]}(); +$a->{$b}[$c](); ${$a}->b; $a[$b]; $a[$b](); -${$a[$b]}; +${$a}[$b]; $a::B; $a::$b; $a::b(); $a::b($c); $a::$b(); $a::$b[$c]; -$a::{$b[$c]}($d); +$a::$b[$c]($d); $a::{$b[$c]}($d); $a::{$b->c}(); -A::${$b[$c]}(); +A::${$b}[$c](); a(); $a(); $a()[$b]; @@ -70,4 +69,4 @@ $a::$b()[$c]; (new A())->b(); (new ${$a}())[$b]; (new $a->b())->c; -global $a, ${$a}, ${$a[$b]}, ${$a->b}; +global $a, ${$a}; \ No newline at end of file diff --git a/test/code/prettyPrinter/expr/yield.test b/test/code/prettyPrinter/expr/yield.test index 12ab7dec1c..7a75891453 100644 --- a/test/code/prettyPrinter/expr/yield.test +++ b/test/code/prettyPrinter/expr/yield.test @@ -8,39 +8,99 @@ function gen() yield $a; yield $a => $b; $a = yield; - $a = (yield $b); - $a = (yield $b => $c); + $a = yield $b; + $a = yield $b => $c; + yield from $a; + $a = yield from $b; + (yield $a) + $b; + (yield from $a) + $b; + [yield $a => $b]; + [(yield $a) => $b]; + [$a + (yield $b) => $c]; + yield yield $a => $b; + yield (yield $a) => $b; + match ($x) { + yield $a, (yield $b) => $c, + }; + yield -$a; + (yield) - $a; + yield * $a; } -// TODO Get rid of parens for cases 2 and 3 ----- function gen() { yield; - (yield $a); - (yield $a => $b); + yield $a; + yield $a => $b; $a = yield; - $a = (yield $b); - $a = (yield $b => $c); + $a = yield $b; + $a = yield $b => $c; + yield from $a; + $a = yield from $b; + (yield $a) + $b; + (yield from $a) + $b; + [yield $a => $b]; + [(yield $a) => $b]; + [$a + (yield $b) => $c]; + yield yield $a => $b; + yield (yield $a) => $b; + match ($x) { + yield $a, (yield $b) => $c, + }; + yield -$a; + (yield) - $a; + (yield) * $a; } -// TODO Get rid of parens for cases 2 and 3 ----- $b; + $a = yield; $a = yield $b; $a = yield $b => $c; yield from $a; $a = yield from $b; + (yield $a) + $b; + (yield from $a) + $b; + [yield $a => $b]; + [(yield $a) => $b]; + [$a + (yield $b) => $c]; + yield yield $a => $b; + yield (yield $a) => $b; + match ($x) { + yield $a, (yield $b) => $c, + }; + yield -$a; + (yield) - $a; + yield * $a; } -// TODO Get rid of parens for last case ----- -!!php7 +!!version=5.6,parserVersion=8.0 function gen() { + yield; + (yield $a); + (yield $a => $b); + $a = yield; $a = (yield $b); $a = (yield $b => $c); yield from $a; - $a = (yield from $b); + $a = yield from $b; + (yield $a) + $b; + (yield from $a) + $b; + [(yield $a => $b)]; + [(yield $a) => $b]; + [$a + (yield $b) => $c]; + (yield (yield $a => $b)); + (yield (yield $a) => $b); + match ($x) { + (yield $a), (yield $b) => $c, + }; + (yield -$a); + (yield) - $a; + (yield) * $a; } -// TODO Get rid of parens for last case \ No newline at end of file diff --git a/test/code/prettyPrinter/indent.test b/test/code/prettyPrinter/indent.test new file mode 100644 index 0000000000..7edd101e10 --- /dev/null +++ b/test/code/prettyPrinter/indent.test @@ -0,0 +1,82 @@ +Indentation +----- +HTML ----- HTMLHTML \ No newline at end of file +?>HTML +----- +@@{ "\r\r\n" }@@Test +----- +@@{ "\n\n" }@@Test \ No newline at end of file diff --git a/test/code/prettyPrinter/stmt/asymmetric_visibility.test b/test/code/prettyPrinter/stmt/asymmetric_visibility.test new file mode 100644 index 0000000000..0e221b6cf6 --- /dev/null +++ b/test/code/prettyPrinter/stmt/asymmetric_visibility.test @@ -0,0 +1,25 @@ +Asymmetric visibility modifiers +----- + 0; new #[A13] class {}; ----- -!!php7 #[A1, A2, A3(0), A4(x: 1)] function a() { @@ -39,7 +38,10 @@ function a() class C { #[A6] - public function m(#[A7] $param) + public function m( + #[A7] + $param + ) { } #[A12] @@ -58,4 +60,12 @@ $x = #[A10] function () { $y = #[A11] fn() => 0; new #[A13] class { -}; \ No newline at end of file +}; +----- + 42; +----- +class Test +{ + function test( + // Comment + $param + ) + { + } +} +function test( + // Comment + $param +) +{ +} +function ( + // Comment + $param +) { +}; +fn( + // Comment + $param +) => 42; +----- + 42; +----- +!!version=8.0 +class Test +{ + function test( + // Comment + $param, + ) + { + } +} +function test( + // Comment + $param, +) +{ +} +function ( + // Comment + $param, +) { +}; +fn( + // Comment + $param, +) => 42; diff --git a/test/code/prettyPrinter/stmt/properties.test b/test/code/prettyPrinter/stmt/properties.test index 5a78ec4929..ee073df70d 100644 --- a/test/code/prettyPrinter/stmt/properties.test +++ b/test/code/prettyPrinter/stmt/properties.test @@ -8,13 +8,14 @@ class A public string $b; protected static ?float $c = 5.0; private static ?self $d; + public readonly int|float $e; } ----- -!!php7 class A { public $a; public string $b; protected static ?float $c = 5.0; private static ?self $d; + public readonly int|float $e; } diff --git a/test/code/prettyPrinter/stmt/property_hooks.test b/test/code/prettyPrinter/stmt/property_hooks.test new file mode 100644 index 0000000000..9f39c61ff0 --- /dev/null +++ b/test/code/prettyPrinter/stmt/property_hooks.test @@ -0,0 +1,59 @@ +Property hooks +----- +prop + 1; + } + set { + $this->prop = $value - 1; + } + } + public $prop = 1 { + #[Attr] + &get => $this->prop; + final set($value) => $value - 1; + } + abstract public $prop { + get; + set; + } + + // TODO: Force multiline for hooks? + public function __construct( + public $foo { + get => 42; + set => 123; + }, + public $bar + ) {} +} +----- +class Test +{ + public int $prop { + get { + return $this->prop + 1; + } + set { + $this->prop = $value - 1; + } + } + public $prop = 1 { + #[Attr] + &get => $this->prop; + final set($value) => $value - 1; + } + abstract public $prop { + get; + set; + } + // TODO: Force multiline for hooks? + public function __construct(public $foo { + get => 42; + set => 123; + }, public $bar) + { + } +} diff --git a/test/code/prettyPrinter/stmt/property_promotion.test b/test/code/prettyPrinter/stmt/property_promotion.test index 036cf5e3b0..03a5f856bb 100644 --- a/test/code/prettyPrinter/stmt/property_promotion.test +++ b/test/code/prettyPrinter/stmt/property_promotion.test @@ -8,14 +8,15 @@ class Point public float $x = 0.0, protected array $y = [], private string $z = 'hello', + public readonly int $a = 0, + protected final bool $b = true, ) { } } ----- -!!php7 class Point { - public function __construct(public float $x = 0.0, protected array $y = [], private string $z = 'hello') + public function __construct(public float $x = 0.0, protected array $y = [], private string $z = 'hello', public readonly int $a = 0, final protected bool $b = true) { } } @@ -34,7 +35,6 @@ class Test } } ----- -!!php7 class Test { public $z; diff --git a/test/code/prettyPrinter/stmt/readonly_class.test b/test/code/prettyPrinter/stmt/readonly_class.test new file mode 100644 index 0000000000..8768ae73cd --- /dev/null +++ b/test/code/prettyPrinter/stmt/readonly_class.test @@ -0,0 +1,11 @@ +Readonly class +----- + $code) { if (false !== strpos($code, '@@{')) { // Skip tests with evaluate segments @@ -19,11 +19,9 @@ list($name, $tests) = $testParser->parseTest($code, 2); $newTests = []; foreach ($tests as list($modeLine, list($input, $expected))) { - $modes = null !== $modeLine ? array_fill_keys(explode(',', $modeLine), true) : []; - list($parser5, $parser7) = $codeParsingTest->createParsers($modes); - list(, $output) = isset($modes['php5']) - ? $codeParsingTest->getParseOutput($parser5, $input, $modes) - : $codeParsingTest->getParseOutput($parser7, $input, $modes); + $modes = $codeParsingTest->parseModeLine($modeLine); + $parser = $codeParsingTest->createParser($modes['version'] ?? null); + list(, $output) = $codeParsingTest->getParseOutput($parser, $input, $modes); $newTests[] = [$modeLine, [$input, $output]]; } diff --git a/test_old/run-php-src.sh b/test_old/run-php-src.sh index bc1a3d698e..16d89cc13d 100755 --- a/test_old/run-php-src.sh +++ b/test_old/run-php-src.sh @@ -1,5 +1,8 @@ VERSION=$1 -wget -q https://github.com/php/php-src/archive/php-$VERSION.tar.gz +if [[ ! -f php-$VERSION.tar.gz ]]; then + wget -q https://github.com/php/php-src/archive/php-$VERSION.tar.gz +fi +rm -rf ./data/php-src mkdir -p ./data/php-src tar -xzf ./php-$VERSION.tar.gz -C ./data/php-src --strip-components=1 php test_old/run.php --verbose --no-progress --php-version=$VERSION PHP ./data/php-src diff --git a/test_old/run.php b/test_old/run.php index 8dac907874..1f430b49e9 100644 --- a/test_old/run.php +++ b/test_old/run.php @@ -1,6 +1,6 @@ true, + '--verbose' => true, + '--php-version' => true, +]; + $options = array(); $arguments = array(); @@ -35,7 +41,11 @@ function showHelp($error) { foreach ($argv as $arg) { if ('-' === $arg[0]) { $parts = explode('=', $arg); - $options[$parts[0]] = $parts[1] ?? true; + $name = $parts[0]; + if (!isset($allowedOptions[$name])) { + showHelp("Unknown option \"$name\""); + } + $options[$name] = $parts[1] ?? true; } else { $arguments[] = $arg; } @@ -95,10 +105,6 @@ function showHelp($error) { | tests.run-test.bug75042-3 # contains invalid chars, which we treat as parse error | Zend.tests.warning_during_heredoc_scan_ahead -# pretty print difference due to INF vs 1e1000 -| ext.standard.tests.general_functions.bug27678 -| tests.lang.bug24640 -| Zend.tests.bug74947 # pretty print differences due to negative LNumbers | Zend.tests.neg_num_string | Zend.tests.numeric_strings.neg_num_string @@ -111,6 +117,12 @@ function showHelp($error) { # whitespace in namespaced name | Zend.tests.bug55086 | Zend.tests.grammar.regression_010 +# not worth emulating on old PHP versions +| Zend.tests.type_declarations.intersection_types.parsing_comment +# comments in property fetch syntax, not emulated on old PHP versions +| Zend.tests.gh14961 +# harmless pretty print difference for clone($x, ) +| Zend.tests.clone.ast )\.phpt$~x', $file)) { return null; } @@ -129,17 +141,7 @@ function showHelp($error) { showHelp('Test type must be one of: PHP or Symfony'); } -$lexer = new PhpParser\Lexer\Emulative([ - 'usedAttributes' => [ - 'comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos', - ], - 'phpVersion' => $phpVersion, -]); -if (version_compare($phpVersion, '7.0', '>=')) { - $parser = new PhpParser\Parser\Php7($lexer); -} else { - $parser = new PhpParser\Parser\Php5($lexer); -} +$parser = (new PhpParser\ParserFactory())->createForVersion(PhpParser\PhpVersion::fromString($phpVersion)); $prettyPrinter = new PhpParser\PrettyPrinter\Standard; $nodeDumper = new PhpParser\NodeDumper; @@ -181,7 +183,7 @@ function showHelp($error) { $origStmts = $parser->parse($origCode); $parseTime += microtime(true) - $startTime; - $origTokens = $lexer->getTokens(); + $origTokens = $parser->getTokens(); $startTime = microtime(true); $stmts = $cloningTraverser->traverse($origStmts); diff --git a/tools/composer.json b/tools/composer.json new file mode 100644 index 0000000000..b990d13f5b --- /dev/null +++ b/tools/composer.json @@ -0,0 +1,6 @@ +{ + "require": { + "friendsofphp/php-cs-fixer": "^3.10", + "phpstan/phpstan": "^2.0" + } +} diff --git a/tools/fuzzing/generateCorpus.php b/tools/fuzzing/generateCorpus.php new file mode 100644 index 0000000000..712e9177ea --- /dev/null +++ b/tools/fuzzing/generateCorpus.php @@ -0,0 +1,30 @@ + $code) { + list($_name, $tests) = $testParser->parseTest($code, 2); + foreach ($tests as list($_modeLine, list($input, $_expected))) { + $path = $corpusDir . '/' . md5($input) . '.txt'; + file_put_contents($path, $input); + } + } +} diff --git a/tools/fuzzing/php.dict b/tools/fuzzing/php.dict new file mode 100644 index 0000000000..e0889f98c1 --- /dev/null +++ b/tools/fuzzing/php.dict @@ -0,0 +1,89 @@ +"" +"__class__" +"__dir__" +"__file__" +"__function__" +"__halt_compiler" +"__line__" +"__method__" +"__namespace__" +"__trait__" +"abstract" +"array" +"as" +"binary" +"bool" +"boolean" +"break" +"callable" +"case" +"catch" +"class" +"clone" +"const" +"continue" +"declare" +"default" +"die" +"do" +"double" +"echo" +"else" +"elseif" +"empty" +"enddeclare" +"endfor" +"endforeach" +"endif" +"endswitch" +"endwhile" +"eval" +"exit" +"extends" +"final" +"finally" +"float" +"fn" +"for" +"foreach" +"function" +"global" +"goto" +"if" +"implements" +"include" +"include_once" +"instanceof" +"insteadof" +"int" +"integer" +"interface" +"isset" +"list" +"namespace" +"new" +"object" +"print" +"private" +"protected" +"public" +"readonly" +"real" +"require" +"require_once" +"return" +"static" +"string" +"switch" +"throw" +"trait" +"try" +"unset" +"unset" +"use" +"var" +"while" +"yield from" +"yield" diff --git a/tools/fuzzing/target.php b/tools/fuzzing/target.php new file mode 100644 index 0000000000..206cc9ecdd --- /dev/null +++ b/tools/fuzzing/target.php @@ -0,0 +1,137 @@ +tokens = $tokens; + } + + public function beforeTraverse(array $nodes): void { + $this->hasProblematicConstruct = false; + } + + public function leaveNode(PhpParser\Node $node) { + // We don't precisely preserve nop statements. + if ($node instanceof Stmt\Nop) { + return NodeVisitor::REMOVE_NODE; + } + + // We don't precisely preserve redundant trailing commas in array destructuring. + if ($node instanceof Expr\List_) { + while (!empty($node->items) && $node->items[count($node->items) - 1] === null) { + array_pop($node->items); + } + } + + // For T_NUM_STRING the parser produced negative integer literals. Convert these into + // a unary minus followed by a positive integer. + if ($node instanceof Scalar\Int_ && $node->value < 0) { + if ($node->value === \PHP_INT_MIN) { + // PHP_INT_MIN == -PHP_INT_MAX - 1 + return new Expr\BinaryOp\Minus( + new Expr\UnaryMinus(new Scalar\Int_(\PHP_INT_MAX)), + new Scalar\Int_(1)); + } + return new Expr\UnaryMinus(new Scalar\Int_(-$node->value)); + } + + // If a constant with the same name as a cast operand occurs inside parentheses, it will + // be parsed back as a cast. E.g. "foo(int)" will fail to parse, because the argument is + // interpreted as a cast. We can run into this with inputs like "foo(int\n)", where the + // newline is not preserved. + if ($node instanceof Expr\ConstFetch && $node->name->isUnqualified() && + in_array($node->name->toLowerString(), self::CAST_NAMES) + ) { + $this->hasProblematicConstruct = true; + } + + // The parser does not distinguish between use X and use \X, as they are semantically + // equivalent. However, use \keyword is legal PHP, while use keyword is not, so we inspect + // tokens to detect this situation here. + if ($node instanceof Stmt\Use_ && $node->uses[0]->name->isUnqualified() && + $this->tokens[$node->uses[0]->name->getStartTokenPos()]->is(\T_NAME_FULLY_QUALIFIED) + ) { + $this->hasProblematicConstruct = true; + } + if ($node instanceof Stmt\GroupUse && $node->prefix->isUnqualified() && + $this->tokens[$node->prefix->getStartTokenPos()]->is(\T_NAME_FULLY_QUALIFIED) + ) { + $this->hasProblematicConstruct = true; + } + + // clone($x, ) is not preserved precisely. + if ($node instanceof Expr\FuncCall && $node->name instanceof Node\Name && + $node->name->toLowerString() == 'clone' && count($node->args) == 1 + ) { + $this->hasProblematicConstruct = true; + } + } +}; +$traverser = new PhpParser\NodeTraverser(); +$traverser->addVisitor($visitor); + +$fuzzer->setTarget(function(string $input) use($lexer, $parser, $prettyPrinter, $nodeDumper, $visitor, $traverser) { + $stmts = $parser->parse($input); + $printed = $prettyPrinter->prettyPrintFile($stmts); + + $visitor->setTokens($parser->getTokens()); + $stmts = $traverser->traverse($stmts); + if ($visitor->hasProblematicConstruct) { + return; + } + + try { + $printedStmts = $parser->parse($printed); + } catch (PhpParser\Error $e) { + throw new Error("Failed to parse pretty printer output"); + } + + $visitor->setTokens($parser->getTokens()); + $printedStmts = $traverser->traverse($printedStmts); + $same = $nodeDumper->dump($stmts) == $nodeDumper->dump($printedStmts); + if (!$same && !preg_match('/<\?php<\?php/i', $input)) { + throw new Error("Result after pretty printing differs"); + } +}); + +$fuzzer->setMaxLen(1024); +$fuzzer->addDictionary(__DIR__ . '/php.dict'); +$fuzzer->setAllowedExceptions([PhpParser\Error::class]);