src/Pure/Thy/thy_info.ML
changeset 59177 f96ff29aa00c
parent 58928 23d0ffd48006
child 59178 e819a6683f87
equal deleted inserted replaced
59176:8cf1bad1c2e7 59177:f96ff29aa00c
     5 file dependencies.
     5 file dependencies.
     6 *)
     6 *)
     7 
     7 
     8 signature THY_INFO =
     8 signature THY_INFO =
     9 sig
     9 sig
    10   datatype action = Update | Remove
       
    11   val add_hook: (action -> string -> unit) -> unit
       
    12   val get_names: unit -> string list
    10   val get_names: unit -> string list
    13   val lookup_theory: string -> theory option
    11   val lookup_theory: string -> theory option
    14   val get_theory: string -> theory
    12   val get_theory: string -> theory
    15   val is_finished: string -> bool
    13   val is_finished: string -> bool
    16   val master_directory: string -> Path.T
    14   val master_directory: string -> Path.T
    27 end;
    25 end;
    28 
    26 
    29 structure Thy_Info: THY_INFO =
    27 structure Thy_Info: THY_INFO =
    30 struct
    28 struct
    31 
    29 
    32 (** theory loader actions and hooks **)
       
    33 
       
    34 datatype action = Update | Remove;
       
    35 
       
    36 local
       
    37   val hooks = Synchronized.var "Thy_Info.hooks" ([]: (action -> string -> unit) list);
       
    38 in
       
    39   fun add_hook f = Synchronized.change hooks (cons f);
       
    40   fun perform action name =
       
    41     List.app (fn f => (try (fn () => f action name) (); ())) (Synchronized.value hooks);
       
    42 end;
       
    43 
       
    44 
       
    45 
       
    46 (** thy database **)
    30 (** thy database **)
    47 
    31 
    48 (* messages *)
    32 (* messages *)
    49 
    33 
    50 val show_path = space_implode " via " o map quote;
    34 val show_path = space_implode " via " o map quote;
   134   if is_finished name then error ("Cannot update finished theory " ^ quote name)
   118   if is_finished name then error ("Cannot update finished theory " ^ quote name)
   135   else
   119   else
   136     let
   120     let
   137       val succs = thy_graph String_Graph.all_succs [name];
   121       val succs = thy_graph String_Graph.all_succs [name];
   138       val _ = writeln ("Theory loader: removing " ^ commas_quote succs);
   122       val _ = writeln ("Theory loader: removing " ^ commas_quote succs);
   139       val _ = List.app (perform Remove) succs;
       
   140       val _ = change_thys (fold String_Graph.del_node succs);
   123       val _ = change_thys (fold String_Graph.del_node succs);
   141     in () end);
   124     in () end);
   142 
   125 
   143 fun kill_thy name = NAMED_CRITICAL "Thy_Info" (fn () =>
   126 fun kill_thy name = NAMED_CRITICAL "Thy_Info" (fn () =>
   144   if known_thy name then remove_thy name
   127   if known_thy name then remove_thy name
   149     val name = Context.theory_name theory;
   132     val name = Context.theory_name theory;
   150     val parents = map Context.theory_name (Theory.parents_of theory);
   133     val parents = map Context.theory_name (Theory.parents_of theory);
   151     val _ = kill_thy name;
   134     val _ = kill_thy name;
   152     val _ = map get_theory parents;
   135     val _ = map get_theory parents;
   153     val _ = change_thys (new_entry name parents (SOME deps, SOME theory));
   136     val _ = change_thys (new_entry name parents (SOME deps, SOME theory));
   154     val _ = perform Update name;
       
   155   in () end);
   137   in () end);
   156 
   138 
   157 
   139 
   158 (* scheduling loader tasks *)
   140 (* scheduling loader tasks *)
   159 
   141