text
stringlengths
12
786k
let dyn_used = Hashtbl . create 256
let ( ) = DeadLexiFi . sig_value := ( fun value -> let add strct = match strct . pstr_desc with | Pstr_eval ( { pexp_desc = Pexp_constant ( PConst_string ( s , _ ) ) ; _ } , _ ) -> hashtbl_add_unique_to_list str s value . val_loc . Location . loc_start | _ -> ( ) i...
let defined : string list ref = ref [ ]
let rec sign ( ? isfunc = false ) = function | Mty_signature sg -> sg | Mty_functor ( _ , t , _ ) when isfunc -> begin match t with | None -> [ ] | Some t -> sign t end | Mty_functor ( _ , _ , t ) -> sign t | _ -> [ ]
let item maker = function | Sig_value ( { name ; _ } , { val_loc = { Location . loc_start = loc ; _ } ; _ } ) -> ( name , loc ) [ ] :: | Sig_type ( { name = t ; _ } , { type_kind ; _ } , _ ) -> begin match type_kind with | Type_record ( l , _ ...
let rec make_content typ = List . map ( item make_content ) ( sign typ ) |> List . flatten
let rec make_arg typ = List . map ( item make_arg ) ( sign ~ isfunc : true typ ) |> List . flatten
let expr m = match m . mod_desc with | Tmod_apply ( m1 , m2 , _ ) -> let l1 = make_arg m1 . mod_type |> List . map ( fun ( x , _ ) -> x ) in let l2 = make_content m2 . mod_type in List . iter ( fun ( x , loc ) -> let is_obj = String . contains x ' ' # in let is_type...
let expr m = if [ @ warning " - 44 " ] DeadFlag . ( ! exported . print || ! typ . print || ! obj . print ) then expr m else ( )
let decs = Hashtbl . create 256
let references = Hashtbl . create 512
let self_ref = Hashtbl . create 512
let content = Hashtbl . create 512
let inheritances = Hashtbl . create 512
let equals = Hashtbl . create 64
let later = ref [ ]
let last_class = ref Lexing . dummy_pos
let path2loc = Hashtbl . create 256
let defined = Hashtbl . create 16
let repr_loc loc = let met = Hashtbl . create 8 in let rec loop loc = if Hashtbl . mem equals loc then let next = Hashtbl . find equals loc in if not ( Hashtbl . mem met next ) then begin Hashtbl . add met loc ( ) ; loop next end else loc else loc in Hashtbl . add met loc ( ) ; loop loc
let meth_tbl tbl loc = if not ( Hashtbl . mem tbl loc ) then Hashtbl . add tbl loc ( Hashtbl . create 16 ) ; Hashtbl . find tbl loc
let meth_ref = meth_tbl references
let meth_self_ref = meth_tbl self_ref
let add_path path loc = Hashtbl . replace path2loc path loc
let get_loc path = let path = try Hashtbl . fold ( fun _ ( _ , path ) acc -> path :: acc ) incl [ ] |> find_path path ~ sep ' . ' : with Not_found -> try Hashtbl . find defined path with Not_found -> path in try repr_loc ( Hashtbl . find path2loc path ) with Not_found -> Lexing...
let know_path path = let path = try Hashtbl . find defined path with Not_found -> path in Hashtbl . mem path2loc path
let get_method s = let rec loop s pos = if s . [ pos ] = ' ' # then String . sub s ( pos + 1 ) ( String . length s - pos - 1 ) else if pos <= 0 then s else loop s ( pos - 1 ) in loop s ( String . length s - 1 )
let add_equal loc1 loc2 = let loc1 = repr_loc loc1 and loc2 = repr_loc loc2 in if loc1 <> loc2 && not ( is_ghost loc1 || is_ghost loc2 ) then begin Hashtbl . replace equals loc1 loc2 ; if loc1 = ! last_class then last_class := loc2 ; let meths = let res = hashtbl_find_list content loc2 in if res =...
let rec sign = function | Cty_signature sg -> sg | Cty_arrow ( _ , _ , t ) | Cty_constr ( _ , _ , t ) -> sign t
let rec treat_fields action typ = match typ . desc with | Tobject ( t , _ ) | Tarrow ( _ , _ , t , _ ) | Tlink t -> treat_fields action t | Tfield ( s , k , _ , t ) -> if Btype . field_kind_repr k = Fpresent && s . [ 0 ] > ' Z ' then action s ; treat_fields acti...
let rec repr_exp expr f = match expr . exp_desc with | Texp_sequence ( _ , expr ) | Texp_function { cases = { c_rhs = expr ; _ } :: _ ; _ } | Texp_apply ( expr , _ ) -> repr_exp expr f | _ -> f expr
let locate expr = let locate expr = match expr . exp_desc with | Texp_instvar ( _ , _ , { Asttypes . loc ; _ } ) | Texp_new ( _ , _ , { Types . cty_loc = loc ; _ } ) | Texp_ident ( _ , _ , { Types . val_loc = loc ; _ } ) -> repr_loc loc . Location . ...
let eom ( ) = Hashtbl . reset defined ; last_class := Lexing . dummy_pos
let collect_export path u stock ~ obj ~ cltyp loc = let pos = loc . Location . loc_start in begin match List . rev_map ( fun id -> id . Ident . name ) path with | h :: t when ! last_class == Lexing . dummy_pos || ! last_class <= pos || decs != incl -> let short = String . concat " . ...
let collect_references ~ meth ~ call_site expr = let loc = locate expr in if not ( is_ghost loc ) then begin hashtbl_add_unique_to_list ( meth_ref loc ) meth call_site ; if loc = ! last_class then hashtbl_add_unique_to_list ( meth_self_ref loc ) meth call_site end
let tstr ( { ci_expr ; ci_decl = { cty_loc = loc ; _ } ; ci_id_name = { txt = name ; _ } ; _ } , _ ) = let loc = loc . Location . loc_start in last_class := loc ; let short = ( List . rev ! mods |> String . concat " . " ) ^ ( if ! mods <> [ ] then "...
let add_var loc expr = let kind expr = match expr . exp_desc with | Texp_object _ -> ` Obj | Texp_new ( _ , _ , { cty_loc = { Location . loc_start = cty_loc ; _ } ; _ } ) -> ` New cty_loc | _ -> ` Ignore in match repr_exp expr kind with | ` Obj -> last_class := loc ; ...
let class_structure cl_struct = let rec add_aliases pat = begin match pat . pat_desc with | Tpat_alias ( _ , _ , _ ) | Tpat_var ( _ , _ ) when not pat . pat_loc . Location . loc_ghost -> add_equal pat . pat_loc . Location . loc_start ! last_class | _ -> ( ) end ; match pa...
let class_field f = let rec locate cl_exp = match cl_exp . cl_desc with | Tcl_ident ( path , _ , _ ) -> let path = Path . name path in if Hashtbl . mem defined path then Hashtbl . find defined path else path | Tcl_fun ( _ , _ , _ , cl_exp , _ ) | Tcl_apply ( cl_exp , _ ) ...
let arg typ args = let apply_to_exp f = function | ( _ , Some exp ) :: _ -> f exp | _ -> ( ) in let rec arg self typ args = if args <> [ ] then match typ . desc with | Tlink t -> arg self t args | Tarrow ( _ , t , typ , _ ) when not self -> arg self t [ ( List . hd args...
let coerce expr typ = let loc = locate expr in let use meth = hashtbl_add_unique_to_list ( meth_ref loc ) meth expr . exp_loc . Location . loc_start in treat_fields use typ
let prepare_report ( ) = List . iter ( fun f -> f ( ) ) ! later ; let apply_self meth loc1 loc2 = let loc1 = repr_loc loc1 and loc2 = repr_loc loc2 in hashtbl_merge_unique_list ( meth_ref loc2 ) meth ( meth_self_ref loc1 ) meth ; hashtbl_merge_unique_list ( meth_self_ref loc2 ) meth ...
let report ( ) = prepare_report ( ) ; let cut_main s = let rec loop s pos = if pos = String . length s then s else if s . [ pos ] = ' . ' then String . sub s ( pos + 1 ) ( String . length s - pos - 1 ) else loop s ( pos + 1 ) in loop s 0 in let no_star s = let rec l...
let wrap f x = if ! DeadFlag . obj . print then f x else ( )
let collect_export path u stock ? obj ? cltyp loc = wrap ( collect_export path u stock ~ obj ~ cltyp ) loc
let collect_references ~ meth ~ call_site exp = wrap ( collect_references ~ meth ~ call_site ) exp
let tstr cl_dec = wrap tstr cl_dec
let add_var loc exp = wrap ( add_var loc ) exp
let class_structure cl_struct = wrap class_structure cl_struct
let class_field cl_field = wrap class_field cl_field
let arg typ args = wrap ( arg typ ) args
let report ( ) = wrap report ( )
let decs = Hashtbl . create 256
let dependencies = ref [ ]
let is_unit t = match ( Ctype . repr t ) . desc with | Tconstr ( p , [ ] , _ ) -> Path . same p Predef . path_unit | _ -> false
let nb_args ~ keep typ = let rec loop n = function | Tarrow ( _ , _ , typ , _ ) when keep = ` All -> loop ( n + 1 ) typ . desc | Tarrow ( Labelled _ , _ , typ , _ ) when keep = ` Lbl -> loop ( n + 1 ) typ . desc | Tarrow ( Optional _ , _ , typ , _ ) w...
let rec _TO_STRING_ typ = begin [ @ warning " - 11 " ] match typ . desc with | Tvar i -> begin match i with Some id -> id | None -> " ' a " end | Tarrow ( _ , t1 , t2 , _ ) -> begin match t1 . desc with | Tarrow _ -> " ( " ^ _TO_STRING_ t1 ^ " ) " | _ -> _T...
let is_type s = let rec blk s p l acc = try if s . [ p ] = ' . ' then let acc = String . sub s ( p - l ) l :: acc in blk s ( p + 1 ) 0 acc else blk s ( p + 1 ) ( l + 1 ) acc with _ -> String . sub s ( p - l ) l :: acc in if not ( String . contains s ' . ' )...
let collect_export path u stock t = let stock = if stock == DeadCommon . decs then decs else stock in let save id loc = if t . type_manifest = None then export path u stock id loc ; let path = String . concat " . " @@ List . rev_map ( fun id -> id . Ident . name ) ( id :: path ) in ...
let collect_references loc exp_loc = LocHash . add_set references loc exp_loc
let rec check_style t loc = if ! DeadFlag . style . DeadFlag . opt_arg then match t . desc with | Tlink t -> check_style t loc | Tarrow ( lab , _ , t , _ ) -> begin match lab with | Optional lab when check_underscore lab -> style := ( ! current_src , loc , " val f : . . . -...
let tstr typ = let assoc name loc = let path = String . concat " . " @@ List . rev @@ name . Asttypes . txt :: typ . typ_name . Asttypes . txt :: ! mods @ ( String . capitalize_ascii ( unit ! current_src ) :: [ ] ) in begin try match typ . typ_manifest with | Some { cty...
let report ( ) = report_basic decs " UNUSED CONSTRUCTORS / RECORD FIELDS " ! DeadFlag . typ
let wrap f x = if DeadFlag . ( ! typ . print ) then f x else ( )
let collect_export path u stock t = wrap ( collect_export path u stock ) t
let tstr typ = wrap tstr typ
let report ( ) = wrap report ( )
module Debug = struct value mode _ = False ; end ;
type section = string ; try let f = Sys . getenv " CAMLP4_DEBUG_FILE " in open_out_gen [ Open_wronly ; Open_creat ; Open_append ; Open_text ] 0o666 f with [ Not_found -> Pervasives . stderr ] ;
module StringSet = Set . Make String ; try let str = Sys . getenv " CAMLP4_DEBUG " in let rec loop acc i = try let pos = String . index_from str i ' ' : in loop ( StringSet . add ( String . sub str i ( pos - i ) ) acc ) ( pos + 1 ) with [ Not_found -> StringSet . add ( ...
let conn = ref Primitives . std_io
type follow_fork_mode = Fork_child | Fork_parent
let fork_mode = ref Fork_parent
let update_follow_fork_mode ( ) = let a = match ! fork_mode with Fork_child -> 0 | Fork_parent -> 1 in output_char ! conn . io_out ' K ' ; output_binary_int ! conn . io_out a
let set_current_connection io_chan = conn := io_chan ; update_follow_fork_mode ( )
type pc = { frag : int ; pos : int ; }
let set_event { frag ; pos } = output_char ! conn . io_out ' e ' ; output_binary_int ! conn . io_out frag ; output_binary_int ! conn . io_out pos
let set_breakpoint { frag ; pos } = output_char ! conn . io_out ' B ' ; output_binary_int ! conn . io_out frag ; output_binary_int ! conn . io_out pos
let reset_instr { frag ; pos } = output_char ! conn . io_out ' i ' ; output_binary_int ! conn . io_out frag ; output_binary_int ! conn . io_out pos
type execution_summary = Event | Breakpoint | Exited | Trap_barrier | Uncaught_exc | Debug_info of Instruct . debug_event list array | Code_loaded of int | Code_unloaded of int
type report = { rep_type : execution_summary ; rep_event_count : int64 ; rep_stack_pointer : int ; rep_program_pointer : pc }
type checkpoint_report = Checkpoint_done of int | Checkpoint_failed
let do_go_smallint n = output_char ! conn . io_out ' g ' ; output_binary_int ! conn . io_out n ; flush ! conn . io_out ; Input_handling . execute_with_other_controller Input_handling . exit_main_loop ! conn ( function ( ) -> Input_handling . main_loop ( ) ; let summary = match i...
let rec do_go n = assert ( n >= _0 ) ; if n > max_small_int then begin match do_go_smallint max_int with | { rep_type = Event } -> do_go ( n -- max_small_int ) | report -> { report with rep_event_count = report . rep_event_count ++ ( n -- max_small_int ) } end else do_go_smallint ( ...
let do_checkpoint ( ) = match Sys . os_type with " Win32 " -> failwith " do_checkpoint " | _ -> output_char ! conn . io_out ' c ' ; flush ! conn . io_out ; let pid = input_binary_int ! conn . io_in in if pid = - 1 then Checkpoint_failed else Checkpoint_done pid
let stop chan = try output_char chan . io_out ' s ' ; flush chan . io_out with Sys_error _ | End_of_file -> ( )
let wait_child chan = try output_char chan . io_out ' w ' with Sys_error _ | End_of_file -> ( )
let initial_frame ( ) = output_char ! conn . io_out ' 0 ' ; flush ! conn . io_out ; let stack_pos = input_binary_int ! conn . io_in in let frag = input_binary_int ! conn . io_in in let pos = input_binary_int ! conn . io_in in ( stack_pos , { frag ; pos } )
let set_initial_frame ( ) = ignore ( initial_frame ( ) )
let up_frame stacksize = output_char ! conn . io_out ' U ' ; output_binary_int ! conn . io_out stacksize ; flush ! conn . io_out ; let stack_pos = input_binary_int ! conn . io_in in let frag , pos = if stack_pos = - 1 then 0 , 0 else let frag = input_binary_int ! conn . io_in in le...
let get_frame ( ) = output_char ! conn . io_out ' f ' ; flush ! conn . io_out ; let stack_pos = input_binary_int ! conn . io_in in let frag = input_binary_int ! conn . io_in in let pos = input_binary_int ! conn . io_in in ( stack_pos , { frag ; pos } )
let set_frame stack_pos = output_char ! conn . io_out ' S ' ; output_binary_int ! conn . io_out stack_pos
let set_trap_barrier pos = output_char ! conn . io_out ' b ' ; output_binary_int ! conn . io_out pos
let value_size = if 1 lsl 31 = 0 then 4 else 8
let input_remote_value ic = really_input_string ic value_size
let output_remote_value ic v = output_substring ic v 0 value_size
module Remote_value = struct type t = Remote of string | Local of Obj . t let repr x = Local ( Obj . repr x ) let obj = function | Local obj -> Obj . obj obj | Remote v -> output_char ! conn . io_out ' M ' ; output_remote_value ! conn . io_out v ; flush ! conn . io_out ; try input_...
let debugger_prompt = " ( ocd ) "
let shell = match Sys . os_type with " Win32 " -> " cmd " | _ -> " / bin / sh "
let history_size = ref 30