14d094d0567abb6eddcda68aa535a93c897c1be4
[bpt/coccinelle.git] / python / pycocci_aux.ml
1 (*
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.
7 *
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.
11 *
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.
16 *
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/>.
19 *
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
22 *)
23
24
25 open Ast_c
26 open Common
27
28 let call_pretty f a =
29 let str = ref ([] : string list) in
30 let pr_elem info = str := (Ast_c.str_of_info info) :: !str in
31 let pr_sp _ = () in
32 f ~pr_elem ~pr_space:pr_sp a;
33 String.concat " " (List.rev !str)
34
35 let exprrep = call_pretty Pretty_print_c.pp_expression_gen
36
37 let stringrep = function
38 Ast_c.MetaIdVal (s,_) -> s
39 | Ast_c.MetaFuncVal s -> s
40 | Ast_c.MetaLocalFuncVal s -> s
41 | Ast_c.MetaExprVal (expr,_) -> exprrep expr
42 | Ast_c.MetaExprListVal expr_list ->
43 call_pretty Pretty_print_c.pp_arg_list_gen expr_list
44 | Ast_c.MetaTypeVal typ -> call_pretty Pretty_print_c.pp_type_gen typ
45 | Ast_c.MetaInitVal ini -> call_pretty Pretty_print_c.pp_init_gen ini
46 | Ast_c.MetaDeclVal decl ->
47 call_pretty Pretty_print_c.pp_decl_gen decl
48 | Ast_c.MetaFieldVal field ->
49 call_pretty Pretty_print_c.pp_field_gen field
50 | Ast_c.MetaStmtVal statement ->
51 call_pretty Pretty_print_c.pp_statement_gen statement
52 | Ast_c.MetaParamVal param ->
53 call_pretty Pretty_print_c.pp_param_gen param
54 | Ast_c.MetaParamListVal params ->
55 call_pretty Pretty_print_c.pp_param_list_gen params
56 | Ast_c.MetaListlenVal n -> string_of_int n
57 | Ast_c.MetaPosVal (pos1, pos2) ->
58 let print_pos = function
59 Ast_cocci.Real x -> string_of_int x
60 | Ast_cocci.Virt(x,off) -> Printf.sprintf "%d+%d" x off in
61 Common.sprintf ("pos(%s,%s)") (print_pos pos1) (print_pos pos2)
62 | Ast_c.MetaPosValList positions -> "TODO: <<postvallist>>"
63