~ubuntu-branches/ubuntu/trusty/coccinelle/trusty-proposed

« back to all changes in this revision

Viewing changes to parsing_c/unparse_cocci.ml

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2010-01-31 22:30:19 UTC
  • mfrom: (7.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100131223019-hbq02ip17tn17n52
Tags: 0.2.0.deb-1ubuntu1
* Merge from debian testing (LP: #515198).Remaining changes:
  - debian/control: build-depend on python2.6-dev,
    set XB-Python-Version to 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
6
 
 * 
 
6
 *
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.
11
 
 * 
 
11
 *
12
12
 * This file was part of Coccinelle.
13
13
 *)
14
14
open Common
15
15
 
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 ?
19
19
 *)
20
20
(*****************************************************************************)
23
23
 
24
24
let term s = Ast.unwrap_mcode s
25
25
 
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)
28
28
 *)
29
29
exception CantBeInPlus
30
30
 
34
34
 
35
35
let unknown = -1
36
36
 
37
 
let rec pp_list_list_any
 
37
let rec do_all
38
38
    (env, pr, pr_celem, pr_cspace, pr_space, pr_arity, pr_barrier,
39
39
     indent, unindent)
40
40
    generating xxs before =
98
98
 
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
105
105
 
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) ->
 
166
  | (true,Ast.PLUS Ast.ONE) ->
167
167
      let fn s =
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) ->
 
171
      let fn s =
 
172
        force_newline(); print_text "++ "; fn s line lcol; print_pos pos in
 
173
      print_string_befaft fn (function _ -> print_text "++ ") s info
170
174
in
171
175
 
172
176
 
227
231
 
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
235
 
        ) 
236
 
  | Ast.MetaFunc(name,_,_,_) -> 
237
 
      handle_metavar name (function
238
 
        | (Ast_c.MetaFuncVal id) -> print_text id
239
 
        | _ -> raise Impossible
240
 
        ) 
241
 
  | Ast.MetaLocalFunc(name,_,_,_) -> 
242
 
      handle_metavar name (function
243
 
        | (Ast_c.MetaLocalFuncVal id) -> print_text id
244
 
        | _ -> raise Impossible
245
 
        )
 
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
 
239
                            )
 
240
    | Ast.MetaFunc(name,_,_,_) ->
 
241
        handle_metavar name (function
 
242
                               | (Ast_c.MetaFuncVal id) -> print_text id
 
243
                               | _ -> raise Impossible
 
244
                            )
 
245
    | Ast.MetaLocalFunc(name,_,_,_) ->
 
246
        handle_metavar name (function
 
247
                               | (Ast_c.MetaLocalFuncVal id) -> print_text id
 
248
                               | _ -> raise Impossible
 
249
                            )
246
250
 
247
 
  | Ast.OptIdent(_) | Ast.UniqueIdent(_) -> 
248
 
      raise CantBeInPlus
 
251
    | Ast.OptIdent(_) | Ast.UniqueIdent(_) ->
 
252
        raise CantBeInPlus
249
253
 
250
254
in
251
255
 
1049
1053
      (* print a newline at the end, if needed *)
1050
1054
      newline_after()
1051
1055
 
 
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 =
 
1059
  List.iter
 
1060
    (function env ->
 
1061
      do_all (env, pr, pr_celem, pr_cspace, pr_space, pr_arity, pr_barrier,
 
1062
              indent, unindent)
 
1063
        generating xxs before)
 
1064
    envs