@@ -411571,6 +411571,98 @@ let rewrite_implementation (ast : Parsetree.structure) : Parsetree.structure =
411571411571 result
411572411572 end
411573411573
411574+ end
411575+ module Ext_io : sig
411576+ #1 "ext_io.mli"
411577+ (* Copyright (C) 2015-2016 Bloomberg Finance L.P.
411578+ *
411579+ * This program is free software: you can redistribute it and/or modify
411580+ * it under the terms of the GNU Lesser General Public License as published by
411581+ * the Free Software Foundation, either version 3 of the License, or
411582+ * (at your option) any later version.
411583+ *
411584+ * In addition to the permissions granted to you by the LGPL, you may combine
411585+ * or link a "work that uses the Library" with a publicly distributed version
411586+ * of this file to produce a combined library or application, then distribute
411587+ * that combined work under the terms of your choosing, with no requirement
411588+ * to comply with the obligations normally placed on you by section 4 of the
411589+ * LGPL version 3 (or the corresponding section of a later version of the LGPL
411590+ * should you choose to use a later version).
411591+ *
411592+ * This program is distributed in the hope that it will be useful,
411593+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
411594+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
411595+ * GNU Lesser General Public License for more details.
411596+ *
411597+ * You should have received a copy of the GNU Lesser General Public License
411598+ * along with this program; if not, write to the Free Software
411599+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
411600+
411601+ val load_file : string -> string
411602+
411603+ val rev_lines_of_file : string -> string list
411604+
411605+ val rev_lines_of_chann : in_channel -> string list
411606+
411607+ val write_file : string -> string -> unit
411608+
411609+ end = struct
411610+ #1 "ext_io.ml"
411611+ (* Copyright (C) 2015-2016 Bloomberg Finance L.P.
411612+ *
411613+ * This program is free software: you can redistribute it and/or modify
411614+ * it under the terms of the GNU Lesser General Public License as published by
411615+ * the Free Software Foundation, either version 3 of the License, or
411616+ * (at your option) any later version.
411617+ *
411618+ * In addition to the permissions granted to you by the LGPL, you may combine
411619+ * or link a "work that uses the Library" with a publicly distributed version
411620+ * of this file to produce a combined library or application, then distribute
411621+ * that combined work under the terms of your choosing, with no requirement
411622+ * to comply with the obligations normally placed on you by section 4 of the
411623+ * LGPL version 3 (or the corresponding section of a later version of the LGPL
411624+ * should you choose to use a later version).
411625+ *
411626+ * This program is distributed in the hope that it will be useful,
411627+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
411628+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
411629+ * GNU Lesser General Public License for more details.
411630+ *
411631+ * You should have received a copy of the GNU Lesser General Public License
411632+ * along with this program; if not, write to the Free Software
411633+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
411634+
411635+
411636+ (** on 32 bit , there are 16M limitation *)
411637+ let load_file f =
411638+ Ext_pervasives.finally (open_in_bin f) ~clean:close_in begin fun ic ->
411639+ let n = in_channel_length ic in
411640+ let s = Bytes.create n in
411641+ really_input ic s 0 n;
411642+ Bytes.unsafe_to_string s
411643+ end
411644+
411645+
411646+ let rev_lines_of_chann chan =
411647+ let rec loop acc chan =
411648+ match input_line chan with
411649+ | line -> loop (line :: acc) chan
411650+ | exception End_of_file -> close_in chan ; acc in
411651+ loop [] chan
411652+
411653+
411654+ let rev_lines_of_file file =
411655+ Ext_pervasives.finally
411656+ ~clean:close_in
411657+ (open_in_bin file) rev_lines_of_chann
411658+
411659+
411660+ let write_file f content =
411661+ Ext_pervasives.finally ~clean:close_out
411662+ (open_out_bin f) begin fun oc ->
411663+ output_string oc content
411664+ end
411665+
411574411666end
411575411667module Super_misc : sig
411576411668#1 "super_misc.mli"
@@ -411780,54 +411872,24 @@ end
411780411872module Super_location
411781411873= struct
411782411874#1 "super_location.ml"
411783- (* open Misc
411784- open Asttypes
411785- open Parsetree
411786- open Types
411787- open Typedtree
411788- open Btype
411789- open Ctype *)
411790411875
411791- open Format
411792- (* open Printtyp *)
411793411876
411794- open Location
411877+ let fprintf = Format.fprintf
411795411878
411796- let file_lines filePath =
411797- (* open_in_bin works on windows, as opposed to open_in, afaik? *)
411798- let chan = open_in_bin filePath in
411799- let lines = ref [] in
411800- try
411801- while true do
411802- lines := (input_line chan) :: !lines
411803- done;
411804- (* leave this here to make things type. The loop will definitly raise *)
411805- [||]
411806- with
411807- | End_of_file -> begin
411808- close_in chan;
411809- List.rev (!lines) |> Array.of_list
411810- end
411879+
411880+
411881+ let file_lines filePath =
411882+ Ext_array.reverse_of_list
411883+ (Ext_io.rev_lines_of_file filePath)
411811411884
411812411885let setup_colors () =
411813411886 Misc.Color.setup !Clflags.color
411814411887
411815- let print_filename ppf file =
411816- match file with
411817- (* modified *)
411818- | "_none_"
411819- | "" -> Format.fprintf ppf "(No file name)"
411820- | real_file -> Format.fprintf ppf "%s" (Location.show_filename real_file)
411888+ let print_filename = Location.print_filename
411821411889
411822- let print_loc ~normalizedRange ppf loc =
411890+ let print_loc ~normalizedRange ppf ( loc : Location.t) =
411823411891 setup_colors ();
411824- let (file, _, _) = Location.get_pos_info loc.loc_start in
411825- if file = "//toplevel//" then begin
411826- if highlight_locations ppf [loc] then () else
411827- fprintf ppf "Characters %i-%i"
411828- loc.loc_start.pos_cnum loc.loc_end.pos_cnum
411829- end else
411830- let dim_loc ppf = function
411892+ let dim_loc ppf = function
411831411893 | None -> ()
411832411894 | Some ((start_line, start_line_start_char), (end_line, end_line_end_char)) ->
411833411895 if start_line = end_line then
@@ -411837,14 +411899,11 @@ let print_loc ~normalizedRange ppf loc =
411837411899 fprintf ppf " @{<dim>%i:%i-%i@}" start_line start_line_start_char end_line_end_char
411838411900 else
411839411901 fprintf ppf " @{<dim>%i:%i-%i:%i@}" start_line start_line_start_char end_line end_line_end_char
411840- in
411841- fprintf ppf "@{<filename>%a@}%a" print_filename file dim_loc normalizedRange
411902+ in
411903+ fprintf ppf "@{<filename>%a@}%a" print_filename loc.loc_start.pos_fname dim_loc normalizedRange
411842411904;;
411843411905
411844- let print ~message_kind intro ppf loc =
411845- if loc.loc_start.pos_fname = "//toplevel//"
411846- && highlight_locations ppf [loc] then ()
411847- else
411906+ let print ~message_kind intro ppf (loc : Location.t) =
411848411907 begin match message_kind with
411849411908 | `warning -> fprintf ppf "@[@{<info>%s@}@]@," intro
411850411909 | `warning_as_error -> fprintf ppf "@[@{<error>%s@} (configured as error) @]@," intro
@@ -411937,17 +411996,17 @@ let print_phanton_error_prefix ppf =
411937411996 (see super_error_reporter above) *)
411938411997 Format.pp_print_as ppf 2 ""
411939411998
411940- let errorf ?(loc = none) ?(sub = []) ?(if_highlight = "") fmt =
411999+ let errorf ?(loc = Location. none) ?(sub = []) ?(if_highlight = "") fmt =
411941412000 Location.pp_ksprintf
411942412001 ~before:print_phanton_error_prefix
411943- (fun msg -> {loc; msg; sub; if_highlight})
412002+ (fun msg -> Location. {loc; msg; sub; if_highlight})
411944412003 fmt
411945412004
411946412005let error_of_printer loc print x =
411947412006 errorf ~loc "%a@?" print x
411948412007
411949412008let error_of_printer_file print x =
411950- error_of_printer (in_file !input_name) print x
412009+ error_of_printer (Location. in_file !Location. input_name) print x
411951412010
411952412011(* This will be called in super_main. This is how you override the default error and warning printers *)
411953412012let setup () =
0 commit comments