From 0cb5d5cc5a929bfc032becc8ae0f9fd19c8394d8 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 10 Nov 2015 18:59:48 -0500 Subject: [PATCH] Internals: Upgrade some C strings to C++ --- src/V3Ast.cpp | 5 ++--- src/V3EmitC.cpp | 2 +- src/V3File.cpp | 12 ++++++------ src/V3File.h | 8 +++----- src/V3Number.cpp | 3 +-- src/VlcTop.cpp | 4 ++-- src/verilog.y | 2 +- 7 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 3a1f90cb7..e1115b620 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -94,10 +94,9 @@ void AstNode::init() { string AstNode::encodeName(const string& namein) { // Encode signal name raw from parser, then not called again on same signal - const char* start = namein.c_str(); string out; - for (const char* pos = start; *pos; pos++) { - if ((pos==start) ? isalpha(pos[0]) // digits can't lead identifiers + for (string::const_iterator pos = namein.begin(); pos!=namein.end(); ++pos) { + if ((pos==namein.begin()) ? isalpha(pos[0]) // digits can't lead identifiers : isalnum(pos[0])) { out += pos[0]; } else if (pos[0]=='_') { diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index 465c32c29..522bfa502 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -1789,7 +1789,7 @@ void EmitCStmts::emitVarList(AstNode* firstp, EisWhich which, const string& pref } } } - ofp()->putAlign(isstatic, 4, 0, prefixIfImp.c_str()); + ofp()->putAlign(isstatic, 4, 0, prefixIfImp); } } diff --git a/src/V3File.cpp b/src/V3File.cpp index dfd2dfb34..b9ab310ac 100644 --- a/src/V3File.cpp +++ b/src/V3File.cpp @@ -750,19 +750,19 @@ void V3OutFormatter::putBreak () { } } -void V3OutFormatter::putsQuoted(const char* strg) { +void V3OutFormatter::putsQuoted(const string& strg) { // Quote \ and " for use inside C programs // Don't use to quote a filename for #include - #include doesn't \ escape. putcNoTracking('"'); string quoted = V3Number::quoteNameControls(strg); - for (const char* cp=quoted.c_str(); *cp; cp++) { - putcNoTracking (*cp); + for (string::const_iterator cp=quoted.begin(); cp!=quoted.end(); ++cp) { + putcNoTracking (*cp); } putcNoTracking('"'); } -void V3OutFormatter::putsNoTracking (const char *strg) { +void V3OutFormatter::putsNoTracking (const string& strg) { // Don't track {}'s, probably because it's a $display format string - for (const char* cp=strg; *cp; cp++) { + for (string::const_iterator cp=strg.begin(); cp!=strg.end(); ++cp) { putcNoTracking (*cp); } } @@ -791,7 +791,7 @@ void V3OutFormatter::putcNoTracking (char chr) { putcOutput (chr); } -void V3OutFormatter::putAlign (bool/*AlignClass*/ isStatic, int align, int size, const char* prefix) { +void V3OutFormatter::putAlign (bool/*AlignClass*/ isStatic, int align, int size, const string& prefix) { if (size==0) size=align; int alignSize = size; if (alignSize>8) alignSize=8; int& alignr = isStatic ? m_declSAlign : m_declNSAlign; diff --git a/src/V3File.h b/src/V3File.h index bbb6b6982..5b3789300 100644 --- a/src/V3File.h +++ b/src/V3File.h @@ -140,13 +140,11 @@ public: void printf(const char* fmt...) VL_ATTR_PRINTF(2); void puts(const char* strg); void puts(const string& strg) { puts(strg.c_str()); } - void putsNoTracking(const char* strg); - void putsNoTracking(const string& strg) { putsNoTracking(strg.c_str()); } - void putsQuoted(const char* strg); - void putsQuoted(const string& strg) { putsQuoted(strg.c_str()); } + void putsNoTracking(const string& strg); + void putsQuoted(const string& strg); void putBreak(); // Print linebreak if line is too wide void putBreakExpr(); // Print linebreak in expression if line is too wide - void putAlign(bool isstatic/*AlignClass*/, int align, int size=0/*=align*/, const char* prefix=""); // Declare a variable, with natural alignment + void putAlign(bool isstatic/*AlignClass*/, int align, int size=0/*=align*/, const string& prefix=""); // Declare a variable, with natural alignment void putbs(const char* strg) { putBreakExpr(); puts(strg); } void putbs(const string& strg) { putBreakExpr(); puts(strg); } bool exceededWidth() const { return m_column > WIDTH; } diff --git a/src/V3Number.cpp b/src/V3Number.cpp index 169c93d5a..73c438365 100644 --- a/src/V3Number.cpp +++ b/src/V3Number.cpp @@ -409,9 +409,8 @@ string V3Number::ascii(bool prefixed, bool cleanVerilog) const { string V3Number::quoteNameControls(const string& namein) { // Encode control chars into C style escapes // Reverse is V3Parse::deQuote - const char* start = namein.c_str(); string out; - for (const char* pos = start; *pos; pos++) { + for (string::const_iterator pos=namein.begin(); pos!=namein.end(); ++pos) { if (pos[0]=='\\' || pos[0]=='"') { out += string("\\")+pos[0]; } else if (pos[0]=='\n') { diff --git a/src/VlcTop.cpp b/src/VlcTop.cpp index 135ec9200..a96b3a828 100644 --- a/src/VlcTop.cpp +++ b/src/VlcTop.cpp @@ -239,8 +239,8 @@ void VlcTop::annotateOutputFiles(const string& dirname) { first = false; // Multiple columns on same line; print line just once string indent = ""; - for (const char* cp=line.c_str(); isspace(*cp); ++cp) { - indent += *cp; + for (string::const_iterator pos=line.begin(); pos!=line.end() && isspace(*pos); ++pos) { + indent += *pos; } line = indent + "verilator_coverage: (next point on previous line)\n"; } diff --git a/src/verilog.y b/src/verilog.y index 2ac1ad217..a9aa6c9b3 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -3786,7 +3786,7 @@ string V3ParseGrammar::deQuote(FileLine* fileline, string text) { string newtext; unsigned char octal_val = 0; int octal_digits = 0; - for (const char* cp=text.c_str(); *cp; ++cp) { + for (string::const_iterator cp=text.begin(); cp!=text.end(); ++cp) { if (quoted) { if (isdigit(*cp)) { octal_val = octal_val*8 + (*cp-'0');