Skip to content
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

Support php 8.1 enums #197

Merged
merged 6 commits into from Apr 5, 2021
Merged

Conversation

@TysonAndre
Copy link
Collaborator

@TysonAndre TysonAndre commented Feb 6, 2021

Add support for https://wiki.php.net/rfc/enumerations

@TysonAndre TysonAndre force-pushed the enum-support-updated branch from 6ff3528 to 97839c7 Mar 27, 2021
@TysonAndre TysonAndre changed the title Support php 8.1 enums RFC proposal Support php 8.1 enums Mar 27, 2021
@TysonAndre TysonAndre force-pushed the enum-support-updated branch from 97839c7 to fdd377f Mar 27, 2021
@TysonAndre TysonAndre requested a review from nikic Mar 27, 2021
0: AST_ENUM_CASE
name: "FOO"
expr: 42
0: null
Copy link
Owner

@nikic nikic Mar 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's that zero index doing here?

Copy link
Collaborator Author

@TysonAndre TysonAndre Mar 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed that - changed to attributes

I started writing this a month ago and didn't notice the 0. Enum cases can have attributes - I updated the test and documentation.

Because this is a brand new node kind, it shouldn't be a breaking change to always set attributes in $node->children instead of an instance property

@TysonAndre TysonAndre force-pushed the enum-support-updated branch from 4f55966 to 9c9367c Mar 28, 2021
ast.c Outdated
@@ -560,7 +572,9 @@ static inline zend_ast_attr ast_assign_op_to_binary_op(zend_ast_attr attr) {
static inline zend_ast **ast_get_children(zend_ast *ast, uint32_t *count) {
if (ast_kind_is_decl(ast->kind)) {
zend_ast_decl *decl = (zend_ast_decl *) ast;
#if PHP_VERSION_ID >= 80000
#if PHP_VERSION_ID >= 80100
*count = decl->kind == ZEND_AST_CLASS ? (decl->child[4] != NULL ? 5 : 4) : 5;
Copy link
Owner

@nikic nikic Mar 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't have anything like this right now (where an AST node has an optional child). Maybe it's better to unconditionally include child 4 in the new version?

nikic
nikic approved these changes Mar 29, 2021
@nikic
Copy link
Owner

@nikic nikic commented Mar 31, 2021

Looks like there's test failures.

@TysonAndre
Copy link
Collaborator Author

@TysonAndre TysonAndre commented Mar 31, 2021

Will look at it tonight - I may also need to set a null placeholder for type in php 8.0 and older

@TysonAndre TysonAndre merged commit 28f5201 into nikic:master Apr 5, 2021
@TysonAndre TysonAndre deleted the enum-support-updated branch May 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants