src/Pure/Thy/thm_deps.ML
author wenzelm
Wed Oct 17 18:52:30 2001 +0200 (2001-10-17)
changeset 11819 9283b3c11234
parent 11612 ae8450657bf0
child 12239 ee360f910ec8
permissions -rw-r--r--
tuned comments;
     1 (*  Title:      Pure/Thy/thm_deps.ML
     2     ID:         $Id$
     3     Author:     Stefan Berghofer, TU Muenchen
     4     License:    GPL (GNU GENERAL PUBLIC LICENSE)
     5 
     6 Visualize dependencies of theorems.
     7 *)
     8 
     9 signature BASIC_THM_DEPS =
    10 sig
    11   val thm_deps : thm list -> unit
    12 end;
    13 
    14 signature THM_DEPS =
    15 sig
    16   include BASIC_THM_DEPS
    17   val enable : unit -> unit
    18   val disable : unit -> unit
    19 end;
    20 
    21 structure ThmDeps : THM_DEPS =
    22 struct
    23 
    24 open Proofterm;
    25 
    26 fun enable () = if ! proofs = 0 then proofs := 1 else ();
    27 fun disable () = proofs := 0;
    28 
    29 fun dest_thm_axm (PThm (nt, prf, _, _)) = (nt, prf)
    30   | dest_thm_axm (PAxm (n, _, _)) = ((n ^ " (Ax)", []), MinProof [])
    31   | dest_thm_axm _ = (("", []), MinProof []);
    32 
    33 fun make_deps_graph (p, AbsP (_, _, prf)) = make_deps_graph (p, prf)
    34   | make_deps_graph (p, Abst (_, _, prf)) = make_deps_graph (p, prf)
    35   | make_deps_graph (p, prf1 %% prf2) =
    36       make_deps_graph (make_deps_graph (p, prf1), prf2)
    37   | make_deps_graph (p, prf % _) = make_deps_graph (p, prf)
    38   | make_deps_graph (p, MinProof prfs) = foldl make_deps_graph (p, prfs)
    39   | make_deps_graph (p as (gra, parents), prf) =
    40       let val ((name, tags), prf') = dest_thm_axm prf
    41       in
    42         if name <> "" andalso not (Drule.has_internal tags) then
    43           if is_none (Symtab.lookup (gra, name)) then
    44             let
    45               val (gra', parents') = make_deps_graph ((gra, []), prf');
    46               val prefx = #1 (Library.split_last (NameSpace.unpack name));
    47               val session =
    48                 (case prefx of
    49                   (x :: _) =>
    50                     (case ThyInfo.lookup_theory x of
    51                       Some thy =>
    52                         let val name = #name (Present.get_info thy)
    53                         in if name = "" then [] else [name] end 
    54                     | None => [])
    55                  | _ => ["global"]);
    56             in
    57               (Symtab.update ((name,
    58                 {name = Sign.base_name name, ID = name,
    59                  dir = space_implode "/" (session @ prefx),
    60                  unfold = false, path = "", parents = parents'}), gra'),
    61                name ins parents)
    62             end
    63           else (gra, name ins parents)
    64         else
    65           make_deps_graph ((gra, parents), prf')
    66       end;
    67 
    68 fun thm_deps thms =
    69   let
    70     val _ = writeln "Generating graph ...";
    71     val gra = map snd (Symtab.dest (fst (foldl make_deps_graph ((Symtab.empty, []),
    72       map (#2 o #der o Thm.rep_thm) thms))));
    73     val path = File.tmp_path (Path.unpack "theorems.graph");
    74     val _ = Present.write_graph gra path;
    75     val _ = system ("$ISATOOL browser -d " ^ Path.pack (Path.expand path) ^ " &");
    76   in () end;
    77 
    78 end;
    79 
    80 structure BasicThmDeps : BASIC_THM_DEPS = ThmDeps;
    81 open BasicThmDeps;