2 * Copyright 2005-2009, 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 module Past
= Ast_popl
25 module Ast
= Ast_cocci
28 force_newline
(); print_string
" "; open_box
0
31 close_box
(); force_newline
()
33 (* --------------------------------------------------------------------- *)
35 let print_around printer term
= function
36 Ast.NOTHING
-> printer term
37 | Ast.BEFORE
(bef
,_
) ->
38 Pretty_print_cocci.print_anything
"<<< " bef
; printer term
40 printer term
; Pretty_print_cocci.print_anything
">>> " aft
41 | Ast.BEFOREAFTER
(bef
,aft
,_
) ->
42 Pretty_print_cocci.print_anything
"<<< " bef
; printer term
;
43 Pretty_print_cocci.print_anything
">>> " aft
45 let mcode fn
= function
46 (x
, _
, Ast.MINUS
(_
,_
,_
,plus_stream
), pos
) ->
47 print_string
"-"; fn x
;
48 Pretty_print_cocci.print_anything
">>> " plus_stream
49 | (x
, _
, Ast.CONTEXT
(_
,plus_streams
), pos
) ->
50 print_around fn x plus_streams
51 | (x
, info
, Ast.PLUS _
, pos
) -> fn x
53 (* --------------------------------------------------------------------- *)
55 let rec print_sequence = function
56 Past.Seq
(e
,seq
) -> print_element e
; force_newline
(); print_sequence seq
58 | Past.SExists
((_
,v
),seq
) -> print_string
"exists "; print_string v
;
59 print_string
" ."; force_newline
(); print_sequence seq
61 and print_term
= function
62 Past.Atomic
(term
) -> Pretty_print_cocci.rule_elem
"" term
63 | Past.IfThen
(test
,thn
,(_
,_
,_
,aft
)) ->
64 print_term test
; print_term thn
;
65 mcode (function _
-> ()) ((),Ast.no_info
,aft
,Ast.NoMetaPos
)
66 | Past.TExists
((_
,v
),term
) -> print_string
"exists "; print_string v
;
67 print_string
" ."; force_newline
(); print_term term
69 and print_element
= function
70 Past.Term
(term
,_
) -> print_term term
71 | Past.Or
(seq1
,seq2
) ->
72 force_newline
(); print_string
"("; force_newline
(); print_sequence seq1
;
73 print_string
"|"; force_newline
(); print_sequence seq2
; print_string
")"
78 | Past.EExists
((_
,v
),elem
) -> print_string
"exists "; print_string v
;
79 print_string
" ."; force_newline
(); print_element elem
81 and print_dots
= function
82 Past.Dots
-> print_string
"..."
83 | Past.Nest
(seq
)-> print_string
"<..."; start_block(); print_sequence seq
;
84 end_block(); print_string
"...>"
85 | Past.When
(dots
,seq
) -> print_dots dots
; print_string
" when != ";
86 open_box
0; print_sequence seq
; close_box
()
88 (* --------------------------------------------------------------------- *)
90 let pretty_print_e e
=