@@ -9415,8 +9415,14 @@ static void zend_compile_const_decl(zend_ast *ast) /* {{{ */
94159415{
94169416 zend_ast_list * list = zend_ast_get_list (ast );
94179417 uint32_t i ;
9418+ zend_ast * attributes_ast = NULL ;
9419+ zend_op * last_op = NULL ;
94189420 for (i = 0 ; i < list -> children ; ++ i ) {
94199421 zend_ast * const_ast = list -> child [i ];
9422+ if (i == list -> children - 1 && const_ast -> kind == ZEND_AST_ATTRIBUTE_LIST ) {
9423+ attributes_ast = const_ast ;
9424+ continue ;
9425+ }
94209426 zend_ast * name_ast = const_ast -> child [0 ];
94219427 zend_ast * * value_ast_ptr = & const_ast -> child [1 ];
94229428 zend_string * unqualified_name = zend_ast_get_str (name_ast );
@@ -9447,10 +9453,30 @@ static void zend_compile_const_decl(zend_ast *ast) /* {{{ */
94479453 name_node .op_type = IS_CONST ;
94489454 ZVAL_STR (& name_node .u .constant , name );
94499455
9450- zend_emit_op (NULL , ZEND_DECLARE_CONST , & name_node , & value_node );
9456+ last_op = zend_emit_op (NULL , ZEND_DECLARE_CONST , & name_node , & value_node );
94519457
94529458 zend_register_seen_symbol (name , ZEND_SYMBOL_CONST );
94539459 }
9460+ if (attributes_ast == NULL ) {
9461+ return ;
9462+ }
9463+ // Validate: attributes can only be applied to one constant at a time
9464+ // Since we store the AST for the attributes in the list of children,
9465+ // there should be exactly 2 children
9466+ if (list -> children > 2 ) {
9467+ zend_error_noreturn (
9468+ E_COMPILE_ERROR ,
9469+ "Cannot apply attributes to multiple constants at once"
9470+ );
9471+ }
9472+ ZEND_ASSERT (last_op != NULL );
9473+ last_op -> opcode = ZEND_DECLARE_ATTRIBUTED_CONST ;
9474+ HashTable * attribs_ht = NULL ;
9475+ zend_compile_attributes (& attribs_ht , list -> child [1 ], 0 , ZEND_ATTRIBUTE_TARGET_CONST , 0 );
9476+ znode attribs_node ;
9477+ attribs_node .op_type = IS_CONST ;
9478+ ZVAL_PTR (& attribs_node .u .constant , attribs_ht );
9479+ zend_emit_op_data (& attribs_node );
94549480}
94559481/* }}}*/
94569482
0 commit comments