Fix display of empty string constant (#3207).

This commit is contained in:
Wilson Snyder 2021-11-17 17:46:08 -05:00
parent 106d635d0f
commit d2a8fa7440
5 changed files with 13 additions and 1 deletions

View File

@ -22,6 +22,7 @@ Verilator 4.215 devel
* Fix array method names with parenthesis (#3181) (#3183). [Teng Huang]
* Fix split_var assign merging (#3177) (#3179). [Yutetsu TAKATSUKASA]
* Fix nested generate if genblk naming (#3189). [yanx21]
* Fix display of empty string constant (#3207). [Julie Schwartz]
Verilator 4.214 2021-10-17

View File

@ -233,6 +233,7 @@ public:
V3Number(String, AstNode* nodep, const string& value) {
init(nodep, 0);
setString(value);
m_fromString = true;
}
class Null {};
V3Number(Null, AstNode* nodep) {

View File

@ -5006,7 +5006,15 @@ str<strp>: // yaSTRING but with \{escapes} need decoded
strAsInt<nodep>:
yaSTRING
{ $$ = new AstConst{$<fl>1, AstConst::VerilogStringLiteral(), GRAMMARP->deQuote($<fl>1, *$1)}; }
{ if ($1->empty()) {
// else "" is not representable as number as is width 0
// TODO all strings should be represented this way
// until V3Width converts as/if needed to a numerical constant
$$ = new AstConst{$<fl>1, AstConst::String{}, GRAMMARP->deQuote($<fl>1, *$1)};
} else {
$$ = new AstConst{$<fl>1, AstConst::VerilogStringLiteral(), GRAMMARP->deQuote($<fl>1, *$1)};
}
}
;
strAsIntIgnore<nodep>: // strAsInt, but never matches for when expr shouldn't parse strings

View File

@ -56,6 +56,7 @@ hello, from a concatenated string.
hello, from a concatenated format string [0].
extra argument: 0
0 : pre argument after
empty: ><
[0] Embedded tab ' ' and <#013> return
[0] Embedded
multiline

View File

@ -149,6 +149,7 @@ module t;
$write("hel", "lo, fr", "om a concatenated format string [%0t].\n", $time);
$display("extra argument: ", $time);
$display($time,, ": pre argument",, "after");
$display("empty: >%s<", "");
$write("[%0t] Embedded tab '\t' and \r return\n", $time);
$display("[%0t] Embedded\
multiline", $time);