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) Stdlib.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 nest : 'b -> 'a * 'c -> ('a * 'b) * 'cNest the first argument with the first element of the pair given as second argument.
val flatten : ('a * 'b) * 'c -> 'a * 'b * 'cFlatten the pairs into a triplet.
val 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 list
val filter_map_opt : ('a -> 'b option) -> 'a list -> 'b listCombines filter and map.
val fold_map : ('a -> 'b -> 'a * 'c) -> 'a -> 'b list -> 'a * 'c listCombines fold_left and map
val fold_map_opt : ('a -> 'b -> 'a * 'c option) -> 'a -> 'b list -> 'a * 'c listCombines filter fold_left 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 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 -> 'bList.find_opt insteadfind_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 list_first_n : int -> 'a list -> 'a listlist_first_n n l returns the first n elements of the list. Tail
recursive.
It returns an empty list if n is nonpositive and the whole list if n is
greater than List.length l.
It is equivalent to list_slice ~last:n l.
val list_slice : ?first:int -> ?last:int -> 'a list -> 'a listlist_slice ?first ?last l is equivalent to Python's slice operator
(lfirst:last): returns the range of the list between first (inclusive)
and last (exclusive), starting from 0.
If omitted, first defaults to 0 and last to List.length l.
Negative indices are allowed, and count from the end of the list.
list_slice never raises exceptions: out-of-bounds arguments are clipped,
and inverted ranges result in empty lists.
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_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.exnexn now mandatory; otherwise,
use Option.get, which is equivalent.val opt_hash : ('a -> int) -> 'a option -> intval opt_map2 : ('a -> 'b -> 'c) -> 'a option -> 'b option -> 'c optionf a b if arguments are Some a and Some b, orelse return
None.val 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 strip_underscore : string -> stringremove underscores at the beginning and end of a string. If a string is composed solely of underscores, return the empty string
val html_escape : string -> string
val format_string_of_stag : Stdlib.Format.stag -> stringformat_string_of_stag stag returns the string corresponding to stag,
or raises an exception if the tag extension is unsupported.
val address_of_value : 'a -> intval try_finally : finally:(unit -> unit) -> ('a -> 'b) -> 'a -> 'bSystem commands
val mkdir : ?parents:bool -> string -> Unix.file_perm -> unitmkdir ?parents name perm creates directory name with permission
perm. If parents is true, recursively create parent directories
if needed. parents defaults to false.
Note that this function may create some of the parent directories
and then fail to create the children, e.g. if perm does not allow
user execution of the created directory. This will leave the filesystem
in a modified state before raising an exception.
Unix.Unix_error if cannot create name or its parents.val safe_at_exit : (unit -> unit) -> unitRegister function to call with Stdlib.at_exit, but only
for non-child process (fork). The order of execution is preserved
wrt ordinary calls to Stdlib.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 -> unitComparison functions
val compare_basic : 'a -> 'a -> intUse this function instead of Stdlib.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.