From dd72c4325cf66f2e46b61ba80669ae3882e99c06 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Fri, 4 Oct 2024 18:34:26 -0700 Subject: [PATCH] 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. --- build/gen_stub.php | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index efa31e7ea58..86f06d6b9b6 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -774,12 +774,12 @@ class ArginfoType { } class ArgInfo { - const SEND_BY_VAL = 0; - const SEND_BY_REF = 1; - const SEND_PREFER_REF = 2; + const SEND_BY_VAL = "0"; + const SEND_BY_REF = "1"; + const SEND_PREFER_REF = "ZEND_SEND_PREFER_REF"; public string $name; - public int $sendBy; + public string $sendBy; public bool $isVariadic; public ?Type $type; public ?Type $phpDocType; @@ -792,7 +792,7 @@ class ArgInfo { */ public function __construct( string $name, - int $sendBy, + string $sendBy, bool $isVariadic, ?Type $type, ?Type $phpDocType, @@ -816,18 +816,6 @@ class ArgInfo { && $this->defaultValue === $other->defaultValue; } - public function getSendByString(): string { - switch ($this->sendBy) { - case self::SEND_BY_VAL: - return "0"; - case self::SEND_BY_REF: - return "1"; - case self::SEND_PREFER_REF: - return "ZEND_SEND_PREFER_REF"; - } - throw new Exception("Invalid sendBy value"); - } - public function getMethodSynopsisType(): Type { if ($this->type) { return $this->type; @@ -5038,14 +5026,14 @@ function funcInfoToCode(FileInfo $fileInfo, FuncInfo $funcInfo): string { if ($simpleArgType->isBuiltin) { $code .= sprintf( "\tZEND_%s_TYPE_INFO%s(%s, %s, %s, %d%s)\n", - $argKind, $argDefaultKind, $argInfo->getSendByString(), $argInfo->name, + $argKind, $argDefaultKind, $argInfo->sendBy, $argInfo->name, $simpleArgType->toTypeCode(), $argType->isNullable(), $argInfo->hasProperDefaultValue() ? ", " . $argInfo->getDefaultValueAsArginfoString() : "" ); } else { $code .= sprintf( "\tZEND_%s_OBJ_INFO%s(%s, %s, %s, %d%s)\n", - $argKind,$argDefaultKind, $argInfo->getSendByString(), $argInfo->name, + $argKind,$argDefaultKind, $argInfo->sendBy, $argInfo->name, $simpleArgType->toEscapedName(), $argType->isNullable(), $argInfo->hasProperDefaultValue() ? ", " . $argInfo->getDefaultValueAsArginfoString() : "" ); @@ -5055,14 +5043,14 @@ function funcInfoToCode(FileInfo $fileInfo, FuncInfo $funcInfo): string { if ($arginfoType->hasClassType()) { $code .= sprintf( "\tZEND_%s_OBJ_TYPE_MASK(%s, %s, %s, %s%s)\n", - $argKind, $argInfo->getSendByString(), $argInfo->name, + $argKind, $argInfo->sendBy, $argInfo->name, $arginfoType->toClassTypeString(), $arginfoType->toTypeMask(), !$argInfo->isVariadic ? ", " . $argInfo->getDefaultValueAsArginfoString() : "" ); } else { $code .= sprintf( "\tZEND_%s_TYPE_MASK(%s, %s, %s, %s)\n", - $argKind, $argInfo->getSendByString(), $argInfo->name, + $argKind, $argInfo->sendBy, $argInfo->name, $arginfoType->toTypeMask(), $argInfo->getDefaultValueAsArginfoString() ); @@ -5071,7 +5059,7 @@ function funcInfoToCode(FileInfo $fileInfo, FuncInfo $funcInfo): string { } else { $code .= sprintf( "\tZEND_%s_INFO%s(%s, %s%s)\n", - $argKind, $argDefaultKind, $argInfo->getSendByString(), $argInfo->name, + $argKind, $argDefaultKind, $argInfo->sendBy, $argInfo->name, $argInfo->hasProperDefaultValue() ? ", " . $argInfo->getDefaultValueAsArginfoString() : "" ); }