Skip to content

Commit

Permalink
Migrate to the final version of PHP-Parser 5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Jan 7, 2024
1 parent 73722df commit 281555d
Showing 1 changed file with 37 additions and 36 deletions.
73 changes: 37 additions & 36 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use PhpParser\Comment\Doc as DocComment;
use PhpParser\ConstExprEvaluator;
use PhpParser\Modifiers;
use PhpParser\Node;
use PhpParser\Node\AttributeGroup;
use PhpParser\Node\Expr;
Expand Down Expand Up @@ -1260,12 +1261,12 @@ public function isMethod(): bool

public function isFinalMethod(): bool
{
return ($this->flags & Class_::MODIFIER_FINAL) || ($this->classFlags & Class_::MODIFIER_FINAL);
return ($this->flags & Modifiers::FINAL) || ($this->classFlags & Modifiers::FINAL);
}

public function isInstanceMethod(): bool
{
return !($this->flags & Class_::MODIFIER_STATIC) && $this->isMethod() && !$this->name->isConstructor();
return !($this->flags & Modifiers::STATIC) && $this->isMethod() && !$this->name->isConstructor();
}

/** @return string[] */
Expand All @@ -1277,21 +1278,21 @@ public function getModifierNames(): array

$result = [];

if ($this->flags & Class_::MODIFIER_FINAL) {
if ($this->flags & Modifiers::FINAL) {
$result[] = "final";
} elseif ($this->flags & Class_::MODIFIER_ABSTRACT && $this->classFlags & ~Class_::MODIFIER_ABSTRACT) {
} elseif ($this->flags & Modifiers::ABSTRACT && $this->classFlags & ~Modifiers::ABSTRACT) {
$result[] = "abstract";
}

if ($this->flags & Class_::MODIFIER_PROTECTED) {
if ($this->flags & Modifiers::PROTECTED) {
$result[] = "protected";
} elseif ($this->flags & Class_::MODIFIER_PRIVATE) {
} elseif ($this->flags & Modifiers::PRIVATE) {
$result[] = "private";
} else {
$result[] = "public";
}

if ($this->flags & Class_::MODIFIER_STATIC) {
if ($this->flags & Modifiers::STATIC) {
$result[] = "static";
}

Expand Down Expand Up @@ -1338,7 +1339,7 @@ public function getDeclarationKey(): string

public function getDeclaration(): ?string
{
if ($this->flags & Class_::MODIFIER_ABSTRACT) {
if ($this->flags & Modifiers::ABSTRACT) {
return null;
}

Expand Down Expand Up @@ -1367,7 +1368,7 @@ public function getFunctionEntry(): string {
}
} else {
$declarationClassName = $this->name->getDeclarationClassName();
if ($this->flags & Class_::MODIFIER_ABSTRACT) {
if ($this->flags & Modifiers::ABSTRACT) {
return sprintf(
"\tZEND_ABSTRACT_ME_WITH_FLAGS(%s, %s, %s, %s)\n",
$declarationClassName, $this->name->methodName, $this->getArgInfoName(),
Expand Down Expand Up @@ -1458,21 +1459,21 @@ public function discardInfoForOldPhpVersions(): void {
private function getFlagsAsArginfoString(): string
{
$flags = "ZEND_ACC_PUBLIC";
if ($this->flags & Class_::MODIFIER_PROTECTED) {
if ($this->flags & Modifiers::PROTECTED) {
$flags = "ZEND_ACC_PROTECTED";
} elseif ($this->flags & Class_::MODIFIER_PRIVATE) {
} elseif ($this->flags & Modifiers::PRIVATE) {
$flags = "ZEND_ACC_PRIVATE";
}

if ($this->flags & Class_::MODIFIER_STATIC) {
if ($this->flags & Modifiers::STATIC) {
$flags .= "|ZEND_ACC_STATIC";
}

if ($this->flags & Class_::MODIFIER_FINAL) {
if ($this->flags & Modifiers::FINAL) {
$flags .= "|ZEND_ACC_FINAL";
}

if ($this->flags & Class_::MODIFIER_ABSTRACT) {
if ($this->flags & Modifiers::ABSTRACT) {
$flags .= "|ZEND_ACC_ABSTRACT";
}

Expand Down Expand Up @@ -2258,9 +2259,9 @@ protected function addTypeToFieldSynopsis(DOMDocument $doc, DOMElement $fieldsyn
protected function getFlagsByPhpVersion(): array
{
$flags = "ZEND_ACC_PUBLIC";
if ($this->flags & Class_::MODIFIER_PROTECTED) {
if ($this->flags & Modifiers::PROTECTED) {
$flags = "ZEND_ACC_PROTECTED";
} elseif ($this->flags & Class_::MODIFIER_PRIVATE) {
} elseif ($this->flags & Modifiers::PRIVATE) {
$flags = "ZEND_ACC_PRIVATE";
}

Expand Down Expand Up @@ -2355,13 +2356,13 @@ public function getFieldSynopsisElement(DOMDocument $doc, array $allConstInfos):

protected function addModifiersToFieldSynopsis(DOMDocument $doc, DOMElement $fieldsynopsisElement): void
{
if ($this->flags & Class_::MODIFIER_PUBLIC) {
if ($this->flags & Modifiers::PUBLIC) {
$fieldsynopsisElement->appendChild(new DOMText("\n "));
$fieldsynopsisElement->appendChild($doc->createElement("modifier", "public"));
} elseif ($this->flags & Class_::MODIFIER_PROTECTED) {
} elseif ($this->flags & Modifiers::PROTECTED) {
$fieldsynopsisElement->appendChild(new DOMText("\n "));
$fieldsynopsisElement->appendChild($doc->createElement("modifier", "protected"));
} elseif ($this->flags & Class_::MODIFIER_PRIVATE) {
} elseif ($this->flags & Modifiers::PRIVATE) {
$fieldsynopsisElement->appendChild(new DOMText("\n "));
$fieldsynopsisElement->appendChild($doc->createElement("modifier", "private"));
}
Expand Down Expand Up @@ -2513,7 +2514,7 @@ public function getPredefinedConstantEntry(DOMDocument $doc, int $indentationLev

public function discardInfoForOldPhpVersions(): void {
$this->type = null;
$this->flags &= ~Class_::MODIFIER_FINAL;
$this->flags &= ~Modifiers::FINAL;
$this->isDeprecated = false;
$this->attributes = [];
}
Expand Down Expand Up @@ -2704,7 +2705,7 @@ protected function getFlagsByPhpVersion(): array
$flags = $this->addFlagForVersionsAbove($flags, "ZEND_ACC_DEPRECATED", PHP_80_VERSION_ID);
}

if ($this->flags & Class_::MODIFIER_FINAL) {
if ($this->flags & Modifiers::FINAL) {
$flags = $this->addFlagForVersionsAbove($flags, "ZEND_ACC_FINAL", PHP_81_VERSION_ID);
}

Expand All @@ -2715,7 +2716,7 @@ protected function addModifiersToFieldSynopsis(DOMDocument $doc, DOMElement $fie
{
parent::addModifiersToFieldSynopsis($doc, $fieldsynopsisElement);

if ($this->flags & Class_::MODIFIER_FINAL) {
if ($this->flags & Modifiers::FINAL) {
$fieldsynopsisElement->appendChild(new DOMText("\n "));
$fieldsynopsisElement->appendChild($doc->createElement("modifier", "final"));
}
Expand Down Expand Up @@ -2784,7 +2785,7 @@ protected function getFieldSynopsisValueString(array $allConstInfos): ?string

public function discardInfoForOldPhpVersions(): void {
$this->type = null;
$this->flags &= ~Class_::MODIFIER_READONLY;
$this->flags &= ~Modifiers::READONLY;
$this->attributes = [];
}

Expand Down Expand Up @@ -2840,11 +2841,11 @@ protected function getFlagsByPhpVersion(): array
{
$flags = parent::getFlagsByPhpVersion();

if ($this->flags & Class_::MODIFIER_STATIC) {
if ($this->flags & Modifiers::STATIC) {
$flags = $this->addFlagForVersionsAbove($flags, "ZEND_ACC_STATIC", PHP_70_VERSION_ID);
}

if ($this->flags & Class_::MODIFIER_READONLY) {
if ($this->flags & Modifiers::READONLY) {
$flags = $this->addFlagForVersionsAbove($flags, "ZEND_ACC_READONLY", PHP_81_VERSION_ID);
}

Expand All @@ -2855,12 +2856,12 @@ protected function addModifiersToFieldSynopsis(DOMDocument $doc, DOMElement $fie
{
parent::addModifiersToFieldSynopsis($doc, $fieldsynopsisElement);

if ($this->flags & Class_::MODIFIER_STATIC) {
if ($this->flags & Modifiers::STATIC) {
$fieldsynopsisElement->appendChild(new DOMText("\n "));
$fieldsynopsisElement->appendChild($doc->createElement("modifier", "static"));
}

if ($this->flags & Class_::MODIFIER_READONLY || $this->isDocReadonly) {
if ($this->flags & Modifiers::READONLY || $this->isDocReadonly) {
$fieldsynopsisElement->appendChild(new DOMText("\n "));
$fieldsynopsisElement->appendChild($doc->createElement("modifier", "readonly"));
}
Expand Down Expand Up @@ -3181,11 +3182,11 @@ private function getFlagsByPhpVersion(): array
$php70Flags[] = "ZEND_ACC_TRAIT";
}

if ($this->flags & Class_::MODIFIER_FINAL) {
if ($this->flags & Modifiers::FINAL) {
$php70Flags[] = "ZEND_ACC_FINAL";
}

if ($this->flags & Class_::MODIFIER_ABSTRACT) {
if ($this->flags & Modifiers::ABSTRACT) {
$php70Flags[] = "ZEND_ACC_ABSTRACT";
}

Expand All @@ -3207,7 +3208,7 @@ private function getFlagsByPhpVersion(): array

$php82Flags = $php81Flags;

if ($this->flags & Class_::MODIFIER_READONLY) {
if ($this->flags & Modifiers::READONLY) {
$php82Flags[] = "ZEND_ACC_READONLY_CLASS";
}

Expand Down Expand Up @@ -3448,15 +3449,15 @@ private static function createOoElement(
$ooElement->appendChild($doc->createElement('modifier', $modifierOverride));
$ooElement->appendChild(new DOMText("\n$indentation "));
} elseif ($withModifiers) {
if ($classInfo->flags & Class_::MODIFIER_FINAL) {
if ($classInfo->flags & Modifiers::FINAL) {
$ooElement->appendChild($doc->createElement('modifier', 'final'));
$ooElement->appendChild(new DOMText("\n$indentation "));
}
if ($classInfo->flags & Class_::MODIFIER_ABSTRACT) {
if ($classInfo->flags & Modifiers::ABSTRACT) {
$ooElement->appendChild($doc->createElement('modifier', 'abstract'));
$ooElement->appendChild(new DOMText("\n$indentation "));
}
if ($classInfo->flags & Class_::MODIFIER_READONLY) {
if ($classInfo->flags & Modifiers::READONLY) {
$ooElement->appendChild($doc->createElement('modifier', 'readonly'));
$ooElement->appendChild(new DOMText("\n$indentation "));
}
Expand Down Expand Up @@ -3601,7 +3602,7 @@ private function hasConstructor(): bool
private function hasNonPrivateConstructor(): bool
{
foreach ($this->funcInfos as $funcInfo) {
if ($funcInfo->name->isConstructor() && !($funcInfo->flags & Class_::MODIFIER_PRIVATE)) {
if ($funcInfo->name->isConstructor() && !($funcInfo->flags & Modifiers::PRIVATE)) {
return true;
}
}
Expand Down Expand Up @@ -4339,7 +4340,7 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
}

$classFlags = $stmt instanceof Class_ ? $stmt->flags : 0;
$abstractFlag = $stmt instanceof Stmt\Interface_ ? Class_::MODIFIER_ABSTRACT : 0;
$abstractFlag = $stmt instanceof Stmt\Interface_ ? Modifiers::ABSTRACT : 0;

if ($classStmt instanceof Stmt\ClassConst) {
foreach ($classStmt->consts as $const) {
Expand Down Expand Up @@ -5530,7 +5531,7 @@ function initPhpParser() {
}

$isInitialized = true;
$version = "5.0.0alpha3";
$version = "5.0.0";
$phpParserDir = __DIR__ . "/PHP-Parser-$version";
if (!is_dir($phpParserDir)) {
installPhpParser($version, $phpParserDir);
Expand Down

0 comments on commit 281555d

Please sign in to comment.