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.MetaTypeVal typ
->
43 Pretty_print_c.pp_type_simple typ
44 | Ast_c.MetaDeclVal decl
->
45 Pretty_print_c.pp_decl_simple decl
46 | Ast_c.MetaFieldVal decl
->
47 Pretty_print_c.pp_field_simple decl
48 | Ast_c.MetaFieldListVal decls
->
49 List.iter
Pretty_print_c.pp_field_simple decls
50 | Ast_c.MetaStmtVal statement
->
51 Pretty_print_c.pp_statement_simple statement
52 | Ast_c.MetaParamVal params
-> pp "<<param>>"
53 | Ast_c.MetaParamListVal params
-> pp "<<paramlist>>"
54 | Ast_c.MetaListlenVal n
-> pp (string_of_int n
)
55 | Ast_c.MetaPosVal
(pos1
, pos2
) ->
56 let print_pos = function
57 Ast_cocci.Real x
-> string_of_int x
58 | Ast_cocci.Virt
(x
,off
) -> Printf.sprintf
"%d+%d" x off
in
59 pp (Common.sprintf
("pos(%s,%s)") (print_pos pos1
) (print_pos pos2
))
60 | Ast_c.MetaPosValList l
->
61 pp (Common.sprintf
("poss[%s]")
64 (function (fl
,ce
,(minl
,minc
),(maxl
,maxc
)) ->
65 Printf.sprintf
"(%s,%s,(%d,%d),(%d,%d))"
66 fl ce minl minc maxl maxc
)
69 and pp_binding subst
=
72 Common.print_between
(fun () -> pp ";"; Format.print_cut
() )
74 pp r
; pp "."; pp s
; pp " --> "; pp_binding_kind kind
)
80 let pp_binding_kind2 = function
81 | ParenVal s
-> pp "pv("; pp_meta s
; pp ")"
82 | NormalMetaVal x
-> pp_binding_kind x
83 | LabelVal
(Absolute xs
) ->
87 Common.print_between
(fun () -> pp ",") Format.print_int xs
;
90 | LabelVal
(Prefix xs
) ->
94 Common.print_between
(fun () -> pp ",") Format.print_int xs
;
97 | GoodVal
-> pp "goodval"
98 | BadVal
-> pp "badval"
101 let rec pp_predicate = function
102 | InLoop
-> pp "InLoop"
103 | TrueBranch
-> pp "TrueBranch"
104 | FalseBranch
-> pp "FalseBranch"
105 | After
-> pp "After"
106 | FallThrough
-> pp "FallThrough"
107 | LoopFallThrough
-> pp "LoopFallThrough"
108 | Return
-> pp "Return"
109 | FunHeader
-> pp "FunHeader"
111 | ErrorExit
-> pp "ErrorExit"
114 | Paren s
-> pp "Paren("; pp_meta s
; pp ")"
115 | Match
(re
) -> Pretty_print_cocci.print_rule_elem re
116 | Label s
-> pp "Label("; pp_meta s
; pp ")"
117 | BCLabel s
-> pp "BreakContinueLabel("; pp_meta s
; pp ")"
118 | PrefixLabel s
-> pp "PrefixLabel("; pp_meta s
; pp ")"
119 | BindGood s
-> pp "BindGood("; pp_meta s
; pp ")"
120 | BindBad s
-> pp "BindBad("; pp_meta s
; pp ")"
121 | FakeBrace
-> pp "FakeBrace"
123 and pp_binding2 subst
=
126 Common.print_between
(fun () -> pp ";";Format.print_cut
(); )
127 (fun (s
, kind
) -> pp s
; pp " --> "; pp_binding_kind2 kind
)
132 and pp_binding2_ctlsubst subst
=
135 Common.print_between
(fun () -> pp ";"; Format.print_cut
(); )
137 Ast_ctl.Subst
(s
, kind
) ->
138 pp_meta s
; pp " --> "; pp_binding_kind2 kind
;
139 | Ast_ctl.NegSubst
(s
, kind
) ->
140 pp_meta s
; pp " -/-> "; pp_binding_kind2 kind
;
146 let predicate_to_string pred
=
147 Common.format_to_string
(function _
-> pp_predicate pred
)
150 let pp_pred_smodif = fun (pred
, smodif
) ->
155 | Ast_ctl.Modif x | Ast_ctl.UnModif x -> pp " with <modifTODO>"
156 | Ast_ctl.Control -> ()
162 let pp_ctlcocci show_plus inline_let_def ctl
=
166 Pretty_print_cocci.print_plus_flag
:= true;
167 Pretty_print_cocci.print_minus_flag
:= true;
170 Pretty_print_cocci.print_plus_flag
:= false;
171 Pretty_print_cocci.print_minus_flag
:= false;
173 Common.pp_do_in_box
(fun () ->
174 Pretty_print_ctl.pp_ctl
(pp_pred_smodif,(fun s
-> pp_meta s
))