2 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller
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.
30 let pp_meta (_,x) = pp x
32 let rec pp_binding_kind = function
33 | Ast_c.MetaIdVal s -> pp ("id " ^ s)
34 | Ast_c.MetaFuncVal s -> pp ("func " ^ s)
35 | Ast_c.MetaLocalFuncVal s -> pp ("localfunc " ^ s)
36 | Ast_c.MetaExprVal expr ->
37 Pretty_print_c.pp_expression_simple expr
38 | Ast_c.MetaExprListVal expr_list -> pp "<<exprlist>>"
39 | Ast_c.MetaTypeVal typ ->
40 Pretty_print_c.pp_type_simple typ
41 | Ast_c.MetaStmtVal statement ->
42 Pretty_print_c.pp_statement_simple statement
43 | Ast_c.MetaParamVal params -> pp "<<param>>"
44 | Ast_c.MetaParamListVal params -> pp "<<paramlist>>"
45 | Ast_c.MetaListlenVal n -> pp (string_of_int n)
46 | Ast_c.MetaPosVal (pos1, pos2) ->
47 let print_pos = function
48 Ast_cocci.Real x -> string_of_int x
49 | Ast_cocci.Virt(x,off) -> Printf.sprintf "%d+%d" x off in
50 pp (Common.sprintf ("pos(%s,%s)") (print_pos pos1) (print_pos pos2))
51 | Ast_c.MetaPosValList l ->
52 pp (Common.sprintf ("poss[%s]")
55 (function (fl,ce,(minl,minc),(maxl,maxc)) ->
56 Printf.sprintf "(%s,%s,(%d,%d),(%d,%d))"
57 fl ce minl minc maxl maxc)
60 and pp_binding subst =
63 Common.print_between (fun () -> pp ";"; Format.print_cut() )
64 (fun ((_,s), kind) -> pp s; pp " --> "; pp_binding_kind kind)
70 let pp_binding_kind2 = function
71 | ParenVal s -> pp "pv("; pp_meta s; pp ")"
72 | NormalMetaVal x -> pp_binding_kind x
77 Common.print_between (fun () -> pp ",") Format.print_int xs;
80 | GoodVal -> pp "goodval"
81 | BadVal -> pp "badval"
84 let rec pp_predicate = function
85 | InLoop -> pp "InLoop"
86 | TrueBranch -> pp "TrueBranch"
87 | FalseBranch -> pp "FalseBranch"
89 | FallThrough -> pp "FallThrough"
90 | Return -> pp "Return"
91 | FunHeader -> pp "FunHeader"
93 | ErrorExit -> pp "ErrorExit"
96 | Paren s -> pp "Paren("; pp_meta s; pp ")"
97 | Match (re) -> Pretty_print_cocci.print_rule_elem re
98 | Label s -> pp "Label("; pp_meta s; pp ")"
99 | BCLabel s -> pp "BreakContinueLabel("; pp_meta s; pp ")"
100 | PrefixLabel s -> pp "PrefixLabel("; pp_meta s; pp ")"
101 | BindGood s -> pp "BindGood("; pp_meta s; pp ")"
102 | BindBad s -> pp "BindBad("; pp_meta s; pp ")"
103 | FakeBrace -> pp "FakeBrace"
105 and pp_binding2 subst =
108 Common.print_between (fun () -> pp ";";Format.print_cut(); )
109 (fun (s, kind) -> pp s; pp " --> "; pp_binding_kind2 kind)
114 and pp_binding2_ctlsubst subst =
117 Common.print_between (fun () -> pp ";"; Format.print_cut(); )
119 Ast_ctl.Subst (s, kind) ->
120 pp_meta s; pp " --> "; pp_binding_kind2 kind;
121 | Ast_ctl.NegSubst (s, kind) ->
122 pp_meta s; pp " -/-> "; pp_binding_kind2 kind;
128 let predicate_to_string pred =
129 Common.format_to_string (function _ -> pp_predicate pred)
132 let pp_pred_smodif = fun (pred, smodif) ->
137 | Ast_ctl.Modif x | Ast_ctl.UnModif x -> pp " with <modifTODO>"
138 | Ast_ctl.Control -> ()
144 let pp_ctlcocci show_plus inline_let_def ctl =
148 Pretty_print_cocci.print_plus_flag := true;
149 Pretty_print_cocci.print_minus_flag := true;
152 Pretty_print_cocci.print_plus_flag := false;
153 Pretty_print_cocci.print_minus_flag := false;
155 Common.pp_do_in_box (fun () ->
156 Pretty_print_ctl.pp_ctl (pp_pred_smodif,(fun s -> pp_meta s))