Refactor while/for loop code to use common base

This commit is contained in:
Nick Gasson 2008-07-24 15:22:25 +01:00
parent 39c9c54760
commit d3296d4895
2 changed files with 16 additions and 19 deletions

View File

@ -761,9 +761,8 @@ void vhdl_while_stmt::emit(std::ostream &of, int level) const
{
of << "while ";
test_->emit(of, level);
of << " loop";
stmts_.emit(of, level);
of << "end loop;";
of << " ";
vhdl_loop_stmt::emit(of, level);
}
void vhdl_loop_stmt::emit(std::ostream &of, int level) const
@ -786,7 +785,7 @@ void vhdl_for_stmt::emit(std::ostream &of, int level) const
of << " to ";
to_->emit(of, level);
of << " ";
loop_.emit(of, level);
vhdl_loop_stmt::emit(of, level);
}
vhdl_function::vhdl_function(const char *name, vhdl_type *ret_type)

View File

@ -395,38 +395,36 @@ private:
};
class vhdl_while_stmt : public vhdl_seq_stmt {
class vhdl_loop_stmt : public vhdl_seq_stmt {
public:
virtual ~vhdl_loop_stmt() {}
stmt_container *get_container() { return &stmts_; }
void emit(std::ostream &of, int level) const;
private:
stmt_container stmts_;
};
class vhdl_while_stmt : public vhdl_loop_stmt {
public:
vhdl_while_stmt(vhdl_expr *test) : test_(test) {}
~vhdl_while_stmt();
stmt_container *get_container() { return &stmts_; }
void emit(std::ostream &of, int level) const;
private:
vhdl_expr *test_;
stmt_container stmts_;
};
class vhdl_loop_stmt : public vhdl_seq_stmt {
public:
stmt_container *get_container() { return &stmts_; }
void emit(std::ostream &of, int level) const;
private:
stmt_container stmts_;
};
class vhdl_for_stmt : public vhdl_seq_stmt {
class vhdl_for_stmt : public vhdl_loop_stmt {
public:
vhdl_for_stmt(const char *lname, vhdl_expr *from, vhdl_expr *to)
: lname_(lname), from_(from), to_(to) {}
~vhdl_for_stmt();
stmt_container *get_container() { return loop_.get_container(); }
void emit(std::ostream &of, int level) const;
private:
vhdl_loop_stmt loop_;
const char *lname_;
vhdl_expr *from_, *to_;
};