1 (**************************************************************************)
2 (* *)
3 (* OCaml *)
4 (* *)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 2002 Institut National de Recherche en Informatique et *)
8 (* en Automatique. *)
9 (* *)
10 (* All rights reserved. This file is distributed under the terms of *)
11 (* the GNU Lesser General Public License version 2.1, with the *)
12 (* special exception on linking described in the file LICENSE. *)
13 (* *)
14 (**************************************************************************)
15
16 (** Consistency tables: for checking consistency of module CRCs
17
18 {b Warning:} this module is unstable and part of
19 {{!Compiler_libs}compiler-libs}.
20
21 *)
22
23 open Misc
24
25 module Make (Module_name : sig
26 type t
27 module Set : Set.S with type elt = t
28 module Map : Map.S with type key = t
29 module Tbl : Hashtbl.S with type key = t
30 val compare : t -> t -> int
31 end) : sig
32 type t
33
34 val create: unit -> t
35
36 val clear: t -> unit
37
38 val check: t -> Module_name.t -> Digest.t -> filepath -> unit
39 (* [check tbl name crc source]
40 checks consistency of ([name], [crc]) with infos previously
41 stored in [tbl]. If no CRC was previously associated with
42 [name], record ([name], [crc]) in [tbl].
43 [source] is the name of the file from which the information
44 comes from. This is used for error reporting. *)
45
46 val check_noadd: t -> Module_name.t -> Digest.t -> filepath -> unit
47 (* Same as [check], but raise [Not_available] if no CRC was previously
48 associated with [name]. *)
49
50 val set: t -> Module_name.t -> Digest.t -> filepath -> unit
51 (* [set tbl name crc source] forcefully associates [name] with
52 [crc] in [tbl], even if [name] already had a different CRC
53 associated with [name] in [tbl]. *)
54
55 val source: t -> Module_name.t -> filepath
56 (* [source tbl name] returns the file name associated with [name]
57 if the latter has an associated CRC in [tbl].
58 Raise [Not_found] otherwise. *)
59
60 val extract: Module_name.t list -> t -> (Module_name.t * Digest.t option) list
61 (* [extract tbl names] returns an associative list mapping each string
62 in [names] to the CRC associated with it in [tbl]. If no CRC is
63 associated with a name then it is mapped to [None]. *)
64
65 val extract_map : Module_name.Set.t -> t -> Digest.t option Module_name.Map.t
66 (* Like [extract] but with a more sophisticated type. *)
67
68 val filter: (Module_name.t -> bool) -> t -> unit
69 (* [filter pred tbl] removes from [tbl] table all (name, CRC) pairs
70 such that [pred name] is [false]. *)
71
72 exception Inconsistency of Module_name.t * filepath * filepath
73 (* Raised by [check] when a CRC mismatch is detected.
74 First string is the name of the compilation unit.
75 Second string is the source that caused the inconsistency.
76 Third string is the source that set the CRC. *)
77
78 exception Not_available of Module_name.t
79 (* Raised by [check_noadd] when a name doesn't have an associated
80 CRC. *)
81 end
82