From 1409207defa5cbdd0fd10765ab0c639e7320ec2b Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 23 Jul 2008 14:31:41 +0100 Subject: [PATCH] Correctly indent case statements --- tgt-vhdl/support.cc | 4 ++-- tgt-vhdl/vhdl_helper.hh | 6 ++++-- tgt-vhdl/vhdl_syntax.cc | 14 ++++++++++---- tgt-vhdl/vhdl_syntax.hh | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tgt-vhdl/support.cc b/tgt-vhdl/support.cc index 159618739..4c396407f 100644 --- a/tgt-vhdl/support.cc +++ b/tgt-vhdl/support.cc @@ -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: diff --git a/tgt-vhdl/vhdl_helper.hh b/tgt-vhdl/vhdl_helper.hh index a3f6f0704..d003ff1ef 100644 --- a/tgt-vhdl/vhdl_helper.hh +++ b/tgt-vhdl/vhdl_helper.hh @@ -28,7 +28,8 @@ template void emit_children(std::ostream &of, const std::list &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); } } diff --git a/tgt-vhdl/vhdl_syntax.cc b/tgt-vhdl/vhdl_syntax.cc index 2f5e9f56f..9637d1fe1 100644 --- a/tgt-vhdl/vhdl_syntax.cc +++ b/tgt-vhdl/vhdl_syntax.cc @@ -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(of, stmts_, level); + emit_children(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;"; } diff --git a/tgt-vhdl/vhdl_syntax.hh b/tgt-vhdl/vhdl_syntax.hh index f7acf9762..f54eb4f64 100644 --- a/tgt-vhdl/vhdl_syntax.hh +++ b/tgt-vhdl/vhdl_syntax.hh @@ -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 stmts_;