For --xml, decrease block indent to 2 spaces.

This commit is contained in:
Wilson Snyder 2015-10-20 21:22:00 -04:00
parent 3702e17b2e
commit cc22847bc3
2 changed files with 15 additions and 11 deletions

View File

@ -551,7 +551,7 @@ bool V3InFilter::readWholefile(const string& filename, V3InFilter::StrList& outl
// V3OutFormatter: A class for printing to a file, with automatic indentation of C++ code.
V3OutFormatter::V3OutFormatter(const string& filename, V3OutFormatter::Language lang)
: m_filename(filename), m_lang(lang)
: m_filename(filename), m_lang(lang), m_blockIndent(4)
, m_lineno(1), m_column(0)
, m_nobreak(false), m_prependIndent(true), m_indentLevel(0)
, m_declSAlign(0), m_declNSAlign(0), m_declPadNum(0) {
@ -619,7 +619,7 @@ int V3OutFormatter::endLevels (const char *strg) {
// label/public/private: Deindent by 2 spaces
const char* mp=cp;
for (; isalnum(*mp); mp++) ;
if (mp[0]==':' && mp[1]!=':') return (levels-INDBLK/2);
if (mp[0]==':' && mp[1]!=':') return (levels-m_blockIndent/2);
}
// We want "} else {" to be one level to the left of normal
@ -627,16 +627,16 @@ int V3OutFormatter::endLevels (const char *strg) {
switch (*cp) {
case '}':
case ')':
levels-=INDBLK;
levels-=m_blockIndent;
break;
case '<':
if (m_lang==LA_XML) {
if (cp[1] == '/') levels-=INDBLK;
if (cp[1] == '/') levels-=m_blockIndent;
}
break;
case 'e':
if (m_lang==LA_VERILOG && tokenEnd(cp)) {
levels-=INDBLK;
levels-=m_blockIndent;
}
break;
case '\t':

View File

@ -97,7 +97,6 @@ public:
class V3OutFormatter {
// TYPES
enum MiscConsts {
INDBLK = 4, // Indentation per block level
WIDTH = 50, // Width after which to break at ,'s
MAXSPACE = 80}; // After this indent, stop indenting more
public:
@ -115,6 +114,7 @@ private:
// MEMBERS
string m_filename;
Language m_lang; // Indenting Verilog code
int m_blockIndent; // Characters per block indent
int m_lineno;
int m_column;
int m_nobreak; // Basic operator or begin paren, don't break next
@ -133,7 +133,9 @@ public:
V3OutFormatter(const string& filename, Language lang);
virtual ~V3OutFormatter() {}
// ACCESSORS
int column() const { return m_column; }
int column() const { return m_column; }
int blockIndent() const { return m_blockIndent; }
void blockIndent(int flag) { m_blockIndent=flag; }
// METHODS
void printf(const char* fmt...) VL_ATTR_PRINTF(2);
void puts(const char* strg);
@ -150,12 +152,12 @@ public:
bool exceededWidth() const { return m_column > WIDTH; }
bool tokenStart(const char* cp, const char* cmp);
bool tokenEnd(const char* cp);
void indentInc() { m_indentLevel += INDBLK; }
void indentInc() { m_indentLevel += m_blockIndent; }
void indentDec() {
m_indentLevel -= INDBLK;
m_indentLevel -= m_blockIndent;
UASSERT(m_indentLevel>=0, ": "<<m_filename<<": Underflow of indentation\n");
}
void blockInc() { m_parenVec.push(m_indentLevel + INDBLK); }
void blockInc() { m_parenVec.push(m_indentLevel + m_blockIndent); }
void blockDec() { if (!m_parenVec.empty()) m_parenVec.pop(); }
// STATIC METHODS
static const string indentSpaces(int levels);
@ -238,7 +240,9 @@ public:
class V3OutXmlFile : public V3OutFile {
public:
explicit V3OutXmlFile(const string& filename) : V3OutFile(filename, V3OutFormatter::LA_XML) {}
explicit V3OutXmlFile(const string& filename) : V3OutFile(filename, V3OutFormatter::LA_XML) {
blockIndent(2);
}
virtual ~V3OutXmlFile() {}
virtual void putsHeader() { puts("<?xml version=\"1.0\" ?>\n"); }
};