-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathbackend_var.ml
96 lines (79 loc) · 2.95 KB
/
backend_var.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
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Mark Shinwell, Jane Street Europe *)
(* *)
(* Copyright 2018--2023 Jane Street Group LLC *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
[@@@ocaml.warning "+a-4-30-40-41-42"]
include Ident
type backend_var = t
let name_for_debugger t = name t
let unique_name_for_debugger t =
Printf.sprintf "%s/%d" (name t) (stamp t)
module Provenance = struct
type t = {
module_path : Path.t;
location : Debuginfo.t;
original_ident : Ident.t;
}
let print ppf { module_path; location; original_ident; } =
let printf fmt = Format.fprintf ppf fmt in
printf "@[<hov 1>(";
printf "@[<hov 1>(module_path@ %a)@]@ "
Path.print module_path;
if !Clflags.locations then
printf "@[<hov 1>(location@ %a)@]@ "
Debuginfo.print_compact location;
printf "@[<hov 1>(original_ident@ %a)@]"
Ident.print original_ident;
printf ")@]"
let create ~module_path ~location ~original_ident =
{ module_path;
location;
original_ident;
}
let module_path t = t.module_path
let location t = t.location
let original_ident t = t.original_ident
let equal t1 t2 = Stdlib.compare t1 t2 = 0
end
module With_provenance = struct
type t =
| Without_provenance of backend_var
| With_provenance of {
var : backend_var;
provenance : Provenance.t;
}
let create ?provenance var =
match provenance with
| None -> Without_provenance var
| Some provenance -> With_provenance { var; provenance; }
let var t =
match t with
| Without_provenance var
| With_provenance { var; provenance = _; } -> var
let provenance t =
match t with
| Without_provenance _ -> None
| With_provenance { var = _; provenance; } -> Some provenance
let name t = name (var t)
let rename t =
let var = rename (var t) in
match provenance t with
| None -> Without_provenance var
| Some provenance -> With_provenance { var; provenance; }
let print ppf t =
match provenance t with
| None -> print ppf (var t)
| Some provenance ->
Format.fprintf ppf "%a[%a]"
print (var t)
Provenance.print provenance
end