| 1 | (* |
| 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. |
| 9 | * |
| 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. |
| 13 | * |
| 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. |
| 18 | * |
| 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/>. |
| 21 | * |
| 22 | * The authors reserve the right to distribute this or future versions of |
| 23 | * Coccinelle under other licenses. |
| 24 | *) |
| 25 | |
| 26 | |
| 27 | open Format |
| 28 | module Past = Ast_popl |
| 29 | |
| 30 | let start_block str = |
| 31 | force_newline(); print_string " "; open_box 0 |
| 32 | |
| 33 | let end_block str = |
| 34 | close_box(); force_newline () |
| 35 | |
| 36 | (* --------------------------------------------------------------------- *) |
| 37 | |
| 38 | let rec print_sequence = function |
| 39 | Past.Seq(e,seq) -> print_element e; force_newline(); print_sequence seq |
| 40 | | Past.Empty -> () |
| 41 | | Past.SExists((_,v),seq) -> print_string "exists "; print_string v; |
| 42 | print_string " ."; force_newline(); print_sequence seq |
| 43 | |
| 44 | and print_element = function |
| 45 | Past.Term(term) -> Pretty_print_cocci.rule_elem "" term |
| 46 | | Past.Or(seq1,seq2) -> |
| 47 | force_newline(); print_string "("; force_newline(); print_sequence seq1; |
| 48 | print_string "|"; force_newline(); print_sequence seq2; print_string ")" |
| 49 | | Past.DInfo(dots,bef,aft) -> |
| 50 | start_block(); |
| 51 | List.iter |
| 52 | (function b -> print_string ">>>"; print_element b; force_newline()) |
| 53 | bef; |
| 54 | print_dots dots; |
| 55 | List.iter |
| 56 | (function b -> force_newline(); print_string "<<<"; print_element b) |
| 57 | aft; |
| 58 | end_block() |
| 59 | | Past.EExists((_,v),elem) -> print_string "exists "; print_string v; |
| 60 | print_string " ."; force_newline(); print_element elem |
| 61 | |
| 62 | and print_dots = function |
| 63 | Past.Dots -> print_string "..." |
| 64 | | Past.Nest(seq)-> print_string "<..."; start_block(); print_sequence seq; |
| 65 | end_block(); print_string "...>" |
| 66 | | Past.When(dots,seq) -> print_dots dots; print_string " when != "; |
| 67 | open_box 0; print_sequence seq; close_box() |
| 68 | | Past.DExists((_,v),dots) -> print_string "exists "; print_string v; |
| 69 | print_string " ."; force_newline(); print_dots dots |
| 70 | |
| 71 | (* --------------------------------------------------------------------- *) |
| 72 | |
| 73 | let pretty_print_e e = |
| 74 | print_element e; |
| 75 | print_newline() |
| 76 | |
| 77 | let pretty_print sl = |
| 78 | print_sequence sl; |
| 79 | print_newline() |
| 80 | |