src/HOL/Tools/datatype_codegen.ML
changeset 22921 475ff421a6a3
parent 22778 a5b87573f427
child 23513 2ebb50c0db4f
equal deleted inserted replaced
22920:0dbcb73bf9bf 22921:475ff421a6a3
   283 
   283 
   284 fun datatype_codegen thy defs gr dep module brack t = (case strip_comb t of
   284 fun datatype_codegen thy defs gr dep module brack t = (case strip_comb t of
   285    (c as Const (s, T), ts) =>
   285    (c as Const (s, T), ts) =>
   286      (case DatatypePackage.datatype_of_case thy s of
   286      (case DatatypePackage.datatype_of_case thy s of
   287         SOME {index, descr, ...} =>
   287         SOME {index, descr, ...} =>
   288           if is_some (get_assoc_code thy s T) then NONE else
   288           if is_some (get_assoc_code thy (s, T)) then NONE else
   289           SOME (pretty_case thy defs gr dep module brack
   289           SOME (pretty_case thy defs gr dep module brack
   290             (#3 (the (AList.lookup op = descr index))) c ts)
   290             (#3 (the (AList.lookup op = descr index))) c ts)
   291       | NONE => case (DatatypePackage.datatype_of_constr thy s, strip_type T) of
   291       | NONE => case (DatatypePackage.datatype_of_constr thy s, strip_type T) of
   292         (SOME {index, descr, ...}, (_, U as Type _)) =>
   292         (SOME {index, descr, ...}, (_, U as Type _)) =>
   293           if is_some (get_assoc_code thy s T) then NONE else
   293           if is_some (get_assoc_code thy (s, T)) then NONE else
   294           let val SOME args = AList.lookup op =
   294           let val SOME args = AList.lookup op =
   295             (#3 (the (AList.lookup op = descr index))) s
   295             (#3 (the (AList.lookup op = descr index))) s
   296           in
   296           in
   297             SOME (pretty_constr thy defs
   297             SOME (pretty_constr thy defs
   298               (fst (invoke_tycodegen thy defs dep module false (gr, U)))
   298               (fst (invoke_tycodegen thy defs dep module false (gr, U)))
   303 
   303 
   304 fun datatype_tycodegen thy defs gr dep module brack (Type (s, Ts)) =
   304 fun datatype_tycodegen thy defs gr dep module brack (Type (s, Ts)) =
   305       (case DatatypePackage.get_datatype thy s of
   305       (case DatatypePackage.get_datatype thy s of
   306          NONE => NONE
   306          NONE => NONE
   307        | SOME {descr, ...} =>
   307        | SOME {descr, ...} =>
   308            if isSome (get_assoc_type thy s) then NONE else
   308            if is_some (get_assoc_type thy s) then NONE else
   309            let
   309            let
   310              val (gr', ps) = foldl_map
   310              val (gr', ps) = foldl_map
   311                (invoke_tycodegen thy defs dep module false) (gr, Ts);
   311                (invoke_tycodegen thy defs dep module false) (gr, Ts);
   312              val (gr'', module') = add_dt_defs thy defs dep module gr' descr;
   312              val (gr'', module') = add_dt_defs thy defs dep module gr' descr;
   313              val (gr''', tyid) = mk_type_id module' s gr''
   313              val (gr''', tyid) = mk_type_id module' s gr''