author | haftmann |
Mon, 05 Jan 2015 18:39:32 +0100 | |
changeset 59296 | 002d817b4c37 |
parent 59210 | 8658b4290aed |
child 59301 | 9089639ba348 |
permissions | -rw-r--r-- |
58201 | 1 |
(* Title: Pure/Tools/class_deps.ML |
2 |
Author: Florian Haftmann, TU Muenchen |
|
3 |
||
4 |
Visualization of class dependencies. |
|
5 |
*) |
|
6 |
||
7 |
signature CLASS_DEPS = |
|
8 |
sig |
|
59210
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
9 |
val class_deps: Proof.context -> sort -> sort option -> unit |
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
10 |
val class_deps_cmd: Proof.context -> string -> string option -> unit |
58201 | 11 |
end; |
12 |
||
59210
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
13 |
structure Class_Deps: CLASS_DEPS = |
58201 | 14 |
struct |
15 |
||
58202 | 16 |
fun gen_visualize prep_sort ctxt raw_super raw_sub = |
58201 | 17 |
let |
59296
002d817b4c37
formal pretty bodies for class specifications, accepting additional formal bookkeeping in locale.ML
haftmann
parents:
59210
diff
changeset
|
18 |
val thy = Proof_Context.theory_of ctxt; |
58202 | 19 |
val super = prep_sort ctxt raw_super; |
20 |
val sub = Option.map (prep_sort ctxt) raw_sub; |
|
21 |
val {classes = (space, original_algebra), ...} = Type.rep_tsig (Proof_Context.tsig_of ctxt); |
|
22 |
fun le_super class = Sorts.sort_le original_algebra ([class], super); |
|
59210
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
23 |
val sub_le = |
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
24 |
(case sub of |
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
25 |
NONE => K true |
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
26 |
| SOME sub => fn class => Sorts.sort_le original_algebra (sub, [class])); |
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
27 |
val (_, algebra) = |
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
28 |
Sorts.subalgebra (Context.pretty ctxt) |
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
29 |
(le_super andf sub_le) (K NONE) original_algebra; |
59296
002d817b4c37
formal pretty bodies for class specifications, accepting additional formal bookkeeping in locale.ML
haftmann
parents:
59210
diff
changeset
|
30 |
fun pretty_body_of c = if Class.is_class thy c then Class.pretty_body thy c else []; |
59210
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
31 |
in |
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
32 |
Sorts.classes_of algebra |
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
33 |
|> Graph.dest |
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
34 |
|> map (fn ((c, _), ds) => |
59296
002d817b4c37
formal pretty bodies for class specifications, accepting additional formal bookkeeping in locale.ML
haftmann
parents:
59210
diff
changeset
|
35 |
((c, Graph_Display.content_node (Name_Space.extern ctxt space c) (pretty_body_of c)), ds)) |
59210
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
36 |
|> Graph_Display.display_graph |
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
37 |
end; |
58202 | 38 |
|
59210
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
39 |
val class_deps = gen_visualize (Type.cert_sort o Proof_Context.tsig_of); |
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
40 |
val class_deps_cmd = gen_visualize Syntax.read_sort; |
58201 | 41 |
|
42 |
val _ = |
|
58893
9e0ecb66d6a7
eliminated unused int_only flag (see also c12484a27367);
wenzelm
parents:
58202
diff
changeset
|
43 |
Outer_Syntax.command @{command_spec "class_deps"} "visualize class dependencies" |
59210
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
44 |
((Scan.optional Parse.sort "{}" -- Scan.option Parse.sort) >> (fn (super, sub) => |
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
45 |
(Toplevel.unknown_theory o |
8658b4290aed
clarified Graph_Display.graph etc.: sort_graph determines order from structure (and names);
wenzelm
parents:
59208
diff
changeset
|
46 |
Toplevel.keep (fn st => class_deps_cmd (Toplevel.context_of st) super sub)))); |
58201 | 47 |
|
48 |
end; |