Commit | Line | Data |
---|---|---|
9f8e26f4 | 1 | (* |
ae4735db | 2 | * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen |
9f8e26f4 C |
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 | ||
5636bb2c C |
23 | (* |
24 | * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen | |
25 | * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix | |
26 | * This file is part of Coccinelle. | |
27 | * | |
28 | * Coccinelle is free software: you can redistribute it and/or modify | |
29 | * it under the terms of the GNU General Public License as published by | |
30 | * the Free Software Foundation, according to version 2 of the License. | |
31 | * | |
32 | * Coccinelle is distributed in the hope that it will be useful, | |
33 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
34 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
35 | * GNU General Public License for more details. | |
36 | * | |
37 | * You should have received a copy of the GNU General Public License | |
38 | * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>. | |
39 | * | |
40 | * The authors reserve the right to distribute this or future versions of | |
41 | * Coccinelle under other licenses. | |
42 | *) | |
43 | ||
44 | ||
34e49164 C |
45 | open Common.Infix |
46 | ||
47 | open Lib_engine | |
48 | ||
49 | ||
ae4735db | 50 | let pp = Common.pp |
34e49164 C |
51 | |
52 | let pp_meta (_,x) = pp x | |
53 | ||
54 | let rec pp_binding_kind = function | |
5636bb2c | 55 | | Ast_c.MetaIdVal (s,_) -> pp ("id " ^ s) |
34e49164 C |
56 | | Ast_c.MetaFuncVal s -> pp ("func " ^ s) |
57 | | Ast_c.MetaLocalFuncVal s -> pp ("localfunc " ^ s) | |
5636bb2c | 58 | | Ast_c.MetaExprVal (expr,_) -> Pretty_print_c.pp_expression_simple expr |
34e49164 | 59 | | Ast_c.MetaExprListVal expr_list -> pp "<<exprlist>>" |
ae4735db | 60 | | Ast_c.MetaInitVal ini -> |
113803cf | 61 | Pretty_print_c.pp_init_simple ini |
ae4735db | 62 | | Ast_c.MetaTypeVal typ -> |
34e49164 | 63 | Pretty_print_c.pp_type_simple typ |
ae4735db | 64 | | Ast_c.MetaStmtVal statement -> |
34e49164 C |
65 | Pretty_print_c.pp_statement_simple statement |
66 | | Ast_c.MetaParamVal params -> pp "<<param>>" | |
67 | | Ast_c.MetaParamListVal params -> pp "<<paramlist>>" | |
68 | | Ast_c.MetaListlenVal n -> pp (string_of_int n) | |
69 | | Ast_c.MetaPosVal (pos1, pos2) -> | |
70 | let print_pos = function | |
71 | Ast_cocci.Real x -> string_of_int x | |
72 | | Ast_cocci.Virt(x,off) -> Printf.sprintf "%d+%d" x off in | |
73 | pp (Common.sprintf ("pos(%s,%s)") (print_pos pos1) (print_pos pos2)) | |
ae4735db | 74 | | Ast_c.MetaPosValList l -> |
34e49164 C |
75 | pp (Common.sprintf ("poss[%s]") |
76 | (String.concat ", " | |
77 | (List.map | |
485bce71 C |
78 | (function (fl,ce,(minl,minc),(maxl,maxc)) -> |
79 | Printf.sprintf "(%s,%s,(%d,%d),(%d,%d))" | |
80 | fl ce minl minc maxl maxc) | |
34e49164 C |
81 | l))) |
82 | ||
ae4735db | 83 | and pp_binding subst = |
34e49164 C |
84 | begin |
85 | pp "["; | |
ae4735db | 86 | Common.print_between (fun () -> pp ";"; Format.print_cut() ) |
aa721442 C |
87 | (fun ((r,s), kind) -> |
88 | pp r; pp "."; pp s; pp " --> "; pp_binding_kind kind) | |
34e49164 C |
89 | subst; |
90 | pp "]"; | |
91 | end | |
92 | ||
93 | ||
94 | let pp_binding_kind2 = function | |
95 | | ParenVal s -> pp "pv("; pp_meta s; pp ")" | |
96 | | NormalMetaVal x -> pp_binding_kind x | |
ae4735db | 97 | | LabelVal (Absolute xs) -> |
34e49164 C |
98 | begin |
99 | pp "labelval"; | |
100 | pp "("; | |
101 | Common.print_between (fun () -> pp ",") Format.print_int xs; | |
102 | pp ")"; | |
103 | end | |
ae4735db | 104 | | LabelVal (Prefix xs) -> |
7f004419 C |
105 | begin |
106 | pp "prefixlabelval"; | |
107 | pp "("; | |
108 | Common.print_between (fun () -> pp ",") Format.print_int xs; | |
109 | pp ")"; | |
110 | end | |
34e49164 C |
111 | | GoodVal -> pp "goodval" |
112 | | BadVal -> pp "badval" | |
113 | ||
ae4735db C |
114 | |
115 | let rec pp_predicate = function | |
34e49164 C |
116 | | InLoop -> pp "InLoop" |
117 | | TrueBranch -> pp "TrueBranch" | |
118 | | FalseBranch -> pp "FalseBranch" | |
119 | | After -> pp "After" | |
120 | | FallThrough -> pp "FallThrough" | |
951c7801 | 121 | | LoopFallThrough -> pp "LoopFallThrough" |
34e49164 C |
122 | | Return -> pp "Return" |
123 | | FunHeader -> pp "FunHeader" | |
124 | | Top -> pp "Top" | |
125 | | ErrorExit -> pp "ErrorExit" | |
126 | | Exit -> pp "Exit" | |
127 | | Goto -> pp "Goto" | |
128 | | Paren s -> pp "Paren("; pp_meta s; pp ")" | |
129 | | Match (re) -> Pretty_print_cocci.print_rule_elem re | |
130 | | Label s -> pp "Label("; pp_meta s; pp ")" | |
131 | | BCLabel s -> pp "BreakContinueLabel("; pp_meta s; pp ")" | |
132 | | PrefixLabel s -> pp "PrefixLabel("; pp_meta s; pp ")" | |
133 | | BindGood s -> pp "BindGood("; pp_meta s; pp ")" | |
134 | | BindBad s -> pp "BindBad("; pp_meta s; pp ")" | |
135 | | FakeBrace -> pp "FakeBrace" | |
136 | ||
ae4735db | 137 | and pp_binding2 subst = |
34e49164 C |
138 | begin |
139 | pp "["; | |
ae4735db | 140 | Common.print_between (fun () -> pp ";";Format.print_cut(); ) |
34e49164 C |
141 | (fun (s, kind) -> pp s; pp " --> "; pp_binding_kind2 kind) |
142 | subst; | |
143 | pp "]"; | |
144 | end | |
145 | ||
ae4735db | 146 | and pp_binding2_ctlsubst subst = |
34e49164 C |
147 | begin |
148 | pp "["; | |
ae4735db | 149 | Common.print_between (fun () -> pp ";"; Format.print_cut(); ) |
34e49164 C |
150 | (function |
151 | Ast_ctl.Subst (s, kind) -> | |
152 | pp_meta s; pp " --> "; pp_binding_kind2 kind; | |
153 | | Ast_ctl.NegSubst (s, kind) -> | |
154 | pp_meta s; pp " -/-> "; pp_binding_kind2 kind; | |
155 | ) | |
156 | subst; | |
157 | pp "]"; | |
158 | end | |
159 | ||
160 | let predicate_to_string pred = | |
161 | Common.format_to_string (function _ -> pp_predicate pred) | |
162 | ||
163 | ||
ae4735db | 164 | let pp_pred_smodif = fun (pred, smodif) -> |
34e49164 C |
165 | begin |
166 | pp_predicate pred; | |
167 | (* | |
168 | (match smodif with | |
169 | | Ast_ctl.Modif x | Ast_ctl.UnModif x -> pp " with <modifTODO>" | |
170 | | Ast_ctl.Control -> () | |
171 | ) | |
172 | *) | |
173 | end | |
174 | ||
175 | ||
ae4735db | 176 | let pp_ctlcocci show_plus inline_let_def ctl = |
34e49164 | 177 | begin |
ae4735db | 178 | if show_plus |
34e49164 C |
179 | then begin |
180 | Pretty_print_cocci.print_plus_flag := true; | |
181 | Pretty_print_cocci.print_minus_flag := true; | |
182 | end | |
183 | else begin | |
184 | Pretty_print_cocci.print_plus_flag := false; | |
185 | Pretty_print_cocci.print_minus_flag := false; | |
186 | end; | |
ae4735db | 187 | Common.pp_do_in_box (fun () -> |
34e49164 C |
188 | Pretty_print_ctl.pp_ctl (pp_pred_smodif,(fun s -> pp_meta s)) |
189 | inline_let_def ctl; | |
190 | ); | |
191 | end | |
192 | ||
193 |