Skip to content

Implement Remaining Requested Changes #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions Zend/tests/attributes/001_placement.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,81 +44,96 @@ $sources = [

foreach ($sources as $r) {
$attr = $r->getAttributes();
var_dump(count($attr));
var_dump(get_class($r), count($attr));

foreach ($attr as $a) {
var_dump($a->getName(), $a->getArguments());
}

echo "\n";
}

?>
--EXPECT--
string(15) "ReflectionClass"
int(1)
string(2) "A1"
array(1) {
[0]=>
int(1)
}

string(23) "ReflectionClassConstant"
int(1)
string(2) "A1"
array(1) {
[0]=>
int(2)
}
int(1)
string(2) "A1"
array(1) {
[0]=>
int(2)
}
int(1)
string(2) "A1"
array(1) {
[0]=>
int(3)
}

string(23) "ReflectionClassConstant"
int(0)

string(18) "ReflectionProperty"
int(1)
string(2) "A1"
array(1) {
[0]=>
int(3)
}

string(18) "ReflectionProperty"
int(0)

string(16) "ReflectionMethod"
int(1)
string(2) "A1"
array(1) {
[0]=>
int(4)
}

string(19) "ReflectionParameter"
int(1)
string(2) "A1"
array(1) {
[0]=>
int(5)
}

string(19) "ReflectionParameter"
int(1)
string(2) "A1"
array(1) {
[0]=>
int(6)
}

string(16) "ReflectionObject"
int(1)
string(2) "A1"
array(1) {
[0]=>
int(7)
}

string(18) "ReflectionFunction"
int(1)
string(2) "A1"
array(1) {
[0]=>
int(8)
}

string(18) "ReflectionFunction"
int(1)
string(2) "A1"
array(1) {
[0]=>
int(9)
}

string(18) "ReflectionFunction"
int(1)
string(2) "A1"
array(1) {
Expand Down
9 changes: 5 additions & 4 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1591,7 +1591,9 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
smart_str_appends(str, "const ");
goto simple_list;
case ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES:
zend_ast_export_attributes(str, ast->child[1], indent, 1);
if (ast->child[1]) {
zend_ast_export_attributes(str, ast->child[1], indent, 1);
}
zend_ast_export_ex(str, ast->child[0], 0, indent);
break;
case ZEND_AST_NAME_LIST:
Expand Down Expand Up @@ -2190,9 +2192,8 @@ zend_ast * ZEND_FASTCALL zend_ast_with_attributes(zend_ast *ast, zend_ast *attr)
case ZEND_AST_PARAM:
ast->child[3] = attr;
break;
case ZEND_AST_CLASS_CONST_DECL:
ast = zend_ast_create(ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES, ast, attr);
ast->lineno = ast->child[0]->lineno;
case ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES:
ast->child[1] = attr;
break;
EMPTY_SWITCH_DEFAULT_CASE()
}
Expand Down
23 changes: 4 additions & 19 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2381,7 +2381,7 @@ static inline zend_bool zend_is_variable_or_call(zend_ast *ast) /* {{{ */
static inline zend_bool zend_is_unticked_stmt(zend_ast *ast) /* {{{ */
{
return ast->kind == ZEND_AST_STMT_LIST || ast->kind == ZEND_AST_LABEL
|| ast->kind == ZEND_AST_PROP_DECL || ast->kind == ZEND_AST_CLASS_CONST_DECL
|| ast->kind == ZEND_AST_PROP_DECL || ast->kind == ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES
|| ast->kind == ZEND_AST_USE_TRAIT || ast->kind == ZEND_AST_METHOD;
}
/* }}} */
Expand Down Expand Up @@ -6517,11 +6517,9 @@ void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t flags, H
ZVAL_UNDEF(&value_zv);
}

if (attributes) {
GC_ADDREF(attributes);
}

zend_declare_typed_property(ce, name, &value_zv, flags, doc_comment, attributes, type);

attributes = NULL;
}
}
/* }}} */
Expand All @@ -6539,10 +6537,6 @@ void zend_compile_prop_group(zend_ast *list) /* {{{ */
}

zend_compile_prop_decl(prop_ast, type_ast, list->attr, attributes);

if (attributes) {
zend_array_release(attributes);
}
}
/* }}} */

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

if (attributes) {
GC_ADDREF(attributes);
}

zend_const_expr_to_zval(&value_zv, value_ast);
zend_declare_class_constant_ex(ce, name, &value_zv, ast->attr, doc_comment, attributes);
}

if (attributes) {
zend_array_release(attributes);
attributes = NULL;
}
}
/* }}} */
Expand Down Expand Up @@ -8909,9 +8897,6 @@ void zend_compile_stmt(zend_ast *ast) /* {{{ */
case ZEND_AST_PROP_GROUP:
zend_compile_prop_group(ast);
break;
case ZEND_AST_CLASS_CONST_DECL:
zend_compile_class_const_decl(ast, NULL);
break;
case ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES:
zend_compile_class_const_decl(ast->child[0], ast->child[1]);
break;
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ annotated_class_statement:
{ $$ = zend_ast_create(ZEND_AST_PROP_GROUP, $2, $3, NULL);
$$->attr = $1; }
| method_modifiers T_CONST class_const_list ';'
{ $$ = $3; $$->attr = $1; }
{ $$ = zend_ast_create(ZEND_AST_CLASS_CONST_DECL_ATTRIBUTES, $3, NULL); $3->attr = $1; }
| method_modifiers function returns_ref identifier backup_doc_comment '(' parameter_list ')'
return_type backup_fn_flags method_body backup_fn_flags
{ $$ = zend_ast_create_decl(ZEND_AST_METHOD, $3 | $1 | $12, $2, $5,
Expand Down