Indent output C code '= {' blocks.
This commit is contained in:
parent
9ad252be34
commit
41be66af95
|
|
@ -576,7 +576,7 @@ bool V3InFilter::readWholefile(const string& filename, V3InFilter::StrList& outl
|
||||||
V3OutFormatter::V3OutFormatter(const string& filename, V3OutFormatter::Language lang)
|
V3OutFormatter::V3OutFormatter(const string& filename, V3OutFormatter::Language lang)
|
||||||
: m_filename(filename), m_lang(lang)
|
: m_filename(filename), m_lang(lang)
|
||||||
, m_lineno(1), m_column(0)
|
, m_lineno(1), m_column(0)
|
||||||
, m_nobreak(false), m_prependIndent(true), m_indentLevel(0) {
|
, m_nobreak(false), m_prependIndent(true), m_indentLevel(0), m_bracketLevel(0) {
|
||||||
m_blockIndent = v3Global.opt.decoration() ? 4 : 1;
|
m_blockIndent = v3Global.opt.decoration() ? 4 : 1;
|
||||||
m_commaWidth = v3Global.opt.decoration() ? 50 : 150;
|
m_commaWidth = v3Global.opt.decoration() ? 50 : 150;
|
||||||
}
|
}
|
||||||
|
|
@ -680,6 +680,7 @@ void V3OutFormatter::puts(const char *strg) {
|
||||||
m_prependIndent = false;
|
m_prependIndent = false;
|
||||||
}
|
}
|
||||||
bool wordstart = true;
|
bool wordstart = true;
|
||||||
|
bool equalsForBracket = false; // Looking for "= {"
|
||||||
for (const char* cp=strg; *cp; cp++) {
|
for (const char* cp=strg; *cp; cp++) {
|
||||||
putcNoTracking(*cp);
|
putcNoTracking(*cp);
|
||||||
switch (*cp) {
|
switch (*cp) {
|
||||||
|
|
@ -700,9 +701,18 @@ void V3OutFormatter::puts(const char *strg) {
|
||||||
wordstart = true;
|
wordstart = true;
|
||||||
break;
|
break;
|
||||||
case '{':
|
case '{':
|
||||||
|
if (m_lang==LA_C && (equalsForBracket || m_bracketLevel)) {
|
||||||
|
// Break up large code inside "= { ..."
|
||||||
|
m_parenVec.push(m_indentLevel*m_blockIndent); // Line up continuation with block+1
|
||||||
|
++m_bracketLevel;
|
||||||
|
}
|
||||||
indentInc();
|
indentInc();
|
||||||
break;
|
break;
|
||||||
case '}':
|
case '}':
|
||||||
|
if (m_bracketLevel>0) {
|
||||||
|
m_parenVec.pop();
|
||||||
|
--m_bracketLevel;
|
||||||
|
}
|
||||||
indentDec();
|
indentDec();
|
||||||
break;
|
break;
|
||||||
case '(':
|
case '(':
|
||||||
|
|
@ -761,6 +771,17 @@ void V3OutFormatter::puts(const char *strg) {
|
||||||
wordstart = false;
|
wordstart = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (*cp) {
|
||||||
|
case '=':
|
||||||
|
equalsForBracket = true;
|
||||||
|
break;
|
||||||
|
case ' ':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
equalsForBracket = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,7 @@ private:
|
||||||
bool m_prependIndent;
|
bool m_prependIndent;
|
||||||
int m_indentLevel; // Current {} indentation
|
int m_indentLevel; // Current {} indentation
|
||||||
std::stack<int> m_parenVec; // Stack of columns where last ( was
|
std::stack<int> m_parenVec; // Stack of columns where last ( was
|
||||||
|
int m_bracketLevel; // Intenting = { block, indicates number of {'s seen.
|
||||||
|
|
||||||
int endLevels(const char* strg);
|
int endLevels(const char* strg);
|
||||||
const char* indentStr(int levels);
|
const char* indentStr(int levels);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue