mirror of
https://github.com/verilator/verilator.git
synced 2025-01-01 12:17:35 +00:00
Internals: Relocate quoteNameControls, part of bug1444.
Signed-off-by: Wilson Snyder <wsnyder@wsnyder.org>
This commit is contained in:
parent
8d6bea8975
commit
3411279294
@ -846,7 +846,7 @@ void AstNode::dump(std::ostream& str) {
|
||||
}
|
||||
if (name()!="") {
|
||||
if (VN_IS(this, Const)) str<<" "<<name(); // Already quoted
|
||||
else str<<" "<<V3Number::quoteNameControls(name());
|
||||
else str<<" "<<V3OutFormatter::quoteNameControls(name());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ class EmitVBaseVisitor : public EmitCBaseVisitor {
|
||||
// Don't use to quote a filename for #include - #include doesn't \ escape.
|
||||
// Duplicate in V3File - here so we can print to string
|
||||
putsNoTracking("\"");
|
||||
putsNoTracking(V3Number::quoteNameControls(str));
|
||||
putsNoTracking(V3OutFormatter::quoteNameControls(str));
|
||||
putsNoTracking("\"");
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ class EmitXmlFileVisitor : public AstNVisitor {
|
||||
// Don't use to quote a filename for #include - #include doesn't \ escape.
|
||||
// Duplicate in V3File - here so we can print to string
|
||||
putsNoTracking("\"");
|
||||
putsNoTracking(V3Number::quoteNameControls(str));
|
||||
putsNoTracking(V3OutFormatter::quoteNameControls(str));
|
||||
putsNoTracking("\"");
|
||||
}
|
||||
|
||||
|
@ -806,7 +806,7 @@ 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);
|
||||
string quoted = quoteNameControls(strg);
|
||||
for (string::const_iterator cp=quoted.begin(); cp!=quoted.end(); ++cp) {
|
||||
putcNoTracking(*cp);
|
||||
}
|
||||
@ -843,6 +843,31 @@ void V3OutFormatter::putcNoTracking(char chr) {
|
||||
putcOutput(chr);
|
||||
}
|
||||
|
||||
string V3OutFormatter::quoteNameControls(const string& namein, V3OutFormatter::Language) {
|
||||
// Encode control chars into C style escapes
|
||||
// Reverse is V3Parse::deQuote
|
||||
string out;
|
||||
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') {
|
||||
out += "\\n";
|
||||
} else if (pos[0]=='\r') {
|
||||
out += "\\r";
|
||||
} else if (pos[0]=='\t') {
|
||||
out += "\\t";
|
||||
} else if (isprint(pos[0])) {
|
||||
out += pos[0];
|
||||
} else {
|
||||
// This will also cover \a etc
|
||||
// Can't use %03o as messes up when signed
|
||||
char octal[10]; sprintf(octal, "\\%o%o%o", (pos[0]>>6)&3, (pos[0]>>3)&7, pos[0]&7);
|
||||
out += octal;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Simple wrappers
|
||||
|
||||
|
@ -161,6 +161,8 @@ public:
|
||||
void blockDec() { if (!m_parenVec.empty()) m_parenVec.pop(); }
|
||||
// STATIC METHODS
|
||||
static const string indentSpaces(int num);
|
||||
// Add escaped characters to strings
|
||||
static string quoteNameControls(const string& namein, Language lang = LA_C);
|
||||
|
||||
// CALLBACKS - MUST OVERRIDE
|
||||
virtual void putcOutput(char chr) = 0;
|
||||
|
@ -429,31 +429,6 @@ string V3Number::ascii(bool prefixed, bool cleanVerilog) const {
|
||||
return out.str();
|
||||
}
|
||||
|
||||
string V3Number::quoteNameControls(const string& namein) {
|
||||
// Encode control chars into C style escapes
|
||||
// Reverse is V3Parse::deQuote
|
||||
string out;
|
||||
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') {
|
||||
out += "\\n";
|
||||
} else if (pos[0]=='\r') {
|
||||
out += "\\r";
|
||||
} else if (pos[0]=='\t') {
|
||||
out += "\\t";
|
||||
} else if (isprint(pos[0])) {
|
||||
out += pos[0];
|
||||
} else {
|
||||
// This will also cover \a etc
|
||||
// Can't use %03o as messes up when signed
|
||||
char octal[10]; sprintf(octal,"\\%o%o%o",(pos[0]>>6)&3, (pos[0]>>3)&7, pos[0]&7);
|
||||
out += octal;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool V3Number::displayedFmtLegal(char format) {
|
||||
// Is this a valid format letter?
|
||||
switch (tolower(format)) {
|
||||
|
@ -195,7 +195,6 @@ public:
|
||||
|
||||
// ACCESSORS
|
||||
string ascii(bool prefixed=true, bool cleanVerilog=false) const;
|
||||
static string quoteNameControls(const string& namein); // Add backslash quotes to strings
|
||||
string displayed(AstNode* nodep, const string& vformat) const;
|
||||
static bool displayedFmtLegal(char format); // Is this a valid format letter?
|
||||
int width() const { return m_width; }
|
||||
|
@ -4097,7 +4097,7 @@ AstVar* V3ParseGrammar::createVariable(FileLine* fileline, string name, AstNodeR
|
||||
|
||||
string V3ParseGrammar::deQuote(FileLine* fileline, string text) {
|
||||
// Fix up the quoted strings the user put in, for example "\"" becomes "
|
||||
// Reverse is V3Number::quoteNameControls(...)
|
||||
// Reverse is V3OutFormatter::quoteNameControls(...)
|
||||
bool quoted = false;
|
||||
string newtext;
|
||||
unsigned char octal_val = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user