@@ -1299,6 +1299,19 @@ public function generateVersionDependentFlagCode(
1299
1299
}
1300
1300
}
1301
1301
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
+
1302
1315
class FuncInfo {
1303
1316
public /* readonly */ FunctionOrMethodName $ name ;
1304
1317
private /* readonly */ int $ classFlags ;
@@ -4189,6 +4202,8 @@ class FileInfo {
4189
4202
public array $ funcInfos = [];
4190
4203
/** @var ClassInfo[] */
4191
4204
public array $ classInfos = [];
4205
+ /** @var IncludeInfo[] */
4206
+ public array $ includeInfos = [];
4192
4207
public bool $ generateFunctionEntries = false ;
4193
4208
public string $ declarationPrefix = "" ;
4194
4209
public bool $ generateClassEntries = false ;
@@ -4337,6 +4352,16 @@ private function handleStatements(array $stmts, PrettyPrinterAbstract $prettyPri
4337
4352
$ conds = [];
4338
4353
foreach ($ stmts as $ stmt ) {
4339
4354
$ 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
+ }
4340
4365
4341
4366
if ($ stmt instanceof Stmt \Nop) {
4342
4367
continue ;
@@ -5162,6 +5187,17 @@ function generateArgInfoCode(
5162
5187
5163
5188
$ generatedFuncInfos = [];
5164
5189
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
+
5165
5201
$ argInfoCode = generateCodeWithConditions (
5166
5202
$ fileInfo ->getAllFuncInfos (), "\n" ,
5167
5203
static function (FuncInfo $ funcInfo ) use (&$ generatedFuncInfos , $ fileInfo ) {
0 commit comments