diff --git a/src/V3Ast.h b/src/V3Ast.h index 269197806..dbe2b02a0 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -1956,10 +1956,6 @@ public: AstNode* belowp); // When calling, "this" is second argument // METHODS - Iterate on a tree - // Clone or return nullptr if nullptr - static AstNode* cloneTreeNull(AstNode* nodep, bool cloneNextLink) { - return nodep ? nodep->cloneTree(cloneNextLink) : nullptr; - } AstNode* cloneTree(bool cloneNextLink); // Not const, as sets clonep() on original nodep bool gateTree() { return gateTreeIter(); } // Is tree isGateOptimizable? inline bool sameTree(const AstNode* node2p) const; // Does tree of this == node2p? diff --git a/src/V3Premit.cpp b/src/V3Premit.cpp index 6a134cd89..6887e175d 100644 --- a/src/V3Premit.cpp +++ b/src/V3Premit.cpp @@ -370,7 +370,7 @@ private: UINFO(4, "Autoflush " << nodep << endl); nodep->addNextHere( new AstFFlush{nodep->fileline(), - VN_AS(AstNode::cloneTreeNull(nodep->filep(), true), NodeExpr)}); + nodep->filep() ? nodep->filep()->cloneTree(true) : nullptr}); } } } diff --git a/src/V3Task.cpp b/src/V3Task.cpp index e1435a43b..a2fc9b0a5 100644 --- a/src/V3Task.cpp +++ b/src/V3Task.cpp @@ -421,7 +421,7 @@ private: // outvscp is the variable for functions only, if nullptr, it's a task UASSERT_OBJ(refp->taskp(), refp, "Unlinked?"); AstNode* const newbodysp - = AstNode::cloneTreeNull(refp->taskp()->stmtsp(), true); // Maybe nullptr + = refp->taskp()->stmtsp() ? refp->taskp()->stmtsp()->cloneTree(true) : nullptr; AstNode* const beginp = new AstComment{refp->fileline(), string{"Function: "} + refp->name(), true}; if (newbodysp) beginp->addNext(newbodysp); diff --git a/src/astgen b/src/astgen index 3a9b65785..048077e3d 100755 --- a/src/astgen +++ b/src/astgen @@ -961,9 +961,6 @@ def write_ast_macros(filename): Ast{t}* cloneTree(bool cloneNext) {{ return static_cast(AstNode::cloneTree(cloneNext)); }} - static Ast{t}* cloneTreeNull(Ast{t}* nodep, bool cloneNextLink) {{ - return nodep ? nodep->cloneTree(cloneNextLink) : nullptr; - }} Ast{t}* clonep() const {{ return static_cast(AstNode::clonep()); }} Ast{t}* addNext(Ast{t}* nodep) {{ return static_cast(AstNode::addNext(this, nodep)); }} ''', diff --git a/src/verilog.y b/src/verilog.y index 076ea09fa..78f93d150 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -148,13 +148,14 @@ public: AstVar* const nodep = createVariable(fileline, name, rangelistp, nullptr); return nodep; } - AstCell* const nodep = new AstCell{fileline, - GRAMMARP->m_instModuleFl, - name, - GRAMMARP->m_instModule, - pinlistp, - AstPin::cloneTreeNull(GRAMMARP->m_instParamp, true), - GRAMMARP->scrubRange(rangelistp)}; + AstCell* const nodep = new AstCell{ + fileline, + GRAMMARP->m_instModuleFl, + name, + GRAMMARP->m_instModule, + pinlistp, + (GRAMMARP->m_instParamp ? GRAMMARP->m_instParamp->cloneTree(true) : nullptr), + GRAMMARP->scrubRange(rangelistp)}; nodep->trace(GRAMMARP->allTracingOn(fileline)); return nodep; } @@ -284,7 +285,9 @@ public: setScopedSigAttr(new AstAttrOf{PARSEP->lexFileline(), vattrT}); } - AstNode* cloneScopedSigAttr() const { return AstNode::cloneTreeNull(m_scopedSigAttr, true); } + AstNode* cloneScopedSigAttr() const { + return m_scopedSigAttr ? m_scopedSigAttr->cloneTree(true) : nullptr; + } }; const VBasicDTypeKwd LOGIC = VBasicDTypeKwd::LOGIC; // Shorthand "LOGIC" @@ -2194,13 +2197,17 @@ member_decl_assignment: // Derived from IEEE: variable_decl_assi // // So this is different from variable_decl_assignment id variable_dimensionListE { $$ = new AstMemberDType{$1, *$1, VFlagChildDType{}, - GRAMMARP->createArray(AstNodeDType::cloneTreeNull(GRAMMARP->m_memDTypep, true), $2, false), + GRAMMARP->createArray((GRAMMARP->m_memDTypep + ? GRAMMARP->m_memDTypep->cloneTree(true) : nullptr), + $2, false), nullptr}; PARSEP->tagNodep($$); } | id variable_dimensionListE '=' variable_declExpr { $$ = new AstMemberDType{$1, *$1, VFlagChildDType{}, - GRAMMARP->createArray(AstNodeDType::cloneTreeNull(GRAMMARP->m_memDTypep, true), $2, false), + GRAMMARP->createArray((GRAMMARP->m_memDTypep + ? GRAMMARP->m_memDTypep->cloneTree(true) : nullptr), + $2, false), $4}; PARSEP->tagNodep($$); }