(***********************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* string let hash_sub hstr id = hstr id let equal id1 id2 = id1 == id2 let hash = Hashtbl.hash end) module IdOrdered = struct type t = identifier let compare = id_ord end module Idset = Set.Make(IdOrdered) module Idmap = Map.Make(IdOrdered) module Idpred = Predicate.Make(IdOrdered) let pr_id id = [< 'sTR (string_of_id id) >] let wildcard = id_of_string "_" (* Names *) type name = Name of identifier | Anonymous (*s Directory paths = section names paths *) let parse_fields s = let len = String.length s in let rec decoupe_dirs n = try let pos = String.index_from s n '.' in let dir = String.sub s n (pos-n) in let dirs,n' = decoupe_dirs (succ pos) in (id_of_string dir)::dirs,n' with | Not_found -> [],n in if len = 0 then invalid_arg "parse_section_path"; let dirs,n = decoupe_dirs 0 in let id = String.sub s n (len-n) in dirs, (id_of_string id) type module_ident = identifier type dir_path = module_ident list module ModIdOrdered = struct type t = identifier let compare = Pervasives.compare end module ModIdmap = Map.Make(ModIdOrdered) let make_dirpath x = x let repr_dirpath x = x let string_of_dirpath = function | [] -> "" | sl -> String.concat "." (List.map string_of_id (List.rev sl)) let pr_dirpath sl = [< 'sTR (string_of_dirpath sl) >] (*s Section paths are absolute names *) type section_path = { dirpath : dir_path ; basename : identifier } let make_path pa id = { dirpath = pa; basename = id } let repr_path { dirpath = pa; basename = id } = (pa,id) (* parsing and printing of section paths *) let string_of_path sp = let (sl,id) = repr_path sp in if sl = [] then string_of_id id else (string_of_dirpath sl) ^ "." ^ (string_of_id id) let pr_sp sp = [< 'sTR (string_of_path sp) >] let sp_ord sp1 sp2 = let (p1,id1) = repr_path sp1 and (p2,id2) = repr_path sp2 in let p_bit = compare p1 p2 in if p_bit = 0 then id_ord id1 id2 else p_bit module SpOrdered = struct type t = section_path let compare = sp_ord end module Spset = Set.Make(SpOrdered) module Sppred = Predicate.Make(SpOrdered) module Spmap = Map.Make(SpOrdered) (*s********************************************************************) (* type of global reference *) type variable = identifier type constant = section_path type inductive = section_path * int type constructor = inductive * int type mutual_inductive = section_path let ith_mutual_inductive (sp,_) i = (sp,i) let ith_constructor_of_inductive ind_sp i = (ind_sp,i) let inductive_of_constructor (ind_sp,i) = ind_sp let index_of_constructor (ind_sp,i) = i (* Hash-consing of name objects *) module Hname = Hashcons.Make( struct type t = name type u = identifier -> identifier let hash_sub hident = function | Name id -> Name (hident id) | n -> n let equal n1 n2 = match (n1,n2) with | (Name id1, Name id2) -> id1 == id2 | (Anonymous,Anonymous) -> true | _ -> false let hash = Hashtbl.hash end) module Hdir = Hashcons.Make( struct type t = dir_path type u = identifier -> identifier let hash_sub hident d = List.map hident d let equal d1 d2 = List.for_all2 (==) d1 d2 let hash = Hashtbl.hash end) module Hsp = Hashcons.Make( struct type t = section_path type u = identifier -> identifier let hash_sub hident sp = { dirpath = List.map hident sp.dirpath; basename = hident sp.basename } let equal sp1 sp2 = (List.length sp1.dirpath = List.length sp2.dirpath) && (List.for_all2 (==) sp1.dirpath sp2.dirpath) let hash = Hashtbl.hash end) let hcons_names () = let hstring = Hashcons.simple_hcons Hashcons.Hstring.f () in let hident = Hashcons.simple_hcons Hident.f hstring in let hname = Hashcons.simple_hcons Hname.f hident in let hdir = Hashcons.simple_hcons Hdir.f hident in let hspcci = Hashcons.simple_hcons Hsp.f hident in (hspcci,hdir,hname,hident,hstring)