From 8d99bdac254fec6d1449e1d00468ad12fd17c997 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 9 Oct 2023 05:03:57 -0400 Subject: [PATCH] Internals: Move afterCommentp to AstNode. No functional change. --- src/V3Ast.h | 9 +++++++++ src/V3Const.cpp | 14 ++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/V3Ast.h b/src/V3Ast.h index 7772581d4..a2fbe15cd 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -2040,6 +2040,15 @@ public: void dumpTreeDot(std::ostream& os = std::cout) const; void dumpTreeDotFile(const string& filename, bool append = false, bool doDump = true); + // METHODS - static advancement + static AstNode* afterCommentp(AstNode* nodep) { + // Skip over comments starting at provided nodep, + // such as to determine if a AstIf is empty. + // nodep may be null, if so return nullptr. + while (nodep && VN_IS(nodep, Comment)) nodep = nodep->nextp(); + return nodep; + } + // METHODS - queries // Changes control flow, disable some optimizations virtual bool isBrancher() const { return false; } diff --git a/src/V3Const.cpp b/src/V3Const.cpp index 087f4b3af..6432a7eb5 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -1372,13 +1372,6 @@ private: return true; } - AstNode* afterComment(AstNode* nodep) { - // Ignore comments, such as to determine if a AstIf is empty. - // nodep may be null, if so return null. - while (nodep && VN_IS(nodep, Comment)) nodep = nodep->nextp(); - return nodep; - } - // Extraction checks bool warnSelect(AstSel* nodep) { if (m_doGenerate) { @@ -1459,7 +1452,7 @@ private: const AstNodeIf* const lowerIfp = VN_CAST(nodep->thensp(), NodeIf); if (!lowerIfp || lowerIfp->nextp()) return false; if (nodep->type() != lowerIfp->type()) return false; - if (afterComment(lowerIfp->elsesp())) return false; + if (AstNode::afterCommentp(lowerIfp->elsesp())) return false; return true; } bool ifConcatMergeableBiop(const AstNode* nodep) { @@ -3007,7 +3000,8 @@ private: nodep->unlinkFrBack(); } VL_DO_DANGLING(nodep->deleteTree(), nodep); - } else if (!afterComment(nodep->thensp()) && !afterComment(nodep->elsesp())) { + } else if (!AstNode::afterCommentp(nodep->thensp()) + && !AstNode::afterCommentp(nodep->elsesp())) { if (!nodep->condp()->isPure()) { // Condition has side effect - leave - perhaps in // future simplify to remove all but side effect terms @@ -3015,7 +3009,7 @@ private: // Empty block, remove it VL_DO_DANGLING(nodep->unlinkFrBack()->deleteTree(), nodep); } - } else if (!afterComment(nodep->thensp())) { + } else if (!AstNode::afterCommentp(nodep->thensp())) { UINFO(4, "IF({x}) nullptr {...} => IF(NOT{x}}: " << nodep << endl); AstNodeExpr* const condp = nodep->condp(); AstNode* const elsesp = nodep->elsesp();