Skip to content

Commit ea3af1b

Browse files
Generated arginfo headers: combine preprocessor conditional blocks (2)
When global constants' or class constants' availability is based on some preprocessor condition, the generated arginfo header files wrap the declarations in the preprocessor `#if` conditional blocks, one per declaration, even if they are in the same conditional block based on comments in the stub file. Instead of having multiple conditional blocks one after the other with the same condition, combine them into a single conditional block.
1 parent 0a2f367 commit ea3af1b

24 files changed

+13
-811
lines changed

build/gen_stub.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,23 +2742,15 @@ public function getDeclaration(array $allConstInfos): string
27422742
throw new Exception("Constant " . $this->name->__toString() . " must have a @cvalue annotation");
27432743
}
27442744

2745-
$code = "";
2746-
2747-
if ($this->cond) {
2748-
$code .= "#if {$this->cond}\n";
2749-
}
2745+
// Condition will be added by generateCodeWithConditions()
27502746

27512747
if ($this->name->isClassConst()) {
2752-
$code .= $this->getClassConstDeclaration($value, $allConstInfos);
2748+
$code = $this->getClassConstDeclaration($value, $allConstInfos);
27532749
} else {
2754-
$code .= $this->getGlobalConstDeclaration($value);
2750+
$code = $this->getGlobalConstDeclaration($value);
27552751
}
27562752
$code .= $this->getValueAssertion($value);
27572753

2758-
if ($this->cond) {
2759-
$code .= "#endif\n";
2760-
}
2761-
27622754
return $code;
27632755
}
27642756

@@ -3553,9 +3545,11 @@ function (Name $item) {
35533545
$code .= "\tzend_register_class_alias(\"" . str_replace("\\", "\\\\", $this->alias) . "\", class_entry);\n";
35543546
}
35553547

3556-
foreach ($this->constInfos as $const) {
3557-
$code .= $const->getDeclaration($allConstInfos);
3558-
}
3548+
$code .= generateCodeWithConditions(
3549+
$this->constInfos,
3550+
'',
3551+
static fn ( $const ) => $const->getDeclaration($allConstInfos)
3552+
);
35593553

35603554
foreach ($this->enumCaseInfos as $enumCase) {
35613555
$code .= $enumCase->getDeclaration($allConstInfos);
@@ -5187,9 +5181,11 @@ static function (FuncInfo $funcInfo) use ($fileInfo, &$generatedFunctionDeclarat
51875181
$code .= "\nstatic void register_{$stubFilenameWithoutExtension}_symbols(int module_number)\n";
51885182
$code .= "{\n";
51895183

5190-
foreach ($fileInfo->constInfos as $constInfo) {
5191-
$code .= $constInfo->getDeclaration($allConstInfos);
5192-
}
5184+
$code .= generateCodeWithConditions(
5185+
$fileInfo->constInfos,
5186+
'',
5187+
static fn ( $constInfo ) => $constInfo->getDeclaration($allConstInfos)
5188+
);
51935189

51945190
if ($attributeInitializationCode !== "" && $fileInfo->constInfos) {
51955191
$code .= "\n";

ext/com_dotnet/com_extension_arginfo.h

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/curl/curl_arginfo.h

Lines changed: 0 additions & 158 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/dba/dba_arginfo.h

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/gd/gd_arginfo.h

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/intl/listformatter/listformatter_arginfo.h

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/intl/spoofchecker/spoofchecker_arginfo.h

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/intl/uchar/uchar_arginfo.h

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)