|
@@ -28,81 +28,58 @@ let s_module_type_kind = function
|
|
| TAbstractDecl a -> "TAbstractDecl(" ^ (s_type_path a.a_path) ^ ")"
|
|
| TAbstractDecl a -> "TAbstractDecl(" ^ (s_type_path a.a_path) ^ ")"
|
|
| TTypeDecl t -> "TTypeDecl(" ^ (s_type_path t.t_path) ^ ")"
|
|
| TTypeDecl t -> "TTypeDecl(" ^ (s_type_path t.t_path) ^ ")"
|
|
|
|
|
|
-let show_mono_ids = true
|
|
|
|
-
|
|
|
|
-let rec s_mono_constraint_kind s_type constr =
|
|
|
|
- let rec loop = function
|
|
|
|
- | CUnknown -> ""
|
|
|
|
- | CTypes tl -> String.concat " & " (List.map (fun (t,_) -> s_type t) tl)
|
|
|
|
- | CStructural(fields,_) -> s_type (mk_anon ~fields (ref Closed))
|
|
|
|
- | CMixed l -> String.concat " & " (List.map loop l)
|
|
|
|
- in
|
|
|
|
- loop constr
|
|
|
|
|
|
|
|
-and s_mono_modifiers s m =
|
|
|
|
- List.fold_left (fun s modi -> match modi with
|
|
|
|
- | MNullable _ -> Printf.sprintf "Null<%s>" s
|
|
|
|
- | MOpenStructure | MDynamic -> s
|
|
|
|
- ) s m.tm_modifiers
|
|
|
|
|
|
+module MonomorphPrinting = struct
|
|
|
|
+ let show_mono_ids = true
|
|
|
|
|
|
-and s_mono ctx m =
|
|
|
|
- match m.tm_type with
|
|
|
|
- | None ->
|
|
|
|
- let print_name id extra =
|
|
|
|
- let s = if show_mono_ids then
|
|
|
|
- Printf.sprintf "Unknown<%d>" id
|
|
|
|
- else
|
|
|
|
- "Unknown"
|
|
|
|
- in
|
|
|
|
- let s = s ^ extra in
|
|
|
|
- s_mono_modifiers s m
|
|
|
|
|
|
+ let s_mono_constraint_kind s_type constr =
|
|
|
|
+ let rec loop = function
|
|
|
|
+ | CUnknown -> ""
|
|
|
|
+ | CTypes tl -> String.concat " & " (List.map (fun (t,_) -> s_type t) tl)
|
|
|
|
+ | CStructural(fields,_) -> s_type (mk_anon ~fields (ref Closed))
|
|
|
|
+ | CMixed l -> String.concat " & " (List.map loop l)
|
|
in
|
|
in
|
|
- begin try
|
|
|
|
- let id = List.assq m (!ctx) in
|
|
|
|
- print_name id ""
|
|
|
|
- with Not_found ->
|
|
|
|
- let id = List.length !ctx in
|
|
|
|
- ctx := (m,id) :: !ctx;
|
|
|
|
- let s_const =
|
|
|
|
- let s = s_mono_constraint_kind (s_type ctx) (!monomorph_classify_constraints_ref m) in
|
|
|
|
- if s = "" then s else " : " ^ s
|
|
|
|
- in
|
|
|
|
- print_name id s_const
|
|
|
|
- end
|
|
|
|
- | Some t -> s_type ctx t
|
|
|
|
|
|
+ loop constr
|
|
|
|
|
|
-(* TODO: refactor these two functions... *)
|
|
|
|
-and s_mono_explicit ctx m =
|
|
|
|
- let print_name id extra =
|
|
|
|
|
|
+ let print_mono_name m id extra =
|
|
let s = if show_mono_ids then
|
|
let s = if show_mono_ids then
|
|
Printf.sprintf "Unknown<%d>" id
|
|
Printf.sprintf "Unknown<%d>" id
|
|
else
|
|
else
|
|
"Unknown"
|
|
"Unknown"
|
|
in
|
|
in
|
|
let s = s ^ extra in
|
|
let s = s ^ extra in
|
|
- s_mono_modifiers s m
|
|
|
|
- in
|
|
|
|
- begin try
|
|
|
|
- let id = List.assq m (!ctx) in
|
|
|
|
- print_name id ""
|
|
|
|
- with Not_found ->
|
|
|
|
- let id = List.length !ctx in
|
|
|
|
- ctx := (m,id) :: !ctx;
|
|
|
|
|
|
+ List.fold_left (fun s modi -> match modi with
|
|
|
|
+ | MNullable _ -> Printf.sprintf "Null<%s>" s
|
|
|
|
+ | MOpenStructure | MDynamic -> s
|
|
|
|
+ ) s m.tm_modifiers
|
|
|
|
+
|
|
|
|
+ let s_mono s_type ctx explicit m =
|
|
match m.tm_type with
|
|
match m.tm_type with
|
|
- | None ->
|
|
|
|
- let s_const =
|
|
|
|
- let s = s_mono_constraint_kind (s_type ctx) (!monomorph_classify_constraints_ref m) in
|
|
|
|
- if s = "" then s else " : " ^ s
|
|
|
|
- in
|
|
|
|
- print_name id s_const
|
|
|
|
- | Some t ->
|
|
|
|
- print_name id (" := " ^ (s_type ctx) t)
|
|
|
|
- end
|
|
|
|
|
|
+ | Some t when not explicit ->
|
|
|
|
+ s_type ctx t
|
|
|
|
+ | _ ->
|
|
|
|
+ begin try
|
|
|
|
+ let id = List.assq m (!ctx) in
|
|
|
|
+ print_mono_name m id ""
|
|
|
|
+ with Not_found ->
|
|
|
|
+ let id = List.length !ctx in
|
|
|
|
+ ctx := (m,id) :: !ctx;
|
|
|
|
+ match m.tm_type with
|
|
|
|
+ | Some t when explicit ->
|
|
|
|
+ print_mono_name m id (" := " ^ (s_type ctx) t)
|
|
|
|
+ | _ ->
|
|
|
|
+ let s_const =
|
|
|
|
+ let s = s_mono_constraint_kind (s_type ctx) (!monomorph_classify_constraints_ref m) in
|
|
|
|
+ if s = "" then s else " : " ^ s
|
|
|
|
+ in
|
|
|
|
+ print_mono_name m id s_const
|
|
|
|
+ end
|
|
|
|
+end
|
|
|
|
|
|
-and s_type ctx t =
|
|
|
|
|
|
+let rec s_type ctx t =
|
|
match t with
|
|
match t with
|
|
| TMono r ->
|
|
| TMono r ->
|
|
- s_mono ctx r
|
|
|
|
|
|
+ MonomorphPrinting.s_mono s_type ctx false r
|
|
| TEnum (e,tl) ->
|
|
| TEnum (e,tl) ->
|
|
s_type_path e.e_path ^ s_type_params ctx tl
|
|
s_type_path e.e_path ^ s_type_params ctx tl
|
|
| TInst (c,tl) ->
|
|
| TInst (c,tl) ->
|