@@ -1299,6 +1299,19 @@ public function generateVersionDependentFlagCode(
12991299 }
13001300}
13011301
1302+ class IncludeInfo {
1303+ public /* readonly */ ?string $ cond ;
1304+ public /* readonly */ string $ include ;
1305+
1306+ public function __construct (
1307+ string $ include ,
1308+ ?string $ cond ,
1309+ ) {
1310+ $ this ->include = $ include ;
1311+ $ this ->cond = $ cond ;
1312+ }
1313+ }
1314+
13021315class FuncInfo {
13031316 public /* readonly */ FunctionOrMethodName $ name ;
13041317 private /* readonly */ int $ classFlags ;
@@ -4189,6 +4202,8 @@ class FileInfo {
41894202 public array $ funcInfos = [];
41904203 /** @var ClassInfo[] */
41914204 public array $ classInfos = [];
4205+ /** @var IncludeInfo[] */
4206+ public array $ includeInfos = [];
41924207 public bool $ generateFunctionEntries = false ;
41934208 public string $ declarationPrefix = "" ;
41944209 public bool $ generateClassEntries = false ;
@@ -4337,6 +4352,16 @@ private function handleStatements(array $stmts, PrettyPrinterAbstract $prettyPri
43374352 $ conds = [];
43384353 foreach ($ stmts as $ stmt ) {
43394354 $ cond = self ::handlePreprocessorConditions ($ conds , $ stmt );
4355+
4356+ if ($ stmt instanceof Stmt \Declare_) {
4357+ foreach ($ stmt ->declares as $ declare ) {
4358+ if ($ declare ->key ->name !== 'c_include ' ) {
4359+ throw new Exception ("Unexpected declare {$ declare ->key ->name }" );
4360+ }
4361+ $ this ->includeInfos [] = new IncludeInfo ((string )EvaluatedValue::createFromExpression ($ declare ->value , null , null , [])->value , $ cond );
4362+ }
4363+ continue ;
4364+ }
43404365
43414366 if ($ stmt instanceof Stmt \Nop) {
43424367 continue ;
@@ -5162,6 +5187,17 @@ function generateArgInfoCode(
51625187
51635188 $ generatedFuncInfos = [];
51645189
5190+ $ argInfoCode = generateCodeWithConditions (
5191+ $ fileInfo ->includeInfos , "\n" ,
5192+ static function (IncludeInfo $ includeInfo ) {
5193+ return sprintf ("#include %s \n" , $ includeInfo ->include );
5194+ }
5195+ );
5196+
5197+ if ($ argInfoCode !== "" ) {
5198+ $ code .= "$ argInfoCode \n" ;
5199+ }
5200+
51655201 $ argInfoCode = generateCodeWithConditions (
51665202 $ fileInfo ->getAllFuncInfos (), "\n" ,
51675203 static function (FuncInfo $ funcInfo ) use (&$ generatedFuncInfos , $ fileInfo ) {
0 commit comments