package pfff

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file test_parsing_java.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
(* Copyright (C) 2008 Yoann Padioleau
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License (GPL)
 * version 2 as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * file license.txt for more details.
 *)
open Common

open Ast_java
module PI = Parse_info
module V = Visitor_java

(*****************************************************************************)
(* Subsystem testing *)
(*****************************************************************************)

let test_parse xs  =
  let fullxs = Lib_parsing_java.find_source_files_of_dir_or_files xs in
  let ext = "java" in

  let stat_list = ref [] in
  let newscore  = Common2.empty_score () in

  Common2.check_stack_nbfiles (List.length fullxs);

  fullxs |> List.iter (fun file -> 
    pr2 ("PARSING: " ^ file);
    let (_xs, stat) = 
      Common.save_excursion Flag_parsing.error_recovery true (fun () ->
        Parse_java.parse file 
      )
    in
    Common.push stat stat_list;
    let s = spf "bad = %d" stat.PI.bad in
    if stat.PI.bad = 0
    then Hashtbl.add newscore file (Common2.Ok)
    else Hashtbl.add newscore file (Common2.Pb s)
    ;
  );
  flush stdout; flush stderr;

  PI.print_parsing_stat_list !stat_list;

  let dirname_opt = 
    match xs with
    | [x] when Common2.is_directory x -> Some (Common.fullpath x)
    | _ -> None
  in
  let score_path = Filename.concat Config_pfff.path "tmp" in
  dirname_opt |> Common.do_option (fun dirname -> 
    pr2 "--------------------------------";
    pr2 "regression testing  information";
    pr2 "--------------------------------";
    let str = Str.global_replace (Str.regexp "/") "__" dirname in
    Common2.regression_testing newscore 
      (Filename.concat score_path
       ("score_parsing__" ^str ^ ext ^ ".marshalled"))
  );
  ()

let test_lexer file =
  let lexbuf = Lexing.from_channel (open_in file) in
  while true do
    let result = Lexer_java.token lexbuf in
    pr2_gen result;
    if Token_helpers_java.is_eof result then
      exit 0
  done

let test_dump file =
  let ast = Parse_java.parse_program file in
  let v = Meta_ast_java.vof_any (Ast_java.AProgram ast) in
  let str = Ocaml.string_of_v v in
  pr str

let test_visitor file = 
  let visitor = V.mk_visitor { V.default_visitor with
    V.kexpr = (fun (k, _) e -> 
      match e with
      | Ast_java.Literal (Ast_java.Int (s,_)) -> 
          pr2 ("int:" ^ s);
          k e
      | Ast_java.Dot (e, (_s,_)) -> 
          pr2 "dot: s";
          k e
      | _ -> k e
    );
  } in

  let ast = Parse_java.parse_program file in
  visitor (AProgram ast);
  ()

(*****************************************************************************)
(* Main entry for Arg *)
(*****************************************************************************)

let actions () = [
  "-tokens_java", "   <file>", 
  Common.mk_action_1_arg test_lexer;
  "-parse_java", "   <file or dir>", 
  Common.mk_action_n_arg test_parse;
  "-dump_java", "   <file>", 
  Common.mk_action_1_arg test_dump;

  "-visitor_java", "   <file>", 
  Common.mk_action_1_arg test_visitor;
]
OCaml

Innovation. Community. Security.