Skip to content
This repository
tree: 6b295a97eb
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 65 lines (55 sloc) 1.812 kb
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
(*
Copyright © 2011 MLstate

This file is part of OPA.

OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.

OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.

You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
module Hashtbl = BaseHashtbl
module String = BaseString

(* -- *)

type native_ident = [ `global | `local ]

type t =
  | ExprIdent of Ident.t
  | Native of native_ident * string

let compare_native n1 n2 =
  if n1 = `local
  then
    match n2 with
    | `local -> 0
    | `global -> -1
  else
    match n2 with
    | `local -> 1
    | `global -> 0

let compare i1 i2 =
  match i1, i2 with
  | Native (n1, s1), Native (n2, s2) ->
      let res = compare_native n1 n2 in
      if res <> 0 then res
      else
        String.compare s1 s2
  | Native _, ExprIdent _ -> -1
  | ExprIdent _, Native _ -> 1
  | ExprIdent i1, ExprIdent i2 -> Ident.compare i1 i2
let equal i1 i2 =
  match i1, i2 with
  | Native (n1, s1), Native (n2, s2) -> n1 = n2 && String.equal s1 s2
  | ExprIdent i1, ExprIdent i2 -> Ident.equal i1 i2
  | Native _, ExprIdent _
  | ExprIdent _, Native _ -> false
let to_string = function
  | Native (_, s) -> s
  | ExprIdent s -> Ident.to_string s
let hash = function
  | Native (n, s) -> Hashtbl.combine (Hashtbl.hash n) (Hashtbl.hash s)
  | ExprIdent s -> Ident.hash s
let stident = function
  | Native (_, s) -> s
  | ExprIdent s -> Ident.stident s
Something went wrong with that request. Please try again.