]> matita.cs.unibo.it Git - helm.git/blob - matita/components/binaries/matitadep/matitadep.ml
fdf5e980fdf594ac4739b59c1d242a0b4c39188f
[helm.git] / matita / components / binaries / matitadep / matitadep.ml
1 module StringSet = Set.Make (String) 
2
3 type file = {
4    ddeps: string list;
5    rdeps: StringSet.t option
6 }
7
8 let graph = Hashtbl.create 503
9
10 let add fname =
11    if Hashtbl.mem graph fname then () else
12    Hashtbl.add graph fname {ddeps = []; rdeps = None}
13
14 let add_ddep fname dname =
15    let file = Hashtbl.find graph fname in
16    Hashtbl.replace graph fname {file with ddeps = dname :: file.ddeps} 
17
18 let init fname dname =
19    add fname; add dname; add_ddep fname dname 
20
21 let rec compute fname file = match file.rdeps with
22    | Some rdeps -> rdeps
23    | None       ->
24       let rdeps = List.fold_left (iter fname) StringSet.empty file.ddeps in
25       Hashtbl.replace graph fname {file with rdeps = Some rdeps};
26       rdeps
27
28 and iter fname rdeps dname =
29    if StringSet.mem dname rdeps then
30       begin Printf.printf "%s: redundant %s\n" fname dname; rdeps end
31    else
32      let file = Hashtbl.find graph dname in
33      StringSet.add dname (StringSet.union (compute dname file) rdeps)
34
35 let check () = 
36    let iter fname file = 
37       if StringSet.mem fname (compute fname file) then
38          Printf.printf "%s: circular\n" fname 
39    in
40    Hashtbl.iter iter graph 
41
42 let rec read ich = 
43    let _ = Scanf.fscanf ich "%s@:include \"%s@\". " init in
44    read ich
45    
46 let _ =
47    try read stdin with End_of_file -> check ()