package pfff

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

Source file lib_parsing_ml.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
(* Yoann Padioleau
 *
 * Copyright (C) 2010 Facebook
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation, with the
 * special exception on linking described in file license.txt.
 * 
 * This library 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

module V = Visitor_ml

(*****************************************************************************)
(* Filemames *)
(*****************************************************************************)

let find_source_files_of_dir_or_files xs = 
  Common.files_of_dir_or_files_no_vcs_nofilter xs 
  |> List.filter (fun filename ->
    match File_type.file_type_of_file filename with
    | File_type.PL (File_type.ML ("ml" | "mli")) -> true
    | _ -> false
  ) |> Common.sort

let find_ml_files_of_dir_or_files xs = 
  Common.files_of_dir_or_files_no_vcs_nofilter xs 
  |> List.filter (fun filename ->
    match File_type.file_type_of_file filename with
    | File_type.PL (File_type.ML ("ml")) -> true
    | _ -> false
  ) |> Common.sort

let find_cmt_files_of_dir_or_files xs = 
  Common.files_of_dir_or_files_no_vcs_nofilter xs 
   |> List.filter (fun filename->
    match File_type.file_type_of_file filename with
    | File_type.Obj ("cmt" | "cmti") -> true
    | _ -> false
   )
  (* ocaml 4.07 stdlib now has those .p.cmt files that cause dupe errors *)
  |> Common.exclude (fun filename -> filename =~ ".*\\.p\\.cmt")
  (* sometimes there is just a .cmti and no corresponding .cmt because
   * people put the information only in a .mli
   *)
  |> (fun xs ->
    let hfiles = Hashtbl.create 101 in
    xs |> List.iter (fun file ->
      let (d,b,e) = Common2.dbe_of_filename file in
      Hashtbl.add hfiles (d,b) e
    );
    Common2.hkeys hfiles |> List.map (fun (d,b) ->
      let xs = Hashtbl.find_all hfiles (d,b) in
      (match xs with
      | ["cmt";"cmti"]
      | ["cmti";"cmt"]
      | ["cmt"] ->
        Common2.filename_of_dbe (d,b,"cmt")
      | ["cmti"] ->
        Common2.filename_of_dbe (d,b,"cmti")
      | _ -> raise Impossible
      )
    )
  ) |> Common.sort

(*****************************************************************************)
(* Extract infos *)
(*****************************************************************************)

let extract_info_visitor recursor = 
  let globals = ref [] in
  let hooks = { V.default_visitor with
    V.kinfo = (fun (_k, _) i -> Common.push i globals)
  } in
  begin
    let vout = V.mk_visitor hooks in
    recursor vout;
    List.rev !globals
  end

let ii_of_any any = 
  extract_info_visitor (fun visitor -> visitor any)
OCaml

Innovation. Community. Security.