src/Pure/pure_thy.ML
changeset 15624 484178635bd8
parent 15570 8d8c70b41bab
child 15696 1da4ce092c0b
equal deleted inserted replaced
15623:8b40f741597c 15624:484178635bd8
    43   val forall_elim_var: int -> thm -> thm
    43   val forall_elim_var: int -> thm -> thm
    44   val forall_elim_vars: int -> thm -> thm
    44   val forall_elim_vars: int -> thm -> thm
    45   val add_thms: ((bstring * thm) * theory attribute list) list -> theory -> theory * thm list
    45   val add_thms: ((bstring * thm) * theory attribute list) list -> theory -> theory * thm list
    46   val add_thmss: ((bstring * thm list) * theory attribute list) list -> theory
    46   val add_thmss: ((bstring * thm list) * theory attribute list) list -> theory
    47     -> theory * thm list list
    47     -> theory * thm list list
    48   val note_thmss: theory attribute -> ((bstring * theory attribute list) *
    48   val note_thmss:
    49     (thmref * theory attribute list) list) list -> theory -> theory * (bstring * thm list) list
    49     theory attribute -> ((bstring * theory attribute list) *
    50   val note_thmss_i: theory attribute -> ((bstring * theory attribute list) *
    50     (thmref * theory attribute list) list) list -> theory ->
    51     (thm list * theory attribute list) list) list -> theory -> theory * (bstring * thm list) list
    51     theory * (bstring * thm list) list
       
    52   val note_thmss_i:
       
    53     theory attribute -> ((bstring * theory attribute list) *
       
    54     (thm list * theory attribute list) list) list -> theory ->
       
    55     theory * (bstring * thm list) list
       
    56   val note_thmss_qualified:
       
    57     (string -> string list) ->
       
    58     theory attribute -> ((bstring * theory attribute list) *
       
    59     (thmref * theory attribute list) list) list -> theory ->
       
    60     theory * (bstring * thm list) list
       
    61   val note_thmss_qualified_i:
       
    62     (string -> string list) ->
       
    63     theory attribute -> ((bstring * theory attribute list) *
       
    64     (thm list * theory attribute list) list) list -> theory ->
       
    65     theory * (bstring * thm list) list
    52   val add_axioms: ((bstring * string) * theory attribute list) list -> theory -> theory * thm list
    66   val add_axioms: ((bstring * string) * theory attribute list) list -> theory -> theory * thm list
    53   val add_axioms_i: ((bstring * term) * theory attribute list) list -> theory -> theory * thm list
    67   val add_axioms_i: ((bstring * term) * theory attribute list) list -> theory -> theory * thm list
    54   val add_axiomss: ((bstring * string list) * theory attribute list) list -> theory
    68   val add_axiomss: ((bstring * string list) * theory attribute list) list -> theory
    55     -> theory * thm list list
    69     -> theory * thm list list
    56   val add_axiomss_i: ((bstring * term list) * theory attribute list) list -> theory
    70   val add_axiomss_i: ((bstring * term list) * theory attribute list) list -> theory
   307 (* enter_thms *)
   321 (* enter_thms *)
   308 
   322 
   309 fun warn_overwrite name = warning ("Replaced old copy of theorems " ^ quote name);
   323 fun warn_overwrite name = warning ("Replaced old copy of theorems " ^ quote name);
   310 fun warn_same name = warning ("Theorem database already contains a copy of " ^ quote name);
   324 fun warn_same name = warning ("Theorem database already contains a copy of " ^ quote name);
   311 
   325 
   312 fun enter_thms _ _ _ app_att thy ("", thms) = app_att (thy, thms)
   326 fun gen_enter_thms _ _ _ _ _ app_att thy ("", thms) = app_att (thy, thms)
   313   | enter_thms sg pre_name post_name app_att thy (bname, thms) =
   327   | gen_enter_thms full acc sg pre_name post_name app_att thy (bname, thms) =
   314       let
   328       let
   315         val name = Sign.full_name sg bname;
   329         val name = full sg bname;
   316         val (thy', thms') = app_att (thy, pre_name name thms);
   330         val (thy', thms') = app_att (thy, pre_name name thms);
   317         val named_thms = post_name name thms';
   331         val named_thms = post_name name thms';
   318 
   332 
   319         val r as ref {space, thms_tab, index} = get_theorems_sg sg;
   333         val r as ref {space, thms_tab, index} = get_theorems_sg sg;
   320         val space' = NameSpace.extend (space, [name]);
   334         val space' = NameSpace.extend' acc (space, [name]);
   321         val thms_tab' = Symtab.update ((name, named_thms), thms_tab);
   335         val thms_tab' = Symtab.update ((name, named_thms), thms_tab);
   322         val index' = FactIndex.add (K false) (index, (name, named_thms));
   336         val index' = FactIndex.add (K false) (index, (name, named_thms));
   323       in
   337       in
   324         (case Symtab.lookup (thms_tab, name) of
   338         (case Symtab.lookup (thms_tab, name) of
   325           NONE => ()
   339           NONE => ()
   328             else warn_overwrite name);
   342             else warn_overwrite name);
   329         r := {space = space', thms_tab = thms_tab', index = index'};
   343         r := {space = space', thms_tab = thms_tab', index = index'};
   330         (thy', named_thms)
   344         (thy', named_thms)
   331       end;
   345       end;
   332 
   346 
       
   347 fun enter_thms sg = gen_enter_thms Sign.full_name NameSpace.accesses sg;
   333 
   348 
   334 (* add_thms(s) *)
   349 (* add_thms(s) *)
   335 
   350 
   336 fun add_thms_atts pre_name ((bname, thms), atts) thy =
   351 fun add_thms_atts pre_name ((bname, thms), atts) thy =
   337   enter_thms (Theory.sign_of thy) pre_name (name_thms false)
   352   enter_thms (Theory.sign_of thy) pre_name (name_thms false)
   349 
   364 
   350 (* note_thmss(_i) *)
   365 (* note_thmss(_i) *)
   351 
   366 
   352 local
   367 local
   353 
   368 
   354 fun gen_note_thss get kind_att (thy, ((bname, more_atts), ths_atts)) =
   369 fun gen_note_thss enter get kind_att (thy, ((bname, more_atts), ths_atts)) =
   355   let
   370   let
   356     fun app (x, (ths, atts)) = Thm.applys_attributes ((x, ths), atts);
   371     fun app (x, (ths, atts)) = Thm.applys_attributes ((x, ths), atts);
   357     val (thy', thms) = enter_thms (Theory.sign_of thy)
   372     val (thy', thms) = enter (Theory.sign_of thy)
   358       name_thmss (name_thms false) (apsnd List.concat o foldl_map app) thy
   373       name_thmss (name_thms false) (apsnd List.concat o foldl_map app) thy
   359       (bname, map (fn (ths, atts) => (get thy ths, atts @ more_atts @ [kind_att])) ths_atts);
   374       (bname, map (fn (ths, atts) => (get thy ths, atts @ more_atts @ [kind_att])) ths_atts);
   360   in (thy', (bname, thms)) end;
   375   in (thy', (bname, thms)) end;
   361 
   376 
   362 fun gen_note_thmss get kind_att args thy =
   377 fun gen_note_thmss enter get kind_att args thy =
   363   foldl_map (gen_note_thss get kind_att) (thy, args);
   378   foldl_map (gen_note_thss enter get kind_att) (thy, args);
   364 
   379 
   365 in
   380 in
   366 
   381 
   367 val note_thmss = gen_note_thmss get_thms;
   382 (* if path is set, only permit unqualified names *)
   368 val note_thmss_i = gen_note_thmss (K I);
   383 
       
   384 val note_thmss = gen_note_thmss enter_thms get_thms;
       
   385 val note_thmss_i = gen_note_thmss enter_thms (K I);
       
   386 
       
   387 (* always permit qualified names,
       
   388    clients may specify non-standard access policy *)
       
   389 
       
   390 fun note_thmss_qualified acc =
       
   391   gen_note_thmss (gen_enter_thms Sign.full_name' acc) get_thms;
       
   392 fun note_thmss_qualified_i acc =
       
   393   gen_note_thmss (gen_enter_thms Sign.full_name' acc) (K I);
   369 
   394 
   370 end;
   395 end;
   371 
   396 
   372 
   397 
   373 (* store_thm *)
   398 (* store_thm *)