src/Pure/Isar/locale.ML
changeset 28024 d1c2fa105443
parent 28020 1ff5167592ba
child 28053 a2106c0d8c45
equal deleted inserted replaced
28023:92dd3ad302b7 28024:d1c2fa105443
  1569 
  1569 
  1570 (** store results **)
  1570 (** store results **)
  1571 
  1571 
  1572 (* naming of interpreted theorems *)
  1572 (* naming of interpreted theorems *)
  1573 
  1573 
  1574 fun global_note_prefix_i kind loc (fully_qualified, prfx) args thy =
  1574 fun global_note_prefix_i kind loc (fully_qualified, prfx) params args thy =
  1575   thy
  1575   thy
  1576   |> Sign.qualified_names
  1576   |> Sign.qualified_names
  1577   |> Sign.add_path (NameSpace.base loc ^ "_locale")
  1577   |> Sign.add_path (NameSpace.base loc ^ "_locale")
  1578   |> (if fully_qualified then Sign.sticky_prefix prfx else Sign.add_path prfx)
  1578   |> (if fully_qualified then Sign.sticky_prefix prfx else Sign.add_path prfx)
       
  1579   |> (if fully_qualified then Sign.add_path (space_implode "_" params) else I)
  1579   |> PureThy.note_thmss kind args
  1580   |> PureThy.note_thmss kind args
  1580   ||> Sign.restore_naming thy;
  1581   ||> Sign.restore_naming thy;
  1581 
  1582 
  1582 fun local_note_prefix_i kind loc (fully_qualified, prfx) args ctxt =
  1583 fun local_note_prefix_i kind loc (fully_qualified, prfx) params args ctxt =
  1583   ctxt
  1584   ctxt
  1584   |> ProofContext.qualified_names
  1585   |> ProofContext.qualified_names
  1585   |> ProofContext.add_path (NameSpace.base loc ^ "_locale")
  1586   |> ProofContext.add_path (NameSpace.base loc ^ "_locale")
  1586   |> (if fully_qualified then ProofContext.sticky_prefix prfx else ProofContext.add_path prfx)
  1587   |> (if fully_qualified then ProofContext.sticky_prefix prfx else ProofContext.add_path prfx)
       
  1588   |> (if fully_qualified then ProofContext.add_path (space_implode "_" params) else I)
  1587   |> ProofContext.note_thmss_i kind args
  1589   |> ProofContext.note_thmss_i kind args
  1588   ||> ProofContext.restore_naming ctxt;
  1590   ||> ProofContext.restore_naming ctxt;
  1589 
  1591 
  1590 
  1592 
  1591 (* join equations of an id with already accumulated ones *)
  1593 (* join equations of an id with already accumulated ones *)
  1640     val morphism =
  1642     val morphism =
  1641       Morphism.morphism {name = I, var = I, typ = exp_typ, term = exp_term, fact = exp_fact};
  1643       Morphism.morphism {name = I, var = I, typ = exp_typ, term = exp_term, fact = exp_fact};
  1642   in Element.facts_map (Element.morph_ctxt morphism) facts end;
  1644   in Element.facts_map (Element.morph_ctxt morphism) facts end;
  1643 
  1645 
  1644 
  1646 
  1645 (* suppress application of name morphism: workaroud for class package *) (* FIXME *)
       
  1646 
       
  1647 fun morph_ctxt' phi = Element.map_ctxt
  1647 fun morph_ctxt' phi = Element.map_ctxt
  1648   {name = I,
  1648   {name = I,
  1649    var = Morphism.var phi,
  1649    var = Morphism.var phi,
  1650    typ = Morphism.typ phi,
  1650    typ = Morphism.typ phi,
  1651    term = Morphism.term phi,
  1651    term = Morphism.term phi,
  1656 (* compute morphism and apply to args *)
  1656 (* compute morphism and apply to args *)
  1657 
  1657 
  1658 fun interpret_args thy prfx insts prems eqns atts2 exp attrib args =
  1658 fun interpret_args thy prfx insts prems eqns atts2 exp attrib args =
  1659   let
  1659   let
  1660     val inst = Morphism.name_morphism (NameSpace.qualified prfx) $>
  1660     val inst = Morphism.name_morphism (NameSpace.qualified prfx) $>
       
  1661 (* need to add parameter prefix *) (* FIXME *)
  1661       Element.inst_morphism thy insts $> Element.satisfy_morphism prems $>
  1662       Element.inst_morphism thy insts $> Element.satisfy_morphism prems $>
  1662       Morphism.term_morphism (MetaSimplifier.rewrite_term thy eqns []) $>
  1663       Morphism.term_morphism (MetaSimplifier.rewrite_term thy eqns []) $>
  1663       Morphism.thm_morphism (MetaSimplifier.rewrite_rule eqns)
  1664       Morphism.thm_morphism (MetaSimplifier.rewrite_rule eqns)
  1664   in
  1665   in
  1665     args |> Element.facts_map (morph_ctxt' inst) |>
  1666     args |> Element.facts_map (morph_ctxt' inst) |>
       
  1667 (* suppresses application of name morphism: workaroud for class package *) (* FIXME *)
  1666       map (fn (attn, bs) => (attn,
  1668       map (fn (attn, bs) => (attn,
  1667         bs |> map (fn (ths, atts) => (ths, (atts @ atts2))))) |>
  1669         bs |> map (fn (ths, atts) => (ths, (atts @ atts2))))) |>
  1668       standardize thy exp |> Attrib.map_facts attrib
  1670       standardize thy exp |> Attrib.map_facts attrib
  1669   end;
  1671   end;
  1670 
  1672 
  1684     fun activate (vts, (((fully_qualified, prfx), atts2), (exp, imp), _, _)) thy =
  1686     fun activate (vts, (((fully_qualified, prfx), atts2), (exp, imp), _, _)) thy =
  1685       let
  1687       let
  1686         val (insts, prems, eqns) = collect_global_witnesses thy imp parms ids vts;
  1688         val (insts, prems, eqns) = collect_global_witnesses thy imp parms ids vts;
  1687         val attrib = Attrib.attribute_i thy;
  1689         val attrib = Attrib.attribute_i thy;
  1688         val args' = interpret_args thy prfx insts prems eqns atts2 exp attrib args;
  1690         val args' = interpret_args thy prfx insts prems eqns atts2 exp attrib args;
  1689       in global_note_prefix_i kind target (fully_qualified, prfx) args' thy |> snd end;
  1691       in global_note_prefix_i kind target (fully_qualified, prfx) (map fst parms) args' thy |> snd end;
  1690   in fold activate regs thy end;
  1692   in fold activate regs thy end;
  1691 
  1693 
  1692 
  1694 
  1693 (* locale results *)
  1695 (* locale results *)
  1694 
  1696 
  2087         let
  2089         let
  2088           val ctxt = mk_ctxt thy_ctxt;
  2090           val ctxt = mk_ctxt thy_ctxt;
  2089           val facts' = interpret_args (ProofContext.theory_of ctxt) prfx
  2091           val facts' = interpret_args (ProofContext.theory_of ctxt) prfx
  2090               (Symtab.empty, Symtab.empty) prems eqns atts
  2092               (Symtab.empty, Symtab.empty) prems eqns atts
  2091               exp (attrib thy_ctxt) facts;
  2093               exp (attrib thy_ctxt) facts;
  2092         in snd (note_interp kind loc (fully_qualified, prfx) facts' thy_ctxt) end
  2094         in snd (note_interp kind loc (fully_qualified, prfx) [] facts' thy_ctxt) end
  2093       | activate_elem _ _ _ _ thy_ctxt = thy_ctxt;
  2095       | activate_elem _ _ _ _ thy_ctxt = thy_ctxt;
  2094 
  2096 
  2095     fun activate_elems all_eqns ((id, _), elems) thy_ctxt =
  2097     fun activate_elems all_eqns ((id, _), elems) thy_ctxt =
  2096       let
  2098       let
  2097         val (prfx_atts, _, _) = case get_reg thy_ctxt imp id
  2099         val (prfx_atts, _, _) = case get_reg thy_ctxt imp id
  2374                     |> Attrib.map_facts (Attrib.attribute_i thy o Args.morph_values att_morphism)
  2376                     |> Attrib.map_facts (Attrib.attribute_i thy o Args.morph_values att_morphism)
  2375                     |> map (apfst (apsnd (fn a => a @ map (Attrib.attribute thy) atts2)))
  2377                     |> map (apfst (apsnd (fn a => a @ map (Attrib.attribute thy) atts2)))
  2376                     |> map (apsnd (map (apfst (map (disch o Element.inst_thm thy insts o satisfy)))))
  2378                     |> map (apsnd (map (apfst (map (disch o Element.inst_thm thy insts o satisfy)))))
  2377                 in
  2379                 in
  2378                   thy
  2380                   thy
  2379                   |> global_note_prefix_i kind loc (fully_qualified, prfx) facts'
  2381                   |> global_note_prefix_i kind loc (fully_qualified, prfx) [] facts'
  2380                   |> snd
  2382                   |> snd
  2381                 end
  2383                 end
  2382               | activate_elem _ _ thy = thy;
  2384               | activate_elem _ _ thy = thy;
  2383 
  2385 
  2384             fun activate_elems ((id, _), elems) thy = fold (activate_elem id) elems thy;
  2386             fun activate_elems ((id, _), elems) thy = fold (activate_elem id) elems thy;