Skip to content

Commit

Permalink
vhdlp: Renamed ExpConditional::else_t to ExpConditional::option_t.
Browse files Browse the repository at this point in the history
  • Loading branch information
orsonmmz committed Jun 24, 2015
1 parent 44dfc41 commit ea12c0f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 44 deletions.
4 changes: 2 additions & 2 deletions vhdlpp/debug.cc
Expand Up @@ -288,13 +288,13 @@ void ExpConditional::dump(ostream&out, int indent) const
(*cur)->dump(out, indent+4);
}

for (list<else_t*>::const_iterator cur = else_clause_.begin()
for (list<option_t*>::const_iterator cur = else_clause_.begin()
; cur != else_clause_.end() ; ++cur) {
(*cur)->dump(out, indent);
}
}

void ExpConditional::else_t::dump(ostream&out, int indent) const
void ExpConditional::option_t::dump(ostream&out, int indent) const
{
out << setw(indent) << "" << "when:" << endl;
if (cond_) cond_->dump(out, indent+4);
Expand Down
50 changes: 26 additions & 24 deletions vhdlpp/expression.cc
Expand Up @@ -301,7 +301,7 @@ void ExpConcat::visit(ExprVisitor& func)
}

ExpConditional::ExpConditional(Expression*co, list<Expression*>*tru,
list<ExpConditional::else_t*>*fal)
list<ExpConditional::option_t*>*fal)
: cond_(co)
{
if (tru) true_clause_.splice(true_clause_.end(), *tru);
Expand All @@ -317,7 +317,7 @@ ExpConditional::~ExpConditional()
delete tmp;
}
while (! else_clause_.empty()) {
else_t*tmp = else_clause_.front();
option_t*tmp = else_clause_.front();
else_clause_.pop_front();
delete tmp;
}
Expand All @@ -335,13 +335,13 @@ Expression*ExpConditional::clone() const
}
}

