src/Pure/Isar/theory_target.ML
changeset 24657 185502d54c3d
parent 24389 9ddef2b1118a
child 24748 ee0a0eb6b738
equal deleted inserted replaced
24656:67f6bf194ca6 24657:185502d54c3d
    88       in (((c, mx2), t), thy') end;
    88       in (((c, mx2), t), thy') end;
    89 
    89 
    90     fun const_class (SOME class) ((c, _), mx) (_, t) =
    90     fun const_class (SOME class) ((c, _), mx) (_, t) =
    91           Class.add_const_in_class class ((c, t), mx)
    91           Class.add_const_in_class class ((c, t), mx)
    92       | const_class NONE _ _ = I;
    92       | const_class NONE _ _ = I;
    93 
    93     fun hide_abbrev (SOME class) abbrs thy =
       
    94           let
       
    95             val raw_cs = map (fst o fst) abbrs;
       
    96             val prfx = (Logic.const_of_class o NameSpace.base) class;
       
    97             fun mk_name c =
       
    98               let
       
    99                 val n1 = Sign.full_name thy c;
       
   100                 val n2 = NameSpace.qualifier n1;
       
   101                 val n3 = NameSpace.base n1;
       
   102               in NameSpace.implode [n2, prfx, prfx, n3] end;
       
   103             val cs = map mk_name raw_cs;
       
   104           in
       
   105             Sign.hide_consts_i true cs thy
       
   106           end
       
   107       | hide_abbrev NONE _ thy = thy;
    94     val (abbrs, lthy') = lthy
   108     val (abbrs, lthy') = lthy
    95       |> LocalTheory.theory_result (fold_map const decls)
   109       |> LocalTheory.theory_result (fold_map const decls)
    96     val defs = map (apsnd (pair ("", []))) abbrs;
   110     val defs = map (apsnd (pair ("", []))) abbrs;
       
   111     
    97   in
   112   in
    98     lthy'
   113     lthy'
       
   114     |> LocalTheory.raw_theory (fold2 (const_class some_class) decls abbrs)
    99     |> is_loc ? fold (internal_abbrev Syntax.default_mode) abbrs
   115     |> is_loc ? fold (internal_abbrev Syntax.default_mode) abbrs
   100     |> LocalTheory.raw_theory (fold2 (const_class some_class) decls abbrs)
   116     |> LocalTheory.raw_theory (hide_abbrev some_class abbrs)
       
   117         (*FIXME abbreviations should never occur*)
   101     |> LocalDefs.add_defs defs
   118     |> LocalDefs.add_defs defs
   102     |>> map (apsnd snd)
   119     |>> map (apsnd snd)
   103   end;
   120   end;
   104 
   121 
   105 
   122 
   340 fun begin loc ctxt =
   357 fun begin loc ctxt =
   341   let
   358   let
   342     val thy = ProofContext.theory_of ctxt;
   359     val thy = ProofContext.theory_of ctxt;
   343     val is_loc = loc <> "";
   360     val is_loc = loc <> "";
   344     val some_class = Class.class_of_locale thy loc;
   361     val some_class = Class.class_of_locale thy loc;
       
   362     fun class_init_exit (SOME class) =
       
   363           Class.init class
       
   364       | class_init_exit NONE =
       
   365           pair I;
   345   in
   366   in
   346     ctxt
   367     ctxt
   347     |> Data.put (if is_loc then SOME loc else NONE)
   368     |> Data.put (if is_loc then SOME loc else NONE)
   348     |> LocalTheory.init (NameSpace.base loc)
   369     |> class_init_exit some_class
       
   370     |-> (fn exit => LocalTheory.init (NameSpace.base loc)
   349      {pretty = pretty loc,
   371      {pretty = pretty loc,
   350       consts = consts is_loc some_class,
   372       consts = consts is_loc some_class,
   351       axioms = axioms,
   373       axioms = axioms,
   352       abbrev = abbrev is_loc some_class,
   374       abbrev = abbrev is_loc some_class,
   353       defs = defs,
   375       defs = defs,
   356       term_syntax = term_syntax loc,
   378       term_syntax = term_syntax loc,
   357       declaration = declaration loc,
   379       declaration = declaration loc,
   358       target_morphism = target_morphism loc,
   380       target_morphism = target_morphism loc,
   359       target_naming = target_naming loc,
   381       target_naming = target_naming loc,
   360       reinit = fn _ =>
   382       reinit = fn _ =>
   361         begin loc o (if is_loc then Locale.init loc else ProofContext.init),
   383         (if is_loc then Locale.init loc else ProofContext.init)
   362       exit = LocalTheory.target_of}
   384         #> begin loc,
       
   385       exit = LocalTheory.target_of #> ProofContext.theory exit })
   363   end;
   386   end;
   364 
   387 
   365 fun init_i NONE thy = begin "" (ProofContext.init thy)
   388 fun init_i NONE thy = begin "" (ProofContext.init thy)
   366   | init_i (SOME loc) thy = begin loc (Locale.init loc thy);
   389   | init_i (SOME loc) thy = begin loc (Locale.init loc thy);
   367 
   390