From ad9f5a3aa6e42fcf914b449398ec6a150b987fe3 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 26 Feb 2022 12:50:41 +0100 Subject: [PATCH] Add parser helper rule for optional task port list There are a few places in the grammar where it is possible to specify a task/function port list in parenthesis or nothing. E.g. task and function prototypes. Factor this out into a common rule to be able to remove some duplicated code. Signed-off-by: Lars-Peter Clausen --- parse.y | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/parse.y b/parse.y index 1e802d8a4..f700e3c73 100644 --- a/parse.y +++ b/parse.y @@ -621,7 +621,8 @@ static void current_function_set_statement(const YYLTYPE&loc, std::vector enum_data_type enum_base_type %type tf_item_declaration tf_item_list tf_item_list_opt -%type tf_port_declaration tf_port_item tf_port_item_list tf_port_list tf_port_list_opt +%type tf_port_declaration tf_port_item tf_port_item_list +%type tf_port_list tf_port_list_opt tf_port_list_parens_opt %type modport_simple_port port_name parameter_value_byname %type port_name_list parameter_value_byname_list @@ -928,25 +929,14 @@ class_item /* IEEE1800-2005: A.1.8 */ /* External class method definitions... */ - | K_extern method_qualifier_opt K_function K_new ';' - { yyerror(@1, "sorry: External constructors are not yet supported."); } - | K_extern method_qualifier_opt K_function K_new '(' tf_port_list_opt ')' ';' + | K_extern method_qualifier_opt K_function K_new tf_port_list_parens_opt ';' { yyerror(@1, "sorry: External constructors are not yet supported."); } | K_extern method_qualifier_opt K_function data_type_or_implicit_or_void - IDENTIFIER ';' + IDENTIFIER tf_port_list_parens_opt ';' { yyerror(@1, "sorry: External methods are not yet supported."); delete[] $5; } - | K_extern method_qualifier_opt K_function data_type_or_implicit_or_void - IDENTIFIER '(' tf_port_list_opt ')' ';' - { yyerror(@1, "sorry: External methods are not yet supported."); - delete[] $5; - } - | K_extern method_qualifier_opt K_task IDENTIFIER ';' - { yyerror(@1, "sorry: External methods are not yet supported."); - delete[] $4; - } - | K_extern method_qualifier_opt K_task IDENTIFIER '(' tf_port_list_opt ')' ';' + | K_extern method_qualifier_opt K_task IDENTIFIER tf_port_list_parens_opt ';' { yyerror(@1, "sorry: External methods are not yet supported."); delete[] $4; } @@ -1937,10 +1927,8 @@ modport_simple_port ; modport_tf_port - : K_task IDENTIFIER - | K_task IDENTIFIER '(' tf_port_list_opt ')' - | K_function data_type_or_implicit_or_void IDENTIFIER - | K_function data_type_or_implicit_or_void IDENTIFIER '(' tf_port_list_opt ')' + : K_task IDENTIFIER tf_port_list_parens_opt + | K_function data_type_or_implicit_or_void IDENTIFIER tf_port_list_parens_opt ; non_integer_type /* IEEE1800-2005: A.2.2.1 */ @@ -6817,6 +6805,13 @@ tf_port_list_opt | { $$ = 0; } ; + /* A task or function prototype can be declared with the task/function name + * followed by a port list in parenthesis or or just the task/function name by + * itself. When a port list is used it might be empty. */ +tf_port_list_parens_opt + : '(' tf_port_list_opt ')' { $$ = $2; } + | { $$ = 0; } + /* Note that the lexor notices the "table" keyword and starts the UDPTABLE state. It needs to happen there so that all the characters in the table are interpreted in that mode. It is still