From da5b9a4e5ffc7f4fb26156c899c267e65b9118d5 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Sat, 26 Feb 2022 12:53:51 +0100 Subject: [PATCH] Support class constructor without parenthesis Class constructors can be declared without parenthesis after the `new` when no arguments are required. Just like for normal function. In a similar way the base class constructor can also be invoked without parenthesis after the `new`. ``` class C extends D; function new; super.new; endfunction endclass ``` Add support for this by making the parenthesis optional in the parser. Signed-off-by: Lars-Peter Clausen --- parse.y | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/parse.y b/parse.y index ff6c25f19..2b5876868 100644 --- a/parse.y +++ b/parse.y @@ -891,14 +891,14 @@ class_item /* IEEE1800-2005: A.1.8 */ { assert(current_function==0); current_function = pform_push_constructor_scope(@3); } - '(' tf_port_list_opt ')' ';' + tf_port_list_parens_opt ';' block_item_decls_opt statement_or_null_list_opt K_endfunction endnew_opt - { current_function->set_ports($6); + { current_function->set_ports($5); pform_set_constructor_return(current_function); pform_set_this_class(@3, current_function); - current_function_set_statement(@3, $10); + current_function_set_statement(@3, $8); pform_pop_scope(); current_function = 0; } @@ -6656,8 +6656,8 @@ statement_item /* This is roughly statement_item in the LRM */ beginning of a constructor, but let the elaborator figure that out. */ - | implicit_class_handle '.' K_new '(' expression_list_with_nuls ')' ';' - { PChainConstructor*tmp = new PChainConstructor(*$5); + | implicit_class_handle '.' K_new argument_list_parens_opt ';' + { PChainConstructor*tmp = new PChainConstructor(*$4); FILE_NAME(tmp, @3); if (peek_head_name(*$1) == THIS_TOKEN) { yyerror(@1, "error: this.new is invalid syntax. Did you mean super.new?");