src/Pure/Isar/locale.ML
changeset 28991 694227dd3e8c
parent 28965 1de908189869
child 29004 a5a91f387791
equal deleted inserted replaced
28966:71a7f76b522d 28991:694227dd3e8c
   385 (
   385 (
   386   type T = NameSpace.T * locale Symtab.table;
   386   type T = NameSpace.T * locale Symtab.table;
   387     (* 1st entry: locale namespace,
   387     (* 1st entry: locale namespace,
   388        2nd entry: locales of the theory *)
   388        2nd entry: locales of the theory *)
   389 
   389 
   390   val empty = (NameSpace.empty, Symtab.empty);
   390   val empty = NameSpace.empty_table;
   391   val copy = I;
   391   val copy = I;
   392   val extend = I;
   392   val extend = I;
   393 
   393 
   394   fun join_locales _
   394   fun join_locales _
   395     ({axiom, elems, params, decls = (decls1, decls2), regs, intros, dests}: locale,
   395     ({axiom, elems, params, decls = (decls1, decls2), regs, intros, dests}: locale,
   401        (Library.merge (eq_snd (op =)) (decls1, decls1'),
   401        (Library.merge (eq_snd (op =)) (decls1, decls1'),
   402         Library.merge (eq_snd (op =)) (decls2, decls2')),
   402         Library.merge (eq_snd (op =)) (decls2, decls2')),
   403       regs = merge_alists (op =) regs regs',
   403       regs = merge_alists (op =) regs regs',
   404       intros = intros,
   404       intros = intros,
   405       dests = dests};
   405       dests = dests};
   406   fun merge _ ((space1, locs1), (space2, locs2)) =
   406   fun merge _ = NameSpace.join_tables join_locales;
   407     (NameSpace.merge (space1, space2), Symtab.join join_locales (locs1, locs2));
       
   408 );
   407 );
   409 
   408 
   410 
   409 
   411 
   410 
   412 (** context data : registrations **)
   411 (** context data : registrations **)
   429 
   428 
   430 fun the_locale thy name = case get_locale thy name
   429 fun the_locale thy name = case get_locale thy name
   431  of SOME loc => loc
   430  of SOME loc => loc
   432   | NONE => error ("Unknown locale " ^ quote name);
   431   | NONE => error ("Unknown locale " ^ quote name);
   433 
   432 
   434 fun register_locale name loc thy =
   433 fun register_locale bname loc thy =
   435   thy |> LocalesData.map (fn (space, locs) =>
   434   thy |> LocalesData.map (NameSpace.bind (Sign.naming_of thy)
   436     (NameSpace.declare_base (Sign.naming_of thy) name space,
   435     (Binding.name bname, loc) #> snd);
   437       Symtab.update (name, loc) locs));
       
   438 
   436 
   439 fun change_locale name f thy =
   437 fun change_locale name f thy =
   440   let
   438   let
   441     val {axiom, elems, params, decls, regs, intros, dests} =
   439     val {axiom, elems, params, decls, regs, intros, dests} =
   442         the_locale thy name;
   440         the_locale thy name;
  1988     val loc_ctxt = thy'
  1986     val loc_ctxt = thy'
  1989       |> Sign.add_path bname
  1987       |> Sign.add_path bname
  1990       |> Sign.no_base_names
  1988       |> Sign.no_base_names
  1991       |> PureThy.note_thmss Thm.assumptionK facts' |> snd
  1989       |> PureThy.note_thmss Thm.assumptionK facts' |> snd
  1992       |> Sign.restore_naming thy'
  1990       |> Sign.restore_naming thy'
  1993       |> register_locale name {axiom = axs',
  1991       |> register_locale bname {axiom = axs',
  1994         elems = map (fn e => (e, stamp ())) elems'',
  1992         elems = map (fn e => (e, stamp ())) elems'',
  1995         params = params_of elemss''' |> map (fn (x, SOME T) => ((x, T), the (Symtab.lookup syn x))),
  1993         params = params_of elemss''' |> map (fn (x, SOME T) => ((x, T), the (Symtab.lookup syn x))),
  1996         decls = ([], []),
  1994         decls = ([], []),
  1997         regs = regs,
  1995         regs = regs,
  1998         intros = intros,
  1996         intros = intros,