3a0f0d939d31a7b3ade20d852e389a7184a1f932
[bpt/coccinelle.git] / python / yes_pycocci_aux.ml
1 (*
2 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
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
23 open Ast_c
24 open Common
25 open Pycaml
26
27 let call_pretty f a =
28 let str = ref ([] : string list) in
29 let pr_elem info = str := (Ast_c.str_of_info info) :: !str in
30 let pr_sp _ = () in
31 f ~pr_elem ~pr_space:pr_sp a;
32 String.concat " " (List.rev !str)
33
34 let exprrep = call_pretty Pretty_print_c.pp_expression_gen
35
36 let stringrep mvb = match mvb with
37 Ast_c.MetaIdVal s -> s
38 | Ast_c.MetaFuncVal s -> s
39 | Ast_c.MetaLocalFuncVal s -> s
40 | Ast_c.MetaExprVal expr -> exprrep expr
41 | Ast_c.MetaExprListVal expr_list -> "TODO: <<exprlist>>"
42 | Ast_c.MetaTypeVal typ -> call_pretty Pretty_print_c.pp_type_gen typ
43 | Ast_c.MetaInitVal ini -> call_pretty Pretty_print_c.pp_init_gen ini
44 | Ast_c.MetaStmtVal statement ->
45 call_pretty Pretty_print_c.pp_statement_gen statement
46 | Ast_c.MetaParamVal param ->
47 call_pretty Pretty_print_c.pp_param_gen param
48 | Ast_c.MetaParamListVal params -> "TODO: <<paramlist>>"
49 | Ast_c.MetaListlenVal n -> string_of_int n
50 | Ast_c.MetaPosVal (pos1, pos2) ->
51 let print_pos = function
52 Ast_cocci.Real x -> string_of_int x
53 | Ast_cocci.Virt(x,off) -> Printf.sprintf "%d+%d" x off in
54 Common.sprintf ("pos(%s,%s)") (print_pos pos1) (print_pos pos2)
55 | Ast_c.MetaPosValList positions -> "TODO: <<postvallist>>"
56