From 512fe0a2d12a8a755dc1eeab4620d0dc8b13063e Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 20 Jun 2021 18:32:57 -0400 Subject: [PATCH] Internals: Add const. No functional change. --- src/V3Assert.cpp | 6 +- src/V3Ast.cpp | 6 +- src/V3AstNodes.cpp | 14 +++-- src/V3AstNodes.h | 6 +- src/V3AstUserAllocator.h | 10 +-- src/V3Begin.cpp | 2 +- src/V3Branch.cpp | 10 +-- src/V3Broken.cpp | 4 +- src/V3CCtors.cpp | 4 +- src/V3Cdc.cpp | 11 ++-- src/V3Clean.cpp | 9 +-- src/V3Clock.cpp | 2 +- src/V3Config.cpp | 8 +-- src/V3Const.cpp | 69 +++++++++++---------- src/V3Coverage.cpp | 27 ++++---- src/V3Delayed.cpp | 14 ++--- src/V3Depth.cpp | 2 +- src/V3Descope.cpp | 5 +- src/V3EmitC.cpp | 85 ++++++++++++------------- src/V3EmitCMain.cpp | 2 +- src/V3EmitCMake.cpp | 4 +- src/V3EmitCSyms.cpp | 60 +++++++++--------- src/V3EmitMk.cpp | 4 +- src/V3EmitV.cpp | 3 +- src/V3EmitXml.cpp | 14 ++--- src/V3Error.cpp | 8 +-- src/V3Expand.cpp | 26 ++++---- src/V3File.cpp | 36 +++++------ src/V3FileLine.cpp | 8 +-- src/V3Gate.cpp | 2 +- src/V3Graph.cpp | 8 +-- src/V3GraphDfa.cpp | 2 +- src/V3GraphPathChecker.cpp | 2 +- src/V3HierBlock.cpp | 6 +- src/V3Inline.cpp | 20 +++--- src/V3Inst.cpp | 29 ++++----- src/V3Life.cpp | 2 +- src/V3LifePost.cpp | 4 +- src/V3LinkCells.cpp | 9 +-- src/V3LinkDot.cpp | 101 +++++++++++++++--------------- src/V3LinkInc.cpp | 2 +- src/V3LinkJump.cpp | 2 +- src/V3LinkParse.cpp | 18 +++--- src/V3LinkResolve.cpp | 10 +-- src/V3List.h | 6 +- src/V3Name.cpp | 6 +- src/V3Number.cpp | 52 ++++++++-------- src/V3Number_test.cpp | 2 +- src/V3OptionParser.cpp | 4 +- src/V3Options.cpp | 54 ++++++++-------- src/V3Order.cpp | 29 ++++----- src/V3Os.cpp | 20 +++--- src/V3Param.cpp | 23 +++---- src/V3ParseImp.cpp | 22 +++---- src/V3ParseLex.cpp | 2 +- src/V3Partition.cpp | 22 +++---- src/V3PreProc.cpp | 60 +++++++++--------- src/V3PreShell.cpp | 6 +- src/V3Premit.cpp | 2 +- src/V3Reloop.cpp | 2 +- src/V3Scope.cpp | 2 +- src/V3Scoreboard.h | 4 +- src/V3Simulate.h | 22 +++---- src/V3Slice.cpp | 22 +++---- src/V3SplitAs.cpp | 2 +- src/V3SplitVar.cpp | 2 +- src/V3Stats.cpp | 10 +-- src/V3StatsReport.cpp | 9 +-- src/V3String.cpp | 38 ++++++------ src/V3String.h | 2 +- src/V3Subst.cpp | 4 +- src/V3SymTable.h | 2 +- src/V3TSP.cpp | 12 ++-- src/V3Task.cpp | 22 +++---- src/V3Trace.cpp | 2 +- src/V3TraceDecl.cpp | 2 +- src/V3Tristate.cpp | 14 ++--- src/V3Undriven.cpp | 16 ++--- src/V3Unknown.cpp | 8 +-- src/V3Unroll.cpp | 4 +- src/V3Width.cpp | 124 +++++++++++++++++++------------------ src/V3WidthCommit.h | 2 +- src/V3WidthSel.cpp | 18 +++--- src/Verilator.cpp | 2 +- src/VlcMain.cpp | 2 +- src/VlcPoint.h | 2 +- src/VlcTop.cpp | 22 +++---- 87 files changed, 690 insertions(+), 669 deletions(-) diff --git a/src/V3Assert.cpp b/src/V3Assert.cpp index 8b53adf95..22ae310ba 100644 --- a/src/V3Assert.cpp +++ b/src/V3Assert.cpp @@ -163,7 +163,7 @@ private: } else { ++m_statAsNotImm; } - bool force = VN_IS(nodep, AssertIntrinsic); + const bool force = VN_IS(nodep, AssertIntrinsic); if (passsp) passsp = newIfAssertOn(passsp, force); if (failsp) failsp = newIfAssertOn(failsp, force); if (!failsp) failsp = newFireAssertUnchecked(nodep, "'assert' failed."); @@ -231,7 +231,7 @@ private: } while (ifp); AstNode* newifp = nodep->cloneTree(false); - bool allow_none = nodep->unique0Pragma(); + const bool allow_none = nodep->unique0Pragma(); // Empty case means no property if (!propp) propp = new AstConst(nodep->fileline(), AstConst::BitFalse()); @@ -305,7 +305,7 @@ private: // Empty case means no property if (!propp) propp = new AstConst(nodep->fileline(), AstConst::BitFalse()); - bool allow_none = has_default || nodep->unique0Pragma(); + const bool allow_none = has_default || nodep->unique0Pragma(); AstNode* ohot = (allow_none ? static_cast(new AstOneHot0(nodep->fileline(), propp)) diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 4329c7633..31f819c53 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -119,7 +119,7 @@ string AstNode::encodeName(const string& namein) { // a user identifier nor a temp we create in Verilator. // We also do *NOT* use __DOT__ etc, as we search for those // in some replacements, and don't want to mangle the user's names. - unsigned val = pos[0] & 0xff; // Mask to avoid sign extension + const unsigned val = pos[0] & 0xff; // Mask to avoid sign extension std::stringstream hex; hex << std::setfill('0') << std::setw(2) << std::hex << val; out += "__0" + hex.str(); @@ -1045,7 +1045,7 @@ void AstNode::dumpTreeFileGdb(const AstNode* nodep, // LCOV_EXCL_START cout << "" << endl; return; } - string filename = filenamep ? filenamep : v3Global.debugFilename("debug.tree", 98); + const string filename = filenamep ? filenamep : v3Global.debugFilename("debug.tree", 98); v3Global.rootp()->dumpTreeFile(filename); } // LCOV_EXCL_STOP @@ -1178,7 +1178,7 @@ string AstNode::locationStr() const { str += modp->hierName(); return str; } else if ((nvrp = VN_CAST_CONST(backp, NodeVarRef))) { - string prettyName = nvrp->prettyName(); + const string prettyName = nvrp->prettyName(); // VarRefs have not been flattened yet and do not contain location information if (prettyName != nvrp->name()) { str += prettyName; diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index e933d6d92..9bb1d5067 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -284,7 +284,7 @@ AstNetlist::AstNetlist() } void AstNetlist::timeprecisionMerge(FileLine*, const VTimescale& value) { - VTimescale prec = v3Global.opt.timeComputePrec(value); + const VTimescale prec = v3Global.opt.timeComputePrec(value); if (prec.isNone() || prec == m_timeprecision) { } else if (m_timeprecision.isNone()) { m_timeprecision = prec; @@ -343,7 +343,8 @@ string AstVar::vlArgType(bool named, bool forReturn, bool forFunc, const string& string ostatic; if (isStatic() && namespc.empty()) ostatic = "static "; - bool isRef = isDpiOpenArray() || (forFunc && (isWritable() || direction().isRefOrConstRef())); + const bool isRef + = isDpiOpenArray() || (forFunc && (isWritable() || direction().isRefOrConstRef())); if (forFunc && isReadOnly() && isRef) ostatic = ostatic + "const "; @@ -358,7 +359,7 @@ string AstVar::vlArgType(bool named, bool forReturn, bool forFunc, const string& string AstVar::vlEnumType() const { string arg; AstBasicDType* bdtypep = basicp(); - bool strtype = bdtypep && bdtypep->keyword() == AstBasicDTypeKwd::STRING; + const bool strtype = bdtypep && bdtypep->keyword() == AstBasicDTypeKwd::STRING; if (bdtypep && bdtypep->keyword() == AstBasicDTypeKwd::CHARPTR) { return "VLVT_PTR"; } else if (bdtypep && bdtypep->keyword() == AstBasicDTypeKwd::SCOPEPTR) { @@ -648,7 +649,7 @@ public: }; string AstNodeDType::cType(const string& name, bool forFunc, bool isRef) const { - CTypeRecursed info = cTypeRecurse(false); + const CTypeRecursed info = cTypeRecurse(false); return info.render(name, isRef); } @@ -1251,8 +1252,9 @@ const char* AstClassPackage::broken() const { return nullptr; } void AstClass::insertCache(AstNode* nodep) { - bool doit = (VN_IS(nodep, Var) || VN_IS(nodep, EnumItemRef) - || (VN_IS(nodep, NodeFTask) && !VN_CAST(nodep, NodeFTask)->isExternProto())); + const bool doit + = (VN_IS(nodep, Var) || VN_IS(nodep, EnumItemRef) + || (VN_IS(nodep, NodeFTask) && !VN_CAST(nodep, NodeFTask)->isExternProto())); if (doit) { if (m_members.find(nodep->name()) != m_members.end()) { nodep->v3error("Duplicate declaration of member name: " << nodep->prettyNameQ()); diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index d47a2aa52..4fe2c3950 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -685,7 +685,7 @@ public: refDTypep(nullptr); setOp2p(rangep); dtypep(nullptr); // V3Width will resolve - int width = subDTypep()->width() * rangep->elementsConst(); + const int width = subDTypep()->width() * rangep->elementsConst(); widthForce(width, width); } AstPackArrayDType(FileLine* fl, AstNodeDType* dtp, AstRange* rangep) @@ -693,7 +693,7 @@ public: refDTypep(dtp); setOp2p(rangep); dtypep(this); - int width = subDTypep()->width() * rangep->elementsConst(); + const int width = subDTypep()->width() * rangep->elementsConst(); widthForce(width, width); } ASTNODE_NODE_FUNCS(PackArrayDType) @@ -848,7 +848,7 @@ private: numeric(numer); if (!rangep && (wantwidth || wantwidthmin >= 0)) { // Constant width if (wantwidth > 1) m.m_nrange.init(wantwidth - 1, 0, false); - int wmin = wantwidthmin >= 0 ? wantwidthmin : wantwidth; + const int wmin = wantwidthmin >= 0 ? wantwidthmin : wantwidth; widthForce(wantwidth, wmin); } else if (!rangep) { // Set based on keyword properties // V3Width will pull from this width diff --git a/src/V3AstUserAllocator.h b/src/V3AstUserAllocator.h index 7ffb70f7b..f00e35550 100644 --- a/src/V3AstUserAllocator.h +++ b/src/V3AstUserAllocator.h @@ -36,19 +36,19 @@ private: inline T_Data* getUserp(T_Node* nodep) const { // This simplifies statically as T_UserN is constant. In C++17, use 'if constexpr'. if (T_UserN == 1) { - VNUser user = nodep->user1u(); + const VNUser user = nodep->user1u(); return user.to(); } else if (T_UserN == 2) { - VNUser user = nodep->user2u(); + const VNUser user = nodep->user2u(); return user.to(); } else if (T_UserN == 3) { - VNUser user = nodep->user3u(); + const VNUser user = nodep->user3u(); return user.to(); } else if (T_UserN == 4) { - VNUser user = nodep->user4u(); + const VNUser user = nodep->user4u(); return user.to(); } else { - VNUser user = nodep->user5u(); + const VNUser user = nodep->user5u(); return user.to(); } } diff --git a/src/V3Begin.cpp b/src/V3Begin.cpp index 8a9f2943c..9c1e3674a 100644 --- a/src/V3Begin.cpp +++ b/src/V3Begin.cpp @@ -117,7 +117,7 @@ private: string dottedname = nodep->name() + "__DOT__"; // So always found string::size_type pos; while ((pos = dottedname.find("__DOT__")) != string::npos) { - string ident = dottedname.substr(0, pos); + const string ident = dottedname.substr(0, pos); dottedname = dottedname.substr(pos + strlen("__DOT__")); if (nodep->name() != "") m_namedScope = dot(m_namedScope, ident); m_unnamedScope = dot(m_unnamedScope, ident); diff --git a/src/V3Branch.cpp b/src/V3Branch.cpp index 30560fb8e..b1a5de551 100644 --- a/src/V3Branch.cpp +++ b/src/V3Branch.cpp @@ -70,15 +70,15 @@ private: // Do if reset(); iterateAndNextNull(nodep->ifsp()); - int ifLikely = m_likely; - int ifUnlikely = m_unlikely; + const int ifLikely = m_likely; + const int ifUnlikely = m_unlikely; // Do else reset(); iterateAndNextNull(nodep->elsesp()); - int elseLikely = m_likely; - int elseUnlikely = m_unlikely; + const int elseLikely = m_likely; + const int elseUnlikely = m_unlikely; // Compute - int likeness = ifLikely - ifUnlikely - (elseLikely - elseUnlikely); + const int likeness = ifLikely - ifUnlikely - (elseLikely - elseUnlikely); if (likeness > 0) { nodep->branchPred(VBranchPred::BP_LIKELY); } else if (likeness < 0) { diff --git a/src/V3Broken.cpp b/src/V3Broken.cpp index 613b4cf2f..3205ce912 100644 --- a/src/V3Broken.cpp +++ b/src/V3Broken.cpp @@ -72,7 +72,7 @@ public: UASSERT_OBJ(!(iter != s_nodes.end() && (iter->second & FLAG_ALLOCATED)), nodep, "Newing AstNode object that is already allocated"); if (iter == s_nodes.end()) { - int flags = FLAG_ALLOCATED; // This int needed to appease GCC 4.1.2 + const int flags = FLAG_ALLOCATED; // This int needed to appease GCC 4.1.2 s_nodes.emplace(nodep, flags); } } @@ -103,7 +103,7 @@ public: UASSERT_OBJ(!(iter->second & FLAG_IN_TREE), nodep, "AstNode is already in tree at another location"); } - int or_flags = FLAG_IN_TREE | (linkable ? FLAG_LINKABLE : 0); + const int or_flags = FLAG_IN_TREE | (linkable ? FLAG_LINKABLE : 0); if (iter == s_nodes.end()) { s_nodes.emplace(nodep, or_flags); } else { diff --git a/src/V3CCtors.cpp b/src/V3CCtors.cpp index 3cc1a9344..2becaa25d 100644 --- a/src/V3CCtors.cpp +++ b/src/V3CCtors.cpp @@ -139,8 +139,8 @@ void V3CCtors::evalAsserts() { if (AstVar* varp = VN_CAST(np, Var)) { if (varp->isPrimaryInish() && !varp->isSc()) { if (AstBasicDType* basicp = VN_CAST(varp->dtypeSkipRefp(), BasicDType)) { - int storedWidth = basicp->widthAlignBytes() * 8; - int lastWordWidth = varp->width() % storedWidth; + const int storedWidth = basicp->widthAlignBytes() * 8; + const int lastWordWidth = varp->width() % storedWidth; if (lastWordWidth != 0) { // if (signal & CONST(upper_non_clean_mask)) { fail; } AstVarRef* const vrefp diff --git a/src/V3Cdc.cpp b/src/V3Cdc.cpp index 29e3114b0..22d2d0333 100644 --- a/src/V3Cdc.cpp +++ b/src/V3Cdc.cpp @@ -151,7 +151,7 @@ private: *m_ofp << " "; } *m_ofp << nodep->prettyTypeName() << "\n"; - string lastPrefix = m_prefix; + const string lastPrefix = m_prefix; m_prefix = lastPrefix + "1:"; iterateAndNextNull(nodep->op1p()); m_prefix = lastPrefix + "2:"; @@ -449,7 +449,7 @@ private: if (!vertexp->asyncPath() && level != 0) return false; // Not part of path // Other logic in the path - string cont = prefix + sep; + const string cont = prefix + sep; string nextsep = " "; for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep = edgep->inNextp()) { CdcEitherVertex* eFromVertexp = static_cast(edgep->fromp()); @@ -506,7 +506,8 @@ private: } } - string filename = v3Global.opt.makeDir() + "/" + v3Global.opt.prefix() + "__cdc_edges.txt"; + const string filename + = v3Global.opt.makeDir() + "/" + v3Global.opt.prefix() + "__cdc_edges.txt"; const std::unique_ptr ofp(V3File::new_ofstream(filename)); if (ofp->fail()) v3fatal("Can't write " << filename); *ofp << "Edge Report for " << v3Global.opt.prefix() << '\n'; @@ -523,7 +524,7 @@ private: os.setf(std::ios::left); // Module name - doesn't work due to flattening having lost the original // so we assume the modulename matches the filebasename - string fname = vvertexp->varScp()->fileline()->filebasename() + ":"; + const string fname = vvertexp->varScp()->fileline()->filebasename() + ":"; os << " " << std::setw(20) << fname; os << " " << std::setw(8) << what; os << " " << std::setw(40) << vvertexp->varScp()->prettyName(); @@ -727,7 +728,7 @@ public: // CONSTRUCTORS explicit CdcVisitor(AstNode* nodep) { // Make report of all signal names and what clock edges they have - string filename = v3Global.opt.makeDir() + "/" + v3Global.opt.prefix() + "__cdc.txt"; + const string filename = v3Global.opt.makeDir() + "/" + v3Global.opt.prefix() + "__cdc.txt"; m_ofp = V3File::new_ofstream(filename); if (m_ofp->fail()) v3fatal("Can't write " << filename); m_ofFilename = filename; diff --git a/src/V3Clean.cpp b/src/V3Clean.cpp index ba0b91d6c..c9087bab7 100644 --- a/src/V3Clean.cpp +++ b/src/V3Clean.cpp @@ -68,7 +68,7 @@ private: void setCppWidth(AstNode* nodep) { nodep->user2(true); // Don't resize it again AstNodeDType* old_dtypep = nodep->dtypep(); - int width = cppWidth(nodep); // widthMin is unchanged + const int width = cppWidth(nodep); // widthMin is unchanged if (old_dtypep->width() != width) { // Since any given dtype's cppWidth() is the same, we can just // remember one conversion for each, and reuse it @@ -103,7 +103,7 @@ private: void setCleanState(AstNode* nodep, CleanState clean) { nodep->user1(clean); } CleanState getCleanState(AstNode* nodep) { return static_cast(nodep->user1()); } bool isClean(AstNode* nodep) { - CleanState clstate = getCleanState(nodep); + const CleanState clstate = getCleanState(nodep); if (clstate == CS_CLEAN) return true; if (clstate == CS_DIRTY) return false; nodep->v3fatalSrc("Unknown clean state on node: " + nodep->prettyTypeName()); @@ -111,8 +111,9 @@ private: } void setClean(AstNode* nodep, bool isClean) { computeCppWidth(nodep); // Just to be sure it's in widthMin - bool wholeUint = (nodep->widthMin() == VL_IDATASIZE || nodep->widthMin() == VL_QUADSIZE - || (nodep->widthMin() % VL_EDATASIZE) == 0); + const bool wholeUint + = (nodep->widthMin() == VL_IDATASIZE || nodep->widthMin() == VL_QUADSIZE + || (nodep->widthMin() % VL_EDATASIZE) == 0); setCleanState(nodep, ((isClean || wholeUint) ? CS_CLEAN : CS_DIRTY)); } diff --git a/src/V3Clock.cpp b/src/V3Clock.cpp index a02d4dcd1..ddb20dec0 100644 --- a/src/V3Clock.cpp +++ b/src/V3Clock.cpp @@ -219,7 +219,7 @@ private: if (ofuncp->finalsp()) tempp->addStmtsp(ofuncp->finalsp()->unlinkFrBackWithNext()); while (tempp->stmtsp()) { AstNode* itemp = tempp->stmtsp()->unlinkFrBack(); - int stmts = EmitCBaseCounterVisitor(itemp).count(); + const int stmts = EmitCBaseCounterVisitor(itemp).count(); if (!funcp || (func_stmts + stmts) > v3Global.opt.outputSplitCFuncs()) { // Make a new function funcp = new AstCFunc{ofuncp->fileline(), ofuncp->name() + cvtToStr(++funcnum), diff --git a/src/V3Config.cpp b/src/V3Config.cpp index eb02a0a72..6b511b6c7 100644 --- a/src/V3Config.cpp +++ b/src/V3Config.cpp @@ -201,7 +201,7 @@ public: } void applyBlock(AstNodeBlock* nodep) { - AstPragmaType pragma = AstPragmaType::COVERAGE_BLOCK_OFF; + const AstPragmaType pragma = AstPragmaType::COVERAGE_BLOCK_OFF; if (!nodep->unnamed()) { for (const string& i : m_coverageOffBlocks) { if (VString::wildmatch(nodep->name(), i)) { @@ -297,14 +297,14 @@ public: void applyBlock(AstNodeBlock* nodep) { // Apply to block at this line - AstPragmaType pragma = AstPragmaType::COVERAGE_BLOCK_OFF; + const AstPragmaType pragma = AstPragmaType::COVERAGE_BLOCK_OFF; if (lineMatch(nodep->fileline()->lineno(), pragma)) { nodep->addStmtsp(new AstPragma(nodep->fileline(), pragma)); } } void applyCase(AstCase* nodep) { // Apply to this case at this line - int lineno = nodep->fileline()->lineno(); + const int lineno = nodep->fileline()->lineno(); if (lineMatch(lineno, AstPragmaType::FULL_CASE)) nodep->fullPragma(true); if (lineMatch(lineno, AstPragmaType::PARALLEL_CASE)) nodep->parallelPragma(true); } @@ -313,7 +313,7 @@ public: if (m_lastIgnore.lineno != filelinep->lineno()) { // UINFO(9, " ApplyIgnores for " << filelinep->ascii() << endl); // Process all on/offs for lines up to and including the current line - int curlineno = filelinep->lastLineno(); + const int curlineno = filelinep->lastLineno(); for (; m_lastIgnore.it != m_ignLines.end(); ++m_lastIgnore.it) { if (m_lastIgnore.it->m_lineno > curlineno) break; // UINFO(9, " Hit " << *m_lastIt << endl); diff --git a/src/V3Const.cpp b/src/V3Const.cpp index 41bcda7cc..0a1fcdb91 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -376,10 +376,10 @@ class ConstBitOpTreeVisitor final : public AstNVisitor { AstAnd* andp = VN_CAST(nodep->lhsp(), And); CONST_BITOP_RETURN_IF(!andp, nodep->lhsp()); - auto mask = findLeaf(andp->lhsp(), true); + const auto mask = findLeaf(andp->lhsp(), true); CONST_BITOP_RETURN_IF(!mask.m_constp || mask.m_lsb != 0, andp->lhsp()); - LeafInfo leaf = findLeaf(andp->rhsp(), false); + const LeafInfo leaf = findLeaf(andp->rhsp(), false); CONST_BITOP_RETURN_IF(!leaf.m_refp, andp->rhsp()); restorer.disableRestore(); // Now all subtree succeeded @@ -394,7 +394,7 @@ class ConstBitOpTreeVisitor final : public AstNVisitor { } virtual void visit(AstNodeBiop* nodep) override { - auto isConst = [](AstNode* nodep, vluint64_t v) -> bool { + const auto isConst = [](AstNode* nodep, vluint64_t v) -> bool { AstConst* constp = VN_CAST(nodep, Const); return constp && constp->toUQuad() == v; }; @@ -452,16 +452,16 @@ class ConstBitOpTreeVisitor final : public AstNVisitor { Restorer restorer{*this}; CONST_BITOP_RETURN_IF(!m_polarity, nodep); const bool maskFlip = isOrTree(); - LeafInfo comp = findLeaf(nodep->lhsp(), true); + const LeafInfo comp = findLeaf(nodep->lhsp(), true); CONST_BITOP_RETURN_IF(!comp.m_constp || comp.m_lsb != 0, nodep->lhsp()); AstAnd* andp = VN_CAST(nodep->rhsp(), And); // comp == (mask & v) CONST_BITOP_RETURN_IF(!andp, nodep->rhsp()); - LeafInfo mask = findLeaf(andp->lhsp(), true); + const LeafInfo mask = findLeaf(andp->lhsp(), true); CONST_BITOP_RETURN_IF(!mask.m_constp || mask.m_lsb != 0, andp->lhsp()); - LeafInfo ref = findLeaf(andp->rhsp(), false); + const LeafInfo ref = findLeaf(andp->rhsp(), false); CONST_BITOP_RETURN_IF(!ref.m_refp, andp->rhsp()); restorer.disableRestore(); // Now all checks passed @@ -1002,7 +1002,7 @@ private: || lp->num().isFourState() || lp->num().isNegative()) { return false; } - int newLsb = lp->toSInt() + bp->toSInt(); + const int newLsb = lp->toSInt() + bp->toSInt(); if (newLsb + nodep->widthConst() > ap->width()) return false; // UINFO(9, "SEL(SHIFTR(a,b),l,w) -> SEL(a,l+b,w)\n"); @@ -1023,7 +1023,7 @@ private: AstExtend* extendp = VN_CAST(nodep->rhsp(), Extend); if (!extendp) return false; AstNode* smallerp = extendp->lhsp(); - int subsize = smallerp->width(); + const int subsize = smallerp->width(); AstConst* constp = VN_CAST(nodep->lhsp(), Const); if (!constp) return false; if (!constp->num().isBitsZero(constp->width() - 1, subsize)) return false; @@ -1048,7 +1048,7 @@ private: const AstExtend* extendp = VN_CAST_CONST(nodep->rhsp(), Extend); if (!extendp) return false; AstNode* smallerp = extendp->lhsp(); - int subsize = smallerp->width(); + const int subsize = smallerp->width(); const AstConst* constp = VN_CAST_CONST(nodep->lhsp(), Const); if (!constp) return false; if (constp->num().isBitsZero(constp->width() - 1, subsize)) return false; @@ -1079,10 +1079,10 @@ private: } // Find range of dtype we are selecting from // Similar code in V3Unknown::AstSel - bool doit = true; + const bool doit = true; if (m_warn && VN_IS(nodep->lsbp(), Const) && VN_IS(nodep->widthp(), Const) && doit) { - int maxDeclBit = nodep->declRange().hiMaxSelect() * nodep->declElWidth() - + (nodep->declElWidth() - 1); + const int maxDeclBit = nodep->declRange().hiMaxSelect() * nodep->declElWidth() + + (nodep->declElWidth() - 1); if (VN_CAST(nodep->lsbp(), Const)->num().isFourState() || VN_CAST(nodep->widthp(), Const)->num().isFourState()) { nodep->v3error("Selection index is constantly unknown or tristated: " @@ -1157,7 +1157,7 @@ private: const AstConst* lwidth = VN_CAST_CONST(lhsp->widthp(), Const); const AstConst* rwidth = VN_CAST_CONST(rhsp->widthp(), Const); if (!lstart || !rstart || !lwidth || !rwidth) return false; // too complicated - int rend = (rstart->toSInt() + rwidth->toSInt()); + const int rend = (rstart->toSInt() + rwidth->toSInt()); return (rend == lstart->toSInt()); } bool ifMergeAdjacent(AstNode* lhsp, AstNode* rhsp) { @@ -1190,7 +1190,7 @@ private: AstConst* lwidth = VN_CAST(lselp->widthp(), Const); AstConst* rwidth = VN_CAST(rselp->widthp(), Const); if (!lstart || !rstart || !lwidth || !rwidth) return false; // too complicated - int rend = (rstart->toSInt() + rwidth->toSInt()); + const int rend = (rstart->toSInt() + rwidth->toSInt()); // a[i:j] a[j-1:k] if (rend == lstart->toSInt()) return true; // a[i:0] a[msb:j] @@ -1207,8 +1207,8 @@ private: const AstNodeBiop* rp = VN_CAST_CONST(rhsp, NodeBiop); if (!lp || !rp) return false; // {a[]&b[], a[]&b[]} - bool lad = ifMergeAdjacent(lp->lhsp(), rp->lhsp()); - bool rad = ifMergeAdjacent(lp->rhsp(), rp->rhsp()); + const bool lad = ifMergeAdjacent(lp->lhsp(), rp->lhsp()); + const bool rad = ifMergeAdjacent(lp->rhsp(), rp->rhsp()); if (lad && rad) return true; // {a[] & b[]&c[], a[] & b[]&c[]} if (lad && concatMergeable(lp->rhsp(), rp->rhsp())) return true; @@ -1449,10 +1449,10 @@ private: // {a[1], a[0]} -> a[1:0] AstSel* lselp = VN_CAST(nodep->lhsp()->unlinkFrBack(), Sel); AstSel* rselp = VN_CAST(nodep->rhsp()->unlinkFrBack(), Sel); - int lstart = lselp->lsbConst(); - int lwidth = lselp->widthConst(); - int rstart = rselp->lsbConst(); - int rwidth = rselp->widthConst(); + const int lstart = lselp->lsbConst(); + const int lwidth = lselp->widthConst(); + const int rstart = rselp->lsbConst(); + const int rwidth = rselp->widthConst(); UASSERT_OBJ((rstart + rwidth) == lstart, nodep, "tried to merge two selects which are not adjacent"); @@ -1513,7 +1513,7 @@ private: } void replaceMulShift(AstMul* nodep) { // Mul, but not MulS as not simple shift UINFO(5, "MUL(2^n,b)->SHIFTL(b,n) " << nodep << endl); - int amount = VN_CAST(nodep->lhsp(), Const)->num().mostSetBitP1() - 1; // 2^n->n+1 + const int amount = VN_CAST(nodep->lhsp(), Const)->num().mostSetBitP1() - 1; // 2^n->n+1 AstNode* opp = nodep->rhsp()->unlinkFrBack(); AstShiftL* newp = new AstShiftL(nodep->fileline(), opp, new AstConst(nodep->fileline(), amount)); @@ -1523,7 +1523,7 @@ private: } void replaceDivShift(AstDiv* nodep) { // Mul, but not MulS as not simple shift UINFO(5, "DIV(b,2^n)->SHIFTR(b,n) " << nodep << endl); - int amount = VN_CAST(nodep->rhsp(), Const)->num().mostSetBitP1() - 1; // 2^n->n+1 + const int amount = VN_CAST(nodep->rhsp(), Const)->num().mostSetBitP1() - 1; // 2^n->n+1 AstNode* opp = nodep->lhsp()->unlinkFrBack(); AstShiftR* newp = new AstShiftR(nodep->fileline(), opp, new AstConst(nodep->fileline(), amount)); @@ -1533,7 +1533,7 @@ private: } void replaceModAnd(AstModDiv* nodep) { // Mod, but not ModS as not simple shift UINFO(5, "MOD(b,2^n)->AND(b,2^n-1) " << nodep << endl); - int amount = VN_CAST(nodep->rhsp(), Const)->num().mostSetBitP1() - 1; // 2^n->n+1 + const int amount = VN_CAST(nodep->rhsp(), Const)->num().mostSetBitP1() - 1; // 2^n->n+1 V3Number mask(nodep, nodep->width()); mask.setMask(amount); AstNode* opp = nodep->lhsp()->unlinkFrBack(); @@ -1576,7 +1576,7 @@ private: if (nodep->type() == lhsp->type()) { int shift1 = VN_CAST(shift1p, Const)->toUInt(); int shift2 = VN_CAST(shift2p, Const)->toUInt(); - int newshift = shift1 + shift2; + const int newshift = shift1 + shift2; VL_DO_DANGLING(shift1p->deleteTree(), shift1p); VL_DO_DANGLING(shift2p->deleteTree(), shift2p); nodep->lhsp(ap); @@ -1588,7 +1588,7 @@ private: if (VN_IS(lhsp, ShiftR)) shift1 = -shift1; int shift2 = VN_CAST(shift2p, Const)->toUInt(); if (VN_IS(nodep, ShiftR)) shift2 = -shift2; - int newshift = shift1 + shift2; + const int newshift = shift1 + shift2; VL_DO_DANGLING(shift1p->deleteTree(), shift1p); VL_DO_DANGLING(shift2p->deleteTree(), shift2p); AstNode* newp; @@ -1656,7 +1656,7 @@ private: && (con2p->toSInt() != con1p->toSInt() + sel1p->width())) { return false; } - bool lsbFirstAssign = (con1p->toUInt() < con2p->toUInt()); + const bool lsbFirstAssign = (con1p->toUInt() < con2p->toUInt()); UINFO(4, "replaceAssignMultiSel " << nodep << endl); UINFO(4, " && " << nextp << endl); // nodep->dumpTree(cout, "comb1: "); @@ -1815,8 +1815,8 @@ private: return true; } else if (m_doV && VN_IS(nodep->lhsp(), StreamL)) { // Push the stream operator to the rhs of the assignment statement - int dWidth = VN_CAST(nodep->lhsp(), StreamL)->lhsp()->width(); - int sWidth = nodep->rhsp()->width(); + const int dWidth = VN_CAST(nodep->lhsp(), StreamL)->lhsp()->width(); + const int sWidth = nodep->rhsp()->width(); // Unlink the stuff AstNode* dstp = VN_CAST(nodep->lhsp(), StreamL)->lhsp()->unlinkFrBack(); AstNode* streamp = VN_CAST(nodep->lhsp(), StreamL)->unlinkFrBack(); @@ -1836,8 +1836,8 @@ private: // The right stream operator on lhs of assignment statement does // not reorder bits. However, if the rhs is wider than the lhs, // then we select bits from the left-most, not the right-most. - int dWidth = VN_CAST(nodep->lhsp(), StreamR)->lhsp()->width(); - int sWidth = nodep->rhsp()->width(); + const int dWidth = VN_CAST(nodep->lhsp(), StreamR)->lhsp()->width(); + const int sWidth = nodep->rhsp()->width(); // Unlink the stuff AstNode* dstp = VN_CAST(nodep->lhsp(), StreamR)->lhsp()->unlinkFrBack(); AstNode* sizep = VN_CAST(nodep->lhsp(), StreamR)->rhsp()->unlinkFrBack(); @@ -2666,7 +2666,7 @@ private: string fmt; bool inPct = false; AstNode* argp = nodep->exprsp(); - string text = nodep->text(); + const string text = nodep->text(); for (const char ch : text) { if (!inPct && ch == '%') { inPct = true; @@ -2688,7 +2688,8 @@ private: if (argp) { AstNode* nextp = argp->nextp(); if (VN_IS(argp, Const)) { // Convert it - string out = VN_CAST(argp, Const)->num().displayed(nodep, fmt); + const string out + = VN_CAST(argp, Const)->num().displayed(nodep, fmt); UINFO(9, " DispConst: " << fmt << " -> " << out << " for " << argp << endl); // fmt = out w/ replace % with %% as it must be literal. @@ -2726,10 +2727,10 @@ private: iterateChildren(nodep); } virtual void visit(AstWhile* nodep) override { - bool oldHasJumpDelay = m_hasJumpDelay; + const bool oldHasJumpDelay = m_hasJumpDelay; m_hasJumpDelay = false; { iterateChildren(nodep); } - bool thisWhileHasJumpDelay = m_hasJumpDelay; + const bool thisWhileHasJumpDelay = m_hasJumpDelay; m_hasJumpDelay = thisWhileHasJumpDelay || oldHasJumpDelay; if (m_doNConst) { if (nodep->condp()->isZero()) { diff --git a/src/V3Coverage.cpp b/src/V3Coverage.cpp index b2fa737d3..2f9524df8 100644 --- a/src/V3Coverage.cpp +++ b/src/V3Coverage.cpp @@ -92,7 +92,7 @@ private: // See also similar rule in V3TraceDecl::varIgnoreTrace if (!nodep->isToggleCoverable()) return "Not relevant signal type"; if (!v3Global.opt.coverageUnderscore()) { - string prettyName = nodep->prettyName(); + const string prettyName = nodep->prettyName(); if (prettyName[0] == '_') return "Leading underscore"; if (prettyName.find("._") != string::npos) return "Inlined leading underscore"; } @@ -114,7 +114,7 @@ private: // Note the module name could have parameters appended, we'll consider this // a feature as it allows for each parameterized block to be counted separately. // Someday the user might be allowed to specify a different page suffix - string page = page_prefix + "/" + m_modp->prettyName(); + const string page = page_prefix + "/" + m_modp->prettyName(); AstCoverDecl* declp = new AstCoverDecl(fl, page, comment, linescov, offset); declp->hier(hier); @@ -144,7 +144,7 @@ private: if (it == m_varnames.end()) { m_varnames.emplace(name, 1); } else { - int suffix = (it->second)++; + const int suffix = (it->second)++; name += "_" + cvtToStr(suffix); } return name; @@ -278,7 +278,7 @@ private: // We'll do this, and make the if(...) coverinc later. // Add signal to hold the old value - string newvarname = string("__Vtogcov__") + nodep->shortName(); + const string newvarname = string("__Vtogcov__") + nodep->shortName(); AstVar* chgVarp = new AstVar(nodep->fileline(), AstVarType::MODULETEMP, newvarname, nodep); chgVarp->fileline()->modifyWarnOff(V3ErrorCode::UNUSED, true); @@ -312,7 +312,7 @@ private: if (bdtypep->isRanged()) { for (int index_docs = bdtypep->lo(); index_docs < bdtypep->hi() + 1; ++index_docs) { - int index_code = index_docs - bdtypep->lo(); + const int index_code = index_docs - bdtypep->lo(); ToggleEnt newent(above.m_comment + string("[") + cvtToStr(index_docs) + "]", new AstSel(varp->fileline(), above.m_varRefp->cloneTree(true), index_code, 1), @@ -326,7 +326,7 @@ private: } } else if (AstUnpackArrayDType* adtypep = VN_CAST(dtypep, UnpackArrayDType)) { for (int index_docs = adtypep->lo(); index_docs <= adtypep->hi(); ++index_docs) { - int index_code = index_docs - adtypep->lo(); + const int index_code = index_docs - adtypep->lo(); ToggleEnt newent(above.m_comment + string("[") + cvtToStr(index_docs) + "]", new AstArraySel(varp->fileline(), above.m_varRefp->cloneTree(true), index_code), @@ -339,7 +339,7 @@ private: } else if (AstPackArrayDType* adtypep = VN_CAST(dtypep, PackArrayDType)) { for (int index_docs = adtypep->lo(); index_docs <= adtypep->hi(); ++index_docs) { AstNodeDType* subtypep = adtypep->subDTypep()->skipRefp(); - int index_code = index_docs - adtypep->lo(); + const int index_code = index_docs - adtypep->lo(); ToggleEnt newent(above.m_comment + string("[") + cvtToStr(index_docs) + "]", new AstSel(varp->fileline(), above.m_varRefp->cloneTree(true), index_code * subtypep->width(), subtypep->width()), @@ -354,7 +354,7 @@ private: for (AstMemberDType* itemp = adtypep->membersp(); itemp; itemp = VN_CAST(itemp->nextp(), MemberDType)) { AstNodeDType* subtypep = itemp->subDTypep()->skipRefp(); - int index_code = itemp->lsb(); + const int index_code = itemp->lsb(); ToggleEnt newent(above.m_comment + string(".") + itemp->name(), new AstSel(varp->fileline(), above.m_varRefp->cloneTree(true), index_code, subtypep->width()), @@ -385,17 +385,18 @@ private: UINFO(4, " IF: " << nodep << endl); if (m_state.m_on) { // An else-if. When we iterate the if, use "elsif" marking - bool elsif = nodep->ifsp() && VN_IS(nodep->elsesp(), If) && !nodep->elsesp()->nextp(); + const bool elsif + = nodep->ifsp() && VN_IS(nodep->elsesp(), If) && !nodep->elsesp()->nextp(); if (elsif) VN_CAST(nodep->elsesp(), If)->user1(true); - bool first_elsif = !nodep->user1() && elsif; - bool cont_elsif = nodep->user1() && elsif; - bool final_elsif = nodep->user1() && !elsif && nodep->elsesp(); + const bool first_elsif = !nodep->user1() && elsif; + const bool cont_elsif = nodep->user1() && elsif; + const bool final_elsif = nodep->user1() && !elsif && nodep->elsesp(); // // Considered: If conditional is on a different line from if/else then we // can show it as part of line coverage of the statement // above. Otherwise show it based on what is inside. // But: Seemed too complicated, and fragile. - CheckState lastState = m_state; + const CheckState lastState = m_state; CheckState ifState; CheckState elseState; { diff --git a/src/V3Delayed.cpp b/src/V3Delayed.cpp index 66d1ff33e..3e3cd280f 100644 --- a/src/V3Delayed.cpp +++ b/src/V3Delayed.cpp @@ -110,7 +110,7 @@ private: if (!lastrefp) { vscp->user5p(nodep); } else { - bool last_was_blocking = lastrefp->user5(); + const bool last_was_blocking = lastrefp->user5(); if (last_was_blocking != blocking) { AstNode* nonblockingp = blocking ? nodep : lastrefp; AstNode* blockingp = blocking ? lastrefp : nodep; @@ -228,7 +228,7 @@ private: UASSERT_OBJ(varrefp->varScopep(), varrefp, "Var didn't get varscoped in V3Scope.cpp"); varrefp->unlinkFrBack(); AstVar* oldvarp = varrefp->varp(); - int modVecNum = m_scopeVecMap[varrefp->varScopep()]++; + const int modVecNum = m_scopeVecMap[varrefp->varScopep()]++; // std::deque dimreadps; // Read value for each dimension of assignment for (unsigned dimension = 0; dimension < dimvalp.size(); dimension++) { @@ -236,8 +236,8 @@ private: if (VN_IS(dimp, Const)) { // bit = const, can just use it dimreadps.push_front(dimp); } else { - string bitvarname = (string("__Vdlyvdim") + cvtToStr(dimension) + "__" - + oldvarp->shortName() + "__v" + cvtToStr(modVecNum)); + const string bitvarname = (string("__Vdlyvdim") + cvtToStr(dimension) + "__" + + oldvarp->shortName() + "__v" + cvtToStr(modVecNum)); AstVarScope* bitvscp = createVarSc(varrefp->varScopep(), bitvarname, dimp->width(), nullptr); AstAssign* bitassignp = new AstAssign( @@ -256,8 +256,8 @@ private: // vlsb = constant, can just push constant into where we use it bitreadp = lsbvaluep; } else { - string bitvarname = (string("__Vdlyvlsb__") + oldvarp->shortName() + "__v" - + cvtToStr(modVecNum)); + const string bitvarname = (string("__Vdlyvlsb__") + oldvarp->shortName() + "__v" + + cvtToStr(modVecNum)); AstVarScope* bitvscp = createVarSc(varrefp->varScopep(), bitvarname, lsbvaluep->width(), nullptr); AstAssign* bitassignp = new AstAssign( @@ -440,7 +440,7 @@ private: checkActivePost(nodep, oldactivep); } if (!dlyvscp) { // First use of this delayed variable - string newvarname = (string("__Vdly__") + nodep->varp()->shortName()); + const string newvarname = (string("__Vdly__") + nodep->varp()->shortName()); dlyvscp = createVarSc(oldvscp, newvarname, 0, nullptr); AstNodeAssign* prep; AstBasicDType* basicp = oldvscp->dtypep()->basicp(); diff --git a/src/V3Depth.cpp b/src/V3Depth.cpp index 789cf8359..9aef1f3b6 100644 --- a/src/V3Depth.cpp +++ b/src/V3Depth.cpp @@ -52,7 +52,7 @@ private: UINFO(6, " Deep " << nodep << endl); // if (debug() >= 9) nodep->dumpTree(cout, "deep:"); - string newvarname = (string("__Vdeeptemp") + cvtToStr(m_modp->varNumGetInc())); + const string newvarname = (string("__Vdeeptemp") + cvtToStr(m_modp->varNumGetInc())); AstVar* varp = new AstVar(nodep->fileline(), AstVarType::STMTTEMP, newvarname, nodep->dtypep()); UASSERT_OBJ(m_cfuncp, nodep, "Deep expression not under a function"); diff --git a/src/V3Descope.cpp b/src/V3Descope.cpp index a1f5453bd..b6057ae85 100644 --- a/src/V3Descope.cpp +++ b/src/V3Descope.cpp @@ -111,7 +111,7 @@ private: // If for any given name only one function exists, we can use that function directly. // If multiple functions exist, we need to select the appropriate scope. for (FuncMmap::iterator it = m_modFuncs.begin(); it != m_modFuncs.end(); ++it) { - string name = it->first; + const string name = it->first; AstCFunc* topFuncp = it->second; auto nextIt1 = it; ++nextIt1; @@ -133,7 +133,8 @@ private: AstCFunc* funcp = eachIt->second; auto nextIt2 = eachIt; ++nextIt2; - bool moreOfSame = (nextIt2 != m_modFuncs.end() && nextIt2->first == name); + const bool moreOfSame + = (nextIt2 != m_modFuncs.end() && nextIt2->first == name); UASSERT_OBJ(funcp->scopep(), funcp, "Not scoped"); UINFO(6, " Wrapping " << name << " " << funcp << endl); diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index b8f870f21..ea505740b 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -561,7 +561,7 @@ public: // displays are handled in AstDisplay if (!nodep->dpiExport()) { // this is where the DPI import context scope is set - string scope = nodep->scopeDpiName(); + const string scope = nodep->scopeDpiName(); putbs("(&(vlSymsp->" + protect("__Vscope_" + scope) + "))"); } } @@ -1520,15 +1520,15 @@ class EmitCImp final : EmitCStmts { if (v3Global.opt.lintOnly()) { // Unfortunately we have some lint checks here, so we can't just skip processing. // We should move them to a different stage. - string filename = VL_DEV_NULL; + const string filename = VL_DEV_NULL; newCFile(filename, slow, source); ofp = new V3OutCFile(filename); } else if (optSystemC()) { - string filename = filenameNoExt + (source ? ".cpp" : ".h"); + const string filename = filenameNoExt + (source ? ".cpp" : ".h"); newCFile(filename, slow, source); ofp = new V3OutScFile(filename); } else { - string filename = filenameNoExt + (source ? ".cpp" : ".h"); + const string filename = filenameNoExt + (source ? ".cpp" : ".h"); newCFile(filename, slow, source); ofp = new V3OutCFile(filename); } @@ -1800,30 +1800,30 @@ class EmitCImp final : EmitCStmts { // Returns string to do resetting, empty to do nothing (which caller should handle) if (AstAssocArrayDType* adtypep = VN_CAST(dtypep, AssocArrayDType)) { // Access std::array as C array - string cvtarray = (adtypep->subDTypep()->isWide() ? ".data()" : ""); + const string cvtarray = (adtypep->subDTypep()->isWide() ? ".data()" : ""); return emitVarResetRecurse(varp, varNameProtected, adtypep->subDTypep(), depth + 1, suffix + ".atDefault()" + cvtarray); } else if (VN_IS(dtypep, ClassRefDType)) { return ""; // Constructor does it } else if (AstDynArrayDType* adtypep = VN_CAST(dtypep, DynArrayDType)) { // Access std::array as C array - string cvtarray = (adtypep->subDTypep()->isWide() ? ".data()" : ""); + const string cvtarray = (adtypep->subDTypep()->isWide() ? ".data()" : ""); return emitVarResetRecurse(varp, varNameProtected, adtypep->subDTypep(), depth + 1, suffix + ".atDefault()" + cvtarray); } else if (AstQueueDType* adtypep = VN_CAST(dtypep, QueueDType)) { // Access std::array as C array - string cvtarray = (adtypep->subDTypep()->isWide() ? ".data()" : ""); + const string cvtarray = (adtypep->subDTypep()->isWide() ? ".data()" : ""); return emitVarResetRecurse(varp, varNameProtected, adtypep->subDTypep(), depth + 1, suffix + ".atDefault()" + cvtarray); } else if (AstUnpackArrayDType* adtypep = VN_CAST(dtypep, UnpackArrayDType)) { UASSERT_OBJ(adtypep->hi() >= adtypep->lo(), varp, "Should have swapped msb & lsb earlier."); - string ivar = string("__Vi") + cvtToStr(depth); - string pre = ("for (int " + ivar + "=" + cvtToStr(0) + "; " + ivar + "<" - + cvtToStr(adtypep->elementsConst()) + "; ++" + ivar + ") {\n"); - string below = emitVarResetRecurse(varp, varNameProtected, adtypep->subDTypep(), - depth + 1, suffix + "[" + ivar + "]"); - string post = "}\n"; + const string ivar = string("__Vi") + cvtToStr(depth); + const string pre = ("for (int " + ivar + "=" + cvtToStr(0) + "; " + ivar + "<" + + cvtToStr(adtypep->elementsConst()) + "; ++" + ivar + ") {\n"); + const string below = emitVarResetRecurse(varp, varNameProtected, adtypep->subDTypep(), + depth + 1, suffix + "[" + ivar + "]"); + const string post = "}\n"; return below.empty() ? "" : pre + below + post; } else if (basicp && basicp->keyword() == AstBasicDTypeKwd::STRING) { // String's constructor deals with it @@ -2224,9 +2224,9 @@ void EmitCStmts::displayEmit(AstNode* nodep, bool isScan) { ofp()->putsQuoted(emitDispState.m_format); // Arguments for (unsigned i = 0; i < emitDispState.m_argsp.size(); i++) { - char fmt = emitDispState.m_argsChar[i]; + const char fmt = emitDispState.m_argsChar[i]; AstNode* argp = emitDispState.m_argsp[i]; - string func = emitDispState.m_argsFunc[i]; + const string func = emitDispState.m_argsFunc[i]; if (func != "" || argp) { puts(","); ofp()->indentInc(); @@ -2234,7 +2234,7 @@ void EmitCStmts::displayEmit(AstNode* nodep, bool isScan) { if (func != "") { puts(func); } else if (argp) { - bool addrof = isScan || (fmt == '@'); + const bool addrof = isScan || (fmt == '@'); if (addrof) puts("&("); iterate(argp); if (!addrof) emitDatap(argp); @@ -2287,7 +2287,7 @@ void EmitCStmts::displayArg(AstNode* dispp, AstNode** elistp, bool isScan, const // + 1.0 rounding bias. double dchars = mantissabits / 3.321928094887362 + 1.0; if (fmtLetter == 'd') dchars++; // space for sign - int nchars = int(dchars); + const int nchars = int(dchars); pfmt = string("%") + cvtToStr(nchars) + fmtLetter; } else { pfmt = string("%") + vfmt + fmtLetter; @@ -2392,7 +2392,7 @@ void EmitCStmts::displayNode(AstNode* nodep, AstScopeName* scopenamep, const str case 'z': displayArg(nodep, &elistp, isScan, vfmt, ignore, 'z'); break; case 'm': { UASSERT_OBJ(scopenamep, nodep, "Display with %m but no AstScopeName"); - string suffix = scopenamep->scopePrettySymName(); + const string suffix = scopenamep->scopePrettySymName(); if (suffix == "") { emitDispState.pushFormat("%S"); } else { @@ -2613,9 +2613,9 @@ void EmitCImp::emitSavableImp(AstNodeModule* modp) { if (v3Global.opt.savable()) { puts("\n// Savable\n"); for (int de = 0; de < 2; ++de) { - string classname = de ? "VerilatedDeserialize" : "VerilatedSerialize"; - string funcname = de ? "__Vdeserialize" : "__Vserialize"; - string op = de ? ">>" : "<<"; + const string classname = de ? "VerilatedDeserialize" : "VerilatedSerialize"; + const string funcname = de ? "__Vdeserialize" : "__Vserialize"; + const string op = de ? ">>" : "<<"; // NOLINTNEXTLINE(performance-inefficient-string-concatenation) puts("void " + prefixNameProtect(modp) + "::" + protect(funcname) + "(" + classname + "& os) {\n"); @@ -2657,10 +2657,10 @@ void EmitCImp::emitSavableImp(AstNodeModule* modp) { AstNodeDType* elementp = varp->dtypeSkipRefp(); for (AstUnpackArrayDType* arrayp = VN_CAST(elementp, UnpackArrayDType); arrayp; arrayp = VN_CAST(elementp, UnpackArrayDType)) { - int vecnum = vects++; + const int vecnum = vects++; UASSERT_OBJ(arrayp->hi() >= arrayp->lo(), varp, "Should have swapped msb & lsb earlier."); - string ivar = string("__Vi") + cvtToStr(vecnum); + const string ivar = string("__Vi") + cvtToStr(vecnum); puts("for (int __Vi" + cvtToStr(vecnum) + "=" + cvtToStr(0)); puts("; " + ivar + "<" + cvtToStr(arrayp->elementsConst())); puts("; ++" + ivar + ") {\n"); @@ -2673,8 +2673,8 @@ void EmitCImp::emitSavableImp(AstNodeModule* modp) { // (i.e. packed types of more than 64 bits). if (elementp->isWide() && !(basicp && basicp->keyword() == AstBasicDTypeKwd::STRING)) { - int vecnum = vects++; - string ivar = string("__Vi") + cvtToStr(vecnum); + const int vecnum = vects++; + const string ivar = string("__Vi") + cvtToStr(vecnum); puts("for (int __Vi" + cvtToStr(vecnum) + "=" + cvtToStr(0)); puts("; " + ivar + "<" + cvtToStr(elementp->widthWords())); puts("; ++" + ivar + ") {\n"); @@ -2731,10 +2731,10 @@ void EmitCImp::emitSensitives() { = VN_CAST(varp->dtypeSkipRefp(), UnpackArrayDType); arrayp; arrayp = VN_CAST(arrayp->subDTypep()->skipRefp(), UnpackArrayDType)) { - int vecnum = vects++; + const int vecnum = vects++; UASSERT_OBJ(arrayp->hi() >= arrayp->lo(), varp, "Should have swapped msb & lsb earlier."); - string ivar = string("__Vi") + cvtToStr(vecnum); + const string ivar = string("__Vi") + cvtToStr(vecnum); puts("for (int __Vi" + cvtToStr(vecnum) + "=" + cvtToStr(arrayp->lo())); puts("; " + ivar + "<=" + cvtToStr(arrayp->hi())); puts("; ++" + ivar + ") {\n"); @@ -2947,7 +2947,7 @@ void EmitCStmts::emitVarList(AstNode* firstp, EisWhich which, const string& pref } if (varp->isStatic() ? !isstatic : isstatic) doit = false; if (doit) { - int sigbytes = varp->dtypeSkipRefp()->widthAlignBytes(); + const int sigbytes = varp->dtypeSkipRefp()->widthAlignBytes(); int sortbytes = 9; if (varp->isUsedClock() && varp->widthMin() == 1) { sortbytes = 0; @@ -2966,13 +2966,14 @@ void EmitCStmts::emitVarList(AstNode* firstp, EisWhich which, const string& pref } else if (sigbytes == 1) { sortbytes = 1; } - bool anonOk = (v3Global.opt.compLimitMembers() != 0 // Enabled - && !varp->isStatic() && !varp->isIO() // Confusing to user - && !varp->isSc() // Aggregates can't be anon - && (varp->basicp() - && !varp->basicp()->isOpaque()) // Aggregates can't be anon - && which != EVL_FUNC_ALL); // Anon not legal in funcs, and gcc - // bug free there anyhow + const bool anonOk + = (v3Global.opt.compLimitMembers() != 0 // Enabled + && !varp->isStatic() && !varp->isIO() // Confusing to user + && !varp->isSc() // Aggregates can't be anon + && (varp->basicp() + && !varp->basicp()->isOpaque()) // Aggregates can't be anon + && which != EVL_FUNC_ALL); // Anon not legal in funcs, and gcc + // bug free there anyhow if (anonOk) { varAnonMap[sortbytes].push_back(varp); } else { @@ -3013,7 +3014,7 @@ void EmitCStmts::emitVarSort(const VarSortMap& vmap, VarVec* sortedp) { using MTaskVarSortMap = std::map; MTaskVarSortMap m2v; for (VarSortMap::const_iterator it = vmap.begin(); it != vmap.end(); ++it) { - int size_class = it->first; + const int size_class = it->first; const VarVec& vec = it->second; for (const AstVar* varp : vec) { m2v[varp->mtaskIds()][size_class].push_back(varp); } } @@ -3048,8 +3049,8 @@ void EmitCStmts::emitSortedVarList(const VarVec& anons, const VarVec& nonanons, string curVarCmt; // Output anons { - int anonMembers = anons.size(); - int lim = v3Global.opt.compLimitMembers(); + const int anonMembers = anons.size(); + const int lim = v3Global.opt.compLimitMembers(); int anonL3s = 1; int anonL2s = 1; int anonL1s = 1; @@ -3643,8 +3644,8 @@ class EmitCTrace final : EmitCStmts { } // // fstVarType - AstVarType vartype = nodep->varType(); - AstBasicDTypeKwd kwd = nodep->declKwd(); + const AstVarType vartype = nodep->varType(); + const AstBasicDTypeKwd kwd = nodep->declKwd(); string fstvt; // Doubles have special decoding properties, so must indicate if a double if (nodep->dtypep()->basicp()->isDouble()) { @@ -3902,7 +3903,7 @@ class EmitCTrace final : EmitCStmts { } } virtual void visit(AstTraceDecl* nodep) override { - int enumNum = emitTraceDeclDType(nodep->dtypep()); + const int enumNum = emitTraceDeclDType(nodep->dtypep()); if (nodep->arrayRange().ranged()) { puts("{int i; for (i=0; i<" + cvtToStr(nodep->arrayRange().elements()) + "; i++) {\n"); emitTraceInitOne(nodep, enumNum); @@ -3947,7 +3948,7 @@ public: static void setParentClassPointers() { // Set user4p in all CFunc and Var to point to the containing AstNodeModule - auto setAll = [](AstNodeModule* modp) -> void { + const auto setAll = [](AstNodeModule* modp) -> void { for (AstNode* nodep = VN_CAST(modp, NodeModule)->stmtsp(); nodep; nodep = nodep->nextp()) { if (VN_IS(nodep, CFunc) || VN_IS(nodep, Var)) nodep->user4p(modp); } diff --git a/src/V3EmitCMain.cpp b/src/V3EmitCMain.cpp index a7260fb8f..493aca407 100644 --- a/src/V3EmitCMain.cpp +++ b/src/V3EmitCMain.cpp @@ -40,7 +40,7 @@ public: private: // MAIN METHOD void emitInt() { - string filename = v3Global.opt.makeDir() + "/" + topClassName() + "__main.cpp"; + const string filename = v3Global.opt.makeDir() + "/" + topClassName() + "__main.cpp"; newCFile(filename, false /*slow*/, true /*source*/); V3OutCFile cf(filename); m_ofp = &cf; diff --git a/src/V3EmitCMake.cpp b/src/V3EmitCMake.cpp index a2aa6bd78..82ea3c1f8 100644 --- a/src/V3EmitCMake.cpp +++ b/src/V3EmitCMake.cpp @@ -64,7 +64,7 @@ class CMakeEmitter final { static void cmake_set(std::ofstream& of, const string& name, const string& value, const string& cache_type = "", const string& docstring = "") { - string raw_value = "\"" + value + "\""; + const string raw_value = "\"" + value + "\""; cmake_set_raw(of, name, raw_value, cache_type, docstring); } @@ -80,7 +80,7 @@ class CMakeEmitter final { static void emitOverallCMake() { const std::unique_ptr of( V3File::new_ofstream(v3Global.opt.makeDir() + "/" + v3Global.opt.prefix() + ".cmake")); - string name = v3Global.opt.prefix(); + const string name = v3Global.opt.prefix(); *of << "# Verilated -*- CMake -*-\n"; *of << "# DESCR" diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index ccd80af56..1a4bbca13 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -125,7 +125,7 @@ class EmitCSyms final : EmitCBaseVisitor { && !(VN_IS(nodep, CFunc) && (VN_CAST(nodep, CFunc)->isConstructor() || VN_CAST(nodep, CFunc)->isDestructor()))) { - string rsvd = V3LanguageWords::isKeyword(nodep->name()); + const string rsvd = V3LanguageWords::isKeyword(nodep->name()); if (rsvd != "") { // Generally V3Name should find all of these and throw SYMRSVDWORD. // We'll still check here because the compiler errors @@ -170,7 +170,7 @@ class EmitCSyms final : EmitCBaseVisitor { const auto scpit = m_vpiScopeCandidates.find(scp); if ((scpit != m_vpiScopeCandidates.end()) && (m_scopeNames.find(scp) == m_scopeNames.end())) { - auto scopeNameit = m_scopeNames.find(scpit->second.m_symName); + const auto scopeNameit = m_scopeNames.find(scpit->second.m_symName); if (scopeNameit == m_scopeNames.end()) { m_scopeNames.emplace(scpit->second.m_symName, scpit->second); } else { @@ -216,9 +216,9 @@ class EmitCSyms final : EmitCBaseVisitor { } // UINFO(9,"For "<name()<<" - "<name()<<" Scp "<second.m_type != "SCOPE_MODULE") continue; - string symName = it->second.m_symName; + const string symName = it->second.m_symName; string above = symName; if (above.substr(0, 4) == "TOP.") above.replace(0, 4, ""); @@ -289,10 +289,11 @@ class EmitCSyms final : EmitCBaseVisitor { } virtual void visit(AstCellInline* nodep) override { if (v3Global.opt.vpi()) { - string type = (nodep->origModName() == "__BEGIN__") ? "SCOPE_OTHER" : "SCOPE_MODULE"; - string name = nodep->scopep()->name() + "__DOT__" + nodep->name(); - string name_dedot = AstNode::dedotName(name); - int timeunit = m_modp->timeunit().powerOfTen(); + const string type + = (nodep->origModName() == "__BEGIN__") ? "SCOPE_OTHER" : "SCOPE_MODULE"; + const string name = nodep->scopep()->name() + "__DOT__" + nodep->name(); + const string name_dedot = AstNode::dedotName(name); + const int timeunit = m_modp->timeunit().powerOfTen(); m_vpiScopeCandidates.insert( std::make_pair(name, ScopeData(scopeSymString(name), name_dedot, timeunit, type))); } @@ -304,19 +305,19 @@ class EmitCSyms final : EmitCBaseVisitor { m_scopes.emplace_back(std::make_pair(nodep, m_modp)); if (v3Global.opt.vpi() && !nodep->isTop()) { - string type = VN_IS(nodep->modp(), Package) ? "SCOPE_OTHER" : "SCOPE_MODULE"; - string name_dedot = AstNode::dedotName(nodep->shortName()); - int timeunit = m_modp->timeunit().powerOfTen(); + const string type = VN_IS(nodep->modp(), Package) ? "SCOPE_OTHER" : "SCOPE_MODULE"; + const string name_dedot = AstNode::dedotName(nodep->shortName()); + const int timeunit = m_modp->timeunit().powerOfTen(); m_vpiScopeCandidates.insert( std::make_pair(nodep->name(), ScopeData(scopeSymString(nodep->name()), name_dedot, timeunit, type))); } } virtual void visit(AstScopeName* nodep) override { - string name = nodep->scopeSymName(); + const string name = nodep->scopeSymName(); // UINFO(9,"scnameins sp "<name()<<" sp "<scopePrettySymName() // <<" ss"<timeunit().powerOfTen() : 0; + const int timeunit = m_modp ? m_modp->timeunit().powerOfTen() : 0; if (m_scopeNames.find(name) == m_scopeNames.end()) { m_scopeNames.emplace( name, ScopeData(name, nodep->scopePrettySymName(), timeunit, "SCOPE_OTHER")); @@ -369,7 +370,7 @@ public: void EmitCSyms::emitSymHdr() { UINFO(6, __FUNCTION__ << ": " << endl); - string filename = v3Global.opt.makeDir() + "/" + symClassName() + ".h"; + const string filename = v3Global.opt.makeDir() + "/" + symClassName() + ".h"; newCFile(filename, true /*slow*/, false /*source*/); if (v3Global.opt.systemC()) { @@ -408,7 +409,8 @@ void EmitCSyms::emitSymHdr() { for (const auto& itr : m_scopeFuncs) { AstCFunc* funcp = itr.second.m_cfuncp; if (funcp->dpiExportImpl()) { - string cbtype = protect(v3Global.opt.prefix() + "__Vcb_" + funcp->cname() + "_t"); + const string cbtype + = protect(v3Global.opt.prefix() + "__Vcb_" + funcp->cname() + "_t"); types["using " + cbtype + " = void (*) (" + cFuncArgs(funcp) + ");\n"] = 1; } } @@ -575,12 +577,12 @@ void EmitCSyms::emitSymImpPreamble() { void EmitCSyms::emitScopeHier(bool destroy) { if (v3Global.opt.vpi()) { - string verb = destroy ? "Tear down" : "Set up"; - string method = destroy ? "remove" : "add"; + const string verb = destroy ? "Tear down" : "Set up"; + const string method = destroy ? "remove" : "add"; puts("\n// " + verb + " scope hierarchy\n"); for (ScopeNames::const_iterator it = m_scopeNames.begin(); it != m_scopeNames.end(); ++it) { - string name = it->second.m_prettyName; + const string name = it->second.m_prettyName; if (it->first == "TOP") continue; if ((name.find('.') == string::npos) && (it->second.m_type == "SCOPE_MODULE")) { puts("__Vhier." + method + "(0, &" + protect("__Vscope_" + it->second.m_symName) @@ -591,8 +593,8 @@ void EmitCSyms::emitScopeHier(bool destroy) { for (auto it = m_vpiScopeHierarchy.cbegin(); it != m_vpiScopeHierarchy.cend(); ++it) { for (ScopeNameList::const_iterator lit = it->second.begin(); lit != it->second.end(); ++lit) { - string fromname = scopeSymString(it->first); - string toname = scopeSymString(*lit); + const string fromname = scopeSymString(it->first); + const string toname = scopeSymString(*lit); const auto from = vlstd::as_const(m_scopeNames).find(fromname); const auto to = vlstd::as_const(m_scopeNames).find(toname); UASSERT(from != m_scopeNames.end(), fromname + " not in m_scopeNames"); @@ -608,7 +610,7 @@ void EmitCSyms::emitScopeHier(bool destroy) { void EmitCSyms::emitSymImp() { UINFO(6, __FUNCTION__ << ": " << endl); - string filename = v3Global.opt.makeDir() + "/" + symClassName() + ".cpp"; + const string filename = v3Global.opt.makeDir() + "/" + symClassName() + ".cpp"; AstCFile* cfilep = newCFile(filename, true /*slow*/, true /*source*/); cfilep->support(true); @@ -623,9 +625,9 @@ void EmitCSyms::emitSymImp() { if (v3Global.opt.savable()) { for (int de = 0; de < 2; ++de) { - string classname = de ? "VerilatedDeserialize" : "VerilatedSerialize"; - string funcname = de ? "__Vdeserialize" : "__Vserialize"; - string op = de ? ">>" : "<<"; + const string classname = de ? "VerilatedDeserialize" : "VerilatedSerialize"; + const string funcname = de ? "__Vdeserialize" : "__Vserialize"; + const string op = de ? ">>" : "<<"; // NOLINTNEXTLINE(performance-inefficient-string-concatenation) puts("void " + symClassName() + "::" + protect(funcname) + "(" + classname + "& os) {\n"); @@ -724,7 +726,7 @@ void EmitCSyms::emitSymImp() { if (!modp->isTop()) { checkSplit(false); // first is used by AstCoverDecl's call to __vlCoverInsert - bool first = !modp->user1(); + const bool first = !modp->user1(); modp->user1(true); puts(protectIf(scopep->nameDotless(), scopep->protect()) + "." + protect("__Vconfigure") + "(this, " + (first ? "true" : "false") + ");\n"); @@ -878,7 +880,7 @@ void EmitCSyms::emitSymImp() { void EmitCSyms::emitDpiHdr() { UINFO(6, __FUNCTION__ << ": " << endl); - string filename = v3Global.opt.makeDir() + "/" + topClassName() + "__Dpi.h"; + const string filename = v3Global.opt.makeDir() + "/" + topClassName() + "__Dpi.h"; AstCFile* cfilep = newCFile(filename, false /*slow*/, false /*source*/); cfilep->support(true); V3OutCFile hf(filename); @@ -927,7 +929,7 @@ void EmitCSyms::emitDpiHdr() { void EmitCSyms::emitDpiImp() { UINFO(6, __FUNCTION__ << ": " << endl); - string filename = v3Global.opt.makeDir() + "/" + topClassName() + "__Dpi.cpp"; + const string filename = v3Global.opt.makeDir() + "/" + topClassName() + "__Dpi.cpp"; AstCFile* cfilep = newCFile(filename, false /*slow*/, true /*source*/); cfilep->support(true); V3OutCFile hf(filename); diff --git a/src/V3EmitMk.cpp b/src/V3EmitMk.cpp index dc8b932c7..dda111668 100644 --- a/src/V3EmitMk.cpp +++ b/src/V3EmitMk.cpp @@ -203,7 +203,7 @@ public: const V3StringSet& cppFiles = v3Global.opt.cppFiles(); for (const auto& cppfile : cppFiles) { of.puts("\t" + V3Os::filenameNonExt(cppfile) + " \\\n"); - string dir = V3Os::filenameDir(cppfile); + const string dir = V3Os::filenameDir(cppfile); dirs.insert(dir); } of.puts("\n"); @@ -228,7 +228,7 @@ public: of.puts("VPATH += $(VM_USER_DIR)\n"); of.puts("\n"); for (const string& cppfile : cppFiles) { - string basename = V3Os::filenameNonExt(cppfile); + const string basename = V3Os::filenameNonExt(cppfile); // NOLINTNEXTLINE(performance-inefficient-string-concatenation) of.puts(basename + ".o: " + cppfile + "\n"); of.puts("\t$(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_FAST) -c -o $@ $<\n"); diff --git a/src/V3EmitV.cpp b/src/V3EmitV.cpp index 648e7510c..aad3f2348 100644 --- a/src/V3EmitV.cpp +++ b/src/V3EmitV.cpp @@ -850,7 +850,8 @@ void V3EmitV::emitvFiles() { void V3EmitV::debugEmitV(const string& stage) { UINFO(2, __FUNCTION__ << ": " << endl); - string filename = v3Global.opt.makeDir() + "/" + v3Global.opt.prefix() + "__" + stage + ".v"; + const string filename + = v3Global.opt.makeDir() + "/" + v3Global.opt.prefix() + "__" + stage + ".v"; V3OutVFile of(filename); EmitVFileVisitor visitor(v3Global.rootp(), &of, true, true); } diff --git a/src/V3EmitXml.cpp b/src/V3EmitXml.cpp index ebe61b2e2..e231a3d43 100644 --- a/src/V3EmitXml.cpp +++ b/src/V3EmitXml.cpp @@ -129,9 +129,9 @@ class EmitXmlFileVisitor final : public AstNVisitor { outputChildrenEnd(nodep, ""); } virtual void visit(AstVar* nodep) override { - AstVarType typ = nodep->varType(); - string kw = nodep->verilogKwd(); - string vt = nodep->dtypep()->name(); + const AstVarType typ = nodep->varType(); + const string kw = nodep->verilogKwd(); + const string vt = nodep->dtypep()->name(); outputTag(nodep, ""); if (nodep->isIO()) { puts(" dir="); @@ -183,7 +183,7 @@ class EmitXmlFileVisitor final : public AstNVisitor { } virtual void visit(AstModportVarRef* nodep) override { // Dump direction for Modport references - string kw = nodep->direction().xmlKwd(); + const string kw = nodep->direction().xmlKwd(); outputTag(nodep, ""); puts(" direction="); putsQuoted(kw); @@ -376,9 +376,9 @@ public: void V3EmitXml::emitxml() { UINFO(2, __FUNCTION__ << ": " << endl); // All-in-one file - string filename = (v3Global.opt.xmlOutput().empty() - ? v3Global.opt.makeDir() + "/" + v3Global.opt.prefix() + ".xml" - : v3Global.opt.xmlOutput()); + const string filename = (v3Global.opt.xmlOutput().empty() + ? v3Global.opt.makeDir() + "/" + v3Global.opt.prefix() + ".xml" + : v3Global.opt.xmlOutput()); V3OutXmlFile of(filename); of.putsHeader(); of.puts("