Skip to content

Commit 988da4c

Browse files
gen_stub: simplify FuncInfo::getFunctionEntry()
1 parent 9dfee95 commit 988da4c

File tree

1 file changed

+33
-46
lines changed

1 file changed

+33
-46
lines changed

build/gen_stub.php

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,14 +1513,6 @@ private function getFramelessFunctionInfosName(): string {
15131513
}
15141514

15151515
public function getFunctionEntry(): string {
1516-
$code = "";
1517-
1518-
$php84MinimumCompatibility = $this->minimumPhpVersionIdCompatibility === null || $this->minimumPhpVersionIdCompatibility >= PHP_84_VERSION_ID;
1519-
$isVanillaEntry = $this->alias === null && !$this->supportsCompileTimeEval && $this->exposedDocComment === null && empty($this->framelessFunctionInfos);
1520-
$argInfoName = $this->getArgInfoName();
1521-
$flagsByPhpVersions = $this->getArginfoFlagsByPhpVersions();
1522-
$functionEntryCode = null;
1523-
15241516
if (!empty($this->framelessFunctionInfos)) {
15251517
if ($this->isMethod()) {
15261518
throw new Exception('Frameless methods are not supported yet');
@@ -1533,6 +1525,10 @@ public function getFunctionEntry(): string {
15331525
}
15341526
}
15351527

1528+
$isVanillaEntry = $this->alias === null && !$this->supportsCompileTimeEval && $this->exposedDocComment === null && empty($this->framelessFunctionInfos);
1529+
$argInfoName = $this->getArgInfoName();
1530+
$flagsByPhpVersions = $this->getArginfoFlagsByPhpVersions();
1531+
15361532
if ($this->isMethod()) {
15371533
$zendName = '"' . $this->name->methodName . '"';
15381534
if ($this->alias) {
@@ -1543,69 +1539,60 @@ public function getFunctionEntry(): string {
15431539
} else {
15441540
throw new Error("Cannot happen");
15451541
}
1542+
} elseif ($this->flags & Modifiers::ABSTRACT) {
1543+
$name = "NULL";
15461544
} else {
1547-
if ($this->flags & Modifiers::ABSTRACT) {
1548-
$name = "NULL";
1549-
} else {
1550-
$name = "zim_" . $this->name->getDeclarationClassName() . "_" . $this->name->methodName;
1545+
$name = "zim_" . $this->name->getDeclarationClassName() . "_" . $this->name->methodName;
15511546

1552-
if ($isVanillaEntry) {
1553-
$template = "\tZEND_ME(" . $this->name->getDeclarationClassName() . ", " . $this->name->methodName . ", $argInfoName, %s)\n";
1554-
$flagsCode = $flagsByPhpVersions->generateVersionDependentFlagCode(
1555-
$template,
1556-
$this->minimumPhpVersionIdCompatibility
1557-
);
1558-
$functionEntryCode = rtrim($flagsCode);
1559-
}
1547+
if ($isVanillaEntry) {
1548+
$template = "\tZEND_ME(" . $this->name->getDeclarationClassName() . ", " . $this->name->methodName . ", $argInfoName, %s)\n";
1549+
$flagsCode = $flagsByPhpVersions->generateVersionDependentFlagCode(
1550+
$template,
1551+
$this->minimumPhpVersionIdCompatibility
1552+
);
1553+
return rtrim($flagsCode) . "\n";
15601554
}
15611555
}
15621556
} else if ($this->name instanceof FunctionName) {
15631557
$functionName = $this->name->getFunctionName();
15641558
$declarationName = $this->alias ? $this->alias->getNonNamespacedName() : $this->name->getDeclarationName();
1559+
$name = "zif_$declarationName";
15651560

15661561
if ($this->name->getNamespace()) {
15671562
$namespace = addslashes($this->name->getNamespace());
15681563
$zendName = "ZEND_NS_NAME(\"$namespace\", \"$functionName\")";
1569-
$name = "zif_$declarationName";
15701564
} else {
1571-
$zendName = '"' . $functionName . '"';
1572-
$name = "zif_$declarationName";
1573-
15741565
// Can only use ZEND_FE() if we have no flags for *all* versions
15751566
if ($isVanillaEntry && $flagsByPhpVersions->isEmpty()) {
1576-
$functionEntryCode = "\tZEND_FE($declarationName, $argInfoName)";
1567+
return "\tZEND_FE($declarationName, $argInfoName)\n";
15771568
}
1569+
$zendName = '"' . $functionName . '"';
15781570
}
15791571
} else {
15801572
throw new Error("Cannot happen");
15811573
}
15821574

1583-
if ($functionEntryCode !== null) {
1584-
$code .= "$functionEntryCode\n";
1585-
} else {
1586-
if (!$php84MinimumCompatibility) {
1587-
$code .= "#if (PHP_VERSION_ID >= " . PHP_84_VERSION_ID . ")\n";
1588-
}
1575+
$docComment = $this->exposedDocComment ? '"' . $this->exposedDocComment->escape() . '"' : "NULL";
1576+
$framelessFuncInfosName = !empty($this->framelessFunctionInfos) ? $this->getFramelessFunctionInfosName() : "NULL";
15891577

1590-
$docComment = $this->exposedDocComment ? '"' . $this->exposedDocComment->escape() . '"' : "NULL";
1591-
$framelessFuncInfosName = !empty($this->framelessFunctionInfos) ? $this->getFramelessFunctionInfosName() : "NULL";
1578+
// Assume 8.4+ here, if older versions are supported this is conditional
1579+
$code = $flagsByPhpVersions->generateVersionDependentFlagCode(
1580+
"\tZEND_RAW_FENTRY($zendName, $name, $argInfoName, %s, $framelessFuncInfosName, $docComment)\n",
1581+
PHP_84_VERSION_ID
1582+
);
1583+
1584+
$php84MinimumCompatibility = $this->minimumPhpVersionIdCompatibility === null || $this->minimumPhpVersionIdCompatibility >= PHP_84_VERSION_ID;
1585+
if (!$php84MinimumCompatibility) {
1586+
$code = "#if (PHP_VERSION_ID >= " . PHP_84_VERSION_ID . ")\n$code";
1587+
$code .= "#else\n";
15921588

15931589
$code .= $flagsByPhpVersions->generateVersionDependentFlagCode(
1594-
"\tZEND_RAW_FENTRY($zendName, $name, $argInfoName, %s, $framelessFuncInfosName, $docComment)\n",
1595-
PHP_84_VERSION_ID
1590+
"\tZEND_RAW_FENTRY($zendName, $name, $argInfoName, %s)\n",
1591+
$this->minimumPhpVersionIdCompatibility,
1592+
PHP_83_VERSION_ID
15961593
);
15971594

1598-
if (!$php84MinimumCompatibility) {
1599-
$code .= "#else\n";
1600-
1601-
$code .= $flagsByPhpVersions->generateVersionDependentFlagCode(
1602-
"\tZEND_RAW_FENTRY($zendName, $name, $argInfoName, %s)\n",
1603-
$this->minimumPhpVersionIdCompatibility,
1604-
PHP_83_VERSION_ID
1605-
);
1606-
1607-
$code .= "#endif\n";
1608-
}
1595+
$code .= "#endif\n";
16091596
}
16101597

16111598
return $code;

0 commit comments

Comments
 (0)