2 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
4 * This file is part of Coccinelle.
6 * Coccinelle is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, according to version 2 of the License.
10 * Coccinelle is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
24 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
25 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
26 * This file is part of Coccinelle.
28 * Coccinelle is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, according to version 2 of the License.
32 * Coccinelle is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
40 * The authors reserve the right to distribute this or future versions of
41 * Coccinelle under other licenses.
50 (* todo?: a txt_to_latex, that use Format to compute the good space but
51 * then generate latex to better output.
55 let char_and_any = "&+"
68 (* need introduce the Val constructor, or use -rectype. *)
69 type ('a
,'b
,'c
) environment
= (string, ('a
,'b
,'c
) binding_val
) Common.assoc
70 and ('a
, 'b
, 'c
) binding_val
=
71 Val
of ('a
,'b
,'c
) generic_ctl
* ('a
,'b
,'c
) environment
74 ('pred
-> unit) * ('mvar
-> unit) -> bool ->
75 ('pred
, 'mvar
, 'info
) generic_ctl
->
77 fun (pp_pred
, pp_mvar
) inline_let_def ctl
->
79 let rec pp_aux env
= function
82 | Pred
(p
) -> pp_pred p
84 pp
char_not; Common.pp_do_in_box
(fun () -> pp_aux env phi
)
85 | Exists
(keep
,v
,phi
) ->
87 if keep
then pp
("Ex ") else pp
("Ex_ ");
91 Common.pp_do_in_box
(fun () -> pp_aux env phi
);
93 | AndAny
(dir
,s
,phi1
,phi2
) ->
94 pp_2args env
(char_and_any^
(pp_dirc dir
)^
(pp_sc s
)) phi1 phi2
;
95 | HackForStmt
(dir
,s
,phi1
,phi2
) ->
96 pp_2args env
(char_hack^
(pp_dirc dir
)^
(pp_sc s
)) phi1 phi2
;
97 | And
(s
,phi1
,phi2
) -> pp_2args env
(char_and^
(pp_sc s
)) phi1 phi2
;
98 | Or
(phi1
,phi2
) -> pp_2args env
char_or phi1 phi2
;
99 | SeqOr
(phi1
,phi2
) -> pp_2args env
char_seqor phi1 phi2
;
100 | Implies
(phi1
,phi2
) -> pp_2args env
"=>" phi1 phi2
;
101 | AF
(dir
,s
,phi1
) -> pp
"AF"; pp_dir dir
; pp_s s
; pp_arg_paren env phi1
;
102 | AX
(dir
,s
,phi1
) -> pp
"AX"; pp_dir dir
; pp_s s
; pp_arg_paren env phi1
;
103 | AG
(dir
,s
,phi1
) -> pp
"AG"; pp_dir dir
; pp_s s
; pp_arg_paren env phi1
;
104 | EF
(dir
,phi1
) -> pp
"EF"; pp_dir dir
; pp_arg_paren env phi1
;
105 | EX
(dir
,phi1
) -> pp
"EX"; pp_dir dir
; pp_arg_paren env phi1
;
106 | EG
(dir
,phi1
) -> pp
"EG"; pp_dir dir
; pp_arg_paren env phi1
;
107 | AW
(dir
,s
,phi1
,phi2
) ->
108 pp
"A"; pp_dir dir
; pp_s s
; pp
"[";
109 pp_2args_bis env
"W" phi1 phi2
;
111 | AU
(dir
,s
,phi1
,phi2
) ->
112 pp
"A"; pp_dir dir
; pp_s s
; pp
"[";
113 pp_2args_bis env
"U" phi1 phi2
;
115 | EU
(dir
,phi1
,phi2
) ->
116 pp
"E"; pp_dir dir
; pp
"[";
117 pp_2args_bis env
"U" phi1 phi2
;
119 | Let
(x
,phi1
,phi2
) ->
120 let env'
= (x
, (Val
(phi1
,env)))::env in
122 if not inline_let_def
128 Common.pp_do_in_box
(fun () -> pp_aux env phi1
);
133 pp_do_in_zero_box
(fun () -> pp_aux env' phi2
);
134 | LetR
(dir
,x
,phi1
,phi2
) ->
135 let env'
= (x
, (Val
(phi1
,env)))::env in
137 if not inline_let_def
140 pp
("LetR"^
" "^x
); pp_dir dir
;
143 Common.pp_do_in_box
(fun () -> pp_aux env phi1
);
148 pp_do_in_zero_box
(fun () -> pp_aux env' phi2
);
152 let Val (phi1
,env'
) = List.assoc s
env in
159 pp
"Uncheck"; pp_arg_paren
env phi1
161 pp
"InnerAnd"; pp_arg_paren
env phi1
162 | XX _
-> failwith
"should be removed"
164 and pp_dir
= function
166 | BACKWARD
-> pp
char_back
168 and pp_dirc
= function
170 | BACKWARD
-> char_back
173 STRICT
-> if !Flag_ctl.partial_match
then pp
"," else ()
180 and pp_2args
env sym phi1 phi2
=
183 Common.pp_do_in_box
(fun () -> pp_aux env phi1
);
187 Common.pp_do_in_box
(fun () -> pp_aux env phi2
);
190 and pp_2args_bis
env sym phi1 phi2
=
192 Common.pp_do_in_box
(fun () -> pp_aux env phi1
);
196 Common.pp_do_in_box
(fun () -> pp_aux env phi2
);
199 and pp_arg_paren
env phi
= Common.pp_do_in_box
(fun () ->
205 Common.pp_do_in_box
(fun () -> pp_aux [] ctl
;)