Release coccinelle-0.2.4
[bpt/coccinelle.git] / popl / pretty_print_popl.ml
CommitLineData
9bc82bae
C
1(*
2 * Copyright 2010, INRIA, University of Copenhagen
3 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
4 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
5 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
6 * This file is part of Coccinelle.
7 *
8 * Coccinelle is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, according to version 2 of the License.
11 *
12 * Coccinelle is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
22 *)
23
24
c491d8ee
C
25(*
26 * Copyright 2010, INRIA, University of Copenhagen
27 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
28 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
29 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
30 * This file is part of Coccinelle.
31 *
32 * Coccinelle is free software: you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation, according to version 2 of the License.
35 *
36 * Coccinelle is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details.
40 *
41 * You should have received a copy of the GNU General Public License
42 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
43 *
44 * The authors reserve the right to distribute this or future versions of
45 * Coccinelle under other licenses.
46 *)
47
48
951c7801
C
49open Format
50module Past = Ast_popl
51
52let start_block str =
53 force_newline(); print_string " "; open_box 0
54
55let end_block str =
56 close_box(); force_newline ()
57
58(* --------------------------------------------------------------------- *)
59
60let rec print_sequence = function
61 Past.Seq(e,seq) -> print_element e; force_newline(); print_sequence seq
62 | Past.Empty -> ()
63 | Past.SExists((_,v),seq) -> print_string "exists "; print_string v;
64 print_string " ."; force_newline(); print_sequence seq
65
66and print_element = function
67 Past.Term(term) -> Pretty_print_cocci.rule_elem "" term
68 | Past.Or(seq1,seq2) ->
69 force_newline(); print_string "("; force_newline(); print_sequence seq1;
70 print_string "|"; force_newline(); print_sequence seq2; print_string ")"
71 | Past.DInfo(dots,bef,aft) ->
72 start_block();
73 List.iter
74 (function b -> print_string ">>>"; print_element b; force_newline())
75 bef;
76 print_dots dots;
77 List.iter
78 (function b -> force_newline(); print_string "<<<"; print_element b)
79 aft;
80 end_block()
81 | Past.EExists((_,v),elem) -> print_string "exists "; print_string v;
82 print_string " ."; force_newline(); print_element elem
83
84and print_dots = function
85 Past.Dots -> print_string "..."
86 | Past.Nest(seq)-> print_string "<..."; start_block(); print_sequence seq;
87 end_block(); print_string "...>"
88 | Past.When(dots,seq) -> print_dots dots; print_string " when != ";
89 open_box 0; print_sequence seq; close_box()
90 | Past.DExists((_,v),dots) -> print_string "exists "; print_string v;
91 print_string " ."; force_newline(); print_dots dots
92
93(* --------------------------------------------------------------------- *)
94
95let pretty_print_e e =
96 print_element e;
97 print_newline()
98
99let pretty_print sl =
100 print_sequence sl;
101 print_newline()
102