src/Pure/Thy/export_theory.ML
changeset 69034 855c3c501b09
parent 69029 aec64b88e708
child 69069 b9aca3b9619f
equal deleted inserted replaced
69033:c5db368833b1 69034:855c3c501b09
    70   (fold_types o fold_atyps) (fn TFree (a, S) => is_free used a ? insert (op =) (a, S) | _ => I);
    70   (fold_types o fold_atyps) (fn TFree (a, S) => is_free used a ? insert (op =) (a, S) | _ => I);
    71 
    71 
    72 
    72 
    73 (* locale content *)
    73 (* locale content *)
    74 
    74 
    75 fun locale_content ctxt loc =
    75 fun locale_content thy loc =
    76   let
    76   let
    77     val thy = Proof_Context.theory_of ctxt;
       
    78 
       
    79     val args = map #1 (Locale.params_of thy loc);
    77     val args = map #1 (Locale.params_of thy loc);
    80     val axioms =
    78     val axioms =
    81       let
    79       let
    82         val (intro1, intro2) = Locale.intros_of thy loc;
    80         val (intro1, intro2) = Locale.intros_of thy loc;
    83         fun intros_tac ctxt = Method.try_intros_tac ctxt (the_list intro1 @ the_list intro2);
    81         fun intros_tac ctxt = Method.try_intros_tac ctxt (the_list intro1 @ the_list intro2);
    91       in
    89       in
    92         (case res of
    90         (case res of
    93           SOME st => Thm.prems_of (#goal (Proof.goal st))
    91           SOME st => Thm.prems_of (#goal (Proof.goal st))
    94         | NONE => raise Fail ("Cannot unfold locale " ^ quote loc))
    92         | NONE => raise Fail ("Cannot unfold locale " ^ quote loc))
    95       end;
    93       end;
    96 
       
    97     val typargs = rev (fold Term.add_tfrees (map Free args @ axioms) []);
    94     val typargs = rev (fold Term.add_tfrees (map Free args @ axioms) []);
    98     val typargs_dups =
       
    99       AList.group (op =) typargs |> filter (fn (_, [_]) => false | _ => true)
       
   100         |> maps (fn (x, ys) => map (pair x) ys);
       
   101     val typargs_print = Syntax.string_of_typ (Config.put show_sorts true ctxt) o TFree;
       
   102     val _ =
       
   103       if null typargs_dups then ()
       
   104       else error ("Duplicate type parameters " ^ commas (map typargs_print typargs_dups));
       
   105   in {typargs = typargs, args = args, axioms = axioms} end;
    95   in {typargs = typargs, args = args, axioms = axioms} end;
   106 
    96 
   107 
    97 
   108 (* general setup *)
    98 (* general setup *)
   109 
    99 
   288       let open XML.Encode Term_XML.Encode
   278       let open XML.Encode Term_XML.Encode
   289       in triple (list (pair string sort)) (list (pair string typ)) (list (encode_axiom used)) end;
   279       in triple (list (pair string sort)) (list (pair string typ)) (list (encode_axiom used)) end;
   290 
   280 
   291     fun export_locale loc =
   281     fun export_locale loc =
   292       let
   282       let
   293         val {typargs, args, axioms} = locale_content thy_ctxt loc;
   283         val {typargs, args, axioms} = locale_content thy loc;
   294         val used = fold Name.declare (map #1 typargs @ map #1 args) Name.context;
   284         val used = fold Name.declare (map #1 typargs @ map #1 args) Name.context;
   295       in encode_locale used (typargs, args, axioms) end
   285       in encode_locale used (typargs, args, axioms) end
   296       handle ERROR msg =>
   286       handle ERROR msg =>
   297         cat_error msg ("The error(s) above occurred in locale " ^
   287         cat_error msg ("The error(s) above occurred in locale " ^
   298           quote (Locale.markup_name thy_ctxt loc));
   288           quote (Locale.markup_name thy_ctxt loc));