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

« back to all changes in this revision

Viewing changes to parsing_c/test_parsing_c.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu
  • Date: 2011-04-21 15:05:03 UTC
  • mfrom: (7.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110421150503-2pde6r9lgsn31t33
Tags: 0.2.5.deb-3
* Team upload
* Compile in bytecode only on non-natdynlink architectures (fixes FTBFS)

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
  Flag_parsing_c.debug_etdt := false;
34
34
  Flag_parsing_c.filter_msg := true;
35
35
 
36
 
  let dirname_opt =
 
36
  (*let dirname_opt =
37
37
    match xs with
38
38
    | [x] when is_directory x -> Some x
39
39
    | _ -> None
40
 
  in
 
40
  in*)
41
41
 
42
42
  (* old:
43
43
     let xs = if !Flag.dir then
119
119
 
120
120
(* ---------------------------------------------------------------------- *)
121
121
(* file can be   "foo.c"  or "foo.c:main" *)
122
 
let test_cfg file =
 
122
(* local function that is parameterized by whether to launch gv *)
 
123
let local_test_cfg launchgv file =
123
124
  let (file, specific_func) =
124
125
    if file =~ "\\(.*\\.c\\):\\(.*\\)"
125
126
    then
137
138
  program +> List.iter (fun (e,_) ->
138
139
    let toprocess =
139
140
      match specific_func, e with
140
 
      | None, _ -> true
 
141
      | None, Ast_c.Definition (defbis,_) ->
 
142
          Some (Ast_c.str_of_name (defbis.Ast_c.f_name))
141
143
      | Some s, Ast_c.Definition (defbis,_)  ->
142
 
          s =$= Ast_c.str_of_name (defbis.Ast_c.f_name)
143
 
      | _, _ -> false
 
144
          let nm = Ast_c.str_of_name (defbis.Ast_c.f_name) in
 
145
          if s =$= nm then Some nm else None
 
146
      | _, _ -> None
144
147
    in
145
148
 
146
 
    if toprocess
147
 
    then
148
 
      (* old: Flow_to_ast.test !Flag.show_flow def *)
149
 
      (try
 
149
    match toprocess with
 
150
      None -> ()
 
151
    | Some fn -> (* old: Flow_to_ast.test !Flag.show_flow def *)
 
152
        try
150
153
          let flow = Ast_to_flow.ast_to_control_flow e in
151
154
          flow +> do_option (fun flow ->
152
155
            Ast_to_flow.deadcode_detection flow;
160
163
*)
161
164
              flow
162
165
            in
163
 
            let filename = Filename.temp_file "output" ".dot" in
164
 
            Ograph_extended.print_ograph_mutable flow' (filename) true
 
166
            let filename =
 
167
              if launchgv
 
168
              then Filename.temp_file "output" ".dot"
 
169
              else
 
170
                let fl = Filename.chop_extension (Filename.basename file) in 
 
171
                fl^":"^fn^".dot" in
 
172
            Ograph_extended.print_ograph_mutable flow' (filename) launchgv
165
173
          )
166
174
        with Ast_to_flow.Error (x) -> Ast_to_flow.report_error x
167
175
      )
168
 
  )
 
176
 
 
177
let test_cfg = local_test_cfg true
169
178
 
170
179
 
171
180
 
204
213
  ()
205
214
 
206
215
 
 
216
(*
207
217
let parse_and_print_sexp file =
208
218
  let (ast2,_stat) = Parse_c.parse_c_and_cpp file in
209
219
  let ast = Parse_c.program_of_program2 ast2 in
219
229
  let s = Sexp_ast_c.string_of_program ast in
220
230
  pr2 s;
221
231
  ()
222
 
 
 
232
*)
223
233
 
224
234
 
225
235
let test_type_c infile =
488
498
  Common.mk_action_n_arg test_parse;
489
499
 
490
500
  "-show_flow", "   <file or file:function>",
491
 
  Common.mk_action_1_arg test_cfg;
 
501
  Common.mk_action_1_arg (local_test_cfg true);
492
502
  "-control_flow", "   <file or file:function>",
493
 
  Common.mk_action_1_arg test_cfg;
 
503
  Common.mk_action_1_arg (local_test_cfg true);
 
504
  "-control_flow_to_file", "   <file or file:function>",
 
505
  Common.mk_action_1_arg (local_test_cfg false);
494
506
  "-test_cfg_ifdef", " <file>",
495
507
  Common.mk_action_1_arg test_cfg_ifdef;
496
508
  "-parse_unparse", "   <file>",
497
509
  Common.mk_action_1_arg test_parse_unparse;
498
 
  "-parse_and_print_sexp", "   <file>",
499
 
    Common.mk_action_1_arg parse_and_print_sexp;
 
510
(*  "-parse_and_print_sexp", "   <file>",
 
511
    Common.mk_action_1_arg parse_and_print_sexp;*)
500
512
  "-type_c", "   <file>",
501
513
  Common.mk_action_1_arg test_type_c;
502
514
  "-compare_c", "   <file1> <file2>",