3
3
* This program is free software; you can redistribute it and/or
4
4
* modify it under the terms of the GNU General Public License (GPL)
5
5
* version 2 as published by the Free Software Foundation.
7
7
* This program is distributed in the hope that it will be useful,
8
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
10
* file license.txt for more details.
12
12
* This file was part of Coccinelle.
16
16
(*****************************************************************************)
17
(* mostly a copy paste of parsing_cocci/pretty_print_cocci.ml
17
(* mostly a copy paste of parsing_cocci/pretty_print_cocci.ml
18
18
* todo?: try to factorize ?
20
20
(*****************************************************************************)
24
24
let term s = Ast.unwrap_mcode s
26
(* or perhaps can have in plus, for instance a Disj, but those Disj must be
27
* handled by interactive tool (by proposing alternatives)
26
(* or perhaps can have in plus, for instance a Disj, but those Disj must be
27
* handled by interactive tool (by proposing alternatives)
29
29
exception CantBeInPlus
99
99
let print_around printer term = function
100
100
Ast.NOTHING -> printer term
101
| Ast.BEFORE(bef) -> print_anything bef; printer term
102
| Ast.AFTER(aft) -> printer term; print_anything aft
103
| Ast.BEFOREAFTER(bef,aft) ->
101
| Ast.BEFORE(bef,_) -> print_anything bef; printer term
102
| Ast.AFTER(aft,_) -> printer term; print_anything aft
103
| Ast.BEFOREAFTER(bef,aft,_) ->
104
104
print_anything bef; printer term; print_anything aft in
106
106
let print_string_befaft fn fn1 x info =
163
163
| (true, Ast.CONTEXT(_,plus_streams)) ->
164
164
let fn s = force_newline(); fn s line lcol; print_pos pos in
165
165
print_around fn s plus_streams
166
| (true,Ast.PLUS Ast.ONE) ->
168
168
force_newline(); print_text "+ "; fn s line lcol; print_pos pos in
169
169
print_string_befaft fn (function _ -> print_text "+ ") s info
170
| (true,Ast.PLUS Ast.MANY) ->
172
force_newline(); print_text "++ "; fn s line lcol; print_pos pos in
173
print_string_befaft fn (function _ -> print_text "++ ") s info
228
232
let rec ident i =
229
233
match Ast.unwrap i with
230
Ast.Id(name) -> mcode print_string name
231
| Ast.MetaId(name,_,_,_) ->
232
handle_metavar name (function
233
| (Ast_c.MetaIdVal id) -> print_text id
234
| _ -> raise Impossible
236
| Ast.MetaFunc(name,_,_,_) ->
237
handle_metavar name (function
238
| (Ast_c.MetaFuncVal id) -> print_text id
239
| _ -> raise Impossible
241
| Ast.MetaLocalFunc(name,_,_,_) ->
242
handle_metavar name (function
243
| (Ast_c.MetaLocalFuncVal id) -> print_text id
244
| _ -> raise Impossible
234
Ast.Id(name) -> mcode print_string name
235
| Ast.MetaId(name,_,_,_) ->
236
handle_metavar name (function
237
| (Ast_c.MetaIdVal id) -> print_text id
238
| _ -> raise Impossible
240
| Ast.MetaFunc(name,_,_,_) ->
241
handle_metavar name (function
242
| (Ast_c.MetaFuncVal id) -> print_text id
243
| _ -> raise Impossible
245
| Ast.MetaLocalFunc(name,_,_,_) ->
246
handle_metavar name (function
247
| (Ast_c.MetaLocalFuncVal id) -> print_text id
248
| _ -> raise Impossible
247
| Ast.OptIdent(_) | Ast.UniqueIdent(_) ->
251
| Ast.OptIdent(_) | Ast.UniqueIdent(_) ->
1049
1053
(* print a newline at the end, if needed *)
1050
1054
newline_after()
1056
let rec pp_list_list_any (envs, pr, pr_celem, pr_cspace, pr_space, pr_arity,
1057
pr_barrier, indent, unindent)
1058
generating xxs before =
1061
do_all (env, pr, pr_celem, pr_cspace, pr_space, pr_arity, pr_barrier,
1063
generating xxs before)