PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/src/utils/misc.mli

http://github.com/colinbenner/ocamlllvm
OCaml | 104 lines | 28 code | 14 blank | 62 comment | 0 complexity | 84b906763253db5948e50c0a8f30343d MD5 | raw file
Possible License(s): LGPL-2.0
  1. (***********************************************************************)
  2. (* *)
  3. (* Objective Caml *)
  4. (* *)
  5. (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
  6. (* *)
  7. (* Copyright 1996 Institut National de Recherche en Informatique et *)
  8. (* en Automatique. All rights reserved. This file is distributed *)
  9. (* under the terms of the Q Public License version 1.0. *)
  10. (* *)
  11. (***********************************************************************)
  12. (* $Id: misc.mli 9547 2010-01-22 12:48:24Z doligez $ *)
  13. (* Miscellaneous useful types and functions *)
  14. val fatal_error: string -> 'a
  15. exception Fatal_error
  16. val try_finally : (unit -> 'a) -> (unit -> unit) -> 'a;;
  17. val map_end: ('a -> 'b) -> 'a list -> 'b list -> 'b list
  18. (* [map_end f l t] is [map f l @ t], just more efficient. *)
  19. val map_left_right: ('a -> 'b) -> 'a list -> 'b list
  20. (* Like [List.map], with guaranteed left-to-right evaluation order *)
  21. val for_all2: ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
  22. (* Same as [List.for_all] but for a binary predicate.
  23. In addition, this [for_all2] never fails: given two lists
  24. with different lengths, it returns false. *)
  25. val replicate_list: 'a -> int -> 'a list
  26. (* [replicate_list elem n] is the list with [n] elements
  27. all identical to [elem]. *)
  28. val list_remove: 'a -> 'a list -> 'a list
  29. (* [list_remove x l] returns a copy of [l] with the first
  30. element equal to [x] removed. *)
  31. val split_last: 'a list -> 'a list * 'a
  32. (* Return the last element and the other elements of the given list. *)
  33. val samelist: ('a -> 'a -> bool) -> 'a list -> 'a list -> bool
  34. (* Like [List.for_all2] but returns [false] if the two
  35. lists have different length. *)
  36. val may: ('a -> unit) -> 'a option -> unit
  37. val may_map: ('a -> 'b) -> 'a option -> 'b option
  38. val find_in_path: string list -> string -> string
  39. (* Search a file in a list of directories. *)
  40. val find_in_path_uncap: string list -> string -> string
  41. (* Same, but search also for uncapitalized name, i.e.
  42. if name is Foo.ml, allow /path/Foo.ml and /path/foo.ml
  43. to match. *)
  44. val remove_file: string -> unit
  45. (* Delete the given file if it exists. Never raise an error. *)
  46. val expand_directory: string -> string -> string
  47. (* [expand_directory alt file] eventually expands a [+] at the
  48. beginning of file into [alt] (an alternate root directory) *)
  49. val create_hashtable: int -> ('a * 'b) list -> ('a, 'b) Hashtbl.t
  50. (* Create a hashtable of the given size and fills it with the
  51. given bindings. *)
  52. val copy_file: in_channel -> out_channel -> unit
  53. (* [copy_file ic oc] reads the contents of file [ic] and copies
  54. them to [oc]. It stops when encountering EOF on [ic]. *)
  55. val copy_file_chunk: in_channel -> out_channel -> int -> unit
  56. (* [copy_file_chunk ic oc n] reads [n] bytes from [ic] and copies
  57. them to [oc]. It raises [End_of_file] when encountering
  58. EOF on [ic]. *)
  59. val log2: int -> int
  60. (* [log2 n] returns [s] such that [n = 1 lsl s]
  61. if [n] is a power of 2*)
  62. val align: int -> int -> int
  63. (* [align n a] rounds [n] upwards to a multiple of [a]
  64. (a power of 2). *)
  65. val no_overflow_add: int -> int -> bool
  66. (* [no_overflow_add n1 n2] returns [true] if the computation of
  67. [n1 + n2] does not overflow. *)
  68. val no_overflow_sub: int -> int -> bool
  69. (* [no_overflow_add n1 n2] returns [true] if the computation of
  70. [n1 - n2] does not overflow. *)
  71. val no_overflow_lsl: int -> bool
  72. (* [no_overflow_add n] returns [true] if the computation of
  73. [n lsl 1] does not overflow. *)
  74. val chop_extension_if_any: string -> string
  75. (* Like Filename.chop_extension but returns the initial file
  76. name if it has no extension *)
  77. val chop_extensions: string -> string
  78. (* Return the given file name without its extensions. The extensions
  79. is the longest suffix starting with a period and not including
  80. a directory separator, [.xyz.uvw] for instance.
  81. Return the given name if it does not contain an extension. *)
  82. val search_substring: string -> string -> int -> int
  83. (* [search_substring pat str start] returns the position of the first
  84. occurrence of string [pat] in string [str]. Search starts
  85. at offset [start] in [str]. Raise [Not_found] if [pat]
  86. does not occur. *)
  87. val rev_split_words: string -> string list
  88. (* [rev_split_words s] splits [s] in blank-separated words, and return
  89. the list of words in reverse order. *)