From b0c79d5d1c25b4a61f6181f07ba37ac03c5b0f9d Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 25 Aug 2014 16:57:27 +0200 Subject: [PATCH] vhdlpp: Added VType::emit_name() that skips emission of a name if it is empty (otherwise '\' is outputted). --- vhdlpp/vtype.h | 6 ++++++ vhdlpp/vtype_emit.cc | 25 +++++++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/vhdlpp/vtype.h b/vhdlpp/vtype.h index d8c5f6b9a..a52e7d377 100644 --- a/vhdlpp/vtype.h +++ b/vhdlpp/vtype.h @@ -103,6 +103,12 @@ class VType { bool reg_flag; }; + protected: + inline void emit_name(std::ostream&out, perm_string name) const + { + if(name != empty_perm_string) + out << " \\" << name << " "; + } }; inline std::ostream&operator << (std::ostream&out, const VType&item) diff --git a/vhdlpp/vtype_emit.cc b/vhdlpp/vtype_emit.cc index d0dea54bd..473107245 100644 --- a/vhdlpp/vtype_emit.cc +++ b/vhdlpp/vtype_emit.cc @@ -67,26 +67,22 @@ int VTypeArray::emit_def(ostream&out, perm_string name) const const VType*raw_base = cur->etype_; const VTypePrimitive*base = dynamic_cast (raw_base); - stringstream buf; if (base) { assert(dimensions() == 1); - base->emit_def(buf, empty_perm_string); + base->emit_def(out, empty_perm_string); if (signed_flag_) - buf << " signed"; + out << " signed"; } else { - raw_base->emit_def(buf, empty_perm_string); + raw_base->emit_def(out, empty_perm_string); } - string tmp(buf.str()); - out << tmp.substr(0, tmp.length() - 2); // drop the empty type name (\ ) - if(raw_base->can_be_packed()) { errors += emit_dimensions(out); - out << " \\" << name; + emit_name(out, name); } else { - out << "\\" << name << " "; + emit_name(out, name); errors += emit_dimensions(out); } @@ -136,7 +132,8 @@ int VTypeEnum::emit_def(ostream&out, perm_string name) const for (size_t idx = 1 ; idx < names_.size() ; idx += 1) out << ", \\" << names_[idx] << " "; - out << "} \\" << name << " "; + out << "}"; + emit_name(out, name); return errors; } @@ -172,7 +169,7 @@ int VTypePrimitive::emit_def(ostream&out, perm_string name) const { int errors = 0; errors += emit_primitive_type(out); - out << " \\" << name << " "; + emit_name(out, name); return errors; } @@ -197,7 +194,8 @@ int VTypeRecord::emit_def(ostream&out, perm_string name) const out << " \\" << element_name << " ; "; } - out << "} \\ " << name << " "; + out << "}"; + emit_name(out, name); return errors; } @@ -209,7 +207,7 @@ int VTypeRecord::emit_def(ostream&out, perm_string name) const int VTypeDef::emit_def(ostream&out, perm_string) const { int errors = 0; - out << "\\" << name_ << " "; + emit_name(out, name_); return errors; } @@ -222,7 +220,6 @@ int VTypeDef::emit_decl(ostream&out, perm_string name, bool reg_flag) const out << "wire "; errors += type_->emit_def(out, name); - out << " \\" << name << " "; return errors; }