2002-03-27 08:20:32 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* OCamldoc *)
|
|
|
|
(* *)
|
|
|
|
(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2001 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
2003-11-24 02:44:07 -08:00
|
|
|
(* $Id$ *)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** The functions to get a string from different kinds of elements (types, modules, ...). *)
|
|
|
|
|
|
|
|
module Name = Odoc_name
|
|
|
|
|
2003-09-05 08:40:12 -07:00
|
|
|
let string_of_variance t (co,cn) =
|
|
|
|
if t.Odoc_type.ty_kind = Odoc_type.Type_abstract &&
|
|
|
|
t.Odoc_type.ty_manifest = None
|
|
|
|
then
|
|
|
|
match (co, cn) with
|
|
|
|
(true, false) -> "+"
|
|
|
|
| (false, true) -> "-"
|
|
|
|
| _ -> ""
|
|
|
|
else
|
|
|
|
""
|
2005-03-24 09:20:54 -08:00
|
|
|
let rec is_arrow_type t =
|
|
|
|
match t.Types.desc with
|
|
|
|
Types.Tarrow _ -> true
|
|
|
|
| Types.Tlink t2 | Types.Tsubst t2 -> is_arrow_type t2
|
|
|
|
| Types.Ttuple _
|
|
|
|
| Types.Tconstr _
|
|
|
|
| Types.Tvar | Types.Tunivar | Types.Tobject _ | Types.Tpoly _
|
|
|
|
| Types.Tfield _ | Types.Tnil | Types.Tvariant _ -> false
|
2003-09-05 08:40:12 -07:00
|
|
|
|
|
|
|
let raw_string_of_type_list sep type_list =
|
2003-09-12 17:40:31 -07:00
|
|
|
let buf = Buffer.create 256 in
|
|
|
|
let fmt = Format.formatter_of_buffer buf in
|
2003-09-05 08:40:12 -07:00
|
|
|
let rec need_parent t =
|
|
|
|
match t.Types.desc with
|
|
|
|
Types.Tarrow _ | Types.Ttuple _ -> true
|
|
|
|
| Types.Tlink t2 | Types.Tsubst t2 -> need_parent t2
|
|
|
|
| Types.Tconstr _ ->
|
|
|
|
false
|
|
|
|
| Types.Tvar | Types.Tunivar | Types.Tobject _ | Types.Tpoly _
|
|
|
|
| Types.Tfield _ | Types.Tnil | Types.Tvariant _ -> false
|
|
|
|
in
|
|
|
|
let print_one_type variance t =
|
|
|
|
Printtyp.mark_loops t;
|
|
|
|
if need_parent t then
|
2005-03-24 09:20:54 -08:00
|
|
|
(
|
2003-09-12 17:40:31 -07:00
|
|
|
Format.fprintf fmt "(%s" variance;
|
|
|
|
Printtyp.type_scheme_max ~b_reset_names: false fmt t;
|
|
|
|
Format.fprintf fmt ")"
|
2003-09-05 08:40:12 -07:00
|
|
|
)
|
|
|
|
else
|
|
|
|
(
|
2003-09-12 17:40:31 -07:00
|
|
|
Format.fprintf fmt "%s" variance;
|
|
|
|
Printtyp.type_scheme_max ~b_reset_names: false fmt t
|
2003-09-05 08:40:12 -07:00
|
|
|
)
|
|
|
|
in
|
|
|
|
begin match type_list with
|
|
|
|
[] -> ()
|
|
|
|
| [(variance, ty)] -> print_one_type variance ty
|
|
|
|
| (variance, ty) :: tyl ->
|
2003-10-17 08:30:47 -07:00
|
|
|
Format.fprintf fmt "@[<hov 2>";
|
2003-09-05 08:40:12 -07:00
|
|
|
print_one_type variance ty;
|
|
|
|
List.iter
|
2005-03-24 09:20:54 -08:00
|
|
|
(fun (variance, t) ->
|
|
|
|
Format.fprintf fmt "@,%s" sep;
|
2003-09-05 08:40:12 -07:00
|
|
|
print_one_type variance t
|
|
|
|
)
|
|
|
|
tyl;
|
2003-10-17 08:30:47 -07:00
|
|
|
Format.fprintf fmt "@]"
|
2003-09-05 08:40:12 -07:00
|
|
|
end;
|
2003-09-12 17:40:31 -07:00
|
|
|
Format.pp_print_flush fmt ();
|
|
|
|
Buffer.contents buf
|
2003-09-05 08:40:12 -07:00
|
|
|
|
2004-03-22 07:06:31 -08:00
|
|
|
let string_of_type_list ?par sep type_list =
|
2003-10-17 08:30:47 -07:00
|
|
|
let par =
|
2004-03-22 07:06:31 -08:00
|
|
|
match par with
|
|
|
|
| Some b -> b
|
|
|
|
| None ->
|
|
|
|
match type_list with
|
|
|
|
[] | [_] -> false
|
|
|
|
| _ -> true
|
2003-10-17 08:30:47 -07:00
|
|
|
in
|
|
|
|
Printf.sprintf "%s%s%s"
|
|
|
|
(if par then "(" else "")
|
|
|
|
(raw_string_of_type_list sep (List.map (fun t -> ("", t)) type_list))
|
|
|
|
(if par then ")" else "")
|
2003-09-05 08:40:12 -07:00
|
|
|
|
|
|
|
let string_of_type_param_list t =
|
2005-03-24 09:20:54 -08:00
|
|
|
let par =
|
2003-10-17 08:30:47 -07:00
|
|
|
match t.Odoc_type.ty_parameters with
|
|
|
|
[] | [_] -> false
|
|
|
|
| _ -> true
|
|
|
|
in
|
|
|
|
Printf.sprintf "%s%s%s"
|
|
|
|
(if par then "(" else "")
|
|
|
|
(raw_string_of_type_list ", "
|
2005-03-24 09:20:54 -08:00
|
|
|
(List.map
|
2003-10-17 08:30:47 -07:00
|
|
|
(fun (typ, co, cn) -> (string_of_variance t (co, cn), typ))
|
|
|
|
t.Odoc_type.ty_parameters
|
|
|
|
)
|
|
|
|
)
|
|
|
|
(if par then ")" else "")
|
|
|
|
|
|
|
|
let string_of_class_type_param_list l =
|
2005-03-24 09:20:54 -08:00
|
|
|
let par =
|
2003-10-17 08:30:47 -07:00
|
|
|
match l with
|
|
|
|
[] | [_] -> false
|
|
|
|
| _ -> true
|
|
|
|
in
|
|
|
|
Printf.sprintf "%s%s%s"
|
|
|
|
(if par then "[" else "")
|
|
|
|
(raw_string_of_type_list ", "
|
2005-03-24 09:20:54 -08:00
|
|
|
(List.map
|
2003-10-17 08:30:47 -07:00
|
|
|
(fun typ -> ("", typ))
|
|
|
|
l
|
|
|
|
)
|
2003-09-05 08:40:12 -07:00
|
|
|
)
|
2003-10-17 08:30:47 -07:00
|
|
|
(if par then "]" else "")
|
2003-09-05 08:40:12 -07:00
|
|
|
|
2004-08-20 10:04:35 -07:00
|
|
|
let string_of_class_params c =
|
|
|
|
let b = Buffer.create 256 in
|
|
|
|
let rec iter = function
|
|
|
|
Types.Tcty_fun (label, t, ctype) ->
|
2005-03-24 09:20:54 -08:00
|
|
|
let parent = is_arrow_type t in
|
|
|
|
Printf.bprintf b "%s%s%s%s -> "
|
2004-08-20 10:04:35 -07:00
|
|
|
(
|
|
|
|
match label with
|
|
|
|
"" -> ""
|
|
|
|
| s -> s^":"
|
|
|
|
)
|
2005-03-24 09:20:54 -08:00
|
|
|
(if parent then "(" else "")
|
2004-08-20 10:04:35 -07:00
|
|
|
(Odoc_print.string_of_type_expr
|
|
|
|
(if Odoc_misc.is_optional label then
|
|
|
|
Odoc_misc.remove_option t
|
|
|
|
else
|
|
|
|
t
|
|
|
|
)
|
2005-03-24 09:20:54 -08:00
|
|
|
)
|
|
|
|
(if parent then ")" else "");
|
2004-08-20 10:04:35 -07:00
|
|
|
iter ctype
|
2005-03-24 09:20:54 -08:00
|
|
|
| Types.Tcty_signature _
|
2004-08-20 10:04:35 -07:00
|
|
|
| Types.Tcty_constr _ -> ()
|
|
|
|
in
|
|
|
|
iter c.Odoc_class.cl_type;
|
|
|
|
Buffer.contents b
|
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
let string_of_type t =
|
|
|
|
let module M = Odoc_type in
|
|
|
|
"type "^
|
|
|
|
(String.concat ""
|
2005-03-24 09:20:54 -08:00
|
|
|
(List.map
|
|
|
|
(fun (p, co, cn) ->
|
2003-09-05 08:40:12 -07:00
|
|
|
(string_of_variance t (co, cn))^
|
2004-03-05 06:57:52 -08:00
|
|
|
(Odoc_print.string_of_type_expr p)^" "
|
2003-09-05 08:40:12 -07:00
|
|
|
)
|
2002-07-23 07:12:03 -07:00
|
|
|
t.M.ty_parameters
|
2002-03-27 08:20:32 -08:00
|
|
|
)
|
|
|
|
)^
|
|
|
|
(Name.simple t.M.ty_name)^" "^
|
|
|
|
(match t.M.ty_manifest with
|
|
|
|
None -> ""
|
2004-03-05 06:57:52 -08:00
|
|
|
| Some typ -> "= "^(Odoc_print.string_of_type_expr typ)^" "
|
2002-03-27 08:20:32 -08:00
|
|
|
)^
|
|
|
|
(match t.M.ty_kind with
|
2005-03-24 09:20:54 -08:00
|
|
|
M.Type_abstract ->
|
2002-03-27 08:20:32 -08:00
|
|
|
""
|
2003-07-04 02:31:03 -07:00
|
|
|
| M.Type_variant (l, priv) ->
|
|
|
|
"="^(if priv then " private" else "")^"\n"^
|
2002-03-27 08:20:32 -08:00
|
|
|
(String.concat ""
|
2005-03-24 09:20:54 -08:00
|
|
|
(List.map
|
2002-07-23 07:12:03 -07:00
|
|
|
(fun cons ->
|
|
|
|
" | "^cons.M.vc_name^
|
|
|
|
(match cons.M.vc_args with
|
2005-03-24 09:20:54 -08:00
|
|
|
[] -> ""
|
|
|
|
| l ->
|
|
|
|
" of "^(String.concat " * "
|
2004-03-05 06:57:52 -08:00
|
|
|
(List.map (fun t -> "("^(Odoc_print.string_of_type_expr t)^")") l))
|
2002-07-23 07:12:03 -07:00
|
|
|
)^
|
|
|
|
(match cons.M.vc_text with
|
|
|
|
None ->
|
|
|
|
""
|
|
|
|
| Some t ->
|
|
|
|
"(* "^(Odoc_misc.string_of_text t)^" *)"
|
|
|
|
)^"\n"
|
|
|
|
)
|
|
|
|
l
|
|
|
|
)
|
2002-03-27 08:20:32 -08:00
|
|
|
)
|
2003-07-04 02:31:03 -07:00
|
|
|
| M.Type_record (l, priv) ->
|
|
|
|
"= "^(if priv then "private " else "")^"{\n"^
|
2002-03-27 08:20:32 -08:00
|
|
|
(String.concat ""
|
2005-03-24 09:20:54 -08:00
|
|
|
(List.map
|
2002-07-23 07:12:03 -07:00
|
|
|
(fun record ->
|
|
|
|
" "^(if record.M.rf_mutable then "mutable " else "")^
|
2004-03-05 06:57:52 -08:00
|
|
|
record.M.rf_name^" : "^(Odoc_print.string_of_type_expr record.M.rf_type)^";"^
|
2002-07-23 07:12:03 -07:00
|
|
|
(match record.M.rf_text with
|
|
|
|
None ->
|
|
|
|
""
|
|
|
|
| Some t ->
|
|
|
|
"(* "^(Odoc_misc.string_of_text t)^" *)"
|
|
|
|
)^"\n"
|
|
|
|
)
|
|
|
|
l
|
|
|
|
)
|
2002-03-27 08:20:32 -08:00
|
|
|
)^
|
|
|
|
"}\n"
|
|
|
|
)^
|
|
|
|
(match t.M.ty_info with
|
|
|
|
None -> ""
|
|
|
|
| Some info -> Odoc_misc.string_of_info info)
|
|
|
|
|
|
|
|
let string_of_exception e =
|
|
|
|
let module M = Odoc_exception in
|
|
|
|
"exception "^(Name.simple e.M.ex_name)^
|
|
|
|
(match e.M.ex_args with
|
|
|
|
[] -> ""
|
|
|
|
| _ ->" : "^
|
2005-03-24 09:20:54 -08:00
|
|
|
(String.concat " -> "
|
2004-03-05 06:57:52 -08:00
|
|
|
(List.map (fun t -> "("^(Odoc_print.string_of_type_expr t)^")") e.M.ex_args)
|
2002-03-27 08:20:32 -08:00
|
|
|
)
|
|
|
|
)^
|
|
|
|
(match e.M.ex_alias with
|
|
|
|
None -> ""
|
|
|
|
| Some ea ->
|
|
|
|
" = "^
|
|
|
|
(match ea.M.ea_ex with
|
2002-07-23 07:12:03 -07:00
|
|
|
None -> ea.M.ea_name
|
|
|
|
| Some e2 -> e2.M.ex_name
|
2002-03-27 08:20:32 -08:00
|
|
|
)
|
|
|
|
)^"\n"^
|
|
|
|
(match e.M.ex_info with
|
|
|
|
None -> ""
|
|
|
|
| Some i -> Odoc_misc.string_of_info i)
|
|
|
|
|
|
|
|
let string_of_value v =
|
|
|
|
let module M = Odoc_value in
|
|
|
|
"val "^(Name.simple v.M.val_name)^" : "^
|
2004-03-05 06:57:52 -08:00
|
|
|
(Odoc_print.string_of_type_expr v.M.val_type)^"\n"^
|
2002-03-27 08:20:32 -08:00
|
|
|
(match v.M.val_info with
|
|
|
|
None -> ""
|
|
|
|
| Some i -> Odoc_misc.string_of_info i)
|
|
|
|
|
|
|
|
let string_of_attribute a =
|
|
|
|
let module M = Odoc_value in
|
|
|
|
"val "^
|
|
|
|
(if a.M.att_mutable then Odoc_messages.mutab^" " else "")^
|
|
|
|
(Name.simple a.M.att_value.M.val_name)^" : "^
|
2004-03-05 06:57:52 -08:00
|
|
|
(Odoc_print.string_of_type_expr a.M.att_value.M.val_type)^"\n"^
|
2002-03-27 08:20:32 -08:00
|
|
|
(match a.M.att_value.M.val_info with
|
|
|
|
None -> ""
|
|
|
|
| Some i -> Odoc_misc.string_of_info i)
|
|
|
|
|
|
|
|
let string_of_method m =
|
|
|
|
let module M = Odoc_value in
|
|
|
|
"method "^
|
|
|
|
(if m.M.met_private then Odoc_messages.privat^" " else "")^
|
|
|
|
(Name.simple m.M.met_value.M.val_name)^" : "^
|
2004-03-05 06:57:52 -08:00
|
|
|
(Odoc_print.string_of_type_expr m.M.met_value.M.val_type)^"\n"^
|
2002-03-27 08:20:32 -08:00
|
|
|
(match m.M.met_value.M.val_info with
|
|
|
|
None -> ""
|
|
|
|
| Some i -> Odoc_misc.string_of_info i)
|
2003-11-24 02:44:07 -08:00
|
|
|
|
|
|
|
(* eof $Id$ *)
|