summaryrefslogtreecommitdiff
path: root/src/runtime/c/pgf/expr.c
diff options
context:
space:
mode:
authorkr.angelov <kr.angelov@gmail.com>2012-02-17 14:11:29 +0000
committerkr.angelov <kr.angelov@gmail.com>2012-02-17 14:11:29 +0000
commit4f8ad8c23f955b2d8df48ccfa1e8e8621483c3dc (patch)
treea8c09d62b2a7ba041c77f52c2f4461d3e389f414 /src/runtime/c/pgf/expr.c
parent21f657a64a8e286fd779a0fa4aae799342a0fcce (diff)
libpgf: added printer.c
Diffstat (limited to 'src/runtime/c/pgf/expr.c')
-rw-r--r--src/runtime/c/pgf/expr.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/runtime/c/pgf/expr.c b/src/runtime/c/pgf/expr.c
index cedb25989..6f2de5a6b 100644
--- a/src/runtime/c/pgf/expr.c
+++ b/src/runtime/c/pgf/expr.c
@@ -390,18 +390,38 @@ pgf_print_hypo(PgfHypo *hypo, int prec, GuWriter *wtr, GuExn *err)
void
pgf_print_type(PgfType *type, int prec, GuWriter *wtr, GuExn *err)
{
- size_t len = gu_seq_length(type->hypos);
- for (size_t i = 0; i < len; i++) {
- PgfHypo *hypo = gu_seq_index(type->hypos, PgfHypo, i);
- pgf_print_hypo(hypo, 1, wtr, err);
-
- gu_puts(" -> ", wtr, err);
- }
+ size_t n_hypos = gu_seq_length(type->hypos);
+
+ if (n_hypos > 0) {
+ if (prec > 0) gu_putc('(', wtr, err);
+
+ for (size_t i = 0; i < n_hypos; i++) {
+ PgfHypo *hypo = gu_seq_index(type->hypos, PgfHypo, i);
+ pgf_print_hypo(hypo, 1, wtr, err);
+
+ gu_puts(" -> ", wtr, err);
+ }
- gu_string_write(type->cid, wtr, err);
+ gu_string_write(type->cid, wtr, err);
- for (int i = 0; i < type->n_exprs; i++) {
- gu_puts(" ", wtr, err);
- pgf_print_expr(type->exprs[i], 4, wtr, err);
- }
+ for (int i = 0; i < type->n_exprs; i++) {
+ gu_puts(" ", wtr, err);
+ pgf_print_expr(type->exprs[i], 4, wtr, err);
+ }
+
+ if (prec > 0) gu_putc(')', wtr, err);
+ } else if (type->n_exprs > 0) {
+ if (prec > 3) gu_putc('(', wtr, err);
+
+ gu_string_write(type->cid, wtr, err);
+
+ for (int i = 0; i < type->n_exprs; i++) {
+ gu_puts(" ", wtr, err);
+ pgf_print_expr(type->exprs[i], 4, wtr, err);
+ }
+
+ if (prec > 3) gu_putc(')', wtr, err);
+ } else {
+ gu_string_write(type->cid, wtr, err);
+ }
}