src/Pure/Thy/thm_deps.ML
author berghofe
Fri Sep 28 11:04:44 2001 +0200 (2001-09-28)
changeset 11612 ae8450657bf0
parent 11543 d61b913431c5
child 11819 9283b3c11234
permissions -rw-r--r--
Exchanged % and %%.
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@11530
    23
open Proofterm;
berghofe@7765
    24
wenzelm@11543
    25
fun enable () = if ! proofs = 0 then proofs := 1 else ();
wenzelm@11543
    26
fun disable () = proofs := 0;
berghofe@7765
    27
berghofe@11530
    28
fun dest_thm_axm (PThm (nt, prf, _, _)) = (nt, prf)
berghofe@11530
    29
  | dest_thm_axm (PAxm (n, _, _)) = ((n ^ " (Ax)", []), MinProof [])
berghofe@11530
    30
  | dest_thm_axm _ = (("", []), MinProof []);
berghofe@7765
    31
berghofe@11530
    32
fun make_deps_graph (p, AbsP (_, _, prf)) = make_deps_graph (p, prf)
berghofe@11530
    33
  | make_deps_graph (p, Abst (_, _, prf)) = make_deps_graph (p, prf)
berghofe@11612
    34
  | make_deps_graph (p, prf1 %% prf2) =
berghofe@11530
    35
      make_deps_graph (make_deps_graph (p, prf1), prf2)
berghofe@11612
    36
  | make_deps_graph (p, prf % _) = make_deps_graph (p, prf)
berghofe@11530
    37
  | make_deps_graph (p, MinProof prfs) = foldl make_deps_graph (p, prfs)
berghofe@11530
    38
  | make_deps_graph (p as (gra, parents), prf) =
berghofe@11530
    39
      let val ((name, tags), prf') = dest_thm_axm prf
berghofe@11530
    40
      in
berghofe@11530
    41
        if name <> "" andalso not (Drule.has_internal tags) then
berghofe@11530
    42
          if is_none (Symtab.lookup (gra, name)) then
berghofe@11530
    43
            let
berghofe@11530
    44
              val (gra', parents') = make_deps_graph ((gra, []), prf');
berghofe@11530
    45
              val prefx = #1 (Library.split_last (NameSpace.unpack name));
berghofe@11530
    46
              val session =
berghofe@11530
    47
                (case prefx of
berghofe@11530
    48
                  (x :: _) =>
berghofe@11530
    49
                    (case ThyInfo.lookup_theory x of
berghofe@11530
    50
                      Some thy =>
berghofe@11530
    51
                        let val name = #name (Present.get_info thy)
berghofe@11530
    52
                        in if name = "" then [] else [name] end 
berghofe@11530
    53
                    | None => [])
berghofe@11530
    54
                 | _ => ["global"]);
berghofe@11530
    55
            in
berghofe@11530
    56
              (Symtab.update ((name,
berghofe@11530
    57
                {name = Sign.base_name name, ID = name,
berghofe@11530
    58
                 dir = space_implode "/" (session @ prefx),
berghofe@11530
    59
                 unfold = false, path = "", parents = parents'}), gra'),
berghofe@11530
    60
               name ins parents)
berghofe@11530
    61
            end
berghofe@11530
    62
          else (gra, name ins parents)
berghofe@11530
    63
        else
berghofe@11530
    64
          make_deps_graph ((gra, parents), prf')
berghofe@11530
    65
      end;
berghofe@7765
    66
berghofe@7765
    67
fun thm_deps thms =
berghofe@7765
    68
  let
berghofe@7765
    69
    val _ = writeln "Generating graph ...";
berghofe@7765
    70
    val gra = map snd (Symtab.dest (fst (foldl make_deps_graph ((Symtab.empty, []),
wenzelm@9502
    71
      map (#2 o #der o Thm.rep_thm) thms))));
berghofe@7765
    72
    val path = File.tmp_path (Path.unpack "theorems.graph");
wenzelm@9450
    73
    val _ = Present.write_graph gra path;
wenzelm@7853
    74
    val _ = system ("$ISATOOL browser -d " ^ Path.pack (Path.expand path) ^ " &");
berghofe@7765
    75
  in () end;
berghofe@7765
    76
berghofe@7765
    77
end;
berghofe@7765
    78
berghofe@7785
    79
structure BasicThmDeps : BASIC_THM_DEPS = ThmDeps;
berghofe@7785
    80
open BasicThmDeps;