package ocaml-base-compiler
-
bigarray
-
dynlink
-
ocamlbytecomp
-
ocamlcommon
-
ocamlmiddleend
-
ocamloptcomp
-
odoc_info
-
stdlib
-
str
-
unix
Library
Module
Module type
Parameter
Class
Class type
Source code locations (ranges of positions), used in parsetree.
Warning: this module is unstable and part of compiler-libs.
Note on the use of Lexing.position in this module. If pos_fname = ""
, then use !input_name
instead. If pos_lnum = -1
, then pos_bol = 0
. Use pos_cnum
and re-parse the file to get the line and character numbers. Else all fields are correct.
val none : t
An arbitrary value of type t
; describes an empty ghost range.
val is_none : t -> bool
True for Location.none
, false any other location
val in_file : string -> t
Return an empty ghost range located in a given file.
val init : Lexing.lexbuf -> string -> unit
Set the file name and line number of the lexbuf
to be the start of the named file.
val curr : Lexing.lexbuf -> t
Get the location of the current token from the lexbuf
.
val symbol_rloc : unit -> t
val symbol_gloc : unit -> t
val rhs_loc : int -> t
rhs_loc n
returns the location of the symbol at position n
, starting at 1, in the current parser rule.
val rhs_interval : int -> int -> t
val get_pos_info : Lexing.position -> string * int * int
file, line, char
val mknoloc : 'a -> 'a loc
Input info
val input_name : string ref
val input_lexbuf : Lexing.lexbuf option ref
Toplevel-specific functions
Printing locations
rewrite absolute path to honor the BUILD_PATH_PREFIX_MAP variable (https://reproducible-builds.org/specs/build-path-prefix-map/) if it is set.
In -absname mode, return the absolute path for this filename. Otherwise, returns the filename unchanged.
val print_filename : Format.formatter -> string -> unit
val print_loc : Format.formatter -> t -> unit
val print_locs : Format.formatter -> t list -> unit
Toplevel-specific location highlighting
val highlight_terminfo : Lexing.lexbuf -> Format.formatter -> t list -> unit
Reporting errors and warnings
The type of reports and report printers
type msg = (Format.formatter -> unit) loc
val msg : ?loc:t -> ('a, Format.formatter, unit, msg) format4 -> 'a
type report_printer = {
pp : report_printer -> Format.formatter -> report -> unit;
pp_report_kind : report_printer -> report -> Format.formatter -> report_kind -> unit;
pp_main_loc : report_printer -> report -> Format.formatter -> t -> unit;
pp_main_txt : report_printer -> report -> Format.formatter -> (Format.formatter -> unit) -> unit;
pp_submsgs : report_printer -> report -> Format.formatter -> msg list -> unit;
pp_submsg : report_printer -> report -> Format.formatter -> msg -> unit;
pp_submsg_loc : report_printer -> report -> Format.formatter -> t -> unit;
pp_submsg_txt : report_printer -> report -> Format.formatter -> (Format.formatter -> unit) -> unit;
}
A printer for report
s, defined using open-recursion. The goal is to make it easy to define new printers by re-using code from existing ones.
Report printers used in the compiler
val batch_mode_printer : report_printer
val terminfo_toplevel_printer : Lexing.lexbuf -> report_printer
val best_toplevel_printer : unit -> report_printer
Detects the terminal capabilities and selects an adequate printer
Printing a report
val print_report : Format.formatter -> report -> unit
Display an error or warning report.
val report_printer : (unit -> report_printer) ref
Hook for redefining the printer of reports.
The hook is a unit -> report_printer
and not simply a report_printer
: this is useful so that it can detect the type of the output (a file, a terminal, ...) and select a printer accordingly.
val default_report_printer : unit -> report_printer
Original report printer for use in hooks.
Reporting warnings
Converting a Warnings.t
into a report
val report_warning : t -> Warnings.t -> report option
report_warning loc w
produces a report for the given warning w
, or None
if the warning is not to be printed.
val warning_reporter : (t -> Warnings.t -> report option) ref
Hook for intercepting warnings.
val default_warning_reporter : t -> Warnings.t -> report option
Original warning reporter for use in hooks.
Printing warnings
val formatter_for_warnings : Format.formatter ref
val print_warning : t -> Format.formatter -> Warnings.t -> unit
Prints a warning. This is simply the composition of report_warning
and print_report
.
val prerr_warning : t -> Warnings.t -> unit
Same as print_warning
, but uses !formatter_for_warnings
as output formatter.
Reporting alerts
Converting an Alert.t
into a report
val report_alert : t -> Warnings.alert -> report option
report_alert loc w
produces a report for the given alert w
, or None
if the alert is not to be printed.