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.
28 (* todo?: a txt_to_latex, that use Format to compute the good space but
29 * then generate latex to better output.
33 let char_and_any = "&+"
46 (* need introduce the Val constructor, or use -rectype. *)
47 type ('a
,'b
,'c
) environment
= (string, ('a
,'b
,'c
) binding_val
) Common.assoc
48 and ('a
, 'b
, 'c
) binding_val
=
49 Val
of ('a
,'b
,'c
) generic_ctl
* ('a
,'b
,'c
) environment
52 ('pred
-> unit) * ('mvar
-> unit) -> bool ->
53 ('pred
, 'mvar
, 'info
) generic_ctl
->
55 fun (pp_pred
, pp_mvar
) inline_let_def ctl
->
57 let rec pp_aux env
= function
60 | Pred
(p
) -> pp_pred p
62 pp
char_not; Common.pp_do_in_box
(fun () -> pp_aux env phi
)
63 | Exists
(keep
,v
,phi
) ->
65 if keep
then pp
("Ex ") else pp
("Ex_ ");
69 Common.pp_do_in_box
(fun () -> pp_aux env phi
);
71 | AndAny
(dir
,s
,phi1
,phi2
) ->
72 pp_2args env
(char_and_any^
(pp_dirc dir
)^
(pp_sc s
)) phi1 phi2
;
73 | HackForStmt
(dir
,s
,phi1
,phi2
) ->
74 pp_2args env
(char_hack^
(pp_dirc dir
)^
(pp_sc s
)) phi1 phi2
;
75 | And
(s
,phi1
,phi2
) -> pp_2args env
(char_and^
(pp_sc s
)) phi1 phi2
;
76 | Or
(phi1
,phi2
) -> pp_2args env
char_or phi1 phi2
;
77 | SeqOr
(phi1
,phi2
) -> pp_2args env
char_seqor phi1 phi2
;
78 | Implies
(phi1
,phi2
) -> pp_2args env
"=>" phi1 phi2
;
79 | AF
(dir
,s
,phi1
) -> pp
"AF"; pp_dir dir
; pp_s s
; pp_arg_paren env phi1
;
80 | AX
(dir
,s
,phi1
) -> pp
"AX"; pp_dir dir
; pp_s s
; pp_arg_paren env phi1
;
81 | AG
(dir
,s
,phi1
) -> pp
"AG"; pp_dir dir
; pp_s s
; pp_arg_paren env phi1
;
82 | EF
(dir
,phi1
) -> pp
"EF"; pp_dir dir
; pp_arg_paren env phi1
;
83 | EX
(dir
,phi1
) -> pp
"EX"; pp_dir dir
; pp_arg_paren env phi1
;
84 | EG
(dir
,phi1
) -> pp
"EG"; pp_dir dir
; pp_arg_paren env phi1
;
85 | AW
(dir
,s
,phi1
,phi2
) ->
86 pp
"A"; pp_dir dir
; pp_s s
; pp
"[";
87 pp_2args_bis env
"W" phi1 phi2
;
89 | AU
(dir
,s
,phi1
,phi2
) ->
90 pp
"A"; pp_dir dir
; pp_s s
; pp
"[";
91 pp_2args_bis env
"U" phi1 phi2
;
93 | EU
(dir
,phi1
,phi2
) ->
94 pp
"E"; pp_dir dir
; pp
"[";
95 pp_2args_bis env
"U" phi1 phi2
;
97 | Let
(x
,phi1
,phi2
) ->
98 let env'
= (x
, (Val
(phi1
,env)))::env in
100 if not inline_let_def
106 Common.pp_do_in_box
(fun () -> pp_aux env phi1
);
111 pp_do_in_zero_box
(fun () -> pp_aux env' phi2
);
112 | LetR
(dir
,x
,phi1
,phi2
) ->
113 let env'
= (x
, (Val
(phi1
,env)))::env in
115 if not inline_let_def
118 pp
("LetR"^
" "^x
); pp_dir dir
;
121 Common.pp_do_in_box
(fun () -> pp_aux env phi1
);
126 pp_do_in_zero_box
(fun () -> pp_aux env' phi2
);
130 let Val (phi1
,env'
) = List.assoc s
env in
137 pp
"Uncheck"; pp_arg_paren
env phi1
139 pp
"InnerAnd"; pp_arg_paren
env phi1
140 | XX _
-> failwith
"should be removed"
142 and pp_dir
= function
144 | BACKWARD
-> pp
char_back
146 and pp_dirc
= function
148 | BACKWARD
-> char_back
151 STRICT
-> if !Flag_ctl.partial_match
then pp
"," else ()
158 and pp_2args
env sym phi1 phi2
=
161 Common.pp_do_in_box
(fun () -> pp_aux env phi1
);
165 Common.pp_do_in_box
(fun () -> pp_aux env phi2
);
168 and pp_2args_bis
env sym phi1 phi2
=
170 Common.pp_do_in_box
(fun () -> pp_aux env phi1
);
174 Common.pp_do_in_box
(fun () -> pp_aux env phi2
);
177 and pp_arg_paren
env phi
= Common.pp_do_in_box
(fun () ->
183 Common.pp_do_in_box
(fun () -> pp_aux [] ctl
;)