diff options
-rw-r--r-- | ocamldoc/Changes.txt | 2 | ||||
-rw-r--r-- | ocamldoc/odoc_latex.ml | 770 | ||||
-rw-r--r-- | ocamldoc/odoc_messages.ml | 6 | ||||
-rw-r--r-- | ocamldoc/odoc_sig.ml | 6 |
4 files changed, 438 insertions, 346 deletions
diff --git a/ocamldoc/Changes.txt b/ocamldoc/Changes.txt index a87dbedb1..30da4b7ce 100644 --- a/ocamldoc/Changes.txt +++ b/ocamldoc/Changes.txt @@ -1,4 +1,5 @@ Current : +OK - mod: odoc_latex: use buffers instead of string concatenation OK - add: new ocamldoc man page, thanks to Samuel Mimram OK - fix: useless parenthesis around agruments of arguments of a type constructor in type definitions, and aournd arguments of exceptions in exception definitions. @@ -42,7 +43,6 @@ OK - fix: bad display of type parameters for class and class types TODO: - need to fix display of type parameters for inherited classes/class types - - odoc_latex: use buffers instead of string concatenation diff --git a/ocamldoc/odoc_latex.ml b/ocamldoc/odoc_latex.ml index 0744f19cb..793c4d263 100644 --- a/ocamldoc/odoc_latex.ml +++ b/ocamldoc/odoc_latex.ml @@ -23,6 +23,31 @@ open Exception open Class open Module +let new_buf () = Buffer.create 1024 +let new_fmt () = + let b = new_buf () in + let fmt = Format.formatter_of_buffer b in + (fmt, + fun () -> + Format.pp_print_flush fmt (); + let s = Buffer.contents b in + Buffer.reset b; + s + ) + +let bp = Printf.bprintf +let bs = Buffer.add_string + +let print_concat b sep f = + let rec iter = function + [] -> () + | [c] -> f c + | c :: q -> + f c; + bs b sep; + iter q + in + iter (** Generation of LaTeX code from text structures. *) class text = @@ -186,108 +211,137 @@ class text = method make_ref label = "\\ref{"^label^"}" (** Return the LaTeX code corresponding to the [text] parameter.*) - method latex_of_text t = String.concat "" (List.map self#latex_of_text_element t) + method latex_of_text b t = + List.iter (self#latex_of_text_element b) t (** Return the LaTeX code for the [text_element] in parameter. *) - method latex_of_text_element te = + method latex_of_text_element b te = match te with - | Odoc_info.Raw s -> self#latex_of_Raw s - | Odoc_info.Code s -> self#latex_of_Code s - | Odoc_info.CodePre s -> self#latex_of_CodePre s - | Odoc_info.Verbatim s -> self#latex_of_Verbatim s - | Odoc_info.Bold t -> self#latex_of_Bold t - | Odoc_info.Italic t -> self#latex_of_Italic t - | Odoc_info.Emphasize t -> self#latex_of_Emphasize t - | Odoc_info.Center t -> self#latex_of_Center t - | Odoc_info.Left t -> self#latex_of_Left t - | Odoc_info.Right t -> self#latex_of_Right t - | Odoc_info.List tl -> self#latex_of_List tl - | Odoc_info.Enum tl -> self#latex_of_Enum tl - | Odoc_info.Newline -> self#latex_of_Newline - | Odoc_info.Block t -> self#latex_of_Block t - | Odoc_info.Title (n, l_opt, t) -> self#latex_of_Title n l_opt t - | Odoc_info.Latex s -> self#latex_of_Latex s - | Odoc_info.Link (s, t) -> self#latex_of_Link s t - | Odoc_info.Ref (name, ref_opt) -> self#latex_of_Ref name ref_opt - | Odoc_info.Superscript t -> self#latex_of_Superscript t - | Odoc_info.Subscript t -> self#latex_of_Subscript t + | Odoc_info.Raw s -> self#latex_of_Raw b s + | Odoc_info.Code s -> self#latex_of_Code b s + | Odoc_info.CodePre s -> self#latex_of_CodePre b s + | Odoc_info.Verbatim s -> self#latex_of_Verbatim b s + | Odoc_info.Bold t -> self#latex_of_Bold b t + | Odoc_info.Italic t -> self#latex_of_Italic b t + | Odoc_info.Emphasize t -> self#latex_of_Emphasize b t + | Odoc_info.Center t -> self#latex_of_Center b t + | Odoc_info.Left t -> self#latex_of_Left b t + | Odoc_info.Right t -> self#latex_of_Right b t + | Odoc_info.List tl -> self#latex_of_List b tl + | Odoc_info.Enum tl -> self#latex_of_Enum b tl + | Odoc_info.Newline -> self#latex_of_Newline b + | Odoc_info.Block t -> self#latex_of_Block b t + | Odoc_info.Title (n, l_opt, t) -> self#latex_of_Title b n l_opt t + | Odoc_info.Latex s -> self#latex_of_Latex b s + | Odoc_info.Link (s, t) -> self#latex_of_Link b s t + | Odoc_info.Ref (name, ref_opt) -> self#latex_of_Ref b name ref_opt + | Odoc_info.Superscript t -> self#latex_of_Superscript b t + | Odoc_info.Subscript t -> self#latex_of_Subscript b t - method latex_of_Raw s = self#escape s + method latex_of_Raw b s = + bs b (self#escape s) - method latex_of_Code s = + method latex_of_Code b s = let s2 = self#escape_code s in let s3 = Str.global_replace (Str.regexp "\n") ("\\\\\n") s2 in - "{\\tt{"^s3^"}}" - - method latex_of_CodePre s = - "\\begin{ocamldoccode}\n"^(self#escape_simple s)^"\n\\end{ocamldoccode}\n" - - method latex_of_Verbatim s = "\\begin{verbatim}"^s^"\\end{verbatim}" - - method latex_of_Bold t = - let s = self#latex_of_text t in - "{\\bf "^s^"}" - - method latex_of_Italic t = - let s = self#latex_of_text t in - "{\\it "^s^"}" - - method latex_of_Emphasize t = - let s = self#latex_of_text t in - "{\\em "^s^"}" - - method latex_of_Center t = - let s = self#latex_of_text t in - "\\begin{center}\n"^s^"\\end{center}\n" - - method latex_of_Left t = - let s = self#latex_of_text t in - "\\begin{flushleft}\n"^s^"\\end{flushleft}\n" - - method latex_of_Right t = - let s = self#latex_of_text t in - "\\begin{flushright}\n"^s^"\\end{flushright}\n" - - method latex_of_List tl = - "\\begin{itemize}"^ - (String.concat "" - (List.map (fun t -> "\\item "^(self#latex_of_text t)^"\n") tl))^ - "\\end{itemize}\n" - - method latex_of_Enum tl = - "\\begin{enumerate}"^ - (String.concat "" - (List.map (fun t -> "\\item "^(self#latex_of_text t)^"\n") tl))^ - "\\end{enumerate}\n" - - method latex_of_Newline = "\n\n" - - method latex_of_Block t = - let s = self#latex_of_text t in - "\\begin{ocamldocdescription}\n"^s^"\n\\end{ocamldocdescription}\n" - - method latex_of_Title n label_opt t = - let s_title = self#latex_of_text t in - let s_title2 = self#section_style n s_title in - s_title2^ - (match label_opt with - None -> "" - | Some l -> self#make_label (self#label ~no_: false l)) + bs b ("{\\tt{"^s3^"}}") + + method latex_of_CodePre b s = + bs b "\\begin{ocamldoccode}\n"; + bs b (self#escape_simple s); + bs b "\n\\end{ocamldoccode}\n" + + method latex_of_Verbatim b s = + bs b "\\begin{verbatim}"; + bs b s; + bs b "\\end{verbatim}" + + method latex_of_Bold b t = + bs b "{\\bf "; + self#latex_of_text b t; + bs b "}" + + method latex_of_Italic b t = + bs b "{\\it "; + self#latex_of_text b t; + bs b "}" + + method latex_of_Emphasize b t = + bs b "{\\em "; + self#latex_of_text b t; + bs b "}" + + method latex_of_Center b t = + bs b "\\begin{center}\n"; + self#latex_of_text b t; + bs b "\\end{center}\n" + + method latex_of_Left b t = + bs b "\\begin{flushleft}\n"; + self#latex_of_text b t; + bs b "\\end{flushleft}\n" + + method latex_of_Right b t = + bs b "\\begin{flushright}\n"; + self#latex_of_text b t; + bs b "\\end{flushright}\n" + + method latex_of_List b tl = + bs b "\\begin{itemize}\n"; + List.iter + (fun t -> + bs b "\\item "; + self#latex_of_text b t; + bs b "\n" + ) + tl; + bs b "\\end{itemize}\n" + + method latex_of_Enum b tl = + bs b "\\begin{enumerate}\n"; + List.iter + (fun t -> + bs b "\\item "; + self#latex_of_text b t; + bs b "\n" + ) + tl; + bs b "\\end{enumerate}\n" + + method latex_of_Newline b = bs b "\n\n" + + method latex_of_Block b t = + bs b "\\begin{ocamldocdescription}\n"; + self#latex_of_text b t; + bs b "\n\\end{ocamldocdescription}\n" + + method latex_of_Title b n label_opt t = + let b2 = new_buf () in + self#latex_of_text b2 t; + let s_title2 = self#section_style n (Buffer.contents b2) in + bs b s_title2; + ( + match label_opt with + None -> () + | Some l -> + bs b (self#make_label (self#label ~no_: false l)) + ) - method latex_of_Latex s = s + method latex_of_Latex b s = bs b s - method latex_of_Link s t = - let s1 = self#latex_of_text t in - let s2 = "[\\url{"^s^"}]" in - s1^s2 + method latex_of_Link b s t = + self#latex_of_text b t ; + bs b "[\\url{"; + bs b s ; + bs b "}]" - method latex_of_Ref name ref_opt = + method latex_of_Ref b name ref_opt = match ref_opt with None -> - self#latex_of_text_element + self#latex_of_text_element b (Odoc_info.Code (Odoc_info.use_hidden_modules name)) | Some (RK_section _) -> - self#latex_of_text_element + self#latex_of_text_element b (Latex ("["^(self#make_ref (self#label ~no_:false (Name.simple name)))^"]")) | Some kind -> let f_label = @@ -303,16 +357,21 @@ class text = | Odoc_info.RK_method -> self#method_label | Odoc_info.RK_section _ -> assert false in - (self#latex_of_text - [ - Odoc_info.Code (Odoc_info.use_hidden_modules name) ; - Latex ("["^(self#make_ref (f_label name))^"]") - ] - ) - - method latex_of_Superscript t = "$^{"^(self#latex_of_text t)^"}$" - - method latex_of_Subscript t = "$_{"^(self#latex_of_text t)^"}$" + self#latex_of_text b + [ + Odoc_info.Code (Odoc_info.use_hidden_modules name) ; + Latex ("["^(self#make_ref (f_label name))^"]") + ] + + method latex_of_Superscript b t = + bs b "$^{"; + self#latex_of_text b t; + bs b "}$" + + method latex_of_Subscript b t = + bs b "$_{"; + self#latex_of_text b t; + bs b "}$" end @@ -320,14 +379,14 @@ class text = class virtual info = object (self) (** The method used to get LaTeX code from a [text]. *) - method virtual latex_of_text : Odoc_info.text -> string + method virtual latex_of_text : Buffer.t -> Odoc_info.text -> unit (** The method used to get a [text] from an optionel info structure. *) method virtual text_of_info : ?block: bool -> Odoc_info.info option -> Odoc_info.text (** Return LaTeX code for a description, except for the [i_params] field. *) - method latex_of_info info_opt = - self#latex_of_text + method latex_of_info b info_opt = + self#latex_of_text b (self#text_of_info ~block: false info_opt) end @@ -357,77 +416,73 @@ class latex = (Odoc_info.text_no_title_no_list first, rest) (** Return LaTeX code for a value. *) - method latex_of_value v = + method latex_of_value b v = Odoc_info.reset_type_names () ; - self#latex_of_text + self#latex_of_text b ((Latex (self#make_label (self#value_label v.val_name))) :: (to_text#text_of_value v)) (** Return LaTeX code for a class attribute. *) - method latex_of_attribute a = - self#latex_of_text + method latex_of_attribute b a = + self#latex_of_text b ((Latex (self#make_label (self#attribute_label a.att_value.val_name))) :: (to_text#text_of_attribute a)) (** Return LaTeX code for a class method. *) - method latex_of_method m = - self#latex_of_text + method latex_of_method b m = + self#latex_of_text b ((Latex (self#make_label (self#method_label m.met_value.val_name))) :: (to_text#text_of_method m)) (** Return LaTeX code for the parameters of a type. *) - method latex_of_type_params m_name t = - let f (p, co, cn) = - Printf.sprintf "%s%s" - (Odoc_info.string_of_variance t (co,cn)) - (self#normal_type m_name p) + method latex_of_type_params b m_name t = + let print_one (p, co, cn) = + bs b (Odoc_info.string_of_variance t (co,cn)); + bs b (self#normal_type m_name p) in match t.ty_parameters with - [] -> "" - | [(p,co,cn)] -> f (p, co, cn) + [] -> () + | [(p,co,cn)] -> print_one (p, co, cn) | l -> - Printf.sprintf "(%s)" - (String.concat ", " (List.map f t.ty_parameters)) + bs b "("; + print_concat b ", " print_one t.ty_parameters; + bs b ")" - (** Return LaTeX code for a type. *) - method latex_of_type t = + (** TODO: regarder si les format servent ici. + Return LaTeX code for a type. *) + method latex_of_type b t = let s_name = Name.simple t.ty_name in + let btmp = new_buf () in let text = + let (fmt, flush) = new_fmt () in Odoc_info.reset_type_names () ; let mod_name = Name.father t.ty_name in - let s_type1 = - Format.fprintf Format.str_formatter "@[<hov 2>type "; - Format.fprintf Format.str_formatter "%s%s" - (self#latex_of_type_params mod_name t) - (match t.ty_parameters with [] -> "" | _ -> " "); - Format.flush_str_formatter () - in - Format.fprintf Format.str_formatter - ("@[<hov 2>%s %s") - s_type1 - s_name; - let s_type2 = - ( - match t.ty_manifest with - None -> () - | Some typ -> - Format.fprintf Format.str_formatter - " = %s" - (self#normal_type mod_name typ) - ); - Format.flush_str_formatter () - in + Format.fprintf fmt "@[<hov 2>type "; + let s_param_types = + self#latex_of_type_params btmp mod_name t; + (match t.ty_parameters with [] -> () | _ -> bs btmp " "); + let s = Buffer.contents btmp in + Buffer.reset btmp; + s + in + Format.fprintf fmt "%s %s" s_param_types s_name; + ( + match t.ty_manifest with + None -> () + | Some typ -> + Format.fprintf fmt " = %s" + (self#normal_type mod_name typ) + ); let s_type3 = - Format.fprintf Format.str_formatter - ("%s %s") - s_type2 + Format.fprintf fmt + " %s" ( match t.ty_kind with Type_abstract -> "" | Type_variant (_, priv) -> "="^(if priv then " private" else "") | Type_record (_, priv) -> "= "^(if priv then "private " else "")^"{" ) ; - Format.flush_str_formatter () + flush () in let defs = @@ -438,28 +493,32 @@ class latex = (List.map (fun constr -> let s_cons = - Format.fprintf Format.str_formatter + Format.fprintf fmt "@[<hov 6> | %s" constr.vc_name; ( match constr.vc_args with [] -> () | l -> - Format.fprintf Format.str_formatter " %s@ %s" + Format.fprintf fmt " %s@ %s" "of" (self#normal_type_list ~par: false mod_name " * " l) ); - Format.flush_str_formatter () + flush () in [ CodePre s_cons ] @ (match constr.vc_text with None -> [] | Some t -> - [ Latex - ("\\begin{ocamldoccomment}\n"^ - (self#latex_of_text t)^ - "\n\\end{ocamldoccomment}\n") - ] + let s = + bs btmp "\\begin{ocamldoccomment}\n"; + self#latex_of_text btmp t; + bs btmp "\n\\end{ocamldoccomment}\n"; + let s = Buffer.contents btmp in + Buffer.reset btmp; + s + in + [ Latex s] ) ) l @@ -470,22 +529,26 @@ class latex = (List.map (fun r -> let s_field = - Format.fprintf Format.str_formatter + Format.fprintf fmt "@[<hov 6> %s%s :@ %s ;" (if r.rf_mutable then "mutable " else "") r.rf_name (self#normal_type mod_name r.rf_type); - Format.flush_str_formatter () + flush () in [ CodePre s_field ] @ (match r.rf_text with None -> [] | Some t -> - [ Latex - ("\\begin{ocamldoccomment}\n"^ - (self#latex_of_text t)^ - "\n\\end{ocamldoccomment}\n") - ] + let s = + bs btmp "\\begin{ocamldoccomment}\n"; + self#latex_of_text btmp t; + bs btmp "\n\\end{ocamldoccomment}\n"; + let s = Buffer.contents btmp in + Buffer.reset btmp; + s + in + [ Latex s] ) ) l @@ -506,189 +569,182 @@ class latex = [Latex ("\\index{"^(self#type_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")] @ (self#text_of_info t.ty_info) in - self#latex_of_text + self#latex_of_text b ((Latex (self#make_label (self#type_label t.ty_name))) :: text) (** Return LaTeX code for an exception. *) - method latex_of_exception e = + method latex_of_exception b e = Odoc_info.reset_type_names () ; - self#latex_of_text + self#latex_of_text b ((Latex (self#make_label (self#exception_label e.ex_name))) :: (to_text#text_of_exception e)) (** Return the LaTeX code for the given module. @param for_detail indicate if we must print the type ([false]) or just ["sig"] ([true]).*) - method latex_of_module ?(for_detail=false) ?(with_link=true) m = - let buf = Buffer.create 32 in - let f = Format.formatter_of_buffer buf in + method latex_of_module b ?(for_detail=false) ?(with_link=true) m = let father = Name.father m.m_name in + let b2 = new_buf () in let t = - Format.fprintf f "module %s" (Name.simple m.m_name); - Format.fprintf f " : %s" - ( + bs b2 "module "; + bs b2 (Name.simple m.m_name); + bs b2 " : "; + bs b2 + ( if for_detail then "sig" else (self#normal_module_type father m.m_type) ); - Format.pp_print_flush f (); - - (CodePre (Buffer.contents buf)) :: + (CodePre (Buffer.contents b2)) :: ( if with_link then [Odoc_info.Latex ("\\\n["^(self#make_ref (self#module_label m.m_name))^"]")] else [] ) in - self#latex_of_text t + self#latex_of_text b t (** Return the LaTeX code for the given module type. @param for_detail indicate if we must print the type ([false]) or just ["sig"] ([true]).*) - method latex_of_module_type ?(for_detail=false) ?(with_link=true) mt = - let buf = Buffer.create 32 in - let f = Format.formatter_of_buffer buf in + method latex_of_module_type b ?(for_detail=false) ?(with_link=true) mt = + let b2 = new_buf () in let father = Name.father mt.mt_name in let t = - Format.fprintf f "module type %s" (Name.simple mt.mt_name); + bs b2 "module type "; + bs b2 (Name.simple mt.mt_name); (match mt.mt_type with None -> () | Some mtyp -> - Format.fprintf f " = %s" - ( + bs b2 " = "; + bs b2 + ( if for_detail then "sig" else (self#normal_module_type father mtyp) ) ); - Format.pp_print_flush f (); - - (CodePre (Buffer.contents buf)) :: + (CodePre (Buffer.contents b2)) :: ( if with_link then [Odoc_info.Latex ("\\\n["^(self#make_ref (self#module_type_label mt.mt_name))^"]")] else [] ) in - self#latex_of_text t + self#latex_of_text b t (** Return the LaTeX code for the given included module. *) - method latex_of_included_module im = - (self#latex_of_text ((Code "include ") :: - (Code - (match im.im_module with - None -> im.im_name - | Some (Mod m) -> m.m_name - | Some (Modtype mt) -> mt.mt_name) - ) :: - (self#text_of_info im.im_info) - ) - ) + method latex_of_included_module b im = + self#latex_of_text b + ((Code "include ") :: + (Code + (match im.im_module with + None -> im.im_name + | Some (Mod m) -> m.m_name + | Some (Modtype mt) -> mt.mt_name) + ) :: + (self#text_of_info im.im_info) + ) (** Return the LaTeX code for the given class. @param for_detail indicate if we must print the type ([false]) or just ["object"] ([true]).*) - method latex_of_class ?(for_detail=false) ?(with_link=true) c = + method latex_of_class b ?(for_detail=false) ?(with_link=true) c = Odoc_info.reset_type_names () ; - let buf = Buffer.create 32 in - let f = Format.formatter_of_buffer buf in + let b2 = new_buf () in let father = Name.father c.cl_name in let t = - Format.fprintf f "class %s" - (if c.cl_virtual then "virtual " else ""); + bs b2 "class "; + if c.cl_virtual then bs b2 "virtual " ; ( match c.cl_type_parameters with [] -> () | l -> let s1 = self#normal_class_type_param_list father l in - Format.fprintf f "%s " s1 + bs b2 s1; + bs b2 " " ); - Format.fprintf f "%s : %s" - (Name.simple c.cl_name) - ( + bs b2 (Name.simple c.cl_name); + bs b2 " : " ; + bs b2 + ( if for_detail then "object" else self#normal_class_type father c.cl_type ); - Format.pp_print_flush f (); - - (CodePre (Buffer.contents buf)) :: + (CodePre (Buffer.contents b2)) :: ( if with_link then [Odoc_info.Latex (" ["^(self#make_ref (self#class_label c.cl_name))^"]")] else [] ) in - self#latex_of_text t + self#latex_of_text b t (** Return the LaTeX code for the given class type. @param for_detail indicate if we must print the type ([false]) or just ["object"] ([true]).*) - method latex_of_class_type ?(for_detail=false) ?(with_link=true) ct = + method latex_of_class_type b ?(for_detail=false) ?(with_link=true) ct = Odoc_info.reset_type_names () ; - let buf = Buffer.create 32 in - let f = Format.formatter_of_buffer buf in + let b2 = new_buf () in let father = Name.father ct.clt_name in let t = - Format.fprintf f "class type %s" - (if ct.clt_virtual then "virtual " else ""); + bs b2 "class type "; + if ct.clt_virtual then bs b2 "virtual " ; ( match ct.clt_type_parameters with - [] -> () + [] -> () | l -> let s1 = self#normal_class_type_param_list father l in - Format.fprintf f "%s " s1 + bs b2 s1; + bs b2 " " ); - Format.fprintf f "%s = %s" - (Name.simple ct.clt_name) + bs b2 (Name.simple ct.clt_name); + bs b2 " = " ; + bs b2 (if for_detail then "object" else self#normal_class_type father ct.clt_type ); - Format.pp_print_flush f (); - (CodePre (Buffer.contents buf)) :: + (CodePre (Buffer.contents b2)) :: ( if with_link then [Odoc_info.Latex (" ["^(self#make_ref (self#class_type_label ct.clt_name))^"]")] else [] ) in - self#latex_of_text t + self#latex_of_text b t (** Return the LaTeX code for the given class element. *) - method latex_of_class_element class_name class_ele = - (self#latex_of_text [Newline])^ - ( - match class_ele with - Class_attribute att -> self#latex_of_attribute att - | Class_method met -> self#latex_of_method met - | Class_comment t -> - match t with - | [] -> "" - | (Title (_,_,_)) :: _ -> self#latex_of_text t - | _ -> self#latex_of_text [ Title ((Name.depth class_name) + 2, None, t) ] - ) + method latex_of_class_element b class_name class_ele = + self#latex_of_text b [Newline]; + match class_ele with + Class_attribute att -> self#latex_of_attribute b att + | Class_method met -> self#latex_of_method b met + | Class_comment t -> + match t with + | [] -> () + | (Title (_,_,_)) :: _ -> self#latex_of_text b t + | _ -> self#latex_of_text b [ Title ((Name.depth class_name) + 2, None, t) ] (** Return the LaTeX code for the given module element. *) - method latex_of_module_element module_name module_ele = - (self#latex_of_text [Newline])^ - ( - match module_ele with - Element_module m -> self#latex_of_module m - | Element_module_type mt -> self#latex_of_module_type mt - | Element_included_module im -> self#latex_of_included_module im - | Element_class c -> self#latex_of_class c - | Element_class_type ct -> self#latex_of_class_type ct - | Element_value v -> self#latex_of_value v - | Element_exception e -> self#latex_of_exception e - | Element_type t -> self#latex_of_type t - | Element_module_comment t -> self#latex_of_text t - ) + method latex_of_module_element b module_name module_ele = + self#latex_of_text b [Newline]; + match module_ele with + Element_module m -> self#latex_of_module b m + | Element_module_type mt -> self#latex_of_module_type b mt + | Element_included_module im -> self#latex_of_included_module b im + | Element_class c -> self#latex_of_class b c + | Element_class_type ct -> self#latex_of_class_type b ct + | Element_value v -> self#latex_of_value b v + | Element_exception e -> self#latex_of_exception b e + | Element_type t -> self#latex_of_type b t + | Element_module_comment t -> self#latex_of_text b t (** Generate the LaTeX code for the given list of inherited classes.*) - method generate_inheritance_info chanout inher_l = + method generate_inheritance_info b inher_l = let f inh = match inh.ic_class with None -> (* we can't make the reference *) @@ -716,17 +772,16 @@ class latex = Odoc_info.List (List.map f inher_l) ] in - let s = self#latex_of_text text in - output_string chanout s + self#latex_of_text b text (** Generate the LaTeX code for the inherited classes of the given class. *) - method generate_class_inheritance_info chanout cl = + method generate_class_inheritance_info b cl = let rec iter_kind k = match k with Class_structure ([], _) -> () | Class_structure (l, _) -> - self#generate_inheritance_info chanout l + self#generate_inheritance_info b l | Class_constraint (k, _) -> iter_kind k | Class_apply _ @@ -736,17 +791,17 @@ class latex = iter_kind cl.cl_kind (** Generate the LaTeX code for the inherited classes of the given class type. *) - method generate_class_type_inheritance_info chanout clt = + method generate_class_type_inheritance_info b clt = match clt.clt_kind with Class_signature ([], _) -> () | Class_signature (l, _) -> - self#generate_inheritance_info chanout l + self#generate_inheritance_info b l | Class_type _ -> () - (** Generate the LaTeX code for the given class, in the given out channel. *) - method generate_for_class chanout c = + (** Generate the LaTeX code for the given class, in the given buffer. *) + method generate_for_class b c = Odoc_info.reset_type_names () ; let depth = Name.depth c.cl_name in let (first_t, rest_t) = self#first_and_rest_of_info c.cl_info in @@ -757,28 +812,32 @@ class latex = Latex (self#make_label (self#class_label c.cl_name)) ; ] in - output_string chanout (self#latex_of_text text); - output_string chanout ((self#latex_of_class ~for_detail: true ~with_link: false c)^"\n\n") ; + self#latex_of_text b text; + self#latex_of_class b ~for_detail: true ~with_link: false c; + bs b "\n\n" ; let s_name = Name.simple c.cl_name in - output_string chanout - (self#latex_of_text [Latex ("\\index{"^(self#class_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")]); - output_string chanout (self#latex_of_text rest_t) ; + self#latex_of_text b + [Latex ("\\index{"^(self#class_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")]; + self#latex_of_text b rest_t; + (* parameters *) - output_string chanout - (self#latex_of_text (self#text_of_parameter_list (Name.father c.cl_name) c.cl_parameters)); + self#latex_of_text b (self#text_of_parameter_list (Name.father c.cl_name) c.cl_parameters); - output_string chanout (self#latex_of_text [ Newline ] ); - output_string chanout ("\\ocamldocvspace{0.5cm}\n\n"); - self#generate_class_inheritance_info chanout c; + self#latex_of_text b [ Newline ]; + bs b "\\ocamldocvspace{0.5cm}\n\n"; + self#generate_class_inheritance_info b c; List.iter - (fun ele -> output_string chanout ((self#latex_of_class_element c.cl_name ele)^"\n\n")) + (fun ele -> + self#latex_of_class_element b c.cl_name ele; + bs b "\n\n" + ) (Class.class_elements ~trans: false c); - output_string chanout (self#latex_of_text [ CodePre "end"]) + self#latex_of_text b [ CodePre "end"] - (** Generate the LaTeX code for the given class type, in the given out channel. *) - method generate_for_class_type chanout ct = + (** Generate the LaTeX code for the given class type, in the given buffer. *) + method generate_for_class_type b ct = Odoc_info.reset_type_names () ; let depth = Name.depth ct.clt_name in let (first_t, rest_t) = self#first_and_rest_of_info ct.clt_info in @@ -790,24 +849,31 @@ class latex = ] in - output_string chanout (self#latex_of_text text); - output_string chanout ((self#latex_of_class_type ~for_detail: true ~with_link: false ct)^"\n\n") ; + self#latex_of_text b text; + self#latex_of_class_type b ~for_detail: true ~with_link: false ct; + bs b "\n\n" ; let s_name = Name.simple ct.clt_name in - output_string chanout - (self#latex_of_text [Latex ("\\index{"^(self#class_type_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")]); - output_string chanout ((self#latex_of_text rest_t)) ; - output_string chanout (self#latex_of_text [ Newline]) ; - output_string chanout ("\\ocamldocvspace{0.5cm}\n\n"); - self#generate_class_type_inheritance_info chanout ct; + self#latex_of_text b + [Latex ("\\index{"^(self#class_type_label s_name)^"@\\verb`"^ + (self#label ~no_:false s_name)^"`}\n" + ) + ]; + self#latex_of_text b rest_t; + self#latex_of_text b [Newline]; + bs b "\\ocamldocvspace{0.5cm}\n\n"; + self#generate_class_type_inheritance_info b ct; List.iter - (fun ele -> output_string chanout ((self#latex_of_class_element ct.clt_name ele)^"\n\n")) + (fun ele -> + self#latex_of_class_element b ct.clt_name ele; + bs b "\n\n" + ) (Class.class_type_elements ~trans: false ct); - output_string chanout (self#latex_of_text [ CodePre "end"]) + self#latex_of_text b [ CodePre "end"] - (** Generate the LaTeX code for the given module type, in the given out channel. *) - method generate_for_module_type chanout mt = + (** Generate the LaTeX code for the given module type, in the given buffer. *) + method generate_for_module_type b mt = let depth = Name.depth mt.mt_name in let (first_t, rest_t) = self#first_and_rest_of_info mt.mt_info in let text = [ Title (depth, None, @@ -818,41 +884,49 @@ class latex = Latex (self#make_label (self#module_type_label mt.mt_name)) ; ] in - output_string chanout (self#latex_of_text text); + self#latex_of_text b text; if depth > 1 then - output_string chanout ((self#latex_of_module_type ~for_detail: true ~with_link: false mt)^"\n\n"); + ( + self#latex_of_module_type b ~for_detail: true ~with_link: false mt; + bs b "\n\n" + ); let s_name = Name.simple mt.mt_name in - output_string chanout - (self#latex_of_text [Latex ("\\index{"^(self#module_type_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")]); - output_string chanout (self#latex_of_text rest_t) ; + self#latex_of_text b + [Latex ("\\index{"^(self#module_type_label s_name)^"@\\verb`"^ + (self#label ~no_:false s_name)^"`}\n" + ) + ]; + self#latex_of_text b rest_t ; (* parameters *) - output_string chanout - (self#latex_of_text - (self#text_of_module_parameter_list - (Module.module_type_parameters mt))); + self#latex_of_text b + (self#text_of_module_parameter_list + (Module.module_type_parameters mt)); - output_string chanout (self#latex_of_text [ Newline ] ); - output_string chanout ("\\ocamldocvspace{0.5cm}\n\n"); + self#latex_of_text b [ Newline ]; + bs b "\\ocamldocvspace{0.5cm}\n\n"; List.iter - (fun ele -> output_string chanout ((self#latex_of_module_element mt.mt_name ele)^"\n\n")) + (fun ele -> + self#latex_of_module_element b mt.mt_name ele; + bs b "\n\n" + ) (Module.module_type_elements ~trans: false mt); if depth > 1 then - output_string chanout (self#latex_of_text [ CodePre "end"]); + self#latex_of_text b [ CodePre "end"]; (* create sub parts for modules, module types, classes and class types *) let rec iter ele = match ele with - Element_module m -> self#generate_for_module chanout m - | Element_module_type mt -> self#generate_for_module_type chanout mt - | Element_class c -> self#generate_for_class chanout c - | Element_class_type ct -> self#generate_for_class_type chanout ct + Element_module m -> self#generate_for_module b m + | Element_module_type mt -> self#generate_for_module_type b mt + | Element_class c -> self#generate_for_class b c + | Element_class_type ct -> self#generate_for_class_type b ct | _ -> () in List.iter iter (Module.module_type_elements ~trans: false mt) - (** Generate the LaTeX code for the given module, in the given out channel. *) - method generate_for_module chanout m = + (** Generate the LaTeX code for the given module, in the given buffer. *) + method generate_for_module b m = let depth = Name.depth m.m_name in let (first_t, rest_t) = self#first_and_rest_of_info m.m_info in let text = [ Title (depth, None, @@ -863,63 +937,76 @@ class latex = Latex (self#make_label (self#module_label m.m_name)) ; ] in - output_string chanout (self#latex_of_text text); + self#latex_of_text b text; if depth > 1 then - output_string chanout ((self#latex_of_module ~for_detail:true ~with_link: false m)^"\n\n"); + ( + self#latex_of_module b ~for_detail:true ~with_link: false m; + bs b "\n\n" + ); let s_name = Name.simple m.m_name in - output_string chanout - (self#latex_of_text [Latex ("\\index{"^(self#module_label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")]); - output_string chanout (self#latex_of_text rest_t) ; + self#latex_of_text b + [Latex ("\\index{"^(self#module_label s_name)^"@\\verb`"^ + (self#label ~no_:false s_name)^"`}\n" + ) + ]; + self#latex_of_text b rest_t ; (* parameters *) - output_string chanout - (self#latex_of_text - (self#text_of_module_parameter_list - (Module.module_parameters m))); + self#latex_of_text b + (self#text_of_module_parameter_list + (Module.module_parameters m)); - output_string chanout (self#latex_of_text [ Newline ]) ; - output_string chanout ("\\ocamldocvspace{0.5cm}\n\n"); + self#latex_of_text b [ Newline ] ; + bs b "\\ocamldocvspace{0.5cm}\n\n"; List.iter - (fun ele -> output_string chanout ((self#latex_of_module_element m.m_name ele)^"\n\n")) + (fun ele -> + self#latex_of_module_element b m.m_name ele; + bs b "\n\n" + ) (Module.module_elements ~trans: false m); if depth > 1 then - output_string chanout (self#latex_of_text [ CodePre "end"]); + self#latex_of_text b [ CodePre "end"]; (* create sub parts for modules, module types, classes and class types *) let rec iter ele = match ele with - Element_module m -> self#generate_for_module chanout m - | Element_module_type mt -> self#generate_for_module_type chanout mt - | Element_class c -> self#generate_for_class chanout c - | Element_class_type ct -> self#generate_for_class_type chanout ct + Element_module m -> self#generate_for_module b m + | Element_module_type mt -> self#generate_for_module_type b mt + | Element_class c -> self#generate_for_class b c + | Element_class_type ct -> self#generate_for_class_type b ct | _ -> () in List.iter iter (Module.module_elements ~trans: false m) (** Return the header of the TeX document. *) - method latex_header = - "\\documentclass[11pt]{article} \n"^ - "\\usepackage[latin1]{inputenc} \n"^ - "\\usepackage[T1]{fontenc} \n"^ - "\\usepackage{fullpage} \n"^ - "\\usepackage{url} \n"^ - "\\usepackage{ocamldoc}\n"^ + method latex_header b = + bs b "\\documentclass[11pt]{article} \n"; + bs b "\\usepackage[latin1]{inputenc} \n"; + bs b "\\usepackage[T1]{fontenc} \n"; + bs b "\\usepackage{fullpage} \n"; + bs b "\\usepackage{url} \n"; + bs b "\\usepackage{ocamldoc}\n"; ( match !Args.title with - None -> "" - | Some s -> "\\title{"^(self#escape s)^"}\n" - )^ - "\\begin{document}\n"^ - (match !Args.title with None -> "" | Some _ -> "\\maketitle\n")^ - (if !Args.with_toc then "\\tableofcontents\n" else "")^ + None -> () + | Some s -> + bs b "\\title{"; + bs b (self#escape s); + bs b "}\n" + ); + bs b "\\begin{document}\n"; + (match !Args.title with + None -> () | + Some _ -> bs b "\\maketitle\n" + ); + if !Args.with_toc then bs b "\\tableofcontents\n"; ( let info = Odoc_info.apply_opt Odoc_info.info_of_comment_file !Odoc_info.Args.intro_file in - Printf.sprintf "%s%s%s" - (match info with None -> "" | Some _ -> "\\vspace{0.2cm}") - (self#latex_of_info info) - (match info with None -> "" | Some _ -> "\n\n") + (match info with None -> () | Some _ -> bs b "\\vspace{0.2cm}"); + self#latex_of_info b info; + (match info with None -> () | Some _ -> bs b "\n\n") ) @@ -953,7 +1040,9 @@ class latex = let chanout = open_out ((Filename.concat !Args.target_dir (Name.simple m.m_name))^".tex") in - self#generate_for_module chanout m ; + let b = new_buf () in + self#generate_for_module b m ; + Buffer.output_buffer chanout b; close_out chanout with Failure s @@ -966,15 +1055,18 @@ class latex = try let chanout = open_out !Args.out_file in - let _ = if !Args.with_header then output_string chanout self#latex_header else () in + let b = new_buf () in + if !Args.with_header then self#latex_header b; List.iter - (fun m -> if !Args.separate_files then - output_string chanout ("\\input{"^((Name.simple m.m_name))^".tex}\n") - else - self#generate_for_module chanout m + (fun m -> + if !Args.separate_files then + bs b ("\\input{"^((Name.simple m.m_name))^".tex}\n") + else + self#generate_for_module b m ) module_list ; - let _ = if !Args.with_trailer then output_string chanout "\\end{document}" else () in + if !Args.with_trailer then bs b "\\end{document}"; + Buffer.output_buffer chanout b; close_out chanout with Failure s diff --git a/ocamldoc/odoc_messages.ml b/ocamldoc/odoc_messages.ml index 0143098e9..bac8df08f 100644 --- a/ocamldoc/odoc_messages.ml +++ b/ocamldoc/odoc_messages.ml @@ -15,9 +15,9 @@ let ok = "Ok" let software = "OCamldoc" -let version = Config.version -let magic = version^"" -let message_version = software^" "^version +let config_version = Config.version +let magic = config_version^"" +let message_version = software^" "^config_version (** Messages for command line *) diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml index cb025f22d..19f2dfdb3 100644 --- a/ocamldoc/odoc_sig.ml +++ b/ocamldoc/odoc_sig.ml @@ -285,7 +285,7 @@ module Analyser = let f_DEBUG var (mutable_flag, type_exp) = print_DEBUG var in Types.Vars.iter f_DEBUG class_signature.Types.cty_vars; print_DEBUG ("Type de la classe "^current_class_name^" : "); - print_DEBUG (Odoc_misc.string_of_type_expr class_signature.Types.cty_self); + print_DEBUG (Odoc_print.string_of_type_expr class_signature.Types.cty_self); let get_pos_limit2 q = match q with [] -> pos_limit @@ -1196,7 +1196,7 @@ module Analyser = let f_DEBUG var (mutable_flag, type_exp) = print_DEBUG var in Types.Vars.iter f_DEBUG class_signature.Types.cty_vars; print_DEBUG ("Type de la classe "^current_class_name^" : "); - print_DEBUG (Odoc_misc.string_of_type_expr class_signature.Types.cty_self); + print_DEBUG (Odoc_print.string_of_type_expr class_signature.Types.cty_self); (* we get the elements of the class in class_type_field_list *) let (inher_l, ele) = analyse_class_elements env current_class_name last_pos @@ -1250,7 +1250,7 @@ module Analyser = let f_DEBUG var (mutable_flag, type_exp) = print_DEBUG var in Types.Vars.iter f_DEBUG class_signature.Types.cty_vars; print_DEBUG ("Type de la classe "^current_class_name^" : "); - print_DEBUG (Odoc_misc.string_of_type_expr class_signature.Types.cty_self); + print_DEBUG (Odoc_print.string_of_type_expr class_signature.Types.cty_self); (* we get the elements of the class in class_type_field_list *) let (inher_l, ele) = analyse_class_elements env current_class_name last_pos |