Commit | Line | Data |
---|---|---|
9f8e26f4 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 | ||
34e49164 C |
23 | open Common.Infix |
24 | ||
25 | open Lib_engine | |
26 | ||
27 | ||
28 | let pp = Common.pp | |
29 | ||
30 | let pp_meta (_,x) = pp x | |
31 | ||
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) | |
978fd7e5 | 36 | | Ast_c.MetaExprVal expr -> Pretty_print_c.pp_expression_simple expr |
34e49164 | 37 | | Ast_c.MetaExprListVal expr_list -> pp "<<exprlist>>" |
113803cf C |
38 | | Ast_c.MetaInitVal ini -> |
39 | Pretty_print_c.pp_init_simple ini | |
34e49164 C |
40 | | Ast_c.MetaTypeVal typ -> |
41 | Pretty_print_c.pp_type_simple typ | |
42 | | Ast_c.MetaStmtVal statement -> | |
43 | Pretty_print_c.pp_statement_simple statement | |
44 | | Ast_c.MetaParamVal params -> pp "<<param>>" | |
45 | | Ast_c.MetaParamListVal params -> pp "<<paramlist>>" | |
46 | | Ast_c.MetaListlenVal n -> pp (string_of_int n) | |
47 | | Ast_c.MetaPosVal (pos1, pos2) -> | |
48 | let print_pos = function | |
49 | Ast_cocci.Real x -> string_of_int x | |
50 | | Ast_cocci.Virt(x,off) -> Printf.sprintf "%d+%d" x off in | |
51 | pp (Common.sprintf ("pos(%s,%s)") (print_pos pos1) (print_pos pos2)) | |
52 | | Ast_c.MetaPosValList l -> | |
53 | pp (Common.sprintf ("poss[%s]") | |
54 | (String.concat ", " | |
55 | (List.map | |
485bce71 C |
56 | (function (fl,ce,(minl,minc),(maxl,maxc)) -> |
57 | Printf.sprintf "(%s,%s,(%d,%d),(%d,%d))" | |
58 | fl ce minl minc maxl maxc) | |
34e49164 C |
59 | l))) |
60 | ||
61 | and pp_binding subst = | |
62 | begin | |
63 | pp "["; | |
64 | Common.print_between (fun () -> pp ";"; Format.print_cut() ) | |
65 | (fun ((_,s), kind) -> pp s; pp " --> "; pp_binding_kind kind) | |
66 | subst; | |
67 | pp "]"; | |
68 | end | |
69 | ||
70 | ||
71 | let pp_binding_kind2 = function | |
72 | | ParenVal s -> pp "pv("; pp_meta s; pp ")" | |
73 | | NormalMetaVal x -> pp_binding_kind x | |
7f004419 | 74 | | LabelVal (Absolute xs) -> |
34e49164 C |
75 | begin |
76 | pp "labelval"; | |
77 | pp "("; | |
78 | Common.print_between (fun () -> pp ",") Format.print_int xs; | |
79 | pp ")"; | |
80 | end | |
7f004419 C |
81 | | LabelVal (Prefix xs) -> |
82 | begin | |
83 | pp "prefixlabelval"; | |
84 | pp "("; | |
85 | Common.print_between (fun () -> pp ",") Format.print_int xs; | |
86 | pp ")"; | |
87 | end | |
34e49164 C |
88 | | GoodVal -> pp "goodval" |
89 | | BadVal -> pp "badval" | |
90 | ||
91 | ||
92 | let rec pp_predicate = function | |
93 | | InLoop -> pp "InLoop" | |
94 | | TrueBranch -> pp "TrueBranch" | |
95 | | FalseBranch -> pp "FalseBranch" | |
96 | | After -> pp "After" | |
97 | | FallThrough -> pp "FallThrough" | |
951c7801 | 98 | | LoopFallThrough -> pp "LoopFallThrough" |
34e49164 C |
99 | | Return -> pp "Return" |
100 | | FunHeader -> pp "FunHeader" | |
101 | | Top -> pp "Top" | |
102 | | ErrorExit -> pp "ErrorExit" | |
103 | | Exit -> pp "Exit" | |
104 | | Goto -> pp "Goto" | |
105 | | Paren s -> pp "Paren("; pp_meta s; pp ")" | |
106 | | Match (re) -> Pretty_print_cocci.print_rule_elem re | |
107 | | Label s -> pp "Label("; pp_meta s; pp ")" | |
108 | | BCLabel s -> pp "BreakContinueLabel("; pp_meta s; pp ")" | |
109 | | PrefixLabel s -> pp "PrefixLabel("; pp_meta s; pp ")" | |
110 | | BindGood s -> pp "BindGood("; pp_meta s; pp ")" | |
111 | | BindBad s -> pp "BindBad("; pp_meta s; pp ")" | |
112 | | FakeBrace -> pp "FakeBrace" | |
113 | ||
114 | and pp_binding2 subst = | |
115 | begin | |
116 | pp "["; | |
117 | Common.print_between (fun () -> pp ";";Format.print_cut(); ) | |
118 | (fun (s, kind) -> pp s; pp " --> "; pp_binding_kind2 kind) | |
119 | subst; | |
120 | pp "]"; | |
121 | end | |
122 | ||
123 | and pp_binding2_ctlsubst subst = | |
124 | begin | |
125 | pp "["; | |
126 | Common.print_between (fun () -> pp ";"; Format.print_cut(); ) | |
127 | (function | |
128 | Ast_ctl.Subst (s, kind) -> | |
129 | pp_meta s; pp " --> "; pp_binding_kind2 kind; | |
130 | | Ast_ctl.NegSubst (s, kind) -> | |
131 | pp_meta s; pp " -/-> "; pp_binding_kind2 kind; | |
132 | ) | |
133 | subst; | |
134 | pp "]"; | |
135 | end | |
136 | ||
137 | let predicate_to_string pred = | |
138 | Common.format_to_string (function _ -> pp_predicate pred) | |
139 | ||
140 | ||
141 | let pp_pred_smodif = fun (pred, smodif) -> | |
142 | begin | |
143 | pp_predicate pred; | |
144 | (* | |
145 | (match smodif with | |
146 | | Ast_ctl.Modif x | Ast_ctl.UnModif x -> pp " with <modifTODO>" | |
147 | | Ast_ctl.Control -> () | |
148 | ) | |
149 | *) | |
150 | end | |
151 | ||
152 | ||
153 | let pp_ctlcocci show_plus inline_let_def ctl = | |
154 | begin | |
155 | if show_plus | |
156 | then begin | |
157 | Pretty_print_cocci.print_plus_flag := true; | |
158 | Pretty_print_cocci.print_minus_flag := true; | |
159 | end | |
160 | else begin | |
161 | Pretty_print_cocci.print_plus_flag := false; | |
162 | Pretty_print_cocci.print_minus_flag := false; | |
163 | end; | |
164 | Common.pp_do_in_box (fun () -> | |
165 | Pretty_print_ctl.pp_ctl (pp_pred_smodif,(fun s -> pp_meta s)) | |
166 | inline_let_def ctl; | |
167 | ); | |
168 | end | |
169 | ||
170 |