1 (**************************************************************************)
2 (* *)
3 (* OCaml *)
4 (* *)
5 (* Mark Shinwell, Jane Street Europe *)
6 (* *)
7 (* Copyright 2018 Jane Street Group LLC *)
8 (* *)
9 (* All rights reserved. This file is distributed under the terms of *)
10 (* the GNU Lesser General Public License version 2.1, with the *)
11 (* special exception on linking described in the file LICENSE. *)
12 (* *)
13 (**************************************************************************)
14
15 [@@@ocaml.warning "+a-4-30-40-41-42"]
16
17 include Ident
18
19 type backend_var = t
20
21 module Provenance = struct
22 type t = {
23 module_path : Path.t;
24 location : Debuginfo.t;
25 original_ident : Ident.t;
26 }
27
28 let print ppf { module_path; location; original_ident; } =
29 Format.fprintf ppf "@[<hov 1>(\
30 @[<hov 1>(module_path@ %a)@]@ \
31 @[<hov 1>(location@ %a)@]@ \
32 @[<hov 1>(original_ident@ %a)@]\
33 )@]"
34 Path.print module_path
35 Debuginfo.print_compact location
36 Ident.print original_ident
37
38 let create ~module_path ~location ~original_ident =
39 { module_path;
40 location;
41 original_ident;
42 }
43
44 let module_path t = t.module_path
45 let location t = t.location
46 let original_ident t = t.original_ident
47 end
48
49 module With_provenance = struct
50 type t =
51 | Without_provenance of backend_var
52 | With_provenance of {
53 var : backend_var;
54 provenance : Provenance.t;
55 }
56
57 let create ?provenance var =
58 match provenance with
59 | None -> Without_provenance var
60 | Some provenance -> With_provenance { var; provenance; }
61
62 let var t =
63 match t with
64 | Without_provenance var
65 | With_provenance { var; provenance = _; } -> var
66
67 let provenance t =
68 match t with
69 | Without_provenance _ -> None
70 | With_provenance { var = _; provenance; } -> Some provenance
71
72 let name t = name (var t)
73
74 let rename t =
75 let var = rename (var t) in
76 match provenance t with
77 | None -> Without_provenance var
78 | Some provenance -> With_provenance { var; provenance; }
79
80 let print ppf t =
81 match provenance t with
82 | None -> print ppf (var t)
83 | Some provenance ->
84 Format.fprintf ppf "%a[%a]"
85 print (var t)
86 Provenance.print provenance
87 end
88