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