text
stringlengths
12
786k
let rec loadfiles ppf name = try let filename = Load_path . find name in Dynlink . allow_unsafe_modules true ; Dynlink . loadfile filename ; let d = Filename . dirname name in if d <> Filename . current_dir_name then begin if not ( List . mem d ( Load_path . get_paths ( ) ) ) then Load...
let loadfile ppf name = ignore ( loadfiles ppf name )
let rec eval_address = function | Env . Aident id -> assert ( Ident . persistent id ) ; let bytecode_or_asm_symbol = Ident . name id in begin match Dynlink . unsafe_get_global_value ~ bytecode_or_asm_symbol with | None -> raise ( Symtable . Error ( Symtable . Undefined_global bytecode_or_as...
let eval_value_path env path = match Env . find_value_address path env with | addr -> eval_address addr | exception Not_found -> fatal_error ( " Cannot find address for : " ^ ( Path . name path ) )
let init ( ) = let topdirs = Filename . concat ! Parameters . topdirs_path " topdirs . cmi " in ignore ( Env . read_signature " Topdirs " topdirs )
let match_printer_type desc typename = let printer_type = match Env . find_type_by_name ( Ldot ( Lident " Topdirs " , typename ) ) Env . empty with | path , _ -> path | exception Not_found -> raise ( Error ( Unbound_identifier ( Ldot ( Lident " Topdirs " , typename ) ) ) )...
let find_printer_type lid = match Env . find_value_by_name lid Env . empty with | ( path , desc ) -> begin match match_printer_type desc " printer_type_new " with | ty_arg -> ( ty_arg , path , false ) | exception Ctype . Unify _ -> begin match match_printer_type desc " printer_type_old...
let install_printer ppf lid = let ( ty_arg , path , is_old_style ) = find_printer_type lid in let v = try eval_value_path Env . empty path with Symtable . Error ( Symtable . Undefined_global s ) -> raise ( Error ( Unavailable_module ( s , lid ) ) ) in let print_function = if is_old_...
let remove_printer lid = let ( _ty_arg , path , _is_old_style ) = find_printer_type lid in try Printval . remove_printer path with Not_found -> raise ( Error ( No_active_printer lid ) )
let report_error ppf = function | Load_failure e -> fprintf ppf " [ @ Error during code loading : % s ] . " @@ ( Dynlink . error_message e ) | Unbound_identifier lid -> fprintf ppf " [ @ Unbound identifier % a ] . " @@ Printtyp . longident lid | Unavailable_module ( md , lid...
| Concrete of loc ] ; 2 / type loc = { file_name : string ; start : pos ; stop : pos } ; type t = option loc ; 3 / type t = { file_name : option string ; start : pos ; stop : pos } ; ) *
type pos = { line : int ; bol : int ; off : int } ;
type t = { file_name : string ; start : pos ; stop : pos ; ghost : bool } ; let s = match x with [ ` start -> " ` start " | ` stop -> " ` stop " | ` both -> " ` both " | _ -> " < not - printable " > ] in pp_print_string f s ; fprintf f " [ @< hov 2 { ...
type ' a ref = { mutable contents : ' a }
let f1 x g = let r = ref x in try while ! r < 42 do if g ! r then raise Exit ; r := ! r + 1 done ; 0 with Exit -> 42
let f2 x g = let r = ref x in try while ! r < 42 do if try g ! r with _ -> false then raise Exit ; r := ! r + 1 done ; 0 with Exit -> 42
let f3 x g = let r = ref x in try while ! r < 42 do if try g ! r with _ -> false then raise_notrace Exit ; r := ! r + 1 done ; 0 with Exit -> 42
let f4 x g = let r = ref x in try while ! r < 42 do if try g ! r with _ -> false then raise_notrace ( Exit2 ( ! r + 2 , ! r + 3 ) ) ; r := ! r + 1 done ; 0 with Exit2 ( a , b ) -> a + b
type t = Warnings . loc = { loc_start : position ; loc_end : position ; loc_ghost : bool } ; ;
let in_file name = let loc = { dummy_pos with pos_fname = name } in { loc_start = loc ; loc_end = loc ; loc_ghost = true } ; ;
let none = in_file " _none_ " ; ;
let is_none l = ( l = none ) ; ;
let curr lexbuf = { loc_start = lexbuf . lex_start_p ; loc_end = lexbuf . lex_curr_p ; loc_ghost = false } ; ;
let init lexbuf fname = lexbuf . lex_curr_p <- { pos_fname = fname ; pos_lnum = 1 ; pos_bol = 0 ; pos_cnum = 0 ; } ; ;
let symbol_rloc ( ) = { loc_start = Parsing . symbol_start_pos ( ) ; loc_end = Parsing . symbol_end_pos ( ) ; loc_ghost = false ; } ; ;
let symbol_gloc ( ) = { loc_start = Parsing . symbol_start_pos ( ) ; loc_end = Parsing . symbol_end_pos ( ) ; loc_ghost = true ; } ; ;
let rhs_loc n = { loc_start = Parsing . rhs_start_pos n ; loc_end = Parsing . rhs_end_pos n ; loc_ghost = false ; } ; ;
let rhs_interval m n = { loc_start = Parsing . rhs_start_pos m ; loc_end = Parsing . rhs_end_pos n ; loc_ghost = false ; } ; ;
let get_pos_info pos = ( pos . pos_fname , pos . pos_lnum , pos . pos_cnum - pos . pos_bol ) ; ;
type ' a loc = { txt : ' a ; loc : t ; }
let mkloc txt loc = { txt ; loc }
let mknoloc txt = mkloc txt none
let input_name = ref " _none_ "
let input_lexbuf = ref ( None : lexbuf option )
let input_phrase_buffer = ref ( None : Buffer . t option )
let status = ref Terminfo . Uninitialised
let setup_terminal ( ) = if ! status = Terminfo . Uninitialised then status := Terminfo . setup stdout
let num_loc_lines = ref 0
let reset ( ) = num_loc_lines := 0
let echo_eof ( ) = print_newline ( ) ; incr num_loc_lines
let print_updating_num_loc_lines ppf f arg = let open Format in let out_functions = pp_get_formatter_out_functions ppf ( ) in let out_string str start len = let rec count i c = if i = start + len then c else if String . get str i = ' \ n ' then count ( succ i ) ( succ c ) else count ( succ i...
let setup_colors ( ) = Misc . Color . setup ! Clflags . color
let rewrite_absolute_path path = match Misc . get_build_path_prefix_map ( ) with | None -> path | Some map -> Build_path_prefix_map . rewrite map path
let absolute_path s = let open Filename in let s = if not ( is_relative s ) then s else ( rewrite_absolute_path ( concat ( Sys . getcwd ( ) ) s ) ) in let rec aux s = let base = basename s in let dir = dirname s in if dir = s then dir else if base = current_dir_name then aux dir else if bas...
let show_filename file = if ! Clflags . absname then absolute_path file else file
let print_filename ppf file = Format . pp_print_string ppf ( show_filename file )
let print_loc ppf loc = setup_colors ( ) ; let file_valid = function | " _none_ " -> true | " " | " // toplevel " // -> false | _ -> true in let line_valid line = line > 0 in let chars_valid ~ startchar ~ endchar = startchar <> - 1 && endchar <> - 1 in let file = if loc . ...
let print_locs ppf locs = Format . pp_print_list ~ pp_sep ( : fun ppf ( ) -> Format . fprintf ppf " , @ " ) print_loc ppf locs
module ISet : sig type ' a bound = ' a * int type ' a t val of_intervals : ( ' a bound * ' a bound ) list -> ' a t val mem : ' a t -> pos : int -> bool val find_bound_in : ' a t -> range ( : int * int ) -> ' a bound option val is_start : ' a t -> pos : int -> ' a option ...
let highlight_terminfo lb ppf locs = Format . pp_print_flush ppf ( ) ; let pos0 = - lb . lex_abs_pos in if pos0 < 0 then raise Exit ; let lines = ref ! num_loc_lines in for i = pos0 to lb . lex_buffer_len - 1 do if Bytes . get lb . lex_buffer i = ' \ n ' then incr lines done ; if ! ...
let highlight_terminfo lb ppf locs = try highlight_terminfo lb ppf locs with Exit -> ( )
type input_line = { text : string ; start_pos : int ; }
let infer_line_numbers ( lines : ( int option * input_line ) list ) : ( int option * input_line ) list = let ( _ , offset , consistent ) = List . fold_left ( fun ( i , offset , consistent ) ( lnum , _ ) -> match lnum , offset with | None , _ -> ( i + 1 , offse...
let highlight_quote ppf ( ~ get_lines : start_pos : position -> end_pos : position -> input_line list ) ( ? max_lines = 10 ) highlight_tag locs = let iset = ISet . of_intervals @@ List . filter_map ( fun loc -> let s , e = loc . loc_start , loc . loc_end in if s . pos_cnum = - 1 ...
let lines_around ( ~ start_pos : position ) ( ~ end_pos : position ) ( ~ seek : int -> unit ) ( ~ read_char : unit -> char option ) : input_line list = seek start_pos . pos_bol ; let lines = ref [ ] in let bol = ref start_pos . pos_bol in let cur = ref start_pos . pos_bol in l...
let lines_around_from_lexbuf ( ~ start_pos : position ) ( ~ end_pos : position ) ( lb : lexbuf ) : input_line list = let rel n = n - lb . lex_abs_pos in if rel start_pos . pos_bol < 0 then begin [ ] end else begin let pos = ref 0 in let seek n = pos := rel n in let read_char ( ) ...
let lines_around_from_phrasebuf ( ~ start_pos : position ) ( ~ end_pos : position ) ( pb : Buffer . t ) : input_line list = let pos = ref 0 in let seek n = pos := n in let read_char ( ) = if ! pos >= Buffer . length pb then None else begin let c = Buffer . nth pb ! pos in incr pos ...
let lines_around_from_file ( ~ start_pos : position ) ( ~ end_pos : position ) ( filename : string ) : input_line list = try let cin = open_in_bin filename in let read_char ( ) = try Some ( input_char cin ) with End_of_file -> None in let lines = lines_around ~ start_pos ~ end_pos ~ se...
let lines_around_from_current_input ~ start_pos ~ end_pos = let file_valid = function | " // toplevel " // | " _none_ " | " " -> false | _ -> true in let from_file ( ) = if file_valid ! input_name then lines_around_from_file ! input_name ~ start_pos ~ end_pos else [ ] in match ! ...
type msg = ( Format . formatter -> unit ) loc
let msg ( ? loc = none ) fmt = Format . kdprintf ( fun txt -> { loc ; txt } ) fmt
type report_kind = | Report_error | Report_warning of string | Report_warning_as_error of string | Report_alert of string | Report_alert_as_error of string
type report = { kind : report_kind ; main : msg ; sub : msg list ; }
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...
let is_dummy_loc loc = loc . loc_start . pos_cnum = - 1 || loc . loc_end . pos_cnum = - 1
let is_quotable_loc loc = not ( is_dummy_loc loc ) && loc . loc_start . pos_fname = ! input_name && loc . loc_end . pos_fname = ! input_name
let error_style ( ) = match ! Clflags . error_style with | Some setting -> setting | None -> Misc . Error_style . default_setting
let batch_mode_printer : report_printer = let pp_loc _self report ppf loc = let tag = match report . kind with | Report_warning_as_error _ | Report_alert_as_error _ | Report_error -> " error " | Report_warning _ | Report_alert _ -> " warning " in let highlight ppf loc = match error_style ( ...
let terminfo_toplevel_printer ( lb : lexbuf ) : report_printer = let pp self ppf err = setup_colors ( ) ; let sub_locs = List . map ( fun { loc ; _ } -> loc ) err . sub in let all_locs = err . main . loc :: sub_locs in let locs_highlighted = List . filter is_quotable_loc all_locs...
let best_toplevel_printer ( ) = setup_terminal ( ) ; match ! status , ! input_lexbuf with | Terminfo . Good_term , Some lb -> terminfo_toplevel_printer lb | _ , _ -> batch_mode_printer
let default_report_printer ( ) : report_printer = if ! input_name = " // toplevel " // then best_toplevel_printer ( ) else batch_mode_printer
let report_printer = ref default_report_printer
let print_report ppf report = let printer = ! report_printer ( ) in printer . pp printer ppf report
let report_error ppf err = print_report ppf err
let mkerror loc sub txt = { kind = Report_error ; main = { loc ; txt } ; sub }
let errorf ( ? loc = none ) ( ? sub = [ ] ) = Format . kdprintf ( mkerror loc sub )
let error ( ? loc = none ) ( ? sub = [ ] ) msg_str = mkerror loc sub ( fun ppf -> Format . pp_print_string ppf msg_str )
let error_of_printer ( ? loc = none ) ( ? sub = [ ] ) pp x = mkerror loc sub ( fun ppf -> pp ppf x )
let error_of_printer_file print x = error_of_printer ~ loc ( : in_file ! input_name ) print x
let default_warning_alert_reporter report mk ( loc : t ) w : report option = match report w with | ` Inactive -> None | ` Active { Warnings . id ; message ; is_error ; sub_locs } -> let msg_of_str str = fun ppf -> Format . pp_print_string ppf str in let kind = mk is_error id in let main ...
let default_warning_reporter = default_warning_alert_reporter Warnings . report ( fun is_error id -> if is_error then Report_warning_as_error id else Report_warning id )
let warning_reporter = ref default_warning_reporter
let report_warning loc w = ! warning_reporter loc w
let formatter_for_warnings = ref Format . err_formatter
let print_warning loc ppf w = match report_warning loc w with | None -> ( ) | Some report -> print_report ppf report
let prerr_warning loc w = print_warning loc ! formatter_for_warnings w
let default_alert_reporter = default_warning_alert_reporter Warnings . report_alert ( fun is_error id -> if is_error then Report_alert_as_error id else Report_alert id )
let alert_reporter = ref default_alert_reporter
let report_alert loc w = ! alert_reporter loc w
let print_alert loc ppf w = match report_alert loc w with | None -> ( ) | Some report -> print_report ppf report
let prerr_alert loc w = print_alert loc ! formatter_for_warnings w
let alert ( ? def = none ) ( ? use = none ) ~ kind loc message = prerr_alert loc { Warnings . kind ; message ; def ; use }
let deprecated ? def ? use loc message = alert ? def ? use ~ kind " : deprecated " loc message
let error_of_exn : ( exn -> error option ) list ref = ref [ ]
let register_error_of_exn f = error_of_exn := f :: ! error_of_exn
let error_of_exn exn = match exn with | Already_displayed_error -> Some ` Already_displayed | _ -> let rec loop = function | [ ] -> None | f :: rest -> match f exn with | Some error -> Some ( ` Ok error ) | None -> loop rest in loop ! error_of_exn
let ( ) = register_error_of_exn ( function | Sys_error msg -> Some ( errorf ~ loc ( : in_file ! input_name ) " I / O error : % s " msg ) | _ -> None )
let report_exception ppf exn = let rec loop n exn = match error_of_exn exn with | None -> reraise exn | Some ` Already_displayed -> ( ) | Some ( ` Ok err ) -> report_error ppf err | exception exn when n > 0 -> loop ( n - 1 ) exn in loop 5 exn
let ( ) = register_error_of_exn ( function | Error e -> Some e | _ -> None )
let raise_errorf ( ? loc = none ) ( ? sub = [ ] ) = Format . kdprintf ( fun txt -> raise ( Error ( mkerror loc sub txt ) ) )