|
@@ -10192,6 +10192,60 @@ struct
|
|
gen.gmodule_filters#add ~name:name ~priority:(PCustom priority) map
|
|
gen.gmodule_filters#add ~name:name ~priority:(PCustom priority) map
|
|
end;;
|
|
end;;
|
|
|
|
|
|
|
|
+(* ******************************************* *)
|
|
|
|
+(* NormalizeType *)
|
|
|
|
+(* ******************************************* *)
|
|
|
|
+
|
|
|
|
+(*
|
|
|
|
+
|
|
|
|
+ - Filters out enum constructor type parameters from the AST; See Issue #1796
|
|
|
|
+ - Filters out monomorphs
|
|
|
|
+
|
|
|
|
+ dependencies:
|
|
|
|
+ No dependencies; but it still should be one of the first filters to run,
|
|
|
|
+ as it will help normalize the AST
|
|
|
|
+
|
|
|
|
+*)
|
|
|
|
+
|
|
|
|
+module NormalizeType =
|
|
|
|
+struct
|
|
|
|
+
|
|
|
|
+ let name = "normalize_type"
|
|
|
|
+
|
|
|
|
+ let priority = max_dep
|
|
|
|
+
|
|
|
|
+ let rec filter_param t = match t with
|
|
|
|
+ | TInst({ cl_kind = KTypeParameter _ } as c,_) when Meta.has Meta.EnumConstructorParam c.cl_meta ->
|
|
|
|
+ t_dynamic
|
|
|
|
+ | TMono r -> (match !r with
|
|
|
|
+ | None -> t_dynamic
|
|
|
|
+ | Some t -> filter_param t)
|
|
|
|
+ | TInst(_,[]) | TEnum(_,[]) | TType(_,[]) | TAbstract(_,[]) -> t
|
|
|
|
+ | TType(t,tl) -> TType(t,List.map filter_param tl)
|
|
|
|
+ | TInst(c,tl) -> TInst(c,List.map filter_param tl)
|
|
|
|
+ | TEnum(e,tl) -> TEnum(e,List.map filter_param tl)
|
|
|
|
+ | TAbstract(a,tl) -> TAbstract(a, List.map filter_param tl)
|
|
|
|
+ | TAnon a ->
|
|
|
|
+ TAnon {
|
|
|
|
+ a_fields = PMap.map (fun f -> { f with cf_type = filter_param f.cf_type }) a.a_fields;
|
|
|
|
+ a_status = a.a_status;
|
|
|
|
+ }
|
|
|
|
+ | TFun(args,ret) -> TFun(List.map (fun (n,o,t) -> (n,o,filter_param t)) args, filter_param ret)
|
|
|
|
+ | TDynamic _ -> t
|
|
|
|
+ | TLazy f -> filter_param (!f())
|
|
|
|
+
|
|
|
|
+ let default_implementation gen =
|
|
|
|
+ let rec run e =
|
|
|
|
+ map_expr_type (fun e -> run e) filter_param (fun v -> v.v_type <- filter_param v.v_type; v) e
|
|
|
|
+ in
|
|
|
|
+ run
|
|
|
|
+
|
|
|
|
+ let configure gen =
|
|
|
|
+ let map e = Some(default_implementation gen e) in
|
|
|
|
+ gen.gexpr_filters#add ~name:name ~priority:(PCustom priority) map
|
|
|
|
+
|
|
|
|
+end;;
|
|
|
|
+
|
|
(*
|
|
(*
|
|
(* ******************************************* *)
|
|
(* ******************************************* *)
|
|
(* Example *)
|
|
(* Example *)
|