2 * Copyright 2010, INRIA, University of Copenhagen
3 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
4 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
5 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
6 * This file is part of Coccinelle.
8 * Coccinelle is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, according to version 2 of the License.
12 * Coccinelle is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
32 let pp_meta (_
,x
) = pp x
34 let rec pp_binding_kind = function
35 | Ast_c.MetaIdVal
(s
,_
) -> pp ("id " ^ s
)
36 | Ast_c.MetaFuncVal s
-> pp ("func " ^ s
)
37 | Ast_c.MetaLocalFuncVal s
-> pp ("localfunc " ^ s
)
38 | Ast_c.MetaExprVal
(expr
,_
) -> Pretty_print_c.pp_expression_simple expr
39 | Ast_c.MetaExprListVal expr_list
-> pp "<<exprlist>>"
40 | Ast_c.MetaInitVal ini
->
41 Pretty_print_c.pp_init_simple ini
42 | Ast_c.MetaInitListVal ini
-> pp "<<initlist>>"
43 | Ast_c.MetaTypeVal typ
->
44 Pretty_print_c.pp_type_simple typ
45 | Ast_c.MetaDeclVal decl
->
46 Pretty_print_c.pp_decl_simple decl
47 | Ast_c.MetaFieldVal decl
->
48 Pretty_print_c.pp_field_simple decl
49 | Ast_c.MetaFieldListVal decls
->
50 List.iter
Pretty_print_c.pp_field_simple decls
51 | Ast_c.MetaStmtVal statement
->
52 Pretty_print_c.pp_statement_simple statement
53 | Ast_c.MetaParamVal params
-> pp "<<param>>"
54 | Ast_c.MetaParamListVal params
-> pp "<<paramlist>>"
55 | Ast_c.MetaListlenVal n
-> pp (string_of_int n
)
56 | Ast_c.MetaPosVal
(pos1
, pos2
) ->
57 let print_pos = function
58 Ast_cocci.Real x
-> string_of_int x
59 | Ast_cocci.Virt
(x
,off
) -> Printf.sprintf
"%d+%d" x off
in
60 pp (Common.sprintf
("pos(%s,%s)") (print_pos pos1
) (print_pos pos2
))
61 | Ast_c.MetaPosValList l
->
62 pp (Common.sprintf
("poss[%s]")
65 (function (fl
,ce
,(minl
,minc
),(maxl
,maxc
)) ->
66 Printf.sprintf
"(%s,%s,(%d,%d),(%d,%d))"
67 fl ce minl minc maxl maxc
)
70 and pp_binding subst
=
73 Common.print_between
(fun () -> pp ";"; Format.print_cut
() )
75 pp r
; pp "."; pp s
; pp " --> "; pp_binding_kind kind
)
81 let pp_binding_kind2 = function
82 | ParenVal s
-> pp "pv("; pp_meta s
; pp ")"
83 | NormalMetaVal x
-> pp_binding_kind x
84 | LabelVal
(Absolute xs
) ->
88 Common.print_between
(fun () -> pp ",") Format.print_int xs
;
91 | LabelVal
(Prefix xs
) ->
95 Common.print_between
(fun () -> pp ",") Format.print_int xs
;
98 | GoodVal
-> pp "goodval"
99 | BadVal
-> pp "badval"
102 let rec pp_predicate = function
103 | InLoop
-> pp "InLoop"
104 | TrueBranch
-> pp "TrueBranch"
105 | FalseBranch
-> pp "FalseBranch"
106 | After
-> pp "After"
107 | FallThrough
-> pp "FallThrough"
108 | LoopFallThrough
-> pp "LoopFallThrough"
109 | Return
-> pp "Return"
110 | UnsafeBrace
-> pp "UnsafeBrace"
111 | FunHeader
-> pp "FunHeader"
113 | ErrorExit
-> pp "ErrorExit"
116 | Paren s
-> pp "Paren("; pp_meta s
; pp ")"
117 | Match
(re
) -> Pretty_print_cocci.print_rule_elem re
118 | Label s
-> pp "Label("; pp_meta s
; pp ")"
119 | BCLabel s
-> pp "BreakContinueLabel("; pp_meta s
; pp ")"
120 | PrefixLabel s
-> pp "PrefixLabel("; pp_meta s
; pp ")"
121 | BindGood s
-> pp "BindGood("; pp_meta s
; pp ")"
122 | BindBad s
-> pp "BindBad("; pp_meta s
; pp ")"
123 | FakeBrace
-> pp "FakeBrace"
125 and pp_binding2 subst
=
128 Common.print_between
(fun () -> pp ";";Format.print_cut
(); )
129 (fun (s
, kind
) -> pp s
; pp " --> "; pp_binding_kind2 kind
)
134 and pp_binding2_ctlsubst subst
=
137 Common.print_between
(fun () -> pp ";"; Format.print_cut
(); )
139 Ast_ctl.Subst
(s
, kind
) ->
140 pp_meta s
; pp " --> "; pp_binding_kind2 kind
;
141 | Ast_ctl.NegSubst
(s
, kind
) ->
142 pp_meta s
; pp " -/-> "; pp_binding_kind2 kind
;
148 let predicate_to_string pred
=
149 Common.format_to_string
(function _
-> pp_predicate pred
)
152 let pp_pred_smodif = fun (pred
, smodif
) ->
157 | Ast_ctl.Modif x | Ast_ctl.UnModif x -> pp " with <modifTODO>"
158 | Ast_ctl.Control -> ()
164 let pp_ctlcocci show_plus inline_let_def ctl
=
168 Pretty_print_cocci.print_plus_flag
:= true;
169 Pretty_print_cocci.print_minus_flag
:= true;
172 Pretty_print_cocci.print_plus_flag
:= false;
173 Pretty_print_cocci.print_minus_flag
:= false;
175 Common.pp_do_in_box
(fun () ->
176 Pretty_print_ctl.pp_ctl
(pp_pred_smodif,(fun s
-> pp_meta s
))