text
stringlengths
12
786k
let pp ppf ( Oid ( v1 , v2 , vs ) ) = Format . fprintf ppf " % d . % d % a " v1 v2 ( fun ppf -> List . iter ( Format . fprintf ppf " . % d " ) ) vs
let of_string s = let rec go ic = if Scanf . Scanning . end_of_input ic then [ ] else Scanf . bscanf ic " . % d % r " go ( fun n ns -> n :: ns ) in try Scanf . sscanf s " % d . % d % r " go of_nodes with End_of_file | Scanf . Scan_failure _ -> None
let compare ( Oid ( v1 , v2 , vs ) ) ( Oid ( v1 ' , v2 ' , vs ' ) ) = let rec cmp ( xs : int list ) ys = match ( xs , ys ) with | ( [ ] , [ ] ) -> 0 | ( [ ] , _ ) -> - 1 | ( _ , [ ] ) -> 1 | ( x :: xs , y :: ys ) -> match...
let equal o1 o2 = compare o1 o2 = 0
let seeded_hash seed ( Oid ( v1 , v2 , vs ) ) = Hashtbl . ( List . fold_left seeded_hash ( seeded_hash ( seeded_hash seed v1 ) v2 ) vs )
let hash o = seeded_hash 0 o
module type Prim = sig type t val of_cstruct : Cstruct . t -> t val to_writer : t -> Writer . t val random : unit -> t end
module type Prim_s = sig include Prim val random : ? size : int -> unit -> t val concat : t list -> t val length : t -> int end
let rec replicate_l n f = if n < 1 then [ ] else f ( ) :: replicate_l ( pred n ) f
let max_r_int = ( 1 lsl 30 ) - 1
let random_int ( ) = Random . int max_r_int
let random_int_r a b = a + Random . int ( b - a )
let random_size = function | Some size -> size | None -> Random . int 20
let random_string ? size ~ chars ( : lo , hi ) ( ) = String . init ( random_size size ) ( fun _ -> Char . chr ( random_int_r lo hi ) )
module Int64 = struct include Int64 let ( + ) = add and ( - ) = sub and ( * ) = mul and ( / ) = div and ( lsl ) = shift_left and ( lsr ) = shift_right_logical and ( asr ) = shift_right and ( lor ) = logor and ( land ) = logand let max_p_int = Int64 . of_int Stdlib . ...
module Boolean : Prim with type t = bool = struct type t = bool let of_cstruct cs = if cs . Cstruct . len = 1 then Cstruct . get_uint8 cs 0 <> 0x00 else parse_error " BOOLEAN : % a " pp_cs cs let to_writer b = Writer . of_byte ( if b then 0xff else 0x00 ) let random = Random . bool end
module Null : Prim with type t = unit = struct type t = unit let of_cstruct cs = if cs . Cstruct . len <> 0 then parse_error " NULL : % a " pp_cs cs let to_writer ( ) = Writer . empty let random ( ) = ( ) end
module Integer : Prim with type t = Z . t = struct type t = Z . t let of_int8 x = Z . of_int ( if x >= 0x80 then x - 0x100 else x ) [ @@ inline ] let of_int16 x = Z . of_int ( if x >= 0x8000 then x - 0x10000 else x ) [ @@ inline ] let of_cstruct cs = let open Cstruct in let rec ...
module Gen_string : Prim_s with type t = string = struct type t = string let of_cstruct x = Cstruct . to_string x let to_writer = Writer . of_string let random ? size ( ) = random_string ? size ~ chars ( : 32 , 127 ) ( ) let ( concat , length ) = String . ( concat " " , l...
module Octets : Prim_s with type t = Cstruct . t = struct type t = Cstruct . t let of_cstruct { Cstruct . buffer ; off ; len } = Cstruct . of_bigarray @@ Bigarray . Array1 . sub buffer off len let to_writer = Writer . of_cstruct let random ? size ( ) = random_string ? size ~ chars (...
module Bits : sig include Prim_s with type t = bits val to_array : t -> bool array val of_array : bool array -> t struct type t = int * Cstruct . t let of_cstruct cs = let n = Cstruct . length cs in if n = 0 then parse_error " BITS " else let unused = Cstruct . get_uint8 cs 0 in if n = 1 && u...
module OID = struct open Asn_oid let uint64_chain cs i n = let rec go acc cs i = function 0 -> parse_error " OID : unterminated component " | n -> match Cstruct . get_uint8 cs i with 0x80 when acc = 0L -> parse_error " OID : redundant form " | b -> let lo = b land 0x7f in let acc = Int64 . ...
module Time = struct let ps_per_ms = 1_000_000_000L let pp_tz ppf = function | 0 -> pf ppf " Z " | tz -> pf ppf " % c % 02d % 02d " ( if tz < 0 then ' ' + else ' ' ) - ( abs tz / 3600 ) ( ( abs tz mod 3600 ) / 60 ) let pp_utc_time ppf t = let ( ( y , m , d...
let replicate n f a = let rec loop acc n = if n <= 0 then acc else loop ( f a :: acc ) ( pred n ) in loop [ ] n
let r_prim : type a . a prim -> a = function | Bool -> Boolean . random ( ) | Int -> Integer . random ( ) | Bits -> Bits . random ( ) | Octets -> Octets . random ( ) | Null -> ( ) | OID -> OID . random ( ) | CharString -> Gen_string . random ( )
let rec r_element : type a . a element -> a = function | Required ( _ , asn ) -> r_asn asn | Optional ( _ , asn ) -> if Random . int 3 = 0 then None else Some ( r_asn asn ) | Last e -> r_element e | Pair ( e , es ) -> ( r_element e , r_seq es ) replicate Random . ( in...
let cs_lex_compare cs1 cs2 = let ( s1 , s2 ) = Cstruct . ( length cs1 , length cs2 ) in let rec go i lim = if i = lim then compare s1 s2 else match compare ( Cstruct . get_uint8 cs1 i ) ( Cstruct . get_uint8 cs2 i ) with | 0 -> go ( succ i ) lim | n -> n in go 0 ( min s1 s2 )
type t = int * ( int -> Cstruct . t -> unit )
let immediate n f = ( n , f )
let len ( n , _ ) = n
let empty = ( 0 , ( fun _ _ -> ( ) ) )
let ( ) <+> ( l1 , w1 ) ( l2 , w2 ) = let w off buf = ( w1 off buf ; w2 ( off + l1 ) buf ) in ( l1 + l2 , w )
let rec concat = function | [ ] -> empty | w :: ws -> w <+> concat ws
let of_list lst = let open List in let w off cs = iteri ( fun i -> Cstruct . set_uint8 cs ( off + i ) ) lst in ( length lst , w )
let of_string str = let n = String . length str in ( n , fun off cs -> Cstruct . blit_from_string str 0 cs off n )
let of_cstruct cs ' = let n = Cstruct . length cs ' in ( n , fun off cs -> Cstruct . blit cs ' 0 cs off n )
let of_byte b = ( 1 , fun off cs -> Cstruct . set_uint8 cs off b )
let to_cstruct ( n , w ) = let cs = Cstruct . create n in ( w 0 cs ; cs )
let to_writer ( n , w ) = ( n , fun cs -> w 0 cs )
type result = { abbrev_table : Abbreviations_table . t ; dies : Debugging_information_entry . t list ; compilation_unit_die : Debugging_information_entry . t option ; dwarf_4_location_lists : Dwarf_4_location_list . t list }
let run ~ proto_die_root = let abbrev_table , dies_rev , compilation_unit_die , location_lists_rev = let next_abbreviation_code = ref 1 in Proto_die . depth_first_fold proto_die_root ~ init ( : Abbreviations_table . create ( ) , [ ] , None , [ ] ) ~ f : ( fun ( abbrev_table ...
type identifier = string | Module of ' a stmt list * ' a | Interactive of ' a stmt list * ' a | Expression of ' a expr * ' a | Suite of ' a stmt list * ' a | FunctionDef of identifier * ' a arguments * ' a stmt list * ' a expr list * ' a | ClassDef of identifier * ' a expr list...
let name_of_mod = function | Module _ -> " Module " | Interactive _ -> " Interactive " | Expression _ -> " Expression " | Suite _ -> " Suite " | FunctionDef _ -> " FunctionDef " | ClassDef _ -> " ClassDef " | Return _ -> " Return " | Delete _ -> " Delete " | Ass...
let annot_of_mod = function | Module ( _ , a ) | Interactive ( _ , a ) | Expression ( _ , a ) | Suite ( _ , a ) -> a | FunctionDef ( _ , _ , _ , _ , a ) | ClassDef ( _ , _ , _ , _ , a ) | Return ( _ , a ) | Delete ( _ , a ) | Assign ( ...
let context_of_expr = function | Attribute ( _ , _ , ctx , _ ) -> Some ctx | Subscript ( _ , _ , ctx , _ ) -> Some ctx | Name ( _ , ctx , _ ) -> Some ctx | List ( _ , ctx , _ ) -> Some ctx | Tuple ( _ , ctx , _ ) -> Some ctx | _ -> None
let string_of_boolop = function | And -> " and " | Or -> " or "
let string_of_operator = function | Add -> " " + | Sub -> " " - | Mult -> " " * | Div -> " " / | Mod -> " " % | Pow -> " " ** | LShift -> " " << | RShift -> " " >> | BitOr -> " " | | BitXor -> " " ^ | BitAnd -> " " & | FloorDiv -> " " ...
let string_of_unaryop = function | Invert -> " " ~ | Not -> " not " | UAdd -> " " + | USub -> " " -
let string_of_cmpop = function | Eq -> " " == | NotEq -> " " != | Lt -> " " < | LtE -> " " <= | Gt -> " " > | GtE -> " " >= | Is -> " is " | IsNot -> " is not " | In -> " in " | NotIn -> " not in "
let string_of_number = function | Int ( n ) -> string_of_int n | LongInt ( n ) -> ( string_of_int n ) ^ " L " | Float ( n ) -> ( string_of_float n ) | Imag ( n ) -> n
module type Annot = sig type t val of_pos : Lexing . position -> t end
module Pos : Annot = struct type t = Lexing . position let of_pos pos = pos end
let err_empty_string = " the string is empty "
let err_empty_sep = " ~ sep is an empty string "
let err_neg_max max = strf " negative ~ max ( % d ) " max
let err_neg_min max = strf " negative ~ min ( % d ) " max
let err_neg_len len = strf " negative length ( % d ) " len
let err_max_string_len = " Sys . max_string_length exceeded "
let for_all sat s ~ first ~ last = let rec loop i = if i > last then true else if sat ( string_unsafe_get s i ) then loop ( i + 1 ) else false in loop first
let exists sat s ~ first ~ last = let rec loop i = if i > last then false else if sat ( string_unsafe_get s i ) then true else loop ( i + 1 ) in loop first
let fold_left f acc s ~ first ~ last = let rec loop acc i = if i > last then acc else loop ( f acc ( string_unsafe_get s i ) ) ( i + 1 ) in loop acc first
let fold_right f s acc ~ first ~ last = let rec loop i acc = if i < first then acc else loop ( i - 1 ) ( f ( string_unsafe_get s i ) acc ) in loop last acc
let of_char c = let b = Bytes . create 1 in bytes_unsafe_set b 0 c ; bytes_unsafe_to_string b
let to_char s = match string_length s with
let to_bool s = try Some ( bool_of_string s ) with Invalid_argument _ -> None
let to_int s = try Some ( int_of_string s ) with Failure _ -> None
let to_nativeint s = try Some ( Nativeint . of_string s ) with Failure _ -> None
let to_int32 s = try Some ( Int32 . of_string s ) with Failure _ -> None
let to_int64 s = try Some ( Int64 . of_string s ) with Failure _ -> None
let to_float s = try Some ( float_of_string s ) with Failure _ -> None
let err_byte b = Printf . sprintf " % d is not a byte " b
let of_byte b = if b < 0 || b > 255 then invalid_arg ( err_byte b ) else unsafe_of_byte b
let of_int b = if b < 0 || b > 255 then None else ( Some ( unsafe_of_byte b ) )
let hash c = Hashtbl . hash c
let equal : t -> t -> bool = fun c0 c1 -> c0 = c1
let compare : t -> t -> int = fun c0 c1 -> compare c0 c1
module Ascii = struct let max_ascii = ' \ x7F ' let is_valid : t -> bool = fun c -> c <= max_ascii let is_digit = function ' 0 ' . . ' 9 ' -> true | _ -> false let is_hex_digit = function | ' 0 ' . . ' 9 ' | ' A ' . . ' F ' | ' a ' . . ' f ' -> t...
let dump ppf c = Format . pp_print_char ppf ' ' ' ; \ Format . pp_print_string ppf ( Ascii . escape_char c ) ; Format . pp_print_char ppf ' ' ' ; \ ( )
let hex_escape b k c = let byte = char_to_byte c in let hi = byte / 16 in let lo = byte mod 16 in bytes_unsafe_set b ( k ) ' ' ; \\ bytes_unsafe_set b ( k + 1 ) ' x ' ; bytes_unsafe_set b ( k + 2 ) ( array_unsafe_get hex_digit hi ) ; bytes_unsafe_set b ( k + 3 ) ( array...
let letter_escape b k letter = bytes_unsafe_set b ( k ) ' ' ; \\ bytes_unsafe_set b ( k + 1 ) letter ; ( )
let char_escape = function let b = Bytes . create 1 in bytes_unsafe_set b 0 c ; bytes_unsafe_to_string b let b = Bytes . create 4 in hex_escape b 0 c ; bytes_unsafe_to_string b
let char_escape_char = function let b = Bytes . create 1 in bytes_unsafe_set b 0 c ; bytes_unsafe_to_string b let b = Bytes . create 4 in hex_escape b 0 c ; bytes_unsafe_to_string b
let escape s = let max_idx = string_length s - 1 in let rec escaped_len i l = if i > max_idx then l else match string_unsafe_get s i with | ' ' \\ -> escaped_len ( i + 1 ) ( l + 2 ) | ' \ x20 ' . . ' \ x7E ' -> escaped_len ( i + 1 ) ( l + 1 ) | _ -> escaped_len ( ...
let escape_string s = let max_idx = string_length s - 1 in let rec escaped_len i l = if i > max_idx then l else match string_unsafe_get s i with | ' \ b ' | ' \ t ' | ' \ n ' | ' \ r ' | ' " ' \ | ' ' \\ -> escaped_len ( i + 1 ) ( l + 2 ) | ' \ x20 ' . . ...
let unescaped_len ~ ocaml s = let max_idx = string_length s - 1 in let rec loop i l = if i > max_idx then Some l else if string_unsafe_get s i <> ' ' \\ then loop ( i + 1 ) ( l + 1 ) else let i = i + 1 in if i > max_idx then None else match string_unsafe_get s i with | ' ' \\ -> loop...
let _unescape ~ ocaml s = match unescaped_len ~ ocaml s with let b = Bytes . create l in let max_idx = string_length s - 1 in let rec loop i k = if i > max_idx then Some ( bytes_unsafe_to_string b ) else let c = string_unsafe_get s i in if c <> ' ' \\ then ( bytes_unsafe_set b k c ; loop ( ...
let unescape s = _unescape ~ ocaml : false s
let unescape_string s = _unescape ~ ocaml : true s
let v ~ len f = let b = Bytes . create len in for i = 0 to len - 1 do bytes_unsafe_set b i ( f i ) done ; bytes_unsafe_to_string b
let get_byte s i = char_to_byte ( get s i )
let unsafe_get_byte s i = char_to_byte ( unsafe_get s i )
let head ( ? rev = false ) s = let len = length s in if len = 0 then None else Some ( string_unsafe_get s ( if rev then len - 1 else 0 ) )
let get_head ( ? rev = false ) s = let len = length s in if len = 0 then invalid_arg Astring_base . err_empty_string else string_unsafe_get s ( if rev then len - 1 else 0 )
let hash c = Hashtbl . hash c
let append s0 s1 = let l0 = length s0 in if l0 = 0 then s1 else let l1 = length s1 in if l1 = 0 then s0 else let b = Bytes . create ( l0 + l1 ) in bytes_unsafe_blit_string s0 0 b 0 l0 ; bytes_unsafe_blit_string s1 0 b l0 l1 ; bytes_unsafe_to_string b
let concat ( ? sep = empty ) = function let s_len = length s in let sep_len = length sep in let rec cat_len sep_count l ss = if l < 0 then l else match ss with | s :: ss -> cat_len ( sep_count + 1 ) ( l + length s ) ss | [ ] -> if sep_len = 0 then l else let max_sep_count = Sys . ma...
let is_empty s = length s = 0
let is_prefix ~ affix s = let len_a = length affix in let len_s = length s in if len_a > len_s then false else let max_idx_a = len_a - 1 in let rec loop i = if i > max_idx_a then true else if unsafe_get affix i <> unsafe_get s i then false else loop ( i + 1 ) in loop 0
let is_infix ~ affix s = let len_a = length affix in let len_s = length s in if len_a > len_s then false else let max_idx_a = len_a - 1 in let max_idx_s = len_s - len_a in let rec loop i k = if i > max_idx_s then false else if k > max_idx_a then true else if k > 0 then if unsafe_get affix k = unsafe_get...
let is_suffix ~ affix s = let max_idx_a = length affix - 1 in let max_idx_s = length s - 1 in if max_idx_a > max_idx_s then false else let rec loop i = if i > max_idx_a then true else if unsafe_get affix ( max_idx_a - i ) <> unsafe_get s ( max_idx_s - i ) then false else loop ( i + 1 ) in lo...