Skip to content

Commit d98d354

Browse files
committed
Address a few review comments
1 parent 7616901 commit d98d354

File tree

7 files changed

+89
-50
lines changed

7 files changed

+89
-50
lines changed

Zend/zend_constants.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
const E_USER_ERROR = UNKNOWN;
1717
const E_USER_WARNING = UNKNOWN;
1818
const E_USER_NOTICE = UNKNOWN;
19-
const E_STRICT = UNKNOWNN;
19+
const E_STRICT = UNKNOWN;
2020
const E_RECOVERABLE_ERROR = UNKNOWN;
2121
const E_DEPRECATED = UNKNOWN;
2222
const E_USER_DEPRECATED = UNKNOWN;

Zend/zend_constants_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 77f39014422633b26c62049152878f0df242b896 */
2+
* Stub hash: 87186b2c9fa37d09b1c0b4bbc1ffeaebd0dae2f7 */
33

44
#include "zend_constants_consts.h"
55

Zend/zend_constants_consts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 77f39014422633b26c62049152878f0df242b896 */
2+
* Stub hash: 87186b2c9fa37d09b1c0b4bbc1ffeaebd0dae2f7 */
33

44
#define E_ERROR 1
55
#define E_WARNING 2

build/gen_stub.php

Lines changed: 82 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,20 @@ function processStubFile(string $stubFile, Context $context): ?FileInfo {
6969
$constInfos = $fileInfo->getAllConstInfos();
7070
$context->allConstInfos = array_merge($context->allConstInfos, $constInfos);
7171

72-
$generatedConstCode = false;
7372
$constCode = generateConstCode($constInfos, $stubHash);
74-
if (($context->forceRegeneration || $stubHash !== $oldStubHash) && $constCode !== "" && file_put_contents($constFile, $constCode)) {
73+
if (($context->forceRegeneration || $stubHash !== $oldStubHash) && $constCode !== "") {
74+
if (file_put_contents($constFile, $constCode) === false) {
75+
throw new Exception("Failed to write $constFile");
76+
}
77+
7578
echo "Saved $constFile\n";
76-
$generatedConstCode = true;
7779
}
7880

7981
$arginfoCode = generateArgInfoCode(
8082
basename($stubFilenameWithoutExtension),
8183
$fileInfo,
8284
$context->allConstInfos,
83-
$generatedConstCode ? basename($constFile) : null,
85+
$constCode ? basename($constFile) : null,
8486
$stubHash
8587
);
8688
if (($context->forceRegeneration || $stubHash !== $oldStubHash) && file_put_contents($arginfoFile, $arginfoCode)) {
@@ -776,10 +778,25 @@ private function setTypes(?Type $type, ?Type $phpDocType): void
776778

777779
interface ConstOrClassConstName {
778780
public function __toString(): string;
781+
public function equals(ConstOrClassConstName $const): bool;
779782
public function isClassConst(): bool;
783+
public function isUnknown(): bool;
784+
}
785+
786+
abstract class AbstractConstName implements ConstOrClassConstName
787+
{
788+
public function equals(ConstOrClassConstName $const): bool
789+
{
790+
return $this->__toString() === $const->__toString();
791+
}
792+
793+
public function isUnknown(): bool
794+
{
795+
return strtolower($this->__toString()) === "unknown";
796+
}
780797
}
781798

782-
class ConstName implements ConstOrClassConstName {
799+
class ConstName extends AbstractConstName {
783800
/** @var string */
784801
public $const;
785802

@@ -799,7 +816,7 @@ public function __toString(): string
799816
}
800817
}
801818

802-
class ClassConstName implements ConstOrClassConstName {
819+
class ClassConstName extends AbstractConstName {
803820
/** @var Name */
804821
public $class;
805822
/** @var string */
@@ -1453,14 +1470,14 @@ public static function createFromExpression(Expr $expr, ?string $cConstName, ite
14531470
function (Expr $expr) use ($allConstInfos, &$cConstName, &$originatingConst, &$isUnknownConstValue) {
14541471
if ($expr instanceof Expr\ConstFetch || $expr instanceof Expr\ClassConstFetch) {
14551472
if ($expr instanceof Expr\ClassConstFetch) {
1456-
$constName = $expr->class->toString() . "::" . $expr->name->toString();
1473+
$constName = new ClassConstName($expr->class, $expr->name->toString());
14571474
} else {
1458-
$constName = $expr->name->toString();
1475+
$constName = new ConstName($expr->name->toString());
14591476
}
14601477

1461-
if ($constName !== "UNKNOWN") {
1478+
if ($constName->isUnknown() === false) {
14621479
foreach ($allConstInfos as $const) {
1463-
if ($const->name->__toString() === $constName) {
1480+
if ($constName->equals($const->name)) {
14641481
if ($cConstName === null) {
14651482
$cConstName = $const->cname;
14661483
}
@@ -1472,6 +1489,8 @@ function (Expr $expr) use ($allConstInfos, &$cConstName, &$originatingConst, &$i
14721489
return self::createFromExpression($const->value, $cConstName, $allConstInfos)->value;
14731490
}
14741491
}
1492+
1493+
throw new Exception("Constant " . $constName->__toString() . " cannot be found");
14751494
}
14761495

14771496
if ($isUnknownConstValue === null) {
@@ -1530,6 +1549,8 @@ public function initializeZval(string $zvalName): string
15301549
throw new Exception("Unknown const value");
15311550
}
15321551

1552+
$cConstValue = $this->getCConstValue();
1553+
15331554
$code = "\tzval $zvalName;\n";
15341555

15351556
switch ($this->type) {
@@ -1538,29 +1559,29 @@ public function initializeZval(string $zvalName): string
15381559
break;
15391560

15401561
case "boolean":
1541-
$code .= "\tZVAL_BOOL(&$zvalName, " . ($this->cConstName ?: ($this->value ? "true" : "false")) . ");\n";
1562+
$code .= "\tZVAL_BOOL(&$zvalName, " . ($cConstValue ?: ($this->value ? "true" : "false")) . ");\n";
15421563
break;
15431564

15441565
case "integer":
1545-
$code .= "\tZVAL_LONG(&$zvalName, " . ($this->cConstName ?: $this->value) . ");\n";
1566+
$code .= "\tZVAL_LONG(&$zvalName, " . ($cConstValue ?: $this->value) . ");\n";
15461567
break;
15471568

15481569
case "double":
1549-
$code .= "\tZVAL_DOUBLE(&$zvalName, " . ($this->cConstName ?: $this->value) . ");\n";
1570+
$code .= "\tZVAL_DOUBLE(&$zvalName, " . ($cConstValue ?: $this->value) . ");\n";
15501571
break;
15511572

15521573
case "string":
15531574
if (!$this->cConstName && $this->value === "") {
15541575
$code .= "\tZVAL_EMPTY_STRING(&$zvalName);\n";
15551576
} else {
1556-
$constValue = $this->cConstName ?: '"' . addslashes($this->value) . '"';
1577+
$constValue = $cConstValue ?: '"' . addslashes($this->value) . '"';
15571578
$code .= "\tzend_string *{$zvalName}_str = zend_string_init($constValue, sizeof($constValue) - 1, 1);\n";
15581579
$code .= "\tZVAL_STR(&$zvalName, {$zvalName}_str);\n";
15591580
}
15601581
break;
15611582

15621583
case "array":
1563-
if (!$this->cConstName && empty($this->value)) {
1584+
if (!$cConstValue && empty($this->value)) {
15641585
$code .= "\tZVAL_EMPTY_ARRAY(&$zvalName);\n";
15651586
} else {
15661587
throw new Exception("Unimplemented default value");
@@ -1573,6 +1594,19 @@ public function initializeZval(string $zvalName): string
15731594

15741595
return $code;
15751596
}
1597+
1598+
public function getCConstValue(): ?string
1599+
{
1600+
if ($this->cConstName) {
1601+
return $this->cConstName;
1602+
}
1603+
1604+
if ($this->originatingConst) {
1605+
return $this->originatingConst->cname;
1606+
}
1607+
1608+
return null;
1609+
}
15761610
}
15771611

15781612
abstract class VariableLike
@@ -1594,14 +1628,14 @@ abstract protected function getVariableLikeName(): string;
15941628

15951629
abstract protected function addTypeToFieldSynopsis(DOMDocument $doc, DOMElement $fieldsynopsisElement): void;
15961630

1597-
abstract protected function getFieldsynopsisDefaultLinkend(): string;
1631+
abstract protected function getFieldSynopsisDefaultLinkend(): string;
15981632

1599-
abstract protected function getFieldsynopsisName(): string;
1633+
abstract protected function getFieldSynopsisName(): string;
16001634

16011635
/**
16021636
* @param iterable<ConstInfo> $allConstInfos
16031637
*/
1604-
abstract protected function getFieldsynopsisValueString(iterable $allConstInfos): ?string;
1638+
abstract protected function getFieldSynopsisValueString(iterable $allConstInfos): ?string;
16051639

16061640
protected function getFlagsAsString(): string
16071641
{
@@ -1626,17 +1660,17 @@ public function getFieldSynopsisElement(DOMDocument $doc, iterable $allConstInfo
16261660

16271661
$this->addTypeToFieldSynopsis($doc, $fieldsynopsisElement);
16281662

1629-
$varnameElement = $doc->createElement("varname", $this->getFieldsynopsisName());
1663+
$varnameElement = $doc->createElement("varname", $this->getFieldSynopsisName());
16301664
if ($this->link) {
16311665
$varnameElement->setAttribute("linkend", $this->link);
16321666
} else {
1633-
$varnameElement->setAttribute("linkend", $this->getFieldsynopsisDefaultLinkend());
1667+
$varnameElement->setAttribute("linkend", $this->getFieldSynopsisDefaultLinkend());
16341668
}
16351669

16361670
$fieldsynopsisElement->appendChild(new DOMText("\n "));
16371671
$fieldsynopsisElement->appendChild($varnameElement);
16381672

1639-
$valueString = $this->getFieldsynopsisValueString($allConstInfos);
1673+
$valueString = $this->getFieldSynopsisValueString($allConstInfos);
16401674
if ($valueString) {
16411675
$fieldsynopsisElement->appendChild(new DOMText("\n "));
16421676
$initializerElement = $doc->createElement("initializer", $valueString);
@@ -1715,14 +1749,14 @@ protected function getVariableTypeCode(): string
17151749
return "const";
17161750
}
17171751

1718-
protected function getFieldsynopsisDefaultLinkend(): string
1752+
protected function getFieldSynopsisDefaultLinkend(): string
17191753
{
17201754
$className = str_replace(["\\", "_"], ["-", "-"], $this->name->class->toLowerString());
17211755

17221756
return "$className.constants." . strtolower(str_replace("_", "-", $this->name->const));
17231757
}
17241758

1725-
protected function getFieldsynopsisName(): string
1759+
protected function getFieldSynopsisName(): string
17261760
{
17271761
return $this->name->__toString();
17281762
}
@@ -1738,7 +1772,7 @@ protected function addTypeToFieldSynopsis(DOMDocument $doc, DOMElement $fieldsyn
17381772
/**
17391773
* @param iterable<ConstInfo> $allConstInfos
17401774
*/
1741-
protected function getFieldsynopsisValueString(iterable $allConstInfos): ?string
1775+
protected function getFieldSynopsisValueString(iterable $allConstInfos): ?string
17421776
{
17431777
$value = EvaluatedValue::createFromExpression($this->value, $this->cname, $allConstInfos);
17441778
if ($value->isUnknownConstValue) {
@@ -1825,9 +1859,9 @@ public function getDeclaration(iterable $allConstInfos): string
18251859

18261860
private function getConstDeclaration(string $code, EvaluatedValue $value): string
18271861
{
1828-
$cConstName = $value->cConstName;
18291862
$constName = str_replace('\\', '\\\\', $this->name->__toString());
18301863
$constValue = $value->value;
1864+
$cConstValue = $value->getCConstValue();
18311865

18321866
$flags = "CONST_CS | CONST_PERSISTENT";
18331867
if ($this->isDeprecated) {
@@ -1839,16 +1873,16 @@ private function getConstDeclaration(string $code, EvaluatedValue $value): strin
18391873
$code .= " REGISTER_NULL_CONSTANT(\"$constName\", $flags);\n";
18401874
break;
18411875
case "boolean":
1842-
$code .= " REGISTER_BOOL_CONSTANT(\"$constName\", " . ($cConstName ?: ($constValue ? "true" : "false")) . ", $flags);\n";
1876+
$code .= " REGISTER_BOOL_CONSTANT(\"$constName\", " . ($cConstValue ?: ($constValue ? "true" : "false")) . ", $flags);\n";
18431877
break;
18441878
case "integer":
1845-
$code .= " REGISTER_LONG_CONSTANT(\"$constName\", " . ($cConstName ?: (int) $constValue) . ", $flags);\n";
1879+
$code .= " REGISTER_LONG_CONSTANT(\"$constName\", " . ($cConstValue ?: (int) $constValue) . ", $flags);\n";
18461880
break;
18471881
case "double":
1848-
$code .= " REGISTER_DOUBLE_CONSTANT(\"$constName\", " . ($cConstName ?: (int) $constValue) . ", $flags);\n";
1882+
$code .= " REGISTER_DOUBLE_CONSTANT(\"$constName\", " . ($cConstValue ?: (int) $constValue) . ", $flags);\n";
18491883
break;
18501884
case "string":
1851-
$code .= " REGISTER_STRING_CONSTANT(\"$constName\", " . ($cConstName ?: '"' . addslashes($constValue) . '"') . ", $flags);\n";
1885+
$code .= " REGISTER_STRING_CONSTANT(\"$constName\", " . ($cConstValue ?: '"' . addslashes($constValue) . '"') . ", $flags);\n";
18521886
break;
18531887
default:
18541888
throw new Exception("Unimplemented constant type");
@@ -1951,22 +1985,22 @@ protected function getVariableLikeName(): string
19511985
return $this->name->property;
19521986
}
19531987

1954-
protected function getFieldsynopsisDefaultLinkend(): string
1988+
protected function getFieldSynopsisDefaultLinkend(): string
19551989
{
19561990
$className = str_replace(["\\", "_"], ["-", "-"], $this->name->class->toLowerString());
19571991

19581992
return "$className.props." . strtolower(str_replace("_", "-", $this->name->property));
19591993
}
19601994

1961-
protected function getFieldsynopsisName(): string
1995+
protected function getFieldSynopsisName(): string
19621996
{
1963-
return $this->name->__toString();
1997+
return $this->name->property;
19641998
}
19651999

19662000
/**
19672001
* @param iterable<ConstInfo> $allConstInfos
19682002
*/
1969-
protected function getFieldsynopsisValueString(iterable $allConstInfos): ?string
2003+
protected function getFieldSynopsisValueString(iterable $allConstInfos): ?string
19702004
{
19712005
return $this->defaultValueString;
19722006
}
@@ -2085,9 +2119,11 @@ protected function addModifiersToFieldSynopsis(DOMDocument $doc, DOMElement $fie
20852119

20862120
protected function addTypeToFieldSynopsis(DOMDocument $doc, DOMElement $fieldsynopsisElement): void
20872121
{
2088-
if ($this->type) {
2122+
$type = $this->phpDocType ?? $this->type;
2123+
2124+
if ($type) {
20892125
$fieldsynopsisElement->appendChild(new DOMText("\n "));
2090-
$fieldsynopsisElement->appendChild($this->type->getTypeForDoc($doc));
2126+
$fieldsynopsisElement->appendChild($type->getTypeForDoc($doc));
20912127
}
20922128
}
20932129

@@ -3298,7 +3334,7 @@ function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstrac
32983334

32993335
$fileInfo->classInfos[] = parseClass(
33003336
$className, $stmt, $constInfos, $propertyInfos, $methodInfos, $enumCaseInfos
3301-
);
3337+
);
33023338
continue;
33033339
}
33043340

@@ -3459,25 +3495,26 @@ function findEquivalentFuncInfo(array $generatedFuncInfos, FuncInfo $funcInfo):
34593495
return null;
34603496
}
34613497

3462-
/** @param iterable<FuncInfo> $funcInfos */
3498+
/** @param iterable $infos */
34633499
function generateCodeWithConditions(
3464-
iterable $funcInfos, string $separator, Closure $codeGenerator): string {
3500+
iterable $infos, string $separator, Closure $codeGenerator): string {
34653501
$code = "";
3466-
foreach ($funcInfos as $funcInfo) {
3467-
$funcCode = $codeGenerator($funcInfo);
3468-
if ($funcCode === null) {
3502+
foreach ($infos as $info) {
3503+
$infoCode = $codeGenerator($info);
3504+
if ($infoCode === null) {
34693505
continue;
34703506
}
34713507

34723508
$code .= $separator;
3473-
if ($funcInfo->cond) {
3474-
$code .= "#if {$funcInfo->cond}\n";
3475-
$code .= $funcCode;
3509+
if ($info->cond) {
3510+
$code .= "#if {$info->cond}\n";
3511+
$code .= $infoCode;
34763512
$code .= "#endif\n";
34773513
} else {
3478-
$code .= $funcCode;
3514+
$code .= $infoCode;
34793515
}
34803516
}
3517+
34813518
return $code;
34823519
}
34833520

ext/date/php_date.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,11 @@
147147
* RSS 2.0 Specification: http://blogs.law.harvard.edu/tech/rss
148148
* "All date-times in RSS conform to the Date and Time Specification of RFC 822,
149149
* with the exception that the year may be expressed with two characters or four characters (four preferred)"
150+
* @var string
150151
*/
151152
const DATE_RSS = DATE_RFC1123;
152153

154+
/** @var string */
153155
const DATE_W3C = DATE_RFC3339;
154156

155157
/** @cname SUNFUNCS_RET_TIMESTAMP */

ext/date/php_date_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 7a48dac2712129036b55f01a6c0423c670c5efb7 */
2+
* Stub hash: e597f9576d16dbde0d704d99ea6369189c1bd67f */
33

44
#include "php_date_consts.h"
55

ext/date/php_date_consts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 7a48dac2712129036b55f01a6c0423c670c5efb7 */
2+
* Stub hash: e597f9576d16dbde0d704d99ea6369189c1bd67f */
33

44
#define DATE_FORMAT_RFC3339 "Y-m-d\\TH:i:sP"
55
#define DATE_FORMAT_COOKIE "l, d-M-Y H:i:s T"

0 commit comments

Comments
 (0)