src/Pure/Isar/theory_target.ML
changeset 28861 f53abb0733ee
parent 28849 9458d7a6388a
child 28941 128459bd72d2
equal deleted inserted replaced
28860:b1d46059d502 28861:f53abb0733ee
     1 (*  Title:      Pure/Isar/theory_target.ML
     1 (*  Title:      Pure/Isar/theory_target.ML
       
     2     ID:         $Id$
     2     ID:         $Id$
     3     ID:         $Id$
     3     Author:     Makarius
     4     Author:     Makarius
     4 
     5 
     5 Common theory/locale/class/instantiation/overloading targets.
     6 Common theory/locale/class/instantiation/overloading targets.
     6 *)
     7 *)
   190 fun fork_mixfix (Target {is_locale, is_class, ...}) mx =
   191 fun fork_mixfix (Target {is_locale, is_class, ...}) mx =
   191   if not is_locale then (NoSyn, NoSyn, mx)
   192   if not is_locale then (NoSyn, NoSyn, mx)
   192   else if not is_class then (NoSyn, mx, NoSyn)
   193   else if not is_class then (NoSyn, mx, NoSyn)
   193   else (mx, NoSyn, NoSyn);
   194   else (mx, NoSyn, NoSyn);
   194 
   195 
   195 fun locale_const (Target {target, is_class, ...}) (prmode as (mode, _)) tags ((c, mx), rhs) phi =
   196 fun locale_const (Target {target, is_class, ...}) (prmode as (mode, _)) tags ((b, mx), rhs) phi =
   196   let
   197   let
   197     val c' = Morphism.name phi c;
   198     val b' = Morphism.name phi b;
   198     val rhs' = Morphism.term phi rhs;
   199     val rhs' = Morphism.term phi rhs;
   199     val name' = Name.name_with_prefix c';
   200     val legacy_arg = (b', Term.close_schematic_term (Logic.legacy_varify rhs'));
   200     val legacy_arg = (name', Term.close_schematic_term (Logic.legacy_varify rhs'));
   201     val arg = (b', Term.close_schematic_term rhs');
   201     val arg = (name', Term.close_schematic_term rhs');
       
   202     val similar_body = Type.similar_types (rhs, rhs');
   202     val similar_body = Type.similar_types (rhs, rhs');
   203     (* FIXME workaround based on educated guess *)
   203     (* FIXME workaround based on educated guess *)
   204     val class_global = Name.name_of c = Name.name_of c'
   204     val (prefix', _) = Name.dest_binding b';
   205       andalso not (null (Name.prefix_of c'))
   205     val class_global = Name.name_of b = Name.name_of b'
   206       andalso (fst o snd o split_last) (Name.prefix_of c') = Class.class_prefix target;
   206       andalso not (null prefix')
       
   207       andalso (fst o snd o split_last) prefix' = Class.class_prefix target;
   207   in
   208   in
   208     not (is_class andalso (similar_body orelse class_global)) ?
   209     not (is_class andalso (similar_body orelse class_global)) ?
   209       (Context.mapping_result
   210       (Context.mapping_result
   210         (fn thy => thy |> 
   211         (fn thy => thy |> 
   211           Sign.no_base_names
   212           Sign.no_base_names
   265     val global_rhs =
   266     val global_rhs =
   266       singleton (Variable.export_terms (Variable.declare_term u target_ctxt) thy_ctxt) u;
   267       singleton (Variable.export_terms (Variable.declare_term u target_ctxt) thy_ctxt) u;
   267   in
   268   in
   268     lthy |>
   269     lthy |>
   269      (if is_locale then
   270      (if is_locale then
   270         LocalTheory.theory_result (Sign.add_abbrev PrintMode.internal tags (c, global_rhs))
   271         LocalTheory.theory_result (Sign.add_abbrev PrintMode.internal tags (b, global_rhs))
   271         #-> (fn (lhs, _) =>
   272         #-> (fn (lhs, _) =>
   272           let val lhs' = Term.list_comb (Logic.unvarify lhs, xs) in
   273           let val lhs' = Term.list_comb (Logic.unvarify lhs, xs) in
   273             term_syntax ta (locale_const ta prmode tags ((b, mx2), lhs')) #>
   274             term_syntax ta (locale_const ta prmode tags ((b, mx2), lhs')) #>
   274             is_class ? class_target ta (Class.abbrev target prmode tags ((c, mx1), t'))
   275             is_class ? class_target ta (Class.abbrev target prmode tags ((c, mx1), t'))
   275           end)
   276           end)
   276       else
   277       else
   277         LocalTheory.theory
   278         LocalTheory.theory
   278           (Sign.add_abbrev (#1 prmode) tags (c, global_rhs) #-> (fn (lhs, _) =>
   279           (Sign.add_abbrev (#1 prmode) tags (b, global_rhs) #-> (fn (lhs, _) =>
   279            Sign.notation true prmode [(lhs, mx3)])))
   280            Sign.notation true prmode [(lhs, mx3)])))
   280     |> ProofContext.add_abbrev PrintMode.internal tags (c, t) |> snd
   281     |> ProofContext.add_abbrev PrintMode.internal tags (b, t) |> snd
   281     |> LocalDefs.fixed_abbrev ((b, NoSyn), t)
   282     |> LocalDefs.fixed_abbrev ((b, NoSyn), t)
   282   end;
   283   end;
   283 
   284 
   284 
   285 
   285 (* define *)
   286 (* define *)