aboutsummaryrefslogtreecommitdiff
path: root/lib/containers/importContainers.ml
blob: bf65ba44de5590324b88dc8cf3b1b7a9b3c476d0 (plain)
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
module Conf = ImportConf
module Syntax = Conf.Syntax
module Table = ImportDataTypes.Table

(** This key is used to create the table of each externals in the
    configuration. 

    This table allow to check if there are cycles between the references *)
module KeyName : sig
  type t

  val compare : t -> t -> int
  val from_table : Table.t -> t
  val hash : t -> int
  val equal : t -> t -> bool
end = struct
  type t = Table.t

  let compare v1 v2 = String.compare (Table.name v1) (Table.name v2)
  (* We use the alias given in the configuration as key, because we want to
     be sure there is no cycle in the dependencies. It’s OK to have the same
     file used in differents sources, but the sources cannot induce cycles *)

  let from_table (s : Table.t) = s
  let hash = Hashtbl.hash
  let equal v1 v2 = String.equal (Table.name v1) (Table.name v2)
end

module Source : sig
  type t

  val compare : t -> t -> int
  val from_table : Table.t -> t
  val hash : t -> int
  val equal : t -> t -> bool
  val name : t -> KeyName.t
end = struct
  type t = Table.t

  let compare v1 v2 = String.compare v1.Table.name v2.Table.name
  (* We use the alias given in the configuration as key, because we want to
     be sure there is no cycle in the dependencies. It’s OK to have the same
     file used in differents sources, but the sources cannot induce cycles *)

  let from_table (s : Table.t) = s
  let hash = Hashtbl.hash
  let equal v1 v2 = String.equal v1.Table.name v2.Table.name
  let name t = KeyName.from_table t
end

module Externals = MoreLabels.Map.Make (KeyName)
module IntSet = MoreLabels.Set.Make (Int)

let show_intSet set =
  let b = Buffer.create 16 in
  IntSet.iter
    ~f:(fun v ->
      Buffer.add_string b (string_of_int v);
      Buffer.add_char b ',')
    set;
  Buffer.contents b