src/Pure/Isar/theory_target.ML
changeset 25212 9dd61cb753ae
parent 25150 9d8893e9f381
child 25240 ff5815d04c23
equal deleted inserted replaced
25211:aec1cbdbca71 25212:9dd61cb753ae
   167 fun fork_mixfix (Target {is_locale, is_class, ...}) mx =
   167 fun fork_mixfix (Target {is_locale, is_class, ...}) mx =
   168   if not is_locale then (NoSyn, NoSyn, mx)
   168   if not is_locale then (NoSyn, NoSyn, mx)
   169   else if not is_class then (NoSyn, mx, NoSyn)
   169   else if not is_class then (NoSyn, mx, NoSyn)
   170   else (mx, NoSyn, NoSyn);
   170   else (mx, NoSyn, NoSyn);
   171 
   171 
   172 fun locale_const (prmode as (mode, _)) pos ((c, mx), rhs) phi =
   172 fun locale_const (Target {target, is_class, ...}) (prmode as (mode, _)) pos ((c, mx), rhs) phi =
   173   let
   173   let
   174     val c' = Morphism.name phi c;
   174     val c' = Morphism.name phi c;
   175     val rhs' = Morphism.term phi rhs;
   175     val rhs' = Morphism.term phi rhs;
   176     val legacy_arg = (c', Term.close_schematic_term (Logic.legacy_varify rhs'));
   176     val legacy_arg = (c', Term.close_schematic_term (Logic.legacy_varify rhs'));
   177     val arg = (c', Term.close_schematic_term rhs');
   177     val arg = (c', Term.close_schematic_term rhs');
   178   in
   178     (* FIXME workaround based on educated guess *)
   179     Context.mapping_result
   179     val in_class = is_class andalso c' = NameSpace.qualified (Class.class_prefix target) c;
   180       (Sign.add_abbrev PrintMode.internal pos legacy_arg)
   180   in
   181       (ProofContext.add_abbrev PrintMode.internal pos arg)
   181     not in_class ?
   182     #-> (fn (lhs' as Const (d, _), _) =>
   182       (Context.mapping_result
   183         Type.similar_types (rhs, rhs') ?
   183         (Sign.add_abbrev PrintMode.internal pos legacy_arg)
   184           (Context.mapping (Sign.revert_abbrev mode d) (ProofContext.revert_abbrev mode d) #>
   184         (ProofContext.add_abbrev PrintMode.internal pos arg)
   185            Morphism.form (ProofContext.target_notation true prmode [(lhs', mx)])))
   185       #-> (fn (lhs' as Const (d, _), _) =>
       
   186           Type.similar_types (rhs, rhs') ?
       
   187             (Context.mapping (Sign.revert_abbrev mode d) (ProofContext.revert_abbrev mode d) #>
       
   188              Morphism.form (ProofContext.target_notation true prmode [(lhs', mx)]))))
   186   end;
   189   end;
   187 
   190 
   188 fun declare_const (ta as Target {target, is_locale, is_class}) depends ((c, T), mx) lthy =
   191 fun declare_const (ta as Target {target, is_locale, is_class}) depends ((c, T), mx) lthy =
   189   let
   192   let
   190     val pos = ContextPosition.properties_of lthy;
   193     val pos = ContextPosition.properties_of lthy;
   193     val (mx1, mx2, mx3) = fork_mixfix ta mx;
   196     val (mx1, mx2, mx3) = fork_mixfix ta mx;
   194     val (const, lthy') = lthy |> LocalTheory.theory_result (Sign.declare_const pos (c, U, mx3));
   197     val (const, lthy') = lthy |> LocalTheory.theory_result (Sign.declare_const pos (c, U, mx3));
   195     val t = Term.list_comb (const, map Free xs);
   198     val t = Term.list_comb (const, map Free xs);
   196   in
   199   in
   197     lthy'
   200     lthy'
   198     |> is_locale ? term_syntax ta (locale_const Syntax.mode_default pos ((c, mx2), t))
   201     |> is_locale ? term_syntax ta (locale_const ta Syntax.mode_default pos ((c, mx2), t))
   199     |> is_class ? class_target ta (Class.add_logical_const target pos ((c, mx1), t))
   202     |> is_class ? class_target ta (Class.add_logical_const target pos ((c, mx1), t))
   200     |> LocalDefs.add_def ((c, NoSyn), t)
   203     |> LocalDefs.add_def ((c, NoSyn), t)
   201   end;
   204   end;
   202 
   205 
   203 
   206 
   219     lthy |>
   222     lthy |>
   220      (if is_locale then
   223      (if is_locale then
   221         LocalTheory.theory_result (Sign.add_abbrev PrintMode.internal pos (c, global_rhs))
   224         LocalTheory.theory_result (Sign.add_abbrev PrintMode.internal pos (c, global_rhs))
   222         #-> (fn (lhs, _) =>
   225         #-> (fn (lhs, _) =>
   223           let val lhs' = Term.list_comb (Logic.unvarify lhs, xs) in
   226           let val lhs' = Term.list_comb (Logic.unvarify lhs, xs) in
   224             term_syntax ta (locale_const prmode pos ((c, mx2), lhs')) #>
   227             term_syntax ta (locale_const ta prmode pos ((c, mx2), lhs')) #>
   225             is_class ? class_target ta (Class.add_syntactic_const target prmode pos ((c, mx1), t'))
   228             is_class ? class_target ta (Class.add_syntactic_const target prmode pos ((c, mx1), t'))
   226           end)
   229           end)
   227       else
   230       else
   228         LocalTheory.theory
   231         LocalTheory.theory
   229           (Sign.add_abbrev (#1 prmode) pos (c, global_rhs) #-> (fn (lhs, _) =>
   232           (Sign.add_abbrev (#1 prmode) pos (c, global_rhs) #-> (fn (lhs, _) =>