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