2016-02-18 07:11:59 -08:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* OCaml *)
|
|
|
|
(* *)
|
|
|
|
(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2001 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. This file is distributed under the terms of *)
|
|
|
|
(* the GNU Lesser General Public License version 2.1, with the *)
|
|
|
|
(* special exception on linking described in the file LICENSE. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2006-09-20 04:14:37 -07:00
|
|
|
(** Definition of a class which outputs a dot file showing
|
2002-03-27 08:20:32 -08:00
|
|
|
top modules dependencies.*)
|
|
|
|
|
2002-08-13 07:09:26 -07:00
|
|
|
open Odoc_info
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
module F = Format
|
|
|
|
|
2010-08-24 02:45:45 -07:00
|
|
|
let dot_include_all = ref false
|
|
|
|
|
|
|
|
let dot_types = ref false
|
|
|
|
|
|
|
|
let dot_reduce = ref false
|
|
|
|
|
|
|
|
let dot_colors = ref (List.flatten Odoc_messages.default_dot_colors)
|
|
|
|
|
|
|
|
module Generator =
|
|
|
|
struct
|
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
(** This class generates a dot file showing the top modules dependencies. *)
|
|
|
|
class dot =
|
|
|
|
object (self)
|
|
|
|
|
|
|
|
(** To store the colors associated to locations of modules. *)
|
|
|
|
val mutable loc_colors = []
|
|
|
|
|
|
|
|
(** the list of modules we know. *)
|
|
|
|
val mutable modules = []
|
|
|
|
|
|
|
|
(** Colors to use when finding new locations of modules. *)
|
2010-08-24 02:45:45 -07:00
|
|
|
val mutable colors = !dot_colors
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Graph header. *)
|
2006-09-20 04:14:37 -07:00
|
|
|
method header =
|
2002-03-27 08:20:32 -08:00
|
|
|
"digraph G {\n"^
|
|
|
|
" size=\"10,7.5\";\n"^
|
|
|
|
" ratio=\"fill\";\n"^
|
|
|
|
" rotate=90;\n"^
|
|
|
|
" fontsize=\"12pt\";\n"^
|
|
|
|
" rankdir = TB ;\n"
|
|
|
|
|
|
|
|
method get_one_color =
|
|
|
|
match colors with
|
2002-07-23 07:12:03 -07:00
|
|
|
[] -> None
|
2006-09-20 04:14:37 -07:00
|
|
|
| h :: q ->
|
2002-07-23 07:12:03 -07:00
|
|
|
colors <- q ;
|
|
|
|
Some h
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
method node_color s =
|
|
|
|
try Some (List.assoc s loc_colors)
|
|
|
|
with
|
2006-09-20 04:14:37 -07:00
|
|
|
Not_found ->
|
2002-07-23 07:12:03 -07:00
|
|
|
match self#get_one_color with
|
|
|
|
None -> None
|
|
|
|
| Some c ->
|
|
|
|
loc_colors <- (s, c) :: loc_colors ;
|
|
|
|
Some c
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
method print_module_atts fmt m =
|
|
|
|
match self#node_color (Filename.dirname m.Module.m_file) with
|
2002-07-23 07:12:03 -07:00
|
|
|
None -> ()
|
|
|
|
| Some col -> F.fprintf fmt "\"%s\" [style=filled, color=%s];\n" m.Module.m_name col
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
method print_type_atts fmt t =
|
|
|
|
match self#node_color (Name.father t.Type.ty_name) with
|
2002-07-23 07:12:03 -07:00
|
|
|
None -> ()
|
|
|
|
| Some col -> F.fprintf fmt "\"%s\" [style=filled, color=%s];\n" t.Type.ty_name col
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
method print_one_dep fmt src dest =
|
|
|
|
F.fprintf fmt "\"%s\" -> \"%s\";\n" src dest
|
|
|
|
|
|
|
|
method generate_for_module fmt m =
|
2006-09-20 04:14:37 -07:00
|
|
|
let l = List.filter
|
|
|
|
(fun n ->
|
2013-05-28 04:04:11 -07:00
|
|
|
!dot_include_all ||
|
2006-09-20 04:14:37 -07:00
|
|
|
(List.exists (fun m -> m.Module.m_name = n) modules))
|
2002-07-23 07:12:03 -07:00
|
|
|
m.Module.m_top_deps
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
|
|
|
self#print_module_atts fmt m;
|
|
|
|
List.iter (self#print_one_dep fmt m.Module.m_name) l
|
|
|
|
|
|
|
|
method generate_for_type fmt (t, l) =
|
|
|
|
self#print_type_atts fmt t;
|
|
|
|
List.iter
|
2002-07-23 07:12:03 -07:00
|
|
|
(self#print_one_dep fmt t.Type.ty_name)
|
|
|
|
l
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
method generate_types types =
|
|
|
|
try
|
2010-08-24 02:45:45 -07:00
|
|
|
let oc = open_out !Global.out_file in
|
2002-07-23 07:12:03 -07:00
|
|
|
let fmt = F.formatter_of_out_channel oc in
|
|
|
|
F.fprintf fmt "%s" self#header;
|
2006-09-20 04:14:37 -07:00
|
|
|
let graph = Odoc_info.Dep.deps_of_types
|
2010-08-24 02:45:45 -07:00
|
|
|
~kernel: !dot_reduce
|
2006-09-20 04:14:37 -07:00
|
|
|
types
|
2002-07-23 07:12:03 -07:00
|
|
|
in
|
|
|
|
List.iter (self#generate_for_type fmt) graph;
|
|
|
|
F.fprintf fmt "}\n" ;
|
|
|
|
F.pp_print_flush fmt ();
|
|
|
|
close_out oc
|
2002-03-27 08:20:32 -08:00
|
|
|
with
|
2002-07-23 07:12:03 -07:00
|
|
|
Sys_error s ->
|
|
|
|
raise (Failure s)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2006-09-20 04:14:37 -07:00
|
|
|
method generate_modules modules_list =
|
2002-03-27 08:20:32 -08:00
|
|
|
try
|
2002-07-23 07:12:03 -07:00
|
|
|
modules <- modules_list ;
|
2010-08-24 02:45:45 -07:00
|
|
|
let oc = open_out !Global.out_file in
|
2002-07-23 07:12:03 -07:00
|
|
|
let fmt = F.formatter_of_out_channel oc in
|
|
|
|
F.fprintf fmt "%s" self#header;
|
|
|
|
|
2010-08-24 02:45:45 -07:00
|
|
|
if !dot_reduce then
|
2002-07-23 07:12:03 -07:00
|
|
|
Odoc_info.Dep.kernel_deps_of_modules modules_list;
|
|
|
|
|
|
|
|
List.iter (self#generate_for_module fmt) modules_list;
|
|
|
|
F.fprintf fmt "}\n" ;
|
|
|
|
F.pp_print_flush fmt ();
|
|
|
|
close_out oc
|
2002-03-27 08:20:32 -08:00
|
|
|
with
|
2002-07-23 07:12:03 -07:00
|
|
|
Sys_error s ->
|
|
|
|
raise (Failure s)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2002-10-11 01:25:17 -07:00
|
|
|
(** Generate the dot code in the file {!Odoc_info.Args.out_file}. *)
|
2002-03-27 08:20:32 -08:00
|
|
|
method generate (modules_list : Odoc_info.Module.t_module list) =
|
2010-08-24 02:45:45 -07:00
|
|
|
colors <- !dot_colors;
|
|
|
|
if !dot_types then
|
2002-07-23 07:12:03 -07:00
|
|
|
self#generate_types (Odoc_info.Search.types modules_list)
|
2002-03-27 08:20:32 -08:00
|
|
|
else
|
2002-07-23 07:12:03 -07:00
|
|
|
self#generate_modules modules_list
|
2002-03-27 08:20:32 -08:00
|
|
|
end
|
2010-08-24 02:45:45 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
module type Dot_generator = module type of Generator
|