From 7d8c51181d8291a85eaad4f5b78e11a968adc40f Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 13 Sep 2016 22:53:09 -0400 Subject: [PATCH] With --no-decoration also shrink output code indents. --- src/V3File.cpp | 10 ++++++++-- src/V3File.h | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/V3File.cpp b/src/V3File.cpp index 8e3f7213d..4b7ae4fd6 100644 --- a/src/V3File.cpp +++ b/src/V3File.cpp @@ -551,10 +551,12 @@ 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_blockIndent(4) + : m_filename(filename), m_lang(lang) , m_lineno(1), m_column(0) , m_nobreak(false), m_prependIndent(true), m_indentLevel(0) , m_declSAlign(0), m_declNSAlign(0), m_declPadNum(0) { + m_blockIndent = v3Global.opt.decoration() ? 4 : 1; + m_commaWidth = v3Global.opt.decoration() ? 50 : 150; } //---------------------------------------------------------------------- @@ -682,7 +684,11 @@ void V3OutFormatter::puts (const char *strg) { break; case '(': indentInc(); - m_parenVec.push(m_column); + if (v3Global.opt.decoration()) { + m_parenVec.push(m_column); // Line up continuation with open paren, plus one indent + } else { + m_parenVec.push(m_indentLevel*m_blockIndent); // Line up continuation with block+1 + } break; case ')': if (!m_parenVec.empty()) m_parenVec.pop(); diff --git a/src/V3File.h b/src/V3File.h index 56d61824f..9142f696b 100644 --- a/src/V3File.h +++ b/src/V3File.h @@ -97,7 +97,6 @@ public: class V3OutFormatter { // TYPES enum MiscConsts { - WIDTH = 50, // Width after which to break at ,'s MAXSPACE = 80}; // After this indent, stop indenting more public: enum AlignClass { @@ -115,6 +114,7 @@ private: string m_filename; Language m_lang; // Indenting Verilog code int m_blockIndent; // Characters per block indent + int m_commaWidth; // Width after which to break at ,'s int m_lineno; int m_column; int m_nobreak; // Basic operator or begin paren, don't break next @@ -147,7 +147,7 @@ public: void putAlign(bool isstatic/*AlignClass*/, int align, int size=0/*=align*/, const string& prefix=""); // Declare a variable, with natural alignment void putbs(const char* strg) { putBreakExpr(); puts(strg); } void putbs(const string& strg) { putBreakExpr(); puts(strg); } - bool exceededWidth() const { return m_column > WIDTH; } + bool exceededWidth() const { return m_column > m_commaWidth; } bool tokenStart(const char* cp, const char* cmp); bool tokenEnd(const char* cp); void indentInc() { m_indentLevel += m_blockIndent; }