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