Release coccinelle-0.1.8
[bpt/coccinelle.git] / commons / common.mli
index 21a05da..723748b 100644 (file)
@@ -117,16 +117,21 @@ val reset_pr_indent : unit -> unit
 (* The following functions first indent _tab_level_print spaces.
  * They also add the _prefix_pr, for instance used in MPI to show which
  * worker is talking.
+ * update: for pr2, it can also print into a log file.
  * 
  * The use of 2 in pr2 is because 2 is under UNIX the second descriptor
  * which corresponds to stderr. 
  *)
 val _prefix_pr : string ref
+
 val pr : string -> unit
-val pr2 : string -> unit
 val pr_no_nl : string -> unit
-val pr2_no_nl : string -> unit
 val pr_xxxxxxxxxxxxxxxxx : unit -> unit
+
+(* pr2 print on stderr, but can also in addition print into a file *)
+val _chan_pr2: out_channel option ref
+val pr2 : string -> unit
+val pr2_no_nl : string -> unit
 val pr2_xxxxxxxxxxxxxxxxx : unit -> unit
 
 (* use Dumper.dump *)
@@ -137,10 +142,15 @@ val dump: 'a -> string
 val _already_printed : (string, bool) Hashtbl.t
 val pr2_once : string -> unit
 
+val mk_pr2_wrappers: bool ref -> (string -> unit) * (string -> unit)
+
+
 val redirect_stdout_stderr : filename -> (unit -> unit) -> unit
 val redirect_stdin : filename -> (unit -> unit) -> unit
 val redirect_stdin_opt : filename option -> (unit -> unit) -> unit
 
