text
stringlengths
0
601k
let example1 ( ) = let buf = of_h { __ | 4c 56 28 00 00 01 00 00 00 01 00 00 07 45 78 41 6d 50 6c 45 03 63 6f 6d 00 00 06 00 01 03 66 6f 6f 07 65 78 61 6d 70 6c 65 c0 14 00 ff 00 ff 00 00 00 00 00 00 | __ } and now = 1506887742 . and mac = of_h { __ | 70 67 ae 70 9e fd 22 9e ce d9 65 25 8a db 8c 96 10 95 80 89 a7 ee 4f...
let example2 ( ) = let buf = of_h { __ | 76 8a 28 00 00 01 00 00 00 01 00 00 07 65 78 61 6d 70 6c 65 00 00 06 00 01 03 66 6f 6f c0 0c 00 ff 00 ff 00 00 00 00 00 00 | __ } and now = 1506888104 . and mac = of_h { __ | e7 76 e6 df 4e 73 14 c8 eb ba 4c c7 a5 39 b3 93 a7 df 6d de 47 b6 fa cc 81 c8 47 29 20 77 40 44 | __ } i...
let tsig_tests = [ " example0 " , ` Quick , example0 ; " example1 " , ` Quick , example1 ; " example2 " , ` Quick , example2 ; ]
let tests = [ " Tsig example " , tsig_tests ; ]
let ( ) = Alcotest . run " DNS name tests " tests
let string_of_location loc = let buf = Buffer . create 64 in let fmt = Format . formatter_of_buffer buf in Location . print_loc fmt loc ; Format . pp_print_flush fmt ( ) ; Buffer . contents buf
let no_such_variable loc name = let locstr = string_of_location loc in Printf . eprintf " % s \ nNo such variable % s \ n " %! locstr name ; exit 2
let no_such_modifiers loc name = let locstr = string_of_location loc in Printf . eprintf " % s \ nNo such modifiers % s \ n " %! locstr name ; exit 2
let apply_modifiers env modifiers_name = let name = modifiers_name . node in let modifier = Environments . Include name in try Environments . apply_modifier env modifier with | Environments . Modifiers_name_not_found name -> no_such_modifiers modifiers_name . loc name
let rec add_to_env decl loc variable_name value env = match ( Variables . find_variable variable_name , decl ) with | ( None , true ) -> let newvar = Variables . make ( variable_name , " User variable " ) in Variables . register_variable newvar ; add_to_env false loc variable_name value env | ( Some variable , false ) ...
let append_to_env loc variable_name value env = let variable = match Variables . find_variable variable_name with | None -> raise ( Variables . No_such_variable variable_name ) | Some variable -> variable in try Environments . append variable value env with Variables . No_such_variable name -> no_such_variable loc name
let interprete_environment_statement env statement = match statement . node with | Assignment ( decl , var , value ) -> add_to_env decl statement . loc var . node value . node env | Append ( var , value ) -> append_to_env statement . loc var . node value . node env | Include modifiers_name -> apply_modifiers env modifi...
let interprete_environment_statements env l = List . fold_left interprete_environment_statement env l
type test_tree = | Node of ( Tsl_ast . environment_statement located list ) * Tests . t * string located list * ( test_tree list )
let too_deep testname max_level real_level = Printf . eprintf " Test % s should have depth atmost % d but has depth % d \ n " %! testname max_level real_level ; exit 2
let unexpected_environment_statement s = let locstr = string_of_location s . loc in Printf . eprintf " % s \ nUnexpected environment statement \ n " %! locstr ; exit 2
let no_such_test_or_action t = let locstr = string_of_location t . loc in Printf . eprintf " % s \ nNo such test or action : % s \ n " %! locstr t . node ; exit 2
let test_trees_of_tsl_block tsl_block = let rec env_of_lines = function | [ ] -> ( [ ] , [ ] ) | Environment_statement s :: lines -> let ( env ' , remaining_lines ) = env_of_lines lines in ( s :: env ' , remaining_lines ) | lines -> ( [ ] , lines ) and tree_of_lines depth = function | [ ] -> ( None , [ ] ) | line :: re...
let rec tests_in_tree_aux set = function Node ( _ , test , _ , subtrees ) -> let set ' = List . fold_left tests_in_tree_aux set subtrees in Tests . TestSet . add test set '
let tests_in_tree t = tests_in_tree_aux Tests . TestSet . empty t
let tests_in_trees subtrees = List . fold_left tests_in_tree_aux Tests . TestSet . empty subtrees
let actions_in_test test = let add action_set action = Actions . ActionSet . add action action_set in List . fold_left add Actions . ActionSet . empty test . Tests . test_actions
let actions_in_tests tests = let f test action_set = Actions . ActionSet . union ( actions_in_test test ) action_set in Tests . TestSet . fold f tests Actions . ActionSet . empty
module T = Transport inherit T . t val mutable chans = None method isOpen = chans != None method opn = try let addr = ( let { Unix . h_addr_list = x } = Unix . gethostbyname host in x . ( 0 ) ) in chans <- Some ( Unix . open_connection ( Unix . ADDR_INET ( addr , port ) ) ) with Unix . Unix_error ( e , fn , _ ) -> rais...
type ' a entry = { node : ' a ; mutable pred_count : int ; mutable successors : ' a entry list }
type ' a porder = ' a entry list ref
let find_entry order node = let rec search_entry = function [ ] -> raise Not_found | x :: l -> if x . node = node then x else search_entry l in try search_entry ! order with Not_found -> let entry = { node = node ; pred_count = 0 ; successors = [ ] } in order := entry ::! order ; entry
let create ( ) = ref [ ]
let add_relation order ( succ , pred ) = let pred_entry = find_entry order pred and succ_entry = find_entry order succ in succ_entry . pred_count <- succ_entry . pred_count + 1 ; pred_entry . successors <- succ_entry :: pred_entry . successors
let add_element order e = ignore ( find_entry order e )
let sort order = let q = Queue . create ( ) and result = ref [ ] in List . iter ! order ~ f ( : function { pred_count = n } as node -> if n = 0 then Queue . add node q ) ; begin try while true do let t = Queue . take q in result := t . node :: ! result ; List . iter t . successors ~ f : begin fun s -> let n = s . pred_...
module Literal = struct type t = | String of string | Int of int | Float of float end
module Enum = struct type t = ( string * Literal . t ) list end
module type S = sig type ident type field_def = | Single of { optional : bool ; typ : typ } | Pattern of { pat : typ ; typ : typ } and field = field_def Named . t and typ = | Literal of Literal . t | Ident of ident | Sum of typ list | List of typ | Record of field list | Tuple of typ list | App of typ * typ and interfa...
module Make ( Ident : sig type t struct type field_def = | Single of { optional : bool ; typ : typ } | Pattern of { pat : typ ; typ : typ } and field = field_def Named . t and typ = | Literal of Literal . t | Ident of Ident . t | Sum of typ list | List of typ | Record of field list | Tuple of typ list | App of typ * ty...
module Unresolved = struct include Make ( String ) let enum ~ name ~ constrs : Enum . t Named . t = { Named . name ; data = constrs } let interface ~ name ~ extends ~ fields ~ params : interface Named . t = { Named . name ; data = { extends ; fields ; params } } let pattern_field ~ name ~ pat ~ typ = { Named . name ; d...
module type Prim_intf = sig type resolved type t = | Null | String | Bool | Number | Any | Object | List | Self | Resolved of resolved val of_string : string -> resolve ( : string -> t ) -> t end
module Prim_make ( Resolved : sig type t struct type t = | Null | String | Bool | Number | Any | Object | List | Self | Resolved of Resolved . t let of_string s ~ resolve = match String . lowercase_ascii s with | " null " -> Null | " string " -> String | " boolean " -> Bool | " number " -> Number | " any " -> Any | " a...
module rec Resolved : ( S with type ident := Prim . t ) = Make ( Prim )
let subst unresolved = object val params = String . Map . empty val inside = None method inside s = { < inside = Some s } > method resolve n = match String . Map . find params n with | Some [ ] -> assert false | Some ( x :: _ ) -> ` Resolved x | None -> if inside = Some n then ` Self else ` Unresolved ( String . Map . ...
let rec resolve_all ts ( ~ names : Unresolved . t String . Map . t ) : Resolved . t list = let names = subst names in List . map ts ~ f ( : resolve ~ names ) let data : Resolved . decl = match t . data with | Interface i -> Interface ( resolve_interface { t with data = i } ~ names ) | Type t -> Type ( resolve_type t ~ ...
type pattern = { p_node : pattern_node ; p_ty : ty ; p_loc : Location . t option ; [ @ printer fun fmt _ -> fprintf fmt " < Location . t " ] > } | Pwild | Pvar of vsymbol | Papp of lsymbol * pattern list | Por of pattern * pattern | Pas of pattern * vsymbol | Pinterval of char * char [ @ printer fun fmt ( c1 , c2 ) -> ...
type binop = Tand | Tand_asym | Tor | Tor_asym | Timplies | Tiff
type quant = Tforall | Texists | Tlambda [ @@ deriving show ]
type term = { t_node : term_node ; t_ty : ty option ; t_attrs : string list ; t_loc : Location . t ; [ @ printer fun fmt _ -> fprintf fmt " < Location . t " ] > } | Tvar of vsymbol | Tconst of constant [ @ printer fun fmt _ -> fprintf fmt " < constant " ] > | Tapp of lsymbol * term list | Tfield of term * lsymbol | Tif...
let rec p_vars p = match p . p_node with | Pwild | Pconst _ | Pinterval _ -> Svs . empty | Pvar vs -> Svs . singleton vs | Papp ( _ , pl ) -> List . fold_left ( fun vsl p -> Svs . union ( p_vars p ) vsl ) Svs . empty pl | Por ( p1 , p2 ) -> Svs . union ( p_vars p1 ) ( p_vars p2 ) | Pas ( p , vs ) -> Svs . add vs ( p_va...
let rec t_free_vars t = match t . t_node with | Tvar vs -> Svs . singleton vs | Tconst _ -> Svs . empty | Tapp ( _ , tl ) -> List . fold_left ( fun fvs t -> Svs . union ( t_free_vars t ) fvs ) Svs . empty tl | Tfield ( t , _ ) -> t_free_vars t | Tif ( t1 , t2 , t3 ) -> Svs . union ( t_free_vars t1 ) ( Svs . union ( t_f...
let t_free_vs_in_set svs t = let diff = Svs . diff ( t_free_vars t ) svs in if not ( Svs . is_empty diff ) then W . error ~ loc : t . t_loc ( W . Free_variables ( Svs . elements diff |> List . map ( fun vs -> vs . vs_name . id_str ) ) )
let t_prop t = if t . t_ty = None then t else W . error ~ loc : t . t_loc W . Formula_expected
let t_type t = match t . t_ty with | Some ty -> ty | None -> W . error ~ loc : t . t_loc W . Formula_expected
let t_ty_check t ty = match ( ty , t . t_ty ) with | Some l , Some r -> ty_equal_check l r | Some _ , None -> W . error ~ loc : t . t_loc W . Term_expected | None , Some _ -> W . error ~ loc : t . t_loc W . Formula_expected | None , None -> ( )
let ls_arg_inst ls tl = try List . fold_left2 ( fun tvm ty t -> ty_match tvm ty ( t_type t ) ) Mtv . empty ls . ls_args tl with Invalid_argument _ -> let loc = ( List . hd tl ) . t_loc in W . error ~ loc ( W . Bad_arity ( ls . ls_name . id_str , List . length ls . ls_args , List . length tl ) )
let ls_app_inst ls tl ty = let s = ls_arg_inst ls tl in match ( ls . ls_value , ty ) with | Some _ , None -> W . error ~ loc : Location . none ( W . Predicate_symbol_expected ls . ls_name . id_str ) | None , Some _ -> W . error ~ loc : Location . none ( W . Function_symbol_expected ls . ls_name . id_str ) | Some vty , ...
let mk_pattern p_node p_ty = { p_node ; p_ty ; p_loc = None }
let p_wild ty = mk_pattern Pwild ty
let p_var vs = mk_pattern ( Pvar vs ) vs . vs_ty
let p_app ls pl ty = mk_pattern ( Papp ( ls , pl ) ) ty
let p_or p1 p2 = mk_pattern ( Por ( p1 , p2 ) ) p1 . p_ty
let p_as p vs = mk_pattern ( Pas ( p , vs ) ) p . p_ty
let p_interval c1 c2 = mk_pattern ( Pinterval ( c1 , c2 ) ) ty_char
let p_const c = match c with | Pconst_integer _ -> mk_pattern ( Pconst c ) ty_int | Pconst_char _ -> mk_pattern ( Pconst c ) ty_char | Pconst_string _ -> mk_pattern ( Pconst c ) ty_string | Pconst_float _ -> mk_pattern ( Pconst c ) ty_float
let mk_term t_node t_ty t_loc = { t_node ; t_ty ; t_attrs = [ ] ; t_loc }
let t_var vs = mk_term ( Tvar vs ) ( Some vs . vs_ty )
let t_const c ty = mk_term ( Tconst c ) ( Some ty )
let t_app ls tl ty = ignore ( ls_app_inst ls tl ty : ty Mtv . t ) ; mk_term ( Tapp ( ls , tl ) ) ty
let t_field t ls ty = ignore ( ls_app_inst ls [ t ] ty : ty Mtv . t ) ; mk_term ( Tfield ( t , ls ) ) ty
let t_if t1 t2 t3 = mk_term ( Tif ( t1 , t2 , t3 ) ) t2 . t_ty
let t_let vs t1 t2 = mk_term ( Tlet ( vs , t1 , t2 ) ) t2 . t_ty
let t_case t1 ptl = match ptl with | [ ] -> assert false | ( _ , t ) :: _ -> mk_term ( Tcase ( t1 , ptl ) ) t . t_ty
let t_quant q vsl t ty = mk_term ( Tquant ( q , vsl , t ) ) ty
let t_binop b t1 t2 = mk_term ( Tbinop ( b , t1 , t2 ) ) None
let t_not t = mk_term ( Tnot t ) None
let t_old t = mk_term ( Told t ) t . t_ty
let t_true = mk_term Ttrue None
let t_false = mk_term Tfalse None
let t_attr_set attr t = { t with t_attrs = attr }
let t_bool_true = mk_term ( Tapp ( fs_bool_true , [ ] ) ) ( Some ty_bool )
let t_bool_false = mk_term ( Tapp ( fs_bool_false , [ ] ) ) ( Some ty_bool )
let t_equ t1 t2 = t_app ps_equ [ t1 ; t2 ] None
let t_neq t1 t2 loc = t_not ( t_equ t1 t2 loc )
let f_binop op f1 f2 = t_binop op ( t_prop f1 ) ( t_prop f2 )
let f_not f = t_not ( t_prop f )
let t_quant q vsl t ty loc = match ( q , vsl ) with | Tlambda , [ ] -> t | _ , [ ] -> t_prop t | Tlambda , _ -> t_quant q vsl t ty loc | _ , _ -> if ty <> None then W . error ~ loc W . Formula_expected ; t_quant q vsl ( t_prop t ) None loc
let f_forall = t_quant Tforall
let f_exists = t_quant Texists
let t_lambda = t_quant Tlambda
let f_and = f_binop Tand
let f_and_asym = f_binop Tand_asym
let f_or = f_binop Tor
let f_or_asym = f_binop Tor_asym
let f_implies = f_binop Timplies
let f_iff = f_binop Tiff
let print_vs fmt { vs_name ; vs_ty } = pp fmt " [ @% a :% a ] " @ Ident . pp vs_name print_ty vs_ty
let print_ls_decl fmt { ls_name ; ls_args ; ls_value ; _ } = let is_func = Option . is_some ls_value in let print_unnamed_arg fmt ty = pp fmt " ( _ :% a ) " print_ty ty in pp fmt " % s % a % a % s % a " ( if is_func then " function " else " predicate " ) Ident . pp ls_name ( list ~ sep : sp print_unnamed_arg ) ls_args ...
let print_ls_nm fmt { ls_name ; _ } = pp fmt " % a " Ident . pp ls_name
let protect_on x s = if x then " ( " ^^ s ^^ " ) " else s
let rec print_pat_node pri fmt p = match p . p_node with | Pwild -> pp fmt " _ " | Pvar v -> print_vs fmt v | Pas ( p , v ) -> pp fmt ( protect_on ( pri > 1 ) " % a as % a " ) ( print_pat_node 1 ) p print_vs v | Por ( p , q ) -> pp fmt ( protect_on ( pri > 0 ) " % a | % a " ) ( print_pat_node 0 ) p ( print_pat_node 0 )...
let print_pattern = print_pat_node 0
let print_binop fmt = function | Tand -> pp fmt " " /\\ | Tor -> pp fmt " " \\/ | Timplies -> pp fmt " " -> | Tiff -> pp fmt " " <-> | Tand_asym -> pp fmt " " && | Tor_asym -> pp fmt " " ||
let print_quantifier fmt = function | Tforall -> pp fmt " forall " | Texists -> pp fmt " exists " | Tlambda -> pp fmt " fun "