text stringlengths 0 601k |
|---|
let invalid_arg fmt = Format . ksprintf invalid_arg fmt |
let pp_list ~ sep pp ppf xs = let rec go ppf = function | [ ] -> ( ) | [ x ] -> pp ppf x | x :: xs -> pf ppf " % a % a @ " pp x sep ( ) ; go ppf xs in pf ppf " [ @% a ] " @ go xs |
let pp_dump_list pp ppf xs = let sep ppf ( ) = Format . pp_print_string ppf " , " in pf ppf " [ [ @% a ] ] " @ ( pp_list ~ sep pp ) xs |
let pp_cs ppf cs = let f ppf cs = for i = 0 to cs . Cstruct . len - 1 do if i mod 8 = 0 && i > 0 then pf ppf " @ " ; pf ppf " % 02x " ( Cstruct . get_uint8 cs i ) done in pf ppf " [ @% a ] " @ f cs |
module Tag = struct type t = | Universal of int | Application of int | Context_specific of int | Private of int let compare t1 t2 = match ( t1 , t2 ) with | ( Universal a , Universal b ) | ( Application a , Application b ) | ( Context_specific a , Context_specific b ) | ( Private a , Private b ) -> compare a b | ( Univ... |
type tags = Tag . t list |
module Generic = struct type t = | Cons of tag * t list | Prim of tag * Cstruct . t let tag = function Cons ( t , _ ) -> t | Prim ( t , _ ) -> t let pp_form_name ppf fsym = Format . pp_print_string ppf @@ match fsym with ` Cons -> " Constructed " | ` Prim -> " Primitive " | ` Both -> " ANY " let pp_tag ppf g = let form... |
type bits = int * Cstruct . t |
type ' a rand = unit -> ' a |
type _ asn = | Iso : ( ' a -> ' b ) * ( ' b -> ' a ) * ' b rand option * ' a asn -> ' b asn | Fix : ( ' a asn -> ' a asn ) * ' a Asn_cache . var -> ' a asn | Sequence : ' a sequence -> ' a asn | Sequence_of : ' a asn -> ' a list asn | Set : ' a sequence -> ' a asn | Set_of : ' a asn -> ' a list asn | Choice : ' a asn *... |
let label = opt " " |
let seq_tag = Tag . Universal 0x10 |
let tag_of_p : type a . a prim -> tag = let open Tag in function | Bool -> Universal 0x01 | Int -> Universal 0x02 | Bits -> Universal 0x03 | Octets -> Universal 0x04 | Null -> Universal 0x05 | OID -> Universal 0x06 | CharString -> Universal 0x1d |
let rec tag_set : type a . a asn -> tags = function | Iso ( _ , _ , _ , asn ) -> tag_set asn | Fix ( f , _ ) as fix -> tag_set ( f fix ) | Sequence _ -> [ seq_tag ] | Sequence_of _ -> [ seq_tag ] | Set _ -> [ set_tag ] | Set_of _ -> [ set_tag ] | Choice ( asn1 , asn2 ) -> tag_set asn1 @ tag_set asn2 | Implicit ( t , _ ... |
let rec tag : type a . a -> a asn -> tag = fun a -> function | Iso ( _ , g , _ , asn ) -> tag ( g a ) asn | Fix _ as fix -> tag a fix | Sequence _ -> seq_tag | Sequence_of _ -> seq_tag | Set _ -> set_tag | Set_of _ -> set_tag | Choice ( a1 , a2 ) -> ( match a with L a ' -> tag a ' a1 | R b ' -> tag b ' a2 ) | Implicit ... |
type error = [ ` Parse of string ] |
let pp_error ppf ( ` Parse err ) = pf ppf " Parse error : % s " err |
let error err = raise ( Parse_error err ) |
let parse_error fmt = kstrf ( fun s -> error ( ` Parse s ) ) fmt |
module FSet = struct type f = Fn : ( ' a -> ' b ) -> f include Set . Make ( struct type t = f let compare ( Fn f1 ) ( Fn f2 ) = Hashtbl . ( compare ( hash f1 ) ( hash f2 ) ) end ) let mem f s = mem ( Fn f ) s and add f s = add ( Fn f ) s end |
let validate asn = let rec check : type a . ? tag : tag -> FSet . t -> a asn -> unit = fun ? tag fs -> function | Iso ( _ , _ , _ , a ) -> check ? tag fs a | Fix ( f , _ ) as fix -> if not ( FSet . mem f fs ) then check ? tag FSet . ( add f fs ) ( f fix ) | Sequence s -> disjoint_seq s ; check_s fs s | Set s -> disjoin... |
type t = Oid of int * int * int list |
let invalid_arg fmt = Format . ksprintf invalid_arg fmt |
let ( ) <| ( Oid ( v1 , v2 , vs ) ) vn = if vn < 0 then invalid_arg " OID . ( ) <|: negative component : % d " vn ; Oid ( v1 , v2 , vs @ [ vn ] ) |
let ( ) <|| ( Oid ( v1 , v2 , vs ) ) vs ' = let f v = if v < 0 then invalid_arg " OID . ( ) <||: negative component : % d " v in List . iter f vs ; Oid ( v1 , v2 , vs @ vs ' ) |
let base v1 v2 = match v1 with | 0 | 1 when v2 >= 0 && v2 < 40 -> Oid ( v1 , v2 , [ ] ) | 2 when v2 >= 0 -> Oid ( v1 , v2 , [ ] ) | _ -> invalid_arg " OID . base : out of range : % d . % d " v1 v2 |
let base_opt v1 v2 = try Some ( base v1 v2 ) with Invalid_argument _ -> None |
let to_nodes ( Oid ( v1 , v2 , vs ) ) = ( v1 , v2 , vs ) |
let of_nodes n1 n2 ns = try Some ( base n1 n2 <|| ns ) with Invalid_argument _ -> None |
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 compare x y with 0 -> cmp xs ys | r -> r in match compare v1 v1 ' with | 0 -> ( match compare v2 v... |
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 . max_int let to_nat_checked i64 = if i64 < 0L || i64 >... |
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 go acc i = function n when n >= 8 -> let ... |
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 " " , length ) end |
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 ( : 0 , 256 ) ( ) |> Cstruct . of_stri... |
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 && unused > 0 || unused > 7 the... |
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 . ( logor ( shift_left acc 7 ) ... |
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 ) , ( ( hh , mm , ss ) , tz ) ) = Ptime . to_date_time ~ tz_off... |
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 . ( int 10 ) r_asn asn | Iso ( f , _ , None , asn ) -> f @... |
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 , dies , compilation_unit_die , location_list... |
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 * ' a stmt list * ' a expr list * ' a | R... |
let name_of_mod = function | Module _ -> " Module " | Interactive _ -> " Interactive " | Expression _ -> " Expression " | Suite _ -> " Suite " | FunctionDef _ -> " FunctionDef " | ClassDef _ -> " ClassDef " | Return _ -> " Return " | Delete _ -> " Delete " | Assign _ -> " Assign " | AugAssign _ -> " AugAssign " | Print... |
let annot_of_mod = function | Module ( _ , a ) | Interactive ( _ , a ) | Expression ( _ , a ) | Suite ( _ , a ) -> a | FunctionDef ( _ , _ , _ , _ , a ) | ClassDef ( _ , _ , _ , _ , a ) | Return ( _ , a ) | Delete ( _ , a ) | Assign ( _ , _ , a ) | AugAssign ( _ , _ , _ , a ) | Print ( _ , _ , _ , a ) | For ( _ , _ , _... |
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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.