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
+1
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) {
+9 -1
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