diff --git a/elab_expr.cc b/elab_expr.cc index 588766ce6..8aa0ac696 100644 --- a/elab_expr.cc +++ b/elab_expr.cc @@ -4604,14 +4604,8 @@ NetExpr* PENewClass::elaborate_expr(Design*des, NetScope*scope, int parm_errors = 0; for (size_t idx = 1 ; idx < parms.size() ; idx += 1) { // While there are default arguments, check them. - if (idx <= parms_.size()) { + if (idx <= parms_.size() && parms_[idx-1]) { PExpr*tmp = parms_[idx-1]; - if (tmp == 0) { - parms[idx] = 0; - missing_parms += 1; - continue; - } - parms[idx] = elaborate_rval_expr(des, scope, def->port(idx)->data_type(), def->port(idx)->vector_width(), tmp, false); diff --git a/parse.y b/parse.y index d415d5965..2e4ffc09e 100644 --- a/parse.y +++ b/parse.y @@ -167,6 +167,18 @@ template void append(vector&out, const vector&in) out.push_back(in[idx]); } +/* + * Look at the list and pull null pointers off the end. + */ +static void strip_tail_items(list*lst) +{ + while (lst->size() > 0) { + if (lst->back() != 0) + return; + lst->pop_back(); + } +} + /* * This is a shorthand for making a PECallFunction that takes a single * arg. This is used by some of the code that detects built-ins. @@ -855,13 +867,10 @@ class_item_qualifier_opt ; class_new /* IEEE1800-2005 A.2.4 */ - : K_new '(' ')' - { PENewClass*tmp = new PENewClass; - FILE_NAME(tmp, @1); - $$ = tmp; - } - | K_new '(' expression_list_proper ')' - { PENewClass*tmp = new PENewClass(*$3); + : K_new '(' expression_list_with_nuls ')' + { list*expr_list = $3; + strip_tail_items(expr_list); + PENewClass*tmp = new PENewClass(*expr_list); FILE_NAME(tmp, @1); delete $3; $$ = tmp; @@ -3035,8 +3044,10 @@ expr_primary function call. If a system identifier, then a system function call. */ - | hierarchy_identifier '(' expression_list_proper ')' - { PECallFunction*tmp = pform_make_call_function(@1, *$1, *$3); + | hierarchy_identifier '(' expression_list_with_nuls ')' + { list*expr_list = $3; + strip_tail_items(expr_list); + PECallFunction*tmp = pform_make_call_function(@1, *$1, *expr_list); delete $1; $$ = tmp; } @@ -3047,15 +3058,6 @@ expr_primary delete[]$1; $$ = tmp; } - | hierarchy_identifier '(' ')' - { const list empty; - PECallFunction*tmp = pform_make_call_function(@1, *$1, empty); - delete $1; - $$ = tmp; - if (!gn_system_verilog()) { - yyerror(@1, "error: Empty function argument list requires SystemVerilog."); - } - } | PACKAGE_IDENTIFIER K_SCOPE_RES IDENTIFIER '(' expression_list_proper ')' { perm_string use_name = lex_strings.make($3); PECallFunction*tmp = new PECallFunction($1, use_name, *$5); diff --git a/pform_dump.cc b/pform_dump.cc index 17c01d653..967b772f1 100644 --- a/pform_dump.cc +++ b/pform_dump.cc @@ -306,7 +306,7 @@ void PENewClass::dump(ostream&out) const parms_[0]->dump(out); for (size_t idx = 1 ; idx < parms_.size() ; idx += 1) { out << ", "; - parms_[idx]->dump(out); + if (parms_[idx]) parms_[idx]->dump(out); } } out << ")";