std::list<else_t*>*new_else_clause = NULL;
std::list<option_t*>*new_else_clause = NULL;
if(!else_clause_.empty()) {
new_else_clause = new std::list<else_t*>();
new_else_clause = new std::list<option_t*>();

for(std::list<else_t*>::const_iterator it = else_clause_.begin();
for(std::list<option_t*>::const_iterator it = else_clause_.begin();
it != else_clause_.end(); ++it) {
new_else_clause->push_back(new else_t(**it));
new_else_clause->push_back(new option_t(**it));
}
}

Expand All @@ -350,35 +350,26 @@ Expression*ExpConditional::clone() const

void ExpConditional::visit(ExprVisitor& func)
{
if(!true_clause_.empty()) {
for(std::list<Expression*>::iterator it = true_clause_.begin();
it != true_clause_.end(); ++it) {
(*it)->visit(func);
}
for(std::list<Expression*>::iterator it = true_clause_.begin();
it != true_clause_.end(); ++it) {
(*it)->visit(func);
}

if(!else_clause_.empty()) {
for(std::list<else_t*>::iterator it = else_clause_.begin();
it != else_clause_.end(); ++it) {
std::list<Expression*>& else_clause = (*it)->extract_true_clause();

for(std::list<Expression*>::iterator jt = else_clause.begin();
jt != else_clause.end(); ++jt) {
(*jt)->visit(func);
}
}
for(std::list<option_t*>::iterator it = else_clause_.begin();
it != else_clause_.end(); ++it) {
(*it)->visit(func);
}

func(this);
}

ExpConditional::else_t::else_t(Expression*cond, std::list<Expression*>*tru)
ExpConditional::option_t::option_t(Expression*cond, std::list<Expression*>*tru)
: cond_(cond)
{
if (tru) true_clause_.splice(true_clause_.end(), *tru);
}

ExpConditional::else_t::else_t(const else_t&other)
ExpConditional::option_t::option_t(const option_t&other)
: LineInfo(other)
{
cond_ = other.cond_->clone();
Expand All @@ -388,7 +379,7 @@ ExpConditional::else_t::else_t(const else_t&other)
}
}

ExpConditional::else_t::~else_t()
ExpConditional::option_t::~option_t()
{
delete cond_;
while (! true_clause_.empty()) {
Expand All @@ -399,6 +390,17 @@ ExpConditional::else_t::~else_t()
}


void ExpConditional::option_t::visit(ExprVisitor& func)
{
if(cond_)
func(cond_);

for(std::list<Expression*>::iterator it = true_clause_.begin();
it != true_clause_.end(); ++it) {
func(*it);
}
}

ExpEdge::ExpEdge(ExpEdge::fun_t typ, Expression*op)
: ExpUnary(op), fun_(typ)
{
Expand Down
13 changes: 7 additions & 6 deletions vhdlpp/expression.h
Expand Up @@ -460,17 +460,18 @@ class ExpConcat : public Expression {
class ExpConditional : public Expression {

public:
class else_t : public LineInfo {
class option_t : public LineInfo {
public:
else_t(Expression*cond, std::list<Expression*>*tru);
else_t(const else_t&other);
~else_t();
option_t(Expression*cond, std::list<Expression*>*tru);
option_t(const option_t&other);
~option_t();

int elaborate_expr(Entity*ent, ScopeBase*scope, const VType*lt);
int emit_when_else(ostream&out, Entity*ent, ScopeBase*scope);
int emit_else(ostream&out, Entity*ent, ScopeBase*scope);
void dump(ostream&out, int indent = 0) const;
std::list<Expression*>& extract_true_clause() { return true_clause_; }
void visit(ExprVisitor& func);

private:
Expression*cond_;
Expand All @@ -479,7 +480,7 @@ class ExpConditional : public Expression {

public:
ExpConditional(Expression*cond, std::list<Expression*>*tru,
std::list<else_t*>*fal);
std::list<option_t*>*fal);
~ExpConditional();

Expression*clone() const;
Expand All @@ -494,7 +495,7 @@ class ExpConditional : public Expression {
private:
Expression*cond_;
std::list<Expression*> true_clause_;
std::list<else_t*> else_clause_;
std::list<option_t*> else_clause_;
};

/*
Expand Down
4 changes: 2 additions & 2 deletions vhdlpp/expression_elaborate.cc
Expand Up @@ -721,15 +721,15 @@ int ExpConditional::elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltyp
errors += (*cur)->elaborate_expr(ent, scope, ltype);
}

for (list<else_t*>::const_iterator cur = else_clause_.begin()
for (list<option_t*>::const_iterator cur = else_clause_.begin()
; cur != else_clause_.end() ; ++cur) {
errors += (*cur)->elaborate_expr(ent, scope, ltype);
}

return errors;
}

int ExpConditional::else_t::elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype)
int ExpConditional::option_t::elaborate_expr(Entity*ent, ScopeBase*scope, const VType*ltype)
{
int errors = 0;

Expand Down
8 changes: 4 additions & 4 deletions vhdlpp/expression_emit.cc
Expand Up @@ -497,10 +497,10 @@ int ExpConditional::emit(ostream&out, Entity*ent, ScopeBase*scope)
// Draw out any when-else expressions. These are all the else_
// clauses besides the last.
if (else_clause_.size() > 1) {
list<else_t*>::iterator last = else_clause_.end();
list<option_t*>::iterator last = else_clause_.end();
-- last;

for (list<else_t*>::iterator cur = else_clause_.begin()
for (list<option_t*>::iterator cur = else_clause_.begin()
; cur != last ; ++cur) {
errors += (*cur) ->emit_when_else(out, ent, scope);
}
Expand All @@ -519,7 +519,7 @@ int ExpConditional::emit(ostream&out, Entity*ent, ScopeBase*scope)
return errors;
}

int ExpConditional::else_t::emit_when_else(ostream&out, Entity*ent, ScopeBase*scope)
int ExpConditional::option_t::emit_when_else(ostream&out, Entity*ent, ScopeBase*scope)
{
int errors = 0;
assert(cond_ != 0);
Expand All @@ -541,7 +541,7 @@ int ExpConditional::else_t::emit_when_else(ostream&out, Entity*ent, ScopeBase*sc
return errors;
}

int ExpConditional::else_t::emit_else(ostream&out, Entity*ent, ScopeBase*scope)
int ExpConditional::option_t::emit_else(ostream&out, Entity*ent, ScopeBase*scope)
{
int errors = 0;
// Trailing else must have no condition.
Expand Down
12 changes: 6 additions & 6 deletions vhdlpp/parse.y
Expand Up @@ -228,8 +228,8 @@ static void touchup_interface_for_functions(std::list<InterfacePort*>*ports)
IfSequential::Elsif*elsif;
std::list<IfSequential::Elsif*>*elsif_list;

ExpConditional::else_t*exp_else;
std::list<ExpConditional::else_t*>*exp_else_list;
ExpConditional::option_t*exp_else;
std::list<ExpConditional::option_t*>*exp_else_list;

CaseSeqStmt::CaseStmtAlternative* case_alt;
std::list<CaseSeqStmt::CaseStmtAlternative*>* case_alt_list;
Expand Down Expand Up @@ -800,25 +800,25 @@ concurrent_simple_signal_assignment

else_when_waveforms
: else_when_waveforms else_when_waveform
{ list<ExpConditional::else_t*>*tmp = $1;
{ list<ExpConditional::option_t*>*tmp = $1;
tmp ->push_back($2);
$$ = tmp;
}
| else_when_waveform
{ list<ExpConditional::else_t*>*tmp = new list<ExpConditional::else_t*>;
{ list<ExpConditional::option_t*>*tmp = new list<ExpConditional::option_t*>;
tmp->push_back($1);
$$ = tmp;
}
;

else_when_waveform
: K_else waveform K_when expression
{ ExpConditional::else_t*tmp = new ExpConditional::else_t($4, $2);
{ ExpConditional::option_t*tmp = new ExpConditional::option_t($4, $2);
FILE_NAME(tmp, @1);
$$ = tmp;
}
| K_else waveform
{ ExpConditional::else_t*tmp = new ExpConditional::else_t(0, $2);
{ ExpConditional::option_t*tmp = new ExpConditional::option_t(0, $2);
FILE_NAME(tmp, @1);
$$ = tmp;
}
Expand Down

0 comments on commit ea12c0f

Please sign in to comment.