Skip to content

Commit 24b7c7a

Browse files
gen_stub: add ArgInfo::toZendInfo()
Move the logic out of `funcInfoToCode()` and update it. In the process, make `ArgInfo::getDefaultValueAsArginfoString()` private.
1 parent 0d79039 commit 24b7c7a

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

build/gen_stub.php

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ public function hasProperDefaultValue(): bool {
839839
return $this->defaultValue !== null && $this->defaultValue !== "UNKNOWN";
840840
}
841841

842-
public function getDefaultValueAsArginfoString(): string {
842+
private function getDefaultValueAsArginfoString(): string {
843843
if ($this->hasProperDefaultValue()) {
844844
return '"' . addslashes($this->defaultValue) . '"';
845845
}
@@ -859,6 +859,50 @@ public function getDefaultValueAsMethodSynopsisString(): ?string {
859859

860860
return $this->defaultValue;
861861
}
862+
863+
public function toZendInfo(): string {
864+
$argKind = $this->isVariadic ? "ARG_VARIADIC" : "ARG";
865+
$argDefaultKind = $this->hasProperDefaultValue() ? "_WITH_DEFAULT_VALUE" : "";
866+
$argType = $this->type;
867+
if ($argType !== null) {
868+
if (null !== $simpleArgType = $argType->tryToSimpleType()) {
869+
if ($simpleArgType->isBuiltin) {
870+
return sprintf(
871+
"\tZEND_%s_TYPE_INFO%s(%s, %s, %s, %d%s)\n",
872+
$argKind, $argDefaultKind, $this->sendBy, $this->name,
873+
$simpleArgType->toTypeCode(), $argType->isNullable(),
874+
$this->hasProperDefaultValue() ? ", " . $this->getDefaultValueAsArginfoString() : ""
875+
);
876+
}
877+
return sprintf(
878+
"\tZEND_%s_OBJ_INFO%s(%s, %s, %s, %d%s)\n",
879+
$argKind, $argDefaultKind, $this->sendBy, $this->name,
880+
$simpleArgType->toEscapedName(), $argType->isNullable(),
881+
$this->hasProperDefaultValue() ? ", " . $this->getDefaultValueAsArginfoString() : ""
882+
);
883+
}
884+
$arginfoType = $argType->toArginfoType();
885+
if ($arginfoType->hasClassType()) {
886+
return sprintf(
887+
"\tZEND_%s_OBJ_TYPE_MASK(%s, %s, %s, %s%s)\n",
888+
$argKind, $this->sendBy, $this->name,
889+
$arginfoType->toClassTypeString(), $arginfoType->toTypeMask(),
890+
!$this->isVariadic ? ", " . $this->getDefaultValueAsArginfoString() : ""
891+
);
892+
}
893+
return sprintf(
894+
"\tZEND_%s_TYPE_MASK(%s, %s, %s, %s)\n",
895+
$argKind, $this->sendBy, $this->name,
896+
$arginfoType->toTypeMask(),
897+
$this->getDefaultValueAsArginfoString()
898+
);
899+
}
900+
return sprintf(
901+
"\tZEND_%s_INFO%s(%s, %s%s)\n",
902+
$argKind, $argDefaultKind, $this->sendBy, $this->name,
903+
$this->hasProperDefaultValue() ? ", " . $this->getDefaultValueAsArginfoString() : ""
904+
);
905+
}
862906
}
863907

864908
interface VariableLikeName {
@@ -5029,51 +5073,7 @@ function funcInfoToCode(FileInfo $fileInfo, FuncInfo $funcInfo): string {
50295073
}
50305074

50315075
foreach ($funcInfo->args as $argInfo) {
5032-
$argKind = $argInfo->isVariadic ? "ARG_VARIADIC" : "ARG";
5033-
$argDefaultKind = $argInfo->hasProperDefaultValue() ? "_WITH_DEFAULT_VALUE" : "";
5034-
$argType = $argInfo->type;
5035-
if ($argType !== null) {
5036-
if (null !== $simpleArgType = $argType->tryToSimpleType()) {
5037-
if ($simpleArgType->isBuiltin) {
5038-
$code .= sprintf(
5039-
"\tZEND_%s_TYPE_INFO%s(%s, %s, %s, %d%s)\n",
5040-
$argKind, $argDefaultKind, $argInfo->sendBy, $argInfo->name,
5041-
$simpleArgType->toTypeCode(), $argType->isNullable(),
5042-
$argInfo->hasProperDefaultValue() ? ", " . $argInfo->getDefaultValueAsArginfoString() : ""
5043-
);
5044-
} else {
5045-
$code .= sprintf(
5046-
"\tZEND_%s_OBJ_INFO%s(%s, %s, %s, %d%s)\n",
5047-
$argKind, $argDefaultKind, $argInfo->sendBy, $argInfo->name,
5048-
$simpleArgType->toEscapedName(), $argType->isNullable(),
5049-
$argInfo->hasProperDefaultValue() ? ", " . $argInfo->getDefaultValueAsArginfoString() : ""
5050-
);
5051-
}
5052-
} else {
5053-
$arginfoType = $argType->toArginfoType();
5054-
if ($arginfoType->hasClassType()) {
5055-
$code .= sprintf(
5056-
"\tZEND_%s_OBJ_TYPE_MASK(%s, %s, %s, %s%s)\n",
5057-
$argKind, $argInfo->sendBy, $argInfo->name,
5058-
$arginfoType->toClassTypeString(), $arginfoType->toTypeMask(),
5059-
!$argInfo->isVariadic ? ", " . $argInfo->getDefaultValueAsArginfoString() : ""
5060-
);
5061-
} else {
5062-
$code .= sprintf(
5063-
"\tZEND_%s_TYPE_MASK(%s, %s, %s, %s)\n",
5064-
$argKind, $argInfo->sendBy, $argInfo->name,
5065-
$arginfoType->toTypeMask(),
5066-
$argInfo->getDefaultValueAsArginfoString()
5067-
);
5068-
}
5069-
}
5070-
} else {
5071-
$code .= sprintf(
5072-
"\tZEND_%s_INFO%s(%s, %s%s)\n",
5073-
$argKind, $argDefaultKind, $argInfo->sendBy, $argInfo->name,
5074-
$argInfo->hasProperDefaultValue() ? ", " . $argInfo->getDefaultValueAsArginfoString() : ""
5075-
);
5076-
}
5076+
$code .= $argInfo->toZendInfo();
50775077
}
50785078

50795079
$code .= "ZEND_END_ARG_INFO()";

0 commit comments

Comments
 (0)