src/Pure/simplifier.ML
changeset 42464 ae16b8abf1a8
parent 42375 774df7c59508
child 42465 1ba52683512a
equal deleted inserted replaced
42463:f270e3e18be5 42464:ae16b8abf1a8
    56   val simp_add: attribute
    56   val simp_add: attribute
    57   val simp_del: attribute
    57   val simp_del: attribute
    58   val cong_add: attribute
    58   val cong_add: attribute
    59   val cong_del: attribute
    59   val cong_del: attribute
    60   val map_simpset: (simpset -> simpset) -> theory -> theory
    60   val map_simpset: (simpset -> simpset) -> theory -> theory
    61   val get_simproc: Context.generic -> xstring -> simproc
    61   val get_simproc: Proof.context -> xstring * Position.T -> simproc
    62   val def_simproc: {name: string, lhss: string list,
    62   val def_simproc: {name: binding, lhss: term list,
    63     proc: morphism -> simpset -> cterm -> thm option, identifier: thm list} ->
    63     proc: morphism -> simpset -> cterm -> thm option, identifier: thm list} ->
    64     local_theory -> local_theory
    64     local_theory -> local_theory
    65   val def_simproc_i: {name: string, lhss: term list,
    65   val def_simproc_cmd: {name: binding, lhss: string list,
    66     proc: morphism -> simpset -> cterm -> thm option, identifier: thm list} ->
    66     proc: morphism -> simpset -> cterm -> thm option, identifier: thm list} ->
    67     local_theory -> local_theory
    67     local_theory -> local_theory
    68   val cong_modifiers: Method.modifier parser list
    68   val cong_modifiers: Method.modifier parser list
    69   val simp_modifiers': Method.modifier parser list
    69   val simp_modifiers': Method.modifier parser list
    70   val simp_modifiers: Method.modifier parser list
    70   val simp_modifiers: Method.modifier parser list
   160 );
   160 );
   161 
   161 
   162 
   162 
   163 (* get simprocs *)
   163 (* get simprocs *)
   164 
   164 
   165 fun get_simproc context xname =
   165 fun get_simproc ctxt (xname, pos) =
   166   let
   166   let
   167     val (space, tab) = Simprocs.get context;
   167     val (space, tab) = Simprocs.get (Context.Proof ctxt);
   168     val name = Name_Space.intern space xname;
   168     val name = Name_Space.intern space xname;
   169   in
   169   in
   170     (case Symtab.lookup tab name of
   170     (case Symtab.lookup tab name of
   171       SOME proc => proc
   171       SOME proc => (Context_Position.report ctxt pos (Name_Space.markup space name); proc)
   172     | NONE => error ("Undefined simplification procedure: " ^ quote name))
   172     | NONE => error ("Undefined simplification procedure: " ^ quote name))
   173   end;
   173   end;
   174 
   174 
   175 val _ = ML_Antiquote.value "simproc" (Scan.lift Args.name >> (fn name =>
   175 val _ =
   176   "Simplifier.get_simproc (ML_Context.the_generic_context ()) " ^ ML_Syntax.print_string name));
   176   ML_Antiquote.value "simproc" (Scan.lift (Parse.position Args.name) >> (fn x =>
       
   177     "Simplifier.get_simproc (ML_Context.the_local_context ()) " ^
       
   178       ML_Syntax.print_pair ML_Syntax.print_string  ML_Syntax.print_position x));
   177 
   179 
   178 
   180 
   179 (* define simprocs *)
   181 (* define simprocs *)
   180 
   182 
   181 local
   183 local
   182 
   184 
   183 fun gen_simproc prep {name, lhss, proc, identifier} lthy =
   185 fun gen_simproc prep {name = b, lhss, proc, identifier} lthy =
   184   let
   186   let
   185     val b = Binding.name name;
       
   186     val naming = Local_Theory.naming_of lthy;
   187     val naming = Local_Theory.naming_of lthy;
   187     val simproc = make_simproc
   188     val simproc = make_simproc
   188       {name = Name_Space.full_name naming b,
   189       {name = Name_Space.full_name naming b,
   189        lhss =
   190        lhss =
   190         let
   191         let
   209       end)
   210       end)
   210   end;
   211   end;
   211 
   212 
   212 in
   213 in
   213 
   214 
   214 val def_simproc = gen_simproc Syntax.read_terms;
   215 val def_simproc = gen_simproc Syntax.check_terms;
   215 val def_simproc_i = gen_simproc Syntax.check_terms;
   216 val def_simproc_cmd = gen_simproc Syntax.read_terms;
   216 
   217 
   217 end;
   218 end;
   218 
   219 
   219 
   220 
   220 
   221 
   308 in
   309 in
   309 
   310 
   310 val simproc_att =
   311 val simproc_att =
   311   Scan.peek (fn context =>
   312   Scan.peek (fn context =>
   312     add_del :|-- (fn decl =>
   313     add_del :|-- (fn decl =>
   313       Scan.repeat1 (Args.named_attribute (decl o get_simproc context))
   314       Scan.repeat1 (Args.named_attribute (decl o get_simproc (Context.proof_of context)))
   314       >> (Library.apply o map Morphism.form)));
   315       >> (Library.apply o map Morphism.form)));
   315 
   316 
   316 end;
   317 end;
   317 
   318 
   318 
   319