text stringlengths 0 601k |
|---|
type threshold = { exceptions : int ; percentage : float ; optional : [ ` Percent | ` Both ] } |
type opt = { print : bool ; call_sites : bool ; threshold : threshold } |
let opta = ref { print = false ; call_sites = false ; threshold = { exceptions = 0 ; percentage = 1 . ; optional = ` Percent } ; } |
let optn = ref { print = false ; call_sites = false ; threshold = { exceptions = 0 ; percentage = 1 . ; optional = ` Percent } ; } |
let update_opt opt s = let threshold s = let len = String . length s in if len > 5 && String . sub s 0 5 = " both " : then begin let limits = String . sub s 5 ( String . length s - 5 ) in let thr = let rec loop s pos len = if len = String . length s then s else if s . [ pos ] = ' , ' then String . sub s ( pos - len ) l... |
type style = { opt_arg : bool ; unit_pat : bool ; seq : bool ; binding : bool } |
let style = ref { opt_arg = false ; unit_pat = false ; seq = false ; binding = false ; } |
let update_style s = let rec aux = function | ( b , " opt " ) :: l -> style := { ! style with opt_arg = b } ; aux l | ( b , " unit " ) :: l -> style := { ! style with unit_pat = b } ; aux l | ( b , " seq " ) :: l -> style := { ! style with seq = b } ; aux l | ( b , " bind " ) :: l -> style := { ! style with binding = b... |
type basic = { print : bool ; call_sites : bool ; threshold : int } |
let exported : basic ref = ref ( { print = true ; call_sites = false ; threshold = 0 } : basic ) |
let obj = ref ( { print = true ; call_sites = false ; threshold = 0 ; } : basic ) |
let typ : basic ref = ref ( { print = true ; call_sites = false ; threshold = 0 } : basic ) |
let update_basic opt ( flag : basic ref ) = function | " all " -> flag := { ! flag with print = true } | " nothing " -> flag := { ! flag with print = false } | s -> flag := { ! flag with print = true } ; let threshold = let len = String . length s in if len > 6 && String . sub s 0 6 = " calls " : then begin flag := { !... |
let verbose = ref false |
let set_verbose ( ) = verbose := true |
let underscore = ref true |
let set_underscore ( ) = underscore := false |
let internal = ref false |
let set_internal ( ) = internal := true |
let normalize_path s = let rec split_path s = let open Filename in if s = current_dir_name || s = dirname s then [ s ] else ( basename s ) :: ( split_path ( dirname s ) ) in let rec norm_path = function | [ ] -> [ ] | x :: ( ( y :: _ ) as yss ) when x = y && x = Filename . current_dir_name -> norm_path yss | x :: xss -... |
let exclude , is_excluded = let tbl = Hashtbl . create 10 in let exclude s = Hashtbl . replace tbl ( normalize_path s ) ( ) in let is_excluded s = Hashtbl . mem tbl ( normalize_path s ) in exclude , is_excluded |
let directories : string list ref = ref [ ] |
let dyn_rec = ref [ ] |
let str = Hashtbl . create 256 |
let used = ref [ ] |
let field_link = Hashtbl . create 256 |
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 | _ -> ( ) in let add = function | ( { Asttypes . txt " = mlfi . va... |
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 , _ ) -> List . map ( fun { Types . ld_id { = name ; _ } ; ld_loc = { Location . ... |
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 = not is_obj && DeadType . is_type x in if ( List . m... |
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 . dummy_pos |
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 = [ ] then hashtbl_find... |
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 action t | _ -> ( ) |
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 . loc_start | _ -> Lexing . dummy_pos in repr_exp expr locate |
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 " . " t in let path = h ^ " . " ^ short ... |
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 " . " else " " ) ^ name in let path = String . capitalize_ascii ( unit !... |
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 ; | ` New cty_loc -> add_equal loc cty_loc | ` Ignore ... |
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 pat . pat_desc with | Tpat_alias ( pat , _ , _ ) -... |
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 , _ ) | Tcl_let ( _ , _ , _ , cl_exp ) | Tcl_constrain... |
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 ) ] ; arg self typ ( List . tl args ) | Tarrow ( ... |
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 ( meth_self_ref loc1 ) meth ; in let... |
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 loop s pos = if pos = String . length s then s else if ... |
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 , _ ) when keep = ` Opt -> loop ( n + 1 ) typ . desc | Tarrow ( Nolabel , _ ... |
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 ^ " ) " | _ -> _TO_STRING_ t1 end ^ " -> " ^ _TO_STRING_ t2 | Ttuple l -> begin ... |
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 ' . ' ) then false else match blk s 0 0 [ ] with | hd :: cont :: _ -> ... |
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 Hashtbl . replace fields path loc . L... |
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 { ctyp_desc = Ttyp_constr ( _ , { txt ; _ } , _ ) ; _ }... |
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 ( String . sub str i ( String . length str - i ) ) a... |
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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.