Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 70 lines (53 sloc) 1.866 kB
fccc685 Initial open-source release
MLstate authored
1 (*
243f43d @BourgerieQuentin [enhance] compiler, utils: Added remove to the renaming maps
BourgerieQuentin authored
2 Copyright © 2011, 2012 MLstate
fccc685 Initial open-source release
MLstate authored
3
5bb0f1a @Aqua-Ye [cleanup] compiler: typo on Opa
Aqua-Ye authored
4 This file is part of Opa.
fccc685 Initial open-source release
MLstate authored
5
5bb0f1a @Aqua-Ye [cleanup] compiler: typo on Opa
Aqua-Ye authored
6 Opa is free software: you can redistribute it and/or modify it under the
fccc685 Initial open-source release
MLstate authored
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
5bb0f1a @Aqua-Ye [cleanup] compiler: typo on Opa
Aqua-Ye authored
10 Opa is distributed in the hope that it will be useful, but WITHOUT ANY
fccc685 Initial open-source release
MLstate authored
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
5bb0f1a @Aqua-Ye [cleanup] compiler: typo on Opa
Aqua-Ye authored
16 along with Opa. If not, see <http://www.gnu.org/licenses/>.
fccc685 Initial open-source release
MLstate authored
17 *)
18
19 type id_to_id = Ident.t IdentMap.t
20
21 type t = {
22 map : id_to_id;
23 rev : id_to_id;
24 }
25
26 let empty = {
27 map = IdentMap.empty;
28 rev = IdentMap.empty;
29 }
30
31 let add t original_id new_id = {
32 map = IdentMap.add original_id new_id t.map;
33 rev = IdentMap.add new_id original_id t.rev;
34 }
35
36 let from_map map = {
37 map = map;
38 rev = IdentMap.fold (fun k v acc -> IdentMap.safe_add v k acc) map IdentMap.empty;
39 }
40
41 let original_from_new t new_id =
42 IdentMap.find new_id t.rev
43
44 let original_from_new_opt t new_id =
45 IdentMap.find_opt new_id t.rev
46
47 let new_from_original t original_id =
48 IdentMap.find original_id t.map
49
50 let new_from_original_opt t original_id =
51 IdentMap.find_opt original_id t.map
52
243f43d @BourgerieQuentin [enhance] compiler, utils: Added remove to the renaming maps
BourgerieQuentin authored
53 let remove_from_original t original_id =
54 let old_id = new_from_original t original_id in
55 {
56 map = IdentMap.remove original_id t.map;
57 rev = IdentMap.remove old_id t.rev;
58 }
59
fccc685 Initial open-source release
MLstate authored
60 let filter t filter =
61 IdentMap.fold
62 (fun original_id new_id filtered ->
63 match filter original_id new_id with
64 | true -> add filtered original_id new_id
65 | false -> filtered)
66 t.map empty
67
68 let pp f m =
69 IdentMap.iter (fun k v -> Format.fprintf f "%s <-> %s@ " (Ident.to_string k) (Ident.to_string v)) m.map
Something went wrong with that request. Please try again.