text stringlengths 12 786k |
|---|
let lookup_module name env = let path , md = Env . find_module_by_name name env in path , md . Types . md_type , md . Types . md_attributes |
let verbosity = ref 0 |
module Printtyp = struct include Printtyp let expand_type env ty = Env . with_cmis @@ fun ( ) -> if ! verbosity = 0 then ty else let ty = Subst . type_expr Subst . identity ty in let marks = Hashtbl . create 7 in let mark ty = if Hashtbl . mem marks ty . Types . id then false else ( Hasht... |
let rec mod_smallerthan n m = if n < 0 then None else let open Types in match m with | Mty_ident _ -> Some 1 | Mty_signature s -> begin match List . length_lessthan n s with | None -> None | Some _ -> List . fold_left s ~ init ( : Some 0 ) ~ f : begin fun acc item -> let sub n1 m = match mo... |
let print_short_modtype verbosity env ppf md = match mod_smallerthan 1000 md with | None when verbosity = 0 -> Format . pp_print_string ppf " " ; | _ -> Printtyp . modtype env ppf md |
let print_type_with_decl ~ verbosity env ppf typ = if verbosity > 0 then match ( Ctype . repr typ ) . Types . desc with | Types . Tconstr ( path , params , _ ) -> let decl = Env . with_cmis @@ fun ( ) -> Env . find_type path env in let is_abstract = match decl . Types . type_k... |
let print_exn ppf exn = match Location . error_of_exn exn with | None | Some ` Already_displayed -> Format . pp_print_string ppf ( Printexc . to_string exn ) | Some ( ` Ok report ) -> Location . print_main ppf report |
let print_type ppf env lid = let p , t = Env . find_type_by_name lid . Asttypes . txt env in Printtyp . type_declaration env ( Ident . create_persistent ( Path . last p ) ) ppf t |
let print_modtype ppf verbosity env lid = let _p , mtd = Env . find_modtype_by_name lid . Asttypes . txt env in match mtd . mtd_type with | Some mt -> print_short_modtype verbosity env ppf mt | None -> Format . pp_print_string ppf " " |
let print_modpath ppf verbosity env lid = let _path , md = Env . find_module_by_name lid . Asttypes . txt env in print_short_modtype verbosity env ppf ( md . md_type ) |
let print_constr ppf env lid = let cstr_desc = Env . find_constructor_by_name lid . Asttypes . txt env in ! Oprint . out_type ppf ( Browse_misc . print_constructor cstr_desc ) |
let type_in_env ( ? verbosity = 0 ) ? keywords ~ context env ppf expr = let print_expr expression = let ( str , _sg , _ ) = Env . with_cmis @@ fun ( ) -> Typemod . type_toplevel_phrase env [ Ast_helper . Str . eval expression ] in let open Typedtree in let exp = Raw_compat . d... |
let read_doc_attributes attrs = let rec loop = function | ( { Location . txt = ( " doc " | " ocaml . doc " ) ; loc = _ } , payload ) :: _ -> Ast_helper . extract_str_payload payload | _ :: rest -> loop rest | [ ] -> None in loop ( List . map ~ f : Ast_helper . A... |
let is_deprecated = List . exists ~ f ( : fun ( attr : Parsetree . attribute ) -> match Ast_helper . Attr . as_tuple attr with | { Location . txt = ( " deprecated " | " ocaml . deprecated " ) ; loc = _ } , _ -> true | _ -> false ) |
module List = struct let map t ~ f = List . rev ( List . rev_map f t ) end |
module Make ( Pos : sig type t val sexp_of_t : t -> Type . t end ) = struct module T = struct type t = | Atom of Pos . t * string * string option | List of Pos . t * t_or_comment list * Pos . t and t_or_comment = | Sexp of t | Comment of comment and comment = | Plain_comment of Pos . t *... |
module Parsed = Make ( Src_pos . Absolute ) |
let relativize = let rel ~ outer_p p = Src_pos . Absolute . diff p outer_p in let rec aux_t ~ outer_p = function | Parsed . Atom ( pos , s , sopt ) -> Atom ( rel pos ~ outer_p , s , sopt ) | Parsed . List ( start_pos , tocs , end_pos ) -> List ( rel start_pos ~ outer_p , L... |
let find_value loc f = try find_value f with Not_found -> error loc ( Eglobal_undefined ( Value , f ) ) |
let find_type loc f = try find_type f with Not_found -> error loc ( Eglobal_undefined ( Type , f ) ) |
let find_constr loc c = try find_constr c with Not_found -> error loc ( Eglobal_undefined ( Constr , c ) ) |
let find_label loc l = try find_label l with Not_found -> error loc ( Eglobal_undefined ( Label , l ) ) |
let unify loc expected_ty actual_ty = try Ztypes . unify expected_ty actual_ty with | Ztypes . Unify -> error loc ( Etype_clash ( actual_ty , expected_ty ) ) |
let equal_sizes loc expected_size actual_size = try Ztypes . equal_sizes expected_size actual_size with | Ztypes . Unify -> error loc ( Esize_clash ( actual_size , expected_size ) ) |
let unify_expr expr expected_ty actual_ty = try Ztypes . unify expected_ty actual_ty with | Ztypes . Unify -> error expr . e_loc ( Etype_clash ( actual_ty , expected_ty ) ) |
let unify_pat pat expected_ty actual_ty = try Ztypes . unify expected_ty actual_ty with | Ztypes . Unify -> error pat . p_loc ( Etype_clash ( actual_ty , expected_ty ) ) |
let less_than loc actual_k expected_k = try Ztypes . less_than actual_k expected_k with | Ztypes . Unify -> error loc ( Ekind_clash ( actual_k , expected_k ) ) |
let type_is_in_kind loc expected_k ty = try Ztypes . kind expected_k ty with | Ztypes . Unify -> error loc ( Etype_kind_clash ( expected_k , ty ) ) |
let lift loc left_k right_k = try Ztypes . lift left_k right_k with | Ztypes . Unify -> error loc ( Ekind_clash ( right_k , left_k ) ) |
let sort_less_than loc sort expected_k = match expected_k , sort with | Tstatic _ , Sstatic -> ( ) | Tstatic _ , _ -> error loc ( Ekind_clash ( Deftypes . Tany , expected_k ) ) | _ -> ( ) |
let check_is_vec loc actual_ty = try let ty_arg , size = Ztypes . filter_vec actual_ty in ty_arg , size with | Ztypes . Unify -> error loc Esize_of_vec_is_undetermined |
let rec expansive { e_desc = desc } = match desc with | Elocal _ | Eglobal _ | Econst _ | Econstr0 _ -> false | Etuple ( e_list ) -> List . exists expansive e_list | Erecord ( l_e_list ) -> List . exists ( fun ( _ , e ) -> expansive e ) l_e_list | Erecord_access ( e , _ ... |
let check_statefull loc expected_k = if not ( Ztypes . is_statefull_kind expected_k ) then error loc Ekind_not_combinatorial |
type state = { mutable s_reset : bool option ; s_parameters : typ list } |
let check_target_state loc expected_reset actual_reset = match expected_reset with | None -> Some ( actual_reset ) | Some ( expected_reset ) -> if expected_reset <> actual_reset then warning loc ( Wreset_target_state ( actual_reset , expected_reset ) ) ; Some ( expected_reset ) |
let turn_vars_into_memories h { dv = dv } = let add n acc = let ( { t_sort = sort ; t_typ = typ } as tentry ) = Env . find n h in match sort with | Smem ( { m_init = Noinit } as m ) -> Env . add n { tentry with t_sort = Smem { m with m_init = InitEq } } acc | Sstatic | Sva... |
let immediate = function | Ebool _ -> Initial . typ_bool | Eint ( i ) -> Initial . typ_int | Efloat ( i ) -> Initial . typ_float | Echar ( c ) -> Initial . typ_char | Estring ( c ) -> Initial . typ_string | Evoid -> Initial . typ_unit |
let incorporate_into_env first_h h = let mark n { t_sort = sort } = let tentry = Env . find n h in match sort with | Smem ( { m_init = InitEq } as m ) -> tentry . t_sort <- Smem { m with m_init = Noinit } | _ -> ( ) in Env . iter mark first_h |
let vars pat = Vars . fv_pat S . empty S . empty pat |
let var loc h n = try Env . find n h with Not_found -> error loc ( Evar_undefined ( n ) ) |
let typ_of_var loc h n = let { t_typ = typ } = var loc h n in typ |
let last loc h n = let { t_sort = sort ; t_typ = typ } as entry = var loc h n in begin match sort with | Sstatic | Sval | Svar _ | Smem { m_next = Some ( true ) } -> | Smem ( m ) -> entry . t_sort <- Smem { m with m_previous = true } end ; typ |
let derivative loc h n = let { t_typ = typ ; t_sort = sort } as entry = var loc h n in match sort with | Sstatic | Sval | Svar _ -> | Smem ( m ) -> entry . t_sort <- Smem { m with m_kind = Some ( Cont ) } ; typ |
let pluseq loc h n = let ( { t_typ = typ ; t_sort = sort } as entry ) = var loc h n in match sort with | Svar { v_combine = Some _ } -> typ | Sstatic | Sval | Svar { v_combine = None } | Smem { m_combine = None } -> error loc ( Ecombination_function ( n ) ) | Smem ( { m... |
let init loc h n = let { t_typ = typ ; t_sort = sort } as entry = var loc h n in match sort with | Sstatic | Sval | Svar _ -> assert false | Smem ( { m_init = i } as m ) -> match i with | Noinit -> entry . t_sort <- Smem { m with m_init = InitEq } ; typ | InitEq -> typ | InitDec... |
let next loc h n = let { t_typ = typ ; t_sort = sort } as entry = var loc h n in match sort with | Sstatic | Sval | Svar _ -> assert false | Smem { m_previous = true } -> error loc ( Enext_forbidden ( n ) ) | Smem ( { m_next = n_opt } as m ) -> match n_opt with | None -> entry... |
let def loc h n = let { t_sort = sort } as entry = var loc h n in match sort with | Sstatic | Sval | Svar _ -> ( ) | Smem ( { m_next = n_opt } as m ) -> match n_opt with | None -> entry . t_sort <- Smem { m with m_next = Some ( false ) } | Some ( false ) -> ( ) | Some... |
let global loc expected_k lname = let { qualid = qualid ; info = { value_static = is_static ; value_typ = tys } } = find_value loc lname in less_than loc ( if is_static then Tstatic true else expected_k ) expected_k ; qualid , Ztypes . instance_of_type tys |
let global_with_instance loc expected_k lname = let { qualid = qualid ; info = { value_static = is_static ; value_typ = tys } } = find_value loc lname in less_than loc ( if is_static then Tstatic true else expected_k ) expected_k ; let typ_instance , typ_body = Ztypes . instance_and_vars_of... |
let label loc l = let { qualid = qualid ; info = tys_label } = find_label loc l in qualid , Ztypes . label_instance tys_label |
let constr loc c = let { qualid = qualid ; info = tys_c } = find_constr loc c in qualid , Ztypes . constr_instance tys_c |
let rec get_all_labels loc ty = match ty . t_desc with | Tconstr ( qual , _ , _ ) -> let { info = { type_desc = ty_c } } = find_type loc ( Lident . Modname ( qual ) ) in begin match ty_c with Record_type ( l ) -> l | _ -> assert false end | Tlink ( link ) -> get_all_lab... |
let check_definitions_for_every_name defined_names n_list = List . fold_left ( fun { dv = dv ; di = di ; der = der ; nv = nv ; mv = mv } { vardec_name = n ; vardec_default = d_opt ; vardec_loc = loc } -> let in_dv = S . mem n dv in let in_di = S . mem n di in let in_der = S . ... |
let combine loc expected_ty lname = let { qualid = qualid ; info = { value_typ = tys } } = find_value loc lname in let ty = Ztypes . instance_of_type tys in let ty_combine = Ztypes . type_of_combine ( ) in unify loc ty_combine ty |
let constant loc expected_k expected_ty = function | Cimmediate ( i ) -> let actual_ty = immediate ( i ) in unify loc expected_ty actual_ty | Cglobal ( lname ) -> let qualid , actual_ty = global loc expected_k lname in unify loc expected_ty actual_ty |
let vardec_list expected_k n_list inames = let default loc expected_ty c_opt = function | Init ( v ) -> if not ( Ztypes . is_statefull_kind expected_k ) then error loc Ekind_not_combinatorial ; constant loc expected_k expected_ty v ; Deftypes . Smem ( Deftypes . cmem c_opt { empty_mem with m_i... |
let rec build ( names , inames ) { eq_desc = desc } = let block_with_bounded ( names , inames ) let vardec acc { vardec_name = n } = S . add n acc in let bounded = List . fold_left vardec S . empty b_vars in let ( local_names , local_inames ) = build_list ( S . empty , S . ... |
let env_of_eq_list expected_k eq_list = let names , inames = build_list ( S . empty , S . empty ) eq_list in S . fold ( fun n acc -> let sort = match expected_k with | Deftypes . Tstatic _ -> Deftypes . static | Deftypes . Tany | Deftypes . Tdiscrete false -> Deftypes . variable | D... |
let intro_sort_of_var expected_k = match expected_k with | Deftypes . Tstatic _ -> Deftypes . static | Deftypes . Tany | Deftypes . Tdiscrete false -> Deftypes . Sval | Deftypes . Tcont | Deftypes . Tdiscrete true | Deftypes . Tproba -> Deftypes . Smem ( Deftypes . empty_mem ) |
let env_of_scondpat expected_k scpat = let rec env_of acc { desc = desc } = match desc with | Econdand ( sc1 , sc2 ) -> env_of ( env_of acc sc1 ) sc2 | Econdor ( sc , _ ) | Econdon ( sc , _ ) -> env_of acc sc | Econdexp _ -> acc | Econdpat ( _ , pat ) -> Vars . fv_pat S... |
let env_of_statepat expected_k spat = let rec env_of acc { desc = desc } = match desc with | Estate0pat _ -> acc | Estate1pat ( _ , l ) -> List . fold_left ( fun acc n -> S . add n acc ) acc l in let acc = env_of S . empty spat in S . fold ( fun n acc -> Env . add n { t_typ = Zt... |
let env_of_pattern expected_k h0 pat = let acc = Vars . fv_pat S . empty S . empty pat in S . fold ( fun n acc -> Env . add n { t_typ = Ztypes . new_var ( ) ; t_sort = intro_sort_of_var expected_k } acc ) acc h0 |
let env_of_pattern_list expected_k env p_list = let p_list , p = Zmisc . firsts p_list in let env = List . fold_left ( env_of_pattern ( Deftypes . Tstatic true ) ) env p_list in env_of_pattern expected_k env p |
let env_of_pattern expected_k pat = env_of_pattern expected_k Env . empty pat |
let rec pattern h ( { p_desc = desc ; p_loc = loc } as pat ) ty = match desc with | Ewildpat -> pat . p_typ <- ty | Econstpat ( im ) -> unify_pat pat ty ( immediate im ) ; pat . p_typ <- ty | Econstr0pat ( c0 ) -> let qualid , { constr_res = ty_res ; constr_arity = n } ... |
let pattern_list h pat_list ty_list = List . iter2 ( pattern h ) pat_list ty_list |
let check_total_pattern p = let is_exhaustive = Patternsig . check_activate p . p_loc p in if not is_exhaustive then error p . p_loc Epattern_not_total |
let check_total_pattern_list p_list = List . iter check_total_pattern p_list |
let match_handlers body loc expected_k h total m_handlers pat_ty ty = let handler ( { m_pat = pat ; m_body = b } as mh ) = let h0 = env_of_pattern expected_k pat in pattern h0 pat pat_ty ; mh . m_env <- h0 ; let h = Env . append h0 h in body expected_k h b ty in let defined_names_list = List .... |
let present_handlers scondpat body loc expected_k h p_h_list b_opt expected_ty = let handler ( { p_cond = scpat ; p_body = b } as ph ) = let h0 = env_of_scondpat expected_k scpat in let h = Env . append h0 h in let is_zero = Ztypes . is_continuous_kind expected_k in scondpat expected_k is_zero h sc... |
let rec expression expected_k h ( { e_desc = desc ; e_loc = loc } as e ) = let ty = match desc with | Econst ( i ) -> immediate i | Elocal ( x ) -> let { t_typ = typ ; t_sort = sort } = var loc h x in sort_less_than loc sort expected_k ; typ | Eglobal { lname = lname } -> let... |
let no_unbounded_name loc free_in_ty ty = if not ( S . is_empty free_in_ty ) then let n = S . choose free_in_ty in error loc ( Esize_parameter_cannot_be_generalized ( n , ty ) ) else ty |
let funtype loc expected_k pat_list ty_list ty_res = let rec arg pat_list ty_list fv_in_ty_res = match pat_list , ty_list with | [ ] , [ ] -> [ ] , fv_in_ty_res | pat :: pat_list , ty_arg :: ty_list -> let ty_res_list , fv_in_ty_res = arg pat_list ty_list fv_in_ty_res in let fv_pat = Var... |
let constdecl f is_static e = let expected_k = if is_static then Tstatic ( true ) else Tdiscrete ( false ) in Zmisc . push_binding_level ( ) ; let ty = expression expected_k Env . empty e in Zmisc . pop_binding_level ( ) ; let tys = Ztypes . gen ( not ( expansive e ) ) ty in tys |
let fundecl loc f ( { f_kind = k ; f_atomic = is_atomic ; f_args = pat_list ; f_body = e } as body ) = Zmisc . push_binding_level ( ) ; let expected_k = Interface . kindtype k in let h0 = env_of_pattern_list expected_k Env . empty pat_list in body . f_env <- h0 ; let ty_p_list = L... |
let implementation ff is_first impl = try match impl . desc with | Econstdecl ( f , is_static , e ) -> let tys = constdecl f is_static e in if is_first then Interface . add_type_of_value ff impl . loc f is_static tys else Interface . update_type_of_value ff impl . loc f is_static tys | Efundecl (... |
let implementation_list ff is_first impl_list = Zmisc . no_warning := not is_first ; List . iter ( implementation ff is_first ) impl_list ; Zmisc . no_warning := not is_first ; impl_list |
let badwords = [ " abandonned " ; " abandonning " ; " abbrevation " ; " abbrevations " ; " abigious " ; " abilties " ; " abilty " ; " abitrate " ; " abolute " ; " abov " ; " absense " ; " absolut " ; " absoulte " ; " acccept " ; " ... |
let regexp = let make_regexp word = " \\ b " ^ Str . quote word ^ " \\ b " in Str . regexp @@ String . concat " " \\| @@ List . map make_regexp badwords |
let string_search re s start = try ignore ( Str . search_forward re s start ) ; true with Not_found -> false |
let find s = if string_search regexp s 0 then Some ( Str . matched_string s ) else None |
module Seq = struct include Seq let of_list l = let rec aux l ( ) = match l with | [ ] -> Seq . Nil | x :: tail -> Seq . Cons ( x , aux tail ) in aux l let to_rev_list gen = fold_left ( fun acc x -> x :: acc ) [ ] gen let to_list gen = List . rev ( to_rev_list gen ) end |
let map_3 f ( x , y , z ) = ( x , y , f z ) |
module T = struct type ( ' a , ' b ) conv = { to_ : ' a -> ' b ; from_ : ' b -> ' a ; } type ' a raw = | Regexp : Re . t * Re . re Lazy . t -> string raw | Conv : ' a raw * ( ' a , ' b ) conv -> ' b raw | Opt : ' a raw -> ( ' a option ) raw | Al... |
type ' a t = ' a T . raw |
let regex x : _ t = let re = lazy Re . ( compile @@ whole_string @@ no_group x ) in Regexp ( x , re ) |
let pcre s = regex @@ Re . Pcre . re s |
let conv to_ from_ x : _ t = Conv ( x , { to_ ; from_ } ) |
let seq a b : _ t = Seq ( a , b ) |
let alt a b : _ t = Alt ( a , b ) |
let prefix x a : _ t = Prefix ( x , a ) |
let suffix a x : _ t = Suffix ( a , x ) |
let opt a : _ t = Opt a |
module Infix = struct let ( ) <|> = alt let ( ) <&> = seq let ( ) *> = prefix let ( <* ) = suffix end |
let rep x : _ t = Rep x |
let rep1 x = x <&> rep x |
let modifier f re : _ t = Mod ( f , re ) |
let word re = modifier Re . word re |
let whole_string re = modifier Re . whole_string re |
let longest re = modifier Re . longest re |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.