From 202a53f4f685057237fd0e5f7e41dd086b7d5fad Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Mon, 29 Sep 2025 21:01:40 +0200 Subject: [PATCH] Internals: Parse ++/-- in statement position as AstStmtExpr (#6280) (#6510) Small step towards #6280. No functional change. --- src/V3LinkInc.cpp | 14 ++++++++++++++ src/verilog.y | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/V3LinkInc.cpp b/src/V3LinkInc.cpp index a902010c5..8d70f6ff8 100644 --- a/src/V3LinkInc.cpp +++ b/src/V3LinkInc.cpp @@ -173,6 +173,20 @@ class LinkIncVisitor final : public VNVisitor { iterateChildren(nodep); m_insStmtp = nullptr; // Next thing should be new statement } + void visit(AstStmtExpr* nodep) override { + AstNodeExpr* const exprp = nodep->exprp(); + if (VN_IS(exprp, PostAdd) || VN_IS(exprp, PostSub) || VN_IS(exprp, PreAdd) + || VN_IS(exprp, PreSub)) { + // Repalce this StmtExpr with the expression, visiting it will turn it into a NodeStmt + nodep->replaceWith(exprp->unlinkFrBack()); + VL_DO_DANGLING(pushDeletep(nodep), nodep); + m_insStmtp = nullptr; + iterate(exprp); + m_insStmtp = nullptr; + return; + } + visit(static_cast(nodep)); + } void visit(AstNodeStmt* nodep) override { m_insStmtp = nodep; iterateChildren(nodep); diff --git a/src/verilog.y b/src/verilog.y index d13541859..440e8eadc 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -3493,7 +3493,7 @@ statement_item: // IEEE: statement_item | fexprLvalue yP_EQ__NEW dynamic_array_new ';' { $$ = new AstAssign{$2, $1, $3}; } | fexprLvalue yP_EQ__NEW class_new ';' { $$ = new AstAssign{$2, $1, $3}; } // // IEEE: inc_or_dec_expression - | finc_or_dec_expression ';' { $$ = $1; } + | finc_or_dec_expression ';' { $$ = new AstStmtExpr{$1, $1}; } // // // IEEE: nonblocking_assignment | fexprLvalue yP_LTE delay_or_event_controlE expr ';' @@ -4001,7 +4001,7 @@ for_step: // IEEE: for_step for_step_assignment: // ==IEEE: for_step_assignment foperator_assignment { $$ = $1; } - | finc_or_dec_expression { $$ = $1; } + | finc_or_dec_expression { $$ = new AstStmtExpr{$1, $1}; } // // IEEE: function_subroutine_call | task_subroutine_callNoSemi { $$ = $1; } ;