package libsail
Module Libsail.ReportingSource
Sail error reporting
Reporting contains functions to report errors and warnings. It contains functions to print locations (Parse_ast.l and Ast.l) and lexing positions.
The main functionality is reporting errors. This is done by raising a Fatal_error exception. This is caught internally and reported via report_error. There are several predefined types of errors which all cause different error messages. If none of these fit, Err_general can be used.
If this is true, we will print all warnings, even if generated with ~once_from.
How many backtrace entries to show for unreachable code errors
Auxiliary Functions
loc_to_string prints a location as a string, including source code
loc_file returns the file for a location
Reduce a location to a pair of positions if possible
Returns true if a loc is Unknown. In the case of Hint location only checks the base location.
loc_range_to_src returns the source code text of a range *
val map_loc_range :
(Lexing.position -> Lexing.position -> Lexing.position * Lexing.position) ->
Parse_ast.l ->
Parse_ast.lAdjust the range of a location. Note that only the primary location is adjusted. Hint locations are unaffected.
short_loc_to_string prints the location as a single line in a simple format
print_err prints a custom error message to stderr.
Reduce all spans in a location to just their starting characters
The error type
type error = private | Err_general of Parse_ast.l * string(*General errors, used for multi purpose. If you are unsure, use this one.
*)| Err_unreachable of Parse_ast.l * string * int * int * int * Printexc.raw_backtrace * string(*Unreachable errors should never be thrown. They represent an internal Sail error.
*)| Err_todo of Parse_ast.l * string(*
*)Err_todoindicates that some feature is unimplemented.| Err_syntax of Lexing.position * string| Err_syntax_loc of Parse_ast.l * string(*
*)Err_syntaxandErr_syntax_locare used for syntax errors by the parser.| Err_lex of Lexing.position * string(*
*)Err_lexis a lexical error generated by the lexer.| Err_type of Parse_ast.l * string option * string(*
*)Err_typeis a type error. See the Type_error module.
Errors stop execution and print a message; they typically have a location and message.
Note that all these errors are intended to be fatal, so should not be caught other than by the top-level function.
Raise an unreachable exception.
This should always be used over an assert false or a generic OCaml failwith exception when appropriate.
This function transforms all errors raised by the provided function into internal Err_unreachable errors
val warn :
?once_from:(string * int * int * int) ->
?force_show:bool ->
string ->
Parse_ast.l ->
string ->
unitPrint a warning message. The first string is printed before the location, the second after.
val format_warn :
?once_from:(string * int * int * int) ->
string ->
Parse_ast.l ->
Error_format.message ->
unitPrint information about suppressed warnings
Print a simple one-line warning without a location.
Will suppress all warnings for a given (Sail) file name. Used by $suppress_warnings directive in process_file.ml
Run a command using Unix.system, but raise a Reporting exception if the command fails or is stopped/killed by a signal