src/Pure/Tools/class_deps.ML
changeset 59423 3a0044e95eba
parent 59422 db6ecef63d5b
child 59936 b8ffc3dc9e24
equal deleted inserted replaced
59422:db6ecef63d5b 59423:3a0044e95eba
     4 Visualization of class dependencies.
     4 Visualization of class dependencies.
     5 *)
     5 *)
     6 
     6 
     7 signature CLASS_DEPS =
     7 signature CLASS_DEPS =
     8 sig
     8 sig
     9   val inlined_class_specs: bool Config.T
       
    10   val class_deps: Proof.context -> sort list option -> sort list option -> unit
     9   val class_deps: Proof.context -> sort list option -> sort list option -> unit
    11   val class_deps_cmd: Proof.context -> string list option -> string list option -> unit
    10   val class_deps_cmd: Proof.context -> string list option -> string list option -> unit
    12 end;
    11 end;
    13 
    12 
    14 structure Class_Deps: CLASS_DEPS =
    13 structure Class_Deps: CLASS_DEPS =
    15 struct
    14 struct
    16 
       
    17 val inlined_class_specs = Attrib.setup_config_bool @{binding "inlined_class_specs"} (K false);
       
    18 
       
    19 val stringify = XML.content_of o YXML.parse_body o Pretty.string_of;
       
    20 
    15 
    21 fun gen_class_deps prep_sort ctxt raw_subs raw_supers =
    16 fun gen_class_deps prep_sort ctxt raw_subs raw_supers =
    22   let
    17   let
    23     val thy = Proof_Context.theory_of ctxt;
    18     val thy = Proof_Context.theory_of ctxt;
    24     val some_subs = (Option.map o map) (prep_sort ctxt) raw_subs;
    19     val some_subs = (Option.map o map) (prep_sort ctxt) raw_subs;
    32       SOME supers => (fn class => exists (fn super => sort_le super [class]) supers)
    27       SOME supers => (fn class => exists (fn super => sort_le super [class]) supers)
    33     | NONE => K true
    28     | NONE => K true
    34     val (_, algebra) =
    29     val (_, algebra) =
    35       Sorts.subalgebra (Context.pretty ctxt)
    30       Sorts.subalgebra (Context.pretty ctxt)
    36         (le_sub andf super_le) (K NONE) original_algebra;
    31         (le_sub andf super_le) (K NONE) original_algebra;
    37     val inlined = Config.get ctxt inlined_class_specs;
    32     fun node c =
    38     fun label_for c =
    33       Graph_Display.content_node (Name_Space.extern ctxt space c)
    39       if inlined
    34         (Class.pretty_specification thy c);
    40       then (stringify o Pretty.block o op @) (Class.pretty_specification thy c)
       
    41       else Name_Space.extern ctxt space c;
       
    42     fun tooltip_for c =
       
    43       if inlined
       
    44       then []
       
    45       else
       
    46         let
       
    47           val pretty_spec = Class.pretty_specification thy c
       
    48         in
       
    49           if (null o snd) pretty_spec
       
    50           then []
       
    51           else [(Pretty.block o op @) pretty_spec]
       
    52         end;
       
    53     fun node c = Graph_Display.content_node (label_for c) (tooltip_for c);
       
    54   in
    35   in
    55     Sorts.classes_of algebra
    36     Sorts.classes_of algebra
    56     |> Graph.dest
    37     |> Graph.dest
    57     |> map (fn ((c, _), ds) => ((c, node c), ds))
    38     |> map (fn ((c, _), ds) => ((c, node c), ds))
    58     |> Graph_Display.display_graph
    39     |> Graph_Display.display_graph