mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-07-16 20:06:32 +02:00
Compare commits
90 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
196f177cfe | ||
|
b9afcdfd92 | ||
|
d341d94976 | ||
|
5ede167835 | ||
|
b862de1f5b | ||
|
1d62e9d8cc | ||
|
e3195c246f | ||
|
2a3bc608dc | ||
|
d5668f536d | ||
|
7fbbf83011 | ||
|
42e368e964 | ||
|
fd7ee2e083 | ||
|
179d32cfaf | ||
|
bb2c5303ae | ||
|
69c00ebbe4 | ||
|
30abe062f2 | ||
|
dff239267f | ||
|
8b64195cf2 | ||
|
9caa51b3a5 | ||
|
5513073a53 | ||
|
659d26c231 | ||
|
648800f07f | ||
|
23bf4f0c13 | ||
|
57ac7e39bf | ||
|
272ab6c8d8 | ||
|
0731b47655 | ||
|
3b7d8e8b5d | ||
|
a35c2a2067 | ||
|
55b2ead967 | ||
|
e1a0ec3724 | ||
|
66896dbde6 | ||
|
338bc1f8e7 | ||
|
ab80054e97 | ||
|
a6d2cd69f8 | ||
|
6996db1e3a | ||
|
e30c3ac01b | ||
|
a5477a4eaf | ||
|
7a40498cb4 | ||
|
65f1adbe65 | ||
|
c8454271e1 | ||
|
62f83a0dc2 | ||
|
611fa5c7f1 | ||
|
4defbc2174 | ||
|
33a39fae06 | ||
|
e4eab9ec0c | ||
|
6aaa87f143 | ||
|
08f97eb4ef | ||
|
8d18848fb0 | ||
|
805078e0a9 | ||
|
52dafafd10 | ||
|
dba7524b37 | ||
|
617bf0aa41 | ||
|
dce19b074b | ||
|
edbf162e4c | ||
|
b23c53df5f | ||
|
cea0c4a9d6 | ||
|
879e8dcd6d | ||
|
729c7bde0c | ||
|
8982315b4e | ||
|
0f556c16f5 | ||
|
7ec277e1e1 | ||
|
1a627872f0 | ||
|
592836c4dc | ||
|
68defc2c6a | ||
|
d225555830 | ||
|
251e689283 | ||
|
01f4be6b4d | ||
|
dc28449d81 | ||
|
3ad0d4b310 | ||
|
4dbf067b4b | ||
|
5567f0ab3b | ||
|
0c34706799 | ||
|
f9fc2fc9ee | ||
|
a2d7e8977a | ||
|
73cace360d | ||
|
c96636d192 | ||
|
d56ff5a351 | ||
|
3028bc8081 | ||
|
91295a0790 | ||
|
d600c60779 | ||
|
e3bc5b564d | ||
|
53eac36a3f | ||
|
ce5c76d79b | ||
|
b7ffdbbb92 | ||
|
8f1eacdab7 | ||
|
1366e833a1 | ||
|
6930feac43 | ||
|
54275ad181 | ||
|
21ca7eaf1b | ||
|
a86779198f |
.gitattributes.travis.ymlCHANGELOG.mdREADME.md
bin
composer.jsondoc
grammar
lib
PhpParser
Autoloader.php
bootstrap.phpBuilder
BuilderAbstract.phpBuilderFactory.phpError.phpLexer.phpLexer
Node
Arg.phpConst_.php
NodeAbstract.phpNodeDumper.phpNodeTraverser.phpExpr
ArrayDimFetch.phpArrayItem.phpArray_.phpAssign.phpAssignOp.phpAssignRef.phpBinaryOp.php
FunctionLike.phpName.phpParam.phpBinaryOp
BitwiseNot.phpBooleanNot.phpCast.phpCast
ClassConstFetch.phpClone_.phpClosure.phpClosureUse.phpConstFetch.phpEmpty_.phpErrorSuppress.phpEval_.phpExit_.phpFuncCall.phpInclude_.phpInstanceof_.phpIsset_.phpList_.phpMethodCall.phpNew_.phpPostDec.phpPostInc.phpPreDec.phpPreInc.phpPrint_.phpPropertyFetch.phpShellExec.phpStaticCall.phpStaticPropertyFetch.phpTernary.phpUnaryMinus.phpUnaryPlus.phpVariable.phpYieldFrom.phpYield_.phpScalar
Stmt
Break_.phpCase_.phpCatch_.phpClassConst.phpClassLike.phpClassMethod.phpClass_.phpConst_.phpContinue_.phpDeclareDeclare.phpDeclare_.phpDo_.phpEcho_.phpElseIf_.phpElse_.phpFor_.phpForeach_.phpFunction_.phpGlobal_.phpGoto_.phpHaltCompiler.phpIf_.phpInlineHTML.phpInterface_.phpLabel.phpNamespace_.phpProperty.phpPropertyProperty.phpReturn_.phpStaticVar.phpStatic_.phpSwitch_.phpThrow_.phpTraitUse.phpTraitUseAdaptation.php
TraitUseAdaptation
Trait_.phpTryCatch.phpUnset_.phpUseUse.phpUse_.phpWhile_.phpNodeVisitor
Parser.phpParserAbstract.phpPrettyPrinter
PrettyPrinterAbstract.phpSerializer
Unserializer.phpUnserializer
test
PhpParser
AutoloaderTest.php
Builder
ClassTest.phpFunctionTest.phpInterfaceTest.phpMethodTest.phpNamespaceTest.phpParamTest.phpPropertyTest.phpTraitTest.phpUseTest.php
BuilderFactoryTest.phpCodeTestAbstract.phpErrorTest.phpLexer
LexerTest.phpNode
NodeAbstractTest.phpNodeDumperTest.phpNodeTraverserTest.phpNodeVisitor
ParserTest.phpPrettyPrinterTest.phpSerializer
Unserializer
code
parser
errorHandling
expr
scalar
stmt
class
abstract.testanonymous.testimplicitPublic.testinterface.testmodifier.testname.testname.test-failphp4Style.testsimple.teststaticMethod.testtrait.test
function
byRef.testconditional.testdefaultValues.testgenerator.testreturnTypes.testspecialVars.testtypeHints.testvariadic.testvariadicDefaultValue.test
haltCompilerInvalidSyntax.testhaltCompilerOffset.testhaltCompilerOutermostScope.testhashbang.testnamespace
tryWithoutCatch.testprettyPrinter
5
.gitattributes
vendored
5
.gitattributes
vendored
@@ -1,5 +0,0 @@
|
||||
/doc export-ignore
|
||||
/test export-ignore
|
||||
/test_old export-ignore
|
||||
.gitattributes export-ignore
|
||||
.travis.yml export-ignore
|
@@ -5,9 +5,10 @@ php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- hhvm
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: hhvm
|
||||
- php: 7.0
|
||||
fast_finish: true
|
||||
|
108
CHANGELOG.md
108
CHANGELOG.md
@@ -1,15 +1,119 @@
|
||||
Version 1.1.1-dev
|
||||
Version 1.4.1-dev
|
||||
-----------------
|
||||
|
||||
Nothing yet.
|
||||
|
||||
Version 1.4.0 (2015-07-14)
|
||||
--------------------------
|
||||
|
||||
### Added
|
||||
|
||||
* Added interface `PhpParser\Node\FunctionLike`, which is implemented by `Stmt\ClassMethod`,
|
||||
`Stmt\Function_` and `Expr\Closure` nodes. This interface provides getters for their common
|
||||
subnodes.
|
||||
* Added `Node\Stmt\ClassLike::getMethod()` to look up a specific method on a class/interface/trait.
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed `isPublic()` return value for implicitly public properties and methods that define and
|
||||
additional modifier like `static` or `abstract`.
|
||||
* Properties are now accepted by the trait builder.
|
||||
* Fixed `__HALT_COMPILER_OFFSET__` support on HHVM.
|
||||
|
||||
Version 1.3.0 (2015-05-02)
|
||||
--------------------------
|
||||
|
||||
### Added
|
||||
|
||||
* Errors can now store the attributes of the node/token where the error occurred. Previously only the start line was
|
||||
stored.
|
||||
* If file positions are enabled in the lexer, errors can now provide column information if it is available. See
|
||||
[documentation](https://github.com/nikic/PHP-Parser/blob/master/doc/component/Error.markdown#column-information).
|
||||
* The parser now provides an experimental error recovery mode, which can be enabled by disabling the `throwOnError`
|
||||
parser option. In this mode the parser will try to construct a partial AST even if the code is not valid PHP. See
|
||||
[documentation](https://github.com/nikic/PHP-Parser/blob/master/doc/component/Error.markdown#error-recovery).
|
||||
* Added support for PHP 7 `yield from` expression. It is represented by `Expr\YieldFrom`.
|
||||
* Added support for PHP 7 anonymous classes. These are represented by ordinary `Stmt\Class_` nodes with the name set to
|
||||
`null`. Furthermore this implies that `Expr\New_` can now contain a `Stmt\Class_` in its `class` subnode.
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixed registration of PHP 7 aliases, for the case where the old name was used before the new name.
|
||||
* Fixed handling of precedence when pretty-printing `print` expressions.
|
||||
* Floating point numbers are now pretty-printed with a higher precision.
|
||||
* Checks for special class names like `self` are now case-insensitive.
|
||||
|
||||
Version 1.2.2 (2015-04-03)
|
||||
--------------------------
|
||||
|
||||
* The `NameResolver` now resolves parameter type hints when entering the function/method/closure node. As such other
|
||||
visitors running after it will be able to make use of the resolved names at that point already.
|
||||
* The autoloader no longer sets the `unserialize_callback_func` ini option on registration - this is not necessary and
|
||||
may cause issues when running PhpUnit tests with process isolation.
|
||||
|
||||
Version 1.2.1 (2015-03-24)
|
||||
--------------------------
|
||||
|
||||
* Fixed registration of the aliases introduced in 1.2.0. Previously the old class names could not be used in
|
||||
`instanceof` checks under some circumstances.
|
||||
|
||||
Version 1.2.0 (2015-03-22)
|
||||
--------------------------
|
||||
|
||||
### Changed
|
||||
|
||||
* To ensure compatibility with PHP 7, the following node classes have been renamed:
|
||||
|
||||
OLD => NEW
|
||||
PhpParser\Node\Expr\Cast\Bool => PhpParser\Node\Expr\Cast\Bool_
|
||||
PhpParser\Node\Expr\Cast\Int => PhpParser\Node\Expr\Cast\Int_
|
||||
PhpParser\Node\Expr\Cast\Object => PhpParser\Node\Expr\Cast\Object_
|
||||
PhpParser\Node\Expr\Cast\String => PhpParser\Node\Expr\Cast\String_
|
||||
PhpParser\Node\Scalar\String => PhpParser\Node\Scalar\String_
|
||||
|
||||
**The previous class names are still supported as aliases.** However it is strongly encouraged to use the new names
|
||||
in order to make your code compatible with PHP 7.
|
||||
|
||||
* Subnodes are now stored using real properties instead of an array. This improves performance and memory usage of the
|
||||
initial parse and subsequent node tree operations. The `NodeAbstract` class still supports the old way of specifying
|
||||
subnodes, however this is *deprecated*. In any case properties that are assigned to a node after creation will no
|
||||
longer be considered as subnodes.
|
||||
|
||||
* Methods and property declarations will no longer set the `Stmt\Class_::MODIFIER_PUBLIC` flag if no visibility is
|
||||
explicitly given. However the `isPublic()` method will continue to return true. This allows you to distinguish whether
|
||||
a method/property is explicitly or implicitly public and control the pretty printer output more precisely.
|
||||
|
||||
* The `Stmt\Class_`, `Stmt\Interface_` and `Stmt\Trait_` nodes now inherit from `Stmt\ClassLike`, which provides a
|
||||
`getMethods()` method. Previously this method was only available on `Stmt\Class_`.
|
||||
|
||||
* Support including the `bootstrap.php` file multiple times.
|
||||
|
||||
* Make documentation and tests part of the release tarball again.
|
||||
|
||||
* Improve support for HHVM and PHP 7.
|
||||
|
||||
### Added
|
||||
|
||||
* Added support for PHP 7 return type declarations. This adds an additional `returnType` subnode to `Stmt\Function_`,
|
||||
`Stmt\ClassMethod` and `Expr\Closure`.
|
||||
|
||||
* Added support for the PHP 7 null coalesce operator `??`. The operator is represented by `Expr\BinaryOp\Coalesce`.
|
||||
|
||||
* Added support for the PHP 7 spaceship operator `<=>`. The operator is represented by `Expr\BinaryOp\Spaceship`.
|
||||
|
||||
* Added use builder.
|
||||
|
||||
* Added global namespace support to the namespace builder.
|
||||
|
||||
* Added a constructor flag to `NodeTraverser`, which disables cloning of nodes.
|
||||
|
||||
Version 1.1.0 (2015-01-18)
|
||||
--------------------------
|
||||
|
||||
* Methods that do not specify an explicit visibility (e.g. `function method()`) will now have the `MODIFIER_PUBLIC`
|
||||
flag set. This also means that their `isPublic()` method will return true.
|
||||
|
||||
* Declaring a property as abstract or static is now an error.
|
||||
* Declaring a property as abstract or final is now an error.
|
||||
|
||||
* The `Lexer` and `Lexer\Emulative` classes now accept an `$options` array in their constructors. Currently only the
|
||||
`usedAttributes` option is supported, which determines which attributes will be added to AST nodes. In particular
|
||||
|
19
README.md
19
README.md
@@ -4,7 +4,7 @@ PHP Parser
|
||||
This is a PHP 5.2 to PHP 5.6 parser written in PHP. Its purpose is to simplify static code analysis and
|
||||
manipulation.
|
||||
|
||||
[**Documentation for version 1.0.x**][doc_master] (stable; for running on PHP >= 5.3).
|
||||
[**Documentation for version 1.x**][doc_1_x] (stable; for running on PHP >= 5.3).
|
||||
|
||||
[Documentation for version 0.9.x][doc_0_9] (unsupported; for running on PHP 5.2).
|
||||
|
||||
@@ -22,7 +22,7 @@ hello\world('foo', 'bar' . 'baz');
|
||||
|
||||
You'll get a syntax tree looking roughly like this:
|
||||
|
||||
```
|
||||
```php
|
||||
array(
|
||||
0: Stmt_Echo(
|
||||
exprs: array(
|
||||
@@ -70,7 +70,18 @@ programming errors or security issues).
|
||||
Additionally, you can convert a syntax tree back to PHP code. This allows you to do code preprocessing
|
||||
(like automatedly porting code to older PHP versions).
|
||||
|
||||
So, that's it, in a nutshell. You can find everything else in the [docs][doc_master].
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
1. [Introduction](doc/0_Introduction.markdown)
|
||||
2. [Installation](doc/1_Installation.markdown)
|
||||
3. [Usage of basic components](doc/2_Usage_of_basic_components.markdown)
|
||||
4. [Other node tree representations](doc/3_Other_node_tree_representations.markdown)
|
||||
5. [Code generation](doc/4_Code_generation.markdown)
|
||||
|
||||
Component documentation:
|
||||
|
||||
1. [Lexer](doc/component/Lexer.markdown)
|
||||
|
||||
[doc_0_9]: https://github.com/nikic/PHP-Parser/tree/0.9/doc
|
||||
[doc_master]: https://github.com/nikic/PHP-Parser/tree/master/doc
|
||||
[doc_1_x]: https://github.com/nikic/PHP-Parser/tree/1.x/doc
|
||||
|
53
bin/php-parse.php
Normal file → Executable file
53
bin/php-parse.php
Normal file → Executable file
@@ -1,15 +1,16 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../lib/bootstrap.php';
|
||||
|
||||
ini_set('xdebug.max_nesting_level', 2000);
|
||||
ini_set('xdebug.max_nesting_level', 3000);
|
||||
|
||||
// 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);
|
||||
|
||||
list($operations, $files) = parseArgs($argv);
|
||||
list($operations, $files, $attributes) = parseArgs($argv);
|
||||
|
||||
/* Dump nodes by default */
|
||||
if (empty($operations)) {
|
||||
@@ -20,7 +21,10 @@ if (empty($files)) {
|
||||
showHelp("Must specify at least one file.");
|
||||
}
|
||||
|
||||
$parser = new PhpParser\Parser(new PhpParser\Lexer\Emulative);
|
||||
$lexer = new PhpParser\Lexer\Emulative(array('usedAttributes' => array(
|
||||
'startLine', 'endLine', 'startFilePos', 'endFilePos'
|
||||
)));
|
||||
$parser = new PhpParser\Parser($lexer);
|
||||
$dumper = new PhpParser\NodeDumper;
|
||||
$prettyPrinter = new PhpParser\PrettyPrinter\Standard;
|
||||
$serializer = new PhpParser\Serializer\XML;
|
||||
@@ -44,7 +48,17 @@ foreach ($files as $file) {
|
||||
try {
|
||||
$stmts = $parser->parse($code);
|
||||
} catch (PhpParser\Error $e) {
|
||||
die("==> Parse Error: {$e->getMessage()}\n");
|
||||
if ($attributes['with-column-info'] && $e->hasColumnInfo()) {
|
||||
$startLine = $e->getStartLine();
|
||||
$endLine = $e->getEndLine();
|
||||
$startColumn = $e->getStartColumn($code);
|
||||
$endColumn = $e->getEndColumn($code);
|
||||
$message .= $e->getRawMessage() . " from $startLine:$startColumn to $endLine:$endColumn";
|
||||
} else {
|
||||
$message = $e->getMessage();
|
||||
}
|
||||
|
||||
die($message . "\n");
|
||||
}
|
||||
|
||||
foreach ($operations as $operation) {
|
||||
@@ -70,24 +84,20 @@ foreach ($files as $file) {
|
||||
function showHelp($error) {
|
||||
die($error . "\n\n" .
|
||||
<<<OUTPUT
|
||||
Usage:
|
||||
|
||||
php php-parse.php [operations] file1.php [file2.php ...]
|
||||
|
||||
The file arguments can also be replaced with a code string:
|
||||
|
||||
php php-parse.php [operations] "<?php code"
|
||||
Usage: php php-parse.php [operations] file1.php [file2.php ...]
|
||||
or: php php-parse.php [operations] "<?php code"
|
||||
Turn PHP source code into an abstract syntax tree.
|
||||
|
||||
Operations is a list of the following options (--dump by default):
|
||||
|
||||
--dump -d Dump nodes using NodeDumper
|
||||
--pretty-print -p Pretty print file using PrettyPrinter\Standard
|
||||
--serialize-xml Serialize nodes using Serializer\XML
|
||||
--var-dump var_dump() nodes (for exact structure)
|
||||
--resolve-names -N Resolve names using NodeVisitor\NameResolver
|
||||
-d, --dump Dump nodes using NodeDumper
|
||||
-p, --pretty-print Pretty print file using PrettyPrinter\Standard
|
||||
--serialize-xml Serialize nodes using Serializer\XML
|
||||
--var-dump var_dump() nodes (for exact structure)
|
||||
-N, --resolve-names Resolve names using NodeVisitor\NameResolver
|
||||
-c, --with-column-info Show column-numbers for errors (if available)
|
||||
|
||||
Example:
|
||||
|
||||
php php-parse.php -d -p -N -d file.php
|
||||
|
||||
Dumps nodes, pretty prints them, then resolves names and dumps them again.
|
||||
@@ -100,6 +110,9 @@ OUTPUT
|
||||
function parseArgs($args) {
|
||||
$operations = array();
|
||||
$files = array();
|
||||
$attributes = array(
|
||||
'with-column-info' => false,
|
||||
);
|
||||
|
||||
array_shift($args);
|
||||
$parseOptions = true;
|
||||
@@ -128,6 +141,10 @@ function parseArgs($args) {
|
||||
case '-N';
|
||||
$operations[] = 'resolve-names';
|
||||
break;
|
||||
case '--with-column-info':
|
||||
case '-c';
|
||||
$attributes['with-column-info'] = true;
|
||||
break;
|
||||
case '--':
|
||||
$parseOptions = false;
|
||||
break;
|
||||
@@ -140,5 +157,5 @@ function parseArgs($args) {
|
||||
}
|
||||
}
|
||||
|
||||
return array($operations, $files);
|
||||
return array($operations, $files, $attributes);
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
"dev-master": "1.4-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ Additionally you may want to set the `xdebug.max_nesting_level` ini option to a
|
||||
|
||||
```php
|
||||
<?php
|
||||
ini_set('xdebug.max_nesting_level', 2000);
|
||||
ini_set('xdebug.max_nesting_level', 3000);
|
||||
```
|
||||
|
||||
This ensures that there will be no errors when traversing highly nested node trees.
|
||||
@@ -102,7 +102,7 @@ with them easier they are grouped into three categories:
|
||||
and thus can occur in other expressions. Examples of expressions are `$var`
|
||||
(`PhpParser\Node\Expr\Variable`) and `func()` (`PhpParser\Node\Expr\FuncCall`).
|
||||
* `PhpParser\Node\Scalar`s are nodes representing scalar values, like `'string'`
|
||||
(`PhpParser\Node\Scalar\String`), `0` (`PhpParser\Node\Scalar\LNumber`) or magic constants
|
||||
(`PhpParser\Node\Scalar\String_`), `0` (`PhpParser\Node\Scalar\LNumber`) or magic constants
|
||||
like `__FILE__` (`PhpParser\Node\Scalar\MagicConst\File`). All `PhpParser\Node\Scalar`s extend
|
||||
`PhpParser\Node\Expr`, as scalars are expressions, too.
|
||||
* There are some nodes not in either of these groups, for example names (`PhpParser\Node\Name`)
|
||||
@@ -224,7 +224,7 @@ use PhpParser\Node;
|
||||
class MyNodeVisitor extends PhpParser\NodeVisitorAbstract
|
||||
{
|
||||
public function leaveNode(Node $node) {
|
||||
if ($node instanceof Node\Scalar\String) {
|
||||
if ($node instanceof Node\Scalar\String_) {
|
||||
$node->value = 'foo';
|
||||
}
|
||||
}
|
||||
|
@@ -2,9 +2,14 @@ Code generation
|
||||
===============
|
||||
|
||||
It is also possible to generate code using the parser, by first creating an Abstract Syntax Tree and then using the
|
||||
pretty printer to convert it to PHP code. To simplify code generation, the project comes with a set of builders for
|
||||
namespaces, classes, interfaces, traits, methods, functions, parameters and properties. The builders allow creating node
|
||||
trees using a fluid interface, instead of instantiating all nodes manually.
|
||||
pretty printer to convert it to PHP code. To simplify code generation, the project comes with builders which allow
|
||||
creating node trees using a fluid interface, instead of instantiating all nodes manually. Builders are available for
|
||||
the following syntactic elements:
|
||||
|
||||
* namespaces and use statements
|
||||
* classes, interfaces and traits
|
||||
* methods, functions and parameters
|
||||
* properties
|
||||
|
||||
Here is an example:
|
||||
|
||||
@@ -12,12 +17,14 @@ Here is an example:
|
||||
<?php
|
||||
$factory = new PhpParser\BuilderFactory;
|
||||
$node = $factory->namespace('Name\Space')
|
||||
->addStmt($factory->use('Some\Other\Thingy')->as('SomeOtherClass'))
|
||||
->addStmt($factory->class('SomeClass')
|
||||
->extend('SomeOtherClass')
|
||||
->implement('A\Few', '\Interfaces')
|
||||
->makeAbstract() // ->makeFinal()
|
||||
|
||||
->addStmt($factory->method('someMethod')
|
||||
->makePublic()
|
||||
->makeAbstract() // ->makeFinal()
|
||||
->addParam($factory->param('someParam')->setTypeHint('SomeClass'))
|
||||
->setDocComment('/**
|
||||
@@ -54,6 +61,7 @@ This will produce the following output with the standard pretty printer:
|
||||
|
||||
namespace Name\Space;
|
||||
|
||||
use Some\Other\Thingy as SomeClass;
|
||||
abstract class SomeClass extends SomeOtherClass implements A\Few, \Interfaces
|
||||
{
|
||||
protected $someProperty;
|
||||
|
77
doc/component/Error.markdown
Normal file
77
doc/component/Error.markdown
Normal file
@@ -0,0 +1,77 @@
|
||||
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.
|
||||
|
||||
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\Parser($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:
|
||||
|
||||
```php
|
||||
if ($e->hasColumnInfo()) {
|
||||
echo $e->getRawMessage() . ' from ' . $e->getStartLine() . ':' . $e->getStartColumn($code)
|
||||
. ' to ' . $e->getEndLine() . ':' . $e->getEndColumn($code);
|
||||
} else {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
```
|
||||
|
||||
Both line numbers and column numbers are 1-based. EOF errors will be located at the position one past the end of the
|
||||
file.
|
||||
|
||||
Error recovery
|
||||
--------------
|
||||
|
||||
> **EXPERIMENTAL**
|
||||
|
||||
By default the parser will throw an exception upon encountering the first error during parsing. An alternative mode is
|
||||
also supported, in which the parser will remember the error, but try to continue parsing the rest of the source code.
|
||||
|
||||
To enable this mode the `throwOnError` parser option needs to be disabled. Any errors that occurred during parsing can
|
||||
then be retrieved using `$parser->getErrors()`. The `$parser->parse()` method will either return a partial syntax tree
|
||||
or `null` if recovery fails.
|
||||
|
||||
A usage example:
|
||||
|
||||
```php
|
||||
$parser = new PhpParser\Parser(new PhpParser\Lexer, array(
|
||||
'throwOnError' => false,
|
||||
));
|
||||
|
||||
$stmts = $parser->parse($code);
|
||||
$errors = $parser->getErrors();
|
||||
|
||||
foreach ($errors as $error) {
|
||||
// $error is an ordinary PhpParser\Error
|
||||
}
|
||||
|
||||
if (null !== $stmts) {
|
||||
// $stmts is a best-effort partial AST
|
||||
}
|
||||
```
|
||||
|
||||
The error recovery implementation is experimental -- it currently won't be able to recover from many types of errors.
|
@@ -13,8 +13,7 @@ The `.phpy` file is a normal grammer in `kmyacc` (`yacc`) style, with some trans
|
||||
applied to it:
|
||||
|
||||
* Nodes are created using the syntax `Name[..., ...]`. This is transformed into
|
||||
`new Node\Name(..., ..., $attributes)`
|
||||
* `Name::abc` is transformed to `Node\Name::abc`
|
||||
`new Name(..., ..., attributes())`
|
||||
* Some function-like constructs are resolved (see `rebuildParser.php` for a list)
|
||||
* Associative arrays are written as `[key: value, ...]`, which is transformed to
|
||||
`array('key' => value, ...)`
|
||||
@@ -25,5 +24,5 @@ Building the parser
|
||||
In order to rebuild the parser, you need [moriyoshi's fork of kmyacc](https://github.com/moriyoshi/kmyacc-forked).
|
||||
After you compiled/installed it, run the `rebuildParser.php` script.
|
||||
|
||||
By default only the `Parser.php` is built. If you want to additionally build `Parser/Debug.php` and `y.output` run the
|
||||
script with `--debug`. If you want to retain the preprocessed grammar pass `--keep-tmp-grammar`.
|
||||
By default only the `Parser.php` is built. If you want to additionally emit debug symbols and create `y.output`, run the
|
||||
script with `--debug`. If you want to retain the preprocessed grammar pass `--keep-tmp-grammar`.
|
||||
|
@@ -2,11 +2,11 @@
|
||||
$meta #
|
||||
#semval($) $this->semValue
|
||||
#semval($,%t) $this->semValue
|
||||
#semval(%n) $this->semStack[$this->stackPos-(%l-%n)]
|
||||
#semval(%n,%t) $this->semStack[$this->stackPos-(%l-%n)]
|
||||
#include;
|
||||
#semval(%n) $this->stackPos-(%l-%n)
|
||||
#semval(%n,%t) $this->stackPos-(%l-%n)
|
||||
|
||||
namespace PhpParser;
|
||||
#include;
|
||||
|
||||
/* This is an automatically GENERATED file, which should not be manually edited.
|
||||
* Instead edit one of the following:
|
||||
@@ -20,7 +20,8 @@ class Parser extends ParserAbstract
|
||||
protected $actionTableSize = #(YYLAST);
|
||||
protected $gotoTableSize = #(YYGLAST);
|
||||
|
||||
protected $invalidToken = #(YYBADCH);
|
||||
protected $invalidSymbol = #(YYBADCH);
|
||||
protected $errorSymbol = #(YYINTERRTOK);
|
||||
protected $defaultAction = #(YYDEFAULT);
|
||||
protected $unexpectedTokenRule = #(YYUNEXPECTED);
|
||||
|
||||
@@ -86,7 +87,7 @@ class Parser extends ParserAbstract
|
||||
#endif
|
||||
#reduce
|
||||
|
||||
protected function reduceRule%n($attributes) {
|
||||
protected function reduceRule%n() {
|
||||
%b
|
||||
}
|
||||
#noact
|
||||
|
@@ -39,10 +39,10 @@ echo 'Building temporary preproprocessed grammar file.', "\n";
|
||||
|
||||
$grammarCode = file_get_contents($grammarFile);
|
||||
|
||||
$grammarCode = resolveConstants($grammarCode);
|
||||
$grammarCode = resolveNodes($grammarCode);
|
||||
$grammarCode = resolveMacros($grammarCode);
|
||||
$grammarCode = resolveArrays($grammarCode);
|
||||
$grammarCode = resolveStackAccess($grammarCode);
|
||||
|
||||
file_put_contents($tmpGrammarFile, $grammarCode);
|
||||
|
||||
@@ -52,7 +52,12 @@ echo "Building parser.\n";
|
||||
$output = trim(shell_exec("$kmyacc $additionalArgs -l -m $skeletonFile $tmpGrammarFile 2>&1"));
|
||||
echo "Output: \"$output\"\n";
|
||||
|
||||
moveFileWithDirCheck($tmpResultFile, $parserResultFile);
|
||||
$resultCode = file_get_contents($tmpResultFile);
|
||||
$resultCode = removeTrailingWhitespace($resultCode);
|
||||
|
||||
ensureDirExists(dirname($parserResultFile));
|
||||
file_put_contents($parserResultFile, $resultCode);
|
||||
unlink($tmpResultFile);
|
||||
|
||||
if (!$optionKeepTmpGrammar) {
|
||||
unlink($tmpGrammarFile);
|
||||
@@ -62,10 +67,6 @@ if (!$optionKeepTmpGrammar) {
|
||||
/// Preprocessing functions ///
|
||||
///////////////////////////////
|
||||
|
||||
function resolveConstants($code) {
|
||||
return preg_replace('~[A-Z][a-zA-Z_\\\\]++::~', 'Node\\\\$0', $code);
|
||||
}
|
||||
|
||||
function resolveNodes($code) {
|
||||
return preg_replace_callback(
|
||||
'~(?<name>[A-Z][a-zA-Z_\\\\]++)\s*' . PARAMS . '~',
|
||||
@@ -83,7 +84,7 @@ function resolveNodes($code) {
|
||||
$paramCode .= $param . ', ';
|
||||
}
|
||||
|
||||
return 'new Node\\' . $matches['name'] . '(' . $paramCode . '$attributes)';
|
||||
return 'new ' . $matches['name'] . '(' . $paramCode . 'attributes())';
|
||||
},
|
||||
$code
|
||||
);
|
||||
@@ -102,10 +103,9 @@ function resolveMacros($code) {
|
||||
$matches['args']
|
||||
);
|
||||
|
||||
if ('error' == $name) {
|
||||
assertArgs(1, $args, $name);
|
||||
|
||||
return 'throw new Error(' . $args[0] . ')';
|
||||
if ('attributes' == $name) {
|
||||
assertArgs(0, $args, $name);
|
||||
return '$this->startAttributeStack[#1] + $this->endAttributes';
|
||||
}
|
||||
|
||||
if ('init' == $name) {
|
||||
@@ -139,16 +139,16 @@ function resolveMacros($code) {
|
||||
if ('parseEncapsed' == $name) {
|
||||
assertArgs(2, $args, $name);
|
||||
|
||||
return 'foreach (' . $args[0] . ' as &$s) { if (is_string($s)) { $s = Node\Scalar\String::parseEscapeSequences($s, ' . $args[1] . '); } }';
|
||||
return 'foreach (' . $args[0] . ' as &$s) { if (is_string($s)) { $s = Node\Scalar\String_::parseEscapeSequences($s, ' . $args[1] . '); } }';
|
||||
}
|
||||
|
||||
if ('parseEncapsedDoc' == $name) {
|
||||
assertArgs(1, $args, $name);
|
||||
|
||||
return 'foreach (' . $args[0] . ' as &$s) { if (is_string($s)) { $s = Node\Scalar\String::parseEscapeSequences($s, null); } } $s = preg_replace(\'~(\r\n|\n|\r)$~\', \'\', $s); if (\'\' === $s) array_pop(' . $args[0] . ');';
|
||||
return 'foreach (' . $args[0] . ' as &$s) { if (is_string($s)) { $s = Node\Scalar\String_::parseEscapeSequences($s, null); } } $s = preg_replace(\'~(\r\n|\n|\r)$~\', \'\', $s); if (\'\' === $s) array_pop(' . $args[0] . ');';
|
||||
}
|
||||
|
||||
throw new Exception(sprintf('Unknown macro "%s"', $name));
|
||||
return $matches[0];
|
||||
},
|
||||
$code
|
||||
);
|
||||
@@ -191,12 +191,22 @@ function resolveArrays($code) {
|
||||
);
|
||||
}
|
||||
|
||||
function moveFileWithDirCheck($fromPath, $toPath) {
|
||||
$dir = dirname($toPath);
|
||||
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);
|
||||
}
|
||||
|
||||
function ensureDirExists($dir) {
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
rename($fromPath, $toPath);
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
|
@@ -8,14 +8,16 @@
|
||||
%left T_LOGICAL_AND
|
||||
%right T_PRINT
|
||||
%right T_YIELD
|
||||
%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
|
||||
%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
|
||||
%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 '+' '-' '.'
|
||||
@@ -109,6 +111,13 @@
|
||||
%token T_NS_SEPARATOR
|
||||
%token T_ELLIPSIS
|
||||
|
||||
%{
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Scalar;
|
||||
use PhpParser\Node\Stmt;
|
||||
%}
|
||||
|
||||
%%
|
||||
|
||||
start:
|
||||
@@ -162,7 +171,7 @@ constant_declaration_list:
|
||||
;
|
||||
|
||||
constant_declaration:
|
||||
T_STRING '=' static_scalar { $$ = Const_[$1, $3]; }
|
||||
T_STRING '=' static_scalar { $$ = Node\Const_[$1, $3]; }
|
||||
;
|
||||
|
||||
inner_statement_list:
|
||||
@@ -174,7 +183,8 @@ inner_statement:
|
||||
statement { $$ = $1; }
|
||||
| function_declaration_statement { $$ = $1; }
|
||||
| class_declaration_statement { $$ = $1; }
|
||||
| T_HALT_COMPILER { error('__HALT_COMPILER() can only be used from the outermost scope'); }
|
||||
| T_HALT_COMPILER
|
||||
{ throw new Error('__HALT_COMPILER() can only be used from the outermost scope', attributes()); }
|
||||
;
|
||||
|
||||
statement:
|
||||
@@ -212,6 +222,7 @@ statement:
|
||||
| T_THROW expr ';' { $$ = Stmt\Throw_[$2]; }
|
||||
| T_GOTO T_STRING ';' { $$ = Stmt\Goto_[$2]; }
|
||||
| T_STRING ':' { $$ = Stmt\Label[$1]; }
|
||||
| error { $$ = array(); /* means: no statement */ }
|
||||
;
|
||||
|
||||
catches:
|
||||
@@ -245,8 +256,8 @@ optional_ellipsis:
|
||||
;
|
||||
|
||||
function_declaration_statement:
|
||||
T_FUNCTION optional_ref T_STRING '(' parameter_list ')' '{' inner_statement_list '}'
|
||||
{ $$ = Stmt\Function_[$3, [byRef: $2, params: $5, stmts: $8]]; }
|
||||
T_FUNCTION optional_ref T_STRING '(' parameter_list ')' optional_return_type '{' inner_statement_list '}'
|
||||
{ $$ = Stmt\Function_[$3, [byRef: $2, params: $5, returnType: $7, stmts: $9]]; }
|
||||
;
|
||||
|
||||
class_declaration_statement:
|
||||
@@ -380,23 +391,32 @@ non_empty_parameter_list:
|
||||
;
|
||||
|
||||
parameter:
|
||||
optional_class_type optional_ref optional_ellipsis T_VARIABLE
|
||||
{ $$ = Param[parseVar($4), null, $1, $2, $3]; }
|
||||
| optional_class_type optional_ref optional_ellipsis T_VARIABLE '=' static_scalar
|
||||
{ $$ = Param[parseVar($4), $6, $1, $2, $3]; }
|
||||
optional_param_type optional_ref optional_ellipsis T_VARIABLE
|
||||
{ $$ = Node\Param[parseVar($4), null, $1, $2, $3]; }
|
||||
| optional_param_type optional_ref optional_ellipsis T_VARIABLE '=' static_scalar
|
||||
{ $$ = Node\Param[parseVar($4), $6, $1, $2, $3]; }
|
||||
;
|
||||
|
||||
optional_class_type:
|
||||
/* empty */ { $$ = null; }
|
||||
| name { $$ = $1; }
|
||||
type:
|
||||
name { $$ = $1; }
|
||||
| T_ARRAY { $$ = 'array'; }
|
||||
| T_CALLABLE { $$ = '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(Arg[$2, false, false]); }
|
||||
| '(' yield_expr ')' { $$ = array(Node\Arg[$2, false, false]); }
|
||||
;
|
||||
|
||||
non_empty_argument_list:
|
||||
@@ -405,9 +425,9 @@ non_empty_argument_list:
|
||||
;
|
||||
|
||||
argument:
|
||||
expr { $$ = Arg[$1, false, false]; }
|
||||
| '&' variable { $$ = Arg[$2, true, false]; }
|
||||
| T_ELLIPSIS expr { $$ = Arg[$2, false, true]; }
|
||||
expr { $$ = Node\Arg[$1, false, false]; }
|
||||
| '&' variable { $$ = Node\Arg[$2, true, false]; }
|
||||
| T_ELLIPSIS expr { $$ = Node\Arg[$2, false, true]; }
|
||||
;
|
||||
|
||||
global_var_list:
|
||||
@@ -439,8 +459,8 @@ class_statement_list:
|
||||
class_statement:
|
||||
variable_modifiers property_declaration_list ';' { $$ = Stmt\Property[$1, $2]; }
|
||||
| T_CONST constant_declaration_list ';' { $$ = Stmt\ClassConst[$2]; }
|
||||
| method_modifiers T_FUNCTION optional_ref T_STRING '(' parameter_list ')' method_body
|
||||
{ $$ = Stmt\ClassMethod[$4, [type: $1, byRef: $3, params: $6, stmts: $8]]; }
|
||||
| method_modifiers T_FUNCTION optional_ref T_STRING '(' parameter_list ')' optional_return_type method_body
|
||||
{ $$ = Stmt\ClassMethod[$4, [type: $1, byRef: $3, params: $6, returnType: $8, stmts: $9]]; }
|
||||
| T_USE name_list trait_adaptations { $$ = Stmt\TraitUse[$2, $3]; }
|
||||
;
|
||||
|
||||
@@ -480,11 +500,11 @@ method_body:
|
||||
|
||||
variable_modifiers:
|
||||
non_empty_member_modifiers { $$ = $1; }
|
||||
| T_VAR { $$ = Stmt\Class_::MODIFIER_PUBLIC; }
|
||||
| T_VAR { $$ = 0; }
|
||||
;
|
||||
|
||||
method_modifiers:
|
||||
/* empty */ { $$ = Stmt\Class_::MODIFIER_PUBLIC; }
|
||||
/* empty */ { $$ = 0; }
|
||||
| non_empty_member_modifiers { $$ = $1; }
|
||||
;
|
||||
|
||||
@@ -571,6 +591,7 @@ expr:
|
||||
| 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]; }
|
||||
@@ -581,6 +602,7 @@ expr:
|
||||
| '(' 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]; }
|
||||
@@ -588,12 +610,12 @@ expr:
|
||||
| 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_INT_CAST expr { $$ = Expr\Cast\Int_ [$2]; }
|
||||
| T_DOUBLE_CAST expr { $$ = Expr\Cast\Double [$2]; }
|
||||
| T_STRING_CAST expr { $$ = Expr\Cast\String [$2]; }
|
||||
| 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_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 { $$ = Expr\Exit_ [$2]; }
|
||||
| '@' expr { $$ = Expr\ErrorSuppress[$2]; }
|
||||
@@ -603,10 +625,13 @@ expr:
|
||||
| '`' backticks_expr '`' { $$ = Expr\ShellExec[$2]; }
|
||||
| T_PRINT expr { $$ = Expr\Print_[$2]; }
|
||||
| T_YIELD { $$ = Expr\Yield_[null, null]; }
|
||||
| T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars '{' inner_statement_list '}'
|
||||
{ $$ = Expr\Closure[[static: false, byRef: $2, params: $4, uses: $6, stmts: $8]]; }
|
||||
| T_STATIC T_FUNCTION optional_ref '(' parameter_list ')' lexical_vars '{' inner_statement_list '}'
|
||||
{ $$ = Expr\Closure[[static: true, byRef: $3, params: $5, uses: $7, stmts: $9]]; }
|
||||
| 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:
|
||||
@@ -627,14 +652,20 @@ array_expr:
|
||||
scalar_dereference:
|
||||
array_expr '[' dim_offset ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
|
||||
| T_CONSTANT_ENCAPSED_STRING '[' dim_offset ']'
|
||||
{ $$ = Expr\ArrayDimFetch[Scalar\String[Scalar\String::parse($1)], $3]; }
|
||||
{ $$ = Expr\ArrayDimFetch[Scalar\String_[Scalar\String_::parse($1)], $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); }
|
||||
|
||||
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:
|
||||
@@ -721,7 +752,7 @@ exit_expr:
|
||||
|
||||
backticks_expr:
|
||||
/* empty */ { $$ = array(); }
|
||||
| T_ENCAPSED_AND_WHITESPACE { $$ = array(Scalar\String::parseEscapeSequences($1, '`')); }
|
||||
| T_ENCAPSED_AND_WHITESPACE { $$ = array(Scalar\String_::parseEscapeSequences($1, '`')); }
|
||||
| encaps_list { parseEncapsed($1, '`'); $$ = $1; }
|
||||
;
|
||||
|
||||
@@ -733,7 +764,7 @@ ctor_arguments:
|
||||
common_scalar:
|
||||
T_LNUMBER { $$ = Scalar\LNumber[Scalar\LNumber::parse($1)]; }
|
||||
| T_DNUMBER { $$ = Scalar\DNumber[Scalar\DNumber::parse($1)]; }
|
||||
| T_CONSTANT_ENCAPSED_STRING { $$ = Scalar\String[Scalar\String::parse($1)]; }
|
||||
| T_CONSTANT_ENCAPSED_STRING { $$ = Scalar\String_[Scalar\String_::parse($1)]; }
|
||||
| T_LINE { $$ = Scalar\MagicConst\Line[]; }
|
||||
| T_FILE { $$ = Scalar\MagicConst\File[]; }
|
||||
| T_DIR { $$ = Scalar\MagicConst\Dir[]; }
|
||||
@@ -743,9 +774,9 @@ common_scalar:
|
||||
| T_FUNC_C { $$ = Scalar\MagicConst\Function_[]; }
|
||||
| T_NS_C { $$ = Scalar\MagicConst\Namespace_[]; }
|
||||
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
|
||||
{ $$ = Scalar\String[Scalar\String::parseDocString($1, $2)]; }
|
||||
{ $$ = Scalar\String_[Scalar\String_::parseDocString($1, $2)]; }
|
||||
| T_START_HEREDOC T_END_HEREDOC
|
||||
{ $$ = Scalar\String['']; }
|
||||
{ $$ = Scalar\String_['']; }
|
||||
;
|
||||
|
||||
static_scalar:
|
||||
@@ -955,8 +986,8 @@ encaps_var:
|
||||
;
|
||||
|
||||
encaps_var_offset:
|
||||
T_STRING { $$ = Scalar\String[$1]; }
|
||||
| T_NUM_STRING { $$ = Scalar\String[$1]; }
|
||||
T_STRING { $$ = Scalar\String_[$1]; }
|
||||
| T_NUM_STRING { $$ = Scalar\String_[$1]; }
|
||||
| T_VARIABLE { $$ = Expr\Variable[parseVar($1)]; }
|
||||
;
|
||||
|
||||
|
@@ -7,14 +7,25 @@ namespace PhpParser;
|
||||
*/
|
||||
class Autoloader
|
||||
{
|
||||
/** @var bool Whether the autoloader has been registered. */
|
||||
private static $registered = false;
|
||||
|
||||
/** @var bool Whether we're running on PHP 7. */
|
||||
private static $runningOnPhp7;
|
||||
|
||||
/**
|
||||
* Registers PhpParser\Autoloader as an SPL autoloader.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader instead of appending
|
||||
*/
|
||||
static public function register($prepend = false) {
|
||||
ini_set('unserialize_callback_func', 'spl_autoload_call');
|
||||
if (self::$registered === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
|
||||
self::$registered = true;
|
||||
self::$runningOnPhp7 = version_compare(PHP_VERSION, '7.0-dev', '>=');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,24 +35,58 @@ class Autoloader
|
||||
*/
|
||||
static public function autoload($class) {
|
||||
if (0 === strpos($class, 'PhpParser\\')) {
|
||||
if (isset(self::$php7AliasesOldToNew[$class])) {
|
||||
if (self::$runningOnPhp7) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load the new class, alias will be registered afterwards
|
||||
$class = self::$php7AliasesOldToNew[$class];
|
||||
}
|
||||
|
||||
$fileName = dirname(__DIR__) . '/' . strtr($class, '\\', '/') . '.php';
|
||||
if (file_exists($fileName)) {
|
||||
require $fileName;
|
||||
}
|
||||
|
||||
if (isset(self::$php7AliasesNewToOld[$class])) {
|
||||
// New class name was used, register alias for old one, otherwise
|
||||
// it won't be usable in "instanceof" and other non-autoloading places.
|
||||
if (!self::$runningOnPhp7) {
|
||||
class_alias($class, self::$php7AliasesNewToOld[$class]);
|
||||
}
|
||||
}
|
||||
} else if (0 === strpos($class, 'PHPParser_')) {
|
||||
if (isset(self::$oldToNewMap[$class])) {
|
||||
self::registerLegacyAliases();
|
||||
if (isset(self::$nonNamespacedAliases[$class])) {
|
||||
// Register all aliases at once to avoid dependency issues
|
||||
self::registerNonNamespacedAliases();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static function registerLegacyAliases() {
|
||||
foreach (self::$oldToNewMap as $old => $new) {
|
||||
private static function registerNonNamespacedAliases() {
|
||||
foreach (self::$nonNamespacedAliases as $old => $new) {
|
||||
class_alias($new, $old);
|
||||
}
|
||||
}
|
||||
|
||||
private static $oldToNewMap = array(
|
||||
private static $php7AliasesOldToNew = array(
|
||||
'PhpParser\Node\Expr\Cast\Bool' => 'PhpParser\Node\Expr\Cast\Bool_',
|
||||
'PhpParser\Node\Expr\Cast\Int' => 'PhpParser\Node\Expr\Cast\Int_',
|
||||
'PhpParser\Node\Expr\Cast\Object' => 'PhpParser\Node\Expr\Cast\Object_',
|
||||
'PhpParser\Node\Expr\Cast\String' => 'PhpParser\Node\Expr\Cast\String_',
|
||||
'PhpParser\Node\Scalar\String' => 'PhpParser\Node\Scalar\String_',
|
||||
);
|
||||
|
||||
private static $php7AliasesNewToOld = array(
|
||||
'PhpParser\Node\Expr\Cast\Bool_' => 'PhpParser\Node\Expr\Cast\Bool',
|
||||
'PhpParser\Node\Expr\Cast\Int_' => 'PhpParser\Node\Expr\Cast\Int',
|
||||
'PhpParser\Node\Expr\Cast\Object_' => 'PhpParser\Node\Expr\Cast\Object',
|
||||
'PhpParser\Node\Expr\Cast\String_' => 'PhpParser\Node\Expr\Cast\String',
|
||||
'PhpParser\Node\Scalar\String_' => 'PhpParser\Node\Scalar\String',
|
||||
);
|
||||
|
||||
private static $nonNamespacedAliases = array(
|
||||
'PHPParser_Builder' => 'PhpParser\Builder',
|
||||
'PHPParser_BuilderAbstract' => 'PhpParser\BuilderAbstract',
|
||||
'PHPParser_BuilderFactory' => 'PhpParser\BuilderFactory',
|
||||
@@ -141,11 +186,11 @@ class Autoloader
|
||||
|
||||
'PHPParser_Node_Expr_Cast' => 'PhpParser\Node\Expr\Cast',
|
||||
'PHPParser_Node_Expr_Cast_Array' => 'PhpParser\Node\Expr\Cast\Array_',
|
||||
'PHPParser_Node_Expr_Cast_Bool' => 'PhpParser\Node\Expr\Cast\Bool',
|
||||
'PHPParser_Node_Expr_Cast_Bool' => 'PhpParser\Node\Expr\Cast\Bool_',
|
||||
'PHPParser_Node_Expr_Cast_Double' => 'PhpParser\Node\Expr\Cast\Double',
|
||||
'PHPParser_Node_Expr_Cast_Int' => 'PhpParser\Node\Expr\Cast\Int',
|
||||
'PHPParser_Node_Expr_Cast_Object' => 'PhpParser\Node\Expr\Cast\Object',
|
||||
'PHPParser_Node_Expr_Cast_String' => 'PhpParser\Node\Expr\Cast\String',
|
||||
'PHPParser_Node_Expr_Cast_Int' => 'PhpParser\Node\Expr\Cast\Int_',
|
||||
'PHPParser_Node_Expr_Cast_Object' => 'PhpParser\Node\Expr\Cast\Object_',
|
||||
'PHPParser_Node_Expr_Cast_String' => 'PhpParser\Node\Expr\Cast\String_',
|
||||
'PHPParser_Node_Expr_Cast_Unset' => 'PhpParser\Node\Expr\Cast\Unset_',
|
||||
|
||||
'PHPParser_Node_Expr_BitwiseAnd' => 'PhpParser\Node\Expr\BinaryOp\BitwiseAnd',
|
||||
@@ -223,8 +268,8 @@ class Autoloader
|
||||
'PHPParser_Node_Scalar_DNumber' => 'PhpParser\Node\Scalar\DNumber',
|
||||
'PHPParser_Node_Scalar_Encapsed' => 'PhpParser\Node\Scalar\Encapsed',
|
||||
'PHPParser_Node_Scalar_LNumber' => 'PhpParser\Node\Scalar\LNumber',
|
||||
'PHPParser_Node_Scalar_String' => 'PhpParser\Node\Scalar\String',
|
||||
'PHPParser_Node_Scalar_String' => 'PhpParser\Node\Scalar\String_',
|
||||
);
|
||||
}
|
||||
|
||||
class_alias('PhpParser\Autoloader', 'PHPParser_Autoloader');
|
||||
class_alias('PhpParser\Autoloader', 'PHPParser_Autoloader');
|
||||
|
@@ -116,10 +116,10 @@ class Method extends FunctionLike
|
||||
*/
|
||||
public function getNode() {
|
||||
return new Stmt\ClassMethod($this->name, array(
|
||||
'type' => $this->type !== 0 ? $this->type : Stmt\Class_::MODIFIER_PUBLIC,
|
||||
'type' => $this->type,
|
||||
'byRef' => $this->returnByRef,
|
||||
'params' => $this->params,
|
||||
'stmts' => $this->stmts,
|
||||
), $this->attributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,10 +14,10 @@ class Namespace_ extends PhpParser\BuilderAbstract
|
||||
/**
|
||||
* Creates a namespace builder.
|
||||
*
|
||||
* @param Node\Name|string $name Name of the namespace
|
||||
* @param Node\Name|string|null $name Name of the namespace
|
||||
*/
|
||||
public function __construct($name) {
|
||||
$this->name = $this->normalizeName($name);
|
||||
$this->name = null !== $name ? $this->normalizeName($name) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -9,6 +9,7 @@ use PhpParser\Node\Stmt;
|
||||
class Trait_ extends Declaration
|
||||
{
|
||||
protected $name;
|
||||
protected $properties = array();
|
||||
protected $methods = array();
|
||||
|
||||
/**
|
||||
@@ -29,12 +30,15 @@ class Trait_ extends Declaration
|
||||
*/
|
||||
public function addStmt($stmt) {
|
||||
$stmt = $this->normalizeNode($stmt);
|
||||
if (!$stmt instanceof Stmt\ClassMethod) {
|
||||
|
||||
if ($stmt instanceof Stmt\Property) {
|
||||
$this->properties[] = $stmt;
|
||||
} else if ($stmt instanceof Stmt\ClassMethod) {
|
||||
$this->methods[] = $stmt;
|
||||
} else {
|
||||
throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType()));
|
||||
}
|
||||
|
||||
$this->methods[] = $stmt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -44,6 +48,8 @@ class Trait_ extends Declaration
|
||||
* @return Stmt\Trait_ The built interface node
|
||||
*/
|
||||
public function getNode() {
|
||||
return new Stmt\Trait_($this->name, $this->methods, $this->attributes);
|
||||
return new Stmt\Trait_(
|
||||
$this->name, array_merge($this->properties, $this->methods), $this->attributes
|
||||
);
|
||||
}
|
||||
}
|
||||
|
58
lib/PhpParser/Builder/Use_.php
Normal file
58
lib/PhpParser/Builder/Use_.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Builder;
|
||||
|
||||
use PhpParser\BuilderAbstract;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt;
|
||||
|
||||
/**
|
||||
* @method $this as(string $alias) Sets alias for used name.
|
||||
*/
|
||||
class Use_ extends BuilderAbstract {
|
||||
protected $name;
|
||||
protected $type;
|
||||
protected $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
|
||||
*/
|
||||
public function __construct($name, $type) {
|
||||
$this->name = $this->normalizeName($name);
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets alias for used name.
|
||||
*
|
||||
* @param string $alias Alias to use (last component of full name by default)
|
||||
*
|
||||
* @return $this The builder instance (for fluid interface)
|
||||
*/
|
||||
protected function as_($alias) {
|
||||
$this->alias = $alias;
|
||||
return $this;
|
||||
}
|
||||
public function __call($name, $args) {
|
||||
if (method_exists($this, $name . '_')) {
|
||||
return call_user_func_array(array($this, $name . '_'), $args);
|
||||
}
|
||||
|
||||
throw new \LogicException(sprintf('Method "%s" does not exist', $name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the built node.
|
||||
*
|
||||
* @return Node The built node
|
||||
*/
|
||||
public function getNode() {
|
||||
$alias = null !== $this->alias ? $this->alias : $this->name->getLast();
|
||||
return new Stmt\Use_(array(
|
||||
new Stmt\UseUse($this->name, $alias)
|
||||
), $this->type);
|
||||
}
|
||||
}
|
@@ -77,7 +77,7 @@ abstract class BuilderAbstract implements Builder {
|
||||
} elseif (is_float($value)) {
|
||||
return new Scalar\DNumber($value);
|
||||
} elseif (is_string($value)) {
|
||||
return new Scalar\String($value);
|
||||
return new Scalar\String_($value);
|
||||
} elseif (is_array($value)) {
|
||||
$items = array();
|
||||
$lastKey = -1;
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace PhpParser;
|
||||
|
||||
use PhpParser\Builder;
|
||||
use PhpParser\Node\Stmt\Use_;
|
||||
|
||||
/**
|
||||
* The following methods use reserved keywords, so their implementation is defined with an underscore and made available
|
||||
@@ -13,13 +14,14 @@ use PhpParser\Builder;
|
||||
* @method Builder\Interface_ interface(string $name) Creates an interface builder.
|
||||
* @method Builder\Trait_ trait(string $name) Creates a trait builder.
|
||||
* @method Builder\Function_ function(string $name) Creates a function builder.
|
||||
* @method Builder\Use_ use(string $name) Creates a namespace/class use builder.
|
||||
*/
|
||||
class BuilderFactory
|
||||
{
|
||||
/**
|
||||
* Creates a namespace builder.
|
||||
*
|
||||
* @param string|Node\Name $name Name of the namespace
|
||||
* @param null|string|Node\Name $name Name of the namespace
|
||||
*
|
||||
* @return Builder\Namespace_ The created namespace builder
|
||||
*/
|
||||
@@ -104,6 +106,17 @@ class BuilderFactory
|
||||
return new Builder\Function_($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a namespace/class use builder.
|
||||
*
|
||||
* @param string|Node\Name Name to alias
|
||||
*
|
||||
* @return Builder\Use_ The create use builder
|
||||
*/
|
||||
protected function _use($name) {
|
||||
return new Builder\Use_($name, Use_::TYPE_NORMAL);
|
||||
}
|
||||
|
||||
public function __call($name, array $args) {
|
||||
if (method_exists($this, '_' . $name)) {
|
||||
return call_user_func_array(array($this, '_' . $name), $args);
|
||||
|
@@ -5,17 +5,22 @@ namespace PhpParser;
|
||||
class Error extends \RuntimeException
|
||||
{
|
||||
protected $rawMessage;
|
||||
protected $rawLine;
|
||||
protected $attributes;
|
||||
|
||||
/**
|
||||
* Creates an Exception signifying a parse error.
|
||||
*
|
||||
* @param string $message Error message
|
||||
* @param int $line Error line in PHP file
|
||||
* @param string $message Error message
|
||||
* @param array|int $attributes Attributes of node/token where error occurred
|
||||
* (or start line of error -- deprecated)
|
||||
*/
|
||||
public function __construct($message, $line = -1) {
|
||||
public function __construct($message, $attributes = array()) {
|
||||
$this->rawMessage = (string) $message;
|
||||
$this->rawLine = (int) $line;
|
||||
if (is_array($attributes)) {
|
||||
$this->attributes = $attributes;
|
||||
} else {
|
||||
$this->attributes = array('startLine' => $attributes);
|
||||
}
|
||||
$this->updateMessage();
|
||||
}
|
||||
|
||||
@@ -28,6 +33,34 @@ class Error extends \RuntimeException
|
||||
return $this->rawMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the line the error starts in.
|
||||
*
|
||||
* @return int Error start line
|
||||
*/
|
||||
public function getStartLine() {
|
||||
return isset($this->attributes['startLine']) ? $this->attributes['startLine'] : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the line the error ends in.
|
||||
*
|
||||
* @return int Error end line
|
||||
*/
|
||||
public function getEndLine() {
|
||||
return isset($this->attributes['endLine']) ? $this->attributes['endLine'] : -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the attributes of the node/token the error occurred at.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes() {
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the line of the PHP file the error occurred in.
|
||||
*
|
||||
@@ -39,22 +72,65 @@ class Error extends \RuntimeException
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the error line in the PHP file.
|
||||
* Sets the line the error starts in.
|
||||
*
|
||||
* @return int Error line in the PHP file
|
||||
* @param int $line Error start line
|
||||
*/
|
||||
public function getRawLine() {
|
||||
return $this->rawLine;
|
||||
public function setStartLine($line) {
|
||||
$this->attributes['startLine'] = (int) $line;
|
||||
$this->updateMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the line of the PHP file the error occurred in.
|
||||
* Returns whether the error has start and end column information.
|
||||
*
|
||||
* @param int $line Error line in the PHP file
|
||||
* For column information enable the startFilePos and endFilePos in the lexer options.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function setRawLine($line) {
|
||||
$this->rawLine = (int) $line;
|
||||
$this->updateMessage();
|
||||
public function hasColumnInfo() {
|
||||
return isset($this->attributes['startFilePos']) && isset($this->attributes['endFilePos']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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($code) {
|
||||
if (!$this->hasColumnInfo()) {
|
||||
throw new \RuntimeException('Error does not have column information');
|
||||
}
|
||||
|
||||
return $this->toColumn($code, $this->attributes['startFilePos']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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($code) {
|
||||
if (!$this->hasColumnInfo()) {
|
||||
throw new \RuntimeException('Error does not have column information');
|
||||
}
|
||||
|
||||
return $this->toColumn($code, $this->attributes['endFilePos']);
|
||||
}
|
||||
|
||||
private function toColumn($code, $pos) {
|
||||
if ($pos > strlen($code)) {
|
||||
throw new \RuntimeException('Invalid position information');
|
||||
}
|
||||
|
||||
$lineStartPos = strrpos($code, "\n", $pos - strlen($code));
|
||||
if (false === $lineStartPos) {
|
||||
$lineStartPos = -1;
|
||||
}
|
||||
|
||||
return $pos - $lineStartPos;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,10 +139,20 @@ class Error extends \RuntimeException
|
||||
protected function updateMessage() {
|
||||
$this->message = $this->rawMessage;
|
||||
|
||||
if (-1 === $this->rawLine) {
|
||||
if (-1 === $this->getStartLine()) {
|
||||
$this->message .= ' on unknown line';
|
||||
} else {
|
||||
$this->message .= ' on line ' . $this->rawLine;
|
||||
$this->message .= ' on line ' . $this->getStartLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @deprecated Use getStartLine() instead */
|
||||
public function getRawLine() {
|
||||
return $this->getStartLine();
|
||||
}
|
||||
|
||||
/** @deprecated Use setStartLine() instead */
|
||||
public function setRawLine($line) {
|
||||
$this->setStartLine($line);
|
||||
}
|
||||
}
|
||||
|
@@ -48,13 +48,15 @@ class Lexer
|
||||
* @throws Error on lexing errors (unterminated comment or unexpected character)
|
||||
*/
|
||||
public function startLexing($code) {
|
||||
$scream = ini_set('xdebug.scream', 0);
|
||||
$scream = ini_set('xdebug.scream', '0');
|
||||
|
||||
$this->resetErrors();
|
||||
$this->tokens = @token_get_all($code);
|
||||
$this->handleErrors();
|
||||
|
||||
ini_set('xdebug.scream', $scream);
|
||||
if (false !== $scream) {
|
||||
ini_set('xdebug.scream', $scream);
|
||||
}
|
||||
|
||||
$this->code = $code; // keep the code around for __halt_compiler() handling
|
||||
$this->pos = -1;
|
||||
@@ -76,7 +78,7 @@ class Lexer
|
||||
'~^Unterminated comment starting line ([0-9]+)$~',
|
||||
$error['message'], $matches
|
||||
)) {
|
||||
throw new Error('Unterminated comment', $matches[1]);
|
||||
throw new Error('Unterminated comment', (int) $matches[1]);
|
||||
}
|
||||
|
||||
if (preg_match(
|
||||
@@ -121,8 +123,13 @@ class Lexer
|
||||
$startAttributes = array();
|
||||
$endAttributes = array();
|
||||
|
||||
while (isset($this->tokens[++$this->pos])) {
|
||||
$token = $this->tokens[$this->pos];
|
||||
while (1) {
|
||||
if (isset($this->tokens[++$this->pos])) {
|
||||
$token = $this->tokens[$this->pos];
|
||||
} else {
|
||||
// EOF token with ID 0
|
||||
$token = "\0";
|
||||
}
|
||||
|
||||
if (isset($this->usedAttributes['startTokenPos'])) {
|
||||
$startAttributes['startTokenPos'] = $this->pos;
|
||||
@@ -190,10 +197,7 @@ class Lexer
|
||||
}
|
||||
}
|
||||
|
||||
$startAttributes['startLine'] = $this->line;
|
||||
|
||||
// 0 is the EOF token
|
||||
return 0;
|
||||
throw new \RuntimeException('Reached end of lexer loop');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,23 +220,13 @@ class Lexer
|
||||
* @return string Remaining text
|
||||
*/
|
||||
public function handleHaltCompiler() {
|
||||
// get the length of the text before the T_HALT_COMPILER token
|
||||
$textBefore = '';
|
||||
for ($i = 0; $i <= $this->pos; ++$i) {
|
||||
if (is_string($this->tokens[$i])) {
|
||||
$textBefore .= $this->tokens[$i];
|
||||
} else {
|
||||
$textBefore .= $this->tokens[$i][1];
|
||||
}
|
||||
}
|
||||
|
||||
// text after T_HALT_COMPILER, still including ();
|
||||
$textAfter = substr($this->code, strlen($textBefore));
|
||||
$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)) {
|
||||
if (!preg_match('~^\s*\(\s*\)\s*(?:;|\?>\r?\n?)~', $textAfter, $matches)) {
|
||||
throw new Error('__HALT_COMPILER must be followed by "();"');
|
||||
}
|
||||
|
||||
@@ -258,20 +252,23 @@ class Lexer
|
||||
// 256 is the minimum possible token number, as everything below
|
||||
// it is an ASCII value
|
||||
for ($i = 256; $i < 1000; ++$i) {
|
||||
// T_DOUBLE_COLON is equivalent to T_PAAMAYIM_NEKUDOTAYIM
|
||||
if (T_DOUBLE_COLON === $i) {
|
||||
// T_DOUBLE_COLON is equivalent to T_PAAMAYIM_NEKUDOTAYIM
|
||||
$tokenMap[$i] = Parser::T_PAAMAYIM_NEKUDOTAYIM;
|
||||
// T_OPEN_TAG_WITH_ECHO with dropped T_OPEN_TAG results in T_ECHO
|
||||
} elseif(T_OPEN_TAG_WITH_ECHO === $i) {
|
||||
// T_OPEN_TAG_WITH_ECHO with dropped T_OPEN_TAG results in T_ECHO
|
||||
$tokenMap[$i] = Parser::T_ECHO;
|
||||
// T_CLOSE_TAG is equivalent to ';'
|
||||
} elseif(T_CLOSE_TAG === $i) {
|
||||
// T_CLOSE_TAG is equivalent to ';'
|
||||
$tokenMap[$i] = ord(';');
|
||||
// and the others can be mapped directly
|
||||
} elseif ('UNKNOWN' !== ($name = token_name($i))
|
||||
&& defined($name = 'PhpParser\Parser::' . $name)
|
||||
) {
|
||||
$tokenMap[$i] = constant($name);
|
||||
} elseif ('UNKNOWN' !== $name = token_name($i)) {
|
||||
if ('T_HASHBANG' === $name) {
|
||||
// HHVM uses a special token for #! hashbang lines
|
||||
$tokenMap[$i] = Parser::T_INLINE_HTML;
|
||||
} else if (defined($name = 'PhpParser\Parser::' . $name)) {
|
||||
// Other tokens can be mapped directly
|
||||
$tokenMap[$i] = constant($name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,6 +276,10 @@ class Lexer
|
||||
if (defined('T_ONUMBER')) {
|
||||
$tokenMap[T_ONUMBER] = Parser::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] = Parser::T_STRING;
|
||||
}
|
||||
|
||||
return $tokenMap;
|
||||
}
|
||||
|
@@ -12,10 +12,14 @@ class Emulative extends \PhpParser\Lexer
|
||||
protected $newKeywords;
|
||||
protected $inObjectAccess;
|
||||
|
||||
const T_ELLIPSIS = 1001;
|
||||
const T_POW = 1002;
|
||||
const T_POW_EQUAL = 1003;
|
||||
const T_ELLIPSIS = 1001;
|
||||
const T_POW = 1002;
|
||||
const T_POW_EQUAL = 1003;
|
||||
const T_COALESCE = 1004;
|
||||
const T_SPACESHIP = 1005;
|
||||
const T_YIELD_FROM = 1006;
|
||||
|
||||
const PHP_7_0 = '7.0.0dev';
|
||||
const PHP_5_6 = '5.6.0rc1';
|
||||
const PHP_5_5 = '5.5.0beta1';
|
||||
const PHP_5_4 = '5.4.0beta1';
|
||||
@@ -45,11 +49,19 @@ class Emulative extends \PhpParser\Lexer
|
||||
$this->newKeywords += $newKeywords;
|
||||
}
|
||||
|
||||
if (version_compare(PHP_VERSION, self::PHP_5_6, '<')) {
|
||||
$this->tokenMap[self::T_ELLIPSIS] = Parser::T_ELLIPSIS;
|
||||
$this->tokenMap[self::T_POW] = Parser::T_POW;
|
||||
$this->tokenMap[self::T_POW_EQUAL] = Parser::T_POW_EQUAL;
|
||||
if (version_compare(PHP_VERSION, self::PHP_7_0, '>=')) {
|
||||
return;
|
||||
}
|
||||
$this->tokenMap[self::T_COALESCE] = Parser::T_COALESCE;
|
||||
$this->tokenMap[self::T_SPACESHIP] = Parser::T_SPACESHIP;
|
||||
$this->tokenMap[self::T_YIELD_FROM] = Parser::T_YIELD_FROM;
|
||||
|
||||
if (version_compare(PHP_VERSION, self::PHP_5_6, '>=')) {
|
||||
return;
|
||||
}
|
||||
$this->tokenMap[self::T_ELLIPSIS] = Parser::T_ELLIPSIS;
|
||||
$this->tokenMap[self::T_POW] = Parser::T_POW;
|
||||
$this->tokenMap[self::T_POW_EQUAL] = Parser::T_POW_EQUAL;
|
||||
}
|
||||
|
||||
public function startLexing($code) {
|
||||
@@ -75,6 +87,17 @@ class Emulative extends \PhpParser\Lexer
|
||||
* inside a string, i.e. a place where they don't have a special meaning).
|
||||
*/
|
||||
protected function preprocessCode($code) {
|
||||
if (version_compare(PHP_VERSION, self::PHP_7_0, '>=')) {
|
||||
return $code;
|
||||
}
|
||||
|
||||
$code = str_replace('??', '~__EMU__COALESCE__~', $code);
|
||||
$code = str_replace('<=>', '~__EMU__SPACESHIP__~', $code);
|
||||
$code = preg_replace_callback('(yield[ \n\r\t]+from)', function($matches) {
|
||||
// Encoding $0 in order to preserve exact whitespace
|
||||
return '~__EMU__YIELDFROM__' . bin2hex($matches[0]) . '__~';
|
||||
}, $code);
|
||||
|
||||
if (version_compare(PHP_VERSION, self::PHP_5_6, '>=')) {
|
||||
return $code;
|
||||
}
|
||||
@@ -110,8 +133,9 @@ class Emulative extends \PhpParser\Lexer
|
||||
if ('BINARY' === $matches[1]) {
|
||||
// the binary number can either be an integer or a double, so return a LNUMBER
|
||||
// or DNUMBER respectively
|
||||
$isInt = is_int(bindec($matches[2]));
|
||||
$replace = array(
|
||||
array(is_int(bindec($matches[2])) ? T_LNUMBER : T_DNUMBER, $matches[2], $this->tokens[$i + 1][2])
|
||||
array($isInt ? T_LNUMBER : T_DNUMBER, $matches[2], $this->tokens[$i + 1][2])
|
||||
);
|
||||
} else if ('ELLIPSIS' === $matches[1]) {
|
||||
$replace = array(
|
||||
@@ -125,9 +149,21 @@ class Emulative extends \PhpParser\Lexer
|
||||
$replace = array(
|
||||
array(self::T_POW_EQUAL, '**=', $this->tokens[$i + 1][2])
|
||||
);
|
||||
} else if ('COALESCE' === $matches[1]) {
|
||||
$replace = array(
|
||||
array(self::T_COALESCE, '??', $this->tokens[$i + 1][2])
|
||||
);
|
||||
} else if ('SPACESHIP' === $matches[1]) {
|
||||
$replace = array(
|
||||
array(self::T_SPACESHIP, '<=>', $this->tokens[$i + 1][2]),
|
||||
);
|
||||
} else if ('YIELDFROM' === $matches[1]) {
|
||||
$content = $this->hex2bin($matches[2]);
|
||||
$replace = array(
|
||||
array(self::T_YIELD_FROM, $content, $this->tokens[$i + 1][2] - substr_count($content, "\n"))
|
||||
);
|
||||
} else {
|
||||
// just ignore all other __EMU__ sequences
|
||||
continue;
|
||||
throw new \RuntimeException('Invalid __EMU__ sequence');
|
||||
}
|
||||
|
||||
array_splice($this->tokens, $i, 3, $replace);
|
||||
@@ -159,11 +195,22 @@ class Emulative extends \PhpParser\Lexer
|
||||
return '**';
|
||||
} else if ('POWEQUAL' === $matches[1]) {
|
||||
return '**=';
|
||||
} else if ('COALESCE' === $matches[1]) {
|
||||
return '??';
|
||||
} else if ('SPACESHIP' === $matches[1]) {
|
||||
return '<=>';
|
||||
} else if ('YIELDFROM' === $matches[1]) {
|
||||
return $this->hex2bin($matches[2]);
|
||||
} else {
|
||||
return $matches[0];
|
||||
}
|
||||
}
|
||||
|
||||
private function hex2bin($str) {
|
||||
// TODO Drop when removing support for PHP 5.3
|
||||
return pack('H*', $str);
|
||||
}
|
||||
|
||||
public function getNextToken(&$value = null, &$startAttributes = null, &$endAttributes = null) {
|
||||
$token = parent::getNextToken($value, $startAttributes, $endAttributes);
|
||||
|
||||
@@ -174,11 +221,9 @@ class Emulative extends \PhpParser\Lexer
|
||||
if (isset($this->newKeywords[strtolower($value)])) {
|
||||
return $this->newKeywords[strtolower($value)];
|
||||
}
|
||||
// keep track of whether we currently are in an object access (after ->)
|
||||
} elseif (Parser::T_OBJECT_OPERATOR === $token) {
|
||||
$this->inObjectAccess = true;
|
||||
} else {
|
||||
$this->inObjectAccess = false;
|
||||
// keep track of whether we currently are in an object access (after ->)
|
||||
$this->inObjectAccess = Parser::T_OBJECT_OPERATOR === $token;
|
||||
}
|
||||
|
||||
return $token;
|
||||
|
@@ -4,13 +4,15 @@ namespace PhpParser\Node;
|
||||
|
||||
use PhpParser\NodeAbstract;
|
||||
|
||||
/**
|
||||
* @property Expr $value Value to pass
|
||||
* @property bool $byRef Whether to pass by ref
|
||||
* @property bool $unpack Whether to unpack the argument
|
||||
*/
|
||||
class Arg extends NodeAbstract
|
||||
{
|
||||
/** @var Expr Value to pass */
|
||||
public $value;
|
||||
/** @var bool Whether to pass by ref */
|
||||
public $byRef;
|
||||
/** @var bool Whether to unpack the argument */
|
||||
public $unpack;
|
||||
|
||||
/**
|
||||
* Constructs a function call argument node.
|
||||
*
|
||||
@@ -20,13 +22,13 @@ class Arg extends NodeAbstract
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $value, $byRef = false, $unpack = false, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'value' => $value,
|
||||
'byRef' => $byRef,
|
||||
'unpack' => $unpack,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->value = $value;
|
||||
$this->byRef = $byRef;
|
||||
$this->unpack = $unpack;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('value', 'byRef', 'unpack');
|
||||
}
|
||||
}
|
||||
|
@@ -4,12 +4,13 @@ namespace PhpParser\Node;
|
||||
|
||||
use PhpParser\NodeAbstract;
|
||||
|
||||
/**
|
||||
* @property string $name Name
|
||||
* @property Expr $value Value
|
||||
*/
|
||||
class Const_ extends NodeAbstract
|
||||
{
|
||||
/** @var string Name */
|
||||
public $name;
|
||||
/** @var Expr Value */
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Constructs a const node for use in class const and const statements.
|
||||
*
|
||||
@@ -18,12 +19,12 @@ class Const_ extends NodeAbstract
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, Expr $value, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'name' => $name,
|
||||
'value' => $value,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->name = $name;
|
||||
$this->value = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('name', 'value');
|
||||
}
|
||||
}
|
||||
|
@@ -4,12 +4,13 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $var Variable
|
||||
* @property null|Expr $dim Array index / dim
|
||||
*/
|
||||
class ArrayDimFetch extends Expr
|
||||
{
|
||||
/** @var Expr Variable */
|
||||
public $var;
|
||||
/** @var null|Expr Array index / dim */
|
||||
public $dim;
|
||||
|
||||
/**
|
||||
* Constructs an array index fetch node.
|
||||
*
|
||||
@@ -18,12 +19,12 @@ class ArrayDimFetch extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, Expr $dim = null, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'var' => $var,
|
||||
'dim' => $dim
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->var = $var;
|
||||
$this->dim = $dim;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubnodeNames() {
|
||||
return array('var', 'dim');
|
||||
}
|
||||
}
|
||||
|
@@ -4,13 +4,15 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $value Value
|
||||
* @property null|Expr $key Key
|
||||
* @property bool $byRef Whether to assign by reference
|
||||
*/
|
||||
class ArrayItem extends Expr
|
||||
{
|
||||
/** @var null|Expr Key */
|
||||
public $key;
|
||||
/** @var Expr Value */
|
||||
public $value;
|
||||
/** @var bool Whether to assign by reference */
|
||||
public $byRef;
|
||||
|
||||
/**
|
||||
* Constructs an array item node.
|
||||
*
|
||||
@@ -20,13 +22,13 @@ class ArrayItem extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $value, Expr $key = null, $byRef = false, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'key' => $key,
|
||||
'value' => $value,
|
||||
'byRef' => $byRef
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->key = $key;
|
||||
$this->value = $value;
|
||||
$this->byRef = $byRef;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('key', 'value', 'byRef');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property ArrayItem[] $items Items
|
||||
*/
|
||||
class Array_ extends Expr
|
||||
{
|
||||
/** @var ArrayItem[] Items */
|
||||
public $items;
|
||||
|
||||
/**
|
||||
* Constructs an array node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class Array_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $items = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'items' => $items
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->items = $items;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('items');
|
||||
}
|
||||
}
|
||||
|
@@ -4,12 +4,13 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $var Variable
|
||||
* @property Expr $expr Expression
|
||||
*/
|
||||
class Assign extends Expr
|
||||
{
|
||||
/** @var Expr Variable */
|
||||
public $var;
|
||||
/** @var Expr Expression */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* Constructs an assignment node.
|
||||
*
|
||||
@@ -18,12 +19,12 @@ class Assign extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, Expr $expr, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'var' => $var,
|
||||
'expr' => $expr
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->var = $var;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('var', 'expr');
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,11 @@ use PhpParser\Node\Expr;
|
||||
*/
|
||||
abstract class AssignOp extends Expr
|
||||
{
|
||||
/** @var Expr Variable */
|
||||
public $var;
|
||||
/** @var Expr Expression */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* Constructs a compound assignment operation node.
|
||||
*
|
||||
@@ -18,12 +23,12 @@ abstract class AssignOp extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, Expr $expr, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'var' => $var,
|
||||
'expr' => $expr
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->var = $var;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('var', 'expr');
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,11 @@ use PhpParser\Node\Expr;
|
||||
*/
|
||||
class AssignRef extends Expr
|
||||
{
|
||||
/** @var Expr Variable reference is assigned to */
|
||||
public $var;
|
||||
/** @var Expr Variable which is referenced */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* Constructs an assignment node.
|
||||
*
|
||||
@@ -18,12 +23,12 @@ class AssignRef extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, Expr $expr, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'var' => $var,
|
||||
'expr' => $expr
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->var = $var;
|
||||
$this->expr = $expr;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('var', 'expr');
|
||||
}
|
||||
}
|
||||
|
@@ -4,12 +4,13 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $left The left hand side expression
|
||||
* @property Expr $right The right hand side expression
|
||||
*/
|
||||
abstract class BinaryOp extends Expr
|
||||
{
|
||||
/** @var Expr The left hand side expression */
|
||||
public $left;
|
||||
/** @var Expr The right hand side expression */
|
||||
public $right;
|
||||
|
||||
/**
|
||||
* Constructs a bitwise and node.
|
||||
*
|
||||
@@ -18,12 +19,12 @@ abstract class BinaryOp extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $left, Expr $right, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'left' => $left,
|
||||
'right' => $right
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->left = $left;
|
||||
$this->right = $right;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('left', 'right');
|
||||
}
|
||||
}
|
||||
|
9
lib/PhpParser/Node/Expr/BinaryOp/Coalesce.php
Normal file
9
lib/PhpParser/Node/Expr/BinaryOp/Coalesce.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Node\Expr\BinaryOp;
|
||||
|
||||
use PhpParser\Node\Expr\BinaryOp;
|
||||
|
||||
class Coalesce extends BinaryOp
|
||||
{
|
||||
}
|
9
lib/PhpParser/Node/Expr/BinaryOp/Spaceship.php
Normal file
9
lib/PhpParser/Node/Expr/BinaryOp/Spaceship.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Node\Expr\BinaryOp;
|
||||
|
||||
use PhpParser\Node\Expr\BinaryOp;
|
||||
|
||||
class Spaceship extends BinaryOp
|
||||
{
|
||||
}
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $expr Expression
|
||||
*/
|
||||
class BitwiseNot extends Expr
|
||||
{
|
||||
/** @var Expr Expression */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* Constructs a bitwise not node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class BitwiseNot extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'expr' => $expr
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->expr = $expr;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('expr');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $expr Expression
|
||||
*/
|
||||
class BooleanNot extends Expr
|
||||
{
|
||||
/** @var Expr Expression */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* Constructs a boolean not node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class BooleanNot extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'expr' => $expr
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->expr = $expr;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('expr');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $expr Expression
|
||||
*/
|
||||
abstract class Cast extends Expr
|
||||
{
|
||||
/** @var Expr Expression */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* Constructs a cast node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ abstract class Cast extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'expr' => $expr
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->expr = $expr;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('expr');
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,6 @@ namespace PhpParser\Node\Expr\Cast;
|
||||
|
||||
use PhpParser\Node\Expr\Cast;
|
||||
|
||||
class String extends Cast
|
||||
class Bool_ extends Cast
|
||||
{
|
||||
}
|
||||
}
|
@@ -6,4 +6,4 @@ use PhpParser\Node\Expr\Cast;
|
||||
|
||||
class Double extends Cast
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,6 @@ namespace PhpParser\Node\Expr\Cast;
|
||||
|
||||
use PhpParser\Node\Expr\Cast;
|
||||
|
||||
class Bool extends Cast
|
||||
class Int_ extends Cast
|
||||
{
|
||||
}
|
||||
}
|
@@ -4,6 +4,6 @@ namespace PhpParser\Node\Expr\Cast;
|
||||
|
||||
use PhpParser\Node\Expr\Cast;
|
||||
|
||||
class Int extends Cast
|
||||
class Object_ extends Cast
|
||||
{
|
||||
}
|
||||
}
|
@@ -4,6 +4,6 @@ namespace PhpParser\Node\Expr\Cast;
|
||||
|
||||
use PhpParser\Node\Expr\Cast;
|
||||
|
||||
class Object extends Cast
|
||||
class String_ extends Cast
|
||||
{
|
||||
}
|
||||
}
|
@@ -5,12 +5,13 @@ namespace PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Name|Expr $class Class name
|
||||
* @property string $name Constant name
|
||||
*/
|
||||
class ClassConstFetch extends Expr
|
||||
{
|
||||
/** @var Name|Expr Class name */
|
||||
public $class;
|
||||
/** @var string Constant name */
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Constructs a class const fetch node.
|
||||
*
|
||||
@@ -19,12 +20,12 @@ class ClassConstFetch extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($class, $name, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'class' => $class,
|
||||
'name' => $name
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->class = $class;
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('class', 'name');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $expr Expression
|
||||
*/
|
||||
class Clone_ extends Expr
|
||||
{
|
||||
/** @var Expr Expression */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* Constructs a clone node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class Clone_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'expr' => $expr
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->expr = $expr;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('expr');
|
||||
}
|
||||
}
|
||||
|
@@ -4,37 +4,62 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
|
||||
/**
|
||||
* @property Node[] $stmts Statements
|
||||
* @property Node\Param[] $params Parameters
|
||||
* @property ClosureUse[] $uses use()s
|
||||
* @property bool $byRef Whether to return by reference
|
||||
* @property bool $static Whether the closure is static
|
||||
*/
|
||||
class Closure extends Expr
|
||||
class Closure extends Expr implements FunctionLike
|
||||
{
|
||||
/** @var bool Whether the closure is static */
|
||||
public $static;
|
||||
/** @var bool Whether to return by reference */
|
||||
public $byRef;
|
||||
/** @var Node\Param[] Parameters */
|
||||
public $params;
|
||||
/** @var ClosureUse[] use()s */
|
||||
public $uses;
|
||||
/** @var null|string|Node\Name Return type */
|
||||
public $returnType;
|
||||
/** @var Node[] Statements */
|
||||
public $stmts;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 'stmts' => array(): Statements
|
||||
* '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
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $subNodes = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'static' => isset($subNodes['static']) ? $subNodes['static'] : false,
|
||||
'byRef' => isset($subNodes['byRef']) ? $subNodes['byRef'] : false,
|
||||
'params' => isset($subNodes['params']) ? $subNodes['params'] : array(),
|
||||
'uses' => isset($subNodes['uses']) ? $subNodes['uses'] : array(),
|
||||
'stmts' => isset($subNodes['stmts']) ? $subNodes['stmts'] : array(),
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->static = isset($subNodes['static']) ? $subNodes['static'] : false;
|
||||
$this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
|
||||
$this->params = isset($subNodes['params']) ? $subNodes['params'] : array();
|
||||
$this->uses = isset($subNodes['uses']) ? $subNodes['uses'] : array();
|
||||
$this->returnType = isset($subNodes['returnType']) ? $subNodes['returnType'] : null;
|
||||
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('static', 'byRef', 'params', 'uses', 'returnType', 'stmts');
|
||||
}
|
||||
|
||||
public function returnsByRef() {
|
||||
return $this->byRef;
|
||||
}
|
||||
|
||||
public function getParams() {
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
public function getReturnType() {
|
||||
return $this->returnType;
|
||||
}
|
||||
|
||||
public function getStmts() {
|
||||
return $this->stmts;
|
||||
}
|
||||
}
|
||||
|
@@ -4,12 +4,13 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property string $var Name of variable
|
||||
* @property bool $byRef Whether to use by reference
|
||||
*/
|
||||
class ClosureUse extends Expr
|
||||
{
|
||||
/** @var string Name of variable */
|
||||
public $var;
|
||||
/** @var bool Whether to use by reference */
|
||||
public $byRef;
|
||||
|
||||
/**
|
||||
* Constructs a closure use node.
|
||||
*
|
||||
@@ -18,12 +19,12 @@ class ClosureUse extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($var, $byRef = false, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'var' => $var,
|
||||
'byRef' => $byRef
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->var = $var;
|
||||
$this->byRef = $byRef;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('var', 'byRef');
|
||||
}
|
||||
}
|
||||
|
@@ -5,11 +5,11 @@ namespace PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Name $name Constant name
|
||||
*/
|
||||
class ConstFetch extends Expr
|
||||
{
|
||||
/** @var Name Constant name */
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Constructs a const fetch node.
|
||||
*
|
||||
@@ -17,11 +17,11 @@ class ConstFetch extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Name $name, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'name' => $name
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('name');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $expr Expression
|
||||
*/
|
||||
class Empty_ extends Expr
|
||||
{
|
||||
/** @var Expr Expression */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* Constructs an empty() node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class Empty_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'expr' => $expr
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->expr = $expr;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('expr');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $expr Expression
|
||||
*/
|
||||
class ErrorSuppress extends Expr
|
||||
{
|
||||
/** @var Expr Expression */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* Constructs an error suppress node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class ErrorSuppress extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'expr' => $expr
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->expr = $expr;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('expr');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $expr Expression
|
||||
*/
|
||||
class Eval_ extends Expr
|
||||
{
|
||||
/** @var Expr Expression */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* Constructs an eval() node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class Eval_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'expr' => $expr
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->expr = $expr;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('expr');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property null|Expr $expr Expression
|
||||
*/
|
||||
class Exit_ extends Expr
|
||||
{
|
||||
/** @var null|Expr Expression */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* Constructs an exit() node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class Exit_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr = null, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'expr' => $expr
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->expr = $expr;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('expr');
|
||||
}
|
||||
}
|
||||
|
@@ -5,12 +5,13 @@ namespace PhpParser\Node\Expr;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Node\Name|Expr $name Function name
|
||||
* @property Node\Arg[] $args Arguments
|
||||
*/
|
||||
class FuncCall extends Expr
|
||||
{
|
||||
/** @var Node\Name|Expr Function name */
|
||||
public $name;
|
||||
/** @var Node\Arg[] Arguments */
|
||||
public $args;
|
||||
|
||||
/**
|
||||
* Constructs a function call node.
|
||||
*
|
||||
@@ -19,12 +20,12 @@ class FuncCall extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, array $args = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'name' => $name,
|
||||
'args' => $args
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->name = $name;
|
||||
$this->args = $args;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('name', 'args');
|
||||
}
|
||||
}
|
||||
|
@@ -4,10 +4,6 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $expr Expression
|
||||
* @property int $type Type of include
|
||||
*/
|
||||
class Include_ extends Expr
|
||||
{
|
||||
const TYPE_INCLUDE = 1;
|
||||
@@ -15,6 +11,11 @@ class Include_ extends Expr
|
||||
const TYPE_REQUIRE = 3;
|
||||
const TYPE_REQUIRE_ONCE = 4;
|
||||
|
||||
/** @var Expr Expression */
|
||||
public $expr;
|
||||
/** @var int Type of include */
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* Constructs an include node.
|
||||
*
|
||||
@@ -23,12 +24,12 @@ class Include_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, $type, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'expr' => $expr,
|
||||
'type' => $type
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->expr = $expr;
|
||||
$this->type = $type;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('expr', 'type');
|
||||
}
|
||||
}
|
||||
|
@@ -5,12 +5,13 @@ namespace PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $expr Expression
|
||||
* @property Name|Expr $class Class name
|
||||
*/
|
||||
class Instanceof_ extends Expr
|
||||
{
|
||||
/** @var Expr Expression */
|
||||
public $expr;
|
||||
/** @var Name|Expr Class name */
|
||||
public $class;
|
||||
|
||||
/**
|
||||
* Constructs an instanceof check node.
|
||||
*
|
||||
@@ -19,12 +20,12 @@ class Instanceof_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, $class, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'expr' => $expr,
|
||||
'class' => $class
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->expr = $expr;
|
||||
$this->class = $class;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('expr', 'class');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr[] $vars Variables
|
||||
*/
|
||||
class Isset_ extends Expr
|
||||
{
|
||||
/** @var Expr[] Variables */
|
||||
public $vars;
|
||||
|
||||
/**
|
||||
* Constructs an array node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class Isset_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $vars, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'vars' => $vars
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->vars = $vars;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('vars');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr[] $vars List of variables to assign to
|
||||
*/
|
||||
class List_ extends Expr
|
||||
{
|
||||
/** @var Expr[] List of variables to assign to */
|
||||
public $vars;
|
||||
|
||||
/**
|
||||
* Constructs a list() destructuring node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class List_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $vars, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'vars' => $vars,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->vars = $vars;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('vars');
|
||||
}
|
||||
}
|
||||
|
@@ -5,13 +5,15 @@ namespace PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $var Variable holding object
|
||||
* @property string|Expr $name Method name
|
||||
* @property Arg[] $args Arguments
|
||||
*/
|
||||
class MethodCall extends Expr
|
||||
{
|
||||
/** @var Expr Variable holding object */
|
||||
public $var;
|
||||
/** @var string|Expr Method name */
|
||||
public $name;
|
||||
/** @var Arg[] Arguments */
|
||||
public $args;
|
||||
|
||||
/**
|
||||
* Constructs a function call node.
|
||||
*
|
||||
@@ -21,13 +23,13 @@ class MethodCall extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, $name, array $args = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'var' => $var,
|
||||
'name' => $name,
|
||||
'args' => $args
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->var = $var;
|
||||
$this->name = $name;
|
||||
$this->args = $args;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('var', 'name', 'args');
|
||||
}
|
||||
}
|
||||
|
@@ -5,26 +5,27 @@ namespace PhpParser\Node\Expr;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Node\Name|Expr $class Class name
|
||||
* @property Node\Arg[] $args Arguments
|
||||
*/
|
||||
class New_ extends Expr
|
||||
{
|
||||
/** @var Node\Name|Expr|Node\Stmt\Class_ Class name */
|
||||
public $class;
|
||||
/** @var Node\Arg[] Arguments */
|
||||
public $args;
|
||||
|
||||
/**
|
||||
* Constructs a function call node.
|
||||
*
|
||||
* @param Node\Name|Expr $class Class name
|
||||
* @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 Node\Arg[] $args Arguments
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($class, array $args = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'class' => $class,
|
||||
'args' => $args
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->class = $class;
|
||||
$this->args = $args;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('class', 'args');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $var Variable
|
||||
*/
|
||||
class PostDec extends Expr
|
||||
{
|
||||
/** @var Expr Variable */
|
||||
public $var;
|
||||
|
||||
/**
|
||||
* Constructs a post decrement node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class PostDec extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'var' => $var
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->var = $var;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('var');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $var Variable
|
||||
*/
|
||||
class PostInc extends Expr
|
||||
{
|
||||
/** @var Expr Variable */
|
||||
public $var;
|
||||
|
||||
/**
|
||||
* Constructs a post increment node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class PostInc extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'var' => $var
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->var = $var;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('var');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $var Variable
|
||||
*/
|
||||
class PreDec extends Expr
|
||||
{
|
||||
/** @var Expr Variable */
|
||||
public $var;
|
||||
|
||||
/**
|
||||
* Constructs a pre decrement node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class PreDec extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'var' => $var
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->var = $var;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('var');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $var Variable
|
||||
*/
|
||||
class PreInc extends Expr
|
||||
{
|
||||
/** @var Expr Variable */
|
||||
public $var;
|
||||
|
||||
/**
|
||||
* Constructs a pre increment node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class PreInc extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'var' => $var
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->var = $var;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('var');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $expr Expression
|
||||
*/
|
||||
class Print_ extends Expr
|
||||
{
|
||||
/** @var Expr Expression */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* Constructs an print() node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class Print_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'expr' => $expr
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->expr = $expr;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('expr');
|
||||
}
|
||||
}
|
||||
|
@@ -4,12 +4,13 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $var Variable holding object
|
||||
* @property string|Expr $name Property Name
|
||||
*/
|
||||
class PropertyFetch extends Expr
|
||||
{
|
||||
/** @var Expr Variable holding object */
|
||||
public $var;
|
||||
/** @var string|Expr Property name */
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Constructs a function call node.
|
||||
*
|
||||
@@ -18,12 +19,12 @@ class PropertyFetch extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $var, $name, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'var' => $var,
|
||||
'name' => $name
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->var = $var;
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('var', 'name');
|
||||
}
|
||||
}
|
||||
|
@@ -4,23 +4,23 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property array $parts Encapsed string array
|
||||
*/
|
||||
class ShellExec extends Expr
|
||||
{
|
||||
/** @var array Encapsed string array */
|
||||
public $parts;
|
||||
|
||||
/**
|
||||
* Constructs a shell exec (backtick) node.
|
||||
*
|
||||
* @param array $parts Encapsed string array
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($parts, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'parts' => $parts
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
public function __construct(array $parts, array $attributes = array()) {
|
||||
parent::__construct(null, $attributes);
|
||||
$this->parts = $parts;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('parts');
|
||||
}
|
||||
}
|
||||
|
@@ -5,13 +5,15 @@ namespace PhpParser\Node\Expr;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Node\Name|Expr $class Class name
|
||||
* @property string|Expr $name Method name
|
||||
* @property Node\Arg[] $args Arguments
|
||||
*/
|
||||
class StaticCall extends Expr
|
||||
{
|
||||
/** @var Node\Name|Expr Class name */
|
||||
public $class;
|
||||
/** @var string|Expr Method name */
|
||||
public $name;
|
||||
/** @var Node\Arg[] Arguments */
|
||||
public $args;
|
||||
|
||||
/**
|
||||
* Constructs a static method call node.
|
||||
*
|
||||
@@ -21,13 +23,13 @@ class StaticCall extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($class, $name, array $args = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'class' => $class,
|
||||
'name' => $name,
|
||||
'args' => $args
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->class = $class;
|
||||
$this->name = $name;
|
||||
$this->args = $args;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('class', 'name', 'args');
|
||||
}
|
||||
}
|
||||
|
@@ -5,12 +5,13 @@ namespace PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Name|Expr $class Class name
|
||||
* @property string|Expr $name Property name
|
||||
*/
|
||||
class StaticPropertyFetch extends Expr
|
||||
{
|
||||
/** @var Name|Expr Class name */
|
||||
public $class;
|
||||
/** @var string|Expr Property name */
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Constructs a static property fetch node.
|
||||
*
|
||||
@@ -19,12 +20,12 @@ class StaticPropertyFetch extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($class, $name, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'class' => $class,
|
||||
'name' => $name
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->class = $class;
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('class', 'name');
|
||||
}
|
||||
}
|
||||
|
@@ -4,13 +4,15 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $cond Condition
|
||||
* @property null|Expr $if Expression for true
|
||||
* @property Expr $else Expression for false
|
||||
*/
|
||||
class Ternary extends Expr
|
||||
{
|
||||
/** @var Expr Condition */
|
||||
public $cond;
|
||||
/** @var null|Expr Expression for true */
|
||||
public $if;
|
||||
/** @var Expr Expression for false */
|
||||
public $else;
|
||||
|
||||
/**
|
||||
* Constructs a ternary operator node.
|
||||
*
|
||||
@@ -20,13 +22,13 @@ class Ternary extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $cond, $if, Expr $else, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'cond' => $cond,
|
||||
'if' => $if,
|
||||
'else' => $else
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->cond = $cond;
|
||||
$this->if = $if;
|
||||
$this->else = $else;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('cond', 'if', 'else');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $expr Expression
|
||||
*/
|
||||
class UnaryMinus extends Expr
|
||||
{
|
||||
/** @var Expr Expression */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* Constructs a unary minus node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class UnaryMinus extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'expr' => $expr
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->expr = $expr;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('expr');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property Expr $expr Expression
|
||||
*/
|
||||
class UnaryPlus extends Expr
|
||||
{
|
||||
/** @var Expr Expression */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* Constructs a unary plus node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class UnaryPlus extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'expr' => $expr
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->expr = $expr;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('expr');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property string|Expr $name Name
|
||||
*/
|
||||
class Variable extends Expr
|
||||
{
|
||||
/** @var string|Expr Name */
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Constructs a variable node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class Variable extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'name' => $name
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('name');
|
||||
}
|
||||
}
|
||||
|
26
lib/PhpParser/Node/Expr/YieldFrom.php
Normal file
26
lib/PhpParser/Node/Expr/YieldFrom.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
class YieldFrom extends Expr
|
||||
{
|
||||
/** @var Expr Expression to yield from */
|
||||
public $expr;
|
||||
|
||||
/**
|
||||
* Constructs an "yield from" node.
|
||||
*
|
||||
* @param Expr $expr Expression
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $expr, array $attributes = array()) {
|
||||
parent::__construct(null, $attributes);
|
||||
$this->expr = $expr;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('expr');
|
||||
}
|
||||
}
|
@@ -4,12 +4,13 @@ namespace PhpParser\Node\Expr;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
|
||||
/**
|
||||
* @property null|Expr $value Value expression
|
||||
* @property null|Expr $key Key expression
|
||||
*/
|
||||
class Yield_ extends Expr
|
||||
{
|
||||
/** @var null|Expr Key expression */
|
||||
public $key;
|
||||
/** @var null|Expr Value expression */
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Constructs a yield expression node.
|
||||
*
|
||||
@@ -18,12 +19,12 @@ class Yield_ extends Expr
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Expr $value = null, Expr $key = null, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'key' => $key,
|
||||
'value' => $value,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->key = $key;
|
||||
$this->value = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('key', 'value');
|
||||
}
|
||||
}
|
||||
|
36
lib/PhpParser/Node/FunctionLike.php
Normal file
36
lib/PhpParser/Node/FunctionLike.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Node;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
interface FunctionLike extends Node
|
||||
{
|
||||
/**
|
||||
* Whether to return by reference
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function returnsByRef();
|
||||
|
||||
/**
|
||||
* List of parameters
|
||||
*
|
||||
* @return Node\Param[]
|
||||
*/
|
||||
public function getParams();
|
||||
|
||||
/**
|
||||
* Get the declared return type or null
|
||||
*
|
||||
* @return null|string|Node\Name
|
||||
*/
|
||||
public function getReturnType();
|
||||
|
||||
/**
|
||||
* The function body
|
||||
*
|
||||
* @return Node\Stmt[]
|
||||
*/
|
||||
public function getStmts();
|
||||
}
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node;
|
||||
|
||||
use PhpParser\NodeAbstract;
|
||||
|
||||
/**
|
||||
* @property array $parts Parts of the name
|
||||
*/
|
||||
class Name extends NodeAbstract
|
||||
{
|
||||
/** @var string[] Parts of the name */
|
||||
public $parts;
|
||||
|
||||
/**
|
||||
* Constructs a name node.
|
||||
*
|
||||
@@ -20,12 +20,12 @@ class Name extends NodeAbstract
|
||||
$parts = explode('\\', $parts);
|
||||
}
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'parts' => $parts,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->parts = $parts;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('parts');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,4 +169,4 @@ class Name extends NodeAbstract
|
||||
'When changing a name you need to pass either a string, an array or a Name node'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,15 +5,19 @@ namespace PhpParser\Node;
|
||||
use PhpParser\Error;
|
||||
use PhpParser\NodeAbstract;
|
||||
|
||||
/**
|
||||
* @property null|string|Name $type Typehint
|
||||
* @property bool $byRef Whether is passed by reference
|
||||
* @property bool $variadic Whether this is a variadic argument
|
||||
* @property string $name Name
|
||||
* @property null|Expr $default Default value
|
||||
*/
|
||||
class Param extends NodeAbstract
|
||||
{
|
||||
/** @var null|string|Name Typehint */
|
||||
public $type;
|
||||
/** @var bool Whether parameter is passed by reference */
|
||||
public $byRef;
|
||||
/** @var bool Whether this is a variadic argument */
|
||||
public $variadic;
|
||||
/** @var string Name */
|
||||
public $name;
|
||||
/** @var null|Expr Default value */
|
||||
public $default;
|
||||
|
||||
/**
|
||||
* Constructs a parameter node.
|
||||
*
|
||||
@@ -24,20 +28,20 @@ class Param extends NodeAbstract
|
||||
* @param bool $variadic Whether this is a variadic argument
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, $default = null, $type = null, $byRef = false, $variadic = false, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'type' => $type,
|
||||
'byRef' => $byRef,
|
||||
'variadic' => $variadic,
|
||||
'name' => $name,
|
||||
'default' => $default,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
public function __construct($name, Expr $default = null, $type = null, $byRef = false, $variadic = false, array $attributes = array()) {
|
||||
parent::__construct(null, $attributes);
|
||||
$this->type = $type;
|
||||
$this->byRef = $byRef;
|
||||
$this->variadic = $variadic;
|
||||
$this->name = $name;
|
||||
$this->default = $default;
|
||||
|
||||
if ($variadic && null !== $default) {
|
||||
throw new Error('Variadic parameter cannot have a default value');
|
||||
throw new Error('Variadic parameter cannot have a default value', $default->getAttributes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('type', 'byRef', 'variadic', 'name', 'default');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Scalar;
|
||||
|
||||
use PhpParser\Node\Scalar;
|
||||
|
||||
/**
|
||||
* @property float $value Number value
|
||||
*/
|
||||
class DNumber extends Scalar
|
||||
{
|
||||
/** @var float Number value */
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Constructs a float number scalar node.
|
||||
*
|
||||
@@ -16,12 +16,12 @@ class DNumber extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($value = 0.0, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'value' => $value
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('value');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,4 +61,4 @@ class DNumber extends Scalar
|
||||
// dec
|
||||
return (float) $str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Scalar;
|
||||
|
||||
use PhpParser\Node\Scalar;
|
||||
|
||||
/**
|
||||
* @property array $parts Encaps list
|
||||
*/
|
||||
class Encapsed extends Scalar
|
||||
{
|
||||
/** @var array Encaps list */
|
||||
public $parts;
|
||||
|
||||
/**
|
||||
* Constructs an encapsed string node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class Encapsed extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $parts = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'parts' => $parts
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->parts = $parts;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('parts');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Scalar;
|
||||
|
||||
use PhpParser\Node\Scalar;
|
||||
|
||||
/**
|
||||
* @property int $value Number value
|
||||
*/
|
||||
class LNumber extends Scalar
|
||||
{
|
||||
/** @var int Number value */
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Constructs an integer number scalar node.
|
||||
*
|
||||
@@ -16,12 +16,12 @@ class LNumber extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($value = 0, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'value' => $value
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('value');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,4 +58,4 @@ class LNumber extends Scalar
|
||||
// dec
|
||||
return (int) $str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,11 @@ abstract class MagicConst extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $attributes = array()) {
|
||||
parent::__construct(array(), $attributes);
|
||||
parent::__construct(null, $attributes);
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -21,4 +25,4 @@ abstract class MagicConst extends Scalar
|
||||
* @return string Name of magic constant
|
||||
*/
|
||||
abstract public function getName();
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Scalar;
|
||||
|
||||
use PhpParser\Node\Scalar;
|
||||
|
||||
/**
|
||||
* @property string $value String value
|
||||
*/
|
||||
class String extends Scalar
|
||||
class String_ extends Scalar
|
||||
{
|
||||
/** @var string String value */
|
||||
public $value;
|
||||
|
||||
protected static $replacements = array(
|
||||
'\\' => '\\',
|
||||
'$' => '$',
|
||||
@@ -27,12 +27,12 @@ class String extends Scalar
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($value = '', array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'value' => $value
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('value');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,4 +116,4 @@ class String extends Scalar
|
||||
|
||||
return self::parseEscapeSequences($str, null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
/**
|
||||
* @property null|Node\Expr $num Number of loops to break
|
||||
*/
|
||||
class Break_ extends Node\Stmt
|
||||
{
|
||||
/** @var null|Node\Expr Number of loops to break */
|
||||
public $num;
|
||||
|
||||
/**
|
||||
* Constructs a break node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class Break_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Node\Expr $num = null, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'num' => $num,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->num = $num;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('num');
|
||||
}
|
||||
}
|
||||
|
@@ -4,12 +4,13 @@ namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
/**
|
||||
* @property null|Node\Expr $cond Condition (null for default)
|
||||
* @property Node[] $stmts Statements
|
||||
*/
|
||||
class Case_ extends Node\Stmt
|
||||
{
|
||||
/** @var null|Node\Expr $cond Condition (null for default) */
|
||||
public $cond;
|
||||
/** @var Node[] Statements */
|
||||
public $stmts;
|
||||
|
||||
/**
|
||||
* Constructs a case node.
|
||||
*
|
||||
@@ -18,12 +19,12 @@ class Case_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($cond, array $stmts = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'cond' => $cond,
|
||||
'stmts' => $stmts,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->cond = $cond;
|
||||
$this->stmts = $stmts;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('cond', 'stmts');
|
||||
}
|
||||
}
|
||||
|
@@ -4,13 +4,15 @@ namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
/**
|
||||
* @property Node\Name $type Class of exception
|
||||
* @property string $var Variable for exception
|
||||
* @property Node[] $stmts Statements
|
||||
*/
|
||||
class Catch_ extends Node\Stmt
|
||||
{
|
||||
/** @var Node\Name Class of exception */
|
||||
public $type;
|
||||
/** @var string Variable for exception */
|
||||
public $var;
|
||||
/** @var Node[] Statements */
|
||||
public $stmts;
|
||||
|
||||
/**
|
||||
* Constructs a catch node.
|
||||
*
|
||||
@@ -20,13 +22,13 @@ class Catch_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Node\Name $type, $var, array $stmts = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'type' => $type,
|
||||
'var' => $var,
|
||||
'stmts' => $stmts,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->type = $type;
|
||||
$this->var = $var;
|
||||
$this->stmts = $stmts;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('type', 'var', 'stmts');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
/**
|
||||
* @property Node\Const_[] $consts Constant declarations
|
||||
*/
|
||||
class ClassConst extends Node\Stmt
|
||||
{
|
||||
/** @var Node\Const_[] Constant declarations */
|
||||
public $consts;
|
||||
|
||||
/**
|
||||
* Constructs a class const list node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class ClassConst extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $consts, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'consts' => $consts,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->consts = $consts;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('consts');
|
||||
}
|
||||
}
|
||||
|
44
lib/PhpParser/Node/Stmt/ClassLike.php
Normal file
44
lib/PhpParser/Node/Stmt/ClassLike.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
abstract class ClassLike extends Node\Stmt {
|
||||
/** @var string Name */
|
||||
public $name;
|
||||
/** @var Node[] Statements */
|
||||
public $stmts;
|
||||
|
||||
/**
|
||||
* Gets all methods defined directly in this class/interface/trait
|
||||
*
|
||||
* @return ClassMethod[]
|
||||
*/
|
||||
public function getMethods() {
|
||||
$methods = array();
|
||||
foreach ($this->stmts as $stmt) {
|
||||
if ($stmt instanceof ClassMethod) {
|
||||
$methods[] = $stmt;
|
||||
}
|
||||
}
|
||||
return $methods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets method with the given name defined directly in this class/interface/trait.
|
||||
*
|
||||
* @param string $name Name of the method (compared case-insensitively)
|
||||
*
|
||||
* @return ClassMethod|null Method node or null if the method does not exist
|
||||
*/
|
||||
public function getMethod($name) {
|
||||
$lowerName = strtolower($name);
|
||||
foreach ($this->stmts as $stmt) {
|
||||
if ($stmt instanceof ClassMethod && $lowerName === strtolower($stmt->name)) {
|
||||
return $stmt;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -3,46 +3,44 @@
|
||||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Error;
|
||||
|
||||
/**
|
||||
* @property int $type Type
|
||||
* @property bool $byRef Whether to return by reference
|
||||
* @property string $name Name
|
||||
* @property Node\Param[] $params Parameters
|
||||
* @property Node[] $stmts Statements
|
||||
*/
|
||||
class ClassMethod extends Node\Stmt
|
||||
class ClassMethod extends Node\Stmt implements FunctionLike
|
||||
{
|
||||
/** @var int Type */
|
||||
public $type;
|
||||
/** @var bool Whether to return by reference */
|
||||
public $byRef;
|
||||
/** @var string Name */
|
||||
public $name;
|
||||
/** @var Node\Param[] Parameters */
|
||||
public $params;
|
||||
/** @var null|string|Node\Name Return type */
|
||||
public $returnType;
|
||||
/** @var Node[] Statements */
|
||||
public $stmts;
|
||||
|
||||
/**
|
||||
* Constructs a class method node.
|
||||
*
|
||||
* @param string $name Name
|
||||
* @param array $subNodes Array of the following optional subnodes:
|
||||
* 'type' => MODIFIER_PUBLIC: Type
|
||||
* 'byRef' => false : Whether to return by reference
|
||||
* 'params' => array() : Parameters
|
||||
* 'stmts' => array() : Statements
|
||||
* 'type' => MODIFIER_PUBLIC: Type
|
||||
* 'byRef' => false : Whether to return by reference
|
||||
* 'params' => array() : Parameters
|
||||
* 'returnType' => null : Return type
|
||||
* 'stmts' => array() : Statements
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
|
||||
$type = isset($subNodes['type']) ? $subNodes['type'] : 0;
|
||||
if (0 === ($type & Class_::VISIBILITY_MODIFER_MASK)) {
|
||||
// If no visibility modifier given, PHP defaults to public
|
||||
$type |= Class_::MODIFIER_PUBLIC;
|
||||
}
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'type' => $type,
|
||||
'byRef' => isset($subNodes['byRef']) ? $subNodes['byRef'] : false,
|
||||
'name' => $name,
|
||||
'params' => isset($subNodes['params']) ? $subNodes['params'] : array(),
|
||||
'stmts' => array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : array(),
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->type = isset($subNodes['type']) ? $subNodes['type'] : 0;
|
||||
$this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
|
||||
$this->name = $name;
|
||||
$this->params = isset($subNodes['params']) ? $subNodes['params'] : array();
|
||||
$this->returnType = isset($subNodes['returnType']) ? $subNodes['returnType'] : null;
|
||||
$this->stmts = array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : array();
|
||||
|
||||
if ($this->type & Class_::MODIFIER_STATIC) {
|
||||
switch (strtolower($this->name)) {
|
||||
@@ -56,8 +54,29 @@ class ClassMethod extends Node\Stmt
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('type', 'byRef', 'name', 'params', 'returnType', 'stmts');
|
||||
}
|
||||
|
||||
public function returnsByRef() {
|
||||
return $this->byRef;
|
||||
}
|
||||
|
||||
public function getParams() {
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
public function getReturnType() {
|
||||
return $this->returnType;
|
||||
}
|
||||
|
||||
public function getStmts() {
|
||||
return $this->stmts;
|
||||
}
|
||||
|
||||
public function isPublic() {
|
||||
return (bool) ($this->type & Class_::MODIFIER_PUBLIC);
|
||||
return ($this->type & Class_::MODIFIER_PUBLIC) !== 0
|
||||
|| ($this->type & Class_::VISIBILITY_MODIFER_MASK) === 0;
|
||||
}
|
||||
|
||||
public function isProtected() {
|
||||
|
@@ -5,14 +5,7 @@ namespace PhpParser\Node\Stmt;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Error;
|
||||
|
||||
/**
|
||||
* @property int $type Type
|
||||
* @property string $name Name
|
||||
* @property null|Node\Name $extends Name of extended class
|
||||
* @property Node\Name[] $implements Names of implemented interfaces
|
||||
* @property Node[] $stmts Statements
|
||||
*/
|
||||
class Class_ extends Node\Stmt
|
||||
class Class_ extends ClassLike
|
||||
{
|
||||
const MODIFIER_PUBLIC = 1;
|
||||
const MODIFIER_PROTECTED = 2;
|
||||
@@ -23,6 +16,13 @@ class Class_ extends Node\Stmt
|
||||
|
||||
const VISIBILITY_MODIFER_MASK = 7; // 1 | 2 | 4
|
||||
|
||||
/** @var int Type */
|
||||
public $type;
|
||||
/** @var null|Node\Name Name of extended class */
|
||||
public $extends;
|
||||
/** @var Node\Name[] Names of implemented interfaces */
|
||||
public $implements;
|
||||
|
||||
protected static $specialNames = array(
|
||||
'self' => true,
|
||||
'parent' => true,
|
||||
@@ -32,7 +32,7 @@ class Class_ extends Node\Stmt
|
||||
/**
|
||||
* Constructs a class node.
|
||||
*
|
||||
* @param string $name Name
|
||||
* @param string|null $name Name
|
||||
* @param array $subNodes Array of the following optional subnodes:
|
||||
* 'type' => 0 : Type
|
||||
* 'extends' => null : Name of extended class
|
||||
@@ -41,32 +41,38 @@ class Class_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'type' => isset($subNodes['type']) ? $subNodes['type'] : 0,
|
||||
'name' => $name,
|
||||
'extends' => isset($subNodes['extends']) ? $subNodes['extends'] : null,
|
||||
'implements' => isset($subNodes['implements']) ? $subNodes['implements'] : array(),
|
||||
'stmts' => isset($subNodes['stmts']) ? $subNodes['stmts'] : array(),
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->type = isset($subNodes['type']) ? $subNodes['type'] : 0;
|
||||
$this->name = $name;
|
||||
$this->extends = isset($subNodes['extends']) ? $subNodes['extends'] : null;
|
||||
$this->implements = isset($subNodes['implements']) ? $subNodes['implements'] : array();
|
||||
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
|
||||
|
||||
if (isset(self::$specialNames[(string) $this->name])) {
|
||||
if (null !== $this->name && isset(self::$specialNames[strtolower($this->name)])) {
|
||||
throw new Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->name));
|
||||
}
|
||||
|
||||
if (isset(self::$specialNames[(string) $this->extends])) {
|
||||
throw new Error(sprintf('Cannot use \'%s\' as class name as it is reserved', $this->extends));
|
||||
if (isset(self::$specialNames[strtolower($this->extends)])) {
|
||||
throw new Error(
|
||||
sprintf('Cannot use \'%s\' as class name as it is reserved', $this->extends),
|
||||
$this->extends->getAttributes()
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($this->implements as $interface) {
|
||||
if (isset(self::$specialNames[(string) $interface])) {
|
||||
throw new Error(sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface));
|
||||
if (isset(self::$specialNames[strtolower($interface)])) {
|
||||
throw new Error(
|
||||
sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface),
|
||||
$interface->getAttributes()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('type', 'name', 'extends', 'implements', 'stmts');
|
||||
}
|
||||
|
||||
public function isAbstract() {
|
||||
return (bool) ($this->type & self::MODIFIER_ABSTRACT);
|
||||
}
|
||||
@@ -75,14 +81,8 @@ class Class_ extends Node\Stmt
|
||||
return (bool) ($this->type & self::MODIFIER_FINAL);
|
||||
}
|
||||
|
||||
public function getMethods() {
|
||||
$methods = array();
|
||||
foreach ($this->stmts as $stmt) {
|
||||
if ($stmt instanceof ClassMethod) {
|
||||
$methods[] = $stmt;
|
||||
}
|
||||
}
|
||||
return $methods;
|
||||
public function isAnonymous() {
|
||||
return null === $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
/**
|
||||
* @property Node\Const_[] $consts Constant declarations
|
||||
*/
|
||||
class Const_ extends Node\Stmt
|
||||
{
|
||||
/** @var Node\Const_[] Constant declarations */
|
||||
public $consts;
|
||||
|
||||
/**
|
||||
* Constructs a const list node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class Const_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $consts, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'consts' => $consts,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->consts = $consts;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('consts');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
/**
|
||||
* @property null|Node\Expr $num Number of loops to continue
|
||||
*/
|
||||
class Continue_ extends Node\Stmt
|
||||
{
|
||||
/** @var null|Node\Expr Number of loops to continue */
|
||||
public $num;
|
||||
|
||||
/**
|
||||
* Constructs a continue node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class Continue_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Node\Expr $num = null, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'num' => $num,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->num = $num;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('num');
|
||||
}
|
||||
}
|
||||
|
@@ -4,12 +4,13 @@ namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
/**
|
||||
* @property string $key Key
|
||||
* @property Node\Expr $value Value
|
||||
*/
|
||||
class DeclareDeclare extends Node\Stmt
|
||||
{
|
||||
/** @var string Key */
|
||||
public $key;
|
||||
/** @var Node\Expr Value */
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* Constructs a declare key=>value pair node.
|
||||
*
|
||||
@@ -18,12 +19,12 @@ class DeclareDeclare extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($key, Node\Expr $value, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'key' => $key,
|
||||
'value' => $value,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->key = $key;
|
||||
$this->value = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('key', 'value');
|
||||
}
|
||||
}
|
||||
|
@@ -3,13 +3,13 @@
|
||||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
/**
|
||||
* @property DeclareDeclare[] $declares List of declares
|
||||
* @property Node[] $stmts Statements
|
||||
*/
|
||||
class Declare_ extends Node\Stmt
|
||||
{
|
||||
/** @var DeclareDeclare[] List of declares */
|
||||
public $declares;
|
||||
/** @var Node[] Statements */
|
||||
public $stmts;
|
||||
|
||||
/**
|
||||
* Constructs a declare node.
|
||||
*
|
||||
@@ -18,12 +18,12 @@ class Declare_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $declares, array $stmts, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'declares' => $declares,
|
||||
'stmts' => $stmts,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->declares = $declares;
|
||||
$this->stmts = $stmts;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('declares', 'stmts');
|
||||
}
|
||||
}
|
||||
|
@@ -4,12 +4,13 @@ namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
/**
|
||||
* @property Node\Expr $cond Condition
|
||||
* @property Node[] $stmts Statements
|
||||
*/
|
||||
class Do_ extends Node\Stmt
|
||||
{
|
||||
/** @var Node\Expr Condition */
|
||||
public $cond;
|
||||
/** @var Node[] Statements */
|
||||
public $stmts;
|
||||
|
||||
/**
|
||||
* Constructs a do while node.
|
||||
*
|
||||
@@ -18,12 +19,12 @@ class Do_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Node\Expr $cond, array $stmts = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'cond' => $cond,
|
||||
'stmts' => $stmts,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->cond = $cond;
|
||||
$this->stmts = $stmts;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('cond', 'stmts');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
/**
|
||||
* @property Node\Expr[] $exprs Expressions
|
||||
*/
|
||||
class Echo_ extends Node\Stmt
|
||||
{
|
||||
/** @var Node\Expr[] Expressions */
|
||||
public $exprs;
|
||||
|
||||
/**
|
||||
* Constructs an echo node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class Echo_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $exprs, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'exprs' => $exprs,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->exprs = $exprs;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('exprs');
|
||||
}
|
||||
}
|
||||
|
@@ -4,12 +4,13 @@ namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
/**
|
||||
* @property Node\Expr $cond Condition
|
||||
* @property Node[] $stmts Statements
|
||||
*/
|
||||
class ElseIf_ extends Node\Stmt
|
||||
{
|
||||
/** @var Node\Expr Condition */
|
||||
public $cond;
|
||||
/** @var Node[] Statements */
|
||||
public $stmts;
|
||||
|
||||
/**
|
||||
* Constructs an elseif node.
|
||||
*
|
||||
@@ -18,12 +19,12 @@ class ElseIf_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Node\Expr $cond, array $stmts = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'cond' => $cond,
|
||||
'stmts' => $stmts,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->cond = $cond;
|
||||
$this->stmts = $stmts;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('cond', 'stmts');
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
/**
|
||||
* @property Node[] $stmts Statements
|
||||
*/
|
||||
class Else_ extends Node\Stmt
|
||||
{
|
||||
/** @var Node[] Statements */
|
||||
public $stmts;
|
||||
|
||||
/**
|
||||
* Constructs an else node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class Else_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $stmts = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'stmts' => $stmts,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->stmts = $stmts;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('stmts');
|
||||
}
|
||||
}
|
||||
|
@@ -4,14 +4,17 @@ namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
/**
|
||||
* @property Node\Expr[] $init Init expressions
|
||||
* @property Node\Expr[] $cond Loop conditions
|
||||
* @property Node\Expr[] $loop Loop expressions
|
||||
* @property Node[] $stmts Statements
|
||||
*/
|
||||
class For_ extends Node\Stmt
|
||||
{
|
||||
/** @var Node\Expr[] Init expressions */
|
||||
public $init;
|
||||
/** @var Node\Expr[] Loop conditions */
|
||||
public $cond;
|
||||
/** @var Node\Expr[] Loop expressions */
|
||||
public $loop;
|
||||
/** @var Node[] Statements */
|
||||
public $stmts;
|
||||
|
||||
/**
|
||||
* Constructs a for loop node.
|
||||
*
|
||||
@@ -23,14 +26,14 @@ class For_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $subNodes = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'init' => isset($subNodes['init']) ? $subNodes['init'] : array(),
|
||||
'cond' => isset($subNodes['cond']) ? $subNodes['cond'] : array(),
|
||||
'loop' => isset($subNodes['loop']) ? $subNodes['loop'] : array(),
|
||||
'stmts' => isset($subNodes['stmts']) ? $subNodes['stmts'] : array(),
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->init = isset($subNodes['init']) ? $subNodes['init'] : array();
|
||||
$this->cond = isset($subNodes['cond']) ? $subNodes['cond'] : array();
|
||||
$this->loop = isset($subNodes['loop']) ? $subNodes['loop'] : array();
|
||||
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('init', 'cond', 'loop', 'stmts');
|
||||
}
|
||||
}
|
||||
|
@@ -4,15 +4,19 @@ namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
/**
|
||||
* @property Node\Expr $expr Expression to iterate
|
||||
* @property null|Node\Expr $keyVar Variable to assign key to
|
||||
* @property bool $byRef Whether to assign value by reference
|
||||
* @property Node\Expr $valueVar Variable to assign value to
|
||||
* @property Node[] $stmts Statements
|
||||
*/
|
||||
class Foreach_ extends Node\Stmt
|
||||
{
|
||||
/** @var Node\Expr Expression to iterate */
|
||||
public $expr;
|
||||
/** @var null|Node\Expr Variable to assign key to */
|
||||
public $keyVar;
|
||||
/** @var bool Whether to assign value by reference */
|
||||
public $byRef;
|
||||
/** @var Node\Expr Variable to assign value to */
|
||||
public $valueVar;
|
||||
/** @var Node[] Statements */
|
||||
public $stmts;
|
||||
|
||||
/**
|
||||
* Constructs a foreach node.
|
||||
*
|
||||
@@ -25,15 +29,15 @@ class Foreach_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(Node\Expr $expr, Node\Expr $valueVar, array $subNodes = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'expr' => $expr,
|
||||
'keyVar' => isset($subNodes['keyVar']) ? $subNodes['keyVar'] : null,
|
||||
'byRef' => isset($subNodes['byRef']) ? $subNodes['byRef'] : false,
|
||||
'valueVar' => $valueVar,
|
||||
'stmts' => isset($subNodes['stmts']) ? $subNodes['stmts'] : array(),
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->expr = $expr;
|
||||
$this->keyVar = isset($subNodes['keyVar']) ? $subNodes['keyVar'] : null;
|
||||
$this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
|
||||
$this->valueVar = $valueVar;
|
||||
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('expr', 'keyVar', 'byRef', 'valueVar', 'stmts');
|
||||
}
|
||||
}
|
||||
|
@@ -3,35 +3,58 @@
|
||||
namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
|
||||
/**
|
||||
* @property bool $byRef Whether returns by reference
|
||||
* @property string $name Name
|
||||
* @property Node\Param[] $params Parameters
|
||||
* @property Node[] $stmts Statements
|
||||
*/
|
||||
class Function_ extends Node\Stmt
|
||||
class Function_ extends Node\Stmt implements FunctionLike
|
||||
{
|
||||
/** @var bool Whether function returns by reference */
|
||||
public $byRef;
|
||||
/** @var string Name */
|
||||
public $name;
|
||||
/** @var Node\Param[] Parameters */
|
||||
public $params;
|
||||
/** @var null|string|Node\Name Return type */
|
||||
public $returnType;
|
||||
/** @var Node[] Statements */
|
||||
public $stmts;
|
||||
|
||||
/**
|
||||
* Constructs a function node.
|
||||
*
|
||||
* @param string $name Name
|
||||
* @param array $subNodes Array of the following optional subnodes:
|
||||
* 'byRef' => false : Whether to return by reference
|
||||
* 'params' => array(): Parameters
|
||||
* 'stmts' => array(): Statements
|
||||
* 'byRef' => false : Whether to return by reference
|
||||
* 'params' => array(): Parameters
|
||||
* 'returnType' => null : Return type
|
||||
* 'stmts' => array(): Statements
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct($name, array $subNodes = array(), array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'byRef' => isset($subNodes['byRef']) ? $subNodes['byRef'] : false,
|
||||
'name' => $name,
|
||||
'params' => isset($subNodes['params']) ? $subNodes['params'] : array(),
|
||||
'stmts' => isset($subNodes['stmts']) ? $subNodes['stmts'] : array(),
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->byRef = isset($subNodes['byRef']) ? $subNodes['byRef'] : false;
|
||||
$this->name = $name;
|
||||
$this->params = isset($subNodes['params']) ? $subNodes['params'] : array();
|
||||
$this->returnType = isset($subNodes['returnType']) ? $subNodes['returnType'] : null;
|
||||
$this->stmts = isset($subNodes['stmts']) ? $subNodes['stmts'] : array();
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('byRef', 'name', 'params', 'returnType', 'stmts');
|
||||
}
|
||||
|
||||
public function returnsByRef() {
|
||||
return $this->byRef;
|
||||
}
|
||||
|
||||
public function getParams() {
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
public function getReturnType() {
|
||||
return $this->returnType;
|
||||
}
|
||||
|
||||
public function getStmts() {
|
||||
return $this->stmts;
|
||||
}
|
||||
}
|
||||
|
@@ -4,11 +4,11 @@ namespace PhpParser\Node\Stmt;
|
||||
|
||||
use PhpParser\Node;
|
||||
|
||||
/**
|
||||
* @property Node\Expr[] $vars Variables
|
||||
*/
|
||||
class Global_ extends Node\Stmt
|
||||
{
|
||||
/** @var Node\Expr[] Variables */
|
||||
public $vars;
|
||||
|
||||
/**
|
||||
* Constructs a global variables list node.
|
||||
*
|
||||
@@ -16,11 +16,11 @@ class Global_ extends Node\Stmt
|
||||
* @param array $attributes Additional attributes
|
||||
*/
|
||||
public function __construct(array $vars, array $attributes = array()) {
|
||||
parent::__construct(
|
||||
array(
|
||||
'vars' => $vars,
|
||||
),
|
||||
$attributes
|
||||
);
|
||||
parent::__construct(null, $attributes);
|
||||
$this->vars = $vars;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSubNodeNames() {
|
||||
return array('vars');
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user