Skip to content

Commit ddd33fd

Browse files
Generated arginfo headers: combine preprocessor conditional blocks (2) (#18667)
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 4dfba7a commit ddd33fd

25 files changed

+13
-817
lines changed

build/gen_stub.php

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

2752-
$code = "";
2753-
2754-
if ($this->cond) {
2755-
$code .= "#if {$this->cond}\n";
2756-
}
2752+
// Condition will be added by generateCodeWithConditions()
27572753

27582754
if ($this->name->isClassConst()) {
2759-
$code .= $this->getClassConstDeclaration($value, $allConstInfos);
2755+
$code = $this->getClassConstDeclaration($value, $allConstInfos);
27602756
} else {
2761-
$code .= $this->getGlobalConstDeclaration($value);
2757+
$code = $this->getGlobalConstDeclaration($value);
27622758
}
27632759
$code .= $this->getValueAssertion($value);
27642760

2765-
if ($this->cond) {
2766-
$code .= "#endif\n";
2767-
}
2768-
27692761
return $code;
27702762
}
27712763

@@ -3556,9 +3548,11 @@ function (Name $item) {
35563548
$code .= "\tzend_register_class_alias(\"" . str_replace("\\", "\\\\", $this->alias) . "\", class_entry);\n";
35573549
}
35583550

3559-
foreach ($this->constInfos as $const) {
3560-
$code .= $const->getDeclaration($allConstInfos);
3561-
}
3551+
$code .= generateCodeWithConditions(
3552+
$this->constInfos,
3553+
'',
3554+
static fn (ConstInfo $const): string => $const->getDeclaration($allConstInfos)
3555+
);
35623556

35633557
foreach ($this->enumCaseInfos as $enumCase) {
35643558
$code .= $enumCase->getDeclaration($allConstInfos);
@@ -5192,9 +5186,11 @@ static function (FuncInfo $funcInfo) use ($fileInfo, &$generatedFunctionDeclarat
51925186
$code .= "\nstatic void register_{$stubFilenameWithoutExtension}_symbols(int module_number)\n";
51935187
$code .= "{\n";
51945188

5195-
foreach ($fileInfo->constInfos as $constInfo) {
5196-
$code .= $constInfo->getDeclaration($allConstInfos);
5197-
}
5189+
$code .= generateCodeWithConditions(
5190+
$fileInfo->constInfos,
5191+
'',
5192+
static fn (ConstInfo $constInfo): string => $constInfo->getDeclaration($allConstInfos)
5193+
);
51985194

51995195
if ($attributeInitializationCode !== "" && $fileInfo->constInfos) {
52005196
$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 & 6 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)