src/Pure/Thy/thy_info.ML
changeset 9327 07598d493d33
parent 9137 bec42c975d13
child 9332 ff3a86a00ea5
equal deleted inserted replaced
9326:1625c1f172b3 9327:07598d493d33
    79 fun cycle_msg name names = loader_msg ("cyclic dependency of " ^ show_path (name :: names)) [];
    79 fun cycle_msg name names = loader_msg ("cyclic dependency of " ^ show_path (name :: names)) [];
    80 
    80 
    81 
    81 
    82 (* derived graph operations *)
    82 (* derived graph operations *)
    83 
    83 
    84 fun add_deps name parents G =
    84 fun add_deps name parents G = Graph.add_deps_acyclic (name, parents) G
    85   foldl (fn (H, parent) => Graph.add_edge_acyclic (parent, name) H) (G, parents)
    85   handle Graph.CYCLES namess => error (cat_lines (map (cycle_msg name) namess));
    86     handle Graph.CYCLES namess => error (cat_lines (map (cycle_msg name) namess));
       
    87 
    86 
    88 fun upd_deps name entry G =
    87 fun upd_deps name entry G =
    89   foldl (fn (H, parent) => Graph.del_edge (parent, name) H) (G, Graph.imm_preds G name)
    88   foldl (fn (H, parent) => Graph.del_edge (parent, name) H) (G, Graph.imm_preds G name)
    90   |> Graph.map_node name (K entry);
    89   |> Graph.map_node name (K entry);
    91 
    90 
   124 
   123 
   125 
   124 
   126 (* access thy *)
   125 (* access thy *)
   127 
   126 
   128 fun lookup_thy name =
   127 fun lookup_thy name =
   129   Some (thy_graph Graph.get_node name) handle Graph.UNDEFINED _ => None;
   128   Some (thy_graph Graph.get_node name) handle Graph.UNDEF _ => None;
   130 
   129 
   131 val known_thy = is_some o lookup_thy;
   130 val known_thy = is_some o lookup_thy;
   132 fun check_known_thy name = known_thy name orelse (warning ("Unknown theory " ^ quote name); false);
   131 fun check_known_thy name = known_thy name orelse (warning ("Unknown theory " ^ quote name); false);
   133 fun if_known_thy f name = if check_known_thy name then f name else ();
   132 fun if_known_thy f name = if check_known_thy name then f name else ();
   134 
   133 
   155   | Some {master, files, ...} =>
   154   | Some {master, files, ...} =>
   156       (case master of Some m => [#1 (ThyLoad.get_thy m)] | None => []) @
   155       (case master of Some m => [#1 (ThyLoad.get_thy m)] | None => []) @
   157       (mapfilter (apsome #1 o #2) files));
   156       (mapfilter (apsome #1 o #2) files));
   158 
   157 
   159 fun get_preds name =
   158 fun get_preds name =
   160   (thy_graph Graph.imm_preds name) handle Graph.UNDEFINED _ =>
   159   (thy_graph Graph.imm_preds name) handle Graph.UNDEF _ =>
   161     error (loader_msg "nothing known about theory" [name]);
   160     error (loader_msg "nothing known about theory" [name]);
   162 
   161 
   163 
   162 
   164 (* access theory *)
   163 (* access theory *)
   165 
   164 
   415       else Some y_name;
   414       else Some y_name;
   416     val variants = mapfilter get_variant (parents ~~ parent_names);
   415     val variants = mapfilter get_variant (parents ~~ parent_names);
   417 
   416 
   418     fun register G =
   417     fun register G =
   419       (Graph.new_node (name, (None, Some theory)) G
   418       (Graph.new_node (name, (None, Some theory)) G
   420         handle Graph.DUPLICATE _ => err "duplicate theory entry" [])
   419         handle Graph.DUP _ => err "duplicate theory entry" [])
   421       |> add_deps name parent_names;
   420       |> add_deps name parent_names;
   422   in
   421   in
   423     if not (null nonfinished) then err "non-finished parent theories" nonfinished
   422     if not (null nonfinished) then err "non-finished parent theories" nonfinished
   424     else if not (null variants) then err "different versions of parent theories" variants
   423     else if not (null variants) then err "different versions of parent theories" variants
   425     else (change_thys register; perform Update name)
   424     else (change_thys register; perform Update name)