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 bb 13 81 e7 38 e3 a0 78 80 | __ } in Alcotest . ( check cs " tsig is the same " mac ( Dns_tsig . compute_tsig key_name ( tsig Dns . Tsig . SHA256 now ) ~ key buf ) )
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 | __ } in Alcotest . ( check cs " tsig is the same " mac ( Dns_tsig . compute_tsig key_name ( tsig Dns . Tsig . SHA256 now ) ~ key buf ) )
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 ) -> Environments . add variable value env | ( None , false ) -> raise ( Variables . No_such_variable variable_name ) | ( Some _ , true ) -> raise ( Variables . Variable_already_registered variable_name )
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 modifiers_name
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 :: remaining_lines as l -> begin match line with | Environment_statement s -> unexpected_environment_statement s | Test ( test_depth , located_name , env_modifiers ) -> begin let name = located_name . node in if test_depth > depth then too_deep name depth test_depth else if test_depth < depth then ( None , l ) else let ( env , rem ) = env_of_lines remaining_lines in let ( trees , rem ) = trees_of_lines ( depth + 1 ) rem in match Tests . lookup name with | None -> begin match Actions . lookup name with | None -> no_such_test_or_action located_name | Some action -> let test = Tests . test_of_action action in ( Some ( Node ( env , test , env_modifiers , trees ) ) , rem ) end | Some test -> ( Some ( Node ( env , test , env_modifiers , trees ) ) , rem ) end end and trees_of_lines depth lines = let remaining_lines = ref lines in let trees = ref [ ] in let continue = ref true in while ! continue ; do let ( tree , rem ) = tree_of_lines depth ! remaining_lines in remaining_lines := rem ; match tree with | None -> continue := false | Some t -> trees := t :: ! trees done ; ( List . rev ! trees , ! remaining_lines ) in let ( env , rem ) = env_of_lines tsl_block in let ( trees , rem ) = trees_of_lines 1 rem in match rem with | [ ] -> ( env , trees ) | ( Environment_statement s ) :: _ -> unexpected_environment_statement s | _ -> assert false
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 , _ ) -> raise ( T . E ( T . NOT_OPEN , ( " TSocket : Could not connect to " ^ host " " ( ^:^ string_of_int port ) " ^ because : " ^ fn " " ( ^:^ Unix . error_message e ) ) ) ) | _ -> raise ( T . E ( T . NOT_OPEN , ( " TSocket : Could not connect to " ^ host " " ( ^:^ string_of_int port ) ) ) ) method close = match chans with None -> ( ) | Some ( inc , out ) -> ( Unix . shutdown_connection inc ; close_in inc ; chans <- None ) method read buf off len = match chans with None -> raise ( T . E ( T . NOT_OPEN , " TSocket : Socket not open " ) ) | Some ( i , o ) -> try really_input i buf off len ; len with Unix . Unix_error ( e , fn , _ ) -> raise ( T . E ( T . UNKNOWN , ( " TSocket : Could not read " ( ^ string_of_int len ) " ^ from " ^ host " " ( ^:^ string_of_int port ) " ^ because : " ^ fn " " ( ^:^ Unix . error_message e ) ) ) ) | _ -> raise ( T . E ( T . UNKNOWN , ( " TSocket : Could not read " ( ^ string_of_int len ) " ^ from " ^ host " " ( ^:^ string_of_int port ) ) ) ) method write buf off len = match chans with None -> raise ( T . E ( T . NOT_OPEN , " TSocket : Socket not open " ) ) | Some ( i , o ) -> output o buf off len method write_string buf off len = match chans with None -> raise ( T . E ( T . NOT_OPEN , " TSocket : Socket not open " ) ) | Some ( i , o ) -> output_substring o buf off len method flush = match chans with None -> raise ( T . E ( T . NOT_OPEN , " TSocket : Socket not open " ) ) | Some ( i , o ) -> flush o end
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_count - 1 in s . pred_count <- n ; if n = 0 then Queue . add s q end done with Queue . Empty -> List . iter ! order ~ f ( : fun node -> if node . pred_count <> 0 then raise Cyclic ) end ; ! result
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 interface = { extends : ident list ; fields : field list ; params : string list } and decl = | Interface of interface | Type of typ | Enum_anon of Enum . t and t = decl Named . t class map : object method typ : typ -> typ method interface : interface -> interface method field : field -> field method t : t -> t end class [ ' a ] fold : object method field : field -> init ' : a -> ' a method ident : ident -> init ' : a -> ' a method t : t -> init ' : a -> ' a method typ : typ -> init ' : a -> ' a end end
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 * typ and interface = { extends : Ident . t list ; fields : field list ; params : string list } and decl = | Interface of interface | Type of typ | Enum_anon of Enum . t and t = decl Named . t class [ ' a ] fold = object ( self ) method t ( t : t ) ~ init = match t . data with | Interface ( i : interface ) -> let init = List . fold_left i . extends ~ init ~ f ( : fun acc e -> self # ident e ~ init : acc ) in List . fold_left ~ init i . fields ~ f ( : fun init f -> self # field f ~ init ) | Type ( t : typ ) -> self # typ t ~ init | Enum_anon _ -> init method ident _ ~ init = init method field ( f : field ) ~ init : ' a = match f . data with | Single { optional = _ ; typ } -> self # typ ~ init typ | Pattern { pat ; typ } -> let init = self # typ ~ init pat in self # typ ~ init typ method typ ( t : typ ) ~ init = match t with | Literal _ -> init | Ident i -> self # ident i ~ init | App ( t1 , t2 ) -> let init = self # typ t1 ~ init in self # typ t2 ~ init | List t -> self # typ t ~ init | Tuple typs | Sum typs -> List . fold_left typs ~ init ~ f ( : fun init f -> self # typ f ~ init ) | Record fs -> List . fold_left fs ~ init ~ f ( : fun init f -> self # field f ~ init ) end class map = object ( self ) method field ( f : field ) = let data = match f . data with | Single s -> let typ = self # typ s . typ in Single { s with typ } | Pattern { pat ; typ } -> let pat = self # typ pat in let typ = self # typ typ in Pattern { pat ; typ } in { f with data } method interface ( i : interface ) = let fields = List . map ~ f : self # field i . fields in { i with fields } method typ ( t : typ ) = match t with | Literal i -> Literal i | Ident i -> Ident i | App ( x , y ) -> let x = self # typ x and y = self # typ y in App ( x , y ) | List t -> List ( self # typ t ) | Tuple ts -> Tuple ( List . map ts ~ f : self # typ ) | Sum ts -> Sum ( List . map ts ~ f : self # typ ) | Record ts -> Record ( List . map ts ~ f : self # field ) method t ( t : t ) = let data = match t . data with | Interface i -> Interface ( self # interface i ) | Type t -> Type ( self # typ t ) | Enum_anon _ -> t . data in { t with data } end end
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 ; data = Pattern { pat ; typ } } let named_field ( ? optional = false ) typ name = { Named . name ; data = Single { optional ; typ } } end
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 | " array " -> List | " object " -> Object | _ -> resolve s end
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 . find_exn unresolved n ) method push x y = let params = String . Map . update params x ~ f ( : function | None -> Some [ y ] | Some [ ] -> assert false | Some ( y ' :: xs ) -> if y = y ' then Some xs else Some ( y :: y ' :: xs ) ) in { < params } > method pop x = let params = String . Map . update params x ~ f ( : function | None -> ignore ( String . Map . find_exn params x ) ; None | Some [ ] -> assert false | Some ( _ :: xs ) -> Some xs ) in { < params } > end
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 ~ names ) | Enum_anon a -> Enum_anon a in { t with Named . data } Prim . of_string i ~ resolve ( : fun s -> match names # resolve s with | ` Resolved s -> s | ` Self -> Self | ` Unresolved s -> Resolved ( resolve s ~ names ) ) match t with | Literal l -> Literal l | Ident i -> Ident ( resolve_ident ~ names i ) | Sum l -> Sum ( List . map ~ f ( : resolve_type ~ names ) l ) | Tuple l -> Tuple ( List . map ~ f ( : resolve_type ~ names ) l ) | App ( f , x ) -> App ( resolve_type ~ names f , resolve_type ~ names x ) | List t -> List ( resolve_type t ~ names ) | Record fields -> Record ( List . map ~ f ( : resolve_field ~ names ) fields ) let names = names # inside i . name in let i = i . data in { extends = List . map ~ f ( : resolve_ident ~ names ) i . extends ; params = i . params ; fields = ( let names = List . fold_left ~ init : names i . params ~ f ( : fun acc x -> acc # push x Prim . Any ) in List . map ~ f ( : resolve_field ~ names ) i . fields ) } let data : Resolved . field_def = match f . data with | Single { optional ; typ } -> let typ = resolve_type ~ names typ in Single { optional ; typ } | Pattern { pat ; typ } -> let typ = resolve_type ~ names typ in let pat = resolve_type ~ names pat in Pattern { pat ; typ } in { f with Named . data }
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 ) -> fprintf fmt " % C . . % C " c1 c2 ] | Pconst of constant [ @ printer fun fmt cc -> let t , v = match cc with | Pconst_integer ( s , _ ) -> ( " integer " , s ) | Pconst_char c -> ( " char " , Format . sprintf " % C " c ) | Pconst_string ( s , _ , _ ) -> ( " string " , Format . sprintf " % S " s ) | Pconst_float ( s , _ ) -> ( " float " , s ) in fprintf fmt " < const_ % s : % s " > t v ]
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 of term * term * term | Tlet of vsymbol * term * term | Tcase of term * ( pattern * term ) list | Tquant of quant * vsymbol list * term | Tbinop of binop * term * term | Tnot of term | Told of term | Ttrue | Tfalse
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_vars p )
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_free_vars t2 ) ( t_free_vars t3 ) ) | Tlet ( vs , t1 , t2 ) -> let t1_fvs , t2_fvs = ( t_free_vars t1 , t_free_vars t2 ) in Svs . union t1_fvs ( Svs . remove vs t2_fvs ) | Tcase ( t , pl ) -> let t_fvs = t_free_vars t in let pl_fvs = List . fold_left ( fun _ ( p , t ) -> Svs . diff ( t_free_vars t ) ( p_vars p ) ) Svs . empty pl in Svs . union t_fvs pl_fvs | Tquant ( _ , vl , t ) -> Svs . diff ( t_free_vars t ) ( Svs . of_list vl ) | Tbinop ( _ , t1 , t2 ) -> Svs . union ( t_free_vars t1 ) ( t_free_vars t2 ) | Tnot t -> t_free_vars t | Told t -> t_free_vars t | Ttrue -> Svs . empty | Tfalse -> Svs . empty
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 , Some ty -> ty_match s vty ty | None , None -> s
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 ( if is_func then " : " else " " ) ( option print_ty ) ls_value
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 ) q | Papp ( cs , pl ) when is_fs_tuple cs -> pp fmt ( protect_on ( pri > 0 ) " % a " ) ( list ~ sep : comma ( print_pat_node 1 ) ) pl | Papp ( cs , [ ] ) -> print_ls_nm fmt cs | Papp ( cs , [ pl ] ) -> pp fmt " % a @ % a " print_ls_nm cs ( print_pat_node 2 ) pl | Papp ( cs , pl ) -> pp fmt " % a @ ( % a ) " print_ls_nm cs ( list ~ sep : comma ( print_pat_node 2 ) ) pl | Pconst c -> Opprintast . constant fmt c | Pinterval ( c1 , c2 ) -> pp fmt " % C . . % C " c1 c2
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 "