src/Pure/Isar/locale.ML
changeset 42360 da8817d01e7c
parent 42358 b47d41d9f4b5
child 42375 774df7c59508
equal deleted inserted replaced
42359:6ca5407863ed 42360:da8817d01e7c
   160   val extend = I;
   160   val extend = I;
   161   val merge = Name_Space.join_tables (K merge_locale);
   161   val merge = Name_Space.join_tables (K merge_locale);
   162 );
   162 );
   163 
   163 
   164 val intern = Name_Space.intern o #1 o Locales.get;
   164 val intern = Name_Space.intern o #1 o Locales.get;
   165 fun extern thy = Name_Space.extern (ProofContext.init_global thy) (#1 (Locales.get thy));
   165 fun extern thy = Name_Space.extern (Proof_Context.init_global thy) (#1 (Locales.get thy));
   166 
   166 
   167 val get_locale = Symtab.lookup o #2 o Locales.get;
   167 val get_locale = Symtab.lookup o #2 o Locales.get;
   168 val defined = Symtab.defined o #2 o Locales.get;
   168 val defined = Symtab.defined o #2 o Locales.get;
   169 
   169 
   170 fun the_locale thy name =
   170 fun the_locale thy name =
   213 
   213 
   214 (* Print instance and qualifiers *)
   214 (* Print instance and qualifiers *)
   215 
   215 
   216 fun pretty_reg ctxt (name, morph) =
   216 fun pretty_reg ctxt (name, morph) =
   217   let
   217   let
   218     val thy = ProofContext.theory_of ctxt;
   218     val thy = Proof_Context.theory_of ctxt;
   219     val name' = extern thy name;
   219     val name' = extern thy name;
   220     fun prt_qual (qual, mand) = Pretty.str (qual ^ (if mand then "!" else "?"));
   220     fun prt_qual (qual, mand) = Pretty.str (qual ^ (if mand then "!" else "?"));
   221     fun prt_quals qs = Pretty.separate "." (map prt_qual qs) |> Pretty.block;
   221     fun prt_quals qs = Pretty.separate "." (map prt_qual qs) |> Pretty.block;
   222     val prt_term = Pretty.quote o Syntax.pretty_term ctxt;
   222     val prt_term = Pretty.quote o Syntax.pretty_term ctxt;
   223     fun prt_term' t =
   223     fun prt_term' t =
   467     |-> put_idents
   467     |-> put_idents
   468   end;
   468   end;
   469 
   469 
   470 fun init name thy =
   470 fun init name thy =
   471   activate_all name thy Element.init (Element.transfer_morphism o Context.theory_of)
   471   activate_all name thy Element.init (Element.transfer_morphism o Context.theory_of)
   472     ([], Context.Proof (ProofContext.init_global thy)) |-> put_idents |> Context.proof_of;
   472     ([], Context.Proof (Proof_Context.init_global thy)) |-> put_idents |> Context.proof_of;
   473 
   473 
   474 
   474 
   475 (*** Add and extend registrations ***)
   475 (*** Add and extend registrations ***)
   476 
   476 
   477 fun amend_registration (name, morph) mixin export context =
   477 fun amend_registration (name, morph) mixin export context =
   554 (* Theorems *)
   554 (* Theorems *)
   555 
   555 
   556 fun add_thmss loc kind args ctxt =
   556 fun add_thmss loc kind args ctxt =
   557   let
   557   let
   558     val (Notes args', ctxt') = Element.activate_i (Notes (kind, args)) ctxt;
   558     val (Notes args', ctxt') = Element.activate_i (Notes (kind, args)) ctxt;
   559     val ctxt'' = ctxt' |> ProofContext.background_theory
   559     val ctxt'' = ctxt' |> Proof_Context.background_theory
   560      ((change_locale loc o apfst o apsnd) (cons (args', serial ()))
   560      ((change_locale loc o apfst o apsnd) (cons (args', serial ()))
   561         #>
   561         #>
   562       (* Registrations *)
   562       (* Registrations *)
   563       (fn thy => fold_rev (fn (_, morph) =>
   563       (fn thy => fold_rev (fn (_, morph) =>
   564             let
   564             let
   576     [((Binding.conceal Binding.empty,
   576     [((Binding.conceal Binding.empty,
   577         [Attrib.internal (fn phi => Thm.declaration_attribute (K (decl phi)))]),
   577         [Attrib.internal (fn phi => Thm.declaration_attribute (K (decl phi)))]),
   578       [([Drule.dummy_thm], [])])];
   578       [([Drule.dummy_thm], [])])];
   579 
   579 
   580 fun add_syntax_declaration loc decl =
   580 fun add_syntax_declaration loc decl =
   581   ProofContext.background_theory ((change_locale loc o apfst o apfst) (cons (decl, serial ())))
   581   Proof_Context.background_theory ((change_locale loc o apfst o apfst) (cons (decl, serial ())))
   582   #> add_declaration loc decl;
   582   #> add_declaration loc decl;
   583 
   583 
   584 
   584 
   585 (*** Reasoning about locales ***)
   585 (*** Reasoning about locales ***)
   586 
   586 
   629 
   629 
   630 val all_locales = Symtab.keys o snd o Locales.get;
   630 val all_locales = Symtab.keys o snd o Locales.get;
   631 
   631 
   632 fun print_locales thy =
   632 fun print_locales thy =
   633   Pretty.strs ("locales:" ::
   633   Pretty.strs ("locales:" ::
   634     map #1 (Name_Space.extern_table (ProofContext.init_global thy) (Locales.get thy)))
   634     map #1 (Name_Space.extern_table (Proof_Context.init_global thy) (Locales.get thy)))
   635   |> Pretty.writeln;
   635   |> Pretty.writeln;
   636 
   636 
   637 fun print_locale thy show_facts raw_name =
   637 fun print_locale thy show_facts raw_name =
   638   let
   638   let
   639     val name = intern thy raw_name;
   639     val name = intern thy raw_name;
   648     |> Pretty.writeln
   648     |> Pretty.writeln
   649   end;
   649   end;
   650 
   650 
   651 fun print_registrations ctxt raw_name =
   651 fun print_registrations ctxt raw_name =
   652   let
   652   let
   653     val thy = ProofContext.theory_of ctxt;
   653     val thy = Proof_Context.theory_of ctxt;
   654     val name = intern thy raw_name;
   654     val name = intern thy raw_name;
   655     val _ = the_locale thy name;  (* error if locale unknown *)
   655     val _ = the_locale thy name;  (* error if locale unknown *)
   656   in
   656   in
   657     (case registrations_of (Context.Proof ctxt) (* FIXME *) name of
   657     (case registrations_of (Context.Proof ctxt) (* FIXME *) name of
   658       [] => Pretty.str ("no interpretations")
   658       [] => Pretty.str ("no interpretations")
   659     | regs => Pretty.big_list "interpretations:" (map (pretty_reg ctxt) (rev regs)))
   659     | regs => Pretty.big_list "interpretations:" (map (pretty_reg ctxt) (rev regs)))
   660   end |> Pretty.writeln;
   660   end |> Pretty.writeln;
   661 
   661 
   662 fun print_dependencies ctxt clean export insts =
   662 fun print_dependencies ctxt clean export insts =
   663   let
   663   let
   664     val thy = ProofContext.theory_of ctxt;
   664     val thy = Proof_Context.theory_of ctxt;
   665     val idents = if clean then [] else get_idents (Context.Proof ctxt);
   665     val idents = if clean then [] else get_idents (Context.Proof ctxt);
   666   in
   666   in
   667     (case fold (roundup thy cons export) insts (idents, []) |> snd of
   667     (case fold (roundup thy cons export) insts (idents, []) |> snd of
   668       [] => Pretty.str ("no dependencies")
   668       [] => Pretty.str ("no dependencies")
   669     | deps => Pretty.big_list "dependencies:" (map (pretty_reg ctxt) (rev deps)))
   669     | deps => Pretty.big_list "dependencies:" (map (pretty_reg ctxt) (rev deps)))