src/Pure/Isar/locale.ML
changeset 46858 05f30c796f95
parent 45601 d5178f19b671
child 46859 79f712a9a815
equal deleted inserted replaced
46857:628b4a3fbf6e 46858:05f30c796f95
   105 
   105 
   106 fun insert_mixin serial' mixin =
   106 fun insert_mixin serial' mixin =
   107   Inttab.map_default (serial', []) (cons (mixin, serial ()));
   107   Inttab.map_default (serial', []) (cons (mixin, serial ()));
   108 
   108 
   109 fun rename_mixin (old, new) mix =
   109 fun rename_mixin (old, new) mix =
   110   case Inttab.lookup mix old of
   110   (case Inttab.lookup mix old of
   111     NONE => mix |
   111     NONE => mix
   112     SOME mxs => Inttab.delete old mix |> Inttab.update_new (new, mxs);
   112   | SOME mxs => Inttab.delete old mix |> Inttab.update_new (new, mxs));
   113 
   113 
   114 fun compose_mixins mixins =
   114 fun compose_mixins mixins =
   115   fold_rev Morphism.compose (map (fst o fst) mixins) Morphism.identity;
   115   fold_rev Morphism.compose (map (fst o fst) mixins) Morphism.identity;
   116 
   116 
   117 datatype locale = Loc of {
   117 datatype locale = Loc of {
   389     |> snd |> filter (snd o fst)  (* only inheritable mixins *)
   389     |> snd |> filter (snd o fst)  (* only inheritable mixins *)
   390     |> (fn x => merge (eq_snd op =) (x, get_mixins context (name, morph)))
   390     |> (fn x => merge (eq_snd op =) (x, get_mixins context (name, morph)))
   391     |> compose_mixins
   391     |> compose_mixins
   392   end;
   392   end;
   393 
   393 
   394 fun get_registrations context select = Registrations.get context
   394 fun get_registrations context select =
       
   395   Registrations.get context
   395   |>> Idtab.dest |>> select
   396   |>> Idtab.dest |>> select
   396   (* with inherited mixins *)
   397   (* with inherited mixins *)
   397   |-> (fn regs => fn _ => map (fn ((name, _), ((base, export) ,_)) =>
   398   |-> (fn regs => fn _ => map (fn ((name, _), ((base, export) ,_)) =>
   398     (name, base $> (collect_mixins context (name, base $> export)) $> export)) regs);
   399     (name, base $> (collect_mixins context (name, base $> export)) $> export)) regs);
   399 
   400 
   541     val thy' = thy |>
   542     val thy' = thy |>
   542       (change_locale loc o apsnd)
   543       (change_locale loc o apsnd)
   543         (apfst (cons ((name, (morph, export)), serial')) #>
   544         (apfst (cons ((name, (morph, export)), serial')) #>
   544           apsnd (case mixin of NONE => I | SOME mixin => insert_mixin serial' mixin));
   545           apsnd (case mixin of NONE => I | SOME mixin => insert_mixin serial' mixin));
   545     val context' = Context.Theory thy';
   546     val context' = Context.Theory thy';
   546     val (_, regs) = fold_rev (roundup thy' cons export)
   547     val (_, regs) =
   547       (registrations_of context' loc) (get_idents (context'), []);
   548       fold_rev (roundup thy' cons export)
       
   549         (registrations_of context' loc) (get_idents (context'), []);
   548   in
   550   in
   549     thy'
   551     thy'
   550     |> fold_rev (fn dep => Context.theory_map (add_registration dep NONE export)) regs
   552     |> fold_rev (fn dep => Context.theory_map (add_registration dep NONE export)) regs
   551   end;
   553   end;
   552 
   554 
   672     | deps => Pretty.big_list "dependencies:" (map (pretty_reg ctxt) (rev deps)))
   674     | deps => Pretty.big_list "dependencies:" (map (pretty_reg ctxt) (rev deps)))
   673   end |> Pretty.writeln;
   675   end |> Pretty.writeln;
   674 
   676 
   675 fun locale_deps thy =
   677 fun locale_deps thy =
   676   let
   678   let
   677     val names = all_locales thy
   679     val names = all_locales thy;
   678     fun add_locale_node name =
   680     fun add_locale_node name =
   679       let
   681       let
   680         val params = params_of thy name;
   682         val params = params_of thy name;
   681         val axioms =
   683         val axioms =
   682           these (Option.map (Logic.strip_imp_prems o Thm.prop_of) (fst (intros_of thy name)));
   684           these (Option.map (Logic.strip_imp_prems o Thm.prop_of) (fst (intros_of thy name)));
   688     fun add_locale_deps name =
   690     fun add_locale_deps name =
   689       let
   691       let
   690         val dependencies =
   692         val dependencies =
   691           map (apsnd (instance_of thy name o op $>) o fst) (dependencies_of thy name);
   693           map (apsnd (instance_of thy name o op $>) o fst) (dependencies_of thy name);
   692       in
   694       in
   693         fold (fn (super, ts) => fn (gr, deps) => (gr |> Graph.add_edge (super, name),
   695         fold (fn (super, ts) => fn (gr, deps) =>
       
   696          (gr |> Graph.add_edge (super, name),
   694           deps |> Symtab.map_default (super, Symtab.empty) (Symtab.cons_list (name, ts))))
   697           deps |> Symtab.map_default (super, Symtab.empty) (Symtab.cons_list (name, ts))))
   695             dependencies
   698             dependencies
   696       end;
   699       end;
   697   in
   700   in
   698     Graph.empty
   701     Graph.empty