Release coccinelle-0.1.5
[bpt/coccinelle.git] / commons / common.mli
CommitLineData
34e49164
C
1(*###########################################################################*)
2(* Globals *)
3(*###########################################################################*)
4
5(* Some conventions:
6 *
7 * When I have some _xxx variables before some functions, it's
8 * because I want to show that those functions internally use a global
9 * variable. That does not mean I want people to modify this global.
10 * In fact they are kind of private, but I still want to show them.
11 * Maybe one day OCaml will have an effect type system so I don't need this.
12 *
13 * The variables that are called _init_xxx show the internal init
14 * side effect of the module (like static var trick used in C/C++)
15 *
16 * Why not split the functionnalities of this file in different files ?
17 * Because when I write ocaml script I want simply to load one
18 * file, common.ml, and that's it. Cf common_extra.ml for more on this.
19 *)
20
21
22(*****************************************************************************)
23(* Flags *)
24(*****************************************************************************)
25(* see the corresponding section for the use of those flags. See also
26 * the "Flags and actions" section at the end of this file.
27 *)
28
29(* if set then will not do certain finalize so faster to go back in replay *)
30val debugger : bool ref
31
32type prof = PALL | PNONE | PSOME of string list
33val profile : prof ref
485bce71
C
34val show_trace_profile : bool ref
35
34e49164
C
36
37val verbose_level : int ref
38
39(* forbid pr2_once to do the once "optimisation" *)
40val disable_pr2_once : bool ref
41
42
43
44(* works with new_temp_file *)
45val save_tmp_files : bool ref
46
47
48
49(*****************************************************************************)
50(* Module side effect *)
51(*****************************************************************************)
52(*
53 * I define a few unit tests via some let _ = example (... = ...).
54 * I also initialize the random seed, cf _init_random .
55 * I also set Gc.stack_size, cf _init_gc_stack .
56*)
57
58(*****************************************************************************)
59(* Semi globals *)
60(*****************************************************************************)
61(* cf the _xxx variables in this file *)
62
63(*###########################################################################*)
64(* Basic features *)
65(*###########################################################################*)
66
67type filename = string
485bce71 68type dirname = string
34e49164
C
69
70(* Trick in case you dont want to do an 'open Common' while still wanting
71 * more pervasive types than the one in Pervasives. Just do the selective
72 * open Common.BasicType.
73 *)
74module BasicType : sig
75 type filename = string
76end
77
78(* Same spirit. Trick found in Jane Street core lib, but originated somewhere
79 * else I think: the ability to open nested modules. *)
80module Infix : sig
81 val ( +> ) : 'a -> ('a -> 'b) -> 'b
82 val ( =~ ) : string -> string -> bool
83 val ( ==~ ) : string -> Str.regexp -> bool
84end
85
86
87(*
88 * Another related trick, found via Jon Harrop to have an extended standard
89 * lib is to do something like
90 *
91 * module List = struct
92 * include List
93 * val map2 : ...
94 * end
95 *
96 * And then can put this "module extension" somewhere to open it.
97 *)
98
99
100
101(* This module defines the Timeout and UnixExit exceptions.
102 * You have to make sure that those exn are not intercepted. So
103 * avoid exn handler such as try (...) with _ -> cos Timeout will not bubble up
104 * enough. In such case, add a case before such as
105 * with Timeout -> raise Timeout | _ -> ...
106 * The same is true for UnixExit (see below).
107 *)
108
109(*****************************************************************************)
110(* Debugging/logging *)
111(*****************************************************************************)
112
113val _tab_level_print: int ref
114val indent_do : (unit -> 'a) -> 'a
115val reset_pr_indent : unit -> unit
116
117(* The following functions first indent _tab_level_print spaces.
118 * They also add the _prefix_pr, for instance used in MPI to show which
119 * worker is talking.
120 *
121 * The use of 2 in pr2 is because 2 is under UNIX the second descriptor
122 * which corresponds to stderr.
123 *)
124val _prefix_pr : string ref
125val pr : string -> unit
126val pr2 : string -> unit
127val pr_no_nl : string -> unit
128val pr2_no_nl : string -> unit
129val pr_xxxxxxxxxxxxxxxxx : unit -> unit
130val pr2_xxxxxxxxxxxxxxxxx : unit -> unit
131
132(* use Dumper.dump *)
133val pr2_gen: 'a -> unit
134val dump: 'a -> string
135
136(* see flag: val disable_pr2_once : bool ref *)
137val _already_printed : (string, bool) Hashtbl.t
138val pr2_once : string -> unit
139
140val redirect_stdout_stderr : filename -> (unit -> unit) -> unit
141val redirect_stdin : filename -> (unit -> unit) -> unit
142val redirect_stdin_opt : filename option -> (unit -> unit) -> unit
143
144val fprintf : out_channel -> ('a, out_channel, unit) format -> 'a
145val printf : ('a, out_channel, unit) format -> 'a
146val eprintf : ('a, out_channel, unit) format -> 'a
147val sprintf : ('a, unit, string) format -> 'a
148
149(* alias *)
150val spf : ('a, unit, string) format -> 'a
151
152(* default = stderr *)
153val _chan : out_channel ref
154(* generate & use a /tmp/debugml-xxx file *)
155val start_log_file : unit -> unit
156
157(* see flag: val verbose_level : int ref *)
158val log : string -> unit
159val log2 : string -> unit
160val log3 : string -> unit
161val log4 : string -> unit
162
163val if_log : (unit -> unit) -> unit
164val if_log2 : (unit -> unit) -> unit
165val if_log3 : (unit -> unit) -> unit
166val if_log4 : (unit -> unit) -> unit
167
168val pause : unit -> unit
169
170(* was used by fix_caml *)
171val _trace_var : int ref
172val add_var : unit -> unit
173val dec_var : unit -> unit
174val get_var : unit -> int
175
176val print_n : int -> string -> unit
177val printerr_n : int -> string -> unit
178
179val _debug : bool ref
180val debugon : unit -> unit
181val debugoff : unit -> unit
182val debug : (unit -> unit) -> unit
183
184(* see flag: val debugger : bool ref *)
185
186
187(*****************************************************************************)
188(* Profiling (cpu/mem) *)
189(*****************************************************************************)
190
191val get_mem : unit -> unit
192val memory_stat : unit -> string
193
194val timenow : unit -> string
195
196val _count1 : int ref
197val _count2 : int ref
198val _count3 : int ref
199val _count4 : int ref
200val _count5 : int ref
201
202val count1 : unit -> unit
203val count2 : unit -> unit
204val count3 : unit -> unit
205val count4 : unit -> unit
206val count5 : unit -> unit
207val profile_diagnostic_basic : unit -> string
208
209val time_func : (unit -> 'a) -> 'a
210
211
212
213(* see flag: type prof = PALL | PNONE | PSOME of string list *)
214(* see flag: val profile : prof ref *)
215
216val _profile_table : (string, (float ref * int ref)) Hashtbl.t ref
217val profile_code : string -> (unit -> 'a) -> 'a
218val profile_diagnostic : unit -> string
219
485bce71
C
220val profile_code_exclusif : string -> (unit -> 'a) -> 'a
221val profile_code_inside_exclusif_ok : string -> (unit -> 'a) -> 'a
222
34e49164
C
223val report_if_take_time : int -> string -> (unit -> 'a) -> 'a
224
225(* similar to profile_code but print some information during execution too *)
226val profile_code2 : string -> (unit -> 'a) -> 'a
227
228(*****************************************************************************)
229(* Test *)
230(*****************************************************************************)
231
232val example : bool -> unit
233(* generate failwith <string> when pb *)
234val example2 : string -> bool -> unit
235(* use Dumper to report when pb *)
236val assert_equal : 'a -> 'a -> unit
237
238val _list_bool : (string * bool) list ref
239val example3 : string -> bool -> unit
240val test_all : unit -> unit
241
242(* regression testing *)
243type score_result = Ok | Pb of string
244type score = (string (* usually a filename *), score_result) Hashtbl.t
245val empty_score : unit -> score
246val regression_testing :
247 score -> filename (* old score file on disk (usually in /tmp) *) -> unit
248val print_score : score -> unit
249
250
251(* quickcheck spirit *)
252type 'a gen = unit -> 'a
253
254(* quickcheck random generators *)
255val ig : int gen
256val lg : 'a gen -> 'a list gen
257val pg : 'a gen -> 'b gen -> ('a * 'b) gen
258val polyg : int gen
259val ng : string gen
260
261val oneofl : 'a list -> 'a gen
262val oneof : 'a gen list -> 'a gen
263val always : 'a -> 'a gen
264val frequency : (int * 'a gen) list -> 'a gen
265val frequencyl : (int * 'a) list -> 'a gen
266
267val laws : string -> ('a -> bool) -> 'a gen -> 'a option
268
269(* example of use:
270 * let b = laws "unit" (fun x -> reverse [x] = [x]) ig
271 *)
272
273val statistic_number : 'a list -> (int * 'a) list
274val statistic : 'a list -> (int * 'a) list
275
276val laws2 :
277 string -> ('a -> bool * 'b) -> 'a gen -> 'a option * (int * 'b) list
278
279(*****************************************************************************)
280(* Persistence *)
281(*****************************************************************************)
282
283(* just wrappers around Marshall *)
284val get_value : filename -> 'a
485bce71 285val read_value : filename -> 'a (* alias *)
34e49164
C
286val write_value : 'a -> filename -> unit
287val write_back : ('a -> 'b) -> filename -> unit
288
289(*****************************************************************************)
290(* Counter *)
291(*****************************************************************************)
292val _counter : int ref
293val _counter2 : int ref
294val _counter3 : int ref
295
296val counter : unit -> int
297val counter2 : unit -> int
298val counter3 : unit -> int
299
300type timestamp = int
301
302(*****************************************************************************)
303(* String_of and (pretty) printing *)
304(*****************************************************************************)
305
306val string_of_string : (string -> string) -> string
307val string_of_list : ('a -> string) -> 'a list -> string
308val string_of_unit : unit -> string
309val string_of_array : ('a -> string) -> 'a array -> string
310val string_of_option : ('a -> string) -> 'a option -> string
311
312val print_bool : bool -> unit
313val print_option : ('a -> 'b) -> 'a option -> unit
314val print_list : ('a -> 'b) -> 'a list -> unit
315val print_between : (unit -> unit) -> ('a -> unit) -> 'a list -> unit
316
317(* use Format internally *)
318val pp_do_in_box : (unit -> unit) -> unit
319val pp_f_in_box : (unit -> 'a) -> 'a
320val pp_do_in_zero_box : (unit -> unit) -> unit
321val pp : string -> unit
322
323(* convert something printed using Format to print into a string *)
324val format_to_string : (unit -> unit) (* printer *) -> string
325
326(* works with _tab_level_print enabling to mix some calls to pp, pr2
327 * and indent_do to sometimes use advanced indentation pretty printing
328 * (with the pp* functions) and sometimes explicit and simple indendation
329 * printing (with pr* and indent_do) *)
330val adjust_pp_with_indent : (unit -> unit) -> unit
331val adjust_pp_with_indent_and_header : string -> (unit -> unit) -> unit
332
333(*****************************************************************************)
334(* Macro *)
335(*****************************************************************************)
336
337(* was working with my macro.ml4 *)
338val macro_expand : string -> unit
339
340(*****************************************************************************)
341(* Composition/Control *)
342(*****************************************************************************)
343
344val ( +> ) : 'a -> ('a -> 'b) -> 'b
345val ( +!> ) : 'a ref -> ('a -> 'a) -> unit
346val ( $ ) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
347
348val compose : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b
349val flip : ('a -> 'b -> 'c) -> 'b -> 'a -> 'c
350
351val curry : ('a * 'b -> 'c) -> 'a -> 'b -> 'c
352val uncurry : ('a -> 'b -> 'c) -> 'a * 'b -> 'c
353
354val id : 'a -> 'a
355val do_nothing : unit -> unit
356
357val forever : (unit -> unit) -> unit
358
359val applyn : int -> ('a -> 'a) -> 'a -> 'a
360
361class ['a] shared_variable_hook :
362 'a ->
363 object
364 val mutable data : 'a
365 val mutable registered : (unit -> unit) list
366 method get : 'a
367 method modify : ('a -> 'a) -> unit
368 method register : (unit -> unit) -> unit
369 method set : 'a -> unit
370 end
371
372val fixpoint : ('a -> 'a) -> 'a -> 'a
373val fixpoint_for_object : ((< equal : 'a -> bool; .. > as 'a) -> 'a) -> 'a -> 'a
374
375val add_hook : ('a -> ('a -> 'b) -> 'b) ref -> ('a -> ('a -> 'b) -> 'b) -> unit
376val add_hook_action : ('a -> unit) -> ('a -> unit) list ref -> unit
377val run_hooks_action : 'a -> ('a -> unit) list ref -> unit
378
379type 'a mylazy = (unit -> 'a)
380
381(* emacs spirit *)
382val save_excursion : 'a ref -> (unit -> 'b) -> 'b
383
384(* emacs spirit *)
385val unwind_protect : (unit -> 'a) -> (exn -> 'b) -> 'a
386
387(* java spirit *)
388val finalize : (unit -> 'a) -> (unit -> 'b) -> 'a
389
390val memoized : ('a, 'b) Hashtbl.t -> 'a -> (unit -> 'b) -> 'b
391
91eba41f
C
392val cache_in_ref : 'a option ref -> (unit -> 'a) -> 'a
393
34e49164
C
394
395(* take file from which computation is done, an extension, and the function
396 * and will compute the function only once and then save result in
397 * file ^ extension
398 *)
399val cache_computation :
400 ?verbose:bool -> ?use_cache:bool -> filename -> string (* extension *) ->
401 (unit -> 'a) -> 'a
402
403(* a more robust version where the client describes the dependencies of the
404 * computation so it will relaunch the computation in 'f' if needed.
405 *)
406val cache_computation_robust :
407 filename ->
408 string (* extension for marshalled object *) ->
409 (filename list * 'x) ->
410 string (* extension for marshalled dependencies *) ->
411 (unit -> 'a) ->
412 'a
413
414
415
416val once : ('a -> unit) -> ('a -> unit)
417
418val before_leaving : ('a -> unit) -> 'a -> 'a
419
420(* do some finalize, signal handling, unix exit conversion, etc *)
421val main_boilerplate : (unit -> unit) -> unit
422
423
424(* cf also the timeout function below that are control related too *)
425
426
427(*****************************************************************************)
428(* Concurrency *)
429(*****************************************************************************)
430
431(* how ensure really atomic file creation ? hehe :) *)
432exception FileAlreadyLocked
433val acquire_file_lock : filename -> unit
434val release_file_lock : filename -> unit
435
436(*****************************************************************************)
437(* Error managment *)
438(*****************************************************************************)
439exception Todo
440exception Impossible
441exception Here
442exception ReturnExn
443
91eba41f
C
444exception MultiFound
445
34e49164
C
446exception WrongFormat of string
447
448
449val internal_error : string -> 'a
450val myassert : bool -> unit
451val warning : string -> 'a -> 'a
452val error_cant_have : 'a -> 'b
453
454val exn_to_s : exn -> string
91eba41f
C
455(* alias *)
456val string_of_exn : exn -> string
34e49164
C
457
458(*****************************************************************************)
459(* Environment *)
460(*****************************************************************************)
461
462val check_stack_size: int -> unit
463val check_stack_nbfiles: int -> unit
464
465(* internally common.ml set Gc. parameters *)
466val _init_gc_stack : unit
467
468(*****************************************************************************)
469(* Arguments and command line *)
470(*****************************************************************************)
471
472type arg_spec_full = Arg.key * Arg.spec * Arg.doc
473type cmdline_options = arg_spec_full list
474
475
476type options_with_title = string * string * arg_spec_full list
477type cmdline_sections = options_with_title list
478
479
480(* A wrapper around Arg modules that have more logical argument order,
481 * and returns the remaining args.
482 *)
483val parse_options :
484 cmdline_options -> Arg.usage_msg -> string array -> string list
485
486(* Another wrapper that does Arg.align automatically *)
487val usage : Arg.usage_msg -> cmdline_options -> unit
488
489
490
491(* Work with the options_with_title type way to organize a long
492 * list of command line switches.
493 *)
494val short_usage :
495 Arg.usage_msg -> short_opt:cmdline_options -> unit
496val long_usage :
497 Arg.usage_msg -> short_opt:cmdline_options -> long_opt:cmdline_sections ->
498 unit
499
500(* With the options_with_title way, we don't want the default -help and --help
501 * so need adapter of Arg module, not just wrapper.
502 *)
503val arg_align2 : cmdline_options -> cmdline_options
504val arg_parse2 :
505 cmdline_options -> Arg.usage_msg -> (unit -> unit) (* short_usage func *) ->
506 string list
507
508
509
510
511
512(* The action lib. Useful to debug supart of your system. cf some of
513 * my main.ml for example of use. *)
514type flag_spec = Arg.key * Arg.spec * Arg.doc
515type action_spec = Arg.key * Arg.doc * action_func
516 and action_func = (string list -> unit)
517
518type cmdline_actions = action_spec list
519exception WrongNumberOfArguments
520
521val mk_action_0_arg : (unit -> unit) -> action_func
522val mk_action_1_arg : (string -> unit) -> action_func
523val mk_action_2_arg : (string -> string -> unit) -> action_func
524val mk_action_3_arg : (string -> string -> string -> unit) -> action_func
525
526val mk_action_n_arg : (string list -> unit) -> action_func
527
528val options_of_actions:
529 string ref (* the action ref *) -> cmdline_actions -> cmdline_options
530val action_list:
531 cmdline_actions -> Arg.key list
532val do_action:
533 Arg.key -> string list (* args *) -> cmdline_actions -> unit
534
535(*****************************************************************************)
536(* Equality *)
537(*****************************************************************************)
538
539(* Using the generic (=) is tempting, but it backfires, so better avoid it *)
540
541(* To infer all the code that use an equal, and that should be
542 * transformed, is not that easy, because (=) is used by many
543 * functions, such as List.find, List.mem, and so on. The strategy to find
544 * them is to turn what you were previously using into a function, because
545 * (=) return an exception when applied to a function, then you simply
546 * use ocamldebug to detect where the code has to be transformed by
547 * finding where the exception was launched from.
548 *)
549
550val (=|=) : int -> int -> bool
551val (=<=) : char -> char -> bool
552val (=$=) : string -> string -> bool
553val (=:=) : bool -> bool -> bool
554
555val (=*=): 'a -> 'a -> bool
556
557(* if want to restrict the use of '=', uncomment this:
558 *
559 * val (=): int -> int -> bool
560 *
561 * But it will not forbid you to use caml functions like List.find, List.mem
562 * which internaly use this convenient but evolution-unfriendly (=)
563*)
564
565
566
567
568(*###########################################################################*)
569(* And now basic types *)
570(*###########################################################################*)
571
572(*****************************************************************************)
573(* Bool *)
574(*****************************************************************************)
575
576val ( ||| ) : 'a -> 'a -> 'a
577val ( ==> ) : bool -> bool -> bool
578val xor : 'a -> 'a -> bool
579
580
581(*****************************************************************************)
582(* Char *)
583(*****************************************************************************)
584
585val string_of_char : char -> string
586val string_of_chars : char list -> string
587
588val is_single : char -> bool
589val is_symbol : char -> bool
590val is_space : char -> bool
591val is_upper : char -> bool
592val is_lower : char -> bool
593val is_alpha : char -> bool
594val is_digit : char -> bool
595
596val cbetween : char -> char -> char -> bool
597
598(*****************************************************************************)
599(* Num *)
600(*****************************************************************************)
601
602val ( /! ) : int -> int -> int
603
604val do_n : int -> (unit -> unit) -> unit
605val foldn : ('a -> int -> 'a) -> 'a -> int -> 'a
606
34e49164
C
607val pi : float
608val pi2 : float
609val pi4 : float
610
611val deg_to_rad : float -> float
612
613val clampf : float -> float
614
615val square : float -> float
616val power : int -> int -> int
617
618val between : 'a -> 'a -> 'a -> bool
619val between_strict : int -> int -> int -> bool
620val bitrange : int -> int -> bool
621
622val prime1 : int -> int option
623val prime : int -> int option
624
625val sum : int list -> int
626val product : int list -> int
627
628val decompose : int -> int list
629
630val mysquare : int -> int
631val sqr : float -> float
632
633type compare = Equal | Inf | Sup
634val ( <=> ) : 'a -> 'a -> compare
635val ( <==> ) : 'a -> 'a -> int
636
637type uint = int
638
639val int_of_stringchar : string -> int
640val int_of_base : string -> int -> int
641val int_of_stringbits : string -> int
642val int_of_octal : string -> int
643val int_of_all : string -> int
644
645(* useful but sometimes when want grep for all places where do modif,
646 * easier to have just code using ':=' and '<-' to do some modifications.
647 * In the same way avoid using {contents = xxx} to build some ref.
648 *)
649val ( += ) : int ref -> int -> unit
650val ( -= ) : int ref -> int -> unit
651
652val pourcent: int -> int -> int
653val pourcent_float: int -> int -> float
654val pourcent_float_of_floats: float -> float -> float
655
91eba41f
C
656val pourcent_good_bad: int -> int -> int
657val pourcent_good_bad_float: int -> int -> float
658
659type 'a max_with_elem = int ref * 'a ref
660val update_max_with_elem:
661 'a max_with_elem -> is_better:(int -> int ref -> bool) -> int * 'a -> unit
34e49164
C
662(*****************************************************************************)
663(* Numeric/overloading *)
664(*****************************************************************************)
665
666type 'a numdict =
667 NumDict of
668 (('a -> 'a -> 'a) * ('a -> 'a -> 'a) * ('a -> 'a -> 'a) * ('a -> 'a))
669val add : 'a numdict -> 'a -> 'a -> 'a
670val mul : 'a numdict -> 'a -> 'a -> 'a
671val div : 'a numdict -> 'a -> 'a -> 'a
672val neg : 'a numdict -> 'a -> 'a
673
674val numd_int : int numdict
675val numd_float : float numdict
676
677val testd : 'a numdict -> 'a -> 'a
678
679
680module ArithFloatInfix : sig
681 val (+) : float -> float -> float
682 val (-) : float -> float -> float
683 val (/) : float -> float -> float
684 val ( * ) : float -> float -> float
685
686
687 val (+..) : int -> int -> int
688 val (-..) : int -> int -> int
689 val (/..) : int -> int -> int
690 val ( *..) : int -> int -> int
691
692 val (+=) : float ref -> float -> unit
693end
694
695(*****************************************************************************)
696(* Random *)
697(*****************************************************************************)
698
699val _init_random : unit
700val random_list : 'a list -> 'a
701val randomize_list : 'a list -> 'a list
702val random_subset_of_list : int -> 'a list -> 'a list
703
704
705(*****************************************************************************)
706(* Tuples *)
707(*****************************************************************************)
708
709type 'a pair = 'a * 'a
710type 'a triple = 'a * 'a * 'a
711
712val fst3 : 'a * 'b * 'c -> 'a
713val snd3 : 'a * 'b * 'c -> 'b
714val thd3 : 'a * 'b * 'c -> 'c
715
716val sndthd : 'a * 'b * 'c -> 'b * 'c
717
718val map_fst : ('a -> 'b) -> 'a * 'c -> 'b * 'c
719val map_snd : ('a -> 'b) -> 'c * 'a -> 'c * 'b
720
721val pair : ('a -> 'b) -> 'a * 'a -> 'b * 'b
722
723val snd : 'a * 'b -> 'b (* alias *)
724val fst : 'a * 'b -> 'a (* alias *)
725
726val double : 'a -> 'a * 'a
727val swap : 'a * 'b -> 'b * 'a
728
729(* maybe a sign of bad programming if use those functions :) *)
730val tuple_of_list1 : 'a list -> 'a
731val tuple_of_list2 : 'a list -> 'a * 'a
732val tuple_of_list3 : 'a list -> 'a * 'a * 'a
733val tuple_of_list4 : 'a list -> 'a * 'a * 'a * 'a
734val tuple_of_list5 : 'a list -> 'a * 'a * 'a * 'a * 'a
735val tuple_of_list6 : 'a list -> 'a * 'a * 'a * 'a * 'a * 'a
736
737(*****************************************************************************)
738(* Maybe *)
739(*****************************************************************************)
740
741type ('a, 'b) either = Left of 'a | Right of 'b
742type ('a, 'b, 'c) either3 = Left3 of 'a | Middle3 of 'b | Right3 of 'c
743
744val just : 'a option -> 'a
745val some : 'a option -> 'a (* alias *)
746
747val fmap : ('a -> 'b) -> 'a option -> 'b option
748val map_option : ('a -> 'b) -> 'a option -> 'b option (* alias *)
749
750val do_option : ('a -> unit) -> 'a option -> unit
751
752val optionise : (unit -> 'a) -> 'a option
753
754val some_or : 'a option -> 'a -> 'a
755
756val partition_either :
757 ('a -> ('b, 'c) either) -> 'a list -> 'b list * 'c list
758
759val filter_some : 'a option list -> 'a list
760val map_filter : ('a -> 'b option) -> 'a list -> 'b list
761val find_some : ('a -> 'b option) -> 'a list -> 'b
762
763(*****************************************************************************)
764(* Strings *)
765(*****************************************************************************)
766
767val slength : string -> int (* alias *)
768val concat : string -> string list -> string (* alias *)
769
770val i_to_s : int -> string
771val s_to_i : string -> int
772
773(* strings take space in memory. Better when can share the space used by
774 * similar strings.
775 *)
776val _shareds : (string, string) Hashtbl.t
777val shared_string : string -> string
778
779val chop : string -> string
780val chop_dirsymbol : string -> string
781
782val ( <!!> ) : string -> int * int -> string
783val ( <!> ) : string -> int -> char
784
91eba41f
C
785val take_string: int -> string -> string
786val take_string_safe: int -> string -> string
787
34e49164
C
788val split_on_char : char -> string -> string list
789
790val lowercase : string -> string
791
792val quote : string -> string
793
794val null_string : string -> bool
795val is_blank_string : string -> bool
796val is_string_prefix : string -> string -> bool
797
798
799val plural : int -> string -> string
800
801val showCodeHex : int list -> unit
802
803val size_mo_ko : int -> string
804val size_ko : int -> string
805
806val edit_distance: string -> string -> int
807
485bce71
C
808val md5sum_of_string : string -> string
809
34e49164
C
810(*****************************************************************************)
811(* Regexp *)
812(*****************************************************************************)
813
814val regexp_alpha : Str.regexp
485bce71 815val regexp_word : Str.regexp
34e49164
C
816
817val _memo_compiled_regexp : (string, Str.regexp) Hashtbl.t
818val ( =~ ) : string -> string -> bool
819val ( ==~ ) : string -> Str.regexp -> bool
820
821
822
823val regexp_match : string -> string -> string
824
825val matched : int -> string -> string
826
827(* not yet politypic functions in ocaml *)
828val matched1 : string -> string
829val matched2 : string -> string * string
830val matched3 : string -> string * string * string
831val matched4 : string -> string * string * string * string
832val matched5 : string -> string * string * string * string * string
833val matched6 : string -> string * string * string * string * string * string
834val matched7 : string -> string * string * string * string * string * string * string
835
836val string_match_substring : Str.regexp -> string -> bool
837
838val split : string (* sep regexp *) -> string -> string list
839val join : string (* sep *) -> string list -> string
840
841val split_list_regexp : string -> string list -> (string * string list) list
842
843val all_match : string (* regexp *) -> string -> string list
485bce71
C
844val global_replace_regexp :
845 string (* regexp *) -> (string -> string) -> string -> string
846
847val regular_words: string -> string list
848val contain_regular_word: string -> bool
34e49164
C
849
850(*****************************************************************************)
851(* Filenames *)
852(*****************************************************************************)
853
854(* now at beginning of this file: type filename = string *)
855val dirname : string -> string
856val basename : string -> string
857
858val filesuffix : filename -> string
859val fileprefix : filename -> string
860
861val adjust_ext_if_needed : filename -> string -> filename
862
863(* db for dir, base *)
864val db_of_filename : filename -> (string * filename)
865val filename_of_db : (string * filename) -> filename
866
867(* dbe for dir, base, ext *)
868val dbe_of_filename : filename -> string * string * string
869val dbe_of_filename_nodot : filename -> string * string * string
870(* Left (d,b,e) | Right (d,b) if file has no extension *)
871val dbe_of_filename_safe :
872 filename -> (string * string * string, string * string) either
873
874val filename_of_dbe : string * string * string -> filename
875
876(* ex: replace_ext "toto.c" "c" "var" *)
877val replace_ext: filename -> string -> string -> filename
878
879(* remove the ., .. *)
880val normalize_path : filename -> filename
881
882val relative_to_absolute : filename -> filename
883
91eba41f
C
884val is_relative: filename -> bool
885val is_absolute: filename -> bool
886
34e49164
C
887val filename_without_leading_path : string -> filename -> filename
888
889(*****************************************************************************)
890(* i18n *)
891(*****************************************************************************)
892type langage =
893 | English
894 | Francais
895 | Deutsch
896
897(*****************************************************************************)
898(* Dates *)
899(*****************************************************************************)
900
901(* can also use ocamlcalendar, but heavier, use many modules ... *)
902
903type month =
904 | Jan | Feb | Mar | Apr | May | Jun
905 | Jul | Aug | Sep | Oct | Nov | Dec
906type year = Year of int
907type day = Day of int
908
909type date_dmy = DMY of day * month * year
910
911type hour = Hour of int
912type minute = Min of int
913type second = Sec of int
914
915type time_hms = HMS of hour * minute * second
916
917type full_date = date_dmy * time_hms
918
919
920(* intervalle *)
921type days = Days of int
922
923type time_dmy = TimeDMY of day * month * year
924
925
926(* from Unix *)
927type float_time = float
928
929
930val mk_date_dmy : int -> int -> int -> date_dmy
931
932
933val check_date_dmy : date_dmy -> unit
934val check_time_dmy : time_dmy -> unit
935val check_time_hms : time_hms -> unit
936
937val int_to_month : int -> string
938val int_of_month : month -> int
939val month_of_string : string -> month
940val month_of_string_long : string -> month
941val string_of_month : month -> string
942
943val string_of_date_dmy : date_dmy -> string
944val string_of_unix_time : ?langage:langage -> Unix.tm -> string
945val short_string_of_unix_time : ?langage:langage -> Unix.tm -> string
946val string_of_floattime: ?langage:langage -> float_time -> string
947val short_string_of_floattime: ?langage:langage -> float_time -> string
948
949val floattime_of_string: string -> float_time
950
951val dmy_to_unixtime: date_dmy -> float_time * Unix.tm
952val unixtime_to_dmy: Unix.tm -> date_dmy
953val unixtime_to_floattime: Unix.tm -> float_time
954
955val sec_to_days : int -> string
956val sec_to_hours : int -> string
957
958val today : unit -> float_time
959val yesterday : unit -> float_time
960val tomorrow : unit -> float_time
961
962val lastweek : unit -> float_time
963val lastmonth : unit -> float_time
964
965val week_before: float_time -> float_time
966val month_before: float_time -> float_time
967val week_after: float_time -> float_time
968
969val days_in_week_of_day : float_time -> float_time list
970
971val first_day_in_week_of_day : float_time -> float_time
972val last_day_in_week_of_day : float_time -> float_time
973
974val day_secs: float_time
975
976val rough_days_since_jesus : date_dmy -> days
977val rough_days_between_dates : date_dmy -> date_dmy -> days
978
979val string_of_unix_time_lfs : Unix.tm -> string
980
485bce71
C
981val is_more_recent : date_dmy -> date_dmy -> bool
982val max_dmy : date_dmy -> date_dmy -> date_dmy
983val min_dmy : date_dmy -> date_dmy -> date_dmy
984val maximum_dmy : date_dmy list -> date_dmy
985val minimum_dmy : date_dmy list -> date_dmy
34e49164
C
986
987(*****************************************************************************)
988(* Lines/Words/Strings *)
989(*****************************************************************************)
990
991val list_of_string : string -> char list
992
993val lines : string -> string list
994val unlines : string list -> string
995
996val words : string -> string list
997val unwords : string list -> string
998
999val split_space : string -> string list
1000
1001val lines_with_nl : string -> string list
1002
1003val nblines : string -> int
1004
1005(*****************************************************************************)
1006(* Process/Files *)
1007(*****************************************************************************)
1008val cat : filename -> string list
1009val cat_orig : filename -> string list
91eba41f
C
1010val cat_array: filename -> string array
1011
1012val uncat: string list -> filename -> unit
34e49164
C
1013
1014val interpolate : string -> string list
1015
1016val echo : string -> string
1017
1018val usleep : int -> unit
1019
1020val process_output_to_list : string -> string list
1021val cmd_to_list : string -> string list (* alias *)
1022val cmd_to_list_and_status : string -> string list * Unix.process_status
1023
1024val command2 : string -> unit
91eba41f 1025val _batch_mode: bool ref
34e49164
C
1026val command2_y_or_no : string -> bool
1027
1028val do_in_fork : (unit -> unit) -> int
1029
1030val mkdir: ?mode:Unix.file_perm -> string -> unit
1031
1032val read_file : filename -> string
1033val write_file : file:filename -> string -> unit
1034
1035val filesize : filename -> int
1036val filemtime : filename -> float
1037
1038val nblines_file : filename -> int
1039
1040val lfile_exists : filename -> bool
1041val is_directory : filename -> bool
1042
1043val capsule_unix : ('a -> unit) -> 'a -> unit
1044
1045val readdir_to_kind_list : string -> Unix.file_kind -> string list
1046val readdir_to_dir_list : string -> string list
1047val readdir_to_file_list : string -> string list
1048val readdir_to_link_list : string -> string list
1049val readdir_to_dir_size_list : string -> (string * int) list
1050
1051val glob : string -> filename list
1052val files_of_dir_or_files :
1053 string (* ext *) -> string list -> filename list
1054val files_of_dir_or_files_no_vcs :
1055 string (* ext *) -> string list -> filename list
1056(* use a post filter =~ for the ext filtering *)
1057val files_of_dir_or_files_no_vcs_post_filter :
1058 string (* regexp *) -> string list -> filename list
1059
1060
1061val sanity_check_files_and_adjust :
1062 string (* ext *) -> string list -> filename list
1063
1064
1065type rwx = [ `R | `W | `X ] list
1066val file_perm_of : u:rwx -> g:rwx -> o:rwx -> Unix.file_perm
1067
1068val has_env : string -> bool
1069
1070(* scheme spirit. do a finalize so no leak. *)
1071val with_open_outfile :
1072 filename -> ((string -> unit) * out_channel -> 'a) -> 'a
1073val with_open_infile :
1074 filename -> (in_channel -> 'a) -> 'a
1075val with_open_outfile_append :
1076 filename -> ((string -> unit) * out_channel -> 'a) -> 'a
1077
1078val with_open_stringbuf :
1079 (((string -> unit) * Buffer.t) -> unit) -> string
1080
1081exception Timeout
1082
1083(* subtil: have to make sure that Timeout is not intercepted before here. So
1084 * avoid exn handler such as try (...) with _ -> cos Timeout will not bubble up
1085 * enough. In such case, add a case before such as
1086 * with Timeout -> raise Timeout | _ -> ...
1087 *
1088 * The same is true for UnixExit (see below).
1089 *)
1090val timeout_function : int -> (unit -> 'a) -> 'a
1091
1092val timeout_function_opt : int option -> (unit -> 'a) -> 'a
1093
1094
1095(* creation of /tmp files, a la gcc
1096 * ex: new_temp_file "cocci" ".c" will give "/tmp/cocci-3252-434465.c"
1097 *)
1098val _temp_files_created : string list ref
1099(* see flag: val save_tmp_files : bool ref *)
1100val new_temp_file : string (* prefix *) -> string (* suffix *) -> filename
1101val erase_temp_files : unit -> unit
1102
1103(* If the user use some exit 0 in his code, then no one can intercept this
1104 * exit and do something before exiting. There is exn handler for exit 0
1105 * so better never use exit 0 but instead use an exception and just at
1106 * the very toplevel transform this exn in a unix exit code.
1107 *
1108 * subtil: same problem than with Timeout. Do not intercept such exception
1109 * with some blind try (...) with _ -> ...
1110 *)
1111exception UnixExit of int
1112val exn_to_real_unixexit : (unit -> 'a) -> 'a
1113
1114
1115
1116
1117
1118
1119
1120
1121(*###########################################################################*)
1122(* And now collection-like types. See also ocollection.mli *)
1123(*###########################################################################*)
1124
1125(*****************************************************************************)
1126(* List *)
1127(*****************************************************************************)
1128
485bce71 1129
34e49164
C
1130(* tail recursive efficient map (but that also reverse the element!) *)
1131val map_eff_rev : ('a -> 'b) -> 'a list -> 'b list
1132(* tail recursive efficient map, use accumulator *)
1133val acc_map : ('a -> 'b) -> 'a list -> 'b list
1134
1135
1136val zip : 'a list -> 'b list -> ('a * 'b) list
1137val zip_safe : 'a list -> 'b list -> ('a * 'b) list
1138val unzip : ('a * 'b) list -> 'a list * 'b list
1139
1140val take : int -> 'a list -> 'a list
1141val take_safe : int -> 'a list -> 'a list
1142val take_until : ('a -> bool) -> 'a list -> 'a list
1143val take_while : ('a -> bool) -> 'a list -> 'a list
1144
1145val drop : int -> 'a list -> 'a list
1146val drop_while : ('a -> bool) -> 'a list -> 'a list
1147val drop_until : ('a -> bool) -> 'a list -> 'a list
1148
1149val span : ('a -> bool) -> 'a list -> 'a list * 'a list
1150
1151val skip_until : ('a list -> bool) -> 'a list -> 'a list
1152val skipfirst : 'a -> 'a list -> 'a list
1153
1154(* cf also List.partition *)
1155val fpartition : ('a -> 'b option) -> 'a list -> 'b list * 'a list
1156
1157val groupBy : ('a -> 'a -> bool) -> 'a list -> 'a list list
1158val exclude_but_keep_attached: ('a -> bool) -> 'a list -> ('a * 'a list) list
485bce71 1159val group_by_post: ('a -> bool) -> 'a list -> ('a list * 'a) list * 'a list
34e49164 1160
91eba41f
C
1161(* Use hash internally to not be in O(n2). If you want to use it on a
1162 * simple list, then first do a List.map to generate a key, for instance the
1163 * first char of the element, and then use this function.
1164 *)
34e49164
C
1165val group_assoc_bykey_eff : ('a * 'b) list -> ('a * 'b list) list
1166
1167val splitAt : int -> 'a list -> 'a list * 'a list
1168
1169val split_when: ('a -> bool) -> 'a list -> 'a list * 'a * 'a list
1170val split_gen_when: ('a list -> 'a list option) -> 'a list -> 'a list list
1171
1172val pack : int -> 'a list -> 'a list list
1173
1174
1175val enum : int -> int -> int list
1176val repeat : 'a -> int -> 'a list
1177val generate : int -> 'a -> 'a list
1178
1179
1180
1181val index_list : 'a list -> ('a * int) list
1182val index_list_1 : 'a list -> ('a * int) list
1183val index_list_and_total : 'a list -> ('a * int * int) list
1184
1185val iter_index : ('a -> int -> 'b) -> 'a list -> unit
1186val map_index : ('a -> int -> 'b) -> 'a list -> 'b list
1187val filter_index : (int -> 'a -> bool) -> 'a list -> 'a list
1188val fold_left_with_index : ('a -> 'b -> int -> 'a) -> 'a -> 'b list -> 'a
1189
1190val nth : 'a list -> int -> 'a
1191val rang : 'a -> 'a list -> int
1192
1193val last_n : int -> 'a list -> 'a list
1194
1195
1196
1197val snoc : 'a -> 'a list -> 'a list
1198val cons : 'a -> 'a list -> 'a list
1199val uncons : 'a list -> 'a * 'a list
1200val safe_tl : 'a list -> 'a list
1201val head_middle_tail : 'a list -> 'a * 'a list * 'a
1202val last : 'a list -> 'a
1203val list_init : 'a list -> 'a list
1204val list_last : 'a list -> 'a
1205val removelast : 'a list -> 'a list
1206
1207val inits : 'a list -> 'a list list
1208val tails : 'a list -> 'a list list
1209
1210
1211val ( ++ ) : 'a list -> 'a list -> 'a list
1212
1213val foldl1 : ('a -> 'a -> 'a) -> 'a list -> 'a
1214val fold_k : ('a -> 'b -> ('a -> 'a) -> 'a) -> ('a -> 'a) -> 'a -> 'b list -> 'a
1215val fold_right1 : ('a -> 'a -> 'a) -> 'a list -> 'a
1216val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a
1217
1218val rev_map : ('a -> 'b) -> 'a list -> 'b list
1219
1220val join_gen : 'a -> 'a list -> 'a list
1221
1222val do_withenv :
1223 (('a -> 'b) -> 'c -> 'd) -> ('e -> 'a -> 'b * 'e) -> 'e -> 'c -> 'd * 'e
1224val map_withenv : ('a -> 'b -> 'c * 'a) -> 'a -> 'b list -> 'c list * 'a
113803cf 1225val map_withkeep: ('a -> 'b) -> 'a list -> ('b * 'a) list
34e49164
C
1226
1227val collect_accu : ('a -> 'b list) -> 'b list -> 'a list -> 'b list
1228val collect : ('a -> 'b list) -> 'a list -> 'b list
1229
1230val remove : 'a -> 'a list -> 'a list
1231
1232val exclude : ('a -> bool) -> 'a list -> 'a list
1233
1234(* Not like unix uniq command line tool that only delete contiguous repeated
1235 * line. Here we delete any repeated line (here list element).
1236 *)
1237val uniq : 'a list -> 'a list
91eba41f
C
1238val uniq_eff: 'a list -> 'a list
1239
113803cf
C
1240val has_no_duplicate: 'a list -> bool
1241val is_set_as_list: 'a list -> bool
1242val get_duplicates: 'a list -> 'a list
1243
34e49164
C
1244val doublon : 'a list -> bool
1245
1246val reverse : 'a list -> 'a list (* alias *)
1247val rev : 'a list -> 'a list (* alias *)
1248val rotate : 'a list -> 'a list
1249
1250val map_flatten : ('a -> 'b list) -> 'a list -> 'b list
1251
1252val map2 : ('a -> 'b) -> 'a list -> 'b list
1253val map3 : ('a -> 'b) -> 'a list -> 'b list
1254
1255
1256val maximum : 'a list -> 'a
1257val minimum : 'a list -> 'a
1258
1259val min_with : ('a -> 'b) -> 'a list -> 'a
1260val two_mins_with : ('a -> 'b) -> 'a list -> 'a * 'a
1261
1262val all_assoc : 'a -> ('a * 'b) list -> 'b list
1263val prepare_want_all_assoc : ('a * 'b) list -> ('a * 'b list) list
1264
1265val or_list : bool list -> bool
1266val and_list : bool list -> bool
1267
485bce71
C
1268val sum_float : float list -> float
1269val sum_int : int list -> int
1270val avg_list: int list -> float
1271
34e49164
C
1272val return_when : ('a -> 'b option) -> 'a list -> 'b
1273
1274
1275val grep_with_previous : ('a -> 'a -> bool) -> 'a list -> 'a list
1276val iter_with_previous : ('a -> 'a -> 'b) -> 'a list -> unit
1277
1278val iter_with_before_after :
1279 ('a list -> 'a -> 'a list -> unit) -> 'a list -> unit
1280
1281val get_pair : 'a list -> ('a * 'a) list
1282
1283val permutation : 'a list -> 'a list list
1284
1285val remove_elem_pos : int -> 'a list -> 'a list
1286val insert_elem_pos : ('a * int) -> 'a list -> 'a list
1287val uncons_permut : 'a list -> (('a * int) * 'a list) list
1288val uncons_permut_lazy : 'a list -> (('a * int) * 'a list Lazy.t) list
1289
1290
1291val pack_sorted : ('a -> 'a -> bool) -> 'a list -> 'a list list
1292
1293val keep_best : ('a * 'a -> 'a option) -> 'a list -> 'a list
1294val sorted_keep_best : ('a -> 'a -> 'a option) -> 'a list -> 'a list
1295
91eba41f 1296
34e49164
C
1297val cartesian_product : 'a list -> 'b list -> ('a * 'b) list
1298
1299(* old stuff *)
1300val surEnsemble : 'a list -> 'a list list -> 'a list list
1301val realCombinaison : 'a list -> 'a list list
1302val combinaison : 'a list -> ('a * 'a) list
1303val insere : 'a -> 'a list list -> 'a list list
1304val insereListeContenant : 'a list -> 'a -> 'a list list -> 'a list list
1305val fusionneListeContenant : 'a * 'a -> 'a list list -> 'a list list
1306
1307(*****************************************************************************)
1308(* Arrays *)
1309(*****************************************************************************)
1310
1311val array_find_index : ('a -> bool) -> 'a array -> int
1312
91eba41f
C
1313(*****************************************************************************)
1314(* Matrix *)
1315(*****************************************************************************)
1316
34e49164
C
1317type 'a matrix = 'a array array
1318
1319val map_matrix : ('a -> 'b) -> 'a matrix -> 'b matrix
1320
91eba41f
C
1321val make_matrix_init:
1322 nrow:int -> ncolumn:int -> (int -> int -> 'a) -> 'a matrix
1323
1324val iter_matrix:
1325 (int -> int -> 'a -> unit) -> 'a matrix -> unit
1326
1327val nb_rows_matrix: 'a matrix -> int
1328val nb_columns_matrix: 'a matrix -> int
1329
1330val rows_of_matrix: 'a matrix -> 'a list list
1331val columns_of_matrix: 'a matrix -> 'a list list
1332
1333val all_elems_matrix_by_row: 'a matrix -> 'a list
1334
34e49164
C
1335(*****************************************************************************)
1336(* Fast array *)
1337(*****************************************************************************)
1338
1339(* ?? *)
1340
1341(*****************************************************************************)
1342(* Set. But have a look too at set*.mli; it's better. Or use Hashtbl. *)
1343(*****************************************************************************)
1344
1345type 'a set = 'a list
1346
1347val empty_set : 'a set
1348
1349val insert_set : 'a -> 'a set -> 'a set
1350val single_set : 'a -> 'a set
1351val set : 'a list -> 'a set
1352
113803cf
C
1353val is_set: 'a list -> bool
1354
34e49164
C
1355val exists_set : ('a -> bool) -> 'a set -> bool
1356val forall_set : ('a -> bool) -> 'a set -> bool
1357
1358val filter_set : ('a -> bool) -> 'a set -> 'a set
1359val fold_set : ('a -> 'b -> 'a) -> 'a -> 'b set -> 'a
1360val map_set : ('a -> 'b) -> 'a set -> 'b set
1361
1362val member_set : 'a -> 'a set -> bool
1363val find_set : ('a -> bool) -> 'a list -> 'a
1364
1365val sort_set : ('a -> 'a -> int) -> 'a list -> 'a list
1366
1367val iter_set : ('a -> unit) -> 'a list -> unit
1368
1369val top_set : 'a set -> 'a
1370
1371val inter_set : 'a set -> 'a set -> 'a set
1372val union_set : 'a set -> 'a set -> 'a set
1373val minus_set : 'a set -> 'a set -> 'a set
1374
1375val union_all : ('a set) list -> 'a set
1376
1377val big_union_set : ('a -> 'b set) -> 'a set -> 'b set
1378val card_set : 'a set -> int
1379
1380val include_set : 'a set -> 'a set -> bool
1381val equal_set : 'a set -> 'a set -> bool
1382val include_set_strict : 'a set -> 'a set -> bool
1383
1384(* could put them in Common.Infix *)
1385val ( $*$ ) : 'a set -> 'a set -> 'a set
1386val ( $+$ ) : 'a set -> 'a set -> 'a set
1387val ( $-$ ) : 'a set -> 'a set -> 'a set
1388
1389val ( $?$ ) : 'a -> 'a set -> bool
1390val ( $<$ ) : 'a set -> 'a set -> bool
1391val ( $<=$ ) : 'a set -> 'a set -> bool
1392val ( $=$ ) : 'a set -> 'a set -> bool
1393
1394val ( $@$ ) : 'a list -> 'a list -> 'a list
1395
1396val nub : 'a list -> 'a list
1397
1398(* use internally a hash and return
1399 * - the common part,
1400 * - part only in a,
1401 * - part only in b
1402 *)
1403val diff_two_say_set_eff : 'a list -> 'a list ->
1404 'a list * 'a list * 'a list
1405
1406(*****************************************************************************)
1407(* Set as normal list *)
1408(*****************************************************************************)
1409
1410(* cf above *)
1411
1412(*****************************************************************************)
1413(* Set as sorted list *)
1414(*****************************************************************************)
1415
1416
1417(*****************************************************************************)
1418(* Sets specialized *)
1419(*****************************************************************************)
1420
1421(*
1422module StringSet = Set.Make(struct type t = string let compare = compare end)
1423*)
1424
1425
1426(*****************************************************************************)
1427(* Assoc. But have a look too at Mapb.mli; it's better. Or use Hashtbl. *)
1428(*****************************************************************************)
1429
1430type ('a, 'b) assoc = ('a * 'b) list
1431
1432val assoc_to_function : ('a, 'b) assoc -> ('a -> 'b)
1433
1434val empty_assoc : ('a, 'b) assoc
1435val fold_assoc : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a
1436val insert_assoc : 'a -> 'a list -> 'a list
1437val map_assoc : ('a -> 'b) -> 'a list -> 'b list
1438val filter_assoc : ('a -> bool) -> 'a list -> 'a list
1439
1440val assoc : 'a -> ('a * 'b) list -> 'b
1441
1442val keys : ('a * 'b) list -> 'a list
1443val lookup : 'a -> ('a * 'b) list -> 'b
1444
1445val del_assoc : 'a -> ('a * 'b) list -> ('a * 'b) list
1446val replace_assoc : 'a * 'b -> ('a * 'b) list -> ('a * 'b) list
1447val apply_assoc : 'a -> ('b -> 'b) -> ('a * 'b) list -> ('a * 'b) list
1448
1449val big_union_assoc : ('a -> 'b set) -> 'a list -> 'b set
1450
1451val assoc_reverse : ('a * 'b) list -> ('b * 'a) list
1452val assoc_map : ('a * 'b) list -> ('a * 'b) list -> ('a * 'a) list
1453
1454val lookup_list : 'a -> ('a, 'b) assoc list -> 'b
1455val lookup_list2 : 'a -> ('a, 'b) assoc list -> 'b * int
1456
1457val assoc_option : 'a -> ('a, 'b) assoc -> 'b option
485bce71 1458val assoc_with_err_msg : 'a -> ('a, 'b) assoc -> 'b
34e49164 1459
113803cf
C
1460val sort_by_val_lowfirst: ('a,'b) assoc -> ('a * 'b) list
1461val sort_by_val_highfirst: ('a,'b) assoc -> ('a * 'b) list
1462
1463val sort_by_key_lowfirst: (int,'b) assoc -> (int * 'b) list
1464val sort_by_key_highfirst: (int,'b) assoc -> (int * 'b) list
91eba41f 1465
34e49164
C
1466(*****************************************************************************)
1467(* Assoc, specialized. *)
1468(*****************************************************************************)
1469
1470module IntMap :
1471 sig
1472 type key = int
1473 type +'a t
1474 val empty : 'a t
1475 val is_empty : 'a t -> bool
1476 val add : key -> 'a -> 'a t -> 'a t
1477 val find : key -> 'a t -> 'a
1478 val remove : key -> 'a t -> 'a t
1479 val mem : key -> 'a t -> bool
1480 val iter : (key -> 'a -> unit) -> 'a t -> unit
1481 val map : ('a -> 'b) -> 'a t -> 'b t
1482 val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t
1483 val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
1484 val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
1485 val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
1486 end
1487val intmap_to_list : 'a IntMap.t -> (IntMap.key * 'a) list
1488val intmap_string_of_t : 'a -> 'b -> string
1489
1490module IntIntMap :
1491 sig
1492 type key = int * int
1493 type +'a t
1494 val empty : 'a t
1495 val is_empty : 'a t -> bool
1496 val add : key -> 'a -> 'a t -> 'a t
1497 val find : key -> 'a t -> 'a
1498 val remove : key -> 'a t -> 'a t
1499 val mem : key -> 'a t -> bool
1500 val iter : (key -> 'a -> unit) -> 'a t -> unit
1501 val map : ('a -> 'b) -> 'a t -> 'b t
1502 val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t
1503 val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
1504 val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
1505 val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
1506 end
1507val intintmap_to_list : 'a IntIntMap.t -> (IntIntMap.key * 'a) list
1508val intintmap_string_of_t : 'a -> 'b -> string
1509
1510
1511(*****************************************************************************)
1512(* Hash *)
1513(*****************************************************************************)
1514
1515(* Note that Hashtbl keep old binding to a key so if want a hash
1516 * of a list, then can use the Hashtbl as is. Use Hashtbl.find_all then
1517 * to get the list of bindings
1518 *
1519 * Note that Hashtbl module use different convention :( the object is
1520 * the first argument, not last as for List or Map.
1521 *)
1522
1523(* obsolete: can use directly the Hashtbl module *)
1524val hcreate : unit -> ('a, 'b) Hashtbl.t
1525val hadd : 'a * 'b -> ('a, 'b) Hashtbl.t -> unit
1526val hmem : 'a -> ('a, 'b) Hashtbl.t -> bool
1527val hfind : 'a -> ('a, 'b) Hashtbl.t -> 'b
1528val hreplace : 'a * 'b -> ('a, 'b) Hashtbl.t -> unit
1529val hiter : ('a -> 'b -> unit) -> ('a, 'b) Hashtbl.t -> unit
1530val hfold : ('a -> 'b -> 'c -> 'c) -> ('a, 'b) Hashtbl.t -> 'c -> 'c
1531val hremove : 'a -> ('a, 'b) Hashtbl.t -> unit
1532
1533
1534val hfind_default : 'a -> (unit -> 'b) -> ('a, 'b) Hashtbl.t -> 'b
1535val hfind_option : 'a -> ('a, 'b) Hashtbl.t -> 'b option
1536val hupdate_default :
1537 'a -> ('b -> 'b) -> (unit -> 'b) -> ('a, 'b) Hashtbl.t -> unit
1538
1539val hash_to_list : ('a, 'b) Hashtbl.t -> ('a * 'b) list
1540val hash_to_list_unsorted : ('a, 'b) Hashtbl.t -> ('a * 'b) list
1541val hash_of_list : ('a * 'b) list -> ('a, 'b) Hashtbl.t
1542
1543
1544val hkeys : ('a, 'b) Hashtbl.t -> 'a list
1545
1546(*****************************************************************************)
1547(* Hash sets *)
1548(*****************************************************************************)
1549
1550type 'a hashset = ('a, bool) Hashtbl.t
1551
1552
1553(* common use of hashset, in a hash of hash *)
1554val hash_hashset_add : 'a -> 'b -> ('a, 'b hashset) Hashtbl.t -> unit
1555
1556val hashset_to_set :
1557 < fromlist : ('a ) list -> 'c; .. > -> ('a, 'b) Hashtbl.t -> 'c
1558
1559val hashset_to_list : 'a hashset -> 'a list
1560val hashset_of_list : 'a list -> 'a hashset
1561
1562
1563(*****************************************************************************)
1564(* Stack *)
1565(*****************************************************************************)
1566
1567type 'a stack = 'a list
1568val empty_stack : 'a stack
1569val push : 'a -> 'a stack -> 'a stack
1570val top : 'a stack -> 'a
1571val pop : 'a stack -> 'a stack
1572
91eba41f
C
1573val top_option: 'a stack -> 'a option
1574
34e49164
C
1575val push2 : 'a -> 'a stack ref -> unit
1576val pop2: 'a stack ref -> 'a
1577
91eba41f
C
1578(*****************************************************************************)
1579(* Stack with undo/redo support *)
1580(*****************************************************************************)
1581
1582type 'a undo_stack = 'a list * 'a list
1583val empty_undo_stack : 'a undo_stack
1584val push_undo : 'a -> 'a undo_stack -> 'a undo_stack
1585val top_undo : 'a undo_stack -> 'a
1586val pop_undo : 'a undo_stack -> 'a undo_stack
1587val redo_undo: 'a undo_stack -> 'a undo_stack
1588val undo_pop: 'a undo_stack -> 'a undo_stack
1589
1590val top_undo_option: 'a undo_stack -> 'a option
1591
34e49164
C
1592
1593(*****************************************************************************)
1594(* Binary tree *)
1595(*****************************************************************************)
1596type 'a bintree = Leaf of 'a | Branch of ('a bintree * 'a bintree)
1597
1598(*****************************************************************************)
1599(* N-ary tree *)
1600(*****************************************************************************)
1601
1602(* no empty tree, must have one root at least *)
1603type 'a tree = Tree of 'a * ('a tree) list
1604
1605val tree_iter : ('a -> unit) -> 'a tree -> unit
1606
1607
1608(*****************************************************************************)
1609(* N-ary tree with updatable childrens *)
1610(*****************************************************************************)
1611
1612(* Leaf can seem redundant, but sometimes want to directly see if
1613 * a children is a leaf without looking if the list is empty.
1614 *)
1615type ('a, 'b) treeref =
1616 | NodeRef of 'a * ('a, 'b) treeref list ref
1617 | LeafRef of 'b
1618
1619val treeref_node_iter:
1620 (('a * ('a, 'b) treeref list ref) -> unit) -> ('a, 'b) treeref -> unit
1621val treeref_node_iter_with_parents:
1622 (('a * ('a, 'b) treeref list ref) -> ('a list) -> unit) ->
1623 ('a, 'b) treeref -> unit
1624
1625val find_treeref:
1626 (('a * ('a, 'b) treeref list ref) -> bool) ->
1627 ('a, 'b) treeref -> ('a, 'b) treeref
1628
91eba41f 1629val treeref_children_ref: ('a, 'b) treeref -> ('a, 'b) treeref list ref
34e49164 1630
91eba41f
C
1631val find_treeref_with_parents_some:
1632 ('a * ('a, 'b) treeref list ref -> 'a list -> 'c option) ->
1633 ('a, 'b) treeref -> 'c
34e49164 1634
91eba41f
C
1635val find_multi_treeref_with_parents_some:
1636 ('a * ('a, 'b) treeref list ref -> 'a list -> 'c option) ->
1637 ('a, 'b) treeref -> 'c list
34e49164
C
1638
1639
1640(*****************************************************************************)
1641(* Graph. But have a look too at Ograph_*.mli; it's better *)
1642(*****************************************************************************)
1643
1644type 'a graph = 'a set * ('a * 'a) set
1645
1646val add_node : 'a -> 'a graph -> 'a graph
1647val del_node : 'a -> 'a graph -> 'a graph
1648
1649val add_arc : 'a * 'a -> 'a graph -> 'a graph
1650val del_arc : 'a * 'a -> 'a graph -> 'a graph
1651
1652val successors : 'a -> 'a graph -> 'a set
1653val predecessors : 'a -> 'a graph -> 'a set
1654
1655val nodes : 'a graph -> 'a set
1656
1657val fold_upward : ('a -> 'b -> 'a) -> 'b set -> 'a -> 'b graph -> 'a
1658
1659val empty_graph : 'a list * 'b list
1660
1661
1662(*****************************************************************************)
1663(* Generic op *)
1664(*****************************************************************************)
1665
1666(* mostly alias to functions in List *)
1667
1668val map : ('a -> 'b) -> 'a list -> 'b list
1669val filter : ('a -> bool) -> 'a list -> 'a list
1670val fold : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a
1671
1672val member : 'a -> 'a list -> bool
1673
1674val iter : ('a -> unit) -> 'a list -> unit
1675
1676val find : ('a -> bool) -> 'a list -> 'a
1677
1678val exists : ('a -> bool) -> 'a list -> bool
1679val forall : ('a -> bool) -> 'a list -> bool
1680
1681val big_union : ('a -> 'b set) -> 'a list -> 'b set
1682
1683(* same than [] but easier to search for, because [] can also be a pattern *)
1684val empty_list : 'a list
1685
1686val sort : ('a -> 'a -> int) -> 'a list -> 'a list
1687
1688val length : 'a list -> int
1689
1690val null : 'a list -> bool
1691
1692val head : 'a list -> 'a
1693val tail : 'a list -> 'a list
1694
1695val is_singleton : 'a list -> bool
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705(*###########################################################################*)
1706(* And now misc functions *)
1707(*###########################################################################*)
1708
1709(*****************************************************************************)
1710(* DB (LFS) *)
1711(*****************************************************************************)
1712
1713(* cf oassocbdb.ml or oassocdbm.ml *)
1714
1715(*****************************************************************************)
1716(* GUI (LFS, CComment, otimetracker) *)
1717(*****************************************************************************)
1718
1719(* cf ocamlgtk and my gui.ml *)
1720
1721
1722(*****************************************************************************)
1723(* Graphics (otimetracker) *)
1724(*****************************************************************************)
1725
1726(* cf ocamlgl and my opengl.ml *)
1727
1728
1729
1730(*****************************************************************************)
1731(* Geometry (ICFP raytracer) *)
1732(*****************************************************************************)
1733
1734type vector = float * float * float
1735
1736type point = vector
1737type color = vector
1738
1739val dotproduct : vector * vector -> float
1740
1741val vector_length : vector -> float
1742
1743val minus_point : point * point -> vector
1744
1745val distance : point * point -> float
1746
1747val normalise : vector -> vector
1748
1749val mult_coeff : vector -> float -> vector
1750
1751val add_vector : vector -> vector -> vector
1752val mult_vector : vector -> vector -> vector
1753val sum_vector : vector list -> vector
1754
1755
1756(*****************************************************************************)
1757(* Pics (ICFP raytracer) *)
1758(*****************************************************************************)
1759type pixel = int * int * int
1760val write_ppm : int -> int -> pixel list -> filename -> unit
1761val test_ppm1 : unit -> unit
1762
1763(*****************************************************************************)
1764(* Diff (LFS) *)
1765(*****************************************************************************)
1766
1767type diff = Match | BnotinA | AnotinB
1768val diff : (int -> int -> diff -> unit) -> string list * string list -> unit
1769val diff2 : (int -> int -> diff -> unit) -> string * string -> unit
1770
1771(*****************************************************************************)
1772(* Parsers (aop-colcombet) *)
1773(*****************************************************************************)
1774
1775val parserCommon : Lexing.lexbuf -> ('a -> Lexing.lexbuf -> 'b) -> 'a -> 'b
1776val getDoubleParser :
1777 ('a -> Lexing.lexbuf -> 'b) -> 'a -> (string -> 'b) * (string -> 'b)
1778
1779(*****************************************************************************)
1780(* Parsers (cocci) *)
1781(*****************************************************************************)
1782
1783
1784(* Currently lexing.ml does not handle the line number position.
1785 * Even if there is some fields in the lexing structure, they are not
1786 * maintained by the lexing engine :( So the following code does not work:
1787 *
1788 * let pos = Lexing.lexeme_end_p lexbuf in
1789 * sprintf "at file %s, line %d, char %d" pos.pos_fname pos.pos_lnum
1790 * (pos.pos_cnum - pos.pos_bol) in
1791 *
1792 * Hence those functions to overcome the previous limitation.
1793 *)
1794
1795type parse_info = {
1796 str: string;
1797 charpos: int;
1798
1799 line: int;
1800 column: int;
1801 file: filename;
1802 }
1803val fake_parse_info : parse_info
1804val string_of_parse_info : parse_info -> string
485bce71 1805val string_of_parse_info_bis : parse_info -> string
34e49164
C
1806
1807(* array[i] will contain the (line x col) of the i char position *)
1808val full_charpos_to_pos : filename -> (int * int) array
1809
1810(* fill in the line and column field of parse_info that were not set
1811 * during lexing because of limitations of ocamllex. *)
1812val complete_parse_info :
1813 filename -> (int * int) array -> parse_info -> parse_info
1814
1815(* return line x col x str_line from a charpos. This function is quite
1816 * expensive so don't use it to get the line x col from every token in
1817 * a file. Instead use full_charpos_to_pos.
1818 *)
1819val info_from_charpos : int -> filename -> (int * int * string)
1820
1821val error_message : filename -> (string * int) -> string
1822val error_message_short : filename -> (string * int) -> string
1823
1824(* add a 'decalage/shift' argument to handle stuff such as cpp which includes
1825 * files and who can make shift.
1826 *)
1827val error_messagebis : filename -> (string * int) -> int -> string
1828
1829(*****************************************************************************)
1830(* Scope managment (cocci) *)
1831(*****************************************************************************)
1832
1833(* for example of use, see the code used in coccinelle *)
1834type ('a, 'b) scoped_env = ('a, 'b) assoc list
1835
1836val lookup_env : 'a -> ('a, 'b) scoped_env -> 'b
1837val member_env_key : 'a -> ('a, 'b) scoped_env -> bool
1838
1839val new_scope : ('a, 'b) scoped_env ref -> unit
1840val del_scope : ('a, 'b) scoped_env ref -> unit
1841
1842val do_in_new_scope : ('a, 'b) scoped_env ref -> (unit -> unit) -> unit
1843
1844val add_in_scope : ('a, 'b) scoped_env ref -> 'a * 'b -> unit
1845
1846
1847
1848
1849(* for example of use, see the code used in coccinelle *)
1850type ('a, 'b) scoped_h_env = {
1851 scoped_h : ('a, 'b) Hashtbl.t;
1852 scoped_list : ('a, 'b) assoc list;
1853}
1854val empty_scoped_h_env : unit -> ('a, 'b) scoped_h_env
1855val clone_scoped_h_env : ('a, 'b) scoped_h_env -> ('a, 'b) scoped_h_env
1856
1857val lookup_h_env : 'a -> ('a, 'b) scoped_h_env -> 'b
1858val member_h_env_key : 'a -> ('a, 'b) scoped_h_env -> bool
1859
1860val new_scope_h : ('a, 'b) scoped_h_env ref -> unit
1861val del_scope_h : ('a, 'b) scoped_h_env ref -> unit
1862
1863val do_in_new_scope_h : ('a, 'b) scoped_h_env ref -> (unit -> unit) -> unit
1864
1865val add_in_scope_h : ('a, 'b) scoped_h_env ref -> 'a * 'b -> unit
1866
1867(*****************************************************************************)
1868(* Terminal (LFS) *)
1869(*****************************************************************************)
1870
91eba41f
C
1871(* don't forget to call Common_extra.set_link () *)
1872
34e49164
C
1873val _execute_and_show_progress_func :
1874 (int (* length *) -> ((unit -> unit) -> unit) -> unit) ref
1875val execute_and_show_progress :
1876 int (* length *) -> ((unit -> unit) -> unit) -> unit
1877
1878(*****************************************************************************)
1879(* Flags and actions *)
1880(*****************************************************************************)
1881
1882val cmdline_flags_devel : unit -> cmdline_options
1883val cmdline_flags_verbose : unit -> cmdline_options
1884val cmdline_flags_other : unit -> cmdline_options
1885
1886(*****************************************************************************)
1887(* Misc/test *)
1888(*****************************************************************************)
1889
1890val generic_print : 'a -> string -> string
1891
1892class ['a] olist :
1893 'a list ->
1894 object
1895 val xs : 'a list
1896 method fold : ('b -> 'a -> 'b) -> 'b -> 'b
1897 method view : 'a list
1898 end
1899
1900val typing_sux_test : unit -> unit
1901