-
Notifications
You must be signed in to change notification settings - Fork 0
/
fbident.ml
96 lines (78 loc) · 1.96 KB
/
fbident.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
(**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the "hack" directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*)
external hh_counter_next : unit -> int = "hh_counter_next"
type t = int
module IMap = Map.Make (struct
type t = int
let compare = (-)
end)
let debug = ref false
let foo = 0
let trace = ref IMap.empty
let origin = ref IMap.empty
let origin_id = ref IMap.empty
let make x =
let res = hh_counter_next () in
if !debug then
trace := IMap.add res x !trace ;
res
let fresh x =
let res = hh_counter_next () in
if !debug then begin
let name = IMap.find x !trace in
trace := IMap.add res name !trace ;
end;
res
let tmp () =
let res = hh_counter_next () in
if !debug then begin
trace := IMap.add res ("__tmp"^string_of_int res) !trace ;
end;
res
let compare x y = x - y
let to_string x =
let v =
try IMap.find x !trace
with Not_found -> "v"^string_of_int x
in
try
let md_id = IMap.find x !origin in
md_id ^ "." ^ v
with Not_found -> v
let no_origin x =
origin := IMap.remove x !origin ;
origin_id := IMap.remove x !origin_id
let expand_name md x =
let md_name = IMap.find md !trace in
origin_id := IMap.add x md !origin_id ;
origin := IMap.add x md_name !origin
let debug x =
try IMap.find x !trace^"["^string_of_int x^"]"
with Not_found -> "v["^string_of_int x^"]"
let print x =
Printf.printf "%s\n" (debug x)
let origin x =
IMap.find x !origin
let origin_id x =
IMap.find x !origin_id
let to_ustring x =
let s = to_string x in
s ^ string_of_int x
let full x =
let v =
try IMap.find x !trace
with Not_found -> "v"^string_of_int x
in
let md = try origin x with Not_found -> "" in
if md = ""
then v
else md ^ "_" ^ v
let set_name x y =
trace := IMap.add x y !trace