types.mli 5.52 KB
Newer Older
1 2
open Ident

3 4 5
type const = | Integer of Intervals.v
	     | Atom of Atoms.v 
	     | Char of Chars.v
6

7 8
val compare_const: const -> const -> int
val hash_const: const -> int
9
val equal_const: const -> const -> bool
10

11 12
(** Algebra **)

13 14
type node
type descr
15

16 17
val make: unit -> node
val define: node -> descr -> unit
18

19 20
val cons: descr -> node
val internalize: node -> node
21

22 23
val id: node -> int
val descr: node -> descr
24

25 26
val equal_descr: descr -> descr -> bool
val hash_descr: descr -> int
27
val compare_descr: descr -> descr -> int
28

29
module DescrHash: Hashtbl.S with type key = descr
30
module DescrSList: SortedList.S with type 'a elem = descr
31
module DescrMap: Map.S with type key = descr
32
module DescrSet: Set.S with type elt = descr
33

34 35
(** Boolean connectives **)

36 37 38 39 40 41
val cup    : descr -> descr -> descr
val cap    : descr -> descr -> descr
val diff   : descr -> descr -> descr
val neg    : descr -> descr
val empty  : descr
val any    : descr
42

43 44
val any_node : node

45 46
val non_constructed : descr

47 48
(** Constructors **)

49 50
type pair_kind = [ `Normal | `XML ]

51
val interval : Intervals.t -> descr
52
val atom     : Atoms.t -> descr
53
val times    : node -> node -> descr
54
val xml      : node -> node -> descr
55
val arrow    : node -> node -> descr
56
val record   : label -> node -> descr
57
  (* bool = true -> open record; bool = false -> closed record *)
58
val record'  : bool * node label_map -> descr
59
val char     : Chars.t -> descr
60
val constant : const -> descr
61

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
(** Helpers *)

  (** given a list of descrs create an OR type including all descrs *)
val choice_of_list: descr list -> descr

  (** do it yourself: create an Xml type from three types (tag type, attribute
  type, content type) *)
val xml': descr -> descr -> descr -> descr

  (** Build a record from a list of <name,descr> pairs. Open defaults to true.
  All specified fields are required. *)
val rec_of_list: ?opened:bool -> (string * descr) list -> descr

  (** Similiar to rec_of_list, the additional boolean value specify whether the
  specified field is optional (true) or not (false. *)
val rec_of_list': ?opened:bool -> (bool * string * descr) list -> descr

val empty_closed_record: descr
val empty_opened_record: descr

82 83 84 85 86 87 88
(** Positive systems and least solutions **)

module Positive :
sig
  type v
  val forward: unit -> v
  val define: v -> v -> unit
89
  val ty: descr -> v
90 91
  val cup: v list -> v
  val times: v -> v -> v
92
  val xml: v -> v -> v
93

94
  val solve: v -> node
95 96 97 98 99
end

(** Normalization **)

module Product : sig
100
  val any : descr
101 102 103
  val any_xml : descr
  val other : ?kind:pair_kind -> descr -> descr
  val is_product : ?kind:pair_kind -> descr -> bool
104 105 106

  (* List of non-empty rectangles *)
  type t = (descr * descr) list
107
  val is_empty: t -> bool
108
  val get: ?kind:pair_kind -> descr -> t
109 110
  val pi1: t -> descr
  val pi2: t -> descr
111
  val pi2_restricted: descr -> t -> descr
112 113 114 115 116 117 118
    
  (* Intersection with (pi1,Any) *)
  val restrict_1: t -> descr -> t

  (* List of non-empty rectangles whose first projection
     are pair-wise disjunct *)
  type normal = t
119
  val normal: ?kind:pair_kind -> descr -> normal
120

121 122 123 124
  val constraint_on_2: normal -> descr -> descr
    (* constraint_on_2 n t1:  maximal t2 such that (t1,t2) <= n *)
    (* Assumption: t1 <= pi1(n) *)

125 126
  val need_second: t -> bool
    (* Is there more than a single rectangle ? *)
127 128 129
end

module Record : sig
130 131 132 133 134 135 136 137 138 139 140 141 142
  val any : descr
  val or_absent: descr -> descr
  val any_or_absent: descr

  val has_absent: descr -> bool
  val has_record: descr -> bool

  val split : descr -> label -> Product.t
  val split_normal : descr -> label -> Product.normal

  val project : descr -> label -> descr
    (* Raise Not_found if label is not necessarily present *)

143 144 145 146 147 148
  val condition : descr -> label -> descr -> descr
    (* condition t1 l t2 : What must follow if field l hash type t2 *)
  val project_opt : descr -> label -> descr
  val has_empty_record: descr -> bool


149 150 151 152
  val first_label: descr -> label

  val empty_cases: descr -> bool * bool

153 154
  val merge: descr -> descr -> descr
  val remove_field: descr -> label -> descr
155

156
  val get: descr -> ((bool * descr) label_map * bool * bool) list
157 158
end

159 160
module Arrow : sig
  val any : descr
161

162 163
  val sample: descr -> descr

164 165 166 167 168 169 170 171
  val check_strenghten: descr -> descr -> descr
    (* [check_strenghten t s]
       Assume that [t] is an intersection of arrow types
       representing the interface of an abstraction;
       check that this abstraction has type [s] (otherwise raise Not_found)
       and returns a refined type for this abstraction.
    *)

172 173
  val check_iface: (descr * descr) list -> descr -> bool

174
  type t
175
  val is_empty: t -> bool
176 177
  val get: descr -> t
    (* Always succeed; no check <= Arrow.any *)
178

179 180 181
  val domain: t -> descr
  val apply: t -> descr -> descr
    (* Always succeed; no check on the domain *)
182 183 184 185 186 187

  val need_arg : t -> bool
    (* True if the type of the argument is needed to obtain
       the type of the result (must use [apply]; otherwise,
       [apply_noarg] is enough *)
  val apply_noarg : t -> descr
188 189 190
end


191
module Int : sig
192
  val has_int : descr -> Intervals.v -> bool
193
  val get: descr -> Intervals.t
194
  val any : descr
195 196
end

197
module Atom : sig
198
  val has_atom : descr -> Atoms.v -> bool
199
  val get: descr -> Atoms.t
200
  val any : descr
201 202
end

203
module Char : sig
204
  val has_char : descr -> Chars.v -> bool
205
  val is_empty : descr -> bool
206
  val get: descr -> Chars.t
207
  val any : descr
208 209
end

210
val normalize : descr -> descr
211

212
(** Subtyping  **)
213

214 215 216
val is_empty : descr -> bool
val non_empty: descr -> bool
val subtype  : descr -> descr -> bool
217

218 219
module Print :
sig
220
  val register_global : U.t -> descr -> unit
221
  val print_const : Format.formatter -> const -> unit
222
  val print: Format.formatter -> descr -> unit
223
end
224