Commit | Line | Data |
---|---|---|
951c7801 C |
1 | (* |
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. | |
5 | * | |
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. | |
9 | * | |
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. | |
14 | * | |
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/>. | |
17 | * | |
18 | * The authors reserve the right to distribute this or future versions of | |
19 | * Coccinelle under other licenses. | |
20 | *) | |
21 | ||
22 | ||
23 | open Format | |
24 | module Past = Ast_popl | |
25 | module Ast = Ast_cocci | |
26 | ||
27 | let start_block str = | |
28 | force_newline(); print_string " "; open_box 0 | |
29 | ||
30 | let end_block str = | |
31 | close_box(); force_newline () | |
32 | ||
33 | (* --------------------------------------------------------------------- *) | |
34 | ||
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 | |
39 | | Ast.AFTER(aft,_) -> | |
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 | |
44 | ||
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 | |
52 | ||
53 | (* --------------------------------------------------------------------- *) | |
54 | ||
55 | let rec print_sequence = function | |
56 | Past.Seq(e,seq) -> print_element e; force_newline(); print_sequence seq | |
57 | | Past.Empty -> () | |
58 | | Past.SExists((_,v),seq) -> print_string "exists "; print_string v; | |
59 | print_string " ."; force_newline(); print_sequence seq | |
60 | ||
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 | |
68 | ||
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 ")" | |
74 | | Past.DInfo(dots) -> | |
75 | start_block(); | |
76 | print_dots dots; | |
77 | end_block() | |
78 | | Past.EExists((_,v),elem) -> print_string "exists "; print_string v; | |
79 | print_string " ."; force_newline(); print_element elem | |
80 | ||
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() | |
87 | ||
88 | (* --------------------------------------------------------------------- *) | |
89 | ||
90 | let pretty_print_e e = | |
91 | print_element e; | |
92 | print_newline() | |
93 | ||
94 | let pretty_print sl = | |
95 | print_sequence sl; | |
96 | print_newline() | |
97 |