Skip to content

Commit 43f2fa7

Browse files
committed
Pretty-printing of multi-variable let expressions
Fix expr2c and format to support LET expressions over multiple variables. expr2c in fact wouldn't even correctly support single-variable LET expressions anymore as it wasn't updated in 71a20e9.
1 parent c05708c commit 43f2fa7

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

src/ansi-c/expr2c.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -924,18 +924,24 @@ std::string expr2ct::convert_let(
924924
const let_exprt &src,
925925
unsigned precedence)
926926
{
927-
if(src.operands().size()<3)
928-
return convert_norep(src, precedence);
927+
std::string dest = "LET ";
929928

930-
unsigned p0;
931-
std::string op0=convert_with_precedence(src.op0(), p0);
929+
bool first = true;
932930

933-
std::string dest="LET ";
934-
dest+=convert(src.symbol());
935-
dest+='=';
936-
dest+=convert(src.value());
937-
dest+=" IN ";
938-
dest+=convert(src.where());
931+
const auto &values = src.values();
932+
auto values_it = values.begin();
933+
for(auto &v : src.variables())
934+
{
935+
if(first)
936+
first = false;
937+
else
938+
dest += ", ";
939+
940+
dest += convert(v) + "=" + convert(*values_it);
941+
++values_it;
942+
}
943+
944+
dest += " IN " + convert(src.where());
939945

940946
return dest;
941947
}

src/util/format_expr.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,26 @@ void format_expr_configt::setup()
369369
};
370370

371371
expr_map[ID_let] = [](std::ostream &os, const exprt &expr) -> std::ostream & {
372-
return os << "LET " << format(to_let_expr(expr).symbol()) << " = "
373-
<< format(to_let_expr(expr).value()) << " IN "
374-
<< format(to_let_expr(expr).where());
372+
const auto &let_expr = to_let_expr(expr);
373+
374+
os << "LET ";
375+
376+
bool first = true;
377+
378+
const auto &values = let_expr.values();
379+
auto values_it = values.begin();
380+
for(auto &v : let_expr.variables())
381+
{
382+
if(first)
383+
first = false;
384+
else
385+
os << ", ";
386+
387+
os << format(v) << " = " << format(*values_it);
388+
++values_it;
389+
}
390+
391+
return os << " IN " << format(let_expr.where());
375392
};
376393

377394
expr_map[ID_lambda] =

0 commit comments

Comments
 (0)