Module Location
: sigend
Source code locations (ranges of positions), used in parsetree.
Warning: this module is unstable and part of Compiler_libs .
typet = Warnings.loc = {
loc_start : Lexing.position ;
loc_end : Lexing.position ;
loc_ghost : bool ;
}
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.
valnone : t
An arbitrary value of type t ; describes an empty ghost range.
valis_none : t->bool
True for Location.none , false any other location
valin_file : string->t
Return an empty ghost range located in a given file.
valinit : Lexing.lexbuf->string->unit
Set the file name and line number of the lexbuf to be the start of the named file.
valcurr : Lexing.lexbuf->t
Get the location of the current token from the lexbuf .
valsymbol_rloc : unit->tvalsymbol_gloc : unit->tvalrhs_loc : int->trhs_locn returns the location of the symbol at position n , starting at 1, in the current parser rule.
valrhs_interval : int->int->tvalget_pos_info : Lexing.position->string*int*int
file, line, char
type'aloc = {
txt : 'a ;
loc : t ;
}
valmknoloc : 'a->'alocvalmkloc : 'a->t->'alocInputinfovalinput_name : stringrefvalinput_lexbuf : Lexing.lexbufoptionrefvalinput_phrase_buffer : Buffer.toptionrefToplevel-specificfunctionsvalecho_eof : unit->unitvalreset : unit->unitRewritingpathvalrewrite_absolute_path : string->stringrewrite_absolute_pathpath rewrites path to honor the BUILD_PATH_PREFIX_MAP variable if it is set. It
does not check whether path is absolute or not. The result is as follows:
-If BUILD_PATH_PREFIX_MAP is not set, just return path .
-otherwise, rewrite using the mapping (and if there are no matching prefixes that will just return path
).
See the BUILD_PATH_PREFIX_MAP spec
valrewrite_find_first_existing : string->stringoptionrewrite_find_first_existingpath uses a BUILD_PATH_PREFIX_MAP mapping and tries to find a source in
mapping that maps to a result that exists in the file system. There are the following return values:
- None , means either
-BUILD_PATH_PREFIX_MAP is not set and path does not exists, or
-no source prefixes of path in the mapping were found,
- Sometarget , means target exists and either
-BUILD_PATH_PREFIX_MAP is not set and target = path , or
- target is the first file (in priority order) that path mapped to that exists in the file system.
- Not_found raised, means some source prefixes in the map were found that matched path , but none of them
existed in the file system. The caller should catch this and issue an appropriate error message.
See the BUILD_PATH_PREFIX_MAP spec
valrewrite_find_all_existing_dirs : string->stringlistrewrite_find_all_existing_dirsdir accumulates a list of existing directories, dirs , that are the result
of mapping a potentially abstract directory, dir , over all the mapping pairs in the
BUILD_PATH_PREFIX_MAP environment variable, if any. The list dirs will be in priority order (head as
highest priority).
The possible results are:
- [] , means either
-BUILD_PATH_PREFIX_MAP is not set and dir is not an existing directory, or
-if set, then there were no matching prefixes of dir .
- Somedirs , means dirs are the directories found. Either
-BUILD_PATH_PREFIX_MAP is not set and dirs=[dir] , or
-it was set and dirs are the mapped existing directories.
-Not_found raised, means some source prefixes in the map were found that matched dir , but none of
mapping results were existing directories (possibly due to misconfiguration). The caller should catch
this and issue an appropriate error message.
See the BUILD_PATH_PREFIX_MAP spec
valabsolute_path : string->stringabsolute_pathpath first makes an absolute path, s from path , prepending the current working directory
if path was relative. Then s is rewritten using rewrite_absolute_path . Finally the result is
normalized by eliminating instances of '.' or '..' .
Printinglocationsvalshow_filename : string->string
In -absname mode, return the absolute path for this filename. Otherwise, returns the filename unchanged.
valprint_filename : Format.formatter->string->unitvalprint_loc : Format.formatter->t->unitvalprint_locs : Format.formatter->tlist->unitvalseparate_new_message : Format.formatter->unitmoduleDoc:sigendToplevel-specificlocationhighlightingvalhighlight_terminfo : Lexing.lexbuf->Format.formatter->tlist->unitReportingerrorsandwarningsThetypeofreportsandreportprinterstypemsg = Format_doc.tlocvalmsg : ?loc:t->('a,Format_doc.formatter,unit,msg)format4->'atypereport_kind =
| Report_error
| Report_warning ofstring
| Report_warning_as_error ofstring
| Report_alert ofstring
| Report_alert_as_error ofstringtypereport = {
kind : report_kind ;
main : msg ;
sub : msglist ;
footnote : Format_doc.toption ;
}
typereport_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_doc.t->unit ;
pp_submsgs : report_printer->report->Format.formatter->msglist->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_doc.t->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.
Reportprintersusedinthecompilervalbatch_mode_printer : report_printervalterminfo_toplevel_printer : Lexing.lexbuf->report_printervalbest_toplevel_printer : unit->report_printer
Detects the terminal capabilities and selects an adequate printer
Printingareportvalprint_report : Format.formatter->report->unit
Display an error or warning report.
valreport_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.
valdefault_report_printer : unit->report_printer
Original report printer for use in hooks.
ReportingwarningsConvertingaWarnings.tintoareportvalreport_warning : t->Warnings.t->reportoptionreport_warninglocw produces a report for the given warning w , or None if the warning is not to be
printed.
valwarning_reporter : (t->Warnings.t->reportoption)ref
Hook for intercepting warnings.
valdefault_warning_reporter : t->Warnings.t->reportoption
Original warning reporter for use in hooks.
Printingwarningsvalformatter_for_warnings : Format.formatterrefvalprint_warning : t->Format.formatter->Warnings.t->unit
Prints a warning. This is simply the composition of report_warning and print_report .
valprerr_warning : t->Warnings.t->unit
Same as print_warning , but uses !formatter_for_warnings as output formatter.
ReportingalertsConvertinganAlert.tintoareportvalreport_alert : t->Warnings.alert->reportoptionreport_alertlocw produces a report for the given alert w , or None if the alert is not to be printed.
valalert_reporter : (t->Warnings.alert->reportoption)ref
Hook for intercepting alerts.
valdefault_alert_reporter : t->Warnings.alert->reportoption
Original alert reporter for use in hooks.
Printingalertsvalprint_alert : t->Format.formatter->Warnings.alert->unit
Prints an alert. This is simply the composition of report_alert and print_report .
valprerr_alert : t->Warnings.alert->unit
Same as print_alert , but uses !formatter_for_warnings as output formatter.
valdeprecated : ?def:t->?use:t->t->string->unit
Prints a deprecation alert.
valalert : ?def:t->?use:t->kind:string->t->string->unit
Prints an arbitrary alert.
valauto_include_alert : string->unit
Prints an alert that -I +lib has been automatically added to the load path
valdeprecated_script_alert : string->unitdeprecated_script_alertcommand prints an alert that commandfoo has been deprecated in favour of command./fooReportingerrorstypeerror = report
An error is a report which report_kind must be Report_error .
typedelayed_msg = unit->Format_doc.toptionvalerror : ?loc:t->?sub:msglist->?footnote:delayed_msg->string->errorvalerrorf : ?loc:t->?sub:msglist->?footnote:delayed_msg->('a,Format_doc.formatter,unit,error)format4->'avalerror_of_printer : ?loc:t->?sub:msglist->?footnote:delayed_msg->(Format_doc.formatter->'a->unit)->'a->errorvalerror_of_printer_file : (Format_doc.formatter->'a->unit)->'a->errorAutomaticallyreportingerrorsforraisedexceptionsvalregister_error_of_exn : (exn->erroroption)->unit
Each compiler module which defines a custom type of exception which can surface as a user-visible error
should register a "printer" for this exception using register_error_of_exn . The result of the printer
is an error value containing a location, a message, and optionally sub-messages (each of them being
located as well).
valerror_of_exn : exn->[`Already_displayed|`Okoferror]optionexceptionErroroferror
Raising Errore signals an error e ; the exception will be caught and the error will be printed.
exceptionAlready_displayed_error
Raising Already_displayed_error signals an error which has already been printed. The exception will be
caught, but nothing will be printed
valraise_errorf : ?loc:t->?sub:msglist->?footnote:delayed_msg->('a,Format_doc.formatter,unit,'b)format4->'avalreport_exception : Format.formatter->exn->unit
Reraise the exception if it is unknown.
OCamldoc 2025-06-12 Location(3o)