From e8b8b33ff6f8aabef4e720261bc85d380585e431 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 13 Oct 2018 22:28:59 -0400 Subject: [PATCH] Internals: Cleanup find with chars for clang-tidy. No functional change. --- include/verilated_vcd_c.cpp | 2 +- src/V3Ast.cpp | 2 +- src/V3AstNodes.cpp | 6 +++--- src/V3Const.cpp | 2 +- src/V3Descope.cpp | 2 +- src/V3EmitCSyms.cpp | 4 ++-- src/V3File.cpp | 4 ++-- src/V3FileLine.cpp | 4 ++-- src/V3Inline.cpp | 2 +- src/V3LinkDot.cpp | 8 ++++---- src/V3Options.cpp | 14 +++++++------- src/V3Os.cpp | 6 +++--- src/V3PreLex.l | 4 ++-- src/V3PreProc.cpp | 12 ++++++------ src/V3StatsReport.cpp | 2 +- src/verilog.l | 2 +- 16 files changed, 38 insertions(+), 38 deletions(-) diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index a08f6da27..2160870e1 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -182,7 +182,7 @@ void VerilatedVcd::openNext(bool incFilename) { if (incFilename) { // Find _0000.{ext} in filename std::string name = m_filename; - size_t pos=name.rfind("."); + size_t pos = name.rfind('.'); if (pos>8 && 0==strncmp("_cat",name.c_str()+pos-8,4) && isdigit(name.c_str()[pos-4]) && isdigit(name.c_str()[pos-3]) diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index e28385051..ed39790a9 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -158,7 +158,7 @@ string AstNode::vcdName(const string& namein) { while ((pos=pretty.find("__DOT__")) != string::npos) { pretty.replace(pos, 7, " "); } - while ((pos=pretty.find(".")) != string::npos) { + while ((pos = pretty.find('.')) != string::npos) { pretty.replace(pos, 1, " "); } // Now convert escaped special characters, etc diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index de9124536..da74a01cc 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -586,7 +586,7 @@ void AstScope::cloneRelink() { string AstScope::nameDotless() const { string out = shortName(); string::size_type pos; - while ((pos=out.find(".")) != string::npos) { + while ((pos = out.find('.')) != string::npos) { out.replace(pos, 1, "__"); } return out; @@ -613,7 +613,7 @@ string AstScopeName::scopeNameFormatter(AstText* scopeTextp) const { if (out.substr(0,7) == "__DOT__") out.replace(0,7,""); if (out.substr(0,1) == ".") out.replace(0,1,""); string::size_type pos; - while ((pos=out.find(".")) != string::npos) { + while ((pos = out.find('.')) != string::npos) { out.replace(pos, 1, "__"); } while ((pos=out.find("__DOT__")) != string::npos) { @@ -1159,7 +1159,7 @@ void AstNodeText::dump(std::ostream& str) { this->AstNode::dump(str); string out = text(); string::size_type pos; - if ((pos = out.find("\n")) != string::npos) { + if ((pos = out.find('\n')) != string::npos) { out.erase(pos,out.length()-pos); out += "..."; } diff --git a/src/V3Const.cpp b/src/V3Const.cpp index a18f1eb94..6a048d403 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -2021,7 +2021,7 @@ private: } } if (!nodep->exprsp() - && nodep->name().find("%") == string::npos + && nodep->name().find('%') == string::npos && !nodep->hidden()) { // Just a simple constant string - the formatting is pointless replaceConstString(nodep, nodep->name()); VL_DANGLING(nodep); diff --git a/src/V3Descope.cpp b/src/V3Descope.cpp index 892810bf5..ebf7b6408 100644 --- a/src/V3Descope.cpp +++ b/src/V3Descope.cpp @@ -126,7 +126,7 @@ private: // Reference to scope of cell directly under this module, can just "cell->" string name = scopep->name(); string::size_type pos; - if ((pos = name.rfind(".")) != string::npos) { + if ((pos = name.rfind('.')) != string::npos) { name.erase(0,pos+1); } m_needThis = true; diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index 8bbea2670..049ed9bf4 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -144,7 +144,7 @@ class EmitCSyms : EmitCBaseVisitor { } if (out.substr(0,10) == "TOP__DOT__") out.replace(0,10,""); if (out.substr(0,4) == "TOP.") out.replace(0,4,""); - while ((pos=out.find(".")) != string::npos) { + while ((pos = out.find('.')) != string::npos) { out.replace(pos, 1, "__"); } while ((pos=out.find("__DOT__")) != string::npos) { @@ -409,7 +409,7 @@ void EmitCSyms::emitSymImp() { if (!modp->isTop()) { string arrow = scopep->name(); string::size_type pos; - while ((pos=arrow.find(".")) != string::npos) { + while ((pos = arrow.find('.')) != string::npos) { arrow.replace(pos, 1, "->"); } if (arrow.substr(0,5) == "TOP->") arrow.replace(0,5,"TOPp->"); diff --git a/src/V3File.cpp b/src/V3File.cpp index 191426806..e77bbd2c3 100644 --- a/src/V3File.cpp +++ b/src/V3File.cpp @@ -103,8 +103,8 @@ class V3FileDependImp { static string stripQuotes(const string& in) { string pretty = in; string::size_type pos; - while ((pos=pretty.find("\"")) != string::npos) pretty.replace(pos, 1, "_"); - while ((pos=pretty.find("\n")) != string::npos) pretty.replace(pos, 1, "_"); + while ((pos = pretty.find('\"')) != string::npos) pretty.replace(pos, 1, "_"); + while ((pos = pretty.find('\n')) != string::npos) pretty.replace(pos, 1, "_"); return pretty; } public: diff --git a/src/V3FileLine.cpp b/src/V3FileLine.cpp index 38cc42689..f690cbb18 100644 --- a/src/V3FileLine.cpp +++ b/src/V3FileLine.cpp @@ -154,7 +154,7 @@ FileLine* FileLine::copyOrSameFileLine() { const string FileLine::filebasename() const { string name = filename(); string::size_type pos; - if ((pos = name.rfind("/")) != string::npos) { + if ((pos = name.rfind('/')) != string::npos) { name.erase(0,pos+1); } return name; @@ -163,7 +163,7 @@ const string FileLine::filebasename() const { const string FileLine::filebasenameNoExt() const { string name = filebasename(); string::size_type pos; - if ((pos = name.find(".")) != string::npos) { + if ((pos = name.find('.')) != string::npos) { name = name.substr(0,pos); } return name; diff --git a/src/V3Inline.cpp b/src/V3Inline.cpp index 32fb3ff10..7de1565fa 100644 --- a/src/V3Inline.cpp +++ b/src/V3Inline.cpp @@ -409,7 +409,7 @@ private: break; } // If foo.bar, and foo is an interface, then need to search again for foo - string::size_type pos = tryname.rfind("."); + string::size_type pos = tryname.rfind('.'); if (pos == string::npos || pos==0) { break; } else { diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index a7fba0a12..040a3717b 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -476,7 +476,7 @@ public: while (leftname != "") { // foreach dotted part of xref name string::size_type pos; string ident; - if ((pos = leftname.find(".")) != string::npos) { + if ((pos = leftname.find('.')) != string::npos) { ident = leftname.substr(0,pos); leftname = leftname.substr(pos+1); } else { @@ -611,8 +611,8 @@ class LinkDotFindVisitor : public AstNVisitor { string v = literal.substr(1, literal.find('"', 1) - 1); V3Number n(V3Number::VerilogStringLiteral(), fl, v); return new AstConst(fl,n); - } else if ((literal.find(".") != string::npos) - || (literal.find("e") != string::npos)) { + } else if ((literal.find('.') != string::npos) + || (literal.find('e') != string::npos)) { // This may be a real double v = V3ParseImp::parseDouble(literal.c_str(), literal.length(), &success); if (success) { @@ -750,7 +750,7 @@ class LinkDotFindVisitor : public AstNVisitor { VSymEnt* aboveSymp = m_curSymp; string origname = AstNode::dedotName(nodep->name()); string::size_type pos; - if ((pos = origname.rfind(".")) != string::npos) { + if ((pos = origname.rfind('.')) != string::npos) { // Flattened, find what CellInline it should live under string scope = origname.substr(0,pos); string baddot; diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 76ca4ffff..6952efce1 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -116,14 +116,14 @@ void V3Options::addDefine(const string& defline, bool allowPlus) { while (left != "") { string def = left; string::size_type pos; - if (allowPlus && ((pos=left.find("+")) != string::npos)) { + if (allowPlus && ((pos = left.find('+')) != string::npos)) { left = left.substr(pos+1); def.erase(pos); } else { left = ""; } string value; - if ((pos=def.find("=")) != string::npos) { + if ((pos = def.find('=')) != string::npos) { value = def.substr(pos+1); def.erase(pos); } @@ -138,14 +138,14 @@ void V3Options::addParameter(const string& paramline, bool allowPlus) { while (left != "") { string param = left; string::size_type pos; - if (allowPlus && ((pos=left.find("+")) != string::npos)) { + if (allowPlus && ((pos = left.find('+')) != string::npos)) { left = left.substr(pos+1); param.erase(pos); } else { left = ""; } string value; - if ((pos=param.find("=")) != string::npos) { + if ((pos = param.find('=')) != string::npos) { value = param.substr(pos+1); param.erase(pos); } @@ -396,7 +396,7 @@ void V3Options::filePathLookedMsg(FileLine* fl, const string& modname) { V3LangCode V3Options::fileLanguage(const string &filename) { string ext = V3Os::filenameNonDir(filename); string::size_type pos; - if ((pos = ext.rfind(".")) != string::npos) { + if ((pos = ext.rfind('.')) != string::npos) { ext.erase(0, pos + 1); std::map::iterator it = m_impp->m_langExts.find(ext); if (it != m_impp->m_langExts.end()) { @@ -620,7 +620,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char else if ( !strncmp (sw, "+libext+", 8)) { string exts = string(sw+strlen("+libext+")); string::size_type pos; - while ((pos=exts.find("+")) != string::npos) { + while ((pos = exts.find('+')) != string::npos) { addLibExtV(exts.substr(0,pos)); exts = exts.substr(pos+1); } @@ -1139,7 +1139,7 @@ void V3Options::parseOptsFile(FileLine* fl, const string& filename, bool rel) { // Split into argument list and process // Note we don't respect quotes. It seems most simulators dont. // Woez those that expect it; we'll at least complain. - if (whole_file.find("\"") != string::npos) { + if (whole_file.find('\"') != string::npos) { fl->v3error("Double quotes in -f files cause unspecified behavior."); } diff --git a/src/V3Os.cpp b/src/V3Os.cpp index 781bc6067..46f3ade89 100644 --- a/src/V3Os.cpp +++ b/src/V3Os.cpp @@ -79,7 +79,7 @@ string V3Os::filenameFromDirBase(const string& dir, const string& basename) { string V3Os::filenameDir(const string& filename) { string::size_type pos; - if ((pos = filename.rfind("/")) != string::npos) { + if ((pos = filename.rfind('/')) != string::npos) { return filename.substr(0,pos); } else { return "."; @@ -88,7 +88,7 @@ string V3Os::filenameDir(const string& filename) { string V3Os::filenameNonDir(const string& filename) { string::size_type pos; - if ((pos = filename.rfind("/")) != string::npos) { + if ((pos = filename.rfind('/')) != string::npos) { return filename.substr(pos+1); } else { return filename; @@ -98,7 +98,7 @@ string V3Os::filenameNonDir(const string& filename) { string V3Os::filenameNonExt(const string& filename) { string base = filenameNonDir(filename); string::size_type pos; - if ((pos = base.find(".")) != string::npos) { + if ((pos = base.find('.')) != string::npos) { base.erase(pos); } return base; diff --git a/src/V3PreLex.l b/src/V3PreLex.l index 25e2e4b16..908921c49 100644 --- a/src/V3PreLex.l +++ b/src/V3PreLex.l @@ -532,8 +532,8 @@ void V3PreLex::dumpStack() { string V3PreLex::cleanDbgStrg(const string& in) { string out = in; string::size_type pos; - while ((pos=out.find("\n")) != string::npos) { out.replace(pos, 1, "\\n"); } - while ((pos=out.find("\r")) != string::npos) { out.replace(pos, 1, "\\r"); } + while ((pos = out.find('\n')) != string::npos) { out.replace(pos, 1, "\\n"); } + while ((pos = out.find('\r')) != string::npos) { out.replace(pos, 1, "\\r"); } return out; } diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index b39c27c18..87c47d918 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -421,11 +421,11 @@ void V3PreProcImp::comment(const string& text) { string cmd (cp, ep-cp); string::size_type pos; - while ((pos=cmd.find("\"")) != string::npos) + while ((pos = cmd.find('\"')) != string::npos) cmd.replace(pos, 1, " "); - while ((pos=cmd.find("\t")) != string::npos) + while ((pos = cmd.find('\t')) != string::npos) cmd.replace(pos, 1, " "); - while ((pos=cmd.find(" ")) != string::npos) + while ((pos = cmd.find(" ")) != string::npos) cmd.replace(pos, 2, " "); if (synth) { @@ -853,8 +853,8 @@ void V3PreProcImp::debugToken(int tok, const char* cmtp) { if (debug()>=5) { string buf = string(yyourtext(), yyourleng()); string::size_type pos; - while ((pos=buf.find("\n")) != string::npos) { buf.replace(pos, 1, "\\n"); } - while ((pos=buf.find("\r")) != string::npos) { buf.replace(pos, 1, "\\r"); } + while ((pos = buf.find('\n')) != string::npos) { buf.replace(pos, 1, "\\n"); } + while ((pos = buf.find('\r')) != string::npos) { buf.replace(pos, 1, "\\r"); } fprintf(stderr, "%d: %s %s %s(%d) dr%d: <%d>%-10s: %s\n", m_lexp->m_tokFilelinep->lineno(), cmtp, m_off?"of":"on", procStateName(state()), (int)m_states.size(), (int)m_defRefs.size(), @@ -1214,7 +1214,7 @@ int V3PreProcImp::getStateToken() { // Convert any newlines to spaces, so we don't get a multiline "..." without \ escapes // The spec is silent about this either way; simulators vary string::size_type pos; - while ((pos=out.find("\n")) != string::npos) { + while ((pos=out.find('\n')) != string::npos) { out.replace(pos, 1, " "); } unputString(string("\"")+out+"\""); diff --git a/src/V3StatsReport.cpp b/src/V3StatsReport.cpp index ee8d7c8b8..3c3791d6a 100644 --- a/src/V3StatsReport.cpp +++ b/src/V3StatsReport.cpp @@ -162,7 +162,7 @@ class StatsReport { { string commaName = lastName; string::size_type pos; - if ((pos=commaName.find(",")) != string::npos) { + if ((pos = commaName.find(',')) != string::npos) { commaName.erase(pos); } if (lastCommaName != commaName) { diff --git a/src/verilog.l b/src/verilog.l index 62e5497ce..dc322bc7b 100644 --- a/src/verilog.l +++ b/src/verilog.l @@ -65,7 +65,7 @@ void V3ParseImp::verilatorCmtLint(const char* textp, bool warnOff) { while (*sp && !isspace(*sp)) sp++; while (*sp && isspace(*sp)) sp++; string msg = sp; string::size_type pos; - if ((pos=msg.find("*")) != string::npos) { msg.erase(pos); } + if ((pos = msg.find('*')) != string::npos) { msg.erase(pos); } if (!(PARSEP->fileline()->warnOff(msg, warnOff))) { if (!PARSEP->optFuture(msg)) { yyerrorf("Unknown verilator lint message code: %s, in %s",msg.c_str(), textp);