Release coccinelle-0.2.3rc1
[bpt/coccinelle.git] / python / yes_pycocci_aux.ml
CommitLineData
9f8e26f4 1(*
ae4735db 2 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
9f8e26f4
C
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
5636bb2c
C
23(*
24 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
25 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
26 * This file is part of Coccinelle.
27 *
28 * Coccinelle is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, according to version 2 of the License.
31 *
32 * Coccinelle is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
36 *
37 * You should have received a copy of the GNU General Public License
38 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
39 *
40 * The authors reserve the right to distribute this or future versions of
41 * Coccinelle under other licenses.
42 *)
43
44
34e49164
C
45open Ast_c
46open Common
47open Pycaml
48
34e49164
C
49let call_pretty f a =
50 let str = ref ([] : string list) in
51 let pr_elem info = str := (Ast_c.str_of_info info) :: !str in
52 let pr_sp _ = () in
978fd7e5 53 f ~pr_elem ~pr_space:pr_sp a;
34e49164
C
54 String.concat " " (List.rev !str)
55
0708f913
C
56let exprrep = call_pretty Pretty_print_c.pp_expression_gen
57
34e49164 58let stringrep mvb = match mvb with
5636bb2c 59 Ast_c.MetaIdVal (s,_) -> s
34e49164
C
60| Ast_c.MetaFuncVal s -> s
61| Ast_c.MetaLocalFuncVal s -> s
5636bb2c 62| Ast_c.MetaExprVal (expr,_) -> exprrep expr
34e49164
C
63| Ast_c.MetaExprListVal expr_list -> "TODO: <<exprlist>>"
64| Ast_c.MetaTypeVal typ -> call_pretty Pretty_print_c.pp_type_gen typ
0708f913
C
65| Ast_c.MetaInitVal ini -> call_pretty Pretty_print_c.pp_init_gen ini
66| Ast_c.MetaStmtVal statement ->
67 call_pretty Pretty_print_c.pp_statement_gen statement
68| Ast_c.MetaParamVal param ->
69 call_pretty Pretty_print_c.pp_param_gen param
34e49164
C
70| Ast_c.MetaParamListVal params -> "TODO: <<paramlist>>"
71| Ast_c.MetaListlenVal n -> string_of_int n
72| Ast_c.MetaPosVal (pos1, pos2) ->
73 let print_pos = function
74 Ast_cocci.Real x -> string_of_int x
75 | Ast_cocci.Virt(x,off) -> Printf.sprintf "%d+%d" x off in
76 Common.sprintf ("pos(%s,%s)") (print_pos pos1) (print_pos pos2)
77| Ast_c.MetaPosValList positions -> "TODO: <<postvallist>>"
78