Skip to content

Commit d8bba0b

Browse files
authored
Merge pull request #12 from koolkode/AttributeHandling
Implement Remaining Requested Changes
2 parents bd1e66b + 334aad6 commit d8bba0b

File tree

4 files changed

+38
-37
lines changed

4 files changed

+38
-37
lines changed

Zend/tests/attributes/001_placement.phpt

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,81 +44,96 @@ $sources = [
4444

4545
foreach ($sources as $r) {
4646
$attr = $r->getAttributes();
47-
var_dump(count($attr));
47+
var_dump(get_class($r), count($attr));
4848

4949
foreach ($attr as $a) {
5050
var_dump($a->getName(), $a->getArguments());
5151
}
52+
53+
echo "\n";
5254
}
5355

5456
?>
5557
--EXPECT--
58+
string(15) "ReflectionClass"
5659
int(1)
5760
string(2) "A1"
5861
array(1) {
5962
[0]=>
6063
int(1)
6164
}
65+
66+
string(23) "ReflectionClassConstant"
6267
int(1)
6368
string(2) "A1"
6469
array(1) {
6570
[0]=>
6671
int(2)
6772
}
68-
int(1)
69-
string(2) "A1"
70-
array(1) {
71-
[0]=>
72-
int(2)
73-
}
74-
int(1)
75-
string(2) "A1"
76-
array(1) {
77-
[0]=>
78-
int(3)
79-
}
73+
74+
string(23) "ReflectionClassConstant"
75+
int(0)
76+
77+
string(18) "ReflectionProperty"
8078
int(1)
8179
string(2) "A1"
8280
array(1) {
8381
[0]=>
8482
int(3)
8583
}
84+
85+
string(18) "ReflectionProperty"
86+
int(0)
87+
88+
string(16) "ReflectionMethod"
8689
int(1)
8790
string(2) "A1"
8891
array(1) {
8992
[0]=>
9093
int(4)
9194
}
95+
96+
string(19) "ReflectionParameter"
9297
int(1)
9398
string(2) "A1"
9499
array(1) {
95100
[0]=>
96101
int(5)
97102
}
103+
104+
string(19) "ReflectionParameter"
98105
int(1)
99106
string(2) "A1"
100107
array(1) {
101108
[0]=>
102109
int(6)
103110
}
111+
112+
string(16) "ReflectionObject"
104113
int(1)
105114
string(2) "A1"
106115
array(1) {
107116
[0]=>
108117
int(7)
109118
}
119+
120+
string(18) "ReflectionFunction"
110121
int(1)
111122
string(2) "A1"
112123
array(1) {
113124
[0]=>
114125
int(8)
115126
}
127+
128+
string(18) "ReflectionFunction"
116129
int(1)
117130
string(2) "A1"
118131
array(1) {
119132
[0]=>
120133
int(9)
121134
}
135+
136+
string(18) "ReflectionFunction"
122137
int(1)
123138
string(2) "A1"
124139
array(1) {

Zend/zend_ast.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,9 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
15911591
smart_str_appends(str, "const ");
15921592
goto simple_list;
15931593
case ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES:
1594-
zend_ast_export_attributes(str, ast->child[1], indent, 1);
1594+
if (ast->child[1]) {
1595+
zend_ast_export_attributes(str, ast->child[1], indent, 1);
1596+
}
15951597
zend_ast_export_ex(str, ast->child[0], 0, indent);
15961598
break;
15971599
case ZEND_AST_NAME_LIST:
@@ -2190,9 +2192,8 @@ zend_ast * ZEND_FASTCALL zend_ast_with_attributes(zend_ast *ast, zend_ast *attr)
21902192
case ZEND_AST_PARAM:
21912193
ast->child[3] = attr;
21922194
break;
2193-
case ZEND_AST_CLASS_CONST_DECL:
2194-
ast = zend_ast_create(ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES, ast, attr);
2195-
ast->lineno = ast->child[0]->lineno;
2195+
case ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES:
2196+
ast->child[1] = attr;
21962197
break;
21972198
EMPTY_SWITCH_DEFAULT_CASE()
21982199
}

Zend/zend_compile.c

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,7 +2381,7 @@ static inline zend_bool zend_is_variable_or_call(zend_ast *ast) /* {{{ */
23812381
static inline zend_bool zend_is_unticked_stmt(zend_ast *ast) /* {{{ */
23822382
{
23832383
return ast->kind == ZEND_AST_STMT_LIST || ast->kind == ZEND_AST_LABEL
2384-
|| ast->kind == ZEND_AST_PROP_DECL || ast->kind == ZEND_AST_CLASS_CONST_DECL
2384+
|| ast->kind == ZEND_AST_PROP_DECL || ast->kind == ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES
23852385
|| ast->kind == ZEND_AST_USE_TRAIT || ast->kind == ZEND_AST_METHOD;
23862386
}
23872387
/* }}} */
@@ -6517,11 +6517,9 @@ void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t flags, H
65176517
ZVAL_UNDEF(&value_zv);
65186518
}
65196519

6520-
if (attributes) {
6521-
GC_ADDREF(attributes);
6522-
}
6523-
65246520
zend_declare_typed_property(ce, name, &value_zv, flags, doc_comment, attributes, type);
6521+
6522+
attributes = NULL;
65256523
}
65266524
}
65276525
/* }}} */
@@ -6539,10 +6537,6 @@ void zend_compile_prop_group(zend_ast *list) /* {{{ */
65396537
}
65406538

65416539
zend_compile_prop_decl(prop_ast, type_ast, list->attr, attributes);
6542-
6543-
if (attributes) {
6544-
zend_array_release(attributes);
6545-
}
65466540
}
65476541
/* }}} */
65486542

@@ -6588,16 +6582,10 @@ void zend_compile_class_const_decl(zend_ast *ast, zend_ast *attr_ast) /* {{{ */
65886582
zend_check_const_and_trait_alias_attr(ast->attr, "constant");
65896583
}
65906584

6591-
if (attributes) {
6592-
GC_ADDREF(attributes);
6593-
}
6594-
65956585
zend_const_expr_to_zval(&value_zv, value_ast);
65966586
zend_declare_class_constant_ex(ce, name, &value_zv, ast->attr, doc_comment, attributes);
6597-
}
65986587

6599-
if (attributes) {
6600-
zend_array_release(attributes);
6588+
attributes = NULL;
66016589
}
66026590
}
66036591
/* }}} */
@@ -8909,9 +8897,6 @@ void zend_compile_stmt(zend_ast *ast) /* {{{ */
89098897
case ZEND_AST_PROP_GROUP:
89108898
zend_compile_prop_group(ast);
89118899
break;
8912-
case ZEND_AST_CLASS_CONST_DECL:
8913-
zend_compile_class_const_decl(ast, NULL);
8914-
break;
89158900
case ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES:
89168901
zend_compile_class_const_decl(ast->child[0], ast->child[1]);
89178902
break;

Zend/zend_language_parser.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ annotated_class_statement:
786786
{ $$ = zend_ast_create(ZEND_AST_PROP_GROUP, $2, $3, NULL);
787787
$$->attr = $1; }
788788
| method_modifiers T_CONST class_const_list ';'
789-
{ $$ = $3; $$->attr = $1; }
789+
{ $$ = zend_ast_create(ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES, $3, NULL); $3->attr = $1; }
790790
| method_modifiers function returns_ref identifier backup_doc_comment '(' parameter_list ')'
791791
return_type backup_fn_flags method_body backup_fn_flags
792792
{ $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1 | $12, $2, $5,

0 commit comments

Comments
 (0)