8 let pp_meta (_
,x
) = pp x
10 let rec pp_binding_kind = function
11 | Ast_c.MetaIdVal s
-> pp ("id " ^ s
)
12 | Ast_c.MetaFuncVal s
-> pp ("func " ^ s
)
13 | Ast_c.MetaLocalFuncVal s
-> pp ("localfunc " ^ s
)
14 | Ast_c.MetaExprVal expr
-> Pretty_print_c.pp_expression_simple expr
15 | Ast_c.MetaExprListVal expr_list
-> pp "<<exprlist>>"
16 | Ast_c.MetaInitVal ini
->
17 Pretty_print_c.pp_init_simple ini
18 | Ast_c.MetaTypeVal typ
->
19 Pretty_print_c.pp_type_simple typ
20 | Ast_c.MetaStmtVal statement
->
21 Pretty_print_c.pp_statement_simple statement
22 | Ast_c.MetaParamVal params
-> pp "<<param>>"
23 | Ast_c.MetaParamListVal params
-> pp "<<paramlist>>"
24 | Ast_c.MetaListlenVal n
-> pp (string_of_int n
)
25 | Ast_c.MetaPosVal
(pos1
, pos2
) ->
26 let print_pos = function
27 Ast_cocci.Real x
-> string_of_int x
28 | Ast_cocci.Virt
(x
,off
) -> Printf.sprintf
"%d+%d" x off
in
29 pp (Common.sprintf
("pos(%s,%s)") (print_pos pos1
) (print_pos pos2
))
30 | Ast_c.MetaPosValList l
->
31 pp (Common.sprintf
("poss[%s]")
34 (function (fl
,ce
,(minl
,minc
),(maxl
,maxc
)) ->
35 Printf.sprintf
"(%s,%s,(%d,%d),(%d,%d))"
36 fl ce minl minc maxl maxc
)
39 and pp_binding subst
=
42 Common.print_between
(fun () -> pp ";"; Format.print_cut
() )
43 (fun ((_
,s
), kind
) -> pp s
; pp " --> "; pp_binding_kind kind
)
49 let pp_binding_kind2 = function
50 | ParenVal s
-> pp "pv("; pp_meta s
; pp ")"
51 | NormalMetaVal x
-> pp_binding_kind x
52 | LabelVal
(Absolute xs
) ->
56 Common.print_between
(fun () -> pp ",") Format.print_int xs
;
59 | LabelVal
(Prefix xs
) ->
63 Common.print_between
(fun () -> pp ",") Format.print_int xs
;
66 | GoodVal
-> pp "goodval"
67 | BadVal
-> pp "badval"
70 let rec pp_predicate = function
71 | InLoop
-> pp "InLoop"
72 | TrueBranch
-> pp "TrueBranch"
73 | FalseBranch
-> pp "FalseBranch"
75 | FallThrough
-> pp "FallThrough"
76 | LoopFallThrough
-> pp "LoopFallThrough"
77 | Return
-> pp "Return"
78 | FunHeader
-> pp "FunHeader"
80 | ErrorExit
-> pp "ErrorExit"
83 | Paren s
-> pp "Paren("; pp_meta s
; pp ")"
84 | Match
(re
) -> Pretty_print_cocci.print_rule_elem re
85 | Label s
-> pp "Label("; pp_meta s
; pp ")"
86 | BCLabel s
-> pp "BreakContinueLabel("; pp_meta s
; pp ")"
87 | PrefixLabel s
-> pp "PrefixLabel("; pp_meta s
; pp ")"
88 | BindGood s
-> pp "BindGood("; pp_meta s
; pp ")"
89 | BindBad s
-> pp "BindBad("; pp_meta s
; pp ")"
90 | FakeBrace
-> pp "FakeBrace"
92 and pp_binding2 subst
=
95 Common.print_between
(fun () -> pp ";";Format.print_cut
(); )
96 (fun (s
, kind
) -> pp s
; pp " --> "; pp_binding_kind2 kind
)
101 and pp_binding2_ctlsubst subst
=
104 Common.print_between
(fun () -> pp ";"; Format.print_cut
(); )
106 Ast_ctl.Subst
(s
, kind
) ->
107 pp_meta s
; pp " --> "; pp_binding_kind2 kind
;
108 | Ast_ctl.NegSubst
(s
, kind
) ->
109 pp_meta s
; pp " -/-> "; pp_binding_kind2 kind
;
115 let predicate_to_string pred
=
116 Common.format_to_string
(function _
-> pp_predicate pred
)
119 let pp_pred_smodif = fun (pred
, smodif
) ->
124 | Ast_ctl.Modif x | Ast_ctl.UnModif x -> pp " with <modifTODO>"
125 | Ast_ctl.Control -> ()
131 let pp_ctlcocci show_plus inline_let_def ctl
=
135 Pretty_print_cocci.print_plus_flag
:= true;
136 Pretty_print_cocci.print_minus_flag
:= true;
139 Pretty_print_cocci.print_plus_flag
:= false;
140 Pretty_print_cocci.print_minus_flag
:= false;
142 Common.pp_do_in_box
(fun () ->
143 Pretty_print_ctl.pp_ctl
(pp_pred_smodif,(fun s
-> pp_meta s
))