Skip to content
Newer
Older
100644 65 lines (55 sloc) 1.77 KB
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
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
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 module Hashtbl = BaseHashtbl
19 module String = BaseString
20
21 (* -- *)
22
23 type native_ident = [ `global | `local ]
24
25 type t =
26 | ExprIdent of Ident.t
27 | Native of native_ident * string
28
29 let compare_native n1 n2 =
30 if n1 = `local
31 then
32 match n2 with
33 | `local -> 0
34 | `global -> -1
35 else
36 match n2 with
37 | `local -> 1
38 | `global -> 0
39
40 let compare i1 i2 =
41 match i1, i2 with
42 | Native (n1, s1), Native (n2, s2) ->
43 let res = compare_native n1 n2 in
44 if res <> 0 then res
45 else
46 String.compare s1 s2
47 | Native _, ExprIdent _ -> -1
48 | ExprIdent _, Native _ -> 1
49 | ExprIdent i1, ExprIdent i2 -> Ident.compare i1 i2
50 let equal i1 i2 =
51 match i1, i2 with
52 | Native (n1, s1), Native (n2, s2) -> n1 = n2 && String.equal s1 s2
53 | ExprIdent i1, ExprIdent i2 -> Ident.equal i1 i2
54 | Native _, ExprIdent _
55 | ExprIdent _, Native _ -> false
56 let to_string = function
57 | Native (_, s) -> s
58 | ExprIdent s -> Ident.to_string s
59 let hash = function
60 | Native (n, s) -> Hashtbl.combine (Hashtbl.hash n) (Hashtbl.hash s)
61 | ExprIdent s -> Ident.hash s
62 let stident = function
63 | Native (_, s) -> s
64 | ExprIdent s -> Ident.stident s
Something went wrong with that request. Please try again.