From 6b377719c10d5ab3343fd5221f99a4a21008e25a Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Thu, 14 Mar 2024 08:26:58 +0100 Subject: Initial commit --- lib/containers/dune | 7 +++++ lib/containers/importContainers.ml | 61 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100755 lib/containers/dune create mode 100644 lib/containers/importContainers.ml (limited to 'lib/containers') diff --git a/lib/containers/dune b/lib/containers/dune new file mode 100755 index 0000000..46d0e24 --- /dev/null +++ b/lib/containers/dune @@ -0,0 +1,7 @@ +(library + (name importContainers) + (libraries + importDataTypes + importConf + ) +) diff --git a/lib/containers/importContainers.ml b/lib/containers/importContainers.ml new file mode 100644 index 0000000..bf65ba4 --- /dev/null +++ b/lib/containers/importContainers.ml @@ -0,0 +1,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 -- cgit v1.2.3