module Extlib:sig..end
Useful operations. This module does not depend of any of frama-c module.
val nop : 'a -> unitDo nothing.
val id : 'a -> 'aidentity function.
val adapt_filename : string -> stringEnsure that the given filename has the extension "cmo" in bytecode and "cmxs" in native
val max_cpt : int -> int -> intmax_cpt t1 t2 returns the maximum of t1 and t2 wrt the total ordering
induced by tags creation. This ordering is defined as follows:
forall tags t1 t2, t1 <= t2 iff t1 is before t2 in the finite sequence
0; 1; ..; max_int; min_int; min_int-1; -1
val number_to_color : int -> intexception Unregistered_function of string
Never catch it yourself: let the kernel do the job.
val mk_labeled_fun : string -> 'aTo be used to initialized a reference over a labeled function.
Unregistered_function when not properly initializedval mk_fun : string -> ('a -> 'b) Pervasives.refBuild a reference to an uninitialized function
Unregistered_function when not properly initializedval ($) : ('b -> 'c) -> ('a -> 'b) -> 'a -> 'cComposition.
val swap : ('a -> 'b -> 'c) -> 'b -> 'a -> 'cSwap arguments.
val uncurry : ('a -> 'b -> 'c) -> 'a * 'b -> 'c
val iter_uncurry2 : (('a -> 'b -> unit) -> 'c -> unit) -> ('a * 'b -> unit) -> 'c -> unitval as_singleton : 'a list -> 'areturns the unique element of a singleton list.
Invalid_argument on a non singleton list.val last : 'a list -> 'areturns the last element of a list.
Invalid_argument on an empty listval filter_out : ('a -> bool) -> 'a list -> 'a listFilter out elements that pass the test
val replace : ('a -> 'a -> bool) -> 'a -> 'a list -> 'a listreplace cmp x l replaces the first element y of l such that
cmp x y is true by x. If no such element exists, x is added
at the tail of l.
val filter_map : ('a -> bool) -> ('a -> 'b) -> 'a list -> 'b list
val filter_map' : ('a -> 'b) -> ('b -> bool) -> 'a list -> 'b listCombines filter and map.
val product_fold : ('a -> 'b -> 'c -> 'a) -> 'a -> 'b list -> 'c list -> 'aproduct f acc l1 l2 is similar to fold_left f acc l12 with l12 the
list of all pairs of an elt of l1 and an elt of l2
val product : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c listproduct f l1 l2 applies f to all the pairs of an elt of l1 and
an element of l2.
val find_index : ('a -> bool) -> 'a list -> intreturns the index (starting at 0) of the first element verifying the condition
Not_found if no element in the list matches the conditionval list_compare : ('a -> 'a -> int) -> 'a list -> 'a list -> intGeneric list comparison function, where the elements are compared with the specified function
val list_of_opt : 'a option -> 'a listconverts an option into a list with 0 or 1 elt.
val opt_of_list : 'a list -> 'a optionconverts a list with 0 or 1 element into an option.
Invalid_argument on lists with more than one argumentval find_opt : ('a -> 'b option) -> 'a list -> 'bfind_option p l returns the value p e, e being the first
element of l such that p e is not None. Raise Not_found if there
is no such value the list l.
val iteri : (int -> 'a -> unit) -> 'a list -> unitSame as iter, but the function to be applied take also as argument the index of the element (starting from 0). Tail-recursive
val mapi : (int -> 'a -> 'b) -> 'a list -> 'b listSame as map, but the function to be applied take also as argument the index of the element (starting from 0). Tail-recursive
val sort_unique : ('a -> 'a -> int) -> 'a list -> 'a listSame as List.sort , but also remove duplicates.
val subsets : int -> 'a list -> 'a list listsubsets k l computes the combinations of k elements from list l.
E.g. subsets 2 1;2;3;4 = [1;2];[1;3];[1;4];[2;3];[2;4];[3;4].
This function preserves the order of the elements in l when
computing the sublists. l should not contain duplicates.
val array_exists : ('a -> bool) -> 'a array -> bool
val array_existsi : (int -> 'a -> bool) -> 'a array -> boolval has_some : 'a option -> booltrue iff its argument is Some x
val may : ('a -> unit) -> 'a option -> unitmay f v applies f to x if v = Some(x)
val opt_conv : 'a -> 'a option -> 'aopt_conv default v returns default if v is None and a if
v is Some a
val opt_if : bool -> 'a -> 'a optionopt_if cond v returns Some v if cond is true and
None otherwise
val may_map : ('a -> 'b) -> ?dft:'b -> 'a option -> 'bmay_map f ?dft x applies f to the value of x if exists. Otherwise
returns the default value dft.
Assume that either x or dft is defined.
val opt_map : ('a -> 'b) -> 'a option -> 'b option
val opt_fold : ('a -> 'b -> 'b) -> 'a option -> 'b -> 'bval merge_opt : ('a -> 'b -> 'b -> 'b) -> 'a -> 'b option -> 'b option -> 'b optionmerge f k a b returns
None if both a and b are NoneSome a' (resp. b' if b (resp a) is None
and a (resp. b) is Somef k a' b' if both a and b are SomeIt is mainly intended to be used with Map.merge
val opt_bind : ('a -> 'b option) -> 'a option -> 'b optionopt_bind f x returns None if x is None and f y if is Some y
(monadic bind)
val opt_filter : ('a -> bool) -> 'a option -> 'a option
val the : ?exn:exn -> 'a option -> 'aExn if the value is None and exn is specified.Invalid_argument if the value is None and exn is not specified.Some v.exnval find_or_none : ('a -> 'b) -> 'a -> 'b option
val opt_equal : ('a -> 'a -> bool) -> 'a option -> 'a option -> bool
val opt_compare : ('a -> 'a -> int) -> 'a option -> 'a option -> intval opt_hash : ('a -> int) -> 'a option -> intval xor : bool -> bool -> boolexclusive-or.
val string_prefix : ?strict:bool -> string -> string -> boolstring_prefix ~strict p s returns true if and only if p is a
prefix of the string s. If strict is true, the prefix must be strict
(that is, s must moreover be strictly longer than p. strict
is false by default.
val string_del_prefix : ?strict:bool -> string -> string -> string optionstring_del_prefix ~strict p s returns None if p is not a prefix of
s and Some s1 iff s=p^s1.
val string_suffix : ?strict:bool -> string -> string -> boolstring_suffix ~strict suf s returns true iff suf is a suffix of
string s. strict, which defaults to false, indicates whether s
should be strictly longer than p.
val string_del_suffix : ?strict:bool -> string -> string -> string optionstring_del_suffix ~strict suf s returns Some s1 when s = s1 ^ suf
and None of suf is not a suffix of s.
val string_split : string -> int -> string * stringstring_split s i returns the beginning of s up to char i-1 and the
end of s starting from char i+1
Invalid_argument if i is not in the range [0,(length s -1)]val make_unique_name : (string -> bool) -> ?sep:string -> ?start:int -> string -> int * stringmake_unique_name mem s returns (0, s) when (mem s)=false
otherwise returns (n,new_string) such that new_string is
derived from (s,sep,start) and (mem new_string)=false and n<>0
val html_escape : string -> stringval address_of_value : 'a -> intval try_finally : finally:(unit -> unit) -> ('a -> 'b) -> 'a -> 'bSystem commands
val safe_at_exit : (unit -> unit) -> unitRegister function to call with Pervasives.at_exit, but only
for non-child process (fork). The order of execution is preserved
wrt ordinary calls to Pervasives.at_exit.
val cleanup_at_exit : string -> unitcleanup_at_exit file indicates that file must be removed when the
program exits (except if exit is caused by a signal).
If file does not exist, nothing happens.
exception Temp_file_error of string
val temp_file_cleanup_at_exit : ?debug:bool -> string -> string -> stringSimilar to Filename.temp_file except that the temporary file will be
deleted at the end of the execution (see above), unless debug is set
to true, in which case a message with the name of the kept file will be
printed.
Temp_file_error if the temp file cannot be created.val temp_dir_cleanup_at_exit : ?debug:bool -> string -> stringTemp_file_error if the temp dir cannot be created.val safe_remove : string -> unitTries to delete a file and never fails.
val safe_remove_dir : string -> unit
val terminate_process : int -> unitTerminate a process id.
val usleep : int -> unitUnix function that sleep for n microseconds.
See man usleep for details.
Should not be used under Win32.
Comparison functions
val compare_basic : 'a -> 'a -> intUse this function instead of Pervasives.compare, as this makes
it easier to find incorrect uses of the latter
val compare_ignore_case : string -> string -> intCase-insensitive string comparison. Only ISO-8859-1 accents are handled.