updated-packages
This commit is contained in:
@@ -7,6 +7,7 @@ namespace PhpParser;
|
||||
* turn is based on work by Masato Bito.
|
||||
*/
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Cast\Double;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Scalar\Encapsed;
|
||||
@@ -15,6 +16,7 @@ use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassConst;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Enum_;
|
||||
use PhpParser\Node\Stmt\Interface_;
|
||||
use PhpParser\Node\Stmt\Namespace_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
@@ -59,7 +61,7 @@ abstract class ParserAbstract implements Parser
|
||||
|
||||
/** @var int[] Map of states to a displacement into the $action table. The corresponding action for this
|
||||
* state/symbol pair is $action[$actionBase[$state] + $symbol]. If $actionBase[$state] is 0, the
|
||||
action is defaulted, i.e. $actionDefault[$state] should be used instead. */
|
||||
* action is defaulted, i.e. $actionDefault[$state] should be used instead. */
|
||||
protected $actionBase;
|
||||
/** @var int[] Table of actions. Indexed according to $actionBase comment. */
|
||||
protected $action;
|
||||
@@ -218,10 +220,7 @@ abstract class ParserAbstract implements Parser
|
||||
));
|
||||
}
|
||||
|
||||
// This is necessary to assign some meaningful attributes to /* empty */ productions. They'll get
|
||||
// the attributes of the next token, even though they don't contain it themselves.
|
||||
$this->startAttributeStack[$stackPos+1] = $startAttributes;
|
||||
$this->endAttributeStack[$stackPos+1] = $endAttributes;
|
||||
// Allow productions to access the start attributes of the lookahead token.
|
||||
$this->lookaheadStartAttributes = $startAttributes;
|
||||
|
||||
//$this->traceRead($symbol);
|
||||
@@ -293,7 +292,8 @@ abstract class ParserAbstract implements Parser
|
||||
|
||||
/* Goto - shift nonterminal */
|
||||
$lastEndAttributes = $this->endAttributeStack[$stackPos];
|
||||
$stackPos -= $this->ruleToLength[$rule];
|
||||
$ruleLength = $this->ruleToLength[$rule];
|
||||
$stackPos -= $ruleLength;
|
||||
$nonTerminal = $this->ruleToNonTerminal[$rule];
|
||||
$idx = $this->gotoBase[$nonTerminal] + $stateStack[$stackPos];
|
||||
if ($idx >= 0 && $idx < $this->gotoTableSize && $this->gotoCheck[$idx] === $nonTerminal) {
|
||||
@@ -306,6 +306,10 @@ abstract class ParserAbstract implements Parser
|
||||
$stateStack[$stackPos] = $state;
|
||||
$this->semStack[$stackPos] = $this->semValue;
|
||||
$this->endAttributeStack[$stackPos] = $lastEndAttributes;
|
||||
if ($ruleLength === 0) {
|
||||
// Empty productions use the start attributes of the lookahead token.
|
||||
$this->startAttributeStack[$stackPos] = $this->lookaheadStartAttributes;
|
||||
}
|
||||
} else {
|
||||
/* error */
|
||||
switch ($this->errorState) {
|
||||
@@ -339,6 +343,7 @@ abstract class ParserAbstract implements Parser
|
||||
|
||||
// We treat the error symbol as being empty, so we reset the end attributes
|
||||
// to the end attributes of the last non-error symbol
|
||||
$this->startAttributeStack[$stackPos] = $this->lookaheadStartAttributes;
|
||||
$this->endAttributeStack[$stackPos] = $this->endAttributeStack[$stackPos - 1];
|
||||
$this->endAttributes = $this->endAttributeStack[$stackPos - 1];
|
||||
break;
|
||||
@@ -647,7 +652,7 @@ abstract class ParserAbstract implements Parser
|
||||
}
|
||||
|
||||
protected function handleBuiltinTypes(Name $name) {
|
||||
$scalarTypes = [
|
||||
$builtinTypes = [
|
||||
'bool' => true,
|
||||
'int' => true,
|
||||
'float' => true,
|
||||
@@ -655,6 +660,11 @@ abstract class ParserAbstract implements Parser
|
||||
'iterable' => true,
|
||||
'void' => true,
|
||||
'object' => true,
|
||||
'null' => true,
|
||||
'false' => true,
|
||||
'mixed' => true,
|
||||
'never' => true,
|
||||
'true' => true,
|
||||
];
|
||||
|
||||
if (!$name->isUnqualified()) {
|
||||
@@ -662,7 +672,7 @@ abstract class ParserAbstract implements Parser
|
||||
}
|
||||
|
||||
$lowerName = $name->toLowerString();
|
||||
if (!isset($scalarTypes[$lowerName])) {
|
||||
if (!isset($builtinTypes[$lowerName])) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
@@ -680,6 +690,20 @@ abstract class ParserAbstract implements Parser
|
||||
return $this->startAttributeStack[$pos] + $this->endAttributeStack[$pos];
|
||||
}
|
||||
|
||||
protected function getFloatCastKind(string $cast): int
|
||||
{
|
||||
$cast = strtolower($cast);
|
||||
if (strpos($cast, 'float') !== false) {
|
||||
return Double::KIND_FLOAT;
|
||||
}
|
||||
|
||||
if (strpos($cast, 'real') !== false) {
|
||||
return Double::KIND_REAL;
|
||||
}
|
||||
|
||||
return Double::KIND_DOUBLE;
|
||||
}
|
||||
|
||||
protected function parseLNumber($str, $attributes, $allowInvalidOctal = false) {
|
||||
try {
|
||||
return LNumber::fromString($str, $attributes, $allowInvalidOctal);
|
||||
@@ -824,6 +848,43 @@ abstract class ParserAbstract implements Parser
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create attributes for a zero-length common-capturing nop.
|
||||
*
|
||||
* @param Comment[] $comments
|
||||
* @return array
|
||||
*/
|
||||
protected function createCommentNopAttributes(array $comments) {
|
||||
$comment = $comments[count($comments) - 1];
|
||||
$commentEndLine = $comment->getEndLine();
|
||||
$commentEndFilePos = $comment->getEndFilePos();
|
||||
$commentEndTokenPos = $comment->getEndTokenPos();
|
||||
|
||||
$attributes = ['comments' => $comments];
|
||||
if (-1 !== $commentEndLine) {
|
||||
$attributes['startLine'] = $commentEndLine;
|
||||
$attributes['endLine'] = $commentEndLine;
|
||||
}
|
||||
if (-1 !== $commentEndFilePos) {
|
||||
$attributes['startFilePos'] = $commentEndFilePos + 1;
|
||||
$attributes['endFilePos'] = $commentEndFilePos;
|
||||
}
|
||||
if (-1 !== $commentEndTokenPos) {
|
||||
$attributes['startTokenPos'] = $commentEndTokenPos + 1;
|
||||
$attributes['endTokenPos'] = $commentEndTokenPos;
|
||||
}
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
protected function checkClassModifier($a, $b, $modifierPos) {
|
||||
try {
|
||||
Class_::verifyClassModifier($a, $b);
|
||||
} catch (Error $error) {
|
||||
$error->setAttributes($this->getAttributesAt($modifierPos));
|
||||
$this->emitError($error);
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkModifier($a, $b, $modifierPos) {
|
||||
// Jumping through some hoops here because verifyModifier() is also used elsewhere
|
||||
try {
|
||||
@@ -852,13 +913,6 @@ abstract class ParserAbstract implements Parser
|
||||
}
|
||||
|
||||
protected function checkNamespace(Namespace_ $node) {
|
||||
if ($node->name && $node->name->isSpecialClassName()) {
|
||||
$this->emitError(new Error(
|
||||
sprintf('Cannot use \'%s\' as namespace name', $node->name),
|
||||
$node->name->getAttributes()
|
||||
));
|
||||
}
|
||||
|
||||
if (null !== $node->stmts) {
|
||||
foreach ($node->stmts as $stmt) {
|
||||
if ($stmt instanceof Namespace_) {
|
||||
@@ -870,22 +924,17 @@ abstract class ParserAbstract implements Parser
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkClass(Class_ $node, $namePos) {
|
||||
if (null !== $node->name && $node->name->isSpecialClassName()) {
|
||||
private function checkClassName($name, $namePos) {
|
||||
if (null !== $name && $name->isSpecialClassName()) {
|
||||
$this->emitError(new Error(
|
||||
sprintf('Cannot use \'%s\' as class name as it is reserved', $node->name),
|
||||
sprintf('Cannot use \'%s\' as class name as it is reserved', $name),
|
||||
$this->getAttributesAt($namePos)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if ($node->extends && $node->extends->isSpecialClassName()) {
|
||||
$this->emitError(new Error(
|
||||
sprintf('Cannot use \'%s\' as class name as it is reserved', $node->extends),
|
||||
$node->extends->getAttributes()
|
||||
));
|
||||
}
|
||||
|
||||
foreach ($node->implements as $interface) {
|
||||
private function checkImplementedInterfaces(array $interfaces) {
|
||||
foreach ($interfaces as $interface) {
|
||||
if ($interface->isSpecialClassName()) {
|
||||
$this->emitError(new Error(
|
||||
sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface),
|
||||
@@ -895,22 +944,27 @@ abstract class ParserAbstract implements Parser
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkInterface(Interface_ $node, $namePos) {
|
||||
if (null !== $node->name && $node->name->isSpecialClassName()) {
|
||||
protected function checkClass(Class_ $node, $namePos) {
|
||||
$this->checkClassName($node->name, $namePos);
|
||||
|
||||
if ($node->extends && $node->extends->isSpecialClassName()) {
|
||||
$this->emitError(new Error(
|
||||
sprintf('Cannot use \'%s\' as class name as it is reserved', $node->name),
|
||||
$this->getAttributesAt($namePos)
|
||||
sprintf('Cannot use \'%s\' as class name as it is reserved', $node->extends),
|
||||
$node->extends->getAttributes()
|
||||
));
|
||||
}
|
||||
|
||||
foreach ($node->extends as $interface) {
|
||||
if ($interface->isSpecialClassName()) {
|
||||
$this->emitError(new Error(
|
||||
sprintf('Cannot use \'%s\' as interface name as it is reserved', $interface),
|
||||
$interface->getAttributes()
|
||||
));
|
||||
}
|
||||
}
|
||||
$this->checkImplementedInterfaces($node->implements);
|
||||
}
|
||||
|
||||
protected function checkInterface(Interface_ $node, $namePos) {
|
||||
$this->checkClassName($node->name, $namePos);
|
||||
$this->checkImplementedInterfaces($node->extends);
|
||||
}
|
||||
|
||||
protected function checkEnum(Enum_ $node, $namePos) {
|
||||
$this->checkClassName($node->name, $namePos);
|
||||
$this->checkImplementedInterfaces($node->implements);
|
||||
}
|
||||
|
||||
protected function checkClassMethod(ClassMethod $node, $modifierPos) {
|
||||
@@ -933,6 +987,12 @@ abstract class ParserAbstract implements Parser
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($node->flags & Class_::MODIFIER_READONLY) {
|
||||
$this->emitError(new Error(
|
||||
sprintf('Method %s() cannot be readonly', $node->name),
|
||||
$this->getAttributesAt($modifierPos)));
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkClassConst(ClassConst $node, $modifierPos) {
|
||||
@@ -946,9 +1006,9 @@ abstract class ParserAbstract implements Parser
|
||||
"Cannot use 'abstract' as constant modifier",
|
||||
$this->getAttributesAt($modifierPos)));
|
||||
}
|
||||
if ($node->flags & Class_::MODIFIER_FINAL) {
|
||||
if ($node->flags & Class_::MODIFIER_READONLY) {
|
||||
$this->emitError(new Error(
|
||||
"Cannot use 'final' as constant modifier",
|
||||
"Cannot use 'readonly' as constant modifier",
|
||||
$this->getAttributesAt($modifierPos)));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user