src/Pure/Tools/codegen_funcgr.ML
changeset 20938 041badc7fcaf
parent 20896 1484c7af6d68
child 21120 e333c844b057
equal deleted inserted replaced
20937:4297a44e26ae 20938:041badc7fcaf
    13   val all_deps_of: T -> CodegenConsts.const list -> CodegenConsts.const list list
    13   val all_deps_of: T -> CodegenConsts.const list -> CodegenConsts.const list list
    14   val get_funcs: T -> CodegenConsts.const -> thm list
    14   val get_funcs: T -> CodegenConsts.const -> thm list
    15   val get_func_typs: T -> (CodegenConsts.const * typ) list
    15   val get_func_typs: T -> (CodegenConsts.const * typ) list
    16   val normalize: theory -> thm list -> thm list
    16   val normalize: theory -> thm list -> thm list
    17   val print_codethms: theory -> CodegenConsts.const list -> unit
    17   val print_codethms: theory -> CodegenConsts.const list -> unit
       
    18   structure Constgraph : GRAPH
    18 end;
    19 end;
    19 
    20 
    20 structure CodegenFuncgr: CODEGEN_FUNCGR =
    21 structure CodegenFuncgr: CODEGEN_FUNCGR =
    21 struct
    22 struct
    22 
    23 
    34 (struct
    35 (struct
    35   val name = "Pure/codegen_funcgr";
    36   val name = "Pure/codegen_funcgr";
    36   type T = T;
    37   type T = T;
    37   val empty = Constgraph.empty;
    38   val empty = Constgraph.empty;
    38   fun merge _ _ = Constgraph.empty;
    39   fun merge _ _ = Constgraph.empty;
    39   fun purge _ _ = Constgraph.empty;
    40   fun purge _ NONE _ = Constgraph.empty
       
    41     | purge _ (SOME cs) funcgr =
       
    42         Constgraph.del_nodes ((Constgraph.all_succs funcgr 
       
    43           o filter (can (Constgraph.get_node funcgr))) cs) funcgr;
    40 end);
    44 end);
    41 
    45 
    42 val _ = Context.add_setup Funcgr.init;
    46 val _ = Context.add_setup Funcgr.init;
    43 
    47 
    44 
    48 
   275   in eqss'' end;
   279   in eqss'' end;
   276 
   280 
   277 fun merge_eqsyss thy raw_eqss funcgr =
   281 fun merge_eqsyss thy raw_eqss funcgr =
   278   let
   282   let
   279     val eqss = specialize_typs thy funcgr raw_eqss;
   283     val eqss = specialize_typs thy funcgr raw_eqss;
   280     val tys = map (fn (c as (name, _), []) => (case AxClass.class_of_param thy name
   284     val tys = map (CodegenData.typ_funcs thy) eqss;
   281          of SOME class => (case ClassPackage.the_consts_sign thy class of (v, cs) =>
       
   282               (Logic.varifyT o map_type_tfree (fn u as (w, _) =>
       
   283                 if w = v then TFree (v, [class]) else TFree u))
       
   284               ((the o AList.lookup (op =) cs) name))
       
   285           | NONE => Sign.the_const_type thy name)
       
   286                    | (_, eq :: _) => CodegenData.typ_func thy eq) eqss;
       
   287     val rhss = map (rhs_of thy) eqss;
   285     val rhss = map (rhs_of thy) eqss;
   288   in
   286   in
   289     funcgr
   287     funcgr
   290     |> fold2 (fn (c, thms) => fn ty => Constgraph.new_node (c, (ty, thms))) eqss tys
   288     |> fold2 (fn (c, thms) => fn ty => Constgraph.new_node (c, (ty, thms))) eqss tys
   291     |> `(fn funcgr => map (insts_of_thms thy funcgr) eqss)
   289     |> `(fn funcgr => map (insts_of_thms thy funcgr) eqss)