aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pprint.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/pprint.cpp b/src/pprint.cpp
index ca2ee92..15e9f54 100644
--- a/src/pprint.cpp
+++ b/src/pprint.cpp
@@ -34,6 +34,13 @@ newline(ostream& out, unsigned indent)
out << " ";
}
+static inline void
+print_annotation(ostream& out, CEnv* cenv, const AST* ast, bool print)
+{
+ if (print)
+ out << " :" << cenv->tsubst.apply(cenv->tenv.var(ast));
+}
+
ostream&
print_list_one_line(ostream& out, const ATuple* tup, ATuple::const_iterator i,
unsigned indent, CEnv* cenv, bool types, bool elem_types)
@@ -43,8 +50,7 @@ print_list_one_line(ostream& out, const ATuple* tup, ATuple::const_iterator i,
++next;
print_to(out, *i, indent, cenv, types);
- if (elem_types)
- out << " :" << cenv->tsubst.apply(cenv->tenv.var(*i));
+ print_annotation(out, cenv, *i, elem_types);
if (next != tup->end())
out << " ";
@@ -116,13 +122,13 @@ print_to(ostream& out, const AST* ast, unsigned indent, CEnv* cenv, bool types)
out << " ";
if (form == "def") {
- out << (*i++) << " "; // Print symbol
+ out << (*i++); // Print symbol
unsigned child_indent = types ? indent + 2 : indent;
if (types) {
- out << ":" << cenv->type(tup->list_ref(2)) << " ";
+ print_annotation(out, cenv, tup->list_ref(2), true);
newline(out, child_indent);
}
-
+ out << " ";
print_to(out, (*i++), child_indent, cenv, types);
out << ")";
newline(out, 0);
@@ -151,8 +157,7 @@ print_to(ostream& out, const AST* ast, unsigned indent, CEnv* cenv, bool types)
const ATuple* vars = (*i)->as_tuple();
for (ATuple::const_iterator v = vars->begin(); v != vars->end();) {
out << (*v);
- if (types)
- out << " :" << cenv->tsubst.apply(cenv->tenv.var(*v));
+ print_annotation(out, cenv, *v, types);
out << " " << (*++v);
@@ -164,8 +169,7 @@ print_to(ostream& out, const AST* ast, unsigned indent, CEnv* cenv, bool types)
newline(out, indent + 2);
print_list(out, tup, tup->iter_at(2), indent + 2, cenv, types, false);
out << ")";
- if (types)
- out << " :" << cenv->tsubst.apply(cenv->tenv.var(tup->list_last()));
+ print_annotation(out, cenv, tup->list_last(), types);
} else if (form == "match") {
out << (*i++);
@@ -204,5 +208,6 @@ void
pprint(ostream& out, const AST* ast, CEnv* cenv, bool types)
{
print_to(out, ast, 0, cenv, types);
+ print_annotation(out, cenv, ast, types);
out << endl;
}