aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-28 07:08:56 +0000
committerDavid Robillard <d@drobilla.net>2010-12-28 07:08:56 +0000
commit867601738b4fc9a8536a34112f43f33e1541e7fd (patch)
treecd93886fe757721c705c539d6049f9665741b6ae /src
parent1928afa8968b8bb5b921da52c0e845e42dde518b (diff)
downloadresp-867601738b4fc9a8536a34112f43f33e1541e7fd.tar.gz
resp-867601738b4fc9a8536a34112f43f33e1541e7fd.tar.bz2
resp-867601738b4fc9a8536a34112f43f33e1541e7fd.zip
Print type annotations for top-level expressions when -a is given.
git-svn-id: http://svn.drobilla.net/resp/resp@364 ad02d1e2-f140-0410-9f75-f8b11f17cedd
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;
}