Add helper function for printing expression list

There are a few places where some sort of expression list is printed. Add
helper functions to consolidate this in a single place and reduce the
amount of code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2023-01-01 12:54:49 -08:00
parent 520b00095c
commit 2cef85f8a1
2 changed files with 52 additions and 104 deletions

View File

@ -206,6 +206,18 @@ ostream& operator << (ostream&fd, NetCaseCmp::kind_t that)
return fd;
}
static std::ostream& operator << (std::ostream &out, const std::vector<NetExpr*> &exprs)
{
for (size_t idx = 0; idx < exprs.size(); idx++) {
if (idx != 0)
out << ", ";
if (exprs[idx])
out << *exprs[idx];
}
return out;
}
ostream& ivl_type_s::debug_dump(ostream&o) const
{
o << typeid(*this).name();
@ -1650,17 +1662,7 @@ void NetSTask::dump(ostream&o, unsigned ind) const
o << setw(ind) << "" << name_;
if (! parms_.empty()) {
o << "(";
if (parms_[0])
parms_[0]->dump(o);
for (unsigned idx = 1 ; idx < parms_.size() ; idx += 1) {
o << ", ";
if (parms_[idx])
parms_[idx]->dump(o);
}
o << ")";
o << "(" << parms_ << ")";
}
o << ";" << endl;
}
@ -1702,15 +1704,7 @@ void NetEAccess::dump(ostream&o) const
void NetEArrayPattern::dump(ostream&fd) const
{
fd << "'{";
if (items_.size() >= 1) {
if (items_[0]) fd << *items_[0];
}
for (size_t idx = 1 ; idx < items_.size() ; idx += 1) {
fd << ", ";
if (items_[idx]) fd << *items_[idx];
}
fd << "}";
fd << "'{" << items_ << "}";
}
void NetEBinary::dump(ostream&o) const
@ -1814,18 +1808,7 @@ void NetEConcat::dump(ostream&o) const
if (repeat_ != 1)
o << repeat_;
if (parms_[0])
o << "{" << *parms_[0];
else
o << "{";
for (unsigned idx = 1 ; idx < parms_.size() ; idx += 1) {
if (parms_[idx])
o << ", " << *parms_[idx];
else
o << ", ";
}
o << "}";
o << "{" << parms_ << "}";
}
void NetEConst::dump(ostream&o) const
@ -1965,15 +1948,7 @@ void NetETernary::dump(ostream&o) const
void NetEUFunc::dump(ostream&o) const
{
o << scope_path(func_) << "(";
if (! parms_.empty()) {
parms_[0]->dump(o);
for (unsigned idx = 1 ; idx < parms_.size() ; idx += 1) {
o << ", ";
parms_[idx]->dump(o);
}
}
o << ")";
o << scope_path(func_) << "(" << parms_ << ")";
}
void NetEUnary::dump(ostream&o) const

View File

@ -177,6 +177,35 @@ std::ostream& operator << (std::ostream&out, ivl_dis_domain_t dom)
return out;
}
static std::ostream& operator << (std::ostream &out, const std::vector<PExpr*> &exprs)
{
for (size_t idx = 0; idx < exprs.size(); idx++) {
if (idx != 0)
out << ", ";
if (exprs[idx])
exprs[idx]->dump(out);
}
return out;
}
static std::ostream& operator << (std::ostream &out,
const std::vector<named_pexpr_t> &exprs)
{
for (size_t idx = 0; idx < exprs.size(); idx++) {
if (idx != 0)
out << ", ";
if (!exprs[idx].name.nil())
out << "." << exprs[idx].name << "(";
if (exprs[idx].parm)
exprs[idx].parm->dump(out);
if (!exprs[idx].name.nil())
out << ")";
}
return out;
}
void data_type_t::pform_dump(ostream&out, unsigned indent) const
{
out << setw(indent) << "" << typeid(*this).name() << endl;
@ -380,15 +409,7 @@ void PExpr::dump(ostream&out) const
void PEAssignPattern::dump(ostream&out) const
{
out << "'{";
if (parms_.size() > 0) {
parms_[0]->dump(out);
for (size_t idx = 1 ; idx < parms_.size() ; idx += 1) {
out << ", ";
parms_[idx]->dump(out);
}
}
out << "}";
out << "'{" << parms_ << "}";
}
void PEConcat::dump(ostream&out) const
@ -401,30 +422,14 @@ void PEConcat::dump(ostream&out) const
return;
}
out << "{";
if (parms_[0]) out << *parms_[0];
for (unsigned idx = 1 ; idx < parms_.size() ; idx += 1) {
out << ", ";
if (parms_[idx]) out << *parms_[idx];
}
out << "}";
out << "{" << parms_ << "}";
if (repeat_) out << "}";
}
void PECallFunction::dump(ostream &out) const
{
out << path_ << "(";
if (! parms_.empty()) {
if (parms_[0]) parms_[0]->dump(out);
for (unsigned idx = 1; idx < parms_.size(); ++idx) {
out << ", ";
if (parms_[idx]) parms_[idx]->dump(out);
}
}
out << ")";
out << path_ << "(" << parms_ << ")";
}
void PECastSize::dump(ostream &out) const
@ -487,15 +492,7 @@ void PENewArray::dump(ostream&out) const
void PENewClass::dump(ostream&out) const
{
out << "class_new(";
if (parms_.size() > 0) {
parms_[0]->dump(out);
for (size_t idx = 1 ; idx < parms_.size() ; idx += 1) {
out << ", ";
if (parms_[idx]) parms_[idx]->dump(out);
}
}
out << ")";
out << "class_new(" << parms_ << ")";
}
void PENewCopy::dump(ostream&out) const
@ -830,14 +827,7 @@ void PGModule::dump(ostream&out, unsigned ind) const
// If parameters are overridden by name, dump them.
if (parms_) {
assert(overrides_ == 0);
out << "#(";
for (unsigned idx = 0 ; idx < nparms_ ; idx += 1) {
if (idx > 0) out << ", ";
out << "." << parms_[idx].name << "(";
if (parms_[idx].parm) out << *parms_[idx].parm;
out << ")";
}
out << ") ";
out << "#(" << parms_ << ") ";
}
out << get_name();
@ -940,16 +930,7 @@ void PCallTask::dump(ostream&out, unsigned ind) const
out << setw(ind) << "" << path_;
if (! parms_.empty()) {
out << "(";
if (parms_[0])
out << *parms_[0];
for (unsigned idx = 1 ; idx < parms_.size() ; idx += 1) {
out << ", ";
if (parms_[idx])
out << *parms_[idx];
}
out << ")";
out << "(" << parms_ << ")";
}
out << "; /* " << get_fileline() << " */" << endl;
@ -1017,15 +998,7 @@ void PCase::dump(ostream&out, unsigned ind) const
void PChainConstructor::dump(ostream&out, unsigned ind) const
{
out << setw(ind) << "" << "super.new(";
if (parms_.size() > 0) {
if (parms_[0]) out << *parms_[0];
}
for (size_t idx = 1 ; idx < parms_.size() ; idx += 1) {
out << ", ";
if (parms_[idx]) out << *parms_[idx];
}
out << ");" << endl;
out << setw(ind) << "" << "super.new(" << parms_ << ")" <<endl;
}
void PCondit::dump(ostream&out, unsigned ind) const