Project

General

Profile

[logo] 
 
Home
News
Activity
About/Contact
Major Tools
  Dinotrace
  Verilator
  Verilog-mode
  Verilog-Perl
Other Tools
  BugVise
  CovVise
  Force-Gate-Sim
  Gspice
  IPC::Locker
  Rsvn
  SVN::S4
  Voneline
  WFH
General Info
  Papers

0001-relocate-quoteNameControls-function-from-V3Number-to.patch

Kanad Kanhere, 05/16/2019 10:54 PM

Download (6.05 KB)

View differences:

src/V3AstNodes.cpp
846 846
    }
847 847
    if (name()!="") {
848 848
        if (VN_IS(this, Const)) str<<"  "<<name();  // Already quoted
849
	else str<<"  "<<V3Number::quoteNameControls(name());
849
	else str<<"  "<<V3OutFormatter::quoteNameControls(name());
850 850
    }
851 851
}
852 852

  
src/V3EmitV.cpp
52 52
	// Don't use to quote a filename for #include - #include doesn't \ escape.
53 53
	// Duplicate in V3File - here so we can print to string
54 54
	putsNoTracking("\"");
55
	putsNoTracking(V3Number::quoteNameControls(str));
55
	putsNoTracking(V3OutFormatter::quoteNameControls(str));
56 56
	putsNoTracking("\"");
57 57
    }
58 58

  
src/V3EmitXml.cpp
59 59
	// Don't use to quote a filename for #include - #include doesn't \ escape.
60 60
	// Duplicate in V3File - here so we can print to string
61 61
	putsNoTracking("\"");
62
	putsNoTracking(V3Number::quoteNameControls(str));
62
	putsNoTracking(V3OutFormatter::quoteNameControls(str));
63 63
	putsNoTracking("\"");
64 64
    }
65 65

  
src/V3File.cpp
806 806
    // Quote \ and " for use inside C programs
807 807
    // Don't use to quote a filename for #include - #include doesn't \ escape.
808 808
    putcNoTracking('"');
809
    string quoted = V3Number::quoteNameControls(strg);
809
    string quoted = quoteNameControls(strg);
810 810
    for (string::const_iterator cp=quoted.begin(); cp!=quoted.end(); ++cp) {
811 811
        putcNoTracking(*cp);
812 812
    }
......
843 843
    putcOutput(chr);
844 844
}
845 845

  
846
string V3OutFormatter::quoteNameControls(const string& namein, V3OutFormatter::Language) {
847
    // Encode control chars into C style escapes
848
    // Reverse is V3Parse::deQuote
849
    string out;
850
    for (string::const_iterator pos=namein.begin(); pos!=namein.end(); ++pos) {
851
	if (pos[0]=='\\' || pos[0]=='"') {
852
	    out += string("\\")+pos[0];
853
	} else if (pos[0]=='\n') {
854
	    out += "\\n";
855
	} else if (pos[0]=='\r') {
856
	    out += "\\r";
857
	} else if (pos[0]=='\t') {
858
	    out += "\\t";
859
	} else if (isprint(pos[0])) {
860
	    out += pos[0];
861
	} else {
862
	    // This will also cover \a etc
863
	    // Can't use %03o as messes up when signed
864
	    char octal[10]; sprintf(octal,"\\%o%o%o",(pos[0]>>6)&3, (pos[0]>>3)&7, pos[0]&7);
865
	    out += octal;
866
	}
867
    }
868
    return out;
869
}
870

  
846 871
//----------------------------------------------------------------------
847 872
// Simple wrappers
848 873

  
src/V3File.h
161 161
    void blockDec() { if (!m_parenVec.empty()) m_parenVec.pop(); }
162 162
    // STATIC METHODS
163 163
    static const string indentSpaces(int num);
164
    static string quoteNameControls(const string& namein, Language lang = LA_C); // Add escaped characters to strings
164 165

  
165 166
    // CALLBACKS - MUST OVERRIDE
166 167
    virtual void putcOutput(char chr) = 0;
src/V3Number.cpp
429 429
    return out.str();
430 430
}
431 431

  
432
string V3Number::quoteNameControls(const string& namein) {
433
    // Encode control chars into C style escapes
434
    // Reverse is V3Parse::deQuote
435
    string out;
436
    for (string::const_iterator pos=namein.begin(); pos!=namein.end(); ++pos) {
437
	if (pos[0]=='\\' || pos[0]=='"') {
438
	    out += string("\\")+pos[0];
439
	} else if (pos[0]=='\n') {
440
	    out += "\\n";
441
	} else if (pos[0]=='\r') {
442
	    out += "\\r";
443
	} else if (pos[0]=='\t') {
444
	    out += "\\t";
445
	} else if (isprint(pos[0])) {
446
	    out += pos[0];
447
	} else {
448
	    // This will also cover \a etc
449
	    // Can't use %03o as messes up when signed
450
	    char octal[10]; sprintf(octal,"\\%o%o%o",(pos[0]>>6)&3, (pos[0]>>3)&7, pos[0]&7);
451
	    out += octal;
452
	}
453
    }
454
    return out;
455
}
456

  
457 432
bool V3Number::displayedFmtLegal(char format) {
458 433
    // Is this a valid format letter?
459 434
    switch (tolower(format)) {
src/V3Number.h
195 195

  
196 196
    // ACCESSORS
197 197
    string ascii(bool prefixed=true, bool cleanVerilog=false) const;
198
    static string quoteNameControls(const string& namein); // Add backslash quotes to strings
199 198
    string displayed(AstNode* nodep, const string& vformat) const;
200 199
    static bool displayedFmtLegal(char format);  // Is this a valid format letter?
201 200
    int width() const { return m_width; }
src/verilog.y
4097 4097

  
4098 4098
string V3ParseGrammar::deQuote(FileLine* fileline, string text) {
4099 4099
    // Fix up the quoted strings the user put in, for example "\"" becomes "
4100
    // Reverse is V3Number::quoteNameControls(...)
4100
    // Reverse is V3OutFormatter::quoteNameControls(...)
4101 4101
    bool quoted = false;
4102 4102
    string newtext;
4103 4103
    unsigned char octal_val = 0;
4104
-