src/Pure/Isar/expression.ML
changeset 29394 4638ab6c878f
parent 29383 223f18cfbb32
parent 29391 1f6e8c00dc3e
child 29441 28d7d7572b81
equal deleted inserted replaced
29387:d23fdfa46b6a 29394:4638ab6c878f
    16     Proof.context ->  (term * term list) list list * Proof.context;
    16     Proof.context ->  (term * term list) list list * Proof.context;
    17   val cert_statement: Element.context_i list -> (term * term list) list list ->
    17   val cert_statement: Element.context_i list -> (term * term list) list list ->
    18     Proof.context -> (term * term list) list list * Proof.context;
    18     Proof.context -> (term * term list) list list * Proof.context;
    19 
    19 
    20   (* Declaring locales *)
    20   (* Declaring locales *)
    21   val add_locale: string -> bstring -> expression_i -> Element.context_i list ->
    21   val add_locale: bstring -> bstring -> expression_i -> Element.context_i list ->
    22     theory -> string * local_theory;
    22     theory -> string * local_theory;
    23   val add_locale_cmd: string -> bstring -> expression -> Element.context list ->
    23   val add_locale_cmd: bstring -> bstring -> expression -> Element.context list ->
    24     theory -> string * local_theory;
    24     theory -> string * local_theory;
    25 
    25 
    26   (* Interpretation *)
    26   (* Interpretation *)
    27   val sublocale: string -> expression_i -> theory -> Proof.state;
    27   val sublocale: string -> expression_i -> theory -> Proof.state;
    28   val sublocale_cmd: string -> expression -> theory -> Proof.state;
    28   val sublocale_cmd: string -> expression -> theory -> Proof.state;
   696         (a, [([Assumption.assume (cterm_of thy def)],
   696         (a, [([Assumption.assume (cterm_of thy def)],
   697           [(Attrib.internal o K) Locale.witness_attrib])])) defs)
   697           [(Attrib.internal o K) Locale.witness_attrib])])) defs)
   698   | defines_to_notes _ e = e;
   698   | defines_to_notes _ e = e;
   699 
   699 
   700 fun gen_add_locale prep_decl
   700 fun gen_add_locale prep_decl
   701     bname predicate_name raw_imprt raw_body thy =
   701     bname raw_predicate_bname raw_imprt raw_body thy =
   702   let
   702   let
   703     val name = Sign.full_bname thy bname;
   703     val name = Sign.full_bname thy bname;
   704     val _ = Locale.test_locale thy name andalso
   704     val _ = Locale.defined thy name andalso
   705       error ("Duplicate definition of locale " ^ quote name);
   705       error ("Duplicate definition of locale " ^ quote name);
   706 
   706 
   707     val ((fixed, deps, body_elems), (parms, ctxt')) =
   707     val ((fixed, deps, body_elems), (parms, ctxt')) =
   708       prep_decl raw_imprt raw_body (ProofContext.init thy);
   708       prep_decl raw_imprt raw_body (ProofContext.init thy);
   709     val text as (((_, exts'), _), defs) = eval ctxt' deps body_elems;
   709     val text as (((_, exts'), _), defs) = eval ctxt' deps body_elems;
   710 
   710 
       
   711     val predicate_bname = if raw_predicate_bname = "" then bname
       
   712       else raw_predicate_bname;
   711     val ((a_statement, a_intro, a_axioms), (b_statement, b_intro, b_axioms), thy') =
   713     val ((a_statement, a_intro, a_axioms), (b_statement, b_intro, b_axioms), thy') =
   712       define_preds predicate_name parms text thy;
   714       define_preds predicate_bname parms text thy;
   713 
   715 
   714     val extraTs = fold Term.add_tfrees exts' [] \\ fold Term.add_tfreesT (map snd parms) [];
   716     val extraTs = fold Term.add_tfrees exts' [] \\ fold Term.add_tfreesT (map snd parms) [];
   715     val _ = if null extraTs then ()
   717     val _ = if null extraTs then ()
   716       else warning ("Additional type variable(s) in locale specification " ^ quote bname);
   718       else warning ("Additional type variable(s) in locale specification " ^ quote bname);
   717 
   719 
   785       ProofContext.theory (
   787       ProofContext.theory (
   786         (* store dependencies *)
   788         (* store dependencies *)
   787         fold store_dep (deps ~~ prep_result propss results) #>
   789         fold store_dep (deps ~~ prep_result propss results) #>
   788         (* propagate registrations *)
   790         (* propagate registrations *)
   789         (fn thy => fold_rev (fn reg => Locale.activate_global_facts reg)
   791         (fn thy => fold_rev (fn reg => Locale.activate_global_facts reg)
   790           (Locale.get_global_registrations thy) thy));
   792           (Locale.get_registrations thy) thy));
   791   in
   793   in
   792     goal_ctxt |>
   794     goal_ctxt |>
   793       Proof.theorem_i NONE after_qed (prep_propp propss) |>
   795       Proof.theorem_i NONE after_qed (prep_propp propss) |>
   794       Element.refine_witness |> Seq.hd
   796       Element.refine_witness |> Seq.hd
   795   end;
   797   end;
   822 
   824 
   823     fun store (Reg (name, morph), thms) (regs, thy) =
   825     fun store (Reg (name, morph), thms) (regs, thy) =
   824         let
   826         let
   825           val thms' = map (Element.morph_witness export') thms;
   827           val thms' = map (Element.morph_witness export') thms;
   826           val morph' = morph $> Element.satisfy_morphism thms';
   828           val morph' = morph $> Element.satisfy_morphism thms';
   827           val add = Locale.add_global_registration (name, (morph', export));
   829           val add = Locale.add_registration (name, (morph', export));
   828         in ((name, morph') :: regs, add thy) end
   830         in ((name, morph') :: regs, add thy) end
   829       | store (Eqns [], []) (regs, thy) =
   831       | store (Eqns [], []) (regs, thy) =
   830         let val add = fold_rev (fn (name, morph) =>
   832         let val add = fold_rev (fn (name, morph) =>
   831               Locale.activate_global_facts (name, morph $> export)) regs;
   833               Locale.activate_global_facts (name, morph $> export)) regs;
   832         in (regs, add thy) end
   834         in (regs, add thy) end
   840             Morphism.term_morphism (MetaSimplifier.rewrite_term thy thms' []) $>
   842             Morphism.term_morphism (MetaSimplifier.rewrite_term thy thms' []) $>
   841             Morphism.thm_morphism (MetaSimplifier.rewrite_rule thms');
   843             Morphism.thm_morphism (MetaSimplifier.rewrite_rule thms');
   842           val attns' = map ((apsnd o map) (Attrib.attribute_i thy)) attns;
   844           val attns' = map ((apsnd o map) (Attrib.attribute_i thy)) attns;
   843           val add =
   845           val add =
   844             fold_rev (fn (name, morph) =>
   846             fold_rev (fn (name, morph) =>
   845               Locale.amend_global_registration eq_morph (name, morph) #>
   847               Locale.amend_registration eq_morph (name, morph) #>
   846               Locale.activate_global_facts (name, morph $> eq_morph $> export)) regs #>
   848               Locale.activate_global_facts (name, morph $> eq_morph $> export)) regs #>
   847             PureThy.note_thmss Thm.lemmaK (attns' ~~ map (fn th => [([th], [])]) thms') #>
   849             PureThy.note_thmss Thm.lemmaK (attns' ~~ map (fn th => [([th], [])]) thms') #>
   848             snd
   850             snd
   849         in (regs, add thy) end;
   851         in (regs, add thy) end;
   850 
   852