@@ -47,10 +47,8 @@ void compile_alias_attributes(
47
47
HashTable * * attributes , zend_ast * ast
48
48
) /* {{{ */ {
49
49
zend_attribute * attr ;
50
- zend_internal_attribute * config ;
51
50
52
51
zend_ast_list * list = zend_ast_get_list (ast );
53
- uint32_t j ;
54
52
55
53
ZEND_ASSERT (ast -> kind == ZEND_AST_ARRAY );
56
54
@@ -71,53 +69,17 @@ void compile_alias_attributes(
71
69
}
72
70
73
71
zend_string * name = zend_resolve_class_name_ast (array_content -> child [0 ]);
74
- zend_string * lcname = zend_string_tolower_ex (name , false);
75
72
zend_ast_list * args = array_content -> child [1 ] ? zend_ast_get_list (array_content -> child [1 ]) : NULL ;
76
73
77
- config = zend_internal_attribute_get (lcname );
78
- zend_string_release (lcname );
79
-
80
74
uint32_t flags = (CG (active_op_array )-> fn_flags & ZEND_ACC_STRICT_TYPES )
81
75
? ZEND_ATTRIBUTE_STRICT_TYPES : 0 ;
82
76
attr = zend_add_attribute (
83
77
attributes , name , args ? args -> children : 0 , flags , 0 , array_content -> lineno );
84
78
zend_string_release (name );
85
79
86
80
/* Populate arguments */
87
- if (!args ) {
88
- continue ;
89
- }
90
- ZEND_ASSERT (args -> kind == ZEND_AST_ARG_LIST );
91
-
92
- bool uses_named_args = 0 ;
93
- for (j = 0 ; j < args -> children ; j ++ ) {
94
- zend_ast * * arg_ast_ptr = & args -> child [j ];
95
- zend_ast * arg_ast = * arg_ast_ptr ;
96
-
97
- if (arg_ast -> kind == ZEND_AST_UNPACK ) {
98
- zend_error_noreturn (E_COMPILE_ERROR ,
99
- "Cannot use unpacking in attribute argument list" );
100
- }
101
-
102
- if (arg_ast -> kind == ZEND_AST_NAMED_ARG ) {
103
- attr -> args [j ].name = zend_string_copy (zend_ast_get_str (arg_ast -> child [0 ]));
104
- arg_ast_ptr = & arg_ast -> child [1 ];
105
- uses_named_args = 1 ;
106
-
107
- for (uint32_t k = 0 ; k < j ; k ++ ) {
108
- if (attr -> args [k ].name &&
109
- zend_string_equals (attr -> args [k ].name , attr -> args [j ].name )) {
110
- zend_error_noreturn (E_COMPILE_ERROR , "Duplicate named parameter $%s" ,
111
- ZSTR_VAL (attr -> args [j ].name ));
112
- }
113
- }
114
- } else if (uses_named_args ) {
115
- zend_error_noreturn (E_COMPILE_ERROR ,
116
- "Cannot use positional argument after named argument" );
117
- }
118
-
119
- zend_const_expr_to_zval (
120
- & attr -> args [j ].value , arg_ast_ptr , /* allow_dynamic */ true);
81
+ if (args ) {
82
+ zend_attribute_populate_arguments (attr , args );
121
83
}
122
84
}
123
85
@@ -158,6 +120,41 @@ ZEND_API void zend_apply_internal_attribute_validation(HashTable *attributes, ui
158
120
} ZEND_HASH_FOREACH_END ();
159
121
}
160
122
123
+ ZEND_API void zend_attribute_populate_arguments (zend_attribute * attr , zend_ast_list * args ) {
124
+ ZEND_ASSERT (args -> kind == ZEND_AST_ARG_LIST );
125
+
126
+ bool uses_named_args = 0 ;
127
+ for (uint32_t j = 0 ; j < args -> children ; j ++ ) {
128
+ zend_ast * * arg_ast_ptr = & args -> child [j ];
129
+ zend_ast * arg_ast = * arg_ast_ptr ;
130
+
131
+ if (arg_ast -> kind == ZEND_AST_UNPACK ) {
132
+ zend_error_noreturn (E_COMPILE_ERROR ,
133
+ "Cannot use unpacking in attribute argument list" );
134
+ }
135
+
136
+ if (arg_ast -> kind == ZEND_AST_NAMED_ARG ) {
137
+ attr -> args [j ].name = zend_string_copy (zend_ast_get_str (arg_ast -> child [0 ]));
138
+ arg_ast_ptr = & arg_ast -> child [1 ];
139
+ uses_named_args = 1 ;
140
+
141
+ for (uint32_t k = 0 ; k < j ; k ++ ) {
142
+ if (attr -> args [k ].name &&
143
+ zend_string_equals (attr -> args [k ].name , attr -> args [j ].name )) {
144
+ zend_error_noreturn (E_COMPILE_ERROR , "Duplicate named parameter $%s" ,
145
+ ZSTR_VAL (attr -> args [j ].name ));
146
+ }
147
+ }
148
+ } else if (uses_named_args ) {
149
+ zend_error_noreturn (E_COMPILE_ERROR ,
150
+ "Cannot use positional argument after named argument" );
151
+ }
152
+
153
+ zend_const_expr_to_zval (
154
+ & attr -> args [j ].value , arg_ast_ptr , /* allow_dynamic */ true);
155
+ }
156
+ }
157
+
161
158
uint32_t zend_attribute_attribute_get_flags (zend_attribute * attr , zend_class_entry * scope )
162
159
{
163
160
// TODO: More proper signature validation: Too many args, incorrect arg names.
0 commit comments