src/Pure/Isar/locale.ML
changeset 19585 70a1ce3b23ae
parent 19482 9f11af8f7ef9
child 19662 2f5d076fde32
equal deleted inserted replaced
19584:606d6a73e6d9 19585:70a1ce3b23ae
    54   val global_asms_of: theory -> string ->
    54   val global_asms_of: theory -> string ->
    55     ((string * Attrib.src list) * term list) list
    55     ((string * Attrib.src list) * term list) list
    56 
    56 
    57   (* Processing of locale statements *)
    57   (* Processing of locale statements *)
    58   val read_context_statement: xstring option -> Element.context element list ->
    58   val read_context_statement: xstring option -> Element.context element list ->
    59     (string * (string list * string list)) list list -> Proof.context ->
    59     (string * string list) list list -> Proof.context ->
    60     string option * (cterm list * Proof.context) * (cterm list * Proof.context) *
    60     string option * (cterm list * Proof.context) * (cterm list * Proof.context) *
    61       (term * (term list * term list)) list list
    61       (term * term list) list list
    62   val cert_context_statement: string option -> Element.context_i element list ->
    62   val cert_context_statement: string option -> Element.context_i element list ->
    63     (term * (term list * term list)) list list -> Proof.context ->
    63     (term * term list) list list -> Proof.context ->
    64     string option * (cterm list * Proof.context) * (cterm list * Proof.context) *
    64     string option * (cterm list * Proof.context) * (cterm list * Proof.context) *
    65       (term * (term list * term list)) list list
    65       (term * term list) list list
    66 
    66 
    67   (* Diagnostic functions *)
    67   (* Diagnostic functions *)
    68   val print_locales: theory -> unit
    68   val print_locales: theory -> unit
    69   val print_locale: theory -> bool -> expr -> Element.context list -> unit
    69   val print_locale: theory -> bool -> expr -> Element.context list -> unit
    70   val print_global_registrations: bool -> string -> theory -> unit
    70   val print_global_registrations: bool -> string -> theory -> unit
   862         val defs' = Attrib.map_specs (Attrib.attribute_i (ProofContext.theory_of ctxt)) defs;
   862         val defs' = Attrib.map_specs (Attrib.attribute_i (ProofContext.theory_of ctxt)) defs;
   863         val (_, ctxt') =
   863         val (_, ctxt') =
   864         ctxt |> ProofContext.add_assms_i LocalDefs.def_export
   864         ctxt |> ProofContext.add_assms_i LocalDefs.def_export
   865           (defs' |> map (fn ((name, atts), (t, ps)) =>
   865           (defs' |> map (fn ((name, atts), (t, ps)) =>
   866             let val ((c, _), t') = LocalDefs.cert_def ctxt t
   866             let val ((c, _), t') = LocalDefs.cert_def ctxt t
   867             in ((if name = "" then Thm.def_name c else name, atts), [(t', (ps, []))]) end))
   867             in ((if name = "" then Thm.def_name c else name, atts), [(t', ps)]) end))
   868       in ((ctxt', Assumed axs), []) end
   868       in ((ctxt', Assumed axs), []) end
   869   | activate_elem _ ((ctxt, Derived ths), Defines defs) =
   869   | activate_elem _ ((ctxt, Derived ths), Defines defs) =
   870       ((ctxt, Derived ths), [])
   870       ((ctxt, Derived ths), [])
   871   | activate_elem is_ext ((ctxt, mode), Notes facts) =
   871   | activate_elem is_ext ((ctxt, mode), Notes facts) =
   872       let
   872       let
   945       in (ctxt |> ProofContext.add_fixes_i vars |> snd, []) end
   945       in (ctxt |> ProofContext.add_fixes_i vars |> snd, []) end
   946   | declare_ext_elem prep_vars (ctxt, Constrains csts) =
   946   | declare_ext_elem prep_vars (ctxt, Constrains csts) =
   947       let val (_, ctxt') = prep_vars (map (fn (x, T) => (x, SOME T, NoSyn)) csts) ctxt
   947       let val (_, ctxt') = prep_vars (map (fn (x, T) => (x, SOME T, NoSyn)) csts) ctxt
   948       in (ctxt', []) end
   948       in (ctxt', []) end
   949   | declare_ext_elem _ (ctxt, Assumes asms) = (ctxt, map #2 asms)
   949   | declare_ext_elem _ (ctxt, Assumes asms) = (ctxt, map #2 asms)
   950   | declare_ext_elem _ (ctxt, Defines defs) = (ctxt, map (fn (_, (t, ps)) => [(t, (ps, []))]) defs)
   950   | declare_ext_elem _ (ctxt, Defines defs) = (ctxt, map (fn (_, (t, ps)) => [(t, ps)]) defs)
   951   | declare_ext_elem _ (ctxt, Notes facts) = (ctxt, []);
   951   | declare_ext_elem _ (ctxt, Notes facts) = (ctxt, []);
   952 
   952 
   953 fun declare_elems prep_vars (ctxt, (((name, ps), Assumed _), elems)) =
   953 fun declare_elems prep_vars (ctxt, (((name, ps), Assumed _), elems)) =
   954     let val (ctxt', propps) =
   954     let val (ctxt', propps) =
   955       (case elems of
   955       (case elems of
  1022       in (ctxt |> ProofContext.add_fixes_i vars |> snd, []) end
  1022       in (ctxt |> ProofContext.add_fixes_i vars |> snd, []) end
  1023   | declare_ext_elem prep_vars (ctxt, Constrains csts) =
  1023   | declare_ext_elem prep_vars (ctxt, Constrains csts) =
  1024       let val (_, ctxt') = prep_vars (map (fn (x, T) => (x, SOME T, NoSyn)) csts) ctxt
  1024       let val (_, ctxt') = prep_vars (map (fn (x, T) => (x, SOME T, NoSyn)) csts) ctxt
  1025       in (ctxt', []) end
  1025       in (ctxt', []) end
  1026   | declare_ext_elem _ (ctxt, Assumes asms) = (ctxt, map #2 asms)
  1026   | declare_ext_elem _ (ctxt, Assumes asms) = (ctxt, map #2 asms)
  1027   | declare_ext_elem _ (ctxt, Defines defs) = (ctxt, map (fn (_, (t, ps)) => [(t, (ps, []))]) defs)
  1027   | declare_ext_elem _ (ctxt, Defines defs) = (ctxt, map (fn (_, (t, ps)) => [(t, ps)]) defs)
  1028   | declare_ext_elem _ (ctxt, Notes facts) = (ctxt, []);
  1028   | declare_ext_elem _ (ctxt, Notes facts) = (ctxt, []);
  1029 
  1029 
  1030 fun declare_elems prep_vars (ctxt, (((name, ps), Assumed _), elems)) =
  1030 fun declare_elems prep_vars (ctxt, (((name, ps), Assumed _), elems)) =
  1031     let val (ctxt', propps) =
  1031     let val (ctxt', propps) =
  1032       (case elems of
  1032       (case elems of
  1134         fun no_binds [] = []
  1134         fun no_binds [] = []
  1135           | no_binds _ = error "Illegal term bindings in locale element";
  1135           | no_binds _ = error "Illegal term bindings in locale element";
  1136       in
  1136       in
  1137         (case elem of
  1137         (case elem of
  1138           Assumes asms => Assumes (asms |> map (fn (a, propps) =>
  1138           Assumes asms => Assumes (asms |> map (fn (a, propps) =>
  1139             (a, map (fn (t, (ps, qs)) => (close_frees t, (no_binds ps, no_binds qs))) propps)))
  1139             (a, map (fn (t, ps) => (close_frees t, no_binds ps)) propps)))
  1140         | Defines defs => Defines (defs |> map (fn (a, (t, ps)) =>
  1140         | Defines defs => Defines (defs |> map (fn (a, (t, ps)) =>
  1141             (a, (close_frees (#2 (LocalDefs.cert_def ctxt t)), no_binds ps))))
  1141             (a, (close_frees (#2 (LocalDefs.cert_def ctxt t)), no_binds ps))))
  1142         | e => e)
  1142         | e => e)
  1143       end;
  1143       end;
  1144 
  1144 
  1147       (x, AList.lookup (op =) parms x, mx)) fixes)
  1147       (x, AList.lookup (op =) parms x, mx)) fixes)
  1148   | finish_ext_elem parms _ (Constrains _, _) = Constrains []
  1148   | finish_ext_elem parms _ (Constrains _, _) = Constrains []
  1149   | finish_ext_elem _ close (Assumes asms, propp) =
  1149   | finish_ext_elem _ close (Assumes asms, propp) =
  1150       close (Assumes (map #1 asms ~~ propp))
  1150       close (Assumes (map #1 asms ~~ propp))
  1151   | finish_ext_elem _ close (Defines defs, propp) =
  1151   | finish_ext_elem _ close (Defines defs, propp) =
  1152       close (Defines (map #1 defs ~~ map (fn [(t, (ps, []))] => (t, ps)) propp))
  1152       close (Defines (map #1 defs ~~ map (fn [(t, ps)] => (t, ps)) propp))
  1153   | finish_ext_elem _ _ (Notes facts, _) = Notes facts;
  1153   | finish_ext_elem _ _ (Notes facts, _) = Notes facts;
  1154 
  1154 
  1155 
  1155 
  1156 (* CB: finish_parms introduces type info from parms to identifiers *)
  1156 (* CB: finish_parms introduces type info from parms to identifiers *)
  1157 (* CB: only needed for types that have been NONE so far???
  1157 (* CB: only needed for types that have been NONE so far???
  1665           val aname = if null ints then bname else bname ^ "_" ^ axiomsN;
  1665           val aname = if null ints then bname else bname ^ "_" ^ axiomsN;
  1666           val ((statement, intro, axioms), def_thy) =
  1666           val ((statement, intro, axioms), def_thy) =
  1667             thy |> def_pred aname parms defs exts exts';
  1667             thy |> def_pred aname parms defs exts exts';
  1668           val elemss' =
  1668           val elemss' =
  1669             change_elemss axioms elemss
  1669             change_elemss axioms elemss
  1670             @ [(("", []), [Assumes [((bname ^ "_" ^ axiomsN, []), [(statement, ([], []))])]])];
  1670             @ [(("", []), [Assumes [((bname ^ "_" ^ axiomsN, []), [(statement, [])])]])];
  1671         in
  1671         in
  1672           def_thy
  1672           def_thy
  1673           |> PureThy.note_thmss_qualified "" aname [((introN, []), [([intro], [])])]
  1673           |> PureThy.note_thmss_qualified "" aname [((introN, []), [([intro], [])])]
  1674           |> snd
  1674           |> snd
  1675           |> pair (elemss', [statement])
  1675           |> pair (elemss', [statement])
  2143       end;
  2143       end;
  2144 
  2144 
  2145   in (propss, activate) end;
  2145   in (propss, activate) end;
  2146 
  2146 
  2147 fun prep_propp propss = propss |> map (fn ((name, _), props) =>
  2147 fun prep_propp propss = propss |> map (fn ((name, _), props) =>
  2148   (("", []), map (rpair ([], []) o Logic.protect) props));
  2148   (("", []), map (rpair [] o Logic.protect) props));
  2149 
  2149 
  2150 fun prep_result propps thmss =
  2150 fun prep_result propps thmss =
  2151   ListPair.map (fn ((_, props), thms) => (props ~~ thms)) (propps, thmss);
  2151   ListPair.map (fn ((_, props), thms) => (props ~~ thms)) (propps, thmss);
  2152 
  2152 
  2153 val refine_protected =
  2153 val refine_protected =