@@ -1317,6 +1317,41 @@ static ZEND_COLD void zend_ast_export_class_no_header(smart_str *str, zend_ast_d
1317
1317
smart_str_appends (str , "}" );
1318
1318
}
1319
1319
1320
+ static ZEND_COLD void zend_ast_export_attributes (smart_str * str , zend_ast * ast , int indent , zend_bool newlines ) {
1321
+ zend_ast_list * list = zend_ast_get_list (ast );
1322
+ uint32_t i ;
1323
+
1324
+ for (i = 0 ; i < list -> children ; i ++ ) {
1325
+ zend_ast * attr = list -> child [i ];
1326
+
1327
+ smart_str_appends (str , "<<" );
1328
+ smart_str_append (str , zend_ast_get_str (attr -> child [0 ]));
1329
+
1330
+ if (attr -> child [1 ]) {
1331
+ zend_ast_list * args = zend_ast_get_list (attr -> child [1 ]);
1332
+ uint32_t j ;
1333
+
1334
+ smart_str_appendc (str , '(' );
1335
+ for (j = 0 ; j < args -> children ; j ++ ) {
1336
+ if (j ) {
1337
+ smart_str_appends (str , ", " );
1338
+ }
1339
+ zend_ast_export_ex (str , args -> child [j ], 0 , indent );
1340
+ }
1341
+ smart_str_appendc (str , ')' );
1342
+ }
1343
+
1344
+ smart_str_appends (str , ">>" );
1345
+
1346
+ if (newlines ) {
1347
+ smart_str_appendc (str , '\n' );
1348
+ zend_ast_export_indent (str , indent );
1349
+ } else {
1350
+ smart_str_appendc (str , ' ' );
1351
+ }
1352
+ }
1353
+ }
1354
+
1320
1355
static ZEND_COLD void zend_ast_export_type (smart_str * str , zend_ast * ast , int indent ) {
1321
1356
if (ast -> kind == ZEND_AST_TYPE_UNION ) {
1322
1357
zend_ast_list * list = zend_ast_get_list (ast );
@@ -1410,6 +1445,10 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
1410
1445
case ZEND_AST_ARROW_FUNC :
1411
1446
case ZEND_AST_METHOD :
1412
1447
decl = (zend_ast_decl * ) ast ;
1448
+ if (decl -> attributes ) {
1449
+ zend_bool newlines = (ast -> kind == ZEND_AST_CLOSURE || ast -> kind == ZEND_AST_ARROW_FUNC ) ? 0 : 1 ;
1450
+ zend_ast_export_attributes (str , decl -> attributes , indent , newlines );
1451
+ }
1413
1452
if (decl -> flags & ZEND_ACC_PUBLIC ) {
1414
1453
smart_str_appends (str , "public " );
1415
1454
} else if (decl -> flags & ZEND_ACC_PROTECTED ) {
@@ -1466,6 +1505,9 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
1466
1505
break ;
1467
1506
case ZEND_AST_CLASS :
1468
1507
decl = (zend_ast_decl * ) ast ;
1508
+ if (decl -> attributes ) {
1509
+ zend_ast_export_attributes (str , decl -> attributes , indent , 1 );
1510
+ }
1469
1511
if (decl -> flags & ZEND_ACC_INTERFACE ) {
1470
1512
smart_str_appends (str , "interface " );
1471
1513
} else if (decl -> flags & ZEND_ACC_TRAIT ) {
@@ -1521,6 +1563,9 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
1521
1563
zend_ast * type_ast = ast -> child [0 ];
1522
1564
zend_ast * prop_ast = ast -> child [1 ];
1523
1565
1566
+ if (ast -> child [2 ]) {
1567
+ zend_ast_export_attributes (str , ast -> child [2 ], indent , 1 );
1568
+ }
1524
1569
if (ast -> attr & ZEND_ACC_PUBLIC ) {
1525
1570
smart_str_appends (str , "public " );
1526
1571
} else if (ast -> attr & ZEND_ACC_PROTECTED ) {
@@ -1546,6 +1591,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
1546
1591
smart_str_appends (str , "const " );
1547
1592
goto simple_list ;
1548
1593
case ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES :
1594
+ zend_ast_export_attributes (str , ast -> child [1 ], indent , 1 );
1549
1595
zend_ast_export_ex (str , ast -> child [0 ], 0 , indent );
1550
1596
break ;
1551
1597
case ZEND_AST_NAME_LIST :
@@ -1789,13 +1835,17 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
1789
1835
case ZEND_AST_NEW :
1790
1836
smart_str_appends (str , "new " );
1791
1837
if (ast -> child [0 ]-> kind == ZEND_AST_CLASS ) {
1838
+ zend_ast_decl * decl = (zend_ast_decl * ) ast -> child [0 ];
1839
+ if (decl -> attributes ) {
1840
+ zend_ast_export_attributes (str , decl -> attributes , indent , 0 );
1841
+ }
1792
1842
smart_str_appends (str , "class" );
1793
1843
if (zend_ast_get_list (ast -> child [1 ])-> children ) {
1794
1844
smart_str_appendc (str , '(' );
1795
1845
zend_ast_export_ex (str , ast -> child [1 ], 0 , indent );
1796
1846
smart_str_appendc (str , ')' );
1797
1847
}
1798
- zend_ast_export_class_no_header (str , ( zend_ast_decl * ) ast -> child [ 0 ] , indent );
1848
+ zend_ast_export_class_no_header (str , decl , indent );
1799
1849
} else {
1800
1850
zend_ast_export_ns_name (str , ast -> child [0 ], 0 , indent );
1801
1851
smart_str_appendc (str , '(' );
@@ -2006,6 +2056,9 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
2006
2056
zend_ast_export_indent (str , indent );
2007
2057
break ;
2008
2058
case ZEND_AST_PARAM :
2059
+ if (ast -> child [3 ]) {
2060
+ zend_ast_export_attributes (str , ast -> child [3 ], indent , 0 );
2061
+ }
2009
2062
if (ast -> child [0 ]) {
2010
2063
zend_ast_export_type (str , ast -> child [0 ], indent );
2011
2064
smart_str_appendc (str , ' ' );
0 commit comments