Internals: Upgrade some C strings to C++

This commit is contained in:
Wilson Snyder 2015-11-10 18:59:48 -05:00
parent 9208c87f91
commit 0cb5d5cc5a
7 changed files with 16 additions and 20 deletions

View File

@ -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]=='_') {

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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; }

View File

@ -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') {

View File

@ -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";
}

View File

@ -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');