handle constant format field widths (#3946)

This commit is contained in:
Todd Strader
2023-02-09 10:09:00 -05:00
committed by GitHub
parent b778784333
commit 4eb280601e
2 changed files with 12 additions and 2 deletions
+8 -1
View File
@@ -1084,12 +1084,19 @@ private:
const string format = nodep->text();
auto pos = format.cbegin();
bool inPct = false;
string width;
for (; pos != format.cend(); ++pos) {
if (!inPct && pos[0] == '%') {
inPct = true;
width = "";
} else if (!inPct) { // Normal text
result += *pos;
} else { // Format character
if (std::isdigit(pos[0])) {
width += pos[0];
continue;
}
inPct = false;
if (V3Number::displayedFmtLegal(tolower(pos[0]), false)) {
@@ -1101,7 +1108,7 @@ private:
nodep, "Argument for $display like statement is not constant");
break;
}
const string pformat = std::string{"%"} + pos[0];
const string pformat = std::string{"%"} + width + pos[0];
result += constp->num().displayed(nodep, pformat);
} else {
switch (tolower(pos[0])) {