Skip to content

diff #18200

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

Closed
wants to merge 6 commits into from
Closed

diff #18200

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
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM ubuntu:noble

RUN apt update && apt install -y pkg-config build-essential autoconf bison re2c \
libxml2-dev libsqlite3-dev cmake gdb
WORKDIR /app

CMD while true; do sleep 3600; done
1 change: 1 addition & 0 deletions Zend/zend_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ enum _zend_ast_kind {
ZEND_AST_ATTRIBUTE_GROUP,
ZEND_AST_MATCH_ARM_LIST,
ZEND_AST_MODIFIER_LIST,
ZEND_AST_GENERIC_TYPE_PARAM_LIST,

/* 0 child nodes */
ZEND_AST_MAGIC_CONST = 0 << ZEND_AST_NUM_CHILDREN_SHIFT,
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -9133,7 +9133,7 @@ static void zend_compile_class_decl(znode *result, zend_ast *ast, bool toplevel)

CG(active_class_entry) = ce;

if (decl->child[3]) {
if (decl->child[3] && decl->child[3]->kind != ZEND_AST_GENERIC_TYPE_PARAM_LIST) {
zend_compile_attributes(&ce->attributes, decl->child[3], 0, ZEND_ATTRIBUTE_TARGET_CLASS, 0);
}

Expand Down
25 changes: 21 additions & 4 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%token T_COALESCE "'??'"
%token T_POW "'**'"
%token T_POW_EQUAL "'**='"

// Generics
%token T_GENERIC_START "'<'"
%token T_GENERIC_END "'>'"

/* We need to split the & token in two to avoid a shift/reduce conflict. For T1&$v and T1&T2,
* with only one token lookahead, bison does not know whether to reduce T1 as a complete type,
* or shift to continue parsing an intersection type. */
Expand Down Expand Up @@ -286,6 +291,8 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%type <ast> function_name non_empty_member_modifiers
%type <ast> property_hook property_hook_list optional_property_hook_list hooked_property property_hook_body
%type <ast> optional_parameter_list
%type <ast> generic_type_parameter_list
%type <ast> generic_type_parameters

%type <num> returns_ref function fn is_reference is_variadic property_modifiers property_hook_modifiers
%type <num> method_modifiers class_const_modifiers member_modifier optional_cpp_modifiers
Expand Down Expand Up @@ -597,11 +604,21 @@ is_variadic:

class_declaration_statement:
class_modifiers T_CLASS { $<num>$ = CG(zend_lineno); }
T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1, $<num>3, $7, zend_ast_get_str($4), $5, $6, $9, NULL, NULL); }
T_STRING generic_type_parameters extends_from implements_list backup_doc_comment '{' class_statement_list '}'
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, $1, $<num>3, $8, zend_ast_get_str($4), $6, $7, $10, $5, NULL); }
| T_CLASS { $<num>$ = CG(zend_lineno); }
T_STRING extends_from implements_list backup_doc_comment '{' class_statement_list '}'
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, 0, $<num>2, $6, zend_ast_get_str($3), $4, $5, $8, NULL, NULL); }
T_STRING generic_type_parameters extends_from implements_list backup_doc_comment '{' class_statement_list '}'
{ $$ = zend_ast_create_decl(ZEND_AST_CLASS, 0, $<num>2, $7, zend_ast_get_str($3), $5, $6, $9, $4, NULL); }
;

generic_type_parameters:
T_GENERIC_START generic_type_parameter_list possible_comma T_GENERIC_END { $$ = $2; }
| %empty { $$ = NULL; }
;

generic_type_parameter_list:
T_STRING { $$ = zend_ast_create_list(1, ZEND_AST_GENERIC_TYPE_PARAM_LIST, $1); }
| generic_type_parameter_list ',' T_STRING { $$ = zend_ast_list_add($1, $3); }
;

class_modifiers:
Expand Down
24 changes: 24 additions & 0 deletions Zend/zend_language_scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,30 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
RETURN_TOKEN_WITH_IDENT(T_PRINT);
}

<ST_IN_SCRIPTING>"<"{LABEL}">" {
yyless(1);
yy_push_state(ST_GENERIC);
RETURN_TOKEN(T_GENERIC_START);
}

<ST_GENERIC>{LABEL} {
RETURN_TOKEN_WITH_STR(T_STRING, 0);
}

<ST_GENERIC>"," {
RETURN_TOKEN(',');
}

<ST_GENERIC>">" {
yy_pop_state();
RETURN_TOKEN(T_GENERIC_END);
}

<ST_GENERIC>{WHITESPACE} {
HANDLE_NEWLINES(yytext, yyleng);
RETURN_TOKEN(T_WHITESPACE);
}

<ST_IN_SCRIPTING>"class" {
RETURN_TOKEN_WITH_IDENT(T_CLASS);
}
Expand Down
2 changes: 2 additions & 0 deletions dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker build -t php-dev-setup .
docker run --volume .:/app php-dev-setup
2 changes: 2 additions & 0 deletions ext/tokenizer/tokenizer_data.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions ext/tokenizer/tokenizer_data.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,16 @@
* @cvalue T_POW_EQUAL
*/
const T_POW_EQUAL = UNKNOWN;
/**
* @var int
* @cvalue T_GENERIC_START
*/
const T_GENERIC_START = UNKNOWN;
/**
* @var int
* @cvalue T_GENERIC_END
*/
const T_GENERIC_END = UNKNOWN;
/**
* @var int
* @cvalue T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG
Expand Down
4 changes: 3 additions & 1 deletion ext/tokenizer/tokenizer_data_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading