package ppxlib

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

Source file ignore_unused_warning.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
open Import
open Ast_builder.Default

let underscore_binding exp =
  let loc = exp.pexp_loc in
  value_binding ~loc ~pat:(ppat_any ~loc) ~expr:exp

let vars_of = object
  inherit [Longident.t Located.t list] Ast_traverse.fold as super
  method! pattern patt acc =
    match patt.ppat_desc with
    | Ppat_var v -> Located.map (fun var -> Longident.Lident var) v :: acc
    | _ -> super#pattern patt acc
end

(* For every [let x = ...] structure item, add a [let _ = x] *)
let add_dummy_user_for_values = object
  inherit Ast_traverse.map as super
  method! structure st =
    let rec loop st acc =
      match st with
      | [] -> List.rev acc
      | { pstr_desc = Pstr_value (_, vbs); pstr_loc = loc } as item :: rest ->
        let vars =
          List.fold_left vbs ~init:[] ~f:(fun acc vb -> vars_of#pattern vb.pvb_pat acc)
        in
        let ign =
          pstr_value_list ~loc Nonrecursive
            (List.rev_map vars ~f:(fun v ->
               underscore_binding (pexp_ident ~loc:v.loc v)))
        in
        loop rest (ign @ (item :: acc))
      | item :: rest ->
        loop rest (item :: acc)
    in
    loop (super#structure st) []
end
OCaml

Innovation. Community. Security.