package zanuda

  1. Overview
  2. Docs

Source file Unused_ML_logger.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
(** Collect used values from structure files.

    An initial implementation was contributed by GitHub user [jegorpopow] *)

[@@@ocaml.text "/*"]

(** Copyright 2021-2024, Kakadu. *)

(** SPDX-License-Identifier: LGPL-3.0-or-later *)

[@@@ocaml.text "/*"]

open Base
open Utils

let run _info filename fallback =
  let _ : string = filename in
  let rec get_ident_string = function
    | Path.Pident id -> Some (Ident.name id)
    | Path.Pdot (lhs, rhs) ->
      get_ident_string lhs |> Option.map ~f:(fun str -> str ^ "." ^ rhs)
    | _ -> None
  in
  let pat =
    let open Tast_pattern in
    texp_ident __
  in
  let open Tast_iterator in
  { fallback with
    expr =
      (fun self expr ->
        let open Typedtree in
        let loc = expr.exp_loc in
        Tast_pattern.parse
          pat
          loc
          ~on_error:(fun _desc () -> ())
          expr
          (fun path () ->
            (*Format.printf "path: %s\n" (String.concat ~sep:", " (List.map ~f:Ident.unique_toplevel_name (Path.heads path)));*)
            match path, get_ident_string path with
            | Pdot (_, _), Some str ->
              (* if String.is_substring filename ~substring:"demo"
                 then printfn "Adding used %S" str; *)
              (* printfn " ... %a\n" (LoadDune.pp_w )  _info; *)
              Collected_decls.add_used_decl str
            | _, _ -> ()
            (*Format.printf "%s\n" (Ident.unique_toplevel_name (Path.head path))*))
          ();
        fallback.expr self expr)
  }
;;
OCaml

Innovation. Community. Security.