Skip to content

Commit dd72c43

Browse files
DanielEScherzerkocsismate
authored andcommitted
gen_stub: convert ArgInfo::$sendBy to a string
Instead of using integers that then need to be converted to the string representation via `::getSendByString()`, just always store a string, eliminating the conversion method and replacing it with property access.
1 parent 9ab7458 commit dd72c43

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

build/gen_stub.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -774,12 +774,12 @@ public function toTypeMask(): string {
774774
}
775775

776776
class ArgInfo {
777-
const SEND_BY_VAL = 0;
778-
const SEND_BY_REF = 1;
779-
const SEND_PREFER_REF = 2;
777+
const SEND_BY_VAL = "0";
778+
const SEND_BY_REF = "1";
779+
const SEND_PREFER_REF = "ZEND_SEND_PREFER_REF";
780780

781781
public string $name;
782-
public int $sendBy;
782+
public string $sendBy;
783783
public bool $isVariadic;
784784
public ?Type $type;
785785
public ?Type $phpDocType;
@@ -792,7 +792,7 @@ class ArgInfo {
792792
*/
793793
public function __construct(
794794
string $name,
795-
int $sendBy,
795+
string $sendBy,
796796
bool $isVariadic,
797797
?Type $type,
798798
?Type $phpDocType,
@@ -816,18 +816,6 @@ public function equals(ArgInfo $other): bool {
816816
&& $this->defaultValue === $other->defaultValue;
817817
}
818818

819-
public function getSendByString(): string {
820-
switch ($this->sendBy) {
821-
case self::SEND_BY_VAL:
822-
return "0";
823-
case self::SEND_BY_REF:
824-
return "1";
825-
case self::SEND_PREFER_REF:
826-
return "ZEND_SEND_PREFER_REF";
827-
}
828-
throw new Exception("Invalid sendBy value");
829-
}
830-
831819
public function getMethodSynopsisType(): Type {
832820
if ($this->type) {
833821
return $this->type;
@@ -5038,14 +5026,14 @@ function funcInfoToCode(FileInfo $fileInfo, FuncInfo $funcInfo): string {
50385026
if ($simpleArgType->isBuiltin) {
50395027
$code .= sprintf(
50405028
"\tZEND_%s_TYPE_INFO%s(%s, %s, %s, %d%s)\n",
5041-
$argKind, $argDefaultKind, $argInfo->getSendByString(), $argInfo->name,
5029+
$argKind, $argDefaultKind, $argInfo->sendBy, $argInfo->name,
50425030
$simpleArgType->toTypeCode(), $argType->isNullable(),
50435031
$argInfo->hasProperDefaultValue() ? ", " . $argInfo->getDefaultValueAsArginfoString() : ""
50445032
);
50455033
} else {
50465034
$code .= sprintf(
50475035
"\tZEND_%s_OBJ_INFO%s(%s, %s, %s, %d%s)\n",
5048-
$argKind,$argDefaultKind, $argInfo->getSendByString(), $argInfo->name,
5036+
$argKind,$argDefaultKind, $argInfo->sendBy, $argInfo->name,
50495037
$simpleArgType->toEscapedName(), $argType->isNullable(),
50505038
$argInfo->hasProperDefaultValue() ? ", " . $argInfo->getDefaultValueAsArginfoString() : ""
50515039
);
@@ -5055,14 +5043,14 @@ function funcInfoToCode(FileInfo $fileInfo, FuncInfo $funcInfo): string {
50555043
if ($arginfoType->hasClassType()) {
50565044
$code .= sprintf(
50575045
"\tZEND_%s_OBJ_TYPE_MASK(%s, %s, %s, %s%s)\n",
5058-
$argKind, $argInfo->getSendByString(), $argInfo->name,
5046+
$argKind, $argInfo->sendBy, $argInfo->name,
50595047
$arginfoType->toClassTypeString(), $arginfoType->toTypeMask(),
50605048
!$argInfo->isVariadic ? ", " . $argInfo->getDefaultValueAsArginfoString() : ""
50615049
);
50625050
} else {
50635051
$code .= sprintf(
50645052
"\tZEND_%s_TYPE_MASK(%s, %s, %s, %s)\n",
5065-
$argKind, $argInfo->getSendByString(), $argInfo->name,
5053+
$argKind, $argInfo->sendBy, $argInfo->name,
50665054
$arginfoType->toTypeMask(),
50675055
$argInfo->getDefaultValueAsArginfoString()
50685056
);
@@ -5071,7 +5059,7 @@ function funcInfoToCode(FileInfo $fileInfo, FuncInfo $funcInfo): string {
50715059
} else {
50725060
$code .= sprintf(
50735061
"\tZEND_%s_INFO%s(%s, %s%s)\n",
5074-
$argKind, $argDefaultKind, $argInfo->getSendByString(), $argInfo->name,
5062+
$argKind, $argDefaultKind, $argInfo->sendBy, $argInfo->name,
50755063
$argInfo->hasProperDefaultValue() ? ", " . $argInfo->getDefaultValueAsArginfoString() : ""
50765064
);
50775065
}

0 commit comments

Comments
 (0)