Commit | Line | Data |
---|---|---|
34e49164 C |
1 | (* |
2 | * Copyright 2005-2008, 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. | |
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 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) | |
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]") | |
53 | (String.concat ", " | |
54 | (List.map | |
55 | (function (fl,(minl,minc),(maxl,maxc)) -> | |
56 | Printf.sprintf "(%s,(%d,%d),(%d,%d))" | |
57 | fl minl minc maxl maxc) | |
58 | l))) | |
59 | ||
60 | and pp_binding subst = | |
61 | begin | |
62 | pp "["; | |
63 | Common.print_between (fun () -> pp ";"; Format.print_cut() ) | |
64 | (fun ((_,s), kind) -> pp s; pp " --> "; pp_binding_kind kind) | |
65 | subst; | |
66 | pp "]"; | |
67 | end | |
68 | ||
69 | ||
70 | let pp_binding_kind2 = function | |
71 | | ParenVal s -> pp "pv("; pp_meta s; pp ")" | |
72 | | NormalMetaVal x -> pp_binding_kind x | |
73 | | LabelVal xs -> | |
74 | begin | |
75 | pp "labelval"; | |
76 | pp "("; | |
77 | Common.print_between (fun () -> pp ",") Format.print_int xs; | |
78 | pp ")"; | |
79 | end | |
80 | | GoodVal -> pp "goodval" | |
81 | | BadVal -> pp "badval" | |
82 | ||
83 | ||
84 | let rec pp_predicate = function | |
85 | | InLoop -> pp "InLoop" | |
86 | | TrueBranch -> pp "TrueBranch" | |
87 | | FalseBranch -> pp "FalseBranch" | |
88 | | After -> pp "After" | |
89 | | FallThrough -> pp "FallThrough" | |
90 | | Return -> pp "Return" | |
91 | | FunHeader -> pp "FunHeader" | |
92 | | Top -> pp "Top" | |
93 | | ErrorExit -> pp "ErrorExit" | |
94 | | Exit -> pp "Exit" | |
95 | | Goto -> pp "Goto" | |
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" | |
104 | ||
105 | and pp_binding2 subst = | |
106 | begin | |
107 | pp "["; | |
108 | Common.print_between (fun () -> pp ";";Format.print_cut(); ) | |
109 | (fun (s, kind) -> pp s; pp " --> "; pp_binding_kind2 kind) | |
110 | subst; | |
111 | pp "]"; | |
112 | end | |
113 | ||
114 | and pp_binding2_ctlsubst subst = | |
115 | begin | |
116 | pp "["; | |
117 | Common.print_between (fun () -> pp ";"; Format.print_cut(); ) | |
118 | (function | |
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; | |
123 | ) | |
124 | subst; | |
125 | pp "]"; | |
126 | end | |
127 | ||
128 | let predicate_to_string pred = | |
129 | Common.format_to_string (function _ -> pp_predicate pred) | |
130 | ||
131 | ||
132 | let pp_pred_smodif = fun (pred, smodif) -> | |
133 | begin | |
134 | pp_predicate pred; | |
135 | (* | |
136 | (match smodif with | |
137 | | Ast_ctl.Modif x | Ast_ctl.UnModif x -> pp " with <modifTODO>" | |
138 | | Ast_ctl.Control -> () | |
139 | ) | |
140 | *) | |
141 | end | |
142 | ||
143 | ||
144 | let pp_ctlcocci show_plus inline_let_def ctl = | |
145 | begin | |
146 | if show_plus | |
147 | then begin | |
148 | Pretty_print_cocci.print_plus_flag := true; | |
149 | Pretty_print_cocci.print_minus_flag := true; | |
150 | end | |
151 | else begin | |
152 | Pretty_print_cocci.print_plus_flag := false; | |
153 | Pretty_print_cocci.print_minus_flag := false; | |
154 | end; | |
155 | Common.pp_do_in_box (fun () -> | |
156 | Pretty_print_ctl.pp_ctl (pp_pred_smodif,(fun s -> pp_meta s)) | |
157 | inline_let_def ctl; | |
158 | ); | |
159 | end | |
160 | ||
161 |