text stringlengths 0 601k |
|---|
let read_result f p lb = JsonUtil . read_next_item ( Result_util . read_t f ( Yojson . Basic . read_list Result_util . read_message ) ) p lb |
let receive mailbox x = JsonUtil . read_of_string ( JsonUtil . read_variant Yojson . Basic . read_int ( fun p lb id -> let ( ) = match Hashtbl . find mailbox id with | B ( Nothing , thread ) -> Lwt . wakeup thread ( read_result Yojson . Basic . read_null p lb ) | B ( BigString , thread ) -> let out = read_result Yojson... |
let is_computing mailbox = Hashtbl . length mailbox <> 0 val mutable id = 0 method private message : type a . a handle -> ( Bi_outbuf . t -> unit ) -> ( a , Result_util . message list ) Result_util . t Lwt . t = fun handle request -> if is_running ( ) then let result , feeder = Lwt . task ( ) in let message = JsonUtil ... |
let insert_inferred_intf ~ source_uri client text_editor = let open Promise . Syntax in match String . is_suffix source_uri ~ suffix " . : ml " with | false -> Promise . return ( ) | true -> let * inferred_intf = Custom_requests . send_request client Custom_requests . inferIntf source_uri in let + edit_applied = TextEd... |
let request_switch client document = let open Promise . Syntax in let source_uri = Uri . toString ( TextDocument . uri document ) ~ skipEncoding : true ( ) in let fill_intf_if_empty_untitled text_editor = let doc = TextEditor . document text_editor in let is_empty_doc doc = TextDocument . getText doc ( ) |> String . is... |
type test = Test : ' b * ' a * ( ' b -> ' a ) -> test |
type t = A | B | C |
let passes = ref 0 |
let full_test line ~ f ~ results ( ) = let f = Sys . opaque_identity f in List . iter ( fun ( input , output ) -> let result = f input in if result <> output then raise ( Assert_failure ( __FILE__ , line , 0 ) ) ) results ; incr passes |
let test_int_match = full_test __LINE__ ~ f ( : function | 1 -> 1 | 2 -> 2 | 3 -> 3 | _ -> 0 ) ~ results : [ 1 , 1 ; 2 , 2 ; 3 , 3 ; 4 , 0 ; 0 , 0 ] |
let test_int_match_reverse = full_test __LINE__ ~ f ( : function | 1 -> 3 | 2 -> 2 | 3 -> 1 | _ -> 0 ) ~ results : [ 1 , 3 ; 2 , 2 ; 3 , 1 ; 4 , 0 ; 0 , 0 ] |
let test_int_match_negative = full_test __LINE__ ~ f ( : function | 1 -> - 1 | 2 -> - 2 | 3 -> - 3 | _ -> 0 ) ~ results : [ 1 , - 1 ; 2 , - 2 ; 3 , - 3 ; 4 , 0 ; 0 , 0 ] |
let test_int_match_negative_reverse = full_test __LINE__ ~ f ( : function | 1 -> - 3 | 2 -> - 2 | 3 -> - 1 | _ -> 0 ) ~ results : [ 1 , - 3 ; 2 , - 2 ; 3 , - 1 ; 4 , 0 ; 0 , 0 ] |
let test_int_min_int = full_test __LINE__ ~ f ( : function | 1 -> 1 | 2 -> 2 | 3 -> min_int | _ -> 0 ) ~ results : [ 1 , 1 ; 2 , 2 ; 3 , min_int ; 4 , 0 ; 0 , 0 ] |
let test_int_max_int = full_test __LINE__ ~ f ( : function | 1 -> 1 | 2 -> 2 | 3 -> max_int | _ -> 0 ) ~ results : [ 1 , 1 ; 2 , 2 ; 3 , max_int ; 4 , 0 ; 0 , 0 ] |
let test_float = full_test __LINE__ ~ f ( : function | 1 -> 1 . 0 | 2 -> 2 . 0 | 3 -> 3 . 0 | _ -> 0 . 0 ) ~ results : [ 1 , 1 . 0 ; 2 , 2 . 0 ; 3 , 3 . 0 ; 4 , 0 . 0 ; 0 , 0 . 0 ] |
let test_string = full_test __LINE__ ~ f ( : function | 1 -> " a " | 2 -> " b " | 3 -> " cc " | _ -> " " ) ~ results : [ 1 , " a " ; 2 , " b " ; 3 , Sys . opaque_identity " c " ^ Sys . opaque_identity " c " ; 4 , " " ; 0 , " " ] |
let test_list = full_test __LINE__ ~ f ( : function | 1 -> [ ] | 2 -> [ 42 ] | 3 -> [ 1 ; 2 ; 3 ] | _ -> [ 415 ] ) ~ results : [ 1 , [ ] ; 2 , [ 42 ] ; 3 , List . rev [ 3 ; 2 ; 1 ] ; 4 , [ 415 ] ; 0 , [ 415 ] ] |
let test_abc = full_test __LINE__ ~ f ( : function | A -> 1 | B -> 2 | C -> 3 ) ~ results : [ A , 1 ; B , 2 ; C , 3 ] |
let test_abc_unsorted = full_test __LINE__ ~ f ( : function | C -> 3 | A -> 1 | B -> 2 ) ~ results : [ A , 1 ; B , 2 ; C , 3 ] |
let test_abc_neg3 = full_test __LINE__ ~ f ( : function | A -> 1 | B -> 2 | C -> - 3 ) ~ results : [ A , 1 ; B , 2 ; C , - 3 ] |
let test_abc_min_int = full_test __LINE__ ~ f ( : function | A -> 1 | B -> 2 | C -> min_int ) ~ results : [ A , 1 ; B , 2 ; C , min_int ] |
let test_abc_max_int = full_test __LINE__ ~ f ( : function | A -> 1 | B -> 2 | C -> max_int ) ~ results : [ A , 1 ; B , 2 ; C , max_int ] |
let test_abc_float = full_test __LINE__ ~ f ( : function | A -> 1 . | B -> 2 . | C -> 3 . ) ~ results : [ A , 1 . ; B , 2 . ; C , 3 . ] |
let test_abc_string = full_test __LINE__ ~ f ( : function | A -> " a " | B -> " b " | C -> " c " ) ~ results : [ A , " a " ; B , " b " ; C , " c " ] |
let test_abc_list = full_test __LINE__ ~ f ( : function | A -> [ ] | B -> [ 42 ] | C -> [ 1 ; 2 ; 3 ] ) ~ results : [ A , [ ] ; B , [ 42 ] ; C , List . rev [ 3 ; 2 ; 1 ] ] |
let test_f99 = full_test __LINE__ ~ f ( : function | 1 -> 1 | 2 -> 2 | 3 -> 3 | 4 -> 4 | 5 -> 5 | 6 -> 6 | 7 -> 7 | 8 -> 8 | 9 -> 9 | 10 -> 10 | 11 -> 11 | 12 -> 12 | 13 -> 13 | 14 -> 14 | 15 -> 15 | 16 -> 16 | 17 -> 17 | 18 -> 18 | 19 -> 19 | 20 -> 20 | 21 -> 21 | 22 -> 22 | 23 -> 23 | 24 -> 24 | 25 -> 25 | 26 -> 26 |... |
let test_poly = full_test __LINE__ ~ f ( : function | 1 -> ` Primary | 2 -> ` Secondary | 3 -> ` Tertiary | n -> invalid_arg " test " ) ~ results : [ 1 , ` Primary ; 2 , ` Secondary ; 3 , ` Tertiary ] |
let test_or = full_test __LINE__ ~ f ( : function | 1 | 2 | 3 -> 0 | 4 | 5 | 6 -> 1 | 7 -> 2 | _ -> 0 ) ~ results : [ 1 , 0 ; 2 , 0 ; 3 , 0 ; 4 , 1 ; 5 , 1 ; 6 , 1 ; 7 , 2 ; 8 , 0 ; 0 , 0 ] |
type t ' = E | F | G | H |
let test_or_efgh = full_test __LINE__ ~ f ( : function | E | H -> 0 | F -> 1 | G -> 2 ) ~ results : [ E , 0 ; H , 0 ; F , 1 ; G , 2 ] |
type ' a gadt = | Ag : int gadt | Bg : string gadt | Cg : int gadt | Dg : int gadt | Eg : int gadt |
let test_gadt = full_test __LINE__ ~ f ( : function | Ag -> 1 | Cg -> 2 | Dg -> 3 | Eg -> 4 ) ~ results : [ Ag , 1 ; Cg , 2 ; Dg , 3 ; Eg , 4 ] |
let ( ) = test_int_match ( ) ; test_int_match_reverse ( ) ; test_int_match_negative ( ) ; test_int_match_negative_reverse ( ) ; test_int_min_int ( ) ; test_int_max_int ( ) ; test_float ( ) ; test_string ( ) ; test_list ( ) ; test_abc ( ) ; test_abc_unsorted ( ) ; test_abc_neg3 ( ) ; test_abc_min_int ( ) ; test_abc_max_... |
let ( ) = Printf . printf " % d tests passed \ n " ! passes |
type variable = string and term = | Var of variable | Lam of variable * term | App of term * term | Const of constant and constant = | CInt of int | CString of string ; ; |
let free_variables_v1 = let o = object ( self ) inherit fold as super val fv = VarSet . empty method fv = fv method empty_fv = { < fv = VarSet . empty } > method term t = match t with | Var ( v ) -> { < fv = VarSet . add v fv } > | Lam ( v , t ) -> let fv1 = VarSet . remove v ( self # empty_fv # term t ) # fv in { < fv... |
let fold_term f t init = let o = object ( self ) inherit fold as super val acc = init method get = acc method reset = { < acc = init } > method term t = { < acc = f t acc ( fun t -> ( self # reset # term t ) # get ) ( fun t -> ( super # term t ) # get ) } > end in ( o # term t ) # get ; ; |
let free_variables_v2 t = VarSet . elements begin fold_term begin fun t fv self next -> match t with | Var ( v ) -> VarSet . add v fv | Lam ( v , t ) -> VarSet . union fv ( VarSet . remove v ( self t ) ) | _ -> next t end t VarSet . empty end ; ; |
let term1 = App ( App ( Var " x1 " , Lam ( " x " , App ( Var " x " , App ( Var " y " , ( Lam ( " y " , Lam ( " z " , ( App ( Var " y " , App ( Var " x4 " , Var " z " ) ) ) ) ) ) ) ) ) ) , Var " x3 " ) ; ; |
let fv1 = free_variables_v1 term1 ; ; |
let fv2 = free_variables_v2 term1 ; ; |
let ( ^-> ) v t = Lam ( v , t ) |
let ( @ ) t1 t2 = App ( t1 , t2 ) |
let ( ! ) s = Var s |
let term2 = " ! x1 " @ ( " x " ^-> " ! x " @ " ! y " @ ( " y " ^-> ( " z " ^-> " ! y " @ " ! x4 " @ " ! z " ) ) ) @ " ! x3 " ; ; |
let fv1 ' = free_variables_v1 term2 ; ; |
let fv2 ' = free_variables_v2 term2 ; ; |
type variable = string and term = | Var of variable | Lam of variable * term | App of term * term | Const of constant and constant = | CInt of int | CString of string and program = | Def of string * term | Seq of program list ; ; |
let map_term f = object inherit map as super method term t = f ( super # term t ) end ; ; |
let map_term ' f = object ( self ) inherit map as super method term t = f t self # term super # term end ; ; |
let suppress_id = map_term begin function | App ( Lam ( v , Var ( v ' ) ) , t ) when v = v ' -> t | x -> x end ; ; |
let raw_subst v t = map_term ' begin fun t ' _ next -> match t ' with | Var ( v ' ) when v = v ' -> t | x -> next x end ; ; |
let id = Lam ( " x " , Var " x " ) ; ; |
let _42 = Const ( CInt 42 ) ; ; |
let prog = Seq [ Def ( " foo " , App ( id , _42 ) ) ; Def ( " bar " , App ( id , id ) ) ] ; ; |
let prog2 = suppress_id # program prog ; ; |
let term3 = suppress_id # term ( App ( id , _42 ) ) ; ; |
let term4 = ( raw_subst " x " _42 ) # term ( App ( Var " succ " , Var " x " ) ) ; ; |
type marshaled_value = { num_cnt : int ; num_tbl : ( Ident . t , int ) Tree . t ; } |
type t = Ident . t option array |
let maxind_of_tree tree = Tree . fold ( fun _ident ind acc -> max ind acc ) ( - 1 ) tree |
let table_of_tree tree = let size = maxind_of_tree tree + 1 in let table = Array . make size None in let store ident ind = assert ( table . ( ind ) = None ) ; table . ( ind ) <- Some ident in Tree . iter store tree ; table |
let tree_of_table table = let aggr_idents acc ident_opt = match ident_opt with | None -> acc | Some ident -> ident :: acc in let sorted_tbl = Array . of_list ( Array . fold_left aggr_idents [ ] table ) in let ( ) = Array . sort compare sorted_tbl in let rec make_tree i j = if i >= j then Tree . Empty else let m = ( i +... |
let print oc table = Array . iteri ( fun ind ident_opt -> match ident_opt with | None -> ( ) | Some ident -> Printf . fprintf oc " % 4d : % a \ n " ind Ident . print ident ) table |
let read version index ic = let ( offset , _length ) = Index . find_section index Section . SYMB in let ( ) = seek_in ic offset in let mv = ( input_value ic : marshaled_value ) in let table = table_of_tree mv . num_tbl in Array . iter ( Ident . check_opt version ) table ; table |
let write version oc table = Array . iter ( Ident . check_opt version ) table ; let tree = tree_of_table table in let num_cnt = maxind_of_tree tree + 1 in let marshaled_value = { num_cnt = num_cnt ; num_tbl = tree } in output_value oc marshaled_value |
module PS = SetDomain . ToppedSet ( LP ) ( struct let topname = " All " end ) |
module Spec = struct include Analyses . DefaultSpec exception Top module D = LockDomain . Symbolic module C = LockDomain . Symbolic let name ( ) = " symb_locks " let startstate v = D . top ( ) let threadenter ctx lval f args = [ D . top ( ) ] let threadspawn ctx lval f args fctx = ctx . local let exitstate v = D . top ... |
let _ = MCP . register_analysis ( module Spec : MCPSpec ) |
module Exp = struct include CilType . Exp let contains_var v e = let rec offs_contains o = match o with | NoOffset -> false | Field ( _ , o ) -> offs_contains o | Index ( e , o ) -> cv false e || offs_contains o and cv deref e = match e with | SizeOf _ | SizeOfE _ | SizeOfStr _ | AlignOf _ | Const _ | AlignOfE _ -> fal... |
module LockingPattern = struct include Printable . Std type t = Exp . t * Exp . t * Exp . t [ @@ deriving eq , ord , hash , to_yojson ] let name ( ) = " Per - Element locking triple " let pretty ( ) ( x , y , z ) = text " ( " ++ d_exp ( ) x ++ text " , " ++ d_exp ( ) y ++ text " , " ++ d_exp ( ) z ++ text " ) " let sho... |
type t = | Linkage of { compilation_unit : Compilation_unit . t ; label : Linkage_name . t ; hash : int ; } | Variable of { compilation_unit : Compilation_unit . t ; variable : Variable . t ; } |
let label t = match t with | Linkage { label ; _ } -> label | Variable { variable ; _ } -> let compilation_unit = Variable . get_compilation_unit variable in let unit_linkage_name = Linkage_name . to_string ( Compilation_unit . get_linkage_name compilation_unit ) in let label = unit_linkage_name ^ " __ " ^ Variable . u... |
let of_global_linkage compilation_unit label = let hash = Linkage_name . hash label in Linkage { compilation_unit ; hash ; label } |
let of_variable variable = let compilation_unit = Variable . get_compilation_unit variable in Variable { variable ; compilation_unit } |
let import_to_compilation_unit ~ unit : compilation_unit symbol = match symbol with | Linkage l -> Linkage { l with compilation_unit } | Variable v -> Variable { v with compilation_unit } |
let compilation_unit t = match t with | Linkage { compilation_unit ; _ } -> compilation_unit | Variable { compilation_unit ; _ } -> compilation_unit |
let print_opt ppf = function | None -> Format . fprintf ppf " < no symbol " > | Some t -> print ppf t |
let compare_lists l1 l2 = Misc . Stdlib . List . compare compare l1 l2 |
let modules = ref ( [ ] : string list ) |
let program_source_dirs = ref ( [ ] : string list ) |
let events_by_pc = ( Hashtbl . create 257 : ( pc , debug_event ) Hashtbl . t ) |
let events_by_module = ( Hashtbl . create 17 : ( string , int * debug_event array ) Hashtbl . t ) |
let all_events_by_module = ( Hashtbl . create 17 : ( string , int * debug_event list ) Hashtbl . t ) |
let partition_modules evl = let rec partition_modules ' ev evl = match evl with [ ] -> [ ev ] , [ ] | ev ' :: evl -> let evl , evll = partition_modules ' ev ' evl in if ev . ev_module = ev ' . ev_module then ev :: evl , evll else [ ev ] , evl :: evll in match evl with [ ] -> [ ] | ev :: evl -> let evl , evll = partitio... |
let relocate_event orig ev = ev . ev_pos <- orig + ev . ev_pos ; match ev . ev_repr with Event_parent repr -> repr := ev . ev_pos | _ -> ( ) |
let read_symbols ' bytecode_file = let ic = open_in_bin bytecode_file in begin try Bytesections . read_toc ic ; ignore ( Bytesections . seek_section ic " SYMB " ) ; with Bytesections . Bad_magic_number | Not_found -> prerr_string bytecode_file ; prerr_endline " is not a bytecode file . " ; raise Toplevel end ; Symtable... |
let clear_symbols ( ) = modules := [ ] ; program_source_dirs := [ ] ; Hashtbl . clear events_by_pc ; Hashtbl . clear events_by_module ; Hashtbl . clear all_events_by_module |
let add_symbols frag all_events = List . iter ( fun evl -> List . iter ( fun ev -> Hashtbl . add events_by_pc { frag ; pos = ev . ev_pos } ev ) evl ) all_events ; List . iter ( function [ ] -> ( ) | ev :: _ as evl -> let md = ev . ev_module in let cmp ev1 ev2 = compare ( Events . get_pos ev1 ) . Lexing . pos_cnum ( Eve... |
let read_symbols frag bytecode_file = let all_events , all_dirs = read_symbols ' bytecode_file in program_source_dirs := ! program_source_dirs @ ( String . Set . elements all_dirs ) ; add_symbols frag all_events |
let erase_symbols frag = let pcs = Hashtbl . fold ( fun pc _ pcs -> if pc . frag = frag then pc :: pcs else pcs ) events_by_pc [ ] in List . iter ( Hashtbl . remove events_by_pc ) pcs ; let mds = Hashtbl . fold ( fun md ( frag ' , _ ) mds -> if frag ' = frag then md :: mds else mds ) events_by_module [ ] in List . iter... |
let code_fragments ( ) = let frags = Hashtbl . fold ( fun _ ( frag , _ ) l -> frag :: l ) all_events_by_module [ ] in List . sort_uniq compare frags |
let modules_in_code_fragment frag ' = Hashtbl . fold ( fun md ( frag , _ ) l -> if frag ' = frag then md :: l else l ) all_events_by_module [ ] |
let any_event_at_pc pc = { ev_frag = pc . frag ; ev_ev = Hashtbl . find events_by_pc pc } |
let event_at_pc pc = match any_event_at_pc pc with { ev_ev = { ev_kind = Event_pseudo } } -> raise Not_found | ev -> ev |
let set_event_at_pc pc = try ignore ( event_at_pc pc ) ; set_event pc with Not_found -> ( ) |
let events_in_module mdle = try Hashtbl . find all_events_by_module mdle with Not_found -> 0 , [ ] |
let find_event ev char = let rec bsearch lo hi = if lo >= hi then begin if ( Events . get_pos ev . ( hi ) ) . Lexing . pos_cnum < char then raise Not_found else hi end else begin let pivot = ( lo + hi ) / 2 in let e = ev . ( pivot ) in if char <= ( Events . get_pos e ) . Lexing . pos_cnum then bsearch lo pivot else bse... |
let event_at_pos md char = let ev_frag , ev = Hashtbl . find events_by_module md in { ev_frag ; ev_ev = ev . ( find_event ev char ) } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.