2 * Copyright 2012, INRIA
3 * Julia Lawall, Gilles Muller
4 * Copyright 2010-2011, INRIA, University of Copenhagen
5 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
6 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
7 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
8 * This file is part of Coccinelle.
10 * Coccinelle is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, according to version 2 of the License.
14 * Coccinelle is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
22 * The authors reserve the right to distribute this or future versions of
23 * Coccinelle under other licenses.
28 module Past
= Ast_popl
29 module Ast
= Ast_cocci
32 force_newline
(); print_string
" "; open_box
0
35 close_box
(); force_newline
()
37 (* --------------------------------------------------------------------- *)
39 let print_around printer term
= function
40 Ast.NOTHING
-> printer term
41 | Ast.BEFORE
(bef
,_
) ->
42 Pretty_print_cocci.print_anything
"<<< " bef
; printer term
44 printer term
; Pretty_print_cocci.print_anything
">>> " aft
45 | Ast.BEFOREAFTER
(bef
,aft
,_
) ->
46 Pretty_print_cocci.print_anything
"<<< " bef
; printer term
;
47 Pretty_print_cocci.print_anything
">>> " aft
49 let mcode fn
= function
50 (x
, _
, Ast.MINUS
(_
,_
,_
,plus_stream
), pos
) ->
51 print_string
"-"; fn x
;
52 (match plus_stream
with
53 Ast.NOREPLACEMENT
-> ()
54 | Ast.REPLACEMENT
(plus_stream
,_
) ->
55 Pretty_print_cocci.print_anything
">>> " plus_stream
)
56 | (x
, _
, Ast.CONTEXT
(_
,plus_streams
), pos
) ->
57 print_around fn x plus_streams
58 | (x
, info
, Ast.PLUS _
, pos
) -> fn x
60 (* --------------------------------------------------------------------- *)
62 let rec print_sequence = function
63 Past.Seq
(e
,seq
) -> print_element e
; force_newline
(); print_sequence seq
65 | Past.SExists
((_
,v
),seq
) -> print_string
"exists "; print_string v
;
66 print_string
" ."; force_newline
(); print_sequence seq
68 and print_term
= function
69 Past.Atomic
(term
) -> Pretty_print_cocci.rule_elem
"" term
70 | Past.IfThen
(test
,thn
,(_
,_
,_
,aft
)) ->
71 print_term test
; print_term thn
;
72 mcode (function _
-> ()) ((),Ast.no_info
,aft
,[])
73 | Past.TExists
((_
,v
),term
) -> print_string
"exists "; print_string v
;
74 print_string
" ."; force_newline
(); print_term term
76 and print_element
= function
77 Past.Term
(term
,_
) -> print_term term
78 | Past.Or
(seq1
,seq2
) ->
79 force_newline
(); print_string
"("; force_newline
(); print_sequence seq1
;
80 print_string
"|"; force_newline
(); print_sequence seq2
; print_string
")"
85 | Past.EExists
((_
,v
),elem
) -> print_string
"exists "; print_string v
;
86 print_string
" ."; force_newline
(); print_element elem
88 and print_dots
= function
89 Past.Dots
-> print_string
"..."
90 | Past.Nest
(seq
)-> print_string
"<..."; start_block(); print_sequence seq
;
91 end_block(); print_string
"...>"
92 | Past.When
(dots
,seq
) -> print_dots dots
; print_string
" when != ";
93 open_box
0; print_sequence seq
; close_box
()
95 (* --------------------------------------------------------------------- *)
97 let pretty_print_e e
=
101 let pretty_print sl
=