diff --git a/vhdlpp/debug.cc b/vhdlpp/debug.cc index 3d5d72a30..03164de49 100644 --- a/vhdlpp/debug.cc +++ b/vhdlpp/debug.cc @@ -279,17 +279,9 @@ void ExpCharacter::dump(ostream&out, int indent) const void ExpConditional::dump(ostream&out, int indent) const { out << setw(indent) << "" << "Conditional expression at "<< get_fileline() << endl; - out << setw(indent) << "" << " when:" << endl; - cond_->dump(out, indent+4); - out << setw(indent) << "" << " do:" << endl; - for (list::const_iterator cur = true_clause_.begin() - ; cur != true_clause_.end() ; ++cur) { - (*cur)->dump(out, indent+4); - } - - for (list::const_iterator cur = else_clause_.begin() - ; cur != else_clause_.end() ; ++cur) { + for (list::const_iterator cur = options_.begin() + ; cur != options_.end() ; ++cur) { (*cur)->dump(out, indent); } } diff --git a/vhdlpp/expression.cc b/vhdlpp/expression.cc index 6dc4c2125..7124b2532 100644 --- a/vhdlpp/expression.cc +++ b/vhdlpp/expression.cc @@ -301,51 +301,34 @@ void ExpConcat::visit(ExprVisitor& func) } ExpConditional::ExpConditional(Expression*co, list*tru, - list*fal) -: cond_(co) + list*options) { - if (tru) true_clause_.splice(true_clause_.end(), *tru); - if (fal) else_clause_.splice(else_clause_.end(), *fal); + if(co && tru) options_.push_back(new option_t(co, tru)); + if(options) options_.splice(options_.end(), *options); } ExpConditional::~ExpConditional() { - delete cond_; - while (! true_clause_.empty()) { - Expression*tmp = true_clause_.front(); - true_clause_.pop_front(); - delete tmp; - } - while (! else_clause_.empty()) { - option_t*tmp = else_clause_.front(); - else_clause_.pop_front(); + while (!options_.empty()) { + option_t*tmp = options_.front(); + options_.pop_front(); delete tmp; } } Expression*ExpConditional::clone() const { - std::list*new_true_clause = NULL; - if(!true_clause_.empty()) { - new_true_clause = new std::list(); + std::list*new_options = NULL; + if(!options_.empty()) { + new_options = new std::list(); - for(std::list::const_iterator it = true_clause_.begin(); - it != true_clause_.end(); ++it) { - new_true_clause->push_back((*it)->clone()); + for(std::list::const_iterator it = options_.begin(); + it != options_.end(); ++it) { + new_options->push_back(new option_t(**it)); } } - std::list*new_else_clause = NULL; - if(!else_clause_.empty()) { - new_else_clause = new std::list(); - - for(std::list::const_iterator it = else_clause_.begin(); - it != else_clause_.end(); ++it) { - new_else_clause->push_back(new option_t(**it)); - } - } - - return new ExpConditional(cond_->clone(), new_true_clause, new_else_clause); + return new ExpConditional(NULL, NULL, new_options); } void ExpConditional::visit(ExprVisitor& func) diff --git a/vhdlpp/expression.h b/vhdlpp/expression.h index d770507a0..02ac37ccf 100644 --- a/vhdlpp/expression.h +++ b/vhdlpp/expression.h @@ -480,7 +480,7 @@ class ExpConditional : public Expression { public: ExpConditional(Expression*cond, std::list*tru, - std::list*fal); + std::list*options); ~ExpConditional(); Expression*clone() const; @@ -493,9 +493,7 @@ class ExpConditional : public Expression { void visit(ExprVisitor& func); private: - Expression*cond_; - std::list true_clause_; - std::list else_clause_; + std::list options_; }; /* diff --git a/vhdlpp/expression_elaborate.cc b/vhdlpp/expression_elaborate.cc index 72fe1cf7f..fd3eaa93e 100644 --- a/vhdlpp/expression_elaborate.cc +++ b/vhdlpp/expression_elaborate.cc @@ -714,15 +714,9 @@ int ExpConditional::elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltyp /* Note that the type for the condition expression need not have anything to do with the type of this expression. */ - errors += cond_->elaborate_expr(ent, scope, 0); - for (list::const_iterator cur = true_clause_.begin() - ; cur != true_clause_.end() ; ++cur) { - errors += (*cur)->elaborate_expr(ent, scope, ltype); - } - - for (list::const_iterator cur = else_clause_.begin() - ; cur != else_clause_.end() ; ++cur) { + for (list::const_iterator cur = options_.begin() + ; cur != options_.end() ; ++cur) { errors += (*cur)->elaborate_expr(ent, scope, ltype); } diff --git a/vhdlpp/expression_emit.cc b/vhdlpp/expression_emit.cc index ae5ad492e..895c2a7c7 100644 --- a/vhdlpp/expression_emit.cc +++ b/vhdlpp/expression_emit.cc @@ -481,39 +481,27 @@ int ExpConditional::emit(ostream&out, Entity*ent, ScopeBase*scope) { int errors = 0; out << "("; - errors += cond_->emit(out, ent, scope); - out << ")? ("; - - if (true_clause_.size() > 1) { - cerr << get_fileline() << ": sorry: Multiple expression waveforms not supported here." << endl; - errors += 1; - } - - Expression*tmp = true_clause_.front(); - errors += tmp->emit(out, ent, scope); - - out << ") : ("; // Draw out any when-else expressions. These are all the else_ // clauses besides the last. - if (else_clause_.size() > 1) { - list::iterator last = else_clause_.end(); - -- last; + if (options_.size() > 1) { + list::iterator last = options_.end(); + --last; - for (list::iterator cur = else_clause_.begin() + for (list::iterator cur = options_.begin() ; cur != last ; ++cur) { errors += (*cur) ->emit_when_else(out, ent, scope); } } - errors += else_clause_.back()->emit_else(out, ent, scope); + errors += options_.back()->emit_else(out, ent, scope); out << ")"; // The emit_when_else() functions do not close the last // parentheses so that the following expression can be // nested. But that means come the end, we have some // expressions to close. - for (size_t idx = 1 ; idx < else_clause_.size() ; idx += 1) + for (size_t idx = 1 ; idx < options_.size() ; idx += 1) out << ")"; return errors;