src/Pure/Thy/thm_deps.ML
author wenzelm
Thu Jul 27 18:23:12 2000 +0200 (2000-07-27)
changeset 9450 c97dba47e504
parent 7853 a4acf1b4d5a8
child 9502 50ec59aff389
permissions -rw-r--r--
tuned;
berghofe@7765
     1
(*  Title:      Pure/Thy/thm_deps.ML
berghofe@7765
     2
    ID:         $Id$
berghofe@7765
     3
    Author:     Stefan Berghofer, TU Muenchen
berghofe@7765
     4
berghofe@7765
     5
Visualize dependencies of theorems.
berghofe@7765
     6
*)
berghofe@7765
     7
berghofe@7785
     8
signature BASIC_THM_DEPS =
berghofe@7785
     9
sig
berghofe@7785
    10
  val thm_deps : thm list -> unit
berghofe@7785
    11
end;
berghofe@7785
    12
berghofe@7765
    13
signature THM_DEPS =
berghofe@7765
    14
sig
berghofe@7785
    15
  include BASIC_THM_DEPS
berghofe@7785
    16
  val enable : unit -> unit
berghofe@7785
    17
  val disable : unit -> unit
berghofe@7765
    18
end;
berghofe@7765
    19
berghofe@7765
    20
structure ThmDeps : THM_DEPS =
berghofe@7765
    21
struct
berghofe@7765
    22
berghofe@7785
    23
fun enable () = Thm.keep_derivs := ThmDeriv;
berghofe@7785
    24
fun disable () = Thm.keep_derivs := MinDeriv;
berghofe@7785
    25
wenzelm@9450
    26
fun is_internal (name, tags) = name = "" orelse Drule.has_internal tags;
berghofe@7765
    27
wenzelm@9450
    28
fun is_thm_axm (Theorem x) = not (is_internal x)
wenzelm@9450
    29
  | is_thm_axm (Axiom x) = not (is_internal x)
berghofe@7765
    30
  | is_thm_axm _ = false;
berghofe@7765
    31
berghofe@7765
    32
fun get_name (Theorem (s, _)) = s
berghofe@7765
    33
  | get_name (Axiom (s, _)) = s
berghofe@7765
    34
  | get_name _ = "";
berghofe@7765
    35
berghofe@7765
    36
fun make_deps_graph ((gra, parents), Join (ta, ders)) =
berghofe@7765
    37
  let
berghofe@7765
    38
    val name = get_name ta;
berghofe@7765
    39
  in
berghofe@7765
    40
    if is_thm_axm ta then
berghofe@7765
    41
      if is_none (Symtab.lookup (gra, name)) then
berghofe@7765
    42
        let
berghofe@7765
    43
          val (gra', parents') = foldl make_deps_graph ((gra, []), ders);
wenzelm@9450
    44
          val prefx = #1 (Library.split_last (NameSpace.unpack name));
wenzelm@9450
    45
          val session =
wenzelm@9450
    46
            (case prefx of
wenzelm@9450
    47
              (x :: _) =>
wenzelm@9450
    48
                (case ThyInfo.lookup_theory x of
wenzelm@9450
    49
                  Some thy =>
wenzelm@9450
    50
                    let val name = #name (Present.get_info thy)
wenzelm@9450
    51
                    in if name = "" then [] else [name] end 
wenzelm@9450
    52
                | None => [])
wenzelm@9450
    53
             | _ => ["global"]);
berghofe@7765
    54
        in
berghofe@7786
    55
          (Symtab.update ((name,
berghofe@7765
    56
            {name = Sign.base_name name, ID = name,
berghofe@7765
    57
             dir = space_implode "/" (session @ prefx),
berghofe@7765
    58
             unfold = false, path = "", parents = parents'}), gra'), name ins parents)
berghofe@7765
    59
        end
berghofe@7765
    60
      else (gra, name ins parents)
berghofe@7765
    61
    else
berghofe@7765
    62
      foldl make_deps_graph ((gra, parents), ders)
berghofe@7765
    63
  end;
berghofe@7765
    64
berghofe@7765
    65
fun thm_deps thms =
berghofe@7765
    66
  let
berghofe@7765
    67
    val _ = writeln "Generating graph ...";
berghofe@7765
    68
    val gra = map snd (Symtab.dest (fst (foldl make_deps_graph ((Symtab.empty, []),
wenzelm@9450
    69
      map (#der o Thm.rep_thm) thms))));
berghofe@7765
    70
    val path = File.tmp_path (Path.unpack "theorems.graph");
wenzelm@9450
    71
    val _ = Present.write_graph gra path;
wenzelm@7853
    72
    val _ = system ("$ISATOOL browser -d " ^ Path.pack (Path.expand path) ^ " &");
berghofe@7765
    73
  in () end;
berghofe@7765
    74
berghofe@7765
    75
end;
berghofe@7765
    76
berghofe@7785
    77
structure BasicThmDeps : BASIC_THM_DEPS = ThmDeps;
berghofe@7785
    78
open BasicThmDeps;