Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gen_stub: various simplifications and clean up (4) #18109

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
gen_stub: add ArgInfo::toZendInfo()
Move the logic out of `funcInfoToCode()` and update it. In the process, make
`ArgInfo::getDefaultValueAsArginfoString()` private.
  • Loading branch information
DanielEScherzer committed Mar 18, 2025
commit 8de7c06b35932d72961d19cf1587b4edc7069189
92 changes: 46 additions & 46 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ public function hasProperDefaultValue(): bool {
return $this->defaultValue !== null && $this->defaultValue !== "UNKNOWN";
}

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

return $this->defaultValue;
}

public function toZendInfo(): string {
$argKind = $this->isVariadic ? "ARG_VARIADIC" : "ARG";
$argDefaultKind = $this->hasProperDefaultValue() ? "_WITH_DEFAULT_VALUE" : "";
$argType = $this->type;
if ($argType !== null) {
if (null !== $simpleArgType = $argType->tryToSimpleType()) {
if ($simpleArgType->isBuiltin) {
return sprintf(
"\tZEND_%s_TYPE_INFO%s(%s, %s, %s, %d%s)\n",
$argKind, $argDefaultKind, $this->sendBy, $this->name,
$simpleArgType->toTypeCode(), $argType->isNullable(),
$this->hasProperDefaultValue() ? ", " . $this->getDefaultValueAsArginfoString() : ""
);
}
return sprintf(
"\tZEND_%s_OBJ_INFO%s(%s, %s, %s, %d%s)\n",
$argKind, $argDefaultKind, $this->sendBy, $this->name,
$simpleArgType->toEscapedName(), $argType->isNullable(),
$this->hasProperDefaultValue() ? ", " . $this->getDefaultValueAsArginfoString() : ""
);
}
$arginfoType = $argType->toArginfoType();
if ($arginfoType->hasClassType()) {
return sprintf(
"\tZEND_%s_OBJ_TYPE_MASK(%s, %s, %s, %s%s)\n",
$argKind, $this->sendBy, $this->name,
$arginfoType->toClassTypeString(), $arginfoType->toTypeMask(),
!$this->isVariadic ? ", " . $this->getDefaultValueAsArginfoString() : ""
);
}
return sprintf(
"\tZEND_%s_TYPE_MASK(%s, %s, %s, %s)\n",
$argKind, $this->sendBy, $this->name,
$arginfoType->toTypeMask(),
$this->getDefaultValueAsArginfoString()
);
}
return sprintf(
"\tZEND_%s_INFO%s(%s, %s%s)\n",
$argKind, $argDefaultKind, $this->sendBy, $this->name,
$this->hasProperDefaultValue() ? ", " . $this->getDefaultValueAsArginfoString() : ""
);
}
}

interface VariableLikeName {
Expand Down Expand Up @@ -5002,51 +5046,7 @@ function funcInfoToCode(FileInfo $fileInfo, FuncInfo $funcInfo): string {
}

foreach ($funcInfo->args as $argInfo) {
$argKind = $argInfo->isVariadic ? "ARG_VARIADIC" : "ARG";
$argDefaultKind = $argInfo->hasProperDefaultValue() ? "_WITH_DEFAULT_VALUE" : "";
$argType = $argInfo->type;
if ($argType !== null) {
if (null !== $simpleArgType = $argType->tryToSimpleType()) {
if ($simpleArgType->isBuiltin) {
$code .= sprintf(
"\tZEND_%s_TYPE_INFO%s(%s, %s, %s, %d%s)\n",
$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->sendBy, $argInfo->name,
$simpleArgType->toEscapedName(), $argType->isNullable(),
$argInfo->hasProperDefaultValue() ? ", " . $argInfo->getDefaultValueAsArginfoString() : ""
);
}
} else {
$arginfoType = $argType->toArginfoType();
if ($arginfoType->hasClassType()) {
$code .= sprintf(
"\tZEND_%s_OBJ_TYPE_MASK(%s, %s, %s, %s%s)\n",
$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->sendBy, $argInfo->name,
$arginfoType->toTypeMask(),
$argInfo->getDefaultValueAsArginfoString()
);
}
}
} else {
$code .= sprintf(
"\tZEND_%s_INFO%s(%s, %s%s)\n",
$argKind, $argDefaultKind, $argInfo->sendBy, $argInfo->name,
$argInfo->hasProperDefaultValue() ? ", " . $argInfo->getDefaultValueAsArginfoString() : ""
);
}
$code .= $argInfo->toZendInfo();
}

$code .= "ZEND_END_ARG_INFO()";
Expand Down