1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
(* depends.ML
Experimental code for communicating theorem dependencies from Isabelle
to Proof General.
This code is taken from thm_deps.ML in Isabelle 99-2. It's incompatible
with other Isabelle versions.
It is duplicated almost verbatim because what we need is
hardwired to a call on the browser tool.
*)
fun depends_enable () = Thm.keep_derivs := ThmDeriv;
fun depends_disable () = Thm.keep_derivs := MinDeriv;
fun is_internal (name, tags) = name = "" orelse Drule.has_internal tags;
fun is_thm_axm (Theorem x) = not (is_internal x)
| is_thm_axm (Axiom x) = not (is_internal x)
| is_thm_axm _ = false;
fun get_name (Theorem (s, _)) = s
| get_name (Axiom (s, _)) = s
| get_name _ = "";
fun make_deps_graph ((gra, parents), Join (ta, ders)) =
let
val name = get_name ta;
in
if is_thm_axm ta then
if is_none (Symtab.lookup (gra, name)) then
let
val (gra', parents') = foldl make_deps_graph ((gra, []), ders);
val prefx = #1 (Library.split_last (NameSpace.unpack name));
val session =
(case prefx of
(x :: _) =>
(case ThyInfo.lookup_theory x of
Some thy =>
let val name = #name (Present.get_info thy)
in if name = "" then [] else [name] end
| None => [])
| _ => ["global"]);
in
(Symtab.update ((name,
{name = Sign.base_name name, ID = name,
dir = space_implode "/" (session @ prefx),
unfold = false, path = "", parents = parents'}), gra'), name ins parents)
end
else (gra, name ins parents)
else
foldl make_deps_graph ((gra, parents), ders)
end;
fun thm_deps thms =
let
val _ = writeln "Generating graph ...";
val gra = map snd (Symtab.dest (fst (foldl make_deps_graph ((Symtab.empty, []),
map (#2 o #der o Thm.rep_thm) thms))));
val path = File.tmp_path (Path.unpack "theorems.graph");
val _ = Present.write_graph gra path;
val _ = system ("$ISATOOL browser -d " ^ Path.pack (Path.expand path) ^ " &");
in () end;
fun new_thm_deps thms =
let
val header = "Proof General, the theorem dependencies are: \"";
val gra = map snd (Symtab.dest (fst (foldl make_deps_graph ((Symtab.empty, []),
map (#2 o #der o Thm.rep_thm) thms))));
val deps = sort_strings (foldl (op union) ([],(map #parents gra)))
val msg = header ^ (space_implode " " deps) ^ "\""
in priority msg end;
val old_qed = qed;
fun qed name =
let val _ = old_qed name
val proved_thm = thm name
in new_thm_deps [proved_thm] end;
val old_qed_goal = qed_goal;
fun qed_goal name thy goal tacsf =
let val _ = old_qed_goal name thy goal tacsf
val proved_thm = thm name
in new_thm_deps [proved_thm] end;
val old_qed_goalw = qed_goalw;
fun qed_goalw name thy rews goal tacsf =
let val _ = old_qed_goalw name thy rews goal tacsf
val proved_thm = thm name
in new_thm_deps [proved_thm] end;
(* FIXME: this one only in HOL?? *)
val old_qed_spec_mp = qed_spec_mp;
fun qed_spec_mp name =
let val _ = old_qed_spec_mp name
val proved_thm = thm name
in new_thm_deps [proved_thm] end;
|