@@ -1570,6 +1570,16 @@ static ZEND_COLD void zend_ast_export_ns_name(smart_str *str, zend_ast *ast, int
1570
1570
zend_ast_export_ex (str , ast , priority , indent );
1571
1571
}
1572
1572
1573
+ static ZEND_COLD void zend_ast_export_class_name (smart_str * str , zend_ast * ast , int priority , int indent )
1574
+ {
1575
+ if (ast -> kind == ZEND_AST_CLASS_REF ) {
1576
+ ZEND_ASSERT (ast -> child [1 ] == NULL && "Generic params not supported yet" );
1577
+ zend_ast_export_ns_name (str , ast -> child [0 ], priority , indent );
1578
+ return ;
1579
+ }
1580
+ zend_ast_export_ex (str , ast , priority , indent );
1581
+ }
1582
+
1573
1583
static ZEND_COLD bool zend_ast_valid_var_char (char ch )
1574
1584
{
1575
1585
unsigned char c = (unsigned char )ch ;
@@ -1690,7 +1700,7 @@ static ZEND_COLD void zend_ast_export_name_list_ex(smart_str *str, zend_ast_list
1690
1700
if (i != 0 ) {
1691
1701
smart_str_appends (str , separator );
1692
1702
}
1693
- zend_ast_export_name (str , list -> child [i ], 0 , indent );
1703
+ zend_ast_export_ns_name (str , list -> child [i ], 0 , indent );
1694
1704
i ++ ;
1695
1705
}
1696
1706
}
@@ -1957,6 +1967,21 @@ static ZEND_COLD void zend_ast_export_type(smart_str *str, zend_ast *ast, int in
1957
1967
zend_ast_export_ns_name (str , ast , 0 , indent );
1958
1968
}
1959
1969
1970
+ static ZEND_COLD void zend_ast_export_generic_arg_list (smart_str * str , const zend_ast_list * list , int indent ) {
1971
+ // TODO Why cannot I just use
1972
+ // zend_ast_export_list(str, list, true, 0, indent);
1973
+ // ?
1974
+
1975
+ uint32_t i = 0 ;
1976
+ while (i < list -> children ) {
1977
+ if (i != 0 ) {
1978
+ smart_str_appends (str , ", " );
1979
+ }
1980
+ zend_ast_export_type (str , list -> child [i ], indent );
1981
+ i ++ ;
1982
+ }
1983
+ }
1984
+
1960
1985
static ZEND_COLD void zend_ast_export_hook_list (smart_str * str , zend_ast_list * hook_list , int indent )
1961
1986
{
1962
1987
smart_str_appends (str , " {" );
@@ -2156,10 +2181,17 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
2156
2181
}
2157
2182
smart_str_appends (str , "class " );
2158
2183
}
2159
- smart_str_appendl (str , ZSTR_VAL (decl -> name ), ZSTR_LEN (decl -> name ));
2160
- if (decl -> flags & ZEND_ACC_ENUM && decl -> child [4 ]) {
2161
- smart_str_appends (str , ": " );
2162
- zend_ast_export_type (str , decl -> child [4 ], indent );
2184
+ smart_str_append (str , decl -> name );
2185
+ if (decl -> child [4 ]) {
2186
+ if (decl -> flags & ZEND_ACC_ENUM ) {
2187
+ smart_str_appends (str , ": " );
2188
+ zend_ast_export_type (str , decl -> child [4 ], indent );
2189
+ } else {
2190
+ ZEND_ASSERT (decl -> flags & ZEND_ACC_INTERFACE );
2191
+ smart_str_appendc (str , '<' );
2192
+ zend_ast_export_list (str , zend_ast_get_list (decl -> child [4 ]), true, 0 , indent );
2193
+ smart_str_appendc (str , '>' );
2194
+ }
2163
2195
}
2164
2196
zend_ast_export_class_no_header (str , decl , indent );
2165
2197
smart_str_appendc (str , '\n' );
@@ -2444,6 +2476,21 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
2444
2476
smart_str_appends (str , "::" );
2445
2477
zend_ast_export_name (str , ast -> child [1 ], 0 , indent );
2446
2478
break ;
2479
+ case ZEND_AST_GENERIC_PARAM :
2480
+ zend_ast_export_name (str , ast -> child [0 ], 0 , indent );
2481
+ if (ast -> child [1 ]) {
2482
+ smart_str_appendl (str , ZEND_STRL (" : " ));
2483
+ zend_ast_export_type (str , ast -> child [1 ], indent );
2484
+ }
2485
+ break ;
2486
+ case ZEND_AST_CLASS_REF :
2487
+ zend_ast_export_ns_name (str , ast -> child [0 ], 0 , indent );
2488
+ if (ast -> child [1 ]) {
2489
+ smart_str_appendc (str , '<' );
2490
+ zend_ast_export_generic_arg_list (str , zend_ast_get_list (ast -> child [1 ]), indent );
2491
+ smart_str_appendc (str , '>' );
2492
+ }
2493
+ break ;
2447
2494
case ZEND_AST_CLASS_NAME :
2448
2495
if (ast -> child [0 ] == NULL ) {
2449
2496
/* The const expr representation stores the fetch type instead. */
@@ -2457,7 +2504,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
2457
2504
EMPTY_SWITCH_DEFAULT_CASE ()
2458
2505
}
2459
2506
} else {
2460
- zend_ast_export_ns_name (str , ast -> child [0 ], 0 , indent );
2507
+ zend_ast_export_class_name (str , ast -> child [0 ], 0 , indent );
2461
2508
}
2462
2509
smart_str_appends (str , "::class" );
2463
2510
break ;
@@ -2725,17 +2772,6 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
2725
2772
smart_str_appends (str , ": " );
2726
2773
ast = ast -> child [1 ];
2727
2774
goto tail_call ;
2728
- // TODO Export generic types
2729
- //case ZEND_AST_ASSOCIATED_TYPE:
2730
- // smart_str_appends(str, "type ");
2731
- // zend_ast_export_name(str, ast->child[0], 0, indent);
2732
- // if (ast->child[1]) {
2733
- // smart_str_appends(str, " : ");
2734
- // smart_str_appends(str, " : ");
2735
- // zend_ast_export_type(str, ast->child[1], indent);
2736
- // }
2737
- // smart_str_appendc(str, ';');
2738
- //break;
2739
2775
2740
2776
/* 3 child nodes */
2741
2777
case ZEND_AST_METHOD_CALL :
0 commit comments