aboutsummaryrefslogtreecommitdiff
path: root/lib/containers/importContainers.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/containers/importContainers.ml')
-rw-r--r--lib/containers/importContainers.ml61
1 files changed, 61 insertions, 0 deletions
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