Skip to content

Commit

Permalink
Emit: Fix indent tracking when // inside string literal (verilator#2990)
Browse files Browse the repository at this point in the history
// was so far unconditionally treated as comment.
c443e22 introduced a string literal in
the output that contained a http:// url, which broke the indent
tracking. No functional change intended
  • Loading branch information
gezalore committed May 29, 2021
1 parent ef9f477 commit f4c1a7e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/V3File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,9 +715,13 @@ void V3OutFormatter::puts(const char* strg) {
break;
case ' ': wordstart = true; break;
case '\t': wordstart = true; break;
case '"':
wordstart = false;
m_inStringLiteral = !m_inStringLiteral;
break;
case '/':
if (m_lang == LA_C || m_lang == LA_VERILOG) {
if (cp > strg && cp[-1] == '/') {
if (cp > strg && cp[-1] == '/' && !m_inStringLiteral) {
// Output ignoring contents to EOL
cp++;
while (*cp && cp[1] && cp[1] != '\n') putcNoTracking(*cp++);
Expand Down
1 change: 1 addition & 0 deletions src/V3File.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class V3OutFormatter VL_NOT_FINAL {
int m_column = 0;
int m_nobreak = false; // Basic operator or begin paren, don't break next
bool m_prependIndent = true;
bool m_inStringLiteral = false;
int m_indentLevel = 0; // Current {} indentation
std::stack<int> m_parenVec; // Stack of columns where last ( was
int m_bracketLevel = 0; // Intenting = { block, indicates number of {'s seen.
Expand Down

0 comments on commit f4c1a7e

Please sign in to comment.