Emit: Fix indent tracking when // inside string literal (#2990)

// was so far unconditionally treated as comment.
c443e229ee introduced a string literal in
the output that contained a http:// url, which broke the indent
tracking. No functional change intended
This commit is contained in:
Geza Lore 2021-05-29 23:46:15 +01:00 committed by GitHub
parent ef9f477df2
commit f4c1a7efeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -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++);

View File

@ -121,6 +121,7 @@ private:
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.