2 * Copyright 2010-2011 INRIA Saclay
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
11 #include "pet_printer.h"
14 static void print_pet_expr_help(FILE *out
, struct pet_expr
*expr
, int outer
,
15 void (*print_access_fn
)(struct pet_expr
*expr
, void *usr
), void *usr
)
21 fprintf(out
, "%g", expr
->d
);
24 print_access_fn(expr
, usr
);
29 fprintf(out
, " %s ", pet_op_str(expr
->op
));
30 print_pet_expr_help(out
, expr
->args
[pet_un_arg
], 0,
31 print_access_fn
, usr
);
38 print_pet_expr_help(out
, expr
->args
[pet_bin_lhs
], 0,
39 print_access_fn
, usr
);
40 fprintf(out
, " %s ", pet_op_str(expr
->op
));
41 print_pet_expr_help(out
, expr
->args
[pet_bin_rhs
], 0,
42 print_access_fn
, usr
);
46 case pet_expr_ternary
:
49 print_pet_expr_help(out
, expr
->args
[pet_ter_cond
], 0,
50 print_access_fn
, usr
);
52 print_pet_expr_help(out
, expr
->args
[pet_ter_true
], 0,
53 print_access_fn
, usr
);
55 print_pet_expr_help(out
, expr
->args
[pet_ter_false
], 0,
56 print_access_fn
, usr
);
61 fprintf(out
, "%s(", expr
->name
);
62 for (i
= 0; i
< expr
->n_arg
; ++i
) {
65 print_pet_expr_help(out
, expr
->args
[i
], 1,
66 print_access_fn
, usr
);
72 void print_pet_expr(FILE *out
, struct pet_expr
*expr
,
73 void(*print_access
)(struct pet_expr
*expr
, void *usr
), void *usr
)
75 print_pet_expr_help(out
, expr
, 1, print_access
, usr
);