Release coccinelle-0.2.0rc1
[bpt/coccinelle.git] / popl09 / pretty_print_popl.ml
1 open Format
2 module Past = Ast_popl
3 module Ast = Ast_cocci
4
5 let start_block str =
6 force_newline(); print_string " "; open_box 0
7
8 let end_block str =
9 close_box(); force_newline ()
10
11 (* --------------------------------------------------------------------- *)
12
13 let print_around printer term = function
14 Ast.NOTHING -> printer term
15 | Ast.BEFORE(bef,_) ->
16 Pretty_print_cocci.print_anything "<<< " bef; printer term
17 | Ast.AFTER(aft,_) ->
18 printer term; Pretty_print_cocci.print_anything ">>> " aft
19 | Ast.BEFOREAFTER(bef,aft,_) ->
20 Pretty_print_cocci.print_anything "<<< " bef; printer term;
21 Pretty_print_cocci.print_anything ">>> " aft
22
23 let mcode fn = function
24 (x, _, Ast.MINUS(_,_,_,plus_stream), pos) ->
25 print_string "-"; fn x;
26 Pretty_print_cocci.print_anything ">>> " plus_stream
27 | (x, _, Ast.CONTEXT(_,plus_streams), pos) ->
28 print_around fn x plus_streams
29 | (x, info, Ast.PLUS _, pos) -> fn x
30
31 (* --------------------------------------------------------------------- *)
32
33 let rec print_sequence = function
34 Past.Seq(e,seq) -> print_element e; force_newline(); print_sequence seq
35 | Past.Empty -> ()
36 | Past.SExists((_,v),seq) -> print_string "exists "; print_string v;
37 print_string " ."; force_newline(); print_sequence seq
38
39 and print_term = function
40 Past.Atomic(term) -> Pretty_print_cocci.rule_elem "" term
41 | Past.IfThen(test,thn,(_,_,_,aft)) ->
42 print_term test; print_term thn;
43 mcode (function _ -> ()) ((),Ast.no_info,aft,Ast.NoMetaPos)
44 | Past.TExists((_,v),term) -> print_string "exists "; print_string v;
45 print_string " ."; force_newline(); print_term term
46
47 and print_element = function
48 Past.Term(term,_) -> print_term term
49 | Past.Or(seq1,seq2) ->
50 force_newline(); print_string "("; force_newline(); print_sequence seq1;
51 print_string "|"; force_newline(); print_sequence seq2; print_string ")"
52 | Past.DInfo(dots) ->
53 start_block();
54 print_dots dots;
55 end_block()
56 | Past.EExists((_,v),elem) -> print_string "exists "; print_string v;
57 print_string " ."; force_newline(); print_element elem
58
59 and print_dots = function
60 Past.Dots -> print_string "..."
61 | Past.Nest(seq)-> print_string "<..."; start_block(); print_sequence seq;
62 end_block(); print_string "...>"
63 | Past.When(dots,seq) -> print_dots dots; print_string " when != ";
64 open_box 0; print_sequence seq; close_box()
65
66 (* --------------------------------------------------------------------- *)
67
68 let pretty_print_e e =
69 print_element e;
70 print_newline()
71
72 let pretty_print sl =
73 print_sequence sl;
74 print_newline()
75