@@ -4302,7 +4302,7 @@ public function shouldGenerateLegacyArginfo(): bool {
4302
4302
public function handleStatements (array $ stmts , PrettyPrinterAbstract $ prettyPrinter ): void {
4303
4303
$ conds = [];
4304
4304
foreach ($ stmts as $ stmt ) {
4305
- $ cond = handlePreprocessorConditions ($ conds , $ stmt );
4305
+ $ cond = self :: handlePreprocessorConditions ($ conds , $ stmt );
4306
4306
4307
4307
if ($ stmt instanceof Stmt \Nop) {
4308
4308
continue ;
@@ -4352,7 +4352,7 @@ public function handleStatements(array $stmts, PrettyPrinterAbstract $prettyPrin
4352
4352
$ methodInfos = [];
4353
4353
$ enumCaseInfos = [];
4354
4354
foreach ($ stmt ->stmts as $ classStmt ) {
4355
- $ cond = handlePreprocessorConditions ($ conds , $ classStmt );
4355
+ $ cond = self :: handlePreprocessorConditions ($ conds , $ classStmt );
4356
4356
if ($ classStmt instanceof Stmt \Nop) {
4357
4357
continue ;
4358
4358
}
@@ -4442,6 +4442,34 @@ public function handleStatements(array $stmts, PrettyPrinterAbstract $prettyPrin
4442
4442
throw new Exception ("Unterminated preprocessor conditions " );
4443
4443
}
4444
4444
}
4445
+
4446
+ private static function handlePreprocessorConditions (array &$ conds , Stmt $ stmt ): ?string {
4447
+ foreach ($ stmt ->getComments () as $ comment ) {
4448
+ $ text = trim ($ comment ->getText ());
4449
+ if (preg_match ('/^#\s*if\s+(.+)$/ ' , $ text , $ matches )) {
4450
+ $ conds [] = $ matches [1 ];
4451
+ } else if (preg_match ('/^#\s*ifdef\s+(.+)$/ ' , $ text , $ matches )) {
4452
+ $ conds [] = "defined( $ matches [1 ]) " ;
4453
+ } else if (preg_match ('/^#\s*ifndef\s+(.+)$/ ' , $ text , $ matches )) {
4454
+ $ conds [] = "!defined( $ matches [1 ]) " ;
4455
+ } else if (preg_match ('/^#\s*else$/ ' , $ text )) {
4456
+ if (empty ($ conds )) {
4457
+ throw new Exception ("Encountered else without corresponding #if " );
4458
+ }
4459
+ $ cond = array_pop ($ conds );
4460
+ $ conds [] = "!( $ cond) " ;
4461
+ } else if (preg_match ('/^#\s*endif$/ ' , $ text )) {
4462
+ if (empty ($ conds )) {
4463
+ throw new Exception ("Encountered #endif without corresponding #if " );
4464
+ }
4465
+ array_pop ($ conds );
4466
+ } else if ($ text [0 ] === '# ' ) {
4467
+ throw new Exception ("Unrecognized preprocessor directive \"$ text \"" );
4468
+ }
4469
+ }
4470
+
4471
+ return empty ($ conds ) ? null : implode (' && ' , $ conds );
4472
+ }
4445
4473
}
4446
4474
4447
4475
class DocCommentTag {
@@ -5014,34 +5042,6 @@ function parseClass(
5014
5042
);
5015
5043
}
5016
5044
5017
- function handlePreprocessorConditions (array &$ conds , Stmt $ stmt ): ?string {
5018
- foreach ($ stmt ->getComments () as $ comment ) {
5019
- $ text = trim ($ comment ->getText ());
5020
- if (preg_match ('/^#\s*if\s+(.+)$/ ' , $ text , $ matches )) {
5021
- $ conds [] = $ matches [1 ];
5022
- } else if (preg_match ('/^#\s*ifdef\s+(.+)$/ ' , $ text , $ matches )) {
5023
- $ conds [] = "defined( $ matches [1 ]) " ;
5024
- } else if (preg_match ('/^#\s*ifndef\s+(.+)$/ ' , $ text , $ matches )) {
5025
- $ conds [] = "!defined( $ matches [1 ]) " ;
5026
- } else if (preg_match ('/^#\s*else$/ ' , $ text )) {
5027
- if (empty ($ conds )) {
5028
- throw new Exception ("Encountered else without corresponding #if " );
5029
- }
5030
- $ cond = array_pop ($ conds );
5031
- $ conds [] = "!( $ cond) " ;
5032
- } else if (preg_match ('/^#\s*endif$/ ' , $ text )) {
5033
- if (empty ($ conds )) {
5034
- throw new Exception ("Encountered #endif without corresponding #if " );
5035
- }
5036
- array_pop ($ conds );
5037
- } else if ($ text [0 ] === '# ' ) {
5038
- throw new Exception ("Unrecognized preprocessor directive \"$ text \"" );
5039
- }
5040
- }
5041
-
5042
- return empty ($ conds ) ? null : implode (' && ' , $ conds );
5043
- }
5044
-
5045
5045
/** @return DocComment[] */
5046
5046
function getFileDocComments (array $ stmts ): array {
5047
5047
if (empty ($ stmts )) {
0 commit comments