Correctly indent case statements

This commit is contained in:
Nick Gasson 2008-07-23 14:31:41 +01:00
parent 30fdadc525
commit 1409207def
4 changed files with 17 additions and 9 deletions

View File

@ -86,9 +86,9 @@ void support_function::emit(std::ostream &of, int level) const
of << "(B : Boolean) return std_logic is" << nl_string(level)
<< "begin" << nl_string(indent(level))
<< "if B then" << nl_string(indent(indent(level)))
<< "return '1'" << nl_string(indent(level))
<< "return '1';" << nl_string(indent(level))
<< "else" << nl_string(indent(indent(level)))
<< "return '0'" << nl_string(indent(level))
<< "return '0';" << nl_string(indent(level))
<< "end if;" << nl_string(level);
break;
case SF_REDUCE_OR:

View File

@ -28,7 +28,8 @@
template <class T>
void emit_children(std::ostream &of,
const std::list<T*> &children,
int level, const char *delim="")
int level, const char *delim = "",
bool trailing_newline = true)
{
// Don't indent if there are no children
if (children.size() == 0)
@ -42,7 +43,8 @@ void emit_children(std::ostream &of,
if (--sz > 0)
of << delim;
}
newline(of, level);
if (trailing_newline)
newline(of, level);
}
}

View File

@ -192,9 +192,9 @@ void stmt_container::add_stmt(vhdl_seq_stmt *stmt)
stmts_.push_back(stmt);
}
void stmt_container::emit(std::ostream &of, int level) const
void stmt_container::emit(std::ostream &of, int level, bool newline) const
{
emit_children<vhdl_seq_stmt>(of, stmts_, level);
emit_children<vhdl_seq_stmt>(of, stmts_, level, "", newline);
}
vhdl_comp_inst::vhdl_comp_inst(const char *inst_name, const char *comp_name)
@ -724,7 +724,7 @@ void vhdl_case_branch::emit(std::ostream &of, int level) const
of << "when ";
when_->emit(of, level);
of << " =>";
stmts_.emit(of, indent(level));
stmts_.emit(of, indent(level), false);
}
vhdl_case_stmt::~vhdl_case_stmt()
@ -740,8 +740,14 @@ void vhdl_case_stmt::emit(std::ostream &of, int level) const
newline(of, indent(level));
case_branch_list_t::const_iterator it;
for (it = branches_.begin(); it != branches_.end(); ++it)
int n = branches_.size();
for (it = branches_.begin(); it != branches_.end(); ++it) {
(*it)->emit(of, level);
if (--n > 0)
newline(of, indent(level));
else
newline(of, level);
}
of << "end case;";
}

View File

@ -261,7 +261,7 @@ public:
~stmt_container();
void add_stmt(vhdl_seq_stmt *stmt);
void emit(std::ostream &of, int level) const;
void emit(std::ostream &of, int level, bool newline=true) const;
bool empty() const { return stmts_.empty(); }
private:
std::list<vhdl_seq_stmt*> stmts_;