src/Pure/Isar/theory_target.ML
changeset 30437 910a7aeb8dec
parent 30364 577edc39b501
child 30438 c2d49315b93b
equal deleted inserted replaced
30436:0e3c88f132fc 30437:910a7aeb8dec
     1 (*  Title:      Pure/Isar/theory_target.ML
     1 (*  Title:      Pure/Isar/theory_target.ML
     2     Author:     Makarius
     2     Author:     Makarius
       
     3     Author:     Florian Haftmann, TU Muenchen
     3 
     4 
     4 Common theory/locale/class/instantiation/overloading targets.
     5 Common theory/locale/class/instantiation/overloading targets.
     5 *)
     6 *)
     6 
     7 
     7 signature THEORY_TARGET =
     8 signature THEORY_TARGET =
    46 
    47 
    47 fun pretty_thy ctxt target is_locale is_class =
    48 fun pretty_thy ctxt target is_locale is_class =
    48   let
    49   let
    49     val thy = ProofContext.theory_of ctxt;
    50     val thy = ProofContext.theory_of ctxt;
    50     val target_name = (if is_class then "class " else "locale ") ^ Locale.extern thy target;
    51     val target_name = (if is_class then "class " else "locale ") ^ Locale.extern thy target;
    51     val fixes = map (fn (x, T) => (Binding.name x, SOME T, NoSyn))
    52     val fixes =
    52       (#1 (ProofContext.inferred_fixes ctxt));
    53       map (fn (x, T) => (Binding.name x, SOME T, NoSyn)) (#1 (ProofContext.inferred_fixes ctxt));
    53     val assumes = map (fn A => (Attrib.empty_binding, [(Thm.term_of A, [])]))
    54     val assumes =
    54       (Assumption.assms_of ctxt);
    55       map (fn A => (Attrib.empty_binding, [(Thm.term_of A, [])])) (Assumption.assms_of ctxt);
    55     val elems =
    56     val elems =
    56       (if null fixes then [] else [Element.Fixes fixes]) @
    57       (if null fixes then [] else [Element.Fixes fixes]) @
    57       (if null assumes then [] else [Element.Assumes assumes]);
    58       (if null assumes then [] else [Element.Assumes assumes]);
    58   in
    59   in
    59     if target = "" then []
    60     if target = "" then []
   193       andalso not (null prefix')
   194       andalso not (null prefix')
   194       andalso (fst o snd o split_last) prefix' = Class_Target.class_prefix target;
   195       andalso (fst o snd o split_last) prefix' = Class_Target.class_prefix target;
   195   in
   196   in
   196     not (is_class andalso (similar_body orelse class_global)) ?
   197     not (is_class andalso (similar_body orelse class_global)) ?
   197       (Context.mapping_result
   198       (Context.mapping_result
   198         (fn thy => thy |> 
   199         (fn thy => thy
   199           Sign.no_base_names
   200           |> Sign.no_base_names
   200           |> Sign.add_abbrev PrintMode.internal tags legacy_arg
   201           |> Sign.add_abbrev PrintMode.internal tags legacy_arg
   201           ||> Sign.restore_naming thy)
   202           ||> Sign.restore_naming thy)
   202         (ProofContext.add_abbrev PrintMode.internal tags arg)
   203         (ProofContext.add_abbrev PrintMode.internal tags arg)
   203       #-> (fn (lhs' as Const (d, _), _) =>
   204       #-> (fn (lhs' as Const (d, _), _) =>
   204           similar_body ?
   205           similar_body ?
   208 
   209 
   209 fun syntax_error c = error ("Illegal mixfix syntax for overloaded constant " ^ quote c);
   210 fun syntax_error c = error ("Illegal mixfix syntax for overloaded constant " ^ quote c);
   210 
   211 
   211 fun declare_const (ta as Target {target, is_locale, is_class, ...}) depends ((b, T), mx) lthy =
   212 fun declare_const (ta as Target {target, is_locale, is_class, ...}) depends ((b, T), mx) lthy =
   212   let
   213   let
   213     val c = Binding.name_of b;  (* FIXME Binding.qualified_name_of *)
   214     val c = Binding.qualified_name_of b;
   214     val tags = LocalTheory.group_position_of lthy;
   215     val tags = LocalTheory.group_position_of lthy;
   215     val xs = filter depends (#1 (ProofContext.inferred_fixes (LocalTheory.target_of lthy)));
   216     val xs = filter depends (#1 (ProofContext.inferred_fixes (LocalTheory.target_of lthy)));
   216     val U = map #2 xs ---> T;
   217     val U = map #2 xs ---> T;
   217     val (mx1, mx2, mx3) = fork_mixfix ta mx;
   218     val (mx1, mx2, mx3) = fork_mixfix ta mx;
   218     val declare_const =
   219     val declare_const =
   276     kind ((b, mx), ((name, atts), rhs)) lthy =
   277     kind ((b, mx), ((name, atts), rhs)) lthy =
   277   let
   278   let
   278     val thy = ProofContext.theory_of lthy;
   279     val thy = ProofContext.theory_of lthy;
   279     val thy_ctxt = ProofContext.init thy;
   280     val thy_ctxt = ProofContext.init thy;
   280 
   281 
   281     val c = Binding.name_of b;   (* FIXME Binding.qualified_name_of (!?) *)
   282     val name' = Thm.def_binding_optional b name;
   282     val name' = Binding.map_name (Thm.def_name_optional (Binding.name_of b)) name;
       
   283     val (rhs', rhs_conv) =
   283     val (rhs', rhs_conv) =
   284       LocalDefs.export_cterm lthy thy_ctxt (Thm.cterm_of thy rhs) |>> Thm.term_of;
   284       LocalDefs.export_cterm lthy thy_ctxt (Thm.cterm_of thy rhs) |>> Thm.term_of;
   285     val xs = Variable.add_fixed (LocalTheory.target_of lthy) rhs' [];
   285     val xs = Variable.add_fixed (LocalTheory.target_of lthy) rhs' [];
   286     val T = Term.fastype_of rhs;
   286     val T = Term.fastype_of rhs;
   287 
   287 
   288     (*const*)
   288     (*const*)
   289     val ((lhs, local_def), lthy2) = lthy |> declare_const ta (member (op =) xs) ((b, T), mx);
   289     val ((lhs, local_def), lthy2) = lthy |> declare_const ta (member (op =) xs) ((b, T), mx);
   290     val (_, lhs') = Logic.dest_equals (Thm.prop_of local_def);
   290     val (_, lhs') = Logic.dest_equals (Thm.prop_of local_def);
   291 
   291 
   292     (*def*)
   292     (*def*)
       
   293     val c = Binding.qualified_name_of b;
   293     val define_const =
   294     val define_const =
   294       (case Overloading.operation lthy c of
   295       (case Overloading.operation lthy c of
   295         SOME (_, checked) =>
   296         SOME (_, checked) =>
   296           (fn name => fn (Const (c, _), rhs) => Overloading.define checked name (c, rhs))
   297           (fn name => fn (Const (c, _), rhs) => Overloading.define checked name (c, rhs))
   297       | NONE =>
   298       | NONE =>