@@ -4275,7 +4275,7 @@ public function shouldGenerateLegacyArginfo(): bool {
42754275 public function handleStatements (array $ stmts , PrettyPrinterAbstract $ prettyPrinter ): void {
42764276 $ conds = [];
42774277 foreach ($ stmts as $ stmt ) {
4278- $ cond = handlePreprocessorConditions ($ conds , $ stmt );
4278+ $ cond = self :: handlePreprocessorConditions ($ conds , $ stmt );
42794279
42804280 if ($ stmt instanceof Stmt \Nop) {
42814281 continue ;
@@ -4325,7 +4325,7 @@ public function handleStatements(array $stmts, PrettyPrinterAbstract $prettyPrin
43254325 $ methodInfos = [];
43264326 $ enumCaseInfos = [];
43274327 foreach ($ stmt ->stmts as $ classStmt ) {
4328- $ cond = handlePreprocessorConditions ($ conds , $ classStmt );
4328+ $ cond = self :: handlePreprocessorConditions ($ conds , $ classStmt );
43294329 if ($ classStmt instanceof Stmt \Nop) {
43304330 continue ;
43314331 }
@@ -4415,6 +4415,34 @@ public function handleStatements(array $stmts, PrettyPrinterAbstract $prettyPrin
44154415 throw new Exception ("Unterminated preprocessor conditions " );
44164416 }
44174417 }
4418+
4419+ private static function handlePreprocessorConditions (array &$ conds , Stmt $ stmt ): ?string {
4420+ foreach ($ stmt ->getComments () as $ comment ) {
4421+ $ text = trim ($ comment ->getText ());
4422+ if (preg_match ('/^#\s*if\s+(.+)$/ ' , $ text , $ matches )) {
4423+ $ conds [] = $ matches [1 ];
4424+ } else if (preg_match ('/^#\s*ifdef\s+(.+)$/ ' , $ text , $ matches )) {
4425+ $ conds [] = "defined( $ matches [1 ]) " ;
4426+ } else if (preg_match ('/^#\s*ifndef\s+(.+)$/ ' , $ text , $ matches )) {
4427+ $ conds [] = "!defined( $ matches [1 ]) " ;
4428+ } else if (preg_match ('/^#\s*else$/ ' , $ text )) {
4429+ if (empty ($ conds )) {
4430+ throw new Exception ("Encountered else without corresponding #if " );
4431+ }
4432+ $ cond = array_pop ($ conds );
4433+ $ conds [] = "!( $ cond) " ;
4434+ } else if (preg_match ('/^#\s*endif$/ ' , $ text )) {
4435+ if (empty ($ conds )) {
4436+ throw new Exception ("Encountered #endif without corresponding #if " );
4437+ }
4438+ array_pop ($ conds );
4439+ } else if ($ text [0 ] === '# ' ) {
4440+ throw new Exception ("Unrecognized preprocessor directive \"$ text \"" );
4441+ }
4442+ }
4443+
4444+ return empty ($ conds ) ? null : implode (' && ' , $ conds );
4445+ }
44184446}
44194447
44204448class DocCommentTag {
@@ -4987,34 +5015,6 @@ function parseClass(
49875015 );
49885016}
49895017
4990- function handlePreprocessorConditions (array &$ conds , Stmt $ stmt ): ?string {
4991- foreach ($ stmt ->getComments () as $ comment ) {
4992- $ text = trim ($ comment ->getText ());
4993- if (preg_match ('/^#\s*if\s+(.+)$/ ' , $ text , $ matches )) {
4994- $ conds [] = $ matches [1 ];
4995- } else if (preg_match ('/^#\s*ifdef\s+(.+)$/ ' , $ text , $ matches )) {
4996- $ conds [] = "defined( $ matches [1 ]) " ;
4997- } else if (preg_match ('/^#\s*ifndef\s+(.+)$/ ' , $ text , $ matches )) {
4998- $ conds [] = "!defined( $ matches [1 ]) " ;
4999- } else if (preg_match ('/^#\s*else$/ ' , $ text )) {
5000- if (empty ($ conds )) {
5001- throw new Exception ("Encountered else without corresponding #if " );
5002- }
5003- $ cond = array_pop ($ conds );
5004- $ conds [] = "!( $ cond) " ;
5005- } else if (preg_match ('/^#\s*endif$/ ' , $ text )) {
5006- if (empty ($ conds )) {
5007- throw new Exception ("Encountered #endif without corresponding #if " );
5008- }
5009- array_pop ($ conds );
5010- } else if ($ text [0 ] === '# ' ) {
5011- throw new Exception ("Unrecognized preprocessor directive \"$ text \"" );
5012- }
5013- }
5014-
5015- return empty ($ conds ) ? null : implode (' && ' , $ conds );
5016- }
5017-
50185018/** @return DocComment[] */
50195019function getFileDocComments (array $ stmts ): array {
50205020 if (empty ($ stmts )) {
0 commit comments