+val with_pr2_to_string: (unit -> unit) -> string list
+
 val fprintf : out_channel -> ('a, out_channel, unit) format -> 'a
 val printf : ('a, out_channel, unit) format -> 'a
 val eprintf : ('a, out_channel, unit) format -> 'a
@@ -239,13 +249,18 @@ val _list_bool : (string * bool) list ref
 val example3 : string -> bool -> unit
 val test_all : unit -> unit
 
+
 (* regression testing *)
 type score_result = Ok | Pb of string 
-type score = (string (* usually a filename *), score_result) Hashtbl.t
+type score =      (string (* usually a filename *), score_result) Hashtbl.t
+type score_list = (string (* usually a filename *) * score_result) list
 val empty_score : unit -> score
 val regression_testing : 
   score -> filename (* old score file on disk (usually in /tmp) *) -> unit
+val regression_testing_vs: score -> score -> score
+val total_scores : score -> int (* good *) * int (* total *)
 val print_score : score -> unit
+val print_total_score: score -> unit
 
 
 (* quickcheck spirit *)
@@ -280,12 +295,16 @@ val laws2 :
 (* Persistence *)
 (*****************************************************************************)
 
-(* just wrappers around Marshall *)
+(* just wrappers around Marshal *)
 val get_value : filename -> 'a
 val read_value : filename -> 'a (* alias *)
 val write_value : 'a -> filename -> unit
 val write_back : ('a -> 'b) -> filename -> unit
 
+(* wrappers that also use profile_code *)
+val marshal__to_string:   'a -> Marshal.extern_flags list -> string
+val marshal__from_string:   string -> int -> 'a
+
 (*****************************************************************************)
 (* Counter *)
 (*****************************************************************************)
@@ -330,6 +349,10 @@ val format_to_string : (unit -> unit) (* printer *) -> string
 val adjust_pp_with_indent : (unit -> unit) -> unit
 val adjust_pp_with_indent_and_header : string -> (unit -> unit) -> unit
 
+
+val mk_str_func_of_assoc_conv: 
+  ('a * string) list -> (string -> 'a) * ('a -> string)
+
 (*****************************************************************************)
 (* Macro *)
 (*****************************************************************************)
@@ -380,6 +403,8 @@ type 'a mylazy = (unit -> 'a)
 
 (* emacs spirit *)
 val save_excursion : 'a ref -> (unit -> 'b) -> 'b
+val save_excursion_and_disable : bool ref -> (unit -> 'b) -> 'b
+val save_excursion_and_enable :  bool ref -> (unit -> 'b) -> 'b
 
 (* emacs spirit *)
 val unwind_protect : (unit -> 'a) -> (exn -> 'b) -> 'a
@@ -441,7 +466,7 @@ exception Impossible
 exception Here
 exception ReturnExn
 
-exception MultiFound
+exception Multi_found
 
 exception WrongFormat of string
 
@@ -455,6 +480,11 @@ val exn_to_s : exn -> string
 (* alias *)
 val string_of_exn : exn -> string
 
+type error = Error of string 
+
+type evotype = unit
+val evoval : evotype
+
 (*****************************************************************************)
 (* Environment *)
 (*****************************************************************************)
@@ -556,7 +586,7 @@ val (=*=): 'a -> 'a -> bool
 
 (* if want to restrict the use of '=', uncomment this:
  *
- * val (=): int -> int -> bool
+ * val (=): unit -> unit -> bool
  * 
  * But it will not forbid you to use caml functions like List.find, List.mem
  * which internaly use this convenient but evolution-unfriendly (=)
@@ -564,7 +594,6 @@ val (=*=): 'a -> 'a -> bool
 
 
 
-
 (*###########################################################################*)
 (* And now basic types *)
 (*###########################################################################*)
@@ -578,6 +607,7 @@ val ( ==> ) : bool -> bool -> bool
 val xor : 'a -> 'a -> bool
 
 
+
 (*****************************************************************************)
 (* Char *)
 (*****************************************************************************)
@@ -760,6 +790,14 @@ val filter_some : 'a option list -> 'a list
 val map_filter : ('a -> 'b option) -> 'a list -> 'b list
 val find_some : ('a -> 'b option) -> 'a list -> 'b
 
+val list_to_single_or_exn: 'a list -> 'a
+
+(*****************************************************************************)
+(* TriBool *)
+(*****************************************************************************)
+type bool3 = True3 | False3 | TrueFalsePb3 of string
+
+
 (*****************************************************************************)
 (* Strings *)
 (*****************************************************************************)
@@ -951,6 +989,7 @@ val floattime_of_string: string -> float_time
 val dmy_to_unixtime: date_dmy -> float_time * Unix.tm
 val unixtime_to_dmy: Unix.tm -> date_dmy
 val unixtime_to_floattime: Unix.tm -> float_time
+val floattime_to_unixtime: float_time -> Unix.tm
 
 val sec_to_days : int -> string
 val sec_to_hours : int -> string
@@ -1024,6 +1063,7 @@ val cmd_to_list_and_status : string -> string list * Unix.process_status
 val command2 : string -> unit
 val _batch_mode: bool ref
 val command2_y_or_no : string -> bool
+val command2_y_or_no_exit_if_no : string -> unit
 
 val do_in_fork : (unit -> unit) -> int
 
@@ -1149,14 +1189,16 @@ val drop_until : ('a -> bool) -> 'a list -> 'a list
 val span : ('a -> bool) -> 'a list -> 'a list * 'a list
 
 val skip_until : ('a list -> bool) -> 'a list -> 'a list
-val skipfirst : 'a -> 'a list -> 'a list
+val skipfirst : (* Eq a *) 'a -> 'a list -> 'a list
 
 (* cf also List.partition *)
 val fpartition : ('a -> 'b option) -> 'a list -> 'b list * 'a list
 
 val groupBy : ('a -> 'a -> bool) -> 'a list -> 'a list list
 val exclude_but_keep_attached: ('a -> bool) -> 'a list -> ('a * 'a list) list
-val group_by_post: ('a -> bool) -> 'a list -> ('a list * 'a) list * 'a list
+val group_by_post: ('a -> bool) -> 'a list -> ('a list * 'a) list *    'a list
+val group_by_pre:  ('a -> bool) -> 'a list -> 'a list *    ('a * 'a list) list
+val group_by_mapped_key: ('a -> 'b) -> 'a list -> ('b * 'a list) list
 
 (* Use hash internally to not be in O(n2). If you want to use it on a
  * simple list, then first do a List.map to generate a key, for instance the
@@ -1188,7 +1230,7 @@ val filter_index : (int -> 'a -> bool) -> 'a list -> 'a list
 val fold_left_with_index : ('a -> 'b -> int -> 'a) -> 'a -> 'b list -> 'a
 
 val nth : 'a list -> int -> 'a
-val rang : 'a -> 'a list -> int
+val rang : (* Eq a *) 'a -> 'a list -> int
 
 val last_n : int -> 'a list -> 'a list
 
@@ -1259,7 +1301,7 @@ val minimum : 'a list -> 'a
 val min_with : ('a -> 'b) -> 'a list -> 'a
 val two_mins_with : ('a -> 'b) -> 'a list -> 'a * 'a
 
-val all_assoc : 'a -> ('a * 'b) list -> 'b list
+val all_assoc : (* Eq a *) 'a -> ('a * 'b) list -> 'b list
 val prepare_want_all_assoc : ('a * 'b) list -> ('a * 'b list) list
 
 val or_list : bool list -> bool
@@ -1308,7 +1350,17 @@ val fusionneListeContenant : 'a * 'a -> 'a list list -> 'a list list
 (* Arrays *)
 (*****************************************************************************)
 
-val array_find_index : ('a -> bool) -> 'a array -> int
+val array_find_index : (int -> bool) -> 'a array -> int
+val array_find_index_via_elem : ('a -> bool) -> 'a array -> int
+
+(* for better type checking, as sometimes when have an 'int array', can
+ * easily mess up the index from the value.
+ *)
+type idx = Idx of int 
+val next_idx: idx -> idx
+val int_of_idx: idx -> int
+
+val array_find_index_typed : (idx -> bool) -> 'a array -> idx
 
 (*****************************************************************************)
 (* Matrix *)
@@ -1429,7 +1481,7 @@ module StringSet = Set.Make(struct type t = string let compare = compare end)
 
 type ('a, 'b) assoc = ('a * 'b) list
 
-val assoc_to_function : ('a, 'b) assoc -> ('a -> 'b)
+val assoc_to_function : (* Eq a *) ('a, 'b) assoc -> ('a -> 'b)
 
 val empty_assoc : ('a, 'b) assoc
 val fold_assoc : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a
@@ -1463,6 +1515,9 @@ val sort_by_val_highfirst: ('a,'b) assoc -> ('a * 'b) list
 val sort_by_key_lowfirst: (int,'b) assoc -> (int * 'b) list
 val sort_by_key_highfirst: (int,'b) assoc -> (int * 'b) list
 
+val sortgen_by_key_lowfirst: ('a,'b) assoc -> ('a * 'b) list
+val sortgen_by_key_highfirst: ('a,'b) assoc -> ('a * 'b) list
+
 (*****************************************************************************)
 (* Assoc, specialized. *)
 (*****************************************************************************)
@@ -1609,22 +1664,53 @@ val tree_iter : ('a -> unit) -> 'a tree -> unit
 (* N-ary tree with updatable childrens *)
 (*****************************************************************************)
 
-(* Leaf can seem redundant, but sometimes want to directly see if 
- * a children is a leaf without looking if the list is empty.
- *)
-type ('a, 'b) treeref = 
-  | NodeRef of 'a * ('a, 'b) treeref list ref 
-  | LeafRef of 'b
+(* no empty tree, must have one root at least *)
+type 'a treeref = 
+  | NodeRef of 'a *   'a treeref list ref 
 
 val treeref_node_iter: 
-  (('a * ('a, 'b) treeref list ref) -> unit) -> ('a, 'b) treeref -> unit
+  (('a * 'a treeref list ref) -> unit) -> 'a treeref -> unit
 val treeref_node_iter_with_parents: 
-  (('a * ('a, 'b) treeref list ref) -> ('a list) -> unit) -> 
-  ('a, 'b) treeref -> unit
+  (('a * 'a treeref list ref) -> ('a list) -> unit) -> 
+  'a treeref -> unit
 
 val find_treeref: 
-  (('a * ('a, 'b) treeref list ref) -> bool) -> 
-  ('a, 'b) treeref -> ('a, 'b) treeref
+  (('a * 'a treeref list ref) -> bool) -> 
+  'a treeref -> 'a treeref
+
+val treeref_children_ref: 
+  'a treeref -> 'a treeref list ref 
+
+val find_treeref_with_parents_some:
+ ('a * 'a treeref list ref -> 'a list -> 'c option) ->
+ 'a treeref -> 'c
+
+val find_multi_treeref_with_parents_some:
+ ('a * 'a treeref list ref -> 'a list -> 'c option) ->
+ 'a treeref -> 'c list
+
+
+(* Leaf can seem redundant, but sometimes want to directly see if 
+ * a children is a leaf without looking if the list is empty.
+ *)
+type ('a, 'b) treeref2 = 
+  | NodeRef2 of 'a * ('a, 'b) treeref2 list ref 
+  | LeafRef2 of 'b
+
+
+val find_treeref2: 
+  (('a * ('a, 'b) treeref2 list ref) -> bool) -> 
+  ('a, 'b) treeref2 -> ('a, 'b) treeref2
+
+val treeref_node_iter_with_parents2: 
+  (('a * ('a, 'b) treeref2 list ref) -> ('a list) -> unit) -> 
+  ('a, 'b) treeref2 -> unit
+
+val treeref_node_iter2: 
+  (('a * ('a, 'b) treeref2 list ref) -> unit) -> ('a, 'b) treeref2 -> unit
+
+(*
+
 
 val treeref_children_ref: ('a, 'b) treeref -> ('a, 'b) treeref list ref 
 
@@ -1635,7 +1721,7 @@ val find_treeref_with_parents_some:
 val find_multi_treeref_with_parents_some:
  ('a * ('a, 'b) treeref list ref -> 'a list -> 'c option) ->
  ('a, 'b) treeref -> 'c list
-
+*)
 
 (*****************************************************************************)
 (* Graph. But have a look too at Ograph_*.mli; it's better *)
@@ -1812,6 +1898,12 @@ val full_charpos_to_pos : filename -> (int * int) array
 val complete_parse_info : 
   filename -> (int * int) array -> parse_info -> parse_info
 
+val full_charpos_to_pos_large: 
+  filename -> (int -> (int * int))
+
+val complete_parse_info_large : 
+  filename -> (int -> (int * int))  -> parse_info -> parse_info
+
 (* return line x col x str_line  from a charpos. This function is quite
  * expensive so don't use it to get the line x col from every token in
  * a file. Instead use full_charpos_to_pos.
@@ -1833,7 +1925,7 @@ val error_messagebis : filename -> (string * int) -> int -> string
 (* for example of use, see the code used in coccinelle *)
 type ('a, 'b) scoped_env = ('a, 'b) assoc list
 
-val lookup_env : 'a -> ('a, 'b) scoped_env -> 'b
+val lookup_env : (* Eq a *) 'a -> ('a, 'b) scoped_env -> 'b
 val member_env_key : 'a -> ('a, 'b) scoped_env -> bool
 
 val new_scope : ('a, 'b) scoped_env ref -> unit