Module Extlib


module Extlib: sig .. end
Useful operations.

This module does not depend of any of frama-c module.
Consult the Plugin Development Guide for additional details.


val nop : 'a -> unit
Do nothing.
val adapt_filename : string -> string
Ensure that the given filename has the extension "cmo" in bytecode and "cmxs" in native
val max_cpt : int -> int -> int
max_cpt t1 t2 returns the maximum of t1 and t2 wrt the total ordering induced by tags creation. This ordering is defined as follow: 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 -> int

Function builders


exception NotYetImplemented of string
Use function Extlib.not_yet_implemented to raise this exception. Do never catch it yourself: let the kernel do the job.
Consult the Plugin Development Guide for additional details.
val not_yet_implemented : string -> 'a
Raises NotYetImplemented with the given string.
val mk_fun : string -> ('a -> 'b) Pervasives.ref
Deprecated.since Beryllium-20090901
build a reference to an unitialized function (which raises NotYetImplemented if it is called).

Function combinators


val ($) : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b
Composition.
val swap : ('a -> 'b -> 'c) -> 'b -> 'a -> 'c
Swap arguments.

Lists


val as_singleton : 'a list -> 'a
returns the unique element of a singleton list.
Raises Invalid_argument on a non singleton list.
val filter_out : ('a -> bool) -> 'a list -> 'a list
Filter out elements that pass the test
val filter_map : ('a -> bool) -> ('a -> 'b) -> 'a list -> 'b list
Combines filter and map.
val product_fold : ('a -> 'b -> 'c -> 'a) -> 'a -> 'b list -> 'c list -> 'a
product 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 list
product 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 -> int
returns the index (starting at 0) of the first element verifying the condition
Raises Not_found if no element in the list matches the condition
val list_compare : ('a -> 'a -> int) -> 'a list -> 'a list -> int
Generic list comparison function, where the elements are compared with the specified function
Since Boron-20100401
val list_of_opt : 'a option -> 'a list
converts an option into a list with 0 or 1 elt.
Since Carbon-20111201-beta2+dev

Options


val may : ('a -> unit) -> 'a option -> unit
val may_map : ('a -> 'b) -> ?dft:'b -> 'a option -> 'b
may_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_filter : ('a -> bool) -> 'a option -> 'a option
val the : 'a option -> 'a
Raises Invalid_argument if the value is none.
Consult the Plugin Development Guide for additional details.
val 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 -> int
Since Boron-20100401

Strings


val string_prefix : ?strict:bool -> string -> string -> bool
string_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.
Since Boron-20100401

Performance


val getperfcount : unit -> int
val getperfcount1024 : unit -> int
val time : ?msg:string -> ('a -> 'b) -> 'a -> 'b
val time1024 : ?msg:string -> ('a -> 'b) -> 'a -> 'b
val address_of_value : 'a -> int

Exception catcher


val try_finally : finally:(unit -> unit) -> ('a -> 'b) -> 'a -> 'b

System commands
val cleanup_at_exit : string -> unit
cleanup_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.
val temp_file_cleanup_at_exit : string -> string -> string
Similar to Filename.temp_file except that the temporary file will be deleted at the end of the execution (see above).
val temp_dir_cleanup_at_exit : string -> string
val safe_remove : string -> unit
Tries to delete a file and never fails.
val safe_remove_dir : string -> unit
val terminate_process : int -> unit
Terminate a process id.
val usleep : int -> unit
Unix function that sleep for n microseconds. See man usleep for details. Should not be used under Win32.

Comparison functions
val compare_basic : 'a -> 'a -> int
Use this function instead of Pervasives.compare, as this makes it easier to find incorrect uses of the latter