Internals: Cleanup find with chars for clang-tidy. No functional change.

This commit is contained in:
Wilson Snyder 2018-10-13 22:28:59 -04:00
parent e4d638c73d
commit e8b8b33ff6
16 changed files with 38 additions and 38 deletions

View File

@ -182,7 +182,7 @@ void VerilatedVcd::openNext(bool incFilename) {
if (incFilename) { if (incFilename) {
// Find _0000.{ext} in filename // Find _0000.{ext} in filename
std::string name = m_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) if (pos>8 && 0==strncmp("_cat",name.c_str()+pos-8,4)
&& isdigit(name.c_str()[pos-4]) && isdigit(name.c_str()[pos-4])
&& isdigit(name.c_str()[pos-3]) && isdigit(name.c_str()[pos-3])

View File

@ -158,7 +158,7 @@ string AstNode::vcdName(const string& namein) {
while ((pos=pretty.find("__DOT__")) != string::npos) { while ((pos=pretty.find("__DOT__")) != string::npos) {
pretty.replace(pos, 7, " "); pretty.replace(pos, 7, " ");
} }
while ((pos=pretty.find(".")) != string::npos) { while ((pos = pretty.find('.')) != string::npos) {
pretty.replace(pos, 1, " "); pretty.replace(pos, 1, " ");
} }
// Now convert escaped special characters, etc // Now convert escaped special characters, etc

View File

@ -586,7 +586,7 @@ void AstScope::cloneRelink() {
string AstScope::nameDotless() const { string AstScope::nameDotless() const {
string out = shortName(); string out = shortName();
string::size_type pos; string::size_type pos;
while ((pos=out.find(".")) != string::npos) { while ((pos = out.find('.')) != string::npos) {
out.replace(pos, 1, "__"); out.replace(pos, 1, "__");
} }
return out; 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,7) == "__DOT__") out.replace(0,7,"");
if (out.substr(0,1) == ".") out.replace(0,1,""); if (out.substr(0,1) == ".") out.replace(0,1,"");
string::size_type pos; string::size_type pos;
while ((pos=out.find(".")) != string::npos) { while ((pos = out.find('.')) != string::npos) {
out.replace(pos, 1, "__"); out.replace(pos, 1, "__");
} }
while ((pos=out.find("__DOT__")) != string::npos) { while ((pos=out.find("__DOT__")) != string::npos) {
@ -1159,7 +1159,7 @@ void AstNodeText::dump(std::ostream& str) {
this->AstNode::dump(str); this->AstNode::dump(str);
string out = text(); string out = text();
string::size_type pos; 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.erase(pos,out.length()-pos);
out += "..."; out += "...";
} }

View File

@ -2021,7 +2021,7 @@ private:
} }
} }
if (!nodep->exprsp() if (!nodep->exprsp()
&& nodep->name().find("%") == string::npos && nodep->name().find('%') == string::npos
&& !nodep->hidden()) { && !nodep->hidden()) {
// Just a simple constant string - the formatting is pointless // Just a simple constant string - the formatting is pointless
replaceConstString(nodep, nodep->name()); VL_DANGLING(nodep); replaceConstString(nodep, nodep->name()); VL_DANGLING(nodep);

View File

@ -126,7 +126,7 @@ private:
// Reference to scope of cell directly under this module, can just "cell->" // Reference to scope of cell directly under this module, can just "cell->"
string name = scopep->name(); string name = scopep->name();
string::size_type pos; string::size_type pos;
if ((pos = name.rfind(".")) != string::npos) { if ((pos = name.rfind('.')) != string::npos) {
name.erase(0,pos+1); name.erase(0,pos+1);
} }
m_needThis = true; m_needThis = true;

View File

@ -144,7 +144,7 @@ class EmitCSyms : EmitCBaseVisitor {
} }
if (out.substr(0,10) == "TOP__DOT__") out.replace(0,10,""); if (out.substr(0,10) == "TOP__DOT__") out.replace(0,10,"");
if (out.substr(0,4) == "TOP.") out.replace(0,4,""); 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, "__"); out.replace(pos, 1, "__");
} }
while ((pos=out.find("__DOT__")) != string::npos) { while ((pos=out.find("__DOT__")) != string::npos) {
@ -409,7 +409,7 @@ void EmitCSyms::emitSymImp() {
if (!modp->isTop()) { if (!modp->isTop()) {
string arrow = scopep->name(); string arrow = scopep->name();
string::size_type pos; string::size_type pos;
while ((pos=arrow.find(".")) != string::npos) { while ((pos = arrow.find('.')) != string::npos) {
arrow.replace(pos, 1, "->"); arrow.replace(pos, 1, "->");
} }
if (arrow.substr(0,5) == "TOP->") arrow.replace(0,5,"TOPp->"); if (arrow.substr(0,5) == "TOP->") arrow.replace(0,5,"TOPp->");

View File

@ -103,8 +103,8 @@ class V3FileDependImp {
static string stripQuotes(const string& in) { static string stripQuotes(const string& in) {
string pretty = in; string pretty = in;
string::size_type pos; string::size_type pos;
while ((pos=pretty.find("\"")) != 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, "_"); while ((pos = pretty.find('\n')) != string::npos) pretty.replace(pos, 1, "_");
return pretty; return pretty;
} }
public: public:

View File

@ -154,7 +154,7 @@ FileLine* FileLine::copyOrSameFileLine() {
const string FileLine::filebasename() const { const string FileLine::filebasename() const {
string name = filename(); string name = filename();
string::size_type pos; string::size_type pos;
if ((pos = name.rfind("/")) != string::npos) { if ((pos = name.rfind('/')) != string::npos) {
name.erase(0,pos+1); name.erase(0,pos+1);
} }
return name; return name;
@ -163,7 +163,7 @@ const string FileLine::filebasename() const {
const string FileLine::filebasenameNoExt() const { const string FileLine::filebasenameNoExt() const {
string name = filebasename(); string name = filebasename();
string::size_type pos; string::size_type pos;
if ((pos = name.find(".")) != string::npos) { if ((pos = name.find('.')) != string::npos) {
name = name.substr(0,pos); name = name.substr(0,pos);
} }
return name; return name;

View File

@ -409,7 +409,7 @@ private:
break; break;
} }
// If foo.bar, and foo is an interface, then need to search again for foo // 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) { if (pos == string::npos || pos==0) {
break; break;
} else { } else {

View File

@ -476,7 +476,7 @@ public:
while (leftname != "") { // foreach dotted part of xref name while (leftname != "") { // foreach dotted part of xref name
string::size_type pos; string::size_type pos;
string ident; string ident;
if ((pos = leftname.find(".")) != string::npos) { if ((pos = leftname.find('.')) != string::npos) {
ident = leftname.substr(0,pos); ident = leftname.substr(0,pos);
leftname = leftname.substr(pos+1); leftname = leftname.substr(pos+1);
} else { } else {
@ -611,8 +611,8 @@ class LinkDotFindVisitor : public AstNVisitor {
string v = literal.substr(1, literal.find('"', 1) - 1); string v = literal.substr(1, literal.find('"', 1) - 1);
V3Number n(V3Number::VerilogStringLiteral(), fl, v); V3Number n(V3Number::VerilogStringLiteral(), fl, v);
return new AstConst(fl,n); return new AstConst(fl,n);
} else if ((literal.find(".") != string::npos) } else if ((literal.find('.') != string::npos)
|| (literal.find("e") != string::npos)) { || (literal.find('e') != string::npos)) {
// This may be a real // This may be a real
double v = V3ParseImp::parseDouble(literal.c_str(), literal.length(), &success); double v = V3ParseImp::parseDouble(literal.c_str(), literal.length(), &success);
if (success) { if (success) {
@ -750,7 +750,7 @@ class LinkDotFindVisitor : public AstNVisitor {
VSymEnt* aboveSymp = m_curSymp; VSymEnt* aboveSymp = m_curSymp;
string origname = AstNode::dedotName(nodep->name()); string origname = AstNode::dedotName(nodep->name());
string::size_type pos; string::size_type pos;
if ((pos = origname.rfind(".")) != string::npos) { if ((pos = origname.rfind('.')) != string::npos) {
// Flattened, find what CellInline it should live under // Flattened, find what CellInline it should live under
string scope = origname.substr(0,pos); string scope = origname.substr(0,pos);
string baddot; string baddot;

View File

@ -116,14 +116,14 @@ void V3Options::addDefine(const string& defline, bool allowPlus) {
while (left != "") { while (left != "") {
string def = left; string def = left;
string::size_type pos; string::size_type pos;
if (allowPlus && ((pos=left.find("+")) != string::npos)) { if (allowPlus && ((pos = left.find('+')) != string::npos)) {
left = left.substr(pos+1); left = left.substr(pos+1);
def.erase(pos); def.erase(pos);
} else { } else {
left = ""; left = "";
} }
string value; string value;
if ((pos=def.find("=")) != string::npos) { if ((pos = def.find('=')) != string::npos) {
value = def.substr(pos+1); value = def.substr(pos+1);
def.erase(pos); def.erase(pos);
} }
@ -138,14 +138,14 @@ void V3Options::addParameter(const string& paramline, bool allowPlus) {
while (left != "") { while (left != "") {
string param = left; string param = left;
string::size_type pos; string::size_type pos;
if (allowPlus && ((pos=left.find("+")) != string::npos)) { if (allowPlus && ((pos = left.find('+')) != string::npos)) {
left = left.substr(pos+1); left = left.substr(pos+1);
param.erase(pos); param.erase(pos);
} else { } else {
left = ""; left = "";
} }
string value; string value;
if ((pos=param.find("=")) != string::npos) { if ((pos = param.find('=')) != string::npos) {
value = param.substr(pos+1); value = param.substr(pos+1);
param.erase(pos); param.erase(pos);
} }
@ -396,7 +396,7 @@ void V3Options::filePathLookedMsg(FileLine* fl, const string& modname) {
V3LangCode V3Options::fileLanguage(const string &filename) { V3LangCode V3Options::fileLanguage(const string &filename) {
string ext = V3Os::filenameNonDir(filename); string ext = V3Os::filenameNonDir(filename);
string::size_type pos; string::size_type pos;
if ((pos = ext.rfind(".")) != string::npos) { if ((pos = ext.rfind('.')) != string::npos) {
ext.erase(0, pos + 1); ext.erase(0, pos + 1);
std::map<string,V3LangCode>::iterator it = m_impp->m_langExts.find(ext); std::map<string,V3LangCode>::iterator it = m_impp->m_langExts.find(ext);
if (it != m_impp->m_langExts.end()) { 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)) { else if ( !strncmp (sw, "+libext+", 8)) {
string exts = string(sw+strlen("+libext+")); string exts = string(sw+strlen("+libext+"));
string::size_type pos; string::size_type pos;
while ((pos=exts.find("+")) != string::npos) { while ((pos = exts.find('+')) != string::npos) {
addLibExtV(exts.substr(0,pos)); addLibExtV(exts.substr(0,pos));
exts = exts.substr(pos+1); 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 // Split into argument list and process
// Note we don't respect quotes. It seems most simulators dont. // Note we don't respect quotes. It seems most simulators dont.
// Woez those that expect it; we'll at least complain. // 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."); fl->v3error("Double quotes in -f files cause unspecified behavior.");
} }

View File

@ -79,7 +79,7 @@ string V3Os::filenameFromDirBase(const string& dir, const string& basename) {
string V3Os::filenameDir(const string& filename) { string V3Os::filenameDir(const string& filename) {
string::size_type pos; string::size_type pos;
if ((pos = filename.rfind("/")) != string::npos) { if ((pos = filename.rfind('/')) != string::npos) {
return filename.substr(0,pos); return filename.substr(0,pos);
} else { } else {
return "."; return ".";
@ -88,7 +88,7 @@ string V3Os::filenameDir(const string& filename) {
string V3Os::filenameNonDir(const string& filename) { string V3Os::filenameNonDir(const string& filename) {
string::size_type pos; string::size_type pos;
if ((pos = filename.rfind("/")) != string::npos) { if ((pos = filename.rfind('/')) != string::npos) {
return filename.substr(pos+1); return filename.substr(pos+1);
} else { } else {
return filename; return filename;
@ -98,7 +98,7 @@ string V3Os::filenameNonDir(const string& filename) {
string V3Os::filenameNonExt(const string& filename) { string V3Os::filenameNonExt(const string& filename) {
string base = filenameNonDir(filename); string base = filenameNonDir(filename);
string::size_type pos; string::size_type pos;
if ((pos = base.find(".")) != string::npos) { if ((pos = base.find('.')) != string::npos) {
base.erase(pos); base.erase(pos);
} }
return base; return base;

View File

@ -532,8 +532,8 @@ void V3PreLex::dumpStack() {
string V3PreLex::cleanDbgStrg(const string& in) { string V3PreLex::cleanDbgStrg(const string& in) {
string out = in; string out = in;
string::size_type pos; string::size_type pos;
while ((pos=out.find("\n")) != string::npos) { out.replace(pos, 1, "\\n"); } 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('\r')) != string::npos) { out.replace(pos, 1, "\\r"); }
return out; return out;
} }

View File

@ -421,9 +421,9 @@ void V3PreProcImp::comment(const string& text) {
string cmd (cp, ep-cp); string cmd (cp, ep-cp);
string::size_type pos; string::size_type pos;
while ((pos=cmd.find("\"")) != string::npos) while ((pos = cmd.find('\"')) != string::npos)
cmd.replace(pos, 1, " "); cmd.replace(pos, 1, " ");
while ((pos=cmd.find("\t")) != string::npos) while ((pos = cmd.find('\t')) != string::npos)
cmd.replace(pos, 1, " "); cmd.replace(pos, 1, " ");
while ((pos = cmd.find(" ")) != string::npos) while ((pos = cmd.find(" ")) != string::npos)
cmd.replace(pos, 2, " "); cmd.replace(pos, 2, " ");
@ -853,8 +853,8 @@ void V3PreProcImp::debugToken(int tok, const char* cmtp) {
if (debug()>=5) { if (debug()>=5) {
string buf = string(yyourtext(), yyourleng()); string buf = string(yyourtext(), yyourleng());
string::size_type pos; string::size_type pos;
while ((pos=buf.find("\n")) != string::npos) { buf.replace(pos, 1, "\\n"); } 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('\r')) != string::npos) { buf.replace(pos, 1, "\\r"); }
fprintf(stderr, "%d: %s %s %s(%d) dr%d: <%d>%-10s: %s\n", fprintf(stderr, "%d: %s %s %s(%d) dr%d: <%d>%-10s: %s\n",
m_lexp->m_tokFilelinep->lineno(), cmtp, m_off?"of":"on", m_lexp->m_tokFilelinep->lineno(), cmtp, m_off?"of":"on",
procStateName(state()), (int)m_states.size(), (int)m_defRefs.size(), 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 // Convert any newlines to spaces, so we don't get a multiline "..." without \ escapes
// The spec is silent about this either way; simulators vary // The spec is silent about this either way; simulators vary
string::size_type pos; string::size_type pos;
while ((pos=out.find("\n")) != string::npos) { while ((pos=out.find('\n')) != string::npos) {
out.replace(pos, 1, " "); out.replace(pos, 1, " ");
} }
unputString(string("\"")+out+"\""); unputString(string("\"")+out+"\"");

View File

@ -162,7 +162,7 @@ class StatsReport {
{ {
string commaName = lastName; string commaName = lastName;
string::size_type pos; string::size_type pos;
if ((pos=commaName.find(",")) != string::npos) { if ((pos = commaName.find(',')) != string::npos) {
commaName.erase(pos); commaName.erase(pos);
} }
if (lastCommaName != commaName) { if (lastCommaName != commaName) {

View File

@ -65,7 +65,7 @@ void V3ParseImp::verilatorCmtLint(const char* textp, bool warnOff) {
while (*sp && !isspace(*sp)) sp++; while (*sp && isspace(*sp)) sp++; while (*sp && !isspace(*sp)) sp++; while (*sp && isspace(*sp)) sp++;
string msg = sp; string msg = sp;
string::size_type pos; 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->fileline()->warnOff(msg, warnOff))) {
if (!PARSEP->optFuture(msg)) { if (!PARSEP->optFuture(msg)) {
yyerrorf("Unknown verilator lint message code: %s, in %s",msg.c_str(), textp); yyerrorf("Unknown verilator lint message code: %s, in %s",msg.c_str(), textp);